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; }
<?php // 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
<?php ob_start(); session_start(); require 'routeros_api.class.php'; ?> <?php $API = new routeros_api(); $IP = $_SESSION['ip']; $user = $_SESSION['user']; $password = $_SESSION['password']; //Comprobamos conexion API if ($API->connect($IP, $user, $password)) { //Comprobamos interfaces $Ports = $API->comm("/interface/ethernet/print"); $numPorts = count($Ports); //Modelo $modeloCom = $API->comm("/system/routerboard/print"); $modelo = $modeloCom[0]['model']; //Estado Link $valoresPar = json_encode(range(0, $numPorts - 1)); $valores = substr($valoresPar, 1, -1); //Switch $switches = $API->comm("/interface/ethernet/switch/print"); $numSwitches = count($switches); //Ports Switch $portsSwitch = $API->comm("/interface/ethernet/switch/port/print"); $numPortsSwitch = count($portsSwitch); //puerto Trunk CR $estadoTrunkCR = $API->comm("/interface/ethernet/switch/egress-vlan-tag/print");
<!-- PAGE TITLE --> <div class="page-title"> <h2><span class="fa fa-arrow-circle-o-left"></span> Listado Usuarios Activos Hotspot</h2> </div> <!-- END PAGE TITLE --> <!-- PAGE CONTENT WRAPPER --> <div class="page-content-wrap"> <div class="row"> <!-- empieza IF--> <?php if ($API->connect(IP_MIKROTIK, USER, PASS)) { ?> <div class="col-md-12"> <!-- START DATATABLE EXPORT --> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Usuarios Creados</h3> <div class="btn-group pull-right"> <button class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i> Exportar Info</button> <ul class="dropdown-menu"> <li><a href="#" onClick ="$('#customers2').tableExport({type:'xml',escape:'false'});"><img src='../img/icons/xml.png' width="24"/> XML</a></li> <li><a href="#" onClick ="$('#customers2').tableExport({type:'sql'});"><img src='../img/icons/sql.png' width="24"/> SQL</a></li> <li class="divider"></li> <li><a href="#" onClick ="$('#customers2').tableExport({type:'csv',escape:'false'});"><img src='../img/icons/csv.png' width="24"/> CSV</a></li> <li><a href="#" onClick ="$('#customers2').tableExport({type:'txt',escape:'false'});"><img src='../img/icons/txt.png' width="24"/> TXT</a></li> <li class="divider"></li>
<?php // 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('204.9.216.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
<?php require '/usr/local/gts/routeros_api.class.php'; $API = new routeros_api(); $API->debug = false; //Query Botruc-41 if ($API->connect('216.226.76.91', 'admin', 'P@55w0rd!')) { $API->write('/system/gps/monitor'); $API->write('=once='); $ARRAY = $API->read(); $API->write('/cancel'); $cleanlat = explode(" ", $ARRAY[0]['latitude']); $cleanlong = explode(" ", $ARRAY[0]['longitude']); $botruc41['latitude'] = $cleanlat[1] + trim($cleanlat[2], "'") / 60 + trim(trim($cleanlat[3], "'"), "'") / 3600; $botruc41['longitude'] = 0 - $cleanlong[1] - trim($cleanlong[2], "'") / 60 - trim(trim($cleanlong[3], "'"), "'") / 3600; $API->disconnect(); } //Query Botruc-40 if ($API->connect('216.226.75.139', 'admin', 'P@55w0rd!')) { $API->write('/system/gps/monitor'); $API->write('=once='); $ARRAY = $API->read(); $API->write('/cancel'); $cleanlat = explode(" ", $ARRAY[0]['latitude']); $cleanlong = explode(" ", $ARRAY[0]['longitude']); $botruc40['latitude'] = $cleanlat[1] + trim($cleanlat[2], "'") / 60 + trim(trim($cleanlat[3], "'"), "'") / 3600; $botruc40['longitude'] = 0 - $cleanlong[1] - trim($cleanlong[2], "'") / 60 - trim(trim($cleanlong[3], "'"), "'") / 3600; $API->disconnect(); } //Build device insert query $insertquery[0] = "INSERT INTO Device (accountID,deviceID,groupID,equipmentType,vehicleID,uniqueID,displayName,description,isActive,lastUpdateTime,lastInputState) VALUES ('gtg','Botruc40','lmbotruc','netmodem','Botruc40','Botruc40','Botruc40','Botruc40',1," . time() . ",40000) ON DUPLICATE KEY UPDATE groupID=VALUES(groupID),lastUpdateTime=VALUES(lastUpdateTime),displayName=VALUES(displayName),description=VALUES(description);";
if ($nastype === 1 || $nastype === 15) { $hostek = $nd_list[$i]['ipaddr']; if (!empty($nd_list['port'])) { $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; }
// Load Mikrotik API Class require '/usr/local/gts/routeros_api.class.php'; $host = "172.17.10.60"; // Convert results to integer MS function convertms($resulttime) { $result1 = explode(":", $resulttime); $result2 = explode(".", $result1[2]); $msval = $result1[0] * 60 * 60 * 1000 + $result1[1] * 60 * 1000 + $result2[0] * 1000 + $result2[1]; return $msval; } // Instanciate MT API call $API = new routeros_api(); $API->debug = false; // Query Mikrotik if ($API->connect($host, 'admin', 'DataCom')) { $API->write('/interface/sstp-client/print'); $TARGET = $API->read(); $tunuser = $TARGET[0]['user']; $pingtargarr = explode(':', $TARGET[0]['connect-to']); $pingtarg = $pingtargarr[0]; echo "Ping Target: " . $pingtarg . "\n"; $API->write('/ping', false); $API->write('=address=' . $pingtarg, false); $API->write('=count=10'); $ARRAY = $API->read(); $API->disconnect(); } // Query Tunnel End point for real public ip if ($API->connect($pingtarg, 'admin', 'D@t@c0m#')) { $API->write('/ppp/active/print');