moved the config functions to /inc/lib_config.php

remotes/origin/stable
Robin 15 years ago
parent 2aef090ac5
commit 97270d5c63
  1. 111
      inc/lib_base.php
  2. 166
      inc/lib_config.php
  3. 18
      inc/templates/configform.php
  4. 4
      inc/templates/header.php
  5. 6
      settings/index.php

@ -43,7 +43,7 @@ set_include_path(get_include_path().PATH_SEPARATOR.$DOCUMENTROOT.PATH_SEPARATOR.
// define default config values // define default config values
$CONFIG_ADMINLOGIN=''; $CONFIG_ADMINLOGIN='';
$CONFIG_ADMINPASSWORD=''; $CONFIG_ADMINPASSWORD='';
$CONFIG_DATADIRECTORY='/var/data'; $CONFIG_DATADIRECTORY=$SERVERROOT.$WEBROOT.'/data';
$CONFIG_HTTPFORCESSL=false; $CONFIG_HTTPFORCESSL=false;
$CONFIG_DATEFORMAT='j M Y G:i'; $CONFIG_DATEFORMAT='j M Y G:i';
$CONFIG_DBHOST='localhost'; $CONFIG_DBHOST='localhost';
@ -66,6 +66,7 @@ if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){
// load core libs // load core libs
require_once('lib_files.php'); require_once('lib_files.php');
require_once('lib_log.php'); require_once('lib_log.php');
require_once('lib_config.php');
// load plugins // load plugins
$CONFIG_LOADPLUGINS=''; $CONFIG_LOADPLUGINS='';
@ -186,15 +187,15 @@ class OC_UTIL {
global $WEBROOT; global $WEBROOT;
echo('<table cellpadding="5" cellspacing="0" border="0"><tr>'); echo('<table cellpadding="5" cellspacing="0" border="0"><tr>');
echo('<td class="navigationitem1"><a href="'.$WEBROOT.'/">'.$_SESSION['username'].'</a></td>'); echo('<td class="navigationitem1"><a href="'.$WEBROOT.'/">'.$_SESSION['username'].'</a></td>');
if($_SERVER['SCRIPT_NAME']=='/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/">Files</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/">Files</a></td>'); if($_SERVER['SCRIPT_NAME']==$WEBROOT.'/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/">Files</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/">Files</a></td>');
foreach(OC_UTIL::$NAVIGATION as $NAVI) { foreach(OC_UTIL::$NAVIGATION as $NAVI) {
if($_SERVER['SCRIPT_NAME']==$NAVI['url']) echo('<td class="navigationitemselected"><a href="'.$NAVI['url'].'">'.$NAVI['name'].'</a></td>'); else echo('<td class="navigationitem"><a href="'.$NAVI['url'].'">'.$NAVI['name'].'</a></td>'); if($_SERVER['SCRIPT_NAME']==$SERVERROOT.$WEBROOT.$NAVI['url']) echo('<td class="navigationitemselected"><a href="'.$WEBROOT.$NAVI['url'].'">'.$NAVI['name'].'</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.$NAVI['url'].'">'.$NAVI['name'].'</a></td>');
} }
if($_SERVER['SCRIPT_NAME']=='/log/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/log">Log</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/log">Log</a></td>'); if($_SERVER['SCRIPT_NAME']==$WEBROOT.'/log/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/log">Log</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/log">Log</a></td>');
if($_SERVER['SCRIPT_NAME']=='/settings/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/settings">Settings</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/settings">Settings</a></td>'); if($_SERVER['SCRIPT_NAME']==$WEBROOT.'/settings/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/settings">Settings</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/settings">Settings</a></td>');
echo('<td class="navigationitem"><a href="'.$WEBROOT.'?logoutbutton=1">Logout</a></td>'); echo('<td class="navigationitem"><a href="'.$WEBROOT.'/?logoutbutton=1">Logout</a></td>');
echo('</tr></table>'); echo('</tr></table>');
} }
@ -221,74 +222,6 @@ class OC_UTIL {
} }
} }
/**
* show the configform
*
*/
public static function showconfigform(){
global $CONFIG_ADMINLOGIN;
global $CONFIG_ADMINPASSWORD;
global $CONFIG_DATADIRECTORY;
global $CONFIG_HTTPFORCESSL;
global $CONFIG_DATEFORMAT;
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
require('templates/configform.php');
}
/**
* lisen for configuration changes and write it to the file
*
*/
public static function writeconfiglisener(){
global $DOCUMENTROOT;
global $WEBROOT;
if(isset($_POST['set_config'])){
//checkdata
$error='';
if(!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) $error.='admin login not set<br />';
if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])) $error.='admin password not set<br />';
if(!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2'])) $error.='retype admin password not set<br />';
if(!isset($_POST['datadirectory']) or empty($_POST['datadirectory'])) $error.='data directory not set<br />';
if(!isset($_POST['dateformat']) or empty($_POST['dateformat'])) $error.='dteformat not set<br />';
if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set<br />';
if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set<br />';
if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set<br />';
if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])) $error.='database password not set<br />';
if(!isset($_POST['dbpassword2']) or empty($_POST['dbpassword2'])) $error.='retype database password not set<br />';
if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same<br />';
if($_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same<br />';
if(empty($error)) {
//storedata
$config='<?php '."\n";
$config.='$CONFIG_ADMINLOGIN=\''.$_POST['adminlogin']."';\n";
$config.='$CONFIG_ADMINPASSWORD=\''.$_POST['adminpassword']."';\n";
$config.='$CONFIG_DATADIRECTORY=\''.$_POST['datadirectory']."';\n";
if(isset($_POST['forcessl'])) $config.='$CONFIG_HTTPFORCESSL=true'.";\n"; else $config.='$CONFIG_HTTPFORCESSL=false'.";\n";
$config.='$CONFIG_DATEFORMAT=\''.$_POST['dateformat']."';\n";
$config.='$CONFIG_DBHOST=\''.$_POST['dbhost']."';\n";
$config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n";
$config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n";
$config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n";
$config.='?> ';
$filename=$DOCUMENTROOT.'/config/config.php';
file_put_contents($filename,$config);
header("Location: ".$WEBROOT."/");
}
return($error);
}
}
} }
@ -327,6 +260,36 @@ class OC_DB {
return $result; return $result;
} }
/**
* executes multiply queries on the database
*
* @param string $cmd
* @return result-set
*/
static function multiquery($cmd) {
global $DBConnection;
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
if(!isset($DBConnection)) {
$DBConnection = @new mysqli($CONFIG_DBHOST, $CONFIG_DBUSER, $CONFIG_DBPASSWORD,$CONFIG_DBNAME);
if (mysqli_connect_errno()) {
@ob_end_clean();
echo('<b>can not connect to database.</center>');
exit();
}
}
$result = @$DBConnection->multi_query($cmd);
if (!$result) {
$entry='DB Error: "'.$DBConnection->error.'"<br />';
$entry.='Offending command was: '.$cmd.'<br />';
echo($entry);
}
return $result;
}
/** /**
* closing a db connection * closing a db connection
* *

@ -0,0 +1,166 @@
<?php
class OC_CONFIG{
/**
* show the configform
*
*/
public static function showconfigform(){
global $CONFIG_ADMINLOGIN;
global $CONFIG_ADMINPASSWORD;
global $CONFIG_DATADIRECTORY;
global $CONFIG_HTTPFORCESSL;
global $CONFIG_DATEFORMAT;
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
require('templates/configform.php');
}
/**
* lisen for configuration changes and write it to the file
*
*/
public static function writeconfiglisener(){
global $DOCUMENTROOT;
global $WEBROOT;
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
if(isset($_POST['set_config'])){
//checkdata
$error='';
if(!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) $error.='admin login not set<br />';
if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])) $error.='admin password not set<br />';
if(!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2'])) $error.='retype admin password not set<br />';
if(!isset($_POST['datadirectory']) or empty($_POST['datadirectory'])) $error.='data directory not set<br />';
if(!isset($_POST['dateformat']) or empty($_POST['dateformat'])) $error.='dteformat not set<br />';
if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set<br />';
if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set<br />';
if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set<br />';
if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])) $error.='database password not set<br />';
if(!isset($_POST['dbpassword2']) or empty($_POST['dbpassword2'])) $error.='retype database password not set<br />';
if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same<br />';
if($_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same<br />';
if(empty($error)) {
//create/fill database
$CONFIG_DBHOST=$_POST['dbhost'];
$CONFIG_DBNAME=$_POST['dbname'];
$CONFIG_DBUSER=$_POST['dbuser'];
$CONFIG_DBPASSWORD=$_POST['dbpassword'];
if(isset($_POST['createdatabase'])){
self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']);
}
if(isset($_POST['filldb'])){
self::filldatabase();
}
//storedata
$config='<?php '."\n";
$config.='$CONFIG_ADMINLOGIN=\''.$_POST['adminlogin']."';\n";
$config.='$CONFIG_ADMINPASSWORD=\''.$_POST['adminpassword']."';\n";
$config.='$CONFIG_DATADIRECTORY=\''.$_POST['datadirectory']."';\n";
if(isset($_POST['forcessl'])) $config.='$CONFIG_HTTPFORCESSL=true'.";\n"; else $config.='$CONFIG_HTTPFORCESSL=false'.";\n";
$config.='$CONFIG_DATEFORMAT=\''.$_POST['dateformat']."';\n";
$config.='$CONFIG_DBHOST=\''.$_POST['dbhost']."';\n";
$config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n";
$config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n";
$config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n";
$config.='?> ';
$filename=$DOCUMENTROOT.'/config/config.php';
file_put_contents($filename,$config);
header("Location: ".$WEBROOT."/");
}
return($error);
}
}
/**
* Create the database and user
* @param string adminUser
* @param string adminPwd
*
*/
private static function createdatabase($adminUser,$adminPwd){
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
global $CONFIG_DBUSER;
global $CONFIG_DBPWD;
//we cant user OC_BD functions here because we need to connect as the administrative user.
$connection = @new mysqli($CONFIG_DBHOST, $adminUser, $adminPwd);
if (mysqli_connect_errno()) {
@ob_end_clean();
echo('<html><head></head><body bgcolor="#F0F0F0"><br /><br /><center><b>can not connect to database as administrative user.</center></body></html>');
exit();
}
$query="CREATE USER '{$_POST['dbuser']}' IDENTIFIED BY '{$_POST['dbpassword']}';
CREATE DATABASE IF NOT EXISTS `{$_POST['dbname']}` ;
GRANT ALL PRIVILEGES ON `{$_POST['dbname']}` . * TO '{$_POST['dbuser']}';";
$result = @$connection->multi_query($query);
if (!$result) {
$entry='DB Error: "'.$connection->error.'"<br />';
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
$connection->close();
}
/**
* Fills the database with the initial tables
*
*/
private static function filldatabase(){
$query="SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";
CREATE TABLE IF NOT EXISTS `locks` (
`token` varchar(255) NOT NULL DEFAULT '',
`path` varchar(200) NOT NULL DEFAULT '',
`expires` int(11) NOT NULL DEFAULT '0',
`owner` varchar(200) DEFAULT NULL,
`recursive` int(11) DEFAULT '0',
`writelock` int(11) DEFAULT '0',
`exclusivelock` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`token`),
UNIQUE KEY `token` (`token`),
KEY `path` (`path`),
KEY `path_2` (`path`),
KEY `path_3` (`path`,`token`),
KEY `expires` (`expires`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` int(11) NOT NULL,
`user` varchar(250) NOT NULL,
`type` int(11) NOT NULL,
`message` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
CREATE TABLE IF NOT EXISTS `properties` (
`path` varchar(255) NOT NULL DEFAULT '',
`name` varchar(120) NOT NULL DEFAULT '',
`ns` varchar(120) NOT NULL DEFAULT 'DAV:',
`value` text,
PRIMARY KEY (`path`,`name`,`ns`),
KEY `path` (`path`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";
OC_DB::multiquery($query);
}
}
?>

@ -1,3 +1,16 @@
<?php
global $createDB;
global $fillDB;
if(!isset($createDB)) $createDB=true;
if(!isset($fillDB)) $fillDB=true;
?>
<script type="text/javascript">
function showDBAdmin(){
var show=document.getElementById('dbCreate').checked;
document.getElementById('dbAdminUser').style.display=(show)?'table-row':'none';
document.getElementById('dbAdminPwd').style.display=(show)?'table-row':'none';
}
</script>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> <table cellpadding="5" cellspacing="5" border="0" class="loginform">
<tr><td>admin login:</td><td><input type="text" name="adminlogin" size="30" class="formstyle" value="<?php echo($CONFIG_ADMINLOGIN);?>"></input></td></tr> <tr><td>admin login:</td><td><input type="text" name="adminlogin" size="30" class="formstyle" value="<?php echo($CONFIG_ADMINLOGIN);?>"></input></td></tr>
@ -11,5 +24,10 @@
<tr><td>database user:</td><td><input type="text" name="dbuser" size="30" class="formstyle" value='<?php echo($CONFIG_DBUSER);?>'></input></td></tr> <tr><td>database user:</td><td><input type="text" name="dbuser" size="30" class="formstyle" value='<?php echo($CONFIG_DBUSER);?>'></input></td></tr>
<tr><td>database password:</td><td><input type="password" name="dbpassword" size="30" class="formstyle" value='<?php echo($CONFIG_DBPASSWORD);?>'></input></td></tr> <tr><td>database password:</td><td><input type="password" name="dbpassword" size="30" class="formstyle" value='<?php echo($CONFIG_DBPASSWORD);?>'></input></td></tr>
<tr><td>retype database password:</td><td><input type="password" name="dbpassword2" size="30" class="formstyle" value='<?php echo($CONFIG_DBPASSWORD);?>'></input></td></tr> <tr><td>retype database password:</td><td><input type="password" name="dbpassword2" size="30" class="formstyle" value='<?php echo($CONFIG_DBPASSWORD);?>'></input></td></tr>
<tr><td>create database and user:</td><td><input id='dbCreate' type="checkbox" name="createdatabase" size="30" class="formstyle" value='1' <?php if($createDB) echo 'checked'; ?> onchange='showDBAdmin()'></input></td></tr>
<tr id='dbAdminUser'><td>database administrative user:</td><td><input type="text" name="dbadminuser" size="30" class="formstyle" value='root'></input></td></tr>
<tr id='dbAdminPwd'><td>database administrative password:</td><td><input type="password" name="dbadminpwd" size="30" class="formstyle" value=''></input></td></tr>
<tr><td>automaticly fill initial database:</td><td><input type="checkbox" name="filldb" size="30" class="formstyle" value='1' <?php if($fillDB) echo 'checked'; ?>></input></td></tr>
<tr><td></td><td><input type="submit" name="set_config" alt="save" value="save" class="formstyle" /></td></tr> <tr><td></td><td><input type="submit" name="set_config" alt="save" value="save" class="formstyle" /></td></tr>
</table></form> </table></form>
<script type="text/javascript">showDBAdmin()</script>

@ -11,12 +11,12 @@ echo('<h1><a id="owncloud-logo" href="'.$WEBROOT.'/"><span>ownCloud</span></a></
// check if already configured. otherwise start configuration wizard // check if already configured. otherwise start configuration wizard
$error=OC_UTIL::writeconfiglisener(); $error=OC_CONFIG::writeconfiglisener();
if(empty($CONFIG_ADMINLOGIN)) { if(empty($CONFIG_ADMINLOGIN)) {
echo('<div class="center">'); echo('<div class="center">');
echo('<p class="errortext">'.$error.'</p>'); echo('<p class="errortext">'.$error.'</p>');
echo('<p class="highlighttext">First Run Wizard</p>'); echo('<p class="highlighttext">First Run Wizard</p>');
OC_UTIL::showconfigform(); OC_CONFIG::showconfigform();
echo('</div>'); echo('</div>');
OC_UTIL::showfooter(); OC_UTIL::showfooter();
exit(); exit();

@ -26,8 +26,12 @@ require_once('../inc/lib_base.php');
OC_UTIL::showheader(); OC_UTIL::showheader();
//uncheck the create and fill db options on default.
$createDB=false;
$fillDB=false;
echo('<div class="center">'); echo('<div class="center">');
OC_UTIL::showconfigform(); OC_CONFIG::showconfigform();
echo('</div>'); echo('</div>');

Loading…
Cancel
Save