diff options
| -rw-r--r-- | admin_site_access.php | 10 | ||||
| -rw-r--r-- | app/Log.php | 4 | ||||
| -rw-r--r-- | app/Mail.php | 4 | ||||
| -rw-r--r-- | includes/session.php | 27 | ||||
| -rw-r--r-- | login.php | 10 | ||||
| -rw-r--r-- | message.php | 4 | ||||
| -rw-r--r-- | setup.php | 5 |
7 files changed, 26 insertions, 38 deletions
diff --git a/admin_site_access.php b/admin_site_access.php index 52aafe3a90..74bc863636 100644 --- a/admin_site_access.php +++ b/admin_site_access.php @@ -17,14 +17,6 @@ namespace Fisharebest\Webtrees; */ use PDO; -use Zend_Controller_Request_Http; - -/** - * Defined in session.php - * - * @global Zend_Controller_Request_Http $WT_REQUEST - */ -global $WT_REQUEST; define('WT_SCRIPT_NAME', 'admin_site_access.php'); require './includes/session.php'; @@ -54,7 +46,7 @@ case 'save': $rule = Filter::post('rule', 'allow|deny|robot'); $comment = Filter::post('comment'); $user_agent_string = Filter::server('HTTP_USER_AGENT'); - $ip_address = $WT_REQUEST->getClientIp(); + $ip_address = WT_CLIENT_IP; if ($ip_address_start !== null && $ip_address_end !== null && $user_agent_pattern !== null && $rule !== null) { // This doesn't work with named placeholders. The :user_agent_string parameter is not recognised... diff --git a/app/Log.php b/app/Log.php index b018233338..b483be05ca 100644 --- a/app/Log.php +++ b/app/Log.php @@ -38,7 +38,7 @@ class Log { * @param Tree|null $tree */ private static function addLog($message, $log_type, Tree $tree = null) { - global $WT_REQUEST, $WT_TREE; + global $WT_TREE; if (!$tree) { $tree = $WT_TREE; @@ -49,7 +49,7 @@ class Log { )->execute(array( $log_type, $message, - $WT_REQUEST->getClientIp(), + WT_CLIENT_IP, Auth::id(), $tree ? $tree->getTreeId() : null )); diff --git a/app/Mail.php b/app/Mail.php index 36edb40513..a654d2efc9 100644 --- a/app/Mail.php +++ b/app/Mail.php @@ -33,12 +33,10 @@ class Mail { * @return string */ public static function auditFooter() { - global $WT_REQUEST; - return self::EOL . '---------------------------------------' . self::EOL . - 'IP ADDRESS: ' . $WT_REQUEST->getClientIp() . self::EOL . + 'IP ADDRESS: ' . WT_CLIENT_IP . self::EOL . 'LANGUAGE: ' . WT_LOCALE . self::EOL; } diff --git a/includes/session.php b/includes/session.php index 41e730b8f3..b30a0ac240 100644 --- a/includes/session.php +++ b/includes/session.php @@ -17,7 +17,6 @@ namespace Fisharebest\Webtrees; */ use PDOException; -use Zend_Controller_Request_Http; /** * This is the bootstrap script, that is run on every request. @@ -32,11 +31,10 @@ if (!defined('WT_SCRIPT_NAME')) { /** * We set the following globals * - * @global boolean $SEARCH_SPIDER - * @global Zend_Controller_Request_Http $WT_REQUEST - * @global Tree $WT_TREE + * @global boolean $SEARCH_SPIDER + * @global Tree $WT_TREE */ -global $WT_REQUEST, $WT_TREE, $SEARCH_SPIDER; +global $WT_TREE, $SEARCH_SPIDER; // Identify ourself define('WT_WEBTREES', 'webtrees'); @@ -284,7 +282,14 @@ if (file_exists(WT_ROOT . 'data/config.ini.php')) { exit; } -$WT_REQUEST = new Zend_Controller_Request_Http; +// What is the remote client's IP address +if (Filter::server('HTTP_CLIENT_IP') !== null) { + define('WT_CLIENT_IP', Filter::server('HTTP_CLIENT_IP')); +} else if (Filter::server('HTTP_X_FORWARDED_FOR') !== null) { + define('WT_CLIENT_IP', Filter::server('HTTP_X_FORWARDED_FOR')); +} else { + define('WT_CLIENT_IP', Filter::server('REMOTE_ADDR')); +} // Connect to the database try { @@ -328,7 +333,7 @@ $rule = Database::prepare( " WHERE IFNULL(INET_ATON(?), 0) BETWEEN ip_address_start AND ip_address_end" . " AND ? LIKE user_agent_pattern" . " ORDER BY ip_address_end LIMIT 1" -)->execute(array($WT_REQUEST->getClientIp(), Filter::server('HTTP_USER_AGENT')))->fetchOne(); +)->execute(array(WT_CLIENT_IP, Filter::server('HTTP_USER_AGENT')))->fetchOne(); switch ($rule) { case 'allow': @@ -341,13 +346,13 @@ case 'robot': case 'unknown': // Search engines don’t send cookies, and so create a new session with every visit. // Make sure they always use the same one - Session::setId('search-engine-' . str_replace('.', '-', $WT_REQUEST->getClientIp())); + Session::setId('search-engine-' . str_replace('.', '-', WT_CLIENT_IP)); $SEARCH_SPIDER = true; break; case '': Database::prepare( "INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, comment) VALUES (IFNULL(INET_ATON(?), 0), IFNULL(INET_ATON(?), 4294967295), ?, '')" - )->execute(array($WT_REQUEST->getClientIp(), $WT_REQUEST->getClientIp(), Filter::server('HTTP_USER_AGENT', null, ''))); + )->execute(array(WT_CLIENT_IP, WT_CLIENT_IP, Filter::server('HTTP_USER_AGENT', null, ''))); $SEARCH_SPIDER = true; break; } @@ -367,7 +372,7 @@ session_set_save_handler( return Database::prepare("SELECT session_data FROM `##session` WHERE session_id=?")->execute(array($id))->fetchOne(); }, // write - function($id, $data) use ($WT_REQUEST) { + function($id, $data) { // Only update the session table once per minute, unless the session data has actually changed. Database::prepare( "INSERT INTO `##session` (session_id, user_id, ip_address, session_data, session_time)" . @@ -377,7 +382,7 @@ session_set_save_handler( " ip_address = VALUES(ip_address)," . " session_data = VALUES(session_data)," . " session_time = CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP)" - )->execute(array($id, (int) Auth::id(), $WT_REQUEST->getClientIp(), $data)); + )->execute(array($id, (int) Auth::id(), WT_CLIENT_IP, $data)); return true; }, @@ -17,15 +17,13 @@ namespace Fisharebest\Webtrees; */ use Rhumsaa\Uuid\Uuid; -use Zend_Controller_Request_Http; /** * Defined in session.php * - * @global Zend_Controller_Request_Http $WT_REQUEST - * @global Tree $WT_TREE + * @global Tree $WT_TREE */ -global $WT_REQUEST, $WT_TREE; +global $WT_TREE; define('WT_SCRIPT_NAME', 'login.php'); require './includes/session.php'; @@ -369,7 +367,7 @@ case 'register': $mail1_method = $webmaster->getPreference('contact_method'); if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') { Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)") - ->execute(array($user->getEmail(), $WT_REQUEST->getClientIp(), $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body))); + ->execute(array($user->getEmail(), WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body))); } echo '<div class="confirm"><p>', I18N::translate('Hello %s…<br>Thank you for your registration.', $user->getRealNameHtml()), '</p>'; @@ -585,7 +583,7 @@ case 'verify_hash': $mail1_method = $webmaster->getPreference('CONTACT_METHOD'); if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') { Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)") - ->execute(array($user_name, $WT_REQUEST->getClientIp(), $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body))); + ->execute(array($user_name, WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body))); } $user diff --git a/message.php b/message.php index 70775dd41b..48850cc3f3 100644 --- a/message.php +++ b/message.php @@ -208,7 +208,7 @@ case 'send': * @return bool */ function addMessage($message) { - global $WT_TREE, $WT_REQUEST; + global $WT_TREE; $success = true; @@ -290,7 +290,7 @@ function addMessage($message) { Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)") ->execute(array( $message['from'], - $WT_REQUEST->getClientIp(), + WT_CLIENT_IP, $recipient->getUserId(), $message['subject'], str_replace('<br>', '', $message['body']) // Remove the <br> that we added for the external email. TODO: create different messages @@ -17,13 +17,9 @@ namespace Fisharebest\Webtrees; */ use PDOException; -use Zend_Controller_Request_Http; error_reporting(E_ALL); -// To embed webtrees code in other applications, we must explicitly declare any global variables that we create. -global $WT_REQUEST; - define('WT_SCRIPT_NAME', 'setup.php'); define('WT_CONFIG_FILE', 'config.ini.php'); @@ -63,7 +59,6 @@ if (version_compare(PHP_VERSION, WT_REQUIRED_PHP_VERSION) < 0) { Session::start(); -$WT_REQUEST = new Zend_Controller_Request_Http; define('WT_LOCALE', I18N::init(Filter::post('lang', '[@a-zA-Z_]+'))); header('Content-Type: text/html; charset=UTF-8'); |
