function mtPublicIP($host) { // Instanciate MT API call $API = new routeros_api(); $API->debug = false; // Set a default value to return if connection to MT fails $ipaddr = "0.0.0.0"; // Query Mikrotik if ($API->connect($host, 'admin', 'DataCom')) { $API->write('/ip/dhcp-client/print'); $ARRAY = $API->read(); $API->disconnect(); $ipaddr = substr($ARRAY['0']['address'], 0, -3); if ($ipaddr == "") { $API->connect($host, 'admin', 'DataCom'); $API->write('/ip/address/print'); $ARRAY = $API->read(); $API->disconnect(); foreach ($ARRAY as $addr) { if ($addr['interface'] == "ether1") { $ipaddr = substr($addr['address'], 0, -3); } } } } return $ipaddr; }
// Email Alerts Function function email_alert($message, $subject) { system("echo '{$message}' | mail -s '{$subject}' trouble@getdatacom.com -- -f alerts@mydatacomgts.com"); } // Read old states from file $oldstate = parse_ini_file("/root/oldstatefile.txt"); // Get current states from Mikrotik require '/usr/local/gts/routeros_api.class.php'; $API = new routeros_api(); $API->debug = false; // Query Mikrotik if ($API->connect('69.1.163.102', 'admin', 'd@t@c0m#')) { $API->write('/ppp/active/print'); $ARRAY = $API->read(); $API->disconnect(); foreach ($ARRAY as $item) { $currentstate[$item['name']] = $item['caller-id']; } $savefile = ""; foreach ($currentstate as $name => $ip) { $savefile .= $name . "=" . $ip . "\n"; } file_put_contents("/root/oldstatefile.txt", $savefile); } // Compare old to new arrays $newchange = array_diff_assoc($currentstate, $oldstate); $oldchange = array_diff_assoc($oldstate, $currentstate); // Figure out changed IPs and Tunnel Ups $tunnelchange = ""; $tunnelup = "";
$hostek .= ':' . $nd_list[$i]['port']; } $result = $LMS->WIFI_GetAllSignal($hostek, $nd_list[$i]['login']); if ($result) { $data = $result; } else { $data = array(); } } if ($nastype === 14) { $MT->debug = false; $MT->port = $nd_list[$i]['port']; if ($connect = $MT->connect($nd_list[$i]['ipaddr'], $nd_list[$i]['login'], $nd_list[$i]['passwd'])) { $MT->write('/interface/wireless/registration-table/print'); $result = $MT->read(); $MT->disconnect(); if ($result) { for ($k = 0; $k < sizeof($result); $k++) { if (isset($result[$k]['signal-strength']) && !empty($result[$k]['signal-strength'])) { $tab[$k]['rx_signal'] = substr($result[$k]['signal-strength'], 0, strpos($result[$k]['signal-strength'], "dBm")); } else { $tab[$k]['rx_signal'] = 0; } if (isset($result[$k]['tx-signal-strength']) && !empty($result[$k]['tx-signal-strength'])) { $tab[$k]['tx_signal'] = $result[$k]['tx-signal-strength']; } else { $tab[$k]['tx_signal'] = 0; } if (isset($result[$k]['rx-rate']) && !empty($result[$k]['rx-rate'])) { $tab[$k]['rx_rate'] = str_replace('Mbps', '', $result[$k]['rx-rate']); } else {