Skip to content

Commit a2e0cab

Browse files
committed
Update to read relevant options from DB
1 parent 78bb717 commit a2e0cab

File tree

5 files changed

+97
-35
lines changed

5 files changed

+97
-35
lines changed

admin/index.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
define("WEB_URL", $db->getSetting($mysqli,"url"));
2020
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
2121
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
22+
23+
define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli, "google_recaptcha"));
24+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli, "google_recaptcha_secret"));
25+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli, "google_recaptcha_sitekey"));
26+
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli, "subscribe_email"));
27+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
28+
define("TG_BOT_USERNAME", $db->getSetting($mysqli, "tg_bot_username"));
29+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli, "tg_bot_api_token"));
30+
define("PHP_MAILER", $db->getBooleanSetting($mysqli, "php_mailer"));
31+
define("PHP_MAILER_SMTP", $db->getBooleanSetting($mysqli, "php_mailer_smtp"));
32+
define("PHP_MAILER_PATH", $db->getSetting($mysqli, "php_mailer_path"));
33+
define("PHP_MAILER_HOST", $db->getSetting($mysqli, "php_mailer_host"));
34+
define("PHP_MAILER_PORT", $db->getSetting($mysqli, "php_mailer_port"));
35+
define("PHP_MAILER_SECURE", $db->getBooleanSetting($mysqli, "php_mailer_secure"));
36+
define("PHP_MAILER_USER", $db->getSetting($mysqli, "php_mailer_user"));
37+
define("PHP_MAILER_PASS", $db->getSetting($mysqli, "php_mailer_pass"));
38+
define("CRON_SERVER_IP", $db->getSetting($mysqli, "cron_server_ip"));
39+
2240
// Process the subscriber notification queue
2341
// If CRON_SERVER_IP is not set, call notification once incident has been saved
2442
if ( empty(CRON_SERVER_IP) )
@@ -95,11 +113,11 @@
95113
case 'options':
96114
require_once("options.php");
97115
break;
98-
116+
99117
case 'logout':
100118
User::logout();
101119
break;
102-
120+
103121
default:
104122
require_once("dashboard.php");
105123
break;

email_subscriptions.php

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
define("WEB_URL", $db->getSetting($mysqli,"url"));
1414
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
1515
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
16+
define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli, "google_recaptcha"));
17+
//define("", $db->getSettings($mysqli, ""));
18+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli, "google_recaptcha_secret"));
19+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli, "google_recaptcha_sitekey"));
20+
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli, "subscribe_email"));
21+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
22+
define("TG_BOT_USERNAME", $db->getSetting($mysqli, "tg_bot_username"));
23+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli, "tg_bot_api_token"));
24+
define("PHP_MAILER", $db->getBooleanSetting($mysqli, "php_mailer"));
25+
define("PHP_MAILER_SMTP", $db->getBooleanSetting($mysqli, "php_mailer_smtp"));
26+
define("PHP_MAILER_PATH", $db->getSetting($mysqli, "php_mailer_path"));
27+
define("PHP_MAILER_HOST", $db->getSetting($mysqli, "php_mailer_host"));
28+
define("PHP_MAILER_PORT", $db->getSetting($mysqli, "php_mailer_port"));
29+
define("PHP_MAILER_SECURE", $db->getBooleanSetting($mysqli, "php_mailer_secure"));
30+
define("PHP_MAILER_USER", $db->getSetting($mysqli, "php_mailer_user"));
31+
define("PHP_MAILER_PASS", $db->getSetting($mysqli, "php_mailer_pass"));
32+
1633
$mailer = new Mailer();
1734
$subscriber = new Subscriber();
1835
$subscription = new Subscriptions();
@@ -25,18 +42,18 @@
2542
// Form validation for subscribers signing up
2643
$message = "";
2744
Template :: render_header(_("Email Subscription"));
28-
45+
2946
if (isset($_POST['emailaddress'])) {
30-
47+
3148
if (0 == strlen(trim($_POST['emailaddress']))){
3249
$messages[] = _("Email address");
3350
}
34-
51+
3552
// Perform DNS domain validation on
3653
if ( ! $mailer->verify_domain($_POST['emailaddress']) ) {
3754
$messages[] = _("Domain does not apper to be a valid email domain. (Check MX record)");
3855
}
39-
56+
4057
if (GOOGLE_RECAPTCHA) {
4158
// Validate recaptcha
4259
$response = $_POST["g-recaptcha-response"];
@@ -70,7 +87,7 @@
7087
if(isset($_POST['emailaddress']) && empty($message))
7188
{
7289

73-
// Check if email is already registered
90+
// Check if email is already registered
7491
$boolUserExist = false;
7592
$subscriber->userID = $_POST['emailaddress'];
7693
$subscriber->typeID = 2; // Email
@@ -82,17 +99,17 @@
8299
// Create a new subscriber as it does not exist
83100
$subscriber->add($subscriber->typeID, $_POST['emailaddress']);
84101
$url = WEB_URL."/index.php?do=manage&token=".$subscriber->token; // Needed again after adding subscriber since token did not exist before add
85-
$msg = sprintf(_("Thank you for registering to receive status updates via email.</br></br> Click on the following link to confirm and manage your subcription: <a href=\"%s\">%s</a>. New subscriptions must be confirmed within 2 hours"), $url, NAME .' - ' . _("Validate subscription"));
86-
102+
$msg = sprintf(_("Thank you for registering to receive status updates via email.</br></br> Click on the following link to confirm and manage your subcription: <a href=\"%s\">%s</a>. New subscriptions must be confirmed within 2 hours"), $url, NAME .' - ' . _("Validate subscription"));
103+
87104
} else {
88105
if ( ! $subscriber->active ) {
89106
// Subscriber is registered, but has not been activated yet...
90107
$msg = sprintf(_("Thank you for registering to receive status updates via email.</br></br> Click on the following link to confirm and manage your subcription: <a href=\"%s\">%s</a>. New subscriptions must be confirmed within 2 hours"), $url, NAME .' - ' . _("Validate subscription"));
91108
$subscriber->activate($subscriber->id);
92-
109+
93110
} else {
94111
// subscriber is registered and active
95-
$msg = sprintf(_("Click on the following link to update your existing subscription: <a href=\"%s\">%s</a>"), $url, NAME .' - ' . _("Manage subscription"));
112+
$msg = sprintf(_("Click on the following link to update your existing subscription: <a href=\"%s\">%s</a>"), $url, NAME .' - ' . _("Manage subscription"));
96113
$subscriber->update($subscriber->id);
97114
}
98115
}
@@ -101,10 +118,10 @@
101118
$message = _("You will receive an email shortly with an activation link. Please click on the link to activate and/or manage your subscription.");
102119
$constellation->render_success($header, $message, true, WEB_URL, _('Go back'));
103120

104-
// Send email about new registration
121+
// Send email about new registration
105122
$subject = _('Email subscription registered').' - '.NAME;
106123
$mailer->send_mail($_POST['emailaddress'], $subject, $msg);
107-
124+
108125
$boolRegistered = true;
109126
}
110127

@@ -116,8 +133,8 @@
116133
}
117134
$strPostedEmail = (isset($_POST['emailaddress'])) ? $_POST['emailaddress'] : "";
118135
?>
119-
120-
136+
137+
121138
<form method="post" action="index.php?do=email_subscription&new=1" class="clearfix" enctype="multipart/form-data" >
122139
<h3><?php echo _('Subscribe to get email notifications on status updates');?></h3>
123140
<div class="form-group clearfix">
@@ -154,7 +171,7 @@
154171
// check if userid/token combo is valid, active or expired
155172
$subscriber->typeID = 2; //EMAIL
156173
if ( $subscriber->is_active_subscriber($_GET['token']) ) {
157-
// forward user to subscriber list....
174+
// forward user to subscriber list....
158175
$subscriber->set_logged_in();
159176
header('Location: subscriptions.php');
160177
exit;
@@ -165,38 +182,38 @@
165182
$message = _("If you have recently subscribed, please make sure you activate the account within two hours of doing so. You are welcome to try and re-subscribe.");
166183
$constellation->render_warning($header, $message, true, WEB_URL, _('Go back'));
167184
}
168-
169-
185+
186+
170187
} else if (isset($_GET['do']) && $_GET['do'] == 'unsubscribe') {
171188
// Handle unsubscriptions
172189
// TODO This function is universal and should probably live elsewhere??
173190
if (isset($_GET['token'])) {
174-
$subscriber->typeID = (int) $_GET['type'];
175-
191+
$subscriber->typeID = (int) $_GET['type'];
192+
176193
if ( $subscriber->get_subscriber_by_token($_GET['token'])) {
177194
$subscriber->delete($subscriber->id);
178195
$subscriber->set_logged_off();
179196
Template :: render_header(_("Email Subscription"));
180-
197+
181198
$header = _("You have been unsubscribed from our system");
182199
$message = _("We are sorry to see you go. If you want to subscribe again at a later date please feel free to re-subscribe.");
183-
$constellation->render_success($header, $message, true, WEB_URL, _('Go back'));
184-
200+
$constellation->render_success($header, $message, true, WEB_URL, _('Go back'));
201+
185202
} else {
186203
// TODO Log token for troubleshooting ?
187204
// Cannot find subscriber - show alert
188205
Template :: render_header(_("Email Subscription"));
189206
$header = _("We are unable to find any valid subscriber detail matching your submitted data!");
190-
$message = _("If you believe this to be an error, please contact the system admininistrator.");
207+
$message = _("If you believe this to be an error, please contact the system admininistrator.");
191208
$constellation->render_warning($header, $message, true, WEB_URL, _('Go back'));
192-
193-
//
209+
210+
//
194211
}
195212
} else {
196213
// TODO Log $_GET[] for troubleshooting ?
197214
$header = _("We are unable to find any valid subscriber detail matching your submitted data!");
198-
$message = _("If you believe this to be an error, please contact the system admininistrator.");
199-
$constellation->render_warning($header, $message, true, WEB_URL, _('Go back'));
200-
}
215+
$message = _("If you believe this to be an error, please contact the system admininistrator.");
216+
$constellation->render_warning($header, $message, true, WEB_URL, _('Go back'));
217+
}
201218
}
202219
Template :: render_footer();

index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
define("WEB_URL", $db->getSetting($mysqli,"url"));
4141
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
4242
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
43+
44+
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli,"subscribe_email"));
45+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli,"subscribe_telegram"));
46+
define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username"));
47+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token"));
48+
define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli,"google_recaptcha"));
49+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey"));
50+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret"));
4351
$offset = 0;
4452

4553
if (isset($_GET['ajax']))

subscriptions.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
require_once("config.php");
33
require_once("template.php");
44
require_once("classes/constellation.php");
@@ -11,6 +11,14 @@
1111
define("WEB_URL", $db->getSetting($mysqli,"url"));
1212
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
1313
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
14+
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli, "subscribe_email"));
15+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
16+
define("GOOGLE_RECAPTCHA", $db->getSetting($mysqli, "google_recaptcha"));
17+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli, "google_recaptcha_secret"));
18+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli, "google_recaptcha_sitekey"));
19+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli, "tg_bot_api_token"));
20+
define("TG_BOT_USERNAME", $db->getSetting($mysqli, "tg_bot_username"));
21+
1422
$subscription = new Subscriptions();
1523
$telegram = new Telegram();
1624

@@ -21,12 +29,12 @@
2129
}
2230

2331
if( $_SESSION['subscriber_valid'] ){
24-
32+
2533
$typeID = $_SESSION['subscriber_typeid'];
26-
$subscriberID = $_SESSION['subscriber_id'];
34+
$subscriberID = $_SESSION['subscriber_id'];
2735
$userID = $_SESSION['subscriber_userid'];
2836
$token = $_SESSION['subscriber_token'];
29-
37+
3038
if(isset($_GET['add'])){
3139
$subscription->add($subscriberID, $_GET['add']);
3240
}
@@ -38,11 +46,11 @@
3846
$subscription->render_subscribed_services($typeID, $subscriberID, $userID, $token);
3947

4048
} else {
41-
49+
4250
$header = _("Your session has expired or you tried something we don't suppprt");
4351
$message = _('If your session expired, retry your link or in case of Telegram use the login button in the top menu.');
4452
$constellation->render_warning($header, $message);
45-
53+
4654
header('Location: index.php');
4755
}
4856

telegram_check.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
require_once ("config.php");
33
require_once ("classes/telegram.php");
44
require_once ("classes/subscriber.php");
5+
require_once ("classes/db-class.php");
6+
$db = new SSDB();
7+
define("NAME", $db->getSetting($mysqli,"name"));
8+
define("TITLE", $db->getSetting($mysqli,"title"));
9+
define("WEB_URL", $db->getSetting($mysqli,"url"));
10+
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
11+
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
12+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
13+
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
14+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli, "tg_bot_api_token"));
15+
define("TG_BOT_USERNAME", $db->getSetting($mysqli, "tg_bot_username"));
516

617
$telegram = new Telegram();
718
$subscriber = new Subscriber();

0 commit comments

Comments
 (0)