Skip to content
Snippets Groups Projects
Select Git revision
  • 4d87276f4be55419189fb23d3c3c13f00c19f006
  • master default protected
2 results

console.php

Blame
  • util.php 13.90 KiB
    <?php
    
    /**
     * Class for utility functions
     *
     */
    class OC_Util {
    	public static $scripts=array();
    	public static $styles=array();
    	public static $headers=array();
    	private static $rootMounted=false;
    	private static $fsSetup=false;
    
    	// Can be set up
    	public static function setupFS( $user = "", $root = "files" ){ // configure the initial filesystem based on the configuration
    		if(self::$fsSetup){ //setting up the filesystem twice can only lead to trouble
    			return false;
    		}
    
    		$CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
    		$CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
    
    		// Check if config folder is writable.
    		if(!is_writable(OC::$SERVERROOT."/config/")) {
    			$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 giving the webserver user write access to the config directory in owncloud")));
    			$tmpl->printPage();
    			exit;
    		}
    
    		// Check if apps folder is writable.
    		if(OC_Config::getValue('writable_appsdir', true) && !is_writable(OC::$SERVERROOT."/apps/")) {
    			$tmpl = new OC_Template( '', 'error', 'guest' );
    			$tmpl->assign('errors',array(1=>array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
    			$tmpl->printPage();
    			exit;
    		}
    		
    		
    		// 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 giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' ")));
    				$tmpl->printPage();
    				exit;
      			}
    		}
    
    		// If we are not forced to load a specific user we load the one that is logged in
    		if( $user == "" && OC_User::isLoggedIn()){
    			$user = OC_User::getUser();
    		}
    
    		//first set up the local "root" storage
    		if(!self::$rootMounted){
    			OC_Filesystem::mount('OC_Filestorage_Local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
    			self::$rootMounted=true;
    		}
    		if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
    
    			OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
    			if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
    				mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true );
    			}
    
    			//jail the user into his "home" directory
    			OC_Filesystem::init('/'.$user.'/'.$root);
    			$quotaProxy=new OC_FileProxy_Quota();