20 #include "sysdep_decls.h"
27 void cmd_delf(char *filename)
32 if (!(CC->logged_in)) {
33 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
37 if (!is_room_aide()) {
38 cprintf("%d Higher access required.\n",
39 ERROR+HIGHER_ACCESS_REQUIRED);
44 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
45 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
49 if (strlen(filename)==0) {
50 cprintf("%d You must specify a file name.\n",
51 ERROR+FILE_NOT_FOUND);
54 for (a=0; a<strlen(filename); ++a)
55 if (filename[a]=='/') filename[a] = '_';
56 snprintf(pathname,sizeof pathname,"./files/%s/%s",
57 CC->quickroom.QRdirname,filename);
59 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
60 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
67 * move a file from one room directory to another
69 void cmd_movf(char *cmdbuf)
77 struct quickroom qrbuf;
79 extract(filename,cmdbuf,0);
80 extract(newroom,cmdbuf,1);
82 if (!(CC->logged_in)) {
83 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
87 if (!is_room_aide()) {
88 cprintf("%d Higher access required.\n",
89 ERROR+HIGHER_ACCESS_REQUIRED);
93 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
94 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
98 if (strlen(filename)==0) {
99 cprintf("%d You must specify a file name.\n",
100 ERROR+FILE_NOT_FOUND);
104 for (a=0; a<strlen(filename); ++a)
105 if (filename[a]=='/') filename[a] = '_';
106 snprintf(pathname,sizeof pathname,"./files/%s/%s",
107 CC->quickroom.QRdirname,filename);
108 if (access(pathname,0)!=0) {
109 cprintf("%d File '%s' not found.\n",
110 ERROR+FILE_NOT_FOUND,pathname);
114 if (getroom(&qrbuf, newroom)!=0) {
115 cprintf("%d '%s' does not exist.\n",
119 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
120 cprintf("%d '%s' is not a directory room.\n",
121 ERROR+NOT_HERE,qrbuf.QRname);
124 snprintf(newpath,sizeof newpath,"./files/%s/%s",qrbuf.QRdirname,
126 if (link(pathname,newpath)!=0) {
127 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
132 /* this is a crude method of copying the file description */
133 snprintf(buf, sizeof buf,
134 "cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
135 CC->quickroom.QRdirname,
139 cprintf("%d File '%s' has been moved.\n",OK,filename);
144 * send a file over the net
146 void cmd_netf(char *cmdbuf)
148 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
153 extract(filename,cmdbuf,0);
154 extract(destsys,cmdbuf,1);
156 if (!(CC->logged_in)) {
157 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
161 if (!is_room_aide()) {
162 cprintf("%d Higher access required.\n",
163 ERROR+HIGHER_ACCESS_REQUIRED);
167 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
168 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
172 if (strlen(filename)==0) {
173 cprintf("%d You must specify a file name.\n",
174 ERROR+FILE_NOT_FOUND);
178 for (a=0; a<strlen(filename); ++a)
179 if (filename[a]=='/') filename[a] = '_';
180 snprintf(pathname,sizeof pathname,"./files/%s/%s",
181 CC->quickroom.QRdirname,filename);
182 if (access(pathname,0)!=0) {
183 cprintf("%d File '%s' not found.\n",
184 ERROR+FILE_NOT_FOUND,pathname);
187 snprintf(buf,sizeof buf,"sysop@%s",destsys);
190 cprintf("%d No such system: '%s'\n",
191 ERROR+NO_SUCH_SYSTEM,destsys);
194 snprintf(outfile,sizeof outfile,"%s/network/spoolin/nsf.%d",BBSDIR,
196 ofp=fopen(outfile,"a");
198 cprintf("%d internal error\n",ERROR);
203 putc(MES_NORMAL,ofp);
205 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
207 fprintf(ofp,"T%ld",(long)now); putc(0,ofp);
208 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
209 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
210 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
211 fprintf(ofp,"D%s",destsys); putc(0,ofp);
212 fprintf(ofp,"SFILE"); putc(0,ofp);
216 snprintf(buf,sizeof buf,
217 "cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
218 CC->quickroom.QRdirname,filename,filename,outfile);
221 ofp = fopen(outfile,"a");
225 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
226 system("nohup ./netproc -i >/dev/null 2>&1 &");
231 * This code is common to all commands which open a file for downloading.
232 * It examines the file and displays the OK result code and some information
233 * about the file. NOTE: this stuff is Unix dependent.
235 void OpenCmdResult(char *filename, char *mime_type) {
238 fstat(fileno(CC->download_fp), &statbuf);
239 cprintf("%d %ld|%ld|%s|%s\n", OK, statbuf.st_size, statbuf.st_mtime,
240 filename, mime_type);
245 * open a file for downloading
247 void cmd_open(char *cmdbuf)
253 extract(filename,cmdbuf,0);
255 if (!(CC->logged_in)) {
256 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
260 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
261 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
265 if (strlen(filename)==0) {
266 cprintf("%d You must specify a file name.\n",
267 ERROR+FILE_NOT_FOUND);
271 if (CC->download_fp != NULL) {
272 cprintf("%d You already have a download file open.\n",ERROR);
276 for (a=0; a<strlen(filename); ++a)
277 if (filename[a]=='/') filename[a] = '_';
279 snprintf(pathname,sizeof pathname,
280 "./files/%s/%s",CC->quickroom.QRdirname,filename);
281 CC->download_fp = fopen(pathname,"r");
283 if (CC->download_fp==NULL) {
284 cprintf("%d cannot open %s: %s\n",
285 ERROR,pathname,strerror(errno));
289 OpenCmdResult(filename, "application/octet-stream");
295 void cmd_oimg(char *cmdbuf)
299 struct usersupp usbuf;
304 extract(filename,cmdbuf,0);
306 if (strlen(filename)==0) {
307 cprintf("%d You must specify a file name.\n",
308 ERROR+FILE_NOT_FOUND);
312 if (CC->download_fp != NULL) {
313 cprintf("%d You already have a download file open.\n",ERROR);
317 if (!strcasecmp(filename, "_userpic_")) {
318 extract(which_user, cmdbuf, 1);
319 if (getuser(&usbuf, which_user) != 0) {
320 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
323 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
326 else if (!strcasecmp(filename, "_floorpic_")) {
327 which_floor = extract_int(cmdbuf, 1);
328 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
331 else if (!strcasecmp(filename, "_roompic_")) {
332 assoc_file_name(pathname, &CC->quickroom, "images");
335 for (a=0; a<strlen(filename); ++a) {
336 filename[a] = tolower(filename[a]);
337 if (filename[a]=='/') filename[a] = '_';
339 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
342 CC->download_fp = fopen(pathname,"r");
343 if (CC->download_fp == NULL) {
344 cprintf("%d Cannot open %s: %s\n",
345 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
349 OpenCmdResult(pathname, "image/gif");
353 * open a file for uploading
355 void cmd_uopn(char *cmdbuf)
359 extract(CC->upl_file,cmdbuf,0);
360 extract(CC->upl_comment,cmdbuf,1);
362 if (!(CC->logged_in)) {
363 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
367 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
368 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
372 if (strlen(CC->upl_file)==0) {
373 cprintf("%d You must specify a file name.\n",
374 ERROR+FILE_NOT_FOUND);
378 if (CC->upload_fp != NULL) {
379 cprintf("%d You already have a upload file open.\n",ERROR);
383 for (a=0; a<strlen(CC->upl_file); ++a)
384 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
385 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
386 CC->quickroom.QRdirname,CC->upl_file);
387 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
388 CC->quickroom.QRdirname);
390 CC->upload_fp = fopen(CC->upl_path,"r");
391 if (CC->upload_fp != NULL) {
392 fclose(CC->upload_fp);
393 CC->upload_fp = NULL;
394 cprintf("%d '%s' already exists\n",
395 ERROR+ALREADY_EXISTS,CC->upl_path);
399 CC->upload_fp = fopen(CC->upl_path,"wb");
400 if (CC->upload_fp == NULL) {
401 cprintf("%d Cannot open %s: %s\n",
402 ERROR,CC->upl_path,strerror(errno));
405 cprintf("%d Ok\n",OK);
411 * open an image file for uploading
413 void cmd_uimg(char *cmdbuf)
415 int is_this_for_real;
420 if (num_parms(cmdbuf) < 2) {
421 cprintf("%d Usage error.\n", ERROR);
425 is_this_for_real = extract_int(cmdbuf,0);
426 extract(basenm, cmdbuf, 1);
427 if (CC->upload_fp != NULL) {
428 cprintf("%d You already have an upload file open.\n", ERROR);
432 strcpy(CC->upl_path, "");
434 for (a=0; a<strlen(basenm); ++a) {
435 basenm[a] = tolower(basenm[a]);
436 if (basenm[a]=='/') basenm[a] = '_';
439 if (CC->usersupp.axlevel >= 6) {
440 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
444 if (!strcasecmp(basenm, "_userpic_")) {
445 snprintf(CC->upl_path, sizeof CC->upl_path,
446 "./userpics/%ld.gif", CC->usersupp.usernum);
449 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
450 which_floor = extract_int(cmdbuf, 2);
451 snprintf(CC->upl_path, sizeof CC->upl_path,
452 "./images/floor.%d.gif", which_floor);
455 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
456 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
459 if (strlen(CC->upl_path) == 0) {
460 cprintf("%d Higher access required.\n",
461 ERROR+HIGHER_ACCESS_REQUIRED);
465 if (is_this_for_real == 0) {
466 cprintf("%d Ok to send image\n", OK);
470 CC->upload_fp = fopen(CC->upl_path,"wb");
471 if (CC->upload_fp == NULL) {
472 cprintf("%d Cannot open %s: %s\n",
473 ERROR,CC->upl_path,strerror(errno));
476 cprintf("%d Ok\n",OK);
477 CC->upload_type = UPL_IMAGE;
482 * close the download file
484 void cmd_clos(void) {
487 if (CC->download_fp == NULL) {
488 cprintf("%d You don't have a download file open.\n",ERROR);
492 fclose(CC->download_fp);
493 CC->download_fp = NULL;
495 if (CC->dl_is_net == 1) {
497 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
502 cprintf("%d Ok\n",OK);
509 void abort_upl(struct CitContext *who)
511 if (who->upload_fp != NULL) {
512 fclose(who->upload_fp);
513 who->upload_fp = NULL;
514 unlink(CC->upl_path);
521 * close the upload file
523 void cmd_ucls(char *cmd)
528 if (CC->upload_fp == NULL) {
529 cprintf("%d You don't have an upload file open.\n",ERROR);
533 fclose(CC->upload_fp);
534 CC->upload_fp = NULL;
536 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
537 CC->upload_type = UPL_FILE;
538 cprintf("%d Upload completed.\n", OK);
542 if (!strcasecmp(cmd,"1")) {
543 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
544 fp = fopen(CC->upl_filedir,"a");
545 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
547 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
551 /* put together an upload notice */
553 fp=fopen(CC->temp,"wb");
557 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
558 fprintf(fp,"T%ld",(long)now); putc(0,fp);
559 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
560 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
561 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
562 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
565 save_message(CC->temp, "", "", M_LOCAL, 1);
570 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
575 * read from the download file
577 void cmd_read(char *cmdbuf)
583 start_pos = extract_long(cmdbuf,0);
584 bytes = extract_int(cmdbuf,1);
586 if (CC->download_fp == NULL) {
587 cprintf("%d You don't have a download file open.\n",ERROR);
592 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
596 fseek(CC->download_fp,start_pos,0);
597 fread(buf,bytes,1,CC->download_fp);
598 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
599 client_write(buf, bytes);
605 * write to the upload file
607 void cmd_writ(char *cmdbuf)
612 bytes = extract_int(cmdbuf,0);
614 if (CC->upload_fp == NULL) {
615 cprintf("%d You don't have an upload file open.\n",ERROR);
620 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
624 cprintf("%d %d\n",SEND_BINARY,bytes);
625 client_read(buf, bytes);
626 fwrite(buf,bytes,1,CC->upload_fp);
632 * cmd_netp() - identify as network poll session
634 void cmd_netp(char *cmdbuf)
638 extract(buf,cmdbuf,1);
639 if (strcasecmp(buf,config.c_net_password)) {
640 cprintf("%d authentication failed\n",ERROR);
643 extract(CC->net_node,cmdbuf,0);
644 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
648 * cmd_ndop() - open a network spool file for downloading
650 void cmd_ndop(char *cmdbuf)
655 if (strlen(CC->net_node)==0) {
656 cprintf("%d Not authenticated as a network node.\n",
657 ERROR+NOT_LOGGED_IN);
661 if (CC->download_fp != NULL) {
662 cprintf("%d You already have a download file open.\n",ERROR);
666 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
669 /* first open the file in append mode in order to create a
670 * zero-length file if it doesn't already exist
672 CC->download_fp = fopen(pathname,"a");
673 fclose(CC->download_fp);
676 CC->download_fp = fopen(pathname,"r");
677 if (CC->download_fp==NULL) {
678 cprintf("%d cannot open %s: %s\n",
679 ERROR,pathname,strerror(errno));
684 /* set this flag so other routines know that the download file
685 * currently open is a network spool file
689 stat(pathname,&statbuf);
690 cprintf("%d %ld\n",OK,statbuf.st_size);
694 * cmd_nuop() - open a network spool file for uploading
696 void cmd_nuop(char *cmdbuf)
698 if (strlen(CC->net_node)==0) {
699 cprintf("%d Not authenticated as a network node.\n",
700 ERROR+NOT_LOGGED_IN);
704 if (CC->upload_fp != NULL) {
705 cprintf("%d You already have an upload file open.\n",ERROR);
709 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
710 BBSDIR,CC->net_node,getpid());
712 CC->upload_fp = fopen(CC->upl_path,"r");
713 if (CC->upload_fp != NULL) {
714 fclose(CC->upload_fp);
715 CC->upload_fp = NULL;
716 cprintf("%d '%s' already exists\n",
717 ERROR+ALREADY_EXISTS,CC->upl_path);
721 CC->upload_fp = fopen(CC->upl_path,"w");
722 if (CC->upload_fp == NULL) {
723 cprintf("%d Cannot open %s: %s\n",
724 ERROR,CC->upl_path,strerror(errno));
728 CC->upload_type = UPL_NET;
729 cprintf("%d Ok\n",OK);