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 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
267 CC->download_fp = fopen(pathname,"r");
269 if (CC->download_fp==NULL) {
270 cprintf("%d cannot open %s: %s\n",
271 ERROR,pathname,strerror(errno));
281 void cmd_oimg(char *cmdbuf)
285 struct usersupp usbuf;
290 extract(filename,cmdbuf,0);
292 if (strlen(filename)==0) {
293 cprintf("%d You must specify a file name.\n",
294 ERROR+FILE_NOT_FOUND);
298 if (CC->download_fp != NULL) {
299 cprintf("%d You already have a download file open.\n",ERROR);
303 if (!strcasecmp(filename, "_userpic_")) {
304 extract(which_user, cmdbuf, 1);
305 if (getuser(&usbuf, which_user) != 0) {
306 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
309 sprintf(pathname, "./userpics/%ld.gif", usbuf.usernum);
311 else if (!strcasecmp(filename, "_floorpic_")) {
312 which_floor = extract_int(cmdbuf, 1);
313 sprintf(pathname, "./images/floor.%d.gif", which_floor);
315 else if (!strcasecmp(filename, "_roompic_")) {
316 assoc_file_name(pathname, &CC->quickroom, "images");
319 for (a=0; a<strlen(filename); ++a) {
320 filename[a] = tolower(filename[a]);
321 if (filename[a]=='/') filename[a] = '_';
323 sprintf(pathname,"./images/%s.gif",filename);
326 CC->download_fp = fopen(pathname,"r");
327 if (CC->download_fp == NULL) {
328 cprintf("%d Cannot open %s: %s\n",
329 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
337 * open a file for uploading
339 void cmd_uopn(char *cmdbuf)
343 extract(CC->upl_file,cmdbuf,0);
344 extract(CC->upl_comment,cmdbuf,1);
346 if (!(CC->logged_in)) {
347 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
351 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
352 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
356 if (strlen(CC->upl_file)==0) {
357 cprintf("%d You must specify a file name.\n",
358 ERROR+FILE_NOT_FOUND);
362 if (CC->upload_fp != NULL) {
363 cprintf("%d You already have a upload file open.\n",ERROR);
367 for (a=0; a<strlen(CC->upl_file); ++a)
368 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
369 sprintf(CC->upl_path,"./files/%s/%s",CC->quickroom.QRdirname,CC->upl_file);
370 sprintf(CC->upl_filedir,"./files/%s/filedir",CC->quickroom.QRdirname);
372 CC->upload_fp = fopen(CC->upl_path,"r");
373 if (CC->upload_fp != NULL) {
374 fclose(CC->upload_fp);
375 CC->upload_fp = NULL;
376 cprintf("%d '%s' already exists\n",
377 ERROR+ALREADY_EXISTS,CC->upl_path);
381 CC->upload_fp = fopen(CC->upl_path,"wb");
382 if (CC->upload_fp == NULL) {
383 cprintf("%d Cannot open %s: %s\n",
384 ERROR,CC->upl_path,strerror(errno));
387 cprintf("%d Ok\n",OK);
393 * open an image file for uploading
395 void cmd_uimg(char *cmdbuf)
397 int is_this_for_real;
402 if (num_parms(cmdbuf) < 2) {
403 cprintf("%d Usage error.\n", ERROR);
407 is_this_for_real = extract_int(cmdbuf,0);
408 extract(basenm, cmdbuf, 1);
409 if (CC->upload_fp != NULL) {
410 cprintf("%d You already have an upload file open.\n", ERROR);
414 strcpy(CC->upl_path, "");
416 for (a=0; a<strlen(basenm); ++a) {
417 basenm[a] = tolower(basenm[a]);
418 if (basenm[a]=='/') basenm[a] = '_';
421 if (CC->usersupp.axlevel >= 6) {
422 sprintf(CC->upl_path, "./images/%s", basenm);
425 if (!strcasecmp(basenm, "_userpic_")) {
426 sprintf(CC->upl_path, "./userpics/%ld.gif",
427 CC->usersupp.usernum);
430 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
431 which_floor = extract_int(cmdbuf, 2);
432 sprintf(CC->upl_path, "./images/floor.%d.gif", which_floor);
435 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
436 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
439 if (strlen(CC->upl_path) == 0) {
440 cprintf("%d Higher access required.\n",
441 ERROR+HIGHER_ACCESS_REQUIRED);
445 if (is_this_for_real == 0) {
446 cprintf("%d Ok to send image\n", OK);
450 CC->upload_fp = fopen(CC->upl_path,"wb");
451 if (CC->upload_fp == NULL) {
452 cprintf("%d Cannot open %s: %s\n",
453 ERROR,CC->upl_path,strerror(errno));
456 cprintf("%d Ok\n",OK);
457 CC->upload_type = UPL_IMAGE;
462 * close the download file
464 void cmd_clos(void) {
467 if (CC->download_fp == NULL) {
468 cprintf("%d You don't have a download file open.\n",ERROR);
472 fclose(CC->download_fp);
473 CC->download_fp = NULL;
475 if (CC->dl_is_net == 1) {
477 sprintf(buf,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
481 cprintf("%d Ok\n",OK);
488 void abort_upl(struct CitContext *who)
490 if (who->upload_fp != NULL) {
491 fclose(who->upload_fp);
492 who->upload_fp = NULL;
493 unlink(CC->upl_path);
500 * close the upload file
502 void cmd_ucls(char *cmd)
507 if (CC->upload_fp == NULL) {
508 cprintf("%d You don't have an upload file open.\n",ERROR);
512 fclose(CC->upload_fp);
513 CC->upload_fp = NULL;
515 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
516 CC->upload_type = UPL_FILE;
517 cprintf("%d Upload completed.\n", OK);
521 if (!strcasecmp(cmd,"1")) {
522 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
523 fp = fopen(CC->upl_filedir,"a");
524 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
526 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
530 /* put together an upload notice */
532 fp=fopen(CC->temp,"wb");
536 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
537 fprintf(fp,"T%ld",now); putc(0,fp);
538 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
539 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
540 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
541 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
544 save_message(CC->temp, "", 0, M_LOCAL, 1);
549 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
554 * read from the download file
556 void cmd_read(char *cmdbuf)
562 start_pos = extract_long(cmdbuf,0);
563 bytes = extract_int(cmdbuf,1);
565 if (CC->download_fp == NULL) {
566 cprintf("%d You don't have a download file open.\n",ERROR);
571 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
575 if (CC->dl_is_net) if (bytes>64) bytes = 64; /**** FIX ****/
577 fseek(CC->download_fp,start_pos,0);
578 fread(buf,bytes,1,CC->download_fp);
579 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
580 client_write(buf, bytes);
586 * write to the upload file
588 void cmd_writ(char *cmdbuf)
593 bytes = extract_int(cmdbuf,0);
595 if (CC->upload_fp == NULL) {
596 cprintf("%d You don't have an upload file open.\n",ERROR);
601 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
605 if (CC->upload_type==UPL_NET) if (bytes > 64) bytes = 64; /*** FIX ***/
607 cprintf("%d %d\n",SEND_BINARY,bytes);
608 client_read(buf, bytes);
609 fwrite(buf,bytes,1,CC->upload_fp);
615 * cmd_netp() - identify as network poll session
617 void cmd_netp(char *cmdbuf)
621 extract(buf,cmdbuf,1);
622 if (strcasecmp(buf,config.c_net_password)) {
623 cprintf("%d authentication failed\n",ERROR);
626 extract(CC->net_node,cmdbuf,0);
627 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
631 * cmd_ndop() - open a network spool file for downloading
633 void cmd_ndop(char *cmdbuf)
638 if (strlen(CC->net_node)==0) {
639 cprintf("%d Not authenticated as a network node.\n",
640 ERROR+NOT_LOGGED_IN);
644 if (CC->download_fp != NULL) {
645 cprintf("%d You already have a download file open.\n",ERROR);
649 sprintf(pathname,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
651 /* first open the file in append mode in order to create a
652 * zero-length file if it doesn't already exist
654 CC->download_fp = fopen(pathname,"a");
655 fclose(CC->download_fp);
658 CC->download_fp = fopen(pathname,"r");
659 if (CC->download_fp==NULL) {
660 cprintf("%d cannot open %s: %s\n",
661 ERROR,pathname,strerror(errno));
666 /* set this flag so other routines know that the download file
667 * currently open is a network spool file
671 stat(pathname,&statbuf);
672 cprintf("%d %ld\n",OK,statbuf.st_size);
676 * cmd_nuop() - open a network spool file for uploading
678 void cmd_nuop(char *cmdbuf)
680 if (strlen(CC->net_node)==0) {
681 cprintf("%d Not authenticated as a network node.\n",
682 ERROR+NOT_LOGGED_IN);
686 if (CC->upload_fp != NULL) {
687 cprintf("%d You already have an upload file open.\n",ERROR);
691 sprintf(CC->upl_path,"%s/network/spoolin/%s.%d",
692 BBSDIR,CC->net_node,getpid());
694 CC->upload_fp = fopen(CC->upl_path,"r");
695 if (CC->upload_fp != NULL) {
696 fclose(CC->upload_fp);
697 CC->upload_fp = NULL;
698 cprintf("%d '%s' already exists\n",
699 ERROR+ALREADY_EXISTS,CC->upl_path);
703 CC->upload_fp = fopen(CC->upl_path,"w");
704 if (CC->upload_fp == NULL) {
705 cprintf("%d Cannot open %s: %s\n",
706 ERROR,CC->upl_path,strerror(errno));
710 CC->upload_type = UPL_NET;
711 cprintf("%d Ok\n",OK);