<?php | |||||
/** | |||||
* ownCloud | |||||
* | |||||
* @author Frank Karlitschek | |||||
* @copyright 2010 Frank Karlitschek karlitschek@kde.org | |||||
* | |||||
* This library is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | |||||
* License as published by the Free Software Foundation; either | |||||
* version 3 of the License, or any later version. | |||||
* | |||||
* This library is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | |||||
* | |||||
* You should have received a copy of the GNU Lesser General Public | |||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||||
* | |||||
*/ | |||||
$CONFIG_ERROR=''; | |||||
require_once('../inc/lib_base.php'); | |||||
OC_UTIL::showheader(); | |||||
$FIRSTRUN=false; | |||||
echo('<div class="center">'); | |||||
OC_CONFIG::showadminform(); | |||||
echo('</div>'); | |||||
OC_UTIL::showfooter(); | |||||
?> | |||||
} | } | ||||
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']==$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']==$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>'); | |||||
if(OC_USER::ingroup($_SESSION['username'],'admin')){ | if(OC_USER::ingroup($_SESSION['username'],'admin')){ | ||||
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>'); | |||||
if($_SERVER['SCRIPT_NAME']==$WEBROOT.'/admin/index.php') echo('<td class="navigationitemselected"><a href="'.$WEBROOT.'/admin">Admin Panel</a></td>'); else echo('<td class="navigationitem"><a href="'.$WEBROOT.'/admin">Admin Panel</a></td>'); | |||||
} | } | ||||
echo('<td class="navigationitem"><a href="?logoutbutton=1">Logout</a></td>'); | echo('<td class="navigationitem"><a href="?logoutbutton=1">Logout</a></td>'); | ||||
echo('</tr></table>'); | echo('</tr></table>'); |
global $CONFIG_DBNAME; | global $CONFIG_DBNAME; | ||||
require('templates/configform.php'); | require('templates/configform.php'); | ||||
} | } | ||||
public static function createuserlisener(){ | |||||
if(isset($_POST['new_username']) and isset($_POST['new_password'])){ | |||||
if(OC_USER::createuser($_POST['new_username'],$_POST['new_password'])){ | |||||
return 'user successfully created'; | |||||
}else{ | |||||
return 'error while trying to create user'; | |||||
} | |||||
}else{ | |||||
return false; | |||||
} | |||||
} | |||||
/** | /** | ||||
* lisen for configuration changes and write it to the file | |||||
* show the configform | |||||
* | * | ||||
*/ | */ | ||||
public static function writeconfiglisener(){ | |||||
global $DOCUMENTROOT; | |||||
global $SERVERROOT; | |||||
global $WEBROOT; | |||||
global $CONFIG_DBHOST; | |||||
global $CONFIG_DBNAME; | |||||
global $CONFIG_DBUSER; | |||||
global $CONFIG_DBPASSWORD; | |||||
global $CONFIG_DBTYPE; | |||||
public static function showadminform(){ | |||||
global $CONFIG_ADMINLOGIN; | global $CONFIG_ADMINLOGIN; | ||||
global $CONFIG_ADMINPASSWORD; | global $CONFIG_ADMINPASSWORD; | ||||
if(isset($_POST['set_config'])){ | |||||
global $CONFIG_DATADIRECTORY; | |||||
global $CONFIG_HTTPFORCESSL; | |||||
global $CONFIG_DATEFORMAT; | |||||
global $CONFIG_DBNAME; | |||||
global $CONFIG_INSTALLED; | |||||
if(OC_USER::ingroup($_SESSION['username'],'admin') or $CONFIG_INSTALLED==false){ | |||||
require('templates/adminform.php'); | |||||
} | |||||
} | |||||
//checkdata | |||||
$error=''; | |||||
$FIRSTRUN=empty($CONFIG_ADMINLOGIN); | |||||
if(!$FIRSTRUN){ | |||||
if($_POST['currentpassword']!=$CONFIG_ADMINPASSWORD){ | |||||
$error.='wrong password<br />'; | |||||
public static function createuserlisener(){ | |||||
if(OC_USER::ingroup($_SESSION['username'],'admin')){ | |||||
if(isset($_POST['new_username']) and isset($_POST['new_password'])){ | |||||
if(OC_USER::createuser($_POST['new_username'],$_POST['new_password'])){ | |||||
return 'user successfully created'; | |||||
}else{ | |||||
return 'error while trying to create user'; | |||||
} | |||||
}else{ | |||||
return false; | |||||
} | } | ||||
}else{ | |||||
return false; | |||||
} | } | ||||
if(!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) $error.='admin login not set<br />'; | |||||
if((!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])) and $FIRSTRUN) $error.='admin password not set<br />'; | |||||
if((!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2'])) and $FIRSTRUN) $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.='dateformat not set<br />'; | |||||
if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set<br />'; | |||||
if($_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same<br />'; | |||||
$dbtype=$_POST['dbtype']; | |||||
if($dbtype=='mysql'){ | |||||
if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set<br />'; | |||||
if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set<br />'; | |||||
if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same<br />'; | |||||
} | |||||
if(!$FIRSTRUN){ | |||||
if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])){ | |||||
$_POST['adminpassword']=$CONFIG_ADMINPASSWORD; | |||||
} | |||||
if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])){ | |||||
$_POST['dbpassword']=$CONFIG_DBPASSWORD; | |||||
} | |||||
public static function creategrouplisener(){ | |||||
if(OC_USER::isLoggedIn()){ | |||||
if(isset($_POST['creategroup']) and $_POST['creategroup']==1){ | |||||
if(OC_USER::creategroup($_POST['groupname'])){ | |||||
if(OC_USER::addtogroup($_SESSION['username'],$_POST['groupname'])){ | |||||
return 'group successfully created'; | |||||
}else{ | |||||
return 'error while trying to add user to the new created group'; | |||||
} | |||||
}else{ | |||||
return 'error while trying to create group'; | |||||
} | |||||
}else{ | |||||
return false; | |||||
} | } | ||||
}else{ | |||||
return false; | |||||
} | } | ||||
if(!is_dir($_POST['datadirectory'])){ | |||||
try{ | |||||
mkdir($_POST['datadirectory']); | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to create data directory<br/>'; | |||||
} | |||||
/** | |||||
* lisen for configuration changes | |||||
* | |||||
*/ | |||||
public static function configlisener(){ | |||||
if(OC_USER::isLoggedIn()){ | |||||
if(isset($_POST['config']) and $_POST['config']==1){ | |||||
$error=''; | |||||
if(!OC_USER::checkpassword($_SESSION['username'],$_POST['currentpassword'])){ | |||||
$error.='wrong password<br />'; | |||||
}else{ | |||||
if(isset($_POST['changepass']) and $_POST['changepass']==1){ | |||||
if(!isset($_POST['password']) or empty($_POST['password'])) $error.='password not set<br />'; | |||||
if(!isset($_POST['password2']) or empty($_POST['password2'])) $error.='retype password not set<br />'; | |||||
if($_POST['password']<>$_POST['password2'] ) $error.='passwords are not the same<br />'; | |||||
if(empty($error)){ | |||||
if(!OC_USER::setpassword($_SESSION['username'],$_POST['password'])){ | |||||
$error.='error while trying to set password<br />'; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return $error; | |||||
}else{ | |||||
return false; | |||||
} | } | ||||
}else{ | |||||
return false; | |||||
} | } | ||||
if(empty($error)) { | |||||
//create/fill database | |||||
$CONFIG_DBTYPE=$dbtype; | |||||
$CONFIG_DBNAME=$_POST['dbname']; | |||||
if($dbtype=='mysql'){ | |||||
$CONFIG_DBHOST=$_POST['dbhost']; | |||||
$CONFIG_DBUSER=$_POST['dbuser']; | |||||
$CONFIG_DBPASSWORD=$_POST['dbpassword']; | |||||
} | |||||
try{ | |||||
if(isset($_POST['createdatabase']) and $CONFIG_DBTYPE=='mysql'){ | |||||
self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']); | |||||
} | |||||
/** | |||||
* lisen for admin configuration changes and write it to the file | |||||
*4bd0be1185e76 | |||||
*/ | |||||
public static function writeadminlisener(){ | |||||
global $CONFIG_INSTALLED; | |||||
if(OC_USER::ingroup($_SESSION['username'],'admin') or $CONFIG_INSTALLED==false){ | |||||
global $DOCUMENTROOT; | |||||
global $SERVERROOT; | |||||
global $WEBROOT; | |||||
global $CONFIG_DBHOST; | |||||
global $CONFIG_DBNAME; | |||||
global $CONFIG_DBUSER; | |||||
global $CONFIG_DBPASSWORD; | |||||
global $CONFIG_DBTYPE; | |||||
global $CONFIG_ADMINLOGIN; | |||||
global $CONFIG_ADMINPASSWORD; | |||||
if(isset($_POST['set_config'])){ | |||||
//checkdata | |||||
$error=''; | |||||
$FIRSTRUN=empty($CONFIG_ADMINLOGIN); | |||||
if(!$FIRSTRUN){ | |||||
if($_POST['currentpassword']!=$CONFIG_ADMINPASSWORD){ | |||||
$error.='wrong password<br />'; | |||||
} | |||||
} | } | ||||
}catch(Exception $e){ | |||||
$error.='error while trying to create the database<br/>'; | |||||
} | |||||
if($CONFIG_DBTYPE=='sqlite'){ | |||||
$f=@fopen($SERVERROOT.'/'.$CONFIG_DBNAME,'a+'); | |||||
if(!$f){ | |||||
$error.='path of sqlite database not writable by server<br/>'; | |||||
if(!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) $error.='admin login not set<br />'; | |||||
if((!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])) and $FIRSTRUN) $error.='admin password not set<br />'; | |||||
if((!isset($_POST['adminpassword2']) or empty($_POST['adminpassword2'])) and $FIRSTRUN) $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.='dateformat not set<br />'; | |||||
if(!isset($_POST['dbname']) or empty($_POST['dbname'])) $error.='databasename not set<br />'; | |||||
if($_POST['adminpassword']<>$_POST['adminpassword2'] ) $error.='admin passwords are not the same<br />'; | |||||
$dbtype=$_POST['dbtype']; | |||||
if($dbtype=='mysql'){ | |||||
if(!isset($_POST['dbhost']) or empty($_POST['dbhost'])) $error.='database host not set<br />'; | |||||
if(!isset($_POST['dbuser']) or empty($_POST['dbuser'])) $error.='database user not set<br />'; | |||||
if($_POST['dbpassword']<>$_POST['dbpassword2'] ) $error.='database passwords are not the same<br />'; | |||||
} | } | ||||
} | |||||
try{ | |||||
if(isset($_POST['filldb'])){ | |||||
self::filldatabase(); | |||||
if(!$FIRSTRUN){ | |||||
if(!isset($_POST['adminpassword']) or empty($_POST['adminpassword'])){ | |||||
$_POST['adminpassword']=$CONFIG_ADMINPASSWORD; | |||||
} | |||||
if(!isset($_POST['dbpassword']) or empty($_POST['dbpassword'])){ | |||||
$_POST['dbpassword']=$CONFIG_DBPASSWORD; | |||||
} | |||||
} | } | ||||
}catch(Exception $e){ | |||||
$error.='error while trying to fill the database<br/>'; | |||||
} | |||||
if(!OC_USER::createuser($_POST['adminlogin'],$_POST['adminpassword']) && !OC_USER::login($_POST['adminlogin'],$_POST['adminpassword'])){ | |||||
$error.='error while trying to create the admin user<br/>'; | |||||
} | |||||
if(OC_USER::getgroupid('admin')==0){ | |||||
if(!OC_USER::creategroup('admin')){ | |||||
$error.='error while trying to create the admin group<br/>'; | |||||
if(!is_dir($_POST['datadirectory'])){ | |||||
try{ | |||||
mkdir($_POST['datadirectory']); | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to create data directory<br/>'; | |||||
} | |||||
} | } | ||||
} | |||||
if(!OC_USER::addtogroup($_POST['adminlogin'],'admin')){ | |||||
$error.='error while trying to add the admin user to the admin group<br/>'; | |||||
} | |||||
//storedata | |||||
$config='<?php '."\n"; | |||||
// $config.='$CONFIG_ADMINLOGIN=\''.$_POST['adminlogin']."';\n"; | |||||
// $config.='$CONFIG_ADMINPASSWORD=\''.$_POST['adminpassword']."';\n"; | |||||
$config.='$CONFIG_INSTALLED=true;'."\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_DBTYPE=\''.$dbtype."';\n"; | |||||
$config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n"; | |||||
if($dbtype=='mysql'){ | |||||
$config.='$CONFIG_DBHOST=\''.$_POST['dbhost']."';\n"; | |||||
$config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n"; | |||||
$config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n"; | |||||
} | |||||
$config.='?> '; | |||||
if(empty($error)) { | |||||
//create/fill database | |||||
$CONFIG_DBTYPE=$dbtype; | |||||
$CONFIG_DBNAME=$_POST['dbname']; | |||||
if($dbtype=='mysql'){ | |||||
$CONFIG_DBHOST=$_POST['dbhost']; | |||||
$CONFIG_DBUSER=$_POST['dbuser']; | |||||
$CONFIG_DBPASSWORD=$_POST['dbpassword']; | |||||
} | |||||
try{ | |||||
if(isset($_POST['createdatabase']) and $CONFIG_DBTYPE=='mysql'){ | |||||
self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']); | |||||
} | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to create the database<br/>'; | |||||
} | |||||
if($CONFIG_DBTYPE=='sqlite'){ | |||||
$f=@fopen($SERVERROOT.'/'.$CONFIG_DBNAME,'a+'); | |||||
if(!$f){ | |||||
$error.='path of sqlite database not writable by server<br/>'; | |||||
} | |||||
} | |||||
try{ | |||||
if(isset($_POST['filldb'])){ | |||||
self::filldatabase(); | |||||
} | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to fill the database<br/>'; | |||||
} | |||||
if(!OC_USER::createuser($_POST['adminlogin'],$_POST['adminpassword']) && !OC_USER::login($_POST['adminlogin'],$_POST['adminpassword'])){ | |||||
$error.='error while trying to create the admin user<br/>'; | |||||
} | |||||
if(OC_USER::getgroupid('admin')==0){ | |||||
if(!OC_USER::creategroup('admin')){ | |||||
$error.='error while trying to create the admin group<br/>'; | |||||
} | |||||
} | |||||
if(!OC_USER::addtogroup($_POST['adminlogin'],'admin')){ | |||||
$error.='error while trying to add the admin user to the admin group<br/>'; | |||||
} | |||||
//storedata | |||||
$config='<?php '."\n"; | |||||
// $config.='$CONFIG_ADMINLOGIN=\''.$_POST['adminlogin']."';\n"; | |||||
// $config.='$CONFIG_ADMINPASSWORD=\''.$_POST['adminpassword']."';\n"; | |||||
$config.='$CONFIG_INSTALLED=true;'."\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_DBTYPE=\''.$dbtype."';\n"; | |||||
$config.='$CONFIG_DBNAME=\''.$_POST['dbname']."';\n"; | |||||
if($dbtype=='mysql'){ | |||||
$config.='$CONFIG_DBHOST=\''.$_POST['dbhost']."';\n"; | |||||
$config.='$CONFIG_DBUSER=\''.$_POST['dbuser']."';\n"; | |||||
$config.='$CONFIG_DBPASSWORD=\''.$_POST['dbpassword']."';\n"; | |||||
} | |||||
$config.='?> '; | |||||
$filename=$SERVERROOT.'/config/config.php'; | |||||
if(empty($error)){ | |||||
header("Location: ".$WEBROOT."/"); | |||||
try{ | |||||
file_put_contents($filename,$config); | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to save the configuration file<br/>'; | |||||
return $error; | |||||
} | |||||
}else{ | |||||
return $error; | |||||
} | |||||
$filename=$SERVERROOT.'/config/config.php'; | |||||
if(empty($error)){ | |||||
header("Location: ".$WEBROOT."/"); | |||||
try{ | |||||
file_put_contents($filename,$config); | |||||
}catch(Exception $e){ | |||||
$error.='error while trying to save the configuration file<br/>'; | |||||
return $error; | |||||
} | } | ||||
}else{ | |||||
return $error; | |||||
} | |||||
return($error); | |||||
} | |||||
} | } | ||||
return($error); | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Fills the database with the initial tables | * Fills the database with the initial tables |
} | } | ||||
} | } | ||||
/** | |||||
* get the name of a group | |||||
* | |||||
*/ | |||||
public static function getgroupname($groupid){ | |||||
$groupid=(integer)$groupid; | |||||
$query="SELECT group_name FROM `groups` WHERE `group_id` = '$groupid' LIMIT 1"; | |||||
$result=OC_DB::select($query); | |||||
if(isset($result[0]) && isset($result[0]['group_name'])){ | |||||
return $result[0]['group_name']; | |||||
}else{ | |||||
return 0; | |||||
} | |||||
} | |||||
/** | /** | ||||
* check if a user belongs to a group | * check if a user belongs to a group | ||||
* | * | ||||
public static function generatepassword(){ | public static function generatepassword(){ | ||||
return uniqid(); | return uniqid(); | ||||
} | } | ||||
/** | |||||
* get all groups the user belongs to | |||||
* | |||||
*/ | |||||
public static function getusergroups($username){ | |||||
$userid=OC_USER::getuserid($username); | |||||
$query="SELECT group_id FROM `user_group` WHERE `user_id` = '$userid'"; | |||||
$result=OC_DB::select($query); | |||||
$groups=array(); | |||||
if(is_array($result)){ | |||||
foreach($result as $group){ | |||||
$groupid=$group['group_id']; | |||||
$groups[]=OC_USER::getgroupname($groupid); | |||||
} | |||||
} | |||||
return $groups; | |||||
} | |||||
/** | |||||
* set the password of a user | |||||
* | |||||
*/ | |||||
public static function setpassword($username,$password){ | |||||
$password=sha1($password); | |||||
$userid=OC_USER::getuserid($username); | |||||
$query="UPDATE `users` SET `user_password` = '$password' WHERE `user_id` =$userid LIMIT 1 ;"; | |||||
$result=OC_DB::query($query); | |||||
if($result){ | |||||
return true; | |||||
}else{ | |||||
return false; | |||||
} | |||||
} | |||||
/** | |||||
* check the password of a user | |||||
* | |||||
*/ | |||||
public static function checkpassword($username,$password){ | |||||
$password=sha1($password); | |||||
$usernameclean=strtolower($username); | |||||
$username=mysql_escape_string($username); | |||||
$usernameclean=mysql_escape_string($usernameclean); | |||||
$query="SELECT user_id FROM `users` WHERE `user_name_clean` = '$usernameclean' AND `user_password` = '$password' LIMIT 1"; | |||||
$result=OC_DB::select($query); | |||||
if(isset($result[0]) && isset($result[0]['user_id']) && $result[0]['user_id']>0){ | |||||
return true; | |||||
}else{ | |||||
return false; | |||||
} | |||||
} | |||||
} | } | ||||
?> | ?> |
<?php | |||||
global $FIRSTRUN; | |||||
global $CONFIG_ERROR; | |||||
if(!isset($fillDB)) $fillDB=true; | |||||
if(!isset($CONFIG_DBHOST)) $CONFIG_DBHOST='localhost'; | |||||
if(!isset($CONFIG_DBUSER)) $CONFIG_DBUSER='owncloud'; | |||||
$newuserpassword=OC_USER::generatepassword(); | |||||
?> | |||||
<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'; | |||||
} | |||||
function dbtypechange(){ | |||||
var dropdown=action=document.getElementById('dbtype'); | |||||
var type=dropdown.options[dropdown.selectedIndex].value; | |||||
var inputs=Array('dbhost','dbuser','dbpass','dbpass_retype','dbcreaterow','dbAdminPwd','dbAdminUser'); | |||||
var id,element; | |||||
if(type=='sqlite'){ | |||||
for(i in inputs){ | |||||
id=inputs[i]; | |||||
element=document.getElementById(id); | |||||
if(element){ | |||||
element.style.display='none'; | |||||
} | |||||
} | |||||
}else if(type=='mysql'){ | |||||
for(i in inputs){ | |||||
id=inputs[i]; | |||||
element=document.getElementById(id); | |||||
if(element){ | |||||
element.style.display='table-row'; | |||||
} | |||||
} | |||||
showDBAdmin() | |||||
} | |||||
} | |||||
</script> | |||||
<form method="post" enctype="multipart/form-data"> | |||||
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> | |||||
<?php | |||||
if(!empty($CONFIG_ERROR) and !$FIRSTRUN){ | |||||
echo "<tr><td colspan='3' class='error'>$CONFIG_ERROR</td></tr>"; | |||||
} | |||||
if(!$FIRSTRUN){?> | |||||
<tr><td>current password</td><td><input type="password" name="currentpassword" size="30" class="formstyle"></input></td></tr> | |||||
<?php | |||||
} | |||||
if($FIRSTRUN){?> | |||||
<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 password:</td><td><input type="password" name="adminpassword" size="30" class="formstyle"></input></td><td>(leave empty to keep current password)</td></tr> | |||||
<tr><td>retype admin password:</td><td><input type="password" name="adminpassword2" size="30" class="formstyle"></input></td></tr> | |||||
<?php | |||||
} | |||||
?> | |||||
<tr><td>data directory:</td><td><input type="text" name="datadirectory" size="30" class="formstyle" value="<?php echo($CONFIG_DATADIRECTORY);?>"></input></td></tr> | |||||
<tr><td>force ssl:</td><td><input type="checkbox" name="forcessl" size="30" class="formstyle" value='<?php echo($CONFIG_HTTPFORCESSL);?>'></input></td></tr> | |||||
<tr><td>date format:</td><td><input type="text" name="dateformat" size="30" class="formstyle" value='<?php echo($CONFIG_DATEFORMAT);?>'></input></td></tr> | |||||
<tr><td>database type:</td><td> | |||||
<select id='dbtype' name="dbtype" onchange='dbtypechange()'> | |||||
<?php | |||||
global $CONFIG_DBTYPE; | |||||
if($CONFIG_DBTYPE=='sqlite'){ | |||||
?> | |||||
<option value="sqlite">SQLite</option> | |||||
<option value="mysql">MySQL</option> | |||||
<?php | |||||
}else{ | |||||
?> | |||||
<option value="mysql">MySQL</option> | |||||
<option value="sqlite">SQLite</option> | |||||
<?php | |||||
} | |||||
?> | |||||
</select> | |||||
</td></tr> | |||||
<tr id='dbhost'><td>database host:</td><td><input type="text" name="dbhost" size="30" class="formstyle" value='<?php echo($CONFIG_DBHOST);?>'></input></td></tr> | |||||
<tr><td>database name:</td><td><input type="text" name="dbname" size="30" class="formstyle" value='<?php echo($CONFIG_DBNAME);?>'></input></td></tr> | |||||
<tr id='dbuser'><td>database user:</td><td><input type="text" name="dbuser" size="30" class="formstyle" value='<?php echo($CONFIG_DBUSER);?>'></input></td></tr> | |||||
<tr id='dbpass'><td>database password:</td><td><input type="password" name="dbpassword" size="30" class="formstyle" value=''></input></td><td>(leave empty to keep current password)</td></tr> | |||||
<tr id='dbpass_retype'><td>retype database password:</td><td><input type="password" name="dbpassword2" size="30" class="formstyle" value=''></input></td></tr> | |||||
<tr id='dbcreaterow'><td>create database and user:</td><td><input id='dbcreate' type="checkbox" name="createdatabase" size="30" class="formstyle" value='1' <?php if($FIRSTRUN) 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($FIRSTRUN) echo 'checked'; ?>></input></td></tr> | |||||
<tr><td></td><td><input type="submit" name="set_config" alt="save" value="save" class="formstyle" /></td></tr> | |||||
</table></form><br/> | |||||
<?php | |||||
if(!$FIRSTRUN){?> | |||||
<br/> | |||||
<form method="post" enctype="multipart/form-data"> | |||||
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> | |||||
<tr><td colspan='2'>Create new user:</td></tr> | |||||
<tr><td>user name</td><td><input type='text' name='new_username' class="formstyle"></input></td></tr> | |||||
<tr><td>password</td><td><input type='text' name='new_password' class="formstyle" autocomplete="off" value='<?php echo($newuserpassword);?>'></input></td></tr> | |||||
<tr><td></td><td><input type='submit' value='create' class="formstyle"></input></td></tr> | |||||
</table> | |||||
</form> | |||||
<?php | |||||
} | |||||
?> | |||||
<script type="text/javascript"> | |||||
dbtypechange() | |||||
</script> |
$newuserpassword=OC_USER::generatepassword(); | $newuserpassword=OC_USER::generatepassword(); | ||||
?> | ?> | ||||
<script type="text/javascript"> | <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'; | |||||
} | |||||
function dbtypechange(){ | |||||
var dropdown=action=document.getElementById('dbtype'); | |||||
var type=dropdown.options[dropdown.selectedIndex].value; | |||||
var inputs=Array('dbhost','dbuser','dbpass','dbpass_retype','dbcreaterow','dbAdminPwd','dbAdminUser'); | |||||
var id,element; | |||||
if(type=='sqlite'){ | |||||
for(i in inputs){ | |||||
id=inputs[i]; | |||||
element=document.getElementById(id); | |||||
if(element){ | |||||
element.style.display='none'; | |||||
} | |||||
} | |||||
}else if(type=='mysql'){ | |||||
for(i in inputs){ | |||||
id=inputs[i]; | |||||
element=document.getElementById(id); | |||||
if(element){ | |||||
element.style.display='table-row'; | |||||
} | |||||
} | |||||
showDBAdmin() | |||||
} | |||||
changepassset=function(){ | |||||
var change=document.getElementById('changepass').checked; | |||||
if(!change){ | |||||
document.getElementById('new_password').style.display='none'; | |||||
document.getElementById('new_password_retype').style.display='none'; | |||||
}else{ | |||||
document.getElementById('new_password').style.display='table-row'; | |||||
document.getElementById('new_password_retype').style.display='table-row'; | |||||
} | |||||
} | } | ||||
</script> | </script> | ||||
<form method="post" enctype="multipart/form-data"> | <form method="post" enctype="multipart/form-data"> | ||||
<input type='hidden' name='config' value='1'> | |||||
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> | <table cellpadding="5" cellspacing="5" border="0" class="loginform"> | ||||
<?php | <?php | ||||
if(!empty($CONFIG_ERROR) and !$FIRSTRUN){ | if(!empty($CONFIG_ERROR) and !$FIRSTRUN){ | ||||
echo "<tr><td colspan='3' class='error'>$CONFIG_ERROR</td></tr>"; | echo "<tr><td colspan='3' class='error'>$CONFIG_ERROR</td></tr>"; | ||||
} | } | ||||
if(!$FIRSTRUN){?> | |||||
<tr><td>current password</td><td><input type="password" name="currentpassword" size="30" class="formstyle"></input></td></tr> | |||||
<?php | |||||
} | |||||
?> | |||||
<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 password:</td><td><input type="password" name="adminpassword" size="30" class="formstyle"></input></td><td>(leave empty to keep current password)</td></tr> | |||||
<tr><td>retype admin password:</td><td><input type="password" name="adminpassword2" size="30" class="formstyle"></input></td></tr> | |||||
<tr><td>data directory:</td><td><input type="text" name="datadirectory" size="30" class="formstyle" value="<?php echo($CONFIG_DATADIRECTORY);?>"></input></td></tr> | |||||
<tr><td>force ssl:</td><td><input type="checkbox" name="forcessl" size="30" class="formstyle" value='<?php echo($CONFIG_HTTPFORCESSL);?>'></input></td></tr> | |||||
<tr><td>date format:</td><td><input type="text" name="dateformat" size="30" class="formstyle" value='<?php echo($CONFIG_DATEFORMAT);?>'></input></td></tr> | |||||
<tr><td>database type:</td><td> | |||||
<select id='dbtype' name="dbtype" onchange='dbtypechange()'> | |||||
<?php | |||||
global $CONFIG_DBTYPE; | |||||
if($CONFIG_DBTYPE=='sqlite'){ | |||||
?> | |||||
<option value="sqlite">SQLite</option> | |||||
<option value="mysql">MySQL</option> | |||||
<?php | |||||
}else{ | |||||
?> | ?> | ||||
<option value="mysql">MySQL</option> | |||||
<option value="sqlite">SQLite</option> | |||||
<tr><td>enter password</td><td><input type="password" name="currentpassword" size="30" class="formstyle"></input></td></tr> | |||||
<tr><td>change password:</td><td><input onchange='changepassset()' id='changepass' type="checkbox" name="changepass" size="30" class="formstyle" value='1'></input></td></tr> | |||||
<tr style='display:none' id='new_password'><td>new password:</td><td><input type="password" name="password" size="30" class="formstyle"></input></td></tr> | |||||
<tr style='display:none' id='new_password_retype'><td>retype admin password:</td><td><input type="password" name="password2" size="30" class="formstyle"></input></td></tr> | |||||
</table> | |||||
</form> | |||||
Groups: | |||||
<form method="post" enctype="multipart/form-data"> | |||||
<input type='hidden' name='creategroup' value='1'> | |||||
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> | |||||
<tr><td colspan='2' class='center'>Current groups</td></tr> | |||||
<?php | <?php | ||||
$groups=OC_USER::getusergroups($_SESSION['username']); | |||||
foreach($groups as $group){ | |||||
?> | |||||
<tr><td><?php echo $group;?></td></tr> | |||||
<?php | |||||
} | } | ||||
?> | ?> | ||||
</select> | |||||
</td></tr> | |||||
<tr id='dbhost'><td>database host:</td><td><input type="text" name="dbhost" size="30" class="formstyle" value='<?php echo($CONFIG_DBHOST);?>'></input></td></tr> | |||||
<tr><td>database name:</td><td><input type="text" name="dbname" size="30" class="formstyle" value='<?php echo($CONFIG_DBNAME);?>'></input></td></tr> | |||||
<tr id='dbuser'><td>database user:</td><td><input type="text" name="dbuser" size="30" class="formstyle" value='<?php echo($CONFIG_DBUSER);?>'></input></td></tr> | |||||
<tr id='dbpass'><td>database password:</td><td><input type="password" name="dbpassword" size="30" class="formstyle" value=''></input></td><td>(leave empty to keep current password)</td></tr> | |||||
<tr id='dbpass_retype'><td>retype database password:</td><td><input type="password" name="dbpassword2" size="30" class="formstyle" value=''></input></td></tr> | |||||
<tr id='dbcreaterow'><td>create database and user:</td><td><input id='dbcreate' type="checkbox" name="createdatabase" size="30" class="formstyle" value='1' <?php if($FIRSTRUN) 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($FIRSTRUN) echo 'checked'; ?>></input></td></tr> | |||||
<tr><td></td><td><input type="submit" name="set_config" alt="save" value="save" class="formstyle" /></td></tr> | |||||
</table></form><br/> | |||||
<br/> | |||||
<form method="post" enctype="multipart/form-data"> | |||||
<table cellpadding="5" cellspacing="5" border="0" class="loginform"> | |||||
<tr><td colspan='2'>Create new user:</td></tr> | |||||
<tr><td>user name</td><td><input type='text' name='new_username' class="formstyle"></input></td></tr> | |||||
<tr><td>password</td><td><input type='text' name='new_password' class="formstyle" autocomplete="off" value='<?php echo($newuserpassword);?>'></input></td></tr> | |||||
<tr><td></td><td><input type='submit' value='create' class="formstyle"></input></td></tr> | |||||
<tr><td colspan='2' class='center'>Create new group</td></tr> | |||||
<tr><td><input type='text' name='groupname' class="formstyle"></input></td><td><input type='submit' value='create' class="formstyle"></input></td></tr> | |||||
</table> | </table> | ||||
</form> | </form> | ||||
<script type="text/javascript"> | |||||
dbtypechange() | |||||
</script> |
// check if already configured. otherwise start configuration wizard | // check if already configured. otherwise start configuration wizard | ||||
$error=OC_CONFIG::writeconfiglisener(); | |||||
$error=OC_CONFIG::writeadminlisener(); | |||||
if($e=OC_CONFIG::configlisener()){ | |||||
$error.=$e; | |||||
} | |||||
if($e=OC_CONFIG::createuserlisener()){ | if($e=OC_CONFIG::createuserlisener()){ | ||||
$error=$e; | |||||
$error.=$e; | |||||
} | |||||
if($e=OC_CONFIG::creategrouplisener()){ | |||||
$error.=$e; | |||||
} | } | ||||
$CONFIG_ERROR=$error; | $CONFIG_ERROR=$error; | ||||
global $CONFIG_INSTALLED; | global $CONFIG_INSTALLED; | ||||
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_CONFIG::showconfigform(); | |||||
OC_CONFIG::showadminform(); | |||||
echo('</div>'); | echo('</div>'); | ||||
OC_UTIL::showfooter(); | OC_UTIL::showfooter(); | ||||
exit(); | exit(); |