From 29ebb8277a35ddfad1f00cbd0916e5ce97ac1b0a Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 6 Feb 2018 08:05:02 +1000 Subject: [PATCH] Initial nodelist parsing --- STRINGS.CHANGES | 4 ++ dist/config/happynet.ini | 1 + dist/magicka.strings | 2 +- src/Makefile.freebsd | 2 +- src/Makefile.freebsd.WWW | 2 +- src/Makefile.linux | 2 +- src/Makefile.linux.WWW | 2 +- src/Makefile.netbsd | 2 +- src/Makefile.netbsd.WWW | 2 +- src/Makefile.openbsd | 4 +- src/Makefile.openbsd.WWW | 4 +- src/Makefile.osx | 2 +- src/Makefile.osx.WWW | 2 +- src/Makefile.sunos | 2 +- src/Makefile.sunos.WWW | 2 +- src/bbs.h | 3 + src/mail_menu.c | 10 ++- src/main.c | 5 +- src/nodelist.c | 53 +++++++++++++++ utils/nodelistp/nodelistp.pl | 124 +++++++++++++++++++++++++++++++++++ 20 files changed, 213 insertions(+), 17 deletions(-) create mode 100644 src/nodelist.c create mode 100755 utils/nodelistp/nodelistp.pl diff --git a/STRINGS.CHANGES b/STRINGS.CHANGES index 5058f41..e225f03 100644 --- a/STRINGS.CHANGES +++ b/STRINGS.CHANGES @@ -66,3 +66,7 @@ NEWSTRING: "" LINE 148 CLEARED OLDSTRING: "Enter the number of a text file to display or Q to quit:" NEWSTRING: "" + +LINE 124 MODIFIED +OLDSTRING: "\r\nMailing to %d:%d/%d.%d\r\n" +NEWSTRING: "\r\nMailing to %d:%d/%d.%d (%s)\r\n" diff --git a/dist/config/happynet.ini b/dist/config/happynet.ini index 7ab3b9a..b93404d 100644 --- a/dist/config/happynet.ini +++ b/dist/config/happynet.ini @@ -10,6 +10,7 @@ Real Names = false [network] type = fido fido node = 637:1/999 +domain = happynet [General] Read Sec Level = 10 diff --git a/dist/magicka.strings b/dist/magicka.strings index 696a28f..f6e995a 100644 --- a/dist/magicka.strings +++ b/dist/magicka.strings @@ -121,7 +121,7 @@ Change Subject? (Y/N) Read message [1-%d] or N for New: \r\nADDR: \r\n\r\nInvalid Address\r\n -\r\nMailing to %d:%d/%d.%d\r\n +\r\nMailing to %d:%d/%d.%d (%s)\r\n \r\nMailing to @%d\r\n Start at message [1-%d] or N for New? \e[2J\e[1;1H\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m diff --git a/src/Makefile.freebsd b/src/Makefile.freebsd index 555f690..f06d3e3 100644 --- a/src/Makefile.freebsd +++ b/src/Makefile.freebsd @@ -29,7 +29,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.freebsd.WWW b/src/Makefile.freebsd.WWW index 648703c..122108d 100644 --- a/src/Makefile.freebsd.WWW +++ b/src/Makefile.freebsd.WWW @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.linux b/src/Makefile.linux index 52b3d5d..3119907 100644 --- a/src/Makefile.linux +++ b/src/Makefile.linux @@ -30,7 +30,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.linux.WWW b/src/Makefile.linux.WWW index 850ea3b..d40f0d0 100644 --- a/src/Makefile.linux.WWW +++ b/src/Makefile.linux.WWW @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.netbsd b/src/Makefile.netbsd index 6322e9a..1f94cba 100644 --- a/src/Makefile.netbsd +++ b/src/Makefile.netbsd @@ -29,7 +29,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.netbsd.WWW b/src/Makefile.netbsd.WWW index f07c917..207574c 100644 --- a/src/Makefile.netbsd.WWW +++ b/src/Makefile.netbsd.WWW @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.openbsd b/src/Makefile.openbsd index 10119a8..0be3e58 100644 --- a/src/Makefile.openbsd +++ b/src/Makefile.openbsd @@ -26,10 +26,10 @@ $(JSMN): cd ../deps/jsmn/ && $(MAKE) $(CDK): - cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses + cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.openbsd.WWW b/src/Makefile.openbsd.WWW index 450250c..69afefd 100644 --- a/src/Makefile.openbsd.WWW +++ b/src/Makefile.openbsd.WWW @@ -31,10 +31,10 @@ $(JSMN): cd ../deps/jsmn/ && $(MAKE) $(CDK): - cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses + cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.osx b/src/Makefile.osx index 3039e58..edbcbec 100644 --- a/src/Makefile.osx +++ b/src/Makefile.osx @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd diff --git a/src/Makefile.osx.WWW b/src/Makefile.osx.WWW index f7aabfe..a8f055f 100644 --- a/src/Makefile.osx.WWW +++ b/src/Makefile.osx.WWW @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.sunos b/src/Makefile.sunos index d0789b4..270fe97 100644 --- a/src/Makefile.sunos +++ b/src/Makefile.sunos @@ -30,7 +30,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Makefile.sunos.WWW b/src/Makefile.sunos.WWW index bcbdb2d..463d7f1 100644 --- a/src/Makefile.sunos.WWW +++ b/src/Makefile.sunos.WWW @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/bbs.h b/src/bbs.h index b173751..92789e7 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -70,6 +70,7 @@ struct mail_conference { char *name; char *path; char *tagline; + char *domain; int networked; int nettype; int realnames; @@ -366,4 +367,6 @@ extern char *www_create_link(int dir, int sub, int fid); extern char *www_decode_hash(char *hash); #endif extern int menu_system(char *menufile); + +extern char *nl_get_bbsname(struct fido_addr *addr, char *domain); #endif diff --git a/src/mail_menu.c b/src/mail_menu.c index 804e520..c2236bd 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -2064,6 +2064,7 @@ void post_message(struct user_record *user) { char buffer2[256]; int z; int sem_fd; + char *bbsname; s_JamBase *jb; s_JamMsgHeader jmh; @@ -2106,7 +2107,14 @@ void post_message(struct user_record *user) { s_printf(get_string(122)); return; } - s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point); + if (conf.mail_conferences[gUser->cur_mail_conf]->domain != NULL) { + bbsname = nl_get_bbsname(from_addr, conf.mail_conferences[gUser->cur_mail_conf]->domain); + } else { + bbsname = strdup("Unknown"); + } + s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point, bbsname); + + free(bbsname); } } } diff --git a/src/main.c b/src/main.c index 43c0c1e..5466722 100644 --- a/src/main.c +++ b/src/main.c @@ -327,7 +327,9 @@ static int mail_area_handler(void* user, const char* section, const char* name, } } else if (strcasecmp(name, "fido node") == 0) { mc->fidoaddr = parse_fido_addr(value); - } + } else if (strcasecmp(name, "domain") == 0) { + mc->domain = strdup(value); + } } else { // check if it's partially filled in for (i=0;imail_area_count;i++) { @@ -551,6 +553,7 @@ static int handler(void* user, const char* section, const char* name, conf->mail_conferences[conf->mail_conference_count]->tagline = NULL; conf->mail_conferences[conf->mail_conference_count]->mail_area_count = 0; conf->mail_conferences[conf->mail_conference_count]->nettype = 0; + conf->mail_conferences[conf->mail_conference_count]->domain = NULL; conf->mail_conference_count++; } else if (strcasecmp(section, "file directories") == 0) { if (conf->file_directory_count == 0) { diff --git a/src/nodelist.c b/src/nodelist.c new file mode 100644 index 0000000..5994a29 --- /dev/null +++ b/src/nodelist.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include "bbs.h" + +extern struct bbs_config conf; + +char *nl_get_bbsname(struct fido_addr *addr, char *domain) { + sqlite3 *db; + sqlite3_stmt *res; + int rc; + char buffer[PATH_MAX]; + char *ret; + char *sql_buf = "SELECT bbsname FROM nodelist WHERE nodeno=? AND domain=?"; + + snprintf(buffer, PATH_MAX, "%s/nodelists.sq3", conf.bbs_path); + + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + return strdup("Unknown"); + } + sqlite3_busy_timeout(db, 5000); + + rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0); + + if (rc != SQLITE_OK) { + sqlite3_close(db); + return 0; + } + + if (addr->point == 0) { + snprintf(buffer, PATH_MAX, "%d:%d/%d", addr->zone, addr->net, addr->node); + } else { + // no support for point addresses yet. + return strdup("Unknown"); + } + + sqlite3_bind_text(res, 1, buffer, -1, 0); + sqlite3_bind_text(res, 2, domain, -1, 0); + + if (sqlite3_step(res) != SQLITE_ROW) { + sqlite3_finalize(res); + sqlite3_close(db); + return strdup("Unknown"); + } + ret = strdup(sqlite3_column_text(res, 0)); + + sqlite3_finalize(res); + sqlite3_close(db); + return ret; +} \ No newline at end of file diff --git a/utils/nodelistp/nodelistp.pl b/utils/nodelistp/nodelistp.pl new file mode 100755 index 0000000..984c90b --- /dev/null +++ b/utils/nodelistp/nodelistp.pl @@ -0,0 +1,124 @@ +#!/usr/bin/env perl + +# Contains code by Robert James Clay's FTNDB project. Licensed under the +# same license as perl. +# https://metacpan.org/source/JAME/App-FTNDB-0.39/bin/ftndb-nodelist + +use DBI; +use strict; + +if ($#ARGV < 2) { + print "Usage ./nodelistp.pl nodelist database.sq3 domain\n"; + exit(0); +} + +my $nodelist = $ARGV[0]; +my $database = $ARGV[1]; +my $domain = $ARGV[2]; + +my $driver = "SQLite"; +my $dsn = "DBI:$driver:dbname=$database"; +my $userid = ""; +my $password = ""; +my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) + or die $DBI::errstr; + +my $stmt = qq(CREATE TABLE IF NOT EXISTS nodelist ( + Id INTEGER PRIMARY KEY, + domain TEXT COLLATE NOCASE, + nodeno TEXT, + sysop TEXT, + location TEXT, + bbsname TEXT);); +my $rv = $dbh->do($stmt); + +if($rv < 0){ + print $DBI::errstr; + exit(0); +} + + +open NODELIST, $nodelist or die print "Cannot open $nodelist"; + +$stmt = 'DELETE FROM nodelist WHERE domain=$1;'; +my $sth = $dbh->prepare( $stmt ); +$rv = $sth->execute($domain) or die $DBI::errstr; +if($rv < 0){ + print $DBI::errstr; +} +my $nodelistcount = 0; +my $zone = 1; +my $net = 0; +my $node = 0; +my $region = 0; +my $location; +my $sysop; +my $name; +my $type; +my $number; +my $phone; +my $bps; +my $flags; +my $zone_number; +my $nodeno; + +while () { + if ( /^;/ || /^\cZ/ ) { + + # print; + next; + } + + ( $type, $number, $name, $location, $sysop, $phone, $bps, $flags ) = + split /,/, $_, 8 ; + + # if $flags is undefined (i.e., nothing after the baud rate) + if ( !defined $flags ) { + $flags = q{ }; + } + else { + $flags =~ s/\r?\n$//; # else remove EOL (removes \r\n or \n but not \r) from $flags + } + + if ( $type eq 'Zone' ) { # Zone line + $zone = $number; + $net = $number; + $node = 0; + } # + elsif ( $type eq 'Region' ) { # Region line + $region = $number; + $net = $number; + $node = 0; + } + elsif ( $type eq 'Host' ) { # Host line + $net = $number; + $node = 0; + } + else { + $node = $number; + } + + # If zone_number is defined, then go to the next line if the zone + # number is not the same as zone_number + if (defined $zone_number) { + if ($zone != $zone_number) { + next; + } + } + + $name =~ s/\_/ /g; + $sysop =~ s/\_/ /g; + $location =~ s/\_/ /g; + + $nodeno = "$zone:$net/$node"; + + + $sth = $dbh->prepare('INSERT INTO nodelist (domain, nodeno, sysop, location, bbsname) VALUES($1, $2, $3, $4, $5)'); + $sth->execute($domain, $nodeno, $sysop, $location, $name); + + $nodelistcount++; +} + +close NODELIST; + +print "Processed $nodelistcount nodes.\n"; \ No newline at end of file