3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2009, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define('INSTALLDIR', dirname(__FILE__));
29 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
36 function checkPrereqs()
38 if (file_exists(INSTALLDIR.'/config.php')) {
39 ?><p class="error">Config file "config.php" already exists.</p>
44 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
45 ?><p class="error">Require PHP version 5 or greater.</p><?php
49 $reqs = array('gd', 'mysql', 'curl',
50 'xmlwriter', 'mbstring',
53 foreach ($reqs as $req) {
54 if (!checkExtension($req)) {
55 ?><p class="error">Cannot load required extension: <code><?php echo $req; ?></code></p><?php
60 if (!is_writable(INSTALLDIR)) {
61 ?><p class="error">Cannot write config file to: <code><?php echo INSTALLDIR; ?></code></p>
62 <p>On your server, try this command: <code>chmod a+w <?php echo INSTALLDIR; ?></code>
67 if (!is_writable(INSTALLDIR.'/avatar/')) {
68 ?><p class="error">Cannot write avatar directory: <code><?php echo INSTALLDIR; ?>/avatar/</code></p>
69 <p>On your server, try this command: <code>chmod a+w <?php echo INSTALLDIR; ?>/avatar/</code></p>
77 function checkExtension($name)
79 if (!extension_loaded($name)) {
80 if (!dl($name.'.so')) {
93 <dl id="page_notice" class="system_notice">
96 <div class="instructions">
97 <p>Enter your database connection information below to initialize the database.</p>
101 <form method="post" action="install.php" class="form_settings" id="form_install">
103 <legend>Connection settings</legend>
104 <ul class="form_data">
106 <label for="sitename">Site name</label>
107 <input type="text" id="sitename" name="sitename" />
108 <p class="form_guide">The name of your site</p>
112 <label for="host">Hostname</label>
113 <input type="text" id="host" name="host" />
114 <p class="form_guide">Database hostname</p>
117 <label for="host">Database</label>
118 <input type="text" id="database" name="database" />
119 <p class="form_guide">Database name</p>
122 <label for="username">Username</label>
123 <input type="text" id="username" name="username" />
124 <p class="form_guide">Database username</p>
127 <label for="password">Password</label>
128 <input type="password" id="password" name="password" />
129 <p class="form_guide">Database password</p>
132 <input type="submit" name="submit" class="submit" value="Submit" />
138 function updateStatus($status, $error=false)
141 <li <?php echo ($error) ? 'class="error"': ''; ?>><?print $status;?></li>
146 function handlePost()
151 $host = $_POST['host'];
152 $database = $_POST['database'];
153 $username = $_POST['username'];
154 $password = $_POST['password'];
155 $sitename = $_POST['sitename'];
157 <dl class="system_notice">
163 updateStatus("No hostname specified.", true);
168 if (empty($database)) {
169 updateStatus("No database specified.", true);
174 if (empty($username)) {
175 updateStatus("No username specified.", true);
180 if (empty($password)) {
181 updateStatus("No password specified.", true);
186 if (empty($sitename)) {
187 updateStatus("No sitename specified.", true);
192 updateStatus("Starting installation...");
193 updateStatus("Checking database...");
194 $conn = mysql_connect($host, $username, $password);
196 updateStatus("Can't connect to server '$host' as '$username'.", true);
200 updateStatus("Changing to database...");
201 $res = mysql_select_db($database, $conn);
203 updateStatus("Can't change to database.", true);
207 updateStatus("Running database script...");
208 $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
209 if ($res === false) {
210 updateStatus("Can't run database script.", true);
214 foreach (array('sms_carrier' => 'SMS carrier',
215 'notice_source' => 'notice source',
216 'foreign_services' => 'foreign service')
218 updateStatus(sprintf("Adding %s data to database...", $name));
219 $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
220 if ($res === false) {
221 updateStatus(sprintf("Can't run %d script.", $name), true);
226 updateStatus("Writing config file...");
227 $sqlUrl = "mysqli://$username:$password@$host/$database";
228 $res = writeConf($sitename, $sqlUrl);
230 updateStatus("Can't write config file.", true);
234 updateStatus("Done!");
240 function writeConf($sitename, $sqlUrl)
242 $res = file_put_contents(INSTALLDIR.'/config.php',
244 "\$config['site']['name'] = \"$sitename\";\n\n".
245 "\$config['db']['database'] = \"$sqlUrl\";\n\n");
249 function runDbScript($filename, $conn)
251 $sql = trim(file_get_contents($filename));
252 $stmts = explode(';', $sql);
253 foreach ($stmts as $stmt) {
255 if (!mb_strlen($stmt)) {
258 $res = mysql_query($stmt, $conn);
259 if ($res === false) {
267 <?php echo"<?"; ?> xml version="1.0" encoding="UTF-8" <?php echo "?>"; ?>
269 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
270 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
271 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
273 <title>Install Laconica</title>
274 <link rel="stylesheet" type="text/css" href="theme/base/css/display.css?version=0.8" media="screen, projection, tv"/>
275 <link rel="stylesheet" type="text/css" href="theme/default/css/display.css?version=0.8" media="screen, projection, tv"/>
276 <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/base/css/ie.css?version=0.8" /><![endif]-->
277 <!--[if lte IE 6]><link rel="stylesheet" type="text/css" theme/base/css/ie6.css?version=0.8" /><![endif]-->
278 <!--[if IE]><link rel="stylesheet" type="text/css" href="theme/earthy/css/ie.css?version=0.8" /><![endif]-->
283 <address id="site_contact" class="vcard">
284 <a class="url home bookmark" href=".">
285 <img class="logo photo" src="theme/default/logo.png" alt="Laconica"/>
286 <span class="fn org">Laconica</span>
292 <h1>Install Laconica</h1>