forked from stephenfewer/grinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.php
More file actions
195 lines (153 loc) · 4.61 KB
/
Copy pathsystem.php
File metadata and controls
195 lines (153 loc) · 4.61 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
// Copyright (c) 2012, Stephen Fewer of Harmony Security (www.harmonysecurity.com)
// Licensed under a 3 clause BSD license (Please see LICENSE.txt)
// Source code located at https://github.com/stephenfewer/grinder
if( $_SERVER['REQUEST_METHOD'] != 'POST' )
exit;
define( 'BASE', true );
require_once 'config.php';
require_once 'user.php';
if( !user_isloggedin() )
exit;
// http://stackoverflow.com/questions/2915864/php-how-to-find-the-time-elapsed-since-a-date-time
function elapsed( $time )
{
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach( $tokens as $unit => $text )
{
if( $time < $unit )
continue;
$count = floor( $time / $unit );
return $count . ' ' . $text . ( ( $count > 1 ) ? 's' : '' );
}
return '';
}
function show_overview()
{
$unique = 0;
$sql = "SELECT hash_quick FROM crashes GROUP BY hash_quick;";
$result = mysql_query( $sql );
if( $result )
{
$unique = mysql_num_rows( $result );
mysql_free_result( $result );
}
if( $unique > 0 )
{
$sql = "SELECT SUM(count) AS total FROM crashes;";
$result = mysql_query( $sql );
if( $result )
{
$row = mysql_fetch_array( $result );
if( $row )
echo "<p class='message-text'>A total of " . htmlentities( $row['total'], ENT_QUOTES ) . " crashes have been generated, of which " . htmlentities( $unique, ENT_QUOTES ) . " appear unique.</p>";
mysql_free_result( $result );
}
}
$sql = "SELECT name, crashes, testcases_per_minute, lastcrash, lastfuzz FROM nodes ORDER BY name ASC;";
$result = mysql_query( $sql );
if( $result )
{
echo "<ul>";
if( mysql_num_rows( $result ) == 0 )
echo "<li><span class='message-text'>No Grinder nodes are available yet. Go set some up and fuzz something!!!</span></li>";
while( $row = mysql_fetch_array( $result ) )
{
// this server may or may not be be +/- N hours from the Nodes
$diff = intval( GRINDER_TIMEDIFF );
if( $diff >= 0 )
$server_time = strtotime( '+' . $diff . ' hours' );
else
$server_time = strtotime( $diff . ' hours' );
$running = false;
$lastcrash_period = null;
$testcases_per_minute = intval( $row['testcases_per_minute'] );
$lastcrash = strtotime( $row['lastcrash'] );
$lastfuzz = strtotime( $row['lastfuzz'] );
if( $lastfuzz )
{
$window = 5;
if( round( ( $server_time - $lastfuzz ) / 60 ) < $window + 1 )
{
$running = true;
}
}
if( $lastcrash )
{
$lastcrash_period = elapsed( ( $server_time - $lastcrash ) );
}
if( $running )
{
if( $testcases_per_minute > 0 )
$running = "<span class='message-active'>active</span> and averaging " . htmlentities( $testcases_per_minute, ENT_QUOTES ) . " testcases per minute";
else
$running = "<span class='message-active'>active</span>";
}
else
{
$running = "<span class='message-inactive'>inactive</span>";
}
echo "<li><span class='message-text'>Node " . htmlentities( $row['name'], ENT_QUOTES ) . " is currently " . $running . ". " . htmlentities( $row['name'], ENT_QUOTES ) ." has generated " . htmlentities( $row['crashes'], ENT_QUOTES ) . " crashes.";
if( intval( $row['crashes'] ) > 0 )
{
if( $lastcrash_period )
echo " The last crash was " . htmlentities( $lastcrash_period, ENT_QUOTES ) . " ago.";
}
echo "</span></li><br/>";
}
echo "</ul>";
mysql_free_result( $result );
}
}
?>
<!DOCTYPE html>
<html>
<body>
<script>
var index = 0;
if( $.cookie( 'grinder-system' ) )
{
index = parseInt( $.cookie( 'grinder-system' ) );
if( index == -1 )
index = false;
}
$( '#system-accordion' ).accordion({
active: index,
autoHeight: false,
animated: false,
collapsible: true,
changestart: function(event, ui) {
index = $( this ).accordion( 'option', 'active' );
if( typeof index == 'boolean' && index == false && $.cookie( 'grinder-system' ) )
index = -1;
$.cookie( 'grinder-system', index, { expires: 31 } );
if( index == 0 )
enableAutoRefresh();
else
disableAutoRefresh();
},
change: function( event, ui ) {
$( ui.newContent ).find('*[jqplot]').each( function(index) {
this.plot.replot();
} );
}
});
</script>
<div id='system-accordion'>
<h3><a href="#">Overview</a></h3>
<div>
<?php
show_overview();
?>
</div>
</div>
</body>
</html>