/** * Log error */ function log_error() { if (!SQL_LOG_ERRORS) { return; } $msg = array(); $err = $this->sql_error(); $msg[] = str_compact(sprintf('#%06d %s', $err['code'], $err['message'])); $msg[] = ''; $msg[] = str_compact($this->cur_query); $msg[] = ''; $msg[] = 'Source : ' . $this->debug_find_source() . " :: {$this->db_server}.{$this->selected_db}"; $msg[] = 'IP : ' . @$_SERVER['REMOTE_ADDR']; $msg[] = 'Date : ' . date('Y-m-d H:i:s'); $msg[] = 'Agent : ' . @$_SERVER['HTTP_USER_AGENT']; $msg[] = 'Req_URI : ' . @$_SERVER['REQUEST_URI']; $msg[] = 'Referer : ' . @$_SERVER['HTTP_REFERER']; $msg[] = 'Method : ' . @$_SERVER['REQUEST_METHOD']; $msg[] = 'PID : ' . sprintf('%05d', getmypid()); $msg[] = 'Request : ' . trim(print_r($_REQUEST, true)) . str_repeat('_', 78) . LOG_LF; $msg[] = ''; bb_log($msg, 'sql_error_bb'); }
if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) { // Update cron_last_check bb_update_config(array('cron_last_check' => TIMENOW + 10)); define('CRON_LOG_ENABLED', true); // global ON/OFF define('CRON_FORCE_LOG', false); // always log regardless of job settings define('CRON_DIR', INC_DIR . 'cron/'); define('CRON_JOB_DIR', CRON_DIR . 'jobs/'); define('CRON_LOG_DIR', 'cron/'); // inside LOG_DIR define('CRON_LOG_FILE', 'cron'); // without ext bb_log(date('H:i:s - ') . getmypid() . ' -x-- DB-LOCK try' . LOG_LF, CRON_LOG_DIR . 'cron_check'); if (DB()->get_lock('cron', 1)) { bb_log(date('H:i:s - ') . getmypid() . ' --x- DB-LOCK OBTAINED !!!!!!!!!!!!!!!!!' . LOG_LF, CRON_LOG_DIR . 'cron_check'); sleep(2); require CRON_DIR . 'cron_init.php'; DB()->release_lock('cron'); } } } $dl_link_css = array(DL_STATUS_RELEASER => 'genmed', DL_STATUS_WILL => 'dlWill', DL_STATUS_DOWN => 'leechmed', DL_STATUS_COMPLETE => 'seedmed', DL_STATUS_CANCEL => 'dlCancel'); $dl_status_css = array(DL_STATUS_RELEASER => 'genmed', DL_STATUS_WILL => 'dlWill', DL_STATUS_DOWN => 'dlDown', DL_STATUS_COMPLETE => 'dlComplete', DL_STATUS_CANCEL => 'dlCancel'); // Exit if board is disabled via ON/OFF trigger or by admin if (($bb_cfg['board_disable'] || file_exists(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) { header('HTTP/1.0 503 Service Unavailable'); if ($bb_cfg['board_disable']) { // admin lock send_no_cache_headers(); bb_die('BOARD_DISABLE');
<?php if (!defined('BB_ROOT')) { die(basename(__FILE__)); } bb_log(date('H:i:s - ') . getmypid() . ' --x- SELECT jobs' . LOG_LF, CRON_LOG_DIR . 'cron_check'); // Get cron jobs $cron_jobs = DB()->fetch_rowset("\n\tSELECT * FROM " . BB_CRON . "\n\tWHERE cron_active = 1\n\t\tAND next_run <= NOW()\n\tORDER BY run_order\n"); // Run cron jobs if ($cron_jobs) { bb_log(date('H:i:s - ') . getmypid() . ' --x- RUN jobs' . LOG_LF, CRON_LOG_DIR . 'cron_check'); foreach ($cron_jobs as $job) { if ($job['disable_board']) { cron_disable_board(); sleep(10); break; } } require CRON_DIR . 'cron_run.php'; // Update cron_last_check bb_update_config(array('cron_last_check' => TIMENOW + 10)); } else { bb_log(date('H:i:s - ') . getmypid() . ' --x- no active jobs found ----------------------------------------------' . LOG_LF, CRON_LOG_DIR . 'cron_check'); }
function log_request($file = '', $prepend_str = false, $add_post = true) { global $user; $file = $file ? $file : 'req/' . date('m-d'); $str = array(); $str[] = date('m-d H:i:s'); if ($prepend_str !== false) { $str[] = $prepend_str; } if (!empty($user->data)) { $str[] = $user->id . "\t" . html_entity_decode($user->name); } $str[] = sprintf('%-15s', $_SERVER['REMOTE_ADDR']); if (isset($_SERVER['REQUEST_URI'])) { $str[] = $_SERVER['REQUEST_URI']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $str[] = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_REFERER'])) { $str[] = $_SERVER['HTTP_REFERER']; } if (!empty($_POST) && $add_post) { $str[] = "post: " . str_compact(urldecode(http_build_query($_POST))); } $str = join("\t", $str) . "\n"; bb_log($str, $file); }
} elseif (!file_exists(CRON_ALLOWED) && !file_exists(CRON_RUNNING)) { file_write('', CRON_ALLOWED); $lock_obtained = @rename(CRON_ALLOWED, CRON_RUNNING); } return $lock_obtained; } function cron_track_running($mode) { @define('CRON_STARTMARK', TRIGGERS_DIR . 'cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid()); if ($mode == 'start') { cron_touch_lock_file(CRON_RUNNING); file_write('', CRON_STARTMARK); } elseif ($mode == 'end') { @unlink(CRON_STARTMARK); } } // // Run cron // if (cron_get_file_lock()) { ignore_user_abort(true); register_shutdown_function('cron_release_file_lock'); register_shutdown_function('cron_enable_board'); # bb_log(date('H:i:s - ') . getmypid() .' --x- FILE-LOCK OBTAINED ###############'. LOG_LF, CRON_LOG_DIR .'cron_check'); cron_track_running('start'); require CRON_DIR . 'cron_check.php'; cron_track_running('end'); } if (defined('IN_CRON')) { bb_log(date('H:i:s - ') . getmypid() . ' --x- ALL jobs FINISHED *************************************************' . LOG_LF, CRON_LOG_DIR . 'cron_check'); }
function log_sphinx_error($err_type, $err_msg, $query = '') { $ignore_err_txt = array('negation on top level', 'Query word length is less than min prefix length'); if (!count($ignore_err_txt) || !preg_match('#' . join('|', $ignore_err_txt) . '#i', $err_msg)) { $orig_query = strtr($_REQUEST['nm'], array("\n" => '\\n')); bb_log(date('m-d H:i:s') . " | {$err_type} | {$err_msg} | {$orig_query} | {$query}" . LOG_LF, 'sphinx_error'); } }
if ($job['log_sql_queries']) { DB()->log_next_query(0); bb_log(LOG_LF, $cron_sql_log_file); } if ($cron_write_log) { $msg = array(); $msg[] = ' end'; $msg[] = date('m-d'); $msg[] = date('H:i:s'); $msg[] = sprintf('%-4s', round(sys('la'), 1)); $msg[] = sprintf('%05d', getmypid()); $msg[] = round(utime() - $cron_start_time) . '/' . round(utime() - TIMESTART) . ' sec'; $msg = join(LOG_SEPR, $msg); $msg .= LOG_LF . '------=-------=----------=------=-------=----------'; bb_log($msg . LOG_LF, CRON_LOG_DIR . CRON_LOG_FILE); if ($cron_runtime_log) { $runtime_log_file = $job['log_file'] ? $job['log_file'] : $job['cron_script']; bb_log($cron_runtime_log . LOG_LF, CRON_LOG_DIR . basename($runtime_log_file)); } } DB()->query("\n\t\t\tUPDATE " . BB_CRON . " SET\n\t\t\t\tlast_run = NOW(),\n\t\t\t\trun_counter = run_counter + 1,\n\t\t\t\tnext_run =\n\t\t\tCASE\n\t\t\t\tWHEN schedule = 'hourly' THEN\n\t\t\t\t\tDATE_ADD(NOW(), INTERVAL 1 HOUR)\n\t\t\t\tWHEN schedule = 'daily' THEN\n\t\t\t\t\tDATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL TIME_TO_SEC(run_time) SECOND)\n\t\t\t\tWHEN schedule = 'weekly' THEN\n\t\t\t\t\tDATE_ADD(\n\t\t\t\t\t\tDATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(NOW()) DAY), INTERVAL 7 DAY),\n\t\t\t\t\tINTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)\n\t\t\t\tWHEN schedule = 'monthly' THEN\n\t\t\t\t\tDATE_ADD(\n\t\t\t\t\t\tDATE_ADD(DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(NOW())-1 DAY), INTERVAL 1 MONTH),\n\t\t\t\t\tINTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)\n\t\t\t\tELSE\n\t\t\t\t\tDATE_ADD(NOW(), INTERVAL TIME_TO_SEC(run_interval) SECOND)\n\t\t\tEND\n\t\t\tWHERE cron_id = {$job['cron_id']}\n\t\t\tLIMIT 1\n\t\t"); sleep(1); if (utime() - TIMESTART > 600) { return; // чтобы daily скрипты не блокировали надолго interval'ные } } else { $cron_err_msg = "Can not run \"{$job['cron_title']}\" : file \"{$job_script}\" not found" . LOG_LF; bb_log($cron_err_msg, 'cron_error'); } }