Skip to content
Snippets Groups Projects
Select Git revision
  • 84a8aea410053686678f8efa6ba00ac63d31133e
  • master default protected
2 results

log.php

Blame
  • setup.php 11.97 KiB
    <?php
    
    $hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
    $hasMySQL = is_callable('mysql_connect');
    $hasPostgreSQL = is_callable('pg_connect');
    $datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data');
    $opts = array(
    	'hasSQLite' => $hasSQLite,
    	'hasMySQL' => $hasMySQL,
    	'hasPostgreSQL' => $hasPostgreSQL,
    	'directory' => $datadir,
    	'errors' => array(),
    );
    
    if(isset($_POST['install']) AND $_POST['install']=='true') {
    	// We have to launch the installation process :
    	$e = OC_Setup::install($_POST);
    	$errors = array('errors' => $e);
    	
    	if(count($e) > 0) {
    		//OC_Template::printGuestPage("", "error", array("errors" => $errors));
    		$options = array_merge($_POST, $opts, $errors);
    		OC_Template::printGuestPage("", "installation", $options);
    	}
    	else {
    		header("Location: ".OC::$WEBROOT.'/');
    		exit();
    	}
    }
    else {
    	OC_Template::printGuestPage("", "installation", $opts);
    }
    
    class OC_Setup {
    	public static function install($options) {
    		$error = array();
    		$dbtype = $options['dbtype'];
    		
    		if(empty($options['adminlogin'])) {
    			$error[] = 'Set an admin username.';
    		}
    		if(empty($options['adminpass'])) {
    			$error[] = 'Set an admin password.';
    		}
    		if(empty($options['directory'])) {
    			$error[] = 'Specify a data folder.';
    		}
    
    		if($dbtype=='mysql' or $dbtype=='pgsql') { //mysql and postgresql needs more config options
    			if($dbtype=='mysql')
    				$dbprettyname = 'MySQL';
    			else
    				$dbprettyname = 'PostgreSQL';
    
    			if(empty($options['dbuser'])) {
    				$error[] = "$dbprettyname enter the database username.";
    			}
    			if(empty($options['dbname'])) {
    				$error[] = "$dbprettyname enter the database name.";
    			}
    			if(empty($options['dbhost'])) {
    				$error[] = "$dbprettyname set the database host.";
    			}
    		}
    
    		if(count($error) == 0) { //no errors, good
    			$username = htmlspecialchars_decode($options['adminlogin']);
    			$password = htmlspecialchars_decode($options['adminpass']);
    			$datadir = htmlspecialchars_decode($options['directory']);