diff options
Diffstat (limited to 'install/index.php')
-rw-r--r-- | install/index.php | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/install/index.php b/install/index.php index 026e00d01..6cb2ace4f 100644 --- a/install/index.php +++ b/install/index.php @@ -10,6 +10,25 @@ <body> <?php + function make_password($length = 8) { + + $password = ""; + $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^"; + + $i = 0; + + while ($i < $length) { + $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); + + if (!strstr($password, $char)) { + $password .= $char; + $i++; + } + } + return $password; + } + + function sanity_check($db_type) { $errors = array(); @@ -17,10 +36,6 @@ array_push($errors, "PHP version 5.3.0 or newer required."); } - if (ini_get("open_basedir")) { - array_push($errors, "PHP configuration option open_basedir is not supported. Please disable this in PHP settings file (php.ini)."); - } - if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL."); } @@ -29,7 +44,7 @@ array_push($errors, "PHP support for JSON is required, but was not found."); } - if ($db_type == "mysql" && !function_exists("mysql_connect")) { + if ($db_type == "mysql" && !function_exists("mysql_connect") && !function_exists("mysqli_connect")) { array_push($errors, "PHP support for MySQL is required for configured $db_type in config.php."); } @@ -65,15 +80,16 @@ } function print_error($msg) { - print "<div class='error'><img src='../images/sign_excl.svg'> $msg</div>"; + print "<div class='error'><span><img src='../images/sign_excl.svg'></span> + <span>$msg</span></div>"; } function print_notice($msg) { print "<div class=\"notice\"> - <img src=\"../images/sign_info.svg\">$msg</div>"; + <span><img src=\"../images/sign_info.svg\"></span><span>$msg</span></div>"; } - function db_connect($host, $user, $pass, $db, $type) { + function db_connect($host, $user, $pass, $db, $type, $port = false) { if ($type == "pgsql") { $string = "dbname=$db user=$user"; @@ -86,8 +102,8 @@ $string .= " host=$host"; } - if (defined('DB_PORT')) { - $string = "$string port=" . DB_PORT; + if ($port) { + $string = "$string port=" . $port; } $link = pg_connect($string); @@ -95,10 +111,18 @@ return $link; } else if ($type == "mysql") { - $link = mysql_connect($host, $user, $pass); - if ($link) { - $result = mysql_select_db($db, $link); - if ($result) return $link; + if (function_exists("mysqli_connect")) { + if ($port) + return mysqli_connect($host, $user, $pass, $db, $port); + else + return mysqli_connect($host, $user, $pass, $db); + + } else { + $link = mysql_connect($host, $user, $pass); + if ($link) { + $result = mysql_select_db($db, $link); + if ($result) return $link; + } } } } @@ -112,6 +136,12 @@ $finished = false; + if (function_exists("mcrypt_decrypt")) { + $crypt_key = make_password(24); + } else { + $crypt_key = ""; + } + foreach ($data as $line) { if (preg_match("/define\('DB_TYPE'/", $line)) { $rv .= "\tdefine('DB_TYPE', '$DB_TYPE');\n"; @@ -127,6 +157,8 @@ $rv .= "\tdefine('DB_PORT', '$DB_PORT');\n"; } else if (preg_match("/define\('SELF_URL_PATH'/", $line)) { $rv .= "\tdefine('SELF_URL_PATH', '$SELF_URL_PATH');\n"; + } else if (preg_match("/define\('FEED_CRYPT_KEY'/", $line)) { + $rv .= "\tdefine('FEED_CRYPT_KEY', '$crypt_key');\n"; } else if (!$finished) { $rv .= "$line\n"; } @@ -150,7 +182,12 @@ } return $result; } else if ($type == "mysql") { - $result = mysql_query($query, $link); + + if (function_exists("mysqli_connect")) { + $result = mysqli_query($link, $query); + } else { + $result = mysql_query($query, $link); + } if (!$result) { $query = htmlspecialchars($query); if ($die_on_error) { @@ -231,17 +268,19 @@ <fieldset> <label>Database name</label> - <input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/> + <input required name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/> </fieldset> <fieldset> <label>Host name</label> - <input name="DB_HOST" placeholder="if needed" size="20" value="<?php echo $DB_HOST ?>"/> + <input name="DB_HOST" size="20" value="<?php echo $DB_HOST ?>"/> + <span class="hint">If needed</span> </fieldset> <fieldset> <label>Port</label> - <input name="DB_PORT" type="number" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/> + <input name="DB_PORT" type="number" size="20" value="<?php echo $DB_PORT ?>"/> + <span class="hint">Usually 3306 for MySQL or 5432 for PostgreSQL</span> </fieldset> <h2>Other settings</h2> @@ -304,7 +343,7 @@ <h2>Checking database</h2> <?php - $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE); + $link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT); if (!$link) { print_error("Unable to connect to database using specified parameters."); |