1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

Made an redirect when it seems like the installation has already been completed.

This commit is contained in:
dipsol 2009-11-04 13:14:31 +00:00
parent c4acbd9e64
commit c717912676
3 changed files with 186 additions and 129 deletions

View file

@ -24,13 +24,13 @@ error_reporting(E_ALL ^ E_NOTICE);
require_once 'lib/general.lib.php';
require_once 'lib/class/config.class.php';
require_once 'lib/class/error.class.php';
require_once 'lib/class/error.class.php';
require_once 'lib/class/vauth.class.php';
require_once 'lib/class/database_object.abstract.php';
require_once 'lib/class/preference.class.php';
require_once 'lib/class/access.class.php';
require_once 'lib/class/preference.class.php';
require_once 'lib/class/access.class.php';
require_once 'lib/ui.lib.php';
require_once 'lib/log.lib.php';
require_once 'lib/log.lib.php';
require_once 'modules/horde/Browser.php';
require_once 'lib/install.php';
require_once 'lib/debug.lib.php';
@ -39,22 +39,23 @@ require_once 'lib/gettext.php';
if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
else { $http_type = "http://"; }
$prefix = dirname(__FILE__);
Config::set('prefix',$prefix,'1');
$prefix = dirname(__FILE__);
Config::set('prefix',$prefix,'1');
$configfile = "$prefix/config/ampache.cfg.php";
set_error_handler('ampache_error_handler');
/* First things first we must be sure that they actually still need to
install ampache
/* First things first we must be sure that they actually still need to
install ampache
*/
if (!install_check_status($configfile)) {
Error::display('general');
exit;
if (!install_check_status($configfile)) {
$redirect_url = "login.php";
require_once Config::get('prefix') . '/templates/error_page.inc.php';
exit;
}
// Define that we are doing an install so the includes will work
define('INSTALL','1');
define('INSTALL','1');
define('INIT_LOADED','1');
/* Clean up incomming variables */
@ -67,10 +68,10 @@ if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
else { $http_type = "http://"; }
define('WEB_PATH',$http_type . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . basename($_SERVER['PHP_SELF']));
define('WEB_ROOT',$http_type . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
define('WEB_ROOT',$http_type . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
/* Catch the Current Action */
switch ($_REQUEST['action']) {
switch ($_REQUEST['action']) {
case 'create_db':
/* Get the variables for the language */
$htmllang = $_REQUEST['htmllang'];
@ -88,25 +89,25 @@ switch ($_REQUEST['action']) {
// Now that it's inserted save the lang preference
Preference::update('lang','-1',$htmllang);
header ("Location: " . WEB_PATH . "?action=show_create_config&local_db=$database&local_host=$hostname&htmllang=$htmllang&charset=$charset");
break;
case 'create_config':
// Test and make sure that the values they give us actually work
if (!check_database($hostname,$username,$password)) {
if (!check_database($hostname,$username,$password)) {
Error::add('config',_('Error: Unable to make Database Connection') . mysql_error());
}
}
if (!Error::occurred()) {
if (!Error::occurred()) {
$created_config = install_create_config($web_path,$username,$password,$hostname,$database);
}
}
require_once 'templates/show_install_config.inc.php';
break;
case 'show_create_config':
/* Attempt to Guess the Web_path */
$web_path = dirname($_SERVER['PHP_SELF']);
$web_path = rtrim($web_path,"\/");
@ -133,14 +134,14 @@ switch ($_REQUEST['action']) {
'tr_TR' => 'iso-8859-9',
'zh_CN' => 'GBK');
$charset = $charsets[$_REQUEST['htmllang']];
// Set the site_charset in the conf array
Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');
/* load_gettext mojo */
load_gettext();
header ("Content-Type: text/html; charset=" . Config::get('site_charset'));
require_once 'templates/show_install_config.inc.php';
break;
case 'create_account':
@ -157,17 +158,17 @@ switch ($_REQUEST['action']) {
Config::set('site_charset', $charset, '1');
load_gettext();
$password2 = scrub_in($_REQUEST['local_pass2']);
$password2 = scrub_in($_REQUEST['local_pass2']);
if (!install_create_account($username,$password,$password2)) {
if (!install_create_account($username,$password,$password2)) {
require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
break;
}
header ("Location: " . WEB_ROOT . "/login.php");
break;
break;
case 'show_create_account':
$results = parse_ini_file($configfile);
/* Get the variables for the language */
@ -180,16 +181,16 @@ switch ($_REQUEST['action']) {
load_gettext();
/* Make sure we've got a valid config file */
if (!check_config_values($results)) {
Error::add('general',_('Error: Config file not found or Unreadable'));
require_once Config::get('prefix') . '/templates/show_install_config.inc.php';
if (!check_config_values($results)) {
Error::add('general',_('Error: Config file not found or Unreadable'));
require_once Config::get('prefix') . '/templates/show_install_config.inc.php';
break;
}
/* Get the variables for the language */
$htmllang = $_REQUEST['htmllang'];
$charset = $_REQUEST['charset'];
// Set the lang in the conf array
Config::set('lang',$htmllang,'1');
@ -207,14 +208,14 @@ switch ($_REQUEST['action']) {
'tr_TR' => 'iso-8859-9',
'zh_CN' => 'GBK');
$charset = $charsets[$_REQUEST['htmllang']];
// Set the site_charset in the conf array
Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');
/* load_gettext mojo */
load_gettext();
header ("Content-Type: text/html; charset=" . Config::get('site_charset'));
require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
break;
case 'init':
@ -243,7 +244,7 @@ switch ($_REQUEST['action']) {
// Set the site_charset in the conf array
Config::set('site_charset',$charsets[$_POST['htmllang']],'1');
// Now we make voodoo with the Load gettext mojo
load_gettext();

View file

@ -22,7 +22,7 @@
/**
* split_sql
* splits up a standard SQL dump file into distinct
* sql queryies
* sql queryies
*/
function split_sql($sql) {
$sql = trim($sql);
@ -59,45 +59,47 @@ function split_sql($sql) {
* still need to install ampache. This function is
* very important, we don't want to reinstall over top of an existing install
*/
function install_check_status($configfile) {
function install_check_status($configfile) {
/*
/*
Check and see if the config file exists
if it does they can't use the web interface
to install ampache.
to install ampache.
*/
if (!file_exists($configfile)) {
return true;
if (!file_exists($configfile)) {
return false;
} else {
Error::add('general',_('Config file already exists, install is probably completed'));
}
/*
/*
Check and see if they've got _any_ account
if they don't then they're cool
*/
$results = parse_ini_file($configfile);
$dbh = check_database($results['database_hostname'],$results['database_username'],$results['database_password']);
$dbh = check_database($results['database_hostname'],$results['database_username'],$results['database_password']);
if (!is_resource($dbh)) {
Error::add('general',_('Unable to connect to database, check your ampache config'));
return false;
}
if (!is_resource($dbh)) {
Error::add('general',_('Unable to connect to database, check your ampache config'));
return false;
}
$select_db = mysql_select_db($results['database_name'],$dbh);
if (!$select_db) {
Error::add('general',_('Unable to select database, check your ampache config'));
return false;
}
if (!$select_db) {
Error::add('general',_('Unable to select database, check your ampache config'));
return false;
}
$sql = "SELECT * FROM `user`";
$db_results = mysql_query($sql, $dbh);
if (!mysql_num_rows($db_results)) {
if (!mysql_num_rows($db_results)) {
return true;
}
else {
Error::add('general',_('Existing Database detected, unable to continue installation'));
return false;
}
else {
Error::add('general',_('Existing Database detected, unable to continue installation'));
return false;
}
/* Defaut to no */
return false;
@ -112,52 +114,52 @@ function install_check_status($configfile) {
function install_insert_db($username,$password,$hostname,$database) {
// Make sure that the database name is valid
$is_valid = preg_match("/([^\d\w\_\-])/",$database,$matches);
$is_valid = preg_match("/([^\d\w\_\-])/",$database,$matches);
if (count($matches)) {
Error::add('general','Error: Database name invalid must not be a reserved word, and must be Alphanumeric');
return false;
if (count($matches)) {
Error::add('general','Error: Database name invalid must not be a reserved word, and must be Alphanumeric');
return false;
}
$data['database_username'] = $username;
$data['database_password'] = $password;
$data['database_hostname'] = $hostname;
$data['database_username'] = $username;
$data['database_password'] = $password;
$data['database_hostname'] = $hostname;
$data['database_name'] = $database;
Config::set_by_array($data,'1');
unset($data);
Config::set_by_array($data,'1');
unset($data);
/* Attempt to make DB connection */
$dbh = Dba::dbh();
if (!is_resource($dbh)) {
Error::add('general',_('Error: Unable to make Database Connection') . " " . mysql_error());
return false;
if (!is_resource($dbh)) {
Error::add('general',_('Error: Unable to make Database Connection') . " " . mysql_error());
return false;
}
/* Check/Create Database as needed */
$db_selected = @mysql_select_db($database, $dbh);
if ($db_selected && $_POST['existing_db']) {
if ($db_selected && $_POST['existing_db']) {
// Rien a faire, we've got the db just blow through
}
elseif ($db_selected && !$_POST['overwrite_db']) {
Error::add('general','Error: Database Already exists and Overwrite not checked');
return false;
}
elseif (!$db_selected) {
}
elseif ($db_selected && !$_POST['overwrite_db']) {
Error::add('general','Error: Database Already exists and Overwrite not checked');
return false;
}
elseif (!$db_selected) {
$sql = "CREATE DATABASE `" . Dba::escape($database) . "`";
if (!$db_results = @mysql_query($sql, $dbh)) {
if (!$db_results = @mysql_query($sql, $dbh)) {
Error::add('general',"Error: Unable to Create Database " . mysql_error());
return false;
}
@mysql_select_db($database, $dbh);
} // if db can't be selected
else {
$sql = "DROP DATABASE `" . Dba::escape($database) . "`";
$db_results = @mysql_query($sql,$dbh);
$sql = "CREATE DATABASE `" . Dba::escape($database) . "`";
else {
$sql = "DROP DATABASE `" . Dba::escape($database) . "`";
$db_results = @mysql_query($sql,$dbh);
$sql = "CREATE DATABASE `" . Dba::escape($database) . "`";
if (!$db_results = @mysql_query($sql, $dbh)) {
Error::add('general',"Error: Unable to Create Database " . mysql_error());
return false;
@ -166,31 +168,31 @@ function install_insert_db($username,$password,$hostname,$database) {
} // end if selected and overwrite
/* Check and see if we should create a user here */
if ($_REQUEST['db_user'] == 'create_db_user') {
if ($_REQUEST['db_user'] == 'create_db_user') {
$db_user = scrub_in($_REQUEST['db_username']);
$db_pass = scrub_in($_REQUEST['db_password']);
$sql = "GRANT ALL PRIVILEGES ON " . Dba::escape($database) . ".* TO " .
"'" . Dba::escape($db_user) . "'@'" . Dba::escape($hostname) . "' IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
"'" . Dba::escape($db_user) . "'@'" . Dba::escape($hostname) . "' IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
// Check if the password has been set
if (!$password) {
Error::add('general','Error: Ampache SQL user must have a password');
return false;
Error::add('general','Error: Ampache SQL user must have a password');
return false;
}
if (!$db_results = @mysql_query($sql, $dbh)) {
if (!$db_results = @mysql_query($sql, $dbh)) {
Error::add('general',"Error: Unable to Insert $db_user with permissions to $database on $hostname " . mysql_error());
return false;
}
} // end if we are creating a user
// Figure out which version of MySQL we're running, if possible we want to use the UTF-8 dump
$sql = "SELECT VERSION()";
$db_results = mysql_query($sql,$dbh);
$sql = "SELECT VERSION()";
$db_results = mysql_query($sql,$dbh);
$data = mysql_fetch_row($db_results);
$data = mysql_fetch_row($db_results);
$mysql_version = substr(preg_replace("/(\d+)\.(\d+)\.(\d+).*/","$1$2$3",$data[0]),0,3);
$sql_file = ($mysql_version < '500') ? 'sql/ampache40.sql' : 'sql/ampache.sql';
$sql_file = ($mysql_version < '500') ? 'sql/ampache40.sql' : 'sql/ampache.sql';
/* Attempt to insert database */
$query = fread(fopen($sql_file, "r"), filesize($sql_file));
@ -206,10 +208,10 @@ function install_insert_db($username,$password,$hostname,$database) {
} // end if
} // end for
if ($mysql_version >= '500') {
if ($mysql_version >= '500') {
$sql = "ALTER DATABASE `" . Dba::escape($database) . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$db_results = mysql_query($sql);
}
$db_results = mysql_query($sql);
}
if(Config::get('lang') != 'en_US') {
$sql = "UPDATE `preference` SET `value`='" . Config::get('lang') . "' WHERE `id`=31";
@ -228,38 +230,38 @@ function install_insert_db($username,$password,$hostname,$database) {
* if it can't write it out it will prompt the
* user to download the config file.
*/
function install_create_config($web_path,$username,$password,$hostname,$database) {
function install_create_config($web_path,$username,$password,$hostname,$database) {
$data['database_username'] = $username;
$data['database_password'] = $password;
$data['database_hostname'] = $hostname;
$data['database_name'] = $database;
$data['web_path'] = $web_path;
$data['web_path'] = $web_path;
Config::set_by_array($data,'1');
/* Attempt to make DB connection */
$dbh = Dba::dbh();
/*
/*
First Test The Variables they've given us to make
sure that they actually work!
*/
// Connect to the DB
if(!is_resource($dbh)) {
if(!is_resource($dbh)) {
Error::add('general',"Database Connection Failed Check Hostname, Username and Password");
return false;
}
if (!$db_selected = @mysql_select_db($database, $dbh)) {
if (!$db_selected = @mysql_select_db($database, $dbh)) {
Error::add('general',"Database Selection Failure Check Existance of $database");
return false;
}
$final = generate_config($data);
$final = generate_config($data);
$browser = new Browser();
$browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize('config/ampache.cfg.php.dist'));
echo $final;
$browser = new Browser();
$browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize('config/ampache.cfg.php.dist'));
echo $final;
exit();
return true;
@ -270,47 +272,47 @@ function install_create_config($web_path,$username,$password,$hostname,$database
* install_create_account
* this creates your initial account and sets up the preferences for the -1 user and you
*/
function install_create_account($username,$password,$password2) {
function install_create_account($username,$password,$password2) {
if (!strlen($username) OR !strlen($password)) {
if (!strlen($username) OR !strlen($password)) {
Error::add('general',_('No Username/Password specified'));
return false;
return false;
}
if ($password !== $password2) {
if ($password !== $password2) {
Error::add('general',_('Passwords do not match'));
return false;
}
$dbh = Dba::dbh();
if (!is_resource($dbh)) {
Error::add('general','Database Connection Failed:' . mysql_error());
return false;
return false;
}
$dbh = Dba::dbh();
if (!is_resource($dbh)) {
Error::add('general','Database Connection Failed:' . mysql_error());
return false;
}
$db_select = @mysql_select_db(Config::get('database_name'),$dbh);
if (!$db_select) {
if (!$db_select) {
Error::add('general','Database Select Failed:' . mysql_error());
return false;
return false;
}
$username = Dba::escape($username);
$password = Dba::escape($password);
$insert_id = User::create($username,'Administrator','',$password,'100');
if (!$insert_id) {
$insert_id = User::create($username,'Administrator','',$password,'100');
if (!$insert_id) {
Error::add('general',"Insert of Base User Failed " . mysql_error());
return false;
return false;
}
// Fix the system users preferences
User::fix_preferences('-1');
return true;
} // install_create_account
?>

View file

@ -0,0 +1,54 @@
<?php
/*
Copyright (c) Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License v2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo $htmllang; ?>" lang="<?php echo $htmllang; ?>"
dir="<?php echo $dir;?>">
<head>
<meta http-equiv="refresh" content="10;URL=<?php echo($redirect_url);?>" />
<link rel="shortcut icon" href="<?php echo $web_path; ?>/favicon.ico" />
<title><?php echo( _("Ampache error page"));?></title>
<link rel="stylesheet" href="<?php echo $web_path; ?>/templates/base.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path; ?><?php echo Config::get('theme_path'); ?>/templates/default.css" type="text/css" media="screen" />
</head>
<body>
<!-- rfc3514 implementation -->
<div id="rfc3514" style="display: none;">0x0</div>
<div id="maincontainer">
<div id="header">
<div id="headerlogo">
<img src="<?php echo $web_path; echo Config::get('theme_path'); ?>/images/ampache.png"
title="<?php echo Config::get('site_title'); ?>"
alt="<?php echo Config::get('site_title'); ?>" />
</div>
</div>
<div>&nbsp;</div>
<div id="errormsg">
<?php echo (_("The folowing error has occured, you will automaticly be redirected after 10 seconds.") ); ?>
<br /><br />
<?php echo(_("Error messages"));?>:<br />
<?php Error::display('general'); ?>
</div>
</div>
</body>
</html>