-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
7,161 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Run the script every day | ||
0 0 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/updatenextpayment.php >> /var/log/cron/updatenextpayment.log 2>&1 | ||
0 1 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/updateexchange.php >> /var/log/cron/updateexchange.log 2>&1 | ||
# Run the scripts every day | ||
0 1 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/updatenextpayment.php >> /var/log/cron/updatenextpayment.log 2>&1 | ||
0 2 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/updateexchange.php >> /var/log/cron/updateexchange.log 2>&1 | ||
0 9 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/sendnotifications.php >> /var/log/cron/sendnotifications.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
#Webroot path | ||
$webPath = "/var/www/html/"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
use PHPMailer\PHPMailer\PHPMailer; | ||
use PHPMailer\PHPMailer\SMTP; | ||
use PHPMailer\PHPMailer\Exception; | ||
|
||
require_once 'conf.php'; | ||
require_once $webPath . 'includes/connect_endpoint_crontabs.php'; | ||
|
||
$query = "SELECT * FROM notifications WHERE id = 1"; | ||
$result = $db->query($query); | ||
|
||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) { | ||
$notificationsEnabled = $row['enabled']; | ||
$days = $row['days']; | ||
$smtpAddress = $row["smtp_address"]; | ||
$smtpPort = $row["smtp_port"]; | ||
$smtpUsername = $row["smtp_username"]; | ||
$smtpPassword = $row["smtp_password"]; | ||
} else { | ||
echo "Notifications are disabled. No need to run."; | ||
} | ||
|
||
if ($notificationsEnabled) { | ||
$currencies = array(); | ||
$query = "SELECT * FROM currencies"; | ||
$result = $db->query($query); | ||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) { | ||
$currencyId = $row['id']; | ||
$currencies[$currencyId] = $row; | ||
} | ||
|
||
$querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1"; | ||
$resultSubscriptions = $db->query($querySubscriptions); | ||
|
||
$notify = []; $i = 0; | ||
$currentDate = new DateTime('now'); | ||
while ($rowSubscription = $resultSubscriptions->fetchArray(SQLITE3_ASSOC)) { | ||
$nextPaymentDate = new DateTime($rowSubscription['next_payment']); | ||
$difference = $currentDate->diff($nextPaymentDate)->days + 1; | ||
if ($difference === $days) { | ||
$notify[$i]['name'] = $rowSubscription['name']; | ||
$notify[$i]['price'] = $rowSubscription['price'] . $currencies[$rowSubscription['currency_id']]['symbol']; | ||
$i++; | ||
} | ||
} | ||
|
||
if (!empty($notify)) { | ||
require $webPath . 'libs/PHPMailer/PHPMailer.php'; | ||
require $webPath . 'libs/PHPMailer/SMTP.php'; | ||
require $webPath . 'libs/PHPMailer/Exception.php'; | ||
|
||
$dayText = $days == 1 ? "tomorrow" : "in " . $days . " days" | ||
$message = "The following subscriptions are up for renewal " . $dayText . ":\n"; | ||
foreach ($notify as $subscription) { | ||
$message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; | ||
} | ||
|
||
$mail = new PHPMailer(true); | ||
$mail->isSMTP(); | ||
|
||
$mail->Host = $smtpAddress; | ||
$mail->SMTPAuth = true; | ||
$mail->Username = $smtpUsername; | ||
$mail->Password = $smtpPassword; | ||
$mail->SMTPSecure = 'tls'; | ||
$mail->Port = $smtpPort; | ||
|
||
$getUser = "SELECT * FROM user WHERE id = 1"; | ||
$user = $db->querySingle($getUser, true); | ||
$email = $user['email']; | ||
$name = $user['username']; | ||
|
||
$mail->setFrom('[email protected]', 'Wallos App'); | ||
$mail->addAddress($email, $name); | ||
|
||
$mail->Subject = 'Wallos Notification'; | ||
$mail->Body = $message; | ||
|
||
if ($mail->send()) { | ||
echo "Notifications sent"; | ||
} else { | ||
echo "Error sending notifications: " . $mail->ErrorInfo; | ||
} | ||
} else { | ||
echo "Nothing to notify."; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
|
||
if ($_SERVER["REQUEST_METHOD"] === "POST") { | ||
$postData = file_get_contents("php://input"); | ||
$data = json_decode($postData, true); | ||
|
||
if ( | ||
!isset($data["days"]) || $data['days'] == "" || | ||
!isset($data["smtpaddress"]) || $data["smtpaddress"] == "" || | ||
!isset($data["smtpport"]) || $data["smtpport"] == "" || | ||
!isset($data["smtpusername"]) || $data["smtpusername"] == "" || | ||
!isset($data["smtppassword"]) || $data["smtppassword"] == "" | ||
) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => "Please fill all fields" | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$enabled = $data["enabled"]; | ||
$days = $data["days"]; | ||
$smtpAddress = $data["smtpaddress"]; | ||
$smtpPort = $data["smtpport"]; | ||
$smtpUsername = $data["smtpusername"]; | ||
$smtpPassword = $data["smtppassword"]; | ||
|
||
$query = "SELECT COUNT(*) FROM notifications"; | ||
$result = $db->querySingle($query); | ||
|
||
if ($result === false) { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => "Error saving notifications data" | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
if ($result == 0) { | ||
$query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password) | ||
VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword)"; | ||
} else { | ||
$query = "UPDATE notifications | ||
SET enabled = :enabled, days = :days, smtp_address = :smtpAddress, smtp_port = :smtpPort, | ||
smtp_username = :smtpUsername, smtp_password = :smtpPassword"; | ||
} | ||
|
||
$stmt = $db->prepare($query); | ||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER); | ||
$stmt->bindValue(':days', $days, SQLITE3_INTEGER); | ||
$stmt->bindValue(':smtpAddress', $smtpAddress, SQLITE3_TEXT); | ||
$stmt->bindValue(':smtpPort', $smtpPort, SQLITE3_INTEGER); | ||
$stmt->bindValue(':smtpUsername', $smtpUsername, SQLITE3_TEXT); | ||
$stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT); | ||
|
||
if ($stmt->execute()) { | ||
$response = [ | ||
"success" => true | ||
]; | ||
echo json_encode($response); | ||
} else { | ||
$response = [ | ||
"success" => false, | ||
"errorMessage" => "Error saving notification data" | ||
]; | ||
echo json_encode($response); | ||
} | ||
} | ||
} | ||
} | ||
?> |
Oops, something went wrong.