Changeset 735 for trunk/lib


Ignore:
Timestamp:
Oct 30, 2020 11:44:05 PM (4 years ago)
Author:
anonymous
Message:

Minor polish. Add getHttpHeader function

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r734 r735  
    962962        }
    963963
    964         // Make sure to log in the system's locale.
     964        // Use the system's locale for log messages (return to previous setting below).
    965965        $locale = setlocale(LC_TIME, 0);
    966966        setlocale(LC_TIME, 'C');
     967
     968        // Logs should always be in UTC (return to previous setting below).
     969        $tz = date_default_timezone_get();
     970        date_default_timezone_set('UTC');
    967971
    968972        // Data to be stored for a log event.
     
    10171021        // Restore original locale.
    10181022        setlocale(LC_TIME, $locale);
     1023
     1024        // Restore original timezone.
     1025        date_default_timezone_set($tz);
    10191026
    10201027        return true;
  • trunk/lib/Auth_SQL.inc.php

    r706 r735  
    728728                    // Only raise message if last session is less than 12 hours old.
    729729                    // Notify user why they were logged out if they haven't yet been given a reason.
    730                     $user_notified || $app->raiseMsg(sprintf(_("For your security we logged you out after being idle for %s. Please log in again."), humanTime($this->_params['idle_timeout'], 'hour', '%01.0f')), MSG_NOTICE, __FILE__, __LINE__);
     730                    $user_notified || $app->raiseMsg(sprintf(_("For your security, we logged you out after being idle for %s. Please log in again."), humanTime($this->_params['idle_timeout'], 'hour', '%01.0f')), MSG_NOTICE, __FILE__, __LINE__);
    731731                    $user_notified = true;
    732732                }
     
    740740                    $expire_reasons[] = sprintf('remote_ip not matched (%s != %s)', $_SESSION['_auth_sql'][$this->_ns]['remote_ip'], getRemoteAddr());
    741741                    // Notify user why they were logged out if they haven't yet been given a reason.
    742                     $user_notified || $app->raiseMsg(sprintf(_("For your security we logged you out because your IP address has changed. Please log in again."), null), MSG_NOTICE, __FILE__, __LINE__);
     742                    $user_notified || $app->raiseMsg(sprintf(_("For your security, we logged you out because your IP address changed. Please log in again."), null), MSG_NOTICE, __FILE__, __LINE__);
    743743                    $user_notified = true;
    744744                } else {
  • trunk/lib/Email.inc.php

    r724 r735  
    112112        . '((?:[^.<>\s@",\[\]]+[^<>\s@",\[\]])*[^.<>\s@",\[\]]+)'       // Local-part
    113113        . '@'                                                           // @
    114         . '((?:(\[)|[A-Z0-9]?)'                                         // Domain, first char
     114        . '((?:(\[)|[a-z0-9]?)'                                         // Domain, first char
    115115        . '(?(4)'                                                       // Domain conditional for if first domain char is [
    116116        . '(?:[0-9]{1,3}\.){3}[0-9]{1,3}\]'                             // TRUE, matches IP address
    117117        . '|'
    118         . '[.-]?(?:[A-Z0-9]+[-.])*(?:[A-Z0-9]+\.)+[A-Z]{2,6}))'         // FALSE, matches domain name
     118        . '[.-]?(?:[a-z0-9]+[-.])*(?:[a-z0-9]+\.)+[a-z]{2,19}))'        // FALSE, matches domain name
    119119        . '(?(1)'                                                       // Comment conditional for if initial < exists
    120120        . '(?:\s*>\s*|>\s+\([^,@]+\)\s*)'                               // TRUE, ensure ending >
     
    398398            $envelope_sender_address = sprintf('<%s>', trim($this->_params['envelope_sender_address'], '<>'));
    399399        } else {
    400             $envelope_sender_address = preg_replace('/^.*<?([^\s@\[\]<>()]+\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5})>?$/iU' . $app->getParam('preg_u'), '$1', $this->_params['from']);
     400            $envelope_sender_address = preg_replace('/^.*<?([^\s@\[\]<>()]+\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,19})>?$/iU' . $app->getParam('preg_u'), '$1', $this->_params['from']);
    401401        }
    402402        if ('' != $envelope_sender_address && $this->validEmail($envelope_sender_address)) {
  • trunk/lib/Utilities.inc.php

    r729 r735  
    15191519* @since    02 May 2015 15:10:09
    15201520*/
    1521 function httpExists($url)
     1521function httpExists($url, $timeout=5)
    15221522{
    15231523    $ch = curl_init($url);
    1524     curl_setopt($ch, CURLOPT_TIMEOUT, 5);
     1524    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    15251525    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    15261526    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     
    15471547    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    15481548    return preg_match('/^[23]\d\d$/', $http_code);
     1549}
     1550
     1551/*
     1552* Get a HTTP response header.
     1553*
     1554* @access   public
     1555* @param    string  $url    URL to hit.
     1556* @param    string  $key    Name of the header to return.
     1557* @param    array   $valid_response_codes   Array of acceptable HTTP return codes.
     1558* @return   string  Value of the http header.
     1559* @author   Quinn Comendant <quinn@strangecode.com>
     1560* @since    28 Oct 2020 20:00:36
     1561*/
     1562function getHttpHeader($url, $key, Array $valid_response_codes=[200])
     1563{
     1564    $headers = @get_headers($url, 1);
     1565
     1566    if ($headers && preg_match(sprintf('/\b(%s)\b/', join('|', $valid_response_codes)), $headers[0])) {
     1567        $headers = array_change_key_case($headers, CASE_LOWER);
     1568        $key = strtolower($key);
     1569        if (isset($headers[$key])) {
     1570            return $headers[$key];
     1571        }
     1572    }
     1573
     1574    return false;
    15491575}
    15501576
Note: See TracChangeset for help on using the changeset viewer.