17 #include "sysdep_decls.h"
23 void cmd_delf(char *filename)
28 if (!(CC->logged_in)) {
29 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
33 if (!is_room_aide()) {
34 cprintf("%d Higher access required.\n",
35 ERROR+HIGHER_ACCESS_REQUIRED);
40 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
41 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
45 if (strlen(filename)==0) {
46 cprintf("%d You must specify a file name.\n",
47 ERROR+FILE_NOT_FOUND);
50 for (a=0; a<strlen(filename); ++a)
51 if (filename[a]=='/') filename[a] = '_';
52 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
54 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
55 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
62 * move a file from one room directory to another
64 void cmd_movf(char *cmdbuf)
72 struct quickroom qrbuf;
74 extract(filename,cmdbuf,0);
75 extract(newroom,cmdbuf,1);
77 if (!(CC->logged_in)) {
78 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
82 if (!is_room_aide()) {
83 cprintf("%d Higher access required.\n",
84 ERROR+HIGHER_ACCESS_REQUIRED);
88 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
89 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
93 if (strlen(filename)==0) {
94 cprintf("%d You must specify a file name.\n",
95 ERROR+FILE_NOT_FOUND);
99 for (a=0; a<strlen(filename); ++a)
100 if (filename[a]=='/') filename[a] = '_';
101 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
102 if (access(pathname,0)!=0) {
103 cprintf("%d File '%s' not found.\n",
104 ERROR+FILE_NOT_FOUND,pathname);
108 if (getroom(&qrbuf, newroom)!=0) {
109 cprintf("%d '%s' does not exist.\n",
113 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
114 cprintf("%d '%s' is not a directory room.\n",
115 ERROR+NOT_HERE,qrbuf.QRname);
118 sprintf(newpath,"./files/%s/%s",qrbuf.QRdirname,filename);
119 if (link(pathname,newpath)!=0) {
120 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
125 /* this is a crude method of copying the file description */
126 sprintf(buf,"cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
127 CC->quickroom.QRdirname,
131 cprintf("%d File '%s' has been moved.\n",OK,filename);
136 * send a file over the net
138 void cmd_netf(char *cmdbuf)
140 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
145 extract(filename,cmdbuf,0);
146 extract(destsys,cmdbuf,1);
148 if (!(CC->logged_in)) {
149 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
153 if (!is_room_aide()) {
154 cprintf("%d Higher access required.\n",
155 ERROR+HIGHER_ACCESS_REQUIRED);
159 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
160 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
164 if (strlen(filename)==0) {
165 cprintf("%d You must specify a file name.\n",
166 ERROR+FILE_NOT_FOUND);
170 for (a=0; a<strlen(filename); ++a)
171 if (filename[a]=='/') filename[a] = '_';
172 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
173 if (access(pathname,0)!=0) {
174 cprintf("%d File '%s' not found.\n",
175 ERROR+FILE_NOT_FOUND,pathname);
178 sprintf(buf,"sysop@%s",destsys);
181 cprintf("%d No such system: '%s'\n",
182 ERROR+NO_SUCH_SYSTEM,destsys);
185 sprintf(outfile,"%s/network/spoolin/nsf.%d",BBSDIR,getpid());
186 ofp=fopen(outfile,"a");
188 cprintf("%d internal error\n",ERROR);
193 putc(MES_NORMAL,ofp);
195 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
197 fprintf(ofp,"T%ld",now); putc(0,ofp);
198 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
199 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
200 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
201 fprintf(ofp,"D%s",destsys); putc(0,ofp);
202 fprintf(ofp,"SFILE"); putc(0,ofp);
206 sprintf(buf,"cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
207 CC->quickroom.QRdirname,filename,filename,outfile);
210 ofp = fopen(outfile,"a");
214 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
215 system("nohup ./netproc >/dev/null 2>&1 &");
220 * This code is common to all commands which open a file for downloading.
221 * It examines the file and displays the OK result code and some information
222 * about the file. NOTE: this stuff is Unix dependent.
224 void OpenCmdResult(void) {
227 fstat(fileno(CC->download_fp), &statbuf);
228 cprintf("%d %ld|%ld\n", OK, statbuf.st_size, statbuf.st_mtime);
233 * open a file for downloading
235 void cmd_open(char *cmdbuf)
241 extract(filename,cmdbuf,0);
243 if (!(CC->logged_in)) {
244 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
248 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
249 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
253 if (strlen(filename)==0) {
254 cprintf("%d You must specify a file name.\n",
255 ERROR+FILE_NOT_FOUND);
259 if (CC->download_fp != NULL) {
260 cprintf("%d You already have a download file open.\n",ERROR);
264 for (a=0; a<strlen(filename); ++a)
265 if (filename[a]=='/') filename[a] = '_';
267 snprintf(pathname,sizeof pathname,
268 "./files/%s/%s",CC->quickroom.QRdirname,filename);
269 CC->download_fp = fopen(pathname,"r");
271 if (CC->download_fp==NULL) {
272 cprintf("%d cannot open %s: %s\n",
273 ERROR,pathname,strerror(errno));
283 void cmd_oimg(char *cmdbuf)
287 struct usersupp usbuf;
292 extract(filename,cmdbuf,0);
294 if (strlen(filename)==0) {
295 cprintf("%d You must specify a file name.\n",
296 ERROR+FILE_NOT_FOUND);
300 if (CC->download_fp != NULL) {
301 cprintf("%d You already have a download file open.\n",ERROR);
305 if (!strcasecmp(filename, "_userpic_")) {
306 extract(which_user, cmdbuf, 1);
307 if (getuser(&usbuf, which_user) != 0) {
308 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
311 sprintf(pathname, "./userpics/%ld.gif", usbuf.usernum);
313 else if (!strcasecmp(filename, "_floorpic_")) {
314 which_floor = extract_int(cmdbuf, 1);
315 sprintf(pathname, "./images/floor.%d.gif", which_floor);
317 else if (!strcasecmp(filename, "_roompic_")) {
318 assoc_file_name(pathname, &CC->quickroom, "images");
321 for (a=0; a<strlen(filename); ++a) {
322 filename[a] = tolower(filename[a]);
323 if (filename[a]=='/') filename[a] = '_';
325 sprintf(pathname,"./images/%s.gif",filename);
328 CC->download_fp = fopen(pathname,"r");
329 if (CC->download_fp == NULL) {
330 cprintf("%d Cannot open %s: %s\n",
331 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
339 * open a file for uploading
341 void cmd_uopn(char *cmdbuf)
345 extract(CC->upl_file,cmdbuf,0);
346 extract(CC->upl_comment,cmdbuf,1);
348 if (!(CC->logged_in)) {
349 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
353 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
354 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
358 if (strlen(CC->upl_file)==0) {
359 cprintf("%d You must specify a file name.\n",
360 ERROR+FILE_NOT_FOUND);
364 if (CC->upload_fp != NULL) {
365 cprintf("%d You already have a upload file open.\n",ERROR);
369 for (a=0; a<strlen(CC->upl_file); ++a)
370 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
371 sprintf(CC->upl_path,"./files/%s/%s",CC->quickroom.QRdirname,CC->upl_file);
372 sprintf(CC->upl_filedir,"./files/%s/filedir",CC->quickroom.QRdirname);
374 CC->upload_fp = fopen(CC->upl_path,"r");
375 if (CC->upload_fp != NULL) {
376 fclose(CC->upload_fp);
377 CC->upload_fp = NULL;
378 cprintf("%d '%s' already exists\n",
379 ERROR+ALREADY_EXISTS,CC->upl_path);
383 CC->upload_fp = fopen(CC->upl_path,"wb");
384 if (CC->upload_fp == NULL) {
385 cprintf("%d Cannot open %s: %s\n",
386 ERROR,CC->upl_path,strerror(errno));
389 cprintf("%d Ok\n",OK);
395 * open an image file for uploading
397 void cmd_uimg(char *cmdbuf)
399 int is_this_for_real;
404 if (num_parms(cmdbuf) < 2) {
405 cprintf("%d Usage error.\n", ERROR);
409 is_this_for_real = extract_int(cmdbuf,0);
410 extract(basenm, cmdbuf, 1);
411 if (CC->upload_fp != NULL) {
412 cprintf("%d You already have an upload file open.\n", ERROR);
416 strcpy(CC->upl_path, "");
418 for (a=0; a<strlen(basenm); ++a) {
419 basenm[a] = tolower(basenm[a]);
420 if (basenm[a]=='/') basenm[a] = '_';
423 if (CC->usersupp.axlevel >= 6) {
424 sprintf(CC->upl_path, "./images/%s", basenm);
427 if (!strcasecmp(basenm, "_userpic_")) {
428 sprintf(CC->upl_path, "./userpics/%ld.gif",
429 CC->usersupp.usernum);
432 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
433 which_floor = extract_int(cmdbuf, 2);
434 sprintf(CC->upl_path, "./images/floor.%d.gif", which_floor);
437 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
438 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
441 if (strlen(CC->upl_path) == 0) {
442 cprintf("%d Higher access required.\n",
443 ERROR+HIGHER_ACCESS_REQUIRED);
447 if (is_this_for_real == 0) {
448 cprintf("%d Ok to send image\n", OK);
452 CC->upload_fp = fopen(CC->upl_path,"wb");
453 if (CC->upload_fp == NULL) {
454 cprintf("%d Cannot open %s: %s\n",
455 ERROR,CC->upl_path,strerror(errno));
458 cprintf("%d Ok\n",OK);
459 CC->upload_type = UPL_IMAGE;
464 * close the download file
466 void cmd_clos(void) {
469 if (CC->download_fp == NULL) {
470 cprintf("%d You don't have a download file open.\n",ERROR);
474 fclose(CC->download_fp);
475 CC->download_fp = NULL;
477 if (CC->dl_is_net == 1) {
479 sprintf(buf,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
483 cprintf("%d Ok\n",OK);
490 void abort_upl(struct CitContext *who)
492 if (who->upload_fp != NULL) {
493 fclose(who->upload_fp);
494 who->upload_fp = NULL;
495 unlink(CC->upl_path);
502 * close the upload file
504 void cmd_ucls(char *cmd)
509 if (CC->upload_fp == NULL) {
510 cprintf("%d You don't have an upload file open.\n",ERROR);
514 fclose(CC->upload_fp);
515 CC->upload_fp = NULL;
517 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
518 CC->upload_type = UPL_FILE;
519 cprintf("%d Upload completed.\n", OK);
523 if (!strcasecmp(cmd,"1")) {
524 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
525 fp = fopen(CC->upl_filedir,"a");
526 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
528 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
532 /* put together an upload notice */
534 fp=fopen(CC->temp,"wb");
538 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
539 fprintf(fp,"T%ld",now); putc(0,fp);
540 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
541 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
542 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
543 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
546 save_message(CC->temp, "", 0, M_LOCAL, 1);
551 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
556 * read from the download file
558 void cmd_read(char *cmdbuf)
564 start_pos = extract_long(cmdbuf,0);
565 bytes = extract_int(cmdbuf,1);
567 if (CC->download_fp == NULL) {
568 cprintf("%d You don't have a download file open.\n",ERROR);
573 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
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 cprintf("%d %d\n",SEND_BINARY,bytes);
606 client_read(buf, bytes);
607 fwrite(buf,bytes,1,CC->upload_fp);
613 * cmd_netp() - identify as network poll session
615 void cmd_netp(char *cmdbuf)
619 extract(buf,cmdbuf,1);
620 if (strcasecmp(buf,config.c_net_password)) {
621 cprintf("%d authentication failed\n",ERROR);
624 extract(CC->net_node,cmdbuf,0);
625 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
629 * cmd_ndop() - open a network spool file for downloading
631 void cmd_ndop(char *cmdbuf)
636 if (strlen(CC->net_node)==0) {
637 cprintf("%d Not authenticated as a network node.\n",
638 ERROR+NOT_LOGGED_IN);
642 if (CC->download_fp != NULL) {
643 cprintf("%d You already have a download file open.\n",ERROR);
647 sprintf(pathname,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
649 /* first open the file in append mode in order to create a
650 * zero-length file if it doesn't already exist
652 CC->download_fp = fopen(pathname,"a");
653 fclose(CC->download_fp);
656 CC->download_fp = fopen(pathname,"r");
657 if (CC->download_fp==NULL) {
658 cprintf("%d cannot open %s: %s\n",
659 ERROR,pathname,strerror(errno));
664 /* set this flag so other routines know that the download file
665 * currently open is a network spool file
669 stat(pathname,&statbuf);
670 cprintf("%d %ld\n",OK,statbuf.st_size);
674 * cmd_nuop() - open a network spool file for uploading
676 void cmd_nuop(char *cmdbuf)
678 if (strlen(CC->net_node)==0) {
679 cprintf("%d Not authenticated as a network node.\n",
680 ERROR+NOT_LOGGED_IN);
684 if (CC->upload_fp != NULL) {
685 cprintf("%d You already have an upload file open.\n",ERROR);
689 sprintf(CC->upl_path,"%s/network/spoolin/%s.%d",
690 BBSDIR,CC->net_node,getpid());
692 CC->upload_fp = fopen(CC->upl_path,"r");
693 if (CC->upload_fp != NULL) {
694 fclose(CC->upload_fp);
695 CC->upload_fp = NULL;
696 cprintf("%d '%s' already exists\n",
697 ERROR+ALREADY_EXISTS,CC->upl_path);
701 CC->upload_fp = fopen(CC->upl_path,"w");
702 if (CC->upload_fp == NULL) {
703 cprintf("%d Cannot open %s: %s\n",
704 ERROR,CC->upl_path,strerror(errno));
708 CC->upload_type = UPL_NET;
709 cprintf("%d Ok\n",OK);