* Properly implemented the network filter list. Finished the server module and
authorArt Cancro <ajc@citadel.org>
Sat, 2 Mar 2002 05:56:49 +0000 (05:56 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 2 Mar 2002 05:56:49 +0000 (05:56 +0000)
  did a client-side <.A>ide <S>ysconfig <F>ilterlist command.

citadel/ChangeLog
citadel/citadel.c
citadel/citadel.h
citadel/citadel.rc
citadel/msgbase.c
citadel/routines2.c
citadel/serv_netfilter.c
citadel/serv_network.c
citadel/serv_network.h

index 69d3f25ca999277d7d7391b85c97aa2dc7f138f3..5164ccb8d8ee7dc1ef9b7c3a9aa37745a523f817 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 590.120  2002/03/02 05:56:48  ajc
+ * Properly implemented the network filter list.  Finished the server module and
+   did a client-side <.A>ide <S>ysconfig <F>ilterlist command.
+
  Revision 590.119  2002/03/01 04:24:20  ajc
  * Cosmetic change to Received: line
 
@@ -3364,3 +3368,5 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
+
index 873074019a0b6243a882d5c10c5c9da633e21a27..5d0d90b693dae7abac9bbf7d655383668100bf53 100644 (file)
@@ -1537,6 +1537,10 @@ PWOK:
                                do_ignet_configuration();
                                break;
 
+                       case 92:
+                               do_filterlist_configuration();
+                               break;
+
                        case 6:
                                if (rc_alt_semantics)
                                        updatelsa();
index 39f2b17568b89a1803dc7a1e4be88d8d153764fd..36002c207627eac4e98c941a6c309b40af3a1fac 100644 (file)
@@ -278,7 +278,7 @@ struct floor {
 #define        INTERNETCFG     "application/x-citadel-internet-config"
 #define IGNETCFG       "application/x-citadel-ignet-config"
 #define IGNETMAP       "application/x-citadel-ignet-map"
-#define USETABLE       "application/x-citadel-usetable"
+#define FILTERLIST     "application/x-citadel-filter-list"
 
 #define TRACE  lprintf(9, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
 
index e5b825dac563b0482b446b830a2cd472bf136cc4..72272cf0e17a147525e6f6d182d41993049fc0de 100644 (file)
@@ -224,6 +224,7 @@ cmd=80,2,&.,&Aide,&System configuration,&General
 cmd=82,2,&.,&Aide,&System configuration,&Internet
 cmd=83,2,&.,&Aide,&System configuration,check &Message base
 cmd=88,2,&.,&Aide,&System configuration,&Network
+cmd=92,2,&.,&Aide,&System configuration,network &Filter list
 cmd=85,2,&.,&Aide,&Terminate server,&Now
 cmd=86,2,&.,&Aide,&Terminate server,&Scheduled
 cmd=87,1,&.,&Aide,mailing &List management
index c2b18561062c9ccf936aa0bd57d52aa860af4d0a..5c2290b274908b463b74a82b774f2ba1431f4ffb 100644 (file)
 extern struct config config;
 long config_msgnum;
 
+
+/* 
+ * This really belongs in serv_network.c, but I don't know how to export
+ * symbols between modules.
+ */
+struct FilterList *filterlist = NULL;
+
+
 /*
  * These are the four-character field headers we use when outputting
  * messages in Citadel format (as opposed to RFC822 format).
index d6d3f8d96a7f15097c7f9fec9d4a5d4881944493..7dc80d4a0f71a41e19a1d04cdd77276a3da2a88e 100644 (file)
@@ -1195,4 +1195,114 @@ void do_ignet_configuration(void) {
        }
 }
 
+/*
+ * Filter list configuration
+ */
+void do_filterlist_configuration(void) {
+       char buf[SIZ];
+       int num_recs = 0;
+       char **recs = NULL;
+       char ch;
+       int badkey;
+       int i, j;
+       int quitting = 0;
+       
+
+       sprintf(buf, "CONF getsys|%s", FILTERLIST);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
+               ++num_recs;
+               if (num_recs == 1) recs = malloc(sizeof(char *));
+               else recs = realloc(recs, (sizeof(char *)) * num_recs);
+               recs[num_recs-1] = malloc(SIZ);
+               strcpy(recs[num_recs-1], buf);
+       }
+
+       do {
+               scr_printf("\n");
+               color(BRIGHT_WHITE);
+               scr_printf(     "### "
+                       "         User name           "
+                       "         Room name           "
+                       "    Node name    "
+                       "\n");
+               color(DIM_WHITE);
+               scr_printf(     "--- "
+                       "---------------------------- "
+                       "---------------------------- "
+                       "---------------- "
+                       "\n");
+               for (i=0; i<num_recs; ++i) {
+               color(DIM_WHITE);
+               scr_printf("%3d ", i+1);
+               extract(buf, recs[i], 0);
+               color(BRIGHT_CYAN);
+               scr_printf("%-28s ", buf);
+               extract(buf, recs[i], 1);
+               color(BRIGHT_MAGENTA);
+               scr_printf("%-28s ", buf);
+               extract(buf, recs[i], 2);
+               color(BRIGHT_CYAN);
+               scr_printf("%-16s\n", buf);
+               extract(buf, recs[i], 3);
+               color(DIM_WHITE);
+               }
+
+               ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
+               switch(ch) {
+                       case 'a':
+                               ++num_recs;
+                               if (num_recs == 1)
+                                       recs = malloc(sizeof(char *));
+                               else recs = realloc(recs,
+                                       (sizeof(char *)) * num_recs);
+                               newprompt("Enter user name: ", buf, 28);
+                               strcat(buf, "|");
+                               newprompt("Enter room name: ",
+                                       &buf[strlen(buf)], 28);
+                               strcat(buf, "|");
+                               newprompt("Enter node name: ",
+                                       &buf[strlen(buf)], 16);
+                               strcat(buf, "|");
+                               recs[num_recs-1] = strdup(buf);
+                               break;
+                       case 'd':
+                               i = intprompt("Delete which one",
+                                       1, 1, num_recs) - 1;
+                               free(recs[i]);
+                               --num_recs;
+                               for (j=i; j<num_recs; ++j)
+                                       recs[j] = recs[j+1];
+                               break;
+                       case 's':
+                               sprintf(buf, "CONF putsys|%s", FILTERLIST);
+                               serv_puts(buf);
+                               serv_gets(buf);
+                               if (buf[0] == '4') {
+                                       for (i=0; i<num_recs; ++i) {
+                                               serv_puts(recs[i]);
+                                       }
+                                       serv_puts("000");
+                               }
+                               else {
+                                       scr_printf("%s\n", &buf[4]);
+                               }
+                               quitting = 1;
+                               break;
+                       case 'q':
+                               quitting = boolprompt(
+                                       "Quit without saving", 0);
+                               break;
+                       default:
+                               badkey = 1;
+               }
+       } while (quitting == 0);
+
+       if (recs != NULL) {
+               for (i=0; i<num_recs; ++i) free(recs[i]);
+               free(recs);
+       }
+}
+
 
index b4db3e850a3b855d9ffa47538d7b7840b76aa4e2..5aeda1b690ab3671c290f0548f492e3322503dc5 100644 (file)
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
+#include "serv_network.h"
 #include "tools.h"
 
 /*
- * This handler detects whether the user is attempting to save a new
- * vCard as part of his/her personal configuration, and handles the replace
- * function accordingly (delete the user's existing vCard in the config room
- * and in the global address book).
+ * This handler detects whether an incoming network message is from some
+ * moron user who the site operator has elected to filter out.  If a match
+ * is found, the message is rejected.
  */
 int filter_the_idiots(struct CtdlMessage *msg, char *target_room) {
+       struct FilterList *fptr;
+       int zap_user = 0;
+       int zap_room = 0;
+       int zap_node = 0;
 
-       if (msg == NULL) {
+       if ( (msg == NULL) || (filterlist == NULL) ) {
                return(0);
        }
 
-       /* FIXME ... write it!  In the meantime, here's a temporary fix */
+       for (fptr = filterlist; fptr != NULL; fptr = fptr->next) {
 
-       if (msg->cm_fields['A'] != NULL) {
-               if (!strcasecmp(msg->cm_fields['A'],
-                               "Curly Surmudgeon")) {
-                       return(1);
+               zap_user = 0;
+               zap_room = 0;
+               zap_node = 0;
+
+               if (msg->cm_fields['A'] != NULL) {
+                       if ( (!strcasecmp(msg->cm_fields['A'], fptr->fl_user))
+                          || (fptr->fl_user[0] == 0) ) {
+                               zap_user = 1;
+                       }
+               }
+
+               if (msg->cm_fields['C'] != NULL) {
+                       if ( (!strcasecmp(msg->cm_fields['C'], fptr->fl_room))
+                          || (fptr->fl_room[0] == 0) ) {
+                               zap_room = 1;
+                       }
+               }
+
+               if (msg->cm_fields['O'] != NULL) {
+                       if ( (!strcasecmp(msg->cm_fields['O'], fptr->fl_room))
+                          || (fptr->fl_room[0] == 0) ) {
+                               zap_room = 1;
+                       }
+               }
+
+               if (msg->cm_fields['N'] != NULL) {
+                       if ( (!strcasecmp(msg->cm_fields['N'], fptr->fl_node))
+                          || (fptr->fl_node[0] == 0) ) {
+                               zap_node = 1;
+                       }
                }
+       
+               if (zap_user + zap_room + zap_node == 3) return(1);
+
        }
 
        return(0);
index 7bdf2c4d203923384bd9cfc839f29b0e13a63bb0..9b92016c9cb0c61602ff79dd620422c682ca5d2a 100644 (file)
@@ -74,6 +74,55 @@ struct RoomProcList *rplist = NULL;
  */
 struct NetMap *the_netmap = NULL;
 
+/*
+ * Keep track of what messages to reject
+ */
+struct FilterList *load_filter_list(void) {
+       char *serialized_list = NULL;
+       int i;
+       char buf[SIZ];
+       struct FilterList *newlist = NULL;
+       struct FilterList *nptr;
+
+       serialized_list = CtdlGetSysConfig(FILTERLIST);
+       if (serialized_list == NULL) return(NULL); /* if null, no entries */
+
+       /* Use the string tokenizer to grab one line at a time */
+       for (i=0; i<num_tokens(serialized_list, '\n'); ++i) {
+               extract_token(buf, serialized_list, i, '\n');
+               nptr = (struct FilterList *) mallok(sizeof(struct FilterList));
+               extract(nptr->fl_user, buf, 0);
+               striplt(nptr->fl_user);
+               extract(nptr->fl_room, buf, 1);
+               striplt(nptr->fl_room);
+               extract(nptr->fl_node, buf, 2);
+               striplt(nptr->fl_node);
+
+               /* Cowardly refuse to add an any/any/any entry that would
+                * end up filtering every single message.
+                */
+               if (strlen(nptr->fl_user) + strlen(nptr->fl_room)
+                  + strlen(nptr->fl_node) == 0) {
+                       phree(nptr);
+               }
+               else {
+                       nptr->next = newlist;
+                       newlist = nptr;
+               }
+       }
+
+       phree(serialized_list);
+       return newlist;
+}
+
+
+void free_filter_list(struct FilterList *fl) {
+       if (fl == NULL) return;
+       free_filter_list(fl->next);
+       phree(fl);
+}
+
+
 
 /*
  * Check the use table.  This is a list of messages which have recently
@@ -1242,9 +1291,10 @@ void network_do_queue(void) {
        network_poll_other_citadel_nodes();
 
        /*
-        * Load the network map into memory.
+        * Load the network map and filter list into memory.
         */
        read_network_map();
+       filterlist = load_filter_list();
 
        /* 
         * Go ahead and run the queue
@@ -1266,12 +1316,15 @@ void network_do_queue(void) {
        /* Save the network map back to disk */
        write_network_map();
 
+       /* Free the filter list in memory */
+       free_filter_list(filterlist);
+       filterlist = NULL;
+
        lprintf(7, "network: queue run completed\n");
        doing_queue = 0;
 }
 
 
-
 /*
  * cmd_netp() - authenticate to the server as another Citadel node polling
  *              for network traffic
index 14ab8b288bcd911585cce01cbfd80b5b7470e167..ed65e04bbbcc0153704cae7a9f1841674cf1aa2f 100644 (file)
@@ -26,3 +26,12 @@ struct UseTable {
        char ut_msgid[SIZ];
        time_t ut_timestamp;
 };
+
+struct FilterList {
+       struct FilterList *next;
+       char fl_user[SIZ];
+       char fl_room[SIZ];
+       char fl_node[SIZ];
+};
+
+extern struct FilterList *filterlist;