Esempio n. 1
0
 public function startTcpServer()
 {
     $source = 'TCP:' . $this->forwarding_messages_ip . ":" . $this->tcp_server_command_port;
     $last_connection = Listener::getLastConnectionInfoForSynch($source);
     if ($last_connection && !$last_connection['stopped']) {
     } else {
         $command = Yii::app()->params['applications']['php_exe_path'] . ' -f ' . Yii::app()->params['applications']['console_app_path'] . ' tcpserver ';
         It::runAsynchCommand($command);
     }
 }
 public function run()
 {
     ListenerProcess::addComment($this->listener->listener_id, 'comment', 'going to start polling, source= ' . $this->source);
     $failureCount = 0;
     $modemFailureCount = 0;
     $resetSmsMessageWasSent = false;
     $modemReset = false;
     $i = 0;
     while (true) {
         $time = time();
         for ($j = 0; $j < 4; $j++) {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Trying to poll data', array('try' => $j));
             // If message was received then exit loop
             if ($this->listenPollingTemp($i++)) {
                 $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Message received on', array('try' => $j));
                 $resetSmsMessageWasSent = false;
                 $modemReset = false;
                 break;
             }
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Delay 1 minute before next try.');
             // Wait 1 minute before next try
             sleep(60);
             // 1min
             if ($j === 3) {
                 $failureCount++;
                 $modemFailureCount++;
             }
         }
         if (!is_null($this->_smsMessageSender) && $failureCount >= Yii::app()->params['sms_params']['failure_count_before_send_sms']) {
             $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Going to send reset SMS message.', array('try' => $resetSmsMessageWasSent + 1));
             $failureCount = 0;
             if ($resetSmsMessageWasSent > 3) {
                 $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Reset SMS message was already sent');
             } else {
                 if ($this->_smsMessageSender->send()) {
                     $resetSmsMessageWasSent += 1;
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' SMS message has been sent');
                 } else {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Failed to send SMS message');
                 }
             }
         }
         if ($modemFailureCount >= Yii::app()->params['polling_params']['failure_count_before_modem_reset']) {
             if (Yii::app()->params['polling_params']['enabled'] === true) {
                 $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Going to reset polling modem.');
                 $modemFailureCount = 0;
                 if ($modemReset) {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Modem was already reset.');
                 } else {
                     $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Resetting.');
                     ListenerProcess::addComment($this->listener->listener_id, 'modem_reset', ' Polling modem was reset.');
                     // Send KILL to wvdial to force modem to re-create connection
                     It::runAsynchCommand('sudo killall wvdial');
                     $modemReset = true;
                 }
             } else {
                 $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Resetting of polling modem is disabled.');
             }
         }
         // Delay for 10 minutes - time spent on tries.
         $time = Yii::app()->params['polling_params']['interval'] - (time() - $time);
         $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Delay before next poll', array('seconds' => $time));
         sleep($time);
     }
 }
Esempio n. 3
0
 public static function runConnection($source, $additional_param, $by = 'user')
 {
     $command = Yii::app()->params['applications']['php_exe_path'] . " -f " . Yii::app()->params['applications']['console_app_path'] . " listen " . $source . " " . $additional_param . " " . $by;
     It::runAsynchCommand($command);
     return true;
 }
Esempio n. 4
0
 public function actionStartListening()
 {
     if (!isset($_REQUEST['source'])) {
         echo json_encode(array('errors' => array('Unknown connection type')));
         Yii::app()->end();
     }
     $source = strtoupper($_REQUEST['source']);
     $communication_type = !empty($_REQUEST['communication_type']) ? strtoupper($_REQUEST['communication_type']) : 'COMMUNICATION_TYPE_NONE';
     $last_connection = Listener::getLastConnectionInfo($source);
     if ($last_connection && !$last_connection['stopped']) {
         echo json_encode(array('ok_still' => 1));
         Yii::app()->end();
     }
     $command = Yii::app()->params['applications']['php_exe_path'] . ' -f ' . Yii::app()->params['console_app_path'] . ' listen ' . $source . '  ' . $communication_type . ' Admin';
     It::runAsynchCommand($command);
     echo json_encode(array('ok' => 1));
     Yii::app()->end();
 }