17 #include "sysdep_decls.h"
24 void cmd_delf(char *filename)
29 if (!(CC->logged_in)) {
30 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
34 if (!is_room_aide()) {
35 cprintf("%d Higher access required.\n",
36 ERROR+HIGHER_ACCESS_REQUIRED);
41 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
42 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
46 if (strlen(filename)==0) {
47 cprintf("%d You must specify a file name.\n",
48 ERROR+FILE_NOT_FOUND);
51 for (a=0; a<strlen(filename); ++a)
52 if (filename[a]=='/') filename[a] = '_';
53 snprintf(pathname,sizeof pathname,"./files/%s/%s",
54 CC->quickroom.QRdirname,filename);
56 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
57 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
64 * move a file from one room directory to another
66 void cmd_movf(char *cmdbuf)
74 struct quickroom qrbuf;
76 extract(filename,cmdbuf,0);
77 extract(newroom,cmdbuf,1);
79 if (!(CC->logged_in)) {
80 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
84 if (!is_room_aide()) {
85 cprintf("%d Higher access required.\n",
86 ERROR+HIGHER_ACCESS_REQUIRED);
90 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
91 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
95 if (strlen(filename)==0) {
96 cprintf("%d You must specify a file name.\n",
97 ERROR+FILE_NOT_FOUND);
101 for (a=0; a<strlen(filename); ++a)
102 if (filename[a]=='/') filename[a] = '_';
103 snprintf(pathname,sizeof pathname,"./files/%s/%s",
104 CC->quickroom.QRdirname,filename);
105 if (access(pathname,0)!=0) {
106 cprintf("%d File '%s' not found.\n",
107 ERROR+FILE_NOT_FOUND,pathname);
111 if (getroom(&qrbuf, newroom)!=0) {
112 cprintf("%d '%s' does not exist.\n",
116 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
117 cprintf("%d '%s' is not a directory room.\n",
118 ERROR+NOT_HERE,qrbuf.QRname);
121 snprintf(newpath,sizeof newpath,"./files/%s/%s",qrbuf.QRdirname,
123 if (link(pathname,newpath)!=0) {
124 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
129 /* this is a crude method of copying the file description */
130 snprintf(buf, sizeof buf,
131 "cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
132 CC->quickroom.QRdirname,
136 cprintf("%d File '%s' has been moved.\n",OK,filename);
141 * send a file over the net
143 void cmd_netf(char *cmdbuf)
145 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
150 extract(filename,cmdbuf,0);
151 extract(destsys,cmdbuf,1);
153 if (!(CC->logged_in)) {
154 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
158 if (!is_room_aide()) {
159 cprintf("%d Higher access required.\n",
160 ERROR+HIGHER_ACCESS_REQUIRED);
164 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
165 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
169 if (strlen(filename)==0) {
170 cprintf("%d You must specify a file name.\n",
171 ERROR+FILE_NOT_FOUND);
175 for (a=0; a<strlen(filename); ++a)
176 if (filename[a]=='/') filename[a] = '_';
177 snprintf(pathname,sizeof pathname,"./files/%s/%s",
178 CC->quickroom.QRdirname,filename);
179 if (access(pathname,0)!=0) {
180 cprintf("%d File '%s' not found.\n",
181 ERROR+FILE_NOT_FOUND,pathname);
184 snprintf(buf,sizeof buf,"sysop@%s",destsys);
187 cprintf("%d No such system: '%s'\n",
188 ERROR+NO_SUCH_SYSTEM,destsys);
191 snprintf(outfile,sizeof outfile,"%s/network/spoolin/nsf.%d",BBSDIR,
193 ofp=fopen(outfile,"a");
195 cprintf("%d internal error\n",ERROR);
200 putc(MES_NORMAL,ofp);
202 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
204 fprintf(ofp,"T%ld",(long)now); putc(0,ofp);
205 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
206 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
207 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
208 fprintf(ofp,"D%s",destsys); putc(0,ofp);
209 fprintf(ofp,"SFILE"); putc(0,ofp);
213 snprintf(buf,sizeof buf,
214 "cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
215 CC->quickroom.QRdirname,filename,filename,outfile);
218 ofp = fopen(outfile,"a");
222 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
223 system("nohup ./netproc -i >/dev/null 2>&1 &");
228 * This code is common to all commands which open a file for downloading.
229 * It examines the file and displays the OK result code and some information
230 * about the file. NOTE: this stuff is Unix dependent.
232 void OpenCmdResult(char *filename, char *mime_type) {
237 fstat(fileno(CC->download_fp), &statbuf);
238 filesize = (long) statbuf.st_size;
239 modtime = (time_t) statbuf.st_mtime;
241 cprintf("%d %ld|%ld|%s|%s\n",
242 OK, filesize, modtime, filename, mime_type);
247 * open a file for downloading
249 void cmd_open(char *cmdbuf)
255 extract(filename,cmdbuf,0);
257 if (!(CC->logged_in)) {
258 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
262 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
263 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
267 if (strlen(filename)==0) {
268 cprintf("%d You must specify a file name.\n",
269 ERROR+FILE_NOT_FOUND);
273 if (CC->download_fp != NULL) {
274 cprintf("%d You already have a download file open.\n",ERROR);
278 for (a=0; a<strlen(filename); ++a)
279 if (filename[a]=='/') filename[a] = '_';
281 snprintf(pathname,sizeof pathname,
282 "./files/%s/%s",CC->quickroom.QRdirname,filename);
283 CC->download_fp = fopen(pathname,"r");
285 if (CC->download_fp==NULL) {
286 cprintf("%d cannot open %s: %s\n",
287 ERROR,pathname,strerror(errno));
291 OpenCmdResult(filename, "application/octet-stream");
297 void cmd_oimg(char *cmdbuf)
301 struct usersupp usbuf;
306 extract(filename,cmdbuf,0);
308 if (strlen(filename)==0) {
309 cprintf("%d You must specify a file name.\n",
310 ERROR+FILE_NOT_FOUND);
314 if (CC->download_fp != NULL) {
315 cprintf("%d You already have a download file open.\n",ERROR);
319 if (!strcasecmp(filename, "_userpic_")) {
320 extract(which_user, cmdbuf, 1);
321 if (getuser(&usbuf, which_user) != 0) {
322 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
325 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
328 else if (!strcasecmp(filename, "_floorpic_")) {
329 which_floor = extract_int(cmdbuf, 1);
330 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
333 else if (!strcasecmp(filename, "_roompic_")) {
334 assoc_file_name(pathname, &CC->quickroom, "images");
337 for (a=0; a<strlen(filename); ++a) {
338 filename[a] = tolower(filename[a]);
339 if (filename[a]=='/') filename[a] = '_';
341 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
344 CC->download_fp = fopen(pathname,"r");
345 if (CC->download_fp == NULL) {
346 cprintf("%d Cannot open %s: %s\n",
347 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
351 OpenCmdResult(pathname, "image/gif");
355 * open a file for uploading
357 void cmd_uopn(char *cmdbuf)
361 extract(CC->upl_file,cmdbuf,0);
362 extract(CC->upl_comment,cmdbuf,1);
364 if (!(CC->logged_in)) {
365 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
369 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
370 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
374 if (strlen(CC->upl_file)==0) {
375 cprintf("%d You must specify a file name.\n",
376 ERROR+FILE_NOT_FOUND);
380 if (CC->upload_fp != NULL) {
381 cprintf("%d You already have a upload file open.\n",ERROR);
385 for (a=0; a<strlen(CC->upl_file); ++a)
386 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
387 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
388 CC->quickroom.QRdirname,CC->upl_file);
389 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
390 CC->quickroom.QRdirname);
392 CC->upload_fp = fopen(CC->upl_path,"r");
393 if (CC->upload_fp != NULL) {
394 fclose(CC->upload_fp);
395 CC->upload_fp = NULL;
396 cprintf("%d '%s' already exists\n",
397 ERROR+ALREADY_EXISTS,CC->upl_path);
401 CC->upload_fp = fopen(CC->upl_path,"wb");
402 if (CC->upload_fp == NULL) {
403 cprintf("%d Cannot open %s: %s\n",
404 ERROR,CC->upl_path,strerror(errno));
407 cprintf("%d Ok\n",OK);
413 * open an image file for uploading
415 void cmd_uimg(char *cmdbuf)
417 int is_this_for_real;
422 if (num_parms(cmdbuf) < 2) {
423 cprintf("%d Usage error.\n", ERROR);
427 is_this_for_real = extract_int(cmdbuf,0);
428 extract(basenm, cmdbuf, 1);
429 if (CC->upload_fp != NULL) {
430 cprintf("%d You already have an upload file open.\n", ERROR);
434 strcpy(CC->upl_path, "");
436 for (a=0; a<strlen(basenm); ++a) {
437 basenm[a] = tolower(basenm[a]);
438 if (basenm[a]=='/') basenm[a] = '_';
441 if (CC->usersupp.axlevel >= 6) {
442 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
446 if (!strcasecmp(basenm, "_userpic_")) {
447 snprintf(CC->upl_path, sizeof CC->upl_path,
448 "./userpics/%ld.gif", CC->usersupp.usernum);
451 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
452 which_floor = extract_int(cmdbuf, 2);
453 snprintf(CC->upl_path, sizeof CC->upl_path,
454 "./images/floor.%d.gif", which_floor);
457 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
458 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
461 if (strlen(CC->upl_path) == 0) {
462 cprintf("%d Higher access required.\n",
463 ERROR+HIGHER_ACCESS_REQUIRED);
467 if (is_this_for_real == 0) {
468 cprintf("%d Ok to send image\n", OK);
472 CC->upload_fp = fopen(CC->upl_path,"wb");
473 if (CC->upload_fp == NULL) {
474 cprintf("%d Cannot open %s: %s\n",
475 ERROR,CC->upl_path,strerror(errno));
478 cprintf("%d Ok\n",OK);
479 CC->upload_type = UPL_IMAGE;
484 * close the download file
486 void cmd_clos(void) {
489 if (CC->download_fp == NULL) {
490 cprintf("%d You don't have a download file open.\n",ERROR);
494 fclose(CC->download_fp);
495 CC->download_fp = NULL;
497 if (CC->dl_is_net == 1) {
499 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
504 cprintf("%d Ok\n",OK);
511 void abort_upl(struct CitContext *who)
513 if (who->upload_fp != NULL) {
514 fclose(who->upload_fp);
515 who->upload_fp = NULL;
516 unlink(CC->upl_path);
523 * close the upload file
525 void cmd_ucls(char *cmd)
528 char upload_notice[512];
530 if (CC->upload_fp == NULL) {
531 cprintf("%d You don't have an upload file open.\n",ERROR);
535 fclose(CC->upload_fp);
536 CC->upload_fp = NULL;
538 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
539 CC->upload_type = UPL_FILE;
540 cprintf("%d Upload completed.\n", OK);
542 if (CC->upload_type == UPL_NET) {
544 execlp("./netproc", "netproc", "-i", NULL);
552 if (!strcasecmp(cmd,"1")) {
553 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
554 fp = fopen(CC->upl_filedir,"a");
555 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
557 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
561 /* put together an upload notice */
562 sprintf(upload_notice,
563 "NEW UPLOAD: '%s'\n %s\n",
564 CC->upl_file,CC->upl_comment);
565 quickie_message(CC->curr_user, NULL, CC->quickroom.QRname,
570 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
577 * read from the download file
579 void cmd_read(char *cmdbuf)
585 start_pos = extract_long(cmdbuf,0);
586 bytes = extract_int(cmdbuf,1);
588 if (CC->download_fp == NULL) {
589 cprintf("%d You don't have a download file open.\n",ERROR);
594 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
598 fseek(CC->download_fp,start_pos,0);
599 fread(buf,bytes,1,CC->download_fp);
600 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
601 client_write(buf, bytes);
607 * write to the upload file
609 void cmd_writ(char *cmdbuf)
614 bytes = extract_int(cmdbuf,0);
616 if (CC->upload_fp == NULL) {
617 cprintf("%d You don't have an upload file open.\n",ERROR);
622 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
626 cprintf("%d %d\n",SEND_BINARY,bytes);
627 client_read(buf, bytes);
628 fwrite(buf,bytes,1,CC->upload_fp);
634 * cmd_netp() - identify as network poll session
636 void cmd_netp(char *cmdbuf)
640 extract(buf,cmdbuf,1);
641 if (strcasecmp(buf,config.c_net_password)) {
642 cprintf("%d authentication failed\n",ERROR);
645 extract(CC->net_node,cmdbuf,0);
646 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
650 * cmd_ndop() - open a network spool file for downloading
652 void cmd_ndop(char *cmdbuf)
657 if (strlen(CC->net_node)==0) {
658 cprintf("%d Not authenticated as a network node.\n",
659 ERROR+NOT_LOGGED_IN);
663 if (CC->download_fp != NULL) {
664 cprintf("%d You already have a download file open.\n",ERROR);
668 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
671 /* first open the file in append mode in order to create a
672 * zero-length file if it doesn't already exist
674 CC->download_fp = fopen(pathname,"a");
675 if (CC->download_fp != NULL) fclose(CC->download_fp);
678 CC->download_fp = fopen(pathname,"r");
679 if (CC->download_fp==NULL) {
680 cprintf("%d cannot open %s: %s\n",
681 ERROR,pathname,strerror(errno));
686 /* set this flag so other routines know that the download file
687 * currently open is a network spool file
691 stat(pathname,&statbuf);
692 cprintf("%d %ld\n",OK,statbuf.st_size);
696 * cmd_nuop() - open a network spool file for uploading
698 void cmd_nuop(char *cmdbuf)
700 if (strlen(CC->net_node)==0) {
701 cprintf("%d Not authenticated as a network node.\n",
702 ERROR+NOT_LOGGED_IN);
706 if (CC->upload_fp != NULL) {
707 cprintf("%d You already have an upload file open.\n",ERROR);
711 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
712 BBSDIR,CC->net_node,getpid());
714 CC->upload_fp = fopen(CC->upl_path,"r");
715 if (CC->upload_fp != NULL) {
716 fclose(CC->upload_fp);
717 CC->upload_fp = NULL;
718 cprintf("%d '%s' already exists\n",
719 ERROR+ALREADY_EXISTS,CC->upl_path);
723 CC->upload_fp = fopen(CC->upl_path,"w");
724 if (CC->upload_fp == NULL) {
725 cprintf("%d Cannot open %s: %s\n",
726 ERROR,CC->upl_path,strerror(errno));
730 CC->upload_type = UPL_NET;
731 cprintf("%d Ok\n",OK);