*/
public static function checkserver(){
global $SERVERROOT;
+ global $CONFIG_DATADIRECTORY_ROOT;
+ global $CONFIG_BACKUPDIRECTORY;
+ global $CONFIG_ENABLEBACKUP;
+ $error='';
$f=@fopen($SERVERROOT.'/config/config.php','a+');
- if(!$f) die('Error: Config file (config/config.php) is not writable for the webserver.');
+ if(!$f) $error.='Error: Config file (config/config.php) is not writable for the webserver.<br/>';
@fclose($f);
+ if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){
+ $error.='No database drivers (sqlite or mysql) installed.<br/>';
+ }
+ global $CONFIG_DBTYPE;
+ global $CONFIG_DBNAME;
+ if($CONFIG_DBTYPE=='sqlite'){
+ $file=$SERVERROOT.'/'.$CONFIG_DBNAME;
+ $prems=substr(decoct(fileperms($file)),-3);
+ if(substr($prems,2,1)!='0'){
+ @chmod($file,0660);
+ clearstatcache();
+ $prems=substr(decoct(fileperms($file)),-3);
+ if(substr($prems,2,1)!='0'){
+ $error.='SQLite database file ('.$file.') is readable from the web<br/>';
+ }
+ }
+ }
+ $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
+ if(substr($CONFIG_DATADIRECTORY_ROOT,2,1)!='0'){
+ chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
+ clearstatcache();
+ $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
+ if(substr($prems,2,1)!='0'){
+ $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>';
+ }
+ }
+ if($CONFIG_ENABLEBACKUP){
+ $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
+ if(substr($CONFIG_BACKUPDIRECTORY,2,1)!='0'){
+ chmodr($CONFIG_BACKUPDIRECTORY,0770);
+ clearstatcache();
+ $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
+ if(substr($prems,2,1)!='0'){
+ $error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>';
+ }
+ }
+ }
+ if($error){
+ die($error);
+ }
}
}
}
+function chmodr($path, $filemode) {
+// echo "$path<br/>";
+ if (!is_dir($path))
+ return chmod($path, $filemode);
+ $dh = opendir($path);
+ while (($file = readdir($dh)) !== false) {
+ if($file != '.' && $file != '..') {
+ $fullpath = $path.'/'.$file;
+ if(is_link($fullpath))
+ return FALSE;
+ elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
+ return FALSE;
+ elseif(!chmodr($fullpath, $filemode))
+ return FALSE;
+ }
+ }
+ closedir($dh);
+ if(chmod($path, $filemode))
+ return TRUE;
+ else
+ return FALSE;
+}
+
?>
\ No newline at end of file
global $WEBROOT;
global $CONFIG_DBHOST;
global $CONFIG_DBNAME;
+ global $CONFIG_INSTALLED;
global $CONFIG_DBUSER;
global $CONFIG_DBPASSWORD;
global $CONFIG_DBTYPE;
//checkdata
$error='';
- $FIRSTRUN=empty($CONFIG_ADMINLOGIN);
+ $FIRSTRUN=!$CONFIG_INSTALLED;
if(!$FIRSTRUN){
- if($_POST['currentpassword']!=$CONFIG_ADMINPASSWORD){
+ if(!OC_USER::login($_SESSION['username'],$_POST['currentpassword'])){
$error.='wrong password<br />';
}
}
- if(!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) $error.='admin login not set<br />';
+ if((!isset($_POST['adminlogin']) or empty($_POST['adminlogin'])) and $FIRSTRUN) $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 />';
+ if($FIRSTRUN and $_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(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']);
+ if($CONFIG_DBTYPE!=$dbtype or $FIRSTRUN){
+ //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'];
}
- }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['createdatabase']) and $CONFIG_DBTYPE=='mysql'){
+ self::createdatabase($_POST['dbadminuser'],$_POST['dbadminpwd']);
+ }
+ }catch(Exception $e){
+ $error.='error while trying to create the database<br/>';
}
- OC_DB::disconnect();
- unlink($SERVERROOT.'/'.$CONFIG_DBNAME);
- }
- try{
- if(isset($_POST['filldb'])){
- self::filldatabase();
+ if($CONFIG_DBTYPE=='sqlite'){
+ $f=@fopen($SERVERROOT.'/'.$CONFIG_DBNAME,'a+');
+ if(!$f){
+ $error.='path of sqlite database not writable by server<br/>';
+ }
+ OC_DB::disconnect();
+ unlink($SERVERROOT.'/'.$CONFIG_DBNAME);
}
- }catch(Exception $e){
- echo 'testin';
- $error.='error while trying to fill the database<br/>';
- }
- if($CONFIG_DBTYPE=='sqlite'){
- OC_DB::disconnect();
- }
- 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/>';
+ try{
+ if(isset($_POST['filldb'])){
+ self::filldatabase();
+ }
+ }catch(Exception $e){
+ echo 'testin';
+ $error.='error while trying to fill the database<br/>';
+ }
+ if($CONFIG_DBTYPE=='sqlite'){
+ OC_DB::disconnect();
}
}
- if(!OC_USER::addtogroup($_POST['adminlogin'],'admin')){
- $error.='error while trying to add the admin user to the admin group<br/>';
+ if($FIRSTRUN){
+ 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";
$usernameclean=mysql_escape_string($usernameclean);
$query="SELECT user_id FROM users WHERE user_name_clean = '$usernameclean'";
$result=OC_DB::select($query);
+ if(!is_array($result)){
+ return 0;
+ }
if(isset($result[0]) && isset($result[0]['user_id'])){
return $result[0]['user_id'];
}else{
$groupname=mysql_escape_string($groupname);
$query="SELECT group_id FROM groups WHERE group_name = '$groupname'";
$result=OC_DB::select($query);
+ if(!is_array($result)){
+ return 0;
+ }
if(isset($result[0]) && isset($result[0]['group_id'])){
return $result[0]['group_id'];
}else{
<?php
global $FIRSTRUN;
global $CONFIG_ENABLEBACKUP;
+global $CONFIG_DATADIRECTORY_ROOT;
global $CONFIG_BACKUPDIRECTORY;
global $CONFIG_ERROR;
if(!isset($fillDB)) $fillDB=true;
<?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>data directory:</td><td><input type="text" name="datadirectory" size="30" class="formstyle" value="<?php echo($CONFIG_DATADIRECTORY_ROOT);?>"></input></td></tr>
<tr><td>force ssl:</td><td><input type="checkbox" name="forcessl" size="30" class="formstyle" value='1' <?php if($CONFIG_HTTPFORCESSL) echo 'checked'?>></input></td></tr>
<tr><td>enable automatic backup:</td><td><input type="checkbox" name="enablebackup" id="enablebackup" onchange='showBackupPath()' size="30" class="formstyle" value='1' <?php if($CONFIG_ENABLEBACKUP) echo 'checked'?>></input></td></tr>
<tr id='backupdir'><td>backup directory:</td><td><input type="text" name="backupdirectory" size="30" class="formstyle" value="<?php echo($CONFIG_BACKUPDIRECTORY);?>"></input></td></tr>
<select id='dbtype' name="dbtype" onchange='dbtypechange()'>
<?php
global $CONFIG_DBTYPE;
+$dbtypes=array();
if($CONFIG_DBTYPE=='sqlite'){
-?>
-<option value="sqlite">SQLite</option>
-<option value="mysql">MySQL</option>
-<?php
+ if(is_callable('sqlite_open')){
+ $dbtypes[]='SQLite';
+ }
+ if(is_callable('mysql_connect')){
+ $dbtypes[]='MySQL';
+ }
}else{
-?>
-<option value="mysql">MySQL</option>
-<option value="sqlite">SQLite</option>
-<?php
+ if(is_callable('mysql_connect')){
+ $dbtypes[]='MySQL';
+ }
+ if(is_callable('sqlite_open')){
+ $dbtypes[]='SQLite';
+ }
+}
+foreach($dbtypes as $dbtype){
+ echo "<option value='".strtolower($dbtype)."'>$dbtype</option>";
}
?>
</select>