HTML comment fixes
[crypto.git] / apps / silcmap / silcmap_html.c
index 975e9bd07eee7756420b5df23da6adb9bed08d5d..f6c56aef9139859c19e3da4a4e69d463e24c5789 100644 (file)
@@ -46,7 +46,7 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn)
 
   /* Write the HTML page */
 
-  fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
+  fprintf(fp, "<!-- Automatically generated by silcmap -->\n");
   fprintf(fp, "<br /><hr ><br />\n");
 
   /* General stuff */
@@ -108,7 +108,7 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn)
     fprintf(fp, "Algorithm</td><td>&nbsp;:</td><td>&nbsp;%s</td></tr>\n", public_key->name);
     if (key_len) {
       fprintf(fp, "<tr><td>&nbsp;&nbsp;");
-      fprintf(fp, "Key length (bits)</td><td>&nbsp;:</td><td>&nbsp;%d</td></tr>\n", (unsigned int)key_len);
+      fprintf(fp, "Key length</td><td>&nbsp;:</td><td>&nbsp;%d bits</td></tr>\n", (unsigned int)key_len);
     }
     if (ident->realname) {
       fprintf(fp, "<tr><td>&nbsp;&nbsp;");
@@ -135,9 +135,9 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn)
       fprintf(fp, "Country</td><td>&nbsp;:</td><td>&nbsp;%s</td></tr>\n", ident->country);
     }
     fprintf(fp, "<tr><td>&nbsp;&nbsp;");
-    fprintf(fp, "Fingerprint (SHA1)</td><td>&nbsp;:</td><td>&nbsp;<small>%s</small></td></tr>\n", fingerprint);
+    fprintf(fp, "Fingerprint</td><td>&nbsp;:</td><td>&nbsp;<tt>%s</tt></td></tr>\n", fingerprint);
     fprintf(fp, "<tr><td>&nbsp;&nbsp;");
-    fprintf(fp, "Babbleprint (SHA1)</td><td>&nbsp;:</td><td>&nbsp;<small>%s</small></td></tr>\n", babbleprint);
+    fprintf(fp, "Babbleprint</td><td>&nbsp;:</td><td>&nbsp;<tt>%s</tt></td></tr>\n", babbleprint);
     fprintf(fp, "</table>\n");
 
     pd = fopen(mapconn->public_key, "r");
@@ -281,7 +281,7 @@ bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn)
   }
 
   /* motd */
-  if (mapconn->motd) {
+  if (mapconn->motd && mapconn->data.motd) {
     fprintf(fp, "&nbsp;<br /><hr ><br />\n");
     fprintf(fp, "<b>Message of the Day:</b>&nbsp;<br />\n");
 
@@ -317,7 +317,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, "<!-- Automatically generated by silcmap --!>\n");
+  fprintf(fp, "<!-- Automatically generated by silcmap -->\n");
   fprintf(fp, "<br />\n");
   fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" "
          "class=\"%s\" border=\"0\">\n", class);
@@ -388,7 +388,7 @@ bool silc_map_writemaphtml(SilcMap map)
 
     memset(url, 0, sizeof(url));
 
-    fprintf(fp, "<!-- Automatically generated by silcmap --!>\n");
+    fprintf(fp, "<!-- Automatically generated by silcmap -->\n");
     fprintf(fp, "<img src=\"%s\" usemap=\"#map\" class=\"silcmap\">\n",
            c->text);
     fprintf(fp, "<map name=\"map\">\n");
@@ -460,3 +460,114 @@ bool silc_map_writemaphtml(SilcMap map)
 
   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, "<!-- Automatically generated by silcmap -->\n");
+  fprintf(fp, "<br />\n");
+  fprintf(fp, "<table cellspacing=\"0\" cellpadding=\"0\" "
+         "class=\"%s\" border=\"0\">\n", class);
+  fprintf(fp,
+         "<tr>\n"
+         "<td align=\"center\" class=\"%s_header\"><b>Server</b></td>\n"
+         "<td colspan=\"2\" align=\"center\" class=\"%s_header\"><b>Reliability</b></td>\n"
+         "</tr>\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, "<tr>\n");
+    if (mapconn->html_url)
+      fprintf(fp,
+             "<td align = \"center\" class=\"%s\">&nbsp;<a href=\"%s\">%s</a></td>\n", class, mapconn->html_url, hostname);
+    else
+      fprintf(fp,
+             "<td align = \"center\" class=\"%s\">&nbsp;<a href=\"%s_%d.html\">%s</a></td>\n", class, hostname, mapconn->port, hostname);
+    fprintf(fp,
+           "<td class=\"%s\" width=\"160\">"
+           "<table style=\"border: solid 1px black; width: 160px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"%s\"><tr>"
+           "<td style=\"width: %fpx; height: 10px;\" bgcolor=\"gray\"></td>"
+           "<td style=\"width: %fpx; height: 10px;\" bgcolor=\"white\"></td>"
+           "</tr></table></td>\n"
+           "<td class=\"%s\">%.2f%% - score: %d</td>\n"
+           "</tr>\n",
+           class, class, rel, 160 - rel, class,
+           ((double)success / (double)try) * (double)100.0, success);
+  }
+
+  fprintf(fp, "</table><br />\n");
+
+  return TRUE;
+}