1 /* More Citadel/UX routines...
2 * unlike routines.c, some of these DO use global variables.
20 #include "routines2.h"
26 void interr(int errnum);
27 void strprompt(char *prompt, char *str, int len);
28 void newprompt(char *prompt, char *str, int len);
29 void sttybbs(int cmd);
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, int do_validate)
404 sprintf(cmd, "GREG %s", user);
412 if (a==1) printf("User #%s - %s ", buf, &cmd[4]);
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]);
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]);
441 void validate(void) { /* validate new users */
449 if (cmd[0]!='3') finished = 1;
450 if (cmd[0]=='2') printf("%s\n",&cmd[4]);
452 extract(buf, cmd, 0);
453 val_user(&buf[4], 1);
455 } while(finished==0);
458 void subshell(void) {
463 signal(SIGINT,SIG_DFL);
464 signal(SIGQUIT,SIG_DFL);
465 execlp(getenv("SHELL"),getenv("SHELL"),NULL);
466 printf("Could not open a shell: %s\n", strerror(errno));
471 } while ((a!=b)&&(a!=(-1)));
476 * <.A>ide <F>ile <D>elete command
478 void deletefile(void) {
482 newprompt("Filename: ",filename,31);
483 if (strlen(filename)==0) return;
484 sprintf(cmd,"DELF %s",filename);
487 printf("%s\n",&cmd[4]);
491 * <.A>ide <F>ile <S>end command
493 void netsendfile(void) {
494 char filename[32],destsys[20],cmd[256];
496 newprompt("Filename: ",filename,31);
497 if (strlen(filename)==0) return;
498 newprompt("System to send to: ",destsys,19);
499 sprintf(cmd,"NETF %s|%s",filename,destsys);
502 printf("%s\n",&cmd[4]);
507 * <.A>ide <F>ile <M>ove command
509 void movefile(void) {
511 char newroom[ROOMNAMELEN];
514 newprompt("Filename: ",filename,63);
515 if (strlen(filename)==0) return;
516 newprompt("Enter target room: ",newroom,ROOMNAMELEN-1);
518 sprintf(cmd,"MOVF %s|%s",filename,newroom);
521 printf("%s\n",&cmd[4]);
526 * list of users who have filled out a bio
528 void list_bio(void) {
535 printf("%s\n",&buf[4]);
538 while (serv_gets(buf), strcmp(buf,"000")) {
539 if ((pos+strlen(buf)+5)>screenwidth) {
544 pos = pos + strlen(buf) + 2;
546 printf("%c%c \n\n",8,8);
553 void read_bio(void) {
558 newprompt("Read bio for who ('?' for list) : ",who,25);
560 if (!strcmp(who,"?")) list_bio();
561 } while(!strcmp(who,"?"));
562 sprintf(buf,"RBIO %s",who);
566 printf("%s\n",&buf[4]);
569 while (serv_gets(buf), strcmp(buf,"000")) {
576 * General system configuration command
578 void do_system_configuration(void) {
582 int expire_value = 0;
585 /* Clear out the config buffers */
586 memset(&sc[0][0], 0, sizeof(sc));
588 /* Fetch the current config */
589 serv_puts("CONF get");
593 while (serv_gets(buf), strcmp(buf, "000")) {
594 if (a<19) strcpy(&sc[a][0], buf);
599 /* Fetch the expire policy (this will silently fail on old servers,
600 * resulting in "default" policy)
602 serv_puts("GPEX site");
605 expire_mode = extract_int(&buf[4], 0);
606 expire_value = extract_int(&buf[4], 1);
609 strprompt("Node name", &sc[0][0], 15);
610 strprompt("Fully qualified domain name", &sc[1][0], 63);
611 strprompt("Human readable node name", &sc[2][0], 20);
612 strprompt("Modem dialup number", &sc[3][0], 15);
614 sprintf(&sc[4][0], "%d", (boolprompt(
615 "Automatically give room aide privs to a user who creates a private room",
618 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
619 strprompt("Initial access level for new users", &sc[6][0], 1);
621 sprintf(&sc[7][0], "%d", (boolprompt(
622 "Require registration for new users",
625 sprintf(&sc[8][0], "%d", (boolprompt(
626 "Automatically move problem user messages to twit room",
629 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
630 strprompt("Paginator prompt", &sc[10][0], 79);
632 sprintf(&sc[11][0], "%d", (boolprompt(
633 "Restrict Internet mail to only those with that privilege",
636 strprompt("Geographic location of this system", &sc[12][0], 31);
637 strprompt("Name of system administrator", &sc[13][0], 25);
638 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
639 strprompt("Server-to-server networking password", &sc[15][0], 19);
640 strprompt("Default user purge time (days)", &sc[16][0], 5);
641 strprompt("Default room purge time (days)", &sc[17][0], 5);
642 strprompt("Name of room to log pages", &sc[18][0], ROOMNAMELEN);
644 /* Angels and demons dancing in my head... */
646 sprintf(buf, "%d", expire_mode);
647 strprompt("System default message expire policy (? for list)",
651 printf("1. Never automatically expire messages\n");
652 printf("2. Expire by message count\n");
653 printf("3. Expire by message age\n");
655 } while((buf[0]<49)||(buf[0]>51));
656 expire_mode = buf[0] - 48;
658 /* ...lunatics and monsters underneath my bed */
659 if (expire_mode == 2) {
660 sprintf(buf, "%d", expire_value);
661 strprompt("Keep how many messages online?", buf, 10);
662 expire_value = atol(buf);
665 if (expire_mode == 3) {
666 sprintf(buf, "%d", expire_value);
667 strprompt("Keep messages for how many days?", buf, 10);
668 expire_value = atol(buf);
672 printf("Save this configuration? ");
674 serv_puts("CONF set");
677 for (a=0; a<19; ++a) serv_puts(&sc[a][0]);
681 snprintf(buf, sizeof buf, "SPEX site|%d|%d",
682 expire_mode, expire_value);