Merge pull request #15510 from owncloud/cron-singleuser

block cron when in single user mode
This commit is contained in:
Thomas Müller 2015-04-10 14:38:50 +02:00
commit a163243e31
5 changed files with 37 additions and 17 deletions

View file

@ -41,6 +41,11 @@ try {
exit;
}
if (\OC::$server->getSystemConfig()->getValue('singleuser', false)) {
\OCP\Util::writeLog('cron', 'We are in admin only mode, skipping cron', \OCP\Util::DEBUG);
exit;
}
// load all apps to get all api routes properly setup
OC_App::loadApps();

View file

@ -294,27 +294,37 @@ class OC {
header('Retry-After: 120');
// render error page
$tmpl = new OC_Template('', 'update.user', 'guest');
$template = new OC_Template('', 'update.user', 'guest');
OC_Util::addscript('maintenance-check');
$tmpl->printPage();
$template->printPage();
die();
}
}
public static function checkSingleUserMode() {
$user = OC_User::getUserSession()->getUser();
$group = OC_Group::getManager()->get('admin');
if ($user && \OC::$server->getSystemConfig()->getValue('singleuser', false) && !$group->inGroup($user)) {
// send http status 503
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 120');
// render error page
$tmpl = new OC_Template('', 'singleuser.user', 'guest');
$tmpl->printPage();
die();
public static function checkSingleUserMode($lockIfNoUserLoggedIn = false) {
if (!\OC::$server->getSystemConfig()->getValue('singleuser', false)) {
return;
}
$user = OC_User::getUserSession()->getUser();
if ($user) {
$group = \OC::$server->getGroupManager()->get('admin');
if ($group->inGroup($user)) {
return;
}
} else {
if(!$lockIfNoUserLoggedIn) {
return;
}
}
// send http status 503
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 120');
// render error page
$template = new OC_Template('', 'singleuser.user', 'guest');
$template->printPage();
die();
}
/**

View file

@ -60,6 +60,9 @@ class MaintenancePlugin extends \Sabre\DAV\ServerPlugin
* @return bool
*/
public function checkMaintenanceMode() {
if (\OC::$server->getSystemConfig()->getValue('singleuser', false)) {
throw new \Sabre\DAV\Exception\ServiceUnavailable();
}
if (\OC_Config::getValue('maintenance', false)) {
throw new \Sabre\DAV\Exception\ServiceUnavailable();
}

View file

@ -27,7 +27,9 @@
require_once '../lib/base.php';
if (\OCP\Util::needUpgrade() || \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
if (\OCP\Util::needUpgrade()
|| \OC::$server->getSystemConfig()->getValue('maintenance', false)
|| \OC::$server->getSystemConfig()->getValue('singleuser', false)) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);

View file

@ -37,7 +37,7 @@ try {
}
OC::checkMaintenanceMode();
OC::checkSingleUserMode();
OC::checkSingleUserMode(true);
$request = \OC::$server->getRequest();
$pathInfo = $request->getPathInfo();