Exemplo n.º 1
0
function processbounces_shutdown()
{
    global $report, $process_id;
    releaseLock($process_id);
    # $report .= "Connection status:".connection_status();
    finish('info', $report);
}
Exemplo n.º 2
0
function begun_or_not($page)
{
    global $duration, $diff;
    $connection = createConn();
    $var = -1;
    $sql_query = "SELECT * FROM googlockstart_end where no='0'";
    $temp = mysql_query($sql_query, $connection);
    $result = mysql_fetch_array($temp);
    finish($connection);
    $curr_timestamp = time();
    $diff = $curr_timestamp - $result['start_timestamp'];
    $duration = $result['finish_timestamp'] - $result['start_timestamp'];
    if ($diff < 0) {
        $msg = "Game has not started yet";
        $var = 0;
    } else {
        if ($curr_timestamp > $result['finish_timestamp']) {
            $msg = "Game has finished";
            $var = 1;
        } else {
            $msg = "Game has Started!!";
        }
    }
    if ($page == 1) {
        if ($var == 0) {
            header("location: index.php");
        } else {
            if ($var == 1) {
                header("location: login.php");
            }
        }
    } else {
        return $msg;
    }
}
Exemplo n.º 3
0
function ProcessError($message)
{
    print "{$message}";
    logEvent("Error: {$message}");
    finish("error", $message);
    exit;
}
Exemplo n.º 4
0
function handle($uri = '')
{
    try {
        if (($matched = dispatch($uri)) != null) {
            if (!before()) {
                $handler = $matched['handler'];
                if (!empty($matched['options']['router'])) {
                    $handler = call_user_func($handler, $matched);
                }
                if (!empty($matched['options']['create'])) {
                    $controllerClass = $handler[0];
                    $handler[0] = new $controllerClass();
                }
                if (isset($matched['params'])) {
                    call_user_func_array($handler, $matched['params']);
                } else {
                    call_user_func_array($handler, $matched['segments']);
                }
                after();
            }
        } else {
            notFound();
        }
        finish();
    } catch (Exception $e) {
        error_log($e->getMessage());
        error_log($e->getTraceAsString());
    }
    exit;
}
Exemplo n.º 5
0
function processTestEmails_shutdown()
{
    global $report, $process_id;
    releaseLock($process_id);
    # $report .= "Connection status:".connection_status();
    finish('info', $report);
    if (!$GLOBALS["commandline"]) {
        include_once dirname(__FILE__) . '/footer.inc';
    }
}
Exemplo n.º 6
0
function my_shutdown()
{
    global $script_stage, $reload;
    #  output( "Script status: ".connection_status(),0); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774
    output($GLOBALS['I18N']->get('Script stage') . ': ' . $script_stage, 0, 'progress');
    global $counters, $report, $send_process_id, $tables, $nothingtodo, $invalid, $processed, $failed_sent, $notsent, $sent, $unconfirmed, $num_per_batch, $batch_period, $counters;
    $some = $processed;
    #$sent;# || $invalid || $notsent;
    if (!$some) {
        output($GLOBALS['I18N']->get('Finished, Nothing to do'), 0, 'progress');
        $nothingtodo = 1;
    }
    $totaltime = $GLOBALS['processqueue_timer']->elapsed(1);
    if ($totaltime > 0) {
        $msgperhour = 3600 / $totaltime * $sent;
    } else {
        $msgperhour = s('Calculating');
    }
    if ($sent) {
        output(sprintf('%d %s %01.2f %s (%d %s)', $sent, $GLOBALS['I18N']->get('messages sent in'), $totaltime, $GLOBALS['I18N']->get('seconds'), $msgperhour, $GLOBALS['I18N']->get('msgs/hr')), $sent, 'progress');
    }
    if ($invalid) {
        output(s('%d invalid email addresses', $invalid), 1, 'progress');
    }
    if ($failed_sent) {
        output(s('%d failed (will retry later)', $failed_sent), 1, 'progress');
        foreach ($counters as $label => $value) {
            #  output(sprintf('%d %s',$value,$GLOBALS['I18N']->get($label)),1,'progress');
            cl_output(sprintf('%d %s', $value, $GLOBALS['I18N']->get($label)));
        }
    }
    if ($unconfirmed) {
        output(sprintf($GLOBALS['I18N']->get('%d emails unconfirmed (not sent)'), $unconfirmed), 1, 'progress');
    }
    foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
        $plugin->processSendStats($sent, $invalid, $failed_sent, $unconfirmed, $counters);
    }
    flushClickTrackCache();
    releaseLock($send_process_id);
    finish("info", $report, $script_stage);
    if ($script_stage < 5 && !$nothingtodo) {
        output($GLOBALS['I18N']->get('Warning: script never reached stage 5') . "\n" . $GLOBALS['I18N']->get('This may be caused by a too slow or too busy server') . " \n");
    } elseif ($script_stage == 5 && (!$nothingtodo || isset($GLOBALS["wait"]))) {
        # if the script timed out in stage 5, reload the page to continue with the rest
        $reload++;
        if (!$GLOBALS["commandline"] && $num_per_batch && $batch_period) {
            if ($sent + 10 < $GLOBALS["original_num_per_batch"]) {
                output($GLOBALS['I18N']->get('Less than batch size were sent, so reloading imminently'), 1, 'progress');
                $delaytime = 10;
            } else {
                // we should actually want batch perion minus time already spent.
                // might be nice to calculate that at some point
                output(sprintf($GLOBALS['I18N']->get('Waiting for %d seconds before reloading'), $batch_period), 1, 'progress');
                $delaytime = $batch_period;
            }
            sleep($delaytime);
            printf('<script type="text/javascript">
        document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d";
      </script>', $reload, $sent, $notsent);
        } else {
            printf('<script type="text/javascript">
        document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d";
      </script>', $reload, $sent, $notsent);
        }
    } elseif ($script_stage == 6 || $nothingtodo) {
        foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
            $plugin->messageQueueFinished();
        }
        output($GLOBALS['I18N']->get('Finished, All done'), 0);
        print '<script type="text/javascript">
      var parentJQuery = window.parent.jQuery;
      window.parent.allDone("' . s('All done') . '");
      </script>';
    } else {
        output(s('Script finished, but not all messages have been sent yet.'));
    }
    if (empty($GLOBALS['commandline']) && empty($_GET['ajaxed'])) {
        include_once "footer.inc";
    } elseif (!empty($GLOBALS['commandline'])) {
        @ob_end_clean();
    }
    exit;
}
Exemplo n.º 7
0
function ProcessError ($message) {
  output( "$message");
  finish("error",$message);
  exit;
}
Exemplo n.º 8
0
function scanner($path, $node, $line)
{
    global $migrational, $items;
    switch ($path) {
        case '/blog':
            if (!preg_match('/^tattertools\\/1\\.[01]$/', @$node['.attributes']['type']) && !preg_match('/^textcube\\/1\\.[01]$/', @$node['.attributes']['type'])) {
                finish(_t('지원하지 않는 백업파일입니다.'));
            }
            $migrational = Validator::getBool(@$node['.attributes']['migrational']);
            return true;
        case '/blog/setting/banner/content':
        case '/blog/post/attachment/content':
        case '/blog/notice/attachment/content':
        case '/blog/keyword/attachment/content':
            if (!empty($node['.stream'])) {
                fclose($node['.stream']);
                unset($node['.stream']);
            }
            return true;
        case '/blog/setting':
        case '/blog/category':
        case '/blog/post':
        case '/blog/notice':
        case '/blog/keyword':
        case '/blog/link':
        case '/blog/logs/referer':
        case '/blog/statistics/referer':
        case '/blog/statistics/visits':
        case '/blog/statistics/daily':
        case '/blog/skin':
        case '/blog/plugin':
        case '/blog/commentNotified/comment':
        case '/blog/commentNotifiedSiteInfo/site':
        case '/blog/guestbook/comment':
        case '/blog/filter':
        case '/blog/feed':
        case '/blog/line':
            $items++;
            if (!strpos($path, 'referer')) {
                setProgress(null, _t('백업파일을 확인하고 있습니다.'), $line);
            }
            return true;
        case '/blog/personalization':
        case '/blog/userSetting':
            // skip
            return true;
    }
}
}
function test_is_running()
{
    return $GLOBALS['current'] != '';
}
function loop_tests($cmd, $line_func)
{
    global $results;
    $ftest = popen($cmd, 'r');
    if (!$ftest) {
        echo "Couldn't run test script\n";
        exit(1);
    }
    while (!feof($ftest)) {
        $line = fgets($ftest);
        $line_func($line);
    }
    say(array('op' => 'all_done', 'results' => $results));
    fclose($ftest);
}
chdir(__DIR__ . '/../../../');
$cmd = "./hphp/tools/run_test_binary.sh " . "'{$argv['1']}' '{$argv['2']}' '{$argv['3']}' '{$argv['4']}' " . "2>/dev/null";
loop_tests($cmd, function ($line) {
    if (preg_match('/^(Test[a-zA-Z]*)\\.\\.\\.\\.\\.\\.$/', $line, $m)) {
        start($m[1]);
    } else {
        if (preg_match('/^Test[a-zA-Z]* (OK|\\#\\#\\#\\#\\#\\>\\>\\> FAILED)/', $line, $m)) {
            finish($m[1] == 'OK' ? 'passed' : 'failed');
        }
    }
});
Exemplo n.º 10
0
if ($mysqli->connect_errno) {
    $ret = "未能连接到数据库 (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    finish($ret);
}
$id = $mysqli->real_escape_string($id);
$name = $mysqli->real_escape_string($name);
if ($res = $mysqli->query("SELECT ID FROM students WHERE stu_id = '{$id}' AND name = '{$name}'")) {
    if ($res->num_rows) {
        $row = $res->fetch_assoc();
        $stuid = $row['ID'];
    } else {
        finish("查无此人");
    }
} else {
    finish("查询失败!");
}
if ($res = $mysqli->query("SELECT * FROM time WHERE student_id = {$stuid} AND event = '{$event}'")) {
    echo "[";
    $i = false;
    while ($row = $res->fetch_assoc()) {
        if ($i) {
            echo ",";
        }
        $i = true;
        printf('{"day": "%s", "item": "%s"}', $row['day'], $row['item']);
    }
    echo "]";
} else {
    finish("查询失败");
}
$mysqli->close();
Exemplo n.º 11
0
function getpage($url)
{
    global $headers, $out, $post_vars, $proxy_variables, $referer;
    $urlobj = new aurl($url);
    $query = $urlobj->get_query();
    $requrl = $urlobj->get_path() . $urlobj->get_file() . (!empty($query) ? "?{$query}" : null);
    $http_auth = null;
    if (extension_loaded('apache')) {
        $fail = false;
        $cheaders = getallheaders();
        $http_auth = $reqarray['Authorization'];
    } else {
        $fail = true;
    }
    $authorization = $fail ? $_SERVER['HTTP_AUTHORIZATION'] : $cheaders['Authorization'];
    $cache_control = $fail ? $_SERVER['HTTP_CACHE_CONTROL'] : $cheaders['Cache-Control'];
    $if_modified = $fail ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : $cheaders['If-Modified-Since'];
    $if_none_match = $fail ? $_SERVER['HTTP_IF_NONE_MATCH'] : $cheaders['If-None-Match'];
    if ($fail) {
        if (!empty($authorization)) {
            $http_auth = $authorization;
        } elseif (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
            $http_auth = 'Basic ' . base64_encode("{$_SERVER['PHP_AUTH_USER']}:{$_SERVER['PHP_AUTH_PW']}");
        } elseif (!empty($_SERVER['PHP_AUTH_DIGEST'])) {
            $http_auth = "Digest {$_SERVER['PHP_AUTH_DIGEST']}";
        }
    }
    if (PIP != null && PPORT != null) {
        $servername = PIP;
        $ipaddress = get_check(PIP);
        $portval = PPORT;
        $requrl = $urlobj->get_url(false);
    } else {
        $servername = $urlobj->get_servername();
        $ipaddress = ($urlobj->get_proto() == 'ssl' || $urlobj->get_proto() == 'https' ? 'ssl://' : null) . get_check($servername);
        $portval = $urlobj->get_portval();
    }
    $out = "{$_SERVER['REQUEST_METHOD']} " . str_replace(' ', '%20', $requrl) . " HTTP/1.1\r\nHost: " . $urlobj->get_servername() . ($portval != 80 && ($urlobj->get_proto() == 'https' ? $portval != 443 : true) ? ":{$portval}" : null) . "\r\n";
    global $useragent;
    $useragent = null;
    if ($_COOKIE[COOK_PREF . '_useragent'] != '-1') {
        $useragent = $_COOKIE[COOK_PREF . '_useragent'];
        if (empty($useragent)) {
            $useragent = $_SERVER['HTTP_USER_AGENT'];
        }
        $useragent_cook = $useragent == 1 ? $_COOKIE[COOK_PREF . '_useragenttext'] : $useragent;
        if (!empty($useragent_cook)) {
            $out .= "User-Agent: {$useragent_cook}\r\n";
        }
    }
    if (!empty($http_auth)) {
        $out .= "Authorization: {$http_auth}\r\n";
    }
    if (empty($_COOKIE[COOK_PREF . '_remove_referer']) && !empty($referer)) {
        $out .= 'Referer: ' . str_replace(' ', '+', $referer) . "\r\n";
    }
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $out .= 'Content-Length: ' . strlen($post_vars) . "\r\nContent-Type: application/x-www-form-urlencoded\r\n";
    }
    $cook_prefdomain = preg_replace('/^www\\./i', null, $urlobj->get_servername());
    #*
    $cook_prefix = str_replace('.', '_', $cook_prefdomain) . COOKIE_SEPARATOR;
    if (count($_COOKIE) > 0 && empty($_COOKIE[COOK_PREF . '_remove_cookies'])) {
        $addtoout = null;
        reset($_COOKIE);
        while (list($key, $val) = each($_COOKIE)) {
            if (ENCRYPT_COOKS) {
                $key = proxdec($key);
                $val = proxdec($val);
                #urldecode($val));
            }
            if (str_replace(COOKIE_SEPARATOR, null, $key) == $key) {
                continue;
            }
            #$cook_domain=preg_replace('/^(.*'.COOKIE_SEPARATOR.').*$/','\1',$key); #**
            $cook_domain = substr($key, 0, strpos($key, COOKIE_SEPARATOR)) . COOKIE_SEPARATOR;
            if (substr($cook_prefix, strlen($cook_prefix) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $key = substr($key, strlen($cook_domain), strlen($key) - strlen($cook_domain));
            if (!in_array($key, $proxy_variables)) {
                $addtoout .= " {$key}={$val};";
            }
        }
        if (!empty($addtoout)) {
            $addtoout .= "\r\n";
            $out .= "Cookie:{$addtoout}";
        }
    }
    $out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n" . "Accept-Language: en-us,en;q=0.5\r\n" . "Accept-Encoding: gzip\r\n" . "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" . "Connection: close\r\n" . ($cache_control != null ? "Cache-Control: {$cache_control}\r\n" : null) . ($if_modified != null ? "If-Modified-Since: {$if_modified}\r\n" : null) . ($if_none_match != null ? "If-None-Match: {$if_none_match}\r\n" : null) . "\r\n{$post_vars}";
    // This part ignores any "SSL: fatal protocol error" errors, and makes sure other errors are still triggered correctly
    function errorHandle($errno, $errmsg)
    {
        if ($errno <= E_PARSE && ($errno != E_WARNING || substr($errmsg, strlen($errmsg) - 25, 25) != 'SSL: fatal protocol error')) {
            restore_error_handler();
            trigger_error($errmsg, $errno << 8);
            set_error_handler('errorHandle');
        }
    }
    set_error_handler('errorHandle');
    $fp = @fsockopen($ipaddress, $portval, $errno, $errval, 5) or havok(6, $servername, $portval);
    stream_set_timeout($fp, 5);
    $ub = stream_get_meta_data($fp);
    $ub = $ub['unread_bytes'];
    if ($ub > 0) {
        fread($fp, $ub);
    }
    fwrite($fp, $out);
    function get_byte($fp)
    {
        $byte = fread($fp, 1);
        return $byte == "\r" ? get_byte($fp) : $byte;
    }
    $response = '100';
    while ($response == '100') {
        $responseline = fread($fp, 12);
        $response = substr($responseline, -3, 3);
        $headers = $responseline . fread($fp, 1);
        while (true) {
            $chunk = null;
            $byte = get_byte($fp);
            if ($byte == "\n") {
                break;
            }
            while ($byte != "\n") {
                $chunk .= $byte;
                $byte = get_byte($fp);
            }
            $headers .= $chunk . $byte;
        }
    }
    #if(header_value('Pragma')==null) header('Pragma: public');
    #if(header_value('Cache-Control')==null) header('Cache-Control: public');
    #if(header_value('Last-Modified')==null && header_value('Expires')==null) header('Expires: '.date('D, d M Y H:i:s e',time()+86400));
    if (empty($_COOKIE[COOK_PREF . '_remove_cookies'])) {
        $setcookiearr = header_value_arr('Set-Cookie');
        for ($i = 0; $i < count($setcookiearr); $i++) {
            $thiscook = explode('=', $setcookiearr[$i], 2);
            if (!strpos($thiscook[1], ';')) {
                $thiscook[1] .= ';';
            }
            $cook_val = substr($thiscook[1], 0, strpos($thiscook[1], ';'));
            $cook_domain = preg_replace('/^.*domain=[	 ]*\\.?([^;]+).*?$/i', '\\1', $thiscook[1]);
            #*
            if ($cook_domain == $thiscook[1]) {
                $cook_domain = $cook_prefdomain;
            } elseif (substr($cook_prefdomain, strlen($cook_prefdomain) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $cook_name = str_replace('.', '_', $cook_domain) . COOKIE_SEPARATOR . $thiscook[0];
            if (ENCRYPT_COOKS) {
                $cook_name = proxenc($cook_name);
                $cook_val = proxenc($cook_val);
            }
            dosetcookie($cook_name, $cook_val);
        }
    }
    if (substr($response, 0, 2) == '30' && $response[2] != '4') {
        $urlobj = new aurl($url);
        $redirurl = framify_url(surrogafy_url(header_value('Location'), $urlobj), NEW_PAGETYPE_FRAMED_PAGE);
        fclose($fp);
        restore_error_handler();
        finish_noexit();
        header("Location: {$redirurl}");
        exit;
    }
    $oheaders = preg_replace("/[\r\n](?:Location|Content-Length|Content-Encoding|Set-Cookie|Transfer-Encoding|Connection|Keep-Alive|Pragma|Cache-Control|Expires)\\: .*/i", null, $headers);
    #*
    $ohsplit = explode("\n", $oheaders);
    foreach ($ohsplit as $header) {
        if (!empty($header)) {
            header($header);
        }
    }
    unset($oheaders, $ohsplit);
    header('Status: ' . $response);
    if (substr(header_value('Content-Type'), 0, 4) == 'text' || substr(header_value('Content-Type'), 0, 24) == 'application/x-javascript') {
        $justoutput = false;
        $justoutputnow = false;
    } else {
        $justoutputnow = header_value('Content-Encoding') == 'gzip' ? false : true;
        $justoutput = true;
    }
    if (header_value('Transfer-Encoding') == 'chunked') {
        $body = null;
        $chunksize = null;
        while ($chunksize !== 0) {
            $byte = null;
            $chunk = null;
            while ($byte != "\r") {
                $chunk .= $byte;
                $byte = fread($fp, 1);
            }
            fread($fp, 1);
            $chunksize = intval($chunk, 16);
            $bufsize = $chunksize;
            while ($bufsize >= 1) {
                $subchunk = fread($fp, $bufsize);
                if ($justoutputnow) {
                    echo $subchunk;
                } else {
                    $body .= $subchunk;
                }
                $bufsize -= strlen($subchunk);
            }
            fread($fp, 2);
        }
    } else {
        $body = null;
        while (true) {
            $chunk = fread($fp, 1024);
            if ($justoutputnow) {
                echo $chunk;
            } else {
                $body .= $chunk;
            }
            if (empty($chunk)) {
                break;
            }
        }
    }
    fclose($fp);
    restore_error_handler();
    if (header_value('Content-Encoding') == 'gzip') {
        $body = gzinflate(substr($body, 10));
    }
    #die('REQ: '.$out.'<br /><br />HEADERS: '.$headers.'<br /><br />Body: '.$body);
    if ($justoutput) {
        if (!$justoutputnow) {
            echo $body;
        }
        finish();
    }
    return array($body, $url, $cook_prefix);
}
Exemplo n.º 12
0
function my_shutdown()
{
    global $script_stage, $reload;
    #  processQueueOutput( "Script status: ".connection_status(),0); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774
    processQueueOutput(s('Script stage') . ': ' . $script_stage, 0, 'progress');
    global $counters, $report, $send_process_id, $tables, $nothingtodo, $processed, $notsent, $unconfirmed, $batch_period;
    $some = $processed;
    $delaytime = 0;
    if (!$some) {
        processQueueOutput($GLOBALS['I18N']->get('Finished, Nothing to do'), 0, 'progress');
        $nothingtodo = 1;
    }
    $totaltime = $GLOBALS['processqueue_timer']->elapsed(1);
    if ($totaltime > 0) {
        $msgperhour = 3600 / $totaltime * $counters['sent'];
    } else {
        $msgperhour = s('Calculating');
    }
    if ($counters['sent']) {
        processQueueOutput(sprintf('%d %s %01.2f %s (%d %s)', $counters['sent'], $GLOBALS['I18N']->get('messages sent in'), $totaltime, $GLOBALS['I18N']->get('seconds'), $msgperhour, $GLOBALS['I18N']->get('msgs/hr')), $counters['sent'], 'progress');
    }
    if ($counters['invalid']) {
        processQueueOutput(s('%d invalid email addresses', $counters['invalid']), 1, 'progress');
    }
    if ($counters['failed_sent']) {
        processQueueOutput(s('%d failed (will retry later)', $counters['failed_sent']), 1, 'progress');
        foreach ($counters as $label => $value) {
            #  processQueueOutput(sprintf('%d %s',$value,$GLOBALS['I18N']->get($label)),1,'progress');
            cl_output(sprintf('%d %s', $value, $GLOBALS['I18N']->get($label)));
        }
    }
    if ($unconfirmed) {
        processQueueOutput(sprintf($GLOBALS['I18N']->get('%d emails unconfirmed (not sent)'), $unconfirmed), 1, 'progress');
    }
    foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
        $plugin->processSendStats($counters['sent'], $counters['invalid'], $counters['failed_sent'], $unconfirmed, $counters);
    }
    flushClickTrackCache();
    releaseLock($send_process_id);
    finish('info', $report, $script_stage);
    if ($script_stage < 5 && !$nothingtodo) {
        processQueueOutput($GLOBALS['I18N']->get('Warning: script never reached stage 5') . "\n" . $GLOBALS['I18N']->get('This may be caused by a too slow or too busy server') . " \n");
    } elseif ($script_stage == 5 && (!$nothingtodo || isset($GLOBALS['wait']))) {
        # if the script timed out in stage 5, reload the page to continue with the rest
        ++$reload;
        if (!$GLOBALS['commandline'] && $counters['num_per_batch'] && $batch_period) {
            if ($counters['sent'] + 10 < $GLOBALS['original_num_per_batch']) {
                processQueueOutput($GLOBALS['I18N']->get('Less than batch size were sent, so reloading imminently'), 1, 'progress');
                $counters['delaysend'] = 10;
            } else {
                $counters['delaysend'] = (int) ($batch_period - $totaltime);
                $delaytime = 30;
                ## actually with the iframe we can reload fairly quickly
                processQueueOutput(s('Waiting for %d seconds before reloading', $delaytime), 1, 'progress');
            }
        }
        $counters['delaysend'] = (int) ($batch_period - $totaltime);
        if (empty($GLOBALS['inRemoteCall']) && empty($GLOBALS['commandline'])) {
            sleep($delaytime);
            printf('<script type="text/javascript">
          document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d%s";
        </script></body></html>', $reload, $counters['sent'], $notsent, addCsrfGetToken());
        }
    } elseif ($script_stage == 6 || $nothingtodo) {
        foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
            $plugin->messageQueueFinished();
        }
        processQueueOutput($GLOBALS['I18N']->get('Finished, All done'), 0);
        print '<script type="text/javascript">
      var parentJQuery = window.parent.jQuery;
      window.parent.allDone("' . s('All done') . '");
      </script>';
    } else {
        processQueueOutput(s('Script finished, but not all messages have been sent yet.'));
    }
    if (!empty($GLOBALS['inRemoteCall'])) {
        ob_end_clean();
        print outputCounters();
        @ob_start();
    }
    if (empty($GLOBALS['inRemoteCall']) && empty($GLOBALS['commandline']) && empty($_GET['ajaxed'])) {
        return;
    } elseif (!empty($GLOBALS['inRemoteCall']) || !empty($GLOBALS['commandline'])) {
        @ob_end_clean();
    }
    exit;
}
Exemplo n.º 13
0
    //lock
    put_lock($connection, "googlockusers", "read");
    $temp = mysql_query($sql_query, $connection) or die("ss");
    remove_lock($connection);
    //unlock
    $no2 = mysql_fetch_array($temp);
    $no = mysql_real_escape_string($no2[completed]);
    //sessionno holds the next question no
    $no = $no + 1;
    $sql_query = "select answer from googlockquestions WHERE no='{$no}'";
    $temp = mysql_query($sql_query, $connection) or die("asdas");
    $corr_ans = mysql_fetch_array($temp);
    $corr_ans2 = strtolower($corr_ans[answer]);
    //echo "no: $no ;$corr_ans2 and $answer and $_POST[answer]";
    $corr_ans2 = explode(";", $corr_ans2);
    $counter = count($corr_ans2) - 1;
    for (; $counter >= 0; $counter -= 1) {
        if (strcmp($corr_ans2[$counter], $answer) == 0) {
            update($connection, $username);
            incrementscore($connection, $username);
            storetimestamp($connection, $username);
            break;
        }
    }
    finish($connection);
    if ($counter == -1) {
        header("Location:play.php?attempt=incorrect");
    } else {
        header("Location: play.php");
    }
}
Exemplo n.º 14
0
        die;
    }
    # is it a valid email?
    if (!$email || $email == "" || !eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,6}\$", $email) || strrpos($email, ' ') > 0) {
        $error = "Invalid email address!";
        Header("Location: init.php?error={$error}&uname={$uname}&fname={$fname}&lname={$lname}&email={$email}");
        die;
    }
    # is it a valid username?
    if (!$uname || $uname == "" || ereg("[^a-zA-Z0-9_-]", $uname) || is_numeric($uname[0])) {
        $error = "Invalid username!";
        Header("Location: init.php?error={$error}&uname={$uname}&fname={$fname}&lname={$lname}&email={$email}");
        die;
    }
    # cypher pwd
    $pwd = md5($pwd1);
    # set privs at 0 (root)
    $privs = 0;
    # insert into db
    sql_query("insert into jones_user values (NULL, '{$uname}', '{$pwd}', '{$fname}', '{$lname}', '{$email}', '{$privs}')", $dbi);
    sql_query("update jones_site set title='{$title}', sitename='{$sitename}', topname='{$topname}', logo='{$logo}', theme='{$theme}'", $dbi);
    Header("Location: index.php");
}
switch ($_GET["cmd"]) {
    case "finish":
        finish($_POST["uname"], $_POST["fname"], $_POST["lname"], $_POST["pwd1"], $_POST["pwd2"], $_POST["email"], $_POST["title"], $_POST["sitename"], $_POST["topname"], $_POST["logo"], $_POST["theme"]);
        break;
    default:
        main($_GET["error"], $_GET["uname"], $_GET["fname"], $_GET["lname"], $_GET["email"], $_GET["title"], $_GET["sitename"], $_GET["topname"], $_GET["logo"], $_GET["theme"]);
        break;
}
Exemplo n.º 15
0
 /**
  * Called when new data received
  * @see http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#page-16
  * @return void
  */
 public function onRead()
 {
     if ($this->state === self::STATE_PREHANDSHAKE) {
         if (!$this->handshake()) {
             return;
         }
     }
     if ($this->state === self::STATE_HANDSHAKED) {
         while (($buflen = $this->getInputLength()) >= 2) {
             $first = ord($this->look(1));
             // first byte integer (fin, opcode)
             $firstBits = decbin($first);
             $opcode = (int) bindec(substr($firstBits, 4, 4));
             if ($opcode === 0x8) {
                 // CLOSE
                 $this->finish();
                 return;
             }
             $opcodeName = isset(static::$opcodes[$opcode]) ? static::$opcodes[$opcode] : false;
             if (!$opcodeName) {
                 Daemon::log(get_class($this) . ': Undefined opcode ' . $opcode);
                 $this->finish();
                 return;
             }
             $second = ord($this->look(1, 1));
             // second byte integer (masked, payload length)
             $fin = (bool) ($first >> 7);
             $isMasked = (bool) ($second >> 7);
             $dataLength = $second & 0x7f;
             $p = 2;
             if ($dataLength === 0x7e) {
                 // 2 bytes-length
                 if ($buflen < $p + 2) {
                     return;
                     // not enough data yet
                 }
                 $dataLength = Binary::bytes2int($this->look(2, $p), false);
                 $p += 2;
             } elseif ($dataLength === 0x7f) {
                 // 8 bytes-length
                 if ($buflen < $p + 8) {
                     return;
                     // not enough data yet
                 }
                 $dataLength = Binary::bytes2int($this->look(8, $p));
                 $p += 8;
             }
             if ($this->pool->maxAllowedPacket <= $dataLength) {
                 // Too big packet
                 $this > finish();
                 return;
             }
             if ($isMasked) {
                 if ($buflen < $p + 4) {
                     return;
                     // not enough data yet
                 }
                 $mask = $this->look(4, $p);
                 $p += 4;
             }
             if ($buflen < $p + $dataLength) {
                 return;
                 // not enough data yet
             }
             $this->drain($p);
             $data = $this->read($dataLength);
             if ($isMasked) {
                 $data = $this->mask($data, $mask);
             }
             //Daemon::log(Debug::dump(array('ext' => $this->extensions, 'rsv1' => $firstBits[1], 'data' => Debug::exportBytes($data))));
             /*if ($firstBits[1] && in_array('deflate-frame', $this->extensions)) { // deflate frame
             			$data = gzuncompress($data, $this->pool->maxAllowedPacket);
             		}*/
             if (!$fin) {
                 $this->framebuf .= $data;
             } else {
                 $this->onFrame($this->framebuf . $data, $opcodeName);
                 $this->framebuf = '';
             }
         }
     }
 }
Exemplo n.º 16
0
    if (strlen($pwd1) > 0 || strlen($pwd2) > 0) {
        # do the passwords differ?
        if (strcmp($pwd1, $pwd2) != 0) {
            $error = "The two passwords provided differ!";
            Header("Location: user.php?error={$error}&uid={$uid}&uname={$uname}&fname={$fname}&lname={$lname}&email={$email}");
            die;
        }
        # is the pwd longer than 6 chars?
        if (strlen($pwd1) < 6) {
            $error = "Password cannot be shorter than 6 chars!";
            Header("Location: user.php?error={$error}&uid={$uid}&uname={$uname}&fname={$fname}&lname={$lname}&email={$email}");
            die;
        }
        # cypher pwd
        $pwd = md5($pwd1);
        sql_query("update jones_user set pwd='{$pwd}', fname='{$fname}', lname='{$lname}', email='{$email}' where id='{$uid}'", $dbi);
        list($privs) = sql_fetch_row(sql_query("select privs from jones_user where id='{$uid}'", $dbi), $dbi);
        sendCookie($uid, $uname, $pwd, $fname, $lname, $email, $privs);
    } else {
        sql_query("update jones_user set fname='{$fname}', lname='{$lname}', email='{$email}' where id='{$uid}'", $dbi);
    }
    Header("Location: index.php");
}
switch ($_POST['cmd']) {
    case "finish":
        finish($_POST['uid'], $_POST['uname'], $_POST['pwd1'], $_POST['pwd2'], $_POST['fname'], $_POST['lname'], $_POST['email']);
        break;
    default:
        main($_GET['error'], $_GET['uid'], $_GET['uname'], $_GET['fname'], $_GET['lname'], $_GET['email']);
        break;
}
Exemplo n.º 17
0
    }
} else {
    finish(false);
}
if (!empty($_POST['agent_id'])) {
    $agent_id = filter_input(INPUT_POST, 'agent_id');
} else {
    $indicator = false;
    finish($indicator);
}
/**
 * Insert the data into the database, and check if insert was successful.
 */
$insert = $db->prepare('UPDATE properties SET address = ?, agent_id = ?, matterport_link = ?, 
                        realestate_link = ?, googlemaps_link = ?, agent_id = ?
                        WHERE id = ?');
$insert->bind_param('sissssi', $address, $agent_id, $matterport_link, $realestate_link, $googlemaps_link, $agent_id, $id);
if ($insert->execute()) {
    finish(true);
} else {
    finish(false);
}
/**
 * Once validation and entry is complete, data is left blank, or invalid data is input,
 * return the indicator to show whether input was a success or not.
 */
function finish($indicator)
{
    echo $indicator;
    exit;
}
             // Editing
             // Group changes together
             forum_utils::start_transaction();
             // 1. Edit post if applicable
             if ($ispost) {
                 $post->edit(stripslashes($fromform->subject), stripslashes($fromform->message), $fromform->format, $deleteattachments, $attachments, !empty($fromform->setimportant), !empty($fromform->mailnow));
             }
             // 2. Edit discussion settings if applicable
             if ($isdiscussion) {
                 $discussion = $post->get_discussion();
                 $groupid = isset($fromform->group) ? $fromform->group : $discussion->get_group_id();
                 $discussion->edit_settings($groupid, $fromform->timestart, $fromform->timeend, $discussion->is_locked(), !empty($fromform->sticky));
             }
             forum_utils::finish_transaction();
             // Redirect to view discussion
             finish($post->get_id(), $cloneid, 'discuss.php?' . $post->get_discussion()->get_link_params(forum::PARAM_PLAIN) . '#p' . $post->get_id(), $fromform, $uploadfolder);
         }
     }
 } else {
     if ($ajax) {
         // If this is an AJAX request we can't go printing the form, this
         // must be an error
         header('Content-Type: text/plain', true, 500);
         print 'Form redisplay attempt';
         exit;
     }
     $navigation = array();
     // Include link to discussion except when creating new discussion
     if (!$isdiscussion || $edit) {
         $navigation[] = array('name' => shorten_text(htmlspecialchars($discussion->get_subject())), 'link' => $discussion->get_url(forum::PARAM_HTML), 'type' => 'forumng');
     }
Exemplo n.º 19
0
}
if ($mysqli->connect_errno) {
    $ret = "未能连接到数据库 (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    finish($ret);
}
$event = $mysqli->real_escape_string($event);
$students = array();
if ($res = $mysqli->query("SELECT DISTINCT(name) FROM time LEFT JOIN students ON students.ID = time.student_id WHERE event = '{$event}'")) {
    while ($row = $res->fetch_assoc()) {
        $students[$row['name']] = true;
    }
} else {
    finish("查询失败!");
}
$map = array();
for ($i = 1; $i <= 8; ++$i) {
    $temp = array();
    for ($j = 1; $j <= 13; ++$j) {
        $temp[] = $students;
    }
    $map[] = $temp;
}
if ($res = $mysqli->query("SELECT * FROM time LEFT JOIN students ON students.ID = time.student_id WHERE event = '{$event}'")) {
    while ($row = $res->fetch_assoc()) {
        $map[$row['day']][$row['item']][$row['name']] = false;
    }
} else {
    finish("查询失败!");
}
echo json_encode($map);
$mysqli->close();
Exemplo n.º 20
0
function getpage($url)
{
    global $headers, $out, $post_vars, $proxy_variables, $referer;
    $urlobj = new aurl($url);
    $query = $urlobj->get_query();
    $requrl = $urlobj->get_path() . $urlobj->get_file() . (!empty($query) ? "?{$query}" : null);
    $http_auth = null;
    if (extension_loaded('apache')) {
        $fail = false;
        $cheaders = getallheaders();
        $http_auth = $reqarray['Authorization'];
    } else {
        $fail = true;
    }
    $authorization = $fail ? $_SERVER['HTTP_AUTHORIZATION'] : $cheaders['Authorization'];
    $cache_control = $fail ? $_SERVER['HTTP_CACHE_CONTROL'] : $cheaders['Cache-Control'];
    $if_modified = $fail ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : $cheaders['If-Modified-Since'];
    $if_none_match = $fail ? $_SERVER['HTTP_IF_NONE_MATCH'] : $cheaders['If-None-Match'];
    if ($fail) {
        if (!empty($authorization)) {
            $http_auth = $authorization;
        } elseif (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
            $http_auth = 'Basic ' . base64_encode("{$_SERVER['PHP_AUTH_USER']}:{$_SERVER['PHP_AUTH_PW']}");
        } elseif (!empty($_SERVER['PHP_AUTH_DIGEST'])) {
            $http_auth = "Digest {$_SERVER['PHP_AUTH_DIGEST']}";
        }
    }
    if (PIP != null && PPORT != null) {
        $servername = PIP;
        $ipaddress = get_check(PIP);
        $portval = PPORT;
        $requrl = $urlobj->get_url(false);
    } else {
        $servername = $urlobj->get_servername();
        $ipaddress = ($urlobj->get_proto() == 'ssl' || $urlobj->get_proto() == 'https' ? 'ssl://' : null) . get_check($servername);
        $portval = $urlobj->get_portval();
    }
    $out = "{$_SERVER['REQUEST_METHOD']} " . str_replace(' ', '%20', $requrl) . " HTTP/1.1\r\nHost: " . $urlobj->get_servername() . ($portval != 80 && ($urlobj->get_proto() == 'https' ? $portval != 443 : true) ? ":{$portval}" : null) . "\r\n";
    global $useragent;
    $useragent = null;
    if ($_COOKIE[COOK_PREF . '_useragent'] != '-1') {
        $useragent = $_COOKIE[COOK_PREF . '_useragent'];
        if (empty($useragent)) {
            $useragent = $_SERVER['HTTP_USER_AGENT'];
        }
        $useragent_cook = $useragent == 1 ? $_COOKIE[COOK_PREF . '_useragenttext'] : $useragent;
        if (!empty($useragent_cook)) {
            $out .= "User-Agent: {$useragent_cook}\r\n";
        }
    }
    if (!empty($http_auth)) {
        $out .= "Authorization: {$http_auth}\r\n";
    }
    if (empty($_COOKIE[COOK_PREF . '_remove_referer']) && !empty($referer)) {
        $out .= 'Referer: ' . str_replace(' ', '+', $referer) . "\r\n";
    }
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $out .= 'Content-Length: ' . strlen($post_vars) . "\r\nContent-Type: application/x-www-form-urlencoded\r\n";
    }
    $cook_prefdomain = preg_replace('/^www\\./i', null, $urlobj->get_servername());
    #*
    $cook_prefix = str_replace('.', '_', $cook_prefdomain) . COOKIE_SEPARATOR;
    if (count($_COOKIE) > 0 && empty($_COOKIE[COOK_PREF . '_remove_cookies'])) {
        $addtoout = null;
        reset($_COOKIE);
        while (list($key, $val) = each($_COOKIE)) {
            if (ENCRYPT_COOKS) {
                $key = proxdec($key);
                $val = proxdec($val);
                #urldecode($val));
            }
            if (str_replace(COOKIE_SEPARATOR, null, $key) == $key) {
                continue;
            }
            #$cook_domain=preg_replace('/^(.*'.COOKIE_SEPARATOR.').*$/','\1',$key); #**
            $cook_domain = substr($key, 0, strpos($key, COOKIE_SEPARATOR)) . COOKIE_SEPARATOR;
            if (substr($cook_prefix, strlen($cook_prefix) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $key = substr($key, strlen($cook_domain), strlen($key) - strlen($cook_domain));
            if (!in_array($key, $proxy_variables)) {
                $addtoout .= " {$key}={$val};";
            }
        }
        if (!empty($addtoout)) {
            $addtoout .= "\r\n";
            $out .= "Cookie:{$addtoout}";
        }
    }
    $out .= "Accept: */*;q=0.1\r\n" . (GZIP_PROXY_SERVER ? "Accept-Encoding: gzip\r\n" : null) . "Connection: close\r\n" . ($cache_control != null ? "Cache-Control: {$cache_control}\r\n" : null) . ($if_modified != null ? "If-Modified-Since: {$if_modified}\r\n" : null) . ($if_none_match != null ? "If-None-Match: {$if_none_match}\r\n" : null) . "\r\n{$post_vars}";
    // This part ignores any "SSL: fatal protocol error" errors, and makes sure other errors are still triggered correctly
    function errorHandle($errno, $errmsg)
    {
        if ($errno <= E_PARSE && ($errno != E_WARNING || substr($errmsg, -25) != 'SSL: fatal protocol error')) {
            restore_error_handler();
            trigger_error($errmsg, $errno << 8);
            set_error_handler('errorHandle');
        }
    }
    set_error_handler('errorHandle');
    $fp = @fsockopen($ipaddress, $portval, $errno, $errval, 5) or havok(6, $servername, $portval);
    stream_set_timeout($fp, 5);
    # for persistent connections, this may be necessary
    /*
    $ub=stream_get_meta_data($fp);
    $ub=$ub['unread_bytes'];
    if($ub>0) fread($fp,$ub);
    */
    fwrite($fp, $out);
    $response = '100';
    while ($response == '100') {
        $responseline = fgets($fp, 8192);
        $response = substr($responseline, 9, 3);
        $headers = array();
        while ($curline != "\r\n" && ($curline = fgets($fp, 8192))) {
            $harr = explode(':', $curline, 2);
            $headers[strtolower($harr[0])][] = trim($harr[1]);
        }
    }
    #if($headers['pragma'][0]==null) header('Pragma: public');
    #if($headers['cache-control'][0]==null) header('Cache-Control: public');
    #if($headers['last-modified'][0]==null && $headers['expires']==null) header('Expires: '.date('D, d M Y H:i:s e',time()+86400));
    # read and store cookies
    if (empty($_COOKIE[COOK_PREF . '_remove_cookies'])) {
        for ($i = 0; $i < count($headers['set-cookie']); $i++) {
            $thiscook = explode('=', $headers['set-cookie'][$i], 2);
            if (!strpos($thiscook[1], ';')) {
                $thiscook[1] .= ';';
            }
            $cook_val = substr($thiscook[1], 0, strpos($thiscook[1], ';'));
            $cook_domain = preg_replace('/^.*domain=[	 ]*\\.?([^;]+).*?$/i', '\\1', $thiscook[1]);
            #*
            if ($cook_domain == $thiscook[1]) {
                $cook_domain = $cook_prefdomain;
            } elseif (substr($cook_prefdomain, strlen($cook_prefdomain) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $cook_name = str_replace('.', '_', $cook_domain) . COOKIE_SEPARATOR . $thiscook[0];
            if (ENCRYPT_COOKS) {
                $cook_name = proxenc($cook_name);
                $cook_val = proxenc($cook_val);
            }
            dosetcookie($cook_name, $cook_val);
        }
    }
    if ($response[0] == '3' && $response[1] == '0' && $response[2] != '4') {
        $urlobj = new aurl($url);
        $redirurl = framify_url(surrogafy_url($headers['location'][0], $urlobj), NEW_PAGETYPE_FRAMED_PAGE);
        fclose($fp);
        restore_error_handler();
        finish_noexit();
        header("Location: {$redirurl}");
        exit;
    }
    $oheaders = $headers;
    $oheaders['location'] = $oheaders['content-length'] = $oheaders['content-encoding'] = $oheaders['set-cookie'] = $oheaders['transfer-encoding'] = $oheaders['connection'] = $oheaders['keep-alive'] = $oheaders['pragma'] = $oheaders['cache-control'] = $oheaders['expires'] = null;
    while (list($key, $val) = each($oheaders)) {
        if (!empty($val[0])) {
            header("{$key}: {$val[0]}");
        }
    }
    unset($oheaders);
    header("Status: {$response}");
    if (substr($headers['content-type'][0], 0, 4) == 'text' || substr($headers['content-type'][0], 0, 24) == 'application/x-javascript') {
        $justoutput = false;
        $justoutputnow = false;
    } else {
        $justoutputnow = $headers['content-encoding'][0] == 'gzip' ? false : true;
        $justoutput = true;
    }
    if ($headers['transfer-encoding'][0] == 'chunked') {
        $body = null;
        $chunksize = null;
        while ($chunksize !== 0) {
            $chunksize = intval(fgets($fp, 8192), 16);
            $bufsize = $chunksize;
            while ($bufsize >= 1) {
                $chunk = fread($fp, $bufsize);
                if ($justoutputnow) {
                    echo $chunk;
                } else {
                    $body .= $chunk;
                }
                $bufsize -= strlen($chunk);
            }
            fread($fp, 2);
        }
    } else {
        if (function_exists('stream_get_contents')) {
            if ($justoutputnow) {
                echo stream_get_contents($fp);
            } else {
                $body = stream_get_contents($fp);
            }
        } else {
            $body = null;
            while (true) {
                $chunk = fread($fp, 8192);
                if (empty($chunk)) {
                    break;
                }
                if ($justoutputnow) {
                    echo $chunk;
                } else {
                    $body .= $chunk;
                }
            }
        }
    }
    fclose($fp);
    restore_error_handler();
    if (GZIP_PROXY_SERVER && $headers['content-encoding'][0] == 'gzip') {
        $body = gzinflate(substr($body, 10));
    }
    if ($justoutput) {
        if (!$justoutputnow) {
            echo $body;
        }
        finish();
    }
    return array($body, $url, $cook_prefix);
}
Exemplo n.º 21
0
                 file_save_draft_area_files($fromform->attachments, $filecontext->id, 'mod_forumng', 'attachment', $post->get_id(), $fileoptions);
                 // itemid is not present when using text-only editor
                 if (!empty($fromform->message['itemid'])) {
                     $fromform->message['text'] = file_save_draft_area_files($fromform->message['itemid'], $filecontext->id, 'mod_forumng', 'message', $postid, $fileoptions, $fromform->message['text']);
                 }
                 $post->edit_finish($fromform->message['text'], $fromform->message['format'], $gotsubject);
             }
             // 2. Edit discussion settings if applicable
             if ($isdiscussion) {
                 $discussion = $post->get_discussion();
                 $groupid = isset($fromform->group) ? $fromform->group : $discussion->get_group_id();
                 $discussion->edit_settings($groupid, $fromform->timestart, $fromform->timeend, $discussion->is_locked(), !empty($fromform->sticky));
             }
             // Redirect to view discussion
             $transaction->allow_commit();
             finish($post->get_id(), $cloneid, 'discuss.php?' . $post->get_discussion()->get_link_params(mod_forumng::PARAM_PLAIN) . $expandparam . '#p' . $post->get_id(), $fromform);
         }
     }
 } else {
     if ($ajax) {
         // If this is an AJAX request we can't go printing the form, this
         // must be an error
         header('Content-Type: text/plain', true, 500);
         print 'Form redisplay attempt';
         exit;
     }
     $navigation = array();
     // Include link to discussion except when creating new discussion
     if (!$isdiscussion || $edit) {
         $PAGE->navbar->add(shorten_text(s($discussion->get_subject())), $discussion->get_url(mod_forumng::PARAM_HTML));
     }
Exemplo n.º 22
0
                  <td class="buttons" colspan="2">
                    <input type="submit" value="Submit" />
										<input type="reset" value="Reset" />
										<input type="hidden" name="cmd" value="finish" />
                  </td>
                </tr>
              </table>
            </fieldset>
          </form>
      </div>
      <div class="backLink">
        <a href="index.php">Back to Main Menu</a>
      </div>
    </div>
<?php 
    include 'footer.php';
}
function finish($title, $sitename, $topname, $logo, $theme, $homepage)
{
    global $dbi;
    sql_query("update jones_site set title='{$title}', sitename='{$sitename}', topname='{$topname}', logo='{$logo}', theme='{$theme}', homepage='{$homepage}'", $dbi);
    Header("Location: index.php");
}
switch ($_POST['cmd']) {
    case "finish":
        finish($_POST['title'], $_POST['sitename'], $_POST['topname'], $_POST['logo'], $_POST['theme'], $_POST['homepage']);
        break;
    default:
        main($_GET['error'], $_GET['title'], $_GET['sitename'], $_GET['topname'], $_GET['logo'], $_GET['theme'], $_GET['homepage']);
        break;
}
Exemplo n.º 23
0
    include 'footer.php';
}
function finish($uname, $pwd)
{
    global $dbi;
    $md5_pwd = md5($pwd);
    $l_result = sql_query("select * from jones_user where uname='{$uname}' and pwd='{$md5_pwd}'", $dbi);
    if (sql_num_rows($l_result, $dbi) == 0) {
        $error = "Incorrect username or password";
        Header("Location: login.php?error={$error}");
        die;
    }
    list($uid, $uname, $pwd, $fname, $lname, $email, $privs) = sql_fetch_row($l_result, $dbi);
    sendCookie($uid, $uname, $pwd, $fname, $lname, $email, $privs);
    Header("Location: index.php");
}
if (isset($_GET['cmd'])) {
    $cmd = $_GET['cmd'];
} else {
    if (isset($_POST['cmd'])) {
        $cmd = $_POST['cmd'];
    }
}
switch ($cmd) {
    case "finish":
        finish($_POST["uname"], $_POST["pwd"]);
        break;
    default:
        main($_GET["error"]);
        break;
}
Exemplo n.º 24
0
            $items = array('EN', 'FE', 'MA', 'AB', 'MY', 'JU', 'JL', 'AG', 'SE', 'OC', 'NO', 'DI');
            $result = array();
            for ($i = 0; $i < 12; $i++) {
                $result[] = ($j = array_search($items[$i], $keys)) !== false ? $result_raw[$j] : array($items[$i], 0);
            }
            break;
        case 4:
            $stmt->bind_param("sss", $_POST['mes'], $_POST['alcohol'], $_POST['cinturon']);
            if (!$stmt->execute()) {
                finish(htmlspecialchars($mainDB->error), $mainDB);
            }
            $stmt->bind_result($category, $tipo, $accidentes, $causa);
            $gender = array('SF', 'M', 'H', 'T');
            while ($stmt->fetch()) {
                $keys[] = $tipo;
                $result_raw[] = array(' ', array_search($category, $gender) + 1, $accidentes, nombreCausa($causa), $accidentes);
            }
            /*$items = array( 'FA', 'NF', 'SD'); // Esto es para poner en ceros los datos que no encuentre
              $result = array();
              for($i = 0; $i < 3; $i++) {
              $result[] = (($j = array_search($items[$i], $keys)) !== false)? $result_raw[$j] : 
                                              array(nombreTipo($items[$i]), 0, 0);
              }*/
            $result = $result_raw;
            break;
    }
    print json_encode($result);
} else {
    finish("Datos insuficientes", $mainDB);
}
$mainDB->close();
function my_shutdown()
{
    global $script_stage, $reload;
    #  output( "Script status: ".connection_status(),0); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774
    output($GLOBALS['I18N']->get('Script stage') . ': ' . $script_stage, 0);
    global $report, $send_process_id, $tables, $nothingtodo, $invalid, $processed, $failed_sent, $notsent, $sent, $unconfirmed, $num_per_batch, $batch_period, $num_users;
    $some = $processed;
    #$sent;# || $invalid || $notsent;
    if (!$some) {
        output($GLOBALS['I18N']->get('Finished, Nothing to do'), 0);
        $nothingtodo = 1;
    }
    $totaltime = $GLOBALS['processqueue_timer']->elapsed(1);
    $msgperhour = 3600 / $totaltime * $sent;
    if ($sent) {
        output(sprintf('%d %s %01.2f %s (%d %s)', $sent, $GLOBALS['I18N']->get('messages sent in'), $totaltime, $GLOBALS['I18N']->get('seconds'), $msgperhour, $GLOBALS['I18N']->get('msgs/hr')), $sent);
    }
    if ($invalid) {
        output(sprintf('%d %s', $invalid, $GLOBALS['I18N']->get('invalid emails')));
    }
    if ($failed_sent) {
        output(sprintf('%d %s', $failed_sent, $GLOBALS['I18N']->get('emails failed (will retry later)')));
    }
    if ($unconfirmed) {
        output(sprintf('%d %s', $unconfirmed, $GLOBALS['I18N']->get('emails unconfirmed (not sent)')));
    }
    releaseLock($send_process_id);
    finish("info", $report);
    if ($script_stage < 5 && !$nothingtodo) {
        output($GLOBALS['I18N']->get('Warning: script never reached stage 5') . "\n" . $GLOBALS['I18N']->get('This may be caused by a too slow or too busy server') . " \n");
    } elseif ($script_stage == 5 && (!$nothingtodo || $GLOBALS["wait"])) {
        # if the script timed out in stage 5, reload the page to continue with the rest
        $reload++;
        if (!$GLOBALS["commandline"] && $num_per_batch && $batch_period) {
            if ($sent + 10 < $GLOBALS["original_num_per_batch"] && !$GLOBALS["wait"]) {
                output($GLOBALS['I18N']->get('Less than batch size were sent, so reloading imminently'));
                $delaytime = 10000;
            } else {
                output(sprintf($GLOBALS['I18N']->get('Waiting for %d seconds before reloading'), $batch_period));
                $delaytime = $batch_period * 1000;
            }
            //output("Do not reload this page yourself, because the next batch would fail");
            printf('<script language="Javascript" type="text/javascript">
        function reload() {
          var query = window.location.search;
          query = query.replace(/&reload=\\d+/,"");
          query = query.replace(/&lastsent=\\d+/,"");
          query = query.replace(/&lastskipped=\\d+/,"");
          document.location = document.location.pathname + query + "&reload=%d&lastsent=%d&lastskipped=%d";
        }
        setTimeout("reload()",%d);
      </script>', $reload, $sent, $notsent, $delaytime);
        } else {
            printf('<script language="Javascript" type="text/javascript">
        var query = window.location.search;
        query = query.replace(/&reload=\\d+/,"");
        query = query.replace(/&lastsent=\\d+/,"");
        query = query.replace(/&lastskipped=\\d+/,"");
        document.location = document.location.pathname + query + "&reload=%d&lastsent=%d&lastskipped=%d";
      </script>', $reload, $sent, $notsent);
            output($GLOBALS['I18N']->get($processed < $num_users ? 'Reload required' : ''));
        }
        #  print '<script language="Javascript" type="text/javascript">alert(document.location)</script>';
    } elseif ($script_stage == 6 || $nothingtodo) {
        output($GLOBALS['I18N']->get('Finished, All done'), 0);
    } else {
        output($GLOBALS['I18N']->get('Script finished, but not all messages have been sent yet.'));
    }
    if (!$GLOBALS['commandline']) {
        include_once "footer.inc";
    }
    exit;
}
Exemplo n.º 26
0
function remove($main_array, $file, $remove_index, $message = null, $finish = true)
{
    unset($main_array[$remove_index]);
    $main_array = array_values($main_array);
    if ($finish) {
        finish($main_array, $file, $message);
    }
    return $main_array;
}
Exemplo n.º 27
0
        $_SESSION['phpCAS']['service_cookies'] = array();
    }
    $sm = $_SESSION['ovd-client']['sessionmanager'];
    foreach ($sm->get_cookies() as $k => $v) {
        $cookie = array('domain' => parse_url($sm->get_base_url(), PHP_URL_HOST), 'path' => '/', 'secure' => false, 'name' => $k, 'value' => $v);
        $_SESSION['phpCAS']['service_cookies'][] = $cookie;
    }
}
$port = parse_url($CAS_server_url, PHP_URL_PORT);
if (is_null($port)) {
    if (parse_url($CAS_server_url, PHP_URL_SCHEME) == 'https') {
        $port = 443;
    } else {
        $port = 80;
    }
}
$path = !parse_url($CAS_server_url, PHP_URL_PATH) ? '' : parse_url($CAS_server_url, PHP_URL_PATH);
phpCAS::proxy(CAS_VERSION_2_0, parse_url($CAS_server_url, PHP_URL_HOST), $port, $path, false);
phpCAS::setNoCasServerValidation();
phpCAS::setPGTStorageFile(CAS_PGT_STORAGE_FILE_FORMAT_PLAIN, session_save_path());
phpCAS::setFixedCallbackURL($CAS_callback_url);
//HTTPS required, and Apache's CRT must be added in Tomcat's keystore (CAS server)
phpCAS::forceAuthentication();
if (!phpCAS::serviceWeb($_SESSION['ovd-client']['sessionmanager_url'] . '/start', $errno, $output)) {
    $_SESSION['ovd-client']['from_SM_start_XML'] = 'ERROR';
    finish();
    die;
}
$_SESSION['ovd-client']['from_SM_start_XML'] = $output;
finish();
die;
Exemplo n.º 28
0
function getpage($url)
{
    global $CONFIG, $OPTIONS, $headers, $out, $proxy_variables, $referer;
    # Generate HTTP packet content {{{
    $content = null;
    $is_formdata = substr($_SERVER['CONTENT_TYPE'], 0, 19) == 'multipart/form-data';
    # Generate for multipart & handle file uploads {{{
    if ($is_formdata) {
        $strnum = null;
        for ($i = 0; $i < 29; $i++) {
            $strnum .= rand(0, 9);
        }
        $boundary = "---------------------------{$strnum}";
        # parse POST variables
        while (list($key, $val) = each($_POST)) {
            if (!is_array($val)) {
                $content .= "--{$boundary}\r\n" . "Content-Disposition: form-data; name=\"{$key}\"\r\n" . "\r\n{$val}\r\n";
            } else {
                while (list($key2, $val2) = each($val)) {
                    $content .= "--{$boundary}\r\n" . "Content-Disposition: form-data; name=\"{$key}[]\"\r\n" . "\r\n{$val2}\r\n";
                }
            }
        }
        # parse uploaded files
        while (list($key, $val) = each($_FILES)) {
            if (!is_array($val['name'])) {
                $fcont = file_get_contents($val['tmp_name']);
                @unlink($val['tmp_name']);
                $content .= "--{$boundary}\r\n" . "Content-Disposition: form-data; name=\"{$key}\"; " . "filename=\"{$val['name']}\"\r\n" . "Content-Type: {$val['type']}\r\n" . "\r\n{$fcont}\r\n";
            } else {
                for ($i = 0; $i < count($val['name']); $i++) {
                    $fcont = file_get_contents($val['tmp_name'][$i]);
                    @unlink($val['tmp_name'][$i]);
                    $content .= "--{$boundary}\r\n" . "Content-Disposition: form-data; name=\"{$key}[]\"; " . "filename=\"{$val['name'][$i]}\"\r\n" . "Content-Type: {$val['type'][$i]}\r\n" . "\r\n{$fcont}\r\n";
                }
            }
        }
        $content .= "--{$boundary}--\r\n";
    } else {
        $postkeys = array_keys($_POST);
        foreach ($postkeys as $postkey) {
            if (!in_array($postkey, $proxy_variables)) {
                if (!is_array($_POST[$postkey])) {
                    $content .= ($content != null ? '&' : null) . httpclean($postkey) . '=' . httpclean($_POST[$postkey]);
                } else {
                    foreach ($_POST[$postkey] as $postval) {
                        $content .= ($content != null ? '&' : null) . httpclean($postkey) . '%5B%5D=' . httpclean($postval);
                    }
                }
            }
        }
    }
    # }}}
    # }}}
    # URL setup {{{
    $urlobj = new aurl($url);
    # don't access SSL sites unless the proxy is being accessed through SSL too
    if ($urlobj->get_proto() == 'https' && $CONFIG['PROTO'] != 'https' && (!is_array($_SESSION['ssl_domains']) || is_array($_SESSION['ssl_domains']) && !in_array($urlobj->get_servername(), $_SESSION['ssl_domains']))) {
        # ignore certain file types from worrying about this
        $skip = false;
        foreach ($CONFIG['SSL_WARNING_IGNORE_FILETYPES'] as $filetype) {
            if (substr($urlobj->get_file(), -strlen($filetype)) == $filetype) {
                $skip = true;
            }
        }
        if (!$skip) {
            havok(8, $urlobj->get_servername());
        }
    }
    # get request URL
    $query = $urlobj->get_query();
    $requrl = $urlobj->get_path() . $urlobj->get_file() . (!empty($query) ? "?{$query}" : null);
    # }}}
    # HTTP Authorization and Cache stuff {{{
    $http_auth = null;
    if (extension_loaded('apache')) {
        $fail = false;
        $cheaders = getallheaders();
        $http_auth = $reqarray['Authorization'];
    } else {
        $fail = true;
    }
    $authorization = $fail ? $_SERVER['HTTP_AUTHORIZATION'] : $cheaders['Authorization'];
    $cache_control = $fail ? $_SERVER['HTTP_CACHE_CONTROL'] : $cheaders['Cache-Control'];
    $if_modified = $fail ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : $cheaders['If-Modified-Since'];
    $if_none_match = $fail ? $_SERVER['HTTP_IF_NONE_MATCH'] : $cheaders['If-None-Match'];
    if ($fail) {
        if (!empty($authorization)) {
            $http_auth = $authorization;
        } elseif (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
            $http_auth = 'Basic ' . base64_encode("{$_SERVER['PHP_AUTH_USER']}:{$_SERVER['PHP_AUTH_PW']}");
        } elseif (!empty($_SERVER['PHP_AUTH_DIGEST'])) {
            $http_auth = "Digest {$_SERVER['PHP_AUTH_DIGEST']}";
        }
    }
    # }}}
    # HTTP packet construction {{{
    # figure out what we are connecting to
    if ($OPTIONS['TUNNEL_IP'] != null && $OPTIONS['TUNNEL_PORT'] != null) {
        $servername = $OPTIONS['TUNNEL_IP'];
        $ipaddress = get_check($servername);
        $portval = $OPTIONS['TUNNEL_PORT'];
        $requrl = $urlobj->get_url(false);
    } else {
        $servername = $urlobj->get_servername();
        $ipaddress = ($urlobj->get_proto() == 'ssl' || $urlobj->get_proto() == 'https' ? 'ssl://' : null) . get_check($servername);
        $portval = $urlobj->get_portval();
    }
    # begin packet construction
    $out = ($content == null ? 'GET' : 'POST') . ' ' . str_replace(' ', '%20', $requrl) . " HTTP/1.1\r\n" . "Host: " . $urlobj->get_servername() . ($portval != 80 && ($urlobj->get_proto() == 'https' ? $portval != 443 : true) ? ":{$portval}" : null) . "\r\n";
    # user agent and auth headers
    global $useragent;
    $useragent = null;
    if ($OPTIONS['USER_AGENT'] != '-1') {
        $useragent = $OPTIONS['USER_AGENT'];
        if (empty($useragent)) {
            $useragent = $_SERVER['HTTP_USER_AGENT'];
        }
        if (!empty($useragent)) {
            $out .= "User-Agent: {$useragent}\r\n";
        }
    }
    if (!empty($http_auth)) {
        $out .= "Authorization: {$http_auth}\r\n";
    }
    # referer headers
    if (!$OPTIONS['REMOVE_REFERER'] && !empty($referer)) {
        $out .= 'Referer: ' . str_replace(' ', '+', $referer) . "\r\n";
    }
    # POST headers
    if ($content != null) {
        $out .= 'Content-Length: ' . strlen($content) . "\r\n" . 'Content-Type: ' . ($is_formdata ? "multipart/form-data; boundary={$boundary}" : 'application/x-www-form-urlencoded') . "\r\n";
    }
    # cookie headers
    $cook_prefdomain = preg_replace('/^www\\./i', null, $urlobj->get_servername());
    #*
    $cook_prefix = str_replace('.', '_', $cook_prefdomain) . COOKIE_SEPARATOR;
    if (!$OPTIONS['REMOVE_COOKIES'] && count($_COOKIE) > 0) {
        $addtoout = null;
        reset($_COOKIE);
        while (list($key, $val) = each($_COOKIE)) {
            if ($key[0] != '~' && strtolower(substr($key, 0, 3)) != '%7e' && str_replace(COOKIE_SEPARATOR, null, $key) == $key) {
                continue;
            }
            if ($OPTIONS['ENCRYPT_COOKIES']) {
                $key = proxdec($key);
                $val = proxdec($val);
            }
            $cook_domain = substr($key, 0, strpos($key, COOKIE_SEPARATOR)) . COOKIE_SEPARATOR;
            if (substr($cook_prefix, strlen($cook_prefix) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $key = substr($key, strlen($cook_domain), strlen($key) - strlen($cook_domain));
            if (!in_array($key, $proxy_variables)) {
                $addtoout .= " {$key}={$val};";
            }
        }
        if (!empty($addtoout)) {
            $addtoout .= "\r\n";
            $out .= "Cookie:{$addtoout}";
        }
    }
    # final packet headers and content
    $out .= "Accept: */*;q=0.1\r\n" . ($CONFIG['GZIP_PROXY_SERVER'] ? "Accept-Encoding: gzip\r\n" : null) . "Connection: close\r\n" . ($cache_control != null ? "Cache-Control: {$cache_control}\r\n" : null) . ($if_modified != null ? "If-Modified-Since: {$if_modified}\r\n" : null) . ($if_none_match != null ? "If-None-Match: {$if_none_match}\r\n" : null) . "\r\n{$content}";
    # }}}
    # Ignore SSL errors {{{
    # This part ignores any "SSL: fatal protocol error" errors, and makes sure
    # other errors are still triggered correctly
    function errorHandle($errno, $errmsg)
    {
        if ($errno <= E_PARSE && ($errno != E_WARNING || substr($errmsg, -25) != 'SSL: fatal protocol error')) {
            restore_error_handler();
            trigger_error($errmsg, $errno << 8);
            set_error_handler('errorHandle');
        }
    }
    set_error_handler('errorHandle');
    # }}}
    # Send HTTP Packet {{{
    $fp = @fsockopen($ipaddress, $portval, $errno, $errval, 5) or havok(6, $servername, $portval);
    stream_set_timeout($fp, 5);
    # for persistent connections, this may be necessary
    /*
    $ub=stream_get_meta_data($fp);
    $ub=$ub['unread_bytes'];
    if($ub>0) fread($fp,$ub);
    */
    fwrite($fp, $out);
    # }}}
    # Retrieve and Parse response headers {{{
    $response = '100';
    while ($response == '100') {
        $responseline = fgets($fp, 8192);
        $response = substr($responseline, 9, 3);
        $headers = array();
        while ($curline != "\r\n" && ($curline = fgets($fp, 8192))) {
            $harr = explode(':', $curline, 2);
            $headers[strtolower($harr[0])][] = trim($harr[1]);
        }
    }
    //if($headers['pragma'][0]==null) header('Pragma: public');
    //if($headers['cache-control'][0]==null) header('Cache-Control: public');
    //if($headers['last-modified'][0]==null && $headers['expires']==null)
    //	header('Expires: '.date('D, d M Y H:i:s e',time()+86400));
    # read and store cookies
    if (!$OPTIONS['REMOVE_COOKIES']) {
        for ($i = 0; $i < count($headers['set-cookie']); $i++) {
            $thiscook = explode('=', $headers['set-cookie'][$i], 2);
            if (!strpos($thiscook[1], ';')) {
                $thiscook[1] .= ';';
            }
            $cook_val = substr($thiscook[1], 0, strpos($thiscook[1], ';'));
            $cook_domain = preg_replace('/^.*domain=[	 ]*\\.?([^;]+).*?$/i', '\\1', $thiscook[1]);
            #*
            if ($cook_domain == $thiscook[1]) {
                $cook_domain = $cook_prefdomain;
            } elseif (substr($cook_prefdomain, strlen($cook_prefdomain) - strlen($cook_domain), strlen($cook_domain)) != $cook_domain) {
                continue;
            }
            $cook_name = str_replace('.', '_', $cook_domain) . COOKIE_SEPARATOR . $thiscook[0];
            if ($OPTIONS['ENCRYPT_COOKIES']) {
                $cook_name = proxenc($cook_name);
                $cook_val = proxenc($cook_val);
            }
            dosetcookie($cook_name, $cook_val);
        }
    }
    # page redirected, send it back to the user
    if ($response[0] == '3' && $response[1] == '0' && $response[2] != '4') {
        $urlobj = new aurl($url);
        $redirurl = framify_url(surrogafy_url($headers['location'][0], $urlobj), NEW_PAGETYPE_FRAMED_PAGE);
        fclose($fp);
        restore_error_handler();
        finish_noexit();
        header("Location: {$redirurl}");
        exit;
    }
    # parse the rest of the headers
    $oheaders = $headers;
    $oheaders['location'] = $oheaders['content-length'] = $oheaders['content-encoding'] = $oheaders['set-cookie'] = $oheaders['transfer-encoding'] = $oheaders['connection'] = $oheaders['keep-alive'] = $oheaders['pragma'] = $oheaders['cache-control'] = $oheaders['expires'] = null;
    while (list($key, $val) = each($oheaders)) {
        if (!empty($val[0])) {
            header("{$key}: {$val[0]}");
        }
    }
    unset($oheaders);
    header("Status: {$response}");
    # }}}
    # Retrieve content {{{
    if (substr($headers['content-type'][0], 0, 4) == 'text' || substr($headers['content-type'][0], 0, 22) == 'application/javascript' || substr($headers['content-type'][0], 0, 24) == 'application/x-javascript') {
        $justoutput = false;
        $justoutputnow = false;
    } else {
        $justoutputnow = $headers['content-encoding'][0] == 'gzip' ? false : true;
        $justoutput = true;
    }
    # Transfer-Encoding: chunked
    if ($headers['transfer-encoding'][0] == 'chunked') {
        $body = null;
        $chunksize = null;
        while ($chunksize !== 0) {
            $chunksize = intval(fgets($fp, 8192), 16);
            $bufsize = $chunksize;
            while ($bufsize >= 1) {
                $chunk = fread($fp, $bufsize);
                if ($justoutputnow) {
                    echo $chunk;
                } else {
                    $body .= $chunk;
                }
                $bufsize -= strlen($chunk);
            }
            fread($fp, 2);
        }
    } else {
        if (function_exists('stream_get_contents')) {
            if ($justoutputnow) {
                echo stream_get_contents($fp);
            } else {
                $body = stream_get_contents($fp);
            }
        } else {
            $body = null;
            while (true) {
                $chunk = fread($fp, 8192);
                if (empty($chunk)) {
                    break;
                }
                if ($justoutputnow) {
                    echo $chunk;
                } else {
                    $body .= $chunk;
                }
            }
        }
    }
    fclose($fp);
    restore_error_handler();
    # }}}
    # GZIP, output, and return {{{
    if ($headers['content-encoding'][0] == 'gzip') {
        # http://us2.php.net/manual/en/function.gzdecode.php
        $temp = tempnam('/tmp', 'ff');
        @file_put_contents($temp, $body);
        ob_start();
        readgzfile($temp);
        $body = ob_get_clean();
        unlink($temp);
    }
    if ($justoutput) {
        if (!$justoutputnow) {
            echo $body;
        }
        finish();
    }
    return array($body, $url, $cook_prefix);
    # }}}
}