Witam
Mam skrypt w php który pobiera z lms adresy "włączonych" ip komputerów i dodaje do ip firewall jako klienci_access, na MT na reguła która blokuje dostęp do neta dla tych co ich wyłączy. skrypt korzysta z routeros_api_class, aktualizuje listę jak lms jakiego kl wyłączy.
plik database.inc -- <?php class config{};
$CONF = new config;
/* MYSQL CONFIG */
$CONF->dbhost = "127.0.0.1"; $CONF->dbname = "user"; $CONF->dbuser = "db"; $CONF->dbpass = "pass";
?> ---
--- <?php set_time_limit(80); include("/etc/database.inc"); require('/etc/routeros_api.class.php');
$mtikhost = "x.x.x.x"; //ip mikrotik'a
$mtikuser = "user"; //user na mikrotiku co ma access do api $mtikpass = "dupa"; // has\304\271\342\200\232o na mikrotika
$API = new routeros_api(); if ($API->connect($mtikhost, $mtikuser, $mtikpass)) { $add = "/ip/firewall/address-list/add";
$ext = $API->comm("/ip/firewall/address-list/print", array( ".proplist"=> "address", "?list" => "klienci_access", ));
function in_array_r($item , $array){ return preg_match('/"'.$item.'"/i' , json_encode($array)); }
mysql_pconnect($CONF->dbhost, $CONF->dbuser, $CONF->dbpass); @mysql_select_db("$CONF->dbname") or die ("Unable to select database"); $ipall = ""; $test = 0; $result = mysql_query("select INET_NTOA(ipaddr) as ip from nodes where access = '1'"); while( list($ip) = mysql_fetch_row($result)) { if(eregi("^10.0.(1|2).[0-9]{1,3}|^78.9.(64|65|66|67|68|69).[0-9]{1,3}", $ip)) { // tu musisz zmienić, skrypt tnie po IP, lub wywalić tą linie if(in_array_r($ip , $ext)){ } else {
$vars = array( "list" => "klienci_access", "comment" => str_replace('.','',$ip), "address" => $ip); $ARRAY = $API->comm($add, $vars); # echo "dodaje $ip\n"; $test++; } } }
mysql_pconnect($CONF->dbhost, $CONF->dbuser, $CONF->dbpass); @mysql_select_db("$CONF->dbname") or die ("Unable to select database"); $ipall = ""; $test = 0; $result = mysql_query("select INET_NTOA(ipaddr) as ip from nodes where access = '0'"); while( list($ip2) = mysql_fetch_row($result)) { if(eregi("^10.0.(1|2).[0-9]{1,3}|^78.9.(64|65|66|67|68|69).[0-9]{1,3}", $ip2)) { // tu musisz zmienić, skrypt tnie po IP, lub wywalić tą linie if(in_array_r($ip2 , $ext)){ $ipip = str_replace('.', '', $ip2); $API->write('/ip/firewall/address-list/remove', false); $API->write('=.id='.$ipip); $API->read(); # echo "usuwa $ip2\n"; $test++; } } }
} $API->disconnect(); ?>