public static function debug($message) { echo $message . PHP_EOL; GWF_Log::rawLog('dog/debug', $message); GWF_Log::flush(); return true; }
private function templateError() { $module = $this->module; $module instanceof Module_GWF; $codes = $module->lang('ERR_HTTP'); # Get the error page $code = Common::getGetString('code', '0'); if (false === isset($codes[$code])) { return GWF_HTML::err('ERR_NO_PERMISSION'); } @header($_SERVER['SERVER_PROTOCOL'] . ' ' . $code . ' ' . $codes[$code]); # Generate template $tVars = array('code' => $code, 'file' => GWF_HTML::error(GWF_SITENAME, $module->getLang()->langA('ERR_HTTP', $code, array(htmlspecialchars($_SERVER['REQUEST_URI']))), false)); $template = $module->template($this->_tpl, $tVars); # Is the request blacklisted? foreach (preg_split('/[,;]/', $module->cfgBlacklist()) as $pattern) { if (false !== strpos($_SERVER['REQUEST_URI'], $pattern)) { # Do not log and email the request return $template; } } $message = self::getMessage($code); # Mail it? if (1 === preg_match("/(?:^|[,;]){$code}(?:\$|[,;])/", $module->cfgMail())) { self::errorMail($code, $message); } # Log it? if (1 === preg_match("/(?:^|[,;]){$code}(?:\$|[,;])/", $module->cfgLog())) { GWF_Log::logHTTP($message); } return $template; }
/** * Return a public key in hex format or false. * @param string $key */ public static function grabFingerprint($file_content) { $gpg = gnupg_init(); if (false === ($result = gnupg_import($gpg, $file_content))) { GWF_Log::logCritical('gnupg_import() failed'); GWF_Log::logCritical(GWF_HTML::lang('ERR_GENERAL', __FILE__, __LINE__)); return false; } if ($result['imported'] + $result['unchanged'] === 0) { return false; } return $result['fingerprint']; }
public function queryRead($query) { $t = microtime(true); if (false === ($result = mysql_query($query, $this->link))) { $this->error($query, mysql_errno($this->link), mysql_error($this->link)); return false; } $time = microtime(true) - $t; $this->query_time += $time; $this->query_count++; $this->queries_opened++; if (GDO_Database::DEBUG) { GWF_Log::rawLog(self::DEBUG_PATH, sprintf('Q#%03d(%.03fs): %s', $this->query_count, $time, $query)); } return $result; }
/** * HTA Writer. * @param string $dir * @param string $content */ private static function protectB($dir, $content) { $dir = rtrim($dir, '\\/'); $path = $dir . '/.htaccess'; if (!is_dir($dir)) { GWF_Log::logCritical(sprintf('Supported arg is not a dir in %s.', __METHOD__)); return false; } if (!is_writable($dir)) { GWF_Log::logCritical(sprintf('Cannot write to directory %s in %s.', $dir, __METHOD__)); return false; } if (false === file_put_contents($path, $content)) { GWF_Log::logCritical(sprintf('Cannot write to file %s in %s.', $path, __METHOD__)); return false; } return true; }
private function ipn(Module_PaymentAlertpay $module) { if (Common::getPost("ap_securitycode") !== $module->cfgSecCode()) { GWF_Log::log('alertpay', 'Invalid alertpay security code'); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (false === ($email = Common::getPost("ap_custemailaddress"))) { GWF_Log::log('alertpay', 'Missing ap_custemailaddress'); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (Common::getPost("ap_status") !== "Success") { GWF_Log::log('alertpay', 'Alertpay post was not success'); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (false === ($token = Common::getPost("ap_itemcode"))) { GWF_Log::log('alertpay', 'Missing ap_itemcode'); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (false === ($order = GWF_Order::getByToken($token))) { GWF_Log::log('alertpay', 'Order not found or token invalid: ' . $token); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (!$order->isCreated()) { return $module->error('err_order'); } if (false === ($price = (double) Common::getPost('ap_amount'))) { GWF_Log::log('alertpay', 'MISSING ap_amount for ' . $token); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if ($price !== (double) $order->getOrderPriceTotal()) { GWF_Log::log('alertpay', 'The price for the orders is not the same: ' . $token); return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } $order->saveVar('order_email', $email); $module2 = $order->getOrderModule(); $module2->onLoadLanguage(); return Module_Payment::onExecuteOrderS($module2, $order); }
/** * Create new Voting table. Name is an identifier for yourself, for example module links has all voting table named as link_%d. An expire time of 0 means no expire * @param string $name * @param int $min * @param int $max * @param int $expire_time * @param int $options * @return GWF_VoteScore */ public static function newVoteScore($name, $min, $max, $expire_time, $options) { # Valid expire time. if (!is_int($expire_time)) { $expire_time = 0; } else { $expire_time = $expire_time > 0 ? $expire_time + time() : 0; } $min = (int) $min; $max = (int) $max; if ($max === $min) { GWF_Log::logCritical('NOTHING TO VOTE! (MIN==MAX==' . $min . ')'); return false; } if (false !== ($vs = self::getByName($name))) { if (false === $vs->resetVotes($min, $max, $expire_time, $options)) { return false; } return $vs; } return new self(array('vs_name' => $name, 'vs_date' => GWF_Time::getDate(self::DATE_LEN), 'vs_expire_date' => $expire_time === 0 ? '' : GWF_Time::getDate(self::DATE_LEN, $expire_time), 'vs_options' => $options, 'vs_min' => $min, 'vs_max' => $max, 'vs_avg' => ($max + $min) / 2, 'vs_count' => 0, 'vs_sum' => 0)); }
private static function sendSubscriptionB(Module_Forum $module, GWF_ForumThread $thread, GWF_User $user, $postername, $msg_block, $msg_count, $boardText, $threadTitle, $sender) { $userid = $user->getID(); $username = $user->displayUsername(); if (false === ($receiver = $user->getValidMail())) { GWF_Log::logCron('[ERROR] User ' . $username . ' has no valid email.'); return false; } if (false === ($options = GWF_ForumOptions::getUserOptions($user))) { GWF_Log::logCron('[ERROR] User ' . $username . ' has no valid forum options.'); } $token = $options->getVar('fopt_token'); $href = Common::getAbsoluteURL($thread->getLastPageHREF(false), false); $showLink = GWF_HTML::anchor($href, $href); $href = Common::getAbsoluteURL($thread->getExternalUnSubscribeHREF($userid, $token, true), false); $unsubLink = GWF_HTML::anchor($href, $href); $href = Common::getAbsoluteURL($thread->getExternalUnSubscribeAllHREF($userid, $token, true), false); $unsubLinkAll = GWF_HTML::anchor($href, $href); $mail = new GWF_Mail(); $mail->setSender($sender); $mail->setReceiver($receiver); $mail->setSubject($module->langUser($user, 'submail_subj', array($threadTitle, $postername, $boardText))); $mail->setBody($module->langUser($user, 'submail_body', array($username, $msg_count, $boardText, $threadTitle, $msg_block, $showLink, $unsubLink, $unsubLinkAll))); if (false === $mail->sendToUser($user)) { GWF_Log::logCron('[ERROR] Can not send mail to ' . $username . '; EMail: ' . $receiver); } else { GWF_Log::logCron('[+] Successfully sent Email to ' . $username . '; EMail: ' . $receiver); } }
public static function messageA($title = NULL, array $messages, $log = true) { if (count($messages) === 0) { return ''; } if ($log === true) { GWF_Log::logMessage(self::decode(implode(PHP_EOL, $messages))); } return self::displayMessages(array('title' => $title, 'messages' => $messages)); }
public static function _proc_err($message) { GWF_Log::logError($message); }
private static function initRealNPCs() { foreach (self::$cities as $city) { $city instanceof SR_City; foreach ($city->getLocations() as $location) { $location instanceof SR_Location; foreach ($location->getRealNPCS() as $classname) { if (false === ($npc = SR_Player::getRealNPCByName($classname))) { GWF_Log::logCritical('Cannot create real npc with classname: ' . $classname); } $party = $npc->getParty(false); if (!$party->isAtLocation() && !$party->isMoving()) { $party->saveVars(array('sr4pa_action' => SR_Party::ACTION_INSIDE, 'sr4pa_target' => $location->getName(), 'sr4pa_eta' => 0, 'sr4pa_last_action' => SR_Party::ACTION_OUTSIDE, 'sr4pa_last_target' => $location->getName(), 'sr4pa_last_eta' => 0)); } $npc = $party->getLeader(); self::addPlayer($npc); self::addParty($party); $party->setTimestamp(time() + GWF_Time::ONE_MONTH); } } } }
public static function exception_handler($e) { try { $mail = self::$MAIL_ON_ERROR; $log = true; if ($e instanceof GWF_Exception) { $mail = $mail && GWF_Exception::MAIL !== $e->getCode(); $log = $log && GWF_Exception::LOG !== $e->getCode(); } # TODO: formatting for log, email, html # Send error to admin? if ($mail) { self::sendDebugMail($e->getMessage() . PHP_EOL . $e->getTrace(), false); } # Log it? if ($log) { GWF_Log::logCritical($e->getMessage()); } } catch (Exception $null) { unset($null); } # TODO: die / return ? }
define('GWF_CONFIG_PATH', realpath(GWF_PATH . 'www/protected/config.php')); #TODO } # Is there a config file? if (false === file_exists(GWF_CONFIG_PATH)) { $write_a_config = true; define('GWF_HAVE_CONFIG', true); } else { GWF3::onLoadConfig(GWF_CONFIG_PATH); } require_once GWF_CORE_PATH . 'inc/install/GWF_InstallWizard.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallFunctions.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallConfig.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallWizardLanguage.php'; GWF_InstallWizardLanguage::init(); GWF_Log::init(false, true, GWF_PATH . '/protected/installlog'); $lang = new GWF_LangTrans(GWF_CORE_PATH . 'lang/install/install'); if (isset($write_a_config)) { GWF_InstallConfig::writeConfig($lang); echo 'I have written a default config to protected/config.php' . PHP_EOL; echo 'Please edit that config.php, before installing gwf3.' . PHP_EOL; die(0); } if (false === gdo_db()) { file_put_contents('php://stderr', 'Cannot connect to the database. Check your protected/config.php!' . PHP_EOL); die(1); } echo "Installing gwf util core..." . PHP_EOL; if (!GWF_InstallFunctions::core(false)) { file_put_contents('php://stderr', 'Cannot install core... giving up!'); die(2);
private function msg_type_call($message) { // printf("msg_type_call: %s\n", print_r($message, true)); if (!is_array($message) || count($message) !== 2) { GWF_Log::logCritical("Dog_WorkerThread::msg_type_call() - The message from queue is not array(func, args)"); } elseif (!GWF_Callback::isCallback($message[0])) { GWF_Log::logCritical("Dog_WorkerThread::msg_type_call() - message[0] is not a valid callback"); } elseif (!is_array($message[1])) { GWF_Log::logCritical("Dog_WorkerThread::msg_type_call() - message[1] is not an args array"); } else { // printf("msg_type_call: %s\n%s", print_r($message[0]), print_r($message[1])); return call_user_func_array($message[0], $message[1]); } }
set_time_limit(0); require_once 'protected/config.php'; require_once '../gwf3.class.php'; $gwf = new GWF3(getcwd(), array('website_init' => false, 'autoload_modules' => false, 'load_module' => false, 'load_config' => false, 'start_debug' => true, 'get_user' => false, 'do_logging' => false, 'log_request' => false, 'blocking' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => true)); ###################### ### Security Check ### ###################### if (!GWF_IP6::isLocal()) { if ($_SERVER['REMOTE_ADDR'] !== $worker_ip) { GWF3::logDie(sprintf('You have no valid $worker_ip in %s line %s.', __FILE__, __LINE__)); } } GWF_Debug::setDieOnError(false); GWF_Language::initEnglish(); GWF_HTML::init(); GWF_Log::init(false, true, GWF_WWW_PATH . 'protected/logs'); require_once GWF_CORE_PATH . 'inc/install/GWF_InstallFunctions.php'; if (false !== Common::getPost('core')) { $success = true; install_core(false, $success); } if (false !== Common::getPost('lang')) { install_createLanguage(true, true, false); } if (false !== Common::getPost('lang2')) { install_createLanguage(true, true, true); } if (false !== Common::getPost('mods')) { install_all_modules(); } if (false !== Common::getPost('users')) {
chdir('../../../www'); require_once 'protected/config.php'; require_once '../gwf3.class.php'; $gwf = new GWF3(getcwd(), array('init' => true, 'bootstrap' => false, 'website_init' => true, 'autoload_modules' => false, 'load_module' => false, 'start_debug' => true, 'get_user' => false, 'do_logging' => false, 'buffered_log' => false, 'log_request' => false, 'blocking' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => false, 'kick_banned_ip' => false)); require_once 'merge/mergefuncs.php'; GWF_Log::init(false, 0x7fffffff, 'protected/logs/merge'); if ($argc !== 6) { merge_usage(); } GWF_Log::logCron('======================'); GWF_Log::logCron('=== STARTING MERGE ==='); GWF_Log::logCron('======================'); if (false === ($db_from = merge_db($argv))) { GWF_Log::logCritical('Connection to the import db failed!'); } $db_to = gdo_db(); // Store some offsets, like highest user(sic) => 1234 $db_offsets = array(); $prefix = $argv[4]; $prevar = $argv[5]; $modules = GWF_ModuleLoader::loadModulesFS(); $modules = GWF_ModuleLoader::sortModules($modules, 'module_priority', 'ASC'); GWF_Log::logCron('=== LOADED MODULES ==='); GWF_Log::logCron('======================'); merge_core($db_from, $db_to, $db_offsets, $prefix, $prevar); foreach ($modules as $module) { $module instanceof GWF_Module; GWF_Cronjob::notice(sprintf('MERGE MODULE %s', $module->getName())); GWF_ModuleLoader::includeAll($module); $module->onMerge($db_from, $db_to, $db_offsets, $prefix, $prevar); }
public static function end($modulename) { GWF_Log::logCron('[DONE] ' . $modulename . PHP_EOL); }
public static function log($type, $s) { $s = self::decode(implode("\n", (array) $s)); switch ($type) { case 'error': GWF_Log::logError($s); break; case 'info': case 'message': GWF_Log::logMessage($s); break; case 'critical': case 'fatal': GWF_Log::logCritical($s); break; case 'warning': case 'warn': GWF_Log::logWarning($s); break; } }
private function modifyGender() { $gender = $this->getGender(); if (!isset(self::$GENDER[$gender])) { $msg = sprintf('%s has an invalid gender: "%s".', $this->getName(), $gender); Dog_Log::error($msg); GWF_Log::logCritical($msg); $gender = 'male'; } $this->applyModifiers(self::$GENDER[$gender]); }
public static function logResArray(array $resArray) { $msg = 'PaypalResponse:' . PHP_EOL; foreach ($resArray as $k => $v) { $msg .= "{$k} => {$v}\n"; } GWF_Log::log('paypal', $msg); }
/** * Run the cronjob for all modules. * Stuff for the cron-logfile goes to stdout. * Errors are redirected to stderr. */ public static function cronjobs() { GWF_Cronjob::notice('=============================='); GWF_Cronjob::notice('=== Starting GWFv3 cronjob ==='); GWF_Cronjob::notice('=============================='); GWF_Log::logCron(''); # Core jobs self::cronjobsCore(); # Modules foreach (self::loadModulesFS() as $module) { $module instanceof GWF_Module; if ($module->isEnabled()) { $module->onInclude(); $module->onLoadLanguage(); $module->onCronjob(); } } GWF_Cronjob::notice('=============================='); GWF_Cronjob::notice('=== Finished GWFv3 cronjob ==='); GWF_Cronjob::notice('=============================='); }
private function zipDir(GWF_ZipArchive $archive, $path, $recursive = true, $ignoreTemplates = true) { if (!is_dir($path)) { GWF_Log::logCritical('Is not Dir: ' . $path); return false; } if (false === ($dir = @dir($path))) { GWF_Log::logCritical('Can not read Dir: ' . $path); return false; } while (false !== ($entry = $dir->read())) { if ($entry[0] === '.') { continue; } $fullpath = sprintf('%s/%s', $path, $entry); if (is_dir($fullpath)) { # ignore some designs... if (!$ignoreTemplates && $this->isIgnored($fullpath)) { continue; } # recursion? if ($recursive) { if (false === $this->zipDir($archive, $fullpath, $recursive, $ignoreTemplates)) { $dir->close(); return false; } } else { # just skip dir continue; } } else { if ($entry === 'Convert.php') { continue; } else { if ($this->isFileWanted($entry)) { # Add a file. if (false === $archive->addFile($fullpath)) { GWF_Log::logCritical('Can not add file: ' . $fullpath); $dir->close(); return false; } } } } } $dir->close(); return true; }
<?php chdir('../../../'); require_once 'core/inc/util/GWF_Log.php'; GWF_Log::init('Guest', true, dirname(__FILE__) . '/testlog'); GWF_Log::log('baim', 'THIS MC IS HACKED!');
private function garbage($real_token = '???', $real_mc = '???', $ext_msg = 'somethings wrong') { $msg = sprintf('InvalidMC: uid=%d, token=%s(%s), mc=%s(%s): %s.', Common::getGet('id') - 1000, Common::getGet('token'), $real_token, Common::getGet('mc'), $real_mc, $ext_msg); GWF_Log::log('baim_log.txt', $msg); return GWF_Random::randomKey(self::SHA512_LEN, GWF_Random::HEXLOWER); }
/** * Autoload modules with autoload flag. * @todo GWF_Result or return integer / modules which could not be loaded * @return boolean */ public static function autoloadModules() { if (false === ($modules = self::table(__CLASS__)->selectAll('*', 'module_options&3=3', 'module_priority ASC'))) { return false; # Database Problem } $msg = array(); foreach ($modules as $data) { $modulename = $data['module_name']; if (true === isset(self::$MODULES[$modulename])) { continue; } if (false === ($module = self::initModuleB($modulename, $data))) { # TODO... $msg[] = 'Could not autoload module ' . $modulename; GWF_Log::logError('Could not autoload module ' . $modulename); } } return true; //return count($msg) ? true : new GWF_Exception($msg, GWF_Exception::MODULES); }
private function logCriticalError(GWF_Module $module, GWF_Order $order) { $message = $this->error('err_crit', $order->getOrderToken()); GWF_Log::logCritical($message); GWF_Website::addDefaultOutput($message); return ''; }
/** * Display the page with layout * If ajax is enabled it returns only the module content * @param string|NULL $content replace page content * @return string */ public function onDisplayPage($content = NULL) { if (true === self::getConfig('log_request') && class_exists('GWF_Log')) { GWF_Log::logRequest(); } # Display the page if (true === isset($_GET['ajax'])) { GWF_Website::plaintext(); return self::$page; } else { $page = $content === NULL ? self::$page : $content; return GWF_Website::displayPage($page); } }
# Require config $config_file = $argv[1]; require_once '../../../www/protected/' . $config_file; # and gwf require_once '../../../gwf3.class.php'; $gwf = new GWF3(NULL, array('init' => true, 'bootstrap' => false, 'website_init' => false, 'autoload_modules' => false, 'load_module' => false, 'load_config' => false, 'start_debug' => true, 'get_user' => false, 'do_logging' => false, 'log_request' => false, 'blocking' => true, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => false, 'kick_banned_ip' => false, 'env' => isset($argv[5]) ? $argv[5] : 'prod', 'unix_user' => isset($argv[6]) ? $argv[6] : 'root')); # That´s all of GWF3 we will share with the worker. GWF_HTML::init(); GWF_Debug::setDieOnError(false); GWF_Debug::setMailOnError(false); $_GET['ajax'] = 1; # And this is the worker process require 'dog_include/Dog_WorkerThread.php'; $worker = new Dog_WorkerThread(); $worker->start(); # Parent resources GWF_Log::init(false, GWF_Log::_DEFAULT - GWF_Log::BUFFERED, GWF_PATH . 'www/protected/logs/dog'); gdo_db(); # Dog please require_once 'Dog.php'; Dog::setUnixUsername(GWF3::getConfig('unix_user')); # Dog installer if (isset($argv[2]) && $argv[2] === 'install') { require_once 'mini_install.php'; } # Dog init Dog_Init::init($worker); # Dog l(a)unch if (!defined('DOG_NO_LAUNCH') && Dog_Init::validate()) { Dog::mainloop(); }
/** * A database error occured. * @param string $query * @param int $errno * @param string $error */ public function error($query, $errno, $error) { $message_html = $this->getErrorMessage($query, $errno, $error, true); $message_ajax = $this->getErrorMessage($query, $errno, $error, false); # Log the error. if ($this->isLogging() && class_exists('GWF_Log')) { GWF_Log::logCritical($message_ajax); } # Output error if (PHP_SAPI === 'cli') { file_put_contents('php://stderr', GWF_Debug::backtrace($message_ajax, false)); } elseif ($this->verbose) { $message = isset($_GET['ajax']) ? $message_ajax : $message_html; $message = GWF_Debug::backtrace($message, !isset($_GET['ajax'])); echo GWF_HTML::error('GDO', $message, false); } else { echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # Send mail if ($this->email) { $this->emailOnError($message_ajax); } # Quit if ($this->die) { die(1); } }
public static function setLogFormat($format) { self::$logformat = $format; }