From b4cec3747459ff09146a820827cdfa181b9a22a4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 28 Mar 2013 10:42:17 +0400 Subject: [PATCH] installer: add ability to automatically save generated config.php --- install/index.php | 110 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 84 insertions(+), 26 deletions(-) diff --git a/install/index.php b/install/index.php index 9855bac7..ba71bbdb 100644 --- a/install/index.php +++ b/install/index.php @@ -107,6 +107,36 @@ } } + function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, + $DB_PORT, $SELF_URL_PATH) { + + $data = explode("\n", file_get_contents("../config.php-dist")); + + $rv = ""; + + foreach ($data as $line) { + if (preg_match("/define\('DB_TYPE'/", $line)) { + $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n"; + } else if (preg_match("/define\('DB_HOST'/", $line)) { + $rv .= "\tdefine('DB_HOST', '$DB_HOST');\n"; + } else if (preg_match("/define\('DB_USER'/", $line)) { + $rv .= "\tdefine('DB_USER', '$DB_USER');\n"; + } else if (preg_match("/define\('DB_NAME'/", $line)) { + $rv .= "\tdefine('DB_NAME', '$DB_NAME');\n"; + } else if (preg_match("/define\('DB_PASS'/", $line)) { + $rv .= "\tdefine('DB_PASS', '$DB_PASS');\n"; + } else if (preg_match("/define\('DB_PORT'/", $line)) { + $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n"; + } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) { + $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n"; + } else { + $rv .= "$line\n"; + } + } + + return $rv; + } + function db_query($link, $query, $type, $die_on_error = true) { if ($type == "pgsql") { $result = pg_query($link, $query); @@ -149,7 +179,7 @@ require "../config.php"; if (!defined('_INSTALLER_IGNORE_CONFIG_CHECK')) { - print_error("Error: config.php already exists; aborting."); + print_error("Error: config.php already exists in tt-rss directory; aborting."); exit; } } @@ -344,34 +374,62 @@ print "

Generated configuration file

"; - print "

Copy following text and save as config.php in tt-rss main directory. It is suggested to read through the file to the end in case you need any options changed fom default values.

"; - - print ""; ?> + + +

We can also try saving the file automatically now.

+ +

+ + "; + print_notice("You can generate the file again by changing the form above."); + + } else if ($op == "saveconfig") { + + print "

Saving configuration file to parent directory...

"; + + if (!file_exists("../config.php")) { + + $fp = fopen("../config.php", "w"); + + if ($fp) { + $written = fwrite($fp, make_config($DB_TYPE, $DB_HOST, + $DB_USER, $DB_NAME, $DB_PASS, + $DB_PORT, $SELF_URL_PATH)); - print "

You can generate the file again by changing the form above.

"; + if ($written > 0) { + print_notice("Successfully saved config.php. You can try loading tt-rss now."); + + } else { + print_notice("Unable to write into config.php in tt-rss directory."); + } + + fclose($fp); + } else { + print_error("Unable to open config.php in tt-rss directory for writing."); + } + } else { + print_error("config.php already present in tt-rss directory, refusing to overwrite."); + } } ?> -- 2.39.5