Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. <?php
  2. require "crud/Conexion.php";
  3. require "crud/Crud.php";
  4. require 'api/api_mt_include2.php';
  5. $mensaje = null;
  6.  
  7.  
  8. class action{
  9. public $host;
  10. public function conectap()
  11. {
  12.  
  13. $this->mensaje = $host . "responde!!";
  14. $Username="ecnex";
  15. $Pass="soporte";
  16. $api_puerto=8728;
  17. $connect = mysqli_connect("localhost", "root", "", "ejercicios");
  18. $mac_to_delete = null;
  19. $host = $this->host;
  20. $API = new routeros_api();
  21. $API->debug = false;
  22.  
  23. if ($API->connect($host , $Username , $Pass, $api_puerto))
  24. {
  25. print "conectado a $host";
  26. $API->write("/interface/wireless/registration-table/getall",true);
  27. $READ = $API->read(false);
  28. $ARRAY = $API->parse_response($READ);
  29. $API->write("/system/identity/getall",true);
  30. $READ_2= $API->read(false);
  31. $ARRAY_2 = $API->parse_response($READ_2);
  32. $API->write("/ip/address/getall",true);
  33. $READ_3= $API->read(false);
  34. $ARRAY_3 = $API->parse_response($READ_3);
  35. $API->write("/system/resource/getall",true);
  36. $READ_4= $API->read(false);
  37. $ARRAY_4 = $API->parse_response($READ_4);
  38. $API->write("/interface/wireless/getall",true);
  39. $READ_5 = $API->read(false);
  40. $WIRELESS = $API->parse_response($READ_5);
  41.  
  42. $identity = $ARRAY_2[0]{'name'};
  43. $ip_ap = $host;
  44. $API->disconnect();
  45.  
  46. $ap_name = $identity;
  47. $cpu_load = $ARRAY_4[0]{"cpu-load"} . 'asdf';
  48. $uptime = $ARRAY_4[0]{"uptime"};
  49. $ssid = $WIRELESS[0]{'ssid'};
  50. $channel = $WIRELESS[0]{'frequency'};
  51.  
  52. /// Update base access point
  53. $model_2 = new Crud;
  54. $model_2->update = "mikrotik";
  55. $model_2->set = "cpu_load='$cpu_load', uptime='$uptime', channel='$channel', ssid='$ssid', ip_address='$host', ap_name='$ap_name'";
  56. $model_2->condition = "ip_address='$host'";
  57. $model_2->Update();
  58. $mensaje = $model_2->mensaje;
  59. //deleting data
  60. for($j = 0; $j < count($ARRAY); $j++)//almaceno mac para comprobar si existen en lab `aps`
  61. {
  62. $mac_to_delete[] = $ARRAY[$j]{'mac-address'};
  63. }
  64.  
  65. /// Delete data vieja Si no esta en el Ap
  66. $sql = "DELETE FROM aps WHERE ip_ap='".$ip_ap."' AND mac_address NOT IN('".implode("','",$mac_to_delete)."')";
  67. if(mysqli_query($connect, $sql))
  68. {
  69. echo 'Data Deleted';
  70. }
  71.  
  72. for ($j = 0; $j < count($ARRAY); $j++)
  73. {
  74. $mac_address = $ARRAY[$j]{'mac-address'};
  75. $last_ip = $ARRAY[$j]{'last-ip'};
  76. $interface = $ARRAY[$j]{'interface'};
  77. $uptime = $ARRAY[$j]{'uptime'};
  78. $id = $ARRAY[$j]{'.id'};
  79. $signal_str = $ARRAY[$j]{'signal-strength'};
  80. $tx_ccq = $ARRAY[$j]{'tx-ccq'};
  81. $signal_on_noise = $ARRAY[$j]{'signal-to-noise'};
  82. // insertar nuevos valores
  83. $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."')";
  84. if(mysqli_query($connect, $sql))
  85. {
  86. echo 'Data Update';
  87. }
  88. }
  89. }
  90. }
  91. }
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement