Configuration.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. class Configuration {
  3. public static $config = null;
  4. public static function verifyInstallation() {
  5. // Check PHP version
  6. if(version_compare(PHP_VERSION, PHP_VERSION_REQUIRED) === -1)
  7. die('RSS-Bridge requires at least PHP version ' . PHP_VERSION_REQUIRED . '!');
  8. // extensions check
  9. if(!extension_loaded('openssl'))
  10. die('"openssl" extension not loaded. Please check "php.ini"');
  11. if(!extension_loaded('libxml'))
  12. die('"libxml" extension not loaded. Please check "php.ini"');
  13. if(!extension_loaded('mbstring'))
  14. die('"mbstring" extension not loaded. Please check "php.ini"');
  15. if(!extension_loaded('simplexml'))
  16. die('"simplexml" extension not loaded. Please check "php.ini"');
  17. if(!extension_loaded('curl'))
  18. die('"curl" extension not loaded. Please check "php.ini"');
  19. // configuration checks
  20. if(ini_get('allow_url_fopen') !== '1')
  21. die('"allow_url_fopen" is not set to "1". Please check "php.ini');
  22. // Check cache folder permissions (write permissions required)
  23. if(!is_writable(CACHE_DIR))
  24. die('RSS-Bridge does not have write permissions for ' . CACHE_DIR . '!');
  25. // Check whitelist file permissions (only in DEBUG mode)
  26. if(!file_exists(WHITELIST_FILE) && !is_writable(dirname(WHITELIST_FILE)))
  27. die('RSS-Bridge does not have write permissions for ' . WHITELIST_FILE . '!');
  28. }
  29. public static function loadConfiguration() {
  30. if(!file_exists('config.default.ini.php'))
  31. die('The default configuration file "config.default.ini.php" is missing!');
  32. Configuration::$config = parse_ini_file('config.default.ini.php', true, INI_SCANNER_TYPED);
  33. if(!Configuration::$config)
  34. die('Error parsing config.default.ini.php');
  35. if(file_exists('config.ini.php')) {
  36. // Replace default configuration with custom settings
  37. foreach(parse_ini_file('config.ini.php', true, INI_SCANNER_TYPED) as $header => $section) {
  38. foreach($section as $key => $value) {
  39. // Skip unknown sections and keys
  40. if(array_key_exists($header, Configuration::$config) && array_key_exists($key, Configuration::$config[$header])) {
  41. Configuration::$config[$header][$key] = $value;
  42. }
  43. }
  44. }
  45. }
  46. if(!is_string(self::getConfig('proxy', 'url')))
  47. die('Parameter [proxy] => "url" is not a valid string! Please check "config.ini.php"!');
  48. if(!empty(self::getConfig('proxy', 'url')))
  49. define('PROXY_URL', self::getConfig('proxy', 'url'));
  50. if(!is_bool(self::getConfig('proxy', 'by_bridge')))
  51. die('Parameter [proxy] => "by_bridge" is not a valid Boolean! Please check "config.ini.php"!');
  52. define('PROXY_BYBRIDGE', self::getConfig('proxy', 'by_bridge'));
  53. if(!is_string(self::getConfig('proxy', 'name')))
  54. die('Parameter [proxy] => "name" is not a valid string! Please check "config.ini.php"!');
  55. define('PROXY_NAME', self::getConfig('proxy', 'name'));
  56. if(!is_bool(self::getConfig('cache', 'custom_timeout')))
  57. die('Parameter [cache] => "custom_timeout" is not a valid Boolean! Please check "config.ini.php"!');
  58. define('CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'custom_timeout'));
  59. if(!is_bool(self::getConfig('authentication', 'enable')))
  60. die('Parameter [authentication] => "enable" is not a valid Boolean! Please check "config.ini.php"!');
  61. if(!is_string(self::getConfig('authentication', 'username')))
  62. die('Parameter [authentication] => "username" is not a valid string! Please check "config.ini.php"!');
  63. if(!is_string(self::getConfig('authentication', 'password')))
  64. die('Parameter [authentication] => "password" is not a valid string! Please check "config.ini.php"!');
  65. }
  66. public static function getConfig($category, $key) {
  67. if(array_key_exists($category, self::$config) && array_key_exists($key, self::$config[$category])) {
  68. return self::$config[$category][$key];
  69. }
  70. return null;
  71. }
  72. }