コード例 #1
0
ファイル: file.php プロジェクト: CDN-Sparks/owncloud
 /**
  * Updates the data
  *
  * The data argument is a readable stream resource.
  *
  * After a succesful put operation, you may choose to return an ETag. The
  * etag must always be surrounded by double-quotes. These quotes must
  * appear in the actual string you're returning.
  *
  * Clients may use the ETag from a PUT request to later on make sure that
  * when they update the file, the contents haven't changed in the mean
  * time.
  *
  * If you don't plan to store the file byte-by-byte, and you return a
  * different object on a subsequent GET you are strongly recommended to not
  * return an ETag, and just return null.
  *
  * @param resource $data
  * @throws Sabre_DAV_Exception_Forbidden
  * @return string|null
  */
 public function put($data)
 {
     if (!\OC\Files\Filesystem::isUpdatable($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     // mark file as partial while uploading (ignored by the scanner)
     $partpath = $this->path . '.part';
     \OC\Files\Filesystem::file_put_contents($partpath, $data);
     //detect aborted upload
     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
         if (isset($_SERVER['CONTENT_LENGTH'])) {
             $expected = $_SERVER['CONTENT_LENGTH'];
             $actual = \OC\Files\Filesystem::filesize($partpath);
             if ($actual != $expected) {
                 \OC\Files\Filesystem::unlink($partpath);
                 throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual);
             }
         }
     }
     // rename to correct path
     \OC\Files\Filesystem::rename($partpath, $this->path);
     //allow sync clients to send the mtime along in a header
     $mtime = OC_Request::hasModificationTime();
     if ($mtime !== false) {
         if (\OC\Files\Filesystem::touch($this->path, $mtime)) {
             header('X-OC-MTime: accepted');
         }
     }
     return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
 }
コード例 #2
0
ファイル: minimizer.php プロジェクト: noci2012/owncloud
 public function output($files, $cache_key)
 {
     header('Content-Type: ' . $this->contentType);
     OC_Response::enableCaching();
     $etag = $this->generateETag($files);
     $cache_key .= '-' . $etag;
     $gzout = false;
     $cache = OC_Cache::getGlobalCache();
     if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)) {
         OC_Response::setETagHeader($etag);
         $gzout = $cache->get($cache_key . '.gz');
     }
     if (!$gzout) {
         $out = $this->minimizeFiles($files);
         $gzout = gzencode($out);
         $cache->set($cache_key . '.gz', $gzout);
         OC_Response::setETagHeader($etag);
     }
     if ($encoding = OC_Request::acceptGZip()) {
         header('Content-Encoding: ' . $encoding);
         $out = $gzout;
     } else {
         $out = gzdecode($gzout);
     }
     header('Content-Length: ' . strlen($out));
     echo $out;
 }
コード例 #3
0
ファイル: request.php プロジェクト: samj1912/repo
 /**
  * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  * @return string
  */
 public static function getRequestID()
 {
     if (self::$reqId === null) {
         self::$reqId = hash('md5', microtime() . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(20));
     }
     return self::$reqId;
 }
コード例 #4
0
ファイル: router.php プロジェクト: ryanshoover/core
 public function __construct()
 {
     $baseUrl = OC_Helper::linkTo('', 'index.php');
     $method = $_SERVER['REQUEST_METHOD'];
     $host = OC_Request::serverHost();
     $schema = OC_Request::serverProtocol();
     $this->context = new RequestContext($baseUrl, $method, $host, $schema);
     // TODO cache
     $this->root = $this->getCollection('root');
 }
コード例 #5
0
ファイル: directory.php プロジェクト: CDN-Sparks/owncloud
 /**
  * Creates a new file in the directory
  *
  * Data will either be supplied as a stream resource, or in certain cases
  * as a string. Keep in mind that you may have to support either.
  *
  * After succesful creation of the file, you may choose to return the ETag
  * of the new file here.
  *
  * The returned ETag must be surrounded by double-quotes (The quotes should
  * be part of the actual string).
  *
  * If you cannot accurately determine the ETag, you should not return it.
  * If you don't store the file exactly as-is (you're transforming it
  * somehow) you should also not return an ETag.
  *
  * This means that if a subsequent GET to this new file does not exactly
  * return the same contents of what was submitted here, you are strongly
  * recommended to omit the ETag.
  *
  * @param string $name Name of the file
  * @param resource|string $data Initial payload
  * @throws Sabre_DAV_Exception_Forbidden
  * @return null|string
  */
 public function createFile($name, $data = null)
 {
     if (!\OC\Files\Filesystem::isCreatable($this->path)) {
         throw new \Sabre_DAV_Exception_Forbidden();
     }
     if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
         $info = OC_FileChunking::decodeName($name);
         if (empty($info)) {
             throw new Sabre_DAV_Exception_NotImplemented();
         }
         $chunk_handler = new OC_FileChunking($info);
         $chunk_handler->store($info['index'], $data);
         if ($chunk_handler->isComplete()) {
             $newPath = $this->path . '/' . $info['name'];
             $chunk_handler->file_assemble($newPath);
             return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
         }
     } else {
         $newPath = $this->path . '/' . $name;
         // mark file as partial while uploading (ignored by the scanner)
         $partpath = $newPath . '.part';
         \OC\Files\Filesystem::file_put_contents($partpath, $data);
         //detect aborted upload
         if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
             if (isset($_SERVER['CONTENT_LENGTH'])) {
                 $expected = $_SERVER['CONTENT_LENGTH'];
                 $actual = \OC\Files\Filesystem::filesize($partpath);
                 if ($actual != $expected) {
                     \OC\Files\Filesystem::unlink($partpath);
                     throw new Sabre_DAV_Exception_BadRequest('expected filesize ' . $expected . ' got ' . $actual);
                 }
             }
         }
         // rename to correct path
         \OC\Files\Filesystem::rename($partpath, $newPath);
         // allow sync clients to send the mtime along in a header
         $mtime = OC_Request::hasModificationTime();
         if ($mtime !== false) {
             if (\OC\Files\Filesystem::touch($newPath, $mtime)) {
                 header('X-OC-MTime: accepted');
             }
         }
         return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
     }
     return null;
 }
コード例 #6
0
ファイル: owncloud.php プロジェクト: Romua1d/core
 /**
  * write a message in the log
  * @param string $app
  * @param string $message
  * @param int $level
  */
 public static function write($app, $message, $level)
 {
     $minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
     if ($level >= $minLevel) {
         // default to ISO8601
         $format = OC_Config::getValue('logdateformat', 'c');
         $logtimezone = OC_Config::getValue("logtimezone", 'UTC');
         try {
             $timezone = new DateTimeZone($logtimezone);
         } catch (Exception $e) {
             $timezone = new DateTimeZone('UTC');
         }
         $time = new DateTime(null, $timezone);
         $reqId = \OC_Request::getRequestID();
         $remoteAddr = \OC_Request::getRemoteAddress();
         // remove username/passwords from URLs before writing the to the log file
         $time = $time->format($format);
         if ($minLevel == OC_Log::DEBUG) {
             $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
             $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
         } else {
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
         }
         $entry = json_encode($entry);
         $handle = @fopen(self::$logFile, 'a');
         @chmod(self::$logFile, 0640);
         if ($handle) {
             fwrite($handle, $entry . "\n");
             fclose($handle);
         } else {
             // Fall back to error_log
             error_log($entry);
         }
     }
 }
コード例 #7
0
ファイル: v1.php プロジェクト: hjimmy/owncloud
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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 along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once '../lib/base.php';
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
try {
    OC::getRouter()->match('/ocs' . OC_Request::getRawPathInfo());
} catch (ResourceNotFoundException $e) {
    OC_API::setContentType();
    OC_OCS::notFound();
} catch (MethodNotAllowedException $e) {
    OC_API::setContentType();
    OC_Response::setStatus(405);
}
コード例 #8
0
<?php

try {
    require_once 'lib/base.php';
    if (\OCP\Util::needUpgrade()) {
        // since the behavior of apps or remotes are unpredictable during
        // an upgrade, return a 503 directly
        OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
        OC_Template::printErrorPage('Service unavailable');
        exit;
    }
    $path_info = OC_Request::getPathInfo();
    if ($path_info === false || $path_info === '') {
        OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
        exit;
    }
    if (!($pos = strpos($path_info, '/', 1))) {
        $pos = strlen($path_info);
    }
    $service = substr($path_info, 1, $pos - 1);
    $file = \OC::$server->getAppConfig()->getValue('core', 'remote_' . $service);
    if (is_null($file)) {
        OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
        exit;
    }
    $file = ltrim($file, '/');
    $parts = explode('/', $file, 2);
    $app = $parts[0];
    // Load all required applications
    \OC::$REQUESTEDAPP = $app;
    OC_App::loadApps(array('authentication'));
コード例 #9
0
 /**
  * Refreshs the roundcube HTTP session
  * @return boolean true if refresh was successfull, otherwise false
  */
 public static function refresh()
 {
     try {
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->refresh(): Preparing refresh for roundcube', OCP\Util::DEBUG);
         $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
         $rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
         if ($rc_host == '') {
             $rc_host = OC_Request::serverHost();
         }
         $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', '');
         OC_RoundCube_App::refresh($rc_host, $rc_port, $maildir);
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->refresh(): Finished refresh for roundcube', OCP\Util::DEBUG);
         return true;
     } catch (Exception $e) {
         // We got an exception during login/refresh
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php: ' . 'Login error during refresh.' . $e, OCP\Util::DEBUG);
         return false;
     }
 }
コード例 #10
0
ファイル: setup.php プロジェクト: hjimmy/owncloud
 public static function install($options)
 {
     $l = self::getTrans();
     $error = array();
     $dbtype = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbtype])) {
         $dbtype = 'sqlite';
     }
     $class = self::$dbSetupClasses[$dbtype];
     $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
     $error = array_merge($error, $dbSetup->validate($options));
     if (count($error) != 0) {
         return $error;
     }
     //no errors, good
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $datadir = htmlspecialchars_decode($options['directory']);
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = array(OC_Request::serverHost());
     }
     if (OC_Util::runningOnWindows()) {
         $datadir = rtrim(realpath($datadir), '\\');
     }
     //use sqlite3 when available, otherise sqlite2 will be used.
     if ($dbtype == 'sqlite' and class_exists('SQLite3')) {
         $dbtype = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = OC_Util::generateRandomBytes(30);
     OC_Config::setValue('passwordsalt', $salt);
     //write the config file
     OC_Config::setValue('trusted_domains', $trustedDomains);
     OC_Config::setValue('datadirectory', $datadir);
     OC_Config::setValue('dbtype', $dbtype);
     OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => '');
         return $error;
     }
     //create the user and group
     try {
         OC_User::createUser($username, $password);
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         OC_Appconfig::setValue('core', 'installedat', microtime(true));
         OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
         OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
         OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
         OC_Group::createGroup('admin');
         OC_Group::addToGroup($username, 'admin');
         OC_User::login($username, $password);
         //guess what this does
         OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', '');
         //create htaccess files for apache hosts
         if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
             self::createHtaccess();
         }
         //and we are done
         OC_Config::setValue('installed', true);
     }
     return $error;
 }
コード例 #11
0
ファイル: response.php プロジェクト: olucao/owncloud-core
 /**
  * Sets the content disposition header (with possible workarounds)
  * @param string $filename file name
  * @param string $type disposition type, either 'attachment' or 'inline'
  */
 public static function setContentDispositionHeader($filename, $type = 'attachment')
 {
     if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, OC_Request::USER_AGENT_FREEBOX))) {
         header('Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode($filename) . '"');
     } else {
         header('Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"');
     }
 }
コード例 #12
0
ファイル: request.php プロジェクト: Romua1d/core
 public function testServerHost()
 {
     OC_Config::deleteKey('overwritecondaddr');
     OC_Config::setValue('overwritehost', 'overwritten.host:8080');
     OC_Config::setValue('trusted_domains', array('trusted.host:8080', 'second.trusted.host:8080'));
     $_SERVER['HTTP_HOST'] = 'trusted.host:8080';
     // CLI always gives localhost
     $oldCLI = OC::$CLI;
     OC::$CLI = true;
     $host = OC_Request::serverHost();
     $this->assertEquals('localhost', $host);
     OC::$CLI = false;
     // overwritehost overrides trusted domain
     $host = OC_Request::serverHost();
     $this->assertEquals('overwritten.host:8080', $host);
     // trusted domain returned when used
     OC_Config::deleteKey('overwritehost');
     $host = OC_Request::serverHost();
     $this->assertEquals('trusted.host:8080', $host);
     // trusted domain returned when untrusted one in header
     $_SERVER['HTTP_HOST'] = 'untrusted.host:8080';
     OC_Config::deleteKey('overwritehost');
     $host = OC_Request::serverHost();
     $this->assertEquals('trusted.host:8080', $host);
     // clean up
     OC_Config::deleteKey('overwritecondaddr');
     OC_Config::deleteKey('overwritehost');
     unset($_SERVER['HTTP_HOST']);
     OC::$CLI = $oldCLI;
 }
コード例 #13
0
ファイル: updater.php プロジェクト: WYSAC/oregon-owncloud
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  * except the main .htaccess file
  *
  * @param string $currentVersion current version to upgrade to
  * @param string $installedVersion previous version from which to upgrade from
  *
  * @throws \Exception
  * @return bool true if the operation succeeded, false otherwise
  */
 private function doUpgrade($currentVersion, $installedVersion)
 {
     // Stop update if the update is over several major versions
     if (!self::isUpgradePossible($installedVersion, $currentVersion)) {
         throw new \Exception('Updates between multiple major versions are unsupported.');
     }
     // Update htaccess files for apache hosts
     if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
         \OC_Setup::updateHtaccess();
     }
     // create empty file in data dir, so we can later find
     // out that this is indeed an ownCloud data directory
     // (in case it didn't exist before)
     file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
     /*
      * START CONFIG CHANGES FOR OLDER VERSIONS
      */
     if (!\OC::$CLI && version_compare($installedVersion, '6.90.1', '<')) {
         // Add the trusted_domains config if it is not existant
         // This is added to prevent host header poisoning
         \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost())));
     }
     /*
      * STOP CONFIG CHANGES FOR OLDER VERSIONS
      */
     // pre-upgrade repairs
     $repair = new \OC\Repair(\OC\Repair::getBeforeUpgradeRepairSteps());
     $repair->run();
     // simulate DB upgrade
     if ($this->simulateStepEnabled) {
         $this->checkCoreUpgrade();
         // simulate apps DB upgrade
         $this->checkAppUpgrade($currentVersion);
     }
     // upgrade from OC6 to OC7
     // TODO removed it again for OC8
     $sharePolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
     if ($sharePolicy === 'groups_only') {
         \OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes');
     }
     if ($this->updateStepEnabled) {
         $this->doCoreUpgrade();
         $disabledApps = \OC_App::checkAppsRequirements();
         if (!empty($disabledApps)) {
             $this->emit('\\OC\\Updater', 'disabledApps', array($disabledApps));
         }
         $this->doAppUpgrade();
         // post-upgrade repairs
         $repair = new \OC\Repair(\OC\Repair::getRepairSteps());
         $repair->run();
         //Invalidate update feed
         \OC_Appconfig::setValue('core', 'lastupdatedat', 0);
         // only set the final version if everything went well
         \OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
     }
 }
コード例 #14
0
ファイル: userSettings.php プロジェクト: CDN-Sparks/owncloud
<?php

// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('roundcube');
// CSRF checks
OCP\JSON::callCheck();
$l = new OC_L10N('roundcube');
if (isset($_POST['appname']) && $_POST['appname'] == "roundcube") {
    $ocUser = OCP\User::getUser();
    $result = OC_RoundCube_App::cryptEmailIdentity($ocUser, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    if ($result) {
        // update login credentials
        $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
        $rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
        if ($rc_host == '') {
            $rc_host = OC_Request::serverHost();
        }
        $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', null);
        OC_RoundCube_App::login($rc_host, $rc_port, $maildir, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    } else {
        OC_JSON::error(array("data" => array("message" => $l->t("Unable to store email credentials in the data-base."))));
        return false;
    }
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Not submitted for us."))));
    return false;
}
OCP\JSON::success(array('data' => array('message' => $l->t('Email-user credentials successfully stored.'))));
return true;
コード例 #15
0
ファイル: admin.php プロジェクト: pombredanne/ArcherSys
$template->assign('allowPublicUpload', $appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes'));
$template->assign('allowResharing', $appConfig->getValue('core', 'shareapi_allow_resharing', 'yes'));
$template->assign('allowPublicMailNotification', $appConfig->getValue('core', 'shareapi_allow_public_notification', 'no'));
$template->assign('allowMailNotification', $appConfig->getValue('core', 'shareapi_allow_mail_notification', 'no'));
$template->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
$databaseOverload = (strpos(\OCP\Config::getSystemValue('dbtype'), 'sqlite') !== false);
$template->assign('databaseOverload', $databaseOverload);

// warn if Windows is used
$template->assign('WindowsWarning', OC_Util::runningOnWindows());

// add hardcoded forms from the template
$forms = OC_App::getForms('admin');
$l = OC_L10N::get('settings');
$formsAndMore = array();
if (OC_Request::serverProtocol() !== 'https' || !OC_Util::isAnnotationsWorking() ||
	$suggestedOverwriteCliUrl || !OC_Util::isSetLocaleWorking() || !OC_Util::isPhpCharSetUtf8() ||
	!OC_Util::fileInfoLoaded() || $databaseOverload
) {
	$formsAndMore[] = array('anchor' => 'security-warning', 'section-name' => $l->t('Security & Setup Warnings'));
}

$formsMap = array_map(function ($form) {
	if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
		$sectionName = str_replace('<h2>', '', $regs[0]);
		$sectionName = str_replace('</h2>', '', $sectionName);
		$anchor = strtolower($sectionName);
		$anchor = str_replace(' ', '-', $anchor);

		return array(
			'anchor' => 'goto-' . $anchor,
コード例 #16
0
ファイル: admin.php プロジェクト: WYSAC/oregon-owncloud
$tmpl->assign('old_php', OC_Util::isPHPoutdated());
$tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax'));
$tmpl->assign('cron_log', OC_Config::getValue('cron_log', true));
$tmpl->assign('lastcron', OC_Appconfig::getValue('core', 'lastcron', false));
$tmpl->assign('shareAPIEnabled', OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes'));
$tmpl->assign('shareDefaultExpireDateSet', OC_Appconfig::getValue('core', 'shareapi_default_expire_date', 'no'));
$tmpl->assign('shareExpireAfterNDays', OC_Appconfig::getValue('core', 'shareapi_expire_after_n_days', '7'));
$tmpl->assign('shareEnforceExpireDate', OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no'));
$excludeGroups = OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
$tmpl->assign('shareExcludeGroups', $excludeGroups);
$excludedGroupsList = OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroupsList = explode(',', $excludedGroupsList);
// FIXME: this should be JSON!
$tmpl->assign('shareExcludedGroupsList', implode('|', $excludedGroupsList));
// Check if connected using HTTPS
$tmpl->assign('isConnectedViaHTTPS', OC_Request::serverProtocol() === 'https');
$tmpl->assign('enforceHTTPSEnabled', OC_Config::getValue("forcessl", false));
// If the current webroot is non-empty but the webroot from the config is,
// and system cron is used, the URL generator fails to build valid URLs.
$shouldSuggestOverwriteWebroot = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron' && \OC::$WEBROOT && \OC::$WEBROOT !== '/' && !$config->getSystemValue('overwritewebroot', '');
$tmpl->assign('suggestedOverwriteWebroot', $shouldSuggestOverwriteWebroot ? \OC::$WEBROOT : '');
$tmpl->assign('allowLinks', OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes'));
$tmpl->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired());
$tmpl->assign('allowPublicUpload', OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'));
$tmpl->assign('allowResharing', OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'));
$tmpl->assign('allowMailNotification', OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'no'));
$tmpl->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
$tmpl->assign('forms', array());
foreach ($forms as $form) {
    $tmpl->append('forms', $form);
}
コード例 #17
0
ファイル: templatelayout.php プロジェクト: riso/owncloud-core
 /**
  * @param string $renderAs
  * @param string $appId application id
  */
 public function __construct($renderAs, $appId = '')
 {
     // yes - should be injected ....
     $this->config = \OC::$server->getConfig();
     // Decide which page we show
     if ($renderAs == 'user') {
         parent::__construct('core', 'layout.user');
         if (in_array(OC_APP::getCurrentApp(), array('settings', 'admin', 'help')) !== false) {
             $this->assign('bodyid', 'body-settings');
         } else {
             $this->assign('bodyid', 'body-user');
         }
         // Update notification
         if ($this->config->getSystemValue('updatechecker', true) === true && OC_User::isAdminUser(OC_User::getUser())) {
             $updater = new \OC\Updater(\OC::$server->getHTTPHelper(), \OC::$server->getAppConfig());
             $data = $updater->check();
             if (isset($data['version']) && $data['version'] != '' and $data['version'] !== array()) {
                 $this->assign('updateAvailable', true);
                 $this->assign('updateVersion', $data['versionstring']);
                 $this->assign('updateLink', $data['web']);
             } else {
                 $this->assign('updateAvailable', false);
                 // No update available or not an admin user
             }
         } else {
             $this->assign('updateAvailable', false);
             // Update check is disabled
         }
         // Add navigation entry
         $this->assign('application', '', false);
         $this->assign('appid', $appId);
         $navigation = OC_App::getNavigation();
         $this->assign('navigation', $navigation);
         $this->assign('settingsnavigation', OC_App::getSettingsNavigation());
         foreach ($navigation as $entry) {
             if ($entry['active']) {
                 $this->assign('application', $entry['name']);
                 break;
             }
         }
         $userDisplayName = OC_User::getDisplayName();
         $this->assign('user_displayname', $userDisplayName);
         $this->assign('user_uid', OC_User::getUser());
         $this->assign('appsmanagement_active', strpos(OC_Request::requestUri(), OC_Helper::linkToRoute('settings_apps')) === 0);
         $this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true));
         $this->assign('userAvatarSet', \OC_Helper::userAvatarSet(OC_User::getUser()));
     } else {
         if ($renderAs == 'error') {
             parent::__construct('core', 'layout.guest', '', false);
             $this->assign('bodyid', 'body-login');
         } else {
             if ($renderAs == 'guest') {
                 parent::__construct('core', 'layout.guest');
                 $this->assign('bodyid', 'body-login');
             } else {
                 parent::__construct('core', 'layout.base');
             }
         }
     }
     // Send the language to our layouts
     $this->assign('language', OC_L10N::findLanguage());
     if (empty(self::$versionHash)) {
         self::$versionHash = md5(implode(',', OC_App::getAppVersions()));
     }
     $useAssetPipeline = self::isAssetPipelineEnabled();
     if ($useAssetPipeline) {
         $this->append('jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash)));
         $this->generateAssets();
     } else {
         // Add the js files
         $jsFiles = self::findJavascriptFiles(OC_Util::$scripts);
         $this->assign('jsfiles', array(), false);
         if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
             $this->append('jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash)));
         }
         foreach ($jsFiles as $info) {
             $web = $info[1];
             $file = $info[2];
             $this->append('jsfiles', $web . '/' . $file . '?v=' . self::$versionHash);
         }
         // Add the css files
         $cssFiles = self::findStylesheetFiles(OC_Util::$styles);
         $this->assign('cssfiles', array());
         foreach ($cssFiles as $info) {
             $web = $info[1];
             $file = $info[2];
             $this->append('cssfiles', $web . '/' . $file . '?v=' . self::$versionHash);
         }
     }
 }
コード例 #18
0
ファイル: request.php プロジェクト: samj1912/repo
 /**
  * Returns the requested uri
  *
  * @return string
  */
 public function getUri()
 {
     return OC_Request::requestUri();
 }
コード例 #19
0
ファイル: admin.php プロジェクト: olucao/owncloud-core
$tmpl->assign('shareExcludeGroups', $excludeGroups);
$allGroups = OC_Group::getGroups();
$excludedGroupsList = OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = $excludedGroupsList !== '' ? explode(',', $excludedGroupsList) : array();
$groups = array();
foreach ($allGroups as $group) {
    if (in_array($group, $excludedGroups)) {
        $groups[$group] = array('gid' => $group, 'excluded' => true);
    } else {
        $groups[$group] = array('gid' => $group, 'excluded' => false);
    }
}
ksort($groups);
$tmpl->assign('groups', $groups);
// Check if connected using HTTPS
if (OC_Request::serverProtocol() === 'https') {
    $connectedHTTPS = true;
} else {
    $connectedHTTPS = false;
}
$tmpl->assign('isConnectedViaHTTPS', $connectedHTTPS);
$tmpl->assign('enforceHTTPSEnabled', OC_Config::getValue("forcessl", false));
$tmpl->assign('allowLinks', OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes'));
$tmpl->assign('enforceLinkPassword', \OCP\Util::isPublicLinkPasswordRequired());
$tmpl->assign('allowPublicUpload', OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'));
$tmpl->assign('allowResharing', OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes'));
$tmpl->assign('allowMailNotification', OC_Appconfig::getValue('core', 'shareapi_allow_mail_notification', 'no'));
$tmpl->assign('onlyShareWithGroupMembers', \OC\Share\Share::shareWithGroupMembersOnly());
$tmpl->assign('forms', array());
foreach ($forms as $form) {
    $tmpl->append('forms', $form);
コード例 #20
0
ファイル: base.php プロジェクト: BacLuc/newGryfiPage
	/**
	 * Try to login a user via HTTP authentication
	 * @return bool|void
	 */
	protected static function tryApacheAuth() {
		$return = OC_User::handleApacheAuth();

		// if return is true we are logged in -> redirect to the default page
		if ($return === true) {
			$_REQUEST['redirect_url'] = \OC_Request::requestUri();
			OC_Util::redirectToDefaultPage();
			exit;
		}

		// in case $return is null apache based auth is not enabled
		return is_null($return) ? false : true;
	}
コード例 #21
0
ファイル: base.php プロジェクト: CDN-Sparks/owncloud
 protected static function tryBasicAuthLogin()
 {
     if (!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])) {
         return false;
     }
     OC_App::loadApps(array('authentication'));
     if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
         //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
         OC_User::unsetMagicInCookie();
         $_REQUEST['redirect_url'] = OC_Request::requestUri();
         OC_Util::redirectToDefaultPage();
     }
     return true;
 }
コード例 #22
0
ファイル: util.php プロジェクト: CDN-Sparks/owncloud
 /**
  * @brief Returns the script name
  * @returns the script name
  *
  * Returns the script name, even if the website uses one or more
  * reverse proxies
  */
 public static function getScriptName()
 {
     return \OC_Request::scriptName();
 }
コード例 #23
0
ファイル: base.php プロジェクト: noci2012/owncloud
 public static function checkSSL()
 {
     // redirect to https site if configured
     if (OC_Config::getValue("forcessl", false)) {
         ini_set("session.cookie_secure", "on");
         if (OC_Request::serverProtocol() != 'https' and !OC::$CLI) {
             $url = "https://" . OC_Request::serverHost() . $_SERVER['REQUEST_URI'];
             header("Location: {$url}");
             exit;
         }
     }
 }
コード例 #24
0
ファイル: file.php プロジェクト: olucao/owncloud-core
 /**
  * @param resource $data
  * @return null|string
  */
 private function createFileChunked($data)
 {
     list($path, $name) = \Sabre\DAV\URLUtil::splitPath($this->path);
     $info = OC_FileChunking::decodeName($name);
     if (empty($info)) {
         throw new \Sabre\DAV\Exception\NotImplemented();
     }
     $chunk_handler = new OC_FileChunking($info);
     $bytesWritten = $chunk_handler->store($info['index'], $data);
     //detect aborted upload
     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
         if (isset($_SERVER['CONTENT_LENGTH'])) {
             $expected = $_SERVER['CONTENT_LENGTH'];
             if ($bytesWritten != $expected) {
                 $chunk_handler->remove($info['index']);
                 throw new \Sabre\DAV\Exception\BadRequest('expected filesize ' . $expected . ' got ' . $bytesWritten);
             }
         }
     }
     if ($chunk_handler->isComplete()) {
         // we first assembly the target file as a part file
         $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
         $chunk_handler->file_assemble($partFile);
         // here is the final atomic rename
         $targetPath = $path . '/' . $info['name'];
         $renameOkay = $this->fileView->rename($partFile, $targetPath);
         $fileExists = $this->fileView->file_exists($targetPath);
         if ($renameOkay === false || $fileExists === false) {
             \OC_Log::write('webdav', '\\OC\\Files\\Filesystem::rename() failed', \OC_Log::ERROR);
             // only delete if an error occurred and the target file was already created
             if ($fileExists) {
                 $this->fileView->unlink($targetPath);
             }
             throw new \Sabre\DAV\Exception('Could not rename part file assembled from chunks');
         }
         // allow sync clients to send the mtime along in a header
         $mtime = OC_Request::hasModificationTime();
         if ($mtime !== false) {
             if ($this->fileView->touch($targetPath, $mtime)) {
                 header('X-OC-MTime: accepted');
             }
         }
         $info = $this->fileView->getFileInfo($targetPath);
         return $info->getEtag();
     }
     return null;
 }
コード例 #25
0
ファイル: setup.php プロジェクト: Romua1d/core
 /**
  * @param $options
  * @return array
  */
 public static function install($options)
 {
     $l = self::getTrans();
     $error = array();
     $dbType = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbType])) {
         $dbType = 'sqlite';
     }
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $dataDir = htmlspecialchars_decode($options['directory']);
     $class = self::$dbSetupClasses[$dbType];
     /** @var \OC\Setup\AbstractDatabase $dbSetup */
     $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
     $error = array_merge($error, $dbSetup->validate($options));
     // validate the data directory
     if (!is_dir($dataDir) and !mkdir($dataDir) or !is_writable($dataDir)) {
         $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
     }
     if (count($error) != 0) {
         return $error;
     }
     //no errors, good
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = array(OC_Request::serverHost());
     }
     if (OC_Util::runningOnWindows()) {
         $dataDir = rtrim(realpath($dataDir), '\\');
     }
     //use sqlite3 when available, otherwise sqlite2 will be used.
     if ($dbType == 'sqlite' and class_exists('SQLite3')) {
         $dbType = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30);
     \OC::$server->getConfig()->setSystemValue('passwordsalt', $salt);
     // generate a secret
     $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
     \OC::$server->getConfig()->setSystemValue('secret', $secret);
     //write the config file
     \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains);
     \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir);
     \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT);
     \OC::$server->getConfig()->setSystemValue('dbtype', $dbType);
     \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion()));
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => '');
         return $error;
     }
     //create the user and group
     try {
         OC_User::createUser($username, $password);
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         $appConfig = \OC::$server->getAppConfig();
         $appConfig->setValue('core', 'installedat', microtime(true));
         $appConfig->setValue('core', 'lastupdatedat', microtime(true));
         OC_Group::createGroup('admin');
         OC_Group::addToGroup($username, 'admin');
         OC_User::login($username, $password);
         //guess what this does
         OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', '');
         // Update htaccess files for apache hosts
         if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
             self::updateHtaccess();
             self::protectDataDirectory();
         }
         //and we are done
         OC_Config::setValue('installed', true);
     }
     return $error;
 }
コード例 #26
0
 /**
  * @param string $renderas
  * @param string $appid application id
  */
 public function __construct($renderas, $appid = '')
 {
     // Decide which page we show
     if ($renderas == 'user') {
         parent::__construct('core', 'layout.user');
         if (in_array(OC_APP::getCurrentApp(), array('settings', 'admin', 'help')) !== false) {
             $this->assign('bodyid', 'body-settings');
         } else {
             $this->assign('bodyid', 'body-user');
         }
         // Update notification
         if (OC_Config::getValue('updatechecker', true) === true) {
             $data = OC_Updater::check();
             if (isset($data['version']) && $data['version'] != '' and $data['version'] !== array() && OC_User::isAdminUser(OC_User::getUser())) {
                 $this->assign('updateAvailable', true);
                 $this->assign('updateVersion', $data['versionstring']);
                 $this->assign('updateLink', $data['web']);
             } else {
                 $this->assign('updateAvailable', false);
                 // No update available or not an admin user
             }
         } else {
             $this->assign('updateAvailable', false);
             // Update check is disabled
         }
         // Add navigation entry
         $this->assign('application', '', false);
         $this->assign('appid', $appid);
         $navigation = OC_App::getNavigation();
         $this->assign('navigation', $navigation);
         $this->assign('settingsnavigation', OC_App::getSettingsNavigation());
         foreach ($navigation as $entry) {
             if ($entry['active']) {
                 $this->assign('application', $entry['name']);
                 break;
             }
         }
         $user_displayname = OC_User::getDisplayName();
         $this->assign('user_displayname', $user_displayname);
         $this->assign('user_uid', OC_User::getUser());
         $this->assign('appsmanagement_active', strpos(OC_Request::requestUri(), OC_Helper::linkToRoute('settings_apps')) === 0);
         $this->assign('enableAvatars', \OC_Config::getValue('enable_avatars', true));
     } else {
         if ($renderas == 'error') {
             parent::__construct('core', 'layout.guest', '', false);
         } else {
             if ($renderas == 'guest') {
                 parent::__construct('core', 'layout.guest');
             } else {
                 parent::__construct('core', 'layout.base');
             }
         }
     }
     $versionParameter = '?v=' . md5(implode(OC_Util::getVersion()));
     $useAssetPipeline = $this->isAssetPipelineEnabled();
     if ($useAssetPipeline) {
         $this->append('jsfiles', OC_Helper::linkToRoute('js_config') . $versionParameter);
         $this->generateAssets();
     } else {
         // Add the js files
         $jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
         $this->assign('jsfiles', array(), false);
         if (OC_Config::getValue('installed', false) && $renderas != 'error') {
             $this->append('jsfiles', OC_Helper::linkToRoute('js_config') . $versionParameter);
         }
         foreach ($jsfiles as $info) {
             $web = $info[1];
             $file = $info[2];
             $this->append('jsfiles', $web . '/' . $file . $versionParameter);
         }
         // Add the css files
         $cssfiles = self::findStylesheetFiles(OC_Util::$styles);
         $this->assign('cssfiles', array());
         foreach ($cssfiles as $info) {
             $web = $info[1];
             $file = $info[2];
             $this->append('cssfiles', $web . '/' . $file . $versionParameter);
         }
     }
 }
コード例 #27
0
ファイル: util.php プロジェクト: pinoniq/core
 /**
  * Check if the user is logged in, redirects to home if not. With
  * redirect URL parameter to the request URI.
  *
  * @return void
  */
 public static function checkLoggedIn()
 {
     // Check if we are a user
     if (!OC_User::isLoggedIn()) {
         header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php', array('redirect_url' => OC_Request::requestUri())));
         exit;
     }
 }
コード例 #28
0
ファイル: util.php プロジェクト: noci2012/owncloud
 /**
  * @brief Returns the server protocol
  * @returns the server protocol
  *
  * Returns the server protocol. It respects reverse proxy servers and load balancers
  */
 public static function getServerProtocol()
 {
     return \OC_Request::serverProtocol();
 }
コード例 #29
0
ファイル: app.php プロジェクト: kebenxiaoming/owncloudRedis
 /**
  * get the id of loaded app
  *
  * @return string
  */
 public static function getCurrentApp()
 {
     $script = substr(OC_Request::scriptName(), strlen(OC::$WEBROOT) + 1);
     $topFolder = substr($script, 0, strpos($script, '/'));
     if (empty($topFolder)) {
         $path_info = OC_Request::getPathInfo();
         if ($path_info) {
             $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
         }
     }
     if ($topFolder == 'apps') {
         $length = strlen($topFolder);
         return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
     } else {
         return $topFolder;
     }
 }
コード例 #30
0
ファイル: helper.php プロジェクト: ryanshoover/core
	/**
	 * @brief Makes an $url absolute
	 * @param string $url the url
	 * @return string the absolute url
	 *
	 * Returns a absolute url to the given app and file.
	 */
	public static function makeURLAbsolute( $url )
	{
		return OC_Request::serverProtocol(). '://'  . OC_Request::serverHost() . $url;
	}