1 /* More Citadel/UX routines...
2 * unlike routines.c, some of these DO use global variables.
36 extern char tempdir[];
37 extern char *axdefs[7];
38 extern long highest_msg_read;
39 extern long maxmsgnum;
40 extern unsigned room_flags;
41 extern int screenwidth;
48 ret = open(name,mode);
50 fprintf(stderr,"Cannot open file '%s', mode=%d, errno=%d\n",
58 int room_prompt(qrflags) /* return proper room prompt character */
62 if (qrflags&QR_DIRECTORY) a=']';
63 if ((a==']')&&(qrflags&QR_NETWORK)) a='}';
64 if ((a=='>')&&(qrflags&QR_NETWORK)) a=')';
68 void entregis() /* register with name and address */
89 serv_puts("GREG _SELF_");
93 while (serv_gets(buf), strcmp(buf,"000")) {
94 if (a==2) strcpy(tmpname,buf);
95 if (a==3) strcpy(tmpaddr,buf);
96 if (a==4) strcpy(tmpcity,buf);
97 if (a==5) strcpy(tmpstate,buf);
98 if (a==6) strcpy(tmpzip,buf);
99 if (a==7) strcpy(tmpphone,buf);
100 if (a==9) strcpy(tmpemail,buf);
105 strprompt("REAL name",tmpname,29);
106 strprompt("Address",tmpaddr,24);
107 strprompt("City/town",tmpcity,14);
108 strprompt("State",tmpstate,2);
109 strprompt("ZIP Code",tmpzip,10);
110 strprompt("Telephone number",tmpphone,14);
111 strprompt("Email address",tmpemail,31);
113 /* now send the registration info back to the server */
117 printf("%s\n",&buf[4]);
131 void updatels() { /* make all messages old in current room */
133 serv_puts("SLRP HIGHEST");
135 if (buf[0]!='2') printf("%s\n",&buf[4]);
138 void updatelsa() { /* only make messages old in this room that have been read */
140 sprintf(buf,"SLRP %ld",highest_msg_read);
143 if (buf[0]!='2') printf("%s\n",&buf[4]);
148 * This routine completes a client upload
150 void do_upload(int fd) {
153 long transmitted_bytes, total_bytes;
157 /* learn the size of the file */
158 total_bytes = lseek(fd,0L,2);
161 transmitted_bytes = 0L;
162 progress(transmitted_bytes,total_bytes);
164 bytes_to_send = read(fd,tbuf,4096);
165 if (bytes_to_send>0) {
166 sprintf(buf,"WRIT %d",bytes_to_send);
170 bytes_expected = atoi(&buf[4]);
171 serv_write(tbuf,bytes_expected);
174 printf("%s\n",&buf[4]);
177 transmitted_bytes = transmitted_bytes + (long)bytes_to_send;
178 progress(transmitted_bytes, total_bytes);
179 } while (bytes_to_send > 0);
181 /* close the upload file, locally and at the server */
185 printf("%s\n",&buf[4]);
190 * client-based uploads (for users with their own clientware)
200 if ((room_flags & QR_UPLOAD) == 0) {
201 printf("*** You cannot upload to this room.\n");
205 newprompt("File to be uploaded: ",flnm,55);
206 fd = open(flnm,O_RDONLY);
208 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
211 printf("Enter a description of this file:\n");
212 newprompt(": ",desc,75);
214 /* keep generating filenames in hope of finding a unique one */
217 if (a==10) return; /* fail if tried 10 times */
219 while ((strlen(buf)>0)&&(haschar(buf,'/')))
221 if (a>0) sprintf(&buf[strlen(buf)],"%d",a);
222 sprintf(tbuf,"UOPN %s|%s",buf,desc);
225 if (buf[0]!='2') printf("%s\n",&buf[4]);
227 } while (buf[0]!='2');
229 /* at this point we have an open upload file at the server */
235 * Function used for various image upload commands
237 void cli_image_upload(char *keyname) {
242 sprintf(buf, "UIMG 0|%s", keyname);
246 printf("%s\n", &buf[4]);
250 newprompt("Image file to be uploaded: ",flnm,55);
251 fd = open(flnm,O_RDONLY);
253 printf("Cannot open '%s': %s\n",flnm,strerror(errno));
257 sprintf(buf, "UIMG 1|%s", keyname);
261 printf("%s\n", &buf[4]);
270 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
272 void upload(c) /* c = upload mode */
283 if ((room_flags & QR_UPLOAD) == 0) {
284 printf("*** You cannot upload to this room.\n");
288 /* we don't need a filename when receiving batch y/z modem */
289 if ((c==2)||(c==3)) strcpy(flnm,"x");
290 else newprompt("Enter filename: ",flnm,15);
292 for (a=0; a<strlen(flnm); ++a)
293 if ( (flnm[a]=='/') || (flnm[a]=='\\') || (flnm[a]=='>')
294 || (flnm[a]=='?') || (flnm[a]=='*')
295 || (flnm[a]==';') || (flnm[a]=='&') ) flnm[a]='_';
297 newprompt("Enter a short description of the file:\n: ",desc,150);
299 /* create a temporary directory... */
300 if (mkdir(tempdir,0700) != 0) {
301 printf("*** Could not create temporary directory %s: %s\n",
302 tempdir,strerror(errno));
306 /* now do the transfer ... in a separate process */
313 printf("Receiving %s - press Ctrl-D to end.\n",flnm);
314 fp = fopen(flnm,"w");
329 execlp("rx","rx",flnm,NULL);
333 execlp("rb","rb",NULL);
337 execlp("rz","rz",NULL);
343 } while ((b!=xfer_pid)&&(b!=(-1)));
347 printf("\r*** Transfer unsuccessful.\n");
352 printf("\r*** Transfer successful. Sending file(s) to server...\n");
353 sprintf(buf,"cd %s; ls",tempdir);
354 lsfp = popen(buf,"r");
356 while (fgets(flnm,256,lsfp)!=NULL) {
357 flnm[strlen(flnm)-1] = 0;
358 sprintf(buf,"%s/%s",tempdir,flnm);
359 fd = open(buf,O_RDONLY);
363 sprintf(buf,"UOPN %s|%s",flnm,desc);
364 if (a>0) sprintf(&buf[strlen(buf)],
369 } while((buf[0]!='2')&&(a<100));
370 if (buf[0]=='2') do {
371 a=read(fd,tbuf,4096);
373 sprintf(buf,"WRIT %d",a);
383 printf("%s\n",&buf[4]);
402 sprintf(cmd,"GREG %s",user);
410 if (a==1) printf("User #%s - %s ",
412 if (a==2) printf("PW: %s\n",buf);
413 if (a==3) printf("%s\n",buf);
414 if (a==4) printf("%s\n",buf);
415 if (a==5) printf("%s, ",buf);
416 if (a==6) printf("%s ",buf);
417 if (a==7) printf("%s\n",buf);
418 if (a==8) printf("%s\n",buf);
419 if (a==9) ax=atoi(buf);
420 if (a==10) printf("%s\n",buf);
421 } while(strcmp(buf,"000"));
422 printf("Current access level: %d (%s)\n",ax,axdefs[ax]);
425 printf("%-30s\n%s\n",user,&cmd[4]);
428 /* now set the access level */
430 printf("Access level (? for list): ");
435 printf("%d %s\n",b,axdefs[b]);
438 } while((a<0)||(a>6));
440 sprintf(cmd,"VALI %s|%d",user,a);
443 if (cmd[0]!='2') printf("%s\n",&cmd[4]);
448 void validate() { /* validate new users */
456 if (cmd[0]!='3') finished = 1;
457 if (cmd[0]=='2') printf("%s\n",&cmd[4]);
462 } while(finished==0);
470 signal(SIGINT,SIG_DFL);
471 signal(SIGQUIT,SIG_DFL);
472 execlp(getenv("SHELL"),getenv("SHELL"),NULL);
473 printf("Could not open a shell: %s\n", strerror(errno));
478 } while ((a!=b)&&(a!=(-1)));
483 * <.A>ide <F>ile <D>elete command
489 newprompt("Filename: ",filename,31);
490 if (strlen(filename)==0) return;
491 sprintf(cmd,"DELF %s",filename);
494 printf("%s\n",&cmd[4]);
498 * <.A>ide <F>ile <S>end command
501 char filename[32],destsys[20],cmd[256];
503 newprompt("Filename: ",filename,31);
504 if (strlen(filename)==0) return;
505 newprompt("System to send to: ",destsys,19);
506 sprintf(cmd,"NETF %s|%s",filename,destsys);
509 printf("%s\n",&cmd[4]);
514 * <.A>ide <F>ile <M>ove command
521 newprompt("Filename: ",filename,63);
522 if (strlen(filename)==0) return;
523 newprompt("Enter target room: ",newroom,19);
525 sprintf(cmd,"MOVF %s|%s",filename,newroom);
528 printf("%s\n",&cmd[4]);
533 * list of users who have filled out a bio
542 printf("%s\n",&buf[4]);
545 while (serv_gets(buf), strcmp(buf,"000")) {
546 if ((pos+strlen(buf)+5)>screenwidth) {
551 pos = pos + strlen(buf) + 2;
553 printf("%c%c \n\n",8,8);
565 newprompt("Read bio for who ('?' for list) : ",who,25);
567 if (!strcmp(who,"?")) list_bio();
568 } while(!strcmp(who,"?"));
569 sprintf(buf,"RBIO %s",who);
573 printf("%s\n",&buf[4]);
576 while (serv_gets(buf), strcmp(buf,"000")) {