diff options
author | Karl Vollmer <vollmer@ampache.org> | 2011-07-27 14:35:49 -0300 |
---|---|---|
committer | Karl Vollmer <vollmer@ampache.org> | 2011-07-27 14:35:49 -0300 |
commit | ffad56ec182f110c3511ce56d7a3cfe54a6b5de5 (patch) | |
tree | 57dafdf5979889dce1e84dbb11911e2c79870943 | |
parent | 33c629f4ef5e0dfd0e9b6bc0deddb165ffe20df5 (diff) | |
download | ampache-ffad56ec182f110c3511ce56d7a3cfe54a6b5de5.tar.gz ampache-ffad56ec182f110c3511ce56d7a3cfe54a6b5de5.tar.bz2 ampache-ffad56ec182f110c3511ce56d7a3cfe54a6b5de5.zip |
Install now contains two buttons, Download & Write for the config file, there is also
an additional check before that if the config file is writeable
-rw-r--r-- | install.php | 5 | ||||
-rw-r--r-- | lib/debug.lib.php | 11 | ||||
-rw-r--r-- | lib/install.php | 36 | ||||
-rw-r--r-- | templates/show_install_check.inc.php | 12 | ||||
-rw-r--r-- | templates/show_install_config.inc.php | 3 |
5 files changed, 47 insertions, 20 deletions
diff --git a/install.php b/install.php index 0a740a5f..f03c3842 100644 --- a/install.php +++ b/install.php @@ -116,8 +116,11 @@ switch ($_REQUEST['action']) { Error::add('config',_('Error: Unable to make Database Connection') . mysql_error()); } + // Was download pressed? + $download = (!isset($_POST['write'])); + if (!Error::occurred()) { - $created_config = install_create_config($web_path,$username,$password,$hostname,$database); + $created_config = install_create_config($web_path,$username,$password,$hostname,$database,$download); } require_once 'templates/show_install_config.inc.php'; diff --git a/lib/debug.lib.php b/lib/debug.lib.php index 03f4de6d..5bdd6619 100644 --- a/lib/debug.lib.php +++ b/lib/debug.lib.php @@ -311,6 +311,17 @@ function check_mbstring() { } // check_mbstring /** + * check_config_writable + * This checks whether we can write the config file + */ +function check_config_writable() { + + // file eixsts && is writable, or dir is writable + return ((file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writable(Config::get('prefix') . '/config/ampache.cfg.php')) + || (!file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writeable(Config::get('prefix') . '/config/'))); +} + +/** * generate_config * This takes an array of results and re-generates the config file * this is used by the installer and by the admin/system page diff --git a/lib/install.php b/lib/install.php index 61892b0a..f7de3a98 100644 --- a/lib/install.php +++ b/lib/install.php @@ -234,11 +234,9 @@ function install_insert_db($username,$password,$hostname,$database,$dbuser=false /** * install_create_config - * attempts to write out the config file - * if it can't write it out it will prompt the - * user to download the config file. + * attempts to write out the config file or offer it as a download */ -function install_create_config($web_path,$username,$password,$hostname,$database) { +function install_create_config($web_path,$username,$password,$hostname,$database,$download) { $config_file = Config::get('prefix') . '/config/ampache.cfg.php'; @@ -262,7 +260,7 @@ function install_create_config($web_path,$username,$password,$hostname,$database Error::add('general',"Database Connection Failed Check Hostname, Username and Password"); return false; } - if (!$db_selected = @mysql_select_db($database, $dbh)) { + if (!@mysql_select_db($database, $dbh)) { Error::add('general',"Database Selection Failure Check Existance of $database"); return false; } @@ -270,23 +268,25 @@ function install_create_config($web_path,$username,$password,$hostname,$database $final = generate_config($data); // Make sure the directory is writable OR the empty config file is - if (!is_writeable(Config::get('prefix') . '/config/') && !is_writeable($config_file)) { - // Fall back to the old method + if (!$download) { + if (!check_config_writable()) { + Error:add('general',"Config file is not writable"); + return false; + } + else { + // Given that $final is > 0, we can ignore lazy comparison problems + if (!file_put_contents($config_file,$final)) { + Error::add('general',"Error Writing config file"); + return false; + } + } + } + else { $browser = new Browser(); - $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, filesize('config/ampache.cfg.php.dist')); + $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final)); echo $final; exit(); } - else { - // Open the file and try to write it - $fhandle = fopen($config_file,'w'); - if (!fwrite($fhandle,$final)) { - Error::add('general',"Error Writing config file"); - fclose ($fhandle); - return false; - } - fclose ($fhandle); - } return true; diff --git a/templates/show_install_check.inc.php b/templates/show_install_check.inc.php index 5f9d64f9..42e5e51a 100644 --- a/templates/show_install_check.inc.php +++ b/templates/show_install_check.inc.php @@ -195,5 +195,17 @@ } ?> </td> +</tr><tr> +<td><?php echo _('ampache.cfg.php is writable'); ?></td> +<td> +<?php + if (!check_config_writable()) { + echo debug_result('', false); + } + else { + echo debug_result('', true); + } +?> +</td> </tr> </table> diff --git a/templates/show_install_config.inc.php b/templates/show_install_config.inc.php index c2513bfe..1244b920 100644 --- a/templates/show_install_config.inc.php +++ b/templates/show_install_config.inc.php @@ -66,7 +66,8 @@ require $prefix . '/templates/install_header.inc.php'; <tr> <td> </td> <td> - <input type="submit" value="<?php echo _('Write Config'); ?>" /> + <input type="submit" name="download" value="<?php echo _('Download'); ?>" /> + <input type="submit" name="write" value="<?php echo _('Write'); ?>" <?php if (!check_config_writable()) { echo "disabled "; } ?>/> <input type="hidden" name="htmllang" value="<?php echo $htmllang; ?>" /> <input type="hidden" name="charset" value="<?php echo $charset; ?>" /> </td> |