.
*/
define('INSTALLDIR', dirname(__FILE__));
function main()
{
if (!checkPrereqs())
{
return;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
handlePost();
} else {
showForm();
}
}
function checkPrereqs()
{
$pass = true;
if (file_exists(INSTALLDIR.'/config.php')) {
?>
Config file "config.php" already exists.
Require PHP version 5 or greater.
Cannot load required extension:
Cannot find mysql or pgsql extension. You need one or the other:
Cannot write config file to:
On your server, try this command: chmod a+w
Cannot write avatar directory: /avatar/
On your server, try this command: chmod a+w /avatar/
$pass = false;
}
if (!is_writable(INSTALLDIR.'/background/')) {
?>Cannot write background directory: /background/
On your server, try this command: chmod a+w /background/
$pass = false;
}
return $pass;
}
function checkExtension($name)
{
if (!extension_loaded($name)) {
if (!dl($name.'.so')) {
return false;
}
}
return true;
}
function showForm()
{
echo<<
- Page notice
-
Enter your database connection information below to initialize the database.
E_O_T;
}
function updateStatus($status, $error=false)
{
?>
>
- Page notice
-
new Laconica site.");
?>
'SMS carrier',
'notice_source' => 'notice source',
'foreign_services' => 'foreign service')
as $scr => $name) {
updateStatus(sprintf("Adding %s data to database...", $name));
$res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn, 'pgsql');
if ($res === false) {
updateStatus(sprintf("Can't run %d script.", $name), true);
showForm();
return;
}
}
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);
if (!$res) {
updateStatus("Can't write config file.", true);
showForm();
return;
}
updateStatus("Done!");
}
function mysql_db_installer($host, $database, $username, $password, $sitename) {
updateStatus("Starting installation...");
updateStatus("Checking database...");
$conn = mysql_connect($host, $username, $password);
if (!$conn) {
updateStatus("Can't connect to server '$host' as '$username'.", true);
showForm();
return;
}
updateStatus("Changing to database...");
$res = mysql_select_db($database, $conn);
if (!$res) {
updateStatus("Can't change to database.", true);
showForm();
return;
}
updateStatus("Running database script...");
$res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
if ($res === false) {
updateStatus("Can't run database script.", true);
showForm();
return;
}
foreach (array('sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
'foreign_services' => 'foreign service')
as $scr => $name) {
updateStatus(sprintf("Adding %s data to database...", $name));
$res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
if ($res === false) {
updateStatus(sprintf("Can't run %d script.", $name), true);
showForm();
return;
}
}
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')
{
$res = file_put_contents(INSTALLDIR.'/config.php',
"");
return $res;
}
function runDbScript($filename, $conn, $type='mysql')
{
$sql = trim(file_get_contents($filename));
$stmts = explode(';', $sql);
foreach ($stmts as $stmt) {
$stmt = trim($stmt);
if (!mb_strlen($stmt)) {
continue;
}
if ($type == 'mysql') {
$res = mysql_query($stmt, $conn);
} elseif ($type=='pgsql') {
$res = pg_query($conn, $stmt);
}
if ($res === false) {
updateStatus("FAILED SQL: $stmt");
return $res;
}
}
return true;
}
?>
xml version="1.0" encoding="UTF-8" "; ?>
Install Laconica