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

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