Skip to content

Commit

Permalink
Merge pull request #123 from yigitkeremoktay/master
Browse files Browse the repository at this point in the history
Version 2  - Migrate Settings to DB -- Add Telegram and Email Subscription Support
  • Loading branch information
Yiğit Kerem Oktay authored Aug 24, 2020
2 parents 95f4fc5 + 5d99ed7 commit 5618b57
Show file tree
Hide file tree
Showing 33 changed files with 5,081 additions and 72 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Server status page
![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)

![screenshot](https://status.trucksbook.eu/img/screenshot.png)

# Server Status Beta (Official)
## This is the official beta fork of Server Status by the contributors.
![License](https://img.shields.io/github/license/Pryx/server-status.svg) ![Current release](https://img.shields.io/badge/version-2-blue)
![Beta-Build](https://img.shields.io/badge/latest_beta-Developmet_Beta_6-black)
![Beta-Stability](https://img.shields.io/badge/Beta_Stability-Unusable-red)
![Stability](https://img.shields.io/badge/master_stability-Unstable-red)
![Build](https://img.shields.io/badge/build-success-green)

## What does **contributor beta** mean?
It means the beta that is heavily unstable that is meant for contributors to make changes and use as a recovery point.
### Other Beta Type
#### Development Beta
##### This beta has some bugs that are noticeable and is sometimes unstable. Best for new contributors
#### Public Beta
##### This beta has some bugs that are not really noticeable and mostly exist as bugs. Best for trying the new features before updating!
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!

## How do I install this thing?
Expand Down
11 changes: 7 additions & 4 deletions admin/dashboard.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
$offset = 0;
if (isset($_GET['ajax']))
{
Expand All @@ -18,8 +18,11 @@
{
Incident::delete($_GET['delete']);
}
if (isset($_GET['tasks'])) {
Queue::process_queue();
}

Template::render_header(_("Dashboard"), true);
Template::render_header(_("Dashboard"), true);
?>

<div class="text-center">
Expand All @@ -45,7 +48,7 @@
<?php
} ?>
<div id="status-container" class="clearfix">
<?php
<?php
if (isset($_POST['services']) && !is_array($_POST['services']))
{
$post_services = array($_POST['services']);
Expand Down Expand Up @@ -82,7 +85,7 @@
</div>
</div>
<select class="form-control pull-left" id="type" name="type">
<?php
<?php
if (isset($_POST['type']))
{
$selected_status = $_POST['type'];
Expand Down
61 changes: 58 additions & 3 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,58 @@
else{
require_once("../config.php");
require_once("../classes/constellation.php");
require_once("../classes/mailer.php");
require_once("../classes/notification.php");
require_once("../template.php");
require_once("../libs/parsedown/Parsedown.php");
require_once("../classes/queue.php");
require_once("../classes/db-class.php");
$db = new SSDB();
define("NAME", $db->getSetting($mysqli,"name"));
define("TITLE", $db->getSetting($mysqli,"title"));
define("WEB_URL", $db->getSetting($mysqli,"url"));
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));

define("GOOGLE_RECAPTCHA", $db->getBooleanSetting($mysqli, "google_recaptcha"));
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli, "google_recaptcha_secret"));
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli, "google_recaptcha_sitekey"));
define("SUBSCRIBE_EMAIL", $db->getBooleanSetting($mysqli, "subscribe_email"));
define("SUBSCRIBE_TELEGRAM", $db->getBooleanSetting($mysqli, "subscribe_telegram"));
define("TG_BOT_USERNAME", $db->getSetting($mysqli, "tg_bot_username"));
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli, "tg_bot_api_token"));
define("PHP_MAILER", $db->getBooleanSetting($mysqli, "php_mailer"));
define("PHP_MAILER_SMTP", $db->getBooleanSetting($mysqli, "php_mailer_smtp"));
define("PHP_MAILER_PATH", $db->getSetting($mysqli, "php_mailer_path"));
define("PHP_MAILER_HOST", $db->getSetting($mysqli, "php_mailer_host"));
define("PHP_MAILER_PORT", $db->getSetting($mysqli, "php_mailer_port"));
define("PHP_MAILER_SECURE", $db->getBooleanSetting($mysqli, "php_mailer_secure"));
define("PHP_MAILER_USER", $db->getSetting($mysqli, "php_mailer_user"));
define("PHP_MAILER_PASS", $db->getSetting($mysqli, "php_mailer_pass"));
define("CRON_SERVER_IP", $db->getSetting($mysqli, "cron_server_ip"));

// Process the subscriber notification queue
// If CRON_SERVER_IP is not set, call notification once incident has been saved
if ( empty(CRON_SERVER_IP) )
{
if ( isset($_GET['sent']) && $_GET['sent'] == true )
{
Queue::process_queue();
}
}
else if ( isset($_GET['task']) && $_GET['task'] == 'cron' )
{
// Else, base it on call to /admin?task=cron being called from IP defined by CRON_SERVER_IP
if (! empty(CRON_SERVER_IP) && $_SERVER['REMOTE_ADDR'] == CRON_SERVER_IP )
{
Queue::process_queue();
syslog(1, "CRON server processed");
}
else {
syslog(1, "CRON called from unauthorised server");
}
}


if(isset($_COOKIE['user'])&&!isset($_SESSION['user']))
{
Expand All @@ -29,7 +80,7 @@
require_once("login-form.php");
}
}
else
else
{
$user = new User($_SESSION['user']);
if (!$user->is_active())
Expand All @@ -50,7 +101,7 @@
case 'user':
require_once("user.php");
break;

case 'settings':
require_once("settings.php");
break;
Expand All @@ -59,6 +110,10 @@
require_once("new-user.php");
break;

case 'options':
require_once("options.php");
break;

case 'logout':
User::logout();
break;
Expand All @@ -70,4 +125,4 @@

Template::render_footer(true);
}
}
}
183 changes: 183 additions & 0 deletions admin/options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
function getToggle($variable){
$res = ((isset($variable) && ($variable == "on")) ? "yes" : "no");
return $res;
}


if (!file_exists("../config.php"))
{
header("Location: ../");
}
else{
require_once("../config.php");
require_once("../classes/constellation.php");
require_once("../classes/mailer.php");
require_once("../classes/notification.php");
require_once("../template.php");
require_once("../libs/parsedown/Parsedown.php");
require_once("../classes/queue.php");
require_once("../classes/db-class.php");
}
$db = new SSDB();
$notifyUpdates_status = $db->getBooleanSetting($mysqli, "notifyUpdates");
$emailSubscription_status = $db->getBooleanSetting($mysqli, "subscribe_email");
$telegramSubscription_status = $db->getBooleanSetting($mysqli, "subscribe_telegram");
$tg_bot_api_token = $db->getSetting($mysqli, "tg_bot_api_token");
$tg_bot_username = $db->getSetting($mysqli, "tg_bot_username");
$php_mailer_status = $db->getBooleanSetting($mysqli, "php_mailer");
$php_mailer_smtp_status = $db->getBooleanSetting($mysqli, "php_mailer_smtp");
$php_mailer_secure_status = $db->getBooleanSetting($mysqli, "php_mailer_secure");
$php_mailer_path = $db->getSetting($mysqli, "php_mailer_path");
$php_mailer_host = $db->getSetting($mysqli, "php_mailer_host");
$php_mailer_port = $db->getSetting($mysqli, "php_mailer_port");
$php_mailer_user = $db->getSetting($mysqli, "php_mailer_user");
$php_mailer_pass = $db->getSetting($mysqli, "php_mailer_pass");
$cron_server_ip = $db->getSetting($mysqli, "cron_server_ip");
$google_rechaptcha_status = $db->getBooleanSetting($mysqli, "google_recaptcha");
$google_recaptcha_sitekey = $db->getSetting($mysqli, "google_recaptcha_sitekey");
$google_recaptcha_secret = $db->getSetting($mysqli, "google_recaptcha_secret");

$db->getSetting($mysqli, "");
$set_post = false;
if(!empty($_POST)){
$db->updateSetting($mysqli, "notifyUpdates", getToggle($_POST["nu_toggle"]));
$db->updateSetting($mysqli, "name",htmlspecialchars($_POST["sitename"], ENT_QUOTES));
$db->updateSetting($mysqli, "subscribe_email", getToggle($_POST["email_subscription_toggle"]));
$db->updateSetting($mysqli, "subscribe_telegram", getToggle($_POST["telegram_subscription_toggle"]));
$db->updateSetting($mysqli, "tg_bot_api_token", htmlspecialchars($_POST["tg_bot_api_token"], ENT_QUOTES));
$db->updateSetting($mysqli, "tg_bot_username", htmlspecialchars($_POST["tg_bot_username"], ENT_QUOTES));
$db->updateSetting($mysqli, "php_mailer", getToggle($_POST["php_mailer_toggle"]));
$db->updateSetting($mysqli, "php_mailer_smtp", getToggle($_POST["php_mailer_smtp_toggle"]));
$db->updateSetting($mysqli, "php_mailer_secure", getToggle($_POST["php_mailer_secure_toggle"]));
$db->updateSetting($mysqli, "php_mailer_path", htmlspecialchars($_POST["php_mailer_path"], ENT_QUOTES));
$db->updateSetting($mysqli, "php_mailer_host", htmlspecialchars($_POST["php_mailer_host"], ENT_QUOTES));
$db->updateSetting($mysqli, "php_mailer_port", htmlspecialchars($_POST["php_mailer_port"], ENT_QUOTES));
$db->updateSetting($mysqli, "php_mailer_user", htmlspecialchars($_POST["php_mailer_user"], ENT_QUOTES));
$db->updateSetting($mysqli, "php_mailer_pass", htmlspecialchars($_POST["php_mailer_pass"], ENT_QUOTES));
$db->updateSetting($mysqli, "cron_server_ip", htmlspecialchars($_POST["cron_server_ip"], ENT_QUOTES));
$db->updateSetting($mysqli, "google_recaptcha", getToggle($_POST["google_rechaptcha_toggle"]));
$db->updateSetting($mysqli, "google_recaptcha_sitekey", htmlspecialchars($_POST["google_recaptcha_sitekey"], ENT_QUOTES));
$db->updateSetting($mysqli, "google_recaptcha_secret", htmlspecialchars($_POST["google_recaptcha_secret"], ENT_QUOTES));

$set_post = true;
/*if($nu_toggle == "yes"){
$notifyUpdates_status = true;
} else {
$notifyUpdates_status = false;
}*/
// TODO - Reload page to prevent showing old values! or update variables being displayed
header("Location: " .$uri = $_SERVER['REQUEST_URI']);
// TODO - The code below will not happen ...

/*define("NAME", $db->getSetting($mysqli,"name"));
define("TITLE", $db->getSetting($mysqli,"title"));
define("WEB_URL", $db->getSetting($mysqli,"url"));
define("MAILER_NAME", $db->getSetting($mysqli,"mailer"));
define("MAILER_ADDRESS", $db->getSetting($mysqli,"mailer_email"));
define("SUBSCRIBER_EMAIL", $db->getSetting($mysqli,"subscriber_email"));
define("SUBSCRIBER_TELEGRAM", $db->getSetting($mysqli,"subscriber_telegram"));
define("TG_BOT_API_TOKEN", $db->getSetting($mysqli,"tg_bot_api_token"));
define("TG_BOT_USERNAME", $db->getSetting($mysqli,"tg_bot_username"));
define("GOOGLE_RECAPTCHA", $db->getSetting($mysqli,"google_recaptcha"));
define("GOOGLE_RECAPTCHA_SITEKEY", $db->getSetting($mysqli,"google_recaptcha_sitekey"));
define("GOOGLE_RECAPTCHA_SECRET", $db->getSetting($mysqli,"google_recaptcha_secret"));
define("PHP_MAILER", $db->getSetting($mysqli,"php_mailer"));
define("PHP_MAILER_PATH", $db->getSetting($mysqli,"php_mailer_path"));
define("PHP_MAILER_SMTP", $db->getSetting($mysqli,"php_mailer_smtp"));
define("PHP_MAILER_HOST", $db->getSetting($mysqli,"php_mailer_host"));
define("PHP_MAILER_PORT", $db->getSetting($mysqli,"php_mailer_port"));
define("PHP_MAILER_SECURE", $db->getSetting($mysqli,"php_mailer_secure"));
define("PHP_MAILER_USER", $db->getSetting($mysqli,"php_mailer_user"));
define("PHP_MAILER_PASS", $db->getSetting($mysqli,"php_mailer_pass"));
define("CRON_SERVER_IP", $db->getSetting($mysqli,"cron_server_ip"));
*/
}
Template::render_header(_("Options"), true);
?>
<div class="text-center">
<h2><?php if($set_post){ echo "Settings Saved"; } else { echo "Server Status Options"; } ?></h2>
</div>
<form method="post">
<?php Template::render_toggle("Notify Updates","nu_toggle",$notifyUpdates_status); ?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Site Name</span>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Username" aria-describedby="basic-addon1" name="sitename" value="<?php echo NAME; ?>">
</div>

<?php Template::render_toggle("Enable Email Subscription","email_subscription_toggle",$emailSubscription_status); ?>
<?php Template::render_toggle("Enable Telegram Subscription","telegram_subscription_toggle",$telegramSubscription_status); ?>

<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Telegram BOT API Token</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Telegram BOT Username</span>
</div>
<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; ?>">
</div>

<?php Template::render_toggle("Use PHPMailer for notifications","php_mailer_toggle",$php_mailer_status); ?>
<?php Template::render_toggle("Use SMTP with PHPMailer","php_mailer_smtp_toggle",$php_mailer_smtp_status); ?>
<?php Template::render_toggle("Use Secure SMTP with PHPMailer","php_mailer_secure_toggle",$php_mailer_secure_status); ?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">PHPMailer Path</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">PHPMailer SMTP Host</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">PHPMailer SMTP Port</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">PHPMailer Username</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">PHPMailer Password</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Cron Server IP</span>
</div>
<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; ?>">
</div>

<?php Template::render_toggle("Use Google reChaptcha for subscriber signup","google_rechaptcha_toggle",$google_rechaptcha_status); ?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Google reChaptcha Sitekey</span>
</div>
<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; ?>">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Google reChaptcha Secret</span>
</div>
<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; ?>">
</div>



<button class="btn btn-primary pull-right" type="submit">Save Settings</button>
</form>
36 changes: 35 additions & 1 deletion classes/constellation.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,40 @@ function get_incidents($future = false, $offset = 0, $limit = 5, $timestamp = 0)
"incidents" => $array
];
}
}


function render_warning($header, $message, $show_link = false, $url = null, $link_text = null)
{
$this->render_alert('alert-warning', $header, $message, $show_link, $url, $link_text);
}
function render_success($header, $message, $show_link = false, $url = null, $link_text = null)
{
$this->render_alert('alert-success', $header, $message, $show_link, $url, $link_text);
}

/**
* Renders an alert on screen with an optional button to return to a given URL
* @param string alert_type - Type of warning to render alert-danger, alert-warning, alert-success etc
* @param string header - Title of warning
* @param string message - Message to display
* @param boolean show_link - True if button is to be displayed
* @param string url - URL for button
* @param string link_txt - Text for button
* @return void
*/
function render_alert($alert_type, $header, $message, $show_link = false, $url = null, $link_text = null)
{
echo '<div><h1></h1>
<div class="alert '.$alert_type.'" role="alert">
<h4 class="alert-heading">'.$header.'</h4>
<hr>
<p class="mb-0">'.$message.'</p>
</div></div>';
if ( $show_link ) {
echo '<div class="clearfix"><a href="'.$url.'" class="btn btn-success" role="button">'.$link_text.'</a></div>';
}

}
}

$constellation = new Constellation();
Loading

0 comments on commit 5618b57

Please sign in to comment.