add_error('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"; 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()); return false; } } // end if we are creating a user /* Attempt to insert database */ $query = fread(fopen("sql/ampache.sql", "r"), filesize("sql/ampache.sql")); $pieces = split_sql($query); for ($i=0; $iadd_error('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"); return false; } /* 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; } return true; } // install_create_config /*! @function install_create_account @discussion this creates your initial account */ function install_create_account($username,$password) { $results = read_config($GLOBALS['configfile'], 0, 0); $dbh = check_database($results['local_host'],$results['local_username'],$results['local_pass']); @mysql_select_db($results['local_db'],$dbh); $username = sql_escape($username,$dbh); $password = sql_escape($password,$dbh); $sql = "INSERT INTO user (`username`,`password`,`offset_limit`,`access`) VALUES ('$username',PASSWORD('$password'),'50','admin')"; $db_results = mysql_query($sql, $dbh); if (!$db_results) { $GLOBALS['error']->add_error('general',"Insert of Base User Failed " . mysql_error()); return false; } return true; } // install_create_account ?>