{"id":337725,"date":"2022-08-31T15:00:04","date_gmt":"2022-08-31T15:00:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337725"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337725","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u0440\u0435\u0448\u0430\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0430\u0431\u043e\u043d\u0435\u043d\u0442\u043e\u0432 HYDRA Billing \u0432 BDCOM<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<blockquote>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c, \u0441 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u043e\u0431\u043e\u0440\u0443\u0434\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043b\u0430 SNMP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0447\u0435\u0440\u0435\u0437 telnet \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043d\u0443 \u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 telnet \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0442\u043e\u0440\u043e\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441 , \u0447\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440 \u043d\u0435 \u043f\u043e\u043c\u043d\u044e \u0433\u0434\u0435 \u0435\u0433\u043e \u0441\u043a\u0430\u0447\u0430\u043b, \u0434\u0443\u043c\u0430\u044e \u043d\u0430\u0438\u0442\u0438 \u0447\u0442\u043e \u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/p>\n<\/blockquote>\n<pre><code class=\"php\">require_once(__DIR__ . '\/TelnetClient\/TelnetClient.php');<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0430\u0448\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u0441\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u0445 \u0444\u0430\u0439\u043b\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u0443\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0430\u043a \u043b\u043e\u0433\u0438\u043d \u043f\u0430\u0440\u043e\u043b\u044c \u0445\u043e\u0441\u0442 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u043b\u0438\u043d\u0433\u0430 \u0433\u0438\u0434\u0440\u044b (Oracle DB)<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f Start , \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 , \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442 \u043d\u0430\u0448 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b  \u043f\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\\\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0430\u0431\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e<\/p>\n<\/blockquote>\n<pre><code class=\"php\">function Start($conf) {    $filelog = new FileLog($conf);   $mac_on_really = [];   $mac_off_really = [];    $hydra = new HydraAPI($conf);   $mac_on =  $hydra->Get_BDCOM_ONOFF(true);   $mac_off =  $hydra->Get_BDCOM_ONOFF(false);      $lines = file($this->conf['bdcom_onoff_file'], FILE_IGNORE_NEW_LINES);             foreach ($mac_on as $mac) {     foreach ($lines as $line) {       $finded = false;       \/\/ \u0418\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u0430\u043a \u0441 \u0441\u0442\u0440\u043e\u043a\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430       if(strpos($line, $mac)>-1)           {             if(trim($line) === trim(\"$mac:enable\")) { $finded = true; break;  }           }     }      if($finded === false) { $mac_on_really[] = $mac; }   }       foreach ($mac_off as $mac) {     foreach ($lines as $line) {       $finded = false;       \/\/ \u0418\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u0430\u043a \u0441 \u0441\u0442\u0440\u043e\u043a\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430       if(strpos($line, $mac)>-1)           {             if(trim($line) === trim(\"$mac:disable\")) { $finded = true; break;  }           }     }      if($finded === false) { $mac_off_really[] = $mac; }   }     TelnetOnOFFBDCOM($conf,$mac_on_really, true);   TelnetOnOFFBDCOM($conf,$mac_off_really, false);  }<\/code><\/pre>\n<blockquote>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\\\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 BDCOM , \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Filelog &#8212; \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043b\u043e\u0433\u0430\u043c\u0438, TelnetClient &#8212; \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 telnet, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0430\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c\\\u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b \u043b\u043e\u0433\u043e\u0432<\/p>\n<\/blockquote>\n<pre><code class=\"php\">\/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\/\u0432\u044b\u043a\u043b \u0431\u0434\u043a\u043e\u043c \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0438\u043b function TelnetOnOFFBDCOM($conf,$mac_arr,$onoff = true) { $epon_port = false; $result_onoff = false;  $filelog = new FileLog($conf);  $telnet = new TelnetClient($host, $port); $telnet->connect(); \/\/ \u041b\u043e\u0433\u0438\u043d $telnet->setPrompt('\/(ogin|name|word|UserName):.*$\/'); $telnet->sendCommand('netadmin', true); \/\/ \u043f\u0430\u0440\u043e\u043b\u044c $telnet->setPrompt('\/(word|PassWord):.*$\/'); $telnet->sendCommand('netadmin', true); $telnet->setPrompt('>'); $telnet->sendCommand('enable', true); $telnet->setPrompt('#'); $telnet->sendCommand('config', true); $telnet->setPrompt('#');  if($onoff) $command = \"enable\" else $command = \"disable\";  foreach ($mac_arr as $mac_item) {   \/\/ \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u043a \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442   $mac = ConvertMacToDelimitier($mac_item,'.');  $telnet->sendCommand('show epon onu-information mac-address '.$mac, true); $telnet->setPrompt('registered'); \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0432\u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 $array = $telnet->exec('', true);  foreach($array as $item) {  \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043c\u0430\u043a   if(strpos($item,$mac)>-1)   {     \/\/ \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0438\u0435   if(strpos($item,'EPON')>-1)     {     $epon_port_arr = explode(':',$item);     \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c EPON \u043f\u043e\u0440\u0442     $epon_port = trim($epon_port_arr[0]).':'.trim(substr($epon_port_arr[1], 0,3));     break;     }   }  } \/\/ \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u043e\u0442\u0432\u0435\u0442\u0430  $telnet->sendCommand(\"\", true);  if($epon_port)  {   $port = str_replace(\"EPON\",'',$epon_port);   $telnet->sendCommand(\"interface epON \".$port);   $telnet->setPrompt('#');   $telnet->sendCommand(\"epon onu catv $command\", true);   $telnet->setPrompt('\/');   $result_onoff = true;  } \/\/ \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0442\u043e \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0438\u043b if($result_onoff) {    $str = ;     \/\/ \u0438\u0449\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0438\u043b\u0435    $data = $filelog->GetStrFromFile($mac);    if($data)    {    $result =  $data['data'];    $line = $data['line'];    \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438    $filelog->SetReplaceStr($line, $mac.':'.$command);    }    else    {     \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443     $filelog->SetRewriteFile($mac.':'.$command);      }    $log_str = date(\"Y-m-d h:i:s\").\" mac \".$mac.':'.$command;    $filelog->SetRewriteLogFile($log_str);     }  } \/\/ \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0430\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432  $telnet->sendCommand('exit', true);  $telnet->disconnect();  }<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u043e\u0433\u0430\u043c\u0438<\/p>\n<\/blockquote>\n<pre><code class=\"php\">class FileLog {    public $conf;     function __construct($conf)    {     $this->conf = $conf;    }      function SetRewriteLogFile($str)    {     $fhandle = fopen($this->conf['log_file_name'],\"w\");     fwrite($fhandle,$content);     fclose($fhandle);    }     function SetRewriteFile($str)    {     $fhandle = fopen($this->conf['bdcom_onoff_file'],\"w\");     fwrite($fhandle,$content);     fclose($fhandle);    }     function SetAddStringFile($str)    {     $fp = fopen($this->conf['log_file_name'], 'a+'); \/\/- \u0430+ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445     fwrite($fp, $str.\"\\r\\n\"); \/\/\u0430 \"r\\n\\\" - \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0441 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     fclose($fp);    }     \/\/ \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0438 \u0435\u0441\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u043a    function GetStrFromFile($mac)    {                 $result = false;             $line = 0;             $fp = @fopen($this->conf['bdcom_onoff_file'], \"r\");         if ($fp) {             while (($buffer = fgets($fp, 4096)) !== false) {                if(strpos($buffer, $mac) !== false) {  $result['data'] = explode(':', $buffer); $result['line'] = $line; break;  }                $line = $line +1;             }                         if (!feof($fp)) {                 echo \"\u041e\u0448\u0438\u0431\u043a\u0430: fgets() \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e \u043f\u043e\u0442\u0435\u0440\u043f\u0435\u043b \u043d\u0435\u0443\u0434\u0430\u0447\u0443\\n\";             }             fclose($fp);         }         return $result;    }<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u043b\u043b\u0438\u043d\u0433\u043e\u043c Hydra (Oracle DB), \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441  Get_BDCOM_ONOFF &#8212; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u0438\u043a\u043e\u0432 \u0438\u043b\u0438 \u0430\u0431\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u0430\u043b\u0430\u043d\u0441\u043e\u043c<\/p>\n<\/blockquote>\n<pre><code class=\"php\">class HydraAPI {  public $conn;   function __construct($conf)     {         try {             $conn = @oci_connect($conf['hydra_user'], $conf['hydra_pwd'], $conf['hydra_host'] . '\/' . $conf['hydra_db'], 'AL32UTF8');             if (!$conn) {                 $e = oci_error();                \/\/ trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);             }              $this->conn = $conn;         }catch(Exception $e) {}      }     public function Get_BDCOM_ONOFF($onoff = true)     {         try{                          if($onoff) { $balance_str = '>'; } else { $balance_str = '&lt;'; }              $query = \"SELECT DISTINCT CONCAT('https:\/\/95.182.107.243:8000\/subjects\/persons\/edit\/',OS.N_SUBJECT_ID) URL,        SU.VC_BASE_SUBJECT_NAME,        OV.VC_VALUE,        -- \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435         g.vc_name,        SU.N_SUBJ_STATE_ID FROM   SI_V_OBJ_SUBJECTS   OS, si_subj_accounts sa, SI_V_USERS SU,        SR_GOODS G,        SI_OBJ_OBJECTS SOO,        SI_V_OBJECTS_SIMPLE O      LEFT JOIN SI_V_OBJ_VALUES  OV on (OV.N_GOOD_VALUE_TYPE_ID in (55898801,56112401) AND  O.N_OBJECT_ID = OV.N_OBJECT_ID  )    WHERE  OS.N_OBJECT_ID  = O.N_OBJECT_ID  AND    g.n_good_id = o.n_good_id AND SU.N_CUSTOMER_ID = OS.N_SUBJECT_ID AND SU.N_SUBJ_STATE_ID = 2011 AND sa.n_subject_id= os.n_subject_id AND SI_USERS_PKG_S.GET_ACCOUNT_BALANCE_SUM(sa.n_account_id) $balance_str 0 AND OV.VC_VALUE IS NOT NULL and exists (Select * from si_v_subscriptions ss where ss.n_customer_id = su.n_customer_id and ss.n_service_id in (54614801) and ss.c_fl_closed='N'  ) AND soo.n_object_id = o.n_object_id   AND soo.n_bind_object_id in (SELECT obj2.n_object_id FROM SI_V_OBJECTS OBJ2 WHERE obj2.n_good_id=56105201 and obj2.n_object_id = 56107601)\";                    $stid = oci_parse($this->conn, $query);             oci_execute($stid);              while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {              $MAC = $row['VC_VALUE'];               $result[] = $MAC;             }                  return $result;              }catch (\\Exception $e){ return false;}       }    }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/685664\/\"> https:\/\/habr.com\/ru\/post\/685664\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<blockquote>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u043e\u0441\u044c, \u0441 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u043e\u0431\u043e\u0440\u0443\u0434\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043b\u0430 SNMP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0447\u0435\u0440\u0435\u0437 telnet \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043d\u0443 \u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 telnet \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0442\u043e\u0440\u043e\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441 , \u0447\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440 \u043d\u0435 \u043f\u043e\u043c\u043d\u044e \u0433\u0434\u0435 \u0435\u0433\u043e \u0441\u043a\u0430\u0447\u0430\u043b, \u0434\u0443\u043c\u0430\u044e \u043d\u0430\u0438\u0442\u0438 \u0447\u0442\u043e \u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/p>\n<\/blockquote>\n<pre><code class=\"php\">require_once(__DIR__ . '\/TelnetClient\/TelnetClient.php');<\/code><\/pre>\n<blockquote>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0430\u0448\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u0441\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u0445 \u0444\u0430\u0439\u043b\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u0443\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0430\u043a \u043b\u043e\u0433\u0438\u043d \u043f\u0430\u0440\u043e\u043b\u044c \u0445\u043e\u0441\u0442 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u043b\u0438\u043d\u0433\u0430 \u0433\u0438\u0434\u0440\u044b (Oracle DB)<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f Start , \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 , \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442 \u043d\u0430\u0448 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b  \u043f\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\\\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u0430\u0431\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e<\/p>\n<\/blockquote>\n<pre><code class=\"php\">function Start($conf) {    $filelog = new FileLog($conf);   $mac_on_really = [];   $mac_off_really = [];    $hydra = new HydraAPI($conf);   $mac_on =  $hydra->Get_BDCOM_ONOFF(true);   $mac_off =  $hydra->Get_BDCOM_ONOFF(false);      $lines = file($this->conf['bdcom_onoff_file'], FILE_IGNORE_NEW_LINES);             foreach ($mac_on as $mac) {     foreach ($lines as $line) {       $finded = false;       \/\/ \u0418\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u0430\u043a \u0441 \u0441\u0442\u0440\u043e\u043a\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430       if(strpos($line, $mac)>-1)           {             if(trim($line) === trim(\"$mac:enable\")) { $finded = true; break;  }           }     }      if($finded === false) { $mac_on_really[] = $mac; }   }       foreach ($mac_off as $mac) {     foreach ($lines as $line) {       $finded = false;       \/\/ \u0418\u0449\u0435\u043c \u043d\u0430\u0448 \u043c\u0430\u043a \u0441 \u0441\u0442\u0440\u043e\u043a\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430       if(strpos($line, $mac)>-1)           {             if(trim($line) === trim(\"$mac:disable\")) { $finded = true; break;  }           }     }      if($finded === false) { $mac_off_really[] = $mac; }   }     TelnetOnOFFBDCOM($conf,$mac_on_really, true);   TelnetOnOFFBDCOM($conf,$mac_off_really, false);  }<\/code><\/pre>\n<blockquote>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\\\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 BDCOM , \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Filelog &#8212; \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043b\u043e\u0433\u0430\u043c\u0438, TelnetClient &#8212; \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 telnet, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0430\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c\\\u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0439\u043b \u043b\u043e\u0433\u043e\u0432<\/p>\n<\/blockquote>\n<pre><code class=\"php\">\/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\/\u0432\u044b\u043a\u043b \u0431\u0434\u043a\u043e\u043c \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0438\u043b function TelnetOnOFFBDCOM($conf,$mac_arr,$onoff = true) { $epon_port = false; $result_onoff = false;  $filelog = new FileLog($conf);  $telnet = new TelnetClient($host, $port); $telnet->connect(); \/\/ \u041b\u043e\u0433\u0438\u043d $telnet->setPrompt('\/(ogin|name|word|UserName):.*$\/'); $telnet->sendCommand('netadmin', true); \/\/ \u043f\u0430\u0440\u043e\u043b\u044c $telnet->setPrompt('\/(word|PassWord):.*$\/'); $telnet->sendCommand('netadmin', true); $telnet->setPrompt('>'); $telnet->sendCommand('enable', true); $telnet->setPrompt('#'); $telnet->sendCommand('config', true); $telnet->setPrompt('#');  if($onoff) $command = \"enable\" else $command = \"disable\";  foreach ($mac_arr as $mac_item) {   \/\/ \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u043a \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442   $mac = ConvertMacToDelimitier($mac_item,'.');  $telnet->sendCommand('show epon onu-information mac-address '.$mac, true); $telnet->setPrompt('registered'); \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0432\u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 $array = $telnet->exec('', true);  foreach($array as $item) {  \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043c\u0430\u043a   if(strpos($item,$mac)>-1)   {     \/\/ \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0438\u0435   if(strpos($item,'EPON')>-1)     {     $epon_port_arr = explode(':',$item);     \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c EPON \u043f\u043e\u0440\u0442     $epon_port = trim($epon_port_arr[0]).':'.trim(substr($epon_port_arr[1], 0,3));     break;     }   }  } \/\/ \u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u043e\u0442\u0432\u0435\u0442\u0430  $telnet->sendCommand(\"\", true);  if($epon_port)  {   $port = str_replace(\"EPON\",'',$epon_port);   $telnet->sendCommand(\"interface epON \".$port);   $telnet->setPrompt('#');   $telnet->sendCommand(\"epon onu catv $command\", true);   $telnet->setPrompt('\/');   $result_onoff = true;  } \/\/ \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0442\u043e \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0438\u043b if($result_onoff) {    $str = ;     \/\/ \u0438\u0449\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0444\u0430\u0438\u043b\u0435    $data = $filelog->GetStrFromFile($mac);    if($data)    {    $result =  $data['data'];    $line = $data['line'];    \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438    $filelog->SetReplaceStr($line, $mac.':'.$command);    }    else    {     \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443     $filelog->SetRewriteFile($mac.':'.$command);      }    $log_str = date(\"Y-m-d h:i:s\").\" mac \".$mac.':'.$command;    $filelog->SetRewriteLogFile($log_str);     }  } \/\/ \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0430\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432  $telnet->sendCommand('exit', true);  $telnet->disconnect();  }<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u043e\u0433\u0430\u043c\u0438<\/p>\n<\/blockquote>\n<pre><code class=\"php\">class FileLog {    public $conf;     function __construct($conf)    {     $this->conf = $conf;    }      function SetRewriteLogFile($str)    {     $fhandle = fopen($this->conf['log_file_name'],\"w\");     fwrite($fhandle,$content);     fclose($fhandle);    }     function SetRewriteFile($str)    {     $fhandle = fopen($this->conf['bdcom_onoff_file'],\"w\");     fwrite($fhandle,$content);     fclose($fhandle);    }     function SetAddStringFile($str)    {     $fp = fopen($this->conf['log_file_name'], 'a+'); \/\/- \u0430+ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445     fwrite($fp, $str.\"\\r\\n\"); \/\/\u0430 \"r\\n\\\" - \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0441 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     fclose($fp);    }     \/\/ \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0438 \u0435\u0441\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u043a    function GetStrFromFile($mac)    {                 $result = false;             $line = 0;             $fp = @fopen($this->conf['bdcom_onoff_file'], \"r\");         if ($fp) {             while (($buffer = fgets($fp, 4096)) !== false) {                if(strpos($buffer, $mac) !== false) {  $result['data'] = explode(':', $buffer); $result['line'] = $line; break;  }                $line = $line +1;             }                         if (!feof($fp)) {                 echo \"\u041e\u0448\u0438\u0431\u043a\u0430: fgets() \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e \u043f\u043e\u0442\u0435\u0440\u043f\u0435\u043b \u043d\u0435\u0443\u0434\u0430\u0447\u0443\\n\";             }             fclose($fp);         }         return $result;    }<\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u043b\u043b\u0438\u043d\u0433\u043e\u043c Hydra (Oracle DB), \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441  Get_BDCOM_ONOFF &#8212; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u0438\u043a\u043e\u0432 \u0438\u043b\u0438 \u0430\u0431\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u0430\u043b\u0430\u043d\u0441\u043e\u043c<\/p>\n<\/blockquote>\n<pre><code class=\"php\">class HydraAPI {  public $conn;   function __construct($conf)     {         try {             $conn = @oci_connect($conf['hydra_user'], $conf['hydra_pwd'], $conf['hydra_host'] . '\/' . $conf['hydra_db'], 'AL32UTF8');             if (!$conn) {                 $e = oci_error();                \/\/ trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);             }              $this->conn = $conn;         }catch(Exception $e) {}      }     public function Get_BDCOM_ONOFF($onoff = true)     {         try{                          if($onoff) { $balance_str = '>'; } else { $balance_str = '&lt;'; }              $query = \"SELECT DISTINCT CONCAT('https:\/\/95.182.107.243:8000\/subjects\/persons\/edit\/',OS.N_SUBJECT_ID) URL,        SU.VC_BASE_SUBJECT_NAME,        OV.VC_VALUE,        -- \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435         g.vc_name,        SU.N_SUBJ_STATE_ID FROM   SI_V_OBJ_SUBJECTS   OS, si_subj_accounts sa, SI_V_USERS SU,        SR_GOODS G,        SI_OBJ_OBJECTS SOO,        SI_V_OBJECTS_SIMPLE O      LEFT JOIN SI_V_OBJ_VALUES  OV on (OV.N_GOOD_VALUE_TYPE_ID in (55898801,56112401) AND  O.N_OBJECT_ID = OV.N_OBJECT_ID  )    WHERE  OS.N_OBJECT_ID  = O.N_OBJECT_ID  AND    g.n_good_id = o.n_good_id AND SU.N_CUSTOMER_ID = OS.N_SUBJECT_ID AND SU.N_SUBJ_STATE_ID = 2011 AND sa.n_subject_id= os.n_subject_id AND SI_USERS_PKG_S.GET_ACCOUNT_BALANCE_SUM(sa.n_account_id) $balance_str 0 AND OV.VC_VALUE IS NOT NULL and exists (Select * from si_v_subscriptions ss where ss.n_customer_id = su.n_customer_id and ss.n_service_id in (54614801) and ss.c_fl_closed='N'  ) AND soo.n_object_id = o.n_object_id   AND soo.n_bind_object_id in (SELECT obj2.n_object_id FROM SI_V_OBJECTS OBJ2 WHERE obj2.n_good_id=56105201 and obj2.n_object_id = 56107601)\";                    $stid = oci_parse($this->conn, $query);             oci_execute($stid);              while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {              $MAC = $row['VC_VALUE'];               $result[] = $MAC;             }                  return $result;              }catch (\\Exception $e){ return false;}       }    }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/685664\/\"> https:\/\/habr.com\/ru\/post\/685664\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-337725","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337725"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337725\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}