1 /* More Citadel/UX routines...
2 * unlike routines.c, some of these DO use global variables.
20 #include "routines2.h"
24 void interr(int errnum);
25 void strprompt(char *prompt, char *str, int len);
26 void newprompt(char *prompt, char *str, int len);
27 void sttybbs(int cmd);
29 int ka_wait(pid_t *kstatus);
30 void serv_write(char *buf, int nbytes);
31 void extract(char *dest, char *source, int parmnum);
32 int haschar(char *st, int ch);
33 void progress(long int curr, long int cmax);
34 void citedit(FILE *fp, long int base_pos);
38 extern char tempdir[];
39 extern char *axdefs[7];
40 extern long highest_msg_read;
41 extern long maxmsgnum;
42 extern unsigned room_flags;
43 extern int screenwidth;
46 int eopen(char *name, int mode)
49 ret = open(name,mode);
51 fprintf(stderr,"Cannot open file '%s', mode=%d, errno=%d\n",
59 int room_prompt(int qrflags) /* return proper room prompt character */
63 if (qrflags&QR_DIRECTORY) a=']';
64 if ((a==']')&&(qrflags&QR_NETWORK)) a='}';
65 if ((a=='>')&&(qrflags&QR_NETWORK)) a=')';
69 void entregis(void) /* register with name and address */
90 serv_puts("GREG _SELF_");
94 while (serv_gets(buf), strcmp(buf,"000")) {
95 if (a==2) strcpy(tmpname,buf);
96 if (a==3) strcpy(tmpaddr,buf);
97 if (a==4) strcpy(tmpcity,buf);
98 if (a==5) strcpy(tmpstate,buf);
99 if (a==6) strcpy(tmpzip,buf);
100 if (a==7) strcpy(tmpphone,buf);
101 if (a==9) strcpy(tmpemail,buf);
106 strprompt("REAL name",tmpname,29);
107 strprompt("Address",tmpaddr,24);
108 strprompt("City/town",tmpcity,14);
109 strprompt("State",tmpstate,2);
110 strprompt("ZIP Code",tmpzip,10);
111 strprompt("Telephone number",tmpphone,14);
112 strprompt("Email address",tmpemail,31);
114 /* now send the registration info back to the server */
118 printf("%s\n",&buf[4]);
132 void updatels(void) { /* make all messages old in current room */
134 serv_puts("SLRP HIGHEST");
136 if (buf[0]!='2') printf("%s\n",&buf[4]);
139 void updatelsa(void) { /* only make messages old in this room that have been read */
141 sprintf(buf,"SLRP %ld",highest_msg_read);
144 if (buf[0]!='2') printf("%s\n",&buf[4]);
149 * This routine completes a client upload
151 void do_upload(int fd) {
154 long transmitted_bytes, total_bytes;
158 /* learn the size of the file */
159 total_bytes = lseek(fd,0L,2);
162 transmitted_bytes = 0L;
163 progress(transmitted_bytes,total_bytes);
165 bytes_to_send = read(fd,tbuf,4096);
166 if (bytes_to_send>0) {
167 sprintf(buf,"WRIT %d",bytes_to_send);
171 bytes_expected = atoi(&buf[4]);
172 serv_write(tbuf,bytes_expected);
175 printf("%s\n",&buf[4]);
178 transmitted_bytes = transmitted_bytes + (long)bytes_to_send;
179 progress(transmitted_bytes, total_bytes);
180 } while (bytes_to_send > 0);
182 /* close the upload file, locally and at the server */
186 printf("%s\n",&buf[4]);
191 * client-based uploads (for users with their own clientware)
193 void cli_upload(void) {
201 if ((room_flags & QR_UPLOAD) == 0) {
202 printf("*** You cannot upload to this room.\n");
206 newprompt("File to be uploaded: ",flnm,55);
207 fd = open(flnm,O_RDONLY);
209 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
212 printf("Enter a description of this file:\n");
213 newprompt(": ",desc,75);
215 /* keep generating filenames in hope of finding a unique one */
218 if (a==10) return; /* fail if tried 10 times */
220 while ((strlen(buf)>0)&&(haschar(buf,'/')))
222 if (a>0) sprintf(&buf[strlen(buf)],"%d",a);
223 sprintf(tbuf,"UOPN %s|%s",buf,desc);
226 if (buf[0]!='2') printf("%s\n",&buf[4]);
228 } while (buf[0]!='2');
230 /* at this point we have an open upload file at the server */
236 * Function used for various image upload commands
238 void cli_image_upload(char *keyname) {
243 sprintf(buf, "UIMG 0|%s", keyname);
247 printf("%s\n", &buf[4]);
251 newprompt("Image file to be uploaded: ",flnm,55);
252 fd = open(flnm,O_RDONLY);
254 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
258 sprintf(buf, "UIMG 1|%s", keyname);
262 printf("%s\n", &buf[4]);
271 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
273 void upload(int c) /* c = upload mode */
284 if ((room_flags & QR_UPLOAD) == 0) {
285 printf("*** You cannot upload to this room.\n");
289 /* we don't need a filename when receiving batch y/z modem */
290 if ((c==2)||(c==3)) strcpy(flnm,"x");
291 else newprompt("Enter filename: ",flnm,15);
293 for (a=0; a<strlen(flnm); ++a)
294 if ( (flnm[a]=='/') || (flnm[a]=='\\') || (flnm[a]=='>')
295 || (flnm[a]=='?') || (flnm[a]=='*')
296 || (flnm[a]==';') || (flnm[a]=='&') ) flnm[a]='_';
298 newprompt("Enter a short description of the file:\n: ",desc,150);
300 /* create a temporary directory... */
301 if (mkdir(tempdir,0700) != 0) {
302 printf("*** Could not create temporary directory %s: %s\n",
303 tempdir,strerror(errno));
307 /* now do the transfer ... in a separate process */
314 printf("Receiving %s - press Ctrl-D to end.\n",flnm);
315 fp = fopen(flnm,"w");
330 execlp("rx","rx",flnm,NULL);
334 execlp("rb","rb",NULL);
338 execlp("rz","rz",NULL);
344 } while ((b!=xfer_pid)&&(b!=(-1)));
348 printf("\r*** Transfer unsuccessful.\n");
353 printf("\r*** Transfer successful. Sending file(s) to server...\n");
354 sprintf(buf,"cd %s; ls",tempdir);
355 lsfp = popen(buf,"r");
357 while (fgets(flnm,256,lsfp)!=NULL) {
358 flnm[strlen(flnm)-1] = 0;
359 sprintf(buf,"%s/%s",tempdir,flnm);
360 fd = open(buf,O_RDONLY);
364 sprintf(buf,"UOPN %s|%s",flnm,desc);
365 if (a>0) sprintf(&buf[strlen(buf)],
370 } while((buf[0]!='2')&&(a<100));
371 if (buf[0]=='2') do {
372 a=read(fd,tbuf,4096);
374 sprintf(buf,"WRIT %d",a);
384 printf("%s\n",&buf[4]);
396 void val_user(char *user)
403 sprintf(cmd,"GREG %s",user);
411 if (a==1) printf("User #%s - %s ",
413 if (a==2) printf("PW: %s\n",buf);
414 if (a==3) printf("%s\n",buf);
415 if (a==4) printf("%s\n",buf);
416 if (a==5) printf("%s, ",buf);
417 if (a==6) printf("%s ",buf);
418 if (a==7) printf("%s\n",buf);
419 if (a==8) printf("%s\n",buf);
420 if (a==9) ax=atoi(buf);
421 if (a==10) printf("%s\n",buf);
422 } while(strcmp(buf,"000"));
423 printf("Current access level: %d (%s)\n",ax,axdefs[ax]);
426 printf("%-30s\n%s\n",user,&cmd[4]);
429 /* now set the access level */
430 ax = intprompt("Access level", ax, 0, 6);
431 sprintf(cmd,"VALI %s|%d",user,ax);
434 if (cmd[0]!='2') printf("%s\n",&cmd[4]);
439 void validate(void) { /* validate new users */
447 if (cmd[0]!='3') finished = 1;
448 if (cmd[0]=='2') printf("%s\n",&cmd[4]);
453 } while(finished==0);
456 void subshell(void) {
461 signal(SIGINT,SIG_DFL);
462 signal(SIGQUIT,SIG_DFL);
463 execlp(getenv("SHELL"),getenv("SHELL"),NULL);
464 printf("Could not open a shell: %s\n", strerror(errno));
469 } while ((a!=b)&&(a!=(-1)));
474 * <.A>ide <F>ile <D>elete command
476 void deletefile(void) {
480 newprompt("Filename: ",filename,31);
481 if (strlen(filename)==0) return;
482 sprintf(cmd,"DELF %s",filename);
485 printf("%s\n",&cmd[4]);
489 * <.A>ide <F>ile <S>end command
491 void netsendfile(void) {
492 char filename[32],destsys[20],cmd[256];
494 newprompt("Filename: ",filename,31);
495 if (strlen(filename)==0) return;
496 newprompt("System to send to: ",destsys,19);
497 sprintf(cmd,"NETF %s|%s",filename,destsys);
500 printf("%s\n",&cmd[4]);
505 * <.A>ide <F>ile <M>ove command
507 void movefile(void) {
509 char newroom[ROOMNAMELEN];
512 newprompt("Filename: ",filename,63);
513 if (strlen(filename)==0) return;
514 newprompt("Enter target room: ",newroom,ROOMNAMELEN-1);
516 sprintf(cmd,"MOVF %s|%s",filename,newroom);
519 printf("%s\n",&cmd[4]);
524 * list of users who have filled out a bio
526 void list_bio(void) {
533 printf("%s\n",&buf[4]);
536 while (serv_gets(buf), strcmp(buf,"000")) {
537 if ((pos+strlen(buf)+5)>screenwidth) {
542 pos = pos + strlen(buf) + 2;
544 printf("%c%c \n\n",8,8);
551 void read_bio(void) {
556 newprompt("Read bio for who ('?' for list) : ",who,25);
558 if (!strcmp(who,"?")) list_bio();
559 } while(!strcmp(who,"?"));
560 sprintf(buf,"RBIO %s",who);
564 printf("%s\n",&buf[4]);
567 while (serv_gets(buf), strcmp(buf,"000")) {
574 * General system configuration command
576 void do_system_configuration(void) {
580 int expire_value = 0;
583 /* Clear out the config buffers */
584 bzero(&sc[0][0], sizeof(sc));
586 /* Fetch the current config */
587 serv_puts("CONF get");
591 while (serv_gets(buf), strcmp(buf, "000")) {
592 if (a<18) strcpy(&sc[a][0], buf);
597 /* Fetch the expire policy (this will silently fail on old servers,
598 * resulting in "default" policy)
600 serv_puts("GPEX site");
603 expire_mode = extract_int(&buf[4], 0);
604 expire_value = extract_int(&buf[4], 1);
607 strprompt("Node name", &sc[0][0], 15);
608 strprompt("Fully qualified domain name", &sc[1][0], 63);
609 strprompt("Human readable node name", &sc[2][0], 20);
610 strprompt("Modem dialup number", &sc[3][0], 15);
612 sprintf(&sc[4][0], "%d", (boolprompt(
613 "Automatically give room aide privs to a user who creates a private room",
616 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
617 strprompt("Initial access level for new users", &sc[6][0], 1);
619 sprintf(&sc[7][0], "%d", (boolprompt(
620 "Require registration for new users",
623 sprintf(&sc[8][0], "%d", (boolprompt(
624 "Automatically move promblem user messages to twit room",
627 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
628 strprompt("Paginator prompt", &sc[10][0], 79);
630 sprintf(&sc[11][0], "%d", (boolprompt(
631 "Restrict Internet mail to only those with that privilege",
634 strprompt("Geographic location of this system", &sc[12][0], 31);
635 strprompt("Name of system administrator", &sc[13][0], 25);
636 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
637 strprompt("Server-to-server networking password", &sc[15][0], 19);
638 strprompt("Default user purge time (days)", &sc[16][0], 5);
639 strprompt("Default room purge time (days)", &sc[17][0], 5);
641 /* Angels and demons dancing in my head... */
643 sprintf(buf, "%d", expire_mode);
644 strprompt("System default message expire policy (? for list)",
648 printf("1. Never automatically expire messages\n");
649 printf("2. Expire by message count\n");
650 printf("3. Expire by message age\n");
652 } while((buf[0]<49)||(buf[0]>51));
653 expire_mode = buf[0] - 48;
655 /* ...lunatics and monsters underneath my bed */
656 if (expire_mode == 2) {
657 sprintf(buf, "%d", expire_value);
658 strprompt("Keep how many messages online?", buf, 10);
659 expire_value = atol(buf);
662 if (expire_mode == 3) {
663 sprintf(buf, "%d", expire_value);
664 strprompt("Keep messages for how many days?", buf, 10);
665 expire_value = atol(buf);
669 printf("Save this configuration? ");
671 serv_puts("CONF set");
674 for (a=0; a<18; ++a) serv_puts(&sc[a][0]);
678 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
679 expire_mode, expire_value);