1 /* More Citadel/UX routines...
2 * unlike routines.c, some of these DO use global variables.
20 #include "routines2.h"
25 void interr(int errnum);
26 void strprompt(char *prompt, char *str, int len);
27 void newprompt(char *prompt, char *str, int len);
28 void sttybbs(int cmd);
30 int ka_wait(pid_t *kstatus);
31 void serv_write(char *buf, int nbytes);
32 void extract(char *dest, char *source, int parmnum);
33 int haschar(char *st, int ch);
34 void progress(long int curr, long int cmax);
35 void citedit(FILE *fp, long int base_pos);
39 extern char tempdir[];
40 extern char *axdefs[7];
41 extern long highest_msg_read;
42 extern long maxmsgnum;
43 extern unsigned room_flags;
44 extern int screenwidth;
47 int eopen(char *name, int mode)
50 ret = open(name,mode);
52 fprintf(stderr,"Cannot open file '%s', mode=%d, errno=%d\n",
60 int room_prompt(int qrflags) /* return proper room prompt character */
64 if (qrflags&QR_DIRECTORY) a=']';
65 if ((a==']')&&(qrflags&QR_NETWORK)) a='}';
66 if ((a=='>')&&(qrflags&QR_NETWORK)) a=')';
70 void entregis(void) /* register with name and address */
91 serv_puts("GREG _SELF_");
95 while (serv_gets(buf), strcmp(buf,"000")) {
96 if (a==2) strcpy(tmpname,buf);
97 if (a==3) strcpy(tmpaddr,buf);
98 if (a==4) strcpy(tmpcity,buf);
99 if (a==5) strcpy(tmpstate,buf);
100 if (a==6) strcpy(tmpzip,buf);
101 if (a==7) strcpy(tmpphone,buf);
102 if (a==9) strcpy(tmpemail,buf);
107 strprompt("REAL name",tmpname,29);
108 strprompt("Address",tmpaddr,24);
109 strprompt("City/town",tmpcity,14);
110 strprompt("State",tmpstate,2);
111 strprompt("ZIP Code",tmpzip,10);
112 strprompt("Telephone number",tmpphone,14);
113 strprompt("Email address",tmpemail,31);
115 /* now send the registration info back to the server */
119 printf("%s\n",&buf[4]);
133 void updatels(void) { /* make all messages old in current room */
135 serv_puts("SLRP HIGHEST");
137 if (buf[0]!='2') printf("%s\n",&buf[4]);
140 void updatelsa(void) { /* only make messages old in this room that have been read */
142 sprintf(buf,"SLRP %ld",highest_msg_read);
145 if (buf[0]!='2') printf("%s\n",&buf[4]);
150 * This routine completes a client upload
152 void do_upload(int fd) {
155 long transmitted_bytes, total_bytes;
159 /* learn the size of the file */
160 total_bytes = lseek(fd,0L,2);
163 transmitted_bytes = 0L;
164 progress(transmitted_bytes,total_bytes);
166 bytes_to_send = read(fd,tbuf,4096);
167 if (bytes_to_send>0) {
168 sprintf(buf,"WRIT %d",bytes_to_send);
172 bytes_expected = atoi(&buf[4]);
173 serv_write(tbuf,bytes_expected);
176 printf("%s\n",&buf[4]);
179 transmitted_bytes = transmitted_bytes + (long)bytes_to_send;
180 progress(transmitted_bytes, total_bytes);
181 } while (bytes_to_send > 0);
183 /* close the upload file, locally and at the server */
187 printf("%s\n",&buf[4]);
192 * client-based uploads (for users with their own clientware)
194 void cli_upload(void) {
202 if ((room_flags & QR_UPLOAD) == 0) {
203 printf("*** You cannot upload to this room.\n");
207 newprompt("File to be uploaded: ",flnm,55);
208 fd = open(flnm,O_RDONLY);
210 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
213 printf("Enter a description of this file:\n");
214 newprompt(": ",desc,75);
216 /* keep generating filenames in hope of finding a unique one */
219 if (a==10) return; /* fail if tried 10 times */
221 while ((strlen(buf)>0)&&(haschar(buf,'/')))
223 if (a>0) sprintf(&buf[strlen(buf)],"%d",a);
224 sprintf(tbuf,"UOPN %s|%s",buf,desc);
227 if (buf[0]!='2') printf("%s\n",&buf[4]);
229 } while (buf[0]!='2');
231 /* at this point we have an open upload file at the server */
237 * Function used for various image upload commands
239 void cli_image_upload(char *keyname) {
244 sprintf(buf, "UIMG 0|%s", keyname);
248 printf("%s\n", &buf[4]);
252 newprompt("Image file to be uploaded: ",flnm,55);
253 fd = open(flnm,O_RDONLY);
255 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
259 sprintf(buf, "UIMG 1|%s", keyname);
263 printf("%s\n", &buf[4]);
272 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
274 void upload(int c) /* c = upload mode */
285 if ((room_flags & QR_UPLOAD) == 0) {
286 printf("*** You cannot upload to this room.\n");
290 /* we don't need a filename when receiving batch y/z modem */
291 if ((c==2)||(c==3)) strcpy(flnm,"x");
292 else newprompt("Enter filename: ",flnm,15);
294 for (a=0; a<strlen(flnm); ++a)
295 if ( (flnm[a]=='/') || (flnm[a]=='\\') || (flnm[a]=='>')
296 || (flnm[a]=='?') || (flnm[a]=='*')
297 || (flnm[a]==';') || (flnm[a]=='&') ) flnm[a]='_';
299 newprompt("Enter a short description of the file:\n: ",desc,150);
301 /* create a temporary directory... */
302 if (mkdir(tempdir,0700) != 0) {
303 printf("*** Could not create temporary directory %s: %s\n",
304 tempdir,strerror(errno));
308 /* now do the transfer ... in a separate process */
315 printf("Receiving %s - press Ctrl-D to end.\n",flnm);
316 fp = fopen(flnm,"w");
331 execlp("rx","rx",flnm,NULL);
335 execlp("rb","rb",NULL);
339 execlp("rz","rz",NULL);
345 } while ((b!=xfer_pid)&&(b!=(-1)));
349 printf("\r*** Transfer unsuccessful.\n");
354 printf("\r*** Transfer successful. Sending file(s) to server...\n");
355 sprintf(buf,"cd %s; ls",tempdir);
356 lsfp = popen(buf,"r");
358 while (fgets(flnm,256,lsfp)!=NULL) {
359 flnm[strlen(flnm)-1] = 0;
360 sprintf(buf,"%s/%s",tempdir,flnm);
361 fd = open(buf,O_RDONLY);
365 sprintf(buf,"UOPN %s|%s",flnm,desc);
366 if (a>0) sprintf(&buf[strlen(buf)],
371 } while((buf[0]!='2')&&(a<100));
372 if (buf[0]=='2') do {
373 a=read(fd,tbuf,4096);
375 sprintf(buf,"WRIT %d",a);
385 printf("%s\n",&buf[4]);
397 void val_user(char *user)
404 sprintf(cmd,"GREG %s",user);
412 if (a==1) printf("User #%s - %s ",
414 if (a==2) printf("PW: %s\n",buf);
415 if (a==3) printf("%s\n",buf);
416 if (a==4) printf("%s\n",buf);
417 if (a==5) printf("%s, ",buf);
418 if (a==6) printf("%s ",buf);
419 if (a==7) printf("%s\n",buf);
420 if (a==8) printf("%s\n",buf);
421 if (a==9) ax=atoi(buf);
422 if (a==10) printf("%s\n",buf);
423 } while(strcmp(buf,"000"));
424 printf("Current access level: %d (%s)\n",ax,axdefs[ax]);
427 printf("%-30s\n%s\n",user,&cmd[4]);
430 /* now set the access level */
431 ax = intprompt("Access level", ax, 0, 6);
432 sprintf(cmd,"VALI %s|%d",user,ax);
435 if (cmd[0]!='2') printf("%s\n",&cmd[4]);
440 void validate(void) { /* validate new users */
448 if (cmd[0]!='3') finished = 1;
449 if (cmd[0]=='2') printf("%s\n",&cmd[4]);
454 } while(finished==0);
457 void subshell(void) {
462 signal(SIGINT,SIG_DFL);
463 signal(SIGQUIT,SIG_DFL);
464 execlp(getenv("SHELL"),getenv("SHELL"),NULL);
465 printf("Could not open a shell: %s\n", strerror(errno));
470 } while ((a!=b)&&(a!=(-1)));
475 * <.A>ide <F>ile <D>elete command
477 void deletefile(void) {
481 newprompt("Filename: ",filename,31);
482 if (strlen(filename)==0) return;
483 sprintf(cmd,"DELF %s",filename);
486 printf("%s\n",&cmd[4]);
490 * <.A>ide <F>ile <S>end command
492 void netsendfile(void) {
493 char filename[32],destsys[20],cmd[256];
495 newprompt("Filename: ",filename,31);
496 if (strlen(filename)==0) return;
497 newprompt("System to send to: ",destsys,19);
498 sprintf(cmd,"NETF %s|%s",filename,destsys);
501 printf("%s\n",&cmd[4]);
506 * <.A>ide <F>ile <M>ove command
508 void movefile(void) {
510 char newroom[ROOMNAMELEN];
513 newprompt("Filename: ",filename,63);
514 if (strlen(filename)==0) return;
515 newprompt("Enter target room: ",newroom,ROOMNAMELEN-1);
517 sprintf(cmd,"MOVF %s|%s",filename,newroom);
520 printf("%s\n",&cmd[4]);
525 * list of users who have filled out a bio
527 void list_bio(void) {
534 printf("%s\n",&buf[4]);
537 while (serv_gets(buf), strcmp(buf,"000")) {
538 if ((pos+strlen(buf)+5)>screenwidth) {
543 pos = pos + strlen(buf) + 2;
545 printf("%c%c \n\n",8,8);
552 void read_bio(void) {
557 newprompt("Read bio for who ('?' for list) : ",who,25);
559 if (!strcmp(who,"?")) list_bio();
560 } while(!strcmp(who,"?"));
561 sprintf(buf,"RBIO %s",who);
565 printf("%s\n",&buf[4]);
568 while (serv_gets(buf), strcmp(buf,"000")) {
575 * General system configuration command
577 void do_system_configuration(void) {
581 int expire_value = 0;
584 /* Clear out the config buffers */
585 bzero(&sc[0][0], sizeof(sc));
587 /* Fetch the current config */
588 serv_puts("CONF get");
592 while (serv_gets(buf), strcmp(buf, "000")) {
593 if (a<18) strcpy(&sc[a][0], buf);
598 /* Fetch the expire policy (this will silently fail on old servers,
599 * resulting in "default" policy)
601 serv_puts("GPEX site");
604 expire_mode = extract_int(&buf[4], 0);
605 expire_value = extract_int(&buf[4], 1);
608 strprompt("Node name", &sc[0][0], 15);
609 strprompt("Fully qualified domain name", &sc[1][0], 63);
610 strprompt("Human readable node name", &sc[2][0], 20);
611 strprompt("Modem dialup number", &sc[3][0], 15);
613 sprintf(&sc[4][0], "%d", (boolprompt(
614 "Automatically give room aide privs to a user who creates a private room",
617 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
618 strprompt("Initial access level for new users", &sc[6][0], 1);
620 sprintf(&sc[7][0], "%d", (boolprompt(
621 "Require registration for new users",
624 sprintf(&sc[8][0], "%d", (boolprompt(
625 "Automatically move problem user messages to twit room",
628 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
629 strprompt("Paginator prompt", &sc[10][0], 79);
631 sprintf(&sc[11][0], "%d", (boolprompt(
632 "Restrict Internet mail to only those with that privilege",
635 strprompt("Geographic location of this system", &sc[12][0], 31);
636 strprompt("Name of system administrator", &sc[13][0], 25);
637 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
638 strprompt("Server-to-server networking password", &sc[15][0], 19);
639 strprompt("Default user purge time (days)", &sc[16][0], 5);
640 strprompt("Default room purge time (days)", &sc[17][0], 5);
642 /* Angels and demons dancing in my head... */
644 sprintf(buf, "%d", expire_mode);
645 strprompt("System default message expire policy (? for list)",
649 printf("1. Never automatically expire messages\n");
650 printf("2. Expire by message count\n");
651 printf("3. Expire by message age\n");
653 } while((buf[0]<49)||(buf[0]>51));
654 expire_mode = buf[0] - 48;
656 /* ...lunatics and monsters underneath my bed */
657 if (expire_mode == 2) {
658 sprintf(buf, "%d", expire_value);
659 strprompt("Keep how many messages online?", buf, 10);
660 expire_value = atol(buf);
663 if (expire_mode == 3) {
664 sprintf(buf, "%d", expire_value);
665 strprompt("Keep messages for how many days?", buf, 10);
666 expire_value = atol(buf);
670 printf("Save this configuration? ");
672 serv_puts("CONF set");
675 for (a=0; a<18; ++a) serv_puts(&sc[a][0]);
679 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
680 expire_mode, expire_value);