123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace TR069Bundle\Services;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\Process\Process;
- use Symfony\Component\Process\Exception\ProcessFailedException;
- class TR069Econocable extends TR069Service
- {
- public function getTR069Data($data)
- {
- $result = array();
- $result['_id'] = $data['_id'] ?? null;
-
- $this->refreshObject($result['_id'], 'InternetGatewayDevice.DeviceConfig.ConfigFile');
- $result['_deviceId'] = $data['_deviceId'] ?? null;
- $result['SSID'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSID'] ?? null;
- $result['keyPassphrase'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['KeyPassphrase'] ?? null;
- $result['SSIDAdvertisementEnabled'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['SSIDAdvertisementEnabled'] ?? null;
- $result['Status'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['Enable'] ?? null;
-
- //InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey
- $result['preSharedKey'] = $data['InternetGatewayDevice']['LANDevice']['1']['WLANConfiguration']['1']['PreSharedKey']['1']['PreSharedKey'] ?? null;
-
- //InternetGatewayDevice.DeviceConfig.ConfigFile
- $aux = $this->getParameter($result['_id'], 'InternetGatewayDevice.DeviceConfig.ConfigFile');
- $configFile = $aux[0]['InternetGatewayDevice']['DeviceConfig']['ConfigFile']['_value'] ?? null;
- if(is_null($configFile)) {
- $result['CatvPower']['_value'] = null;
- } else {
-
- if(preg_match('(CATV_ENABLED\" Value=\"1)',$configFile)) {
- $result['CatvPower']['_value'] = true;
- } elseif(preg_match('(CATV_ENABLED\" Value=\"0)',$configFile)) {
- $result['CatvPower']['_value'] = false;
- } else {
- $result['CatvPower']['_value'] = null;
- }
- }
- $result['ExternalIPAddress'] = $data['InternetGatewayDevice']['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['ExternalIPAddress'] ?? null;
- return $result;
- }
- // SET ConfigFile XML Data -_- :| :\ :/
- // https://memegenerator.net/img/instances/81512436/no-digan-como-programo.jpg
- public function setCATV($id, $state = true)
- {
- $url = "{$this->url}/devices/{$id}/tasks?connection_request";
-
- $data = $this->getParameter($id, 'InternetGatewayDevice.DeviceConfig.ConfigFile');
- $configFile = $data[0]['InternetGatewayDevice']['DeviceConfig']['ConfigFile']['_value'] ?? null;
- if(is_null($configFile))
- return false; //without estate information
- if(preg_match('(CATV_ENABLED\" Value=\"1)',$configFile) && $state) {
- return true; //Se encuentra habilitada y la queremos habilitar - No ejecutamos acción
- } elseif(preg_match('(CATV_ENABLED\" Value=\"0)',$configFile) && !$state) {
- return true;
- } else {
- $data = $this->getParameter($id, 'InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress');
- $ip = $data[0]['InternetGatewayDevice']['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['ExternalIPAddress']['_value'] ?? null;
- if(is_null($ip)) return false;
- $this->executeSelenium($ip);
-
- return true;
- }
-
- return true;
- }
-
- private function executeSelenium($ip)
- {
- //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'"
- //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
- $host = $this->serviceContainer->getParameter("tr069_selenium_host");
- $root = "{$this->serviceContainer->get('kernel')->getRootDir()}/../";
- $codecept = "{$root}vendor/bin/codecept";
- $params = "-c {$root}vendor/ik/tr069-bundle -o 'modules: config: WebDriver: host: {$host}' -o 'modules: config: WebDriver: url: http://{$ip}'";
-
- $cmd = "$codecept run acceptance {$params}";
- $command = $root . 'bin/console amqp:remote --route=ftth ' . '"' . $cmd.'" --args=--executeName';
- $process = new Process($command);
- $process->run();
- }
- }
|