Commit 52e820fc7bc86c892c343d127a8403ff2fa84ae8
1 parent
f076fb23
KTS-3882 - Added config settings for both internal and external ip's and ports f…
…or indexing and alerts emails. "Indexer not working" Committed by: Megan Watson Reviewed by: Donald Jackson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/branches/RB_3.5.4a@9621 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
153 additions
and
59 deletions
config/dmsDefaults.php
| ... | ... | @@ -425,8 +425,8 @@ class KTInit { |
| 425 | 425 | { |
| 426 | 426 | $oKTConfig =& KTConfig::getSingleton(); |
| 427 | 427 | |
| 428 | + // Override the config setting - KT_DIR is resolved on page load | |
| 428 | 429 | $oKTConfig->setdefaultns('KnowledgeTree', 'fileSystemRoot', KT_DIR); |
| 429 | - $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', KTUtil::arrayGet($_SERVER, 'HTTP_HOST', 'localhost')); | |
| 430 | 430 | |
| 431 | 431 | // Set ssl to enabled if using https - if the server variable is not set, allow the config setting to take precedence |
| 432 | 432 | if (array_key_exists('HTTPS', $_SERVER)) { |
| ... | ... | @@ -434,9 +434,34 @@ class KTInit { |
| 434 | 434 | $oKTConfig->setdefaultns('KnowledgeTree', 'sslEnabled', 'true'); |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | - $oKTConfig->setdefaultns('KnowledgeTree', 'rootUrl', $this->guessRootUrl()); | |
| 438 | - $oKTConfig->setdefaultns('KnowledgeTree', 'execSearchPath', $_SERVER['PATH']); | |
| 439 | - $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', KTInit::detectMagicFile()); | |
| 437 | + | |
| 438 | + $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', $_SERVER['HTTP_HOST']); | |
| 439 | + | |
| 440 | + // Check for the config setting before overriding with the resolved setting | |
| 441 | + $serverName = $oKTConfig->get('KnowledgeTree/serverName'); | |
| 442 | + $rootUrl = $oKTConfig->get('KnowledgeTree/rootUrl'); | |
| 443 | + $execSearchPath = $oKTConfig->get('KnowledgeTree/execSearchPath'); | |
| 444 | + $magicDatabase = $oKTConfig->get('KnowledgeTree/magicDatabase'); | |
| 445 | + | |
| 446 | + // base server name | |
| 447 | + if(empty($serverName) || $serverName == 'default'){ | |
| 448 | + $oKTConfig->setdefaultns('KnowledgeTree', 'serverName', KTUtil::getServerName()); | |
| 449 | + } | |
| 450 | + | |
| 451 | + // the sub directory or root url | |
| 452 | + if(empty($rootUrl) || $rootUrl == 'default'){ | |
| 453 | + $oKTConfig->setdefaultns('KnowledgeTree', 'rootUrl', $this->guessRootUrl()); | |
| 454 | + } | |
| 455 | + | |
| 456 | + // path to find the executable binaries | |
| 457 | + if(empty($execSearchPath) || $execSearchPath == 'default'){ | |
| 458 | + $oKTConfig->setdefaultns('KnowledgeTree', 'execSearchPath', $_SERVER['PATH']); | |
| 459 | + } | |
| 460 | + | |
| 461 | + // path to magic database | |
| 462 | + if(empty($magicDatabase) || $magicDatabase == 'default'){ | |
| 463 | + $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', KTInit::detectMagicFile()); | |
| 464 | + } | |
| 440 | 465 | } |
| 441 | 466 | // }}} |
| 442 | 467 | ... | ... |
lib/upgrades/UpgradeFunctions.inc.php
| ... | ... | @@ -62,7 +62,7 @@ class UpgradeFunctions { |
| 62 | 62 | '3.5.0' => array('cleanupOldKTAdminVersionNotifier', 'updateConfigFile35', 'registerIndexingTasks'), |
| 63 | 63 | '3.5.2' => array('setStorageEngine','dropForeignKeys','dropPrimaryKeys','dropIndexes','createPrimaryKeys','createForeignKeys','createIndexes', 'removeSlashesFromObjects'), |
| 64 | 64 | '3.5.3' => array('moveConfigSettingsToDB','removeAdminVersionNotifier','removeOldSearchPlugins','addAutoIncrementToTables', 'addAutoIncrementToTables2'), |
| 65 | - '3.5.4' => array('createIndexes') | |
| 65 | + '3.5.4' => array('createIndexes', 'updateServerConfigSettings') | |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | 68 | var $descriptions = array( |
| ... | ... | @@ -97,7 +97,8 @@ class UpgradeFunctions { |
| 97 | 97 | 'removeAdminVersionNotifier' => 'Remove the old Admin Version Notifier Plugin.', |
| 98 | 98 | 'removeOldSearchPlugins' => 'Remove the old Search Plugins.', |
| 99 | 99 | 'addAutoIncrementToTables' => 'Update all current db tables to use auto_increment.', |
| 100 | - 'addAutoIncrementToTables2' => 'Update all new db tables to use auto_increment.' | |
| 100 | + 'addAutoIncrementToTables2' => 'Update all new db tables to use auto_increment.', | |
| 101 | + 'updateServerConfigSettings' => 'Update the configuration settings for the server with the correct port' | |
| 101 | 102 | ); |
| 102 | 103 | var $phases = array( |
| 103 | 104 | "setPermissionFolder" => 1, |
| ... | ... | @@ -1363,6 +1364,17 @@ class UpgradeFunctions { |
| 1363 | 1364 | return true; |
| 1364 | 1365 | } |
| 1365 | 1366 | |
| 1367 | + function updateServerConfigSettings() { | |
| 1368 | + global $default; | |
| 1369 | + $port = $_SERVER['SERVER_PORT']+0; | |
| 1370 | + | |
| 1371 | + if($port > 0){ | |
| 1372 | + DBUtil::whereUpdate('config_settings', | |
| 1373 | + array('value' => $port), | |
| 1374 | + array('item' => 'internal_server_port', 'group_name' => 'server')); | |
| 1375 | + } | |
| 1376 | + } | |
| 1377 | + | |
| 1366 | 1378 | function rm_recursive($filepath) |
| 1367 | 1379 | { |
| 1368 | 1380 | if (is_dir($filepath) && !is_link($filepath)) | ... | ... |
lib/util/ktutil.inc
| ... | ... | @@ -58,40 +58,76 @@ class KTUtil { |
| 58 | 58 | { |
| 59 | 59 | global $default; |
| 60 | 60 | |
| 61 | - $serverName = KTUtil::getSystemSetting('server_name', false); | |
| 62 | - if($serverName !== false && !empty($serverName)){ | |
| 63 | - return $serverName; | |
| 64 | - } | |
| 61 | + $serverName = $default->server_name; | |
| 62 | + $serverPort = $default->server_port; | |
| 63 | + | |
| 64 | + $pos = strpos($serverName, '://'); | |
| 65 | + if($pos !== false){ | |
| 66 | + $serverName = substr($serverName, $pos + 3); | |
| 67 | + } | |
| 65 | 68 | |
| 66 | - $rootUrl = $default->rootUrl; | |
| 67 | - $protocol = $default->sslEnabled ? 'https' : 'http'; | |
| 68 | - $port = $_SERVER['SERVER_PORT']+0; | |
| 69 | - $serverName = $_SERVER['SERVER_NAME']; | |
| 69 | + $server = $_SERVER['SERVER_NAME']; | |
| 70 | + $port = $_SERVER['SERVER_PORT']+0; | |
| 71 | + | |
| 72 | + // If server_name exists, exit | |
| 73 | + if(!empty($serverName)){ | |
| 74 | + // 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 | |
| 75 | + //if($port == $serverPort && $server == $serverName){ | |
| 76 | + return true; | |
| 77 | + //} | |
| 78 | + } | |
| 70 | 79 | |
| 71 | - // We don't want to set the servername to localhost, it should be set to the url that will be used normally | |
| 72 | - if($serverName == 'localhost' || $serverName == '127.0.0.1') | |
| 80 | + // We don't want to set the servername to localhost, it should be set to the url that will be used normally | |
| 81 | + if($server == 'localhost' || $server == '127.0.0.1') | |
| 73 | 82 | { |
| 74 | 83 | return false; |
| 75 | 84 | } |
| 76 | 85 | |
| 77 | - $base_url = $protocol . '://' . $serverName; | |
| 86 | + // If the servername is empty and not localhost - update it | |
| 78 | 87 | |
| 79 | - if (($protocol == 'http' && $port == 80) || ($protocol == 'https' && $port == 443)) | |
| 80 | - { | |
| 81 | - // don't need to do anything | |
| 82 | - } | |
| 83 | - else | |
| 84 | - { | |
| 85 | - $base_url .= ':' . $port; | |
| 86 | - } | |
| 88 | + // Save the server name and port | |
| 89 | + DBUtil::whereUpdate('config_settings', | |
| 90 | + array('value' => $server), | |
| 91 | + array('item' => 'server_name', 'group_name' => 'server')); | |
| 87 | 92 | |
| 88 | - // Add the root url | |
| 89 | - $base_url .= $rootUrl; | |
| 93 | + if($port > 0){ | |
| 94 | + DBUtil::whereUpdate('config_settings', | |
| 95 | + array('value' => $port), | |
| 96 | + array('item' => 'server_port', 'group_name' => 'server')); | |
| 97 | + } | |
| 90 | 98 | |
| 91 | - // Save as system setting | |
| 92 | - KTUtil::setSystemSetting('server_name', $base_url); | |
| 99 | + // Save the rootUrl | |
| 100 | + $rootUrl = $default->rootUrl; | |
| 101 | + if(!empty($rootUrl)){ | |
| 102 | + DBUtil::whereUpdate('config_settings', | |
| 103 | + array('value' => $rootUrl), | |
| 104 | + array('item' => 'rootUrl', 'group_name' => 'KnowledgeTree')); | |
| 105 | + } | |
| 106 | + return true; | |
| 93 | 107 | } |
| 94 | 108 | |
| 109 | + static function getServerName() | |
| 110 | + { | |
| 111 | + static $host = null; | |
| 112 | + | |
| 113 | + if(!is_null($host)){ | |
| 114 | + return $host; | |
| 115 | + } | |
| 116 | + | |
| 117 | + $host = $_SERVER['HTTP_HOST']; | |
| 118 | + | |
| 119 | + if(empty($host)){ | |
| 120 | + global $default; | |
| 121 | + $host = (!empty($default->server_name)) ? $default->server_name : '127.0.0.1'; | |
| 122 | + $host .= !empty($default->server_port) ? ':'.$default->server_port : ''; | |
| 123 | + | |
| 124 | + $pos = strpos($host, '://'); | |
| 125 | + if($pos !== false){ | |
| 126 | + $host = substr($host, $pos + 3); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + return $host; | |
| 130 | + } | |
| 95 | 131 | |
| 96 | 132 | static function kt_url() |
| 97 | 133 | { |
| ... | ... | @@ -103,30 +139,13 @@ class KTUtil { |
| 103 | 139 | return $base_url; |
| 104 | 140 | } |
| 105 | 141 | |
| 106 | - $config = KTConfig::getSingleton(); | |
| 107 | - $serverName = $config->get('knowledgeTree/serverName', $_SERVER['HTTP_HOST']); | |
| 142 | + $serverName = $_SERVER['HTTP_HOST']; | |
| 108 | 143 | |
| 109 | - // $serverName gets set in dmsDefaults, if $_SERVER['HTTP_HOST'] is empty, it gets set to localhost | |
| 110 | - // we want to avoid this if possible | |
| 111 | - if(empty($serverName) || $serverName == 'localhost') | |
| 144 | + // $serverName gets set in dmsDefaults using KTUtil::getServerName(); | |
| 145 | + if(empty($serverName)) | |
| 112 | 146 | { |
| 113 | - // The host has not been set - check if the serverName setting exists | |
| 114 | - $base_url = KTUtil::getSystemSetting('server_name', false); | |
| 115 | - | |
| 116 | - if (false !== $base_url && !empty($base_url)) | |
| 117 | - { | |
| 118 | - /* We are checking if the object exists because we could have an error pre or during initialization */ | |
| 119 | - if(is_object($default->log)) | |
| 120 | - { | |
| 121 | - $default->log->debug("kt_url: base url - $base_url"); | |
| 122 | - } | |
| 123 | - | |
| 124 | - $base_url = str_replace(array("\n","\r"), array('',''), $base_url); | |
| 125 | - return $base_url; | |
| 126 | - } | |
| 127 | - | |
| 128 | - // TODO: Check if the $_SERVER['SERVER_NAME'] variable is set. | |
| 129 | - $serverName = 'localhost'; | |
| 147 | + // The host has not been set - check if server_name is set in the config_settings | |
| 148 | + $serverName = KTUtil::getServerName(); | |
| 130 | 149 | } |
| 131 | 150 | |
| 132 | 151 | // build up the url |
| ... | ... | @@ -138,23 +157,45 @@ class KTUtil { |
| 138 | 157 | return $base_url; |
| 139 | 158 | } |
| 140 | 159 | |
| 160 | + static function kt_internal_url() | |
| 161 | + { | |
| 162 | + global $default; | |
| 163 | + static $internal_url = null; | |
| 164 | + | |
| 165 | + if(!is_null($internal_url)){ | |
| 166 | + return $internal_url; | |
| 167 | + } | |
| 168 | + | |
| 169 | + // build url | |
| 170 | + $internal_url = !empty($default->internal_server_name) ? $default->internal_server_name : '127.0.0.1'; | |
| 171 | + $internal_url .= !empty($default->internal_server_port) ? ':' . $default->internal_server_port : ''; | |
| 172 | + $internal_url .= !empty($default->rootUrl) ? $default->rootUrl : ''; | |
| 173 | + | |
| 174 | + $pos = strpos($internal_url, '://'); | |
| 175 | + if($pos === false){ | |
| 176 | + $port = $default->internal_server_port; | |
| 177 | + $internal_url = (($port == 443 || $port == 8443) ? 'https://' : 'http://') . $internal_url; | |
| 178 | + } | |
| 179 | + | |
| 180 | + return $internal_url; | |
| 181 | + } | |
| 182 | + | |
| 141 | 183 | static function call_page($path) |
| 142 | 184 | { |
| 143 | 185 | global $default; |
| 144 | 186 | |
| 145 | - $base_url = KTUtil::getSystemSetting('server_name', false); | |
| 187 | + // Using curl so we want to run using the internal url | |
| 188 | + $base_url = KTUtil::kt_internal_url(); | |
| 146 | 189 | |
| 147 | 190 | if (false === $base_url || empty($base_url)) |
| 148 | 191 | { |
| 149 | - $default->log->info("call_page: $path - cannot call script until user logs in from a url other than localhost or 127.0.0.1!"); | |
| 192 | + $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."); | |
| 150 | 193 | return; |
| 151 | 194 | } |
| 152 | 195 | |
| 153 | - $kt_url = KTUtil::kt_url(); | |
| 154 | - | |
| 155 | - $full_url = $kt_url . '/' . $path; | |
| 196 | + $full_url = $base_url . '/' . $path; | |
| 156 | 197 | |
| 157 | - $default->log->debug("call_page: calling $full_url"); | |
| 198 | + $default->log->debug("call_page: calling curl with - $full_url"); | |
| 158 | 199 | |
| 159 | 200 | $ch = curl_init($full_url); |
| 160 | 201 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); | ... | ... |
sql/mysql/install/data.sql
| ... | ... | @@ -161,7 +161,8 @@ INSERT INTO `config_groups` VALUES |
| 161 | 161 | (20, 'urls', 'Urls', 'The paths to the KnowledgeTree server and filesystem. <br>Full values are specific to your installation (Windows or Linux). Only advanced users should change these settings.', 'General Settings'), |
| 162 | 162 | (21, 'user_prefs', 'User Preferences', 'Configures user preferences.', 'General Settings'), |
| 163 | 163 | (22, 'webservice', 'Web Services', 'KnowledgeTree Web Service Interface configuration. Note that a number of KnowledgeTree Tools rely on this service.', 'Client Tools Settings'), |
| 164 | -(23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'); | |
| 164 | +(23, 'ldapAuthentication', 'LDAP Authentication', 'Configures LDAP Authentication', 'General Settings'), | |
| 165 | +(24, 'server', 'Server Settings', 'Configuration settings for the server', 'General Settings'); | |
| 165 | 166 | /*!40000 ALTER TABLE `config_groups` ENABLE KEYS */; |
| 166 | 167 | UNLOCK TABLES; |
| 167 | 168 | |
| ... | ... | @@ -276,7 +277,12 @@ INSERT INTO `config_settings` VALUES |
| 276 | 277 | (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), |
| 277 | 278 | (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), |
| 278 | 279 | (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), |
| 279 | -(105, 'search', 'Maximum results from SQL query', 'The maximum results from an SQL query', 'maxSqlResults', 'default', '1000', 'numeric_string', NULL, 1); | |
| 280 | +(105, 'search', 'Maximum results from SQL query', 'The maximum results from an SQL query', 'maxSqlResults', 'default', '1000', 'numeric_string', NULL, 1), | |
| 281 | +(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), | |
| 282 | +(107, 'server', 'Internal Server port', 'The internal port for the server.', 'internal_server_port', 'default', '80', 'numeric_string', NULL, 1), | |
| 283 | +(108, 'server', 'External Server IP', 'The external IP for the server.', 'server_name', 'default', '', 'string', NULL, 1), | |
| 284 | +(109, 'server', 'External Server port', 'The external port for the server.', 'server_port', 'default', '', 'numeric_string', NULL, 1), | |
| 285 | +(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); | |
| 280 | 286 | /*!40000 ALTER TABLE `config_settings` ENABLE KEYS */; |
| 281 | 287 | UNLOCK TABLES; |
| 282 | 288 | ... | ... |
sql/mysql/upgrade/3.5.4/server_config_settings.sql
0 → 100644
| 1 | +INSERT INTO config_groups (name, display_name, description, category) VALUES | |
| 2 | +('server', 'Server Settings', 'Configuration settings for the server', 'General Settings'); | |
| 3 | + | |
| 4 | + | |
| 5 | +INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) VALUES | |
| 6 | +('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), | |
| 7 | +('server', 'Internal Server port', 'The internal port for the server.', 'internal_server_port', 'default', '80', 'numeric_string', NULL, 1), | |
| 8 | +('server', 'External Server IP', 'The external IP for the server.', 'server_name', 'default', '', 'string', NULL, 1), | |
| 9 | +('server', 'External Server port', 'The external port for the server.', 'server_port', 'default', '', 'numeric_string', NULL, 1), | |
| 10 | +('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); | ... | ... |