public function handle(Bot $bot) { if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!php ') { if (!Core::compareLevel($bot->lookUpUserID(), 'php.eval')) return $bot->denied(); Core::log()->php = $bot->message['usernameraw'].' used '.Module::removeWhisper($bot->message['text']); eval(substr(Module::removeWhisper($bot->message['text']), 5)); } }
public function loadEnabled() { $enPlugins = $this->_listPluginsFiles('enabled'); foreach ($enPlugins as $plugin) { $plugin = realpath($plugin); $info = $this->_getPluginInformation($plugin); $path = $this->_path . DS . 'enabled'; $filename = str_replace($path, "", $plugin); if ($info) { $sysname = $info['plugin_sysname']; if (!array_key_exists($sysname, $this->loadedPlugins)) { if (!empty($info['textdomain'])) { $relpath = 'enabled' . DS . trim(str_replace($path, '', dirname($plugin)), DS); if (!empty($info['domainpath'])) { $relpath .= DS . trim($info['domainpath'], '\\/'); } if (!load_plugin_textdomain($info['textdomain'], $relpath)) { Core::log('Failed to get localization data for plugin \'' . $filename . '\'.', YG_NOTICE); } } if (require_once $plugin) { $this->loadedPlugins[$sysname] = $plugin; } else { $this->log("Unable to require plugin file " . $filename, YG_NOTICE); } } else { $dpfilename = str_replace($path, "", $this->loadedPlugins[$sysname]); $this->log("Duplicated plugin sysname '" . $sysname . "' at file " . $filename . ", previously declared at " . $dpfilename . ". Ignoring this one.", YG_NOTICE); } } else { $this->log("Unable to load plugin file " . $filename . ". Failed to parse the meta-data.", YG_NOTICE); } } }
private function __construct() { self::init(); self::$log = new Log(); self::log()->info = 'Starting, PID is '.getmypid(); if (VERBOSE > 5) { self::log()->info = ' (__) '; self::log()->info = ' (oo) '; self::log()->info = ' /------\/ '; self::log()->info = ' / | || '; self::log()->info = ' * /\---/\ '; self::log()->info = ' ~~ ~~ '; self::log()->info = '...."Have you mooed today?"...'; } self::$config = new Config(); self::$permission = new Permission(); self::$language = new Language(LANGUAGE); if (VERBOSE > 0) self::log()->info = 'Loaded Config'; self::$bot = new Bot(); $modules = self::config()->config['modules']; // load default modules if (VERBOSE > 0) self::log()->info = 'Loading Modules'; foreach ($modules as $module) { self::loadModule($module); } self::bot()->work(); }
function load_query_template($type, $templates = array()) { $located = get_query_template($type, $templates); if (!empty($located)) { load_template($located); } else { Core::log('Unable to locate template part \'' . $type . '\'.'); } }
function get_footer() { $template = get_query_template('footer'); if (!empty($template)) { load_template($template, true); } else { Core::log('Footer file missing for theme', YG_WARNING); } }
public static function register($handle, $src, $deps = array(), $group) { if (!is_string($src) || !is_string($handle)) { return false; } if (!isset(self::$_scripts[$handle])) { self::$_scripts[$handle] = array($src, $deps, $group); } else { Core::log('Attempt to override a script identifier \'' . $handle . '\'.', YG_NOTICE); } }
public static function register($handle, $src, $deps = array(), $media = 'all', $extra = array()) { if (!is_string($src) || !is_string($handle)) { return false; } if (!isset(self::$_styles[$handle])) { self::$_styles[$handle] = array($src, $deps, $media, $extra); } else { Core::log('Attempt to override a style identifier \'' . $handle . '\'.', YG_NOTICE); } }
/** * Delete layout */ public function delete() { //! check input if (empty($this->id)) { throw new \Exception(L('No layout id')); } if (empty(Core::$user->id) || !Core::$user->has("siteadm")) { throw new \Exception(L('No user id')); } Core::log('A', sprintf("Layout %s deleted by %s", $this->id, Core::$user->name), "cmsaudit"); DS::exec("DELETE FROM " . static::$_table . " WHERE id=?", [$this->id]); DS::exec("DELETE FROM " . Page::$_table . "_list WHERE page_id IN (SELECT id FROM pages WHERE template=?)", [$this->id]); DS::exec("DELETE FROM " . Page::$_table . " WHERE template=?", [$this->id]); }
public function handle(Bot $bot) { if (substr($bot->message['text'], 0, 7) != 'apt-get') return; $text = explode(' ', substr($bot->message['text'], 8), 2); switch ($text[0]) { case 'moo': $bot->queue('...."Have you mooed today?"...'); break; case 'install': if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); if (stripos($text[1], '--reinstall') !== -1) { $text[1] = str_replace('--reinstall', '', $text[1]); Core::log()->info = $bot->message['usernameraw'].' reloaded a module'; $result = Core::reloadModule(trim($text[1])); } else { Core::log()->info = $bot->message['usernameraw'].' loaded a module'; $result = Core::loadModule(trim($text[1])); } if (!is_int($result)) { $bot->success(); } else { $name = 'module_error_'.$result; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->$name); } break; case 'remove': case 'purge': $text[1] = str_replace('--purge', '', $text[1]); if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' unloaded a module'; $result = Core::unloadModule(trim($text[1])); if (!is_int($result)) { $bot->success(); } else { $name = 'module_error_'.$result; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->$name); } break; case 'upgrade': if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); $modules = Core::getModules(); foreach ($modules as $module => $tmp) Core::reloadModule($module); break; } }
public function handle(Bot $bot) { if (Module::removeWhisper($bot->message['text']) == '!shutdown') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.shutdown')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' shutted the bot down'; $bot->shutdown(); } else if (Module::removeWhisper($bot->message['text']) == '!restart') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.shutdown')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' restarted the bot'; $bot->shutdown(SIGUSR1); } else if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!say ') { if (!Core::compareLevel($bot->lookUpUserID(), 500)) return $bot->denied(); $bot->queue(substr(Module::removeWhisper($bot->message['text']), 5)); } else if (Module::removeWhisper($bot->message['text']) == '!loaded') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_loaded.': '.implode(', ', array_keys(Core::getModules()))); } else if (substr(Module::removeWhisper($bot->message['text']), 0, 6) == '!join ') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.join')) return $bot->denied(); $bot->getConnection()->join(substr(Module::removeWhisper($bot->message['text']), 6)); $bot->success(); } else if (Module::removeWhisper($bot->message['text']) == '!perms') { if (!Core::compareLevel($bot->lookUpUserID(), 500)) return $bot->denied(); $perms = Core::permission()->getNodes(); ksort($perms); $permString = array(); foreach ($perms as $name => $level) { $permString[] = $name.': '.$level; } $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_perms.': '.implode(', ', $permString)); } else if (Module::removeWhisper($bot->message['text']) == '!rooms') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.join')) return $bot->denied(); $rooms = $bot->getConnection()->getRooms(); $roomString = array(); foreach ($rooms as $id => $name) { $roomString[] = $name.': '.$id; } $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_rooms.': '.implode(', ', $roomString)); } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->config->write(); if (substr($bot->message['text'], 0, 1) == '-') { if (isset($this->config->config[substr($bot->message['text'], 1)])) { $bot->queue($this->config->config[substr($bot->message['text'], 1)]); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!dic ') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.add')) { $data = explode(' ', substr(Module::removeWhisper($bot->message['text']), 5), 2); if (substr($data[1], 0, 1) == '!') return $bot->denied(); $this->config->config[$data[0]] = $data[1]; Core::log()->info = $bot->message['usernameraw'].' added '.$data[0].' to dictionary'; $bot->success(); } else { $bot->denied(); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 8) == '!deldic ') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.add')) { $data = substr(Module::removeWhisper($bot->message['text']), 8); unset($this->config->config[$data]); $bot->success(); } else { $bot->denied(); } } else if (Module::removeWhisper($bot->message['text']) == '!listdic') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.list')) { $entries = array_keys($this->config->config); sort($entries); $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->dic_listdic.': '.implode(', ', $entries)); } else { $bot->denied(); } } }
/** * 返回错误信息方法 * @author 景云山 * @version 2008-9-15 * @return void 无返回值 */ public static function error_handler($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_USER_ERROR: $logs .= date("Y-m-d H:i:s") . "<b>My ERROR</b> [{$errno}] {$errstr}<br />\n"; $logs .= " Fatal error on line {$errline} in file {$errfile}"; $logs .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; $logs .= "Aborting...<br />\n"; break; case E_USER_WARNING: $logs .= date("Y-m-d H:i:s") . "<b>My WARNING</b> [{$errno}] {$errstr}<br />\n"; break; case E_USER_NOTICE: $logs .= date("Y-m-d H:i:s") . "<b>My NOTICE</b> [{$errno}] {$errstr}<br />\n"; break; } if ($logs) { Core::log($logs, "error/logs"); } /* Don't execute PHP internal error handler */ return true; }
public static function set($keys, $value = false, $id = null) { if (is_array($keys) && $value !== false) { return false; } if (!is_array($keys)) { $data = array(); $data[$keys] = $value; } else { $data = $keys; } if (count($data) == 0) { return false; } if (empty($id)) { $id = Session::get('uid'); } $setData = ''; $psvals = array(); foreach ($data as $key => $val) { if (!empty($setData)) { $setData .= ', '; } $setData .= $key . ' = ?'; $psvals[] = $val; } $psvals[] = $id; $query = DB::prepared('UPDATE users SET ' . $setData . ' WHERE id = ?', $psvals); if ($query) { foreach ($data as $key => $val) { self::$keys[$id][$key] = $val; } return true; } else { Core::log('Failed to get user information.', YG_NOTICE); return false; } }
/** * Set configuration for an extension from $_POST * * @param Extension directory */ function setConf($dir) { if (empty($dir) || empty($_POST)) { return "PHPPE-E: " . L("Bad arguments"); } //! check rights if (!Core::$user->has("install")) { Core::log('A', "Suspicious behavior " . $url . " " . $this->getsiteurl(), "extensions"); return "PHPPE-E: " . L("Access denied"); } //! construct new configuration file $conf = "<" . "?p" . "hp\nreturn [\n"; foreach ($_POST as $k => $v) { $conf .= "\t\"" . addslashes($k) . "\" => " . $this->formatvalue($v) . ",\n"; } $conf .= "];\n"; try { //! save new config.php $r = Tools::ssh("cat \\>" . escapeshellarg(Core::$user->data['remote']['path'] . "/vendor/" . $dir . "/config.php"), $conf); } catch (\Exception $e) { return "PHPPE-E: " . $e->getMessage(); } //! check results if (self::isErr($r)) { Core::log('E', "Failed to set configuration for " . $dir . " " . $this->getSiteUrl() . ", " . str_replace("\n", " ", $r), "extensions"); return "PHPPE-E: " . L("Failed set configuration!") . "\n\n" . str_replace("\n", " ", $r); } else { die(L("Configuration saved.") . "\n" . $r); } }
static function cleanUp($pages = null) { //! check input if (!empty(Core::lib("CMS")->revert)) { return; } if (empty(Core::$user->id) || !Core::$user->has("siteadm|pubadm")) { throw new \Exception(L('No user id')); } if (empty($pages)) { $pages = self::getPages(); } //! write audit log Core::log('A', sprintf("Purge page history by %s", Core::$user->name), "cmsaudit"); //! purge old records foreach ($pages as $p) { if ($p['versions'] > 1) { DS::exec("DELETE FROM " . static::$_table . " WHERE id=? AND (lang='' OR lang=?) AND created!=?", [$p['id'], $p['lang'], $p['created']]); } } //! make it published (without history that feature is off) DS::exec("UPDATE " . static::$_table . " SET publishid=? WHERE publishid=0", [Core::$user->id]); }
public function __construct($languageCode) { if (!$this->load($languageCode)) { Core::log()->error = 'Could not find language '.$languageCode; exit; } }
/** * 内部调用合并文件 * */ public function action_join() { # 目录 $dir = $this->arguments[0]; if (!isset(File::$dir[$dir])) { # 目录不允许操作 $this->show_error('目录不允许操作'); } if (!$this->arguments[1]) { $this->show_error('缺少参数'); } # 文件 $filename = File::$dir[$dir] . $this->arguments[1]; if (File::join($filename)) { $this->show_success(); } else { # 记录错误日志 Core::log('system.error.file.join', array('file' => $filename), LOG_ERR); $this->show_error('执行失败'); } }
/** * 记录慢查询 * * @return boolean */ protected static function save_slow_query() { if (!Database::$slow_querys) { return true; } // 记录URL信息 $data = "\n" . str_pad(HttpIO::METHOD, 4, ' ') . ' ' . date('H:i:s', TIME) . ' - ' . str_pad((int) (1000 * (microtime(1) - START_TIME)), 6, ' ', STR_PAD_LEFT) . ' - ' . str_pad(HttpIO::IP, 15) . ' ' . $_SERVER["SCRIPT_URI"] . ('' !== $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '') . (HttpIO::METHOD == 'POST' ? ' POST:' . json_encode(HttpIO::POST()) : '') . "\n"; foreach (Database::$slow_querys as $item) { $data .= ' ' . date('H:i:s', $item[0]) . ' - ' . str_pad((int) $item[1], 6, ' ', STR_PAD_LEFT) . ' - ' . $item[2] . "\n"; } // 写入LOG Core::log($data, 'log', 'slow_query/' . date('Y/m_d', TIME)); }
public function questionEnd() { Core::log()->quiz = 'Times over'; Core::log()->quiz = 'Answers by: '.implode(', ', $this->questionAnswers); $this->bot->queue('Die Zeit ist um'); $this->bot->queue('Es gab Antworten von '.implode(', ', $this->questionAnswers)); $this->questionAnswers = array(); }
public function handle(Bot $bot) { Core::log()->message = $bot->message['usernameraw'].': '.$bot->message['text']; }
/** * Load a language file * * This method loads a language file that has been properly formatted for * translation. * * @access public * @param string $path lang file being loaded */ static function load_language($path) { if (isset(self::$loaded_language_files[$path])) { return; } /* * We'll keep track of the loaded langs so we don't keep loading the * same ones twice or overriding langs with the original that were meant * to be the overrides anyway. */ if (!isset(self::$language[$path])) { if (file_exists($path)) { $langcontents = file_get_contents($path); $matches = []; if ($this->tripwire && !preg_match('/^\\:([A-Z0-9\\_]+)\\=/', $langcontents)) { Core::err(['LOAD_LANG_PARSE_ERROR', $path]); } preg_match_all('/\\:([A-Z0-9\\_]+)\\=/', $langcontents, $matches); $matches = $matches[1]; $contents = preg_split('/\\:([A-Z0-9\\_]+)\\=/', $langcontents); array_shift($contents); $lang = []; for ($i = 0; $i < count($matches); ++$i) { $lang[$matches[$i]] = $contents[$i]; } Core::$lang = $lang; /* * Capture the file location for reference. */ self::$language[$path] = 1; self::$loaded_language_files[$path] = 1; if (!self::$env) { Core::log(['LOADING_LANG', $path]); } return true; } } return false; }
/** * 内部调用合并文件 * */ public function action_join() { # 目录 $dir = $this->arguments[0]; if (!isset(\File::$dir[$dir])) { # 目录不允许操作 static::show_error('目录不允许操作'); } if (!$this->arguments[1]) { static::show_error('缺少参数'); } # 文件 $filename = \File::$dir[$dir] . $this->arguments[1]; if (\File::join($filename)) { static::show_message('success', null, 1); } else { # 记录错误日志 \Core::log('join file(' . $filename . ') error.', 'error'); static::show_error('执行失败'); } }
/** * 检查内部调用HASH是否有效 * * @return boolean */ protected static function check_system_request_allow() { $hash = $_SERVER['HTTP_X_MYQEE_SYSTEM_HASH']; // 请求验证HASH $time = $_SERVER['HTTP_X_MYQEE_SYSTEM_TIME']; // 请求验证时间 $rstr = $_SERVER['HTTP_X_MYQEE_SYSTEM_RSTR']; // 请求随机字符串 $project = $_SERVER['HTTP_X_MYQEE_SYSTEM_PROJECT']; // 请求的项目 $path_info = $_SERVER['HTTP_X_MYQEE_SYSTEM_PATHINFO']; // 请求的path_info $isadmin = $_SERVER['HTTP_X_MYQEE_SYSTEM_ISADMIN']; // 是否ADMIN $isrest = $_SERVER['HTTP_X_MYQEE_SYSTEM_ISREST']; // 是否RESTFul请求 if (!$hash || !$time || !$rstr || !$project || !$path_info) { return false; } // 请求时效检查 if (microtime(1) - $time > 600) { Core::log('system.error.request.timeout', array('msg' => 'system request timeout', 'time1' => microtime(1), 'time0' => $time), LOG_WARNING); return false; } // 验证IP if ('127.0.0.1' !== HttpIO::IP && HttpIO::IP !== $_SERVER["SERVER_ADDR"]) { $allow_ip = Core::config('system_exec_allow_ip'); if (is_array($allow_ip) && $allow_ip) { $allow = false; foreach ($allow_ip as $ip) { if (HttpIO::IP === $ip) { $allow = true; break; } if (strpos($allow_ip, '*')) { // 对IP进行匹配 if (preg_match('#^' . str_replace('\\*', '[^\\.]+', preg_quote($allow_ip, '#')) . '$#', HttpIO::IP)) { $allow = true; break; } } } if (!$allow) { Core::log('system.error.request.ip', array('ip' => HttpIO::IP), LOG_WARNING); return false; } } } $body = http_build_query(HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA)); // 系统调用密钥 $system_exec_pass = Core::config('system_exec_key'); $key = Core::config()->get('system_exec_key', 'system', true); if (!$key || abs(TIME - $key['time']) > 86400 * 10) { return false; } $other = $path_info . '_' . ($isadmin ? 1 : 0) . '_' . ($isrest ? 1 : 0) . $key['str']; if ($system_exec_pass && strlen($system_exec_pass) >= 10) { // 如果有则使用系统调用密钥 $new_hash = sha1($body . $time . $system_exec_pass . $rstr . '_' . $other); } else { // 没有,则用系统配置和数据库加密 $new_hash = sha1($body . $time . serialize(Core::config('core')) . serialize(Core::config('database')) . $rstr . '_' . $other); } if ($new_hash == $hash) { return true; } else { Core::log('system.error.request.hash', array('hash' => $hash), LOG_WARNING); return false; } }
public static function ssh($cmd, $input = "", $precmd = "") { if (empty(Core::$user->data['remote']['identity']) || empty(Core::$user->data['remote']['user']) || empty(Core::$user->data['remote']['host']) || empty(Core::$user->data['remote']['path'])) { throw new \Exception(L('configure remote access')); } $idfile = tempnam('.tmp', '.id_'); file_put_contents($idfile, trim(Core::$user->data['remote']['identity']) . "\n", LOCK_EX); chmod($idfile, 0400); if ($cmd == "rsync") { $ssh = "rsync -an -e \\'ssh -i " . escapeshellarg($idfile) . "\\' --include-from=/dev/stdin " . escapeshellarg(Core::$user->data['remote']['user'] . "@" . Core::$user->data['remote']['host'] . ":" . $precmd); } else { $ssh = ($precmd ? $precmd . "|" : "") . "ssh -i " . escapeshellarg($idfile) . " -l " . escapeshellarg(Core::$user->data['remote']['user']) . (!empty(Core::$user->data['remote']['port']) && Core::$user->data['remote']['port'] > 0 ? " -p " . intval(Core::$user->data['remote']['port']) : "") . " " . escapeshellarg(Core::$user->data['remote']['host']) . " sh -c \\\" " . $cmd . " \\\" 2>&1"; } Core::log('A', $ssh, "remote"); $d = [0 => ["pipe", "r"], 1 => ["pipe", "w"]]; $pr = proc_open($ssh, $d, $p); if ($pr !== false && is_array($p)) { if (!empty($input)) { fwrite($p[0], is_array($input) ? implode("\n", $input) : $input); } fclose($p[0]); $r = trim(stream_get_contents($p[1])); fclose($p[1]); proc_close($pr); } else { $r = "ssh: unable to execute"; } unlink($idfile); return $r; }
/** * 记录慢查询 * * @return boolean */ protected static function save_slow_query() { if (!Database::$slow_querys) { return true; } $queries = array(); foreach (Database::$slow_querys as $item) { $queries[] = array('from' => $item[0], 'to' => $item[1], 'use' => $item[1] - $item[0], 'sql' => $item[2]); } $data = array('url' => $_SERVER["SCRIPT_URI"] . ('' !== $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : ''), 'method' => HttpIO::METHOD, 'time' => TIME, 'ip' => HttpIO::IP, 'page_time' => microtime(1) - START_TIME, 'post' => HttpIO::POST(), 'queries' => $queries); // 写入LOG return Core::log('database.slow_query', $data, LOG_WARNING); }
/** * 内部调用合并文件 * */ public function action_join() { # 目录 $dir = $this->arguments[0]; if (!isset(File::$dir[$dir])) { # 目录不允许操作 $this->show_error('目录不允许操作'); } if (!$this->arguments[1]) { $this->show_error('缺少参数'); } # 文件 $filename = File::$dir[$dir] . $this->arguments[1]; if (File::join($filename)) { $this->show_success(); } else { # 记录错误日志 Core::log('join file(' . $filename . ') error.', 'error'); $this->show_error('执行失败'); } }
/** * Cron job to read mails from queue and send them out */ public function cronMinute($item) { //! get real mailer backend ($core->mailer points to db queue backend) // @codeCoverageIgnoreStart if (empty(Core::$core->realmailer)) { Core::log('C', L('Real mailer backend not configured!')); } // @codeCoverageIgnoreEnd //! get items from database $lastId = 0; while ($row = DS::fetch('*', 'email_queue', 'id>?', '', 'id ASC', [$lastId])) { $email = new self($row['data']); $lastId = $row['id']; try { if (!$email->send(Core::$core->realmailer)) { // @codeCoverageIgnoreStart throw new \Exception('send() returned false'); } DS::exec('DELETE FROM email_queue WHERE id=?;', [$row['id']]); } catch (\Exception $e) { Core::log('E', sprintf(L('Unable to send #%s from queue'), $row['id']) . ': ' . $e->getMessage()); } // @codeCoverageIgnoreEnd sleep(1); } }
/** * 检查内部调用HASH是否有效 * * @return boolean */ protected static function check_system_request_allow() { $hash = $_SERVER['HTTP_X_MYQEE_SYSTEM_HASH']; // 请求验证HASH $time = $_SERVER['HTTP_X_MYQEE_SYSTEM_TIME']; // 请求验证时间 $rstr = $_SERVER['HTTP_X_MYQEE_SYSTEM_RSTR']; // 请求随机字符串 if (!$hash || !$time || !$rstr) { return false; } // 请求时效检查 if (microtime(1) - $time > 600) { Core::log('system request timeout', 'system-request'); return false; } // 验证IP if ('127.0.0.1' != HttpIO::IP && HttpIO::IP != $_SERVER["SERVER_ADDR"]) { $allow_ip = Core::config('core.system_exec_allow_ip'); if (is_array($allow_ip) && $allow_ip) { $allow = false; foreach ($allow_ip as $ip) { if (HttpIO::IP == $ip) { $allow = true; break; } if (strpos($allow_ip, '*')) { // 对IP进行匹配 if (preg_match('#^' . str_replace('\\*', '[^\\.]+', preg_quote($allow_ip, '#')) . '$#', HttpIO::IP)) { $allow = true; break; } } } if (!$allow) { Core::log('system request not allow ip:' . HttpIO::IP, 'system-request'); return false; } } } $body = http_build_query(HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA)); // 系统调用密钥 $system_exec_pass = Core::config('core.system_exec_key'); if ($system_exec_pass && strlen($system_exec_pass) >= 10) { // 如果有则使用系统调用密钥 $newhash = sha1($body . $time . $system_exec_pass . $rstr); } else { // 没有,则用系统配置和数据库加密 $newhash = sha1($body . $time . serialize(Core::config('core')) . serialize(Core::config('database')) . $rstr); } if ($newhash == $hash) { return true; } else { Core::log('system request hash error', 'system-request'); return false; } }
public function __call($methodName, $args = null) { Core::log($this->ClassName, $methodName); if ($args !== null) { /** @noinspection PhpParamsInspection */ return call_user_func_array(array($this->Instance, $methodName), $args); } else { return $this->Instance->{$methodName}(); } }
/** * @description gotoError( $msg ) 返回错误信息,并跳转到错误页面 * @author 景云山 * @version 2008-10-10 * @param string $msg 消息内容 * @return void */ private static function gotoError($msg) { $format = Core::get('format'); ob_end_clean(); if ($msg) { if (self::$_jump) { Core::jump($msg, '', 2); } else { $data = array('msg' => $msg, 'status' => 0); $json = json_encode($data); if ($format == 'xml') { $json = Core::json_to_xml($json); } print $json; Core::log($msg, "error/logs"); exit; } } else { $msg = '数据类型错误,请检查'; if (self::$_jump) { Core::jump($msg, '', 2); } else { $data = array('msg' => $msg, 'status' => 0); $json = json_encode($data); if ($format == 'xml') { $json = Core::json_to_xml($json); } print $json; Core::log($msg, "error/logs"); exit; } } }