Commit 15eda068 authored by Hugo Leisink's avatar Hugo Leisink

Release 1.4

parent da951e4a
monitor (1.4) stable; urgency=low
* Daily report optimized for mobile devices.
* Small improvements.
* Bugfix: foreign key issue when deleting a webserver.
-- Hugo Leisink <hugo@leisink.net> Thu, 11 Feb 2016 09:49:48 +0100
monitor (1.3) stable; urgency=low
* Improved dashboard.
* Hourly graph added to day overview page.
* Setup module added.
-- Hugo Leisink <hugo@leisink.net> Thu, 3 Sep 2015 14:15:29 +0200
-- Hugo Leisink <hugo@leisink.net> Thu, 3 Sep 2015 12:50:34 +0200
monitor (1.2) stable; urgency=low
......
......@@ -10,7 +10,7 @@ Use the following Hiawatha configuration for this website.
UrlToolkit {
ToolkitID = monitor
RequestURI isfile Return
Match ^/(css|images|js)/ Return
Match ^/(css|files|fonts|images|js)(/|$) Return
Match ^/(favicon.ico|robots.txt)$ Return
Match [^?]*(\?.*)? Rewrite /index.php$1
}
......
......@@ -100,7 +100,7 @@
foreach ($parts as $part) {
if (in_array(substr(ltrim($part), 0, 3), array("TLS", "SSL"))) {
$version = trim(substr($part, 4), " ()");
$version = trim(substr($part, 4), " (v)");
if (version_compare($version, $_SESSION["latest_mbedtls_version"], "<")) {
$webserver["uptodate"] .= " (mbed TLS out of date)";
}
......
......@@ -11,6 +11,7 @@
$this->user->log_action("switched back to self");
$_SESSION["user_id"] = $_SESSION["user_switch"];
unset($_SESSION["user_switch"]);
unset($_SESSION["filter"]);
$url = "cms/switch";
}
......
......@@ -40,8 +40,6 @@
ob_clean();
break;
case "done":
ob_clean();
$this->model->ensure_settings();
break;
}
$this->output->close_tag();
......
......@@ -136,7 +136,7 @@
if (($hostname_id = get_hostname_id($db, $hostname)) == false) {
print "Error getting hostname id\n";
continue;
return;
}
list($date, $hour) = get_date_hour($timestamp_begin, $timestamp_end);
......@@ -220,7 +220,7 @@
if (($hostname_id = get_hostname_id($db, $hostname)) == false) {
print "Error getting hostname id\n";
continue;
return;
}
list($date, $hour) = get_date_hour($timestamp_begin, $timestamp_end);
......
......@@ -176,7 +176,7 @@
foreach ($stats as $label => $stat) {
$header = "<h3>".$label."</h3>\n".
"<table class=\"stats\">\n".
"<tr><th>Type</th><th>Value</th><th>= &#916;% of</th><th>".$type."</th></tr>\n";
"<thead>\n<tr><th>Type</th><th>Value</th><th>= &#916;% of</th><th>".$type."</th></tr>\n</thead>\n<tbody>\n";
$header_set = false;
$columns = array_keys($stat["details"]);
......@@ -209,7 +209,7 @@
}
if ($header_set) {
$report["content"] .= "</table>\n";
$report["content"] .= "</tbody>\n</table>\n";
}
}
......@@ -218,13 +218,13 @@
if (($events = $db->execute($query, $webserver["id"])) != false) {
$report["content"] .= "<h3>Events</h3>\n";
$report["content"] .= "<table class=\"events\">\n";
$report["content"] .= "<tr><th>Time</th><th>Event</th></tr>\n";
$report["content"] .= "<thead>\n<tr><th>Time</th><th>Event</th></tr>\n</thead>\n<tbody>\n";
foreach ($events as $event) {
$report["content"] .= "<tr><td>".date("H:i:s", $event["timestamp"])."</td><td>".$event["event"]."</td></tr>\n";
$report["content"] .= "<tr><td>".date("H:i:s", $event["timestamp"])."</td><td>".htmlentities($event["event"])."</td></tr>\n";
}
$report["content"] .= "</table>\n";
$report["content"] .= "</tbody>\n</table>\n";
$add_count++;
}
......@@ -263,7 +263,7 @@
return;
}
$query = "select * from webservers w, webserver_user l ".
$query = "select w.* from webservers w, webserver_user l ".
"where w.id=l.webserver_id and l.user_id=%d order by w.name";
foreach ($users as $user) {
if (($webservers = $db->execute($query, $user["id"])) == false) {
......@@ -273,7 +273,7 @@
$report_content = "";
$report_alerts = array();
foreach ($webservers as $webserver) {
if (($report = generate_report($db, $settings, $user, $webserver)) == false) {
if (($report = generate_report($db, $settings, $user, $webserver)) === false) {
continue;
}
$report_content .= $report["content"];
......
......@@ -2,21 +2,29 @@
<head>
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
font-family:courier-sans;
background-color:#c0c0c0;
font-size:9pt;
padding:20px 0 20px 0;
}
div.container {
width:550px;
width:100%;
background-color:#ffffff;
box-shadow:15px 10px 5px #606060;
padding:30px 40px;
margin:0 auto;
}
div.container > div {
padding:10px 20px;
}
p {
margin:20px 0 0 0;
margin-top:10px;
}
p.footer {
font-style:italic;
margin-top:30px;
}
h2 + p {
margin-top:5px;
......@@ -24,22 +32,23 @@
h1 {
font-size:16pt;
color:#1010c0;
margin:0;
}
h2 {
font-size:14pt;
color:#6060ff;
padding-bottom:5px;
margin-bottom:0;
margin-top:15px;
border-bottom:1px dashed #ff8000;
}
h3 {
font-size:12pt;
margin-bottom:0;
margin-top:10px;
}
table {
font-size:inherit;
width:500px;
width:100%;
border-spacing:2px;
border:1px solid #c0c0ff;
}
table th {
background-color:#c0c0ff;
......@@ -59,22 +68,40 @@
color:#ff0000;
}
table.stats td:nth-child(n+2) {
width:75px;
width:50px;
text-align:right;
}
table.events th:nth-child(2) {
width:400px;
table.events th:nth-child(1) {
width:50px;
}
@media (max-width:767px) {
h1 {
display:none;
}
}
@media (min-width:767px) {
body {
padding-top:20px;
}
div.container {
max-width:500px;
box-shadow:15px 10px 5px #606060;
margin:0 auto 50px auto;
}
div.container > div {
padding:30px 40px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="container"><div>
<h1>Daily Hiawatha Monitor report</h1>
<p>Alerts in this report for: [ALERTS]</p>
[CONTENT]
<p>The [TYPE] is calculated over the last [HISTORY] days. This report was generated at [TIMESTAMP].</p>
</div>
<p class="footer">The [TYPE] is calculated over the last [HISTORY] days. This report was generated at [TIMESTAMP].</p>
</div></div>
</body>
</html>
......@@ -9,7 +9,7 @@
/* For internal usage. Only change if you know what you're doing!
*/
define("BANSHEE_VERSION", "5.0");
define("MONITOR_VERSION", "1.3");
define("MONITOR_VERSION", "1.4");
define("ADMIN_ROLE_ID", 1);
define("YES", 1);
define("NO", 0);
......
......@@ -229,7 +229,7 @@
}
$remote = sprintf("%s://%s:%s", $protocol, $this->connect_host, $this->connect_port);
if (($sock = stream_socket_client($remote, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context)) === false) {
if (($sock = @stream_socket_client($remote, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context)) === false) {
return false;
}
......
......@@ -57,14 +57,14 @@
list($protocol,, $referer_host) = explode("/", $referer, 4);
list($referer_host) = explode(":", $referer_host);
if (($protocol != "http:") && ($protocol == "https:")) {
if (($protocol != "http:") && ($protocol != "https:")) {
return false;
}
$valid_hostnames = array($_SERVER["HTTP_HOST"]);
if (in_array($referer_host, $valid_hostnames)) {
list($http_host) = explode(":", $_SERVER["HTTP_HOST"]);
if ($http_host == $referer_host) {
return false;
}
}
$message = sprintf("CSRF attempt from %s blocked", $_SERVER["HTTP_REFERER"]);
......
......@@ -25,11 +25,7 @@
$this->db = $db;
$this->settings = $settings;
if ($_SERVER["HTTP_X_BANSHEE_SESSION"] == "disk") {
$this->use_database = false;
} else {
$this->use_database = ($this->settings->session_timeout >= ini_get("session.gc_maxlifetime"));
}
$this->use_database = ($this->settings->session_timeout >= ini_get("session.gc_maxlifetime"));
if ($this->use_database) {
$this->db->query("delete from sessions where expire<=now()");
......
......@@ -139,6 +139,7 @@
$queries = array(
array("delete from webserver_user where webserver_id=%d", $webserver_id),
array("delete from events where webserver_id=%d", $webserver_id),
array("delete from cgi_statistics where webserver_id=%d", $webserver_id),
array("delete from host_statistics where webserver_id=%d", $webserver_id),
array("delete from server_statistics where webserver_id=%d", $webserver_id),
array("delete from webservers where id=%d", $webserver_id));
......
......@@ -21,6 +21,9 @@
*/
if ((DB_HOSTNAME == "localhost") && (DB_DATABASE == "monitor") && (DB_USERNAME == "monitor") && (DB_PASSWORD == "monitor")) {
return "db_settings";
} else if (strpos(DB_PASSWORD, "'") !== false) {
$this->output->add_system_message("A single quote is not allowed in the password!");
return "db_settings";
}
return "create_db";
......@@ -31,8 +34,7 @@
return "import_sql";
}
$settings = new settings($db);
if ($settings->database_version == null) {
if ($this->settings->database_version < $this->latest_database_version()) {
return "update_db";
}
......@@ -143,7 +145,7 @@
/* Import SQL script from file
*/
public function import_sql() {
system("mysql -u \"".DB_USERNAME."\" --password=\"".DB_PASSWORD."\" \"".DB_DATABASE."\" < ../database/mysql.sql", $result);
system("mysql -h '".DB_HOSTNAME."' -u '".DB_USERNAME."' --password='".DB_PASSWORD."' '".DB_DATABASE."' < ../database/mysql.sql", $result);
if ($result != 0) {
$this->output->add_message("Error while importing database tables.");
return false;
......@@ -155,35 +157,24 @@
return true;
}
/* Update database
/* Collect latest database version from update_database() function
*/
public function update_database() {
$tables = array("cgi_statistics", "host_statistics", "server_statistics");
foreach ($tables as $table) {
$this->db->query("alter table %S add %S date not null after %S", $table, "date", "id");
$this->db->query("alter table %S add %S tinyint unsigned not null after %S", $table, "hour", "date");
$this->db->query("update %S set %S=date(%S), %S=%d", $table, "date", "timestamp_begin", "hour", 0);
$this->db->query("alter table %S drop %S", $table, "timestamp_begin");
$this->db->query("alter table %S drop %S", $table, "timestamp_end");
}
$this->db->query("alter table %S add index(%S)", "cgi_statistics", "date");
$this->db->query("alter table %S add index(%S)", "cgi_statistics", "hour");
$this->db->query("alter table %S add index(%S)", "host_statistics", "date");
$this->db->query("alter table %S add index(%S)", "host_statistics", "hour");
$this->db->query("alter table %S add index(%S)", "server_statistics", "date");
$this->db->query("alter table %S add index(%S)", "server_statistics", "hour");
$settings = new settings($this->db);
$settings->dashboard_threshold_change = 150;
$settings->dashboard_threshold_value = 5;
$settings->dashboard_page_refresh = 1;
$settings->report_alert_high = 300;
$settings->report_alert_medium = 150;
$settings->report_history_days = 15;
$settings->report_skip_normal = false;
$settings->report_use_median = true;
$settings->database_version = 103;
private function latest_database_version() {
$old_db = $this->db;
$old_settings = $this->settings;
$this->db = new dummy_object();
$this->settings = new dummy_object();
$this->settings->database_version = 0;
$this->update_database();
$version = $this->settings->database_version;
unset($this->db);
unset($this->settings);
$this->db = $old_db;
$this->settings = $old_settings;
return $version;
}
/* Add setting when missing
......@@ -200,13 +191,70 @@
return $this->db->insert("settings", $entry) !== false;
}
/* Ensure settings
/* Update database
*/
public function ensure_settings() {
$this->ensure_setting("hiawatha_cache_enabled", "boolean", "false");
$this->ensure_setting("hiawatha_cache_default_time", "integer", "3600");
$this->ensure_setting("session_timeout", "integer", "3600");
$this->ensure_setting("session_persistent", "boolean", "false");
public function update_database() {
if ($this->settings->database_version < 101) {
$this->settings->database_version = 101;
}
if ($this->settings->database_version < 102) {
$this->ensure_setting("hiawatha_cache_enabled", "boolean", "false");
$this->ensure_setting("hiawatha_cache_default_time", "integer", "3600");
$this->ensure_setting("session_timeout", "integer", "3600");
$this->ensure_setting("session_persistent", "boolean", "false");
$this->settings->database_version = 102;
}
if ($this->settings->database_version < 103) {
$tables = array("cgi_statistics", "host_statistics", "server_statistics");
foreach ($tables as $table) {
$this->db->query("alter table %S add %S date not null after %S", $table, "date", "id");
$this->db->query("alter table %S add %S tinyint unsigned not null after %S", $table, "hour", "date");
$this->db->query("update %S set %S=date(%S), %S=%d", $table, "date", "timestamp_begin", "hour", 0);
$this->db->query("alter table %S drop %S", $table, "timestamp_begin");
$this->db->query("alter table %S drop %S", $table, "timestamp_end");
}
$this->db->query("alter table %S add index(%S)", "cgi_statistics", "date");
$this->db->query("alter table %S add index(%S)", "cgi_statistics", "hour");
$this->db->query("alter table %S add index(%S)", "host_statistics", "date");
$this->db->query("alter table %S add index(%S)", "host_statistics", "hour");
$this->db->query("alter table %S add index(%S)", "server_statistics", "date");
$this->db->query("alter table %S add index(%S)", "server_statistics", "hour");
$this->settings->dashboard_threshold_change = 150;
$this->settings->dashboard_threshold_value = 5;
$this->settings->dashboard_page_refresh = 1;
$this->settings->report_alert_high = 300;
$this->settings->report_alert_medium = 150;
$this->settings->report_history_days = 15;
$this->settings->report_skip_normal = false;
$this->settings->report_use_median = true;
$this->settings->database_version = 103;
}
if ($this->settings->database_version < 104) {
$this->settings->database_version = 104;
}
}
}
class dummy_object {
private $cache = array();
public function __set($key, $value) {
$this->cache[$key] = $value;
}
public function __get($key) {
return $this->cache[$key];
}
public function __call($func, $args) {
return false;
}
}
?>
div.form-control {
margin-bottom:5px;
max-width:500px;
}
@media (max-width:767px) {
table.table th:nth-child(2),
table.table td:nth-child(2) {
......
div.content div.hidess {
position:absolute;
top:16px;
right:300px;
@media (min-width:768px) {
div.content div.hidess {
position:absolute;
margin-top:-29px;
right:300px;
}
}
@media (max-width:767px) {
div.content div.hidess {
position:static;
float:right;
}
}
......@@ -31,6 +31,13 @@
$_language = new language($_database, $_page, $_output);
}
/* Logging
*/
if (library_exists("logging") && ($_user->is_admin == false)) {
$logging = new logging($_database, $_page);
$logging->execute();
}
/* Prevent Cross-Site Request Forgery
*/
prevent_csrf($_output, $_user);
......
$(document).ready(function() {
labels = $("table.label").detach();
$("table.tablemanager").before(labels);
labels = $("div.labels").detach();
$("form").before(labels);
});
User-agent: *
Disallow: /
Disallow: /cms
......@@ -4,10 +4,12 @@
<xsl:include href="../banshee/tablemanager.xslt" />
<xsl:template match="tablemanager/label">
<table class="label">
<tr><td>Key:</td><td><xsl:value-of select="key" /></td></tr>
<tr><td>Type:</td><td><xsl:value-of select="type" /></td></tr>
</table>
<div class="labels">
<label>Key:</label>
<div class="form-control" disabled="disabled"><xsl:value-of select="key" /></div>
<label>Type:</label>
<div class="form-control" disabled="disabled"><xsl:value-of select="type" /></div>
</div>
</xsl:template>
<xsl:template match="content">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment