Subversion Repositories oidplus

Rev

Rev 780 | Rev 806 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 780 Rev 801
Line 34... Line 34...
34
 
34
 
35
        protected static $html = true;
35
        protected static $html = true;
36
 
36
 
37
        /*public*/ const DEFAULT_LANGUAGE = 'enus'; // the language of the source code
37
        /*public*/ const DEFAULT_LANGUAGE = 'enus'; // the language of the source code
38
 
38
 
-
 
39
        /*public*/ const PATH_RELATIVE = 1;
-
 
40
        /*public*/ const PATH_ABSOLUTE = 2;
-
 
41
        /*public*/ const PATH_ABSOLUTE_CANONICAL = 3;
-
 
42
 
39
        // These plugin types can contain HTML code and therefore may
43
        // These plugin types can contain HTML code and therefore may
40
        // emit (non-setup) CSS/JS code via their manifest.
44
        // emit (non-setup) CSS/JS code via their manifest.
41
        /*public*/ const INTERACTIVE_PLUGIN_TYPES = array(
45
        /*public*/ const INTERACTIVE_PLUGIN_TYPES = array(
42
                'publicPages',
46
                'publicPages',
43
                'raPages',
47
                'raPages',
Line 106... Line 110...
106
                        } else {
110
                        } else {
107
                                if (!is_dir(OIDplus::localpath().'setup')) {
111
                                if (!is_dir(OIDplus::localpath().'setup')) {
108
                                        throw new OIDplusConfigInitializationException(_L('File %1 is missing, but setup can\'t be started because its directory missing.','userdata/baseconfig/config.inc.php'));
112
                                        throw new OIDplusConfigInitializationException(_L('File %1 is missing, but setup can\'t be started because its directory missing.','userdata/baseconfig/config.inc.php'));
109
                                } else {
113
                                } else {
110
                                        if (self::$html) {
114
                                        if (self::$html) {
111
                                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,true).'setup/') !== 0) {
115
                                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/') !== 0) {
112
                                                        header('Location:'.OIDplus::webpath().'setup/');
116
                                                        header('Location:'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/');
113
                                                        die(_L('Redirecting to setup...'));
117
                                                        die(_L('Redirecting to setup...'));
114
                                                } else {
118
                                                } else {
115
                                                        return self::$baseConfig;
119
                                                        return self::$baseConfig;
116
                                                }
120
                                                }
117
                                        } else {
121
                                        } else {
Line 122... Line 126...
122
                        }
126
                        }
123
 
127
 
124
                        // Check important config settings
128
                        // Check important config settings
125
 
129
 
126
                        if (self::$baseConfig->getValue('CONFIG_VERSION') != 2.1) {
130
                        if (self::$baseConfig->getValue('CONFIG_VERSION') != 2.1) {
127
                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,true).'setup/') !== 0) {
131
                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/') !== 0) {
128
                                        throw new OIDplusConfigInitializationException(_L("The information located in %1 is outdated.",realpath($config_file)));
132
                                        throw new OIDplusConfigInitializationException(_L("The information located in %1 is outdated.",realpath($config_file)));
129
                                }
133
                                }
130
                        }
134
                        }
131
 
135
 
132
                        if (self::$baseConfig->getValue('SERVER_SECRET', '') === '') {
136
                        if (self::$baseConfig->getValue('SERVER_SECRET', '') === '') {
133
                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,true).'setup/') !== 0) {
137
                                if (strpos($_SERVER['REQUEST_URI'], OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/') !== 0) {
134
                                        throw new OIDplusConfigInitializationException(_L("You must set a value for SERVER_SECRET in %1 for the system to operate secure.",realpath($config_file)));
138
                                        throw new OIDplusConfigInitializationException(_L("You must set a value for SERVER_SECRET in %1 for the system to operate secure.",realpath($config_file)));
135
                                }
139
                                }
136
                        }
140
                        }
137
                }
141
                }
138
 
142
 
Line 1029... Line 1033...
1029
 
1033
 
1030
        # --- System URL, System ID, PKI, and other functions
1034
        # --- System URL, System ID, PKI, and other functions
1031
 
1035
 
1032
        private static function recognizeSystemUrl() {
1036
        private static function recognizeSystemUrl() {
1033
                try {
1037
                try {
1034
                        $url = OIDplus::webpath();
1038
                        $url = OIDplus::webpath(null,self::PATH_ABSOLUTE_CANONICAL); // TODO: canonical or not?
1035
                        OIDplus::config()->setValue('last_known_system_url', $url);
1039
                        OIDplus::config()->setValue('last_known_system_url', $url);
1036
                } catch (Exception $e) {
1040
                } catch (Exception $e) {
1037
                }
1041
                }
1038
        }
1042
        }
1039
 
1043
 
Line 1057... Line 1061...
1057
 
1061
 
1058
        public static function isSSL() {
1062
        public static function isSSL() {
1059
                return isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on');
1063
                return isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on');
1060
        }
1064
        }
1061
 
1065
 
-
 
1066
        /* $mode == self::PATH_RELATIVE */
-
 
1067
        /* $mode == self::PATH_ABSOLUTE */
-
 
1068
        /* $mode == self::PATH_ABSOLUTE_CANONICAL */
1062
        private static function getSystemUrl($relative=false) {
1069
        private static function getSystemUrl($mode) {
-
 
1070
                $relative = $mode == self::PATH_RELATIVE;
-
 
1071
                $canonical_sysurl = $mode == self::PATH_ABSOLUTE_CANONICAL;
-
 
1072
 
-
 
1073
                if ($canonical_sysurl) {
-
 
1074
                        $tmp = OIDplus::baseConfig()->getValue('CANONICAL_SYSTEM_URL', '');
-
 
1075
                        if ($tmp !== '') {
-
 
1076
                                return rtrim($tmp,'/').'/';
-
 
1077
                        }
-
 
1078
                }
-
 
1079
 
1063
                if ($relative) {
1080
                if ($relative) {
1064
                        $steps_up = self::getExecutingScriptPathDepth();
1081
                        $steps_up = self::getExecutingScriptPathDepth();
1065
                        if ($steps_up === false) {
1082
                        if ($steps_up === false) {
1066
                                return false;
1083
                                return false;
1067
                        } else {
1084
                        } else {
Line 1260... Line 1277...
1260
 
1277
 
1261
                $timeout = 2;
1278
                $timeout = 2;
1262
                $already_ssl = self::isSSL();
1279
                $already_ssl = self::isSSL();
1263
                $ssl_port = 443;
1280
                $ssl_port = 443;
1264
 
1281
 
-
 
1282
                // TODO: Instead of 0, 1, 2, maybe make OIDplus:: constants
1265
                $mode = OIDplus::baseConfig()->getValue('ENFORCE_SSL', 2/*auto*/);
1283
                $mode = OIDplus::baseConfig()->getValue('ENFORCE_SSL', 2/*auto*/);
1266
 
1284
 
1267
                if ($mode == 0) {
1285
                if ($mode == 0) {
1268
                        // No SSL available
1286
                        // No SSL available
1269
                        self::$sslAvailableCache = $already_ssl;
1287
                        self::$sslAvailableCache = $already_ssl;
Line 1357... Line 1375...
1357
                        $res = rtrim($res,'/'); // avoid '..//' for localpath(null,true)
1375
                        $res = rtrim($res,'/'); // avoid '..//' for localpath(null,true)
1358
                } else {
1376
                } else {
1359
                        $res = realpath($target);
1377
                        $res = realpath($target);
1360
                }
1378
                }
1361
 
1379
 
1362
                if (is_dir($target)) $res .= DIRECTORY_SEPARATOR;
1380
                if (is_dir($target)) $res .= '/';
-
 
1381
 
-
 
1382
                $res = str_replace('/', DIRECTORY_SEPARATOR, $res);
1363
 
1383
 
1364
                return $res;
1384
                return $res;
1365
        }
1385
        }
1366
 
1386
 
1367
        /**
1387
        /**
1368
         * Gets a URL pointing to a resource
1388
         * Gets a URL pointing to a resource
1369
         * @param string $target Target resource (file or directory must exist), or null to get the OIDplus base directory
1389
         * @param string $target Target resource (file or directory must exist), or null to get the OIDplus base directory
1370
         * @param boolean $relative If true, the returning path is relative to the currently executed PHP script (i.e. index.php , not the plugin PHP script!)
1390
         * @param int|mixed $mode If true or 1, the returning path is relative to the currently executed PHP script (i.e. index.php , not the plugin PHP script!). False or 2 is an absolute URL. 3 is an absolute URL, but a canonical path is preferred.
1371
         * @return string|false The URL, with guaranteed trailing path delimiter for directories
1391
         * @return string|false The URL, with guaranteed trailing path delimiter for directories
1372
         */
1392
         */
1373
        public static function webpath($target=null, $relative=false) {
1393
        public static function webpath($target=null, $mode=self::PATH_ABSOLUTE) {
-
 
1394
 
-
 
1395
                // backwards compatibility
-
 
1396
                if ($mode === true) $mode = self::PATH_RELATIVE;
-
 
1397
                if ($mode === false) $mode = self::PATH_ABSOLUTE;
-
 
1398
 
1374
                $res = self::getSystemUrl($relative); // Note: already contains a trailing path delimiter
1399
                $res = self::getSystemUrl($mode); // Note: already contains a trailing path delimiter
1375
                if ($res === false) return false;
1400
                if ($res === false) return false;
1376
 
1401
 
1377
                if (!is_null($target)) {
1402
                if (!is_null($target)) {
1378
                        $basedir = realpath(__DIR__.'/../../');
1403
                        $basedir = realpath(__DIR__.'/../../');
1379
                        $target = realpath($target);
1404
                        $target = realpath($target);
Line 1386... Line 1411...
1386
                return $res;
1411
                return $res;
1387
        }
1412
        }
1388
 
1413
 
1389
        public static function canonicalURL() {
1414
        public static function canonicalURL() {
1390
                // First part: OIDplus system URL (or canonical system URL)
1415
                // First part: OIDplus system URL (or canonical system URL)
1391
                $sysurl = OIDplus::baseConfig()->getValue('CANONICAL_SYSTEM_URL', '');
-
 
1392
                if ($sysurl !== '') {
-
 
1393
                        $sysurl = rtrim($sysurl,'/').'/';
-
 
1394
                } else {
-
 
1395
                        $sysurl = OIDplus::getSystemUrl();
1416
                $sysurl = OIDplus::getSystemUrl(self::PATH_ABSOLUTE_CANONICAL);
1396
                }
-
 
1397
 
1417
 
1398
                // Second part: Directory
1418
                // Second part: Directory
1399
                $basedir = realpath(__DIR__.'/../../');
1419
                $basedir = realpath(__DIR__.'/../../');
1400
                $target = realpath('.');
1420
                $target = realpath('.');
1401
                if ($target === false) return false;
1421
                if ($target === false) return false;