Пример #1
0
 public static function exception($exception, $trace = true)
 {
     static::log($exception);
     ob_get_level() and ob_end_clean();
     $message = $exception->getMessage();
     $file = $exception->getFile();
     $code = $exception->getCode();
     $response = "<html>\n<h2>Unhandled Exception</h2>\n<h3>Message:</h3>\n<pre>(" . $code . ") " . $message . "</pre>\n<h3>Location:</h3>\n<pre>" . $file . " on line " . $exception->getLine() . "</pre>\n";
     if ($trace) {
         $response .= "<h3>Stack Trace:</h3>\n<pre>" . $exception->getTraceAsString() . "</pre>\n";
     }
     $response .= "</html>";
     Response::code(500);
     if (Config::item("errors", "show", false)) {
         echo $response;
     }
     if (Config::item("errors", "email", false) && !Request::isLocal() && !Request::isPreview()) {
         $e = new Email();
         $e->from = Config::item("errors", "emailFrom", "*****@*****.**");
         $e->to = Config::item("errors", "emailTo", "*****@*****.**");
         $e->subject = URL::root() . " - erro!";
         $e->content = $response;
         $e->send();
     }
     return exit(1);
 }
Пример #2
0
 protected static function tmpRoot()
 {
     return URL::root(false) . "storage/tmp/";
 }
Пример #3
0
function process_login_form()
{
    $email = strtolower($_POST['email']);
    $passhash = hash_pass($email, $_POST['pass']);
    // Check to see if the user/ip is temporarily banned:
    //   An IP is banned when 10 unsuccessful attempts are made to log in from a single IP/email within 10 minutes,
    //   regardless of whether any successful attempts were made.
    $attempts = DBExt::queryCount('login_attempts', array('successful=0', '(remote_ip=%s OR email=%s)', DBExt::timeInInterval('request_time', '-10m', '')), $_SERVER['REMOTE_ADDR'], $email);
    if ($attempts > 10) {
        log_attempt($email, false);
        alert('You have been temporarily locked out. Please wait 10 minutes before attempting to sign in again.', -1);
        show_login_form('');
        return;
    }
    // Check for super-user login:
    // (the account LHSMATH and password set in CONFIG
    if ($email == 'lhsmath') {
        global $LHSMATH_PASSWORD;
        if ($passhash == $LHSMATH_PASSWORD) {
            // $LHSMATH_PASSWORD is pre-hashed
            log_attempt('LHSMATH', true);
            session_destroy();
            session_name('Session');
            session_start();
            session_regenerate_id(true);
            $_SESSION['user_name'] = 'LHSMATH Super-Admin';
            $_SESSION['permissions'] = '+';
            $_SESSION['login_time'] = time();
            $_SESSION['user_id'] = '-999';
            header('Location: ' . URL::root() . '/Admin/Super_Admin');
            die;
        }
    }
    // Validate credentials
    $id = DB::queryFirstField('SELECT id FROM users WHERE LOWER(email)=%s AND passhash=%s LIMIT 1', $email, $passhash);
    if (is_null($id)) {
        log_attempt($email, false);
        show_login_form($email);
        alert('Incorrect email address or password', -1);
        return;
    }
    // ** CREDENTIALS ARE VALIDATED AT THIS POINT ** //
    log_attempt($email, true);
    set_login_data($id);
    alert('Logged in!', 1);
    //If this page was being included, redirect back.
    global $being_included;
    if ($being_included) {
        header('Location: ' . $_SERVER['REQUEST_URI']);
    } else {
        header('Location: ../Home');
    }
}
Пример #4
0
        //Insert anywhere: "global $show_debug_backtrace;$show_debug_backtrace=true;" and it'll do it.
        if ($show_debug_backtrace) {
            var_dump(debug_backtrace());
        }
        return;
    }
    if ($errno & (E_USER_NOTICE | E_USER_WARNING | E_WARNING | E_NOTICE)) {
        return;
    }
    //Just a notice/warning, not worth bothering the user for
    if (headers_sent()) {
        //Headers were already sent; we can't tell the browser HTTP/1.1 500 Internal Server Error
        echo '<meta http-equiv="refresh" content="0;url=' . URL::root() . '/Error">';
    } elseif (isset($_GET['xsrf_token'])) {
        //So we don't resubmit with the xsrf_token again and cause infinite error generation.
        header('Location: ' . URL::root() . '/Error');
    } else {
        header("HTTP/1.1 500 Internal Server Error");
        page_title('Error');
        echo <<<HEREDOC
      <h1>Error</h1>
      
      Whoops! Something went wrong. Try again?
HEREDOC;
    }
    die;
}, E_ALL);
error_reporting(E_ALL);
/*else{function a(){debug_print_backtrace();}function b(){global $a;if($a)echo var_dump($a);}
function c(){global $a;if(!$a)$a=array();$a[]=debug_backtrace();}set_error_handler('a',E_ALL&!E_NOTICE);
register_shutdown_function('b');}*/
Пример #5
0
 public static function headers()
 {
     $root = URL::root();
     echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n\t\t<link rel=\"stylesheet\" href=\"" . $root . "allCSS/\">\n\t\t<script type='text/javascript' src='" . $root . "allJS/'></script>\n\t\t<script type='text/javascript'>window.J_ROOT = '" . $root . "';</script>\n\t\t\n";
 }
Пример #6
0
function navbar_html($navbar = NULL)
{
    if (is_null($navbar)) {
        global $navbar_array;
        $navbar = $navbar_array;
    }
    $html = '';
    foreach ($navbar as $key => $nav_elem) {
        if (is_array($nav_elem)) {
            if (user_access($key)) {
                //If it's a section and it's allowed, then recursively continue flattening the array.
                $html .= navbar_html($nav_elem);
            }
        } elseif ($nav_elem === '') {
            $html .= "</div><div class='linkgroup'>";
        } elseif (is_string($key)) {
            //In this case $key is the name, $nav_elem is the path.
            if ($nav_elem === get_relative_path()) {
                //In this case it's the current page, so indicate so.
                $html .= "<span class='selected'>{$key}</span><br />";
            } else {
                $html .= "<a href='" . URL::root() . "/{$nav_elem}'>{$key}</a><br />";
            }
        } else {
            //In this case $nav_elem is both the name and the path.
            if ($nav_elem === get_relative_path()) {
                //In this case it's the current page, so indicate so.
                $html .= "<span class='selected'>{$nav_elem}</span><br />";
            } else {
                $html .= "<a href='" . URL::root() . "/{$nav_elem}'>{$nav_elem}</a><br />";
            }
        }
    }
    return $html;
}
Пример #7
0
function thumbnail($picture, $w = "", $h = "", $thumb = 1, $crop = 0, $arrMore = array())
{
    $arr_duoi = array('gif', 'png', 'jpg');
    $duoi = strtolower(substr($picture, strrpos($picture, ".") + 1));
    if (!in_array($duoi, $arr_duoi)) {
        $picture = 'public/upload/nophoto/nophoto.jpg';
    }
    $out = "";
    $pre = $w;
    if ($h) {
        $pre = $w . "x" . $h;
    } else {
        $h = $w;
    }
    if (isset($arrMore['fixMin'])) {
        $pre .= "_fmin";
    }
    if (isset($arrMore['fixMax'])) {
        $pre .= "_fmax";
    }
    if (isset($arrMore['fixWidth'])) {
        $pre .= "_fw";
    }
    if (isset($arrMore['zoomMax'])) {
        $pre .= "_zmax";
    }
    if ($crop != 0) {
        $pre .= "_crop";
    }
    $linkhinh = $picture;
    $linkhinh = str_replace("//", "/", $linkhinh);
    $dir = substr($linkhinh, 0, strrpos($linkhinh, "/"));
    $pic_name = substr($linkhinh, strrpos($linkhinh, "/") + 1);
    //$linkhinh = "uploads/" . $linkhinh;
    if ($w) {
        if ($thumb) {
            $folder_thumbs = str_replace('public/upload/', 'public/thumbs_size/', $dir . '/');
            $folder_thumbs .= substr($pic_name, 0, strrpos($pic_name, "."));
            $folder_thumbs .= '_' . substr($pic_name, strrpos($pic_name, ".") + 1);
            $file_thumbs = $folder_thumbs . "/{$pre}_" . substr($linkhinh, strrpos($linkhinh, "/") + 1);
            $linkhinhthumbs = SITE_PATH . $file_thumbs;
            //$linkhinhthumbs = SITE_PATH . "public/thumbs_size/" . $file_thumbs;
            if (!file_exists($linkhinhthumbs)) {
                rmkdir($folder_thumbs, 0777, "thumbs_size");
                // thum hinh
                thumbs(SITE_PATH . $linkhinh, $linkhinhthumbs, $w, $h, $crop, $arrMore);
            }
            $src = URL::root() . $file_thumbs;
        } else {
            $src = URL::root() . $folder_thumbs . "/" . $pic_name;
        }
    } else {
        $src = URL::root() . 'uploads/' . $picture;
    }
    return $src;
}
Пример #8
0
function lmt_page_header($title)
{
    global $page_title;
    $page_title = $title;
    global $header_title;
    $header_title = 'Lexington Math Tournament';
    global $logged_in_header;
    if (isset($_SESSION['LMT_user_id'])) {
        $logged_in_header = '<div id="user"><span id="username">School: ' . $_SESSION['LMT_school_name'] . '</span><span id="bar"> | </span><a href="' . URL::root() . '/LMT/Registration/Signout">Log Out</a></div>';
    }
    global $more_head_stuff;
    $more_head_stuff .= '<link rel="stylesheet" href="' . URL::root() . '/res/lmt.css" type="text/css" media="all" />';
    global $jquery_function, $javascript;
    $jquery_function .= $javascript;
    global $header_noprint, $header_class;
    if (isset($header_noprint)) {
        $header_class = 'noPrint';
    }
}