Skip to content

Commit 5618b57

Browse files
author
Yiğit Kerem Oktay
authored
Merge pull request #123 from yigitkeremoktay/master
Version 2 - Migrate Settings to DB -- Add Telegram and Email Subscription Support
2 parents 95f4fc5 + 5d99ed7 commit 5618b57

33 files changed

+5081
-72
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
# Server status page
2-
![License](https://img.shields.io/github/license/Pryx/server-status.svg) ![Current release](https://img.shields.io/github/release/Pryx/server-status.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b82d62fa6d8b41119f68fd9eca3c3a08)](https://www.codacy.com/app/sajdl.vojtech/server-status?utm_source=github.com&utm_medium=referral&utm_content=Pryx/server-status&utm_campaign=Badge_Grade) [![Discord](https://img.shields.io/discord/742703112590065745?logo=discord)](https://discord.gg/Wgxnxz4)
3-
4-
![screenshot](https://status.trucksbook.eu/img/screenshot.png)
5-
1+
# Server Status Beta (Official)
2+
## This is the official beta fork of Server Status by the contributors.
3+
![License](https://img.shields.io/github/license/Pryx/server-status.svg) ![Current release](https://img.shields.io/badge/version-2-blue)
4+
![Beta-Build](https://img.shields.io/badge/latest_beta-Developmet_Beta_6-black)
5+
![Beta-Stability](https://img.shields.io/badge/Beta_Stability-Unusable-red)
6+
![Stability](https://img.shields.io/badge/master_stability-Unstable-red)
7+
![Build](https://img.shields.io/badge/build-success-green)
8+
9+
## What does **contributor beta** mean?
10+
It means the beta that is heavily unstable that is meant for contributors to make changes and use as a recovery point.
11+
### Other Beta Type
12+
#### Development Beta
13+
##### This beta has some bugs that are noticeable and is sometimes unstable. Best for new contributors
14+
#### Public Beta
15+
##### This beta has some bugs that are not really noticeable and mostly exist as bugs. Best for trying the new features before updating!
616
Very simple server status page written in PHP that can run on **PHP 5.4+** - even on **shared webhosting** even without shell access. Because why waste your money on another server (or host on a server that you might want to do maintenance on), when you can use cheap webhosting? And as a cherry on top - it works even without javascript!
717

818
## How do I install this thing?

admin/dashboard.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
$offset = 0;
33
if (isset($_GET['ajax']))
44
{
@@ -18,8 +18,11 @@
1818
{
1919
Incident::delete($_GET['delete']);
2020
}
21+
if (isset($_GET['tasks'])) {
22+
Queue::process_queue();
23+
}
2124

22-
Template::render_header(_("Dashboard"), true);
25+
Template::render_header(_("Dashboard"), true);
2326
?>
2427

2528
<div class="text-center">
@@ -45,7 +48,7 @@
4548
<?php
4649
} ?>
4750
<div id="status-container" class="clearfix">
48-
<?php
51+
<?php
4952
if (isset($_POST['services']) && !is_array($_POST['services']))
5053
{
5154
$post_services = array($_POST['services']);
@@ -82,7 +85,7 @@
8285
</div>
8386
</div>
8487
<select class="form-control pull-left" id="type" name="type">
85-
<?php
88+
<?php
8689
if (isset($_POST['type']))
8790
{
8891
$selected_status = $_POST['type'];

admin/index.php

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,58 @@
77
else{
88
require_once("../config.php");
99
require_once("../classes/constellation.php");
10+
require_once("../classes/mailer.php");
11+
require_once("../classes/notification.php");
1012
require_once("../template.php");
13+
require_once("../libs/parsedown/Parsedown.php");
14+
require_once("../classes/queue.php");
15+
require_once("../classes/db-class.php");
16+
$db = new SSDB();
17+
define("NAME", $db->getSetting($mysqli,"name"));
18+
define("TITLE", $db->getSetting($mysqli,"title"));
19+
define("WEB_URL", $db->getSetting($mysqli,"url"));
20+
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
21+
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+
40+
// Process the subscriber notification queue
41+
// If CRON_SERVER_IP is not set, call notification once incident has been saved
42+
if ( empty(CRON_SERVER_IP) )
43+
{
44+
if ( isset($_GET['sent']) && $_GET['sent'] == true )
45+
{
46+
Queue::process_queue();
47+
}
48+
}
49+
else if ( isset($_GET['task']) && $_GET['task'] == 'cron' )
50+
{
51+
// Else, base it on call to /admin?task=cron being called from IP defined by CRON_SERVER_IP
52+
if (! empty(CRON_SERVER_IP) && $_SERVER['REMOTE_ADDR'] == CRON_SERVER_IP )
53+
{
54+
Queue::process_queue();
55+
syslog(1, "CRON server processed");
56+
}
57+
else {
58+
syslog(1, "CRON called from unauthorised server");
59+
}
60+
}
61+
1162

1263
if(isset($_COOKIE['user'])&&!isset($_SESSION['user']))
1364
{
@@ -29,7 +80,7 @@
2980
require_once("login-form.php");
3081
}
3182
}
32-
else
83+
else
3384
{
3485
$user = new User($_SESSION['user']);
3586
if (!$user->is_active())
@@ -50,7 +101,7 @@
50101
case 'user':
51102
require_once("user.php");
52103
break;
53-
104+
54105
case 'settings':
55106
require_once("settings.php");
56107
break;
@@ -59,6 +110,10 @@
59110
require_once("new-user.php");
60111
break;
61112

113+
case 'options':
114+
require_once("options.php");
115+
break;
116+
62117
case 'logout':
63118
User::logout();
64119
break;
@@ -70,4 +125,4 @@
70125

71126
Template::render_footer(true);
72127
}
73-
}
128+
}

admin/options.php

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
function getToggle($variable){
3+
$res = ((isset($variable) && ($variable == "on")) ? "yes" : "no");
4+
return $res;
5+
}
6+
7+
8+
if (!file_exists("../config.php"))
9+
{
10+
header("Location: ../");
11+
}
12+
else{
13+
require_once("../config.php");
14+
require_once("../classes/constellation.php");
15+
require_once("../classes/mailer.php");
16+
require_once("../classes/notification.php");
17+
require_once("../template.php");
18+
require_once("../libs/parsedown/Parsedown.php");
19+
require_once("../classes/queue.php");
20+
require_once("../classes/db-class.php");
21+
}
22+
$db = new SSDB();
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, "");
42+
$set_post = false;
43+
if(!empty($_POST)){
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+
63+
$set_post = true;
64+
/*if($nu_toggle == "yes"){
65+
$notifyUpdates_status = true;
66+
} else {
67+
$notifyUpdates_status = false;
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"));
74+
define("TITLE", $db->getSetting($mysqli,"title"));
75+
define("WEB_URL", $db->getSetting($mysqli,"url"));
76+
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
77+
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+
*/
95+
}
96+
Template::render_header(_("Options"), true);
97+
?>
98+
<div class="text-center">
99+
<h2><?php if($set_post){ echo "Settings Saved"; } else { echo "Server Status Options"; } ?></h2>
100+
</div>
101+
<form method="post">
102+
<?php Template::render_toggle("Notify Updates","nu_toggle",$notifyUpdates_status); ?>
103+
<div class="input-group mb-3">
104+
<div class="input-group-prepend">
105+
<span class="input-group-text" id="basic-addon1">Site Name</span>
106+
</div>
107+
<input type="text" class="form-control" placeholder="" aria-label="Username" aria-describedby="basic-addon1" name="sitename" value="<?php echo NAME; ?>">
108+
</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+
182+
<button class="btn btn-primary pull-right" type="submit">Save Settings</button>
183+
</form>

classes/constellation.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,40 @@ function get_incidents($future = false, $offset = 0, $limit = 5, $timestamp = 0)
156156
"incidents" => $array
157157
];
158158
}
159-
}
159+
160+
161+
function render_warning($header, $message, $show_link = false, $url = null, $link_text = null)
162+
{
163+
$this->render_alert('alert-warning', $header, $message, $show_link, $url, $link_text);
164+
}
165+
function render_success($header, $message, $show_link = false, $url = null, $link_text = null)
166+
{
167+
$this->render_alert('alert-success', $header, $message, $show_link, $url, $link_text);
168+
}
169+
170+
/**
171+
* Renders an alert on screen with an optional button to return to a given URL
172+
* @param string alert_type - Type of warning to render alert-danger, alert-warning, alert-success etc
173+
* @param string header - Title of warning
174+
* @param string message - Message to display
175+
* @param boolean show_link - True if button is to be displayed
176+
* @param string url - URL for button
177+
* @param string link_txt - Text for button
178+
* @return void
179+
*/
180+
function render_alert($alert_type, $header, $message, $show_link = false, $url = null, $link_text = null)
181+
{
182+
echo '<div><h1></h1>
183+
<div class="alert '.$alert_type.'" role="alert">
184+
<h4 class="alert-heading">'.$header.'</h4>
185+
<hr>
186+
<p class="mb-0">'.$message.'</p>
187+
</div></div>';
188+
if ( $show_link ) {
189+
echo '<div class="clearfix"><a href="'.$url.'" class="btn btn-success" role="button">'.$link_text.'</a></div>';
190+
}
191+
192+
}
193+
}
160194

161195
$constellation = new Constellation();

0 commit comments

Comments
 (0)