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 void extract(char *dest, char *source, int parmnum);
38 int haschar(char *st, int ch);
39 void progress(long int curr, long int cmax);
40 void citedit(FILE *fp, long int base_pos);
44 extern char tempdir[];
45 extern char *axdefs[7];
46 extern long highest_msg_read;
47 extern long maxmsgnum;
48 extern unsigned room_flags;
49 extern int screenwidth;
52 int eopen(char *name, int mode)
55 ret = open(name,mode);
57 fprintf(stderr,"Cannot open file '%s', mode=%d, errno=%d\n",
65 int room_prompt(int qrflags) /* return proper room prompt character */
69 if (qrflags&QR_DIRECTORY) a=']';
70 if ((a==']')&&(qrflags&QR_NETWORK)) a='}';
71 if ((a=='>')&&(qrflags&QR_NETWORK)) a=')';
75 void entregis(void) /* register with name and address */
96 serv_puts("GREG _SELF_");
100 while (serv_gets(buf), strcmp(buf,"000")) {
101 if (a==2) strcpy(tmpname,buf);
102 if (a==3) strcpy(tmpaddr,buf);
103 if (a==4) strcpy(tmpcity,buf);
104 if (a==5) strcpy(tmpstate,buf);
105 if (a==6) strcpy(tmpzip,buf);
106 if (a==7) strcpy(tmpphone,buf);
107 if (a==9) strcpy(tmpemail,buf);
112 strprompt("REAL name",tmpname,29);
113 strprompt("Address",tmpaddr,24);
114 strprompt("City/town",tmpcity,14);
115 strprompt("State",tmpstate,2);
116 strprompt("ZIP Code",tmpzip,10);
117 strprompt("Telephone number",tmpphone,14);
118 strprompt("Email address",tmpemail,31);
120 /* now send the registration info back to the server */
124 printf("%s\n",&buf[4]);
138 void updatels(void) { /* make all messages old in current room */
140 serv_puts("SLRP HIGHEST");
142 if (buf[0]!='2') printf("%s\n",&buf[4]);
145 void updatelsa(void) { /* only make messages old in this room that have been read */
147 sprintf(buf,"SLRP %ld",highest_msg_read);
150 if (buf[0]!='2') printf("%s\n",&buf[4]);
155 * This routine completes a client upload
157 void do_upload(int fd) {
160 long transmitted_bytes, total_bytes;
164 /* learn the size of the file */
165 total_bytes = lseek(fd,0L,2);
168 transmitted_bytes = 0L;
169 progress(transmitted_bytes,total_bytes);
171 bytes_to_send = read(fd,tbuf,4096);
172 if (bytes_to_send>0) {
173 sprintf(buf,"WRIT %d",bytes_to_send);
177 bytes_expected = atoi(&buf[4]);
178 serv_write(tbuf,bytes_expected);
181 printf("%s\n",&buf[4]);
184 transmitted_bytes = transmitted_bytes + (long)bytes_to_send;
185 progress(transmitted_bytes, total_bytes);
186 } while (bytes_to_send > 0);
188 /* close the upload file, locally and at the server */
192 printf("%s\n",&buf[4]);
197 * client-based uploads (for users with their own clientware)
199 void cli_upload(void) {
207 if ((room_flags & QR_UPLOAD) == 0) {
208 printf("*** You cannot upload to this room.\n");
212 newprompt("File to be uploaded: ",flnm,55);
213 fd = open(flnm,O_RDONLY);
215 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
218 printf("Enter a description of this file:\n");
219 newprompt(": ",desc,75);
221 /* keep generating filenames in hope of finding a unique one */
224 if (a==10) return; /* fail if tried 10 times */
226 while ((strlen(buf)>0)&&(haschar(buf,'/')))
228 if (a>0) sprintf(&buf[strlen(buf)],"%d",a);
229 sprintf(tbuf,"UOPN %s|%s",buf,desc);
232 if (buf[0]!='2') printf("%s\n",&buf[4]);
234 } while (buf[0]!='2');
236 /* at this point we have an open upload file at the server */
242 * Function used for various image upload commands
244 void cli_image_upload(char *keyname) {
249 sprintf(buf, "UIMG 0|%s", keyname);
253 printf("%s\n", &buf[4]);
257 newprompt("Image file to be uploaded: ",flnm,55);
258 fd = open(flnm,O_RDONLY);
260 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
264 sprintf(buf, "UIMG 1|%s", keyname);
268 printf("%s\n", &buf[4]);
277 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
279 void upload(int c) /* c = upload mode */
290 if ((room_flags & QR_UPLOAD) == 0) {
291 printf("*** You cannot upload to this room.\n");
295 /* we don't need a filename when receiving batch y/z modem */
296 if ((c==2)||(c==3)) strcpy(flnm,"x");
297 else newprompt("Enter filename: ",flnm,15);
299 for (a=0; a<strlen(flnm); ++a)
300 if ( (flnm[a]=='/') || (flnm[a]=='\\') || (flnm[a]=='>')
301 || (flnm[a]=='?') || (flnm[a]=='*')
302 || (flnm[a]==';') || (flnm[a]=='&') ) flnm[a]='_';
304 newprompt("Enter a short description of the file:\n: ",desc,150);
306 /* create a temporary directory... */
307 if (mkdir(tempdir,0700) != 0) {
308 printf("*** Could not create temporary directory %s: %s\n",
309 tempdir,strerror(errno));
313 /* now do the transfer ... in a separate process */
320 printf("Receiving %s - press Ctrl-D to end.\n",flnm);
321 fp = fopen(flnm,"w");
336 execlp("rx","rx",flnm,NULL);
340 execlp("rb","rb",NULL);
344 execlp("rz","rz",NULL);
350 } while ((b!=xfer_pid)&&(b!=(-1)));
354 printf("\r*** Transfer unsuccessful.\n");
359 printf("\r*** Transfer successful. Sending file(s) to server...\n");
360 sprintf(buf,"cd %s; ls",tempdir);
361 lsfp = popen(buf,"r");
363 while (fgets(flnm,256,lsfp)!=NULL) {
364 flnm[strlen(flnm)-1] = 0;
365 sprintf(buf,"%s/%s",tempdir,flnm);
366 fd = open(buf,O_RDONLY);
370 sprintf(buf,"UOPN %s|%s",flnm,desc);
371 if (a>0) sprintf(&buf[strlen(buf)],
376 } while((buf[0]!='2')&&(a<100));
377 if (buf[0]=='2') do {
378 a=read(fd,tbuf,4096);
380 sprintf(buf,"WRIT %d",a);
390 printf("%s\n",&buf[4]);
402 void val_user(char *user, int do_validate)
409 sprintf(cmd, "GREG %s", user);
417 if (a==1) printf("User #%s - %s ", buf, &cmd[4]);
418 if (a==2) printf("PW: %s\n",buf);
419 if (a==3) printf("%s\n",buf);
420 if (a==4) printf("%s\n",buf);
421 if (a==5) printf("%s, ",buf);
422 if (a==6) printf("%s ",buf);
423 if (a==7) printf("%s\n",buf);
424 if (a==8) printf("%s\n",buf);
425 if (a==9) ax=atoi(buf);
426 if (a==10) printf("%s\n",buf);
427 } while(strcmp(buf,"000"));
428 printf("Current access level: %d (%s)\n",ax,axdefs[ax]);
431 printf("%-30s\n%s\n",user,&cmd[4]);
435 /* now set the access level */
436 ax = intprompt("Access level", ax, 0, 6);
437 sprintf(cmd,"VALI %s|%d",user,ax);
440 if (cmd[0]!='2') printf("%s\n",&cmd[4]);
446 void validate(void) { /* validate new users */
454 if (cmd[0]!='3') finished = 1;
455 if (cmd[0]=='2') printf("%s\n",&cmd[4]);
457 extract(buf, cmd, 0);
458 val_user(&buf[4], 1);
460 } while(finished==0);
463 void subshell(void) {
468 signal(SIGINT,SIG_DFL);
469 signal(SIGQUIT,SIG_DFL);
470 execlp(getenv("SHELL"),getenv("SHELL"),NULL);
471 printf("Could not open a shell: %s\n", strerror(errno));
476 } while ((a!=b)&&(a!=(-1)));
481 * <.A>ide <F>ile <D>elete command
483 void deletefile(void) {
487 newprompt("Filename: ",filename,31);
488 if (strlen(filename)==0) return;
489 sprintf(cmd,"DELF %s",filename);
492 printf("%s\n",&cmd[4]);
496 * <.A>ide <F>ile <S>end command
498 void netsendfile(void) {
499 char filename[32],destsys[20],cmd[256];
501 newprompt("Filename: ",filename,31);
502 if (strlen(filename)==0) return;
503 newprompt("System to send to: ",destsys,19);
504 sprintf(cmd,"NETF %s|%s",filename,destsys);
507 printf("%s\n",&cmd[4]);
512 * <.A>ide <F>ile <M>ove command
514 void movefile(void) {
516 char newroom[ROOMNAMELEN];
519 newprompt("Filename: ",filename,63);
520 if (strlen(filename)==0) return;
521 newprompt("Enter target room: ",newroom,ROOMNAMELEN-1);
523 sprintf(cmd,"MOVF %s|%s",filename,newroom);
526 printf("%s\n",&cmd[4]);
531 * list of users who have filled out a bio
533 void list_bio(void) {
540 printf("%s\n",&buf[4]);
543 while (serv_gets(buf), strcmp(buf,"000")) {
544 if ((pos+strlen(buf)+5)>screenwidth) {
549 pos = pos + strlen(buf) + 2;
551 printf("%c%c \n\n",8,8);
558 void read_bio(void) {
563 newprompt("Read bio for who ('?' for list) : ",who,25);
565 if (!strcmp(who,"?")) list_bio();
566 } while(!strcmp(who,"?"));
567 sprintf(buf,"RBIO %s",who);
571 printf("%s\n",&buf[4]);
574 while (serv_gets(buf), strcmp(buf,"000")) {
581 * General system configuration command
583 void do_system_configuration(void) {
587 int expire_value = 0;
590 /* Clear out the config buffers */
591 memset(&sc[0][0], 0, sizeof(sc));
593 /* Fetch the current config */
594 serv_puts("CONF get");
598 while (serv_gets(buf), strcmp(buf, "000")) {
599 if (a<19) strcpy(&sc[a][0], buf);
604 /* Fetch the expire policy (this will silently fail on old servers,
605 * resulting in "default" policy)
607 serv_puts("GPEX site");
610 expire_mode = extract_int(&buf[4], 0);
611 expire_value = extract_int(&buf[4], 1);
614 strprompt("Node name", &sc[0][0], 15);
615 strprompt("Fully qualified domain name", &sc[1][0], 63);
616 strprompt("Human readable node name", &sc[2][0], 20);
617 strprompt("Modem dialup number", &sc[3][0], 15);
619 sprintf(&sc[4][0], "%d", (boolprompt(
620 "Automatically give room aide privs to a user who creates a private room",
623 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
624 strprompt("Initial access level for new users", &sc[6][0], 1);
626 sprintf(&sc[7][0], "%d", (boolprompt(
627 "Require registration for new users",
630 sprintf(&sc[8][0], "%d", (boolprompt(
631 "Automatically move problem user messages to twit room",
634 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
635 strprompt("Paginator prompt", &sc[10][0], 79);
637 sprintf(&sc[11][0], "%d", (boolprompt(
638 "Restrict Internet mail to only those with that privilege",
641 strprompt("Geographic location of this system", &sc[12][0], 31);
642 strprompt("Name of system administrator", &sc[13][0], 25);
643 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
644 strprompt("Server-to-server networking password", &sc[15][0], 19);
645 strprompt("Default user purge time (days)", &sc[16][0], 5);
646 strprompt("Default room purge time (days)", &sc[17][0], 5);
647 strprompt("Name of room to log pages", &sc[18][0], ROOMNAMELEN);
649 /* Angels and demons dancing in my head... */
651 sprintf(buf, "%d", expire_mode);
652 strprompt("System default message expire policy (? for list)",
656 printf("1. Never automatically expire messages\n");
657 printf("2. Expire by message count\n");
658 printf("3. Expire by message age\n");
660 } while((buf[0]<49)||(buf[0]>51));
661 expire_mode = buf[0] - 48;
663 /* ...lunatics and monsters underneath my bed */
664 if (expire_mode == 2) {
665 sprintf(buf, "%d", expire_value);
666 strprompt("Keep how many messages online?", buf, 10);
667 expire_value = atol(buf);
670 if (expire_mode == 3) {
671 sprintf(buf, "%d", expire_value);
672 strprompt("Keep messages for how many days?", buf, 10);
673 expire_value = atol(buf);
677 printf("Save this configuration? ");
679 serv_puts("CONF set");
682 for (a=0; a<19; ++a) serv_puts(&sc[a][0]);
686 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
687 expire_mode, expire_value);