17 #include "sysdep_decls.h"
23 #include "citserver.h"
25 void cmd_delf(char *filename)
30 if (CtdlAccessCheck(ac_room_aide)) return;
32 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
33 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
37 if (strlen(filename)==0) {
38 cprintf("%d You must specify a file name.\n",
39 ERROR+FILE_NOT_FOUND);
42 for (a=0; a<strlen(filename); ++a)
43 if (filename[a]=='/') filename[a] = '_';
44 snprintf(pathname,sizeof pathname,"./files/%s/%s",
45 CC->quickroom.QRdirname,filename);
47 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
48 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
55 * move a file from one room directory to another
57 void cmd_movf(char *cmdbuf)
65 struct quickroom qrbuf;
67 extract(filename,cmdbuf,0);
68 extract(newroom,cmdbuf,1);
70 if (CtdlAccessCheck(ac_room_aide)) return;
72 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
73 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
77 if (strlen(filename)==0) {
78 cprintf("%d You must specify a file name.\n",
79 ERROR+FILE_NOT_FOUND);
83 for (a=0; a<strlen(filename); ++a)
84 if (filename[a]=='/') filename[a] = '_';
85 snprintf(pathname,sizeof pathname,"./files/%s/%s",
86 CC->quickroom.QRdirname,filename);
87 if (access(pathname,0)!=0) {
88 cprintf("%d File '%s' not found.\n",
89 ERROR+FILE_NOT_FOUND,pathname);
93 if (getroom(&qrbuf, newroom)!=0) {
94 cprintf("%d '%s' does not exist.\n",
98 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
99 cprintf("%d '%s' is not a directory room.\n",
100 ERROR+NOT_HERE,qrbuf.QRname);
103 snprintf(newpath,sizeof newpath,"./files/%s/%s",qrbuf.QRdirname,
105 if (link(pathname,newpath)!=0) {
106 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
111 /* this is a crude method of copying the file description */
112 snprintf(buf, sizeof buf,
113 "cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
114 CC->quickroom.QRdirname,
118 cprintf("%d File '%s' has been moved.\n",OK,filename);
123 * send a file over the net
125 void cmd_netf(char *cmdbuf)
127 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
132 extract(filename,cmdbuf,0);
133 extract(destsys,cmdbuf,1);
135 if (CtdlAccessCheck(ac_room_aide)) return;
137 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
138 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
142 if (strlen(filename)==0) {
143 cprintf("%d You must specify a file name.\n",
144 ERROR+FILE_NOT_FOUND);
148 for (a=0; a<strlen(filename); ++a)
149 if (filename[a]=='/') filename[a] = '_';
150 snprintf(pathname,sizeof pathname,"./files/%s/%s",
151 CC->quickroom.QRdirname,filename);
152 if (access(pathname,0)!=0) {
153 cprintf("%d File '%s' not found.\n",
154 ERROR+FILE_NOT_FOUND,pathname);
157 snprintf(buf,sizeof buf,"sysop@%s",destsys);
160 cprintf("%d No such system: '%s'\n",
161 ERROR+NO_SUCH_SYSTEM,destsys);
164 snprintf(outfile,sizeof outfile,"%s/network/spoolin/nsf.%d",BBSDIR,
166 ofp=fopen(outfile,"a");
168 cprintf("%d internal error\n",ERROR);
173 putc(MES_NORMAL,ofp);
175 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
177 fprintf(ofp,"T%ld",(long)now); putc(0,ofp);
178 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
179 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
180 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
181 fprintf(ofp,"D%s",destsys); putc(0,ofp);
182 fprintf(ofp,"SFILE"); putc(0,ofp);
186 snprintf(buf,sizeof buf,
187 "cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
188 CC->quickroom.QRdirname,filename,filename,outfile);
191 ofp = fopen(outfile,"a");
195 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
196 system("nohup ./netproc -i >/dev/null 2>&1 &");
201 * This code is common to all commands which open a file for downloading.
202 * It examines the file and displays the OK result code and some information
203 * about the file. NOTE: this stuff is Unix dependent.
205 void OpenCmdResult(char *filename, char *mime_type) {
210 fstat(fileno(CC->download_fp), &statbuf);
211 filesize = (long) statbuf.st_size;
212 modtime = (time_t) statbuf.st_mtime;
214 cprintf("%d %ld|%ld|%s|%s\n",
215 OK, filesize, modtime, filename, mime_type);
220 * open a file for downloading
222 void cmd_open(char *cmdbuf)
228 extract(filename,cmdbuf,0);
230 if (CtdlAccessCheck(ac_logged_in)) return;
232 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
233 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
237 if (strlen(filename)==0) {
238 cprintf("%d You must specify a file name.\n",
239 ERROR+FILE_NOT_FOUND);
243 if (CC->download_fp != NULL) {
244 cprintf("%d You already have a download file open.\n",ERROR);
248 for (a=0; a<strlen(filename); ++a)
249 if (filename[a]=='/') filename[a] = '_';
251 snprintf(pathname,sizeof pathname,
252 "./files/%s/%s",CC->quickroom.QRdirname,filename);
253 CC->download_fp = fopen(pathname,"r");
255 if (CC->download_fp==NULL) {
256 cprintf("%d cannot open %s: %s\n",
257 ERROR,pathname,strerror(errno));
261 OpenCmdResult(filename, "application/octet-stream");
267 void cmd_oimg(char *cmdbuf)
271 struct usersupp usbuf;
276 extract(filename,cmdbuf,0);
278 if (strlen(filename)==0) {
279 cprintf("%d You must specify a file name.\n",
280 ERROR+FILE_NOT_FOUND);
284 if (CC->download_fp != NULL) {
285 cprintf("%d You already have a download file open.\n",ERROR);
289 if (!strcasecmp(filename, "_userpic_")) {
290 extract(which_user, cmdbuf, 1);
291 if (getuser(&usbuf, which_user) != 0) {
292 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
295 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
298 else if (!strcasecmp(filename, "_floorpic_")) {
299 which_floor = extract_int(cmdbuf, 1);
300 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
303 else if (!strcasecmp(filename, "_roompic_")) {
304 assoc_file_name(pathname, &CC->quickroom, "images");
307 for (a=0; a<strlen(filename); ++a) {
308 filename[a] = tolower(filename[a]);
309 if (filename[a]=='/') filename[a] = '_';
311 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
314 CC->download_fp = fopen(pathname,"r");
315 if (CC->download_fp == NULL) {
316 cprintf("%d Cannot open %s: %s\n",
317 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
321 OpenCmdResult(pathname, "image/gif");
325 * open a file for uploading
327 void cmd_uopn(char *cmdbuf)
331 extract(CC->upl_file,cmdbuf,0);
332 extract(CC->upl_comment,cmdbuf,1);
334 if (CtdlAccessCheck(ac_logged_in)) return;
336 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
337 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
341 if (strlen(CC->upl_file)==0) {
342 cprintf("%d You must specify a file name.\n",
343 ERROR+FILE_NOT_FOUND);
347 if (CC->upload_fp != NULL) {
348 cprintf("%d You already have a upload file open.\n",ERROR);
352 for (a=0; a<strlen(CC->upl_file); ++a)
353 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
354 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
355 CC->quickroom.QRdirname,CC->upl_file);
356 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
357 CC->quickroom.QRdirname);
359 CC->upload_fp = fopen(CC->upl_path,"r");
360 if (CC->upload_fp != NULL) {
361 fclose(CC->upload_fp);
362 CC->upload_fp = NULL;
363 cprintf("%d '%s' already exists\n",
364 ERROR+ALREADY_EXISTS,CC->upl_path);
368 CC->upload_fp = fopen(CC->upl_path,"wb");
369 if (CC->upload_fp == NULL) {
370 cprintf("%d Cannot open %s: %s\n",
371 ERROR,CC->upl_path,strerror(errno));
374 cprintf("%d Ok\n",OK);
380 * open an image file for uploading
382 void cmd_uimg(char *cmdbuf)
384 int is_this_for_real;
389 if (num_parms(cmdbuf) < 2) {
390 cprintf("%d Usage error.\n", ERROR);
394 is_this_for_real = extract_int(cmdbuf,0);
395 extract(basenm, cmdbuf, 1);
396 if (CC->upload_fp != NULL) {
397 cprintf("%d You already have an upload file open.\n", ERROR);
401 strcpy(CC->upl_path, "");
403 for (a=0; a<strlen(basenm); ++a) {
404 basenm[a] = tolower(basenm[a]);
405 if (basenm[a]=='/') basenm[a] = '_';
408 if (CC->usersupp.axlevel >= 6) {
409 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
413 if (!strcasecmp(basenm, "_userpic_")) {
414 snprintf(CC->upl_path, sizeof CC->upl_path,
415 "./userpics/%ld.gif", CC->usersupp.usernum);
418 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
419 which_floor = extract_int(cmdbuf, 2);
420 snprintf(CC->upl_path, sizeof CC->upl_path,
421 "./images/floor.%d.gif", which_floor);
424 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
425 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
428 if (strlen(CC->upl_path) == 0) {
429 cprintf("%d Higher access required.\n",
430 ERROR+HIGHER_ACCESS_REQUIRED);
434 if (is_this_for_real == 0) {
435 cprintf("%d Ok to send image\n", OK);
439 CC->upload_fp = fopen(CC->upl_path,"wb");
440 if (CC->upload_fp == NULL) {
441 cprintf("%d Cannot open %s: %s\n",
442 ERROR,CC->upl_path,strerror(errno));
445 cprintf("%d Ok\n",OK);
446 CC->upload_type = UPL_IMAGE;
451 * close the download file
453 void cmd_clos(void) {
456 if (CC->download_fp == NULL) {
457 cprintf("%d You don't have a download file open.\n",ERROR);
461 fclose(CC->download_fp);
462 CC->download_fp = NULL;
464 if (CC->dl_is_net == 1) {
466 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
471 cprintf("%d Ok\n",OK);
478 void abort_upl(struct CitContext *who)
480 if (who->upload_fp != NULL) {
481 fclose(who->upload_fp);
482 who->upload_fp = NULL;
483 unlink(CC->upl_path);
490 * close the upload file
492 void cmd_ucls(char *cmd)
495 char upload_notice[512];
497 if (CC->upload_fp == NULL) {
498 cprintf("%d You don't have an upload file open.\n",ERROR);
502 fclose(CC->upload_fp);
503 CC->upload_fp = NULL;
505 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
506 CC->upload_type = UPL_FILE;
507 cprintf("%d Upload completed.\n", OK);
509 if (CC->upload_type == UPL_NET) {
511 execlp("./netproc", "netproc", "-i", NULL);
519 if (!strcasecmp(cmd,"1")) {
520 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
521 fp = fopen(CC->upl_filedir,"a");
522 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
524 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
528 /* put together an upload notice */
529 sprintf(upload_notice,
530 "NEW UPLOAD: '%s'\n %s\n",
531 CC->upl_file,CC->upl_comment);
532 quickie_message(CC->curr_user, NULL, CC->quickroom.QRname,
537 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
544 * read from the download file
546 void cmd_read(char *cmdbuf)
552 start_pos = extract_long(cmdbuf,0);
553 bytes = extract_int(cmdbuf,1);
555 if (CC->download_fp == NULL) {
556 cprintf("%d You don't have a download file open.\n",ERROR);
561 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
565 fseek(CC->download_fp,start_pos,0);
566 fread(buf,bytes,1,CC->download_fp);
567 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
568 client_write(buf, bytes);
574 * write to the upload file
576 void cmd_writ(char *cmdbuf)
581 bytes = extract_int(cmdbuf,0);
583 if (CC->upload_fp == NULL) {
584 cprintf("%d You don't have an upload file open.\n",ERROR);
589 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
593 cprintf("%d %d\n",SEND_BINARY,bytes);
594 client_read(buf, bytes);
595 fwrite(buf,bytes,1,CC->upload_fp);
601 * cmd_netp() - identify as network poll session
603 void cmd_netp(char *cmdbuf)
607 extract(buf,cmdbuf,1);
608 if (strcasecmp(buf,config.c_net_password)) {
609 cprintf("%d authentication failed\n",ERROR);
612 extract(CC->net_node,cmdbuf,0);
613 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
617 * cmd_ndop() - open a network spool file for downloading
619 void cmd_ndop(char *cmdbuf)
624 if (strlen(CC->net_node)==0) {
625 cprintf("%d Not authenticated as a network node.\n",
626 ERROR+NOT_LOGGED_IN);
630 if (CC->download_fp != NULL) {
631 cprintf("%d You already have a download file open.\n",ERROR);
635 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
638 /* first open the file in append mode in order to create a
639 * zero-length file if it doesn't already exist
641 CC->download_fp = fopen(pathname,"a");
642 if (CC->download_fp != NULL) fclose(CC->download_fp);
645 CC->download_fp = fopen(pathname,"r");
646 if (CC->download_fp==NULL) {
647 cprintf("%d cannot open %s: %s\n",
648 ERROR,pathname,strerror(errno));
653 /* set this flag so other routines know that the download file
654 * currently open is a network spool file
658 stat(pathname,&statbuf);
659 cprintf("%d %ld\n",OK,statbuf.st_size);
663 * cmd_nuop() - open a network spool file for uploading
665 void cmd_nuop(char *cmdbuf)
667 if (strlen(CC->net_node)==0) {
668 cprintf("%d Not authenticated as a network node.\n",
669 ERROR+NOT_LOGGED_IN);
673 if (CC->upload_fp != NULL) {
674 cprintf("%d You already have an upload file open.\n",ERROR);
678 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
679 BBSDIR,CC->net_node,getpid());
681 CC->upload_fp = fopen(CC->upl_path,"r");
682 if (CC->upload_fp != NULL) {
683 fclose(CC->upload_fp);
684 CC->upload_fp = NULL;
685 cprintf("%d '%s' already exists\n",
686 ERROR+ALREADY_EXISTS,CC->upl_path);
690 CC->upload_fp = fopen(CC->upl_path,"w");
691 if (CC->upload_fp == NULL) {
692 cprintf("%d Cannot open %s: %s\n",
693 ERROR,CC->upl_path,strerror(errno));
697 CC->upload_type = UPL_NET;
698 cprintf("%d Ok\n",OK);