Beispiel #1
0
function math_pyramid_check(WC_Challenge $chall, $formula, $maxlen, $precision = 4)
{
    error_reporting(E_ERROR);
    GWF_Debug::setDieOnError(false);
    GWF_Debug::setMailOnError(false);
    $len = strlen($formula);
    $tests = array('0' => 0, '1' => 0.2357, '3.14' => 7.2971, '10' => 235.7023, '100' => 235702.2604);
    $eval = new EvalMath();
    $fa = "f(a) = {$formula}";
    if (false === $eval->evaluate($fa)) {
        echo GWF_HTML::error('Math Pyramid', $chall->lang('err_formula', array(htmlspecialchars($fa))));
        return false;
    }
    GWF_Debug::setDieOnError(true);
    GWF_Debug::setMailOnError(true);
    $back = GWF_HTML::message('Math Pyramid', $chall->lang('msg_formula', array(htmlspecialchars($fa))), false);
    $correct = 0;
    foreach ($tests as $a => $result) {
        $result2 = $eval->evaluate("f({$a})");
        $result = sprintf('%.0' . $precision . 'f', $result);
        $result2 = sprintf('%.0' . $precision . 'f', $result2);
        if ($result === $result2) {
            $back .= GWF_HTML::message('Math Pyramid', $chall->lang('msg_correct', array($a, $result2, $result)), false);
            $correct++;
        } else {
            $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_wrong', array($a, $result2, $result)), false);
        }
    }
    require_once GWF_CORE_PATH . 'module/WeChall/WC_MathChall.php';
    if ($chall->getID() > 0 && $correct === count($tests)) {
        if (false === WC_MathChall::insertSolution($chall->getID(), GWF_Session::getUserID(), $formula)) {
            $back .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
        } else {
            $back .= GWF_HTML::message('Math Pyramid', WC_HTML::lang('msg_wmc_sol_inserted', array($len, WC_MathChall::getLimitedHREF($chall, $len))), false);
        }
    }
    # Check Len
    if ($len > $maxlen) {
        $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_too_long', array($len, $maxlen)), false);
    }
    echo $back;
    if ($correct === count($tests) && $len <= $maxlen) {
        if ($len < $maxlen) {
            echo GWF_HTML::message('Math Pyramid', $chall->lang('msg_new_record', array($len, $maxlen)), false);
            GWF_Settings::setSetting('WC_MATH_PYRAMID', $len);
        }
        $chall->onChallengeSolved(GWF_Session::getUserID());
    }
}
Beispiel #2
0
 /**
  * Initialize by ConfigOptions
  * @return GWF3 
  */
 public function init()
 {
     $config =& self::$CONFIG;
     if (true === $config['start_debug']) {
         GWF_Debug::enableErrorHandler();
         GWF_Debug::setMailOnError((GWF_DEBUG_EMAIL & 2) > 0);
     }
     if (true === $config['kick_banned_ip']) {
         $this->onKickBannedIP();
     }
     if (true === defined('GWF_WEBSITE_DOWN')) {
         $this->setConfig('load_module', false);
         $this->setConfig('autoload_modules', false);
         $this->setConfig('no_session', true);
     }
     // 		$db = gdo_db();
     if (false === $config['no_session']) {
         $this->onStartSession($config['blocking']);
     }
     if (true === $config['website_init']) {
         $db = gdo_db();
         GWF_Website::init();
     }
     if (true === $config['do_logging']) {
         $this->onStartLogging($config['no_session']);
     }
     if (true === $config['autoload_modules']) {
         $this->onAutoloadModules();
     }
     if (true === $config['get_user']) {
         GWF_Template::addMainTvars(array('user' => self::$user = GWF_User::getStaticOrGuest()));
     }
     if (true === $config['load_module']) {
         $this->onLoadModule();
     }
     if (true === defined('GWF_WEBSITE_DOWN')) {
         die($this->onDisplayPage(GWF_WEBSITE_DOWN));
     }
     return $this;
 }
Beispiel #3
0
<?php

# WeChall things
chdir('../../../');
define('GWF_PAGE_TITLE', 'PHP 0819');
require_once 'challenge/html_head.php';
if (false === ($chall = WC_Challenge::getByTitle(GWF_PAGE_TITLE))) {
    $chall = WC_Challenge::dummyChallenge(GWF_PAGE_TITLE, 2, 'challenge/space/php0819/index.php', false);
}
$chall->showHeader();
###############
## Challenge ##
###############
GWF_Debug::setDieOnError(false);
GWF_Debug::setMailOnError(false);
require_once 'challenge/space/php0819/php0819.php';
echo GWF_Box::box($chall->lang('info', array(GWF_WEB_ROOT . 'profile/space')), $chall->lang('title'));
if (isset($_GET['eval'])) {
    if (true === $challenge()) {
        $chall->onChallengeSolved(GWF_Session::getUserID());
    }
}
GWF_Debug::setDieOnError(true);
GWF_Debug::setMailOnError(true);
$filename = 'challenge/space/php0819/php0819.php';
$message = '[PHP]' . file_get_contents($filename) . '[/PHP]';
echo GWF_Message::display($message);
# TODO: GET form input box? (gizmore)
echo $chall->copyrightFooter();
require_once 'challenge/html_foot.php';
Beispiel #4
0
<?php

chdir(dirname(__FILE__));
chdir('../');
# 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);