From 8fc26c419b6b5f948f57b7a4ee9e27962d43af5e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 11 Jan 2011 12:20:00 +0300 Subject: [PATCH] properly check whether all constants are defined in config.php --- sanity_check.php | 11 +++++++++++ sanity_config.php | 3 +++ utils/regen_config_checks.sh | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 sanity_config.php create mode 100755 utils/regen_config_checks.sh diff --git a/sanity_check.php b/sanity_check.php index 35d5c2a7..d70445e0 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -11,6 +11,7 @@ } require_once "config.php"; + require_once "sanity_config.php"; if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { $err_msg = "config: your config file version is incorrect. See config.php-dist.\n"; @@ -22,6 +23,16 @@ $err_msg = "config: HTMLPurifier cache directory should be writable by anyone (chmod -R 777 $purifier_cache_dir)"; } + if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { + $err_msg = "config: your sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"; + } + + foreach ($requred_defines as $d) { + if (!defined($d)) { + $err_msg = "config: required constant $d is not defined. Please check config.php"; + } + } + if (defined('RSS_BACKEND_TYPE')) { print "Fatal error: RSS_BACKEND_TYPE is deprecated. Please remove this option from config.php\n"; diff --git a/sanity_config.php b/sanity_config.php new file mode 100644 index 00000000..6410c540 --- /dev/null +++ b/sanity_config.php @@ -0,0 +1,3 @@ + diff --git a/utils/regen_config_checks.sh b/utils/regen_config_checks.sh new file mode 100755 index 00000000..78f2dbfb --- /dev/null +++ b/utils/regen_config_checks.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +DESTINATION="sanity_config.php" + +echo " $DESTINATION + +echo -n "define('GENERATED_CONFIG_CHECK', " >> $DESTINATION +grep CONFIG_VERSION config.php-dist | awk -F ' |)' '{ print $2 }' | xargs echo -n >> $DESTINATION +echo ");" >> $DESTINATION + +echo -n "\$requred_defines = array( " >> $DESTINATION + +grep define\( config.php-dist | awk -F\' '{ print "*" $2 "*," }' | xargs echo -n | sed -e s/,$// -e s/*/\'/g >> $DESTINATION + +echo "); ?>" >> $DESTINATION + + -- 2.39.5