From 52e820fc7bc86c892c343d127a8403ff2fa84ae8 Mon Sep 17 00:00:00 2001 From: megan_w Date: Tue, 25 Nov 2008 11:35:31 +0000 Subject: [PATCH] KTS-3882 - Added config settings for both internal and external ip's and ports for indexing and alerts emails. "Indexer not working" --- config/dmsDefaults.php | 33 +++++++++++++++++++++++++++++---- lib/upgrades/UpgradeFunctions.inc.php | 16 ++++++++++++++-- lib/util/ktutil.inc | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- sql/mysql/install/data.sql | 10 ++++++++-- sql/mysql/upgrade/3.5.4/server_config_settings.sql | 10 ++++++++++ 5 files changed, 153 insertions(+), 59 deletions(-) create mode 100644 sql/mysql/upgrade/3.5.4/server_config_settings.sql diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php index ecbf690..7ec4b10 100644 --- a/config/dmsDefaults.php +++ b/config/dmsDefaults.php @@ -425,8 +425,8 @@ class KTInit { { $oKTConfig =& KTConfig::getSingleton(); + // Override the config setting - KT_DIR is resolved on page load $oKTConfig->setdefaultns('KnowledgeTree', 'fileSystemRoot', KT_DIR); - $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', KTUtil::arrayGet($_SERVER, 'HTTP_HOST', 'localhost')); // Set ssl to enabled if using https - if the server variable is not set, allow the config setting to take precedence if (array_key_exists('HTTPS', $_SERVER)) { @@ -434,9 +434,34 @@ class KTInit { $oKTConfig->setdefaultns('KnowledgeTree', 'sslEnabled', 'true'); } } - $oKTConfig->setdefaultns('KnowledgeTree', 'rootUrl', $this->guessRootUrl()); - $oKTConfig->setdefaultns('KnowledgeTree', 'execSearchPath', $_SERVER['PATH']); - $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', KTInit::detectMagicFile()); + + $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', $_SERVER['HTTP_HOST']); + + // Check for the config setting before overriding with the resolved setting + $serverName = $oKTConfig->get('KnowledgeTree/serverName'); + $rootUrl = $oKTConfig->get('KnowledgeTree/rootUrl'); + $execSearchPath = $oKTConfig->get('KnowledgeTree/execSearchPath'); + $magicDatabase = $oKTConfig->get('KnowledgeTree/magicDatabase'); + + // base server name + if(empty($serverName) || $serverName == 'default'){ + $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', KTUtil::getServerName()); + } + + // the sub directory or root url + if(empty($rootUrl) || $rootUrl == 'default'){ + $oKTConfig->setdefaultns('KnowledgeTree', 'rootUrl', $this->guessRootUrl()); + } + + // path to find the executable binaries + if(empty($execSearchPath) || $execSearchPath == 'default'){ + $oKTConfig->setdefaultns('KnowledgeTree', 'execSearchPath', $_SERVER['PATH']); + } + + // path to magic database + if(empty($magicDatabase) || $magicDatabase == 'default'){ + $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', KTInit::detectMagicFile()); + } } // }}} diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php index d9f6f78..2134d36 100644 --- a/lib/upgrades/UpgradeFunctions.inc.php +++ b/lib/upgrades/UpgradeFunctions.inc.php @@ -62,7 +62,7 @@ class UpgradeFunctions { '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'), '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'), '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier','removeOldSearchPlugins','addAutoIncrementToTables', 'addAutoIncrementToTables2'), - '3.5.4' => array('createIndexes') + '3.5.4' => array('createIndexes', 'updateServerConfigSettings') ); var $descriptions = array( @@ -97,7 +97,8 @@ class UpgradeFunctions { 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.', 'removeOldSearchPlugins' => 'Remove the old Search Plugins.', 'addAutoIncrementToTables' => 'Update all current db tables to use auto_increment.', - 'addAutoIncrementToTables2' => 'Update all new db tables to use auto_increment.' + 'addAutoIncrementToTables2' => 'Update all new db tables to use auto_increment.', + 'updateServerConfigSettings' => 'Update the configuration settings for the server with the correct port' ); var $phases = array( "setPermissionFolder" => 1, @@ -1363,6 +1364,17 @@ class UpgradeFunctions { return true; } + function updateServerConfigSettings() { + global $default; + $port = $_SERVER['SERVER_PORT']+0; + + if($port > 0){ + DBUtil::whereUpdate('config_settings', + array('value' => $port), + array('item' => 'internal_server_port', 'group_name' => 'server')); + } + } + function rm_recursive($filepath) { if (is_dir($filepath) && !is_link($filepath)) diff --git a/lib/util/ktutil.inc b/lib/util/ktutil.inc index 3348145..b5232b6 100644 --- a/lib/util/ktutil.inc +++ b/lib/util/ktutil.inc @@ -58,40 +58,76 @@ class KTUtil { { global $default; - $serverName = KTUtil::getSystemSetting('server_name', false); - if($serverName !== false && !empty($serverName)){ - return $serverName; - } + $serverName = $default->server_name; + $serverPort = $default->server_port; + + $pos = strpos($serverName, '://'); + if($pos !== false){ + $serverName = substr($serverName, $pos + 3); + } - $rootUrl = $default->rootUrl; - $protocol = $default->sslEnabled ? 'https' : 'http'; - $port = $_SERVER['SERVER_PORT']+0; - $serverName = $_SERVER['SERVER_NAME']; + $server = $_SERVER['SERVER_NAME']; + $port = $_SERVER['SERVER_PORT']+0; + + // If server_name exists, exit + if(!empty($serverName)){ + // check that it hasn't changed and update if it has - disabled because it should be set by the system administrator and may have unforeseen consequences + //if($port == $serverPort && $server == $serverName){ + return true; + //} + } - // We don't want to set the servername to localhost, it should be set to the url that will be used normally - if($serverName == 'localhost' || $serverName == '127.0.0.1') + // We don't want to set the servername to localhost, it should be set to the url that will be used normally + if($server == 'localhost' || $server == '127.0.0.1') { return false; } - $base_url = $protocol . '://' . $serverName; + // If the servername is empty and not localhost - update it - if (($protocol == 'http' && $port == 80) || ($protocol == 'https' && $port == 443)) - { - // don't need to do anything - } - else - { - $base_url .= ':' . $port; - } + // Save the server name and port + DBUtil::whereUpdate('config_settings', + array('value' => $server), + array('item' => 'server_name', 'group_name' => 'server')); - // Add the root url - $base_url .= $rootUrl; + if($port > 0){ + DBUtil::whereUpdate('config_settings', + array('value' => $port), + array('item' => 'server_port', 'group_name' => 'server')); + } - // Save as system setting - KTUtil::setSystemSetting('server_name', $base_url); + // Save the rootUrl + $rootUrl = $default->rootUrl; + if(!empty($rootUrl)){ + DBUtil::whereUpdate('config_settings', + array('value' => $rootUrl), + array('item' => 'rootUrl', 'group_name' => 'KnowledgeTree')); + } + return true; } + static function getServerName() + { + static $host = null; + + if(!is_null($host)){ + return $host; + } + + $host = $_SERVER['HTTP_HOST']; + + if(empty($host)){ + global $default; + $host = (!empty($default->server_name)) ? $default->server_name : '127.0.0.1'; + $host .= !empty($default->server_port) ? ':'.$default->server_port : ''; + + $pos = strpos($host, '://'); + if($pos !== false){ + $host = substr($host, $pos + 3); + } + } + return $host; + } static function kt_url() { @@ -103,30 +139,13 @@ class KTUtil { return $base_url; } - $config = KTConfig::getSingleton(); - $serverName = $config->get('knowledgeTree/serverName', $_SERVER['HTTP_HOST']); + $serverName = $_SERVER['HTTP_HOST']; - // $serverName gets set in dmsDefaults, if $_SERVER['HTTP_HOST'] is empty, it gets set to localhost - // we want to avoid this if possible - if(empty($serverName) || $serverName == 'localhost') + // $serverName gets set in dmsDefaults using KTUtil::getServerName(); + if(empty($serverName)) { - // The host has not been set - check if the serverName setting exists - $base_url = KTUtil::getSystemSetting('server_name', false); - - if (false !== $base_url && !empty($base_url)) - { - /* We are checking if the object exists because we could have an error pre or during initialization */ - if(is_object($default->log)) - { - $default->log->debug("kt_url: base url - $base_url"); - } - - $base_url = str_replace(array("\n","\r"), array('',''), $base_url); - return $base_url; - } - - // TODO: Check if the $_SERVER['SERVER_NAME'] variable is set. - $serverName = 'localhost'; + // The host has not been set - check if server_name is set in the config_settings + $serverName = KTUtil::getServerName(); } // build up the url @@ -138,23 +157,45 @@ class KTUtil { return $base_url; } + static function kt_internal_url() + { + global $default; + static $internal_url = null; + + if(!is_null($internal_url)){ + return $internal_url; + } + + // build url + $internal_url = !empty($default->internal_server_name) ? $default->internal_server_name : '127.0.0.1'; + $internal_url .= !empty($default->internal_server_port) ? ':' . $default->internal_server_port : ''; + $internal_url .= !empty($default->rootUrl) ? $default->rootUrl : ''; + + $pos = strpos($internal_url, '://'); + if($pos === false){ + $port = $default->internal_server_port; + $internal_url = (($port == 443 || $port == 8443) ? 'https://' : 'http://') . $internal_url; + } + + return $internal_url; + } + static function call_page($path) { global $default; - $base_url = KTUtil::getSystemSetting('server_name', false); + // Using curl so we want to run using the internal url + $base_url = KTUtil::kt_internal_url(); if (false === $base_url || empty($base_url)) { - $default->log->info("call_page: $path - cannot call script until user logs in from a url other than localhost or 127.0.0.1!"); + $default->log->info("call_page: $path - cannot call script, there is a problem with the internal url. Please check the configuration settings for General Settings => Server Settings."); return; } - $kt_url = KTUtil::kt_url(); - - $full_url = $kt_url . '/' . $path; + $full_url = $base_url . '/' . $path; - $default->log->debug("call_page: calling $full_url"); + $default->log->debug("call_page: calling curl with - $full_url"); $ch = curl_init($full_url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index b3a4c67..b2228dd 100644 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -161,7 +161,8 @@ INSERT INTO `config_groups` VALUES (20, 'urls', 'Urls', 'The paths to the KnowledgeTree server and filesystem.
Full values are specific to your installation (Windows or Linux). Only advanced users should change these settings.', 'General Settings'), (21, 'user_prefs', 'User Preferences', 'Configures user preferences.', 'General Settings'), (22, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Settings'), -(23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'); +(23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'), +(24, 'server', 'Server Settings', 'Configuration settings for the server', 'General Settings'); /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */; UNLOCK TABLES; @@ -276,7 +277,12 @@ INSERT INTO `config_settings` VALUES (102, 'tweaks', 'Update Document Version (Content) on Editing Metadata', 'The document version is equivalent to the document content version. When set to true the document version will be increased when the document metadata is updated.', 'updateContentVersion', 'default', 'false', 'boolean', NULL, 1), (103, 'tweaks', 'Always Force Original Filename on Checkin', 'When set to true, the checkbox for "Force Original Filename" will be hidden on check-in. This ensures that the filename will always stay the same.', 'disableForceFilenameOption', 'default', 'false', 'boolean', NULL, 1), (104, 'KnowledgeTree', 'The Location of the Mime Magic File', 'The path to the mime magic database file.', 'magicDatabase', 'default', '/usr/share/file/magic', 'string', NULL, 1), -(105, 'search', 'Maximum results from SQL query', 'The maximum results from an SQL query', 'maxSqlResults', 'default', '1000', 'numeric_string', NULL, 1); +(105, 'search', 'Maximum results from SQL query', 'The maximum results from an SQL query', 'maxSqlResults', 'default', '1000', 'numeric_string', NULL, 1), +(106, 'server', 'Internal Server IP', 'The internal IP for the server, this is usually set to 127.0.0.1.', 'internal_server_name', 'default', '127.0.0.1', 'string', NULL, 1), +(107, 'server', 'Internal Server port', 'The internal port for the server.', 'internal_server_port', 'default', '80', 'numeric_string', NULL, 1), +(108, 'server', 'External Server IP', 'The external IP for the server.', 'server_name', 'default', '', 'string', NULL, 1), +(109, 'server', 'External Server port', 'The external port for the server.', 'server_port', 'default', '', 'numeric_string', NULL, 1), +(110, 'KnowledgeTree', 'Root Url', 'The path to the web application from the root of the web server. For example, if KT is at http://example.org/foo/, then the root directory should be \'/foo\'.', 'rootUrl', '', '', 'string', NULL, 1); /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/mysql/upgrade/3.5.4/server_config_settings.sql b/sql/mysql/upgrade/3.5.4/server_config_settings.sql new file mode 100644 index 0000000..7b21cf8 --- /dev/null +++ b/sql/mysql/upgrade/3.5.4/server_config_settings.sql @@ -0,0 +1,10 @@ +INSERT INTO config_groups (name, display_name, description, category) VALUES +('server', 'Server Settings', 'Configuration settings for the server', 'General Settings'); + + +INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) VALUES +('server', 'Internal Server IP', 'The internal IP for the server, this is usually set to 127.0.0.1.', 'internal_server_name', 'default', '127.0.0.1', 'string', NULL, 1), +('server', 'Internal Server port', 'The internal port for the server.', 'internal_server_port', 'default', '80', 'numeric_string', NULL, 1), +('server', 'External Server IP', 'The external IP for the server.', 'server_name', 'default', '', 'string', NULL, 1), +('server', 'External Server port', 'The external port for the server.', 'server_port', 'default', '', 'numeric_string', NULL, 1), +('KnowledgeTree', 'Root Url', 'The path to the web application from the root of the web server. For example, if KT is at http://example.org/foo/, then the root directory should be \'/foo\'.', 'rootUrl', '', '', 'string', NULL, 1); -- libgit2 0.21.4