downloadHeaders(basename($file), 'text/plain', false, strlen($final)); echo $final; exit(); } return true; } /** * install_insert_db * * Inserts the database using the values from Config. */ function install_insert_db($db_user = null, $db_pass = null, $create_db = true, $overwrite = false, $create_tables = true) { $database = AmpConfig::get('database_name'); // Make sure that the database name is valid preg_match('/([^\d\w\_\-])/', $database, $matches); if (count($matches)) { Error::add('general', T_('Error: Invalid database name.')); return false; } if (!Dba::check_database()) { Error::add('general', sprintf(T_('Error: Unable to make database connection: %s'), Dba::error())); return false; } $db_exists = Dba::read('SHOW TABLES'); if ($db_exists && $create_db) { if ($overwrite) { Dba::write('DROP DATABASE `' . $database . '`'); } else { Error::add('general', T_('Error: Database already exists and overwrite not checked')); return false; } } if ($create_db) { if (!Dba::write('CREATE DATABASE `' . $database . '`')) { Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error())); return false; } } Dba::disconnect(); // Check to see if we should create a user here if (strlen($db_user) && strlen($db_pass)) { $db_host = AmpConfig::get('database_hostname'); $sql = 'GRANT ALL PRIVILEGES ON `' . Dba::escape($database) . '`.* TO ' . "'" . Dba::escape($db_user) . "'"; if ($db_host == 'localhost' || strpos($db_host, '/') === 0) { $sql .= "@'localhost'"; } $sql .= "IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION"; if (!Dba::write($sql)) { Error::add('general', sprintf(T_('Error: Unable to create user %1$s with permissions to %2$s on %3$s: %4$s'), $db_user, $database, $db_host, Dba::error())); return false; } } // end if we are creating a user if ($create_tables) { $sql_file = AmpConfig::get('prefix') . '/sql/ampache.sql'; $query = fread(fopen($sql_file, 'r'), filesize($sql_file)); $pieces = split_sql($query); $errors = array(); for ($i=0; $i 0, we can ignore lazy comparison problems if (!file_put_contents($config_file, $final)) { Error::add('general', T_('Error writing config file')); return false; } } } else { $browser = new Horde_Browser(); $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final)); echo $final; exit(); } return true; } /** * 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) { if (!strlen($username) OR !strlen($password)) { Error::add('general', T_('No Username/Password specified')); return false; } if ($password !== $password2) { Error::add('general', T_('Passwords do not match')); return false; } if (!Dba::check_database()) { Error::add('general', sprintf(T_('Database connection failed: %s'), Dba::error())); return false; } if (!Dba::check_database_inserted()) { Error::add('general', sprintf(T_('Database select failed: %s'), Dba::error())); return false; } $username = Dba::escape($username); $password = Dba::escape($password); $insert_id = User::create($username,'Administrator','','',$password,'100'); if (!$insert_id) { Error::add('general', sprintf(T_('Administrative user creation failed: %s'), Dba::error())); return false; } // Fix the system users preferences User::fix_preferences('-1'); return true; } // install_create_account function command_exists($command) { if (!function_exists('proc_open')) { return false; } $whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'which'; $process = proc_open( "$whereIsCommand $command", array( 0 => array("pipe", "r"), //STDIN 1 => array("pipe", "w"), //STDOUT 2 => array("pipe", "w"), //STDERR ), $pipes ); if ($process !== false) { $stdout = stream_get_contents($pipes[1]); stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); return $stdout != ''; } return false; } /** * install_get_transcode_modes * get transcode modes available on this machine. */ function install_get_transcode_modes() { $modes = array(); if (command_exists('ffmpeg')) { $modes[] = 'ffmpeg'; } if (command_exists('avconv')) { $modes[] = 'avconv'; } return $modes; } // install_get_transcode_modes function install_config_transcode_mode($mode) { $trconfig = array( 'encode_target' => 'mp3', 'transcode_m4a' => 'required', 'transcode_flac' => 'required', 'transcode_mpc' => 'required', 'transcode_ogg' => 'allowed', 'transcode_wav' => 'required' ); if ($mode == 'ffmpeg' || $mode == 'avconv') { $trconfig['transcode_cmd'] = $mode . ' -i %FILE%'; $trconfig['encode_args_mp3'] = '-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1'; $trconfig['encode_args_ogg'] = '-vn -b:a %SAMPLE%K -c:a libvorbis -f ogg pipe:1'; $trconfig['encode_args_wav'] = '-vn -b:a %SAMPLE%K -c:a pcm_s16le -f wav pipe:1'; AmpConfig::set_by_array($trconfig, true); } }