Skip to content

Commit 5d99ed7

Browse files
authored
Merge pull request #3 from thnilsen1/move_config_options
Removed Telegram and email notification setup from install routine.
2 parents 5a275f3 + a2e0cab commit 5d99ed7

File tree

10 files changed

+268
-80
lines changed

10 files changed

+268
-80
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;

admin/options.php

Lines changed: 140 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
function getToggle($variable){
3+
$res = ((isset($variable) && ($variable == "on")) ? "yes" : "no");
4+
return $res;
5+
}
6+
27

38
if (!file_exists("../config.php"))
49
{
@@ -15,29 +20,78 @@
1520
require_once("../classes/db-class.php");
1621
}
1722
$db = new SSDB();
18-
if(trim($db->getSetting($mysqli,"notifyUpdates")) == "yes"){
19-
$notifyUpdates_status = true;
20-
} else {
21-
$notifyUpdates_status = false;
22-
}
23+
$notifyUpdates_status = $db->getBooleanSetting($mysqli, "notifyUpdates");
24+
$emailSubscription_status = $db->getBooleanSetting($mysqli, "subscribe_email");
25+
$telegramSubscription_status = $db->getBooleanSetting($mysqli, "subscribe_telegram");
26+
$tg_bot_api_token = $db->getSetting($mysqli, "tg_bot_api_token");
27+
$tg_bot_username = $db->getSetting($mysqli, "tg_bot_username");
28+
$php_mailer_status = $db->getBooleanSetting($mysqli, "php_mailer");
29+
$php_mailer_smtp_status = $db->getBooleanSetting($mysqli, "php_mailer_smtp");
30+
$php_mailer_secure_status = $db->getBooleanSetting($mysqli, "php_mailer_secure");
31+
$php_mailer_path = $db->getSetting($mysqli, "php_mailer_path");
32+
$php_mailer_host = $db->getSetting($mysqli, "php_mailer_host");
33+
$php_mailer_port = $db->getSetting($mysqli, "php_mailer_port");
34+
$php_mailer_user = $db->getSetting($mysqli, "php_mailer_user");
35+
$php_mailer_pass = $db->getSetting($mysqli, "php_mailer_pass");
36+
$cron_server_ip = $db->getSetting($mysqli, "cron_server_ip");
37+
$google_rechaptcha_status = $db->getBooleanSetting($mysqli, "google_recaptcha");
38+
$google_recaptcha_sitekey = $db->getSetting($mysqli, "google_recaptcha_sitekey");
39+
$google_recaptcha_secret = $db->getSetting($mysqli, "google_recaptcha_secret");
40+
41+
$db->getSetting($mysqli, "");
2342
$set_post = false;
2443
if(!empty($_POST)){
25-
if($_POST["nu_toggle"] == "on"){ $nu_toggle = "yes"; } else { $nu_toggle = "no"; }
26-
$db->deleteSetting($mysqli,"notifyUpdates");
27-
$db->setSetting($mysqli,"notifyUpdates",$nu_toggle);
28-
$db->deleteSetting($mysqli,"name");
29-
$db->setSetting($mysqli,"name",$_POST["sitename"]);
44+
$db->updateSetting($mysqli, "notifyUpdates", getToggle($_POST["nu_toggle"]));
45+
$db->updateSetting($mysqli, "name",htmlspecialchars($_POST["sitename"], ENT_QUOTES));
46+
$db->updateSetting($mysqli, "subscribe_email", getToggle($_POST["email_subscription_toggle"]));
47+
$db->updateSetting($mysqli, "subscribe_telegram", getToggle($_POST["telegram_subscription_toggle"]));
48+
$db->updateSetting($mysqli, "tg_bot_api_token", htmlspecialchars($_POST["tg_bot_api_token"], ENT_QUOTES));
49+
$db->updateSetting($mysqli, "tg_bot_username", htmlspecialchars($_POST["tg_bot_username"], ENT_QUOTES));
50+
$db->updateSetting($mysqli, "php_mailer", getToggle($_POST["php_mailer_toggle"]));
51+
$db->updateSetting($mysqli, "php_mailer_smtp", getToggle($_POST["php_mailer_smtp_toggle"]));
52+
$db->updateSetting($mysqli, "php_mailer_secure", getToggle($_POST["php_mailer_secure_toggle"]));
53+
$db->updateSetting($mysqli, "php_mailer_path", htmlspecialchars($_POST["php_mailer_path"], ENT_QUOTES));
54+
$db->updateSetting($mysqli, "php_mailer_host", htmlspecialchars($_POST["php_mailer_host"], ENT_QUOTES));
55+
$db->updateSetting($mysqli, "php_mailer_port", htmlspecialchars($_POST["php_mailer_port"], ENT_QUOTES));
56+
$db->updateSetting($mysqli, "php_mailer_user", htmlspecialchars($_POST["php_mailer_user"], ENT_QUOTES));
57+
$db->updateSetting($mysqli, "php_mailer_pass", htmlspecialchars($_POST["php_mailer_pass"], ENT_QUOTES));
58+
$db->updateSetting($mysqli, "cron_server_ip", htmlspecialchars($_POST["cron_server_ip"], ENT_QUOTES));
59+
$db->updateSetting($mysqli, "google_recaptcha", getToggle($_POST["google_rechaptcha_toggle"]));
60+
$db->updateSetting($mysqli, "google_recaptcha_sitekey", htmlspecialchars($_POST["google_recaptcha_sitekey"], ENT_QUOTES));
61+
$db->updateSetting($mysqli, "google_recaptcha_secret", htmlspecialchars($_POST["google_recaptcha_secret"], ENT_QUOTES));
62+
3063
$set_post = true;
31-
if($nu_toggle == "yes"){
64+
/*if($nu_toggle == "yes"){
3265
$notifyUpdates_status = true;
3366
} else {
3467
$notifyUpdates_status = false;
35-
}
36-
define("NAME", $db->getSetting($mysqli,"name"));
68+
}*/
69+
// TODO - Reload page to prevent showing old values! or update variables being displayed
70+
header("Location: " .$uri = $_SERVER['REQUEST_URI']);
71+
// TODO - The code below will not happen ...
72+
73+
/*define("NAME", $db->getSetting($mysqli,"name"));
3774
define("TITLE", $db->getSetting($mysqli,"title"));
3875
define("WEB_URL", $db->getSetting($mysqli,"url"));
3976
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
4077
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
78+
define("SUBSCRIBER_EMAIL", $db->getSetting($mysqli,"subscriber_email"));
79+
define("SUBSCRIBER_TELEGRAM", $db->getSetting($mysqli,"subscriber_telegram"));
80+
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token"));
81+
define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username"));
82+
define("GOOGLE_RECAPTCHA", $db->getSetting($mysqli,"google_recaptcha"));
83+
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey"));
84+
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret"));
85+
define("PHP_MAILER", $db->getSetting($mysqli,"php_mailer"));
86+
define("PHP_MAILER_PATH", $db->getSetting($mysqli,"php_mailer_path"));
87+
define("PHP_MAILER_SMTP", $db->getSetting($mysqli,"php_mailer_smtp"));
88+
define("PHP_MAILER_HOST", $db->getSetting($mysqli,"php_mailer_host"));
89+
define("PHP_MAILER_PORT", $db->getSetting($mysqli,"php_mailer_port"));
90+
define("PHP_MAILER_SECURE", $db->getSetting($mysqli,"php_mailer_secure"));
91+
define("PHP_MAILER_USER", $db->getSetting($mysqli,"php_mailer_user"));
92+
define("PHP_MAILER_PASS", $db->getSetting($mysqli,"php_mailer_pass"));
93+
define("CRON_SERVER_IP", $db->getSetting($mysqli,"cron_server_ip"));
94+
*/
4195
}
4296
Template::render_header(_("Options"), true);
4397
?>
@@ -52,5 +106,78 @@
52106
</div>
53107
<input type="text" class="form-control" placeholder="" aria-label="Username" aria-describedby="basic-addon1" name="sitename" value="<?php echo NAME; ?>">
54108
</div>
109+
110+
<?php Template::render_toggle("Enable Email Subscription","email_subscription_toggle",$emailSubscription_status); ?>
111+
<?php Template::render_toggle("Enable Telegram Subscription","telegram_subscription_toggle",$telegramSubscription_status); ?>
112+
113+
<div class="input-group mb-3">
114+
<div class="input-group-prepend">
115+
<span class="input-group-text" id="basic-addon1">Telegram BOT API Token</span>
116+
</div>
117+
<input type="text" class="form-control" placeholder="" aria-label="telegram_bot_api_token" aria-describedby="basic-addon1" name="tg_bot_api_token" value="<?php echo $tg_bot_api_token; ?>">
118+
</div>
119+
<div class="input-group mb-3">
120+
<div class="input-group-prepend">
121+
<span class="input-group-text" id="basic-addon1">Telegram BOT Username</span>
122+
</div>
123+
<input type="text" class="form-control" placeholder="" aria-label="telegram_bot_username" aria-describedby="basic-addon1" name="tg_bot_username" value="<?php echo $tg_bot_username; ?>">
124+
</div>
125+
126+
<?php Template::render_toggle("Use PHPMailer for notifications","php_mailer_toggle",$php_mailer_status); ?>
127+
<?php Template::render_toggle("Use SMTP with PHPMailer","php_mailer_smtp_toggle",$php_mailer_smtp_status); ?>
128+
<?php Template::render_toggle("Use Secure SMTP with PHPMailer","php_mailer_secure_toggle",$php_mailer_secure_status); ?>
129+
<div class="input-group mb-3">
130+
<div class="input-group-prepend">
131+
<span class="input-group-text" id="basic-addon1">PHPMailer Path</span>
132+
</div>
133+
<input type="text" class="form-control" placeholder="" aria-label="phpmailer_path" aria-describedby="basic-addon1" name="php_mailer_path" value="<?php echo $php_mailer_path; ?>">
134+
</div>
135+
<div class="input-group mb-3">
136+
<div class="input-group-prepend">
137+
<span class="input-group-text" id="basic-addon1">PHPMailer SMTP Host</span>
138+
</div>
139+
<input type="text" class="form-control" placeholder="" aria-label="php_mailer_host" aria-describedby="basic-addon1" name="php_mailer_host" value="<?php echo $php_mailer_host; ?>">
140+
</div>
141+
<div class="input-group mb-3">
142+
<div class="input-group-prepend">
143+
<span class="input-group-text" id="basic-addon1">PHPMailer SMTP Port</span>
144+
</div>
145+
<input type="text" class="form-control" placeholder="" aria-label="php_mailer_port" aria-describedby="basic-addon1" name="php_mailer_port" value="<?php echo $php_mailer_port; ?>">
146+
</div>
147+
<div class="input-group mb-3">
148+
<div class="input-group-prepend">
149+
<span class="input-group-text" id="basic-addon1">PHPMailer Username</span>
150+
</div>
151+
<input type="text" class="form-control" placeholder="" aria-label="php_mailer_username" aria-describedby="basic-addon1" name="php_mailer_user" value="<?php echo $php_mailer_user; ?>">
152+
</div>
153+
<div class="input-group mb-3">
154+
<div class="input-group-prepend">
155+
<span class="input-group-text" id="basic-addon1">PHPMailer Password</span>
156+
</div>
157+
<input type="password" class="form-control" placeholder="" aria-label="php_mailer_password" aria-describedby="basic-addon1" name="php_mailer_pass" value="<?php echo $php_mailer_pass; ?>">
158+
</div>
159+
<div class="input-group mb-3">
160+
<div class="input-group-prepend">
161+
<span class="input-group-text" id="basic-addon1">Cron Server IP</span>
162+
</div>
163+
<input type="text" class="form-control" placeholder="" aria-label="cron_server_ip" aria-describedby="basic-addon1" name="cron_server_ip" value="<?php echo $cron_server_ip; ?>">
164+
</div>
165+
166+
<?php Template::render_toggle("Use Google reChaptcha for subscriber signup","google_rechaptcha_toggle",$google_rechaptcha_status); ?>
167+
<div class="input-group mb-3">
168+
<div class="input-group-prepend">
169+
<span class="input-group-text" id="basic-addon1">Google reChaptcha Sitekey</span>
170+
</div>
171+
<input type="text" class="form-control" placeholder="" aria-label="google_sitekey" aria-describedby="basic-addon1" name="google_recaptcha_sitekey" value="<?php echo $google_recaptcha_sitekey; ?>">
172+
</div>
173+
<div class="input-group mb-3">
174+
<div class="input-group-prepend">
175+
<span class="input-group-text" id="basic-addon1">Google reChaptcha Secret</span>
176+
</div>
177+
<input type="text" class="form-control" placeholder="" aria-label="google_secret" aria-describedby="basic-addon1" name="google_recaptcha_secret" value="<?php echo $google_recaptcha_secret; ?>">
178+
</div>
179+
180+
181+
55182
<button class="btn btn-primary pull-right" type="submit">Save Settings</button>
56183
</form>

classes/db-class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ function deleteSetting($conn,$settingname){
4040
}
4141

4242
}
43+
function updateSetting($conn, $settingname, $settingvalue){
44+
$this->deleteSetting($conn, $settingname);
45+
$this->setSetting($conn, $settingname, $settingvalue);
46+
return true;
47+
}
48+
49+
function getBooleanSetting($conn, $setting) {
50+
if (trim($this->getSetting($conn, $setting)) == "yes"){
51+
return true;
52+
}
53+
return false;
54+
}
4355
}

classes/queue.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function add_notification($arr_data) {
9898
$this->set_task_status($this->all_status['ready']); // Make task available for release
9999
}
100100

101-
public function update_notfication_retries($task_id, $subscriber_id) {
101+
public function update_notification_retries($task_id, $subscriber_id) {
102102
global $mysqli;
103103
$stmt = $mysqli->prepare("UPDATE queue_notify SET retries = retries+1 WHERE task_id = ? AND subscriber_id = ?");
104104
$stmt->bind_param("ii", $task_id, $subscriber_id);
@@ -126,12 +126,12 @@ public function process_queue(){
126126
$tmp = $stmt2->get_result();
127127
$result2 = $tmp->fetch_assoc();
128128
$typeID = $result2['type_id'];
129-
129+
130130
// Handle telegram
131131
if ($typeID == 1) {
132132
$msg = str_replace("#s", $result['firstname'], $result2['template_data2']);
133133
if ( ! Notification::submit_queue_telegram($result['userID'], $result['firstname'], $msg) ) {
134-
Queue::update_notfication_retries($result['task_id'], $result['subscriber_id']); // Sent
134+
Queue::update_notification_retries($result['task_id'], $result['subscriber_id']); // Sent
135135
} else {
136136
Queue::delete_notification($result['task_id'], $result['subscriber_id']); // Failed
137137
}

config.php.template

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,10 @@ define("POLICY_MAIL", "##policy_mail##"); //contact email in policy
3131
define("POLICY_PHONE", "##policy_phone##");
3232
define("WHO_WE_ARE","##who_we_are##");
3333
define("POLICY_URL","##policy_url##");
34-
define('SUBSCRIBE_EMAIL', true);
35-
define('SUBSCRIBE_TELEGRAM', false);
36-
define("TG_BOT_API_TOKEN", "##tg_bot_token##"); //Telegram Bot Token
37-
define("TG_BOT_USERNAME", "##tg_bot_username##"); //Telegram Bot username
3834
define("INSTALL_OVERRIDE", false);
3935
define("DEFAULT_LANGUAGE", "en_GB");
40-
define("GOOGLE_RECAPTCHA", false);
41-
define("GOOGLE_RECAPTCHA_SITEKEY", "##google_site_key##");
42-
define("GOOGLE_RECAPTCHA_SECRET", "##google_secret##");
43-
define("PHP_MAILER", false); // Enable if we are to use extenral PHPMailer() library
44-
define("PHP_MAILER_PATH", "##phpmailer_path##"); // Path to src folder of PHPMailer() library - without ending /
45-
define("PHP_MAILER_SMTP", false); // Set to true if we are to use SMTP
46-
define("PHP_MAILER_HOST", "##phpmailer_host##"); // SMTP host
47-
define("PHP_MAILER_PORT", "##phpmailer_port##"); // SMTP Port
48-
define("PHP_MAILER_SECURE", ""); // Set to TLS or SSL or leave blank for plaintext
49-
define("PHP_MAILER_USER", "##phpmailer_user##"); // SMTP Authentication user
50-
define("PHP_MAILER_PASS", "##phpmailer_pass##"); // SMTP authenticatin password
5136
define("CUSTOM_LOGO_URL",""); // This will use the default logo if left empty
5237
define("COPYRIGHT_TEXT",""); // Leave this empty if you don't want your copyright displayed
53-
define("CRON_SERVER_IP",""); // IP Address that will be used to call cron task. Leave empty if not used!
5438
// Without COPYRIGHT_TEXT Set
5539
// 2020 Server Status Project Contributors
5640
// With COPYRIGHT_TEXT Set

0 commit comments

Comments
 (0)