connect_error because of bugs before PHP 5.2.9 $error = mysqli_connect_error(); return empty($error); } function mysql_query($query) { return installer::$mysqli->query($query); } function mysql_num_rows($result) { return $result->num_rows; } function mysql_error() { return installer::$mysqli->error; } function mysql_select_db($db) { return installer::$mysqli->select_db($db); } } $host = empty($config["port"]) ? $config['host'] : "{$config['host']}:{$config['port']}"; return @mysql_connect($host, $config["user"], $config["password"]); } static function select_db($config) { if (mysql_select_db($config["dbname"])) { return true; } return mysql_query("CREATE DATABASE `{$config['dbname']}`") && mysql_select_db($config["dbname"]); } static function verify_mysql_version($config) { return version_compare(installer::mysql_version($config), "5.0.0", ">="); } static function mysql_version($config) { $result = mysql_query("SHOW VARIABLES WHERE variable_name = \"version\""); $row = mysql_fetch_object($result); return $row->Value; } static function db_empty($config) { $query = "SHOW TABLES LIKE '{$config['prefix']}items'"; $results = mysql_query($query); if ($results === false) { $msg = mysql_error(); return $msg; } return mysql_num_rows($results) === 0; } static function create_admin($config) { $salt = ""; for ($i = 0; $i < 4; $i++) { $char = mt_rand(48, 109); $char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0; $salt .= chr($char); } $password = substr(md5(time() . mt_rand()), 0, 6); // Escape backslash in preparation for our UPDATE statement. $hashed_password = str_replace("\\", "\\\\", $salt . md5($salt . $password)); $sql = self::prepend_prefix($config["prefix"], "UPDATE {users} SET `password` = '$hashed_password' WHERE `id` = 2"); if (mysql_query($sql)) { } else { throw new Exception(mysql_error()); } return array("admin", $password); } static function create_admin_session($config) { $session_id = md5(time() . mt_rand()); $user_agent = $_SERVER["HTTP_USER_AGENT"]; $user_agent_len = strlen($user_agent); $now = time(); $data = "session_id|s:32:\"$session_id\""; $data .= ";user_agent|s:{$user_agent_len}:\"$user_agent\""; $data .= ";user|i:2"; $data .= ";after_install|i:1"; $data .= ";last_activity|i:$now"; $data = base64_encode($data); $sql = "INSERT INTO {sessions}(`session_id`, `last_activity`, `data`) " . "VALUES('$session_id', $now, '$data')"; $sql = self::prepend_prefix($config["prefix"], $sql); if (mysql_query($sql)) { setcookie("g3sid", $session_id, 0, "/", "", false, false); } else { throw new Exception(mysql_error()); } } static function create_private_key($config) { $key = md5(uniqid(mt_rand(), true)) . md5(uniqid(mt_rand(), true)); $sql = self::prepend_prefix($config["prefix"], "INSERT INTO {vars} VALUES(NULL, 'gallery', 'private_key', '$key')"); if (mysql_query($sql)) { } else { throw new Exception(mysql_error()); } } static function prepend_prefix($prefix, $sql) { return preg_replace("#{([a-zA-Z0-9_]+)}#", "`{$prefix}$1`", $sql); } static function check_environment() { if (!function_exists("mysql_query") && !function_exists("mysqli_set_charset")) { $errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the MySQL or the MySQLi extension."; } if (!preg_match("/^.$/u", "ñ")) { $errors[] = "PHP is missing Perl-Compatible Regular Expression with UTF-8 support."; } else if (!preg_match("/^\pL$/u", "ñ")) { $errors[] = "PHP is missing Perl-Compatible Regular Expression with Unicode support."; } if (!(function_exists("spl_autoload_register"))) { $errors[] = "PHP is missing Standard PHP Library (SPL) support"; } if (!(class_exists("ReflectionClass"))) { $errors[] = "PHP is missing reflection support"; } if (!(function_exists("filter_list"))) { $errors[] = "PHP is missing the filter extension"; } if (!(extension_loaded("iconv"))) { $errors[] = "PHP is missing the iconv extension"; } if (!(extension_loaded("xml"))) { $errors[] = "PHP is missing the XML Parser extension"; } if (!(extension_loaded("simplexml"))) { $errors[] = "PHP is missing the SimpleXML extension"; } if (!extension_loaded("mbstring")) { $errors[] = "PHP is missing the mbstring extension"; } else if (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING) { $errors[] = "The mbstring extension is overloading PHP's native string functions. Please disable it."; } if (!function_exists("json_encode")) { $errors[] = "PHP is missing the JavaScript Object Notation (JSON) extension. Please install it."; } if (!ini_get("short_open_tag")) { $errors[] = "Gallery requires short_open_tag to be on. Please enable it in your php.ini."; } if (!function_exists("ctype_alpha")) { $errors[] = "Gallery requires the PHP Ctype extension. Please install it."; } if (self::ini_get_bool("safe_mode")) { $errors[] = "Gallery cannot function when PHP is in Safe Mode. Please disable safe mode."; } return @$errors; } /** * Convert any possible boolean ini value to true/false. * On = on = 1 = true * Off = off = 0 = false */ static function ini_get_bool($varname) { $value = ini_get($varname); if (!strcasecmp("on", $value) || $value == 1 || $value === true) { return true; } if (!strcasecmp("off", $value) || $value == 0 || $value === false) { return false; } return false; } }