source: trollforge/lastmeasure/stats/index.php @ 185

Revision 185, 8.0 KB checked in by sam, 7 years ago (diff)
  • typo...
  • Property svn:keywords set to Id
Line 
1<?php
2include($_SERVER['DOCUMENT_ROOT'].'/include/db.php');
3
4function tooltip($id, $text, $full, $href) { ?>
5    <div id="<?php echo $id;?>" class="jstip"><?php echo $full; ?></div>
6    <a onmouseout="jstip(event,'<?php echo $id;?>')" onmouseover="jstip(event,'<?php echo $id;?>')" onclick="return false;"
7    <?php if($href && preg_match('/(http:\/\/[^ ]*)/i', $full, $matches)) {
8        $url = $matches[0];
9        echo ' href="'.$matches[0].'"';
10    } ?>><?php echo $text;?></a><?php
11}
12
13function cut($str, $count) {
14    $l = strlen($str);
15    if($l >= $count) {
16        $n = $count / 2;
17        $s1 = trim(substr($str, 0, $n));
18        $s2 = trim(substr($str, $l - $n));
19        $str = "$s1...$s2";
20    }
21    $str = htmlspecialchars($str);
22    $str = str_replace(" ", "&nbsp;", $str);
23    return $str;
24}
25
26function print_hits() {
27    $id = dba_open($_SERVER['DOCUMENT_ROOT'].'/db/hit.db', 'w', 'db4');
28    if(!$id) {
29        ?><tr><td colspan="6" class="error">Failed to open database!</td></tr><?php
30        return;
31    }
32    $key = dba_firstkey($id);
33    if($key == false) {
34        ?><tr><td colspan="6" class="error">No hits found!</td></tr><?php
35        return;
36    }
37    for($l = 0; $l < 20 && $key != false; $l++) {
38        $val = dba_fetch($key, $id);
39        list($ip, $port, $host, $uagent,
40             $referer, $user, $clipboard) = explode(' ', $val);
41        $date = key2date($key);
42        ?>
43        <tr style="background-color: <?php echo ($l % 2) ? '#cef' : '#ecf'; ?>">
44          <td>
45            <?php tooltip("d$l", date('H:i:s', $date), date('D, d M Y H:i:s', $date), false); ?>
46          </td>
47          <td>
48            <?php if($host == '') {
49              $host = gethostbyaddr($ip);
50              $host = gethostbyaddr($ip);
51              $val = "$ip $port $host $uagent $referer $user $clipboard";
52              dba_replace($key, $val, $id);
53            }
54            if($host != '') {
55              tooltip("h$l", "$ip", "$host $port", false);
56            } else {
57              tooltip("h$l", "$ip", "$ip $port", false);
58            } ?>
59          </td>
60          <td>
61            <?php $uagent = base64_decode($uagent);
62            if(strlen($uagent) > 30) {
63              tooltip("b$l", cut($uagent, 25), htmlspecialchars($uagent), false);
64            } else {
65              echo htmlspecialchars($uagent);
66            } ?>
67          </td>
68          <td>
69            <?php $referer = base64_decode($referer);
70            if(strlen($referer) > 35) {
71              tooltip("r$l", cut($referer, 30), htmlspecialchars($referer), true);
72            } else {
73              echo '<a href="'.htmlspecialchars($referer).'">'.htmlspecialchars($referer).'</a>';
74            } ?>
75          </td>
76          <td>
77            <?php
78              $user = base64_decode($user);
79              echo htmlspecialchars($user);
80            ?>
81          </td>
82          <td>
83            <?php $clipboard = base64_decode($clipboard);
84            if(strlen($clipboard) > 45) {
85              tooltip("c$l", cut($clipboard, 40), htmlspecialchars($clipboard), true);
86            } else {
87              echo htmlspecialchars($clipboard);
88            } ?>
89          </td>
90        </tr><?php
91        $key = dba_nextkey($id);
92    }
93    dba_close($id);
94}
95
96function toplist($title, $table, $count) {
97    $id = dba_open($table, 'w', 'db4');
98    if(!$id) {
99        ?><tr><td colspan="2" class="error">Failed to open database!</td></tr><?php
100        return;
101    }
102    $key = dba_firstkey($id);
103    if($key == false) {
104        ?><tr><td colspan="2" class="error">No hits found!</td></tr><?php
105        return;
106    }
107    $items = array();
108    $total = 0;
109    while($key != false) {
110        $total++;
111        $val = dba_fetch($key, $id);
112        $items[$key] = $val;
113        arsort($items);
114        if(count($items) > $count)
115            array_pop($items);
116        $key = dba_nextkey($id);
117    }
118    if($count > $total) $count = $total;
119    $l = 0; ?>
120    <table style="border: solid black 1px; margin: 5px;">
121      <tr style="background-color: #8af;">
122        <td><?php echo $title;?> (<?php echo "$count of $total";?>)</td>
123        <td>Count</td>
124      </tr> <?php
125    foreach($items as $key => $val) { ?>
126        <tr style="background-color: <?php echo ($l % 2) ? '#cef' : '#ecf'; ?>">
127          <td><?php echo base64_decode($key); ?></td>
128          <td><?php echo $val; ?></td>
129        </tr><?php
130        $l++;
131    } ?>
132    </table><?php
133    dba_close($id);
134}
135
136?>
137<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
138       "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
139<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
140<head>
141   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
142   <title>GNAA Last Measure Statistics</title>
143   <link rel="icon" type="image/x-icon" href="/favicon.ico" />
144   <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
145   <style type="text/css">
146      body,td {
147         font-family: sans-serif, Verdana, Arial, Helvetica;
148         font-size: 0.9em;
149      }
150      .jstip {
151         float: left;
152         clear: both;
153         visibility: hidden;
154         border: solid black 1px;
155         padding: 2px;
156         position: absolute;
157         z-index: 100;
158         background-color: #ffeecc;
159         font-size: 0.8em;
160      }
161      .error {
162         background-color: #ff6666;
163      }
164   </style>
165   <script type="text/javascript">
166//<!--
167var support = false;
168if (document.getElementById || document.all) {
169  support = true;
170  suffix = 'px';
171} else if (navigator.appName.indexOf('Netscape') != -1
172            && parseInt(navigator.appVersion) == 4) {
173  support = true;
174  suffix = '';
175}
176
177function jstip(ev, id) {
178  if (!support)
179    return;
180
181  if (document.getElementById) {
182    tipstyle = document.getElementById(id).style;
183    tipentity = document.getElementById(id);
184  } else if (document.all) {
185    tipstyle = document.all[id].style;
186    tipentity = document.all[id];
187  } else {
188    tipstyle = document.layers[id];
189    tipentity = document.layers[id];
190  }
191
192  if (tipstyle.visibility == 'visible' || tipstyle.visibility == 'show') {
193    tipstyle.visibility = 'hidden';
194    return;
195  }
196
197  if (ev.pageY) {
198    tipx = ev.pageX;
199    tipy = ev.pageY;
200  } else if (ev.clientY && document.documentElement.scrollTop) {
201    tipx = ev.clientX + document.documentElement.scrollLeft;
202    tipy = ev.clientY + document.documentElement.scrollTop;
203  } else if (ev.clientY) {
204    tipx = ev.clientX + document.body.scrollLeft;
205    tipy = ev.clientY + document.body.scrollTop;
206  } else {
207    tipx = tipy = 0;
208  }
209
210  if (tipentity.offsetWidth)
211    tipwidth = tipentity.offsetWidth;
212  else if (tipentity.clip.width)
213    tipwidth = tipentity.clip.width;
214  else
215    tipwidth = 100;
216
217  if (window.innerWidth)
218    winwidth = window.innerWidth;
219  else if (document.body.clientWidth)
220    winwidth = document.body.clientWidth;
221  else
222    winwidth = 800;
223
224  tipx -= tipwidth / 3;
225  tipy += 15;
226
227  if (tipwidth + tipx > winwidth)
228    tipx = winwidth - tipwidth - 2;
229  else if (tipx < 2)
230    tipx = 2;
231
232  tipstyle.left = tipx + suffix;
233  tipstyle.top = tipy + suffix;
234  tipstyle.visibility = 'visible';
235}
236//-->
237   </script>
238</head>
239<body>
240
241  <h1><span style="background-color: transparent;
242              right-margin: 10px; clear: both;">
243    <img src="/gnaa.png" width="108" height="40"
244         alt="GNAA" />
245  </span> GNAA Last Measure Statistics </h1>
246
247  <div style="float: left;">
248    <?php toplist('User', $_SERVER['DOCUMENT_ROOT'].'/db/user.db', 40); ?>
249  </div>
250
251  <table style="border: solid black 1px; margin: 5px;">
252    <tr style="background-color: #8af;">
253      <td>Date</td>
254      <td>Host</td>
255      <td>Browser</td>
256      <td>Referer</td>
257      <td>User</td>
258      <td>Clipboard</td>
259    </tr>
260    <?php print_hits(); ?>
261  </table>
262
263  <?php toplist('Browser', $_SERVER['DOCUMENT_ROOT'].'/db/uagent.db', 20); ?>
264
265  <hr />
266
267  <div style="float: right;">
268    <p>
269      <a href="http://validator.w3.org/check?uri=referer"><img
270          src="http://www.w3.org/Icons/valid-xhtml11" style="border: 0px;"
271          alt="Valid XHTML 1.1" height="31" width="88" /></a>
272    </p>
273  </div>
274
275  <p> Generated by Last Measure Unified <?php echo date('Y-m-d H:i:s'); ?> </p>
276
277</body>
278</html>
Note: See TracBrowser for help on using the repository browser.