21 changed files with 2153 additions and 592 deletions
-
31admin/index.php
-
1admin/index.php~
-
91css/default.php
-
30files/api.php
-
108files/get_file.php
-
49files/get_files.php
-
38files/new.php
-
2files/upload.php
-
33inc/HTTP/WebDAV/Server.php
-
726inc/HTTP/WebDAV/Server/Filesystem.php
-
203inc/lib_base.php
-
359inc/lib_config.php
-
408inc/lib_files.php
-
277inc/lib_user.php
-
106inc/templates/adminform.php
-
99inc/templates/configform.php
-
19inc/templates/header.php
-
6js/filebrowser.js
-
26js/lib_api.js
-
116js/lib_files.js
-
17webdav/owncloud.php
@ -0,0 +1 @@ |
|||
|
|||
@ -1,108 +0,0 @@ |
|||
<?php |
|||
/** |
|||
* ownCloud - ajax frontend |
|||
* |
|||
* @author Robin Appelman |
|||
* @copyright 2010 Robin Appelman icewind1991@gmail.com |
|||
* |
|||
* 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/>. |
|||
* |
|||
*/ |
|||
|
|||
//note this file is for getting files themselves, get_files.php is for getting a list of files.
|
|||
|
|||
require_once('../inc/lib_base.php'); |
|||
|
|||
if(!function_exists('sys_get_temp_dir')) { |
|||
function sys_get_temp_dir() { |
|||
if( $temp=getenv('TMP') ) return $temp; |
|||
if( $temp=getenv('TEMP') ) return $temp; |
|||
if( $temp=getenv('TMPDIR') ) return $temp; |
|||
$temp=tempnam(__FILE__,''); |
|||
if (file_exists($temp)) { |
|||
unlink($temp); |
|||
return dirname($temp); |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
function addDir($dir,$zip,$internalDir=''){ |
|||
$dirname=basename($dir); |
|||
$zip->addEmptyDir($internalDir.$dirname); |
|||
$internalDir.=$dirname.='/'; |
|||
$files=OC_FILES::getdirectorycontent($dir); |
|||
foreach($files as $file){ |
|||
$filename=$file['name']; |
|||
$file=$dir.'/'.$filename; |
|||
if(is_file($file)){ |
|||
$zip->addFile($file,$internalDir.$filename); |
|||
}elseif(is_dir($file)){ |
|||
addDir($file,$zip,$internalDir); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$files=$_GET['files']; |
|||
$dir=(isset($_GET['dir']))?$_GET['dir']:''; |
|||
if(strstr($files,'..') or strstr($dir,'..')){ |
|||
die(); |
|||
} |
|||
if(strpos($files,',')){ |
|||
$files=explode(',',$files); |
|||
} |
|||
|
|||
|
|||
if(is_array($files)){ |
|||
$zip = new ZipArchive(); |
|||
$filename = sys_get_temp_dir()."/ownCloud.zip"; |
|||
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { |
|||
exit("cannot open <$filename>\n"); |
|||
} |
|||
foreach($files as $file){ |
|||
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$file; |
|||
if(is_file($file)){ |
|||
$zip->addFile($file,basename($file)); |
|||
}elseif(is_dir($file)){ |
|||
addDir($file,$zip); |
|||
} |
|||
} |
|||
$zip->close(); |
|||
}elseif(is_dir($CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files)){ |
|||
$zip = new ZipArchive(); |
|||
$filename = sys_get_temp_dir()."/ownCloud.zip"; |
|||
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { |
|||
exit("cannot open <$filename>\n"); |
|||
} |
|||
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; |
|||
addDir($file,$zip); |
|||
$zip->close(); |
|||
}else{ |
|||
$zip=false; |
|||
$filename=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$files; |
|||
} |
|||
header('Content-Description: File Transfer'); |
|||
header('Content-Type: application/octet-stream'); |
|||
header('Content-Disposition: attachment; filename='.basename($filename)); |
|||
header('Content-Transfer-Encoding: binary'); |
|||
header('Expires: 0'); |
|||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|||
header('Pragma: public'); |
|||
header('Content-Length: ' . filesize($filename)); |
|||
ob_end_clean(); |
|||
readfile($filename); |
|||
if($zip){ |
|||
unlink($filename); |
|||
} |
|||
?>
|
|||
@ -1,38 +0,0 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ownCloud - ajax frontend |
|||
* |
|||
* @author Robin Appelman |
|||
* @copyright 2010 Robin Appelman icewind1991@gmail.com |
|||
* |
|||
* 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/>. |
|||
* |
|||
*/ |
|||
require_once('../inc/lib_base.php'); |
|||
|
|||
$dir=$_GET['dir']; |
|||
$name=$_GET['name']; |
|||
$type=$_GET['type']; |
|||
if(isset($_SESSION['username']) and $_SESSION['username'] and strpos($dir,'..')===false and strpos($name,'..')===false){ |
|||
$file=$CONFIG_DATADIRECTORY.'/'.$dir.'/'.$name; |
|||
if($type=='dir'){ |
|||
mkdir($file); |
|||
}elseif($type=='file'){ |
|||
$fileHandle=fopen($file, 'w') or die("can't open file"); |
|||
fclose($fileHandle); |
|||
} |
|||
} |
|||
|
|||
?>
|
|||
@ -0,0 +1,277 @@ |
|||
<?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/>. |
|||
* |
|||
*/ |
|||
|
|||
if(!$CONFIG_INSTALLED){ |
|||
$_SESSION['user_id']=false; |
|||
$_SESSION['username']=''; |
|||
$_SESSION['username_clean']=''; |
|||
} |
|||
|
|||
/** |
|||
* Class for usermanagement |
|||
* |
|||
*/ |
|||
class OC_USER { |
|||
|
|||
/** |
|||
* check if the login button is pressed and logg the user in |
|||
* |
|||
*/ |
|||
public static function loginlisener(){ |
|||
if(isset($_POST['loginbutton']) and isset($_POST['password']) and isset($_POST['login'])){ |
|||
if(OC_USER::login($_POST['login'],$_POST['password'])){ |
|||
OC_LOG::event($_SESSION['username'],1,''); |
|||
return(''); |
|||
}else{ |
|||
return('error'); |
|||
} |
|||
} |
|||
return(''); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* try to create a new user |
|||
* |
|||
*/ |
|||
public static function createuser($username,$password){ |
|||
if(OC_USER::getuserid($username)!=0){ |
|||
return false; |
|||
}else{ |
|||
$password=sha1($password); |
|||
$usernameclean=strtolower($username); |
|||
$username=mysql_escape_string($username); |
|||
$usernameclean=mysql_escape_string($usernameclean); |
|||
$query="INSERT INTO `users` (`user_id` ,`user_name` ,`user_name_clean` ,`user_password`)VALUES (NULL , '$username', '$usernameclean', '$password')"; |
|||
$result=OC_DB::query($query); |
|||
return ($result)?true:false; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* try to login a user |
|||
* |
|||
*/ |
|||
public static function login($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'])){ |
|||
$_SESSION['user_id']=$result[0]['user_id']; |
|||
$_SESSION['username']=$username; |
|||
$_SESSION['username_clean']=$usernameclean; |
|||
return true; |
|||
}else{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* check if the logout button is pressed and logout the user |
|||
* |
|||
*/ |
|||
public static function logoutlisener(){ |
|||
if(isset($_GET['logoutbutton']) && isset($_SESSION['username'])){ |
|||
OC_LOG::event($_SESSION['username'],2,''); |
|||
$_SESSION['user_id']=false; |
|||
$_SESSION['username']=''; |
|||
$_SESSION['username_clean']=''; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* check if a user is logged in |
|||
* |
|||
*/ |
|||
public static function isLoggedIn(){ |
|||
return (isset($_SESSION['user_id']) && $_SESSION['user_id'])?true:false; |
|||
} |
|||
|
|||
/** |
|||
* try to create a new group |
|||
* |
|||
*/ |
|||
public static function creategroup($groupname){ |
|||
if(OC_USER::getgroupid($groupname)==0){ |
|||
$groupname=mysql_escape_string($groupname); |
|||
$query="INSERT INTO `groups` (`group_id` ,`group_name`) VALUES (NULL , '$groupname');"; |
|||
$result=OC_DB::query($query); |
|||
return ($result)?true:false; |
|||
}else{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* get the id of a user |
|||
* |
|||
*/ |
|||
public static function getuserid($username){ |
|||
$usernameclean=strtolower($username); |
|||
$username=mysql_escape_string($username); |
|||
$usernameclean=mysql_escape_string($usernameclean); |
|||
$query="SELECT user_id FROM `users` WHERE `user_name_clean` = '$usernameclean' LIMIT 1"; |
|||
$result=OC_DB::select($query); |
|||
if(isset($result[0]) && isset($result[0]['user_id'])){ |
|||
return $result[0]['user_id']; |
|||
}else{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* get the id of a group |
|||
* |
|||
*/ |
|||
public static function getgroupid($groupname){ |
|||
$groupname=mysql_escape_string($groupname); |
|||
$query="SELECT group_id FROM `groups` WHERE `group_name` = '$groupname' LIMIT 1"; |
|||
$result=OC_DB::select($query); |
|||
if(isset($result[0]) && isset($result[0]['group_id'])){ |
|||
return $result[0]['group_id']; |
|||
}else{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 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 |
|||
* |
|||
*/ |
|||
public static function ingroup($username,$groupname){ |
|||
$userid=OC_USER::getuserid($username); |
|||
$groupid=OC_USER::getgroupid($groupname); |
|||
if($groupid>0 and $userid>0){ |
|||
$query="SELECT user_group_id FROM `user_group` WHERE `group_id` = '$groupid ' AND `user_id` = '$userid 'LIMIT 1"; |
|||
$result=OC_DB::select($query); |
|||
if(isset($result[0]) && isset($result[0]['user_group_id'])){ |
|||
return true; |
|||
}else{ |
|||
return false; |
|||
} |
|||
}else{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* add a user to a group |
|||
* |
|||
*/ |
|||
public static function addtogroup($username,$groupname){ |
|||
if(!OC_USER::ingroup($username,$groupname)){ |
|||
$userid=OC_USER::getuserid($username); |
|||
$groupid=OC_USER::getgroupid($groupname); |
|||
if($groupid!=0 and $userid!=0){ |
|||
$query="INSERT INTO `user_group` (`user_group_id` ,`user_id` ,`group_id`) VALUES (NULL , '$userid', '$groupid');"; |
|||
$result=OC_DB::query($query); |
|||
if($result){ |
|||
return true; |
|||
}else{ |
|||
return false; |
|||
} |
|||
}else{ |
|||
return false; |
|||
} |
|||
}else{ |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
public static function generatepassword(){ |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
|
|||
?>
|
|||
@ -0,0 +1,106 @@ |
|||
<?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=""></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> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue