/* RBN Filter / Server See http://fkurz.net/ham/stuff.html?rbnfilter By Fabian Kurz, DJ1YFK fabian@fkurz.net 2012-10-22 2012-12-10 (update) Code is in the public domain. */ #include #include #include #include #include #include #include #include #include /* errno */ void prompt (char *usercall); void clean (char *text); int iscall (char *call); int main (int argc, char *argv[]) { int i, j, k; char command[80]; char line[80]; char usercall[80]; static char tmp[80]; FILE *tail; FILE *fh; pid_t pid; printf("Welcome ...\r\n" "lalala \r\n\r\n" "Please enter your callsign: "); fflush(stdout); if (fgets(usercall, 64, stdin) == NULL) { printf("Error. Bye.\r\n");; exit(0); } clean(usercall); if (strlen(usercall) < 4) { printf("Please log in with a valid callsign. Bye.\r\n");; exit(0); } /* remove \r\n */ for (i=0; i < strlen(usercall); i++) { usercall[i] = toupper(usercall[i]); if (isspace(usercall[i])) { usercall[i] = '\0'; } } prompt(usercall); pid = fork(); /* Child process: tail -f */ if (pid == 0) { tail = popen("tail -f /tmp/spots.txt", "r"); while (fgets(line, 80, tail)) { printf("%s", line); fflush(stdout); } } /* Parent process: Handle user input */ else { fflush(stdin); while (fgets(command, 60, stdin)) { command[strlen(command)-2] = '\0'; fflush(stdout); fflush(stdin); if (strstr(command, "exit") == command) { printf("bye!\r\n"); fflush(stdout); kill(pid , SIGKILL); exit(0); } else if (strstr(command, "set/member") == command) { strcpy(tmp, command+8); for (i = 0; tmp[i]; i++) { tmp[i] = toupper(tmp[i]); } if (iscall(tmp)) { fh = fopen("/tmp/members.txt", "a"); fprintf(fh,"%s\r\n", tmp); fclose(fh); printf("Added %s to database.\r\n", tmp); fflush(stdout); } else { printf("Not a valid callsign.\r\n"); } } prompt(usercall); fflush(stdout); } } } void prompt (char *usercall) { time_t t; struct tm *timestruct; char timestring[255]; t = time(NULL); timestruct = gmtime(&t); strftime(timestring, sizeof(timestring), "%d-%b-%Y %H%M", gmtime(&t)); printf("%s de MYCALL-1 %sZ foc >\r\n", usercall, timestring); } int iscall (char *call) { return 1; } /* Remove telnet control sequences * Format: 0xFF 0x.. 0x.. */ void clean (char *txt) { int i,l; l = strlen(txt); for ( ; l ; l--) { if ((unsigned char) txt[l] == 0xFF) { break; } } if (l == 0) { return; } l += 2; for (i=0; i < strlen(txt)-l; i++) { txt[i] = txt[i+l]; } }