1 /* More Citadel/UX routines...
2 * unlike routines.c, some of these DO use global variables.
22 #include "routines2.h"
31 void interr(int errnum);
32 void strprompt(char *prompt, char *str, int len);
33 void newprompt(char *prompt, char *str, int len);
34 void sttybbs(int cmd);
36 void serv_write(char *buf, int nbytes);
37 int haschar(char *st, int ch);
38 void progress(long int curr, long int cmax);
42 extern char tempdir[];
43 extern char *axdefs[7];
44 extern long highest_msg_read;
45 extern long maxmsgnum;
46 extern unsigned room_flags;
47 extern int screenwidth;
50 int eopen(char *name, int mode)
53 ret = open(name, mode);
55 fprintf(stderr, "Cannot open file '%s', mode=%d, errno=%d\n",
63 int room_prompt(int qrflags)
64 { /* return proper room prompt character */
67 if (qrflags & QR_DIRECTORY)
69 if ((a == ']') && (qrflags & QR_NETWORK))
71 if ((a == '>') && (qrflags & QR_NETWORK))
77 { /* register with name and address */
97 serv_puts("GREG _SELF_");
101 while (serv_gets(buf), strcmp(buf, "000")) {
103 strcpy(tmpname, buf);
105 strcpy(tmpaddr, buf);
107 strcpy(tmpcity, buf);
109 strcpy(tmpstate, buf);
113 strcpy(tmpphone, buf);
115 strcpy(tmpemail, buf);
119 strprompt("REAL name", tmpname, 29);
120 strprompt("Address", tmpaddr, 24);
121 strprompt("City/town", tmpcity, 14);
122 strprompt("State", tmpstate, 2);
123 strprompt("ZIP Code", tmpzip, 10);
124 strprompt("Telephone number", tmpphone, 14);
125 strprompt("Email address", tmpemail, 31);
127 /* now send the registration info back to the server */
131 printf("%s\n", &buf[4]);
146 { /* make all messages old in current room */
148 serv_puts("SLRP HIGHEST");
151 printf("%s\n", &buf[4]);
155 * only make messages old in this room that have been read
160 sprintf(buf, "SLRP %ld", highest_msg_read);
164 printf("%s\n", &buf[4]);
169 * This routine completes a client upload
171 void do_upload(int fd)
175 long transmitted_bytes, total_bytes;
179 /* learn the size of the file */
180 total_bytes = lseek(fd, 0L, 2);
183 transmitted_bytes = 0L;
184 progress(transmitted_bytes, total_bytes);
186 bytes_to_send = read(fd, tbuf, 4096);
187 if (bytes_to_send > 0) {
188 sprintf(buf, "WRIT %d", bytes_to_send);
192 bytes_expected = atoi(&buf[4]);
193 serv_write(tbuf, bytes_expected);
195 printf("%s\n", &buf[4]);
198 transmitted_bytes = transmitted_bytes + (long) bytes_to_send;
199 progress(transmitted_bytes, total_bytes);
200 } while (bytes_to_send > 0);
202 /* close the upload file, locally and at the server */
206 printf("%s\n", &buf[4]);
211 * client-based uploads (for users with their own clientware)
213 void cli_upload(void)
222 if ((room_flags & QR_UPLOAD) == 0) {
223 printf("*** You cannot upload to this room.\n");
226 newprompt("File to be uploaded: ", flnm, 55);
227 fd = open(flnm, O_RDONLY);
229 printf("Cannot open '%s': %s\n", flnm, strerror(errno));
232 printf("Enter a description of this file:\n");
233 newprompt(": ", desc, 75);
235 /* keep generating filenames in hope of finding a unique one */
239 return; /* fail if tried 10 times */
241 while ((strlen(buf) > 0) && (haschar(buf, '/')))
242 strcpy(buf, &buf[1]);
244 sprintf(&buf[strlen(buf)], "%d", a);
245 sprintf(tbuf, "UOPN %s|%s", buf, desc);
249 printf("%s\n", &buf[4]);
251 } while (buf[0] != '2');
253 /* at this point we have an open upload file at the server */
259 * Function used for various image upload commands
261 void cli_image_upload(char *keyname)
267 sprintf(buf, "UIMG 0|%s", keyname);
271 printf("%s\n", &buf[4]);
274 newprompt("Image file to be uploaded: ", flnm, 55);
275 fd = open(flnm, O_RDONLY);
277 printf("Cannot open '%s': %s\n", flnm, strerror(errno));
280 sprintf(buf, "UIMG 1|%s", keyname);
284 printf("%s\n", &buf[4]);
292 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
295 { /* c = upload mode */
305 if ((room_flags & QR_UPLOAD) == 0) {
306 printf("*** You cannot upload to this room.\n");
309 /* we don't need a filename when receiving batch y/z modem */
310 if ((c == 2) || (c == 3))
313 newprompt("Enter filename: ", flnm, 15);
315 for (a = 0; a < strlen(flnm); ++a)
316 if ((flnm[a] == '/') || (flnm[a] == '\\') || (flnm[a] == '>')
317 || (flnm[a] == '?') || (flnm[a] == '*')
318 || (flnm[a] == ';') || (flnm[a] == '&'))
321 newprompt("Enter a short description of the file:\n: ", desc, 150);
323 /* create a temporary directory... */
324 if (mkdir(tempdir, 0700) != 0) {
325 printf("*** Could not create temporary directory %s: %s\n",
326 tempdir, strerror(errno));
329 /* now do the transfer ... in a separate process */
336 printf("Receiving %s - press Ctrl-D to end.\n", flnm);
337 fp = fopen(flnm, "w");
353 execlp("rx", "rx", flnm, NULL);
357 execlp("rb", "rb", NULL);
361 execlp("rz", "rz", NULL);
367 } while ((b != xfer_pid) && (b != (-1)));
371 printf("\r*** Transfer unsuccessful.\n");
375 printf("\r*** Transfer successful. Sending file(s) to server...\n");
376 sprintf(buf, "cd %s; ls", tempdir);
377 lsfp = popen(buf, "r");
379 while (fgets(flnm, 256, lsfp) != NULL) {
380 flnm[strlen(flnm) - 1] = 0;
381 sprintf(buf, "%s/%s", tempdir, flnm);
382 fd = open(buf, O_RDONLY);
386 sprintf(buf, "UOPN %s|%s", flnm, desc);
388 sprintf(&buf[strlen(buf)],
393 } while ((buf[0] != '2') && (a < 100));
396 a = read(fd, tbuf, 4096);
398 sprintf(buf, "WRIT %d", a);
408 printf("%s\n", &buf[4]);
419 void val_user(char *user, int do_validate)
426 sprintf(cmd, "GREG %s", user);
435 printf("User #%s - %s ", buf, &cmd[4]);
437 printf("PW: %s\n", buf);
454 } while (strcmp(buf, "000"));
455 printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
457 printf("%-30s\n%s\n", user, &cmd[4]);
461 /* now set the access level */
462 ax = intprompt("Access level", ax, 0, 6);
463 sprintf(cmd, "VALI %s|%d", user, ax);
467 printf("%s\n", &cmd[4]);
474 { /* validate new users */
485 printf("%s\n", &cmd[4]);
487 extract(buf, cmd, 0);
488 val_user(&buf[4], 1);
490 } while (finished == 0);
499 signal(SIGINT, SIG_DFL);
500 signal(SIGQUIT, SIG_DFL);
501 execlp(getenv("SHELL"), getenv("SHELL"), NULL);
502 printf("Could not open a shell: %s\n", strerror(errno));
507 } while ((a != b) && (a != (-1)));
512 * <.A>ide <F>ile <D>elete command
514 void deletefile(void)
519 newprompt("Filename: ", filename, 31);
520 if (strlen(filename) == 0)
522 sprintf(cmd, "DELF %s", filename);
525 printf("%s\n", &cmd[4]);
529 * <.A>ide <F>ile <S>end command
531 void netsendfile(void)
533 char filename[32], destsys[20], cmd[256];
535 newprompt("Filename: ", filename, 31);
536 if (strlen(filename) == 0)
538 newprompt("System to send to: ", destsys, 19);
539 sprintf(cmd, "NETF %s|%s", filename, destsys);
542 printf("%s\n", &cmd[4]);
547 * <.A>ide <F>ile <M>ove command
552 char newroom[ROOMNAMELEN];
555 newprompt("Filename: ", filename, 63);
556 if (strlen(filename) == 0)
558 newprompt("Enter target room: ", newroom, ROOMNAMELEN - 1);
560 sprintf(cmd, "MOVF %s|%s", filename, newroom);
563 printf("%s\n", &cmd[4]);
568 * list of users who have filled out a bio
578 pprintf("%s\n", &buf[4]);
581 while (serv_gets(buf), strcmp(buf, "000")) {
582 if ((pos + strlen(buf) + 5) > screenwidth) {
586 pprintf("%s, ", buf);
587 pos = pos + strlen(buf) + 2;
589 pprintf("%c%c \n\n", 8, 8);
602 newprompt("Read bio for who ('?' for list) : ", who, 25);
604 if (!strcmp(who, "?"))
606 } while (!strcmp(who, "?"));
607 sprintf(buf, "RBIO %s", who);
611 pprintf("%s\n", &buf[4]);
614 while (serv_gets(buf), strcmp(buf, "000")) {
615 pprintf("%s\n", buf);
621 * General system configuration command
623 void do_system_configuration(void)
628 int expire_value = 0;
631 /* Clear out the config buffers */
632 memset(&sc[0][0], 0, sizeof(sc));
634 /* Fetch the current config */
635 serv_puts("CONF get");
639 while (serv_gets(buf), strcmp(buf, "000")) {
641 strcpy(&sc[a][0], buf);
645 /* Fetch the expire policy (this will silently fail on old servers,
646 * resulting in "default" policy)
648 serv_puts("GPEX site");
651 expire_mode = extract_int(&buf[4], 0);
652 expire_value = extract_int(&buf[4], 1);
656 /* Identification parameters */
658 strprompt("Node name", &sc[0][0], 15);
659 strprompt("Fully qualified domain name", &sc[1][0], 63);
660 strprompt("Human readable node name", &sc[2][0], 20);
661 strprompt("Modem dialup number", &sc[3][0], 15);
662 strprompt("Geographic location of this system", &sc[12][0], 31);
663 strprompt("Name of system administrator", &sc[13][0], 25);
664 strprompt("Paginator prompt", &sc[10][0], 79);
665 strprompt("Default moderation filter for new users", &sc[25][0], 4);
667 /* Security parameters */
669 sprintf(&sc[7][0], "%d", (boolprompt(
670 "Require registration for new users",
672 strprompt("Initial access level for new users", &sc[6][0], 1);
673 strprompt("Access level required to create rooms", &sc[19][0], 1);
674 sprintf(&sc[4][0], "%d", (boolprompt(
675 "Automatically give room aide privs to a user who creates a private room",
678 sprintf(&sc[8][0], "%d", (boolprompt(
679 "Automatically move problem user messages to twit room",
682 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
683 sprintf(&sc[11][0], "%d", (boolprompt(
684 "Restrict Internet mail to only those with that privilege",
687 strprompt("Name of room to log pages", &sc[18][0], ROOMNAMELEN);
692 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
693 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
694 strprompt("Maximum message length", &sc[20][0], 20);
695 strprompt("Minimum number of worker threads", &sc[21][0], 3);
696 strprompt("Maximum number of worker threads", &sc[22][0], 3);
697 strprompt("Server-to-server networking password", &sc[15][0], 19);
698 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
699 strprompt("SMTP server port (-1 to disable)", &sc[24][0], 5);
702 /* Expiry settings */
703 strprompt("Default user purge time (days)", &sc[16][0], 5);
704 strprompt("Default room purge time (days)", &sc[17][0], 5);
706 /* Angels and demons dancing in my head... */
708 sprintf(buf, "%d", expire_mode);
709 strprompt("System default message expire policy (? for list)",
713 printf("1. Never automatically expire messages\n");
714 printf("2. Expire by message count\n");
715 printf("3. Expire by message age\n");
717 } while ((buf[0] < 49) || (buf[0] > 51));
718 expire_mode = buf[0] - 48;
720 /* ...lunatics and monsters underneath my bed */
721 if (expire_mode == 2) {
722 sprintf(buf, "%d", expire_value);
723 strprompt("Keep how many messages online?", buf, 10);
724 expire_value = atol(buf);
726 if (expire_mode == 3) {
727 sprintf(buf, "%d", expire_value);
728 strprompt("Keep messages for how many days?", buf, 10);
729 expire_value = atol(buf);
732 printf("Save this configuration? ");
734 serv_puts("CONF set");
737 for (a = 0; a < 26; ++a)
738 serv_puts(&sc[a][0]);
741 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
742 expire_mode, expire_value);
750 * support function for do_internet_configuration()
752 void get_inet_rec_type(char *buf) {
755 keyopt(" <1> localhost (Alias for this computer)\n");
756 keyopt(" <2> gateway domain (Domain for all Citadel systems)\n");
757 keyopt(" <3> smart-host (Forward all outbound mail to this host)\n");
758 sel = intprompt("Which one", 1, 1, 3);
760 case 1: strcpy(buf, "localhost");
762 case 2: strcpy(buf, "gatewaydomain");
764 case 3: strcpy(buf, "smarthost");
771 * Internet mail configuration
773 void do_internet_configuration(void) {
783 sprintf(buf, "CONF getsys|%s", INTERNETCFG);
786 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
788 if (num_recs == 1) recs = malloc(sizeof(char *));
789 else recs = realloc(recs, (sizeof(char *)) * num_recs);
790 recs[num_recs-1] = malloc(256);
791 strcpy(recs[num_recs-1], buf);
798 printf(" Host or domain ");
799 printf(" Record type \n");
802 printf("-------------------------------------------------- ");
803 printf("--------------------\n");
804 for (i=0; i<num_recs; ++i) {
807 extract(buf, recs[i], 0);
809 printf("%-50s ", buf);
810 extract(buf, recs[i], 1);
811 color(BRIGHT_MAGENTA);
812 printf("%-20s\n", buf);
816 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
821 recs = malloc(sizeof(char *));
822 else recs = realloc(recs,
823 (sizeof(char *)) * num_recs);
824 newprompt("Enter host name: ",
827 get_inet_rec_type(&buf[strlen(buf)]);
828 recs[num_recs-1] = strdup(buf);
831 i = intprompt("Delete which one",
835 for (j=i; j<num_recs; ++j)
839 sprintf(buf, "CONF putsys|%s",
844 for (i=0; i<num_recs; ++i) {
850 printf("%s\n", &buf[4]);
855 quitting = boolprompt(
856 "Quit without saving", 0);
861 } while (quitting == 0);
864 for (i=0; i<num_recs; ++i) free(recs[i]);