|
|
1.1 ! root 1: /* SMBACTIV.C */ ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: #include <share.h> ! 6: #include "sbbs.h" ! 7: ! 8: #define SMBACTIV_VER "1.01" ! 9: ! 10: typedef struct { ! 11: ulong read; ! 12: ulong firstmsg; ! 13: } sub_status_t; ! 14: ! 15: smb_t smb; ! 16: ! 17: ulong first_msg() ! 18: { ! 19: smbmsg_t msg; ! 20: ! 21: msg.offset=0; ! 22: msg.hdr.number=0; ! 23: if(smb_getmsgidx(&smb,&msg)) /* Get first message index */ ! 24: return(0); ! 25: return(msg.idx.number); ! 26: } ! 27: /****************************************************************************/ ! 28: /* Puts a backslash on path strings */ ! 29: /****************************************************************************/ ! 30: void backslash(char *str) ! 31: { ! 32: int i; ! 33: ! 34: i=strlen(str); ! 35: if(i && str[i-1]!='\\') { ! 36: str[i]='\\'; str[i+1]=0; } ! 37: } ! 38: long lputs(char FAR16 *str) ! 39: { ! 40: char tmp[256]; ! 41: int i,j,k; ! 42: ! 43: j=strlen(str); ! 44: for(i=k=0;i<j;i++) /* remove CRs */ ! 45: if(str[i]==CR && str[i+1]==LF) ! 46: continue; ! 47: else ! 48: tmp[k++]=str[i]; ! 49: tmp[k]=0; ! 50: return(fputs(tmp,stderr)); ! 51: } ! 52: /****************************************************************************/ ! 53: /* Network open function. Opens all files DENYALL and retries LOOP_NOPEN */ ! 54: /* number of times if the attempted file is already open or denying access */ ! 55: /* for some other reason. All files are opened in BINARY mode. */ ! 56: /****************************************************************************/ ! 57: int nopen(char *str, int access) ! 58: { ! 59: char logstr[256]; ! 60: int file,share,count=0; ! 61: ! 62: if(access==O_RDONLY) share=SH_DENYWR; ! 63: else share=SH_DENYRW; ! 64: while(((file=sopen(str,O_BINARY|access,share,S_IWRITE))==-1) ! 65: && errno==EACCES && count++<LOOP_NOPEN); ! 66: if(file==-1 && errno==EACCES) ! 67: lputs("\7\r\nNOPEN: ACCESS DENIED\r\n\7"); ! 68: return(file); ! 69: } ! 70: ! 71: /****************************************************************************/ ! 72: /* This function performs an nopen, but returns a file stream with a buffer */ ! 73: /* allocated. */ ! 74: /****************************************************************************/ ! 75: FILE *fnopen(int *file, char *str, int access) ! 76: { ! 77: char mode[128]; ! 78: FILE *stream; ! 79: ! 80: if(access&O_WRONLY) access|=O_RDWR; /* fdopen can't open WRONLY */ ! 81: ! 82: if(((*file)=nopen(str,access))==-1) ! 83: return(NULL); ! 84: ! 85: if(access&O_APPEND) { ! 86: if(access&(O_RDONLY|O_RDWR)) ! 87: strcpy(mode,"a+"); ! 88: else ! 89: strcpy(mode,"a"); } ! 90: else { ! 91: if(access&(O_WRONLY|O_RDWR)) ! 92: strcpy(mode,"r+"); ! 93: else ! 94: strcpy(mode,"r"); } ! 95: stream=fdopen((*file),mode); ! 96: if(stream==NULL) { ! 97: close(*file); ! 98: return(NULL); } ! 99: setvbuf(stream,NULL,_IOFBF,16*1024); ! 100: return(stream); ! 101: } ! 102: ! 103: /****************************************************************************/ ! 104: /* Truncates white-space chars off end of 'str' and terminates at first tab */ ! 105: /****************************************************************************/ ! 106: void truncsp(char *str) ! 107: { ! 108: char c; ! 109: ! 110: str[strcspn(str,"\t")]=0; ! 111: c=strlen(str); ! 112: while(c && str[c-1]<=SP) c--; ! 113: str[c]=0; ! 114: } ! 115: ! 116: /****************************************************************************/ ! 117: /* Performs printf() through local assembly routines */ ! 118: /* Called from everywhere */ ! 119: /****************************************************************************/ ! 120: int lprintf(char *fmat, ...) ! 121: { ! 122: va_list argptr; ! 123: char sbuf[256]; ! 124: int chcount; ! 125: ! 126: va_start(argptr,fmat); ! 127: chcount=vsprintf(sbuf,fmat,argptr); ! 128: va_end(argptr); ! 129: lputs(sbuf); ! 130: return(chcount); ! 131: } ! 132: void bail(int code) ! 133: { ! 134: exit(code); ! 135: } ! 136: ! 137: void main(int argc, char **argv) ! 138: { ! 139: char str[256],*p; ! 140: int i,j,file; ! 141: ulong l,length,max_users=0xffffffff; ! 142: sub_status_t *sub_status; ! 143: read_cfg_text_t txt; ! 144: struct find_t f; ! 145: FILE *stream; ! 146: ! 147: _fmode=O_BINARY; ! 148: txt.openerr="\7\r\nError opening %s for read.\r\n"; ! 149: txt.reading="\r\nReading %s..."; ! 150: txt.readit="\rRead %s "; ! 151: txt.allocerr="\7\r\nError allocating %u bytes of memory\r\n"; ! 152: txt.error="\7\r\nERROR: Offset %lu in %s\r\n\r\n"; ! 153: ! 154: fprintf(stderr,"\nSMBACTIV Version %s (%s) - Synchronet Message Base Activity " ! 155: "Monitor\n" ! 156: ,SMBACTIV_VER ! 157: #if defined(__OS2__) ! 158: ,"OS/2" ! 159: #elif defined(__NT__) ! 160: ,"Win32" ! 161: #elif defined(__DOS4G__) ! 162: ,"DOS4G" ! 163: #elif defined(__FLAT__) ! 164: ,"DOS32" ! 165: #else ! 166: ,"DOS16" ! 167: #endif ! 168: ); ! 169: ! 170: if(argc>1 && (!stricmp(argv[1],"/?") || !stricmp(argv[1],"?"))) { ! 171: lprintf("\nusage: SMBACTIV [max_users]\n\n"); ! 172: lprintf("max_users = limit output to subs read by this many users " ! 173: "or less\n"); ! 174: exit(0); } ! 175: ! 176: if(argc>1) ! 177: max_users=atol(argv[1]); ! 178: ! 179: if(!node_dir[0]) { ! 180: p=getenv("SBBSNODE"); ! 181: if(p==NULL) { ! 182: printf("\7\nSBBSNODE environment variable not set.\n"); ! 183: exit(1); } ! 184: strcpy(node_dir,p); } ! 185: ! 186: strupr(node_dir); ! 187: ! 188: if(node_dir[strlen(node_dir)-1]!='\\') ! 189: strcat(node_dir,"\\"); ! 190: ! 191: read_node_cfg(txt); ! 192: if(ctrl_dir[0]=='.') { /* Relative path */ ! 193: strcpy(str,ctrl_dir); ! 194: sprintf(ctrl_dir,"%s%s",node_dir,str); ! 195: if(_fullpath(str,ctrl_dir,40)) ! 196: strcpy(ctrl_dir,str); } ! 197: backslash(ctrl_dir); ! 198: ! 199: read_main_cfg(txt); ! 200: if(data_dir[0]=='.') { /* Relative path */ ! 201: strcpy(str,data_dir); ! 202: sprintf(data_dir,"%s%s",node_dir,str); ! 203: if(_fullpath(str,data_dir,40)) ! 204: strcpy(data_dir,str); } ! 205: backslash(data_dir); ! 206: if(text_dir[0]=='.') { /* Relative path */ ! 207: strcpy(str,text_dir); ! 208: sprintf(text_dir,"%s%s",node_dir,str); ! 209: if(_fullpath(str,text_dir,40)) ! 210: strcpy(text_dir,str); } ! 211: backslash(text_dir); ! 212: read_msgs_cfg(txt); ! 213: ! 214: if((sub_status=(sub_status_t *)MALLOC ! 215: (total_subs*sizeof(sub_status_t)))==NULL) { ! 216: printf("ERROR Allocating memory for sub_status\r\n"); ! 217: exit(1); } ! 218: ! 219: lprintf("\nReading sub-board "); ! 220: for(i=0;i<total_subs;i++) { ! 221: lprintf("%5d of %-5d\b\b\b\b\b\b\b\b\b\b\b\b\b\b",i+1,total_subs); ! 222: sprintf(smb.file,"%s%s",sub[i]->data_dir,sub[i]->code); ! 223: if((j=smb_open(&smb))!=0) { ! 224: lprintf("Error %d opening %s\r\n",j,smb.file); ! 225: sub_status[i].read=0; ! 226: sub_status[i].firstmsg=0L; ! 227: continue; } ! 228: sub_status[i].read=0; ! 229: sub_status[i].firstmsg=first_msg(); ! 230: smb_close(&smb); } ! 231: ! 232: sprintf(str,"%sUSER\\PTRS\\*.IXB",data_dir); ! 233: if(_dos_findfirst(str,0,&f)) { ! 234: lprintf("Unable to find any user pointer files.\n"); ! 235: FREE(sub_status); ! 236: exit(1); } ! 237: ! 238: j=0; ! 239: lprintf("\nComparing user pointers "); ! 240: while(1) { ! 241: lprintf("%-5d\b\b\b\b\b",++j); ! 242: sprintf(str,"%sUSER\\PTRS\\%s",data_dir,f.name); ! 243: if((file=nopen(str,O_RDONLY))==-1) { ! 244: if(_dos_findnext(&f)) ! 245: break; ! 246: continue; } ! 247: length=filelength(file); ! 248: for(i=0;i<total_subs;i++) { ! 249: if(sub_status[i].read>max_users) ! 250: continue; ! 251: if(length<(sub[i]->ptridx+1)*10L) ! 252: continue; ! 253: else { ! 254: lseek(file,((long)sub[i]->ptridx*10L)+4L,SEEK_SET); ! 255: read(file,&l,4); } ! 256: if(l>sub_status[i].firstmsg) ! 257: sub_status[i].read++; } ! 258: close(file); ! 259: if(_dos_findnext(&f)) ! 260: break; } ! 261: ! 262: printf("NumUsers Sub-board\n"); ! 263: printf("-------- -------------------------------------------------" ! 264: "-----------\n"); ! 265: for(i=0;i<total_subs;i++) { ! 266: if(sub_status[i].read>max_users) ! 267: continue; ! 268: printf("%8lu %-*s %-*s\n" ! 269: ,sub_status[i].read ! 270: ,LEN_GSNAME,grp[sub[i]->grp]->sname ! 271: ,LEN_SLNAME,sub[i]->lname); } ! 272: ! 273: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.