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) {
235 fstat(fileno(CC->download_fp), &statbuf);
236 cprintf("%d %ld|%ld|%s|%s\n", OK, statbuf.st_size, statbuf.st_mtime,
237 filename, mime_type);
242 * open a file for downloading
244 void cmd_open(char *cmdbuf)
250 extract(filename,cmdbuf,0);
252 if (!(CC->logged_in)) {
253 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
257 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
258 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
262 if (strlen(filename)==0) {
263 cprintf("%d You must specify a file name.\n",
264 ERROR+FILE_NOT_FOUND);
268 if (CC->download_fp != NULL) {
269 cprintf("%d You already have a download file open.\n",ERROR);
273 for (a=0; a<strlen(filename); ++a)
274 if (filename[a]=='/') filename[a] = '_';
276 snprintf(pathname,sizeof pathname,
277 "./files/%s/%s",CC->quickroom.QRdirname,filename);
278 CC->download_fp = fopen(pathname,"r");
280 if (CC->download_fp==NULL) {
281 cprintf("%d cannot open %s: %s\n",
282 ERROR,pathname,strerror(errno));
286 OpenCmdResult(filename, "application/octet-stream");
292 void cmd_oimg(char *cmdbuf)
296 struct usersupp usbuf;
301 extract(filename,cmdbuf,0);
303 if (strlen(filename)==0) {
304 cprintf("%d You must specify a file name.\n",
305 ERROR+FILE_NOT_FOUND);
309 if (CC->download_fp != NULL) {
310 cprintf("%d You already have a download file open.\n",ERROR);
314 if (!strcasecmp(filename, "_userpic_")) {
315 extract(which_user, cmdbuf, 1);
316 if (getuser(&usbuf, which_user) != 0) {
317 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
320 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
323 else if (!strcasecmp(filename, "_floorpic_")) {
324 which_floor = extract_int(cmdbuf, 1);
325 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
328 else if (!strcasecmp(filename, "_roompic_")) {
329 assoc_file_name(pathname, &CC->quickroom, "images");
332 for (a=0; a<strlen(filename); ++a) {
333 filename[a] = tolower(filename[a]);
334 if (filename[a]=='/') filename[a] = '_';
336 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
339 CC->download_fp = fopen(pathname,"r");
340 if (CC->download_fp == NULL) {
341 cprintf("%d Cannot open %s: %s\n",
342 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
346 OpenCmdResult(pathname, "image/gif");
350 * open a file for uploading
352 void cmd_uopn(char *cmdbuf)
356 extract(CC->upl_file,cmdbuf,0);
357 extract(CC->upl_comment,cmdbuf,1);
359 if (!(CC->logged_in)) {
360 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
364 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
365 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
369 if (strlen(CC->upl_file)==0) {
370 cprintf("%d You must specify a file name.\n",
371 ERROR+FILE_NOT_FOUND);
375 if (CC->upload_fp != NULL) {
376 cprintf("%d You already have a upload file open.\n",ERROR);
380 for (a=0; a<strlen(CC->upl_file); ++a)
381 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
382 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
383 CC->quickroom.QRdirname,CC->upl_file);
384 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
385 CC->quickroom.QRdirname);
387 CC->upload_fp = fopen(CC->upl_path,"r");
388 if (CC->upload_fp != NULL) {
389 fclose(CC->upload_fp);
390 CC->upload_fp = NULL;
391 cprintf("%d '%s' already exists\n",
392 ERROR+ALREADY_EXISTS,CC->upl_path);
396 CC->upload_fp = fopen(CC->upl_path,"wb");
397 if (CC->upload_fp == NULL) {
398 cprintf("%d Cannot open %s: %s\n",
399 ERROR,CC->upl_path,strerror(errno));
402 cprintf("%d Ok\n",OK);
408 * open an image file for uploading
410 void cmd_uimg(char *cmdbuf)
412 int is_this_for_real;
417 if (num_parms(cmdbuf) < 2) {
418 cprintf("%d Usage error.\n", ERROR);
422 is_this_for_real = extract_int(cmdbuf,0);
423 extract(basenm, cmdbuf, 1);
424 if (CC->upload_fp != NULL) {
425 cprintf("%d You already have an upload file open.\n", ERROR);
429 strcpy(CC->upl_path, "");
431 for (a=0; a<strlen(basenm); ++a) {
432 basenm[a] = tolower(basenm[a]);
433 if (basenm[a]=='/') basenm[a] = '_';
436 if (CC->usersupp.axlevel >= 6) {
437 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
441 if (!strcasecmp(basenm, "_userpic_")) {
442 snprintf(CC->upl_path, sizeof CC->upl_path,
443 "./userpics/%ld.gif", CC->usersupp.usernum);
446 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
447 which_floor = extract_int(cmdbuf, 2);
448 snprintf(CC->upl_path, sizeof CC->upl_path,
449 "./images/floor.%d.gif", which_floor);
452 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
453 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
456 if (strlen(CC->upl_path) == 0) {
457 cprintf("%d Higher access required.\n",
458 ERROR+HIGHER_ACCESS_REQUIRED);
462 if (is_this_for_real == 0) {
463 cprintf("%d Ok to send image\n", OK);
467 CC->upload_fp = fopen(CC->upl_path,"wb");
468 if (CC->upload_fp == NULL) {
469 cprintf("%d Cannot open %s: %s\n",
470 ERROR,CC->upl_path,strerror(errno));
473 cprintf("%d Ok\n",OK);
474 CC->upload_type = UPL_IMAGE;
479 * close the download file
481 void cmd_clos(void) {
484 if (CC->download_fp == NULL) {
485 cprintf("%d You don't have a download file open.\n",ERROR);
489 fclose(CC->download_fp);
490 CC->download_fp = NULL;
492 if (CC->dl_is_net == 1) {
494 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
499 cprintf("%d Ok\n",OK);
506 void abort_upl(struct CitContext *who)
508 if (who->upload_fp != NULL) {
509 fclose(who->upload_fp);
510 who->upload_fp = NULL;
511 unlink(CC->upl_path);
518 * close the upload file
520 void cmd_ucls(char *cmd)
523 char upload_notice[512];
525 if (CC->upload_fp == NULL) {
526 cprintf("%d You don't have an upload file open.\n",ERROR);
530 fclose(CC->upload_fp);
531 CC->upload_fp = NULL;
533 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
534 CC->upload_type = UPL_FILE;
535 cprintf("%d Upload completed.\n", OK);
537 if (CC->upload_type == UPL_NET) {
539 execlp("./netproc", "netproc", "-i", NULL);
547 if (!strcasecmp(cmd,"1")) {
548 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
549 fp = fopen(CC->upl_filedir,"a");
550 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
552 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
556 /* put together an upload notice */
557 sprintf(upload_notice,
558 "NEW UPLOAD: '%s'\n %s\n",
559 CC->upl_file,CC->upl_comment);
560 quickie_message(CC->curr_user, NULL, CC->quickroom.QRname,
565 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
572 * read from the download file
574 void cmd_read(char *cmdbuf)
580 start_pos = extract_long(cmdbuf,0);
581 bytes = extract_int(cmdbuf,1);
583 if (CC->download_fp == NULL) {
584 cprintf("%d You don't have a download file open.\n",ERROR);
589 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
593 fseek(CC->download_fp,start_pos,0);
594 fread(buf,bytes,1,CC->download_fp);
595 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
596 client_write(buf, bytes);
602 * write to the upload file
604 void cmd_writ(char *cmdbuf)
609 bytes = extract_int(cmdbuf,0);
611 if (CC->upload_fp == NULL) {
612 cprintf("%d You don't have an upload file open.\n",ERROR);
617 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
621 cprintf("%d %d\n",SEND_BINARY,bytes);
622 client_read(buf, bytes);
623 fwrite(buf,bytes,1,CC->upload_fp);
629 * cmd_netp() - identify as network poll session
631 void cmd_netp(char *cmdbuf)
635 extract(buf,cmdbuf,1);
636 if (strcasecmp(buf,config.c_net_password)) {
637 cprintf("%d authentication failed\n",ERROR);
640 extract(CC->net_node,cmdbuf,0);
641 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
645 * cmd_ndop() - open a network spool file for downloading
647 void cmd_ndop(char *cmdbuf)
652 if (strlen(CC->net_node)==0) {
653 cprintf("%d Not authenticated as a network node.\n",
654 ERROR+NOT_LOGGED_IN);
658 if (CC->download_fp != NULL) {
659 cprintf("%d You already have a download file open.\n",ERROR);
663 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
666 /* first open the file in append mode in order to create a
667 * zero-length file if it doesn't already exist
669 CC->download_fp = fopen(pathname,"a");
670 if (CC->download_fp != NULL) fclose(CC->download_fp);
673 CC->download_fp = fopen(pathname,"r");
674 if (CC->download_fp==NULL) {
675 cprintf("%d cannot open %s: %s\n",
676 ERROR,pathname,strerror(errno));
681 /* set this flag so other routines know that the download file
682 * currently open is a network spool file
686 stat(pathname,&statbuf);
687 cprintf("%d %ld\n",OK,statbuf.st_size);
691 * cmd_nuop() - open a network spool file for uploading
693 void cmd_nuop(char *cmdbuf)
695 if (strlen(CC->net_node)==0) {
696 cprintf("%d Not authenticated as a network node.\n",
697 ERROR+NOT_LOGGED_IN);
701 if (CC->upload_fp != NULL) {
702 cprintf("%d You already have an upload file open.\n",ERROR);
706 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
707 BBSDIR,CC->net_node,getpid());
709 CC->upload_fp = fopen(CC->upl_path,"r");
710 if (CC->upload_fp != NULL) {
711 fclose(CC->upload_fp);
712 CC->upload_fp = NULL;
713 cprintf("%d '%s' already exists\n",
714 ERROR+ALREADY_EXISTS,CC->upl_path);
718 CC->upload_fp = fopen(CC->upl_path,"w");
719 if (CC->upload_fp == NULL) {
720 cprintf("%d Cannot open %s: %s\n",
721 ERROR,CC->upl_path,strerror(errno));
725 CC->upload_type = UPL_NET;
726 cprintf("%d Ok\n",OK);