2
* Copyright (C) 2001 Luca Deri <deri@ntop.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include "globals-report.h"
25
static int wapColumnSort = 0;
27
/* ****************************** */
29
void printWMLheader(void) {
30
sendHTTPHeader(HTTP_TYPE_NONE, HTTP_FLAG_NO_CACHE_CONTROL | HTTP_FLAG_MORE_FIELDS);
31
sendString("Content-Type: text/vnd.wap.wml;charset=UTF-8\n\n");
34
/* ********************** */
36
static void printWmlNotFoundError(void) {
40
/* ********************** */
42
static void printWmlNoDataYet(void) {
46
/* ********************** */
48
static int cmpWapFctn(const void *_a, const void *_b) {
49
HostTraffic **a = (HostTraffic **)_a;
50
HostTraffic **b = (HostTraffic **)_b;
51
TrafficCounter a_, b_;
53
if((a == NULL) && (b != NULL)) {
54
traceEvent(TRACE_WARNING, "WARNING (1)\n");
56
} else if((a != NULL) && (b == NULL)) {
57
traceEvent(TRACE_WARNING, "WARNING (2)\n");
59
} else if((a == NULL) && (b == NULL)) {
60
traceEvent(TRACE_WARNING, "WARNING (3)\n");
64
if(wapColumnSort == 0) {
70
a_ = (*a)->bytesReceived;
71
b_ = (*b)->bytesReceived;
82
/* ********************** */
84
static void printWmlIndex(void) {
86
u_int idx, numEntries=0;
88
HostTraffic* tmpTable[HASHNAMESIZE];
89
char *tmpName, buf[BUF_SIZE];
90
TrafficCounter unicastPkts=0;
94
for(idx=1; idx<device[actualDeviceId].actualHashSize; idx++)
95
if(((el = device[actualDeviceId].hash_hostTraffic[idx]) != NULL)
96
&& (!broadcastHost(el)))
97
tmpTable[numEntries++]=el;
104
sendString("<?xml version=\"1.0\"?>\n");
105
sendString("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http:///www.wapforum.org/DTD/wml_1.1.xml\">\n\n");
106
sendString("<wml>\n");
107
sendString(" <card id=\"home\" title=\"ntop for Wap\">\n");
108
sendString(" <p>\n");
109
sendString(" <a href=\"#senders\">Top Senders</a><br/>\n");
110
sendString(" <a href=\"#receivers\">Top Receivers</a><br/>\n");
111
sendString(" <a href=\"#stats\">Stats</a><br/>\n");
112
sendString(" </p>\n");
113
sendString(" </card>\n");
114
sendString(" <card id=\"senders\" title=\"Top Senders\"> \n");
115
sendString(" <p>\n");
116
sendString(" <table columns=\"2\" align=\"LCC\">\n");
117
sendString(" <tr><td><b>Host</b></td><td><b>Total</b></td></tr>\n");
121
quicksort(tmpTable, numEntries, sizeof(HostTraffic*), cmpWapFctn);
123
for(idx=0; idx<numEntries; idx++) {
127
tmpName = getHostName(el, 0);
129
if((strcmp(tmpName, "0.0.0.0") == 0) || (tmpName[0] == '\0'))
130
tmpName = el->ethAddressString;
132
if(snprintf(buf, sizeof(buf),
133
"<tr><td><a href=\"/ntop/host.wml?%s\">%s</a></td>"
134
"<td>%s</td></tr>\n",
136
formatBytes(el->bytesSent, 1)) < 0)
137
traceEvent(TRACE_ERROR, "Buffer overflow!");
141
sendString("</table>\n");
142
sendString(" <a href=\"#home\">[Back Home]</a><br/>\n");
143
sendString(" </p>\n");
144
sendString(" </card>\n");
145
sendString(" <card id=\"receivers\" title=\"Top Receivers\">\n");
146
sendString(" <p>\n");
147
sendString(" <table columns=\"2\" align=\"LCC\">\n");
148
sendString(" <tr><td><b>Host</b></td><td><b>Total</b></td></tr>\n");
152
quicksort(tmpTable, numEntries, sizeof(HostTraffic*), cmpFctn);
154
for(idx=0; idx<numEntries; idx++) {
158
tmpName = getHostName(el, 0);
160
if((strcmp(tmpName, "0.0.0.0") == 0) || (tmpName[0] == '\0'))
161
tmpName = el->ethAddressString;
163
if(snprintf(buf, sizeof(buf),
164
"<tr><td><a href=\"/ntop/host.wml?%s\">%s</a></td>"
165
"<td>%s</td></tr>\n",
167
formatBytes(el->bytesReceived, 1)) < 0)
168
traceEvent(TRACE_ERROR, "Buffer overflow!");
172
sendString("</table>\n");
173
sendString(" <a href=\"#home\">[Back Home]</a><br/>\n");
174
sendString(" </p>\n");
175
sendString(" </card>\n");
176
/* ************************* */
178
sendString(" <card id=\"stats\" title=\"Traffic Stats\">\n");
179
sendString(" <p>\n");
180
sendString(" <table columns=\"2\" align=\"LCC\">\n");
184
if(snprintf(buf, sizeof(buf),"<tr><td>Sampling Time</td>"
185
"<td>%s</td></tr>\n",
186
formatSeconds(actTime-initialSniffTime)) < 0)
187
traceEvent(TRACE_ERROR, "Buffer overflow!");
192
diff = (int)(device[actualDeviceId].ethernetPkts -
193
device[actualDeviceId].broadcastPkts -
194
device[actualDeviceId].multicastPkts);
196
unicastPkts = 0; /* It shouldn't happen */
198
unicastPkts = (TrafficCounter)diff;
200
if(device[actualDeviceId].ethernetPkts <= 0) device[actualDeviceId].ethernetPkts = 1;
202
if(snprintf(buf, sizeof(buf),"<tr><td>Total</td><td>%s</td></tr>\n",
203
formatPkts(device[actualDeviceId].ethernetPkts)) < 0)
204
traceEvent(TRACE_ERROR, "Buffer overflow!");
207
if(snprintf(buf, sizeof(buf),"<tr><td>Unicast</td>"
208
"<td>%s [%.1f%%]</td></tr>\n",
209
formatPkts(unicastPkts),
210
(float)(100*unicastPkts)/(float)device[actualDeviceId].ethernetPkts) < 0)
211
traceEvent(TRACE_ERROR, "Buffer overflow!");
213
if(snprintf(buf, sizeof(buf),"<tr><td>Broadcast</td>"
214
"<td>%s [%.1f%%]</td></tr>\n",
215
formatPkts(device[actualDeviceId].broadcastPkts),
216
(float)(100*device[actualDeviceId].broadcastPkts)
217
/(float)device[actualDeviceId].ethernetPkts) < 0)
218
traceEvent(TRACE_ERROR, "Buffer overflow!");
221
if(device[actualDeviceId].multicastPkts > 0) {
222
if(snprintf(buf, sizeof(buf),"<tr><td>Multicast</td>"
223
"<td>%s [%.1f%%]</td></tr>\n",
224
formatPkts(device[actualDeviceId].multicastPkts),
225
(float)(100*device[actualDeviceId].multicastPkts)
226
/(float)device[actualDeviceId].ethernetPkts) < 0)
227
traceEvent(TRACE_ERROR, "Buffer overflow!");
232
sendString("</table>\n");
233
sendString(" <a href=\"#home\">[Back Home]</a><br/>\n");
234
sendString(" </p>\n");
235
sendString(" </card>\n");
237
/* ************************* */
239
sendString("</wml>\n");
242
/* ********************** */
244
static void printWmlHostInfo(char *host _UNUSED_) {
248
/* ********************** */
250
static void handleWAPrequest(char* url) {
254
|| (strncmp(url, "index.wml",
255
strlen("index.wml")) == 0)) {
257
} else if(strncmp(url, "host.wml", strlen("host.wml")) == 0)
258
printWmlHostInfo(&url[strlen("host.wml")+1]);
260
printWmlNotFoundError();
263
/* ****************************** */
265
static void termWapFunct(void) {
266
traceEvent(TRACE_INFO, "Thanks for using wapWatch...\n");
267
traceEvent(TRACE_INFO, "Done.\n");
270
#endif /* MICRO_NTOP */
272
/* ****************************** */
274
static PluginInfo WAPPluginInfo[] = {
276
"ntop WAP (Wireless Application protocol) Interface",
278
"<A HREF=http://luca.ntop.org/>L.Deri</A>",
279
"WAPPlugin", /* http://<host>:<port>/plugins/WAPPlugin */
281
NULL, /* no special startup after init */
283
termWapFunct, /* TermFunc */
287
NULL, /* PluginFunc */
294
NULL /* BPF Filter */
298
/* Plugin entry fctn */
300
PluginInfo* wapPluginEntryFctn(void) {
302
PluginInfo* PluginEntryFctn(void) {
304
traceEvent(TRACE_INFO, "Welcome to %s. (C) 2000 by Luca Deri.\n",
305
WAPPluginInfo->pluginName);
307
return(WAPPluginInfo);