liudf0716 / apfree-wifidog

Secure and streamline your wireless networks with apfree-wifidog: a high-performance, lightweight captive portal solution optimized for both HTTP and HTTPS traffic.
http://wifidogx.online
GNU General Public License v3.0
816 stars 298 forks source link

limit bandwidth by ip or ip mac on wifidog #163

Closed tidus30691nexus5 closed 7 years ago

tidus30691nexus5 commented 7 years ago

please tell how how to limit bandwidth by id or ip mac on wifidog. Am do sever with code sample : ttps://github.com/ApFree/wifidog_v2_authserver_demo/blob/wifidog_v2/

and am config on method Ping with reponse

1

public function ping()   | {   | if(!$this->valid_agent)   | return;   | //url请求 "gw_id=$gw_id&sys_uptime=$sys_uptime&sys_memfree=$sys_memfree&sys_load=$sys_load&wifidog_uptime=$wifidog_uptime";   | //log_message($this->config->item('MY_log_threshold'), CLASS.':'.FUNCTION.':'.debug_printarray($_GET));   |     | //判断各种参数是否为空   | if( !(isset($_GET['gw_id']) and isset($_GET['sys_uptime']) and isset($_GET['sys_memfree']) and isset($_GET['sys_load']) and isset($_GET['wifidog_uptime']) ) )   | {   | echo '{"error":"wifidog参数提交错误"}';   | return;   | }   | //添加心跳日志处理功能   | /   | 此处可获取 wififog提供的 如下参数   | 1.gw_id 来自wifidog 配置文件中,用来区分不同的路由设备   | 2.sys_uptime 路由器的系统启动时间   | 3.sys_memfree 系统内存使用百分比   | 4.wifidog_uptime wifidog持续运行时间(这个数据经常会有问题)   | ~~~~~~~~~~~~~~~~~~~   | v2新增加参数   | 5.dev_id 设备id ,45位字符串(用来区分不同的设备)   | 6.cpu_usage cpu利用率,单位% 值0-100   | 7.nf_conntrack_num 系统会话数 值为整数   | 8.out_rate 路由器出口(WAN口)的上行即时速率,单位 bps   | 9.in_rate 路由器出口(WAN口)的下行即时速率,单位 bps   | 10.(2014-08-07) online_devices 活跃主机数(包括通过认证和没有通过认证的、凡是连接到路由器上的设备的数量),   | /   |     | //返回值   | //规则返回值   | $rule = ' result=';   |     | //主机、网段规则   | $hostrule = array(   | //一条主机规则:针对192.168.1.6单个ip,配置上行为80bps/10Bps,下行为800bps/100Bps的规则   | array('ip'=>'192.168.1.6','netmask'=>'255.255.255.255','up'=>'80','down'=>'800','session'=>'0'),   | //一条主机规则:针对192.168.1.9单个ip,配置上行不受限,下行为2400bps/300Bps的规则,生效时间:每天8点到18:30   | array('ip'=>'192.168.1.9','netmask'=>'255.255.255.255','up'=>'0','down'=>'2400','session'=>'0','timestart'=>'08:00','timestop'=>'18:30'),   | //一条网段规则:针对192.168.1.0/24整个网段,配置该网段内的所有主机上行为8000bps/1000Bps 约1KBps,下行为16000000bps/2000000Bps 约2MBps的规则   | array('ip'=>'192.168.1.0','netmask'=>'255.255.255.0','up'=>'8000','down'=>'16000000','session'=>'0','timestart'=>NULL,'timestop'=>NULL),   | //......其他规则   | );   | //注:按照先后顺序,1.6将按照第一条规则执行限速,1.9按照第二条规则限速,1.0网段其他ip将按照第三条规则限速   | //注:限速规则到后台是要用Bps的单位配置下去的(先做除8操作,再下发),所以主机限速规则要遵循如下规则:要大于8,否则配置下去的有可能是0;尽量配置成8的整倍数   | //注:因为会话数限速配置容易导致会话数被很快用完而导致正常程序上不去网的问题,故取消掉会话数限制,默认都返回0就行   | //注:(2014-07-29增加)参数timestart 和timestop表示该规则生效的时间,要求:格式“HH:MM” 24小时制,timestart和timestop必须同时有效,而且timestop必须大于timestart   |     | //ip白名单   | $ipwhite = array(   | //添加1.2为不受限速限制的白名单   | array('ip'=>'192.168.1.2','netmask'=>'255.255.255.255'),   | //添加1.254为不受限速限制的白名单   | array('ip'=>'192.168.1.254','netmask'=>'255.255.255.255'),   | //..........   | );   | //注意:netmask也可以使用网段掩码,但是就相应的整个网段都是白名单,为了避免混淆,最好固定255.255.255.255不变   |     | //mac黑名单   | //添加2个mac为mac黑名单,不能上网,不能dhcp获取ip   | $macblack = array(array('mac'=>'aa:aa:aa:aa:aa , bb.bb.bb.bb.bb.bb'));   | //注意:所有的mac地址要写在一个字符串里,中间用“,”号隔开   |     | //mac白名单   | //添加2个mac为mac白名单,不用认证就能上网   | $macwhite = array(array('mac'=>'cc.cc.cc.cc.cc.cc , dd.dd.dd.dd.dd.dd'));   | //注意:所有的mac地址要写在一个字符串里,中间用“,”号隔开   |     | //域名白名单   | //添加2个不用认证就能访问的域名   | $domain = array(array('domain'=>'szshort.weixin.qq.com,www.apfree.net'));   | //注意:所有的域名要写在一个字符串里,中间用“,”号隔开   |     |     | //换算md5验证,必须要填写   | $hostrule_md5 = $this->_json2md5str($hostrule);   | $ipwhite_md5 = $this->_json2md5str($ipwhite);   | $macblack_md5 = $this->_json2md5str($macblack);   | $macwhite_md5 = $this->_json2md5str($macwhite);   | $domain_md5 = $this->_json2md5str($domain);   |     | //拼接返回结果   | $rule =$rule.json_encode(array('rule'=>array('host'=>$hostrule,'host_md5'=>$hostrule_md5,'ipwhite'=>$ipwhite,'ipwhite_md5'=>$ipwhite_md5,   | 'macblack'=>$macblack,'macblack_md5'=>$macblack_md5,'macwhite'=>$macwhite,'macwhite_md5'=>$macwhite_md5,   | 'domain'=>$domain,'domain_md5'=>$domain_md5)));   |     | echo 'Pong '.$rule;   | }

it not work, am till test my phone not limit any bandwitdh. so please guide me how to work it. thank you.

liudf0716 commented 7 years ago

apfree wifidog does not support ip or mac bandwidth limit