Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/settings/lib/Settings/Admin/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function getForm() {
'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
'cronMaxAge' => $this->cronMaxAge(),
'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
'cli_based_cron_possible' => function_exists('posix_getpwuid'),
'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
'cli_based_cron_user' => fileowner(\OC::$configDir . 'config.php'),
];

return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
Expand Down
16 changes: 2 additions & 14 deletions apps/settings/templates/settings/admin/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,10 @@
<input type="radio" name="mode" value="cron" class="radio"
id="backgroundjobs_cron" <?php if ($_['backgroundjobs_mode'] === "cron") {
print_unescaped('checked="checked"');
}
if (!$_['cli_based_cron_possible']) {
print_unescaped('disabled');
}?>>
} ?>>
<label for="backgroundjobs_cron">Cron</label><br/>
<em><?php p($l->t("Use system cron service to call the cron.php file every 5 minutes.")); ?>
<?php if ($_['cli_based_cron_possible']) {
p($l->t('The cron.php needs to be executed by the system user "%s".', [$_['cli_based_cron_user']]));
} else {
print_unescaped(str_replace(
['{linkstart}', '{linkend}'],
['<a href="http://php.net/manual/en/book.posix.php">', ' ↗</a>'],
$l->t('To run this you need the PHP POSIX extension. See {linkstart}PHP documentation{linkend} for more details.')
));
} ?></em>

<?php p($l->t('The cron.php needs to be executed by the user id "%s".', [$_['cli_based_cron_user']])); ?></em>
</p>
</fieldset>
</form>
Expand Down
3 changes: 1 addition & 2 deletions apps/settings/tests/Settings/Admin/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public function testGetForm(): void {
'lastcron' => false,
'cronErrors' => '',
'cronMaxAge' => 1337,
'cli_based_cron_possible' => true,
'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '', // to not explode here because of posix extension not being disabled - which is already checked in the line above
'cli_based_cron_user' => fileowner(\OC::$configDir . 'config.php'),
],
''
);
Expand Down
14 changes: 7 additions & 7 deletions console.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function exceptionHandler($exception) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
exit(1);
}
$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
if ($user['name'] !== $configUser['name']) {
$user = posix_getuid();
$configUser = fileowner(OC::$configDir . 'config.php');
if ($user !== $configUser) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
echo "If running with 'docker exec' try adding the option '-u " . $configUser['name'] . "' to the docker command (without the single quotes)" . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
exit(1);
}

Expand Down
11 changes: 6 additions & 5 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@
exit(1);
}

$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
if ($user['name'] !== $configUser['name']) {
$user = posix_getuid();
$configUser = fileowner(OC::$configDir . 'config.php');
if ($user !== $configUser) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
exit(1);
}


// We call Nextcloud from the CLI (aka cron)
if ($appMode !== 'cron') {
$config->setAppValue('core', 'backgroundjobs_mode', 'cron');
Expand Down