5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2003 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #include "silcincludes.h"
21 #include "silcclient.h"
24 /* Write the HTML data file of the gathered data from the connection. */
26 bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn)
32 /* Generate data filename. First configure hostname is the filename */
33 silc_dlist_start(mapconn->hostnames);
34 hostname = silc_dlist_get(mapconn->hostnames);
35 memset(filename, 0, sizeof(filename));
36 snprintf(filename, sizeof(filename) - 1, "%s_%d.html", hostname,
39 /* Open for writing */
40 fp = fopen(filename, "w+");
42 fprintf(stderr, "Could not open file '%s'\n", filename);
46 /* Write the HTML page */
48 fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
49 fprintf(fp, "<br /><hr ><br />\n");
53 fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
54 silc_dlist_start(mapconn->hostnames);
55 while ((hostname = silc_dlist_get(mapconn->hostnames)) != SILC_LIST_END)
56 fprintf(fp, "<tr><td><b>Hostname</b></td><td> :</td><td> %s</td></tr>\n", hostname);
58 silc_dlist_start(mapconn->ips);
59 while ((hostname = silc_dlist_get(mapconn->ips)) != SILC_LIST_END)
60 fprintf(fp, "<tr><td><b>IP</b></td><td> :</td><td> %s</td></tr>\n", hostname);
62 fprintf(fp, "<tr><td><b>Port</b></td><td> :</td><td> %d</td></tr>\n", mapconn->port);
63 fprintf(fp, "<tr><td><b>Country</b></td><td> :</td><td> %s</td></tr>\n", mapconn->country);
64 fprintf(fp, "<tr><td><b>City</b></td><td> :</td><td> %s</td></tr>\n", mapconn->city);
65 fprintf(fp, "<tr><td><b>Admin</b></td><td> :</td><td> %s</td></tr>\n", mapconn->admin);
66 fprintf(fp, "</table>\n");
69 if (mapconn->public_key) {
70 SilcPublicKey public_key;
71 SilcPublicKeyIdentifier ident;
72 char *fingerprint, *babbleprint;
76 SilcUInt32 key_len = 0;
80 fprintf(fp, " <br /><hr ><br />\n");
81 fprintf(fp, "<b>Public Key:</b> <br />\n");
82 fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
84 if (silc_pkcs_load_public_key(mapconn->public_key, &public_key,
85 SILC_PKCS_FILE_PEM) == FALSE)
86 if (silc_pkcs_load_public_key(mapconn->public_key, &public_key,
87 SILC_PKCS_FILE_BIN) == FALSE) {
88 fprintf(stderr, "Could not load public key file `%s'\n",
93 ident = silc_pkcs_decode_identifier(public_key->identifier);
94 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
95 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
96 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
98 if (silc_pkcs_alloc(public_key->name, &pkcs)) {
99 key_len = silc_pkcs_public_key_set(pkcs, public_key);
100 silc_pkcs_free(pkcs);
103 fprintf(fp, "<tr><td> ");
104 fprintf(fp, "Public key file</td><td> :</td><td> <a href=\"%s\">%s</a></td></tr>\n",
105 mapconn->public_key, mapconn->public_key);
106 fprintf(fp, "<tr><td> ");
107 fprintf(fp, "Algorithm</td><td> :</td><td> %s</td></tr>\n", public_key->name);
109 fprintf(fp, "<tr><td> ");
110 fprintf(fp, "Key length (bits)</td><td> :</td><td> %d</td></tr>\n", (unsigned int)key_len);
112 if (ident->realname) {
113 fprintf(fp, "<tr><td> ");
114 fprintf(fp, "Real name</td><td> :</td><td> %s</td></tr>\n", ident->realname);
116 if (ident->username) {
117 fprintf(fp, "<tr><td> ");
118 fprintf(fp, "Username</td><td> :</td><td> %s</td></tr>\n", ident->username);
121 fprintf(fp, "<tr><td> ");
122 fprintf(fp, "Hostname</td><td> :</td><td> %s</td></tr>\n", ident->host);
125 fprintf(fp, "<tr><td> ");
126 fprintf(fp, "Email</td><td> :</td><td> %s</td></tr>\n", ident->email);
129 fprintf(fp, "<tr><td> ");
130 fprintf(fp, "Organization</td><td> :</td><td> %s</td></tr>\n", ident->org);
132 if (ident->country) {
133 fprintf(fp, "<tr><td> ");
134 fprintf(fp, "Country</td><td> :</td><td> %s</td></tr>\n", ident->country);
136 fprintf(fp, "<tr><td> ");
137 fprintf(fp, "Fingerprint (SHA1)</td><td> :</td><td> %s</td></tr>\n", fingerprint);
138 fprintf(fp, "<tr><td> ");
139 fprintf(fp, "Babbleprint (SHA1)</td><td> :</td><td> %s</td></tr>\n", babbleprint);
140 fprintf(fp, "</table>\n");
142 pd = fopen(mapconn->public_key, "r");
146 pk_len = silc_file_size(mapconn->public_key);
147 pdd = silc_calloc(pk_len + 1, sizeof(*pdd));
150 fread(pdd, pk_len, 1, pd);
152 fprintf(fp, "<pre><tt>\n");
153 fprintf(fp, "%s", pdd);
154 fprintf(fp, "</tt></pre>\n");
158 silc_free(fingerprint);
159 silc_free(babbleprint);
161 silc_pkcs_public_key_free(public_key);
162 silc_pkcs_free_identifier(ident);
166 if (mapconn->description && mapconn->description[0]) {
167 fprintf(fp, "<hr ><br />\n");
168 fprintf(fp, "<b>Description:</b> <br />\n");
169 fprintf(fp, "%s<br /> <br />\n", mapconn->description);
173 if (mapconn->connect) {
174 fprintf(fp, "<hr ><br />\n");
175 fprintf(fp, "<b>Server status:</b> <br />\n");
178 "Server is currently down and unreachable. "
179 "Please try again later to connect the server.<br />\n");
182 "Server is up and running<br />\n");
185 if (mapconn->connect && !mapconn->down) {
186 int days, hours, mins, secs, uptime;
188 uptime = mapconn->data.uptime;
189 days = uptime / (24 * 60 * 60);
190 uptime -= days * (24 * 60 * 60);
191 hours = uptime / (60 * 60);
192 uptime -= hours * (60 * 60);
198 fprintf(fp, "<br />\n");
199 fprintf(fp, "<b>Server statistics:</b> <br />\n");
200 fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
201 if (mapconn->starttime) {
202 fprintf(fp, "<tr><td> ");
203 fprintf(fp, "Server start time</td><td> :</td><td> %s<td></tr>\n",
204 silc_get_time(mapconn->data.starttime));
206 if (mapconn->uptime) {
207 fprintf(fp, "<tr><td> ");
208 fprintf(fp, "Server uptime</td><td> :</td><td> %d days %d hours %d mins %d secs<td></tr>\n",
209 days, hours, mins, secs);
211 if (mapconn->clients) {
212 fprintf(fp, "<tr><td> ");
213 fprintf(fp, "Local clients</td><td> :</td><td> %ld</td></tr>\n",
214 mapconn->data.clients);
216 if (mapconn->channels) {
217 fprintf(fp, "<tr><td> ");
218 fprintf(fp, "Local channels</td><td> :</td><td> %ld</td></tr>\n",
219 mapconn->data.channels);
221 if (mapconn->server_ops) {
222 fprintf(fp, "<tr><td> ");
223 fprintf(fp, "Local server operators</td><td> :</td><td> %ld</td></tr>\n",
224 mapconn->data.server_ops);
226 if (mapconn->router_ops) {
227 fprintf(fp, "<tr><td> ");
228 fprintf(fp, "Local router operators</td><td> :</td><td> %ld</td></tr>\n",
229 mapconn->data.router_ops);
231 if (mapconn->cell_clients) {
232 fprintf(fp, "<tr><td> ");
233 fprintf(fp, "Cell clients</td><td> :</td><td> %ld</td></tr>\n",
234 mapconn->data.cell_clients);
236 if (mapconn->cell_channels) {
237 fprintf(fp, "<tr><td> ");
238 fprintf(fp, "Cell channels</td><td> :</td><td> %ld</td></tr>\n",
239 mapconn->data.cell_channels);
241 if (mapconn->cell_servers) {
242 fprintf(fp, "<tr><td> ");
243 fprintf(fp, "Cell servers</td><td> :</td><td> %ld</td></tr>\n",
244 mapconn->data.cell_servers);
246 if (mapconn->all_clients) {
247 fprintf(fp, "<tr><td> ");
248 fprintf(fp, "All SILC clients</td><td> :</td><td> %ld</td></tr>\n",
249 mapconn->data.all_clients);
251 if (mapconn->all_channels) {
252 fprintf(fp, "<tr><td> ");
253 fprintf(fp, "All SILC channels</td><td> :</td><td> %ld</td></tr>\n",
254 mapconn->data.all_channels);
256 if (mapconn->all_servers) {
257 fprintf(fp, "<tr><td> ");
258 fprintf(fp, "All SILC servers</td><td> :</td><td> %ld</td></tr>\n",
259 mapconn->data.all_servers);
261 if (mapconn->all_routers) {
262 fprintf(fp, "<tr><td> ");
263 fprintf(fp, "All SILC routers</td><td> :</td><td> %ld</td></tr>\n",
264 mapconn->data.all_routers);
266 if (mapconn->all_server_ops) {
267 fprintf(fp, "<tr><td> ");
268 fprintf(fp, "All SILC server operators</td><td> :</td><td> %ld</td></tr>\n",
269 mapconn->data.all_server_ops);
271 if (mapconn->all_router_ops) {
272 fprintf(fp, "<tr><td> ");
273 fprintf(fp, "All SILC router operators</td><td> :</td><td> %ld</td></tr>\n",
274 mapconn->data.all_router_ops);
276 fprintf(fp, "</table>\n");
281 fprintf(fp, " <br /><hr ><br />\n");
282 fprintf(fp, "<b>Message of the Day:</b> <br />\n");
283 fprintf(fp, "<pre><tt>%s</tt><pre>\n", mapconn->data.motd);
286 fprintf(fp, "<br />\n");
292 /* Write the HTML index file that lists all servers. */
294 bool silc_map_writehtml_index(SilcMap map)
296 SilcMapConnection mapconn;
300 /* Open for writing */
301 fp = fopen(map->writehtml.filename, "w+");
303 fprintf(stderr, "Could not open file '%s'\n", map->writehtml.filename);
307 /* Produce a simple HTML index file of all servers */
309 fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
310 fprintf(fp, "<br />\n");
311 fprintf(fp, "<table cellspacing=\"2\" cellpadding=\"2\" border=\"1\">\n");
314 "<td align=\"center\"><b>Hostname</b></td>\n"
315 "<td align=\"center\"><b>IPv4 Address</b></td>\n"
316 "<td align=\"center\"><b>Port</b></td>\n"
317 "<td align=\"center\"><b>Country</b></td>\n"
318 "<td align=\"center\"><b>Oper</b></td>\n"
321 silc_dlist_start(map->conns);
322 while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) {
324 silc_dlist_start(mapconn->hostnames);
325 hostname = silc_dlist_get(mapconn->hostnames);
326 silc_dlist_start(mapconn->ips);
327 ip = silc_dlist_get(mapconn->ips);
331 "<td align = \"center\"> <a href=\"%s_%d.html\">%s</a></td>\n"
332 "<td align = \"center\"> %s</td>\n"
333 "<td align = \"center\"> %d</td>\n"
334 "<td align = \"center\"> %s</td>\n"
335 "<td align = \"center\"> %s</td>\n"
336 "</tr>\n", hostname, mapconn->port,
337 hostname, ip, mapconn->port, mapconn->country, mapconn->admin);
340 fprintf(fp, "</table><br />\n");
345 /* Creates a HTML map file, which can be used to allow user to click
346 URLs on the image at the specified locations. */
348 bool silc_map_writemaphtml(SilcMap map)
350 SilcMapConnection mapconn;
352 char *hostname, url[256];
356 /* Open for writing */
357 fp = fopen(map->writemaphtml.filename, "w+");
359 fprintf(stderr, "Could not open file '%s'\n", map->writemaphtml.filename);
363 /* The target may be portion of the original map, so we must make the
364 new coordinates relative to the new map. */
365 xx = map->writemaphtml.x;
366 yy = map->writemaphtml.y;
368 memset(url, 0, sizeof(url));
370 fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
371 fprintf(fp, "<br />\n");
372 fprintf(fp, "<img src=\"%s\" usemap=\"#map\" border=\"0\">\n",
373 map->writemaphtml.text);
374 fprintf(fp, "<map name=\"map\">\n");
376 memset(url, 0, sizeof(url));
378 silc_dlist_start(map->conns);
379 while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) {
380 if (mapconn->writemaphtml_url && mapconn->writemaphtml_url[0]) {
381 silc_strncat(url, sizeof(url), mapconn->writemaphtml_url,
382 strlen(mapconn->writemaphtml_url));
384 silc_dlist_start(mapconn->hostnames);
385 hostname = silc_dlist_get(mapconn->hostnames);
386 snprintf(url, sizeof(url) - 1, "%s_%d.html", hostname, mapconn->port);
389 /* Print the positions of various items on the map into the map file */
390 silc_dlist_start(mapconn->commands);
391 while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) {
392 if (cmd->draw_text) {
393 w = strlen(cmd->text) * 5;
394 h = map->font.height - 2;
396 "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
397 (int)(cmd->x - xx), (int)(cmd->y - yy), w, h, url);
400 if (cmd->draw_circle) {
403 "<area shape=\"circle\" coords=\"%d,%d,%d\" href=\"%s\">\n",
404 (int)(cmd->x - xx), (int)(cmd->y - yy), w, url);
406 w = strlen(cmd->text) * 5;
407 h = map->font.height - 2;
409 "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
410 (int)(cmd->x - xx + cmd->lposx),
411 (int)(cmd->y - yy - cmd->lposy),
412 (int)(cmd->x - xx + cmd->lposx + w),
413 (int)(cmd->y - yy - cmd->lposy + h), url);
417 if (cmd->draw_rectangle) {
421 "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
422 (int)(cmd->x - xx), (int)(cmd->y - yy),
423 (int)(cmd->x - xx + w), (int)(cmd->y - yy + h), url);
425 w = strlen(cmd->text) * 5;
426 h = map->font.height - 2;
428 "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=\"%s\">\n",
429 (int)(cmd->x - xx + cmd->lposx),
430 (int)(cmd->y - yy - cmd->lposy),
431 (int)(cmd->x - xx + cmd->lposx + w),
432 (int)(cmd->y - yy - cmd->lposy + h), url);
438 fprintf(fp, "</map><br />\n");