Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve teampass cron detection. #4446

Merged
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
17 changes: 11 additions & 6 deletions pages/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
* @license GPL-3.0
* @see https://www.teampass.net
*/
use TiBeN\CrontabManager\CrontabJob;
use TiBeN\CrontabManager\CrontabAdapter;
use TiBeN\CrontabManager\CrontabRepository;
use TeampassClasses\SessionManager\SessionManager;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use TeampassClasses\Language\Language;
Expand Down Expand Up @@ -199,9 +196,17 @@

// Instantiate the adapter and repository
try {
$crontabRepository = new CrontabRepository(new CrontabAdapter());
$results = $crontabRepository->findJobByRegex('/Teampass\ scheduler/');
if (count($results) === 0) {
// Get last cron execution timestamp
$result = DB::query(
'SELECT valeur
FROM ' . prefixTable('misc') . '
WHERE type = %s AND intitule = %s and valeur >= %d',
'admin',
'last_cron_exec',
time() - 600 // max 10 minutes
);

if (DB::count() === 0) {
?>
<div class="callout callout-info alert-dismissible mt-3" role="alert">
<h5><i class="fa-solid fa-info mr-2"></i><?php echo $lang->get('information'); ?></h5>
Expand Down
17 changes: 11 additions & 6 deletions pages/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
* @license GPL-3.0
* @see https://www.teampass.net
*/
use TiBeN\CrontabManager\CrontabJob;
use TiBeN\CrontabManager\CrontabAdapter;
use TiBeN\CrontabManager\CrontabRepository;
use TeampassClasses\SessionManager\SessionManager;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use TeampassClasses\Language\Language;
Expand Down Expand Up @@ -126,9 +123,17 @@

// Instantiate the adapter and repository
try {
$crontabRepository = new CrontabRepository(new CrontabAdapter());
$results = $crontabRepository->findJobByRegex('/Teampass\ scheduler/');
if (count($results) === 0) {
// Get last cron execution timestamp
$result = DB::query(
'SELECT valeur
FROM ' . prefixTable('misc') . '
WHERE type = %s AND intitule = %s and valeur >= %d',
'admin',
'last_cron_exec',
time() - 600 // max 10 minutes
);

if (DB::count() === 0) {
?>
<div class="callout callout-info alert-dismissible mt-3">
<h5><i class="fa-solid fa-info mr-2"></i><?php echo $lang->get('information'); ?></h5>
Expand Down
17 changes: 17 additions & 0 deletions sources/scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
$configManager = new ConfigManager();
$SETTINGS = $configManager->getAllSettings();

// Update row if exists
$updated = DB::update(
prefixTable('misc'),
['valeur' => time()],
'type = "admin" AND intitule = "last_cron_exec"'
);

// Insert row if not exists
if ($updated === 0) {
DB::insert(
prefixTable('misc'), [
'type' => 'admin',
'intitule' => 'last_cron_exec',
'valeur' => time()
]);
}

// Build the scheduler jobs
// https://github.com/peppeocchi/php-cron-scheduler
$scheduler->php(__DIR__.'/../scripts/background_tasks___userKeysCreation.php')->everyMinute($SETTINGS['user_keys_job_frequency'] ?? '1');
Expand Down