Rev 292 | Rev 295 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 292 | Rev 294 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | self::$baseConfig = new OIDplusBaseConfig(); |
43 | self::$baseConfig = new OIDplusBaseConfig(); |
44 | } |
44 | } |
45 | 45 | ||
46 | if ($first_init) { |
46 | if ($first_init) { |
47 | // Include a file containing various size/depth limitations of OIDs |
47 | // Include a file containing various size/depth limitations of OIDs |
48 | // It is important to include it before config.inc.php was included, |
48 | // It is important to include it before userdata/baseconfig/config.inc.php was included, |
49 | // so we can give config.inc.php the chance to override the values. |
49 | // so we can give userdata/baseconfig/config.inc.php the chance to override the values. |
50 | 50 | ||
51 | include __DIR__ . '/../limits.inc.php'; |
51 | include OIDplus::basePath().'/includes/limits.inc.php'; |
52 | 52 | ||
53 | // Include config file |
53 | // Include config file |
54 | 54 | ||
- | 55 | $config_file = OIDplus::basePath() . '/userdata/baseconfig/config.inc.php'; |
|
- | 56 | $config_file_old = OIDplus::basePath() . '/includes/config.inc.php'; // backwards compatibility |
|
- | 57 | ||
- | 58 | if (!file_exists($config_file) && file_exists($config_file_old)) { |
|
- | 59 | $config_file = $config_file_old; |
|
- | 60 | } |
|
- | 61 | ||
55 | if (file_exists(__DIR__ . '/../config.inc.php')) { |
62 | if (file_exists($config_file)) { |
56 | if (self::$old_config_format) { |
63 | if (self::$old_config_format) { |
57 | // Note: We may only include it once due to backwards compatibility, |
64 | // Note: We may only include it once due to backwards compatibility, |
58 | // since in version 2.0, the configuration was defined using define() statements |
65 | // since in version 2.0, the configuration was defined using define() statements |
59 | // Attention: This does mean that a full re-init (e.g. for test cases) is not possible |
66 | // Attention: This does mean that a full re-init (e.g. for test cases) is not possible |
60 | // if a version 2.0 config is used! |
67 | // if a version 2.0 config is used! |
61 | include_once __DIR__ . '/../config.inc.php'; |
68 | include_once $config_file; |
62 | } else { |
69 | } else { |
63 | include __DIR__ . '/../config.inc.php'; |
70 | include $config_file; |
64 | } |
71 | } |
65 | 72 | ||
66 | if (defined('OIDPLUS_CONFIG_VERSION') && (OIDPLUS_CONFIG_VERSION == 2.0)) { |
73 | if (defined('OIDPLUS_CONFIG_VERSION') && (OIDPLUS_CONFIG_VERSION == 2.0)) { |
67 | self::$old_config_format = true; |
74 | self::$old_config_format = true; |
68 | 75 | ||
Line 78... | Line 85... | ||
78 | self::$baseConfig->setValue($name, $value); |
85 | self::$baseConfig->setValue($name, $value); |
79 | } |
86 | } |
80 | } |
87 | } |
81 | } |
88 | } |
82 | } else { |
89 | } else { |
83 | if (!is_dir(__DIR__.'/../../setup')) { |
90 | if (!is_dir(OIDplus::basePath().'/setup')) { |
84 | throw new OIDplusConfigInitializationException('File includes/config.inc.php is missing, but setup can\'t be started because its directory missing.'); |
91 | throw new OIDplusConfigInitializationException('File userdata/baseconfig/config.inc.php is missing, but setup can\'t be started because its directory missing.'); |
85 | } else { |
92 | } else { |
86 | if (self::$html) { |
93 | if (self::$html) { |
87 | header('Location:'.OIDplus::getSystemUrl().'setup/'); |
94 | header('Location:'.OIDplus::getSystemUrl().'setup/'); |
88 | die('Redirecting to setup...'); |
95 | die('Redirecting to setup...'); |
89 | } else { |
96 | } else { |
90 | // This can be displayed in e.g. ajax.php |
97 | // This can be displayed in e.g. ajax.php |
91 | throw new OIDplusConfigInitializationException('File includes/config.inc.php is missing. Please run setup again.'); |
98 | throw new OIDplusConfigInitializationException('File userdata/baseconfig/config.inc.php is missing. Please run setup again.'); |
92 | } |
99 | } |
93 | } |
100 | } |
94 | } |
101 | } |
95 | 102 | ||
96 | // Check important config settings |
103 | // Check important config settings |
97 | 104 | ||
98 | if (self::$baseConfig->getValue('CONFIG_VERSION') != 2.1) { |
105 | if (self::$baseConfig->getValue('CONFIG_VERSION') != 2.1) { |
99 | throw new OIDplusConfigInitializationException("The information located in includes/config.inc.php is outdated."); |
106 | throw new OIDplusConfigInitializationException("The information located in $config_file is outdated."); |
100 | } |
107 | } |
101 | 108 | ||
102 | if (self::$baseConfig->getValue('SERVER_SECRET', '') === '') { |
109 | if (self::$baseConfig->getValue('SERVER_SECRET', '') === '') { |
103 | throw new OIDplusConfigInitializationException("You must set a value for SERVER_SECRET in includes/config.inc.php for the system to operate secure."); |
110 | throw new OIDplusConfigInitializationException("You must set a value for SERVER_SECRET in $config_file for the system to operate secure."); |
104 | } |
111 | } |
105 | } |
112 | } |
106 | 113 | ||
107 | return self::$baseConfig; |
114 | return self::$baseConfig; |
108 | } |
115 | } |
Line 418... | Line 425... | ||
418 | 425 | ||
419 | public static function getAllPluginManifests($pluginFolderMask='*'): array { |
426 | public static function getAllPluginManifests($pluginFolderMask='*'): array { |
420 | $out = array(); |
427 | $out = array(); |
421 | // Note: glob() will sort by default, so we do not need a page priority attribute. |
428 | // Note: glob() will sort by default, so we do not need a page priority attribute. |
422 | // So you just need to use a numeric plugin directory prefix (padded). |
429 | // So you just need to use a numeric plugin directory prefix (padded). |
423 | $ary = glob(__DIR__ . '/../../plugins/'.$pluginFolderMask.'/'.'*'.'/manifest.ini'); |
430 | $ary = glob(OIDplus::basePath().'/plugins/'.$pluginFolderMask.'/'.'*'.'/manifest.ini'); |
424 | foreach ($ary as $ini) { |
431 | foreach ($ary as $ini) { |
425 | if (!file_exists($ini)) continue; |
432 | if (!file_exists($ini)) continue; |
426 | $bry = parse_ini_file($ini, true, INI_SCANNER_TYPED); |
433 | $bry = parse_ini_file($ini, true, INI_SCANNER_TYPED); |
427 | 434 | ||
428 | $plugintype_folder = basename(dirname(dirname($ini))); |
435 | $plugintype_folder = basename(dirname(dirname($ini))); |
Line 491... | Line 498... | ||
491 | self::$system_id_cache = null; |
498 | self::$system_id_cache = null; |
492 | self::$sslAvailableCache = null; |
499 | self::$sslAvailableCache = null; |
493 | 500 | ||
494 | // Continue... |
501 | // Continue... |
495 | 502 | ||
496 | OIDplus::baseConfig(); // this loads the base configuration located in config.inc.php (once!) |
503 | OIDplus::baseConfig(); // this loads the base configuration located in userdata/baseconfig/config.inc.php (once!) |
497 | // You can do changes to the configuration afterwards using OIDplus::baseConfig()->... |
504 | // You can do changes to the configuration afterwards using OIDplus::baseConfig()->... |
498 | 505 | ||
499 | // Register database types (highest priority) |
506 | // Register database types (highest priority) |
500 | 507 | ||
501 | // SQL slangs |
508 | // SQL slangs |
502 | 509 | ||
503 | self::registerAllPlugins('sql_slang', 'OIDplusSqlSlangPlugin', array('OIDplus','registerSqlSlangPlugin')); |
510 | self::registerAllPlugins('sqlSlang', 'OIDplusSqlSlangPlugin', array('OIDplus','registerSqlSlangPlugin')); |
504 | foreach (OIDplus::getSqlSlangPlugins() as $plugin) { |
511 | foreach (OIDplus::getSqlSlangPlugins() as $plugin) { |
505 | $plugin->init($html); |
512 | $plugin->init($html); |
506 | } |
513 | } |
507 | 514 | ||
508 | // Database providers |
515 | // Database providers |
Line 547... | Line 554... | ||
547 | } |
554 | } |
548 | } |
555 | } |
549 | 556 | ||
550 | # --- System URL, System ID, PKI, and other functions |
557 | # --- System URL, System ID, PKI, and other functions |
551 | 558 | ||
- | 559 | public static function basePath() { |
|
- | 560 | return realpath(__DIR__ . '/../../'); |
|
- | 561 | } |
|
- | 562 | ||
552 | public static function getSystemUrl($relative=false) { |
563 | public static function getSystemUrl($relative=false) { |
553 | if (!isset($_SERVER["SCRIPT_NAME"])) return false; |
564 | if (!isset($_SERVER["SCRIPT_NAME"])) return false; |
554 | 565 | ||
555 | $test_dir = dirname($_SERVER['SCRIPT_FILENAME']); |
566 | $test_dir = dirname($_SERVER['SCRIPT_FILENAME']); |
556 | $test_dir = str_replace('\\', '/', $test_dir); |
567 | $test_dir = str_replace('\\', '/', $test_dir); |
Line 647... | Line 658... | ||
647 | 658 | ||
648 | return verify_private_public_key($privKey, $pubKey); |
659 | return verify_private_public_key($privKey, $pubKey); |
649 | } |
660 | } |
650 | 661 | ||
651 | public static function getInstallType() { |
662 | public static function getInstallType() { |
652 | if (!file_exists(__DIR__ . '/../../oidplus_version.txt') && !is_dir(__DIR__ . '/../../.svn')) { |
663 | if (!file_exists(OIDplus::basePath().'/oidplus_version.txt') && !is_dir(OIDplus::basePath().'/.svn')) { |
653 | return 'unknown'; |
664 | return 'unknown'; |
654 | } |
665 | } |
655 | if (file_exists(__DIR__ . '/../../oidplus_version.txt') && is_dir(__DIR__ . '/../../.svn')) { |
666 | if (file_exists(OIDplus::basePath().'/oidplus_version.txt') && is_dir(OIDplus::basePath().'/.svn')) { |
656 | return 'ambigous'; |
667 | return 'ambigous'; |
657 | } |
668 | } |
658 | if (is_dir(__DIR__ . '/../../.svn')) { |
669 | if (is_dir(OIDplus::basePath().'/.svn')) { |
659 | return 'svn-wc'; |
670 | return 'svn-wc'; |
660 | } |
671 | } |
661 | if (file_exists(__DIR__ . '/../../oidplus_version.txt')) { |
672 | if (file_exists(OIDplus::basePath().'/oidplus_version.txt')) { |
662 | return 'svn-snapshot'; |
673 | return 'svn-snapshot'; |
663 | } |
674 | } |
664 | } |
675 | } |
665 | 676 | ||
666 | public static function getVersion() { |
677 | public static function getVersion() { |
667 | if (file_exists(__DIR__ . '/../../oidplus_version.txt') && is_dir(__DIR__ . '/../../.svn')) { |
678 | if (file_exists(OIDplus::basePath().'/oidplus_version.txt') && is_dir(OIDplus::basePath().'/.svn')) { |
668 | return false; // version is ambigous |
679 | return false; // version is ambigous |
669 | } |
680 | } |
670 | 681 | ||
671 | if (is_dir(__DIR__ . '/../../.svn')) { |
682 | if (is_dir(OIDplus::basePath().'/.svn')) { |
672 | // Try to get the version via SQLite3 |
683 | // Try to get the version via SQLite3 |
673 | if (class_exists('SQLite3')) { |
684 | if (class_exists('SQLite3')) { |
674 | try { |
685 | try { |
675 | $db = new SQLite3(__DIR__ . '/../../.svn/wc.db'); |
686 | $db = new SQLite3(OIDplus::basePath().'/.svn/wc.db'); |
676 | $results = $db->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
687 | $results = $db->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
677 | while ($row = $results->fetchArray()) { |
688 | while ($row = $results->fetchArray()) { |
678 | return 'svn-'.$row['rev']; |
689 | return 'svn-'.$row['rev']; |
679 | } |
690 | } |
680 | $db->close(); |
691 | $db->close(); |
Line 682... | Line 693... | ||
682 | } catch (Exception $e) { |
693 | } catch (Exception $e) { |
683 | } |
694 | } |
684 | } |
695 | } |
685 | if (class_exists('PDO')) { |
696 | if (class_exists('PDO')) { |
686 | try { |
697 | try { |
687 | $pdo = new PDO('sqlite:' . __DIR__ . '/../../.svn/wc.db'); |
698 | $pdo = new PDO('sqlite:' . OIDplus::basePath().'/.svn/wc.db'); |
688 | $res = $pdo->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
699 | $res = $pdo->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
689 | $row = $res->fetch(); |
700 | $row = $res->fetch(); |
690 | if ($row !== false) return 'svn-'.$row['rev']; |
701 | if ($row !== false) return 'svn-'.$row['rev']; |
691 | $pdo = null; |
702 | $pdo = null; |
692 | } catch (Exception $e) { |
703 | } catch (Exception $e) { |
693 | } |
704 | } |
694 | } |
705 | } |
695 | 706 | ||
696 | // Try to find out the SVN version using the shell |
707 | // Try to find out the SVN version using the shell |
697 | // We don't prioritize this method, because a failed shell access will flood the apache error log with STDERR messages |
708 | // We don't prioritize this method, because a failed shell access will flood the apache error log with STDERR messages |
698 | $output = @shell_exec('svnversion '.escapeshellarg(realpath(__DIR__ . '/../../'))); |
709 | $output = @shell_exec('svnversion '.escapeshellarg(OIDplus::basePath())); |
699 | if (preg_match('/\d+/', $output, $match)) { |
710 | if (preg_match('/\d+/', $output, $match)) { |
700 | return 'svn-'.$match[0]; |
711 | return 'svn-'.$match[0]; |
701 | } |
712 | } |
702 | 713 | ||
703 | $output = @shell_exec('svn info '.escapeshellarg(realpath(__DIR__ . '/../../'))); |
714 | $output = @shell_exec('svn info '.escapeshellarg(OIDplus::basePath())); |
704 | if (preg_match('/Revision:\s*(\d+)/m', $output, $match)) { |
715 | if (preg_match('/Revision:\s*(\d+)/m', $output, $match)) { |
705 | return 'svn-'.$match[1]; |
716 | return 'svn-'.$match[1]; |
706 | } |
717 | } |
707 | } |
718 | } |
708 | 719 | ||
709 | if (file_exists(__DIR__ . '/../../oidplus_version.txt')) { |
720 | if (file_exists(OIDplus::basePath().'/oidplus_version.txt')) { |
710 | $cont = file_get_contents(__DIR__ . '/../../oidplus_version.txt'); |
721 | $cont = file_get_contents(OIDplus::basePath().'/oidplus_version.txt'); |
711 | if (preg_match('@Revision (\d+)@', $cont, $m)) |
722 | if (preg_match('@Revision (\d+)@', $cont, $m)) |
712 | return 'svn-'.$m[1]; |
723 | return 'svn-'.$m[1]; |
713 | } |
724 | } |
714 | 725 | ||
715 | return false; |
726 | return false; |