Skip to content

Commit

Permalink
Added feature where you can download list of servers in each section …
Browse files Browse the repository at this point in the history
…as a CSV
  • Loading branch information
Peter Malaty committed Feb 22, 2017
1 parent f1234c9 commit 08717c4
Show file tree
Hide file tree
Showing 15 changed files with 864 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php? [QSA,L,E=PATH_INFO:/$1]

39 changes: 39 additions & 0 deletions getgraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

require_once './inc/db.php';
// header("Content-type: image/png");
//$output_file='/tmp/myimage.png';
$dblink = db_connect();

// Packages with updates
// $dbquery2 = "select packagename,count(*) as cunt from packages WHERE packtype='bug' group by packagename order by cunt DESC, packagename ASC;";
$dbquery2 = "select hostname, sum(if (packtype='bug',1,0)) as bug, sum(if (packtype='sec',1,0)) as sec from packages group by hostname;";
$dbresult2 = mysqli_query($dblink, $dbquery2);
// echo "<table>\n";
// echo "<tr><td>Package</td><td>Short Desc</td><td>Num of Affected servers</td></tr><br/>\n";
$data=array();
if ($dbresult2 && mysqli_num_rows($dbresult2)) {
while ($row2 = mysqli_fetch_object($dbresult2)) {
$arr_t=array();

$host_t=$row2->hostname;
$bug_t=$row2->bug;
$sec_t=$row2->sec;
$url_t="https://man.pmalaty.com/view_page.php?action=viewallpkgs&servername=$host_t";
$arr_t['hostname']=$host_t;
$arr_t['bug']=$bug_t;
$arr_t['sec']=$sec_t;
$arr_t['url']=$url_t;

//print_r($row2);
$data[] = $arr_t;
}
}


//print_r($data);
$json_dataset = json_encode($data);

echo $json_dataset;

?>
4 changes: 2 additions & 2 deletions inc/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ function ldapconnect() {
require 'inc/stdfoot.php';
exit(0);
}

if (substr($section, -3) != 'csv') {
echo "<div class='status'>\n";
echo "\t<h2>Info &amp; Status</h2>\n";
echo "\t<p>You are logged in as $displayname (" . $_SESSION['user'] . ")</p>\n";
if ($_SESSION['admin']) echo "\t<p>You have admin level access to this application</p>\n";
echo "\t<form method='post' name='logoutform' style='display: inline-block'><button class='sig1 button' type='submit' name='action' value='logoff'>Logout?</button></form><a class='sig1 button' href='" . $_SERVER['PHP_SELF'] . "'>Refresh?</a><br />\n";
echo "</div>\n";
?>
}

1 change: 0 additions & 1 deletion inc/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ function db_connect() {
return $dblink;
}

?>
1 change: 1 addition & 0 deletions inc/pages/Downloads/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fhsdjvhjksdfhjks
43 changes: 43 additions & 0 deletions inc/pages/SyPUMclient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php


ignore_user_abort(true);
set_time_limit(0); // disable the time limit for this script

$_GET['download_file']='test.txt';
$File='test.txt';

$path = $_SERVER["DOCUMENT_ROOT"] . "/inc/pages/Downloads/"; // change the path to fit your websites document structure

$dl_file = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).]|[\.]{2,})", '', $File); // simple file name validation
$dl_file = filter_var($dl_file, FILTER_SANITIZE_URL); // Remove (more) invalid characters
$fullPath = $path.$dl_file;

if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "txt":
header("Content-type: application/txt");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a file download
break;
// add more headers for other content types here
default:
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;


?>

25 changes: 17 additions & 8 deletions inc/pages/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@
// $dbquery = "SELECT count(distinct hostname) FROM systems;";
$dbquery = "SELECT count(distinct hostname) FROM systems where hostname NOT IN (SELECT distinct hostname from packages where packtype='sec')";
$dbresult = mysqli_query($dblink, $dbquery);
list($servercount) = mysqli_fetch_row($dbresult);
echo "<a href='/servers/withbugs' class='dashbox secondary-1-0'><h3>Servers with non-security updates</h3><span class='count'>$servercount</span></a>";
list($serverupdcount) = mysqli_fetch_row($dbresult);
echo "<a href='/servers/withbugs' class='dashbox secondary-1-0'><h3>Servers with non-security updates</h3><span class='count'>$serverupdcount</span></a>";

// Servers with security updates
$dbquery = "SELECT count(distinct hostname) FROM packages where packtype='sec';";
$dbresult = mysqli_query($dblink, $dbquery);
list($servercount) = mysqli_fetch_row($dbresult);
echo "<a href='/servers/withbugsandupdates' class='dashbox red'><h3>Servers with security updates</h3><span class='count'>$servercount</span></a>";
list($serverseccount) = mysqli_fetch_row($dbresult);
echo "<a href='/servers/withbugsandupdates' class='dashbox red'><h3>Servers with security updates</h3><span class='count'>$serverseccount</span></a>";

// Servers with security updates
// Servers that haven't checked in recently
$dbquery = "SELECT count(distinct hostname) FROM systems where checkin <= now() - INTERVAL 1 DAY;";
$dbresult = mysqli_query($dblink, $dbquery);
list($servercount) = mysqli_fetch_row($dbresult);
Expand Down Expand Up @@ -114,7 +114,16 @@
"startDuration": 1,
"fontFamily": "Sans",
"categoryAxis": {
"gridPosition": "start"
"gridPosition": "start",
"autoGridCount": false,
"gridCount": 1000,
"listeners": [{
"event": "clickItem",
"method": function(event) {
window.location.href = event.serialDataItem.dataContext.url;
}
}]

},
"trendLines": [],
"graphs": [
Expand All @@ -140,7 +149,7 @@
{
"id": "ValueAxis-1",
"stackType": "regular",
"title": "Number of updates"
"title": "Number of updates",
}
],
"allLabels": [],
Expand All @@ -163,7 +172,7 @@
}
);
</script>
<div id="chartdiv" style="width: 100%; height: 400px; background-color: #FFFFFF;" ></div>
<div id="chartdiv" style="width: 100%; height: <?php echo (($serverupdcount + $serverseccount) * 30) + 80; ?>px ; background-color: #FFFFFF;" ></div>

</div>
</div>
Expand Down
88 changes: 88 additions & 0 deletions inc/pages/packages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
// Project SyPUM - Systems Package Update Management
//
//
// Author: Peter Malaty - 12/20/2016 All Rights Reserved
//
// Copyright 2016 Peter G.F Malaty - [email protected]
// This file is part of MAN Spider is distributed under the terms of the GNU General Public License
/*
SyPUM - Systems Package Update Management is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SyPUM - Systems Package Update Management is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/




require_once 'inc/stdhead.php';


require_once('inc/db.php');

$dblink=db_connect();

$servername=mysqli_real_escape_string($dblink,$_GET['servername']);
$Action=mysqli_real_escape_string($dblink,$_GET['action']);
$Ubureleasever=mysqli_real_escape_string($dblink,$_GET['ubureleasever']);


switch ($page) {
case 'bugspacks':
$title = "List of Bug fix Packs on All Servers";
$serversqlcond = "WHERE packtype='bug'";
break;


case 'secupdates':
$title = "List of Security Packages on All Servers";
$serversqlcond = "WHERE packtype='sec'";
break;

// default:
// $title = "Nothing's here";
// $serversqlcond = "";
// break;
}

//echo "<h1>Host $servername</h1>";
echo "<div class='contentbox'>\n";
echo "<h2>$title</h2>";
echo "<div class='content'>\n";
// $dbquery = "SELECT distinct packagename,shortdesc FROM packages $serversqlcond;";
// $dbresult = mysqli_query($dblink, $dbquery);
$dbquery2 = "select packagename,shortdesc,count(*) as cunt from packages $serversqlcond group by packagename order by cunt DESC, packagename ASC;";
$dbresult2 = mysqli_query($dblink, $dbquery2);
if($serversqlcond == "WHERE packtype='bug'") $pkgtype='bug'; elseif ($serversqlcond == "WHERE packtype='sec'") $pkgtype='sec';
echo "<table>\n";
echo "<tr><td>Package</td><td>Short Desc</td><td>Num of Affected servers</td></tr><br/>\n";
if ($dbresult2 && mysqli_num_rows($dbresult2)) {
while ($row2 = mysqli_fetch_object($dbresult2)) {
$Packname=$row2->packagename;
$Shortdesc=$row2->shortdesc;
$count=$row2->cunt;
echo "<tr><td>$Packname</td><td>$Shortdesc</td><td><a href='/view_page.php?action=viewsrvspkg&packagename=$Packname&pktype=$pkgtype'>$count</td></tr>\n";

}
}
else {
echo "No Packages here to display\n";
}

echo"</table>";
echo "</div>\n";
echo "</div>\n";


require_once 'inc/stdfoot.php';

?>
Loading

0 comments on commit 08717c4

Please sign in to comment.