my_ip(); if(!in_array($from_ip, array( '127.0.0.1', '192.168.10.130', '192.168.10.131', '192.168.10.132', '192.168.10.133', '192.168.10.134', '192.168.10.135', '192.168.10.136', '192.168.10.137', '192.168.10.138', '192.168.10.139' ))) { trigger_error('refused://from:'.$from_ip.'..refused..'.print_r($_REQUEST, true)); exit; } $method_name = $this->router->fetch_method(); if (in_array($method_name, array('sos'))) { ob_end_clean(); ignore_user_abort(); ob_start(); echo 'ok'; header('Connection: close'); header('Content-Length: ' . ob_get_length()); ob_end_flush(); flush(); } } // 取得 IP function my_ip() { if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_REAL_IP')) { $ip = getenv('HTTP_X_REAL_IP'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } // 發生錯誤時集中在此處理 public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) { $log_msg = explode('://', $errstr); if (count($log_msg) > 1) { $log_file = $log_msg[0]; $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n"; } else { $log_file = APP_NAME; $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n"; } error_log($str, 3, LOG_PATH.$log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名 } // 顯示logs public function show_logs() { $lines = $this->uri->segment(3); // 顯示行數 if (empty($lines)) $lines = 100; // 無行數參數, 預設為40行 // echo '
';
echo '';
passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 利用linux指令顯示倒數幾行的logs內容
echo "\n----- " . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt' . ' -----';
echo '';
}
// [區網] 由設備端呼叫
public function sos()
{
$msg = isset($_REQUEST['Message']) ? $_REQUEST['Message'] : '';
trigger_error(__FUNCTION__ . "..Message..{$msg}..". print_r($_REQUEST, true));
$msg_arr = explode('-', $msg);
$station_no = isset($msg_arr['0']) ? $msg_arr['0'] : 0;
$machine_no = isset($msg_arr['1']) ? $msg_arr['1'] : 0;
//$station_no = $this->uri->segment(3);
//$machine_no = $this->uri->segment(4);
if(!isset($station_no) || !isset($machine_no))
{
trigger_error(__FUNCTION__ . '..unknown msg..');
exit;
}
require_once(ALTOB_SYNC_FILE) ;
// 傳送 SOS
$sync_agent = new AltobSyncAgent();
$sync_agent->init($station_no, date('Y-m-d H:i:s'));
$sync_result = $sync_agent->sync_st_sos($machine_no);
trigger_error( "..sync_st_sos.." . $sync_result);
}
}