|
|
1.1 root 1: /* str.cpp */
2:
3: /* Synchronet high-level string i/o routines */
4:
5: /* $Id: str.cpp,v 1.56 2006/12/29 19:10:38 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: /****************************************************************************/
41: /* Lists all users who have access to the current sub. */
42: /****************************************************************************/
43: void sbbs_t::userlist(long mode)
44: {
45: char name[256],sort=0;
46: char tmp[512];
47: int i,j,k,users=0;
48: char * line[2500];
49: user_t user;
50:
51: if(lastuser(&cfg)<=(sizeof(line)/sizeof(line[0])))
52: sort=yesno(text[SortAlphaQ]);
53: if(sort) {
54: bputs(text[CheckingSlots]);
55: }
56: else {
57: CRLF;
58: }
59: j=0;
60: k=lastuser(&cfg);
61: for(i=1;i<=k && !msgabort();i++) {
62: if(sort && (online==ON_LOCAL || !rioctl(TXBC)))
63: bprintf("%-4d\b\b\b\b",i);
64: user.number=i;
65: getuserdat(&cfg,&user);
66: if(user.misc&(DELETED|INACTIVE))
67: continue;
68: users++;
69: if(mode==UL_SUB) {
70: if(!usrgrps)
71: continue;
72: if(!chk_ar(cfg.grp[usrgrp[curgrp]]->ar,&user))
73: continue;
74: if(!chk_ar(cfg.sub[usrsub[curgrp][cursub[curgrp]]]->ar,&user)
75: || (cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar[0]
76: && !chk_ar(cfg.sub[usrsub[curgrp][cursub[curgrp]]]->read_ar,&user)))
77: continue;
78: }
79: else if(mode==UL_DIR) {
80: if(user.rest&FLAG('T'))
81: continue;
82: if(!usrlibs)
83: continue;
84: if(!chk_ar(cfg.lib[usrlib[curlib]]->ar,&user))
85: continue;
86: if(!chk_ar(cfg.dir[usrdir[curlib][curdir[curlib]]]->ar,&user))
87: continue;
88: }
89: if(sort) {
90: if((line[j]=(char *)malloc(128))==0) {
91: errormsg(WHERE,ERR_ALLOC,nulstr,83);
92: for(i=0;i<j;i++)
93: free(line[i]);
94: return;
95: }
96: sprintf(name,"%s #%d",user.alias,i);
97: sprintf(line[j],text[UserListFmt],name
98: ,cfg.sys_misc&SM_LISTLOC ? user.location : user.note
99: ,unixtodstr(&cfg,user.laston,tmp)
100: ,user.modem);
101: }
102: else {
103: sprintf(name,"%s #%u",user.alias,i);
104: bprintf(text[UserListFmt],name
105: ,cfg.sys_misc&SM_LISTLOC ? user.location : user.note
106: ,unixtodstr(&cfg,user.laston,tmp)
107: ,user.modem);
108: }
109: j++;
110: }
111: if(i<=k) { /* aborted */
112: if(sort)
113: for(i=0;i<j;i++)
114: free(line[i]);
115: return;
116: }
117: if(!sort) {
118: CRLF;
119: }
120: bprintf(text[NTotalUsers],users);
121: if(mode==UL_SUB)
122: bprintf(text[NUsersOnCurSub],j);
123: else if(mode==UL_DIR)
124: bprintf(text[NUsersOnCurDir],j);
125: if(!sort)
126: return;
127: CRLF;
128: qsort((void *)line,j,sizeof(line[0])
129: ,(int(*)(const void*, const void*))pstrcmp);
130: for(i=0;i<j && !msgabort();i++)
131: bputs(line[i]);
132: for(i=0;i<j;i++)
133: free(line[i]);
134: }
135:
136: /****************************************************************************/
137: /* SIF input function. See SIF.DOC for more info */
138: /****************************************************************************/
139: void sbbs_t::sif(char *fname, char *answers, long len)
140: {
141: char str[256],tmplt[256],*buf;
142: uint t,max,min,mode,cr;
143: int file;
144: long length,l=0,m,top,a=0;
145:
146: sprintf(str,"%s%s.sif",cfg.text_dir,fname);
147: if((file=nopen(str,O_RDONLY))==-1) {
148: errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
149: answers[0]=0;
150: return;
151: }
152: length=filelength(file);
153: if((buf=(char *)malloc(length))==0) {
154: close(file);
155: errormsg(WHERE,ERR_ALLOC,str,length);
156: answers[0]=0;
157: return;
158: }
159: if(lread(file,buf,length)!=length) {
160: close(file);
161: errormsg(WHERE,ERR_READ,str,length);
162: answers[0]=0;
163: return;
164: }
165: close(file);
166: while(l<length && online) {
167: mode=min=max=t=cr=0;
168: top=l;
169: while(l<length && buf[l++]!=STX);
170: for(m=l;m<length;m++)
171: if(buf[m]==ETX || !buf[m]) {
172: buf[m]=0;
173: break;
174: }
175: if(l>=length) break;
176: if(online==ON_REMOTE) {
177: rioctl(IOCM|ABORT);
178: rioctl(IOCS|ABORT);
179: }
180: putmsg(buf+l,P_SAVEATR);
181: m++;
182: if(toupper(buf[m])!='C' && toupper(buf[m])!='S')
183: continue;
184: SYNC;
185: if(online==ON_REMOTE)
186: rioctl(IOSM|ABORT);
187: if(a>=len) {
188: errormsg(WHERE,ERR_LEN,fname,len);
189: break;
190: }
191: if((buf[m]&0xdf)=='C') {
192: if((buf[m+1]&0xdf)=='U') { /* Uppercase only */
193: mode|=K_UPPER;
194: m++;
195: }
196: else if((buf[m+1]&0xdf)=='N') { /* Numbers only */
197: mode|=K_NUMBER;
198: m++;
199: }
200: if((buf[m+1]&0xdf)=='L') { /* Draw line */
201: if(term_supports(COLOR))
202: attr(cfg.color[clr_inputline]);
203: else
204: attr(BLACK|BG_LIGHTGRAY);
205: bputs(" \b");
206: m++;
207: }
208: if((buf[m+1]&0xdf)=='R') { /* Add CRLF */
209: cr=1;
210: m++;
211: }
212: if(buf[m+1]=='"') {
213: m+=2;
214: for(l=m;l<length;l++)
215: if(buf[l]=='"') {
216: buf[l]=0;
217: break;
218: }
219: answers[a++]=(char)getkeys((char *)buf+m,0);
220: }
221: else {
222: answers[a]=getkey(mode);
223: outchar(answers[a++]);
224: attr(LIGHTGRAY);
225: CRLF;
226: }
227: if(cr) {
228: answers[a++]=CR;
229: answers[a++]=LF;
230: }
231: }
232: else if((buf[m]&0xdf)=='S') { /* String */
233: if((buf[m+1]&0xdf)=='U') { /* Uppercase only */
234: mode|=K_UPPER;
235: m++;
236: }
237: else if((buf[m+1]&0xdf)=='F') { /* Force Upper/Lowr case */
238: mode|=K_UPRLWR;
239: m++;
240: }
241: else if((buf[m+1]&0xdf)=='N') { /* Numbers only */
242: mode|=K_NUMBER;
243: m++;
244: }
245: if((buf[m+1]&0xdf)=='L') { /* Draw line */
246: mode|=K_LINE;
247: m++;
248: }
249: if((buf[m+1]&0xdf)=='R') { /* Add CRLF */
250: cr=1;
251: m++;
252: }
253: if(isdigit(buf[m+1])) {
254: max=buf[++m]&0xf;
255: if(isdigit(buf[m+1]))
256: max=max*10+(buf[++m]&0xf);
257: }
258: if(buf[m+1]=='.' && isdigit(buf[m+2])) {
259: m++;
260: min=buf[++m]&0xf;
261: if(isdigit(buf[m+1]))
262: min=min*10+(buf[++m]&0xf);
263: }
264: if(buf[m+1]=='"') {
265: m++;
266: mode&=~K_NUMBER;
267: while(buf[++m]!='"' && t<80)
268: tmplt[t++]=buf[m];
269: tmplt[t]=0;
270: max=strlen(tmplt);
271: }
272: if(t) {
273: if(gettmplt(str,tmplt,mode)<min) {
274: l=top;
275: continue;
276: }
277: }
278: else {
279: if(!max)
280: continue;
281: if(getstr(str,max,mode)<min) {
282: l=top;
283: continue;
284: }
285: }
286: if(!cr) {
287: for(cr=0;str[cr];cr++)
288: answers[a+cr]=str[cr];
289: while(cr<max)
290: answers[a+cr++]=ETX;
291: a+=max;
292: }
293: else {
294: putrec(answers,a,max,str);
295: putrec(answers,a+max,2,crlf);
296: a+=max+2;
297: }
298: }
299: }
300: answers[a]=0;
301: free((char *)buf);
302: }
303:
304: /****************************************************************************/
305: /* SIF output function. See SIF.DOC for more info */
306: /****************************************************************************/
307: void sbbs_t::sof(char *fname, char *answers, long len)
308: {
309: char str[256],*buf,max,min,cr;
310: int file;
311: long length,l=0,m,a=0;
312:
313: sprintf(str,"%s%s.sif",cfg.text_dir,fname);
314: if((file=nopen(str,O_RDONLY))==-1) {
315: errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
316: answers[0]=0;
317: return;
318: }
319: length=filelength(file);
320: if((buf=(char *)malloc(length))==0) {
321: close(file);
322: errormsg(WHERE,ERR_ALLOC,str,length);
323: answers[0]=0;
324: return;
325: }
326: if(lread(file,buf,length)!=length) {
327: close(file);
328: errormsg(WHERE,ERR_READ,str,length);
329: answers[0]=0;
330: return;
331: }
332: close(file);
333: while(l<length && online) {
334: min=max=cr=0;
335: while(l<length && buf[l++]!=STX);
336: for(m=l;m<length;m++)
337: if(buf[m]==ETX || !buf[m]) {
338: buf[m]=0;
339: break;
340: }
341: if(l>=length) break;
342: if(online==ON_REMOTE) {
343: rioctl(IOCM|ABORT);
344: rioctl(IOCS|ABORT);
345: }
346: putmsg(buf+l,P_SAVEATR);
347: m++;
348: if(toupper(buf[m])!='C' && toupper(buf[m])!='S')
349: continue;
350: SYNC;
351: if(online==ON_REMOTE)
352: rioctl(IOSM|ABORT);
353: if(a>=len) {
354: bprintf("\r\nSOF: %s defined more data than buffer size "
355: "(%lu bytes)\r\n",fname,len);
356: break;
357: }
358: if((buf[m]&0xdf)=='C') {
359: if((buf[m+1]&0xdf)=='U') /* Uppercase only */
360: m++;
361: else if((buf[m+1]&0xdf)=='N') /* Numbers only */
362: m++;
363: if((buf[m+1]&0xdf)=='L') { /* Draw line */
364: if(term_supports(COLOR))
365: attr(cfg.color[clr_inputline]);
366: else
367: attr(BLACK|BG_LIGHTGRAY);
368: bputs(" \b");
369: m++;
370: }
371: if((buf[m+1]&0xdf)=='R') { /* Add CRLF */
372: cr=1;
373: m++;
374: }
375: outchar(answers[a++]);
376: attr(LIGHTGRAY);
377: CRLF;
378: if(cr)
379: a+=2;
380: }
381: else if((buf[m]&0xdf)=='S') { /* String */
382: if((buf[m+1]&0xdf)=='U')
383: m++;
384: else if((buf[m+1]&0xdf)=='F')
385: m++;
386: else if((buf[m+1]&0xdf)=='N') /* Numbers only */
387: m++;
388: if((buf[m+1]&0xdf)=='L') {
389: if(term_supports(COLOR))
390: attr(cfg.color[clr_inputline]);
391: else
392: attr(BLACK|BG_LIGHTGRAY);
393: m++;
394: }
395: if((buf[m+1]&0xdf)=='R') {
396: cr=1;
397: m++;
398: }
399: if(isdigit(buf[m+1])) {
400: max=buf[++m]&0xf;
401: if(isdigit(buf[m+1]))
402: max=max*10+(buf[++m]&0xf);
403: }
404: if(buf[m+1]=='.' && isdigit(buf[m+2])) {
405: m++;
406: min=buf[++m]&0xf;
407: if(isdigit(buf[m+1]))
408: min=min*10+(buf[++m]&0xf);
409: }
410: if(buf[m+1]=='"') {
411: max=0;
412: m++;
413: while(buf[++m]!='"' && max<80)
414: max++;
415: }
416: if(!max)
417: continue;
418: getrec(answers,a,max,str);
419: bputs(str);
420: attr(LIGHTGRAY);
421: CRLF;
422: if(!cr)
423: a+=max;
424: else
425: a+=max+2;
426: }
427: }
428: free((char *)buf);
429: }
430:
431: /****************************************************************************/
432: /* Creates data file 'datfile' from input via sif file 'siffile' */
433: /****************************************************************************/
434: void sbbs_t::create_sif_dat(char *siffile, char *datfile)
435: {
436: char *buf;
437: int file;
438:
439: if((buf=(char *)malloc(SIF_MAXBUF))==NULL) {
440: errormsg(WHERE,ERR_ALLOC,siffile,SIF_MAXBUF);
441: return;
442: }
443: memset(buf,SIF_MAXBUF,0); /* initialize to null */
444: sif(siffile,buf,SIF_MAXBUF);
445: if((file=nopen(datfile,O_WRONLY|O_TRUNC|O_CREAT))==-1) {
446: free(buf);
447: errormsg(WHERE,ERR_OPEN,datfile,O_WRONLY|O_TRUNC|O_CREAT);
448: return;
449: }
450: write(file,buf,strlen(buf));
451: close(file);
452: free(buf);
453: }
454:
455: /****************************************************************************/
456: /* Reads data file 'datfile' and displays output via sif file 'siffile' */
457: /****************************************************************************/
458: void sbbs_t::read_sif_dat(char *siffile, char *datfile)
459: {
460: char *buf;
461: int file;
462: long length;
463:
464: if((file=nopen(datfile,O_RDONLY))==-1) {
465: errormsg(WHERE,ERR_OPEN,datfile,O_RDONLY);
466: return;
467: }
468: length=filelength(file);
469: if(!length) {
470: close(file);
471: return;
472: }
473: if((buf=(char *)malloc(length))==NULL) {
474: close(file);
475: errormsg(WHERE,ERR_ALLOC,datfile,length);
476: return;
477: }
478: read(file,buf,length);
479: close(file);
480: sof(siffile,buf,length);
481: free(buf);
482: }
483:
484: /****************************************************************************/
485: /* Get string by template. A=Alpha, N=Number, !=Anything */
486: /* First character MUST be an A,N or !. */
487: /* Modes - K_LINE and K_UPPER are supported. */
488: /****************************************************************************/
489: size_t sbbs_t::gettmplt(char *strout,char *templt, long mode)
490: {
491: char ch,str[256];
492: char tmplt[128];
493: uint t=strlen(templt),c=0;
494:
495: sys_status&=~SS_ABORT;
496: SAFECOPY(tmplt, templt);
497: strupr(tmplt);
498: if(term_supports(ANSI)) {
499: if(mode&K_LINE) {
500: if(term_supports(COLOR))
501: attr(cfg.color[clr_inputline]);
502: else
503: attr(BLACK|BG_LIGHTGRAY);
504: }
505: while(c<t) {
506: if(tmplt[c]=='N' || tmplt[c]=='A' || tmplt[c]=='!')
507: outchar(' ');
508: else
509: outchar(tmplt[c]);
510: c++;
511: }
512: cursor_left(t);
513: }
514: c=0;
515: if(mode&K_EDIT) {
516: strcpy(str,strout);
517: bputs(str);
518: c=strlen(str);
519: }
520: while((ch=getkey(mode))!=CR && online && !(sys_status&SS_ABORT)) {
521: if(ch==BS || ch==DEL) {
522: if(!c)
523: continue;
524: for(ch=1,c--;c;c--,ch++)
525: if(tmplt[c]=='N' || tmplt[c]=='A' || tmplt[c]=='!')
526: break;
527: cursor_left(ch);
528: bputs(" \b");
529: continue;
530: }
531: if(ch==CTRL_X) {
532: for(;c;c--) {
533: outchar(BS);
534: if(tmplt[c-1]=='N' || tmplt[c-1]=='A' || tmplt[c-1]=='!')
535: bputs(" \b");
536: }
537: }
538: else if(c<t) {
539: if(tmplt[c]=='N' && !isdigit(ch))
540: continue;
541: if(tmplt[c]=='A' && !isalpha(ch))
542: continue;
543: outchar(ch);
544: str[c++]=ch;
545: while(c<t && tmplt[c]!='N' && tmplt[c]!='A' && tmplt[c]!='!'){
546: str[c]=tmplt[c];
547: outchar(tmplt[c++]);
548: }
549: }
550: }
551: str[c]=0;
552: attr(LIGHTGRAY);
553: CRLF;
554: if(!(sys_status&SS_ABORT))
555: strcpy(strout,str);
556: return(c);
557: }
558:
559: /*****************************************************************************/
560: /* Accepts a user's input to change a new-scan time pointer */
561: /* Returns 0 if input was aborted or invalid, 1 if complete */
562: /*****************************************************************************/
563: bool sbbs_t::inputnstime(time_t *dt)
564: {
565: int hour;
566: struct tm tm;
567: bool pm=false;
568: char str[256];
569:
570: bputs(text[NScanDate]);
571: bputs(timestr(dt));
572: CRLF;
573: if(localtime_r(dt,&tm)==NULL) {
574: errormsg(WHERE,ERR_CHK,"time ptr",0);
575: return(FALSE);
576: }
577:
578: bputs(text[NScanYear]);
579: ultoa(tm.tm_year+1900,str,10);
580: if(!getstr(str,4,K_EDIT|K_AUTODEL|K_NUMBER|K_NOCRLF) || sys_status&SS_ABORT) {
581: CRLF;
582: return(false);
583: }
584: tm.tm_year=atoi(str);
585: if(tm.tm_year<1970) { /* unix time is seconds since 1/1/1970 */
586: CRLF;
587: return(false);
588: }
589: tm.tm_year-=1900; /* tm_year is years since 1900 */
590:
591: bputs(text[NScanMonth]);
592: ultoa(tm.tm_mon+1,str,10);
593: if(!getstr(str,2,K_EDIT|K_AUTODEL|K_NUMBER|K_NOCRLF) || sys_status&SS_ABORT) {
594: CRLF;
595: return(false);
596: }
597: tm.tm_mon=atoi(str);
598: if(tm.tm_mon<1 || tm.tm_mon>12) {
599: CRLF;
600: return(false);
601: }
602: tm.tm_mon--; /* tm_mon is zero-based */
603:
604: bputs(text[NScanDay]);
605: ultoa(tm.tm_mday,str,10);
606: if(!getstr(str,2,K_EDIT|K_AUTODEL|K_NUMBER|K_NOCRLF) || sys_status&SS_ABORT) {
607: CRLF;
608: return(false);
609: }
610: tm.tm_mday=atoi(str);
611: if(tm.tm_mday<1 || tm.tm_mday>31) {
612: CRLF;
613: return(false);
614: }
615: bputs(text[NScanHour]);
616: if(cfg.sys_misc&SM_MILITARY)
617: hour=tm.tm_hour;
618: else {
619: if(tm.tm_hour==0) { /* 12 midnite */
620: pm=false;
621: hour=12;
622: }
623: else if(tm.tm_hour>12) {
624: hour=tm.tm_hour-12;
625: pm=true;
626: }
627: else {
628: hour=tm.tm_hour;
629: pm=false;
630: }
631: }
632: ultoa(hour,str,10);
633: if(!getstr(str,2,K_EDIT|K_AUTODEL|K_NUMBER|K_NOCRLF) || sys_status&SS_ABORT) {
634: CRLF;
635: return(false);
636: }
637: tm.tm_hour=atoi(str);
638: if(tm.tm_hour>24) {
639: CRLF;
640: return(false);
641: }
642:
643: bputs(text[NScanMinute]);
644: ultoa(tm.tm_min,str,10);
645: if(!getstr(str,2,K_EDIT|K_AUTODEL|K_NUMBER|K_NOCRLF) || sys_status&SS_ABORT) {
646: CRLF;
647: return(false);
648: }
649:
650: tm.tm_min=atoi(str);
651: if(tm.tm_min>59) {
652: CRLF;
653: return(false);
654: }
655: tm.tm_sec=0;
656: if(!(cfg.sys_misc&SM_MILITARY) && tm.tm_hour && tm.tm_hour<13) {
657: if(pm && yesno(text[NScanPmQ])) {
658: if(tm.tm_hour<12)
659: tm.tm_hour+=12;
660: }
661: else if(!pm && !yesno(text[NScanAmQ])) {
662: if(tm.tm_hour<12)
663: tm.tm_hour+=12;
664: }
665: else if(tm.tm_hour==12)
666: tm.tm_hour=0;
667: }
668: else {
669: CRLF;
670: }
671: tm.tm_isdst=-1; /* Do not adjust for DST */
672: *dt=mktime(&tm);
673: return(true);
674: }
675:
676: /*****************************************************************************/
677: /* Checks a password for uniqueness and validity */
678: /*****************************************************************************/
679: bool sbbs_t::chkpass(char *passwd, user_t* user, bool unique)
680: {
681: char c,d,first[128],last[128],sysop[41],sysname[41],*p;
682: char alias[LEN_ALIAS+1], name[LEN_NAME+1], handle[LEN_HANDLE+1];
683: char pass[LEN_PASS+1];
684:
685: SAFECOPY(pass,passwd);
686: strupr(pass);
687:
688: if(strlen(pass)<4) {
689: bputs(text[PasswordTooShort]);
690: return(0);
691: }
692: if(!strcmp(pass,user->pass)) {
693: bputs(text[PasswordNotChanged]);
694: return(0);
695: }
696: d=strlen(pass);
697: for(c=1;c<d;c++)
698: if(pass[c]!=pass[c-1])
699: break;
700: if(c==d) {
701: bputs(text[PasswordInvalid]);
702: return(0);
703: }
704: for(c=0;c<3;c++) /* check for 1234 and ABCD */
705: if(pass[c]!=pass[c+1]+1)
706: break;
707: if(c==3) {
708: bputs(text[PasswordObvious]);
709: return(0);
710: }
711: for(c=0;c<3;c++) /* check for 4321 and ZYXW */
712: if(pass[c]!=pass[c+1]-1)
713: break;
714: if(c==3) {
715: bputs(text[PasswordObvious]);
716: return(0);
717: }
718: SAFECOPY(name,user->name);
719: strupr(name);
720: SAFECOPY(alias,user->alias);
721: strupr(alias);
722: SAFECOPY(first,alias);
723: p=strchr(first,' ');
724: if(p) {
725: *p=0;
726: SAFECOPY(last,p+1);
727: }
728: else
729: last[0]=0;
730: SAFECOPY(handle,user->handle);
731: strupr(handle);
732: SAFECOPY(sysop,cfg.sys_op);
733: strupr(sysop);
734: SAFECOPY(sysname,cfg.sys_name);
735: strupr(sysname);
736: if((unique && user->pass[0]
737: && (strstr(pass,user->pass) || strstr(user->pass,pass)))
738: || (name[0]
739: && (strstr(pass,name) || strstr(name,pass)))
740: || strstr(pass,alias) || strstr(alias,pass)
741: || strstr(pass,first) || strstr(first,pass)
742: || (last[0]
743: && (strstr(pass,last) || strstr(last,pass)))
744: || strstr(pass,handle) || strstr(handle,pass)
745: || (user->zipcode[0]
746: && (strstr(pass,user->zipcode) || strstr(user->zipcode,pass)))
747: || (sysname[0]
748: && (strstr(pass,sysname) || strstr(sysname,pass)))
749: || (sysop[0]
750: && (strstr(pass,sysop) || strstr(sysop,pass)))
751: || (cfg.sys_id[0]
752: && (strstr(pass,cfg.sys_id) || strstr(cfg.sys_id,pass)))
753: || (cfg.node_phone[0] && strstr(pass,cfg.node_phone))
754: || (user->phone[0] && strstr(user->phone,pass))
755: || !strncmp(pass,"QWER",3)
756: || !strncmp(pass,"ASDF",3)
757: || !strncmp(pass,"!@#$",3)
758: )
759: {
760: bputs(text[PasswordObvious]);
761: return(0);
762: }
763: return(1);
764: }
765:
766: /****************************************************************************/
767: /* Displays information about sub-board subnum */
768: /****************************************************************************/
769: void sbbs_t::subinfo(uint subnum)
770: {
771: char str[256];
772:
773: bputs(text[SubInfoHdr]);
774: bprintf(text[SubInfoLongName],cfg.sub[subnum]->lname);
775: bprintf(text[SubInfoShortName],cfg.sub[subnum]->sname);
776: bprintf(text[SubInfoQWKName],cfg.sub[subnum]->qwkname);
777: bprintf(text[SubInfoMaxMsgs],cfg.sub[subnum]->maxmsgs);
778: if(cfg.sub[subnum]->misc&SUB_QNET)
779: bprintf(text[SubInfoTagLine],cfg.sub[subnum]->tagline);
780: if(cfg.sub[subnum]->misc&SUB_FIDO)
781: bprintf(text[SubInfoFidoNet]
782: ,cfg.sub[subnum]->origline
783: ,smb_faddrtoa(&cfg.sub[subnum]->faddr,str));
784: sprintf(str,"%s%s.msg",cfg.sub[subnum]->data_dir,cfg.sub[subnum]->code);
785: if(fexist(str) && yesno(text[SubInfoViewFileQ]))
786: printfile(str,0);
787: }
788:
789: /****************************************************************************/
790: /* Displays information about transfer directory dirnum */
791: /****************************************************************************/
792: void sbbs_t::dirinfo(uint dirnum)
793: {
794: char str[256];
795:
796: bputs(text[DirInfoHdr]);
797: bprintf(text[DirInfoLongName],cfg.dir[dirnum]->lname);
798: bprintf(text[DirInfoShortName],cfg.dir[dirnum]->sname);
799: if(cfg.dir[dirnum]->exts[0])
800: bprintf(text[DirInfoAllowedExts],cfg.dir[dirnum]->exts);
801: bprintf(text[DirInfoMaxFiles],cfg.dir[dirnum]->maxfiles);
802: sprintf(str,"%s%s.msg",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code);
803: if(fexist(str) && yesno(text[DirInfoViewFileQ]))
804: printfile(str,0);
805: }
806:
807: /****************************************************************************/
808: /* Searches the file <name>.can in the TEXT directory for matches */
809: /* Returns TRUE if found in list, FALSE if not. */
810: /* Displays bad<name>.can in text directory if found. */
811: /****************************************************************************/
812: bool sbbs_t::trashcan(char *insearchof, char *name)
813: {
814: char str[MAX_PATH+1];
815: bool result;
816:
817: result=::trashcan(&cfg, insearchof, name)
818: ? true:false; // This is a dumb bool conversion to make BC++ happy
819: if(result) {
820: sprintf(str,"%sbad%s.msg",cfg.text_dir,name);
821: if(fexistcase(str)) {
822: printfile(str,0);
823: mswait(500); // give time for tx buffer to clear before disconnect
824: }
825: }
826: return(result);
827: }
828:
829: char* sbbs_t::timestr(time_t *intime)
830: {
831: return(::timestr(&cfg,intime,timestr_output));
832: }
833:
834: void sbbs_t::sys_info()
835: {
836: char tmp[128];
837: uint i;
838: stats_t stats;
839:
840: bputs(text[SiHdr]);
841: getstats(&cfg,0,&stats);
842: bprintf(text[SiSysName],cfg.sys_name);
843: bprintf(text[SiSysID],cfg.sys_id); /* QWK ID */
844: for(i=0;i<cfg.total_faddrs;i++)
845: bprintf(text[SiSysFaddr],smb_faddrtoa(&cfg.faddr[i],tmp));
846: if(cfg.sys_psname[0]) /* PostLink/PCRelay */
847: bprintf(text[SiSysPsite],cfg.sys_psname,cfg.sys_psnum);
848: bprintf(text[SiSysLocation],cfg.sys_location);
849: bprintf(text[SiSysop],cfg.sys_op);
850: bprintf(text[SiSysNodes],cfg.sys_nodes);
851: // bprintf(text[SiNodeNumberName],cfg.node_num,cfg.node_name);
852: bprintf(text[SiNodePhone],cfg.node_phone);
853: bprintf(text[SiTotalLogons],ultoac(stats.logons,tmp));
854: bprintf(text[SiLogonsToday],ultoac(stats.ltoday,tmp));
855: bprintf(text[SiTotalTime],ultoac(stats.timeon,tmp));
856: bprintf(text[SiTimeToday],ultoac(stats.ttoday,tmp));
857: ver();
858: if(yesno(text[ViewSysInfoFileQ])) {
859: CLS;
860: sprintf(tmp,"%ssystem.msg", cfg.text_dir);
861: printfile(tmp,0);
862: }
863: if(yesno(text[ViewLogonMsgQ])) {
864: CLS;
865: menu("logon");
866: }
867: }
868:
869: void sbbs_t::user_info()
870: {
871: float f;
872: char str[128];
873: char tmp[128];
874: char tmp2[128];
875: struct tm tm;
876:
877: bprintf(text[UserStats],useron.alias,useron.number);
878:
879: if(localtime_r(&useron.laston,&tm)!=NULL)
880: bprintf(text[UserDates]
881: ,unixtodstr(&cfg,useron.firston,str)
882: ,unixtodstr(&cfg,useron.expire,tmp)
883: ,unixtodstr(&cfg,useron.laston,tmp2)
884: ,tm.tm_hour,tm.tm_min);
885:
886: bprintf(text[UserTimes]
887: ,useron.timeon,useron.ttoday
888: ,cfg.level_timeperday[useron.level]
889: ,useron.tlast
890: ,cfg.level_timepercall[useron.level]
891: ,useron.textra);
892: if(useron.posts)
893: f=(float)useron.logons/useron.posts;
894: else
895: f=0;
896: bprintf(text[UserLogons]
897: ,useron.logons,useron.ltoday
898: ,cfg.level_callsperday[useron.level],useron.posts
899: ,f ? (uint)(100/f) : useron.posts>useron.logons ? 100 : 0
900: ,useron.ptoday);
901: bprintf(text[UserEmails]
902: ,useron.emails,useron.fbacks
903: ,getmail(&cfg,useron.number,0),useron.etoday);
904: CRLF;
905: bprintf(text[UserUploads]
906: ,ultoac(useron.ulb,tmp),useron.uls);
907: bprintf(text[UserDownloads]
908: ,ultoac(useron.dlb,tmp),useron.dls,nulstr);
909: bprintf(text[UserCredits],ultoac(useron.cdt,tmp)
910: ,ultoac(useron.freecdt,tmp2)
911: ,ultoac(cfg.level_freecdtperday[useron.level],str));
912: bprintf(text[UserMinutes],ultoac(useron.min,tmp));
913: }
914:
915: void sbbs_t::xfer_policy()
916: {
917: char str[MAX_PATH+1];
918:
919: if(!usrlibs) return;
920: sprintf(str,"%smenu/tpolicy.*", cfg.text_dir);
921: if(fexist(str))
922: menu("tpolicy");
923: else {
924: bprintf(text[TransferPolicyHdr],cfg.sys_name);
925: bprintf(text[TpUpload]
926: ,cfg.dir[usrdir[curlib][curdir[curlib]]]->up_pct);
927: bprintf(text[TpDownload]
928: ,cfg.dir[usrdir[curlib][curdir[curlib]]]->dn_pct);
929: }
930: }
931:
932: const char* prot_menu_file[] = {
933: "ulprot"
934: ,"dlprot"
935: ,"batuprot"
936: ,"batdprot"
937: ,"biprot"
938: };
939:
940: void sbbs_t::xfer_prot_menu(enum XFER_TYPE type)
941: {
942: char path[MAX_PATH+1];
943:
944: sprintf(path,"%smenu/%s.*",cfg.text_dir,prot_menu_file[type]);
945: if(fexistcase(path)) {
946: menu(prot_menu_file[type]);
947: return;
948: }
949:
950: CRLF;
951: int printed=0;
952: for(int i=0;i<cfg.total_prots;i++) {
953: if(!chk_ar(cfg.prot[i]->ar,&useron))
954: continue;
955: if(type==XFER_UPLOAD && cfg.prot[i]->ulcmd[0]==0)
956: continue;
957: if(type==XFER_DOWNLOAD && cfg.prot[i]->dlcmd[0]==0)
958: continue;
959: if(type==XFER_BATCH_UPLOAD && cfg.prot[i]->batulcmd[0]==0)
960: continue;
961: if(type==XFER_BATCH_DOWNLOAD && cfg.prot[i]->batdlcmd[0]==0)
962: continue;
963: if(type==XFER_BIDIR && cfg.prot[i]->bicmd[0]==0)
964: continue;
965: if(printed && (printed%2)==0)
966: CRLF;
967: bprintf(text[TransferProtLstFmt],cfg.prot[i]->mnemonic,cfg.prot[i]->name);
968: printed++;
969: }
970: CRLF;
971: }
972:
973: void sbbs_t::node_stats(uint node_num)
974: {
975: char tmp[128];
976: stats_t stats;
977:
978: if(node_num>cfg.sys_nodes) {
979: bputs(text[InvalidNode]);
980: return;
981: }
982: if(!node_num) node_num=cfg.node_num;
983: bprintf(text[NodeStatsHdr],node_num);
984: getstats(&cfg,node_num,&stats);
985: bprintf(text[StatsTotalLogons],ultoac(stats.logons,tmp));
986: bprintf(text[StatsLogonsToday],ultoac(stats.ltoday,tmp));
987: bprintf(text[StatsTotalTime],ultoac(stats.timeon,tmp));
988: bprintf(text[StatsTimeToday],ultoac(stats.ttoday,tmp));
989: bprintf(text[StatsUploadsToday],ultoac(stats.ulb,tmp)
990: ,stats.uls);
991: bprintf(text[StatsDownloadsToday],ultoac(stats.dlb,tmp)
992: ,stats.dls);
993: bprintf(text[StatsPostsToday],ultoac(stats.ptoday,tmp));
994: bprintf(text[StatsEmailsToday],ultoac(stats.etoday,tmp));
995: bprintf(text[StatsFeedbacksToday],ultoac(stats.ftoday,tmp));
996: }
997:
998: void sbbs_t::sys_stats(void)
999: {
1000: char tmp[128];
1001: stats_t stats;
1002:
1003: bputs(text[SystemStatsHdr]);
1004: getstats(&cfg,0,&stats);
1005: bprintf(text[StatsTotalLogons],ultoac(stats.logons,tmp));
1006: bprintf(text[StatsLogonsToday],ultoac(stats.ltoday,tmp));
1007: bprintf(text[StatsTotalTime],ultoac(stats.timeon,tmp));
1008: bprintf(text[StatsTimeToday],ultoac(stats.ttoday,tmp));
1009: bprintf(text[StatsUploadsToday],ultoac(stats.ulb,tmp)
1010: ,stats.uls);
1011: bprintf(text[StatsDownloadsToday],ultoac(stats.dlb,tmp)
1012: ,stats.dls);
1013: bprintf(text[StatsPostsToday],ultoac(stats.ptoday,tmp));
1014: bprintf(text[StatsEmailsToday],ultoac(stats.etoday,tmp));
1015: bprintf(text[StatsFeedbacksToday],ultoac(stats.ftoday,tmp));
1016: }
1017:
1018: void sbbs_t::logonlist(void)
1019: {
1020: char str[MAX_PATH+1];
1021:
1022: sprintf(str,"%slogon.lst", cfg.data_dir);
1023: if(flength(str)<1) {
1024: bputs("\r\n\r\n");
1025: bputs(text[NoOneHasLoggedOnToday]);
1026: } else {
1027: bputs(text[CallersToday]);
1028: printfile(str,P_NOATCODES|P_OPENCLOSE);
1029: CRLF;
1030: }
1031: }
1032:
1033: extern SOCKET spy_socket[];
1034: extern RingBuf* node_inbuf[];
1035:
1036: bool sbbs_t::spy(uint i /* node_num */)
1037: {
1038: char ch;
1039: char ansi_seq[32];
1040: int ansi_len;
1041: int in;
1042:
1043: if(!i || i>MAX_NODES) {
1044: bprintf("Invalid node number: %d\r\n",i);
1045: return(false);
1046: }
1047: if(i==cfg.node_num) {
1048: bprintf("Can't spy on yourself.\r\n");
1049: return(false);
1050: }
1051: if(spy_socket[i-1]!=INVALID_SOCKET) {
1052: bprintf("Node %d already being spied (%lx)\r\n",i,spy_socket[i-1]);
1053: return(false);
1054: }
1055: bprintf("*** Synchronet Remote Spy on Node %d: Ctrl-C to Abort ***"
1056: "\r\n\r\n",i);
1057: spy_socket[i-1]=client_socket;
1058: ansi_len=0;
1059: while(online
1060: && client_socket!=INVALID_SOCKET
1061: && spy_socket[i-1]!=INVALID_SOCKET
1062: && !msgabort()) {
1063: in=incom(1000);
1064: if(in==NOINP) {
1065: gettimeleft();
1066: continue;
1067: }
1068: ch=in;
1069: if(ch==ESC) {
1070: if(!ansi_len) {
1071: ansi_seq[ansi_len++]=ch;
1072: continue;
1073: }
1074: ansi_len=0;
1075: }
1076: if(ansi_len && ansi_len<(int)sizeof(ansi_seq)-2) {
1077: if(ansi_len==1) {
1078: if(ch=='[') {
1079: ansi_seq[ansi_len++]=ch;
1080: continue;
1081: }
1082: ansi_len=0;
1083: }
1084: if(ch=='R') { /* throw-away cursor position report */
1085: ansi_len=0;
1086: continue;
1087: }
1088: ansi_seq[ansi_len++]=ch;
1089: if(isalpha(ch)) {
1090: RingBufWrite(node_inbuf[i-1],(uchar*)ansi_seq,ansi_len);
1091: ansi_len=0;
1092: }
1093: continue;
1094: }
1095: if(ch<' ') {
1096: lncntr=0; /* defeat pause */
1097: spy_socket[i-1]=INVALID_SOCKET; /* disable spy output */
1098: ch=handle_ctrlkey(ch,K_NONE);
1099: spy_socket[i-1]=client_socket; /* enable spy output */
1100: if(ch==0)
1101: continue;
1102: }
1103: if(node_inbuf[i-1]!=NULL)
1104: RingBufWrite(node_inbuf[i-1],(uchar*)&ch,1);
1105: }
1106: spy_socket[i-1]=INVALID_SOCKET;
1107: return(true);
1108: }
1109:
1110: void sbbs_t::time_bank(void)
1111: {
1112: char str[128];
1113: char tmp[128];
1114: char tmp2[128];
1115: int s;
1116:
1117: if(cfg.sys_misc&SM_TIMEBANK) { /* Allow users to deposit free time */
1118: s=(cfg.level_timeperday[useron.level]-useron.ttoday)+useron.textra;
1119: if(s<0) s=0;
1120: if(s>cfg.level_timepercall[useron.level])
1121: s=cfg.level_timepercall[useron.level];
1122: s-=(now-starttime)/60;
1123: if(s<0) s=0;
1124: bprintf(text[FreeMinLeft],s);
1125: bprintf(text[UserMinutes],ultoac(useron.min,tmp));
1126: if(cfg.max_minutes && useron.min>=cfg.max_minutes) {
1127: bputs(text[YouHaveTooManyMinutes]);
1128: return;
1129: }
1130: if(cfg.max_minutes)
1131: while(s>0 && s+useron.min>cfg.max_minutes) s--;
1132: bprintf(text[FreeMinToDeposit],s);
1133: s=getnum(s);
1134: if(s>0) {
1135: logline(" ","Minute Bank Deposit");
1136: useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10,s);
1137: useron.ttoday=(ushort)adjustuserrec(&cfg,useron.number,U_TTODAY,10,s);
1138: sprintf(str,"Minute Adjustment: %u",s*cfg.cdt_min_value);
1139: logline("*+",str);
1140: }
1141: }
1142:
1143: if(!(cfg.sys_misc&SM_NOCDTCVT)) {
1144: bprintf(text[ConversionRate],cfg.cdt_min_value);
1145: bprintf(text[UserCredits]
1146: ,ultoac(useron.cdt,tmp)
1147: ,ultoac(useron.freecdt,tmp2)
1148: ,ultoac(cfg.level_freecdtperday[useron.level],str));
1149: bprintf(text[UserMinutes],ultoac(useron.min,tmp));
1150: if(useron.cdt/102400L<1L) {
1151: bprintf(text[YouOnlyHaveNCredits],ultoac(useron.cdt,tmp));
1152: return;
1153: }
1154: if(cfg.max_minutes && useron.min>=cfg.max_minutes) {
1155: bputs(text[YouHaveTooManyMinutes]);
1156: return;
1157: }
1158: s=useron.cdt/102400L;
1159: if(cfg.max_minutes)
1160: while(s>0 && (s*cfg.cdt_min_value)+useron.min>cfg.max_minutes) s--;
1161: bprintf(text[CreditsToMin],s);
1162: s=getnum(s);
1163: if(s>0) {
1164: logline(" ","Credit to Minute Conversion");
1165: useron.cdt=adjustuserrec(&cfg,useron.number,U_CDT,10,-(s*102400L));
1166: useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10,s*cfg.cdt_min_value);
1167: sprintf(str,"Credit Adjustment: %ld",-(s*102400L));
1168: logline("$-",str);
1169: sprintf(str,"Minute Adjustment: %u",s*cfg.cdt_min_value);
1170: logline("*+",str);
1171: }
1172: }
1173: }
1174:
1175: void sbbs_t::change_user(void)
1176: {
1177: uint i;
1178: char str[256];
1179: char tmp[128];
1180:
1181: if(!chksyspass())
1182: return;
1183: bputs(text[ChUserPrompt]);
1184: if(!getstr(str,LEN_ALIAS,K_UPPER))
1185: return;
1186: if((i=finduser(str))==0)
1187: return;
1188: if(online==ON_REMOTE) {
1189: getuserrec(&cfg,i,U_LEVEL,2,str);
1190: if(atoi(str)>logon_ml) {
1191: getuserrec(&cfg,i,U_PASS,8,tmp);
1192: bputs(text[ChUserPwPrompt]);
1193: console|=CON_R_ECHOX;
1194: getstr(str,8,K_UPPER);
1195: console&=~(CON_R_ECHOX|CON_L_ECHOX);
1196: if(strcmp(str,tmp))
1197: return;
1198: }
1199: }
1200: putmsgptrs();
1201: putuserrec(&cfg,useron.number,U_CURSUB,0
1202: ,cfg.sub[usrsub[curgrp][cursub[curgrp]]]->code);
1203: putuserrec(&cfg,useron.number,U_CURDIR,0
1204: ,cfg.dir[usrdir[curlib][curdir[curlib]]]->code);
1205: useron.number=i;
1206: getuserdat(&cfg,&useron);
1207: getnodedat(cfg.node_num,&thisnode,1);
1208: thisnode.useron=useron.number;
1209: putnodedat(cfg.node_num,&thisnode);
1210: getmsgptrs();
1211: if(REALSYSOP) sys_status&=~SS_TMPSYSOP;
1212: else sys_status|=SS_TMPSYSOP;
1213: sprintf(str,"Changed into %s #%u",useron.alias,useron.number);
1214: logline("S+",str);
1215: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.