00001 #include <string.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <time.h>
00005 #include "queue.h"
00006
00007 #define NBANISH 0x0100
00008 #define NHOLD 0x0004
00009 #define NVACATION 0x0002
00010 #define GNUPLOT_DAT
00011 #define MAILSTAT_WRITE
00012 #define NZERO(x) ((x)?(x):1)
00013
00014 int main(void);
00015 char *sfgets(char *, int, FILE *);
00016 void *oalloc(size_t);
00017
00018 int email=0, email_valid=0;
00019 int nicks=0, usernicks=0;
00020 int urls=0;
00021 int access=0;
00022 int held=0;
00023
00024 typedef struct emaillist_struct EmailList;
00025
00026 struct emaillist_struct {
00027 char email[128];
00028 LIST_ENTRY(emaillist_struct) emails;
00029 };
00030
00031 typedef struct
00032 {
00033 char *current;
00034 char *start;
00035 } ParseState;
00036
00037 typedef struct urllist_struct UrlList;
00038
00039 struct urllist_struct {
00040 char url[128];
00041 LIST_ENTRY(urllist_struct) urls;
00042 };
00043
00044 typedef struct regnicklist RegNickList;
00045
00046 struct regnicklist {
00047 char nick[33];
00048 unsigned long reged;
00049 char host[128];
00050 char user[128];
00051 char realname[128];
00052 u_int32_t flags;
00053 LIST_ENTRY(regnicklist) users;
00054 };
00055
00056 char *get_arg(ParseState *);
00057
00058 LIST_HEAD(,regnicklist) firstUser;
00059 LIST_HEAD(,regnicklist) heldNick;
00060 LIST_HEAD(,urllist_struct) firstUrl;
00061 LIST_HEAD(,emaillist_struct) firstEmail;
00062
00063 int
00064 main(void)
00065 {
00066 RegNickList *read;
00067 RegNickList *read2;
00068 u_long totalnicklen=0;
00069 u_long totalurllen=0;
00070 u_long totalemail=0;
00071 u_long totalrn=0;
00072 u_long totalhn=0;
00073 u_long totalun=0;
00074 time_t workingtime;
00075 time_t dayssince;
00076 time_t CTime;
00077 u_int longestnick=0;
00078 u_int longesturl=0;
00079 u_int longestemail=0;
00080 u_int longestrn=0;
00081 u_int longesthn=0;
00082 u_int longestun=0;
00083 u_int averagenick=0;
00084 u_int averageurl=0;
00085 u_int averageemail=0;
00086 u_int averagern=0;
00087 u_int averagehn=0;
00088 u_int averageun=0;
00089 u_int thenicks[33];
00090 u_int thedays[50];
00091 UrlList *url;
00092 EmailList *email2;
00093 ParseState *state = (ParseState *)oalloc(sizeof(ParseState));
00094 char *command;
00095 char line[1024];
00096 FILE *fp;
00097 int done = 0;
00098 int a;
00099
00100 for (a = 0; a < 33; a++)
00101 thenicks[a] = 0;
00102
00103 for(a = 0; a < 50; a++)
00104 thedays[a] = 0;
00105
00106 fp = fopen("nickserv/nickserv.db", "r");
00107 if(!fp)
00108 return -1;
00109 while(!done) {
00110 if (!(sfgets(line, 1024, fp))) {
00111 done = 1;
00112 break;
00113 }
00114
00115 state->current = state->start = line;
00116 command = get_arg(state);
00117 if(!strcmp(command, "nick")) {
00118 read = (RegNickList *)oalloc(sizeof(RegNickList));
00119 LIST_INSERT_HEAD(&firstUser, read, users);
00120 strcpy(read->nick, get_arg(state));
00121 strcpy(read->user, get_arg(state));
00122 strcpy(read->host, get_arg(state));
00123 get_arg(state);
00124 read->reged = atol(get_arg(state));
00125 get_arg(state);
00126 read->flags = atoi(get_arg(state));
00127 strcpy(read->realname, state->current);
00128 if (!(read->flags & (NBANISH|NHOLD)))
00129 usernicks++;
00130 nicks++;
00131 }
00132 else if(!strcmp(command, "url")) {
00133 url = (UrlList *)oalloc(sizeof(UrlList));
00134 LIST_INSERT_HEAD(&firstUrl, url, urls);
00135 get_arg(state);
00136 strncpy(url->url, get_arg(state), 128);
00137 urls++;
00138 }
00139 else if(!strcmp(command, "access")) {
00140 access++;
00141 }
00142 else if(!strcmp(command, "email")) {
00143 if (!(read->flags & (NBANISH|NHOLD))) {
00144 email2 = (EmailList *)oalloc(sizeof(EmailList));
00145 LIST_INSERT_HEAD(&firstEmail, email2, emails);
00146 get_arg(state);
00147 strcpy(email2->email, get_arg(state));
00148 email++;
00149 if (strncmp(email2->email, "(none)", 6))
00150 email_valid++;
00151 }
00152 }
00153 else if(!strcmp(command, "done"))
00154 done = 1;
00155 }
00156
00157 fclose(fp);
00158 CTime = time(NULL);
00159 printf("Nicks: %i\nUrls: %i\nAccess List Entries: %i\nEmails: %i\n", nicks, urls, access, email);
00160 for(read = firstUser.lh_first;read;read = read->users.le_next) {
00161 if(read->flags & NBANISH || read->flags & NHOLD) {
00162 read2 = (RegNickList *)oalloc(sizeof(RegNickList));
00163 LIST_INSERT_HEAD(&heldNick, read2, users);
00164 strcpy(read2->nick, read->nick);
00165 held++;
00166 }
00167 else {
00168 if(read->flags & NVACATION)
00169 workingtime = (CTime - read->reged)/2;
00170 else
00171 workingtime=CTime - read->reged;
00172 dayssince = ((60*60*24*25) - workingtime) / (60*60*24);
00173 thedays[dayssince]++;
00174 }
00175 thenicks[strlen(read->nick) - 1]++;
00176 totalnicklen = totalnicklen + strlen(read->nick);
00177 if (strlen(read->nick) > longestnick)
00178 longestnick = strlen(read->nick);
00179 if (strlen(read->realname) > longestrn)
00180 longestrn = strlen(read->realname);
00181 totalrn = totalrn + strlen(read->realname);
00182 if (strlen(read->host) > longesthn)
00183 longesthn = strlen(read->host);
00184 totalhn = totalhn + strlen(read->host);
00185 if (strlen(read->user) > longestun)
00186 longestun = strlen(read->user);
00187 totalun = totalun + strlen(read->user);
00188 }
00189
00190 for(email2 = firstEmail.lh_first;email2;email2 = email2->emails.le_next) {
00191 if(strlen(email2->email) > longestemail)
00192 longestemail = strlen(email2->email);
00193 totalemail = totalemail + strlen(email2->email);
00194 }
00195 for(url = firstUrl.lh_first;url;url = url->urls.le_next) {
00196 totalurllen = totalurllen + strlen(url->url);
00197 if (strlen(url->url) > longesturl)
00198 longesturl = strlen(url->url);
00199 }
00200
00201 averagenick = totalnicklen / nicks;
00202 averageurl = totalurllen / urls;
00203 averageemail = totalemail / email;
00204 averagern = totalrn / nicks;
00205 averagehn = totalhn / nicks;
00206 averageun = totalun / nicks;
00207 printf("E-mail addies : %5i * Elected to set none : %5i\n", email_valid, email - email_valid);
00208 printf("Neglected e-mail field : %5i\n", nicks - email);
00209 printf("Largest Nick Length : %5i * Average Nick Length : %5i\n", longestnick, averagenick);
00210 printf("Largest URL Length : %5i * Average URL Length : %5i\n", longesturl, averageurl);
00211 printf("Largest Email Length : %5i * Average Email Length : %5i\n", longestemail, averageemail);
00212 printf("Largest Realname Length: %5i * Average Realname Length: %5i\n", longestrn, averagern);
00213 printf("Largest Hostname Length: %5i * Average Hostname Length: %5i\n", longesthn, averagehn);
00214 printf("Largest Username Length: %5i * Average Username Length: %5i\n", longestun, averageun);
00215 printf("Nick Lengths (chars):\n");
00216 printf("( 1) = %3i * ( 2) = %3i * ( 3) = %3i * ( 4) = %3i * ( 5) = %3i\n", thenicks[0], thenicks[1], thenicks[2], thenicks[3], thenicks[4]);
00217 printf("( 6) = %3i * ( 7) = %3i * ( 8) = %3i * ( 9) = %3i * (10) = %3i\n", thenicks[5], thenicks[6], thenicks[7], thenicks[8], thenicks[9]);
00218 printf("(11) = %3i * (12) = %3i * (13) = %3i * (14) = %3i * (15) = %3i\n", thenicks[10], thenicks[11], thenicks[12], thenicks[13], thenicks[14]);
00219 printf("(16) = %3i * (17) = %3i\n", thenicks[15], thenicks[16]);
00220 printf("Days until expire (days):\n");
00221 printf("( 1) = %3i * ( 2) = %3i * ( 3) = %3i * ( 4) = %3i * ( 5) = %3i\n", thedays[0], thedays[1], thedays[2], thedays[3], thedays[4]);
00222 printf("( 6) = %3i * ( 7) = %3i * ( 8) = %3i * ( 9) = %3i * (10) = %3i\n", thedays[5], thedays[6], thedays[17], thedays[8], thedays[9]);
00223 printf("(11) = %3i * (12) = %3i * (13) = %3i * (14) = %3i * (15) = %3i\n", thedays[10], thedays[11], thedays[12], thedays[13], thedays[14]);
00224 printf("(16) = %3i * (17) = %3i * (18) = %3i * (19) = %3i * (20) = %3i\n", thedays[15], thedays[16], thedays[17], thedays[18], thedays[19]);
00225 printf("(21) = %3i * (22) = %3i * (23) = %3i * (24) = %3i * (25) = %3i\n", thedays[20], thedays[21], thedays[22], thedays[23], thedays[24]);
00226 printf("Held/Banished nicks:");
00227 for(read = heldNick.lh_first;read;read = read->users.le_next)
00228 printf(" %s", read->nick);
00229 printf("\n");
00230
00231 #ifdef MAILSTAT_WRITE
00232 if (nicks && (fp = fopen("emailstats", "a")))
00233 {
00234
00235 #define PC(x, y) (((100*(x))/y) + (((100*(x))%y > (y/2)) ? 1 : 0))
00236 fprintf(fp, "[%ld]\n", CTime);
00237 fprintf(fp, "E-mail addies : %5i(%3d%%) * Elected to set none : %5i(%3d%%)\n", email_valid, PC(email_valid, usernicks), email - email_valid, PC(email - email_valid, usernicks));
00238 fprintf(fp, "Neglected e-mail field : %5i(%3d%%) * Nicks : %5i/%5i\n", usernicks - email, PC(usernicks - email, usernicks), usernicks, nicks - usernicks);
00239 fflush(fp);
00240 fclose(fp);
00241 }
00242 #endif
00243
00244 #ifdef GNUPLOT_DAT
00245 fp = fopen("NickExpire.dat", "w");
00246 for (a = 0; a < 25 ; a++) {
00247 fprintf(fp, "%d %d\n", a+1, thedays[a]);
00248 fflush(fp);
00249 }
00250 fclose(fp);
00251 fp = fopen("NickLength.dat", "w");
00252 for(a = 0; a < 17; a++) {
00253 fprintf(fp, "%d %d\n", a+1, thenicks[a]);
00254 fflush(fp);
00255 }
00256 fclose(fp);
00257 #endif
00258 return 0;
00259 }
00260
00261 char *
00262 sfgets(char *str, int len, FILE *fp)
00263 {
00264 if(!fgets(str, len, fp))
00265 return NULL;
00266 else {
00267 if(str[0])
00268 str[strlen(str) - 1] = 0;
00269 return str;
00270 }
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280 void *oalloc(size_t size)
00281 {
00282 void *alloctmp = 0;
00283
00284 if (size < 1) {
00285 printf("oalloc: Error, requested size is less than 1");
00286 exit(1);
00287 }
00288
00289 alloctmp = malloc(size);
00290
00291 if (alloctmp == NULL) {
00292 printf("oalloc: Error allocating memory, terminating services\n");
00293 exit(1);
00294 }
00295
00296 memset(alloctmp, 0, size);
00297
00298 return alloctmp;
00299 }
00300
00301 char *
00302 get_arg (ParseState * state)
00303 {
00304 state->current = strsep (&state->start, " ");
00305 return state->current;
00306 }
00307
00308 char *
00309 curr_arg (ParseState * state)
00310 {
00311 return state->current;
00312 }
00313