|
|
1.1 root 1: /* logon.cpp */
2:
3: /* Synchronet user logon routines */
4:
1.1.1.2 ! root 5: /* $Id: logon.cpp,v 1.57 2011/09/21 03:10:53 rswindell Exp $ */
1.1 root 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: * *
1.1.1.2 ! root 11: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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: #include "cmdshell.h"
40:
41: extern "C" void client_on(SOCKET sock, client_t* client, BOOL update);
42:
43: /****************************************************************************/
44: /* Called once upon each user logging on the board */
45: /* Returns 1 if user passed logon, 0 if user failed. */
46: /****************************************************************************/
47: bool sbbs_t::logon()
48: {
49: char str[256],c;
50: char tmp[512];
51: int file;
52: uint i,j,mailw;
53: long kmode;
54: ulong totallogons;
55: node_t node;
56: struct tm tm;
57:
58: now=time(NULL);
59: if(localtime_r(&now,&tm)==NULL)
60: return(false);
61:
62: if(!useron.number)
63: return(false);
64:
65: client.user=useron.alias;
66: client_on(client_socket,&client,TRUE /* update */);
67:
68: #ifdef JAVASCRIPT
69: js_create_user_objects();
70: #endif
71:
72: if(useron.rest&FLAG('Q'))
73: qwklogon=1;
74: if(SYSOP && !(cfg.sys_misc&SM_R_SYSOP))
75: return(false);
76:
77: if(useron.rest&FLAG('G')) { /* Guest account */
78: useron.misc=(cfg.new_misc&(~ASK_NSCAN));
79: useron.rows=0;
80: useron.misc&=~(ANSI|RIP|WIP|NO_EXASCII|COLOR|HTML);
81: useron.misc|=autoterm;
1.1.1.2 ! root 82: if(!(useron.misc&ANSI) && text[AnsiTerminalQ][0] && yesno(text[AnsiTerminalQ]))
1.1 root 83: useron.misc|=ANSI;
84: if(useron.misc&(RIP|WIP|HTML)
1.1.1.2 ! root 85: || (useron.misc&ANSI && text[ColorTerminalQ][0] && yesno(text[ColorTerminalQ])))
1.1 root 86: useron.misc|=COLOR;
1.1.1.2 ! root 87: if(text[ExAsciiTerminalQ][0] && !yesno(text[ExAsciiTerminalQ]))
1.1 root 88: useron.misc|=NO_EXASCII;
89: for(i=0;i<cfg.total_xedits;i++)
90: if(!stricmp(cfg.xedit[i]->code,cfg.new_xedit)
1.1.1.2 ! root 91: && chk_ar(cfg.xedit[i]->ar,&useron,&client))
1.1 root 92: break;
93: if(i<cfg.total_xedits)
94: useron.xedit=i+1;
95: else
96: useron.xedit=0;
97: useron.prot=cfg.new_prot;
98: useron.shell=cfg.new_shell;
99: }
100:
1.1.1.2 ! root 101: if(!chk_ar(cfg.node_ar,&useron,&client)) {
1.1 root 102: bputs(text[NoNodeAccess]);
103: sprintf(str,"(%04u) %-25s Insufficient node access"
104: ,useron.number,useron.alias);
1.1.1.2 ! root 105: logline(LOG_NOTICE,"+!",str);
1.1 root 106: return(false);
107: }
108:
109: getnodedat(cfg.node_num,&thisnode,1);
110: if(thisnode.misc&NODE_LOCK) {
111: putnodedat(cfg.node_num,&thisnode); /* must unlock! */
112: if(!SYSOP && !(useron.exempt&FLAG('N'))) {
113: bputs(text[NodeLocked]);
114: sprintf(str,"(%04u) %-25s Locked node logon attempt"
115: ,useron.number,useron.alias);
1.1.1.2 ! root 116: logline(LOG_NOTICE,"+!",str);
1.1 root 117: return(false);
118: }
119: if(yesno(text[RemoveNodeLockQ])) {
120: getnodedat(cfg.node_num,&thisnode,1);
121: logline("S-","Removed Node Lock");
122: thisnode.misc&=~NODE_LOCK;
123: }
124: else
125: getnodedat(cfg.node_num,&thisnode,1);
126: }
127:
128: if(useron.exempt&FLAG('H'))
129: console|=CON_NO_INACT;
130:
131: if((useron.exempt&FLAG('Q') && useron.misc&QUIET))
132: thisnode.status=NODE_QUIET;
133: else
134: thisnode.status=NODE_INUSE;
135: action=thisnode.action=NODE_LOGN;
1.1.1.2 ! root 136: thisnode.connection=node_connection;
1.1 root 137: thisnode.misc&=~(NODE_ANON|NODE_INTR|NODE_MSGW|NODE_POFF|NODE_AOFF);
138: if(useron.chat&CHAT_NOACT)
139: thisnode.misc|=NODE_AOFF;
140: if(useron.chat&CHAT_NOPAGE)
141: thisnode.misc|=NODE_POFF;
142: thisnode.useron=useron.number;
143: putnodedat(cfg.node_num,&thisnode);
144:
145: getusrsubs();
146: getusrdirs();
147:
148: if(useron.misc&CURSUB && !(useron.rest&FLAG('G'))) {
149: for(i=0;i<usrgrps;i++) {
150: for(j=0;j<usrsubs[i];j++) {
151: if(!strcmp(cfg.sub[usrsub[i][j]]->code,useron.cursub))
152: break;
153: }
154: if(j<usrsubs[i]) {
155: curgrp=i;
156: cursub[i]=j;
157: break;
158: }
159: }
160: for(i=0;i<usrlibs;i++) {
161: for(j=0;j<usrdirs[i];j++)
162: if(!strcmp(cfg.dir[usrdir[i][j]]->code,useron.curdir))
163: break;
164: if(j<usrdirs[i]) {
165: curlib=i;
166: curdir[i]=j;
167: break;
168: }
169: }
170: }
171:
172:
173: if(useron.misc&AUTOTERM) {
174: useron.misc&=~(ANSI|RIP|WIP|HTML);
175: useron.misc|=autoterm;
176: }
177:
1.1.1.2 ! root 178: if(!chk_ar(cfg.shell[useron.shell]->ar,&useron,&client)) {
1.1 root 179: useron.shell=cfg.new_shell;
1.1.1.2 ! root 180: if(!chk_ar(cfg.shell[useron.shell]->ar,&useron,&client)) {
1.1 root 181: for(i=0;i<cfg.total_shells;i++)
1.1.1.2 ! root 182: if(chk_ar(cfg.shell[i]->ar,&useron,&client))
1.1 root 183: break;
184: if(i==cfg.total_shells)
185: useron.shell=0;
186: }
187: }
188:
189: logon_ml=useron.level;
190: logontime=time(NULL);
191: starttime=logontime;
192: useron.logontime=logontime;
193: last_ns_time=ns_time=useron.ns_time;
194: // ns_time-=(useron.tlast*60); /* file newscan time == last logon time */
195: delfiles(cfg.temp_dir,ALLFILES);
196: sprintf(str,"%smsgs/n%3.3u.msg",cfg.data_dir,cfg.node_num);
197: remove(str); /* remove any pending node messages */
198: sprintf(str,"%smsgs/n%3.3u.ixb",cfg.data_dir,cfg.node_num);
199: remove(str); /* remove any pending node message indices */
200:
201: if(!SYSOP && online==ON_REMOTE && !qwklogon) {
202: rioctl(IOCM|ABORT); /* users can't abort anything */
203: rioctl(IOCS|ABORT);
204: }
205:
206: CLS;
207: if(useron.rows)
208: rows=useron.rows;
209: unixtodstr(&cfg,logontime,str);
210: if(!strncmp(str,useron.birth,5) && !(useron.rest&FLAG('Q'))) {
211: bputs(text[HappyBirthday]);
212: pause();
213: CLS;
214: user_event(EVENT_BIRTHDAY);
215: }
1.1.1.2 ! root 216: useron.ltoday++;
1.1 root 217:
218: gettimeleft();
219: sprintf(str,"%sfile/%04u.dwn",cfg.data_dir,useron.number);
220: batch_add_list(str);
221: if(!qwklogon) { /* QWK Nodes don't go through this */
222:
223: if(cfg.sys_pwdays
224: && (ulong)logontime>(useron.pwmod+((ulong)cfg.sys_pwdays*24UL*60UL*60UL))) {
225: bprintf(text[TimeToChangePw],cfg.sys_pwdays);
226:
227: c=0;
228: while(c<LEN_PASS) { /* Create random password */
229: str[c]=sbbs_random(43)+'0';
230: if(isalnum(str[c]))
231: c++;
232: }
233: str[c]=0;
234: bprintf(text[YourPasswordIs],str);
235:
236: if(cfg.sys_misc&SM_PWEDIT && yesno(text[NewPasswordQ]))
237: while(online) {
238: bputs(text[NewPassword]);
239: getstr(str,LEN_PASS,K_UPPER|K_LINE);
240: truncsp(str);
241: if(chkpass(str,&useron,true))
242: break;
243: CRLF;
244: }
245:
246: while(online) {
247: if(cfg.sys_misc&SM_PWEDIT) {
248: CRLF;
249: bputs(text[VerifyPassword]);
250: }
251: else
252: bputs(text[NewUserPasswordVerify]);
253: console|=CON_R_ECHOX;
254: getstr(tmp,LEN_PASS*2,K_UPPER);
255: console&=~(CON_R_ECHOX|CON_L_ECHOX);
256: if(strcmp(str,tmp)) {
257: bputs(text[Wrong]);
258: continue;
259: }
260: break;
261: }
262: strcpy(useron.pass,str);
263: useron.pwmod=time(NULL);
264: putuserrec(&cfg,useron.number,U_PWMOD,8,ultoa(useron.pwmod,str,16));
265: bputs(text[PasswordChanged]);
266: pause();
267: }
268: if(useron.ltoday>cfg.level_callsperday[useron.level]
269: && !(useron.exempt&FLAG('L'))) {
270: bputs(text[NoMoreLogons]);
271: sprintf(str,"(%04u) %-25s Out of logons"
272: ,useron.number,useron.alias);
1.1.1.2 ! root 273: logline(LOG_NOTICE,"+!",str);
1.1 root 274: hangup();
275: return(false);
276: }
277: if(useron.rest&FLAG('L') && useron.ltoday>1) {
278: bputs(text[R_Logons]);
279: sprintf(str,"(%04u) %-25s Out of logons"
280: ,useron.number,useron.alias);
1.1.1.2 ! root 281: logline(LOG_NOTICE,"+!",str);
1.1 root 282: hangup();
283: return(false);
284: }
285: kmode=(cfg.uq&UQ_NOEXASC);
286: if(!(cfg.uq&UQ_NOUPRLWR))
287: kmode|=K_UPRLWR;
288:
289: if(!(useron.rest&FLAG('G'))) {
290: if(!useron.name[0] && ((cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME)
291: || cfg.uq&UQ_COMPANY))
292: while(online) {
293: if(cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME)
294: bputs(text[EnterYourRealName]);
295: else
296: bputs(text[EnterYourCompany]);
297: getstr(useron.name,LEN_NAME,kmode);
298: if(cfg.uq&UQ_ALIASES && cfg.uq&UQ_REALNAME) {
299: if(trashcan(useron.name,"name") || !useron.name[0]
300: || !strchr(useron.name,' ')
301: || strchr(useron.name,0xff)
302: || (cfg.uq&UQ_DUPREAL
303: && userdatdupe(useron.number,U_NAME,LEN_NAME
1.1.1.2 ! root 304: ,useron.name,0,0)))
1.1 root 305: bputs(text[YouCantUseThatName]);
306: else
307: break;
308: }
309: else
310: break;
311: }
312: if(cfg.uq&UQ_HANDLE && !useron.handle[0]) {
313: sprintf(useron.handle,"%.*s",LEN_HANDLE,useron.alias);
314: while(online) {
315: bputs(text[EnterYourHandle]);
316: if(!getstr(useron.handle,LEN_HANDLE
317: ,K_LINE|K_EDIT|K_AUTODEL|(cfg.uq&UQ_NOEXASC))
318: || strchr(useron.handle,0xff)
319: || (cfg.uq&UQ_DUPHAND
320: && userdatdupe(useron.number,U_HANDLE,LEN_HANDLE
1.1.1.2 ! root 321: ,useron.handle,0,0))
1.1 root 322: || trashcan(useron.handle,"name"))
323: bputs(text[YouCantUseThatName]);
324: else
325: break;
326: }
327: }
328: if(cfg.uq&UQ_LOCATION && !useron.location[0])
329: while(online) {
330: bputs(text[EnterYourCityState]);
331: if(getstr(useron.location,LEN_LOCATION,kmode))
332: break;
333: }
334: if(cfg.uq&UQ_ADDRESS && !useron.address[0])
335: while(online) {
336: bputs(text[EnterYourAddress]);
337: if(getstr(useron.address,LEN_ADDRESS,kmode))
338: break;
339: }
340: if(cfg.uq&UQ_ADDRESS && !useron.zipcode[0])
341: while(online) {
342: bputs(text[EnterYourZipCode]);
343: if(getstr(useron.zipcode,LEN_ZIPCODE,K_UPPER|(cfg.uq&UQ_NOEXASC)))
344: break;
345: }
346: if(cfg.uq&UQ_PHONE && !useron.phone[0]) {
1.1.1.2 ! root 347: if(text[CallingFromNorthAmericaQ][0])
! 348: i=yesno(text[CallingFromNorthAmericaQ]);
! 349: else
! 350: i=0;
1.1 root 351: while(online) {
352: bputs(text[EnterYourPhoneNumber]);
353: if(i) {
354: if(gettmplt(useron.phone,cfg.sys_phonefmt
355: ,K_LINE|(cfg.uq&UQ_NOEXASC))<strlen(cfg.sys_phonefmt))
356: continue;
357: } else {
358: if(getstr(useron.phone,LEN_PHONE
359: ,K_UPPER|(cfg.uq&UQ_NOEXASC))<5)
360: continue;
361: }
362: if(!trashcan(useron.phone,"phone"))
363: break;
364: }
365: }
366: if(!(sys_status&SS_RLOGIN)
367: && !(cfg.uq&UQ_NONETMAIL) && !useron.netmail[0]) {
368: while(online) {
369: bputs(text[EnterNetMailAddress]);
370: if(getstr(useron.netmail,LEN_NETMAIL,K_EDIT|K_AUTODEL|K_LINE)
371: && !trashcan(useron.netmail,"email"))
372: break;
373: }
374: if(useron.netmail[0] && cfg.sys_misc&SM_FWDTONET && !noyes(text[ForwardMailQ]))
375: useron.misc|=NETMAIL;
376: else
377: useron.misc&=~NETMAIL;
378: }
379: if(cfg.new_sif[0]) {
380: sprintf(str,"%suser/%4.4u.dat",cfg.data_dir,useron.number);
381: if(flength(str)<1L)
382: create_sif_dat(cfg.new_sif,str);
383: }
384: }
385: }
386: if(!online) {
387: sprintf(str,"(%04u) %-25s Unsuccessful logon"
388: ,useron.number,useron.alias);
1.1.1.2 ! root 389: logline(LOG_NOTICE,"+!",str);
1.1 root 390: return(false);
391: }
1.1.1.2 ! root 392: SAFECOPY(useron.modem,connection);
1.1 root 393: useron.logons++;
394: putuserdat(&cfg,&useron);
395: getmsgptrs();
396: sys_status|=SS_USERON; /* moved from further down */
397:
398: if(useron.rest&FLAG('Q')) {
399: sprintf(str,"(%04u) %-25s QWK Network Connection"
400: ,useron.number,useron.alias);
401: logline("++",str);
402: return(true);
403: }
404:
405: /********************/
406: /* SUCCESSFUL LOGON */
407: /********************/
408: totallogons=logonstats();
409: sprintf(str,"(%04u) %-25s Logon %lu - %u"
410: ,useron.number,useron.alias,totallogons,useron.ltoday);
411: logline("++",str);
412:
413: if(!qwklogon && cfg.logon_mod[0])
414: exec_bin(cfg.logon_mod,&main_csi);
415:
416: if(thisnode.status!=NODE_QUIET && (!REALSYSOP || cfg.sys_misc&SM_SYSSTAT)) {
417: sprintf(str,"%slogon.lst",cfg.data_dir);
418: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
419: errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_CREAT|O_APPEND);
420: return(false);
421: }
422: getuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note);
423: getuserrec(&cfg,useron.number,U_LOCATION,LEN_LOCATION,useron.location);
424: sprintf(str,text[LastFewCallersFmt],cfg.node_num
425: ,totallogons,useron.alias
426: ,cfg.sys_misc&SM_LISTLOC ? useron.location : useron.note
427: ,tm.tm_hour,tm.tm_min
1.1.1.2 ! root 428: ,connection,useron.ltoday > 999 ? 999 : useron.ltoday);
1.1 root 429: write(file,str,strlen(str));
430: close(file);
431: }
432:
433: if(cfg.sys_logon[0]) /* execute system logon event */
1.1.1.2 ! root 434: external(cmdstr(cfg.sys_logon,nulstr,nulstr,NULL),EX_STDOUT); /* EX_SH */
1.1 root 435:
436: if(qwklogon)
437: return(true);
438:
439: sys_status|=SS_PAUSEON; /* always force pause on during this section */
440: mailw=getmail(&cfg,useron.number,0);
441:
442: if(!(cfg.sys_misc&SM_NOSYSINFO)) {
443: bprintf(text[SiSysName],cfg.sys_name);
444: //bprintf(text[SiNodeNumberName],cfg.node_num,cfg.node_name);
445: bprintf(text[LiUserNumberName],useron.number,useron.alias);
446: bprintf(text[LiLogonsToday],useron.ltoday
447: ,cfg.level_callsperday[useron.level]);
448: bprintf(text[LiTimeonToday],useron.ttoday
449: ,cfg.level_timeperday[useron.level]+useron.min);
450: bprintf(text[LiMailWaiting],mailw);
451: strcpy(str,text[LiSysopIs]);
452: if(startup->options&BBS_OPT_SYSOP_AVAILABLE
1.1.1.2 ! root 453: || (cfg.sys_chat_ar[0] && chk_ar(cfg.sys_chat_ar,&useron,&client)))
1.1 root 454: strcat(str,text[LiSysopAvailable]);
455: else
456: strcat(str,text[LiSysopNotAvailable]);
457: bprintf("%s\r\n\r\n",str);
458: }
459:
460: if(sys_status&SS_EVENT)
1.1.1.2 ! root 461: bprintf(text[ReducedTime],timestr(event_time));
1.1 root 462: getnodedat(cfg.node_num,&thisnode,1);
463: thisnode.misc&=~(NODE_AOFF|NODE_POFF);
464: if(useron.chat&CHAT_NOACT)
465: thisnode.misc|=NODE_AOFF;
466: if(useron.chat&CHAT_NOPAGE)
467: thisnode.misc|=NODE_POFF;
468: putnodedat(cfg.node_num,&thisnode);
469:
470: getsmsg(useron.number); /* Moved from further down */
471: SYNC;
472: c=0;
473: for(i=1;i<=cfg.sys_nodes;i++)
474: if(i!=cfg.node_num) {
475: getnodedat(i,&node,0);
476: if(!(cfg.sys_misc&SM_NONODELIST)
477: && (node.status==NODE_INUSE
478: || ((node.status==NODE_QUIET || node.errors) && SYSOP))) {
479: if(!c)
480: bputs(text[NodeLstHdr]);
481: printnodedat(i,&node);
482: c=1;
483: }
484: if(node.status==NODE_INUSE && i!=cfg.node_num && node.useron==useron.number
485: && !SYSOP && !(useron.exempt&FLAG('G'))) {
1.1.1.2 ! root 486: SAFEPRINTF2(str,"(%04u) %-25s On two nodes at the same time"
! 487: ,useron.number,useron.alias);
! 488: logline(LOG_NOTICE,"+!",str);
1.1 root 489: bputs(text[UserOnTwoNodes]);
490: hangup();
491: return(false);
492: }
493: if(thisnode.status!=NODE_QUIET
494: && (node.status==NODE_INUSE || node.status==NODE_QUIET)
495: && !(node.misc&NODE_AOFF) && node.useron!=useron.number) {
496: sprintf(str,text[NodeLoggedOnAtNbps]
497: ,cfg.node_num
498: ,thisnode.misc&NODE_ANON ? text[UNKNOWN_USER] : useron.alias
499: ,connection);
500: putnmsg(&cfg,i,str);
501: }
502: }
503:
504: if(cfg.sys_exp_warn && useron.expire && useron.expire>now /* Warn user of coming */
505: && (useron.expire-now)/(1440L*60L)<=cfg.sys_exp_warn) /* expiration */
506: bprintf(text[AccountWillExpireInNDays],(useron.expire-now)/(1440L*60L));
507:
508: if(criterrs && SYSOP)
509: bprintf(text[CriticalErrors],criterrs);
510: if((i=getuserxfers(0,useron.number,0))!=0)
511: bprintf(text[UserXferForYou],i,i>1 ? "s" : nulstr);
512: if((i=getuserxfers(useron.number,0,0))!=0)
513: bprintf(text[UnreceivedUserXfer],i,i>1 ? "s" : nulstr);
514: SYNC;
515: sys_status&=~SS_PAUSEON; /* Turn off the pause override flag */
516: if(online==ON_REMOTE)
517: rioctl(IOSM|ABORT); /* Turn abort ability on */
1.1.1.2 ! root 518: if(text[ReadYourMailNowQ][0] && mailw) {
1.1 root 519: if(yesno(text[ReadYourMailNowQ]))
520: readmail(useron.number,MAIL_YOUR);
521: }
1.1.1.2 ! root 522: if(usrgrps && useron.misc&ASK_NSCAN && text[NScanAllGrpsQ][0] && yesno(text[NScanAllGrpsQ]))
1.1 root 523: scanallsubs(SCAN_NEW);
1.1.1.2 ! root 524: if(usrgrps && useron.misc&ASK_SSCAN && text[SScanAllGrpsQ][0] && yesno(text[SScanAllGrpsQ]))
1.1 root 525: scanallsubs(SCAN_TOYOU);
526: return(true);
527: }
528:
529: /****************************************************************************/
530: /* Checks the system dsts.dab to see if it is a new day, if it is, all the */
531: /* nodes' and the system's csts.dab are added to, and the dsts.dab's daily */
532: /* stats are cleared. Also increments the logon values in dsts.dab if */
533: /* applicable. */
534: /****************************************************************************/
535: ulong sbbs_t::logonstats()
536: {
537: char str[MAX_PATH+1];
538: int dsts,csts;
539: uint i;
1.1.1.2 ! root 540: time32_t update32_t=0;
1.1 root 541: time_t update_t=0;
1.1.1.2 ! root 542: time32_t now32;
1.1 root 543: stats_t stats;
544: node_t node;
545: struct tm tm, update_tm;
546:
547: sys_status&=~SS_DAILY;
548: memset(&stats,0,sizeof(stats));
549: sprintf(str,"%sdsts.dab",cfg.ctrl_dir);
550: if((dsts=nopen(str,O_RDWR))==-1) {
551: errormsg(WHERE,ERR_OPEN,str,O_RDWR);
552: return(0L);
553: }
1.1.1.2 ! root 554: read(dsts,&update32_t,4); /* Last updated */
! 555: update_t=update32_t;
1.1 root 556: read(dsts,&stats.logons,4); /* Total number of logons on system */
557: close(dsts);
558: now=time(NULL);
1.1.1.2 ! root 559: now32=now;
1.1 root 560: if(update_t>now+(24L*60L*60L)) /* More than a day in the future? */
561: errormsg(WHERE,ERR_CHK,"Daily stats time stamp",update_t);
562: if(localtime_r(&update_t,&update_tm)==NULL)
563: return(0);
564: if(localtime_r(&now,&tm)==NULL)
565: return(0);
566: if((tm.tm_mday>update_tm.tm_mday && tm.tm_mon==update_tm.tm_mon)
567: || tm.tm_mon>update_tm.tm_mon || tm.tm_year>update_tm.tm_year) {
568:
1.1.1.2 ! root 569: sprintf(str,"New Day - Prev: %s ",timestr(update_t));
1.1 root 570: logentry("!=",str);
571:
572: sys_status|=SS_DAILY; /* New Day !!! */
573: sprintf(str,"%slogon.lst",cfg.data_dir); /* Truncate logon list */
574: if((dsts=nopen(str,O_TRUNC|O_CREAT|O_WRONLY))==-1) {
575: errormsg(WHERE,ERR_OPEN,str,O_TRUNC|O_CREAT|O_WRONLY);
576: return(0L);
577: }
578: close(dsts);
579: for(i=0;i<=cfg.sys_nodes;i++) {
580: if(i) { /* updating a node */
581: getnodedat(i,&node,1);
582: node.misc|=NODE_EVENT;
583: putnodedat(i,&node);
584: }
585: sprintf(str,"%sdsts.dab",i ? cfg.node_path[i-1] : cfg.ctrl_dir);
586: if((dsts=nopen(str,O_RDWR))==-1) /* node doesn't have stats yet */
587: continue;
588: sprintf(str,"%scsts.dab",i ? cfg.node_path[i-1] : cfg.ctrl_dir);
589: if((csts=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
590: close(dsts);
591: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
592: continue;
593: }
594: lseek(dsts,8L,SEEK_SET); /* Skip time and logons */
1.1.1.2 ! root 595: write(csts,&now32,4);
1.1 root 596: read(dsts,&stats.ltoday,4);
597: write(csts,&stats.ltoday,4);
598: lseek(dsts,4L,SEEK_CUR); /* Skip total time on */
599: read(dsts,&stats.ttoday,4);
600: write(csts,&stats.ttoday,4);
601: read(dsts,&stats.uls,4);
602: write(csts,&stats.uls,4);
603: read(dsts,&stats.ulb,4);
604: write(csts,&stats.ulb,4);
605: read(dsts,&stats.dls,4);
606: write(csts,&stats.dls,4);
607: read(dsts,&stats.dlb,4);
608: write(csts,&stats.dlb,4);
609: read(dsts,&stats.ptoday,4);
610: write(csts,&stats.ptoday,4);
611: read(dsts,&stats.etoday,4);
612: write(csts,&stats.etoday,4);
613: read(dsts,&stats.ftoday,4);
614: write(csts,&stats.ftoday,4);
615: close(csts);
616: lseek(dsts,0L,SEEK_SET); /* Go back to beginning */
1.1.1.2 ! root 617: write(dsts,&now32,4); /* Update time stamp */
1.1 root 618: lseek(dsts,4L,SEEK_CUR); /* Skip total logons */
619: stats.ltoday=0;
620: write(dsts,&stats.ltoday,4); /* Logons today to 0 */
621: lseek(dsts,4L,SEEK_CUR); /* Skip total time on */
622: stats.ttoday=0; /* Set all other today variables to 0 */
623: write(dsts,&stats.ttoday,4); /* Time on today to 0 */
624: write(dsts,&stats.ttoday,4); /* Uploads today to 0 */
625: write(dsts,&stats.ttoday,4); /* U/L Bytes today */
626: write(dsts,&stats.ttoday,4); /* Download today */
627: write(dsts,&stats.ttoday,4); /* Download bytes */
628: write(dsts,&stats.ttoday,4); /* Posts today */
629: write(dsts,&stats.ttoday,4); /* Emails today */
630: write(dsts,&stats.ttoday,4); /* Feedback today */
631: write(dsts,&stats.ttoday,2); /* New users Today */
632: close(dsts);
633: }
634: }
635:
636: if(cfg.node_num==0) /* called from event_thread() */
637: return(0);
638:
639: if(thisnode.status==NODE_QUIET) /* Quiet users aren't counted */
640: return(0);
641:
642: if(REALSYSOP && !(cfg.sys_misc&SM_SYSSTAT))
643: return(0);
644:
645: for(i=0;i<2;i++) {
646: sprintf(str,"%sdsts.dab",i ? cfg.ctrl_dir : cfg.node_dir);
647: if((dsts=nopen(str,O_RDWR))==-1) {
648: errormsg(WHERE,ERR_OPEN,str,O_RDWR);
649: return(0L);
650: }
651: lseek(dsts,4L,SEEK_SET); /* Skip time stamp */
652: read(dsts,&stats.logons,4);
653: read(dsts,&stats.ltoday,4);
654: stats.logons++;
655: stats.ltoday++;
656: lseek(dsts,4L,SEEK_SET); /* Rewind back and overwrite */
657: write(dsts,&stats.logons,4);
658: write(dsts,&stats.ltoday,4);
659: close(dsts);
660: }
661: return(stats.logons);
662: }
663:
664:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.