Changeset 549 for branches/1.1dev/lib


Ignore:
Timestamp:
Oct 2, 2015 9:02:39 PM (9 years ago)
Author:
anonymous
Message:

Backporting minor debugging niceites.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/App.inc.php

    r414 r549  
    88 * CONFIG
    99 ******************************************************************************
    10  
     10
    1111 This library has some functions that require globally defined values.
    1212 These are defined here.
     
    1414
    1515//  Message Types
    16 /** @constant MSG_NOTICE 
     16/** @constant MSG_NOTICE
    1717    An informational message: Welcome to asdf, Logout successful, etc. */
    1818define('MSG_NOTICE', 0);
    1919
    20 /** @constant MSG_SUCCESS 
     20/** @constant MSG_SUCCESS
    2121    A success message: Message sent, You are logged-in, etc. */
    2222define('MSG_SUCCESS', 1);
     
    2626define('MSG_WARNING', 2);
    2727
    28 /** @constant MSG_ERR 
     28/** @constant MSG_ERR
    2929    Unrecoverable failure: Message could not be sent, File not found, etc. */
    3030define('MSG_ERR', 4); // PHP user error style.
     
    5252{
    5353    $_SESSION['_messages'][] = array(
    54         'type'    => $type, 
     54        'type'    => $type,
    5555        'message' => $message,
    5656        'file'    => $file,
     
    9595        $CFG->log_filename = sprintf('%s_%s.log', getenv('USER'), getenv('HTTP_HOST'));
    9696    }
    97    
     97
     98    // Serialize multi-line messages.
     99    $message = preg_replace('/\s+/m', ' ', trim($message));
     100
    98101    // Data to be stored for a log event.
    99102    $event = array(
     
    108111
    109112    $event_str = strip_tags('[' . preg_replace('/\s{2,}/', ' ', join('] [', $event)) . ']');
    110    
     113
    111114    // FILE ACTION
    112115    if ($CFG->log_file_priority && $priority <= $CFG->log_file_priority) {
     
    127130        mail($CFG->log_to_email, $subject, $email_msg, $headers, '-f codebase@strangecode.com');
    128131    }
    129    
     132
    130133    // SMS ACTION
    131134    if ($CFG->log_sms_priority && $priority <= $CFG->log_sms_priority) {
     
    184187        // Delete any boomerang request keys in the query string.
    185188        $url = preg_replace('/boomerang=[\w]+/', '', $url);
    186        
     189
    187190        if (is_array($_SESSION['_boomerang']['url']) && !empty($_SESSION['_boomerang']['url'])) {
    188191            // If the URL currently exists in the boomerang array, delete.
     
    191194            }
    192195        }
    193        
     196
    194197        if (isset($id)) {
    195198            $_SESSION['_boomerang']['url'][$id] = $url;
     
    255258    // or a boomerang being set.
    256259    $boomerang_time = isset($_SESSION['_boomerang']['time']) ? $_SESSION['_boomerang']['time'] : 0;
    257    
     260
    258261    if (isset($id) && isset($_SESSION['_boomerang']['url'][$id])) {
    259262        $url = $_SESSION['_boomerang']['url'][$id];
     
    277280        return false;
    278281    }
    279    
     282
    280283    return true;
    281284}
     
    318321    // Delete stored boomerang.
    319322    deleteBoomerangURL($id);
    320        
     323
    321324    // A redirection will never happen immediately twice.
    322325    // Set the time so ensure this doesn't happen.
     
    339342 */
    340343function dieURL($url, $carry_args=null, $always_include_sid=false)
    341 { 
     344{
    342345    global $CFG;
    343346
     
    354357
    355358    $url = url($url, $carry_args, $always_include_sid);
    356    
     359
    357360    header(sprintf('Location: %s', $url));
    358361    logMsg(sprintf('dieURL dying to URL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
     
    362365/**
    363366 * Prints a hidden form element with the PHPSESSID when cookies are not used, as well
    364  * as hidden form elements for GET_VARS that might be in use. 
     367 * as hidden form elements for GET_VARS that might be in use.
    365368 *
    366369 * @global string $carry_queries     An array of keys to define which values to
     
    383386        $_using_trans_sid = ini_get('session.use_trans_sid');
    384387    }
    385    
     388
    386389    // Initialize the carried queries.
    387390    if (!isset($carry_queries['_carry_queries_init'])) {
     
    399402    }
    400403
    401     // Get any additional query names to add to the $carry_queries array 
     404    // Get any additional query names to add to the $carry_queries array
    402405    // that are found as function arguments.
    403406    // If FALSE is a function argument, DO NOT carry the queries.
     
    422425        }
    423426    }
    424    
     427
    425428    // For each existing POST value, we create a hidden input to carry it through a form.
    426429    if ($do_carry_queries) {
     
    431434        }
    432435    }
    433    
     436
    434437    // Include the SID if cookies are disabled.
    435438    if (!isset($_COOKIE[session_name()]) && !$_using_trans_sid) {
     
    531534    // - the link stays on our site
    532535    // - transparent SID propogation with session.use_trans_sid is not being used OR url begins with protocol (using_trans_sid has no effect here)
    533     // OR 
     536    // OR
    534537    // - we must include the SID because we say so (it's used in a context where cookies will not be effective, ie. moving from http to https)
    535538    // AND
     
    539542            (
    540543                (
    541                     !isset($_COOKIE[session_name()]) 
     544                    !isset($_COOKIE[session_name()])
    542545                    || !$CFG->session_use_cookies
    543                 ) 
     546                )
    544547                && $CFG->enable_session
    545                 && isMyDomain($url) 
    546                 && 
     548                && isMyDomain($url)
     549                &&
    547550                (
    548551                    !$_using_trans_sid
    549552                    || preg_match('!^(http|https)://!i', $url)
    550553                )
    551             ) 
     554            )
    552555            || $always_include_sid
    553556        )
     
    594597        $modules = array('mod_ssl');
    595598    }
    596    
     599
    597600    if ('on' != getenv('HTTPS') && $CFG->ssl_enabled && in_array('mod_ssl', $modules)) {
    598601        raiseMsg(sprintf(_("Secure SSL connection made to %s"), $CFG->ssl_domain), MSG_NOTICE, __FILE__, __LINE__);
     
    601604    }
    602605}
    603    
     606
    604607
    605608/**
     
    618621 * prevent from sending sensitive info in a get query (like the SID) to another
    619622 * domain. $method can be "ip" or "domain". The domain method might be preferred
    620  * if your domain spans mutiple IP's (load sharing servers) 
     623 * if your domain spans mutiple IP's (load sharing servers)
    621624 *
    622625 * @param  string $url    the URI to test.
     
    627630 */
    628631function isMyDomain($url)
    629 {   
     632{
    630633    if (!preg_match('|\w{1,}\.\w{2,5}/|', $url)) {
    631634        // If we can't find a domain we assume the URL is relative.
     
    637640
    638641/**
    639  * Loads a list of tables in the current database into an array, and returns 
     642 * Loads a list of tables in the current database into an array, and returns
    640643 * true if the requested table is found. Use this function to enable/disable
    641644 * funtionality based upon the current available db tables.
     
    646649 */
    647650function dbTableExists($table)
    648 {   
     651{
    649652    static $existing_tables;
    650    
     653
    651654    // Save the trans_sid setting.
    652655    if (!isset($existing_tables)) {
     
    658661        }
    659662    }
    660        
     663
    661664    // Test if requested table is in database.
    662665    return in_array($table, $existing_tables);
     
    664667
    665668/**
    666  * Takes a URL and returns it without the query or anchor portion 
     669 * Takes a URL and returns it without the query or anchor portion
    667670 *
    668671 * @param  string $url   any kind of URI
     
    676679
    677680/**
    678  * Returns the remote IP address, taking into consideration proxy servers. 
     681 * Returns the remote IP address, taking into consideration proxy servers.
    679682 *
    680683 * @param  bool $dolookup   If true we resolve to IP to a host name,
     
    713716        $ip_pool = array($ip_pool);
    714717    }
    715    
     718
    716719    $my_ip_binary = sprintf('%032b', ip2long($my_ip));
    717720    foreach ($ip_pool as $ip) {
     
    731734        }
    732735    }
    733    
     736
    734737    return false;
    735738}
    736739
    737740/**
    738  * Returns a fully qualified URL to the current script, including the query. 
     741 * Returns a fully qualified URL to the current script, including the query.
    739742 *
    740743 * @return string    a full url to the current script
Note: See TracChangeset for help on using the changeset viewer.