options IPFIREWALL
options IPFIREWALL_DEFAULT_TO_ACCEPT
options IPFIREWALL_FORWARD
options IPFIREWALL_VERBOSE
options IPFIREWALL_VERBOSE_LIMIT=50
options IPFIREWALL_NAT
options LIBALIAS
options ROUTETABLES=2
options DUMMYNET
options HZ="1000"
defaultrouter="1.1.1.1" # .
gateway_enable="YES" # .
ifconfig_re0="inet 1.1.1.2 netmask 255.255.255.252" # , .
ifconfig_re1="inet 10.128.1.1 netmask 255.255.255.0" # , Wi-Fi .
inetd_enable="YES"
sshd_enable="YES" # SSH
sendmail_enable="NO" # Sendmail
firewall_enable="YES" #
firewall_nat_enable="YES" #
dummynet_enable="YES" # Dummynet. .
firewall_script="/etc/firewall.sh" # .
ipfw -q flush
ipfw pipe 1 config bw 512Kbit/s mask dst-ip 0x00000001 #
ipfw pipe 2 config bw 256Kbit/s mask dst-ip 0x00000001 #
ipfw nat 1 config log if re0 reset same_ports # , .
ipfw add 120 nat 1 ip from 10.128.1.0/24 to any via re0 #
ipfw add 121 nat 1 ip from any to 192.168.24.154 via re0 # .
ipfw add 1000 fwd 10.128.1.1,80 tcp from any to any 80 via re1 # , .
RewriteEngine on
ErrorDocument 404 10.128.1.1/index.php
CREATE TABLE `hotspot` ( `time_begin` timestamp NOT NULL default '0000-00-00 00:00:00', `rule_num` smallint(5) unsigned NOT NULL, KEY `rule_num` (`rule_num`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 ;
<?php // : define('conf_DB_HOST', 'localhost'); define('conf_DB_USER', 'root'); define('conf_DB_PASS', ''); define('conf_DB_NAME', 'hotspot'); define('RULE_NUM_MIN', 200); //, , . define('CLIENTS_TIME', '1800'); // 30 ( ) define('CLIENTS_TRAF', '30'); // //, define('RULE_ADD_IP', '/usr/local/bin/sudo /sbin/ipfw add %s pipe 1 ip from any to %s'); define('RULE_ADD_IP2', '/usr/local/bin/sudo /sbin/ipfw add %s pipe 2 ip from %s to any'); define('RULE_DEL_IP', '/usr/local/bin/sudo /sbin/ipfw delete %s'); define('RULE_DEL_IP2', '/usr/local/bin/sudo /sbin/ipfw delete %s'); // . $db_link = mysql_connect(conf_DB_HOST, conf_DB_USER, conf_DB_PASS); if (!$db_link) echo('Connect Error!'); if (!mysql_select_db(conf_DB_NAME, $db_link)) echo('Connect Error'); ?>
<H1> Wi-Fi !<br> 30 30 . </H1> <?php $redir='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo('<form method=GET action="open.php">'); echo("<input type=hidden name=redir value=$redir>"); echo('<input value=" !" type="submit"></form>'); ?>
<?php require_once('config.php'); $user_ip = $_SERVER['REMOTE_ADDR']; $current_date = time(); // . 200. RULE_NUM_MIN. $temp = 0; $sql = 'SELECT rule_num FROM hotspot ORDER BY rule_num'; $res = mysql_query($sql); if ($res) { $t = mysql_fetch_array($res); if (!$t) $rule_num = RULE_NUM_MIN; else { while ($temp = mysql_fetch_array($res)) { if (($t[0]+1) < $temp[0]) break; $t = $temp; } $rule_num = $t[0]+1 } } else return false; // 2 . - " ", " ". 200 . 200 . $command = sprintf(RULE_ADD_IP, $rule_num, $user_ip); exec($command); $command2 = sprintf(RULE_ADD_IP2, $rule_num+200, $user_ip); exec($command2); // . $sql = 'INSERT INTO hotspot (time_begin, rule_num) values (NOW(),'.$rule_num.')'; mysql_query($sql); // , . $redir=$_GET['redir']; header("Location: $redir"); return true; ?>
<?php require_once('config.php'); // , , . $sql = 'SELECT * FROM hotspot WHERE time_begin > 0 AND (TIME_TO_SEC(TIMEDIFF(NOW(), time_begin)) > '.CLIENTS_TIME.')'; $res = mysql_query($sql); if ($res) { while ($user = mysql_fetch_assoc($res)) { block($user['rule_num']); } } // IPFW . - . $sql = 'SELECT * FROM hotspot WHERE 1'; $res = mysql_query($sql); if ($res) { while ($user = mysql_fetch_array($res)) { $rule=$user['rule_num']; exec("/usr/local/bin/sudo /sbin/ipfw show $rule | awk '{print($3)}'",$ct); if($ct[0]>=CLIENTS_TRAF*1024*1024) block($rule); } } return true; //, . function block($num) { $command = sprintf(RULE_DEL_IP, $num); exec($command); $command2 = sprintf(RULE_DEL_IP2, $num+200); exec($command2); $sql = 'DELETE FROM hotspot WHERE rule_num='.$num; mysql_query($sql); } ?>
*/1 * * * * /usr/local/bin/php /var/www/data/cron.php
# .
option domain-name "hotspot.my";
# . .
option domain-name-servers 8.8.8.8;
# . .
default-lease-time 600;
max-lease-time 7200;
# . .
subnet 10.128.1.0 netmask 255.255.255.0 {
range 10.128.1.20 10.128.1.220;
option routers 10.128.1.1;
}
Source: https://habr.com/ru/post/132369/
All Articles