diff --git a/config/ASP/docker-entrypoint.sh b/config/ASP/docker-entrypoint.sh index 5015507a..1d00d5a2 100755 --- a/config/ASP/docker-entrypoint.sh +++ b/config/ASP/docker-entrypoint.sh @@ -18,12 +18,10 @@ echo "Setting permissions on backup volume" setup /src/ASP/system/database/backups 1 echo "Setting up config file" -CONFIG_FILE_SAMPLE=/config.sample/config.php CONFIG_FILE=/src/ASP/system/config/config.php -if [ ! -f "$CONFIG_FILE" ]; then - echo "Creating new config file: $CONFIG_FILE" - cp -v "$CONFIG_FILE_SAMPLE" "$CONFIG_FILE" -fi +php /src/ASP/index.php > /dev/null +ls -al $CONFIG_FILE + echo "Setting permissions on config volume" setup /src/ASP/system/config 1 @@ -49,7 +47,9 @@ write_config() { VAL=$( printenv "$ENVVAR" || true ) if [ -n "$VAL" ]; then echo "Writing key '$KEY' of type '$TYPE' to config file" - if [ "$TYPE" == 'string' ]; then + if [ "$TYPE" == 'boolean' ]; then + sed -i "s|^.$KEY =.*|\$$KEY = $VAL;|" "$CONFIG_FILE" # E.g. $bfhq_hide_bots = false; + elif [ "$TYPE" == 'string' ]; then sed -i "s|^.$KEY =.*|\$$KEY = '$VAL';|" "$CONFIG_FILE" # E.g. $db_host = '127.0.0.1'; elif [ "$TYPE" == 'int' ]; then sed -i "s|^.$KEY =.*|\$$KEY = $VAL;|" "$CONFIG_FILE" # E.g. $db_port = 3306; @@ -75,7 +75,9 @@ echo "$CONFILE_FILE_CONTENT" | grep -E '^\$' | while read -r KEY EQUALS VALUE; d KEY=$( echo "$KEY" | sed 's/^\$//' ) # Strip the dollar sign. E.g. '$db_host' -> 'db_host' VALUE=$( echo "$VALUE" | rev | sed 's/^;//' | rev ) # Strip the trailing semicolon TYPE= - if echo "$VALUE" | grep -E "^'" > /dev/null; then + if echo "$VALUE" | grep -E "^false|true$" > /dev/null; then + TYPE=boolean + elif echo "$VALUE" | grep -E "^'" > /dev/null; then TYPE=string elif echo "$VALUE" | grep -E "^array\(" > /dev/null; then TYPE=array diff --git a/src/ASP/system/core/Config.php b/src/ASP/system/core/Config.php index 4681bcdb..2642a088 100644 --- a/src/ASP/system/core/Config.php +++ b/src/ASP/system/core/Config.php @@ -28,15 +28,71 @@ public static function Init() { if(empty(self::$configFile)) { + // Load config defaults + if ( !self::LoadDefault() ) { + throw new Exception('Failed to load default configuration!'); + } + // Load the config File self::$configFile = SYSTEM_PATH . DS . 'config'. DS . 'config.php'; if( !self::Load() ) { - throw new Exception('Failed to load config file!'); + // Create the config file + self::Save(); + + // throw new Exception('Failed to load config file!'); } } } +/* +| --------------------------------------------------------------- +| Method: getDefault() +| --------------------------------------------------------------- +| +| Returns the default configuration. +| +| @Return: array of the default configuration. +| +*/ + private static function getDefault() + { + $cfg = array( + 'db_host' => '127.0.0.1', + 'db_port' => 3306, + 'db_name' => 'bf2stats', + 'db_user' => 'admin', + 'db_pass' => 'admin', + 'admin_user' => 'admin', + 'admin_pass' => 'admin', + 'admin_hosts' => array('127.0.0.1','192.168.2.0/24','localhost','192.168.1.102','192.168.1.110','0.0.0.0'), + 'admin_backup_path' => 'C:/wamp/www/ASP/system/database/backups/', + 'admin_backup_ext' => '.bak', + 'admin_ignore_ai' => 0, + 'stats_ignore_ai' => 0, + 'stats_min_game_time' => 0, + 'stats_min_player_game_time' => 0, + 'stats_players_min' => 1, + 'stats_players_max' => 256, + 'stats_rank_check' => 0, + 'stats_rank_tenure' => 7, + 'stats_process_smoc' => 1, + 'stats_process_gen' => 1, + 'stats_awds_complete' => 0, + 'stats_lan_override' => '174.49.21.221', + 'stats_local_pids' => array('LocalPlayer01','210.84.29.151','LocalPlayer02','210.84.29.151'), + 'debug_lvl' => 2, + 'game_hosts' => array('127.0.0.1','192.168.2.0/24','192.168.1.102','192.168.1.110','localhost','::1'), + 'game_custom_mapid' => 700, + 'game_unlocks' => 0, + 'game_unlocks_bonus' => 2, + 'game_unlocks_bonus_min' => 1, + 'game_awds_ignore_time' => 0, + 'game_default_pid' => 29000000, + ); + return $cfg; + } + /* | --------------------------------------------------------------- | Method: get() @@ -131,6 +187,16 @@ public static function Save() if (is_numeric($val)) { $cfg .= "\$$key = " . $val . ";\n"; + } + + // If the value is boolean, then put in a "boolean" value + elseif (is_bool($val) || $val === 'true' || $val === 'false') + { + if (!$val || $val === 'false') { + $cfg .= "\$$key = false;\n"; + }else { + $cfg .= "\$$key = true;\n"; + } } // Check for array values (admin_hosts, game_hosts, and stats_local_pids) @@ -203,7 +269,12 @@ protected static function Load() return false; } } + + protected static function LoadDefault() { + self::$data = self::getDefault(); + return true; + } } Config::Init(); -?> \ No newline at end of file +?>