diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php index 9a81e41c1acdc..ad84bdfc6913d 100644 --- a/apps/settings/lib/Settings/Admin/Server.php +++ b/apps/settings/lib/Settings/Admin/Server.php @@ -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, ''); diff --git a/apps/settings/templates/settings/admin/server.php b/apps/settings/templates/settings/admin/server.php index 635e1477fe3a9..84b675219d716 100644 --- a/apps/settings/templates/settings/admin/server.php +++ b/apps/settings/templates/settings/admin/server.php @@ -92,22 +92,10 @@ > + } ?>>
t("Use system cron service to call the cron.php file every 5 minutes.")); ?> - t('The cron.php needs to be executed by the system user "%s".', [$_['cli_based_cron_user']])); - } else { - print_unescaped(str_replace( - ['{linkstart}', '{linkend}'], - ['', ' ↗'], - $l->t('To run this you need the PHP POSIX extension. See {linkstart}PHP documentation{linkend} for more details.') - )); - } ?> - + t('The cron.php needs to be executed by the user id "%s".', [$_['cli_based_cron_user']])); ?>

diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php index f37cb01a40d35..b27d12a1a0717 100644 --- a/apps/settings/tests/Settings/Admin/ServerTest.php +++ b/apps/settings/tests/Settings/Admin/ServerTest.php @@ -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'), ], '' ); diff --git a/console.php b/console.php index 565569ef28ba8..c44c020d2de8f 100644 --- a/console.php +++ b/console.php @@ -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); } diff --git a/cron.php b/cron.php index fd7d2040f1b1f..b8202dd9a88e2 100644 --- a/cron.php +++ b/cron.php @@ -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');