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

Revision 243, 6.4 KB checked in by Rucas, 7 years ago (diff)

Changed name and references

Line 
1<?php
2include('../include/db.php');
3include('../include/tooltips.php');
4
5function print_cell($text, $full, $href) {
6    if($href && preg_match('/(http:\/\/[^ ]*)/i', $full, $matches)) {
7        $url = $matches[0];
8        tooltip($text, $full, $url);
9    } else {
10        tooltip($text, $full, '');
11    }
12}
13
14function cut($str, $count) {
15    $l = strlen($str);
16    if($l >= $count) {
17        $n = $count / 2;
18        $s1 = trim(substr($str, 0, $n));
19        $s2 = trim(substr($str, $l - $n));
20        $str = "$s1...$s2";
21    }
22    $str = htmlspecialchars($str);
23    $str = str_replace(" ", "&nbsp;", $str);
24    return $str;
25}
26
27function print_hits() {
28    $id = dba_open($_SERVER['DOCUMENT_ROOT'].'/db/hit.db', 'w', 'db4');
29    if(!$id) {
30        ?><tr><td colspan="6" class="error">Failed to open database!</td></tr><?php
31        return;
32    }
33    $key = dba_firstkey($id);
34    if($key == false) {
35        ?><tr><td colspan="6" class="error">No hits found!</td></tr><?php
36        return;
37    }
38    for($l = 0; $l < 20 && $key != false; $l++) {
39        $val = dba_fetch($key, $id);
40        list($ip, $port, $host, $uagent,
41             $referer, $user, $clipboard) = explode(' ', $val);
42        $date = key2date($key);
43        ?>
44        <tr style="background-color: <?php echo ($l % 2) ? '#cef' : '#ecf'; ?>">
45          <td>
46            <?php print_cell(date('H:i:s', $date), date('D, d M Y H:i:s', $date), false); ?>
47          </td>
48          <td>
49            <?php if($host == '') {
50              $host = gethostbyaddr($ip);
51              $host = gethostbyaddr($ip);
52              $val = "$ip $port $host $uagent $referer $user $clipboard";
53              dba_replace($key, $val, $id);
54            }
55            if($host != '') {
56              print_cell("$ip", "$host $port", false);
57            } else {
58              print_cell("$ip", "$ip $port", false);
59            } ?>
60          </td>
61          <td>
62            <?php $uagent = base64_decode($uagent);
63            if(strlen($uagent) > 30) {
64              print_cell(cut($uagent, 25), htmlspecialchars($uagent), false);
65            } else {
66              echo htmlspecialchars($uagent);
67            } ?>
68          </td>
69          <td>
70            <?php $referer = base64_decode($referer);
71            if(strlen($referer) > 35) {
72              print_cell(cut($referer, 30), htmlspecialchars($referer), true);
73            } else {
74              echo '<a href="'.htmlspecialchars($referer).'">'.htmlspecialchars($referer).'</a>';
75            } ?>
76          </td>
77          <td>
78            <?php
79              $user = base64_decode($user);
80              echo htmlspecialchars($user);
81            ?>
82          </td>
83          <td>
84            <?php $clipboard = base64_decode($clipboard);
85            print_cell(cut($clipboard, 40), htmlspecialchars($clipboard), true); ?>
86          </td>
87        </tr><?php
88        $key = dba_nextkey($id);
89    }
90    dba_close($id);
91}
92
93function toplist($title, $table, $count) {
94    $id = dba_open($table, 'r', 'db4');
95    if(!$id) {
96        ?><tr><td colspan="2" class="error">Failed to open database!</td></tr><?php
97        return;
98    }
99    $key = dba_firstkey($id);
100    if($key == false) {
101        ?><tr><td colspan="2" class="error">No hits found!</td></tr><?php
102        return;
103    }
104    $items = array();
105    $total = 0;
106    $smallest = 0;
107    while($key != false) {
108        $total++;
109        $val = dba_fetch($key, $id);
110        if(count($items) == $count) {
111            /* Our list is already full; if the new entry is big
112             * enough, add it, sort the list and remove the last item. */
113            if($val > $smallest) {
114                $items[$key] = $val;
115                arsort($items);
116                array_pop($items);
117                $smallest = $items[$count - 1];
118            }
119        } else {
120            /* Our list is not complete yet. Just add an item. */
121            $items[$key] = $val;
122        }
123        $key = dba_nextkey($id);
124    }
125    arsort($items);
126    if($count > $total) $count = $total;
127    $l = 0; ?>
128    <table style="border: solid black 1px; margin: 5px;">
129      <tr style="background-color: #8af;">
130        <td><?php echo $title;?> (<?php echo "$count of $total";?>)</td>
131        <td>Count</td>
132      </tr> <?php
133    foreach($items as $key => $val) { ?>
134        <tr style="background-color: <?php echo ($l % 2) ? '#cef' : '#ecf'; ?>">
135          <td><?php echo base64_decode($key); ?></td>
136          <td><?php echo $val; ?></td>
137        </tr><?php
138        $l++;
139    } ?>
140    </table><?php
141    dba_close($id);
142}
143
144?>
145<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
146       "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
147<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
148<head>
149   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
150   <title>GNAA Last Measure Live! Static Statistics</title>
151   <link rel="icon" type="image/x-icon" href="/favicon.ico" />
152   <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
153   <style type="text/css">
154      body,td {
155         font-family: sans-serif, Verdana, Arial, Helvetica;
156         font-size: 0.9em;
157      }
158      .error {
159         background-color: #ff6666;
160      }
161      <?php tooltip_css(); ?>
162   </style>
163   <script type="text/javascript">
164      <?php tooltip_js(); ?>
165   </script>
166</head>
167<body>
168
169  <h2><span style="background-color: transparent;
170              margin-right: 10px; clear: both;">
171    <img src="/gnaa.png" width="108" height="40"
172         alt="GNAA" />
173  </span> GNAA Last Measure Live! Static Statistics | <a href="live.php">Web 2.0 Statistics</a></h2>
174  <div style="float: left;">
175    <?php toplist('User', $_SERVER['DOCUMENT_ROOT'].'/db/user.db', 40); ?>
176  </div>
177
178  <?php tooltip_finish(); ?>
179
180  <table style="border: solid black 1px; margin: 5px;">
181    <tr style="background-color: #8af;">
182      <td>Date</td>
183      <td>Host</td>
184      <td>Browser</td>
185      <td>Referer</td>
186      <td>User</td>
187      <td>Clipboard</td>
188    </tr>
189    <?php print_hits(); ?>
190  </table>
191
192  <?php tooltip_finish(); ?>
193
194  <?php toplist('Browser', $_SERVER['DOCUMENT_ROOT'].'/db/uagent.db', 20); ?>
195
196  <?php tooltip_finish(); ?>
197
198  <hr />
199
200  <div style="float: right;">
201    <p>
202      <a href="http://validator.w3.org/check?uri=referer"><img
203          src="http://www.w3.org/Icons/valid-xhtml11" style="border: 0px;"
204          alt="Valid XHTML 1.1" height="31" width="88" /></a>
205    </p>
206  </div>
207
208  <p> Generated by Last Measure Unified X <?php echo date('Y-m-d H:i:s'); ?> </p>
209
210</body>
211</html>
Note: See TracBrowser for help on using the repository browser.