16 #include "sysdep_decls.h"
22 void cmd_delf(char *filename)
27 if (!(CC->logged_in)) {
28 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
32 if (!is_room_aide()) {
33 cprintf("%d Higher access required.\n",
34 ERROR+HIGHER_ACCESS_REQUIRED);
39 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
40 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
44 if (strlen(filename)==0) {
45 cprintf("%d You must specify a file name.\n",
46 ERROR+FILE_NOT_FOUND);
49 for (a=0; a<strlen(filename); ++a)
50 if (filename[a]=='/') filename[a] = '_';
51 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
53 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
54 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
61 * move a file from one room directory to another
63 void cmd_movf(char *cmdbuf)
71 struct quickroom qrbuf;
73 extract(filename,cmdbuf,0);
74 extract(newroom,cmdbuf,1);
76 if (!(CC->logged_in)) {
77 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
81 if (!is_room_aide()) {
82 cprintf("%d Higher access required.\n",
83 ERROR+HIGHER_ACCESS_REQUIRED);
87 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
88 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
92 if (strlen(filename)==0) {
93 cprintf("%d You must specify a file name.\n",
94 ERROR+FILE_NOT_FOUND);
98 for (a=0; a<strlen(filename); ++a)
99 if (filename[a]=='/') filename[a] = '_';
100 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
101 if (access(pathname,0)!=0) {
102 cprintf("%d File '%s' not found.\n",
103 ERROR+FILE_NOT_FOUND,pathname);
107 if (getroom(&qrbuf, newroom)!=0) {
108 cprintf("%d '%s' does not exist.\n",
112 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
113 cprintf("%d '%s' is not a directory room.\n",
114 ERROR+NOT_HERE,qrbuf.QRname);
117 sprintf(newpath,"./files/%s/%s",qrbuf.QRdirname,filename);
118 if (link(pathname,newpath)!=0) {
119 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
124 /* this is a crude method of copying the file description */
125 sprintf(buf,"cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
126 CC->quickroom.QRdirname,
130 cprintf("%d File '%s' has been moved.\n",OK,filename);
135 * send a file over the net
137 void cmd_netf(char *cmdbuf)
139 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
144 extract(filename,cmdbuf,0);
145 extract(destsys,cmdbuf,1);
147 if (!(CC->logged_in)) {
148 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
152 if (!is_room_aide()) {
153 cprintf("%d Higher access required.\n",
154 ERROR+HIGHER_ACCESS_REQUIRED);
158 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
159 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
163 if (strlen(filename)==0) {
164 cprintf("%d You must specify a file name.\n",
165 ERROR+FILE_NOT_FOUND);
169 for (a=0; a<strlen(filename); ++a)
170 if (filename[a]=='/') filename[a] = '_';
171 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
172 if (access(pathname,0)!=0) {
173 cprintf("%d File '%s' not found.\n",
174 ERROR+FILE_NOT_FOUND,pathname);
177 sprintf(buf,"sysop@%s",destsys);
180 cprintf("%d No such system: '%s'\n",
181 ERROR+NO_SUCH_SYSTEM,destsys);
184 sprintf(outfile,"%s/network/spoolin/nsf.%d",BBSDIR,getpid());
185 ofp=fopen(outfile,"a");
187 cprintf("%d internal error\n",ERROR);
192 putc(MES_NORMAL,ofp);
194 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
196 fprintf(ofp,"T%ld",now); putc(0,ofp);
197 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
198 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
199 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
200 fprintf(ofp,"D%s",destsys); putc(0,ofp);
201 fprintf(ofp,"SFILE"); putc(0,ofp);
205 sprintf(buf,"cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
206 CC->quickroom.QRdirname,filename,filename,outfile);
209 ofp = fopen(outfile,"a");
213 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
214 system("nohup ./netproc >/dev/null 2>&1 &");
219 * This code is common to all commands which open a file for downloading.
220 * It examines the file and displays the OK result code and some information
221 * about the file. NOTE: this stuff is Unix dependent.
223 void OpenCmdResult(void) {
226 fstat(fileno(CC->download_fp), &statbuf);
227 cprintf("%d %ld|%ld\n", OK, statbuf.st_size, statbuf.st_mtime);
232 * open a file for downloading
234 void cmd_open(char *cmdbuf)
240 extract(filename,cmdbuf,0);
242 if (!(CC->logged_in)) {
243 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
247 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
248 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
252 if (strlen(filename)==0) {
253 cprintf("%d You must specify a file name.\n",
254 ERROR+FILE_NOT_FOUND);
258 if (CC->download_fp != NULL) {
259 cprintf("%d You already have a download file open.\n",ERROR);
263 for (a=0; a<strlen(filename); ++a)
264 if (filename[a]=='/') filename[a] = '_';
266 snprintf(pathname,sizeof pathname,
267 "./files/%s/%s",CC->quickroom.QRdirname,filename);
268 CC->download_fp = fopen(pathname,"r");
270 if (CC->download_fp==NULL) {
271 cprintf("%d cannot open %s: %s\n",
272 ERROR,pathname,strerror(errno));
282 void cmd_oimg(char *cmdbuf)
286 struct usersupp usbuf;
291 extract(filename,cmdbuf,0);
293 if (strlen(filename)==0) {
294 cprintf("%d You must specify a file name.\n",
295 ERROR+FILE_NOT_FOUND);
299 if (CC->download_fp != NULL) {
300 cprintf("%d You already have a download file open.\n",ERROR);
304 if (!strcasecmp(filename, "_userpic_")) {
305 extract(which_user, cmdbuf, 1);
306 if (getuser(&usbuf, which_user) != 0) {
307 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
310 sprintf(pathname, "./userpics/%ld.gif", usbuf.usernum);
312 else if (!strcasecmp(filename, "_floorpic_")) {
313 which_floor = extract_int(cmdbuf, 1);
314 sprintf(pathname, "./images/floor.%d.gif", which_floor);
316 else if (!strcasecmp(filename, "_roompic_")) {
317 assoc_file_name(pathname, &CC->quickroom, "images");
320 for (a=0; a<strlen(filename); ++a) {
321 filename[a] = tolower(filename[a]);
322 if (filename[a]=='/') filename[a] = '_';
324 sprintf(pathname,"./images/%s.gif",filename);
327 CC->download_fp = fopen(pathname,"r");
328 if (CC->download_fp == NULL) {
329 cprintf("%d Cannot open %s: %s\n",
330 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
338 * open a file for uploading
340 void cmd_uopn(char *cmdbuf)
344 extract(CC->upl_file,cmdbuf,0);
345 extract(CC->upl_comment,cmdbuf,1);
347 if (!(CC->logged_in)) {
348 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
352 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
353 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
357 if (strlen(CC->upl_file)==0) {
358 cprintf("%d You must specify a file name.\n",
359 ERROR+FILE_NOT_FOUND);
363 if (CC->upload_fp != NULL) {
364 cprintf("%d You already have a upload file open.\n",ERROR);
368 for (a=0; a<strlen(CC->upl_file); ++a)
369 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
370 sprintf(CC->upl_path,"./files/%s/%s",CC->quickroom.QRdirname,CC->upl_file);
371 sprintf(CC->upl_filedir,"./files/%s/filedir",CC->quickroom.QRdirname);
373 CC->upload_fp = fopen(CC->upl_path,"r");
374 if (CC->upload_fp != NULL) {
375 fclose(CC->upload_fp);
376 CC->upload_fp = NULL;
377 cprintf("%d '%s' already exists\n",
378 ERROR+ALREADY_EXISTS,CC->upl_path);
382 CC->upload_fp = fopen(CC->upl_path,"wb");
383 if (CC->upload_fp == NULL) {
384 cprintf("%d Cannot open %s: %s\n",
385 ERROR,CC->upl_path,strerror(errno));
388 cprintf("%d Ok\n",OK);
394 * open an image file for uploading
396 void cmd_uimg(char *cmdbuf)
398 int is_this_for_real;
403 if (num_parms(cmdbuf) < 2) {
404 cprintf("%d Usage error.\n", ERROR);
408 is_this_for_real = extract_int(cmdbuf,0);
409 extract(basenm, cmdbuf, 1);
410 if (CC->upload_fp != NULL) {
411 cprintf("%d You already have an upload file open.\n", ERROR);
415 strcpy(CC->upl_path, "");
417 for (a=0; a<strlen(basenm); ++a) {
418 basenm[a] = tolower(basenm[a]);
419 if (basenm[a]=='/') basenm[a] = '_';
422 if (CC->usersupp.axlevel >= 6) {
423 sprintf(CC->upl_path, "./images/%s", basenm);
426 if (!strcasecmp(basenm, "_userpic_")) {
427 sprintf(CC->upl_path, "./userpics/%ld.gif",
428 CC->usersupp.usernum);
431 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
432 which_floor = extract_int(cmdbuf, 2);
433 sprintf(CC->upl_path, "./images/floor.%d.gif", which_floor);
436 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
437 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
440 if (strlen(CC->upl_path) == 0) {
441 cprintf("%d Higher access required.\n",
442 ERROR+HIGHER_ACCESS_REQUIRED);
446 if (is_this_for_real == 0) {
447 cprintf("%d Ok to send image\n", OK);
451 CC->upload_fp = fopen(CC->upl_path,"wb");
452 if (CC->upload_fp == NULL) {
453 cprintf("%d Cannot open %s: %s\n",
454 ERROR,CC->upl_path,strerror(errno));
457 cprintf("%d Ok\n",OK);
458 CC->upload_type = UPL_IMAGE;
463 * close the download file
465 void cmd_clos(void) {
468 if (CC->download_fp == NULL) {
469 cprintf("%d You don't have a download file open.\n",ERROR);
473 fclose(CC->download_fp);
474 CC->download_fp = NULL;
476 if (CC->dl_is_net == 1) {
478 sprintf(buf,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
482 cprintf("%d Ok\n",OK);
489 void abort_upl(struct CitContext *who)
491 if (who->upload_fp != NULL) {
492 fclose(who->upload_fp);
493 who->upload_fp = NULL;
494 unlink(CC->upl_path);
501 * close the upload file
503 void cmd_ucls(char *cmd)
508 if (CC->upload_fp == NULL) {
509 cprintf("%d You don't have an upload file open.\n",ERROR);
513 fclose(CC->upload_fp);
514 CC->upload_fp = NULL;
516 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
517 CC->upload_type = UPL_FILE;
518 cprintf("%d Upload completed.\n", OK);
522 if (!strcasecmp(cmd,"1")) {
523 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
524 fp = fopen(CC->upl_filedir,"a");
525 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
527 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
531 /* put together an upload notice */
533 fp=fopen(CC->temp,"wb");
537 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
538 fprintf(fp,"T%ld",now); putc(0,fp);
539 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
540 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
541 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
542 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
545 save_message(CC->temp, "", 0, M_LOCAL, 1);
550 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
555 * read from the download file
557 void cmd_read(char *cmdbuf)
563 start_pos = extract_long(cmdbuf,0);
564 bytes = extract_int(cmdbuf,1);
566 if (CC->download_fp == NULL) {
567 cprintf("%d You don't have a download file open.\n",ERROR);
572 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
576 fseek(CC->download_fp,start_pos,0);
577 fread(buf,bytes,1,CC->download_fp);
578 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
579 client_write(buf, bytes);
585 * write to the upload file
587 void cmd_writ(char *cmdbuf)
592 bytes = extract_int(cmdbuf,0);
594 if (CC->upload_fp == NULL) {
595 cprintf("%d You don't have an upload file open.\n",ERROR);
600 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
604 cprintf("%d %d\n",SEND_BINARY,bytes);
605 client_read(buf, bytes);
606 fwrite(buf,bytes,1,CC->upload_fp);
612 * cmd_netp() - identify as network poll session
614 void cmd_netp(char *cmdbuf)
618 extract(buf,cmdbuf,1);
619 if (strcasecmp(buf,config.c_net_password)) {
620 cprintf("%d authentication failed\n",ERROR);
623 extract(CC->net_node,cmdbuf,0);
624 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
628 * cmd_ndop() - open a network spool file for downloading
630 void cmd_ndop(char *cmdbuf)
635 if (strlen(CC->net_node)==0) {
636 cprintf("%d Not authenticated as a network node.\n",
637 ERROR+NOT_LOGGED_IN);
641 if (CC->download_fp != NULL) {
642 cprintf("%d You already have a download file open.\n",ERROR);
646 sprintf(pathname,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
648 /* first open the file in append mode in order to create a
649 * zero-length file if it doesn't already exist
651 CC->download_fp = fopen(pathname,"a");
652 fclose(CC->download_fp);
655 CC->download_fp = fopen(pathname,"r");
656 if (CC->download_fp==NULL) {
657 cprintf("%d cannot open %s: %s\n",
658 ERROR,pathname,strerror(errno));
663 /* set this flag so other routines know that the download file
664 * currently open is a network spool file
668 stat(pathname,&statbuf);
669 cprintf("%d %ld\n",OK,statbuf.st_size);
673 * cmd_nuop() - open a network spool file for uploading
675 void cmd_nuop(char *cmdbuf)
677 if (strlen(CC->net_node)==0) {
678 cprintf("%d Not authenticated as a network node.\n",
679 ERROR+NOT_LOGGED_IN);
683 if (CC->upload_fp != NULL) {
684 cprintf("%d You already have an upload file open.\n",ERROR);
688 sprintf(CC->upl_path,"%s/network/spoolin/%s.%d",
689 BBSDIR,CC->net_node,getpid());
691 CC->upload_fp = fopen(CC->upl_path,"r");
692 if (CC->upload_fp != NULL) {
693 fclose(CC->upload_fp);
694 CC->upload_fp = NULL;
695 cprintf("%d '%s' already exists\n",
696 ERROR+ALREADY_EXISTS,CC->upl_path);
700 CC->upload_fp = fopen(CC->upl_path,"w");
701 if (CC->upload_fp == NULL) {
702 cprintf("%d Cannot open %s: %s\n",
703 ERROR,CC->upl_path,strerror(errno));
707 CC->upload_type = UPL_NET;
708 cprintf("%d Ok\n",OK);