summaryrefslogtreecommitdiff
path: root/install.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-08-24 16:55:49 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-08-24 16:55:49 -0400
commitff87732053bae38879988ba7d002a294998ccb4e (patch)
treeccccfe7fc8976baf1f0cd4438a57bf817dc4052c /install.php
parent27aeba01dd366f15f7847267b7518fb873987ddb (diff)
parentf3cdc7f272e409d391979d3e6c58dd63573530c0 (diff)
Merge branch '0.8.x' into testing
Conflicts: actions/twitterauthorization.php lib/oauthclient.php lib/twitter.php lib/twitterapi.php lib/twitteroauthclient.php scripts/twitterstatusfetcher.php
Diffstat (limited to 'install.php')
-rw-r--r--install.php137
1 files changed, 84 insertions, 53 deletions
diff --git a/install.php b/install.php
index 227f99789..c13f70272 100644
--- a/install.php
+++ b/install.php
@@ -49,8 +49,7 @@ function checkPrereqs()
}
$reqs = array('gd', 'curl',
- 'xmlwriter', 'mbstring',
- 'gettext');
+ 'xmlwriter', 'mbstring');
foreach ($reqs as $req) {
if (!checkExtension($req)) {
@@ -180,6 +179,9 @@ function handlePost()
$password = $_POST['password'];
$sitename = $_POST['sitename'];
$fancy = !empty($_POST['fancy']);
+ $server = $_SERVER['HTTP_HOST'];
+ $path = substr(dirname($_SERVER['PHP_SELF']), 1);
+
?>
<dl class="system_notice">
<dt>Page notice</dt>
@@ -219,20 +221,42 @@ function handlePost()
}
switch($dbtype) {
- case 'mysql': mysql_db_installer($host, $database, $username, $password, $sitename, $fancy);
- break;
- case 'pgsql': pgsql_db_installer($host, $database, $username, $password, $sitename, $fancy);
- break;
- default:
+ case 'mysql':
+ $db = mysql_db_installer($host, $database, $username, $password);
+ break;
+ case 'pgsql':
+ $db = pgsql_db_installer($host, $database, $username, $password);
+ break;
+ default:
+ }
+
+ if (!$db) {
+ // database connection failed, do not move on to create config file.
+ return false;
+ }
+
+ updateStatus("Writing config file...");
+ $res = writeConf($sitename, $server, $path, $fancy, $db);
+
+ if (!$res) {
+ updateStatus("Can't write config file.", true);
+ showForm();
+ return;
}
- if ($path) $path .= '/';
- updateStatus("You can visit your <a href='/$path'>new Laconica site</a>.");
+
+ /*
+ TODO https needs to be considered
+ */
+ $link = "http://".$server.'/'.$path;
+
+ updateStatus("Laconica has been installed at $link");
+ updateStatus("You can visit your <a href='$link'>new Laconica site</a>.");
?>
<?php
}
-function pgsql_db_installer($host, $database, $username, $password, $sitename, $fancy) {
+function pgsql_db_installer($host, $database, $username, $password) {
$connstring = "dbname=$database host=$host user=$username";
//No password would mean trust authentication used.
@@ -265,7 +289,7 @@ function pgsql_db_installer($host, $database, $username, $password, $sitename, $
if ($res === false) {
updateStatus("Can't run database script.", true);
showForm();
- return;
+ return false;
}
foreach (array('sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
@@ -276,29 +300,24 @@ function pgsql_db_installer($host, $database, $username, $password, $sitename, $
if ($res === false) {
updateStatus(sprintf("Can't run %d script.", $name), true);
showForm();
- return;
+ return false;
}
}
pg_query($conn, 'COMMIT');
- updateStatus("Writing config file...");
if (empty($password)) {
$sqlUrl = "pgsql://$username@$host/$database";
}
else {
$sqlUrl = "pgsql://$username:$password@$host/$database";
}
- $res = writeConf($sitename, $sqlUrl, $fancy, 'pgsql');
- if (!$res) {
- updateStatus("Can't write config file.", true);
- showForm();
- return;
- }
- updateStatus("Done!");
-
+
+ $db = array('type' => 'pgsql', 'database' => $sqlUrl);
+
+ return $db;
}
-function mysql_db_installer($host, $database, $username, $password, $sitename, $fancy) {
+function mysql_db_installer($host, $database, $username, $password) {
updateStatus("Starting installation...");
updateStatus("Checking database...");
@@ -306,21 +325,21 @@ function mysql_db_installer($host, $database, $username, $password, $sitename, $
if (!$conn) {
updateStatus("Can't connect to server '$host' as '$username'.", true);
showForm();
- return;
+ return false;
}
updateStatus("Changing to database...");
$res = mysql_select_db($database, $conn);
if (!$res) {
updateStatus("Can't change to database.", true);
showForm();
- return;
+ return false;
}
updateStatus("Running database script...");
$res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
if ($res === false) {
updateStatus("Can't run database script.", true);
showForm();
- return;
+ return false;
}
foreach (array('sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
@@ -331,35 +350,44 @@ function mysql_db_installer($host, $database, $username, $password, $sitename, $
if ($res === false) {
updateStatus(sprintf("Can't run %d script.", $name), true);
showForm();
- return;
+ return false;
}
}
- updateStatus("Writing config file...");
$sqlUrl = "mysqli://$username:$password@$host/$database";
- $res = writeConf($sitename, $sqlUrl, $fancy);
- if (!$res) {
- updateStatus("Can't write config file.", true);
- showForm();
- return;
- }
- updateStatus("Done!");
- }
-function writeConf($sitename, $sqlUrl, $fancy, $type='mysql')
+ $db = array('type' => 'mysql', 'database' => $sqlUrl);
+ return $db;
+}
+
+function writeConf($sitename, $server, $path, $fancy, $db)
{
- $res = file_put_contents(INSTALLDIR.'/config.php',
- "<?php\n".
- "if (!defined('LACONICA')) { exit(1); }\n\n".
- "\$config['site']['name'] = \"$sitename\";\n\n".
- ($fancy ? "\$config['site']['fancy'] = true;\n\n":'').
- "\$config['db']['database'] = \"$sqlUrl\";\n\n".
- ($type == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n" .
- "\$config['db']['type'] = \"$type\";\n\n" : '').
- "?>");
+ // assemble configuration file in a string
+ $cfg = "<?php\n".
+ "if (!defined('LACONICA')) { exit(1); }\n\n".
+
+ // site name
+ "\$config['site']['name'] = '$sitename';\n\n".
+
+ // site location
+ "\$config['site']['server'] = '$server';\n".
+ "\$config['site']['path'] = '$path'; \n\n".
+
+ // checks if fancy URLs are enabled
+ ($fancy ? "\$config['site']['fancy'] = true;\n\n":'').
+
+ // database
+ "\$config['db']['database'] = '{$db['database']}';\n\n".
+ ($db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n":'').
+ "\$config['db']['type'] = '{$db['type']}';\n\n".
+
+ "?>";
+ // write configuration file out to install directory
+ $res = file_put_contents(INSTALLDIR.'/config.php', $cfg);
+
return $res;
}
-function runDbScript($filename, $conn, $type='mysql')
+function runDbScript($filename, $conn, $type = 'mysql')
{
$sql = trim(file_get_contents($filename));
$stmts = explode(';', $sql);
@@ -368,10 +396,15 @@ function runDbScript($filename, $conn, $type='mysql')
if (!mb_strlen($stmt)) {
continue;
}
- if ($type == 'mysql') {
- $res = mysql_query($stmt, $conn);
- } elseif ($type=='pgsql') {
- $res = pg_query($conn, $stmt);
+ switch ($type) {
+ case 'mysql':
+ $res = mysql_query($stmt, $conn);
+ break;
+ case 'pgsql':
+ $res = pg_query($conn, $stmt);
+ break;
+ default:
+ updateStatus("runDbScript() error: unknown database type ". $type ." provided.");
}
if ($res === false) {
updateStatus("FAILED SQL: $stmt");
@@ -383,9 +416,7 @@ function runDbScript($filename, $conn, $type='mysql')
?>
<?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
-<!DOCTYPE html
-PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<title>Install Laconica</title>