TR069Econocable.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace TR069Bundle\Services;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\Process\Process;
  5. use Symfony\Component\Process\Exception\ProcessFailedException;
  6. class TR069Econocable extends TR069Service
  7. {
  8. public function getTR069Data($data)
  9. {
  10. $result = array();
  11. $result['_id'] = $data['_id'] ?? null;
  12. $this->refreshObject($result['_id'], 'InternetGatewayDevice.DeviceConfig.ConfigFile');
  13. $result['_deviceId'] = $data['_deviceId'] ?? null;
  14. $result['SSID'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSID'] ?? null;
  15. $result['keyPassphrase'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['KeyPassphrase'] ?? null;
  16. $result['SSIDAdvertisementEnabled'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSIDAdvertisementEnabled'] ?? null;
  17. $result['Status'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['Enable'] ?? null;
  18. //InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey
  19. $result['preSharedKey'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['PreSharedKey']['1']['PreSharedKey'] ?? null;
  20. //InternetGatewayDevice.DeviceConfig.ConfigFile
  21. $aux = $this->getParameter($result['_id'], 'InternetGatewayDevice.DeviceConfig.ConfigFile');
  22. $configFile = $aux[0]['InternetGatewayDevice']['DeviceConfig']['ConfigFile']['_value'] ?? null;
  23. if(is_null($configFile)) {
  24. $result['CatvPower']['_value'] = null;
  25. } else {
  26. if(preg_match('(CATV_ENABLED\" Value=\"1)',$configFile)) {
  27. $result['CatvPower']['_value'] = true;
  28. } elseif(preg_match('(CATV_ENABLED\" Value=\"0)',$configFile)) {
  29. $result['CatvPower']['_value'] = false;
  30. } else {
  31. $result['CatvPower']['_value'] = null;
  32. }
  33. }
  34. $result['ExternalIPAddress'] = $data['InternetGatewayDevice']['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['ExternalIPAddress'] ?? null;
  35. return $result;
  36. }
  37. // SET ConfigFile XML Data -_- :| :\ :/
  38. // https://memegenerator.net/img/instances/81512436/no-digan-como-programo.jpg
  39. public function setCATV($id, $state = true)
  40. {
  41. $url = "{$this->url}/devices/{$id}/tasks?connection_request";
  42. $data = $this->getParameter($id, 'InternetGatewayDevice.DeviceConfig.ConfigFile');
  43. $configFile = $data[0]['InternetGatewayDevice']['DeviceConfig']['ConfigFile']['_value'] ?? null;
  44. if(is_null($configFile))
  45. return false; //without estate information
  46. if(preg_match('(CATV_ENABLED\" Value=\"1)',$configFile) && $state) {
  47. return true; //Se encuentra habilitada y la queremos habilitar - No ejecutamos acción
  48. } elseif(preg_match('(CATV_ENABLED\" Value=\"0)',$configFile) && !$state) {
  49. return true;
  50. } else {
  51. $data = $this->getParameter($id, 'InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress');
  52. $ip = $data[0]['InternetGatewayDevice']['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['ExternalIPAddress']['_value'] ?? null;
  53. if(is_null($ip)) return false;
  54. $this->executeSelenium($ip);
  55. return true;
  56. }
  57. return true;
  58. }
  59. private function executeSelenium($ip)
  60. {
  61. //php vendor/bin/codecept run acceptance -c vendor/ik/tr069-bundle -o "modules: config: WebDriver: host: '200.50.168.120'" -o "modules: config: WebDriver: url: 'http://10.1.7.242'"
  62. //bin/console amqp:remote --route=ftth "/opt/ftth/vendor/bin/codecept run acceptance -c /opt/ftth/vendor/ik/tr069-bundle -o 'modules: config: WebDriver: host: 200.50.168.120' -o 'modules: config: WebDriver: url: http://10.1.7.242'" --args=--config:vendor/ik/tr069-bundle
  63. $host = $this->serviceContainer->getParameter("tr069_selenium_host");
  64. $root = "{$this->serviceContainer->get('kernel')->getRootDir()}/../";
  65. $codecept = "{$root}vendor/bin/codecept";
  66. $params = "-c {$root}vendor/ik/tr069-bundle -o 'modules: config: WebDriver: host: {$host}' -o 'modules: config: WebDriver: url: http://{$ip}'";
  67. $cmd = "$codecept run acceptance {$params}";
  68. $command = $root . 'bin/console amqp:remote --route=ftth ' . '"' . $cmd.'" --args=--executeName';
  69. $process = new Process($command);
  70. $process->run();
  71. }
  72. }