X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=install.php;h=08555d19b9515ea2773a774e3403a0287e74fbdd;hb=f85fc944b7ca3d2faaa7b7451068e37f2c5b68a7;hp=dd814a1b5fbeed9944051d402b8912587486ce3e;hpb=c8b8f07af14ad2ce9d0c0267962dd3bbf6473a4b;p=quix0rs-gnu-social.git diff --git a/install.php b/install.php index dd814a1b5f..08555d19b9 100644 --- a/install.php +++ b/install.php @@ -1,7 +1,7 @@ . + * + * @category Installation + * @package Installation + * + * @author Adrian Lang + * @author Brenda Wallace + * @author Brett Taylor + * @author Brion Vibber + * @author CiaranG + * @author Craig Andrews + * @author Eric Helgeson + * @author Evan Prodromou + * @author Robin Millette + * @author Sarven Capadisli + * @author Tom Adams + * @author Zach Copley + * @license GNU Affero General Public License http://www.gnu.org/licenses/ + * @version 0.9.x + * @link http://status.net */ define('INSTALLDIR', dirname(__FILE__)); -function main() -{ - if (!checkPrereqs()) - { - return; - } +require INSTALLDIR . '/lib/installer.php'; - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - handlePost(); - } else { - showForm(); +/** + * Helper class for building form + */ +class Posted { + function value($name) + { + if (isset($_POST[$name])) { + return htmlspecialchars(strval($_POST[$name])); + } else { + return ''; + } } } -function checkPrereqs() +/** + * Web-based installer: provides a form and such. + */ +class WebInstaller extends Installer { - $pass = true; - - if (file_exists(INSTALLDIR.'/config.php')) { - ?>

Config file "config.php" already exists.

-

Require PHP version 5.2.3 or greater.

Cannot load required extension:

checkPrereqs()) { + $this->showForm(); + return; } - } - if (!checkExtension('pgsql') && !checkExtension('mysql')) { - ?>

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 directory:

-

On your server, try this command: chmod a+w

- handlePost(); + } else { + $this->showForm(); } } - return true; -} - -function showForm() -{ - echo<< - - -
-
Page notice
-
-
-

Enter your database connection information below to initialize the database.

-
-
-
-
-
- Connection settings -
    -
  • - - -

    The name of your site

    -
  • -
  • - - enable
    - disable
    -

    Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.

    -
  • -
  • - - -

    Database hostname

    -
  • -
  • - - - MySQL
    - PostgreSQL
    -

    Database type

    -
  • - -
  • - - -

    Database name

    -
  • -
  • - - -

    Database username

    -
  • -
  • - - -

    Database password (optional)

    -
  • -
- -
-
- -E_O_T; -} - -function updateStatus($status, $error=false) -{ -?> -
  • >
  • - - - - -
    -
    Page notice
    -
    -
      -$message

      \n"; + if ($submessage != '') { + print "

      $submessage

      \n"; + } } - if (empty($database)) { - updateStatus("No database specified.", true); - $fail = true; + /** + * Web implementation of status output + */ + function updateStatus($status, $error=false) + { + echo '$status"; } - if (empty($username)) { - updateStatus("No username specified.", true); - $fail = true; - } + /** + * Show the web form! + */ + function showForm() + { + global $dbModules; + $post = new Posted(); + $dbRadios = ''; + if (isset($_POST['dbtype'])) { + $dbtype = $_POST['dbtype']; + } else { + $dbtype = null; + } + foreach (self::$dbModules as $type => $info) { + if ($this->checkExtension($info['check_module'])) { + if ($dbtype == null || $dbtype == $type) { + $checked = 'checked="checked" '; + $dbtype = $type; // if we didn't have one checked, hit the first + } else { + $checked = ''; + } + $dbRadios .= " $info[name]
      \n"; + } + } -// if (empty($password)) { -// updateStatus("No password specified.", true); -// $fail = true; -// } + echo<< +
      +
      + Site settings +
        +
      • + + +

        The name of your site

        +
      • +
      • + + enable
        + disable
        +

        Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.

        +
      • +
      +
      + +
      + Database settings +
        +
      • + + +

        Database hostname

        +
      • +
      • + + $dbRadios +

        Database type

        +
      • +
      • + + +

        Database name

        +
      • +
      • + + +

        Database username

        +
      • +
      • + + +

        Database password (optional)

        +
      • +
      +
      + +
      + Administrator settings +
        +
      • + + +

        Nickname for the initial StatusNet user (administrator)

        +
      • +
      • + + +

        Password for the initial StatusNet user (administrator)

        +
      • +
      • + + +
      • +
      • + + +

        Optional email address for the initial StatusNet user (administrator)

        +
      • +
      • + + +

        Release and security feed from update@status.net (recommended)

        +
      • +
      +
      + +
      + - if (empty($sitename)) { - updateStatus("No sitename specified.", true); - $fail = true; +E_O_T; } - if($fail){ - showForm(); - return; - } - - switch($dbtype) { - 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; + /** + * Handle a POST submission... if we have valid input, start the install! + * Otherwise shows the form along with any error messages. + */ + function handlePost() + { + echo << +
      Page notice
      +
      +
        +STR; + $this->validated = $this->prepare(); + if ($this->validated) { + $this->doInstall(); + } + echo << +
      +
    +STR; + if (!$this->validated) { + $this->showForm(); + } } - - /* - TODO https needs to be considered - */ - $link = "http://".$server.'/'.$path; - - updateStatus("StatusNet has been installed at $link"); - updateStatus("You can visit your new StatusNet site."); -?> -server_encoding != 'UTF8') { - updateStatus("StatusNet requires UTF8 character encoding. Your database is ". htmlentities($record->server_encoding)); - showForm(); - return false; - } - - updateStatus("Running database script..."); - //wrap in transaction; - pg_query($conn, 'BEGIN'); - $res = runDbScript(INSTALLDIR.'/db/laconica_pg.sql', $conn, 'pgsql'); - - if ($res === false) { - updateStatus("Can't run database script.", true); - showForm(); - return false; - } - 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, 'pgsql'); - if ($res === false) { - updateStatus(sprintf("Can't run %d script.", $name), true); - showForm(); - return false; - } - } - pg_query($conn, 'COMMIT'); - - if (empty($password)) { - $sqlUrl = "pgsql://$username@$host/$database"; - } - else { - $sqlUrl = "pgsql://$username:$password@$host/$database"; - } - - $db = array('type' => 'pgsql', 'database' => $sqlUrl); - - return $db; -} - -function mysql_db_installer($host, $database, $username, $password) { - 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 false; - } - updateStatus("Changing to database..."); - $res = mysql_select_db($database, $conn); - if (!$res) { - updateStatus("Can't change to database.", true); - showForm(); - 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 false; - } - 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 false; - } - } - - $sqlUrl = "mysqli://$username:$password@$host/$database"; - $db = array('type' => 'mysql', 'database' => $sqlUrl); - return $db; -} - -function writeConf($sitename, $server, $path, $fancy, $db) -{ - // assemble configuration file in a string - $cfg = ""; - // write configuration file out to install directory - $res = file_put_contents(INSTALLDIR.'/config.php', $cfg); - - 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; + /** + * Read and validate input data. + * May output side effects. + * + * @return boolean success + */ + function prepare() + { + $this->host = $_POST['host']; + $this->dbtype = $_POST['dbtype']; + $this->database = $_POST['database']; + $this->username = $_POST['dbusername']; + $this->password = $_POST['dbpassword']; + $this->sitename = $_POST['sitename']; + $this->fancy = !empty($_POST['fancy']); + + $this->adminNick = strtolower($_POST['admin_nickname']); + $this->adminPass = $_POST['admin_password']; + $adminPass2 = $_POST['admin_password2']; + $this->adminEmail = $_POST['admin_email']; + $this->adminUpdates = $_POST['admin_updates']; + + $this->server = $_SERVER['HTTP_HOST']; + $this->path = substr(dirname($_SERVER['PHP_SELF']), 1); + + $fail = false; + if (!$this->validateDb()) { + $fail = true; } - 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 (!$this->validateAdmin()) { + $fail = true; } - if ($res === false) { - updateStatus("FAILED SQL: $stmt"); - return $res; + + if ($this->adminPass != $adminPass2) { + $this->updateStatus("Administrator passwords do not match. Did you mistype?", true); + $fail = true; } + + return !$fail; } - return true; + } ?> xml version="1.0" encoding="UTF-8" "; ?> - + Install StatusNet - - - - + + + + @@ -440,8 +308,13 @@ function runDbScript($filename, $conn, $type = 'mysql')
    -

    Install StatusNet

    - +
    +

    Install StatusNet

    +main(); +?> +