summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-10-10 21:05:39 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-10-10 21:05:39 +0200
commit9ba384b9a4ebf0e553e01c4450dec4273dc5a707 (patch)
tree9ad8d3d5e3f97c03e072e1b6bf1e2042a4fa16ba /lib
parent39fa5d1c7fe6b0e3c90396eb16a875b74d803894 (diff)
parent8b3c4e9a5206ff6e6f02a8a919863c6525a1910b (diff)
downloadnextcloud-server-9ba384b9a4ebf0e553e01c4450dec4273dc5a707.tar.gz
nextcloud-server-9ba384b9a4ebf0e553e01c4450dec4273dc5a707.zip
merge master into database
Diffstat (limited to 'lib')
-rw-r--r--lib/MDB2/Driver/Manager/sqlite3.php5
-rw-r--r--lib/MDB2/Driver/sqlite3.php5
-rw-r--r--lib/app.php72
-rw-r--r--lib/appconfig.php18
-rw-r--r--lib/base.php263
-rw-r--r--lib/config.php13
-rw-r--r--lib/fileproxy/quota.php3
-rw-r--r--lib/files.php32
-rw-r--r--lib/filestorage/local.php2
-rw-r--r--lib/filesystem.php5
-rw-r--r--lib/helper.php56
-rw-r--r--lib/installer.php35
-rw-r--r--lib/json.php81
-rw-r--r--lib/l10n.php15
-rw-r--r--lib/mimetypes.list.php2
-rw-r--r--lib/preferences.php4
-rw-r--r--lib/remote/cloud.php8
-rw-r--r--lib/setup.php21
-rw-r--r--lib/template.php34
-rw-r--r--lib/user.php37
-rw-r--r--lib/util.php133
21 files changed, 470 insertions, 374 deletions
diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php
index 4e420b5d0b2..eabbb72b3c2 100644
--- a/lib/MDB2/Driver/Manager/sqlite3.php
+++ b/lib/MDB2/Driver/Manager/sqlite3.php
@@ -69,8 +69,7 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
*/
function createDatabase($name, $options = array())
{
- global $SERVERROOT;
- $datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
+ $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$db =$this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
@@ -1361,4 +1360,4 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common
// }}}
}
-?> \ No newline at end of file
+?>
diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php
index ccf6bb53688..a41aeed4850 100644
--- a/lib/MDB2/Driver/sqlite3.php
+++ b/lib/MDB2/Driver/sqlite3.php
@@ -351,8 +351,7 @@ class MDB2_Driver_sqlite3 extends MDB2_Driver_Common
if($this->connection instanceof SQLite3){
return MDB2_OK;
}
- global $SERVERROOT;
- $datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
+ $datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
$database_file = $this->_getDatabaseFile($this->database_name);
if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
@@ -1358,4 +1357,4 @@ class MDB2_Statement_sqlite3 extends MDB2_Statement_Common
}
}
-?> \ No newline at end of file
+?>
diff --git a/lib/app.php b/lib/app.php
index 61ea081c6ff..b9eea483a55 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -44,8 +44,6 @@ class OC_App{
* exists.
*/
public static function loadApps(){
- global $SERVERROOT;
-
// Did we allready load everything?
if( self::$init ){
return true;
@@ -60,7 +58,7 @@ class OC_App{
$apps = OC_Appconfig::getApps();
foreach( $apps as $app ){
if( self::isEnabled( $app )){
- if(is_file($SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){
+ if(is_file(OC::$SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){
require( 'apps/'.$app.'/appinfo/app.php' );
}
}
@@ -202,23 +200,36 @@ class OC_App{
*/
public static function getSettingsNavigation(){
$l=new OC_L10N('core');
- $admin=array(
- array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" )),
- array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )),
- );
- $settings=array(
- array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "help.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" )),
- array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" ))
- );
- if(count(self::$settingsForms)>0){
- $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
- }
- if(count(self::$adminForms)>0){
- $admin[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
- }
- if( OC_Group::inGroup( $_SESSION["user_id"], "admin" )){
- $settings=array_merge($admin,$settings);
- }
+
+ // by default, settings only contain the help menu
+ $settings = array(
+ array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "help.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "settings", "help.svg" ))
+ );
+
+ // if the user is logged-in
+ if (OC_User::isLoggedIn()) {
+ // personal menu
+ $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" ));
+
+ // if there're some settings forms
+ if(!empty(self::$settingsForms))
+ // settings menu
+ $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
+
+ // if the user is an admin
+ if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
+ // admin users menu
+ $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
+ // admin apps menu
+ $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
+
+ // if there're some admin forms
+ if(!empty(self::$adminForms))
+ // admins menu
+ $settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
+ }
+ }
+
$navigation = self::proceedNavigation($settings);
return $navigation;
}
@@ -239,7 +250,7 @@ class OC_App{
return $list;
}
-
+
/**
* @brief Read app metadata from the info.xml file
* @param string $appid id of the app or the path of the info.xml file
@@ -263,7 +274,7 @@ class OC_App{
}
return $data;
}
-
+
/**
* @brief Returns the navigation
* @returns associative array
@@ -279,14 +290,13 @@ class OC_App{
$navigation = self::proceedNavigation( self::$navigation );
return $navigation;
}
-
+
/**
* get the id of loaded app
* @return string
*/
public static function getCurrentApp(){
- global $WEBROOT;
- $script=substr($_SERVER["SCRIPT_NAME"],strlen($WEBROOT)+1);
+ $script=substr($_SERVER["SCRIPT_NAME"],strlen(OC::$WEBROOT)+1);
$topFolder=substr($script,0,strpos($script,'/'));
if($topFolder=='apps'){
$length=strlen($topFolder);
@@ -295,8 +305,8 @@ class OC_App{
return $topFolder;
}
}
-
-
+
+
/**
* get the forms for either settings, admin or personal
*/
@@ -318,28 +328,28 @@ class OC_App{
}
return $forms;
}
-
+
/**
* register a settings form to be shown
*/
public static function registerSettings($app,$page){
self::$settingsForms[]='apps/'.$app.'/'.$page.'.php';
}
-
+
/**
* register an admin form to be shown
*/
public static function registerAdmin($app,$page){
self::$adminForms[]='apps/'.$app.'/'.$page.'.php';
}
-
+
/**
* register a personal form to be shown
*/
public static function registerPersonal($app,$page){
self::$personalForms[]='apps/'.$app.'/'.$page.'.php';
}
-
+
/**
* get a list of all apps in the apps folder
*/
diff --git a/lib/appconfig.php b/lib/appconfig.php
index 392782b2586..f43ef141732 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -100,7 +100,18 @@ class OC_Appconfig{
return $default;
}
}
-
+
+ /**
+ * @brief check if a key is set in the appconfig
+ * @param string $app
+ * @param string $key
+ * @return bool
+ */
+ public static function hasKey($app,$key){
+ $exists = self::getKeys( $app );
+ return in_array( $key, $exists );
+ }
+
/**
* @brief sets a value in the appconfig
* @param $app app
@@ -112,10 +123,7 @@ class OC_Appconfig{
*/
public static function setValue( $app, $key, $value ){
// Does the key exist? yes: update. No: insert
- $exists = self::getKeys( $app );
-
- // null: does not exist
- if( !in_array( $key, $exists )){
+ if(! self::hasKey($app,$key)){
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*appconfig ( appid, configkey, configvalue ) VALUES( ?, ?, ? )' );
$query->execute( array( $app, $key, $value ));
}
diff --git a/lib/base.php b/lib/base.php
index dc3ed4129cd..0156febe231 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -65,199 +65,118 @@ class OC{
elseif(strpos($className,'OC_')===0){
require_once strtolower(str_replace('_','/',substr($className,3)) . '.php');
}
+ elseif(strpos($className,'Sabre_')===0) {
+ require_once str_replace('_','/',$className) . '.php';
+ }
}
-}
-
-// this requires all our OC_* classes
-spl_autoload_register(array('OC','autoload'));
-
-// set some stuff
-//ob_start();
-error_reporting(E_ALL | E_STRICT);
-
-date_default_timezone_set('Europe/Berlin');
-ini_set('arg_separator.output','&amp;');
-ini_set('session.cookie_httponly','1;');
-session_start();
-
-// calculate the documentroot
-$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
-$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
-$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
-$scriptName=$_SERVER["SCRIPT_NAME"];
-if(substr($scriptName,-1)=='/'){
- $scriptName.='index.php';
-}
-$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen($SUBURI));
-
-OC::$SERVERROOT=$SERVERROOT;
-OC::$WEBROOT=$WEBROOT;
-
-if($WEBROOT!='' and $WEBROOT[0]!=='/'){
- $WEBROOT='/'.$WEBROOT;
-}
-// We are going to use OC::* instead of globels soon
-OC::$WEBROOT = $WEBROOT;
-OC::$SERVERROOT = $SERVERROOT;
-OC::$DOCUMENTROOT = $DOCUMENTROOT;
-OC::$SUBURI = $SUBURI;
+ public static function init(){
+ // register autoloader
+ spl_autoload_register(array('OC','autoload'));
-// set the right include path
-set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT);
+ // set some stuff
+ //ob_start();
+ error_reporting(E_ALL | E_STRICT);
-//Some libs we really depend on
-require_once('Sabre/autoload.php');
+ date_default_timezone_set('Europe/Berlin');
+ ini_set('arg_separator.output','&amp;');
-// define runtime variables - unless this already has been done
-if( !isset( $RUNTIME_NOSETUPFS )){
- $RUNTIME_NOSETUPFS = false;
-}
-if( !isset( $RUNTIME_NOAPPS )){
- $RUNTIME_NOAPPS = false;
-}
+ // calculate the documentroot
+ OC::$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
+ OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
+ OC::$SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen(OC::$SERVERROOT));
+ $scriptName=$_SERVER["SCRIPT_NAME"];
+ if(substr($scriptName,-1)=='/'){
+ $scriptName.='index.php';
+ }
+ OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI));
-// TODO: we should get rid of this one, too
-// WARNING: to make everything even more confusing, DATADIRECTORY is a var that
-// changes and DATATIRECTORY_ROOT stays the same, but is set by
-// "datadirectory". Any questions?
-$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
+ if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/'){
+ OC::$WEBROOT='/'.OC::$WEBROOT;
+ }
-// redirect to https site if configured
-if( OC_Config::getValue( "forcessl", false )){
- if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') {
- $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
- header("Location: $url");
- exit();
- }
-}
+ // set the right include path
+ set_include_path(OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.OC::$SERVERROOT.'/config'.PATH_SEPARATOR.OC::$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.OC::$SERVERROOT);
-$errors=OC_Util::checkServer();
-$error=(count($errors)>0);
+ // redirect to https site if configured
+ if( OC_Config::getValue( "forcessl", false )){
+ ini_set("session.cookie_secure", "on");
+ if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') {
+ $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
+ header("Location: $url");
+ exit();
+ }
+ }
+ ini_set('session.cookie_httponly','1;');
+ session_start();
+
+ // Add the stuff we need always
+ OC_Util::addScript( "jquery-1.6.4.min" );
+ OC_Util::addScript( "jquery-ui-1.8.14.custom.min" );
+ OC_Util::addScript( "jquery-showpassword" );
+ OC_Util::addScript( "jquery.infieldlabel.min" );
+ OC_Util::addScript( "jquery-tipsy" );
+ OC_Util::addScript( "js" );
+ //OC_Util::addScript( "multiselect" );
+ OC_Util::addScript('search','result');
+ OC_Util::addStyle( "styles" );
+ OC_Util::addStyle( "multiselect" );
+ OC_Util::addStyle( "jquery-ui-1.8.14.custom" );
+ OC_Util::addStyle( "jquery-tipsy" );
+
+ $errors=OC_Util::checkServer();
+ if(count($errors)>0) {
+ OC_Template::printGuestPage('', 'error', array('errors' => $errors));
+ exit;
+ }
-// User and Groups
-if( !OC_Config::getValue( "installed", false )){
- $_SESSION['user_id'] = '';
-}
+ // TODO: we should get rid of this one, too
+ // WARNING: to make everything even more confusing,
+ // DATADIRECTORY is a var that changes and DATADIRECTORY_ROOT
+ // stays the same, but is set by "datadirectory".
+ // Any questions?
+ OC::$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
+ // User and Groups
+ if( !OC_Config::getValue( "installed", false )){
+ $_SESSION['user_id'] = '';
+ }
-OC_User::useBackend( OC_Config::getValue( "userbackend", "database" ));
-OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" ));
+ OC_User::useBackend( OC_Config::getValue( "userbackend", "database" ));
+ OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" ));
-// Add the stuff we need always
-OC_Util::addScript( "jquery-1.6.2.min" );
-OC_Util::addScript( "jquery-ui-1.8.14.custom.min" );
-OC_Util::addScript( "jquery-showpassword" );
-OC_Util::addScript( "jquery-tipsy" );
-OC_Util::addScript( "js" );
-OC_Util::addScript( "multiselect" );
-OC_Util::addScript('search','result');
-OC_Util::addStyle( "styles" );
-OC_Util::addStyle( "multiselect" );
-OC_Util::addStyle( "jquery-ui-1.8.14.custom" );
-OC_Util::addStyle( "jquery-tipsy" );
+ // Load Apps
+ // This includes plugins for users and filesystems as well
+ global $RUNTIME_NOAPPS;
+ if(!$RUNTIME_NOAPPS ){
+ OC_App::loadApps();
+ }
-// Load Apps
-// This includes plugins for users and filesystems as well
-if(!$error and !$RUNTIME_NOAPPS ){
- OC_App::loadApps();
-}
+ // Was in required file ... put it here
+ OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string'));
-// Was in required file ... put it here
-OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string'));
+ // Set up file system unless forbidden
+ global $RUNTIME_NOSETUPFS;
+ if(!$RUNTIME_NOSETUPFS ){
+ OC_Util::setupFS();
+ }
-// Set up file system unless forbidden
-if(!$error and !$RUNTIME_NOSETUPFS ){
- OC_Util::setupFS();
+ // Last part: connect some hooks
+ OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
+ OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
+ }
}
-// Last part: connect some hooks
-OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
-OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
-
-
-
-if($error) {
- $tmpl = new OC_Template( '', 'error', 'guest' );
- $tmpl->assign('errors',$errors);
- $tmpl->printPage();
- exit;
+// define runtime variables - unless this already has been done
+if( !isset( $RUNTIME_NOSETUPFS )){
+ $RUNTIME_NOSETUPFS = false;
}
-
-
-
-
-// FROM Connect.php
-function OC_CONNECT_TEST($path,$user,$password){
- echo 'connecting...';
- $remote=OC_Connect::connect($path,$user,$password);
- if($remote->connected){
- echo 'done<br/>';
- if($remote->isLoggedIn()){
- echo 'logged in, session working<br/>';
- echo 'trying to get remote files...';
- $files=$remote->getFiles('');
- if($files){
- echo count($files).' files found:<br/>';
- foreach($files as $file){
- echo "{$file['type']} {$file['name']}: {$file['size']} bytes<br/>";
- }
- echo 'getting file "'.$file['name'].'"...';
- $size=$file['size'];
- $file=$remote->getFile('',$file['name']);
- if(file_exists($file)){
- $newSize=filesize($file);
- if($size!=$newSize){
- echo "fail<br/>Error: $newSize bytes received, $size expected.";
- echo '<br/><br/>Recieved file:<br/>';
- readfile($file);
- unlink($file);
- return;
- }
- OC_Filesystem::fromTmpFile($file,'/remoteFile');
- echo 'done<br/>';
- echo 'sending file "burning_avatar.png"...';
- $res=$remote->sendFile('','burning_avatar.png','','burning_avatar.png');
- if($res){
- echo 'done<br/>';
- }else{
- echo 'fail<br/>';
- }
- }else{
- echo 'fail<br/>';
- }
- }else{
- echo 'fail<br/>';
- }
- }else{
- echo 'no longer logged in, session fail<br/>';
- }
- }else{
- echo 'fail<br/>';
- }
- $remote->disconnect();
- die();
+if( !isset( $RUNTIME_NOAPPS )){
+ $RUNTIME_NOAPPS = false;
}
-// From files.php
-function zipAddDir($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(OC_Filesystem::is_file($file)){
- $tmpFile=OC_Filesystem::toTmpFile($file);
- OC_Files::$tmpFiles[]=$tmpFile;
- $zip->addFile($tmpFile,$internalDir.$filename);
- }elseif(OC_Filesystem::is_dir($file)){
- zipAddDir($file,$zip,$internalDir);
- }
- }
-}
+OC::init();
if(!function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
diff --git a/lib/config.php b/lib/config.php
index dafb37edd33..3aa69327f56 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -131,14 +131,12 @@ class OC_Config{
return true;
}
- global $SERVERROOT;
-
- if( !file_exists( "$SERVERROOT/config/config.php" )){
+ if( !file_exists( OC::$SERVERROOT."/config/config.php" )){
return false;
}
// Include the file, save the data from $CONFIG
- include( "$SERVERROOT/config/config.php" );
+ include( OC::$SERVERROOT."/config/config.php" );
if( isset( $CONFIG ) && is_array( $CONFIG )){
self::$cache = $CONFIG;
}
@@ -158,9 +156,6 @@ class OC_Config{
* Known flaws: Strings are not escaped properly
*/
public static function writeData(){
- // We need the serverroot path
- global $SERVERROOT;
-
// Create a php file ...
$content = "<?php\n\$CONFIG = array(\n";
@@ -177,10 +172,10 @@ class OC_Config{
$content .= ");\n?>\n";
// Write the file
- $result=@file_put_contents( "$SERVERROOT/config/config.php", $content );
+ $result=@file_put_contents( OC::$SERVERROOT."/config/config.php", $content );
if(!$result) {
$tmpl = new OC_Template( '', 'error', 'guest' );
- $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by setting the owner of 'config' to the user that the web server uses (".exec('whoami').")")));
+ $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by setting the owner of 'config' to the user that the web server uses (".OC_Util::checkWebserverUser().")")));
$tmpl->printPage();
exit;
}
diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php
index af8ddee1473..f770c9cb32b 100644
--- a/lib/fileproxy/quota.php
+++ b/lib/fileproxy/quota.php
@@ -44,6 +44,9 @@ class OC_FileProxy_Quota extends OC_FileProxy{
}
public function preFile_put_contents($path,$data){
+ if (is_resource($data)) {
+ $data = '';//TODO: find a way to get the length of the stream without emptying it
+ }
return (strlen($data)<$this->getFreeSpace() or $this->getFreeSpace()==0);
}
diff --git a/lib/files.php b/lib/files.php
index f1789d9c7ac..631726bf9b5 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -33,9 +33,8 @@ class OC_Files {
* @param dir $directory
*/
public static function getDirectoryContent($directory){
- global $CONFIG_DATADIRECTORY;
- if(strpos($directory,$CONFIG_DATADIRECTORY)===0){
- $directory=substr($directory,strlen($CONFIG_DATADIRECTORY));
+ if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){
+ $directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY));
}
$filesfound=true;
$content=array();
@@ -103,7 +102,7 @@ class OC_Files {
self::$tmpFiles[]=$tmpFile;
$zip->addFile($tmpFile,basename($file));
}elseif(OC_Filesystem::is_dir($file)){
- zipAddDir($file,$zip);
+ self::zipAddDir($file,$zip);
}
}
$zip->close();
@@ -114,7 +113,7 @@ class OC_Files {
exit("cannot open <$filename>\n");
}
$file=$dir.'/'.$files;
- zipAddDir($file,$zip);
+ self::zipAddDir($file,$zip);
$zip->close();
}else{
$zip=false;
@@ -157,6 +156,23 @@ class OC_Files {
}
}
+ public static function zipAddDir($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(OC_Filesystem::is_file($file)){
+ $tmpFile=OC_Filesystem::toTmpFile($file);
+ OC_Files::$tmpFiles[]=$tmpFile;
+ $zip->addFile($tmpFile,$internalDir.$filename);
+ }elseif(OC_Filesystem::is_dir($file)){
+ self::zipAddDir($file,$zip,$internalDir);
+ }
+ }
+ }
/**
* move a file or folder
*
@@ -279,16 +295,14 @@ class OC_Files {
* @param int size filesisze in bytes
*/
static function setUploadLimit($size){
- global $SERVERROOT;
- global $WEBROOT;
$size=OC_Helper::humanFileSize($size);
$size=substr($size,0,-1);//strip the B
$size=str_replace(' ','',$size); //remove the space between the size and the postfix
- $content = "ErrorDocument 404 /$WEBROOT/core/templates/404.php\n";//custom 404 error page
+ $content = "ErrorDocument 404 /".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
$content.= "php_value upload_max_filesize $size\n";//upload limit
$content.= "php_value post_max_size $size\n";
$content.= "SetEnv htaccessWorking true\n";
$content.= "Options -Indexes\n";
- @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
+ @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
}
}
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 07759b0e88c..180b056f344 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -195,7 +195,7 @@ class OC_Filestorage_Local extends OC_Filestorage{
}
private function delTree($dir) {
- error_log('del'.$dir);
+ if(defined("DEBUG") && DEBUG) {error_log('del'.$dir);}
$dirRelative=$dir;
$dir=$this->datadir.$dir;
if (!file_exists($dir)) return true;
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 76032fae204..b97fa8d784a 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -286,7 +286,6 @@ class OC_Filesystem{
return self::basicOperation('file_get_contents',$path,array('read'));
}
static public function file_put_contents($path,$data){
- error_log($data);
return self::basicOperation('file_put_contents',$path,array('create','write'),$data);
}
static public function unlink($path){
@@ -393,7 +392,6 @@ class OC_Filesystem{
}
}
static public function fromUploadedFile($tmpFile,$path){
- error_log('upload');
if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::canWrite($path) and $storage=self::getStorage($path)){
$run=true;
$exists=self::file_exists($path);
@@ -403,7 +401,6 @@ class OC_Filesystem{
if($run){
OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
}
- error_log('upload2');
if($run){
$result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
if(!$exists){
@@ -454,7 +451,7 @@ class OC_Filesystem{
* @return mixed
*/
private static function basicOperation($operation,$path,$hooks=array(),$extraParam=null){
- if(OC_FileProxy::runPreProxies($operation,$path) and self::canRead($path) and $storage=self::getStorage($path)){
+ if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and self::canRead($path) and $storage=self::getStorage($path)){
$interalPath=self::getInternalPath($path);
$run=true;
foreach($hooks as $hook){
diff --git a/lib/helper.php b/lib/helper.php
index d9b47280ff7..5b3e394cafd 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -35,25 +35,22 @@ class OC_Helper {
* Returns a url to the given app and file.
*/
public static function linkTo( $app, $file, $redirect_url=NULL, $absolute=false ){
- global $WEBROOT;
- global $SERVERROOT;
-
if( $app != '' ){
$app .= '/';
// Check if the app is in the app folder
- if( file_exists( $SERVERROOT . '/apps/'. $app.$file )){
- $urlLinkTo = $WEBROOT . '/apps/' . $app . $file;
+ if( file_exists( OC::$SERVERROOT . '/apps/'. $app.$file )){
+ $urlLinkTo = OC::$WEBROOT . '/apps/' . $app . $file;
}
else{
- $urlLinkTo = $WEBROOT . '/' . $app . $file;
+ $urlLinkTo = OC::$WEBROOT . '/' . $app . $file;
}
}
else{
- if( file_exists( $SERVERROOT . '/core/'. $file )){
- $urlLinkTo = $WEBROOT . '/core/'.$file;
+ if( file_exists( OC::$SERVERROOT . '/core/'. $file )){
+ $urlLinkTo = OC::$WEBROOT . '/core/'.$file;
}
else{
- $urlLinkTo = $WEBROOT . '/'.$file;
+ $urlLinkTo = OC::$WEBROOT . '/'.$file;
}
}
@@ -64,7 +61,7 @@ class OC_Helper {
}
if($redirect_url)
- return $urlLinkTo.'?redirect_url='.$redirect_url;
+ return $urlLinkTo.'?redirect_url='.urlencode($_SERVER["REQUEST_URI"]);
else
return $urlLinkTo;
@@ -79,18 +76,15 @@ class OC_Helper {
* Returns the path to the image.
*/
public static function imagePath( $app, $image ){
- global $SERVERROOT;
- global $WEBROOT;
-
// Check if the app is in the app folder
- if( file_exists( "$SERVERROOT/apps/$app/img/$image" )){
- return "$WEBROOT/apps/$app/img/$image";
+ if( file_exists( OC::$SERVERROOT."/apps/$app/img/$image" )){
+ return OC::$WEBROOT."/apps/$app/img/$image";
}
elseif( !empty( $app )){
- return "$WEBROOT/$app/img/$image";
+ return OC::$WEBROOT."/$app/img/$image";
}
else{
- return "$WEBROOT/core/img/$image";
+ return OC::$WEBROOT."/core/img/$image";
}
}
@@ -102,27 +96,31 @@ class OC_Helper {
* Returns the path to the image of this file type.
*/
public static function mimetypeIcon( $mimetype ){
- global $SERVERROOT;
- global $WEBROOT;
+ $alias=array('application/xml'=>'code/xml');
+// echo $mimetype;
+ if(isset($alias[$mimetype])){
+ $mimetype=$alias[$mimetype];
+// echo $mimetype;
+ }
// Replace slash with a minus
$mimetype = str_replace( "/", "-", $mimetype );
// Is it a dir?
if( $mimetype == "dir" ){
- return "$WEBROOT/core/img/places/folder.svg";
+ return OC::$WEBROOT."/core/img/filetypes/folder.png";
}
// Icon exists?
- if( file_exists( "$SERVERROOT/core/img/filetypes/$mimetype.svg" )){
- return "$WEBROOT/core/img/filetypes/$mimetype.svg";
+ if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )){
+ return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
}
//try only the first part of the filetype
$mimetype=substr($mimetype,0,strpos($mimetype,'-'));
- if( file_exists( "$SERVERROOT/core/img/filetypes/$mimetype.svg" )){
- return "$WEBROOT/core/img/filetypes/$mimetype.svg";
+ if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )){
+ return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
}
else{
- return "$WEBROOT/core/img/filetypes/file.svg";
+ return OC::$WEBROOT."/core/img/filetypes/file.png";
}
}
@@ -274,8 +272,14 @@ class OC_Helper {
return $r;
}
+ /**
+ * returns "checked"-attribut if request contains selected radio element OR if radio element is the default one -- maybe?
+ * @param string $s Name of radio-button element name
+ * @param string $v Value of current radio-button element
+ * @param string $d Value of default radio-button element
+ */
public static function init_radio($s, $v, $d) {
- if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || $v == $d)
+ if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || (!isset($_REQUEST[$s]) && $v == $d))
print "checked=\"checked\" ";
}
diff --git a/lib/installer.php b/lib/installer.php
index e6810a267db..0febb2cab46 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -55,10 +55,8 @@ class OC_Installer{
* needed to get the app working.
*/
public static function installApp( $data = array()){
- global $SERVERROOT;
-
if(!isset($data['source'])){
- error_log("No source specified when installing app");
+ if(defined("DEBUG") && DEBUG) {error_log("No source specified when installing app");}
return false;
}
@@ -66,13 +64,13 @@ class OC_Installer{
if($data['source']=='http'){
$path=tempnam(sys_get_temp_dir(),'oc_installer_');
if(!isset($data['href'])){
- error_log("No href specified when installing app from http");
+ if(defined("DEBUG") && DEBUG) {error_log("No href specified when installing app from http");}
return false;
}
copy($data['href'],$path);
}else{
if(!isset($data['path'])){
- error_log("No path specified when installing app from local file");
+ if(defined("DEBUG") && DEBUG) {error_log("No path specified when installing app from local file");}
return false;
}
$path=$data['path'];
@@ -87,7 +85,7 @@ class OC_Installer{
$zip->extractTo($extractDir);
$zip->close();
} else {
- error_log("Failed to open archive when installing app");
+ if(defined("DEBUG") && DEBUG) {error_log("Failed to open archive when installing app");}
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -97,7 +95,7 @@ class OC_Installer{
//load the info.xml file of the app
if(!is_file($extractDir.'/appinfo/info.xml')){
- error_log("App does not provide an info.xml file");
+ if(defined("DEBUG") && DEBUG) {error_log("App does not provide an info.xml file");}
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -105,11 +103,11 @@ class OC_Installer{
return false;
}
$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml');
- $basedir=$SERVERROOT.'/apps/'.$info['id'];
+ $basedir=OC::$SERVERROOT.'/apps/'.$info['id'];
//check if an app with the same id is already installed
if(self::isInstalled( $info['id'] )){
- error_log("App already installed");
+ if(defined("DEBUG") && DEBUG) {error_log("App already installed");}
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -119,7 +117,7 @@ class OC_Installer{
//check if the destination directory already exists
if(is_dir($basedir)){
- error_log("App's directory already exists");
+ if(defined("DEBUG") && DEBUG) {error_log("App's directory already exists");}
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -133,7 +131,7 @@ class OC_Installer{
//copy the app to the correct place
if(!mkdir($basedir)){
- error_log('Can\'t create app folder ('.$basedir.')');
+ if(defined("DEBUG") && DEBUG) {error_log('Can\'t create app folder ('.$basedir.')');}
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){
unlink($path);
@@ -245,14 +243,14 @@ class OC_Installer{
* If $enabled is true, apps are installed as enabled.
* If $enabled is false, apps are installed as disabled.
*/
- public static function installShippedApps( $enabled ){
- global $SERVERROOT;
- $dir = opendir( "$SERVERROOT/apps" );
+ public static function installShippedApps(){
+ $dir = opendir( OC::$SERVERROOT."/apps" );
while( false !== ( $filename = readdir( $dir ))){
- if( substr( $filename, 0, 1 ) != '.' and is_dir("$SERVERROOT/apps/$filename") ){
- if( file_exists( "$SERVERROOT/apps/$filename/appinfo/app.php" )){
+ if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$SERVERROOT."/apps/$filename") ){
+ if( file_exists( OC::$SERVERROOT."/apps/$filename/appinfo/app.php" )){
if(!OC_Installer::isInstalled($filename)){
- OC_Installer::installShippedApp($filename);
+ $info = OC_Installer::installShippedApp($filename);
+ $enabled = isset($info['default_enable']);
if( $enabled ){
OC_Appconfig::setValue($filename,'enabled','yes');
}else{
@@ -268,7 +266,7 @@ class OC_Installer{
/**
* install an app already placed in the app folder
* @param string $app id of the app to install
- * @return bool
+ * @returns array see OC_App::getAppInfo
*/
public static function installShippedApp($app){
//install the database
@@ -282,5 +280,6 @@ class OC_Installer{
}
$info=OC_App::getAppInfo(OC::$SERVERROOT."/apps/$app/appinfo/info.xml");
OC_Appconfig::setValue($app,'installed_version',$info['version']);
+ return $info;
}
}
diff --git a/lib/json.php b/lib/json.php
new file mode 100644
index 00000000000..cedf79fd7c3
--- /dev/null
+++ b/lib/json.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_JSON{
+ static protected $send_content_type_header = false;
+ /**
+ * set Content-Type header to jsonrequest
+ */
+ public static function setContentTypeHeader($type='application/json'){
+ if (!self::$send_content_type_header){
+ // We send json data
+ header( 'Content-Type: '.$type );
+ self::$send_content_type_header = true;
+ }
+ }
+
+ /**
+ * Check if the app is enabled, send json error msg if not
+ */
+ public static function checkAppEnabled($app){
+ if( !OC_App::isEnabled($app)){
+ $l = new OC_L10N('core');
+ self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled') )));
+ exit();
+ }
+ }
+
+ /**
+ * Check if the user is logged in, send json error msg if not
+ */
+ public static function checkLoggedIn(){
+ if( !OC_User::isLoggedIn()){
+ $l = new OC_L10N('core');
+ self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
+ exit();
+ }
+ }
+
+ /**
+ * Check if the user is a admin, send json error msg if not
+ */
+ public static function checkAdminUser(){
+ self::checkLoggedIn();
+ if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
+ $l = new OC_L10N('core');
+ self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
+ exit();
+ }
+ }
+
+ /**
+ * Send json error msg
+ */
+ public static function error($data = array()){
+ $data['status'] = 'error';
+ self::encodedPrint($data);
+ }
+
+ /**
+ * Send json success msg
+ */
+ public static function success($data = array()){
+ $data['status'] = 'success';
+ self::encodedPrint($data);
+ }
+
+ /**
+ * Encode and print $data in json format
+ */
+ public static function encodedPrint($data,$setContentType=true){
+ if($setContentType){
+ self::setContentTypeHeader();
+ }
+ echo json_encode($data);
+ }
+}
diff --git a/lib/l10n.php b/lib/l10n.php
index c0c32185996..54331d44ae4 100644
--- a/lib/l10n.php
+++ b/lib/l10n.php
@@ -57,7 +57,6 @@ class OC_L10N{
* language.
*/
public function __construct($app, $lang = null){
- global $SERVERROOT;
// Find the right language
if(is_null($lang)){
$lang = self::findLanguage($app);
@@ -81,9 +80,9 @@ class OC_L10N{
}
}
- if(file_exists($SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')){
+ if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')){
// Include the file, save the data from $CONFIG
- include($SERVERROOT.'/core/l10n/l10n-'.$lang.'.php');
+ include(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php');
if(isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)){
$this->localizations = array_merge($this->localizations, $LOCALIZATIONS);
}
@@ -224,17 +223,15 @@ class OC_L10N{
* @returns directory
*/
protected static function findI18nDir($app){
- global $SERVERROOT;
-
// find the i18n dir
- $i18ndir = $SERVERROOT.'/core/l10n/';
+ $i18ndir = OC::$SERVERROOT.'/core/l10n/';
if($app != ''){
// Check if the app is in the app folder
- if(file_exists($SERVERROOT.'/apps/'.$app.'/l10n/')){
- $i18ndir = $SERVERROOT.'/apps/'.$app.'/l10n/';
+ if(file_exists(OC::$SERVERROOT.'/apps/'.$app.'/l10n/')){
+ $i18ndir = OC::$SERVERROOT.'/apps/'.$app.'/l10n/';
}
else{
- $i18ndir = $SERVERROOT.'/'.$app.'/l10n/';
+ $i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';
}
}
return $i18ndir;
diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php
index 24679257199..e0570e84ea5 100644
--- a/lib/mimetypes.list.php
+++ b/lib/mimetypes.list.php
@@ -32,6 +32,8 @@ return array(
'gz'=>'application/x-gzip',
'html'=>'text/html',
'htm'=>'text/html',
+ 'ics'=>'text/calendar',
+ 'ical'=>'text/calendar',
'jpeg'=>'image/jpeg',
'jpg'=>'image/jpeg',
'js'=>'application/javascript',
diff --git a/lib/preferences.php b/lib/preferences.php
index 5af007f0223..6d8aa17afd5 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -63,7 +63,7 @@ class OC_Preferences{
* @param $user user
* @returns array with app ids
*
- * This function returns a list of all apps of the userthat have at least
+ * This function returns a list of all apps of the user that have at least
* one entry in the preferences table.
*/
public static function getApps( $user ){
@@ -140,7 +140,7 @@ class OC_Preferences{
// Check if the key does exist
$query = OC_DB::prepare( 'SELECT configvalue FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ?' );
$values=$query->execute(array($user,$app,$key))->fetchAll();
- error_log(print_r($values,true));
+ if(defined("DEBUG") && DEBUG) {error_log(print_r($values,true));}
$exists=(count($values)>0);
if( !$exists ){
diff --git a/lib/remote/cloud.php b/lib/remote/cloud.php
index 2d3dee47b1c..75d60155d06 100644
--- a/lib/remote/cloud.php
+++ b/lib/remote/cloud.php
@@ -184,7 +184,6 @@ class OC_REMOTE_CLOUD{
}
public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){
- global $WEBROOT;
$source=$sourceDir.'/'.$sourceFile;
$tmp=OC_Filesystem::toTmpFile($source);
return $this->sendTmpFile($tmp,$targetDir,$targetFile);
@@ -192,15 +191,14 @@ class OC_REMOTE_CLOUD{
public function sendTmpFile($tmp,$targetDir,$targetFile){
$token=sha1(uniqid().$tmp);
- global $WEBROOT;
$file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token;
rename($tmp,$file);
if( OC_Config::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') {
- $url = "https://". $_SERVER['SERVER_NAME'] . $WEBROOT;
+ $url = "https://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
}else{
- $url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT;
+ $url = "http://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
}
return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true);
}
}
- \ No newline at end of file
+
diff --git a/lib/setup.php b/lib/setup.php
index ebdf3ef823e..355d979dc65 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -3,7 +3,7 @@
$hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3'));
$hasMySQL = is_callable('mysql_connect');
$hasPostgreSQL = is_callable('pg_connect');
-$datadir = OC_Config::getValue('datadirectory', $SERVERROOT.'/data');
+$datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data');
$opts = array(
'hasSQLite' => $hasSQLite,
'hasMySQL' => $hasMySQL,
@@ -23,7 +23,7 @@ if(isset($_POST['install']) AND $_POST['install']=='true') {
OC_Template::printGuestPage("", "installation", $options);
}
else {
- header("Location: ".$WEBROOT.'/');
+ header("Location: ".OC::$WEBROOT.'/');
exit();
}
}
@@ -55,9 +55,6 @@ class OC_Setup {
if(empty($options['dbuser'])) {
$error[] = "$dbprettyname enter the database username.";
}
- if(empty($options['dbpass'])) {
- $error[] = "$dbprettyname enter the database password.";
- }
if(empty($options['dbname'])) {
$error[] = "$dbprettyname enter the database name.";
}
@@ -206,7 +203,7 @@ class OC_Setup {
OC_User::login($username, $password);
//guess what this does
- OC_Installer::installShippedApps(true);
+ OC_Installer::installShippedApps();
//create htaccess files for apache hosts
if (strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
@@ -235,7 +232,7 @@ class OC_Setup {
}
private static function createDBUser($name,$password,$connection) {
- // we need to create 2 accounts, one for global use and one for local user. if we don't speccify the local one,
+ // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
// the anonymous user would take precedence when there is one.
$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
@@ -270,21 +267,19 @@ class OC_Setup {
* create .htaccess files for apache hosts
*/
private static function createHtaccess() {
- $SERVERROOT=OC::$SERVERROOT;
- $WEBROOT=OC::$WEBROOT;
- $content = "ErrorDocument 404 $WEBROOT/core/templates/404.php\n";//custom 404 error page
+ $content = "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page
$content.= "<IfModule mod_php5.c>\n";
$content.= "php_value upload_max_filesize 512M\n";//upload limit
$content.= "php_value post_max_size 512M\n";
$content.= "SetEnv htaccessWorking true\n";
$content.= "</IfModule>\n";
$content.= "Options -Indexes\n";
- @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
+ @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
$content = "deny from all\n";
$content.= "IndexIgnore *";
- file_put_contents(OC_Config::getValue('datadirectory', $SERVERROOT.'/data').'/.htaccess', $content);
- file_put_contents(OC_Config::getValue('datadirectory', $SERVERROOT.'/data').'/index.html', '');
+ file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
+ file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
}
}
diff --git a/lib/template.php b/lib/template.php
index adedd4f901a..a293e63b437 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -124,18 +124,15 @@ class OC_Template{
* "admin".
*/
public function __construct( $app, $name, $renderas = "" ){
- // Global vars we need
- global $SERVERROOT;
-
// Get the right template folder
- $template = "$SERVERROOT/core/templates/";
+ $template = OC::$SERVERROOT."/core/templates/";
if( $app != "" ){
// Check if the app is in the app folder
- if( file_exists( "$SERVERROOT/apps/$app/templates/" )){
- $template = "$SERVERROOT/apps/$app/templates/";
+ if( file_exists( OC::$SERVERROOT."/apps/$app/templates/" )){
+ $template = OC::$SERVERROOT."/apps/$app/templates/";
}
else{
- $template = "$SERVERROOT/$app/templates/";
+ $template = OC::$SERVERROOT."/$app/templates/";
}
}
@@ -222,9 +219,6 @@ class OC_Template{
* will produce a full page.
*/
public function fetchPage(){
- // global Data we need
- global $WEBROOT;
- global $SERVERROOT;
$data = $this->_fetch();
if( $this->renderas ){
@@ -247,25 +241,25 @@ class OC_Template{
// Add the css and js files
foreach(OC_Util::$scripts as $script){
- if(is_file("$SERVERROOT/apps/$script.js" )){
- $page->append( "jsfiles", "$WEBROOT/apps/$script.js" );
+ if(is_file(OC::$SERVERROOT."/apps/$script.js" )){
+ $page->append( "jsfiles", OC::$WEBROOT."/apps/$script.js" );
}
- elseif(is_file("$SERVERROOT/$script.js" )){
- $page->append( "jsfiles", "$WEBROOT/$script.js" );
+ elseif(is_file(OC::$SERVERROOT."/$script.js" )){
+ $page->append( "jsfiles", OC::$WEBROOT."/$script.js" );
}
else{
- $page->append( "jsfiles", "$WEBROOT/core/$script.js" );
+ $page->append( "jsfiles", OC::$WEBROOT."/core/$script.js" );
}
}
foreach(OC_Util::$styles as $style){
- if(is_file("$SERVERROOT/apps/$style.css" )){
- $page->append( "cssfiles", "$WEBROOT/apps/$style.css" );
+ if(is_file(OC::$SERVERROOT."/apps/$style.css" )){
+ $page->append( "cssfiles", OC::$WEBROOT."/apps/$style.css" );
}
- elseif(is_file("$SERVERROOT/$style.css" )){
- $page->append( "cssfiles", "$WEBROOT/$style.css" );
+ elseif(is_file(OC::$SERVERROOT."/$style.css" )){
+ $page->append( "cssfiles", OC::$WEBROOT."/$style.css" );
}
else{
- $page->append( "cssfiles", "$WEBROOT/core/$style.css" );
+ $page->append( "cssfiles", OC::$WEBROOT."/core/$style.css" );
}
}
diff --git a/lib/user.php b/lib/user.php
index 72dfd7970bb..241d9aa8b10 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -194,16 +194,22 @@ class OC_User {
if( $run ){
$uid=self::checkPassword( $uid, $password );
if($uid){
- $_SESSION['user_id'] = $uid;
OC_Crypt::init($uid,$password);
- OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid ));
- return true;
- }else{
- return false;
+ return self::setUserId($uid);
}
- }else{
- return false;
}
+ return false;
+ }
+
+ /**
+ * @brief Sets user id for session and triggers emit
+ * @returns true
+ *
+ */
+ public static function setUserId($uid) {
+ $_SESSION['user_id'] = $uid;
+ OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid ));
+ return true;
}
/**
@@ -215,7 +221,7 @@ class OC_User {
public static function logout(){
OC_Hook::emit( "OC_User", "logout", array());
$_SESSION['user_id'] = false;
- OC_User::unsetUsernameInCookie();
+ OC_User::unsetMagicInCookie();
return true;
}
@@ -341,21 +347,22 @@ class OC_User {
* @brief Set cookie value to use in next page load
* @param string $username username to be set
*/
- public static function setUsernameInCookie($username, $password){
- setcookie("oc_username", $username, time()+60*60*24*15);
- setcookie("oc_password", $password, time()+60*60*24*15);
- setcookie("oc_remember_login", true, time()+60*60*24*15);
+ public static function setMagicInCookie($username, $token){
+ $secure_cookie = OC_Config::getValue("forcessl", false);
+ setcookie("oc_username", $username, time()+60*60*24*15, '', '', $secure_cookie);
+ setcookie("oc_token", $token, time()+60*60*24*15, '', '', $secure_cookie);
+ setcookie("oc_remember_login", true, time()+60*60*24*15, '', '', $secure_cookie);
}
/**
* @brief Remove cookie for "remember username"
*/
- public static function unsetUsernameInCookie(){
+ public static function unsetMagicInCookie(){
unset($_COOKIE["oc_username"]);
- unset($_COOKIE["oc_password"]);
+ unset($_COOKIE["oc_token"]);
unset($_COOKIE["oc_remember_login"]);
setcookie("oc_username", NULL, -1);
- setcookie("oc_password", NULL, -1);
+ setcookie("oc_token", NULL, -1);
setcookie("oc_remember_login", NULL, -1);
}
}
diff --git a/lib/util.php b/lib/util.php
index f4ca879a9bc..4920d13914d 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -16,19 +16,15 @@ class OC_Util {
return false;
}
- // Global Variables
- global $SERVERROOT;
- global $CONFIG_DATADIRECTORY;
-
- $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
- $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" );
+ $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
+ $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
// Create root dir
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
$success=@mkdir($CONFIG_DATADIRECTORY_ROOT);
if(!$success) {
$tmpl = new OC_Template( '', 'error', 'guest' );
- $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory ($CONFIG_DATADIRECTORY_ROOT)",'hint'=>"You can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (".exec('whoami').")")));
+ $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by setting the owner of '".OC::$SERVERROOT."' to the user that the web server uses (".OC_Util::checkWebserverUser().")")));
$tmpl->printPage();
exit;
}
@@ -57,9 +53,9 @@ class OC_Util {
$sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'));
OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/');
- $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root";
- if( !is_dir( $CONFIG_DATADIRECTORY )){
- mkdir( $CONFIG_DATADIRECTORY, 0755, true );
+ OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
+ if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
+ mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true );
}
// TODO: find a cool way for doing this
@@ -94,7 +90,15 @@ class OC_Util {
* @return array
*/
public static function getVersion(){
- return array(1,90,0);
+ return array(2,90,0);
+ }
+
+ /**
+ * get the current installed version string of ownCloud
+ * @return string
+ */
+ public static function getVersionString(){
+ return '3 alpha 1';
}
/**
@@ -193,11 +197,8 @@ class OC_Util {
* @return array arrays with error messages and hints
*/
public static function checkServer(){
- global $SERVERROOT;
- global $CONFIG_DATADIRECTORY;
-
- $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
- $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" );
+ $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
+ $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
$CONFIG_INSTALLED = OC_Config::getValue( "installed", false );
$errors=array();
@@ -207,28 +208,21 @@ class OC_Util {
}
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
$CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" );
-
- //try to get the username the httpd server runs on, used in hints
- $stat=stat($_SERVER['DOCUMENT_ROOT']);
- if(is_callable('posix_getpwuid')){
- $serverUser=posix_getpwuid($stat['uid']);
- $serverUser='\''.$serverUser['name'].'\'';
- }else{
- $serverUser='\'www-data\' for ubuntu/debian';//TODO: try to detect the distro and give a guess based on that
- }
+ $serverUser=OC_Util::checkWebserverUser();
//common hint for all file permissons error messages
$permissionsHint="Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ($serverUser)";
//check for correct file permissions
if(!stristr(PHP_OS, 'WIN')){
+ $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users.";
$prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,-1)!='0'){
OC_Helper::chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
clearstatcache();
$prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
if(substr($prems,2,1)!='0'){
- $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>','hint'=>$permissionsHint);
+ $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable for other users<br/>','hint'=>$permissionsModHint);
}
}
if( OC_Config::getValue( "enablebackup", false )){
@@ -238,19 +232,100 @@ class OC_Util {
clearstatcache();
$prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3);
if(substr($prems,2,1)!='0'){
- $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>','hint'=>$permissionsHint);
+ $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable for other users<br/>','hint'=>$permissionsModHint);
}
}
}
}else{
- //TODO: premisions checks for windows hosts
+ //TODO: permissions checks for windows hosts
}
if(is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)){
$errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud<br/>','hint'=>$permissionsHint);
}
- //TODO: check for php modules
+ // check if all required php modules are present
+ if(!class_exists('ZipArchive')){
+ $errors[]=array('error'=>'PHP module zip not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
+ }
+
+ if(!function_exists('mb_detect_encoding')){
+ $errors[]=array('error'=>'PHP module mb multibyte not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
+ }
+ if(!function_exists('ctype_digit')){
+ $errors[]=array('error'=>'PHP module ctype is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.');
+ }
return $errors;
}
+
+ public static function displayLoginPage($parameters = array()){
+ if(isset($_COOKIE["username"])){
+ $parameters["username"] = $_COOKIE["username"];
+ } else {
+ $parameters["username"] = '';
+ }
+ OC_Template::printGuestPage("", "login", $parameters);
+ }
+
+ /**
+ * Try to get the username the httpd server runs on, used in hints
+ */
+ public static function checkWebserverUser(){
+ $stat=stat($_SERVER['DOCUMENT_ROOT']);
+ if(is_callable('posix_getpwuid')){
+ $serverUser=posix_getpwuid($stat['uid']);
+ $serverUser='\''.$serverUser['name'].'\'';
+ }elseif(exec('whoami')){
+ $serverUser=exec('whoami');
+ }else{
+ $serverUser='\'www-data\' for ubuntu/debian'; //TODO: try to detect the distro and give a guess based on that
+ }
+ return $serverUser;
+ }
+
+
+ /**
+ * Check if the app is enabled, send json error msg if not
+ */
+ public static function checkAppEnabled($app){
+ if( !OC_App::isEnabled($app)){
+ header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true));
+ exit();
+ }
+ }
+
+ /**
+ * Check if the user is logged in, redirects to home if not
+ */
+ public static function checkLoggedIn(){
+ // Check if we are a user
+ if( !OC_User::isLoggedIn()){
+ header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true));
+ exit();
+ }
+ }
+
+ /**
+ * Check if the user is a admin, redirects to home if not
+ */
+ public static function checkAdminUser(){
+ // Check if we are a user
+ self::checkLoggedIn();
+ if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
+ header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true));
+ exit();
+ }
+ }
+
+ /**
+ * Redirect to the user default page
+ */
+ public static function redirectToDefaultPage(){
+ if(isset($_REQUEST['redirect_url'])) {
+ header( 'Location: '.$_REQUEST['redirect_url']);
+ } else {
+ header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php'));
+ }
+ exit();
+ }
}