Source for file global.php

Documentation is available at global.php

  1. <?php
  2.  
  3. /**
  4.  * global.php
  5.  *
  6.  * @copyright 1999-2020 The SquirrelMail Project Team
  7.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8.  * @version $Id: global.php 14840 2020-01-07 07:42:38Z pdontthink $
  9.  * @package squirrelmail
  10.  */
  11.  
  12. /**
  13.  * Set constants
  14.  */
  15. define('SQ_INORDER',0);
  16. define('SQ_GET',1);
  17. define('SQ_POST',2);
  18. define('SQ_SESSION',3);
  19. define('SQ_COOKIE',4);
  20. define('SQ_SERVER',5);
  21. define('SQ_FORM',6);
  22.  
  23. /** First code that should be executed before other files are loaded */
  24.  
  25. /**
  26.  * Must be executed before any other scripts are loaded.
  27.  *
  28.  * If register_globals are on, unregister globals.
  29.  * Second test covers boolean set as string (php_value register_globals off).
  30.  */
  31. if ((bool) ini_get('register_globals') &&
  32.     strtolower(ini_get('register_globals'))!='off') {
  33.     /**
  34.      * Remove all globals that are not reserved by PHP
  35.      * 'value' and 'key' are used by foreach. Don't unset them inside foreach.
  36.      */
  37.     foreach ($GLOBALS as $key => $value) {
  38.         switch($key) {
  39.         case 'HTTP_POST_VARS':
  40.         case '_POST':
  41.         case 'HTTP_GET_VARS':
  42.         case '_GET':
  43.         case 'HTTP_COOKIE_VARS':
  44.         case '_COOKIE':
  45.         case 'HTTP_SERVER_VARS':
  46.         case '_SERVER':
  47.         case 'HTTP_ENV_VARS':
  48.         case '_ENV':
  49.         case 'HTTP_POST_FILES':
  50.         case '_FILES':
  51.         case '_REQUEST':
  52.         case 'HTTP_SESSION_VARS':
  53.         case '_SESSION':
  54.         case 'GLOBALS':
  55.         case 'key':
  56.         case 'value':
  57.             break;
  58.         default:
  59.             unset($GLOBALS[$key]);
  60.         }
  61.     }
  62.     // Unset variables used in foreach
  63.     unset($GLOBALS['key']);
  64.     unset($GLOBALS['value']);
  65. }
  66.  
  67. /**
  68.  * There are some PHP settings that SquirrelMail is incompatible with
  69.  * and cannot be changed by software at run-time; refuse to run if such
  70.  * settings are being used...
  71.  */
  72. $php_session_auto_start = ini_get('session.auto_start');
  73. if ((bool)$php_session_auto_start && $php_session_auto_start != 'off') {
  74.     die('SquirrelMail 1.4.x is not compatible with PHP\'s session.auto_start setting.  Please disable it at least for the location where SquirrelMail is installed.');
  75. }
  76.  
  77. /**
  78.  * Strip any tags added to the url from PHP_SELF.
  79.  * This fixes hand crafted url XXS expoits for any
  80.  * page that uses PHP_SELF as the FORM action.
  81.  * Must be executed before strings.php is loaded (php_self() call in strings.php).
  82.  * Update: strip_tags() won't catch something like
  83.  * src/right_main.php?sort=0&startMessage=1&mailbox=INBOX&xxx="><script>window.open("http://example.com")</script>
  84.  * or
  85.  * contrib/decrypt_headers.php/%22%20onmouseover=%22alert(%27hello%20world%27)%22%3E
  86.  * because it doesn't bother with broken tags.
  87.  * htmlspecialchars() is the preferred method.
  88.  */
  89. if (isset($_SERVER['PHP_SELF'])) {
  90.     $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
  91. }
  92. /*
  93.  * same needed for QUERY_STRING because SquirrelMail
  94.  * uses it along with PHP_SELF when using location
  95.  * strings
  96.  */
  97. if (isset($_SERVER['QUERY_STRING'])) {
  98.     $_SERVER['QUERY_STRING'] = htmlspecialchars($_SERVER['QUERY_STRING']);
  99. }
  100. /*
  101.  * same needed for REQUEST_URI because it's used in php_self()
  102.  */
  103. if (isset($_SERVER['REQUEST_URI'])) {
  104.     $_SERVER['REQUEST_URI'] = htmlspecialchars($_SERVER['REQUEST_URI']);
  105. }
  106.  
  107. /**
  108.  * Bring in the config file
  109.  * We need $session_name
  110.  * config.php $version depends on strings.php.
  111.  * strings.php sets $PHP_SELF.
  112.  */
  113. require_once(SM_PATH . 'functions/strings.php');
  114. require_once(SM_PATH . 'config/config.php');
  115.  
  116. /**
  117.  * Allow disabling of all plugins or enabling just a select few
  118.  *
  119.  * $temporary_plugins can be set in config_local.php, and
  120.  * must be set as an array of plugin names that will be
  121.  * the only ones activated (overriding the activation from
  122.  * the main configuration file).  If the list is empty,
  123.  * all plugins will be disabled.  Examples follow:
  124.  *
  125.  * Enable only Preview Pane and TNEF Decoder plugins:
  126.  * $temporary_plugins = array('tnef_decoder', 'preview_pane');
  127.  *
  128.  * Disable all plugins:
  129.  * $temporary_plugins = array();
  130.  */
  131. global $temporary_plugins;
  132. if (isset($temporary_plugins)) {
  133.     $plugins = $temporary_plugins;
  134. }
  135.  
  136. /**
  137.  * Detect SSL connections
  138.  */
  139. $is_secure_connection = is_ssl_secured_connection();
  140.  
  141. /** set the name of the session cookie */
  142. if(isset($session_name) && $session_name) {
  143.     ini_set('session.name' , $session_name);
  144. } else {
  145.     ini_set('session.name' , 'SQMSESSID');
  146. }
  147.  
  148. /**
  149.  * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways.
  150.  * Force magic_quotes_runtime off.
  151.  * [email protected] - I put it here in the hopes that all SM code includes this.
  152.  * If there's a better place, please let me know.
  153.  */
  154. ini_set('magic_quotes_runtime','0');
  155.  
  156. /**
  157.  * [#1518885] session.use_cookies = off breaks SquirrelMail
  158.  *
  159.  * When session cookies are not used, all http redirects, meta refreshes,
  160.  * src/download.php and javascript URLs are broken. Setting must be set
  161.  * before session is started.
  162.  */
  163. if (!(bool)ini_get('session.use_cookies') ||
  164.     ini_get('session.use_cookies') == 'off') {
  165.     ini_set('session.use_cookies','1');
  166. }
  167.  
  168. /**
  169.  * Make sure to have $base_uri always initialized to avoid having session
  170.  * cookie set separately for each $base_uri subdirectory that receives direct
  171.  * requests from user's browser (typically $base_uri and $base_uri/src).
  172.  */
  173. $base_uri = sqm_baseuri();
  174.  
  175.  
  176. /* if running with magic_quotes_gpc then strip the slashes
  177.    from POST and GET global arrays */
  178.  
  179. if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) {
  180.     sqstripslashes($_GET);
  181.     sqstripslashes($_POST);
  182. }
  183.  
  184. /**
  185.  * returns true if current php version is at mimimum a.b.c
  186.  *
  187.  * Called: check_php_version(4,1)
  188.  * @param int a major version number
  189.  * @param int b minor version number
  190.  * @param int c release number
  191.  * @return bool 
  192.  */
  193. function check_php_version ($a = '0', $b = '0', $c = '0')
  194. {
  195.     global $SQ_PHP_VERSION;
  196.  
  197.     if(!isset($SQ_PHP_VERSION))
  198.         $SQ_PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
  199.  
  200.     return $SQ_PHP_VERSION >= ($a.$b.$c);
  201. }
  202.  
  203. /**
  204.  * returns true if the current internal SM version is at minimum a.b.c
  205.  * These are plain integer comparisons, as our internal version is
  206.  * constructed by us, as an array of 3 ints.
  207.  *
  208.  * Called: check_sm_version(1,3,3)
  209.  * @param int a major version number
  210.  * @param int b minor version number
  211.  * @param int c release number
  212.  * @return bool 
  213.  */
  214. function check_sm_version($a = 0, $b = 0, $c = 0)
  215. {
  216.     global $SQM_INTERNAL_VERSION;
  217.     if ( !isset($SQM_INTERNAL_VERSION) ||
  218.          $SQM_INTERNAL_VERSION[0] < $a ||
  219.          ( $SQM_INTERNAL_VERSION[0] == $a &&
  220.            $SQM_INTERNAL_VERSION[1] < $b) ||
  221.          ( $SQM_INTERNAL_VERSION[0] == $a &&
  222.            $SQM_INTERNAL_VERSION[1] == $b &&
  223.            $SQM_INTERNAL_VERSION[2] < $c ) ) {
  224.         return FALSE;
  225.     }
  226.     return TRUE;
  227. }
  228.  
  229.  
  230. /**
  231.  * Recursively strip slashes from the values of an array.
  232.  * @param array array the array to strip, passed by reference
  233.  * @return void 
  234.  */
  235. function sqstripslashes(&$array) {
  236.     if(count($array) > 0) {
  237.         foreach ($array as $index=>$value) {
  238.             if (is_array($array[$index])) {
  239.                 sqstripslashes($array[$index]);
  240.             }
  241.             else {
  242.                 $array[$index] = stripslashes($value);
  243.             }
  244.         }
  245.     }
  246. }
  247.  
  248. /**
  249.  * Squelch error output to screen (only) for the given function.
  250.  *
  251.  * This provides an alternative to the @ error-suppression
  252.  * operator where errors will not be shown in the interface
  253.  * but will show up in the server log file (assuming the
  254.  * administrator has configured PHP logging).
  255.  * 
  256.  * @since 1.4.12 and 1.5.2
  257.  * 
  258.  * @param string $function The function to be executed
  259.  * @param array  $args     The arguments to be passed to the function
  260.  *                          (OPTIONAL; default no arguments)
  261.  *                          NOTE: The caller must take extra action if
  262.  *                                the function being called is supposed
  263.  *                                to use any of the parameters by
  264.  *                                reference.  In the following example,
  265.  *                                $x is passed by reference and $y is
  266.  *                                passed by value to the "my_func"
  267.  *                                function.
  268.  *  sq_call_function_suppress_errors('my_func', array(&$x, $y));
  269.  * 
  270.  * @return mixed The return value, if any, of the function being
  271.  *                executed will be returned.
  272.  * 
  273.  */ 
  274. function sq_call_function_suppress_errors($function, $args=array()) {
  275.    $display_errors = ini_get('display_errors');
  276.    ini_set('display_errors', '0');
  277.    if ( is_null( $args ) ) {
  278.      $ret = call_user_func($function);
  279.    } else {
  280.      $ret = call_user_func_array($function, $args);
  281.    }
  282.    ini_set('display_errors', $display_errors);
  283.    return $ret;
  284. }
  285.  
  286. /**
  287.  * Add a variable to the session.
  288.  * @param mixed $var the variable to register
  289.  * @param string $name the name to refer to this variable
  290.  * @return void 
  291.  */
  292. function sqsession_register ($var, $name) {
  293.  
  294.  
  295.     $_SESSION[$name] = $var;
  296. }
  297.  
  298. /**
  299.  * Delete a variable from the session.
  300.  * @param string $name the name of the var to delete
  301.  * @return void 
  302.  */
  303. function sqsession_unregister ($name) {
  304.  
  305.  
  306.     unset($_SESSION[$name]);
  307.  
  308.     // starts throwing warnings in PHP 5.3.0 and is
  309.     // removed in PHP 6 and is redundant anyway
  310.     //session_unregister($name);
  311. }
  312.  
  313. /**
  314.  * Checks to see if a variable has already been registered
  315.  * in the session.
  316.  * @param string $name the name of the var to check
  317.  * @return bool whether the var has been registered
  318.  */
  319. function sqsession_is_registered ($name) {
  320.     $test_name = &$name;
  321.     return isset($_SESSION[$test_name]);
  322. }
  323.  
  324. /**
  325.  * Search for the var $name in $_SESSION, $_POST, $_GET,
  326.  * $_COOKIE, or $_SERVER and set it in provided var.
  327.  *
  328.  * If $search is not provided,  or == SQ_INORDER, it will search
  329.  * $_SESSION, then $_POST, then $_GET. Otherwise,
  330.  * use one of the defined constants to look for
  331.  * a var in one place specifically.
  332.  *
  333.  * Note: $search is an int value equal to one of the
  334.  * constants defined above.
  335.  *
  336.  * example:
  337.  *    sqgetGlobalVar('username',$username,SQ_SESSION);
  338.  *  -- no quotes around last param!
  339.  *
  340.  * @param string name the name of the var to search
  341.  * @param mixed value the variable to return
  342.  * @param int search constant defining where to look
  343.  * @return bool whether variable is found.
  344.  */
  345. function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
  346.  
  347.     /* NOTE: DO NOT enclose the constants in the switch
  348.        statement with quotes. They are constant values,
  349.        enclosing them in quotes will cause them to evaluate
  350.        as strings. */
  351.     switch ($search) {
  352.         /* we want the default case to be first here,
  353.            so that if a valid value isn't specified,
  354.            all three arrays will be searched. */
  355.       default:
  356.       case SQ_INORDER: // check session, post, get
  357.       case SQ_SESSION:
  358.         if( isset($_SESSION[$name]) ) {
  359.             $value = $_SESSION[$name];
  360.             return TRUE;
  361.         } elseif ( $search == SQ_SESSION ) {
  362.             break;
  363.         }
  364.       case SQ_FORM:   // check post, get
  365.       case SQ_POST:
  366.         if( isset($_POST[$name]) ) {
  367.             $value = $_POST[$name];
  368.             return TRUE;
  369.         } elseif ( $search == SQ_POST ) {
  370.           break;
  371.         }
  372.       case SQ_GET:
  373.         if ( isset($_GET[$name]) ) {
  374.             $value = $_GET[$name];
  375.             return TRUE;
  376.         }
  377.         /* NO IF HERE. FOR SQ_INORDER CASE, EXIT after GET */
  378.         break;
  379.       case SQ_COOKIE:
  380.         if ( isset($_COOKIE[$name]) ) {
  381.             $value = $_COOKIE[$name];
  382.             return TRUE;
  383.         }
  384.         break;
  385.       case SQ_SERVER:
  386.         if ( isset($_SERVER[$name]) ) {
  387.             $value = $_SERVER[$name];
  388.             return TRUE;
  389.         }
  390.         break;
  391.     }
  392.     /* if not found, return false */
  393.     return FALSE;
  394. }
  395.  
  396. /**
  397.  * Deletes an existing session, more advanced than the standard PHP
  398.  * session_destroy(), it explicitly deletes the cookies and global vars.
  399.  */
  400. function sqsession_destroy() {
  401.  
  402.     /*
  403.      * php.net says we can kill the cookie by setting just the name:
  404.      * http://www.php.net/manual/en/function.setcookie.php
  405.      * maybe this will help fix the session merging again.
  406.      *
  407.      * Changed the theory on this to kill the cookies first starting
  408.      * a new session will provide a new session for all instances of
  409.      * the browser, we don't want that, as that is what is causing the
  410.      * merging of sessions.
  411.      */
  412.  
  413.     global $base_uri;
  414.  
  415.     if (isset($_COOKIE[session_name()])) {
  416.         sqsetcookie(session_name(), $_COOKIE[session_name()], 1, $base_uri);
  417.  
  418.         /*
  419.          * Make sure to kill /src and /src/ cookies, just in case there are
  420.          * some left-over or malicious ones set in user's browser.
  421.          * NB: Note that an attacker could try to plant a cookie for one
  422.          *     of the /plugins/* directories.  Such cookies can block
  423.          *     access to certain plugin pages, but they do not influence
  424.          *     or fixate the $base_uri cookie, so we don't worry about
  425.          *     trying to delete all of them here.
  426.          */
  427.         sqsetcookie(session_name(), $_COOKIE[session_name()], 1, $base_uri . 'src');
  428.         sqsetcookie(session_name(), $_COOKIE[session_name()], 1, $base_uri . 'src/');
  429.     }
  430.  
  431.     if (isset($_COOKIE['key'])) sqsetcookie('key', 'SQMTRASH', 1, $base_uri);
  432.  
  433.     /* Make sure new session id is generated on subsequent session_start() */
  434.     unset($_COOKIE[session_name()]);
  435.     unset($_GET[session_name()]);
  436.     unset($_POST[session_name()]);
  437.  
  438.     $sessid = session_id();
  439.     if (!empty( $sessid )) {
  440.         $_SESSION = array();
  441.         @session_destroy();
  442.     }
  443.  
  444. }
  445.  
  446. /**
  447.  * Function to verify a session has been started.  If it hasn't
  448.  * start a session up.  php.net doesn't tell you that $_SESSION
  449.  * (even though autoglobal), is not created unless a session is
  450.  * started, unlike $_POST, $_GET and such
  451.  */
  452.  
  453. function sqsession_is_active() {
  454.     sqsession_start();
  455. }
  456.  
  457. /**
  458.  * Function to start the session and store the cookie with the session_id as
  459.  * HttpOnly cookie which means that the cookie isn't accessible by javascript
  460.  * (IE6 only)
  461.  * Note that as sqsession_is_active() no longer discriminates as to when
  462.  * it calls this function, session_start() has to have E_NOTICE suppression
  463.  * (thus the @ sign).  Update: with PHP7.2+, session_set_cookie_params() is
  464.  * similarly affected.
  465.  *
  466.  * @return void 
  467.  *
  468.  * @since 1.4.16
  469.  *
  470.  */
  471. function sqsession_start() {
  472.     global $base_uri;
  473.  
  474.     @session_set_cookie_params (0, $base_uri);
  475.     @session_start();
  476.     // could be: sq_call_function_suppress_errors('session_start');
  477.     $session_id = session_id();
  478.  
  479.     // session_starts sets the sessionid cookie but without the httponly var
  480.     // setting the cookie again sets the httponly cookie attribute
  481.     //
  482.     // need to check if headers have been sent, since sqsession_is_active()
  483.     // has become just a passthru to this function, so the sqsetcookie()
  484.     // below is called every time, even after headers have already been sent
  485.     //
  486.     if (!headers_sent())
  487.        sqsetcookie(session_name(),$session_id,false,$base_uri);
  488. }
  489.  
  490. /**
  491.  * Set a cookie
  492.  *
  493.  * @param string  $sName     The name of the cookie.
  494.  * @param string  $sValue    The value of the cookie.
  495.  * @param int     $iExpire   The time the cookie expires. This is a Unix
  496.  *                            timestamp so is in number of seconds since
  497.  *                            the epoch.
  498.  * @param string  $sPath     The path on the server in which the cookie
  499.  *                            will be available on.
  500.  * @param string  $sDomain   The domain that the cookie is available.
  501.  * @param boolean $bSecure   Indicates that the cookie should only be
  502.  *                            transmitted over a secure HTTPS connection.
  503.  * @param boolean $bHttpOnly Disallow JS to access the cookie (IE6/FF2)
  504.  * @param boolean $bReplace  Replace previous cookies with same name?
  505.  *
  506.  * @return void 
  507.  *
  508.  * @since 1.4.16 and 1.5.1
  509.  *
  510.  */
  511. function sqsetcookie($sName, $sValue='deleted', $iExpire=0, $sPath="", $sDomain="",
  512.                      $bSecure=false, $bHttpOnly=true, $bReplace=false) {
  513.  
  514.     // some environments can get overwhelmed by an excessive
  515.     // setting of the same cookie over and over (e.g., many
  516.     // calls to this function via sqsession_is_active() result
  517.     // in repeated setting of the session cookie when $bReplace
  518.     // is FALSE, but something odd happens (during login only)
  519.     // if we change that to default TRUE) ... so we keep our own
  520.     // naive per-request name/value cache and only set the cookie
  521.     // if its value is changing (or never seen before)
  522.     static $cookies = array();
  523.     if (isset($cookies[$sName]) && $cookies[$sName] === $sValue)
  524.         return;
  525.     else
  526.         $cookies[$sName] = $sValue;
  527.  
  528.  
  529.     // if we have a secure connection then limit the cookies to https only.
  530.     global $is_secure_connection;
  531.     if ($sName && $is_secure_connection)
  532.         $bSecure = true;
  533.  
  534.     // admin config can override the restriction of secure-only cookies
  535.     //
  536.     // (we have to check if the value is set and default it to true if
  537.     // not because when upgrading without re-running conf.pl, it will
  538.     // not be found in config/config.php and thusly evaluate to false,
  539.     // but we want to default people who upgrade to true due to security
  540.     // implications of setting this to false)
  541.     //
  542.     global $only_secure_cookies;
  543.     if (!isset($only_secure_cookies)) $only_secure_cookies = true;
  544.     if (!$only_secure_cookies)
  545.         $bSecure = false;
  546.  
  547.     if (false && check_php_version(5,2)) {
  548.        // php 5 supports the httponly attribute in setcookie, but because setcookie seems a bit
  549.        // broken we use the header function for php 5.2 as well. We might change that later.
  550.        //setcookie($sName,$sValue,(int) $iExpire,$sPath,$sDomain,$bSecure,$bHttpOnly);
  551.     } else {
  552.         if (!empty($sDomain)) {
  553.             // Fix the domain to accept domains with and without 'www.'.
  554.             if (strtolower(substr($sDomain, 0, 4)) == 'www.')  $sDomain = substr($sDomain, 4);
  555.             $sDomain = '.' . $sDomain;
  556.  
  557.             // Remove port information.
  558.             $Port = strpos($sDomain, ':');
  559.             if ($Port !== false)  $sDomain = substr($sDomain, 0, $Port);
  560.         }
  561.         if (!$sValue) $sValue = 'deleted';
  562.         header('Set-Cookie: ' . rawurlencode($sName) . '=' . rawurlencode($sValue)
  563.                             . (empty($iExpire) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', $iExpire) . ' GMT')
  564.                             . (empty($sPath) ? '' : '; path=' . $sPath)
  565.                             . (empty($sDomain) ? '' : '; domain=' . $sDomain)
  566.                             . (!$bSecure ? '' : '; secure')
  567.                             . (!$bHttpOnly ? '' : '; HttpOnly'), $bReplace);
  568.     }
  569. }
  570.  
  571. /**
  572.  * Detect whether or not we have a SSL secured (HTTPS)
  573.  * connection to the browser
  574.  *
  575.  * It is thought to be so if you have 'SSLOptions +StdEnvVars'
  576.  * in your Apache configuration,
  577.  *     OR if you have HTTPS set to a non-empty value (except "off")
  578.  *        in your HTTP_SERVER_VARS,
  579.  *     OR if you have HTTP_X_FORWARDED_PROTO=https in your HTTP_SERVER_VARS,
  580.  *     OR if you are on port 443.
  581.  *
  582.  * Note: HTTP_X_FORWARDED_PROTO could be sent from the client and
  583.  *       therefore possibly spoofed/hackable - for now, the
  584.  *       administrator can tell SM to ignore this value by setting
  585.  *       $sq_ignore_http_x_forwarded_headers to boolean TRUE in
  586.  *       config/config_local.php, but in the future we may
  587.  *       want to default this to TRUE and make administrators
  588.  *       who use proxy systems turn it off (see 1.5.2+).
  589.  *
  590.  * Note: It is possible to run SSL on a port other than 443, and
  591.  *       if that is the case, the administrator should set
  592.  *       $sq_https_port to the applicable port number in
  593.  *       config/config_local.php
  594.  *
  595.  * @return boolean TRUE if the current connection is SSL-encrypted;
  596.  *                  FALSE otherwise.
  597.  *
  598.  * @since 1.4.17 and 1.5.2
  599.  *
  600.  */
  601. { 
  602.     global $sq_ignore_http_x_forwarded_headers, $sq_https_port;
  603.     $https_env_var = getenv('HTTPS');
  604.     if ($sq_ignore_http_x_forwarded_headers
  605.      || !sqgetGlobalVar('HTTP_X_FORWARDED_PROTO', $forwarded_proto, SQ_SERVER))
  606.         $forwarded_proto = '';
  607.     if (empty($sq_https_port)) // won't work with port 0 (zero)
  608.        $sq_https_port = 443;
  609.     if ((isset($https_env_var) && strcasecmp($https_env_var, 'on') === 0)
  610.      || (sqgetGlobalVar('HTTPS', $https, SQ_SERVER) && !empty($https)
  611.       && strcasecmp($https, 'off') !== 0)
  612.      || (strcasecmp($forwarded_proto, 'https') === 0)
  613.      || (sqgetGlobalVar('SERVER_PORT', $server_port, SQ_SERVER)
  614.       && $server_port == $sq_https_port))
  615.         return TRUE;
  616.     return FALSE;
  617. }
  618.  
  619. /**
  620.  * Determine if there are lines in a file longer than a given length
  621.  *
  622.  * @param string $filename   The full file path of the file to inspect
  623.  * @param int    $max_length If any lines in the file are GREATER THAN
  624.  *                            this number, this function returns TRUE.
  625.  *
  626.  * @return boolean TRUE as explained above, otherwise, (no long lines
  627.  *                  found) FALSE is returned.
  628.  *
  629.  */
  630. function file_has_long_lines($filename, $max_length) {
  631.  
  632.     $FILE = @fopen($filename, 'rb');
  633.  
  634.     if ($FILE) {
  635.         while (!feof($FILE)) {
  636.             $buffer = fgets($FILE, 4096);
  637.             if (strlen($buffer) > $max_length) {
  638.                 fclose($FILE);
  639.                 return TRUE;
  640.             }
  641.         }
  642.         fclose($FILE);
  643.     }
  644.  
  645.     return FALSE;
  646. }

Documentation generated on Mon, 13 Jan 2020 04:24:40 +0100 by phpDocumentor 1.4.3