summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--install.php5
-rw-r--r--lib/debug.lib.php11
-rw-r--r--lib/install.php36
-rw-r--r--templates/show_install_check.inc.php12
-rw-r--r--templates/show_install_config.inc.php3
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>&nbsp;</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>