-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhosts.php
176 lines (165 loc) · 6.24 KB
/
hosts.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
include 'f.php';
if ($_REQUEST['s'] == 'ch') {
mysql_query(qsprintf("UPDATE `hosts` SET `state` = !`state` WHERE `id` = %s LIMIT 1", $_REQUEST['host_id']));
mysql_close($dbs);
die(header("Location: hosts.php"));
} else if ($_REQUEST['s'] == 'd') {
mysql_query(qsprintf("DELETE FROM `hosts` WHERE `id` = %s LIMIT 1", $_REQUEST['host_id']));
mysql_close($dbs);
die(header("Location: hosts.php"));
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">ATLAS</a>
<div class="nav-collapse collapse pull-right">
<ul class="nav">
<li><a href="index.php">Results</a></li>
<li class="active dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Hosts <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="hosts.php?a=add">Add</a></li>
<li><a href="hosts.php?a=list">List</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<?php
if ($_REQUEST['a'] == 'list' || !isset($_REQUEST['a'])) {
?>
<h3>Tracked Hosts</h3>
<table class="table table-striped">
<tbody>
<tr>
<th>#</th>
<th>Hostname</th>
<th>IP</th>
<th>Every</th>
<th>Last</th>
<th>State</th>
<th>More</th>
</tr>
<?php
$q = mysql_query("SELECT * FROM `hosts`");
$c = 1;
while ($result = mysql_fetch_row($q, MYSQL_ASSOC)) {
echo '<tr>
<td>', $c++ ,'</td>
<td>', $result['name'] ,'</td>
<td>', $result['ip'] ,'</td>
<td>'. ($result['every'] / 60) .' mins</td>
<td>'. date("d.m G:i", $result['last']). '</td>
<td>'. ($result['state'] == '1' ? 'Active' : 'Disabled') .'</td>
<td><a href="index.php?host_id=', $result['id'] ,'">Results</a> |
<a href="hosts.php?host_id=', $result['id'] ,'&s=ch">Change state</a> |
<a href="hosts.php?host_id=', $result['id'] ,'&s=d">Delete</a></td>
</tr>';
}
?>
</tbody>
</table>
<?php
} else if ($_REQUEST['a'] == 'add') {
if (isset($_REQUEST['add'])) {
$_q = mysql_query(qsprintf("INSERT INTO `hosts` (`name`, `ip`, `every`, `state`)
VALUES (%s, %s, %s, '1');",
$_REQUEST['name'], $_REQUEST['ip'], $_REQUEST['every']));
if ($_q)
echo "<script> alert('Added'); window.location = 'hosts.php'; </script>";
else
echo "<script> alert('Not added. Weird.'); window.location = 'hosts.php'; </script>";
}
?>
<h3>Add Host</h3>
<form class="form-horizontal" method="POST">
<input type="hidden" name="a" value="add">
<div class="control-group">
<label class="control-label" for="inputName">Name</label>
<div class="controls">
<input type="text" id="inputName" placeholder="Name" name="name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputIP">IP</label>
<div class="controls">
<input type="text" id="inputIP" placeholder="IP" name="ip">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEvery">Tracert Every</label>
<div class="controls">
<select id="inputEvery" name="every">
<option value="60">1 min</option>
<option value="300">5 mins</option>
<option value="900">15 mins</option>
</select>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="add">Add</button>
</div>
</div>
</form>
<?php
}
?>
<hr>
<footer>
<p>IPKO 2013</p>
</footer>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
<?php
mysql_close($dbs);
?>