15 #include "sysdep_decls.h"
21 void cmd_delf(char *filename)
26 if (!(CC->logged_in)) {
27 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
31 if (!is_room_aide()) {
32 cprintf("%d Higher access required.\n",
33 ERROR+HIGHER_ACCESS_REQUIRED);
38 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
39 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
43 if (strlen(filename)==0) {
44 cprintf("%d You must specify a file name.\n",
45 ERROR+FILE_NOT_FOUND);
48 for (a=0; a<strlen(filename); ++a)
49 if (filename[a]=='/') filename[a] = '_';
50 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
52 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
53 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
60 * move a file from one room directory to another
62 void cmd_movf(char *cmdbuf)
70 int target_room = (-1);
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 for (a=0; a<MAXROOMS; ++a) {
109 if (!strcasecmp(qrbuf.QRname,newroom)) target_room = a;
111 if (target_room < 0) {
112 cprintf("%d Room '%s' not found.\n",
113 ERROR+ROOM_NOT_FOUND,newroom);
116 getroom(&qrbuf, target_room);
117 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
118 cprintf("%d '%s' is not a directory room.\n",
119 ERROR+NOT_HERE,qrbuf.QRname);
122 sprintf(newpath,"./files/%s/%s",qrbuf.QRdirname,filename);
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 sprintf(buf,"cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
131 CC->quickroom.QRdirname,
135 cprintf("%d File '%s' has been moved.\n",OK,filename);
140 * send a file over the net
142 void cmd_netf(char *cmdbuf)
144 char pathname[256],filename[256],destsys[256],buf[256],outfile[256];
149 extract(filename,cmdbuf,0);
150 extract(destsys,cmdbuf,1);
152 if (!(CC->logged_in)) {
153 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
157 if (!is_room_aide()) {
158 cprintf("%d Higher access required.\n",
159 ERROR+HIGHER_ACCESS_REQUIRED);
163 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
164 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
168 if (strlen(filename)==0) {
169 cprintf("%d You must specify a file name.\n",
170 ERROR+FILE_NOT_FOUND);
174 for (a=0; a<strlen(filename); ++a)
175 if (filename[a]=='/') filename[a] = '_';
176 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
177 if (access(pathname,0)!=0) {
178 cprintf("%d File '%s' not found.\n",
179 ERROR+FILE_NOT_FOUND,pathname);
182 sprintf(buf,"sysop@%s",destsys);
185 cprintf("%d No such system: '%s'\n",
186 ERROR+NO_SUCH_SYSTEM,destsys);
189 sprintf(outfile,"%s/network/spoolin/nsf.%d",BBSDIR,getpid());
190 ofp=fopen(outfile,"a");
192 cprintf("%d internal error\n",ERROR);
197 putc(MES_NORMAL,ofp);
199 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
201 fprintf(ofp,"T%ld",now); putc(0,ofp);
202 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
203 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
204 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
205 fprintf(ofp,"D%s",destsys); putc(0,ofp);
206 fprintf(ofp,"SFILE"); putc(0,ofp);
210 sprintf(buf,"cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
211 CC->quickroom.QRdirname,filename,filename,outfile);
214 ofp = fopen(outfile,"a");
218 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
219 system("nohup ./netproc >/dev/null 2>&1 &");
224 * This code is common to all commands which open a file for downloading.
225 * It examines the file and displays the OK result code and some information
226 * about the file. NOTE: this stuff is Unix dependent.
228 void OpenCmdResult(void) {
231 fstat(fileno(CC->download_fp), &statbuf);
232 cprintf("%d %ld|%ld\n", OK, statbuf.st_size, statbuf.st_mtime);
237 * open a file for downloading
239 void cmd_open(char *cmdbuf)
245 extract(filename,cmdbuf,0);
247 if (!(CC->logged_in)) {
248 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
252 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
253 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
257 if (strlen(filename)==0) {
258 cprintf("%d You must specify a file name.\n",
259 ERROR+FILE_NOT_FOUND);
263 if (CC->download_fp != NULL) {
264 cprintf("%d You already have a download file open.\n",ERROR);
268 for (a=0; a<strlen(filename); ++a)
269 if (filename[a]=='/') filename[a] = '_';
271 sprintf(pathname,"./files/%s/%s",CC->quickroom.QRdirname,filename);
272 CC->download_fp = fopen(pathname,"r");
274 if (CC->download_fp==NULL) {
275 cprintf("%d cannot open %s: %s\n",
276 ERROR,pathname,strerror(errno));
286 void cmd_oimg(char *cmdbuf)
290 struct usersupp usbuf;
295 extract(filename,cmdbuf,0);
297 if (strlen(filename)==0) {
298 cprintf("%d You must specify a file name.\n",
299 ERROR+FILE_NOT_FOUND);
303 if (CC->download_fp != NULL) {
304 cprintf("%d You already have a download file open.\n",ERROR);
308 if (!strcasecmp(filename, "_userpic_")) {
309 extract(which_user, cmdbuf, 1);
310 if (getuser(&usbuf, which_user) != 0) {
311 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
314 sprintf(pathname, "./userpics/%ld.gif", usbuf.usernum);
316 else if (!strcasecmp(filename, "_floorpic_")) {
317 which_floor = extract_int(cmdbuf, 1);
318 sprintf(pathname, "./images/floor.%d.gif", which_floor);
320 else if (!strcasecmp(filename, "_roompic_")) {
321 sprintf(pathname, "./images/room.%d.gif", CC->curr_rm);
324 for (a=0; a<strlen(filename); ++a) {
325 filename[a] = tolower(filename[a]);
326 if (filename[a]=='/') filename[a] = '_';
328 sprintf(pathname,"./images/%s.gif",filename);
331 CC->download_fp = fopen(pathname,"r");
332 if (CC->download_fp == NULL) {
333 cprintf("%d Cannot open %s: %s\n",
334 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
342 * open a file for uploading
344 void cmd_uopn(char *cmdbuf)
348 extract(CC->upl_file,cmdbuf,0);
349 extract(CC->upl_comment,cmdbuf,1);
351 if (!(CC->logged_in)) {
352 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
356 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
357 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
361 if (strlen(CC->upl_file)==0) {
362 cprintf("%d You must specify a file name.\n",
363 ERROR+FILE_NOT_FOUND);
367 if (CC->upload_fp != NULL) {
368 cprintf("%d You already have a upload file open.\n",ERROR);
372 for (a=0; a<strlen(CC->upl_file); ++a)
373 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
374 sprintf(CC->upl_path,"./files/%s/%s",CC->quickroom.QRdirname,CC->upl_file);
375 sprintf(CC->upl_filedir,"./files/%s/filedir",CC->quickroom.QRdirname);
377 CC->upload_fp = fopen(CC->upl_path,"r");
378 if (CC->upload_fp != NULL) {
379 fclose(CC->upload_fp);
380 CC->upload_fp = NULL;
381 cprintf("%d '%s' already exists\n",
382 ERROR+ALREADY_EXISTS,CC->upl_path);
386 CC->upload_fp = fopen(CC->upl_path,"wb");
387 if (CC->upload_fp == NULL) {
388 cprintf("%d Cannot open %s: %s\n",
389 ERROR,CC->upl_path,strerror(errno));
392 cprintf("%d Ok\n",OK);
398 * open an image file for uploading
400 void cmd_uimg(char *cmdbuf)
402 int is_this_for_real;
407 if (num_parms(cmdbuf) < 2) {
408 cprintf("%d Usage error.\n", ERROR);
412 is_this_for_real = extract_int(cmdbuf,0);
413 extract(basenm, cmdbuf, 1);
414 if (CC->upload_fp != NULL) {
415 cprintf("%d You already have an upload file open.\n", ERROR);
419 strcpy(CC->upl_path, "");
421 for (a=0; a<strlen(basenm); ++a) {
422 basenm[a] = tolower(basenm[a]);
423 if (basenm[a]=='/') basenm[a] = '_';
426 if (CC->usersupp.axlevel >= 6) {
427 sprintf(CC->upl_path, "./images/%s", basenm);
430 if (!strcasecmp(basenm, "_userpic_")) {
431 sprintf(CC->upl_path, "./userpics/%ld.gif",
432 CC->usersupp.usernum);
435 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
436 which_floor = extract_int(cmdbuf, 2);
437 sprintf(CC->upl_path, "./images/floor.%d.gif", which_floor);
440 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
441 sprintf(CC->upl_path, "./images/room.%d.gif", CC->curr_rm);
444 if (strlen(CC->upl_path) == 0) {
445 cprintf("%d Higher access required.\n",
446 ERROR+HIGHER_ACCESS_REQUIRED);
450 if (is_this_for_real == 0) {
451 cprintf("%d Ok to send image\n", OK);
455 CC->upload_fp = fopen(CC->upl_path,"wb");
456 if (CC->upload_fp == NULL) {
457 cprintf("%d Cannot open %s: %s\n",
458 ERROR,CC->upl_path,strerror(errno));
461 cprintf("%d Ok\n",OK);
462 CC->upload_type = UPL_IMAGE;
467 * close the download file
469 void cmd_clos(void) {
472 if (CC->download_fp == NULL) {
473 cprintf("%d You don't have a download file open.\n",ERROR);
477 fclose(CC->download_fp);
478 CC->download_fp = NULL;
480 if (CC->dl_is_net == 1) {
482 sprintf(buf,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
486 cprintf("%d Ok\n",OK);
493 void abort_upl(struct CitContext *who)
495 if (who->upload_fp != NULL) {
496 fclose(who->upload_fp);
497 who->upload_fp = NULL;
498 unlink(CC->upl_path);
505 * close the upload file
507 void cmd_ucls(char *cmd)
512 if (CC->upload_fp == NULL) {
513 cprintf("%d You don't have an upload file open.\n",ERROR);
517 fclose(CC->upload_fp);
518 CC->upload_fp = NULL;
520 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
521 CC->upload_type = UPL_FILE;
522 cprintf("%d Upload completed.\n", OK);
526 if (!strcasecmp(cmd,"1")) {
527 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
528 fp = fopen(CC->upl_filedir,"a");
529 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
531 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
535 /* put together an upload notice */
537 fp=fopen(CC->temp,"wb");
541 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
542 fprintf(fp,"T%ld",now); putc(0,fp);
543 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
544 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
545 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
546 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
549 save_message(CC->temp, "", 0, M_LOCAL, 1);
554 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
559 * read from the download file
561 void cmd_read(char *cmdbuf)
567 start_pos = extract_long(cmdbuf,0);
568 bytes = extract_int(cmdbuf,1);
570 if (CC->download_fp == NULL) {
571 cprintf("%d You don't have a download file open.\n",ERROR);
576 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
580 if (CC->dl_is_net) if (bytes>64) bytes = 64; /**** FIX ****/
582 fseek(CC->download_fp,start_pos,0);
583 fread(buf,bytes,1,CC->download_fp);
584 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
585 client_write(buf, bytes);
591 * write to the upload file
593 void cmd_writ(char *cmdbuf)
598 bytes = extract_int(cmdbuf,0);
600 if (CC->upload_fp == NULL) {
601 cprintf("%d You don't have an upload file open.\n",ERROR);
606 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
610 if (CC->upload_type==UPL_NET) if (bytes > 64) bytes = 64; /*** FIX ***/
612 cprintf("%d %d\n",SEND_BINARY,bytes);
613 client_read(buf, bytes);
614 fwrite(buf,bytes,1,CC->upload_fp);
620 * cmd_netp() - identify as network poll session
622 void cmd_netp(char *cmdbuf)
626 extract(buf,cmdbuf,1);
627 if (strcasecmp(buf,config.c_net_password)) {
628 cprintf("%d authentication failed\n",ERROR);
631 extract(CC->net_node,cmdbuf,0);
632 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
636 * cmd_ndop() - open a network spool file for downloading
638 void cmd_ndop(char *cmdbuf)
643 if (strlen(CC->net_node)==0) {
644 cprintf("%d Not authenticated as a network node.\n",
645 ERROR+NOT_LOGGED_IN);
649 if (CC->download_fp != NULL) {
650 cprintf("%d You already have a download file open.\n",ERROR);
654 sprintf(pathname,"%s/network/spoolout/%s",BBSDIR,CC->net_node);
656 /* first open the file in append mode in order to create a
657 * zero-length file if it doesn't already exist
659 CC->download_fp = fopen(pathname,"a");
660 fclose(CC->download_fp);
663 CC->download_fp = fopen(pathname,"r");
664 if (CC->download_fp==NULL) {
665 cprintf("%d cannot open %s: %s\n",
666 ERROR,pathname,strerror(errno));
671 /* set this flag so other routines know that the download file
672 * currently open is a network spool file
676 stat(pathname,&statbuf);
677 cprintf("%d %ld\n",OK,statbuf.st_size);
681 * cmd_nuop() - open a network spool file for uploading
683 void cmd_nuop(char *cmdbuf)
685 if (strlen(CC->net_node)==0) {
686 cprintf("%d Not authenticated as a network node.\n",
687 ERROR+NOT_LOGGED_IN);
691 if (CC->upload_fp != NULL) {
692 cprintf("%d You already have an upload file open.\n",ERROR);
696 sprintf(CC->upl_path,"%s/network/spoolin/%s.%d",
697 BBSDIR,CC->net_node,getpid());
699 CC->upload_fp = fopen(CC->upl_path,"r");
700 if (CC->upload_fp != NULL) {
701 fclose(CC->upload_fp);
702 CC->upload_fp = NULL;
703 cprintf("%d '%s' already exists\n",
704 ERROR+ALREADY_EXISTS,CC->upl_path);
708 CC->upload_fp = fopen(CC->upl_path,"w");
709 if (CC->upload_fp == NULL) {
710 cprintf("%d Cannot open %s: %s\n",
711 ERROR,CC->upl_path,strerror(errno));
715 CC->upload_type = UPL_NET;
716 cprintf("%d Ok\n",OK);