Example #1
0
 public function execute()
 {
     $this->module->includeClass('WC_Warbox');
     $this->module->includeClass('WC_Warflag');
     $this->module->includeClass('WC_WarToken');
     $this->module->includeClass('sites/warbox/WCSite_WARBOX');
     # CHECK TOKEN
     if (isset($_GET['CHECK'])) {
         $_GET['ajax'] = 1;
         if (false === ($username = Common::getGetString('username', false))) {
             return GWF_HTML::err('ERR_PARAMETER', array('username'));
         }
         if (false === ($token = Common::getGetString('token', false))) {
             return GWF_HTML::err('ERR_PARAMETER', array('token'));
         }
         return WC_WarToken::isValidWarToken($username, $token) ? '1' : '0';
     }
     # GET CONFIG
     if (isset($_GET['CONFIG'])) {
         return $this->genConfig();
     }
     if (!GWF_Session::isLoggedIn()) {
         return GWF_HTML::err('ERR_LOGIN_REQUIRED');
     }
     # GEN AND SHOW
     return $this->templateToken();
 }
Example #2
0
function warscore_function($socket, $pid)
{
    # Init GWF
    $gwf = new GWF3(getcwd(), array('website_init' => false, 'autoload_modules' => false, 'load_module' => false, 'start_debug' => true, 'get_user' => false, 'log_request' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => false));
    gdo_db();
    GWF_Debug::setDieOnError(false);
    GWF_HTML::init();
    if (false === ($wechall = GWF_Module::loadModuleDB('WeChall', true, true, true))) {
        warscore_error($socket, 'Cannot load WeChall!');
    }
    $wechall->includeClass('WC_Warbox');
    $wechall->includeClass('WC_WarToken');
    $wechall->includeClass('WC_Warflag');
    $wechall->includeClass('WC_Warflags');
    $wechall->includeClass('sites/warbox/WCSite_WARBOX');
    if (false === ($input = socket_read($socket, 2048))) {
        warscore_error($socket, 'Read Error 1!');
    }
    warscore_debug("GOT INPUT: {$input}");
    if (false === ($username = Common::substrUntil($input, "\n", false))) {
        warscore_error($socket, 'No username sent!');
    }
    if (false === ($user = GWF_User::getByName($username))) {
        warscore_error($socket, 'Unknown user!');
    }
    warscore_debug("GOT USER: {$username}");
    if ('' === ($token = Common::substrFrom($input, "\n", ''))) {
        warscore_error($socket, 'No token sent!');
    }
    $token = trim(Common::substrUntil($token, "\n", $token));
    if (!WC_WarToken::isValidWarToken($user, $token)) {
        warscore_error($socket, 'Invalid Token!');
    }
    if (!socket_getpeername($socket, $client_ip, $client_port)) {
        warscore_error($socket, 'Socket Error 2!');
    }
    echo "{$client_ip}\n";
    $boxes = WC_Warbox::getByIP($client_ip);
    if (count($boxes) === 0) {
        warscore_error($socket, 'Unknown Warbox!');
    }
    warscore_debug("GOT N BOXES: " . count($boxes));
    $curr_port = 0;
    foreach ($boxes as $box) {
        $box instanceof WC_Warbox;
        if ($curr_port !== $box->getVar('wb_port')) {
            $curr_port = $box->getVar('wb_port');
            warscore_identd($socket, $box, $user, $client_ip, $client_port);
        }
    }
    socket_write($socket, 'Bailing out! You should not see me.');
    socket_close($socket);
    die(0);
}