function shutdown($msg = '') { global $ircNetworks, $module, $log; logWrite(L_SYSTEM, sprintf('[SYSTEM] Shutting down neotor%s', !empty($msg) ? ': ' . $msg : '')); // Kill all irc-connections foreach ($ircNetworks as $key => $value) { $ircNetworks[$key]->quit($msg); } // Close all logs if (!is_array($log)) { $log = array(); } foreach ($log as $key => $value) { if ($key > 0) { $log[$key]->close(); } } // Unload all modules if (!is_array($module)) { $module = array(); } foreach ($module as $key => $value) { $value->forceUnload(); } // Going down exit; }
public function getKey() { //时间戳 $ts = time(); //随机数 $tr = $this->ci->ucc->genRandomInt(5); // var_dump($tr.($ts+$tr)); //拼接返回 $this->ci->load->helper("dblog"); logWrite("WCF genKey", print_r(array("ts" => $ts, "tr" => $tr), true), 1, "", 0, 0); return $tr . ($ts + $tr); }
function logPushMsg($msg, $immediate_write = true, $do_echo = FALSE) { global $msg_buf; if (!isset($msg_buf)) { $msg_buf = ''; } if (is_array($msg)) { $msg = print_r($msg, TRUE); } if (defined('PKG_SYSBOOT') & $do_echo) { echo $msg; } $msg_buf .= "{$msg}\n---[MSG END]---\n\n"; if ($immediate_write) { logWrite(); } }
public function query($query) { if (!isset($this->db) || !mysql_ping($this->db)) { $this->db = mysql_connect(CONFIG_mysql_server, CONFIG_mysql_username, CONFIG_mysql_password); mysql_select_db(CONFIG_mysql_database, $this->db); } if (!($q = mysql_query($query, $this->db))) { if (mysql_errno($this->db) == 2006) { mysql_close($this->db); $this->db = mysql_connect(CONFIG_mysql_server, CONFIG_mysql_username, CONFIG_mysql_password); mysql_select_db(CONFIG_mysql_database, $this->db); if ($q = mysql_query($query, $this->db)) { $f = true; } } if (empty($f)) { logWrite(L_ERROR, "[QABOT] Query Failed (" . mysql_errno($this->db) . ' ' . mysql_error($this->db) . "): {$query}\n"); } } return $q; }
$loader = new Zend_Loader_Autoloader_Resource(array('basePath' => $apppath . '/application/', 'namespace' => 'Application')); // Name, path, namepsace $loader->addResourceType('model', 'models', 'Model'); // Get our config file $config = new Zend_Config_Ini($apppath . '/application/configs/application.ini'); Zend_Registry::set('config', $config->production); // Because our models need it this way // Get the Delivery Report model $timestamp = date('Y-m-d H:i:s'); // Log the start of this read logWrite("####################################"); logWrite("Begin store memcache optouts: {$timestamp}"); logWrite("------------------------------------"); $inb = new Application_Model_Smsinbound(); $inb->optoutsListFromInboundToMemcache(); $endofset = date('Y-m-d H:i:s'); logWrite("End of storing optouts into memcache: {$endofset}"); logWrite("------------------------------------"); return 0; /** * Simply writes a log message line to the log file * * @param string $msg The message to write */ function logWrite($msg) { global $logfile; $fh = fopen($logfile, 'a'); fwrite($fh, "{$msg}\n"); fclose($fh); }
/*Memcache server: BDAYCLUB info stores in the memcache memory*/ $msgobj = new Application_Model_Message(); $msgobj->addMemcahceBdclub(); /*end of memcache server use*/ $dataObj = new Application_Model_DataReporting(); $rst = $dataObj->allphonenumbers(); if ($rst) { $log = "Rows inserted: {$rst}"; logWrite($log); } else { logWrite("No data inserted!!"); } // Set up our current timestamp for closing out $timestamp = date('Y-m-d H:i:s'); // Log the end of this send logWrite("\n---------------------"); logWrite("End of inserting: {$timestamp}"); logWrite("**********************************\n"); return 0; /** * Simply writes a log message line to the log file * * @param string $msg The message to write */ function logWrite($msg) { global $logfile; $fh = fopen($logfile, 'a'); fwrite($fh, "{$msg}\n"); fclose($fh); }
public function sendweeklyAction1() { $weeklyreport = new Application_Model_Report(); $sendReportsTo = $weeklyreport->sendRportTo(); $queueCount = count($sendReportsTo); $sendCount = 0; if (is_array($sendReportsTo)) { if (!empty($sendReportsTo)) { foreach ($sendReportsTo as $user) { $mail = new Zend_Mail(); $mail->setBodyText('Please see the weekly report:'); $mail->setFrom('*****@*****.**', 'Textmunication.com'); $mail->addTo($user['email'], 'Joseph Saunders'); $mail->addCc('*****@*****.**', 'Wais Asefi'); //$mail->addCc('*****@*****.**', 'Robert Gonzalez'); $mail->setSubject('Weekly Reports'); // Get the Excel model $excel = new Application_Model_Excel(); if ($weeklyreport->checkAdminUser($user['id']) and $user['id'] != 187) { if (isset($user['edituser'])) { $excelDataArray = $weeklyreport->getWeeklyReportByEditUser($user['edituser']); //echo "single"; print_r($excelDataArray); exit; $date = date('Ymd'); $excelFileName = "weeklyreport_pollo" . $user['edituser'] . '_' . $date; logWrite("Creating the Excel spreadsheets"); $excel = new Application_Model_Excel(); $excelFile = $excel->create($excelDataArray, $excelFileName); logWrite("Attaching the spreadsheets"); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } else { $excelDataArray = $weeklyreport->getWeeklyReport($user['id']); $date = date('Ymd'); $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date; $excel = new Application_Model_Excel(); $excelFile = $excel->create($excelDataArray, $excelFileName); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } } else { // Get the subscriber datasets $excelDataArray = $weeklyreport->getWeeklyReport(); //echo "<pre>"; print_r($excelDataArray); exit; // Get a date stamp for the file $date = date('Ymd'); // Create our file names $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date; // Log the steps //logWrite("Creating the Excel spreadsheets"); // Make the Excel files for each day $excelFile = $excel->create($excelDataArray, $excelFileName); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } // Log the steps //logWrite("Preparing to send..."); // Send it off if (!$mail->send()) { echo "MESSAGE NOT SENT"; } else { echo "Message sent"; } } } else { $this->error = "No reports to send"; } } else { $this->error = "Send to report was not properly fetched"; } }
/** * Called whenever raw data is received from the server. * Calls parseCommand() and all attach():ed methods * * @param string $data The data that was received * * @return void */ public function gotRaw($data) { $extra = $this->parseCommand($data); extract($extra); foreach ($this->attached as $id => $val) { list($filter, $method, $regexp) = $val; if (empty($filter) || in_array($func, $filter)) { if (!empty($regexp)) { if (preg_match($regexp, $msg, $extra['regexp']) == 0) { continue; } } try { call_user_func_array($method, array($this, $data, $extra)); } catch (Exception $e) { logWrite(L_ERROR, "Uncaught exception from module: " . $e->getMessage()); } } } }
$stmt->setFetchMode(PDO::FETCH_ASSOC); $refreshIDs = array(); while ($res = $stmt->fetch()) { $refreshIDs[$res['id']] = ''; } //print_r($refreshIDs); logWrite("Изменения обнаружены в: " . count($refreshIDs) . " товарах"); // TODO: Сохраняем сериализованный массив ресурсов с изменениями в файл refresh.spb.dat // А может и не надо... // Заливаем новые данные в рабочую таблицу ms_products $sql = "UPDATE `modx_ms2_products` as m, temp_import_spb as t, `modx_site_content` as c\nSET m.quantity=t.quantity,\nm.weight=t.weight,\nm.price=t.price,\nm.old_price=t.old_price\nWHERE m.article=t.article\nAND m.id=c.id\nAND c.context_key='web'"; $res = $db->exec($sql); logWrite('Запись новых данных: ' . $res . ' строк внесено'); /**/ //------------- САНКТ-ПЕТЕРБУРГ ВЫПОЛНЕНО ---------------------------------------------------------------------/ // Избирательная чистка Кэша //print_r($refreshIDs); foreach ($refreshIDs as $id => $val) { //$id=79; $resource = $modx->getObject('modResource', $id); $cacheKey = $resource->getCacheKey(); $modx->cacheManager->refresh(array('resource' => array('key' => $cacheKey))); } // Финиш logWrite('затраченное время: ' . (microtime(true) - $modx->startTime) . ' сек.'); logWrite(''); if (DEBUG) { print "</pre>"; } fwrite($fLastLog, $template_end); exit(0);
/** * 错误输出 * @param mixed $error 错误 * @return void */ function halt($error) { $e = array(); if (APP_DEBUG) { //APP_DEBUG || IS_CLI //调试模式下输出错误信息 if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['line'] = $trace[0]['line']; ob_start(); debug_print_backtrace(); $e['trace'] = ob_get_clean(); } else { $e = $error; } //兼容php其他运行模式 // if(IS_CLI){ // exit(iconv('UTF-8','gbk',$e['message']).PHP_EOL.'FILE: '.$e['file'].'('.$e['line'].')'.PHP_EOL.$e['trace']); // } } else { //否则定向到错误页面 $error_page = C('ERROR_PAGE'); if (!empty($error_page)) { include $error_page; exit; } else { $message = is_array($error) ? $error['message'] : $error; $e['message'] = C('SHOW_ERROR_MSG') ? $message : C('ERROR_MESSAGE'); } } logWrite($e['message'] . "\n\r" . $e['file'] . "\n\r" . $e['line'] . "\n\r"); // 包含异常页面模板 $exceptionFile = LWH_PATH . 'View/lwh_exception.html'; include $exceptionFile; exit; }
function get($data) { $data = str_replace("\r", "", str_replace("\n", "", $data)); if (!empty($data)) { $this->idle = time(); // Reset idle-counter if ($this->auth['authed'] == 0) { if (empty($this->auth['username'])) { $this->auth['username'] = $data; $this->put('Password: '******'username'] != CONFIG_telnet_username && $this->auth['password'] != CONFIG_telnet_password) { $this->quit(); } $this->put('Auth ok.', 1); $this->put(sprintf('%s%s (%s) logged in.', timestamp(), $this->auth['username'], $this->host), 1); $this->auth['authed'] = 1; $this->auth['password'] = $data; logWrite(L_TELNET, sprintf('[TELNET:%d] User \'%s\' logged in.', 0, $this->auth['username'])); return; } } else { $cmd = ''; $args = ''; if (strstr($data, ' ')) { list($cmd, $args) = explode(' ', $data, 2); } else { $cmd = $data; } $this->exec($cmd, $args); return; } } }
if (!file_exists($config['system']['pidfile'])) { touch($config['system']['pidfile']); } $pidfile = fopen($config['system']['pidfile'], 'w'); fwrite($pidfile, $pid); exit; } } else { logWrite(L_DEBUG, sprintf('[DEBUG] Entering debug-mode')); if (!defined("DEBUG")) { define("DEBUG", true); } } if (function_exists("pcntl_signal")) { pcntl_signal(SIGTERM, "sigHandler"); pcntl_signal(SIGHUP, "sigHandler"); } $ircNetworks = $writeStreams = $openStreams = $openFiles = array(); if (defined('DEBUG')) { logOpen('php://stdout', L_DEBUG | L_SYSTEM | L_ERROR | L_TELNET | L_PRIVMSG | L_IRCALL); if (PHP_OS !== 'WINNT' && ($tmpfp = fopen('php://stdin', 'r'))) { $openFiles['console'] = array('socket' => $tmpfp, 'type' => 'console'); $console = new stdin($tmpfp); unset($tmpfp); } logWrite(L_DEBUG, sprintf('[DEBUG] Started neotor %s.', $version)); } // logOpen('logs/g33k.se.log', L_CHANNEL, '#g33k.se'); if (function_exists("irc_open_sockets")) { irc_open_sockets(); }
if (empty($opt) || !file_exists('modules/' . $mod . '.php')) { continue; } elseif ($opt == 1) { include_once 'modules/' . $mod . '.php'; $netObj[$mod] = $mod; } else { include_once 'modules/' . $mod . '.php'; if (!isset($netObj[$opt]) || !is_array($netObj[$opt])) { $netObj[$opt] = array(); } $netObj[$opt][$mod] = $mod; } } } /* * Start bot */ include_once SPATH . 'start.php'; // Initiate startup-script. $init = 0; // Disable all init-codes. include_once SPATH . 'main.php'; // Initiate while-loop. /* * If the script got this far, an error ocurred. */ if (function_exists('logWrite')) { logWrite(L_ERROR | L_DEBUG, "[error] Script ended without reason.\n"); } else { exit(timestamp() . " [error] Script ended without reason.\n"); }
} //$output.="REQUEST_TIME ".$_SERVER['REQUEST_TIME']."\n"; if (!empty($info->city->name_ru)) { $output .= "Город\t\t\t" . $info->city->name_ru; } if (!empty($info->region->name_ru)) { $output .= " - регион: " . $info->region->name_ru; } if (!empty($info->country->name_ru)) { $output .= " - " . $info->country->name_ru; } $output .= "\n"; if (!empty($info->request)) { $output .= "Запрос к API Sypex\t" . $info->request . "\n"; } logWrite($output, $fhBuf); //logWrite(microtime(true) - $startTime, $fhBuf); // Закрываем файл fflush($fhBuf) or die($php_errormsg); flock($fhBuf, LOCK_UN) or die($php_errormsg); fclose($fhBuf) or die($php_errormsg); } unset($fhBuf); // Файл освобождён if (DEBUG) { print "</pre>"; } // Template caching system if (!DEBUG) { print getActualCache($template_cache_filename, 86400, $template_source_path); }
logWrite("------------------------------------"); //if ($message->queueBirthDayMessage()) { // logWrite("Birth day messages are queueing."); //} else { // logWrite("Birth day messages can not be queued."); //} $msgobj = new Application_Model_Message(); //$arb = $msgobj->addMemcahceBdclub(); $mobj = memcache_connect('10.179.252.160', 11211); $msgbody = $mobj->get('1386'); echo '<pre>'; print_r($msgbody); // Set up our current timestamp for closing out $timestamp = date('Y-m-d H:i:s'); // Log the end of this send logWrite("\n---------------------"); logWrite("Process complete\nEnd birth day message set: {$timestamp}"); logWrite("####################################\n"); return 0; /** * Simply writes a log message line to the log file * * @param string $msg The message to write */ function logWrite($msg) { global $logfile; $fh = fopen($logfile, 'a'); fwrite($fh, "{$msg}\n"); fclose($fh); }
/** * @return resource */ public function newSms() { $q = $this->query("SELECT 'inbox' AS tblname,id,number,text,insertdate FROM inbox WHERE processed = 0 UNION SELECT 'multipartinbox' as tblname,id,number,text,insertdate FROM multipartinbox WHERE processed = 0"); $id = array('inbox' => array(), 'multipartinbox' => array()); while ($r = mysql_fetch_object($q)) { logWrite(L_DEBUG, "[SMS] New SMS from {$r->number}: {$r->text}"); $number = preg_replace('/^(\\+|00)46/', '0', $r->number); if (preg_match(SMS::$number, $number) == 0) { if (isset($this->network[SMS::$unknownTarget[0]])) { $this->network[SMS::$unknownTarget[0]]->unknownMessage($r->number, $r->text); $id[$r->tblname][] = $r->id; } continue; } $user = $this->getUserByNumber($number); if (count($user) == 0) { if (isset($this->network[SMS::$unknownTarget[0]])) { $this->network[SMS::$unknownTarget[0]]->unknownMessage($r->number, $r->text); $id[$r->tblname][] = $r->id; } continue; } $ch = $r->text; $text = ''; if (strpos($r->text, ' ') !== false) { list($ch, $text) = explode(' ', $r->text, 2); } $fromNick = ''; $toNetwork = ''; $toChannel = ''; $msg = $r->text; foreach ($user as $u) { if (empty($fromNick)) { $fromNick = $u['nick']; $toChannel = $u['channel']; $toNetwork = $u['network']; } $matchChan = strtolower(ltrim($u['channel'], '#')); $matchWord = strtolower(ltrim($ch, '#')); if (strlen($matchWord) > 0 && substr($matchChan, 0, strlen($matchWord)) == $matchWord) { $fromNick = $u['nick']; $toChannel = $u['channel']; $toNetwork = $u['network']; $msg = $text; break; } } if (isset($this->network[strtolower($toNetwork)])) { if ($this->network[strtolower($toNetwork)]->newSms($fromNick, $toChannel, $msg)) { $this->insertHistory($fromNick, '', $toChannel, $toNetwork, $number, 0); } $id[$r->tblname][] = $r->id; } else { logWrite(L_DEBUG, "[SMS] New SMS for {$toNetwork}/{$toChannel}: Network not found"); } } foreach ($id as $table => $ids) { if (count($ids) > 0) { $this->query("UPDATE {$table} SET processed=1 WHERE id IN (" . implode(',', $ids) . ")"); } } Timer::add2('smsservice', 2, array($this, 'newSms')); }
/** * Outputs the specified file to the browser. * * @param string $filePath the path to the file to output * @param string $fileName the name of the file * @param string $mimeType the type of file */ function outputFile($filePath, $fileName, $mimeType = '') { logWrite('outputFile ' . $filePath . ', ' . $fileName . ', ' . $mimeType); // Setup $mimeTypes = array('txt' => 'text/plain', 'html' => 'text/html', 'htm' => 'text/html', 'zip' => 'application/zip', 'rar' => 'application/x-rar-compressed', 'exe' => 'application/x-msdownload', 'msi' => 'application/x-msdownload', 'cab' => 'application/vnd.ms-cab-compressed', 'pdf' => 'application/pdf', 'psd' => 'image/vnd.adobe.photoshop', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'rtf' => 'application/rtf', 'doc' => 'application/msword', 'docx' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.ms-excel', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ppt' => 'application/vnd.ms-powerpoint', 'pps' => 'application/vnd.ms-powerpoint', 'png' => 'image/png', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', 'mp3' => 'audio/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'swf' => 'application/x-shockwave-flash', 'flv' => 'video/x-flv'); $fileSize = filesize($filePath); $fileExt = strtolower(substr(strrchr($fileName, '.'), 1)); $fileName = rawurldecode($fileName); logWrite('file size=' . $fileSize); // Determine MIME Type if ($mimeType == '') { if (array_key_exists($fileExt, $mimeTypes)) { $mimeType = $mimeTypes[$fileExt]; } else { $mimeType = 'application/force-download'; } } logWrite('MIME=' . $mimeType); // Disable Output Buffering @ob_end_clean(); // IE Required if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } // Send Headers header('Content-Type: ' . $mimeType); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); // Send Headers: Prevent Caching of File header('Cache-Control: private'); header('Pragma: private'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); // Multipart-Download and Download Resuming Support if (isset($_SERVER['HTTP_RANGE'])) { list($a, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); list($range) = explode(',', $range, 2); list($range, $rangeEnd) = explode('-', $range); $range = intval($range); if (!$rangeEnd) { $rangeEnd = $fileSize - 1; } else { $rangeEnd = intval($rangeEnd); } $newLength = $rangeEnd - $range + 1; // Send Headers header('HTTP/1.1 206 Partial Content'); header('Content-Length: ' . $newLength); header('Content-Range: bytes ' . $range - $rangeEnd / $fileSize); } else { $newLength = $fileSize; header('Content-Length: ' . $fileSize); $range = 0; } // Output File $chunkSize = 1 * (1024 * 1024); $bytesSend = 0; logWrite('pos=' . $range); if ($file = fopen($filePath, 'r')) { logWrite('file opened'); if (isset($_SERVER['HTTP_RANGE'])) { if ($_SERVER['HTTP_RANGE']) { logWrite('file seek'); fseek($file, $range); } } while (!feof($file) && !connection_aborted() && $bytesSend < $newLength) { $buffer = fread($file, $chunkSize); echo $buffer; flush(); $bytesSend += strlen($buffer); } logWrite('sent=' . $bytesSend); fclose($file); logWrite('file closed'); } }
logWrite("Uploading chunk. Hash " . $hash . " (" . intval($_SERVER["HTTP_PORTION_FROM"]) . "-" . intval($_SERVER["HTTP_PORTION_FROM"] + $_SERVER["HTTP_PORTION_SIZE"]) . ", size: " . intval($_SERVER["HTTP_PORTION_SIZE"]) . ")"); $filename = $uploaddir . "/" . $hash . ".html5upload"; if (intval($_SERVER["HTTP_PORTION_FROM"]) == 0) { $fout = fopen($filename, "wb"); } else { $fout = fopen($filename, "ab"); } if (!$fout) { logWrite("Can't open file for writing: " . $filename); header("HTTP/1.0 500 Internal Server Error"); print "Can't open file for writing."; return; } $fin = fopen("php://input", "rb"); if ($fin) { while (!feof($fin)) { $data = fread($fin, 1024 * 1024); fwrite($fout, $data); } fclose($fin); } fclose($fout); } header("HTTP/1.0 200 OK"); print "ok\n"; } else { logWrite("Uploading chunk. Wrong hash " . $hash); header("HTTP/1.0 500 Internal Server Error"); print "Wrong session hash."; } closelog();