3 * More client-side support functions.
4 * Unlike routines.c, some of these DO use global variables.
11 #include <sys/types.h>
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
23 # include <sys/time.h>
35 #include "routines2.h"
44 void interr(int errnum);
45 void strprompt(char *prompt, char *str, int len);
46 void newprompt(char *prompt, char *str, int len);
47 void sttybbs(int cmd);
49 void serv_write(char *buf, int nbytes);
50 int haschar(char *st, int ch);
51 void progress(long int curr, long int cmax);
55 extern char tempdir[];
56 extern char *axdefs[7];
57 extern long highest_msg_read;
58 extern long maxmsgnum;
59 extern unsigned room_flags;
60 extern int screenwidth;
63 int eopen(char *name, int mode)
66 ret = open(name, mode);
68 fprintf(stderr, "Cannot open file '%s', mode=%d, errno=%d\n",
76 int room_prompt(int qrflags)
77 { /* return proper room prompt character */
80 if (qrflags & QR_DIRECTORY)
82 if ((a == ']') && (qrflags & QR_NETWORK))
84 if ((a == '>') && (qrflags & QR_NETWORK))
90 { /* register with name and address */
100 char tmpcountry[SIZ];
106 strcpy(tmpstate, "");
108 strcpy(tmpphone, "");
109 strcpy(tmpemail, "");
110 strcpy(tmpcountry, "");
112 serv_puts("GREG _SELF_");
116 while (serv_gets(buf), strcmp(buf, "000")) {
118 strcpy(tmpname, buf);
120 strcpy(tmpaddr, buf);
122 strcpy(tmpcity, buf);
124 strcpy(tmpstate, buf);
128 strcpy(tmpphone, buf);
130 strcpy(tmpemail, buf);
132 strcpy(tmpcountry, buf);
136 strprompt("REAL name", tmpname, 29);
137 strprompt("Address", tmpaddr, 24);
138 strprompt("City/town", tmpcity, 14);
139 strprompt("State/province", tmpstate, 2);
140 strprompt("ZIP/Postal Code", tmpzip, 10);
141 strprompt("Country", tmpcountry, 31);
142 strprompt("Telephone number", tmpphone, 14);
143 strprompt("Email address", tmpemail, 31);
145 /* now send the registration info back to the server */
149 printf("%s\n", &buf[4]);
159 serv_puts(tmpcountry);
165 { /* make all messages old in current room */
167 serv_puts("SLRP HIGHEST");
170 printf("%s\n", &buf[4]);
174 * only make messages old in this room that have been read
179 sprintf(buf, "SLRP %ld", highest_msg_read);
183 printf("%s\n", &buf[4]);
188 * This routine completes a client upload
190 void do_upload(int fd)
194 long transmitted_bytes, total_bytes;
198 /* learn the size of the file */
199 total_bytes = lseek(fd, 0L, 2);
202 transmitted_bytes = 0L;
203 progress(transmitted_bytes, total_bytes);
205 bytes_to_send = read(fd, tbuf, 4096);
206 if (bytes_to_send > 0) {
207 sprintf(buf, "WRIT %d", bytes_to_send);
211 bytes_expected = atoi(&buf[4]);
212 serv_write(tbuf, bytes_expected);
214 printf("%s\n", &buf[4]);
217 transmitted_bytes = transmitted_bytes + (long) bytes_to_send;
218 progress(transmitted_bytes, total_bytes);
219 } while (bytes_to_send > 0);
221 /* close the upload file, locally and at the server */
225 printf("%s\n", &buf[4]);
230 * client-based uploads (for users with their own clientware)
232 void cli_upload(void)
241 if ((room_flags & QR_UPLOAD) == 0) {
242 printf("*** You cannot upload to this room.\n");
245 newprompt("File to be uploaded: ", flnm, 55);
246 fd = open(flnm, O_RDONLY);
248 printf("Cannot open '%s': %s\n", flnm, strerror(errno));
251 printf("Enter a description of this file:\n");
252 newprompt(": ", desc, 75);
254 /* keep generating filenames in hope of finding a unique one */
258 return; /* fail if tried 10 times */
260 while ((strlen(buf) > 0) && (haschar(buf, '/')))
261 strcpy(buf, &buf[1]);
263 sprintf(&buf[strlen(buf)], "%d", a);
264 sprintf(tbuf, "UOPN %s|%s", buf, desc);
268 printf("%s\n", &buf[4]);
270 } while (buf[0] != '2');
272 /* at this point we have an open upload file at the server */
278 * Function used for various image upload commands
280 void cli_image_upload(char *keyname)
286 sprintf(buf, "UIMG 0|%s", keyname);
290 printf("%s\n", &buf[4]);
293 newprompt("Image file to be uploaded: ", flnm, 55);
294 fd = open(flnm, O_RDONLY);
296 printf("Cannot open '%s': %s\n", flnm, strerror(errno));
299 sprintf(buf, "UIMG 1|%s", keyname);
303 printf("%s\n", &buf[4]);
311 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
314 { /* c = upload mode */
324 if ((room_flags & QR_UPLOAD) == 0) {
325 printf("*** You cannot upload to this room.\n");
328 /* we don't need a filename when receiving batch y/z modem */
329 if ((c == 2) || (c == 3))
332 newprompt("Enter filename: ", flnm, 15);
334 for (a = 0; a < strlen(flnm); ++a)
335 if ((flnm[a] == '/') || (flnm[a] == '\\') || (flnm[a] == '>')
336 || (flnm[a] == '?') || (flnm[a] == '*')
337 || (flnm[a] == ';') || (flnm[a] == '&'))
340 newprompt("Enter a short description of the file:\n: ", desc, 150);
342 /* create a temporary directory... */
343 if (mkdir(tempdir, 0700) != 0) {
344 printf("*** Could not create temporary directory %s: %s\n",
345 tempdir, strerror(errno));
348 /* now do the transfer ... in a separate process */
355 printf("Receiving %s - press Ctrl-D to end.\n", flnm);
356 fp = fopen(flnm, "w");
372 execlp("rx", "rx", flnm, NULL);
376 execlp("rb", "rb", NULL);
380 execlp("rz", "rz", NULL);
386 } while ((b != xfer_pid) && (b != (-1)));
390 printf("\r*** Transfer unsuccessful.\n");
394 printf("\r*** Transfer successful. Sending file(s) to server...\n");
395 sprintf(buf, "cd %s; ls", tempdir);
396 lsfp = popen(buf, "r");
398 while (fgets(flnm, sizeof flnm, lsfp) != NULL) {
399 flnm[strlen(flnm) - 1] = 0;
400 sprintf(buf, "%s/%s", tempdir, flnm);
401 fd = open(buf, O_RDONLY);
405 sprintf(buf, "UOPN %s|%s", flnm, desc);
407 sprintf(&buf[strlen(buf)],
412 } while ((buf[0] != '2') && (a < 100));
415 a = read(fd, tbuf, 4096);
417 sprintf(buf, "WRIT %d", a);
427 printf("%s\n", &buf[4]);
438 void val_user(char *user, int do_validate)
445 sprintf(cmd, "GREG %s", user);
454 printf("User #%s - %s ", buf, &cmd[4]);
456 printf("PW: %s\n", buf);
475 } while (strcmp(buf, "000"));
476 printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
478 printf("%-30s\n%s\n", user, &cmd[4]);
482 /* now set the access level */
483 ax = intprompt("Access level", ax, 0, 6);
484 sprintf(cmd, "VALI %s|%d", user, ax);
488 printf("%s\n", &cmd[4]);
495 { /* validate new users */
506 printf("%s\n", &cmd[4]);
508 extract(buf, cmd, 0);
509 val_user(&buf[4], 1);
511 } while (finished == 0);
520 signal(SIGINT, SIG_DFL);
521 signal(SIGQUIT, SIG_DFL);
522 execlp(getenv("SHELL"), getenv("SHELL"), NULL);
523 printf("Could not open a shell: %s\n", strerror(errno));
528 } while ((a != b) && (a != (-1)));
533 * <.A>ide <F>ile <D>elete command
535 void deletefile(void)
540 newprompt("Filename: ", filename, 31);
541 if (strlen(filename) == 0)
543 sprintf(cmd, "DELF %s", filename);
546 printf("%s\n", &cmd[4]);
550 * <.A>ide <F>ile <S>end command
552 void netsendfile(void)
554 char filename[32], destsys[20], cmd[SIZ];
556 newprompt("Filename: ", filename, 31);
557 if (strlen(filename) == 0)
559 newprompt("System to send to: ", destsys, 19);
560 sprintf(cmd, "NETF %s|%s", filename, destsys);
563 printf("%s\n", &cmd[4]);
568 * <.A>ide <F>ile <M>ove command
573 char newroom[ROOMNAMELEN];
576 newprompt("Filename: ", filename, 63);
577 if (strlen(filename) == 0)
579 newprompt("Enter target room: ", newroom, ROOMNAMELEN - 1);
581 sprintf(cmd, "MOVF %s|%s", filename, newroom);
584 printf("%s\n", &cmd[4]);
589 * list of users who have filled out a bio
599 pprintf("%s\n", &buf[4]);
602 while (serv_gets(buf), strcmp(buf, "000")) {
603 if ((pos + strlen(buf) + 5) > screenwidth) {
607 pprintf("%s, ", buf);
608 pos = pos + strlen(buf) + 2;
610 pprintf("%c%c \n\n", 8, 8);
623 newprompt("Read bio for who ('?' for list) : ", who, 25);
625 if (!strcmp(who, "?"))
627 } while (!strcmp(who, "?"));
628 sprintf(buf, "RBIO %s", who);
632 pprintf("%s\n", &buf[4]);
635 while (serv_gets(buf), strcmp(buf, "000")) {
636 pprintf("%s\n", buf);
642 * General system configuration command
644 void do_system_configuration(void)
649 int expire_value = 0;
653 /* Clear out the config buffers */
654 memset(&sc[0][0], 0, sizeof(sc));
656 /* Fetch the current config */
657 serv_puts("CONF get");
661 while (serv_gets(buf), strcmp(buf, "000")) {
663 strcpy(&sc[a][0], buf);
667 /* Fetch the expire policy (this will silently fail on old servers,
668 * resulting in "default" policy)
670 serv_puts("GPEX site");
673 expire_mode = extract_int(&buf[4], 0);
674 expire_value = extract_int(&buf[4], 1);
678 /* Identification parameters */
680 strprompt("Node name", &sc[0][0], 15);
681 strprompt("Fully qualified domain name", &sc[1][0], 63);
682 strprompt("Human readable node name", &sc[2][0], 20);
683 strprompt("Modem dialup number", &sc[3][0], 15);
684 strprompt("Geographic location of this system", &sc[12][0], 31);
685 strprompt("Name of system administrator", &sc[13][0], 25);
686 strprompt("Paginator prompt", &sc[10][0], 79);
687 /* strprompt("Default moderation filter for new users", &sc[25][0], 4); */
689 /* Security parameters */
691 sprintf(&sc[7][0], "%d", (boolprompt(
692 "Require registration for new users",
694 strprompt("Initial access level for new users", &sc[6][0], 1);
695 strprompt("Access level required to create rooms", &sc[19][0], 1);
696 sprintf(&sc[4][0], "%d", (boolprompt(
697 "Automatically give room aide privs to a user who creates a private room",
700 sprintf(&sc[8][0], "%d", (boolprompt(
701 "Automatically move problem user messages to twit room",
704 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
705 sprintf(&sc[11][0], "%d", (boolprompt(
706 "Restrict Internet mail to only those with that privilege",
708 sprintf(&sc[26][0], "%d", (boolprompt(
709 "Allow Aides to Zap (forget) rooms",
712 if (strlen(&sc[18][0]) > 0) logpages = 1;
714 logpages = boolprompt("Log all pages", logpages);
716 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
725 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
726 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
727 strprompt("Maximum message length", &sc[20][0], 20);
728 strprompt("Minimum number of worker threads", &sc[21][0], 3);
729 strprompt("Maximum number of worker threads", &sc[22][0], 3);
730 strprompt("Server-to-server networking password", &sc[15][0], 19);
731 strprompt("SMTP server port (-1 to disable)", &sc[24][0], 5);
732 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
733 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
736 /* Expiry settings */
737 strprompt("Default user purge time (days)", &sc[16][0], 5);
738 strprompt("Default room purge time (days)", &sc[17][0], 5);
740 /* Angels and demons dancing in my head... */
742 sprintf(buf, "%d", expire_mode);
743 strprompt("System default message expire policy (? for list)",
747 printf("1. Never automatically expire messages\n");
748 printf("2. Expire by message count\n");
749 printf("3. Expire by message age\n");
751 } while ((buf[0] < 49) || (buf[0] > 51));
752 expire_mode = buf[0] - 48;
754 /* ...lunatics and monsters underneath my bed */
755 if (expire_mode == 2) {
756 sprintf(buf, "%d", expire_value);
757 strprompt("Keep how many messages online?", buf, 10);
758 expire_value = atol(buf);
760 if (expire_mode == 3) {
761 sprintf(buf, "%d", expire_value);
762 strprompt("Keep messages for how many days?", buf, 10);
763 expire_value = atol(buf);
766 printf("Save this configuration? ");
768 serv_puts("CONF set");
771 for (a = 0; a < 28; ++a)
772 serv_puts(&sc[a][0]);
775 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
776 expire_mode, expire_value);
784 * support function for do_internet_configuration()
786 void get_inet_rec_type(char *buf) {
789 keyopt(" <1> localhost (Alias for this computer)\n");
790 keyopt(" <2> gateway domain (Domain for all Citadel systems)\n");
791 keyopt(" <3> smart-host (Forward all outbound mail to this host)\n");
792 sel = intprompt("Which one", 1, 1, 3);
794 case 1: strcpy(buf, "localhost");
796 case 2: strcpy(buf, "gatewaydomain");
798 case 3: strcpy(buf, "smarthost");
805 * Internet mail configuration
807 void do_internet_configuration(void) {
817 sprintf(buf, "CONF getsys|%s", INTERNETCFG);
820 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
822 if (num_recs == 1) recs = malloc(sizeof(char *));
823 else recs = realloc(recs, (sizeof(char *)) * num_recs);
824 recs[num_recs-1] = malloc(SIZ);
825 strcpy(recs[num_recs-1], buf);
832 printf(" Host or domain ");
833 printf(" Record type \n");
836 printf("-------------------------------------------------- ");
837 printf("--------------------\n");
838 for (i=0; i<num_recs; ++i) {
841 extract(buf, recs[i], 0);
843 printf("%-50s ", buf);
844 extract(buf, recs[i], 1);
845 color(BRIGHT_MAGENTA);
846 printf("%-20s\n", buf);
850 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
855 recs = malloc(sizeof(char *));
856 else recs = realloc(recs,
857 (sizeof(char *)) * num_recs);
858 newprompt("Enter host name: ",
861 get_inet_rec_type(&buf[strlen(buf)]);
862 recs[num_recs-1] = strdup(buf);
865 i = intprompt("Delete which one",
869 for (j=i; j<num_recs; ++j)
873 sprintf(buf, "CONF putsys|%s",
878 for (i=0; i<num_recs; ++i) {
884 printf("%s\n", &buf[4]);
889 quitting = boolprompt(
890 "Quit without saving", 0);
895 } while (quitting == 0);
898 for (i=0; i<num_recs; ++i) free(recs[i]);