forked from lozzd/FITB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
81 lines (71 loc) · 3.27 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
include_once('functions.php');
$searchquery = $_GET['query'];
$start = "";
if(isset($_GET['duration'])) {
$start = "&duration=" . $_GET['duration'];
}
if((isset($_GET['type'])) && ($_GET['type'] != "")) {
$type = $_GET['type'];
}
if((isset($_GET['host'])) && ($_GET['host'] != "")) {
$host = $_GET['host'];
}
?>
<html>
<head>
<title>FITB - Search Results for <?php echo $searchquery ?></title>
<link rel="stylesheet" href="fitb.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<?php include_once('header.php'); # includes the <div> for the header ?>
<div id="wrap">
<?php include_once('side.php'); # includes the <div> for the side bar ?>
<div id="main">
<?php
if (isset($host)) {
echo "<h2>Search Results for \"{$searchquery}\" on host {$host}</h2>";
} elseif (isset($type)) {
echo "<h2>Search Results for \"{$searchquery}\", type {$type}</h2>";
} else {
echo "<h2>Search Results for \"{$searchquery}\"</h2>";
}
?>
<?php
connectToDB();
$searchquery = mysql_real_escape_string($searchquery);
if (isset($host)) {
$host = mysql_real_escape_string($host);
$type = mysql_real_escape_string($type);
$result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
AND graphtype like "%' . $type . '%" AND host="' . $host . '" ORDER BY lastpoll DESC, safename ASC');
} elseif (isset($type)) {
$type = mysql_real_escape_string($type);
$result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
AND graphtype="' . $type . '" ORDER BY lastpoll DESC, safename ASC');
} else {
$result = mysql_query('SELECT * FROM ports WHERE (name like "%' . $searchquery . '%" OR alias like "%' . $searchquery . '%")
ORDER BY lastpoll DESC, safename ASC');
}
if(mysql_num_rows($result) > 0) {
$numresults = mysql_num_rows($result);
echo "<div class=\"small\">{$numresults} results found</div>";
while ($row = mysql_fetch_assoc($result)) {
$staletag = "";
if ((time() - $row['lastpoll']) > $staleage) {
$staletag = "STALE: ";
}
$friendlytitle = urlencode("{$staletag}{$row['host']} - {$row['name']} ({$row['alias']})");
$basegraphurl = "graph.php?host={$row['host']}&rrdname={$row['host']}-{$row['safename']}&type={$row['graphtype']}{$start}&friendlytitle={$friendlytitle}";
echo '<a href="view' . $basegraphurl . '">';
echo '<img src="' . $basegraphurl . '&height=100&width=400" alt="'.$row['alias'].'"></a>';
}
} else {
echo "No results :( ";
}
?>
<div>
</div>
</body>
</html>