Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "crud/Conexion.php";
- require "crud/Crud.php";
- require 'api/api_mt_include2.php';
- $mensaje = null;
- class action{
- public $host;
- public function conectap()
- {
- $this->mensaje = $host . "responde!!";
- $Username="ecnex";
- $Pass="soporte";
- $api_puerto=8728;
- $connect = mysqli_connect("localhost", "root", "", "ejercicios");
- $mac_to_delete = null;
- $host = $this->host;
- $API = new routeros_api();
- $API->debug = false;
- if ($API->connect($host , $Username , $Pass, $api_puerto))
- {
- print "conectado a $host";
- $API->write("/interface/wireless/registration-table/getall",true);
- $READ = $API->read(false);
- $ARRAY = $API->parse_response($READ);
- $API->write("/system/identity/getall",true);
- $READ_2= $API->read(false);
- $ARRAY_2 = $API->parse_response($READ_2);
- $API->write("/ip/address/getall",true);
- $READ_3= $API->read(false);
- $ARRAY_3 = $API->parse_response($READ_3);
- $API->write("/system/resource/getall",true);
- $READ_4= $API->read(false);
- $ARRAY_4 = $API->parse_response($READ_4);
- $API->write("/interface/wireless/getall",true);
- $READ_5 = $API->read(false);
- $WIRELESS = $API->parse_response($READ_5);
- $identity = $ARRAY_2[0]{'name'};
- $ip_ap = $host;
- $API->disconnect();
- $ap_name = $identity;
- $cpu_load = $ARRAY_4[0]{"cpu-load"} . 'asdf';
- $uptime = $ARRAY_4[0]{"uptime"};
- $ssid = $WIRELESS[0]{'ssid'};
- $channel = $WIRELESS[0]{'frequency'};
- /// Update base access point
- $model_2 = new Crud;
- $model_2->update = "mikrotik";
- $model_2->set = "cpu_load='$cpu_load', uptime='$uptime', channel='$channel', ssid='$ssid', ip_address='$host', ap_name='$ap_name'";
- $model_2->condition = "ip_address='$host'";
- $model_2->Update();
- $mensaje = $model_2->mensaje;
- //deleting data
- for($j = 0; $j < count($ARRAY); $j++)//almaceno mac para comprobar si existen en lab `aps`
- {
- $mac_to_delete[] = $ARRAY[$j]{'mac-address'};
- }
- /// Delete data vieja Si no esta en el Ap
- $sql = "DELETE FROM aps WHERE ip_ap='".$ip_ap."' AND mac_address NOT IN('".implode("','",$mac_to_delete)."')";
- if(mysqli_query($connect, $sql))
- {
- echo 'Data Deleted';
- }
- for ($j = 0; $j < count($ARRAY); $j++)
- {
- $mac_address = $ARRAY[$j]{'mac-address'};
- $last_ip = $ARRAY[$j]{'last-ip'};
- $interface = $ARRAY[$j]{'interface'};
- $uptime = $ARRAY[$j]{'uptime'};
- $id = $ARRAY[$j]{'.id'};
- $signal_str = $ARRAY[$j]{'signal-strength'};
- $tx_ccq = $ARRAY[$j]{'tx-ccq'};
- $signal_on_noise = $ARRAY[$j]{'signal-to-noise'};
- // insertar nuevos valores
- $sql = "REPLACE INTO aps ( `mac_address`,`last_ip`, `interface`, `id`, `uptime`, `ip_ap`,`signal_on_noise`,`tx_ccq`,`signal_str`,`ap_name` ) VALUES ('".$mac_address."','".$last_ip."', '".$interface."','".$id."','".$uptime."','".$ip_ap."','".$signal_on_noise."','".$tx_ccq."','".$signal_str."','".$ap_name."')";
- if(mysqli_query($connect, $sql))
- {
- echo 'Data Update';
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement