From 877103ed3a4e37e20b91d9fb1d952c35204289e6 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 23 Jul 2003 15:00:50 +0000 Subject: [PATCH] Added SILC Map. --- apps/silcmap/Makefile.am | 34 + apps/silcmap/README | 46 ++ apps/silcmap/data.h | 58 ++ apps/silcmap/default.fnt | Bin 0 -> 6844 bytes apps/silcmap/example.server.com_706.pub | 7 + apps/silcmap/silcmap.c | 243 ++++++ apps/silcmap/silcmap.conf | 141 ++++ apps/silcmap/silcmap.h | 206 ++++++ apps/silcmap/silcmap_bitmap.c | 477 ++++++++++++ apps/silcmap/silcmap_client.c | 613 ++++++++++++++++ apps/silcmap/silcmap_command.c | 933 ++++++++++++++++++++++++ apps/silcmap/silcmap_html.c | 442 +++++++++++ configure.in.pre | 1 + 13 files changed, 3201 insertions(+) create mode 100644 apps/silcmap/Makefile.am create mode 100644 apps/silcmap/README create mode 100644 apps/silcmap/data.h create mode 100644 apps/silcmap/default.fnt create mode 100644 apps/silcmap/example.server.com_706.pub create mode 100644 apps/silcmap/silcmap.c create mode 100644 apps/silcmap/silcmap.conf create mode 100644 apps/silcmap/silcmap.h create mode 100644 apps/silcmap/silcmap_bitmap.c create mode 100644 apps/silcmap/silcmap_client.c create mode 100644 apps/silcmap/silcmap_command.c create mode 100644 apps/silcmap/silcmap_html.c diff --git a/apps/silcmap/Makefile.am b/apps/silcmap/Makefile.am new file mode 100644 index 00000000..fee16ac3 --- /dev/null +++ b/apps/silcmap/Makefile.am @@ -0,0 +1,34 @@ +# +# Makefile.am +# +# Author: Pekka Riikonen +# +# Copyright (C) 2003 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 +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign + +bin_PROGRAMS = silcmap + +silcmap_SOURCES = \ + silcmap.c \ + silcmap_bitmap.c \ + silcmap_command.c \ + silcmap_client.c \ + silcmap_html.c + +LIBS = $(SILC_COMMON_LIBS) -lsilcclient -lsilc +LDADD = + +EXTRA_DIST = *.h + +include $(top_srcdir)/Makefile.defines.in diff --git a/apps/silcmap/README b/apps/silcmap/README new file mode 100644 index 00000000..154d7783 --- /dev/null +++ b/apps/silcmap/README @@ -0,0 +1,46 @@ +The SILC Map +============ + +SILC Map is a utility which can be used to visualize the topology of a +SILC network. It can create maps which indicate the exact global position +of the servers and it can create HTML pages out of the information it +gathers from the servers. It is also possible to create a HTML map +page which allows the user to click the servers on the map image to get +more detailed information of the server. The links between the routers +and servers can also be drawn on the map image. + +The HTML pages that SILC Map creates are by default crude looking. This +is intentional feature to allow the user to easily embed the data pages +into existing web site. This can be done for example by using PHP, server +side includes or similar method. + + +SILC Map Config File +==================== + +By default the SILC Map reads the silcmap.conf file. Please read the +example silcmap.conf file to learn all the possible commands and +configuration options you can use to alter the behavior of the SILC Map. + + +Running the SILC Map +==================== + +After you have configured the silcmap.conf file, simply run the ./silcmap +program. It reads the file, the source map image, creates the connections +to SILC servers and producess the target image and HTML pages. After the +map is created the silcmap program exits. If you want to periodically run +the silcmap to generate maps you may create for example an at (see at(1)) +job on your local system. + + +Contact +======= + +Feedback and comments are welcome. Bug reports should be sent to the +SILC development mailing list. + +Official SILC project web site : http://silcnet.org/ +FTP archive for SILC project : ftp://ftp.silcnet.org/ +Development mailing list address : silc-devel@lists.silcnet.org + diff --git a/apps/silcmap/data.h b/apps/silcmap/data.h new file mode 100644 index 00000000..cf0788e2 --- /dev/null +++ b/apps/silcmap/data.h @@ -0,0 +1,58 @@ +/* + + data.h + + Author: Pekka Riikonen + + Copyright (C) 2003 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#ifndef DATA_H +#define DATA_H + +/* Bitmap context */ +typedef struct { + char width; + char height; + unsigned char data[32 * 32]; +} MapBitmap; + +/* Circle */ +const MapBitmap silc_map_circle = +{ + 6, 7, + { 0, 1, 1, 1, 1, 0, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 0, 1, 1, 1, 1, 0 + } +}; + +/* Rectangle */ +const MapBitmap silc_map_rectangle = +{ + 6, 7, + { 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1 + } +}; + +#endif /* DATA_H */ diff --git a/apps/silcmap/default.fnt b/apps/silcmap/default.fnt new file mode 100644 index 0000000000000000000000000000000000000000..cf6afb4ca4b8982f4c8e7c0c120d00368ab2561f GIT binary patch literal 6844 zcmbW63z8c#2t-|3d$%gLN#*`$+tA%0Aqi%@8Qc0Gc(l;?v&o;ozkhu{=Hp@Gc|GSs zHcy9Y^aTdp*?sdeM;X0!V>o`liT`{ca6y@cD%8y+bY$8}q->lYMZ02lIP{Q&V|a-XIj0v!MPzX6%DgVhpIN)`0Z;RHHoV`2h>;3PlP z@|jAi(fIsiE!wlgs?t=DX?y7wiqc|XFL!v%pk?&QREXkp%q&baS=>SN1+Y$D9%a^k zgz~jl2(k)qPb2OR&(gy1g+(dINZg4)8e3$G(dAWt!w|{@O2+o4@J!Rc|5zib$?c`M z=KJqboo^WRIj-a5N;NcBm2CD$s2g;DlC1d?SpR z3S7Z*U2my_lI39&3xug^siJG*uUNz~c~qJca=9S%^y+xozUUiD2)mr_ZJeflCZgiwcBLOsRY?PW$iUpJH!up@|=Kl!)b&%w16#G{;x+eM^nHrShTavK+1s zowh(>z9DTZwJ!U1v#wGdw}TLD8$J$RYjHy{GaVR>C>vx_9(N?#o7$yqLMd|c z6(^gE*s{TuRVgtIaEhD5XRXm3 z2tadQOZib$W$xP(ku57O4o#aW+Z=q37u>w@Cu_{K(g z8Km)oL;gw^_NNvQ?acfQ`ZaD<`(MtlHj06}usJgyf5d9c6YcgyA^^`>r z5m8=?N!3~^^dGp)@-Y+jD6DMipyzxzPGT>4_O{m*5K6FJk9jzxe$jw{?dj$9BBO+& zHdW8}ke@JO@(U+VPEwJE{-@!{#Ml84YTByXX!-x2wQl;$;Dj)Lh#d4vXZ;UMuAc$S KScRrd*28~DJ|~v| literal 0 HcmV?d00001 diff --git a/apps/silcmap/example.server.com_706.pub b/apps/silcmap/example.server.com_706.pub new file mode 100644 index 00000000..80ed2834 --- /dev/null +++ b/apps/silcmap/example.server.com_706.pub @@ -0,0 +1,7 @@ +-----BEGIN SILC PUBLIC KEY----- +AAAA/QADcnNhAGZVTj1zaWxjLW9wZXIsIEhOPXNpbGMuc2lsY25ldC5vcmcsIFJOPVNJTEM +gUm91dGVyIEFkbWluLCBFPXNpbGMtb3BlckBzaWxjbmV0Lm9yZywgTz1TSUxDIFByb2plY3 +QsIEM9U0sAAAAEAAAAfwAAAIAhKuTYfWdQ5UxB6ICuYCO13+gFIXZne3ciTm4c0AiHUoRat +5Pd116FhO2ktkVZC8QS6IfRso5BkaYtRyp7qsficnXxZmFH5nBctXvlZ5zFWiDLsDz6TKI0 +5ib/T9EyRblNIpzQVrJsopvrz0mYmZKxUuu/e06EbdvpoubeHj6xLQ== +-----END SILC PUBLIC KEY----- diff --git a/apps/silcmap/silcmap.c b/apps/silcmap/silcmap.c new file mode 100644 index 00000000..6e0a16d0 --- /dev/null +++ b/apps/silcmap/silcmap.c @@ -0,0 +1,243 @@ +/* + + silcmap.c + + Author: Pekka Riikonen + + Copyright (C) 2003 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +#include "silcincludes.h" +#include "silcclient.h" +#include "silcversion.h" +#include "silcmap.h" + +/* Allocates new SilcMap context and the SilcClient in it. */ + +SilcMap silc_map_alloc(const char *conffile) +{ + SilcMap map = silc_calloc(1, sizeof(*map)); + if (!map) + return NULL; + + /* Allocate client */ + map->client = silc_client_alloc(&silc_map_client_ops, NULL, NULL, NULL); + if (!map->client) { + silc_free(map); + return NULL; + } + + map->client->username = strdup("silcmap"); + map->client->hostname = silc_net_localhost(); + map->client->realname = strdup("silcmap"); + + /* Init the client */ + if (!silc_client_init(map->client)) { + silc_client_free(map->client); + silc_free(map); + return NULL; + } + + /* Load new key pair if it exists, create if it doesn't. */ + if (!silc_load_key_pair("silcmap.pub", "silcmap.prv", "", + &map->client->pkcs, + &map->client->public_key, + &map->client->private_key)) { + /* The keys don't exist. Let's generate us a key pair then! There's + nice ready routine for that too. Let's do 1024 bit RSA key pair. */ + if (!silc_create_key_pair("rsa", 1024, "silcmap.pub", + "silcmap.prv", NULL, "", + &map->client->pkcs, + &map->client->public_key, + &map->client->private_key, FALSE)) { + fprintf(stderr, "Could not create new key pair"); + silc_client_free(map->client); + silc_free(map); + return NULL; + } + } + + map->conffile = strdup(conffile); + + return map; +} + +/* Free the SilcMap context and all data in it. */ + +void silc_map_free(SilcMap map) +{ + SilcMapConnection mapconn; + SilcMapCommand cmd; + char *h; + + silc_free(map->conffile); + silc_free(map->bitmap); + + if (map->client) { + silc_free(map->client->username); + silc_free(map->client->realname); + silc_free(map->client->hostname); + silc_client_free(map->client); + } + + if (map->conns) { + silc_dlist_start(map->conns); + while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) { + silc_dlist_start(mapconn->hostnames); + while ((h = silc_dlist_get(mapconn->hostnames)) != SILC_LIST_END) + silc_free(h); + silc_dlist_uninit(mapconn->hostnames); + + silc_dlist_start(mapconn->ips); + while ((h = silc_dlist_get(mapconn->ips)) != SILC_LIST_END) + silc_free(h); + silc_dlist_uninit(mapconn->ips); + + silc_dlist_start(mapconn->commands); + while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) { + silc_free(cmd->filename); + silc_free(cmd->text); + silc_free(cmd); + } + silc_dlist_uninit(mapconn->commands); + + silc_free(mapconn->public_key); + silc_free(mapconn->country); + silc_free(mapconn->city); + silc_free(mapconn->admin); + silc_free(mapconn->description); + silc_free(mapconn->writemaphtml_url); + silc_free(mapconn->up_color); + silc_free(mapconn->up_text_color); + silc_free(mapconn->down_color); + silc_free(mapconn->down_text_color); + silc_free(mapconn->data.motd); + silc_free(mapconn); + } + silc_dlist_uninit(map->conns); + } + + silc_free(map->writemap.filename); + silc_free(map->writehtml.filename); + silc_free(map->writemaphtml.filename); + silc_free(map->writemaphtml.text); + silc_free(map->cut.filename); + + silc_free(map); +} + +/* Starts the actual silcmap by parsing the commands script. */ + +SILC_TASK_CALLBACK(silc_map_start) +{ + SilcMap map = context; + + /* Load default font */ + silc_map_load_font(map, "default.fnt"); + + /* Start command parsing. Most of the commands are executed when they + are parsed so most of the real magic happens here. */ + if (!silc_map_commands_parse(map, map->conffile)) { + /* Program stops */ + silc_schedule_stop(map->client->schedule); + } +} + +/* Long command line options */ +static struct option long_opts[] = +{ + { "config-file", 1, NULL, 'f' }, + { "debug", 2, NULL, 'd' }, + { "help", 0, NULL, 'h' }, + { "version", 0, NULL,'V' }, + + { NULL, 0, NULL, 0 } +}; + +static void silc_map_usage(void) +{ + printf("" +"Usage: silcmap [options]\n" +"\n" +" Generic Options:\n" +" -f --config-file=FILE Alternate SILC Map configuration file\n" +" -d --debug=string Enable debugging\n" +" -h --help Display this message and exit\n" +" -V --version Display version and exit\n" +"\n"); + exit(0); +} + +int main(int argc, char **argv) +{ + SilcMap map; + int opt, option_index; + char *filename = NULL; + + if (argc > 1) { + while ((opt = getopt_long(argc, argv, "f:d:hV", + long_opts, &option_index)) != EOF) { + switch(opt) { + case 'h': + silc_map_usage(); + break; + case 'V': + printf("SILC Map, version %s\n", silc_dist_version); + printf("(c) 2003 Pekka Riikonen \n"); + exit(0); + break; + case 'd': +#ifdef SILC_DEBUG + silc_debug = TRUE; + silc_debug_hexdump = TRUE; + if (optarg) + silc_log_set_debug_string(optarg); + silc_log_quick = TRUE; +#else + fprintf(stderr, + "Run-time debugging is not enabled. To enable it recompile\n" + "the server with --enable-debug configuration option.\n"); +#endif + break; + case 'f': + filename = strdup(optarg); + break; + default: + silc_map_usage(); + break; + } + } + } + + /* Allocate map context */ + if (!filename) + filename = strdup("silcmap.conf"); + map = silc_map_alloc(filename); + if (!map) + return 1; + + /* Schedule for command script parsing */ + silc_schedule_task_add(map->client->schedule, 0, + silc_map_start, map, 0, 1, + SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); + + /* Run the silcmap client */ + silc_client_run(map->client); + + /* Cleanup */ + silc_client_stop(map->client); + silc_map_free(map); + silc_free(filename); + + return 0; +} diff --git a/apps/silcmap/silcmap.conf b/apps/silcmap/silcmap.conf new file mode 100644 index 00000000..c8a85ab3 --- /dev/null +++ b/apps/silcmap/silcmap.conf @@ -0,0 +1,141 @@ +# +# Map drawing script file +# +# Command : server { ... } +# Description : Specifies a server to connect, fetch statistics, draw the +# server on map and to show its status on the map. See the +# example server command below for all parameters of this +# command. +# +# Command : loadmap { filename = ; }; +# Example : loadmap { filename = "world_map.ppm"; }; +# Description : Load the source bitmap image file to be used as the map +# +# Command : writemap { filename = ; }; +# Example : writemap { filename = "map.ppm"; }; +# Description : Write the target bitmap image file +# +# Command : writemaphtml { filename = ; image = ; +# cut_lat = ; cut_lon = ; }; +# Example : writemaphtml { filename = "htmlmap.map"; image = "map.jpg"; }; +# Description : Write the gathered information as as HTML map page. This +# allows the user to click the specified points of URLs. +# The writemaphtml_url parameter in server will specify the +# URL that will be used in the HTML map. If omitted the +# filename created by writehml command is used. The +# and are specified if the is a portion of +# the original map image. In this case the lat and lon specify +# which portion it is. +# +# Command : writehtml { filename = ; }; +# Example : writehtml { filename = "index.html"; }; +# Description : Write the gathered information as HTML pages. Every server +# command will have their own HTML file. The filename is +# based on the hostname of the server. The index HTML file +# will include list of the servers. The generated HTML files +# are quite raw and are intended to be embedded into user's +# own website. +# +# Command : cut { lat = ; lon = ; width = ; +# height = ; filename = ; }; +# Example : cut { lat = "20"; lon = "5"; width = "1000"; height = "700"; +# filename = "map_chunk.ppm"; }; +# Description : Cuts a chunk from the source image at specified location. +# The chunk will be * pixels in size. The +# is the output bitmap file where the chunk is saved. +# +# Command : rectangle { lat = ; lon = ; color = ; +# label =