Exemplo n.º 1
0
 /**
  * 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'];
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 /**
  * Log a message as critical, then die()
  * @return NULL 
  */
 public static function logDie($msg = '')
 {
     if (true === self::getConfig('do_logging')) {
         GWF_Log::logCritical($msg);
     }
     die(htmlspecialchars($msg));
     # FIXME: dont die here, raise global GWF_Exception
 }
Exemplo n.º 6
0
 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);
             }
         }
     }
 }
Exemplo n.º 7
0
 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]);
 }
Exemplo n.º 8
0
 /**
  * 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));
 }
Exemplo n.º 9
0
 /**
  * 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);
     }
 }
Exemplo n.º 10
0
 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 '';
 }
Exemplo n.º 11
0
 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 ?
 }
Exemplo n.º 12
0
 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]);
     }
 }
Exemplo n.º 13
0
}
# GWF_PATH
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);
Exemplo n.º 14
0
 protected static function proc_rw_with_callbacks($command, array $callbacks = array(), $input = null)
 {
     $descriptors = array(0 => array('pipe', 'r'), 1 => array('pipe', 'rw'), 2 => array('pipe', 'rw'));
     if (!is_array($callbacks)) {
         $callbacks = array();
     } else {
         $callbacks = array_values($callbacks);
     }
     for ($i = count($callbacks); $i < 3; $i++) {
         $callbacks[] = null;
     }
     # Remove invalids
     for ($i = 0; $i < 3; $i++) {
         if (!GWF_Callback::isCallback($callbacks[$i])) {
             GWF_Log::logCritical("GWF_Worker::proc_with_callback() - Invalid callback {$i}: " . GWF_Callback::printCallback($callbacks[$i]));
             $callbacks[$i] = null;
         }
     }
     # Default handlers
     if ($callbacks[1] === null) {
         $callbacks[1] = array(__CLASS__, '_proc_out');
     }
     if ($callbacks[2] === null) {
         $callbacks[2] = array(__CLASS__, '_proc_err');
     }
     $pipes = null;
     if (false === ($proc = proc_open($command, $descriptors, $pipes, null, $_ENV))) {
         return self::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     fclose($pipes[0]);
     $read_output = $read_error = false;
     $buffer_len = $prev_buffer_len = 0;
     $ms = 10;
     // 		$output      = '';
     $read_output = true;
     // 		$error       = '';
     $read_error = true;
     stream_set_blocking($pipes[1], 0);
     stream_set_blocking($pipes[2], 0);
     // dual reading of STDOUT and STDERR stops one full pipe blocking the other, because the external script is waiting
     while ($read_error != false || $read_output != false) {
         if ($read_output != false) {
             if (feof($pipes[1])) {
                 fclose($pipes[1]);
                 $read_output = false;
             } else {
                 $str = fread($pipes[1], 1024);
                 $len = strlen($str);
                 if ($len) {
                     call_user_func($callbacks[1], $str);
                     $buffer_len += $len;
                 }
             }
         }
         if ($read_error != false) {
             if (feof($pipes[2])) {
                 fclose($pipes[2]);
                 $read_error = false;
             } else {
                 $str = fread($pipes[2], 1024);
                 $len = strlen($str);
                 if ($len) {
                     call_user_func($callbacks[2], $str);
                     $buffer_len += $len;
                 }
             }
         }
         if ($buffer_len > $prev_buffer_len) {
             $prev_buffer_len = $buffer_len;
             $ms = 10;
         } else {
             usleep($ms * 1000);
             // sleep for $ms milliseconds
             if ($ms < 160) {
                 $ms = $ms * 2;
             }
         }
     }
     // 		fclose($pipes[1]);
     // 		fclose($pipes[2]);
     proc_close($proc);
 }