]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - install.php
OStatus: garbage collect unused PuSH subscriptions when the last local subscriber...
[quix0rs-gnu-social.git] / install.php
index 6e7e833a303a96c1a876f2df24fbeae1116c8d6c..435f6d63bf4ffe22f43045568b22cadc92ec0039 100644 (file)
@@ -1,5 +1,6 @@
+
 <?php
-/** 
+/**
  * StatusNet - the distributed open-source microblogging tool
  * Copyright (C) 2009, StatusNet, Inc.
  *
  *
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- * 
+ *
  * @category Installation
  * @package  Installation
+ *
+ * @author   Adrian Lang <mail@adrianlang.de>
+ * @author   Brenda Wallace <shiny@cpan.org>
+ * @author   Brett Taylor <brett@webfroot.co.nz>
+ * @author   Brion Vibber <brion@pobox.com>
+ * @author   CiaranG <ciaran@ciarang.com>
+ * @author   Craig Andrews <candrews@integralblue.com>
+ * @author   Eric Helgeson <helfire@Erics-MBP.local>
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@controlyourself.ca>
+ * @author   Sarven Capadisli <csarven@status.net>
+ * @author   Tom Adams <tom@holizz.com>
  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
- * 
+ * @version  0.9.x
+ * @link     http://status.net
  */
-
 
 define('INSTALLDIR', dirname(__FILE__));
 
@@ -81,6 +93,13 @@ $external_libraries=array(
         'include'=>'HTTP/Request.php',
         'check_class'=>'HTTP_Request'
     ),
+    array(
+        'name'=>'HTTP_Request2',
+        'pear'=>'HTTP_Request2',
+        'url'=>'http://pear.php.net/package/HTTP_Request2',
+        'include'=>'HTTP/Request2.php',
+        'check_class'=>'HTTP_Request2'
+    ),
     array(
         'name'=>'Mail',
         'pear'=>'Mail',
@@ -111,6 +130,14 @@ $external_libraries=array(
         'include'=>'Net/URL/Mapper.php',
         'check_class'=>'Net_URL_Mapper'
     ),
+    array(
+        'name'=>'Net_LDAP2',
+        'pear'=>'Net_LDAP2',
+        'url'=>'http://pear.php.net/package/Net_LDAP2',
+        'deb'=>'php-net-ldap2',
+        'include'=>'Net/LDAP2.php',
+        'check_class'=>'Net_LDAP2'
+    ),
     array(
         'name'=>'Net_Socket',
         'pear'=>'Net_Socket',
@@ -201,10 +228,10 @@ $dbModules = array(
     ),
 );
 
-/** 
+/**
  * the actual installation.
  * If call libraries are present, then install
- * 
+ *
  * @return void
  */
 function main()
@@ -212,8 +239,8 @@ function main()
     if (!checkPrereqs()) {
         return;
     }
-    
-    if ($_GET['checklibs']) {
+
+    if (!empty($_GET['checklibs'])) {
         showLibs();
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -233,7 +260,7 @@ function main()
  */
 function haveExternalLibrary($external_library)
 {
-    if (isset($external_library['include']) && ! include_once $external_library['include'] ) {
+    if (isset($external_library['include']) && !haveIncludeFile($external_library['include'])) {
         return false;
     }
     if (isset($external_library['check_function']) && ! function_exists($external_library['check_function'])) {
@@ -245,6 +272,15 @@ function haveExternalLibrary($external_library)
     return true;
 }
 
+// Attempt to include a PHP file and report if it worked, while
+// suppressing the annoying warning messages on failure.
+function haveIncludeFile($filename) {
+    $old = error_reporting(error_reporting() & ~E_WARNING);
+    $ok = include_once($filename);
+    error_reporting($old);
+    return $ok;
+}
+
 /**
  * Check if all is ready for installation
  *
@@ -265,14 +301,14 @@ function checkPrereqs()
     }
 
     $reqs = array('gd', 'curl',
-                  'xmlwriter', 'mbstring','tidy');
+                  'xmlwriter', 'mbstring', 'xml', 'dom', 'simplexml');
 
     foreach ($reqs as $req) {
         if (!checkExtension($req)) {
             printf('<p class="error">Cannot load required extension: <code>%s</code></p>', $req);
             $pass = false;
         }
-    }    
+    }
     // Make sure we have at least one database module available
     global $dbModules;
     $missingExtensions = array();
@@ -281,12 +317,13 @@ function checkPrereqs()
             $missingExtensions[] = $info['check_module'];
         }
     }
+
     if (count($missingExtensions) == count($dbModules)) {
         $req = implode(', ', $missingExtensions);
-        printf('<p class="error">Cannot find mysql or pgsql extension. You need one or the other: <code>%s</code></p>', $req);
+        printf('<p class="error">Cannot find mysql or pgsql extension. You need one or the other.');
         $pass = false;
     }
-    
+
     if (!is_writable(INSTALLDIR)) {
         printf('<p class="error">Cannot write config file to: <code>%s</code></p>', INSTALLDIR);
         printf('<p>On your server, try this command: <code>chmod a+w %s</code>', INSTALLDIR);
@@ -316,12 +353,19 @@ function checkPrereqs()
  */
 function checkExtension($name)
 {
-    if (!extension_loaded($name)) {
-        if (!@dl($name.'.so')) {
-            return false;
+    if (extension_loaded($name)) {
+        return true;
+    } elseif (function_exists('dl') && ini_get('enable_dl') && !ini_get('safe_mode')) {
+        // dl will throw a fatal error if it's disabled or we're in safe mode.
+        // More fun, it may not even exist under some SAPIs in 5.3.0 or later...
+        $soname = $name . '.' . PHP_SHLIB_SUFFIX;
+        if (PHP_SHLIB_SUFFIX == 'dll') {
+            $soname = "php_" . $soname;
         }
+        return @dl($soname);
+    } else {
+        return false;
     }
-    return true;
 }
 
 /**
@@ -343,7 +387,7 @@ function showLibs()
     }
     echo<<<E_O_T
     <div class="instructions">
-        <p>Laconica comes bundled with a number of libraries required for the application to work. However, it is best that you use PEAR or you distribution to manage
+        <p>StatusNet comes bundled with a number of libraries required for the application to work. However, it is best that you use PEAR or you distribution to manage
         libraries instead, as they tend to provide security updates faster, and may offer improved performance.</p>
         <p>On Debian based distributions, such as Ubuntu, use a package manager (such as &quot;aptitude&quot;, &quot;apt-get&quot;, and &quot;synaptic&quot;) to install the package listed.</p>
         <p>On RPM based distributions, such as Red Hat, Fedora, CentOS, Scientific Linux, Yellow Dog Linux and Oracle Enterprise Linux, use a package manager (such as &quot;yum&quot;, &quot;apt-rpm&quot;, and &quot;up2date&quot;) to install the package listed.</p>
@@ -354,19 +398,19 @@ function showLibs()
 E_O_T;
     foreach ($absent_libraries as $library) {
         echo '<li>';
-        if ($library['url']) {
-            echo '<a href=">'.$library['url'].'">'.htmlentities($library['name']).'</a>';
+        if (isset($library['url'])) {
+            echo '<a href="'.$library['url'].'">'.htmlentities($library['name']).'</a>';
         } else {
             echo htmlentities($library['name']);
         }
         echo '<ul>';
-        if ($library['deb']) {
+        if (isset($library['deb'])) {
             echo '<li class="deb package">deb: <a href="apt:' . urlencode($library['deb']) . '">' . htmlentities($library['deb']) . '</a></li>';
         }
-        if ($library['rpm']) {
+        if (isset($library['rpm'])) {
             echo '<li class="rpm package">rpm: ' . htmlentities($library['rpm']) . '</li>';
         }
-        if ($library['pear']) {
+        if (isset($library['pear'])) {
             echo '<li class="pear package">pear: ' . htmlentities($library['pear']) . '</li>';
         }
         echo '</ul>';
@@ -378,8 +422,8 @@ E_O_T;
 E_O_T;
     foreach ($present_libraries as $library) {
         echo '<li>';
-        if ($library['url']) {
-            echo '<a href=">'.$library['url'].'">'.htmlentities($library['name']).'</a>';
+        if (isset($library['url'])) {
+            echo '<a href="'.$library['url'].'">'.htmlentities($library['name']).'</a>';
         } else {
             echo htmlentities($library['name']);
         }
@@ -410,7 +454,6 @@ function showForm()
     <dd>
         <div class="instructions">
             <p>Enter your database connection information below to initialize the database.</p>
-            <p>Laconica bundles a number of libraries for ease of installation. <a href="?checklibs=true">You can see what bundled libraries you are using, versus what libraries are installed on your server.</a>
         </div>
     </dd>
 </dl>
@@ -466,8 +509,7 @@ E_O_T;
 
 function updateStatus($status, $error=false)
 {
-    echo '<li ' . ($error) ? 'class="error"': '';
-    echo ">$status</li>";
+    echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
 }
 
 function handlePost()
@@ -516,8 +558,7 @@ STR;
     }
 
     global $dbModules;
-    $db = call_user_func($dbModules[$dbtype]['installer'],
-        $host, $database, $username, $password);
+    $db = call_user_func($dbModules[$dbtype]['installer'], $host, $database, $username, $password);
 
     if (!$db) {
         // database connection failed, do not move on to create config file.
@@ -540,12 +581,10 @@ STR;
 
     updateStatus("StatusNet has been installed at $link");
     updateStatus("You can visit your <a href='$link'>new StatusNet site</a>.");
-?>
-
-<?php
 }
 
-function pgsql_db_installer($host, $database, $username, $password) {
+function Pgsql_Db_installer($host, $database, $username, $password)
+{
     $connstring = "dbname=$database host=$host user=$username";
 
     //No password would mean trust authentication used.
@@ -605,7 +644,8 @@ function pgsql_db_installer($host, $database, $username, $password) {
     return $db;
 }
 
-function mysql_db_installer($host, $database, $username, $password) {
+function Mysql_Db_installer($host, $database, $username, $password)
+{
     updateStatus("Starting installation...");
     updateStatus("Checking database...");
 
@@ -666,9 +706,7 @@ function writeConf($sitename, $server, $path, $fancy, $db)
             // 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".
-
-            "?>";
+            "\$config['db']['type'] = '{$db['type']}';\n\n";
     // write configuration file out to install directory
     $res = file_put_contents(INSTALLDIR.'/config.php', $cfg);
 
@@ -678,12 +716,13 @@ function writeConf($sitename, $server, $path, $fancy, $db)
 /**
  * Install schema into the database
  *
- * @param filename $filename    location of database schema file
- * @param conn $conn            connection to database
- * @param type $type type of database, currently mysql or pgsql
+ * @param string $filename location of database schema file
+ * @param dbconn $conn     connection to database
+ * @param string $type     type of database, currently mysql or pgsql
+ *
  * @return boolean - indicating success or failure
  */
-function runDbScript($filename, $conn, $type = 'mysql')
+function runDbScript($filename, $conn, $type = 'mysqli')
 {
     $sql = trim(file_get_contents($filename));
     $stmts = explode(';', $sql);
@@ -694,7 +733,7 @@ function runDbScript($filename, $conn, $type = 'mysql')
         }
         // FIXME: use PEAR::DB or PDO instead of our own switch
         switch ($type) {
-        case 'mysql':
+        case 'mysqli':
             $res = mysql_query($stmt, $conn);
             if ($res === false) {
                 $error = mysql_error();