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 snprintf(pathname,sizeof pathname,"./files/%s/%s",
53 CC->quickroom.QRdirname,filename);
55 if (a==0) cprintf("%d File '%s' deleted.\n",OK,pathname);
56 else cprintf("%d File '%s' not found.\n",ERROR+FILE_NOT_FOUND,pathname);
63 * move a file from one room directory to another
65 void cmd_movf(char *cmdbuf)
73 struct quickroom qrbuf;
75 extract(filename,cmdbuf,0);
76 extract(newroom,cmdbuf,1);
78 if (!(CC->logged_in)) {
79 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
83 if (!is_room_aide()) {
84 cprintf("%d Higher access required.\n",
85 ERROR+HIGHER_ACCESS_REQUIRED);
89 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
90 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
94 if (strlen(filename)==0) {
95 cprintf("%d You must specify a file name.\n",
96 ERROR+FILE_NOT_FOUND);
100 for (a=0; a<strlen(filename); ++a)
101 if (filename[a]=='/') filename[a] = '_';
102 snprintf(pathname,sizeof pathname,"./files/%s/%s",
103 CC->quickroom.QRdirname,filename);
104 if (access(pathname,0)!=0) {
105 cprintf("%d File '%s' not found.\n",
106 ERROR+FILE_NOT_FOUND,pathname);
110 if (getroom(&qrbuf, newroom)!=0) {
111 cprintf("%d '%s' does not exist.\n",
115 if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
116 cprintf("%d '%s' is not a directory room.\n",
117 ERROR+NOT_HERE,qrbuf.QRname);
120 snprintf(newpath,sizeof newpath,"./files/%s/%s",qrbuf.QRdirname,
122 if (link(pathname,newpath)!=0) {
123 cprintf("%d Couldn't move file: %s\n",ERROR,strerror(errno));
128 /* this is a crude method of copying the file description */
129 snprintf(buf, sizeof buf,
130 "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 snprintf(pathname,sizeof pathname,"./files/%s/%s",
177 CC->quickroom.QRdirname,filename);
178 if (access(pathname,0)!=0) {
179 cprintf("%d File '%s' not found.\n",
180 ERROR+FILE_NOT_FOUND,pathname);
183 snprintf(buf,sizeof buf,"sysop@%s",destsys);
186 cprintf("%d No such system: '%s'\n",
187 ERROR+NO_SUCH_SYSTEM,destsys);
190 snprintf(outfile,sizeof outfile,"%s/network/spoolin/nsf.%d",BBSDIR,
192 ofp=fopen(outfile,"a");
194 cprintf("%d internal error\n",ERROR);
199 putc(MES_NORMAL,ofp);
201 fprintf(ofp,"Pcit%ld",CC->usersupp.usernum); putc(0,ofp);
203 fprintf(ofp,"T%ld",now); putc(0,ofp);
204 fprintf(ofp,"A%s",CC->usersupp.fullname); putc(0,ofp);
205 fprintf(ofp,"O%s",CC->quickroom.QRname); putc(0,ofp);
206 fprintf(ofp,"N%s",NODENAME); putc(0,ofp);
207 fprintf(ofp,"D%s",destsys); putc(0,ofp);
208 fprintf(ofp,"SFILE"); putc(0,ofp);
212 snprintf(buf,sizeof buf,
213 "cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
214 CC->quickroom.QRdirname,filename,filename,outfile);
217 ofp = fopen(outfile,"a");
221 cprintf("%d File '%s' has been sent to %s.\n",OK,filename,destsys);
222 system("nohup ./netproc >/dev/null 2>&1 &");
227 * This code is common to all commands which open a file for downloading.
228 * It examines the file and displays the OK result code and some information
229 * about the file. NOTE: this stuff is Unix dependent.
231 void OpenCmdResult(void) {
234 fstat(fileno(CC->download_fp), &statbuf);
235 cprintf("%d %ld|%ld\n", OK, statbuf.st_size, statbuf.st_mtime);
240 * open a file for downloading
242 void cmd_open(char *cmdbuf)
248 extract(filename,cmdbuf,0);
250 if (!(CC->logged_in)) {
251 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
255 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
256 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
260 if (strlen(filename)==0) {
261 cprintf("%d You must specify a file name.\n",
262 ERROR+FILE_NOT_FOUND);
266 if (CC->download_fp != NULL) {
267 cprintf("%d You already have a download file open.\n",ERROR);
271 for (a=0; a<strlen(filename); ++a)
272 if (filename[a]=='/') filename[a] = '_';
274 snprintf(pathname,sizeof pathname,
275 "./files/%s/%s",CC->quickroom.QRdirname,filename);
276 CC->download_fp = fopen(pathname,"r");
278 if (CC->download_fp==NULL) {
279 cprintf("%d cannot open %s: %s\n",
280 ERROR,pathname,strerror(errno));
290 void cmd_oimg(char *cmdbuf)
294 struct usersupp usbuf;
299 extract(filename,cmdbuf,0);
301 if (strlen(filename)==0) {
302 cprintf("%d You must specify a file name.\n",
303 ERROR+FILE_NOT_FOUND);
307 if (CC->download_fp != NULL) {
308 cprintf("%d You already have a download file open.\n",ERROR);
312 if (!strcasecmp(filename, "_userpic_")) {
313 extract(which_user, cmdbuf, 1);
314 if (getuser(&usbuf, which_user) != 0) {
315 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
318 snprintf(pathname, sizeof pathname, "./userpics/%ld.gif",
321 else if (!strcasecmp(filename, "_floorpic_")) {
322 which_floor = extract_int(cmdbuf, 1);
323 snprintf(pathname, sizeof pathname, "./images/floor.%d.gif",
326 else if (!strcasecmp(filename, "_roompic_")) {
327 assoc_file_name(pathname, &CC->quickroom, "images");
330 for (a=0; a<strlen(filename); ++a) {
331 filename[a] = tolower(filename[a]);
332 if (filename[a]=='/') filename[a] = '_';
334 snprintf(pathname,sizeof pathname,"./images/%s.gif",filename);
337 CC->download_fp = fopen(pathname,"r");
338 if (CC->download_fp == NULL) {
339 cprintf("%d Cannot open %s: %s\n",
340 ERROR+FILE_NOT_FOUND,pathname,strerror(errno));
348 * open a file for uploading
350 void cmd_uopn(char *cmdbuf)
354 extract(CC->upl_file,cmdbuf,0);
355 extract(CC->upl_comment,cmdbuf,1);
357 if (!(CC->logged_in)) {
358 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
362 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
363 cprintf("%d No directory in this room.\n",ERROR+NOT_HERE);
367 if (strlen(CC->upl_file)==0) {
368 cprintf("%d You must specify a file name.\n",
369 ERROR+FILE_NOT_FOUND);
373 if (CC->upload_fp != NULL) {
374 cprintf("%d You already have a upload file open.\n",ERROR);
378 for (a=0; a<strlen(CC->upl_file); ++a)
379 if (CC->upl_file[a]=='/') CC->upl_file[a] = '_';
380 snprintf(CC->upl_path,sizeof CC->upl_path,"./files/%s/%s",
381 CC->quickroom.QRdirname,CC->upl_file);
382 snprintf(CC->upl_filedir,sizeof CC->upl_filedir,"./files/%s/filedir",
383 CC->quickroom.QRdirname);
385 CC->upload_fp = fopen(CC->upl_path,"r");
386 if (CC->upload_fp != NULL) {
387 fclose(CC->upload_fp);
388 CC->upload_fp = NULL;
389 cprintf("%d '%s' already exists\n",
390 ERROR+ALREADY_EXISTS,CC->upl_path);
394 CC->upload_fp = fopen(CC->upl_path,"wb");
395 if (CC->upload_fp == NULL) {
396 cprintf("%d Cannot open %s: %s\n",
397 ERROR,CC->upl_path,strerror(errno));
400 cprintf("%d Ok\n",OK);
406 * open an image file for uploading
408 void cmd_uimg(char *cmdbuf)
410 int is_this_for_real;
415 if (num_parms(cmdbuf) < 2) {
416 cprintf("%d Usage error.\n", ERROR);
420 is_this_for_real = extract_int(cmdbuf,0);
421 extract(basenm, cmdbuf, 1);
422 if (CC->upload_fp != NULL) {
423 cprintf("%d You already have an upload file open.\n", ERROR);
427 strcpy(CC->upl_path, "");
429 for (a=0; a<strlen(basenm); ++a) {
430 basenm[a] = tolower(basenm[a]);
431 if (basenm[a]=='/') basenm[a] = '_';
434 if (CC->usersupp.axlevel >= 6) {
435 snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
439 if (!strcasecmp(basenm, "_userpic_")) {
440 snprintf(CC->upl_path, sizeof CC->upl_path,
441 "./userpics/%ld.gif", CC->usersupp.usernum);
444 if ( (!strcasecmp(basenm, "_floorpic_")) && (CC->usersupp.axlevel >= 6) ) {
445 which_floor = extract_int(cmdbuf, 2);
446 snprintf(CC->upl_path, sizeof CC->upl_path,
447 "./images/floor.%d.gif", which_floor);
450 if ( (!strcasecmp(basenm, "_roompic_")) && (is_room_aide()) ) {
451 assoc_file_name(CC->upl_path, &CC->quickroom, "images");
454 if (strlen(CC->upl_path) == 0) {
455 cprintf("%d Higher access required.\n",
456 ERROR+HIGHER_ACCESS_REQUIRED);
460 if (is_this_for_real == 0) {
461 cprintf("%d Ok to send image\n", OK);
465 CC->upload_fp = fopen(CC->upl_path,"wb");
466 if (CC->upload_fp == NULL) {
467 cprintf("%d Cannot open %s: %s\n",
468 ERROR,CC->upl_path,strerror(errno));
471 cprintf("%d Ok\n",OK);
472 CC->upload_type = UPL_IMAGE;
477 * close the download file
479 void cmd_clos(void) {
482 if (CC->download_fp == NULL) {
483 cprintf("%d You don't have a download file open.\n",ERROR);
487 fclose(CC->download_fp);
488 CC->download_fp = NULL;
490 if (CC->dl_is_net == 1) {
492 snprintf(buf,sizeof buf,"%s/network/spoolout/%s",BBSDIR,
497 cprintf("%d Ok\n",OK);
504 void abort_upl(struct CitContext *who)
506 if (who->upload_fp != NULL) {
507 fclose(who->upload_fp);
508 who->upload_fp = NULL;
509 unlink(CC->upl_path);
516 * close the upload file
518 void cmd_ucls(char *cmd)
523 if (CC->upload_fp == NULL) {
524 cprintf("%d You don't have an upload file open.\n",ERROR);
528 fclose(CC->upload_fp);
529 CC->upload_fp = NULL;
531 if ((!strcasecmp(cmd,"1")) && (CC->upload_type != UPL_FILE)) {
532 CC->upload_type = UPL_FILE;
533 cprintf("%d Upload completed.\n", OK);
537 if (!strcasecmp(cmd,"1")) {
538 cprintf("%d File '%s' saved.\n",OK,CC->upl_path);
539 fp = fopen(CC->upl_filedir,"a");
540 if (fp==NULL) fp=fopen(CC->upl_filedir,"w");
542 fprintf(fp,"%s %s\n",CC->upl_file,CC->upl_comment);
546 /* put together an upload notice */
548 fp=fopen(CC->temp,"wb");
552 fprintf(fp,"Pcit%ld",CC->usersupp.usernum); putc(0,fp);
553 fprintf(fp,"T%ld",now); putc(0,fp);
554 fprintf(fp,"A%s",CC->curr_user); putc(0,fp);
555 fprintf(fp,"O%s",CC->quickroom.QRname); putc(0,fp);
556 fprintf(fp,"N%s",NODENAME); putc(0,fp); putc('M',fp);
557 fprintf(fp,"NEW UPLOAD: '%s'\n %s\n",CC->upl_file,CC->upl_comment);
560 save_message(CC->temp, "", 0, M_LOCAL, 1);
565 cprintf("%d File '%s' aborted.\n",OK,CC->upl_path);
570 * read from the download file
572 void cmd_read(char *cmdbuf)
578 start_pos = extract_long(cmdbuf,0);
579 bytes = extract_int(cmdbuf,1);
581 if (CC->download_fp == NULL) {
582 cprintf("%d You don't have a download file open.\n",ERROR);
587 cprintf("%d You may not read more than 4096 bytes.\n",ERROR);
591 fseek(CC->download_fp,start_pos,0);
592 fread(buf,bytes,1,CC->download_fp);
593 cprintf("%d %d\n",BINARY_FOLLOWS,bytes);
594 client_write(buf, bytes);
600 * write to the upload file
602 void cmd_writ(char *cmdbuf)
607 bytes = extract_int(cmdbuf,0);
609 if (CC->upload_fp == NULL) {
610 cprintf("%d You don't have an upload file open.\n",ERROR);
615 cprintf("%d You may not write more than 4096 bytes.\n",ERROR);
619 cprintf("%d %d\n",SEND_BINARY,bytes);
620 client_read(buf, bytes);
621 fwrite(buf,bytes,1,CC->upload_fp);
627 * cmd_netp() - identify as network poll session
629 void cmd_netp(char *cmdbuf)
633 extract(buf,cmdbuf,1);
634 if (strcasecmp(buf,config.c_net_password)) {
635 cprintf("%d authentication failed\n",ERROR);
638 extract(CC->net_node,cmdbuf,0);
639 cprintf("%d authenticated as network node '%s'\n",OK,CC->net_node);
643 * cmd_ndop() - open a network spool file for downloading
645 void cmd_ndop(char *cmdbuf)
650 if (strlen(CC->net_node)==0) {
651 cprintf("%d Not authenticated as a network node.\n",
652 ERROR+NOT_LOGGED_IN);
656 if (CC->download_fp != NULL) {
657 cprintf("%d You already have a download file open.\n",ERROR);
661 snprintf(pathname,sizeof pathname,"%s/network/spoolout/%s",BBSDIR,
664 /* first open the file in append mode in order to create a
665 * zero-length file if it doesn't already exist
667 CC->download_fp = fopen(pathname,"a");
668 fclose(CC->download_fp);
671 CC->download_fp = fopen(pathname,"r");
672 if (CC->download_fp==NULL) {
673 cprintf("%d cannot open %s: %s\n",
674 ERROR,pathname,strerror(errno));
679 /* set this flag so other routines know that the download file
680 * currently open is a network spool file
684 stat(pathname,&statbuf);
685 cprintf("%d %ld\n",OK,statbuf.st_size);
689 * cmd_nuop() - open a network spool file for uploading
691 void cmd_nuop(char *cmdbuf)
693 if (strlen(CC->net_node)==0) {
694 cprintf("%d Not authenticated as a network node.\n",
695 ERROR+NOT_LOGGED_IN);
699 if (CC->upload_fp != NULL) {
700 cprintf("%d You already have an upload file open.\n",ERROR);
704 snprintf(CC->upl_path,sizeof CC->upl_path,"%s/network/spoolin/%s.%d",
705 BBSDIR,CC->net_node,getpid());
707 CC->upload_fp = fopen(CC->upl_path,"r");
708 if (CC->upload_fp != NULL) {
709 fclose(CC->upload_fp);
710 CC->upload_fp = NULL;
711 cprintf("%d '%s' already exists\n",
712 ERROR+ALREADY_EXISTS,CC->upl_path);
716 CC->upload_fp = fopen(CC->upl_path,"w");
717 if (CC->upload_fp == NULL) {
718 cprintf("%d Cannot open %s: %s\n",
719 ERROR,CC->upl_path,strerror(errno));
723 CC->upload_type = UPL_NET;
724 cprintf("%d Ok\n",OK);