Commit 872d7762c85ba2520a2ad1fb0663bdf70ba86589
1 parent
c0927eff
Merged in from DEV trunk...
KTS-3165 "Remove background task permissions problems by making web server user deal with background tasks" Fixed. Sorted issue with server name resolution Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8340 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
57 additions
and
1 deletions
lib/util/ktutil.inc
| ... | ... | @@ -49,19 +49,73 @@ class KTUtil { |
| 49 | 49 | const TB = 1099511627776; |
| 50 | 50 | const PB = 1125899906842624; |
| 51 | 51 | |
| 52 | + const SERVER_NAME_FILE = 'serverName.txt'; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Used to resolve the server name | |
| 56 | + * | |
| 57 | + */ | |
| 58 | + static function save_base_kt_url() | |
| 59 | + { | |
| 60 | + global $default; | |
| 61 | + $config = KTConfig::getSingleton(); | |
| 62 | + $cacheDir = $config->get('cache/cacheDirectory'); | |
| 63 | + | |
| 64 | + $protocol = $default->sslEnabled ? 'https' : 'http'; | |
| 65 | + $port = $_SERVER['SERVER_PORT']+0; | |
| 66 | + | |
| 67 | + $base_url = $protocol . '://' . $_SERVER['SERVER_NAME']; | |
| 68 | + | |
| 69 | + if (($protocol == 'http' && $port == 80) || ($protocol == 'https' && $port == 443)) | |
| 70 | + { | |
| 71 | + // don't need to do anything | |
| 72 | + } | |
| 73 | + else | |
| 74 | + { | |
| 75 | + $base_url .= ':' . $port; | |
| 76 | + } | |
| 77 | + | |
| 78 | + @file_put_contents($cacheDir . '/' . KTUtil::SERVER_NAME_FILE, $base_url); | |
| 79 | + } | |
| 80 | + | |
| 81 | + | |
| 52 | 82 | static function kt_url() |
| 53 | 83 | { |
| 54 | 84 | global $default; |
| 85 | + static $base_url = null; | |
| 55 | 86 | |
| 56 | 87 | $config = KTConfig::getSingleton(); |
| 88 | + $cacheDir = $config->get('cache/cacheDirectory'); | |
| 89 | + | |
| 90 | + $base_url = @file_get_contents($cacheDir . '/' . KTUtil::SERVER_NAME_FILE); | |
| 91 | + | |
| 92 | + $rootUrl = $config->get( 'KnowlegeTree/rootUrl'); | |
| 93 | + if (false !== $base_url) | |
| 94 | + { | |
| 95 | + return $base_url . $rootUrl; | |
| 96 | + } | |
| 97 | + | |
| 57 | 98 | $serverName = $config->get('knowledgeTree/serverName', $_SERVER['HTTP_HOST']); |
| 58 | 99 | |
| 59 | - return ($default->sslEnabled ? 'https' : 'http') .'://'.$serverName . $default->rootUrl; | |
| 100 | + return ($default->sslEnabled ? 'https' : 'http') .'://'.$serverName . $rootUrl; | |
| 60 | 101 | |
| 61 | 102 | } |
| 62 | 103 | |
| 63 | 104 | static function call_page($path) |
| 64 | 105 | { |
| 106 | + $config = KTConfig::getSingleton(); | |
| 107 | + $cacheDir = $config->get('cache/cacheDirectory'); | |
| 108 | + | |
| 109 | + $base_url = @file_get_contents($cacheDir . '/' . KTUtil::SERVER_NAME_FILE); | |
| 110 | + | |
| 111 | + if (false == $base_url) | |
| 112 | + { | |
| 113 | + global $default; | |
| 114 | + $default->log->info("call_page: $path - cannot call script until user logs in for the first time!"); | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + | |
| 118 | + | |
| 65 | 119 | $kt_url = KTUtil::kt_url(); |
| 66 | 120 | |
| 67 | 121 | $full_url = $kt_url . '/' . $path; | ... | ... |
login.php
| ... | ... | @@ -129,6 +129,8 @@ class LoginPageDispatcher extends KTDispatcher { |
| 129 | 129 | function do_main() { |
| 130 | 130 | global $default; |
| 131 | 131 | |
| 132 | + KTUtil::save_base_kt_url(); | |
| 133 | + | |
| 132 | 134 | $oUser =& KTInterceptorRegistry::checkInterceptorsForAuthenticated(); |
| 133 | 135 | if (is_a($oUser, 'User')) { |
| 134 | 136 | $res = $this->performLogin($oUser); | ... | ... |