Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
feat: admin can manually trigger cronjobs
Miguel Ribeiro1946ac985569
diff --git a/README.md b/README.mdindex 4b6684a..2036919 100644--- a/README.md+++ b/README.md@@ -84,6 +84,7 @@ See instructions to run Wallos below.0 9 * * * php /var/www/html/endpoints/cronjobs/sendnotifications.php >> /var/log/cron/sendnotifications.log 2>&1*/2 * * * * php /var/www/html/endpoints/cronjobs/sendverificationemails.php >> /var/log/cron/sendverificationemail.log 2>&1*/2 * * * * php /var/www/html/endpoints/cronjobs/sendresetpasswordemails.php >> /var/log/cron/sendresetpasswordemails.log 2>&1+0 */6 * * * php /var/www/html/endpoints/cronjobs/checkforupdates.php >> /var/log/cron/checkforupdates.log 2>&1```5. If your web root is not `/var/www/html/` adjust the cronjobs above accordingly.diff --git a/admin.php b/admin.phpindex 414de6c..73c3bd5 100644--- a/admin.php+++ b/admin.php@@ -352,6 +352,21 @@ $loginDisabledAllowed = $userCount == 1 && $settings['registrations_open'] == 0;<span class="number-of-logos bold"><?= $logosToDelete ?></span><?= translate('orphaned_logos', $i18n) ?></div>+ <h3><?= translate('cronjobs', $i18n) ?></h3>+ <div>+ <div class="inline">+ <input type="button" value="Check for Updates" class="button tiny mobile-grow" onclick="executeCronJob('checkforupdates')">+ <input type="button" value="Send Notifications" class="button tiny mobile-grow" onclick="executeCronJob('sendnotifications')">+ <input type="button" value="Send Cancellation Notifications" class="button tiny mobile-grow" onclick="executeCronJob('sendcancellationnotifications')">+ <input type="button" value="Send Password Reset Emails" class="button tiny mobile-grow" onclick="executeCronJob('sendresetpasswordemails')">+ <input type="button" value="Send Verification Emails" class="button tiny mobile-grow" onclick="executeCronJob('sendverificationemails')">+ <input type="button" value="Update Exchange Rates" class="button tiny mobile-grow" onclick="executeCronJob('updateexchange')">+ <input type="button" value="Update Next Payments" class="button tiny mobile-grow" onclick="executeCronJob('updatenextpayment')">+ </div>+ <div class="inline">+ <textarea id="cronjobResult" class="thin" readonly></textarea>+ </div>+ </div></div></section>diff --git a/endpoints/cronjobs/checkforupdates.php b/endpoints/cronjobs/checkforupdates.phpindex 32bcb64..e33b396 100644--- a/endpoints/cronjobs/checkforupdates.php+++ b/endpoints/cronjobs/checkforupdates.php@@ -1,10 +1,11 @@<?php+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';$options = ['http' => [- 'header' => "User-Agent: MyApp\r\n"+ 'header' => "User-Agent: Wallos\r\n"]];@@ -27,4 +28,13 @@ if (!preg_match('/^v\d+\.\d+\.\d+$/', $latestVersion)) {$db->exec("UPDATE admin SET latest_version = '$latestVersion'");++if (php_sapi_name() !== 'cli') {+ include __DIR__ . '/../../includes/version.php';+ if (version_compare($latestVersion, $version) > 0) {+ echo "New version available: $latestVersion";+ } else {+ echo "No new version available, currently on $version";+ }+}?>\ No newline at end of filediff --git a/endpoints/cronjobs/sendcancellationnotifications.php b/endpoints/cronjobs/sendcancellationnotifications.phpindex c243508..0856e8b 100644--- a/endpoints/cronjobs/sendcancellationnotifications.php+++ b/endpoints/cronjobs/sendcancellationnotifications.php@@ -3,6 +3,7 @@ use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\SMTP;use PHPMailer\PHPMailer\Exception;+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';@@ -16,7 +17,9 @@ $usersToNotify = $stmt->execute();while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {$userId = $userToNotify['id'];- echo "For user: " . $userToNotify['username'] . "<br />";+ if (php_sapi_name() !== 'cli') {+ echo "For user: " . $userToNotify['username'] . "<br />";+ }$emailNotificationsEnabled = false;$gotifyNotificationsEnabled = false;@@ -110,7 +113,9 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {// If no notifications are enabled, no need to runif (!$notificationsEnabled) {- echo "Notifications are disabled. No need to run.<br />";+ if (php_sapi_name() !== 'cli') {+ echo "Notifications are disabled. No need to run.<br />";+ }continue;} else {// Get all currencies@@ -460,7 +465,9 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {}} else {- echo "Nothing to notify.<br />";+ if (php_sapi_name() !== 'cli') {+ echo "Nothing to notify.<br />";+ }}}diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.phpindex 1298b39..0c5a5b3 100644--- a/endpoints/cronjobs/sendnotifications.php+++ b/endpoints/cronjobs/sendnotifications.php@@ -3,14 +3,17 @@ use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\SMTP;use PHPMailer\PHPMailer\Exception;+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';require __DIR__ . '/../../libs/PHPMailer/SMTP.php';require __DIR__ . '/../../libs/PHPMailer/Exception.php';-$date = new DateTime('now');-echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";+if (php_sapi_name() == 'cli') {+ $date = new DateTime('now');+ echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";+}// Get all user ids$query = "SELECT id, username FROM user";@@ -19,7 +22,9 @@ $usersToNotify = $stmt->execute();while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {$userId = $userToNotify['id'];- echo "\nFor user: " . $userToNotify['username'] . "<br />";+ if (php_sapi_name() !== 'cli') {+ echo "\nFor user: " . $userToNotify['username'] . "<br />";+ }$days = 1;$emailNotificationsEnabled = false;@@ -145,7 +150,9 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {// If no notifications are enabled, no need to runif (!$notificationsEnabled) {- echo "Notifications are disabled. No need to run.<br />";+ if (php_sapi_name() !== 'cli') {+ echo "Notifications are disabled. No need to run.<br />";+ }continue;} else {// Get all currencies@@ -573,7 +580,9 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {} else {- echo "Nothing to notify.<br />";+ if (php_sapi_name() !== 'cli') {+ echo "Nothing to notify.<br />";+ }}}diff --git a/endpoints/cronjobs/sendresetpasswordemails.php b/endpoints/cronjobs/sendresetpasswordemails.phpindex 901d625..c25c41f 100644--- a/endpoints/cronjobs/sendresetpasswordemails.php+++ b/endpoints/cronjobs/sendresetpasswordemails.php@@ -3,6 +3,7 @@ use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\SMTP;use PHPMailer\PHPMailer\Exception;+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';$query = "SELECT * FROM admin";@@ -72,10 +73,16 @@ if ($rows) {}} else {// There are no SMTP settings+ if (php_sapi_name() !== 'cli') {+ echo "SMTP settings are not configured. Please configure SMTP settings in the admin page.";+ }exit();}} else {// There are no password reset emails to be sent+ if (php_sapi_name() !== 'cli') {+ echo "There are no password reset emails to be sent.";+ }exit();}diff --git a/endpoints/cronjobs/sendverificationemails.php b/endpoints/cronjobs/sendverificationemails.phpindex 1322f13..aab55bd 100644--- a/endpoints/cronjobs/sendverificationemails.php+++ b/endpoints/cronjobs/sendverificationemails.php@@ -3,6 +3,7 @@ use PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\SMTP;use PHPMailer\PHPMailer\Exception;+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';$query = "SELECT * FROM admin";@@ -11,7 +12,10 @@ $result = $stmt->execute();$admin = $result->fetchArray(SQLITE3_ASSOC);if ($admin['require_email_verification'] == 0) {- die("Email verification is not required.");+ if (php_sapi_name() !== 'cli') {+ echo "Email verification is not required.";+ }+ die();}$query = "SELECT * FROM email_verification WHERE email_sent = 0";@@ -75,10 +79,16 @@ if ($rows) {}} else {// There are no SMTP settings+ if (php_sapi_name() !== 'cli') {+ echo "SMTP settings are not configured. Please configure SMTP settings in the admin page.";+ }exit();}} else {// There are no verification emails to be sent+ if (php_sapi_name() !== 'cli') {+ echo "No verification emails to be sent.";+ }exit();}diff --git a/endpoints/cronjobs/updateexchange.php b/endpoints/cronjobs/updateexchange.phpindex 40f6196..3af408b 100644--- a/endpoints/cronjobs/updateexchange.php+++ b/endpoints/cronjobs/updateexchange.php@@ -1,8 +1,14 @@<?php+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';// Get all user ids+if (php_sapi_name() == 'cli') {+ $date = new DateTime('now');+ echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";+}+$query = "SELECT id, username FROM user";$stmt = $db->prepare($query);$usersToUpdateExchange = $stmt->execute();diff --git a/endpoints/cronjobs/updatenextpayment.php b/endpoints/cronjobs/updatenextpayment.phpindex 70ad028..308b862 100644--- a/endpoints/cronjobs/updatenextpayment.php+++ b/endpoints/cronjobs/updatenextpayment.php@@ -1,7 +1,13 @@<?php+require_once 'validate.php';require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';+if (php_sapi_name() == 'cli') {+ $date = new DateTime('now');+ echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";+}+$currentDate = new DateTime();$currentDateString = $currentDate->format('Y-m-d');diff --git a/endpoints/cronjobs/validate.php b/endpoints/cronjobs/validate.phpnew file mode 100644index 0000000..d22dbda--- /dev/null+++ b/endpoints/cronjobs/validate.php@@ -0,0 +1,16 @@+<?php++session_start();++$userId = 0;+if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {+ $userId = $_SESSION['userId'];+}++if (php_sapi_name() !== 'cli') {+ if ($userId !== 1) {+ die("Unauthorized");+ }+}++?>\ No newline at end of filediff --git a/includes/i18n/de.php b/includes/i18n/de.phpindex 398aa08..c36d16f 100644--- a/includes/i18n/de.php+++ b/includes/i18n/de.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Neueste Version","on_current_version" => "Sie verwenden die neueste Version von Wallos.","show_update_notification" => "Benachrichtigung über Updates auf dem Dashboard anzeigen",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "E-Mail verifiziert","email_verification_failed" => "E-Mail konnte nicht verifiziert werden",diff --git a/includes/i18n/el.php b/includes/i18n/el.phpindex b0c3bf4..6f65ba5 100644--- a/includes/i18n/el.php+++ b/includes/i18n/el.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Τελευταία Έκδοση","on_current_version" => "Χρησιμοποιείτε την τελευταία έκδοση του Wallos.","show_update_notification" => "Εμφάνιση ειδοποίησης για ενημερώσεις στο dashboard",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Το email επιβεβαιώθηκε","email_verification_failed" => "Η επαλήθευση email απέτυχε",diff --git a/includes/i18n/en.php b/includes/i18n/en.phpindex 6e84637..a1f1b06 100644--- a/includes/i18n/en.php+++ b/includes/i18n/en.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Latest Version","on_current_version" => "You're running the latest version of Wallos.","show_update_notification" => "Show notification for updates on the dashboard",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Email verified successfully","email_verification_failed" => "Email verification failed",diff --git a/includes/i18n/es.php b/includes/i18n/es.phpindex 2ce4ef6..2187da1 100644--- a/includes/i18n/es.php+++ b/includes/i18n/es.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Última Versión","on_current_version" => "Está utilizando la última versión de Wallos.","show_update_notification" => "Mostrar notificación de actualizaciones en el dashboard",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Correo electrónico verificado","email_verification_failed" => "Error al verificar el correo electrónico",diff --git a/includes/i18n/fr.php b/includes/i18n/fr.phpindex cba8f07..e3a42b5 100644--- a/includes/i18n/fr.php+++ b/includes/i18n/fr.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Dernière version","on_current_version" => "Vous utilisez la dernière version de Wallos.","show_update_notification" => "Afficher la notification de mise à jour sur le tableau de bord",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Votre adresse courriel a été vérifiée avec succès","email_verification_failed" => "La vérification de l'adresse courriel a échoué",diff --git a/includes/i18n/it.php b/includes/i18n/it.phpindex ff441ef..19fdfa6 100644--- a/includes/i18n/it.php+++ b/includes/i18n/it.php@@ -335,6 +335,7 @@ $i18n = ["latest_version" => "Ultima versione","on_current_version" => "Stai utilizzando l'ultima versione di Wallos.","show_update_notification" => "Mostra notifica di aggiornamento sulla dashboard",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "L'indirizzo email è stato verificato con successo",diff --git a/includes/i18n/jp.php b/includes/i18n/jp.phpindex 5c9be3c..a84d8c8 100644--- a/includes/i18n/jp.php+++ b/includes/i18n/jp.php@@ -309,6 +309,7 @@ $i18n = ["latest_version" => "最新バージョン","on_current_version" => "最新バージョンのWallosを使用しています。","show_update_notification" => "ダッシュボードに更新通知を表示する",+ "cronjobs" => "クロンジョブズ",// Email Verification"email_verified" => "メールアドレスが確認されました","email_verification_failed" => "メールアドレスの確認に失敗しました",diff --git a/includes/i18n/ko.php b/includes/i18n/ko.phpindex d1eff9f..59efc08 100644--- a/includes/i18n/ko.php+++ b/includes/i18n/ko.php@@ -317,6 +317,7 @@ $i18n = ["latest_version" => "최신 버전","on_current_version" => "최신 버전의 Wallos를 사용 중입니다.","show_update_notification" => "대시보드에 업데이트 알림 표시",+ "cronjobs" => "크론잡",// Email Verification"email_verified" => "이메일 인증 완료","email_verification_failed" => "이메일 인증 실패",diff --git a/includes/i18n/pl.php b/includes/i18n/pl.phpindex fa402cb..fb5da28 100644--- a/includes/i18n/pl.php+++ b/includes/i18n/pl.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Najnowsza wersja","on_current_version" => "Używasz najnowszej wersji Wallos.","show_update_notification" => "Pokaż powiadomienie o aktualizacjach na dashboardzie",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "E-mail został zweryfikowany","email_verification_failed" => "Weryfikacja e-maila nie powiodła się",diff --git a/includes/i18n/pt.php b/includes/i18n/pt.phpindex ad2895c..1622572 100644--- a/includes/i18n/pt.php+++ b/includes/i18n/pt.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Última Versão","on_current_version" => "Está a usar a versão mais recente do Wallos.","show_update_notification" => "Mostrar notificação de atualizações no dashboard",+ "Cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Email verificado","email_verification_failed" => "Verificação de email falhou",diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.phpindex aa054e1..040418c 100644--- a/includes/i18n/pt_br.php+++ b/includes/i18n/pt_br.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" =>"Última versão","on_current_version" => "Você está na última versão do Wallos.","show_update_notification" => "Mostrar notificação de atualização no dashboard",+ "Cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Email verificado","email_verification_failed" => "Falha na verificação do email",diff --git a/includes/i18n/ru.php b/includes/i18n/ru.phpindex fb78e87..b8be5bb 100644--- a/includes/i18n/ru.php+++ b/includes/i18n/ru.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Последняя версия","on_current_version" => "Вы используете последнюю версию Wallos.","show_update_notification" => "Показывать уведомление об обновлениях на дашборде",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "Ваш адрес электронной почты подтвержден. Теперь вы можете войти.","email_verification_failed" => "Не удалось подтвердить ваш адрес электронной почты.",diff --git a/includes/i18n/sl.php b/includes/i18n/sl.phpindex c1960c7..16145e0 100644--- a/includes/i18n/sl.php+++ b/includes/i18n/sl.php@@ -309,6 +309,7 @@ $i18n = ["latest_version" => "Najnovejša različica","on_current_version" => "Uporabljate najnovejšo različico Wallos.","show_update_notification" => "Prikaži obvestilo o posodobitvah na dashboardu",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "E-pošta je bila uspešno preverjena","email_verification_failed" => "Preverjanje e-pošte ni uspelo",diff --git a/includes/i18n/sr.php b/includes/i18n/sr.phpindex 3f17d62..1e04ac3 100644--- a/includes/i18n/sr.php+++ b/includes/i18n/sr.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Најновија верзија","on_current_version" => "Користите најновију верзију Wallos-а.","show_update_notification" => "Прикажи обавештење о ажурирањима на dashboardu",+ "cronjobs" => "Цроњобс",// Email Verification"email_verified" => "Е-пошта је верификована","email_verification_failed" => "Верификација е-поште није успела",diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.phpindex fd0e30a..4f42e82 100644--- a/includes/i18n/sr_lat.php+++ b/includes/i18n/sr_lat.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "Najnovija verzija","on_current_version" => "Koristite najnoviju verziju Wallos-a.","show_update_notification" => "Prikaži obaveštenje o ažuriranjima na dashboardu",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "E-pošta je uspešno verifikovana","email_verification_failed" => "Verifikacija e-pošte nije uspela",diff --git a/includes/i18n/tr.php b/includes/i18n/tr.phpindex c589c25..1c5baf6 100644--- a/includes/i18n/tr.php+++ b/includes/i18n/tr.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "En Son Sürüm","on_current_version" => "Wallos'un en son sürümünü kullanıyorsunuz.","show_update_notification" => "Gösterge panelinde güncelleme bildirimini göster",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "E-posta doğrulandı","email_verification_failed" => "E-posta doğrulaması başarısız oldu",diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.phpindex 3ded75a..aee47e3 100644--- a/includes/i18n/zh_cn.php+++ b/includes/i18n/zh_cn.php@@ -334,6 +334,7 @@ $i18n = ["latest_version" => "最新版本","on_current_version" => "您正在运行最新版本的 Wallos。","show_update_notification" => "在仪表板上显示更新通知",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "电子邮件已验证",diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.phpindex 11a7922..be1e811 100644--- a/includes/i18n/zh_tw.php+++ b/includes/i18n/zh_tw.php@@ -316,6 +316,7 @@ $i18n = ["latest_version" => "最新版本","on_current_version" => "您正在運行最新版本的 Wallos。","show_update_notification" => "在儀表板上顯示更新通知",+ "cronjobs" => "Cronjobs",// Email Verification"email_verified" => "電子郵件已驗證","email_verification_failed" => "電子郵件驗證失敗",diff --git a/includes/version.php b/includes/version.phpindex 3dadda1..d5d110e 100644--- a/includes/version.php+++ b/includes/version.php@@ -1,3 +1,3 @@<?php-$version = "v2.21.3";+$version = "v2.22.0";?>\ No newline at end of filediff --git a/scripts/admin.js b/scripts/admin.jsindex 8a26751..b7a00d9 100644--- a/scripts/admin.js+++ b/scripts/admin.js@@ -314,4 +314,22 @@ function toggleUpdateNotification() {}).catch(error => showErrorMessage('Error:', error));+}++function executeCronJob(job) {+ const url = `endpoints/cronjobs/${job}.php`;+ const resultTextArea = document.getElementById('cronjobResult');++ fetch(url)+ .then(response => {+ return response.text();+ })+ .then(data => {+ const formattedData = data.replace(/<br\s*\/?>/gi, '\n');+ resultTextArea.value = formattedData;+ })+ .catch(error => {+ console.error('Fetch error:', error);+ showErrorMessage('Error:', error);+ });}\ No newline at end of filediff --git a/startup.sh b/startup.shindex 46d0875..7400b17 100644--- a/startup.sh+++ b/startup.sh@@ -43,5 +43,8 @@ crontab -d -u root# Run updateexchange.php/usr/local/bin/php /var/www/html/endpoints/cronjobs/updateexchange.php+# Run checkforupdates.php+/usr/local/bin/php /var/www/html/endpoints/cronjobs/checkforupdates.php+# Keep the container running indefinitely (this won't exit)tail -f /dev/null\ No newline at end of filediff --git a/styles/styles.css b/styles/styles.cssindex caff7e2..7db7315 100644--- a/styles/styles.css+++ b/styles/styles.css@@ -1054,6 +1054,14 @@ header #avatar {flex-basis: 50%;}+.inline {+ display: flex;+ flex-direction: row;+ flex-wrap: wrap;+ gap: 15px;+ margin-bottom: 20px;+}+@media (max-width: 768px) {.form-group .inline .mobile-split-50 {flex-basis: 50%;