Use OC_CONFIG where possible

remotes/origin/stable
Jakob Sack 2011-04-16 12:18:42 +07:00
parent 77fe7240f0
commit 8465f76e7e
6 changed files with 101 additions and 102 deletions

@ -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" => ""
);
?> ?>

@ -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 ));
} }
} }
?> ?>

@ -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; // TODO: we should get rid of this one, too
$CONFIG_ENABLEBACKUP=false; // WARNING: to make everything even more confusing, DATADIRECTORY is a var that
$CONFIG_DATEFORMAT='j M Y G:i'; // changes and DATATIRECTORY_ROOT stays the same, but is set by
$CONFIG_FILESYSTEM=array(); // "datadirectory". Any questions?
$CONFIG_DATADIRECTORY = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
// include the generated configfile
@include_once($SERVERROOT.'/config/config.php');
$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);

@ -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";

@ -236,7 +236,7 @@ class OC_REMOTE_CLOUD{
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;

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