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",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(void) {
235 fstat(fileno(CC->download_fp), &statbuf);
236 cprintf("%d %ld|%ld\n", OK, statbuf.st_size, statbuf.st_mtime);
241 * open a file for downloading
243 void cmd_open(char *cmdbuf)
249 extract(filename,cmdbuf,0);
251 if (!(CC->logged_in)) {
252 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
256 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
257 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
261 if (strlen(filename)==0) {
262 cprintf("%d You must specify a file name.\n",
263 ERROR+FILE_NOT_FOUND);
267 if (CC->download_fp != NULL) {
268 cprintf("%d You already have a download file open.\n",ERROR);
272 for (a=0; a<strlen(filename); ++a)
273 if (filename[a]=='/') filename[a] = '_';
275 snprintf(pathname,sizeof pathname,
276 "./files/%s/%s",CC->quickroom.QRdirname,filename);
277 CC->download_fp = fopen(pathname,"r");
279 if (CC->download_fp==NULL) {
280 cprintf("%d cannot open %s: %s\n",
281 ERROR,pathname,strerror(errno));
291 void cmd_oimg(char *cmdbuf)
295 struct usersupp usbuf;
300 extract(filename,cmdbuf,0);
302 if (strlen(filename)==0) {
303 cprintf("%d You must specify a file name.\n",
304 ERROR+FILE_NOT_FOUND);
308 if (CC->download_fp != NULL) {
309 cprintf("%d You already have a download file open.\n",ERROR);
313 if (!strcasecmp(filename, "_userpic_")) {
314 extract(which_user, cmdbuf, 1);
315 if (getuser(&usbuf, which_user) != 0) {
316 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
319 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
322 else if (!strcasecmp(filename, "_floorpic_")) {
323 which_floor = extract_int(cmdbuf, 1);
324 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
327 else if (!strcasecmp(filename, "_roompic_")) {
328 assoc_file_name(pathname, &CC->quickroom, "images");
331 for (a=0; a<strlen(filename); ++a) {
332 filename[a] = tolower(filename[a]);
333 if (filename[a]=='/') filename[a] = '_';
335 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
338 CC->download_fp = fopen(pathname,"r");
339 if (CC->download_fp == NULL) {
340 cprintf("%d Cannot open %s: %s\n",
341 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
349 * open a file for uploading
351 void cmd_uopn(char *cmdbuf)
355 extract(CC->upl_file,cmdbuf,0);
356 extract(CC->upl_comment,cmdbuf,1);
358 if (!(CC->logged_in)) {
359 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
363 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
364 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
368 if (strlen(CC->upl_file)==0) {
369 cprintf("%d You must specify a file name.\n",
370 ERROR+FILE_NOT_FOUND);
374 if (CC->upload_fp != NULL) {
375 cprintf("%d You already have a upload file open.\n",ERROR);
379 for (a=0; a<strlen(CC->upl_file); ++a)
380 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
381 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
382 CC->quickroom.QRdirname,CC->upl_file);
383 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
384 CC->quickroom.QRdirname);
386 CC->upload_fp = fopen(CC->upl_path,"r");
387 if (CC->upload_fp != NULL) {
388 fclose(CC->upload_fp);
389 CC->upload_fp = NULL;
390 cprintf("%d '%s' already exists\n",
391 ERROR+ALREADY_EXISTS,CC->upl_path);
395 CC->upload_fp = fopen(CC->upl_path,"wb");
396 if (CC->upload_fp == NULL) {
397 cprintf("%d Cannot open %s: %s\n",
398 ERROR,CC->upl_path,strerror(errno));
401 cprintf("%d Ok\n",OK);
407 * open an image file for uploading
409 void cmd_uimg(char *cmdbuf)
411 int is_this_for_real;
416 if (num_parms(cmdbuf) < 2) {
417 cprintf("%d Usage error.\n", ERROR);
421 is_this_for_real = extract_int(cmdbuf,0);
422 extract(basenm, cmdbuf, 1);
423 if (CC->upload_fp != NULL) {
424 cprintf("%d You already have an upload file open.\n", ERROR);
428 strcpy(CC->upl_path, "");
430 for (a=0; a<strlen(basenm); ++a) {
431 basenm[a] = tolower(basenm[a]);
432 if (basenm[a]=='/') basenm[a] = '_';
435 if (CC->usersupp.axlevel >= 6) {
436 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
440 if (!strcasecmp(basenm, "_userpic_")) {
441 snprintf(CC->upl_path, sizeof CC->upl_path,
442 "./userpics/%ld.gif", CC->usersupp.usernum);
445 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
446 which_floor = extract_int(cmdbuf, 2);
447 snprintf(CC->upl_path, sizeof CC->upl_path,
448 "./images/floor.%d.gif", which_floor);
451 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
452 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
455 if (strlen(CC->upl_path) == 0) {
456 cprintf("%d Higher access required.\n",
457 ERROR+HIGHER_ACCESS_REQUIRED);
461 if (is_this_for_real == 0) {
462 cprintf("%d Ok to send image\n", OK);
466 CC->upload_fp = fopen(CC->upl_path,"wb");
467 if (CC->upload_fp == NULL) {
468 cprintf("%d Cannot open %s: %s\n",
469 ERROR,CC->upl_path,strerror(errno));
472 cprintf("%d Ok\n",OK);
473 CC->upload_type = UPL_IMAGE;
478 * close the download file
480 void cmd_clos(void) {
483 if (CC->download_fp == NULL) {
484 cprintf("%d You don't have a download file open.\n",ERROR);
488 fclose(CC->download_fp);
489 CC->download_fp = NULL;
491 if (CC->dl_is_net == 1) {
493 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
498 cprintf("%d Ok\n",OK);
505 void abort_upl(struct CitContext *who)
507 if (who->upload_fp != NULL) {
508 fclose(who->upload_fp);
509 who->upload_fp = NULL;
510 unlink(CC->upl_path);
517 * close the upload file
519 void cmd_ucls(char *cmd)
524 if (CC->upload_fp == NULL) {
525 cprintf("%d You don't have an upload file open.\n",ERROR);
529 fclose(CC->upload_fp);
530 CC->upload_fp = NULL;
532 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
533 CC->upload_type = UPL_FILE;
534 cprintf("%d Upload completed.\n", OK);
538 if (!strcasecmp(cmd,"1")) {
539 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
540 fp = fopen(CC->upl_filedir,"a");
541 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
543 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
547 /* put together an upload notice */
549 fp=fopen(CC->temp,"wb");
553 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
554 fprintf(fp,"T%ld",now); putc(0,fp);
555 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
556 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
557 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
558 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
561 save_message(CC->temp, "", "", M_LOCAL, 1);
566 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
571 * read from the download file
573 void cmd_read(char *cmdbuf)
579 start_pos = extract_long(cmdbuf,0);
580 bytes = extract_int(cmdbuf,1);
582 if (CC->download_fp == NULL) {
583 cprintf("%d You don't have a download file open.\n",ERROR);
588 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
592 fseek(CC->download_fp,start_pos,0);
593 fread(buf,bytes,1,CC->download_fp);
594 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
595 client_write(buf, bytes);
601 * write to the upload file
603 void cmd_writ(char *cmdbuf)
608 bytes = extract_int(cmdbuf,0);
610 if (CC->upload_fp == NULL) {
611 cprintf("%d You don't have an upload file open.\n",ERROR);
616 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
620 cprintf("%d %d\n",SEND_BINARY,bytes);
621 client_read(buf, bytes);
622 fwrite(buf,bytes,1,CC->upload_fp);
628 * cmd_netp() - identify as network poll session
630 void cmd_netp(char *cmdbuf)
634 extract(buf,cmdbuf,1);
635 if (strcasecmp(buf,config.c_net_password)) {
636 cprintf("%d authentication failed\n",ERROR);
639 extract(CC->net_node,cmdbuf,0);
640 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
644 * cmd_ndop() - open a network spool file for downloading
646 void cmd_ndop(char *cmdbuf)
651 if (strlen(CC->net_node)==0) {
652 cprintf("%d Not authenticated as a network node.\n",
653 ERROR+NOT_LOGGED_IN);
657 if (CC->download_fp != NULL) {
658 cprintf("%d You already have a download file open.\n",ERROR);
662 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
665 /* first open the file in append mode in order to create a
666 * zero-length file if it doesn't already exist
668 CC->download_fp = fopen(pathname,"a");
669 fclose(CC->download_fp);
672 CC->download_fp = fopen(pathname,"r");
673 if (CC->download_fp==NULL) {
674 cprintf("%d cannot open %s: %s\n",
675 ERROR,pathname,strerror(errno));
680 /* set this flag so other routines know that the download file
681 * currently open is a network spool file
685 stat(pathname,&statbuf);
686 cprintf("%d %ld\n",OK,statbuf.st_size);
690 * cmd_nuop() - open a network spool file for uploading
692 void cmd_nuop(char *cmdbuf)
694 if (strlen(CC->net_node)==0) {
695 cprintf("%d Not authenticated as a network node.\n",
696 ERROR+NOT_LOGGED_IN);
700 if (CC->upload_fp != NULL) {
701 cprintf("%d You already have an upload file open.\n",ERROR);
705 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
706 BBSDIR,CC->net_node,getpid());
708 CC->upload_fp = fopen(CC->upl_path,"r");
709 if (CC->upload_fp != NULL) {
710 fclose(CC->upload_fp);
711 CC->upload_fp = NULL;
712 cprintf("%d '%s' already exists\n",
713 ERROR+ALREADY_EXISTS,CC->upl_path);
717 CC->upload_fp = fopen(CC->upl_path,"w");
718 if (CC->upload_fp == NULL) {
719 cprintf("%d Cannot open %s: %s\n",
720 ERROR,CC->upl_path,strerror(errno));
724 CC->upload_type = UPL_NET;
725 cprintf("%d Ok\n",OK);