properly check whether all constants are defined in config.php

This commit is contained in:
Andrew Dolgov 2011-01-11 12:20:00 +03:00
parent 0efa586a10
commit 8fc26c419b
3 changed files with 31 additions and 0 deletions

View File

@ -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 "<b>Fatal error</b>: RSS_BACKEND_TYPE is deprecated. Please remove this
option from config.php\n";

3
sanity_config.php Normal file
View File

@ -0,0 +1,3 @@
<?php # This file has been generated at: Tue Jan 11 12:10:54 MSK 2011
define('GENERATED_CONFIG_CHECK', 21);
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'DB_PORT', 'MAGPIE_FETCH_TIME_OUT', 'MAGPIE_CACHE_DIR', 'MAGPIE_CACHE_AGE', 'ICONS_DIR', 'ICONS_URL', 'SINGLE_USER_MODE', 'TMP_DIRECTORY', 'ENABLE_UPDATE_DAEMON', 'DAEMON_SLEEP_INTERVAL', 'DATABASE_BACKED_SESSIONS', 'SESSION_CHECK_ADDRESS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'DAEMON_UPDATE_LOGIN_LIMIT', 'CHECK_FOR_NEW_VERSION', 'USE_CURL', 'DIGEST_ENABLE', 'DIGEST_EMAIL_LIMIT', 'DAEMON_SENDS_DIGESTS', 'ENABLE_TRANSLATIONS', 'MYSQL_CHARSET', 'DEFAULT_UPDATE_METHOD', 'SIMPLEPIE_CACHE_DIR', 'SIMPLEPIE_CACHE_IMAGES', 'COUNTERS_MAX_AGE', 'DIGEST_FROM_NAME', 'DIGEST_FROM_ADDRESS', 'DIGEST_SUBJECT', 'DIGEST_SMTP_HOST', 'DIGEST_SMTP_LOGIN', 'DIGEST_SMTP_PASSWORD', 'DAEMON_FEED_LIMIT', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'LOCK_DIRECTORY', 'ENABLE_GZIP_OUTPUT', 'PHP_EXECUTABLE', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'FEEDBACK_URL', 'FORCE_ARTICLE_PURGE', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_TWEET_BUTTON', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'CONFIG_VERSION'); ?>

17
utils/regen_config_checks.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
DESTINATION="sanity_config.php"
echo "<?php # This file has been generated at: " `date` > $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