Use OC_CONFIG where possible

This commit is contained in:
Jakob Sack 2011-04-16 12:18:42 +02:00
parent 77fe7240f0
commit 8465f76e7e
6 changed files with 99 additions and 100 deletions

View File

@ -1,12 +1,15 @@
<?php <?php
$CONFIG_ADMINLOGIN='admin-username';
$CONFIG_ADMINPASSWORD='password'; $CONFIG = array(
$CONFIG_DATADIRECTORY='write/absolute-drectory/path/here/'; "installed" => false,
$CONFIG_HTTPFORCESSL=false; "dbtype" => "sqlite",
$CONFIG_DATEFORMAT='j M Y G:i'; "dbname" => "owncloud",
$CONFIG_DBHOST='localhost'; "dbuser" => "",
$CONFIG_DBNAME='owncloud-db-name'; "dbpassword" => "",
$CONFIG_DBUSER='user-name'; "dbhost" => "",
$CONFIG_DBPASSWORD='password'; "dbtableprefix" => "",
$CONFIG_DBTABLEPREFIX = 'oc_'; "forcessl" => false,
"enablebackup" => false,
// "datadirectory" => ""
);
?> ?>

View File

@ -24,29 +24,31 @@
require_once( 'lib/base.php' ); require_once( 'lib/base.php' );
require_once( 'appconfig.php' ); require_once( 'appconfig.php' );
require_once( 'template.php' ); require_once( 'template.php' );
var_dump( $_SESSION );
//exit;
if( OC_USER::isLoggedIn()){ if( OC_USER::isLoggedIn()){
if( $_GET["logout"] ){ if( $_GET["logout"] ){
OC_USER::logout(); OC_USER::logout();
OC_TEMPLATE::printGuestPage( "", "logout" ); OC_TEMPLATE::printGuestPage( "", "logout" );
} }
else{ else{
header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" ));
exit(); exit();
} }
} }
else{ else{
if( OC_USER::login( $_POST["user"], $_POST["password"] )){ if( OC_USER::login( $_POST["user"], $_POST["password"] )){
header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" ));
exit(); exit();
} }
else{ else{
$error = false; $error = false;
// Say "bad login" in case the user wanted to login // Say "bad login" in case the user wanted to login
if( $_POST["user"] && $_POST["password"] ){ if( $_POST["user"] && $_POST["password"] ){
$error = true; $error = true;
} }
OC_TEMPLATE::printGuestPage( "", "login", array( "error" => $error )); OC_TEMPLATE::printGuestPage( "", "login", array( "error" => $error ));
} }
} }
?> ?>

View File

@ -55,24 +55,21 @@ if( !isset( $RUNTIME_NOAPPS )){
$RUNTIME_NOAPPS = false; $RUNTIME_NOAPPS = false;
} }
// define default config values // Doing the config stuff first
$CONFIG_DATADIRECTORY=$SERVERROOT.'/data'; require_once('config.php');
$CONFIG_BACKUPDIRECTORY=$SERVERROOT.'/backup';
$CONFIG_HTTPFORCESSL=false;
$CONFIG_ENABLEBACKUP=false;
$CONFIG_DATEFORMAT='j M Y G:i';
$CONFIG_FILESYSTEM=array();
// include the generated configfile // TODO: we should get rid of this one, too
@include_once($SERVERROOT.'/config/config.php'); // 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" );
$CONFIG_DATADIRECTORY_ROOT=$CONFIG_DATADIRECTORY;// store this in a seperate variable so we can change the data directory to jail users.
// redirect to https site if configured // redirect to https site if configured
if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){ if( OC_CONFIG::getValue( "forcessl", false )){
if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') { if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') {
$url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: $url"); header("Location: $url");
exit; exit();
} }
} }
@ -85,7 +82,6 @@ require_once('filesystem.php');
require_once('filestorage.php'); require_once('filestorage.php');
require_once('fileobserver.php'); require_once('fileobserver.php');
require_once('log.php'); require_once('log.php');
require_once('config.php');
require_once('user.php'); require_once('user.php');
require_once('group.php'); require_once('group.php');
require_once('ocs.php'); require_once('ocs.php');
@ -95,11 +91,8 @@ require_once('plugin.php');
OC_PLUGIN::loadPlugins( "" ); OC_PLUGIN::loadPlugins( "" );
if(!isset($CONFIG_BACKEND)){ OC_USER::setBackend( OC_CONFIG::getValue( "userbackend", "database" ));
$CONFIG_BACKEND='database'; OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" ));
}
OC_USER::setBackend( $CONFIG_BACKEND );
OC_GROUP::setBackend( $CONFIG_BACKEND );
// Set up file system unless forbidden // Set up file system unless forbidden
if( !$RUNTIME_NOSETUPFS ){ if( !$RUNTIME_NOSETUPFS ){
@ -138,11 +131,10 @@ class OC_UTIL {
// Global Variables // Global Variables
global $SERVERROOT; global $SERVERROOT;
global $CONFIG_DATADIRECTORY_ROOT;
global $CONFIG_DATADIRECTORY; global $CONFIG_DATADIRECTORY;
global $CONFIG_BACKUPDIRECTORY;
global $CONFIG_ENABLEBACKUP; $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
global $CONFIG_FILESYSTEM; $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" );
// Create root dir // Create root dir
if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
@ -157,7 +149,7 @@ class OC_UTIL {
if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
//first set up the local "root" storage and the backupstorage if needed //first set up the local "root" storage and the backupstorage if needed
$rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY)); $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY));
if($CONFIG_ENABLEBACKUP){ if( OC_CONFIG::getValue( "enablebackup", false )){
// This creates the Directorys recursively // This creates the Directorys recursively
if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){
mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true );
@ -173,18 +165,19 @@ class OC_UTIL {
mkdir( $CONFIG_DATADIRECTORY, 0755, true ); mkdir( $CONFIG_DATADIRECTORY, 0755, true );
} }
//set up the other storages according to the system settings // TODO: find a cool way for doing this
foreach($CONFIG_FILESYSTEM as $storageConfig){ // //set up the other storages according to the system settings
if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){ // foreach($CONFIG_FILESYSTEM as $storageConfig){
$arguments=$storageConfig; // if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){
unset($arguments['type']); // $arguments=$storageConfig;
unset($arguments['mountpoint']); // unset($arguments['type']);
$storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments); // unset($arguments['mountpoint']);
if($storage){ // $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments);
OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']); // if($storage){
} // OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']);
} // }
} // }
// }
//jail the user into his "home" directory //jail the user into his "home" directory
OC_FILESYSTEM::chroot("/$user/$root"); OC_FILESYSTEM::chroot("/$user/$root");
@ -232,9 +225,10 @@ class OC_UTIL {
*/ */
public static function checkServer(){ public static function checkServer(){
global $SERVERROOT; global $SERVERROOT;
global $CONFIG_DATADIRECTORY_ROOT; global $CONFIG_DATADIRECTORY;
global $CONFIG_BACKUPDIRECTORY;
global $CONFIG_ENABLEBACKUP; $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );;
$CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" );
$CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false );
$error=''; $error='';
if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){
@ -266,7 +260,7 @@ class OC_UTIL {
$error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>'; $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>';
} }
} }
if($CONFIG_ENABLEBACKUP){ if( OC_CONFIG::getValue( "enablebackup", false )){
$prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
if(substr($prems,-1)!='0'){ if(substr($prems,-1)!='0'){
OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770); OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770);

View File

@ -172,7 +172,7 @@ class OC_CONFIG{
} }
else{ else{
$value = str_replace( "'", "\\'", $value ); $value = str_replace( "'", "\\'", $value );
$configContent .= "\"$key\" => '$value',\n"; $content .= "\"$key\" => '$value',\n";
} }
} }
$content .= ");\n?>\n"; $content .= ");\n?>\n";

View File

@ -3,22 +3,22 @@
/** /**
* ownCloud * ownCloud
* *
* @author Frank Karlitschek * @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org * @copyright 2010 Frank Karlitschek karlitschek@kde.org
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 3 of the License, or any later version. * version 3 of the License, or any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
* *
* You should have received a copy of the GNU Affero General Public * You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
/** /**
@ -27,7 +27,7 @@
*/ */
class OC_CONNECT{ class OC_CONNECT{
static private $clouds=array(); static private $clouds=array();
static function connect($path,$user,$password){ static function connect($path,$user,$password){
$cloud=new OC_REMOTE_CLOUD($path,$user,$password); $cloud=new OC_REMOTE_CLOUD($path,$user,$password);
if($cloud->connected){ if($cloud->connected){
@ -48,7 +48,7 @@ class OC_REMOTE_CLOUD{
private $path; private $path;
private $connected=false; private $connected=false;
private $cookiefile=false; private $cookiefile=false;
/** /**
* make an api call to the remote cloud * make an api call to the remote cloud
* @param string $action * @param string $action
@ -72,8 +72,8 @@ class OC_REMOTE_CLOUD{
curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($parameters)); curl_setopt($ch,CURLOPT_POST,count($parameters));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result=curl_exec($ch); $result=curl_exec($ch);
$result=trim($result); $result=trim($result);
@ -86,12 +86,12 @@ class OC_REMOTE_CLOUD{
return false; return false;
} }
} }
public function __construct($path,$user,$password){ public function __construct($path,$user,$password){
$this->path=$path; $this->path=$path;
$this->connected=$this->apiCall('login',array('username'=>$user,'password'=>$password)); $this->connected=$this->apiCall('login',array('username'=>$user,'password'=>$password));
} }
/** /**
* check if we are stull logged in on the remote cloud * check if we are stull logged in on the remote cloud
* *
@ -102,14 +102,14 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('checklogin'); return $this->apiCall('checklogin');
} }
public function __get($name){ public function __get($name){
switch($name){ switch($name){
case 'connected': case 'connected':
return $this->connected; return $this->connected;
} }
} }
/** /**
* disconnect from the remote cloud * disconnect from the remote cloud
* *
@ -121,7 +121,7 @@ class OC_REMOTE_CLOUD{
} }
$this->cookiefile=false; $this->cookiefile=false;
} }
/** /**
* create a new file or directory * create a new file or directory
* @param string $dir * @param string $dir
@ -134,7 +134,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('new',array('dir'=>$dir,'name'=>$name,'type'=>$type),true); return $this->apiCall('new',array('dir'=>$dir,'name'=>$name,'type'=>$type),true);
} }
/** /**
* deletes a file or directory * deletes a file or directory
* @param string $dir * @param string $dir
@ -146,7 +146,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('delete',array('dir'=>$dir,'file'=>$name),true); return $this->apiCall('delete',array('dir'=>$dir,'file'=>$name),true);
} }
/** /**
* moves a file or directory * moves a file or directory
* @param string $sorceDir * @param string $sorceDir
@ -160,7 +160,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('move',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); return $this->apiCall('move',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true);
} }
/** /**
* copies a file or directory * copies a file or directory
* @param string $sorceDir * @param string $sorceDir
@ -174,7 +174,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('copy',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); return $this->apiCall('copy',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true);
} }
/** /**
* get a file tree * get a file tree
* @param string $dir * @param string $dir
@ -185,7 +185,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('gettree',array('dir'=>$dir),true); return $this->apiCall('gettree',array('dir'=>$dir),true);
} }
/** /**
* get the files inside a directory of the remote cloud * get the files inside a directory of the remote cloud
* @param string $dir * @param string $dir
@ -196,7 +196,7 @@ class OC_REMOTE_CLOUD{
} }
return $this->apiCall('getfiles',array('dir'=>$dir),true); return $this->apiCall('getfiles',array('dir'=>$dir),true);
} }
/** /**
* get a remove file and save it in a temporary file and return the path of the temporary file * get a remove file and save it in a temporary file and return the path of the temporary file
* @param string $dir * @param string $dir
@ -215,28 +215,28 @@ class OC_REMOTE_CLOUD{
$fp=fopen($tmpfile,'w+'); $fp=fopen($tmpfile,'w+');
$url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file"; $url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file";
curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile);
curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch); curl_exec($ch);
fclose($fp); fclose($fp);
curl_close($ch); curl_close($ch);
return $tmpfile; return $tmpfile;
} }
public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){ public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){
global $WEBROOT; global $WEBROOT;
$source=$sourceDir.'/'.$sourceFile; $source=$sourceDir.'/'.$sourceFile;
$tmp=OC_FILESYSTEM::toTmpFile($source); $tmp=OC_FILESYSTEM::toTmpFile($source);
return $this->sendTmpFile($tmp,$targetDir,$targetFile); return $this->sendTmpFile($tmp,$targetDir,$targetFile);
} }
public function sendTmpFile($tmp,$targetDir,$targetFile){ public function sendTmpFile($tmp,$targetDir,$targetFile){
$token=sha1(uniqid().$tmp); $token=sha1(uniqid().$tmp);
global $WEBROOT; global $WEBROOT;
$file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token; $file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token;
rename($tmp,$file); rename($tmp,$file);
if((isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { 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'] . $WEBROOT;
}else{ }else{
$url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT; $url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT;

View File

@ -20,7 +20,7 @@
* *
*/ */
if( !$CONFIG_INSTALLED ){ if( !OC_CONFIG::getValue( "installed", false )){
$_SESSION['user_id'] = ''; $_SESSION['user_id'] = '';
} }