X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcmap%2Fsilcmap_html.c;h=cb3c475cbc875b38219d285202ba84f471212799;hb=ed46e908363484cad4403d6828aec342b4b82c10;hp=d1382f17c77f3804595d114c0b2eb5192c01c318;hpb=e50736c068acc8ffe6768b4255894fe9e9399005;p=silc.git diff --git a/apps/silcmap/silcmap_html.c b/apps/silcmap/silcmap_html.c index d1382f17..cb3c475c 100644 --- a/apps/silcmap/silcmap_html.c +++ b/apps/silcmap/silcmap_html.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2003 Pekka Riikonen + Copyright (C) 2003 - 2004 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) /* Write the HTML page */ - fprintf(fp, "\n"); + fprintf(fp, "\n"); fprintf(fp, "


\n"); /* General stuff */ @@ -108,7 +108,7 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) fprintf(fp, "Algorithm : %s\n", public_key->name); if (key_len) { fprintf(fp, "  "); - fprintf(fp, "Key length (bits) : %d\n", (unsigned int)key_len); + fprintf(fp, "Key length : %d bits\n", (unsigned int)key_len); } if (ident->realname) { fprintf(fp, "  "); @@ -135,9 +135,9 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) fprintf(fp, "Country : %s\n", ident->country); } fprintf(fp, "  "); - fprintf(fp, "Fingerprint (SHA1) : %s\n", fingerprint); + fprintf(fp, "Fingerprint : %s\n", fingerprint); fprintf(fp, "  "); - fprintf(fp, "Babbleprint (SHA1) : %s\n", babbleprint); + fprintf(fp, "Babbleprint : %s\n", babbleprint); fprintf(fp, "\n"); pd = fopen(mapconn->public_key, "r"); @@ -153,7 +153,8 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) fprintf(fp, "
\n"); begin = 0; - while (silc_gets(line, sizeof(line) - 1, pdd, pk_len + 1, &begin) != EOF) + while ((begin = silc_gets(line, sizeof(line) - 1, pdd, pk_len + 1, + begin)) != EOF) fprintf(fp, "%s
\n", line); fprintf(fp, "

\n"); @@ -215,80 +216,80 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn) if (mapconn->clients) { fprintf(fp, "  "); fprintf(fp, "Local clients : %ld\n", - mapconn->data.clients); + (unsigned long)mapconn->data.clients); } if (mapconn->channels) { fprintf(fp, "  "); fprintf(fp, "Local channels : %ld\n", - mapconn->data.channels); + (unsigned long)mapconn->data.channels); } if (mapconn->server_ops) { fprintf(fp, "  "); fprintf(fp, "Local server operators : %ld\n", - mapconn->data.server_ops); + (unsigned long)mapconn->data.server_ops); } if (mapconn->router_ops) { fprintf(fp, "  "); fprintf(fp, "Local router operators : %ld\n", - mapconn->data.router_ops); + (unsigned long)mapconn->data.router_ops); } if (mapconn->cell_clients) { fprintf(fp, "  "); fprintf(fp, "Cell clients : %ld\n", - mapconn->data.cell_clients); + (unsigned long)mapconn->data.cell_clients); } if (mapconn->cell_channels) { fprintf(fp, "  "); fprintf(fp, "Cell channels : %ld\n", - mapconn->data.cell_channels); + (unsigned long)mapconn->data.cell_channels); } if (mapconn->cell_servers) { fprintf(fp, "  "); fprintf(fp, "Cell servers : %ld\n", - mapconn->data.cell_servers); + (unsigned long)mapconn->data.cell_servers); } if (mapconn->all_clients) { fprintf(fp, "  "); fprintf(fp, "All SILC clients : %ld\n", - mapconn->data.all_clients); + (unsigned long)mapconn->data.all_clients); } if (mapconn->all_channels) { fprintf(fp, "  "); fprintf(fp, "All SILC channels : %ld\n", - mapconn->data.all_channels); + (unsigned long)mapconn->data.all_channels); } if (mapconn->all_servers) { fprintf(fp, "  "); fprintf(fp, "All SILC servers : %ld\n", - mapconn->data.all_servers); + (unsigned long)mapconn->data.all_servers); } if (mapconn->all_routers) { fprintf(fp, "  "); fprintf(fp, "All SILC routers : %ld\n", - mapconn->data.all_routers); + (unsigned long)mapconn->data.all_routers); } if (mapconn->all_server_ops) { fprintf(fp, "  "); fprintf(fp, "All SILC server operators : %ld\n", - mapconn->data.all_server_ops); + (unsigned long)mapconn->data.all_server_ops); } if (mapconn->all_router_ops) { fprintf(fp, "  "); fprintf(fp, "All SILC router operators : %ld\n", - mapconn->data.all_router_ops); + (unsigned long)mapconn->data.all_router_ops); } fprintf(fp, "\n"); } /* motd */ - if (mapconn->motd) { + if (mapconn->motd && mapconn->data.motd) { fprintf(fp, " 


\n"); fprintf(fp, "Message of the Day: 
\n"); fprintf(fp, "
\n"); begin = 0; - while (silc_gets(line, sizeof(line) - 1, mapconn->data.motd, - strlen(mapconn->data.motd), &begin) != EOF) + while ((begin = silc_gets(line, sizeof(line) - 1, mapconn->data.motd, + strlen(mapconn->data.motd), begin)) != EOF) fprintf(fp, "%s
\n", line); fprintf(fp, "
\n"); } @@ -317,7 +318,7 @@ bool silc_map_writehtml_index(SilcMap map) /* Produce a simple HTML index file of all servers */ class = map->writehtml.text ? map->writehtml.text : "silcmap"; - fprintf(fp, "\n"); + fprintf(fp, "\n"); fprintf(fp, "
\n"); fprintf(fp, "\n", class); @@ -366,94 +367,217 @@ bool silc_map_writehtml_index(SilcMap map) bool silc_map_writemaphtml(SilcMap map) { SilcMapConnection mapconn; - SilcMapCommand cmd; + SilcMapCommand cmd, c; char *hostname, url[256]; FILE *fp; - int xx , yy, w, h; + int i, xx , yy, w, h; - /* Open for writing */ - fp = fopen(map->writemaphtml.filename, "w+"); - if (!fp) { - fprintf(stderr, "Could not open file '%s'\n", map->writemaphtml.filename); - return FALSE; - } - - /* The target may be portion of the original map, so we must make the - new coordinates relative to the new map. */ - xx = map->writemaphtml.x; - yy = map->writemaphtml.y; + for (i = 0; i < map->writemaphtml_count; i++) { + c = &map->writemaphtml[i]; + if (c->alon && c->alat) { + c->x = silc_map_lon2x(map, c->alon); + c->y = silc_map_lat2y(map, c->alat); + } - memset(url, 0, sizeof(url)); + /* Open for writing */ + fp = fopen(c->filename, "w+"); + if (!fp) { + fprintf(stderr, "Could not open file '%s'\n", c->filename); + return FALSE; + } - fprintf(fp, "\n"); - fprintf(fp, "
\n"); - fprintf(fp, "\n", - map->writemaphtml.text); - fprintf(fp, "\n"); + /* The target may be portion of the original map, so we must make the + new coordinates relative to the new map. */ + xx = c->x; + yy = c->y; - silc_dlist_start(map->conns); - while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { memset(url, 0, sizeof(url)); - if (mapconn->html_url && mapconn->html_url[0]) { - silc_strncat(url, sizeof(url), mapconn->html_url, - strlen(mapconn->html_url)); - } else { - silc_dlist_start(mapconn->hostnames); - hostname = silc_dlist_get(mapconn->hostnames); - snprintf(url, sizeof(url) - 1, "%s_%d.html", hostname, mapconn->port); - } - /* Print the positions of various items on the map into the map file */ - silc_dlist_start(mapconn->commands); - while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) { - if (cmd->draw_text) { - w = strlen(cmd->text) * 5; - h = map->font.height - 2; - fprintf(fp, - "\n", - (int)(cmd->x - xx), (int)(cmd->y - yy), w, h, url); + fprintf(fp, "\n"); + fprintf(fp, "\n", + c->text); + fprintf(fp, "\n"); + + silc_dlist_start(map->conns); + while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { + memset(url, 0, sizeof(url)); + if (mapconn->html_url && mapconn->html_url[0]) { + silc_strncat(url, sizeof(url), mapconn->html_url, + strlen(mapconn->html_url)); + } else { + silc_dlist_start(mapconn->hostnames); + hostname = silc_dlist_get(mapconn->hostnames); + snprintf(url, sizeof(url) - 1, "%s_%d.html", hostname, mapconn->port); } - if (cmd->draw_circle) { - w = 4; - fprintf(fp, - "\n", - (int)(cmd->x - xx), (int)(cmd->y - yy), w, url); - if (cmd->text) { + /* Print the positions of various items on the map into the map file */ + silc_dlist_start(mapconn->commands); + while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) { + if (cmd->alon && cmd->alat) { + cmd->x = silc_map_lon2x(map, cmd->alon); + cmd->y = silc_map_lat2y(map, cmd->alat); + } + + if (cmd->draw_text) { w = strlen(cmd->text) * 5; h = map->font.height - 2; fprintf(fp, "\n", - (int)(cmd->x - xx + cmd->lposx), - (int)(cmd->y - yy - cmd->lposy), - (int)(cmd->x - xx + cmd->lposx + w), - (int)(cmd->y - yy - cmd->lposy + h), url); + (int)(cmd->x - xx), (int)(cmd->y - yy), w, h, url); } - } - if (cmd->draw_rectangle) { - w = 7; - h = 6; - fprintf(fp, - "\n", - (int)(cmd->x - xx), (int)(cmd->y - yy), - (int)(cmd->x - xx + w), (int)(cmd->y - yy + h), url); - if (cmd->text) { - w = strlen(cmd->text) * 5; - h = map->font.height - 2; + if (cmd->draw_circle) { + w = 4; + fprintf(fp, + "\n", + (int)(cmd->x - xx), (int)(cmd->y - yy), w, url); + if (cmd->text) { + w = strlen(cmd->text) * 5; + h = map->font.height - 2; + fprintf(fp, + "\n", + (int)(cmd->x - xx + cmd->lposx), + (int)(cmd->y - yy - cmd->lposy), + (int)(cmd->x - xx + cmd->lposx + w), + (int)(cmd->y - yy - cmd->lposy + h), url); + } + } + + if (cmd->draw_rectangle) { + w = 7; + h = 6; fprintf(fp, "\n", - (int)(cmd->x - xx + cmd->lposx), - (int)(cmd->y - yy - cmd->lposy), - (int)(cmd->x - xx + cmd->lposx + w), - (int)(cmd->y - yy - cmd->lposy + h), url); + (int)(cmd->x - xx), (int)(cmd->y - yy), + (int)(cmd->x - xx + w), (int)(cmd->y - yy + h), url); + if (cmd->text) { + w = strlen(cmd->text) * 5; + h = map->font.height - 2; + fprintf(fp, + "\n", + (int)(cmd->x - xx + cmd->lposx), + (int)(cmd->y - yy - cmd->lposy), + (int)(cmd->x - xx + cmd->lposx + w), + (int)(cmd->y - yy - cmd->lposy + h), url); + } } } } + + fprintf(fp, "\n"); + fclose(fp); } - fprintf(fp, "\n"); + return TRUE; +} + +/* Writes the server uptime reliablity data file. */ + +bool silc_map_writerel(SilcMap map, SilcMapConnection mapconn) +{ + FILE *fp; + int try = 0, success = 0; + char f[256], *hostname; + + /* Generate data filename */ + memset(f, 0, sizeof(f)); + silc_dlist_start(mapconn->hostnames); + hostname = silc_dlist_get(mapconn->hostnames); + snprintf(f, sizeof(f) - 1, "%s_%d.rel", hostname, mapconn->port); + + /* Read the current data */ + fp = fopen(f, "r"); + if (fp) { + fscanf(fp, "%d:%d", &try, &success); + fclose(fp); + } + + /* Update the data */ + try++; + success = (mapconn->down == FALSE ? success + 1 : success); + + /* Write the data file */ + fp = fopen(f, "w+"); + if (!fp) { + fprintf(stderr, "Could not open file '%s'\n", map->writerel.filename); + return FALSE; + } + fprintf(fp, "%d:%d", try, success); + fclose(fp); + return TRUE; +} + +/* Writes the servers' uptime reliability graph as HTML page. */ + +bool silc_map_writerelhtml(SilcMap map) +{ + SilcMapConnection mapconn; + char *hostname, *class; + FILE *fp, *dp; + + /* Open for writing */ + fp = fopen(map->writerel.filename, "w+"); + if (!fp) { + fprintf(stderr, "Could not open file '%s'\n", map->writerel.filename); + return FALSE; + } + + /* Produce the reliability graph as HTML file. */ + class = map->writerel.text ? map->writerel.text : "silcmap"; + + fprintf(fp, "\n"); + fprintf(fp, "
\n"); + fprintf(fp, "
\n", class); + fprintf(fp, + "\n" + "\n" + "\n" + "\n", class, class); + + silc_dlist_start(map->conns); + while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { + char f[256]; + int try = 0, success = 0; + double rel = 0; + + silc_dlist_start(mapconn->hostnames); + hostname = silc_dlist_get(mapconn->hostnames); + + /* Get the data */ + memset(f, 0, sizeof(f)); + snprintf(f, sizeof(f) - 1, "%s_%d.rel", hostname, mapconn->port); + dp = fopen(f, "r"); + if (dp) { + fscanf(dp, "%d:%d", &try, &success); + fclose(dp); + } + + /* Count the reliability */ + if (try) + rel = ((double)success / (double)try) * (double)160.0; + + fprintf(fp, "\n"); + if (mapconn->html_url) + fprintf(fp, + "\n", class, mapconn->html_url, hostname); + else + fprintf(fp, + "\n", class, hostname, mapconn->port, hostname); + fprintf(fp, + "\n" + "\n" + "\n", + class, class, rel, 160 - rel, class, + ((double)success / (double)try) * (double)100.0, success); + } + + fprintf(fp, "
ServerReliability
 %s %s" + "" + "" + "" + "
%.2f%% - score: %d

\n"); return TRUE; }