protected function _sendInMessageBody()
 {
     $stationsIdCodesArray = array();
     $reportStationsMessage = '';
     foreach ($this->scheduleProcessedReports as $process) {
         $file_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports" . DIRECTORY_SEPARATOR . $process->schedule_processed_id;
         $report_type = strtoupper($this->schedule_report->report_type);
         $fileArray['file_name'] = $process->ScheduleReportToStation->realStation->station_id_code . '_' . $report_type . '_' . gmdate('Y-m-d_Hi', strtotime($process->check_period_end)) . '.' . $this->schedule_report->report_format;
         $fileArray['file_string'] = file_get_contents($file_path);
         $attachments[] = $fileArray;
         $reportStationsMessage .= '<b>' . $process->ScheduleReportToStation->realStation->station_id_code . ' ';
         $reportStationsMessage .= $report_type . ' </b><br> ';
         $reportStationsMessage .= $fileArray['file_string'];
         $reportStationsMessage .= "<br>=====================================================<br><br>";
         $stationsIdCodesArray[] = $process->ScheduleReportToStation->realStation->station_id_code;
     }
     $this->_logger->log(__METHOD__ . ' stations: ' . print_r($stationsIdCodesArray, 1));
     $mail_params = array('{report_id}' => $this->schedule_report->schedule_id, '{stations_id_code}' => implode(', ', $stationsIdCodesArray), '{actuality_time}' => $this->scheduleProcessedReports[0]->created, '{schedule_period}' => Yii::app()->params['schedule_generation_period'][$this->schedule_report->period], '{link}' => Yii::app()->params['site_url_for_console'] . '/site/schedulehistory/schedule_id/' . $this->schedule_report->schedule_id, '{report_type}' => $report_type, '{messages_content}' => $reportStationsMessage);
     $subject = Yii::t('letter', 'scheduled_report_allstations_mail_subject', $mail_params, null, 'en');
     $body = Yii::t('letter', 'scheduled_report_allstations_messages_inside_mail_message', $mail_params, null, 'en');
     if (count($this->destinations) > 0) {
         foreach ($this->destinations as $i => $destination) {
             if ($destination->method === 'mail') {
                 It::sendLetter($destination->destination_email, $subject, $body);
             }
         }
     }
 }
示例#2
0
 public function run($args)
 {
     if (empty($args[0])) {
         exit;
     }
     $logger = LoggerFactory::getFileLogger('listener/' . $args[0]);
     //        $logger = LoggerFactory::getConsoleLogger();
     $logger->log(__METHOD__ . ' args:' . print_r($args, 1));
     // creates object of ProcessListen class, which duty is listening
     try {
         (new ProcessListen($logger, $args[0], $args[1], $args[2]))->run();
     } catch (Exception $e) {
         It::sendLetter(Yii::app()->params['developer_email'], 'Problem', $e->getMessage());
     }
 }
示例#3
0
 public function deliverReport()
 {
     $this->_logger->log(__METHOD__);
     ini_set('memory_limit', '-1');
     $destinations = ScheduleReportDestination::getList($this->schedule_info->schedule_id);
     $total = count($destinations);
     $this->_logger->log(__METHOD__, array('destination_count' => $total));
     $file_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports" . DIRECTORY_SEPARATOR . $this->schedule_process_info->schedule_processed_id;
     $report_type = strtoupper($this->schedule_info->report_type);
     $file_name = $this->station_info->station_id_code . '_' . $report_type . '_' . gmdate('Y-m-d_Hi', strtotime($this->schedule_process_info->check_period_end)) . '.' . $this->schedule_info->report_format;
     if (count($destinations) > 0) {
         foreach ($destinations as $i => $destination) {
             if ($destination->method === 'mail' and !$this->schedule_info->send_email_together) {
                 $this->_logger->log(__METHOD__, array('destination' => $i + 1, 'report_type' => $report_type, 'method' => $destination->method, 'email' => $destination->destination_email));
                 if ($this->schedule_info->send_like_attach) {
                     $mail_params = array('{station_id_code}' => $this->station_info->station_id_code, '{actuality_time}' => $this->schedule_process_info->created, '{schedule_period}' => Yii::app()->params['schedule_generation_period'][$this->schedule_info->period], '{report_file_name}' => $file_name, '{link}' => Yii::app()->params['site_url_for_console'] . '/site/schedulehistory/schedule_id/' . $this->schedule_info->schedule_id, '{report_type}' => $report_type);
                     $subject = Yii::t('letter', 'scheduled_report_mail_subject', $mail_params, null, 'en');
                     $body = Yii::t('letter', 'scheduled_report_mail_message', $mail_params, null, 'en');
                     It::sendLetter($destination->destination_email, $subject, $body, array(0 => array('file_path' => $file_path, 'file_name' => $file_name)));
                     $this->_logger->log(__METHOD__ . ' Message send with attached file');
                 } else {
                     $mail_params = array('{station_id_code}' => $this->station_info->station_id_code, '{actuality_time}' => $this->schedule_process_info->created, '{schedule_period}' => Yii::app()->params['schedule_generation_period'][$this->schedule_info->period], '{messages_content}' => file_get_contents($file_path), '{link}' => Yii::app()->params['site_url_for_console'] . '/site/schedulehistory/schedule_id/' . $this->schedule_info->schedule_id, '{report_type}' => $report_type);
                     $subject = Yii::t('letter', 'scheduled_report_mail_subject', $mail_params, null, 'en');
                     $body = Yii::t('letter', 'scheduled_report__messages_inside_mail_message', $mail_params, null, 'en');
                     It::sendLetter($destination->destination_email, $subject, $body);
                     $this->_logger->log(__METHOD__ . ' Message send in letter body');
                     $this->_logger->log(__METHOD__ . '     ' . file_get_contents($file_path));
                 }
                 $this->_logger->log(__METHOD__ . ' Deliver via mail DONE.');
             } else {
                 if ($destination->method === 'ftp') {
                     $this->_logger->log(__METHOD__, array('destination' => $i + 1, 'report_type' => $report_type, 'method' => $destination->method, 'destination_ip' => $destination->destination_ip, 'destination_ip_port' => $destination->destination_ip_port, 'destination_ip_user' => $destination->destination_ip_user, 'destination_ip_password' => $destination->destination_ip_password));
                     $errors = array();
                     $conn_id = @ftp_connect($destination->destination_ip, $destination->destination_ip_port);
                     if ($conn_id !== false) {
                         $result = false;
                         if (isset($destination->destination_ip_user)) {
                             $result = @ftp_login($conn_id, $destination->destination_ip_user, $destination->destination_ip_password);
                         }
                         if ($result === true) {
                             if (@ftp_chdir($conn_id, $destination->destination_ip_folder)) {
                                 $mode = $this->schedule_info->report_type === 'bufr' ? 'rb' : 'r';
                                 $fp = @fopen($file_path, $mode);
                                 if ($fp !== false) {
                                     // try to upload $file
                                     $res = @ftp_pasv($conn_id, true);
                                     if ($res === true) {
                                         $mode = $this->schedule_info->report_type == 'bufr' ? FTP_BINARY : FTP_ASCII;
                                         if (!@ftp_fput($conn_id, $file_name, $fp, $mode)) {
                                             $errors[] = 'There was a problem with uploading file ' . $file_name . ' to ftp ' . $destination->destination_ip;
                                         }
                                     } else {
                                         $errors[] = 'Can not set passive mode';
                                     }
                                     @fclose($fp);
                                 } else {
                                     $errors[] = 'Can not open stream to copy file to ' . $file_path;
                                 }
                             } else {
                                 $errors[] = 'Can not change ftp directory to ' . $destination->destination_ip_folder;
                             }
                         } else {
                             $errors[] = 'Connection with FTP ' . $destination->destination_ip . ' was failed with given login & password';
                         }
                         @ftp_close($conn_id);
                     } else {
                         $errors[] = 'Connection with FTP ' . $destination->destination_ip . ' was failed';
                     }
                     if ($errors) {
                         foreach ($errors as $error) {
                             $this->errors[] = date('Y-m-d H:i') . ' ' . $error;
                         }
                         $this->saveProcess();
                     }
                     $this->_logger->log(__METHOD__ . ' Deliver via ftp DONE.');
                 } else {
                     if ($destination->method === 'local_folder') {
                         $this->_logger->log(__METHOD__, array('destination' => $i + 1, 'report_type' => $report_type, 'method' => $destination->method, 'destination_folder' => $destination->destination_local_folder));
                         $settings = Settings::model()->findByPk(1);
                         $destinationPath = $settings->scheduled_reports_path . DIRECTORY_SEPARATOR . $destination->destination_local_folder;
                         if (!is_dir($destinationPath)) {
                             @mkdir($destinationPath, 0777, true);
                         }
                         copy($file_path, $destinationPath . DIRECTORY_SEPARATOR . $file_name);
                         $this->_logger->log(__METHOD__ . ' Deliver to local folder DONE.');
                     }
                 }
             }
         }
     }
     $this->_logger->log(__METHOD__ . ' Delivery completed.');
 }
示例#4
0
 /**
  * Find current sms command and set in here response
  *
  * @param $response string
  * @example $response OK   : '@ B AWS01 DT OK   234567890 BV1 126 7558E9F6 $' (without space)
  * @example $response FAIL : '@ B AWS01 DT FAIL                   E3290CA6 $' (without space)
  *
  * @return null|SMSCommand
  */
 public static function setResponse($response)
 {
     /**
      * 1. Min response length
      * 2. Lead X code
      * 3. Start @
      *    Ended $
      * 4. CRC
      */
     if (strlen($response) >= 18 && (substr($response, 1, 1) === 'B' || substr($response, 1, 1) === 'C') && substr($response, 0, 1) === '@' && substr($response, -1) === '$' && substr($response, -9, 8) === It::prepareCRC(substr($response, 1, -9))) {
         $sms_command_code = substr($response, 7, 2);
         $station_id_code = substr($response, 2, 5);
         $qb = new CDbCriteria();
         $qb->compare('sms_command_status', SMSCommand::STATUS_SENT);
         $qb->compare('sms_command_code', $sms_command_code);
         $qb->compare('station.station_id_code', $station_id_code);
         $qb->with = ['station' => ['select' => false]];
         $qb->order = 't.updated ASC';
         /** @var SMSCommand $sms_command */
         $sms_command = SMSCommand::model()->find($qb);
         if (!isset($sms_command)) {
             $sms_command = new SMSCommand();
             $station = Station::Model()->findByAttributes(array('station_id_code' => $station_id_code));
             if (is_null($station)) {
                 return null;
             }
             $sms_command->station_id = $station->station_id;
             $sms_command->sms_command_code = "-";
             $sms_command->sms_command_message = "-";
         }
         $sms_command->sms_command_response = $response;
         $sms_command->sms_command_status = SMSCommand::STATUS_PROCESSED;
         if (!$sms_command->save()) {
             It::sendLetter(yii::app()->params['developer_email'], 'Error', json_encode($sms_command->getErrors()));
         }
         return $sms_command;
     }
     return null;
 }
 public function send()
 {
     return It::sendLetter($this->email, $this->subject, $this->message, array());
 }
 /**
  * Send email messages with attachment $excel_path
  * @param $excel_path
  * @return bool
  */
 private function emailSend($excel_path)
 {
     $this->_logger->log(__METHOD__);
     $time = $this->now['mday'] . ' ' . $this->now['month'] . ' ' . $this->now['year'];
     $file_name = "HeartbeatReport, {$time}.xls";
     $title = "Heartbeat {$this->clientName}, {$time}";
     $body = "Heartbeat {$this->clientName}, {$time},<br>\n                  Attached is the heartbeat report from {$this->clientName}, {$time},<br>\n                  Sincerely,<br>\n                  Delairco Japan KK";
     $flag = true;
     try {
         foreach ($this->email as $email) {
             $flag = $flag && It::sendLetter($email, $title, $body, array(0 => array('file_path' => $excel_path, 'file_name' => $file_name)));
         }
     } catch (Exception $e) {
         $this->_logger->log(__METHOD__ . "ERROR: ", $e->getMessage());
         return false;
     }
     return $flag;
 }