Skip to content

Commit

Permalink
fix: only allow the system and admin to run the cronjobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ribeiro committed Aug 9, 2024
1 parent 0c87fe2 commit d67753c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion endpoints/cronjobs/checkforupdates.php
Original file line number Diff line number Diff line change
@@ -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"
]
];

Expand All @@ -27,4 +28,11 @@

$db->exec("UPDATE admin SET latest_version = '$latestVersion'");

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";
}
?>
1 change: 1 addition & 0 deletions endpoints/cronjobs/sendcancellationnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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';
Expand Down
1 change: 1 addition & 0 deletions endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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';
Expand Down
1 change: 1 addition & 0 deletions endpoints/cronjobs/sendresetpasswordemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

$query = "SELECT * FROM admin";
Expand Down
1 change: 1 addition & 0 deletions endpoints/cronjobs/sendverificationemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

$query = "SELECT * FROM admin";
Expand Down
1 change: 1 addition & 0 deletions endpoints/cronjobs/updateexchange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

// Get all user ids
Expand Down
1 change: 1 addition & 0 deletions endpoints/cronjobs/updatenextpayment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

$currentDate = new DateTime();
Expand Down
16 changes: 16 additions & 0 deletions endpoints/cronjobs/validate.php
Original file line number Diff line number Diff line change
@@ -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");
}
}

?>
3 changes: 3 additions & 0 deletions startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d67753c

Please sign in to comment.