Beispiel #1
0
function redirect($uri, $status_code = 302)
{
    send_header($status_code);
    // Again, why are we doing this? :)
    session_write_close();
    session_regenerate_id(true);
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    header('Location: ' . $uri);
    exit(0);
}
Beispiel #2
0
/**
 * Generate a fatal error, printing the $error and sending the header
 * associated with the $code. By default, this function renders the
 * error message with the error template. If you provide an ErrorController
 * that responds to an action called _$code, it will use that instead.
 * This lets you use the default error handling while developing an app
 * and switch to a more polished solution later.
 * This method can also be handy for testing - call it without args to see
 * all the data associated with a request.
 *
 * @see send_header()
 * @param string $error
 * @param integer $code
 * @return void
 *
 */
function fatal($error = 'Fatal error.', $code = 500)
{
    send_header($code);
    error_log($error);
    // do a mock request to see if we can handle this error with a controller
    $manager = new PathManager(WEB_ROOT . "/error/_{$code}");
    $route = $manager->build_route();
    $instance = $manager->controller_instance($route->controller);
    if ($instance !== FALSE && method_exists($instance, $route->action) !== FALSE) {
        $route->params = array('error' => $error, 'code' => $code);
        $action = $route->action;
        $instance->{$action}($route->params);
    } else {
        template('error');
        sys()->data->error = $error;
        sys()->data->code = $code;
    }
    render($route);
    exit;
}
Beispiel #3
0
/**
 * Http redirection
 * 
 * Same use as {@link url_for()}
 * By default HTTP status code is 302, but a different code can be specified
 * with a status key in array parameter.
 * 
 * <code>
 * redirecto('new','url'); # 302 HTTP_MOVED_TEMPORARILY by default
 * redirecto('new','url', array('status' => HTTP_MOVED_PERMANENTLY));
 * </code>
 * 
 * @param string or array $param1, $param2... 
 * @return void
 */
function redirect_to($params)
{
    # [NOTE]: (from php.net) HTTP/1.1 requires an absolute URI as argument to » Location:
    # including the scheme, hostname and absolute path, but some clients accept
    # relative URIs. You can usually use $_SERVER['HTTP_HOST'],
    # $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative
    # one yourself.
    # TODO make absolute uri
    if (!headers_sent()) {
        $status = HTTP_MOVED_TEMPORARILY;
        # default for a redirection in PHP
        $params = func_get_args();
        $n_params = array();
        # extract status param if exists
        foreach ($params as $param) {
            if (is_array($param)) {
                if (array_key_exists('status', $param)) {
                    $status = $param['status'];
                    unset($param['status']);
                }
            }
            $n_params[] = $param;
        }
        $uri = call_user_func_array('url_for', $n_params);
        $uri = htmlspecialchars_decode($uri, ENT_NOQUOTES);
        stop_and_exit(false);
        send_header('Location: ' . $uri, true, $status);
        exit;
    }
}
Beispiel #4
0
<?php

send_header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title><?php 
echo $page['title'];
?>
</title>

    <!-- Bootstrap -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/v-order.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
      var VK_APP_ID = <?php 
echo $page['VK_APP_ID'];
?>
;
Beispiel #5
0
<?php

define('ROOT', './');
session_start();
require_once ROOT . '../private_html/config.php';
require_once ROOT . '../private_html/includes/database.php';
require_once ROOT . '../private_html/includes/func.php';
cacheCurrentPage();
/// Templating
$page_title = 'MCStats :: Donate to MCStats';
$breadcrumbs = '<a href="/donate/" class="current">Donate</a>';
send_header();
echo '

<div class="row-fluid">
    <div class="widget-box span8 offset2">
        <div class="widget-title"><span><i></i></span><h4 style="float: left; margin-left: 35%;">Serving you rock solid stats.</h4></div>
        <div class="widget-content">
            <p style="font-size: 16px;">
                MCStats serves over <span style="font-weight:bold; font-size: 20px;">550 requests per second</span> 24 hours a day, 7 days a week
            </p>
            <p style="font-size: 16px;">
                That is over <b><span style="font-size: 20px;">1.5 billion</span> requests per month</b> and over <b><span style="font-size: 20px;">50 million</span> requests each day</b> and it will only continue to rise.
            </p>
            <p>
                Every single server is tracked. To get useful data for plugins, every server needs to be identified and from there
                data is stored such as the plugins the server is using (that support MCStats), the amount of players online,
                and even the Minecraft version the server is on.
            </p>
            <p>
                This is no simple task. It requires a lot of power and it also needs room for growth. Right now the service
Beispiel #6
0
<?php

require 'config.php';
require 'functions.php';
require config::redirect_file;
$redirect_key = get_redirect_key();
$redirect_key_formatted = format_redirect_key($redirect_key);
$redirect_target = get_redirect_target($redirect_key_formatted);
$redirect_url = build_url($redirect_target);
send_header($redirect_url);
Beispiel #7
0
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $snoopy->submit($url, $_POST);
} else {
    $snoopy->fetch($url);
}
//---------------处理返回信息------------
//设置cookie
switch ($config['cookies']) {
    case 1:
        //全局cookies
        $snoopy->cookies = set_cache('cookies');
        break;
    default:
        break;
}
$contentType = send_header($snoopy->headers);
$charset = empty($contentType[1]) ? 'utf-8' : $contentType[1];
$charset = trim($charset, "\n\r");
//替换域名 relativeHTML relativeCSS
if (empty($config['replaceDomain'])) {
    if (in_array($thisExt, array('', 'php', 'html'))) {
        //替换域名
        $snoopy->results = str_replace($config['host'], $rootUrl, $snoopy->results);
    }
}
//替换相对地址relativeHTML
if (empty($config['replaceDomain'])) {
    if (in_array($thisExt, array('', 'php', 'html'))) {
        $snoopy->results = str_replace('="/', '="' . siteUri(), $snoopy->results);
        $snoopy->results = str_replace('=\'/', '=\'' . siteUri(), $snoopy->results);
        $snoopy->results = preg_replace('/<base href=.*?\\/>/', '', $snoopy->results);
Beispiel #8
0
function content_type($type)
{
    send_header('Content-Type: ' . $type);
}
Beispiel #9
0
});
dispatch_post('/admin', function () {
    $db = option('db_conn');
    $fh = fopen(realpath(__DIR__ . '/../config/database/initial_data.sql'), 'r');
    while ($sql = fgets($fh)) {
        $sql = rtrim($sql);
        if (!empty($sql)) {
            $db->exec($sql);
        }
    }
    fclose($fh);
    redirect_to('/admin');
});
dispatch('/admin/order.csv', function () {
    $db = option('db_conn');
    $stmt = $db->query(<<<SQL
SELECT order_request.*, stock.seat_id, stock.variation_id, stock.updated_at
FROM order_request JOIN stock ON order_request.id = stock.order_id
ORDER BY order_request.id ASC
SQL
);
    $body = '';
    $orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($orders as &$order) {
        $body .= join(',', array($order['id'], $order['member_id'], $order['seat_id'], $order['variation_id'], $order['updated_at']));
        $body .= "\n";
    }
    send_header('Content-Type: text/csv');
    return $body;
});
run();
Beispiel #10
0
/**
 * Row Export
 */
function export_row_items(&$exportPlugin, $page_title, $include_header, $export_columns, $s_item_type, $owner_id)
{
    $iiresults = fetch_export_item_instance_rs($s_item_type, $owner_id);
    if ($iiresults) {
        send_header($exportPlugin, $page_title);
        if ($include_header == 'Y') {
            if (method_exists($exportPlugin, 'prompt_header')) {
                $row = get_header_row('prompt', $export_columns, $s_item_type);
                if (is_not_empty_array($row)) {
                    send_data($exportPlugin->prompt_header($row));
                }
            } else {
                if (method_exists($exportPlugin, 'data_header')) {
                    $row = get_header_row('data', $export_columns, $s_item_type);
                    if (is_not_empty_array($row)) {
                        send_data($exportPlugin->data_header());
                    }
                }
            }
        }
        $item_instance_r2 = NULL;
        while ($item_instance_r = db_fetch_assoc($iiresults)) {
            $row = get_item_row($export_columns, strlen($s_item_type) == 0, $item_instance_r['item_id'], $item_instance_r['instance_no'], $item_instance_r['owner_id'], $item_instance_r['s_item_type'], $item_instance_r['title'], $item_instance_r['borrow_duration'], $item_instance_r['s_status_type'], $item_instance_r['status_comment']);
            if (is_not_empty_array($row)) {
                send_data($exportPlugin->item_row($row));
            }
            $item_instance_r2 = $item_instance_r;
        }
        db_free_result($iiresults);
        if (method_exists($exportPlugin, 'close')) {
            send_data($exportPlugin->close());
        }
        send_footer($exportPlugin);
        return TRUE;
    } else {
        return FALSE;
    }
}
Beispiel #11
0
function route_post_order_action($local_id)
{
    global $MC_Text;
    if (!preg_match('/^\\d+$/', $local_id)) {
        status(HTTP_NOT_FOUND);
        exit;
    }
    $member = authOpenAPIMember();
    if ($member === FALSE) {
        status(HTTP_FORBIDDEN);
        exit;
    }
    $uid = $member['id'];
    $order = get_order($local_id);
    if ($order === FALSE) {
        status(HTTP_NOT_FOUND);
        exit;
    }
    $response = array();
    $act = $_POST['act'];
    switch ($act) {
        case 'cancel':
            if ($order['uid'] != $member['id']) {
                status(HTTP_FORBIDDEN);
                exit;
            }
            if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) {
                return json_error('ORDER_CANCELLED');
            }
            if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) {
                return json_error('ORDER_COMMITTED');
            }
            // Start and lock 'reverse-order' transaction
            $temp = start_order_transaction($uid, -$order['amount']);
            if ($temp === FALSE) {
                return json_error('START_TRANS');
            }
            // Set order 'DELETED' flag
            $res = $MC_Text->increment("flags-1_{$local_id}", FLAG_DELETED);
            if ($res === FALSE) {
                // Cancel transaction
                delete_temp_transaction($temp);
                return json_error('CANCEL_ORDER');
            }
            // Commit 'reverse-order' transaction
            commit_transaction($temp);
            $response['ok'] = TRUE;
            // Send to common queue
            enqueue(array('cancel' => $local_id), '');
            // Refresh balance
            $response['balance'] = formatBalance('USR', $uid);
            $response['order_balance'] = formatBalance('ORD', $uid);
            // Send to user's queue
            enqueue(array('cancel' => $local_id, 'balance' => $response['balance']), $uid);
            break;
        case 'commit':
            # Prevent from committing own orders
            #if ($order['uid'] == $member['id']) {
            #    status(HTTP_FORBIDDEN);
            #    exit;
            #}
            if (($order['flags'] & FLAG_DELETED) == FLAG_DELETED) {
                return json_error('ORDER_CANCELLED');
            }
            if (($order['flags'] & FLAG_REPLIED) == FLAG_REPLIED) {
                return json_error('ORDER_COMMITTED');
            }
            // Start and lock 'commit-order' transaction
            $temp = start_commit_order_transaction($uid, $order['uid'], $order['amount']);
            if ($temp === FALSE) {
                return json_error('START_TRANS');
            }
            // Set order 'COMMITTED' flag
            $resp = $MC_Text->increment("flags-1_{$local_id}", FLAG_REPLIED);
            if ($resp === FALSE) {
                // Cancel transaction
                delete_temp_transaction($temp);
                return json_error('COMMIT_ORDER');
            }
            // Commit 'commit-order' transaction
            $resp = commit_transaction($temp);
            # TODO: Store transaction id in the order
            $response['ok'] = TRUE;
            // Refresh balance
            $response['balance'] = formatBalance('USR', $uid);
            $response['order_balance'] = formatBalance('ORD', $uid);
            $author = $order['uid'];
            // Send to user's queue
            if ($uid != $author) {
                enqueue(array('commit' => $local_id, 'balance' => $response['balance']), $uid);
            }
            // Send to common queue
            enqueue(array('commit' => $local_id), '');
            // Render author's html
            global $i;
            global $page;
            $i = get_order($local_id);
            $page = array('member' => array('id' => $author));
            ob_start();
            include 'templates/_order.php';
            $html = ob_get_clean();
            // Send to author's queue
            $data = array('commit' => $local_id, 'order' => $i, 'html' => $html);
            if ($author == $uid) {
                $data['balance'] = $response['balance'];
            }
            enqueue($data, $author);
            break;
        default:
            status(HTTP_BAD_REQUEST);
            exit;
    }
    send_header('Content-Type: application/json; charset=utf-8');
    echo json_encode($response);
}
Beispiel #12
0
function get_following()
{
    $db = option('db_conn');
    $user = get('user');
    $stmt = $db->prepare('SELECT users.* FROM follow_map JOIN users ON (follow_map.target = users.id) WHERE follow_map.user = :user ORDER BY follow_map.created_at DESC');
    $stmt->bindValue(':user', $user['id']);
    $stmt->execute();
    $followings = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $users = array();
    foreach ($followings as $following) {
        $users[] = array('id' => $following['id'], 'name' => $following['name'], 'icon' => uri_for('/icon/' . $following['icon']));
    }
    send_header('Cache-Control: no-cache');
    echo json(array(users => $users));
}
/* Include configuration */
require_once './config.php';
/* Get path */
if (isset($_GET['path'])) {
    $dir = sanitize($_GET['path']);
} else {
    $dir = TFTP_FILE_ROOT;
}
/* Download or show files */
if (isset($_GET['download'])) {
    /* Download files */
    $file = sanitize($_GET['download']);
    get_file($file);
} else {
    /* Show files */
    send_header($dir);
    show_files($dir);
    send_footer();
}
function sanitize($path)
{
    /* Don't get back up the directory structure */
    if (preg_match('/\\.\\./', $path) > 0) {
        echo "Illegal path specified";
        exit;
    }
    /* Make sure we are within DIRROOT */
    if (preg_match('!^' . TFTP_FILE_ROOT . '!', $path) == 0) {
        echo "Illegal access";
        exit;
    }