did a client-side <.A>ide <S>ysconfig <F>ilterlist command.
$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
+
do_ignet_configuration();
break;
+ case 92:
+ do_filterlist_configuration();
+ break;
+
case 6:
if (rc_alt_semantics)
updatelsa();
#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__)
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
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).
}
}
+/*
+ * 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);
+ }
+}
+
#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);
*/
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
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
/* 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
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;