diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-05-13 21:37:49 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-05-13 21:37:49 +0000 |
commit | 779f4bf4e560d7f415ea51a96ed547831745a8dc (patch) | |
tree | c99f06687da016d975b3e131ff2d57a8b68da0dd /lib | |
parent | 1a6ae62569dbc5603a361a488641950cc317ac3d (diff) | |
download | ampache-779f4bf4e560d7f415ea51a96ed547831745a8dc.tar.gz ampache-779f4bf4e560d7f415ea51a96ed547831745a8dc.tar.bz2 ampache-779f4bf4e560d7f415ea51a96ed547831745a8dc.zip |
updated sql file, and the install process now works
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/update.class.php | 6 | ||||
-rw-r--r-- | lib/class/user.class.php | 18 | ||||
-rw-r--r-- | lib/debug.lib.php | 55 | ||||
-rw-r--r-- | lib/install.php | 154 |
4 files changed, 129 insertions, 104 deletions
diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 59bf8166..13bfdfdb 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -177,17 +177,15 @@ class Update { /* Define the array */ $version = array(); - $version[] = array('version' => '333004','description' => $update_string); - $update_string = '- Moved back to ID for user tracking internally.<br />' . '- Added date to user_vote to allow sorting by vote time.<br />' . '- Added Random Method and Object Count Preferences.<br />' . '- Removed some unused tables/fields.<br />' . - '- Added Label, Catalog # and Language to Extended Song Data Table<br />'; + '- Added Label, Catalog # and Language to Extended Song Data Table.'; $version[] = array('version' => '340001','description' => $update_string); - $update_string = '- Added Offset Limit to Preferences and removed from user table'; + $update_string = '- Added Offset Limit to Preferences and removed from user table.'; $version[] = array('version' => '340002','description' => $update_string); diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 990a27ce..fe75d587 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -585,26 +585,26 @@ class User { * create * inserts a new user into ampache */ - function create($username, $fullname, $email, $password, $access) { + public static function create($username, $fullname, $email, $password, $access) { /* Lets clean up the fields... */ - $username = sql_escape($username); - $fullname = sql_escape($fullname); - $email = sql_escape($email); - $access = sql_escape($access); + $username = Dba::escape($username); + $fullname = Dba::escape($fullname); + $email = Dba::escape($email); + $access = Dba::escape($access); /* Now Insert this new user */ - $sql = "INSERT INTO user (username, fullname, email, password, access, create_date) VALUES" . + $sql = "INSERT INTO `user` (`username`, `fullname`, `email`, `password`, `access`, `create_date`) VALUES" . " ('$username','$fullname','$email',PASSWORD('$password'),'$access','" . time() ."')"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); if (!$db_results) { return false; } // Get the insert_id - $insert_id = mysql_insert_id(dbh()); + $insert_id = Dba::insert_id(); /* Populates any missing preferences, in this case all of them */ - $this->fix_preferences($insert_id); + self::fix_preferences($insert_id); return $insert_id; diff --git a/lib/debug.lib.php b/lib/debug.lib.php index 69825c68..9f7f1c59 100644 --- a/lib/debug.lib.php +++ b/lib/debug.lib.php @@ -143,11 +143,10 @@ function check_php_pcre() { } // check_php_pcre -/*! - @function check_config_values() - @discussion checks to make sure that they have at - least set the needed variables -*/ +/** + * check_config_values + * checks to make sure that they have at least set the needed variables + */ function check_config_values($conf) { if (!$conf['database_hostname']) { @@ -211,4 +210,50 @@ function check_putenv() { } // check_putenv +/** + * 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 + */ +function generate_config($current) { + + /* Start building the new config file */ + $distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist'; + $handle = fopen($distfile,'r'); + $dist = fread($handle,filesize($distfile)); + fclose($handle); + + $data = explode("\n",$dist); + + /* Run throught the lines and set our settings */ + foreach ($data as $line) { + + /* Attempt to pull out Key */ + if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches) + || preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches) + || preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) { + + $key = $matches[1]; + $value = $matches[2]; + + /* Put in the current value */ + if (isset($current[$key]) AND $key != 'config_version') { + $line = $key . ' = "' . $current[$key] . '"'; + unset($current[$key]); + } // if set + + elseif (isset($array_value[$key])) { + $line = ''; + } + + } // if key + + $final .= $line . "\n"; + + } // end foreach line + + return $final; + +} // generate_config + ?> diff --git a/lib/install.php b/lib/install.php index 4bf47b11..15e705d5 100644 --- a/lib/install.php +++ b/lib/install.php @@ -92,41 +92,55 @@ function install_check_status($configfile) { } // install_check_status -/*! - @function install_insert_db() - @discussion this function inserts the database - using the username/pass/host provided - and reading the .sql file -*/ +/** + * install_insert_db + * this function inserts the database using the username/pass/host provided + * and reading the .sql file + */ function install_insert_db($username,$password,$hostname,$database) { + $data['database_username'] = $username; + $data['database_password'] = $password; + $data['database_hostname'] = $hostname; + $data['database_name'] = $database; + + Config::set_by_array($data,'1'); + + unset($data); + /* Attempt to make DB connection */ - $dbh = @mysql_pconnect($hostname,$username,$password); + $dbh = Dba::dbh(); if (!is_resource($dbh)) { - $GLOBALS['error']->add_error('general',"Error: Unable to make Database Connection " . mysql_error()); + 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['overwrite_db']) { + Error::add('general','Error: Database Already exists and Overwrite no checked'); + return false; + } if (!$db_selected) { $sql = "CREATE DATABASE `" . $database . "`"; if (!$db_results = @mysql_query($sql, $dbh)) { - $GLOBALS['error']->add_error('general',"Error: Unable to Create Database " . mysql_error()); + Error::add('general',"Error: Unable to Create Database " . mysql_error()); return false; } @mysql_select_db($database, $dbh); } // if db can't be selected + /* Check and see if we should create a user here */ 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 " . sql_escape($database,$dbh) . ".* TO " . - "'" . sql_escape($db_user,$dbh) . "'@'" . sql_escape($hostname,$dbh) . "' IDENTIFIED BY '" . sql_escape($db_pass,$dbh) . "' WITH GRANT OPTION"; + "'" . Dba::escape($db_user) . "'@'" . Dba::escape($hostname) . "' IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION"; if (!$db_results = @mysql_query($sql, $dbh)) { - $GLOBALS['error']->add_error('general',"Error: Unable to Insert $db_user with permissions to $database on $hostname " . mysql_error()); + 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 @@ -139,7 +153,7 @@ function install_insert_db($username,$password,$hostname,$database) { if(!empty($pieces[$i]) && $pieces[$i] != "#") { //FIXME: This is for a DB prefix when we get around to it // $pieces[$i] = str_replace( "#__", $DBPrefix, $pieces[$i]); - if (!$result = mysql_query ($pieces[$i])) { + if (!$result = Dba::query ($pieces[$i])) { $errors[] = array ( mysql_error(), $pieces[$i] ); } // end if } // end if @@ -149,120 +163,88 @@ function install_insert_db($username,$password,$hostname,$database) { } // install_insert_db -/*! - @function install_create_config() - @discussion attempts to write out the config file - if it can't write it out it will prompt the - user to download the config file. -*/ +/** + * 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. + */ 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; + + 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(!$dbh = @mysql_pconnect($hostname,$username,$password)) { - $GLOBALS['error']->add_error('general',"Database Connection Failed Check Hostname, Username and Password"); + 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)) { - $GLOBALS['error']->add_error('general',"Database Selection Failure Check Existance of $database"); + Error::add('general',"Database Selection Failure Check Existance of $database"); return false; } + $final = generate_config($data); - /* Read in the .dist file and spit out the .cfg */ - $dist_handle = @fopen("config/ampache.cfg.php.dist",'r'); - $dist_data = @fread($dist_handle,filesize("config/ampache.cfg.php.dist")); - fclose($dist_handle); - - $dist_array = explode("\n",$dist_data); - - // Rather then write it out right away, let's build the string - // incase we can't write to the FS and have to make it a download - - foreach ($dist_array as $row) { - - if (preg_match("/^#?web_path\s*=/",$row)) { - $row = "web_path = \"$web_path\""; - } - elseif (preg_match("/^#?local_db\s*=/",$row)) { - $row = "local_db = \"$database\""; - } - elseif (preg_match("/^#?local_host\s*=/",$row)) { - $row = "local_host = \"$hostname\""; - } - elseif (preg_match("/^#?local_username\s*=/",$row)) { - $row = "local_username = \"$username\""; - } - elseif (preg_match("/^#?local_pass\s*=/",$row)) { - $row = "local_pass = \"$password\""; - } - - $config_data .= $row . "\n"; - - } // foreach row in config file - - /* Attempt to Write out File */ - if (!$config_handle = @fopen("config/ampache.cfg.php",'w')) { - $browser = new Browser(); - $browser->downloadHeaders("ampache.cfg.php","text/plain",false,filesize("config/ampache.cfg.php.dist")); - echo $config_data; - exit(); - - } - if (!@fwrite($config_handle,$config_data)) { - $GLOBALS['error']->add_error('general',"Error: Unable to write Config File but file writeable?"); - return false; - } + $browser = new Browser(); + $browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize('config/ampache.cfg.php.dist')); + echo $final; + exit(); return true; } // install_create_config -/*! - @function install_create_account - @discussion this creates your initial account -*/ +/** + * 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) { if (!strlen($username) OR !strlen($password)) { - $GLOBALS['error']->add_error('general',"No Username/Password specified"); + Error::add('general',"No Username/Password specified"); return false; } - $results = read_config($GLOBALS['configfile'], 0, 0); - $dbh = check_database($results['local_host'],$results['local_username'],$results['local_pass']); + $dbh = Dba::dbh(); if (!is_resource($dbh)) { - $GLOBALS['error']->add_error('general','Database Connection Failed:' . mysql_error()); + Error::add('general','Database Connection Failed:' . mysql_error()); return false; } - $db_select = @mysql_select_db($results['local_db'],$dbh); + $db_select = @mysql_select_db(Config::get('database_name'),$dbh); if (!$db_select) { - $GLOBALS['error']->add_error('general','Database Select Failed:' . mysql_error()); + Error::add('general','Database Select Failed:' . mysql_error()); return false; } - if (is_numeric($username)) { - $GLOBALS['error']->add_error('general',"Error: Due to the incompotence of the programmer of this application usernames with all numbers will cause the world to come to an end, please add a letter"); - return false; - } + $username = Dba::escape($username); + $password = Dba::escape($password); - $username = sql_escape($username,$dbh); - $password = sql_escape($password,$dbh); - - $sql = "INSERT INTO user (`username`,`password`,`offset_limit`,`access`) VALUES ('$username',PASSWORD('$password'),'50','100')"; - $db_results = mysql_query($sql, $dbh); + $insert_id = User::create($username,'Administrator','',$password,'100'); - if (!$db_results) { - $GLOBALS['error']->add_error('general',"Insert of Base User Failed " . mysql_error()); + if (!$insert_id) { + Error::add('general',"Insert of Base User Failed " . mysql_error()); return false; } + // Fix the system users preferences + User::fix_preferences('-1'); + return true; } // install_create_account |