Skip to content

Instantly share code, notes, and snippets.

@mattrude
Last active September 16, 2017 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrude/51f5aa7866169b1c2fbd4865ed5a2f94 to your computer and use it in GitHub Desktop.
Save mattrude/51f5aa7866169b1c2fbd4865ed5a2f94 to your computer and use it in GitHub Desktop.
The current patch to update the look and feel of the https://github.com/iNPUTmice/ServerStatus server to be https://status.im.mattrude.com/

ServerStatus Custom

Installing The Custom Patch

Start by downloading the ServerStatus package

mkdir -p /var/src/ && cd /var/src/
git clone https://github.com/iNPUTmice/ServerStatus.git

Download and Patch the orignal software

cd /var/src/ServerStatus/
curl -L https://gist.githubusercontent.com/mattrude/51f5aa7866169b1c2fbd4865ed5a2f94/raw/ServerStatus-Custom.patch -o ServerStatus-Custom.patch
patch -p1 < ServerStatus-Custom.patch

Then Build and run ServerStatus as you would normily

mvn package
java -jar target/ServerStatus.jar

License

Copyright (c) 2017, Daniel Gultsch All rights reserved.
Copyright (c) 2017, Matt Rude All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/main/java/im/conversations/status/Main.java b/src/main/java/im/conversations/status/Main.java
index 9e5d4b9..11295f4 100644
--- a/src/main/java/im/conversations/status/Main.java
+++ b/src/main/java/im/conversations/status/Main.java
@@ -52,12 +52,13 @@ public class Main {
});
get("/", Controller.getStatus, templateEngine);
+ get("/about/", Controller.getAbout, templateEngine);
get("/historical/", Controller.getHistorical, templateEngine);
get("/reverse/:domain/", Controller.getReverse, templateEngine);
get("/:domain/", Controller.getStatus, templateEngine);
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(5);
for (Credentials credentials : Configuration.getInstance().getCredentials()) {
- scheduledThreadPoolExecutor.scheduleAtFixedRate(new ServerStatusChecker(credentials, Configuration.getInstance().getPingTargets()), 0, 2, TimeUnit.MINUTES);
+ scheduledThreadPoolExecutor.scheduleAtFixedRate(new ServerStatusChecker(credentials, Configuration.getInstance().getPingTargets()), 0, 5, TimeUnit.MINUTES);
}
scheduledThreadPoolExecutor.scheduleAtFixedRate(new ServerStatusStore.HistoricalDataUpdater(),0,10,TimeUnit.MINUTES);
}
diff --git a/src/main/java/im/conversations/status/pojo/HistoricalLoginStatuus.java b/src/main/java/im/conversations/status/pojo/HistoricalLoginStatuus.java
index 995c6ad..8155296 100644
--- a/src/main/java/im/conversations/status/pojo/HistoricalLoginStatuus.java
+++ b/src/main/java/im/conversations/status/pojo/HistoricalLoginStatuus.java
@@ -8,7 +8,7 @@ import java.util.Map;
public class HistoricalLoginStatuus {
- public static List<Integer> DURATIONS = Arrays.asList(1,7,30,365);
+ public static List<Integer> DURATIONS = Arrays.asList(1,7,30,90,180,365);
public static ChronoUnit UNIT = ChronoUnit.DAYS;
private final Map<Duration,Double> durationLoginStatusMap;
diff --git a/src/main/java/im/conversations/status/web/Controller.java b/src/main/java/im/conversations/status/web/Controller.java
index 056bc9c..8c6f223 100644
--- a/src/main/java/im/conversations/status/web/Controller.java
+++ b/src/main/java/im/conversations/status/web/Controller.java
@@ -51,4 +51,10 @@ public class Controller {
model.put("domain",domain);
return new ModelAndView(model, "reverse.ftl");
};
+
+ public static TemplateViewRoute getAbout = (request, response) -> {
+ HashMap<String, Object> model = new HashMap<>();
+ model.put("availableDomains", Configuration.getInstance().getDomains());
+ return new ModelAndView(model, "about.ftl");
+ };
}
diff --git a/src/main/resources/spark/template/freemarker/historical.ftl b/src/main/resources/spark/template/freemarker/historical.ftl
index 5494e5b..e9c6412 100644
--- a/src/main/resources/spark/template/freemarker/historical.ftl
+++ b/src/main/resources/spark/template/freemarker/historical.ftl
@@ -1,9 +1,9 @@
<#ftl output_format="HTML">
<#import "page.ftl" as page/>
-<@page.page title="Historical uptime data" historical=true>
-<h1>Historical uptime data</h1>
+<@page.page title="Historical Uptime Statistics" historical=true>
+<h2>Historical Uptime Statistics</h2>
<#if serverMap?size == 0>
- <p class="info">Calculating historical data</p>
+ <p class="info">Calculating Historical Data</p>
<#else>
<table class="rightbound">
<thead>
@@ -29,4 +29,4 @@
</#list>
</table>
</#if>
-</@page.page>
\ No newline at end of file
+</@page.page>
diff --git a/src/main/resources/spark/template/freemarker/page.ftl b/src/main/resources/spark/template/freemarker/page.ftl
index 7e04c2e..d981e75 100644
--- a/src/main/resources/spark/template/freemarker/page.ftl
+++ b/src/main/resources/spark/template/freemarker/page.ftl
@@ -1,9 +1,13 @@
-<#macro page title="" historical=false>
+<#macro page title="" historical=false reverse=false about=false>
<!DOCTYPE html>
<html>
<head>
- <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
+ <!-- <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'> -->
+ <link rel="shortcut icon" href="/favicon.ico"/>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset="UTF-8">
+ <meta http-equiv="refresh" content="300" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${title}</title>
<style type="text/css">
@@ -11,19 +15,47 @@
color: rgba(0, 0, 0, 0.87);
font-family: 'Roboto', sans-serif;
font-weight: 400;
- font-size: 13pt;
- background-color: #fafafa;
+ background-color: #f1f1f1;
+ }
+
+ #main {
+ padding: 40px 15px;
+ }
+
+ .container {
+ max-width: 768px;
+ background-color: #fff;
+ }
+
+ @media only screen and (max-width: 650px) {
+ #table {
+ font-size: 12pt;
+ overflow-x: scroll
+ }
+ }
+
+ @media only screen and (min-width: 650px) {
+ #table {
+ font-size: 16pt;
+ }
+ #table p {
+ font-size: 14px;
+ padding: 0 0 25px;
+ margin: 0px;
+ }
}
h1 {
- color: rgba(0, 0, 0, 0.87);
- font-family: 'Roboto', sans-serif;
font-weight: 600;
- font-size: 20pt;
+ }
+
+ #page {
+ padding-bottom: 40px;
}
table {
border-collapse: collapse;
+ width: 100%;
}
table.rightbound tr td:not(:first-child) {
@@ -38,6 +70,11 @@
td {
padding-right: 6px;
padding-left: 6px;
+ width: 100%;
+ }
+
+ table thead tr th {
+ text-align: center;
}
table tr:hover td {
@@ -46,10 +83,12 @@
table tbody tr td.successful {
color: #43a047;
+ text-align: right;
}
table tbody tr td.unsuccessful {
color: #e53935;
+ text-align: right;
}
table tbody tr td.info {
@@ -60,6 +99,26 @@
color: rgba(0, 0, 0, 0.54);
}
+ .btn {
+ padding: 0 1px;
+ color: #000;
+ font-size: 9px;
+ }
+
+ .btn-secondary {
+ background-color: yellow;
+ border-color: yellow;
+ }
+
+ .alert-warning span {
+ float: left;
+ }
+
+ .alert-warning p {
+ padding-left: 25px;
+ font-size: 14px;
+ }
+
a {
color: #3f51b5;
}
@@ -70,12 +129,67 @@
p.info {
color: rgba(0, 0, 0, 0.54);
+ padding: 10px 0;
+ }
+
+ /* Sticky footer styles
+ -------------------------------------------------- */
+ html {
+ position: relative;
+ min-height: 100%;
+ }
+ body {
+ /* Margin bottom by footer height */
+ // margin-bottom: 60px;
+ }
+ .footer {
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+ /* Set the fixed height of the footer here */
+ height: 60px;
+ padding-top: 20px;
+ background-color: #f1f1f1;
}
</style>
</head>
<body>
- <#nested />
-<p class="small">Copyright 2017 <a href="https://gultsch.de">Daniel Gultsch</a> <#if !historical>&middot; <a href="/historical/">Historical data</a> </#if>&middot; <a href="https://github.com/iNPUTmice/ServerStatus">Source code</a></p>
+<div id="main" class="container offsetanchor">
+ <div class="section-headder" style="padding-top:0;"><center>
+ <h1 class="page-header text-center" style="border-bottom: 0px;margin:0 0 20px; 0;">XMPP Service Status Site</h1>
+ </div>
+
+ <#if reverse>
+ <div class="alert alert-warning" role="alert">
+ <span class="fa fa-info-circle" style="font-size:26px;"></span>
+ <p>This page shows if the servers listed below are able to receive connections from the domain <b>${domain}</b>.</p>
+ </div>
+ </#if>
+
+ <#if !about>
+ <div id=table>
+ </#if>
+ <#if about>
+ <div id=page>
+ </#if>
+ <#nested />
+ </div>
+</div>
+
+<!-- Page Footer -->
+<footer class="footer">
+ <div class="container" style="background-color:#f1f1f1;">
+ <div class="pull-left">
+ <p><a href="/">Home</a><#if !about> | <a href="/about/">About</a></#if><#if !historical> | <a href="/historical/">Historical</a></#if></p>
+ </div>
+ <div class="pull-right">
+ <p>&copy; 2017 by <a href="https://gultsch.de/">Daniel Gultsch</a></p>
+ </div>
+ </div>
+</footer>
+
</body>
+<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
+<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</html>
-</#macro>
\ No newline at end of file
+</#macro>
diff --git a/src/main/resources/spark/template/freemarker/reverse.ftl b/src/main/resources/spark/template/freemarker/reverse.ftl
index a1be29b..fbda563 100644
--- a/src/main/resources/spark/template/freemarker/reverse.ftl
+++ b/src/main/resources/spark/template/freemarker/reverse.ftl
@@ -1,8 +1,8 @@
<#ftl output_format="HTML">
<#import "page.ftl" as page/>
<#assign title="Reverse reachability for ${domain}">
-<@page.page title=$title historical=false>
-<h1>${title}</h1>
+<@page.page title=$title historical=false reverse=true>
+<h2>${title}</h2>
<table class="rightbound">
<#list pingResults as result>
<tr>
@@ -11,4 +11,4 @@
</tr>
</#list>
</table>
-</@page.page>
\ No newline at end of file
+</@page.page>
diff --git a/src/main/resources/spark/template/freemarker/status.ftl b/src/main/resources/spark/template/freemarker/status.ftl
index c348b6d..3b9189a 100644
--- a/src/main/resources/spark/template/freemarker/status.ftl
+++ b/src/main/resources/spark/template/freemarker/status.ftl
@@ -7,28 +7,44 @@
<#assign lastUpdated = serverStatus.getDate()>
<#assign linkReverse = 1 < availableDomains?size>
<#if isLoggedIn>
- <h1>${domain} is up and running</h1>
+
+ <h2>${domain} is up and running</h2>
+ <p>This server is here to anwser a simple question, can the users on server ${domain} connect to users on a questioned server. The below table tries to give you a snapshot of this servers current connection status with other servers.</p>
+
+ <h3>Primay Domains</h3>
<table>
<#list pingResults as result>
- <tr>
- <td>
- <#if availableDomains?seq_contains(result.getServer())>
- <a href="/<#if availableDomains?seq_index_of(result.getServer()) != 0>${result.getServer()}/</#if>">${result.getServer()}</a>
- <#elseif linkReverse>
- <a href="/reverse/${result.getServer()}">${result.getServer()}</a> <sup><small>R</small></sup>
- <#else>
- ${result.getServer()}
- </#if>
- </td>
- <td class="<#if result.isSuccessful()>successful">reachable<#else>unsuccessful">unreachable</#if></td>
- </tr>
+ <#if availableDomains?seq_contains(result.getServer())>
+ <tr>
+ <td>
+ <a href="/<#if availableDomains?seq_index_of(result.getServer()) != 0>${result.getServer()}/</#if>">${result.getServer()}</a>
+ </td>
+ <td class="<#if result.isSuccessful()>successful">reachable<#else>unsuccessful">unreachable</#if></td>
+ </tr>
+ </#if>
+ </#list>
+ </table>
+
+ <h3>Remote Domains</h3>
+ <table>
+ <#list pingResults as result>
+ <#if !availableDomains?seq_contains(result.getServer())>
+ <tr>
+ <td>
+ <a href="/reverse/${result.getServer()}">${result.getServer()}</a>
+ </td>
+ <td class="<#if result.isSuccessful()>successful">reachable<#else>unsuccessful">unreachable</#if></td>
+ </tr>
+ </#if>
</#list>
</table>
<#else>
- <h1>${domain} seems to be down</h1>
+ <h1 style="color:red;">${domain} seems to be down</h1>
</#if>
-<p class="small info">Last updated: ${lastUpdated?datetime}</p>
+<div class="pull-right">
+ <p class="small info">Last updated: ${lastUpdated?datetime} UTC</p>
+</div>
<#else>
<p>No current information available on ${domain}</p>
</#if>
-</@page.page>
\ No newline at end of file
+</@page.page>
diff --git a/src/main/resources/spark/template/freemarker/about.ftl b/src/main/resources/spark/template/freemarker/about.ftl
new file mode 100644
index 0000000..8388446
--- /dev/null
+++ b/src/main/resources/spark/template/freemarker/about.ftl
@@ -0,0 +1,53 @@
+<#ftl output_format="HTML">
+<#import "page.ftl" as page/>
+<@page.page title="About XMPP Status Site" about=true>
+
+ <h2>About This Site</h2>
+ <p>This is the status site for my XMPP servers. This site shows whether the server is up and accepting connections
+ form clients and other servers. It also shows the historical uptime of the servers. service about every 5 minutes.</p>
+
+ <p>The server will connect to one of the <i>primary</i> domains, as a client, via a standerd JID to the C2S port 5222.
+ It then will send a <code>ping</code> request to each of the other domains (both the <i>Remote Domains</i> and the
+ <i>Primary Domains</i>) and wait for a response. If it receives a response, it considers the domain up and
+ <b style="color:green;">reachable</b>, if it does not receive the response in the prescribed time period, it will
+ consider the domain down and <b style="color:red;">unreachable</b>.</p>
+
+ <p>This site checks the XMPP service about every 5 minutes.</p>
+
+ <h2>Site Source</h2>
+ <p>The software running this site was originally written by <a href="https://gultsch.de/">Daniel Gultsch</a>, the
+ source is available in the Github repository
+ <a href="https://github.com/iNPUTmice/ServerStatus">iNPUTmice/ServerStatus</a> and is licensed under the
+ <a href="https://github.com/iNPUTmice/ServerStatus/blob/master/LICENSE">3 Clause BSD License</a>.</p>
+
+ <p>Customizations to the original software, as shown on this site, is available as a patch in the Gist
+ <a href="https://gist.github.com/mattrude/51f5aa7866169b1c2fbd4865ed5a2f94">ServerStatus-Custom</a>.</p>
+
+ <h2>License</h2>
+ <pre>Copyright (c) 2017, Daniel Gultsch All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation and/or
+other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors
+may be used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre>
+</@page.page>
#!/bin/sh
### BEGIN INIT INFO
# Provides: XMPP Status
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The XMPP Status Daemon
### END INIT INFO
SERVICE_NAME=XMPPStatus
PATH_TO_JAR=target/ServerStatus.jar
PID_PATH_NAME=/var/run/ServerStatus.pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
cd /var/src/ServerStatus/
nohup java -jar $PATH_TO_JAR 2>> /var/log/xmppstatus.err >> /var/log/xmppstatus.log &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stoping ..."
kill $PID;
echo "$SERVICE_NAME stopped ..."
rm $PID_PATH_NAME
else
echo "$SERVICE_NAME is not running ..."
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stopping ...";
kill $PID;
echo "$SERVICE_NAME stopped ...";
rm $PID_PATH_NAME
echo "$SERVICE_NAME starting ..."
nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment