Ejemplo n.º 1
0
 /**
  * Log exception
  *
  * @internal param Exception $e exception
  */
 public function logException($e)
 {
     $exceptionClass = get_class($e);
     if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') {
         \OCP\Util::logException($this->appName, $e);
     }
 }
Ejemplo n.º 2
0
 /**
  * Log exception
  *
  * @internal param Exception $e exception
  */
 public function logException($e)
 {
     $exceptionClass = get_class($e);
     $level = \OCP\Util::FATAL;
     if (isset($this->nonFatalExceptions[$exceptionClass])) {
         $level = \OCP\Util::DEBUG;
     }
     \OCP\Util::logException($this->appName, $e, $level);
 }
Ejemplo n.º 3
0
 /**
  * If an Exception is being caught, return a JSON error response with
  * a suitable status code
  * @param Controller $controller the controller that is being called
  * @param string $methodName the name of the method that will be called on
  *                           the controller
  * @param \Exception $exception the thrown exception
  * @return Response a Response object
  */
 public function afterException($controller, $methodName, \Exception $exception)
 {
     \OCP\Util::writeLog('contacts', __METHOD__ . ' method: ' . $methodName, \OCP\Util::DEBUG);
     // If there's no proper status code associated, set it to 500.
     $response = new JSONResponse();
     if ($exception->getCode() < 100) {
         $response->setStatus(HttpStatus::STATUS_INTERNAL_SERVER_ERROR);
     } else {
         $response->setStatus($exception->getCode());
     }
     $response->setErrorMessage($exception->getMessage());
     \OCP\Util::logException('contacts', $exception);
     return $response;
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @SSOCORS
  */
 public function getFileList($dir = null, $sortby = 'name', $sort = false)
 {
     \OCP\JSON::checkLoggedIn();
     \OC::$server->getSession()->close();
     // Load the files
     $dir = $dir ? (string) $dir : '';
     $dir = \OC\Files\Filesystem::normalizePath($dir);
     try {
         $dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
         if (!$dirInfo || !$dirInfo->getType() === 'dir') {
             header('HTTP/1.0 404 Not Found');
             exit;
         }
         $data = array();
         $baseUrl = \OCP\Util::linkTo('files', 'index.php') . '?dir=';
         $permissions = $dirInfo->getPermissions();
         $sortDirection = $sort === 'desc';
         $mimetypeFilters = '';
         $files = [];
         if (is_array($mimetypeFilters) && count($mimetypeFilters)) {
             $mimetypeFilters = array_unique($mimetypeFilters);
             if (!in_array('httpd/unix-directory', $mimetypeFilters)) {
                 $mimetypeFilters[] = 'httpd/unix-directory';
             }
             foreach ($mimetypeFilters as $mimetypeFilter) {
                 $files = array_merge($files, \OCA\Files\Helper::getFiles($dir, $sortby, $sortDirection, $mimetypeFilter));
             }
             $files = \OCA\Files\Helper::sortFiles($files, $sortby, $sortDirection);
         } else {
             $files = \OCA\Files\Helper::getFiles($dir, $sortby, $sortDirection);
         }
         $files = \OCA\Files\Helper::populateTags($files);
         $data['directory'] = $dir;
         $data['files'] = \OCA\Files\Helper::formatFileInfos($files);
         $data['permissions'] = $permissions;
         return new DataResponse(array('data' => $data, 'status' => 'success'));
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         \OCP\Util::logException('files', $e);
         return new DataResponse(array('data' => array('exception' => '\\OCP\\Files\\StorageNotAvailableException', 'message' => 'Storage not available'), 'status' => 'error'));
     } catch (\OCP\Files\StorageInvalidException $e) {
         \OCP\Util::logException('files', $e);
         return new DataResponse(array('data' => array('exception' => '\\OCP\\Files\\StorageInvalidException', 'message' => 'Storage invalid'), 'status' => 'error'));
     } catch (\Exception $e) {
         \OCP\Util::logException('files', $e);
         return new DataResponse(array('data' => array('exception' => '\\Exception', 'message' => 'Unknown error'), 'status' => 'error'));
     }
 }
Ejemplo n.º 5
0
 /**
  * Check the database version
  *
  * @return array errors array
  */
 public static function checkDatabaseVersion()
 {
     $l = \OC::$server->getL10N('lib');
     $errors = array();
     $dbType = \OC_Config::getValue('dbtype', 'sqlite');
     if ($dbType === 'pgsql') {
         // check PostgreSQL version
         try {
             $result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
             $data = $result->fetchRow();
             if (isset($data['server_version'])) {
                 $version = $data['server_version'];
                 if (version_compare($version, '9.0.0', '<')) {
                     $errors[] = array('error' => $l->t('PostgreSQL >= 9 required'), 'hint' => $l->t('Please upgrade your database version'));
                 }
             }
         } catch (\Doctrine\DBAL\DBALException $e) {
             \OCP\Util::logException('core', $e);
             $errors[] = array('error' => $l->t('Error occurred while checking PostgreSQL version'), 'hint' => $l->t('Please make sure you have PostgreSQL >= 9 or' . ' check the logs for more information about the error'));
         }
     }
     return $errors;
 }
Ejemplo n.º 6
0
 protected static function handleLogin()
 {
     OC_App::loadApps(array('prelogin'));
     $error = array();
     $messages = [];
     try {
         // auth possible via apache module?
         if (OC::tryApacheAuth()) {
             $error[] = 'apacheauthfailed';
         } elseif (OC::tryRememberLogin()) {
             $error[] = 'invalidcookie';
         } elseif (OC::tryFormLogin()) {
             $error[] = 'invalidpassword';
         }
     } catch (\OC\User\LoginException $e) {
         $messages[] = $e->getMessage();
     } catch (\Exception $ex) {
         \OCP\Util::logException('handleLogin', $ex);
         // do not disclose information. show generic error
         $error[] = 'internalexception';
     }
     OC_Util::displayLoginPage(array_unique($error), $messages);
 }
Ejemplo n.º 7
0
	/**
	 * runs the update actions in maintenance mode, does not upgrade the source files
	 * except the main .htaccess file
	 *
	 * @return bool true if the operation succeeded, false otherwise
	 */
	public function upgrade() {
		$wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);

		if(!$wasMaintenanceModeEnabled) {
			$this->config->setSystemValue('maintenance', true);
			$this->emit('\OC\Updater', 'maintenanceEnabled');
		}

		$installedVersion = $this->config->getSystemValue('version', '0.0.0');
		$currentVersion = implode('.', \OC_Util::getVersion());
		if ($this->log) {
			$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
		}

		$success = true;
		try {
			$this->doUpgrade($currentVersion, $installedVersion);
		} catch (\Exception $exception) {
			\OCP\Util::logException('update', $exception);
			$this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
			$success = false;
		}

		$this->emit('\OC\Updater', 'updateEnd', array($success));

		if(!$wasMaintenanceModeEnabled && $success) {
			$this->config->setSystemValue('maintenance', false);
			$this->emit('\OC\Updater', 'maintenanceDisabled');
		} else {
			$this->emit('\OC\Updater', 'maintenanceActive');
		}

		return $success;
	}
Ejemplo n.º 8
0
 * 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 Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Show warning if a PHP version below 5.4.0 is used, this has to happen here
// because base.php will already use 5.4 syntax.
if (version_compare(PHP_VERSION, '5.4.0') === -1) {
    echo 'This version of ownCloud requires at least PHP 5.4.0<br/>';
    echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
    return;
}
try {
    require_once 'lib/base.php';
    OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) {
    \OCP\Util::logException('index', $ex);
    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    OC_Template::printExceptionErrorPage($ex);
} catch (\OC\HintException $ex) {
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    OC_Template::printErrorPage($ex->getMessage(), $ex->getHint());
} catch (Exception $ex) {
    \OCP\Util::logException('index', $ex);
    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
    OC_Template::printExceptionErrorPage($ex);
}
Ejemplo n.º 9
0
 public function writeBack($tmpFile)
 {
     if (!isset(self::$tmpFiles[$tmpFile])) {
         return false;
     }
     try {
         $this->getConnection()->putObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey(self::$tmpFiles[$tmpFile]), 'SourceFile' => $tmpFile, 'ContentType' => \OC::$server->getMimeTypeDetector()->detect($tmpFile), 'ContentLength' => filesize($tmpFile)));
         $this->testTimeout();
         unlink($tmpFile);
     } catch (S3Exception $e) {
         \OCP\Util::logException('files_external', $e);
         return false;
     }
 }
Ejemplo n.º 10
0
            }
        }
    } catch (\Exception $e) {
        \OCP\Util::writeLog('filefilter', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
        return false;
    }
    //将tags赋值给files数组
    if (isset($entries)) {
        foreach ($entries as $fileId => $fileTags) {
            $filesById[$fileId]['tags'] = $fileTags;
        }
    }
    //将最后值变为filelist
    foreach ($filesById as $val) {
        $filelist[] = $val;
    }
    $data['directory'] = $dir;
    $data['files'] = $filelist;
    //\OCA\Files\Helper::formatFileInfos($files);
    $data['permissions'] = (int) $permissions;
    OCP\JSON::success(array('data' => $data));
} catch (\OCP\Files\StorageNotAvailableException $e) {
    \OCP\Util::logException('files', $e);
    OCP\JSON::error(array('data' => array('exception' => '\\OCP\\Files\\StorageNotAvailableException', 'message' => $l->t('Storage not available'))));
} catch (\OCP\Files\StorageInvalidException $e) {
    \OCP\Util::logException('files', $e);
    OCP\JSON::error(array('data' => array('exception' => '\\OCP\\Files\\StorageInvalidException', 'message' => $l->t('Storage invalid'))));
} catch (\Exception $e) {
    \OCP\Util::logException('files', $e);
    OCP\JSON::error(array('data' => array('exception' => '\\Exception', 'message' => $l->t('Unknown error'))));
}
Ejemplo n.º 11
0
 /**
  * Test connecting using the given backend configuration
  *
  * @param string $class backend class name
  * @param array $options backend configuration options
  * @return int see self::STATUS_*
  */
 public static function getBackendStatus($class, $options, $isPersonal)
 {
     if (self::$skipTest) {
         return self::STATUS_SUCCESS;
     }
     foreach ($options as &$option) {
         $option = self::setUserVars(OCP\User::getUser(), $option);
     }
     if (class_exists($class)) {
         try {
             $storage = new $class($options);
             if ($storage->test($isPersonal)) {
                 return self::STATUS_SUCCESS;
             }
         } catch (Exception $exception) {
             \OCP\Util::logException('files_external', $exception);
         }
     }
     return self::STATUS_ERROR;
 }
Ejemplo n.º 12
0
 protected static function handleLogin()
 {
     OC_App::loadApps(array('prelogin'));
     $error = array();
     $messages = [];
     try {
         // auth possible via apache module?
         if (OC::tryApacheAuth()) {
             $error[] = 'apacheauthfailed';
         } elseif (OC::tryRememberLogin()) {
             $error[] = 'invalidcookie';
         } elseif (OC::tryFormLogin()) {
             $error[] = 'invalidpassword';
         }
     } catch (\OC\User\LoginException $e) {
         $messages[] = $e->getMessage();
     } catch (\Exception $ex) {
         \OCP\Util::logException('handleLogin', $ex);
         // do not disclose information. show generic error
         $error[] = 'internalexception';
     }
     if (!\OC::$server->getUserSession()->isLoggedIn()) {
         $loginMessages = array(array_unique($error), $messages);
         \OC::$server->getSession()->set('loginMessages', $loginMessages);
         // Read current user and append if possible
         $args = [];
         if (isset($_POST['user'])) {
             $args['user'] = $_POST['user'];
         }
         $redirectionTarget = \OC::$server->getURLGenerator()->linkToRoute('core.login.showLoginForm', $args);
         header('Location: ' . $redirectionTarget);
     }
 }
Ejemplo n.º 13
0
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  * except the main .htaccess file
  *
  * @return bool true if the operation succeeded, false otherwise
  */
 public function upgrade()
 {
     $logLevel = \OC_Config::getValue('loglevel', \OCP\Util::WARN);
     $this->emit('\\OC\\Updater', 'setDebugLogLevel', array($logLevel, $this->logLevelNames[$logLevel]));
     \OC_Config::setValue('loglevel', \OCP\Util::DEBUG);
     \OC_DB::enableCaching(false);
     \OC_Config::setValue('maintenance', true);
     $installedVersion = \OC_Config::getValue('version', '0.0.0');
     $currentVersion = implode('.', \OC_Util::getVersion());
     if ($this->log) {
         $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
     }
     $this->emit('\\OC\\Updater', 'maintenanceStart');
     $success = true;
     try {
         $this->doUpgrade($currentVersion, $installedVersion);
     } catch (\Exception $exception) {
         \OCP\Util::logException('update', $exception);
         $this->emit('\\OC\\Updater', 'failure', array(get_class($exception) . ': ' . $exception->getMessage()));
         $success = false;
     }
     \OC_Config::setValue('maintenance', false);
     $this->emit('\\OC\\Updater', 'maintenanceEnd');
     $this->emit('\\OC\\Updater', 'updateEnd', array($success));
     $this->emit('\\OC\\Updater', 'resetLogLevel', array($logLevel, $this->logLevelNames[$logLevel]));
     \OC_Config::setValue('loglevel', $logLevel);
     return $success;
 }
Ejemplo n.º 14
0
 /**
  * Test connecting using the given backend configuration
  * @param string $class backend class name
  * @param array $options backend configuration options
  * @return bool true if the connection succeeded, false otherwise
  */
 private static function getBackendStatus($class, $options, $isPersonal)
 {
     if (self::$skipTest) {
         return true;
     }
     foreach ($options as &$option) {
         $option = self::setUserVars(OCP\User::getUser(), $option);
     }
     if (class_exists($class)) {
         try {
             $storage = new $class($options);
             return $storage->test($isPersonal);
         } catch (Exception $exception) {
             \OCP\Util::logException('files_external', $exception);
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 15
0
 public static function initSession()
 {
     // prevents javascript from accessing php session cookies
     ini_set('session.cookie_httponly', true);
     // set the cookie path to the ownCloud directory
     $cookie_path = OC::$WEBROOT ?: '/';
     ini_set('session.cookie_path', $cookie_path);
     // Let the session name be changed in the initSession Hook
     $sessionName = OC_Util::getInstanceId();
     try {
         // Allow session apps to create a custom session object
         $useCustomSession = false;
         $session = self::$server->getSession();
         OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession));
         if (!$useCustomSession) {
             // set the session name to the instance id - which is unique
             $session = new \OC\Session\Internal($sessionName);
         }
         $cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
         $session = $cryptoWrapper->wrapSession($session);
         self::$server->setSession($session);
         // if session can't be started break with http 500 error
     } catch (Exception $e) {
         \OCP\Util::logException('base', $e);
         //show the user a detailed error page
         OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
         OC_Template::printExceptionErrorPage($e);
         die;
     }
     $sessionLifeTime = self::getSessionLifeTime();
     // session timeout
     if ($session->exists('LAST_ACTIVITY') && time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime) {
         if (isset($_COOKIE[session_name()])) {
             setcookie(session_name(), null, -1, self::$WEBROOT ?: '/');
         }
         \OC::$server->getUserSession()->logout();
     }
     $session->set('LAST_ACTIVITY', time());
 }
Ejemplo n.º 16
0
 /**
  * Test connecting using the given backend configuration
  *
  * @param string $class backend class name
  * @param array $options backend configuration options
  * @return int see self::STATUS_*
  * @throws Exception
  */
 public static function getBackendStatus($class, $options, $isPersonal)
 {
     if (self::$skipTest) {
         return self::STATUS_SUCCESS;
     }
     foreach ($options as &$option) {
         $option = self::setUserVars(OCP\User::getUser(), $option);
     }
     if (class_exists($class)) {
         try {
             /** @var \OC\Files\Storage\Common $storage */
             $storage = new $class($options);
             try {
                 $result = $storage->test($isPersonal);
                 $storage->setAvailability($result);
                 if ($result) {
                     return self::STATUS_SUCCESS;
                 }
             } catch (\Exception $e) {
                 $storage->setAvailability(false);
                 throw $e;
             }
         } catch (Exception $exception) {
             \OCP\Util::logException('files_external', $exception);
             throw $exception;
         }
     }
     return self::STATUS_ERROR;
 }
Ejemplo n.º 17
0
 private static function getBackendStatus($class, $options)
 {
     foreach ($options as &$option) {
         $option = str_replace('$user', OCP\User::getUser(), $option);
     }
     if (class_exists($class)) {
         try {
             $storage = new $class($options);
             return $storage->test();
         } catch (Exception $exception) {
             \OCP\Util::logException('files_external', $exception);
             return false;
         }
     }
     return false;
 }