00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "module.h"
00017
00018
00019
00020 int do_stats(User * u);
00021 void get_operserv_stats(long *nrec, long *memuse);
00022 void myOperServHelp(User * u);
00023
00030 int AnopeInit(int argc, char **argv)
00031 {
00032 Command *c;
00033
00034 moduleAddAuthor("Anope");
00035 moduleAddVersion("$Id: os_stats.c 1265 2007-08-26 15:33:06Z geniusdex $");
00036 moduleSetType(CORE);
00037
00038 c = createCommand("STATS", do_stats, NULL, OPER_HELP_STATS,
00039 -1, -1, -1, -1);
00040 moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00041 c = createCommand("UPTIME", do_stats, NULL,
00042 OPER_HELP_STATS, -1, -1, -1, -1);
00043 moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00044
00045 moduleSetOperHelp(myOperServHelp);
00046
00047 return MOD_CONT;
00048 }
00049
00053 void AnopeFini(void)
00054 {
00055
00056 }
00057
00058
00063 void myOperServHelp(User * u)
00064 {
00065 notice_lang(s_OperServ, u, OPER_HELP_CMD_STATS);
00066 }
00067
00073 int stats_count_servers(Server * s)
00074 {
00075 int count = 0;
00076
00077 while (s) {
00078 count++;
00079 if (s->links)
00080 count += stats_count_servers(s->links);
00081 s = s->next;
00082 }
00083
00084 return count;
00085 }
00086
00092 int do_stats(User * u)
00093 {
00094 time_t uptime = time(NULL) - start_time;
00095 char *extra = strtok(NULL, "");
00096 int days = uptime / 86400, hours = (uptime / 3600) % 24,
00097 mins = (uptime / 60) % 60, secs = uptime % 60;
00098 struct tm *tm;
00099 char timebuf[64];
00100 char buf[512];
00101 int buflen;
00102 int i;
00103
00104 if (extra && stricmp(extra, "ALL") != 0) {
00105 if (stricmp(extra, "AKILL") == 0) {
00106 int timeout;
00107
00108 notice_lang(s_OperServ, u, OPER_STATS_AKILL_COUNT,
00109 akills.count);
00110 timeout = AutokillExpiry + 59;
00111 if (timeout >= 172800)
00112 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_DAYS,
00113 timeout / 86400);
00114 else if (timeout >= 86400)
00115 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_DAY);
00116 else if (timeout >= 7200)
00117 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_HOURS,
00118 timeout / 3600);
00119 else if (timeout >= 3600)
00120 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_HOUR);
00121 else if (timeout >= 120)
00122 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_MINS,
00123 timeout / 60);
00124 else if (timeout >= 60)
00125 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_MIN);
00126 else
00127 notice_lang(s_OperServ, u, OPER_STATS_AKILL_EXPIRE_NONE);
00128 if (ircd->sgline) {
00129
00130 notice_lang(s_OperServ, u, OPER_STATS_SGLINE_COUNT,
00131 sglines.count);
00132 timeout = SGLineExpiry + 59;
00133 if (timeout >= 172800)
00134 notice_lang(s_OperServ, u,
00135 OPER_STATS_SGLINE_EXPIRE_DAYS,
00136 timeout / 86400);
00137 else if (timeout >= 86400)
00138 notice_lang(s_OperServ, u,
00139 OPER_STATS_SGLINE_EXPIRE_DAY);
00140 else if (timeout >= 7200)
00141 notice_lang(s_OperServ, u,
00142 OPER_STATS_SGLINE_EXPIRE_HOURS,
00143 timeout / 3600);
00144 else if (timeout >= 3600)
00145 notice_lang(s_OperServ, u,
00146 OPER_STATS_SGLINE_EXPIRE_HOUR);
00147 else if (timeout >= 120)
00148 notice_lang(s_OperServ, u,
00149 OPER_STATS_SGLINE_EXPIRE_MINS,
00150 timeout / 60);
00151 else if (timeout >= 60)
00152 notice_lang(s_OperServ, u,
00153 OPER_STATS_SGLINE_EXPIRE_MIN);
00154 else
00155 notice_lang(s_OperServ, u,
00156 OPER_STATS_SGLINE_EXPIRE_NONE);
00157 }
00158 if (ircd->sqline) {
00159
00160 notice_lang(s_OperServ, u, OPER_STATS_SQLINE_COUNT,
00161 sqlines.count);
00162 timeout = SQLineExpiry + 59;
00163 if (timeout >= 172800)
00164 notice_lang(s_OperServ, u,
00165 OPER_STATS_SQLINE_EXPIRE_DAYS,
00166 timeout / 86400);
00167 else if (timeout >= 86400)
00168 notice_lang(s_OperServ, u,
00169 OPER_STATS_SQLINE_EXPIRE_DAY);
00170 else if (timeout >= 7200)
00171 notice_lang(s_OperServ, u,
00172 OPER_STATS_SQLINE_EXPIRE_HOURS,
00173 timeout / 3600);
00174 else if (timeout >= 3600)
00175 notice_lang(s_OperServ, u,
00176 OPER_STATS_SQLINE_EXPIRE_HOUR);
00177 else if (timeout >= 120)
00178 notice_lang(s_OperServ, u,
00179 OPER_STATS_SQLINE_EXPIRE_MINS,
00180 timeout / 60);
00181 else if (timeout >= 60)
00182 notice_lang(s_OperServ, u,
00183 OPER_STATS_SQLINE_EXPIRE_MIN);
00184 else
00185 notice_lang(s_OperServ, u,
00186 OPER_STATS_SQLINE_EXPIRE_NONE);
00187 }
00188 if (ircd->szline) {
00189
00190 notice_lang(s_OperServ, u, OPER_STATS_SZLINE_COUNT,
00191 szlines.count);
00192 timeout = SZLineExpiry + 59;
00193 if (timeout >= 172800)
00194 notice_lang(s_OperServ, u,
00195 OPER_STATS_SZLINE_EXPIRE_DAYS,
00196 timeout / 86400);
00197 else if (timeout >= 86400)
00198 notice_lang(s_OperServ, u,
00199 OPER_STATS_SZLINE_EXPIRE_DAY);
00200 else if (timeout >= 7200)
00201 notice_lang(s_OperServ, u,
00202 OPER_STATS_SZLINE_EXPIRE_HOURS,
00203 timeout / 3600);
00204 else if (timeout >= 3600)
00205 notice_lang(s_OperServ, u,
00206 OPER_STATS_SZLINE_EXPIRE_HOUR);
00207 else if (timeout >= 120)
00208 notice_lang(s_OperServ, u,
00209 OPER_STATS_SZLINE_EXPIRE_MINS,
00210 timeout / 60);
00211 else if (timeout >= 60)
00212 notice_lang(s_OperServ, u,
00213 OPER_STATS_SZLINE_EXPIRE_MIN);
00214 else
00215 notice_lang(s_OperServ, u,
00216 OPER_STATS_SZLINE_EXPIRE_NONE);
00217 }
00218 return MOD_CONT;
00219 } else if (!stricmp(extra, "RESET")) {
00220 if (is_services_admin(u)) {
00221 maxusercnt = usercnt;
00222 notice_lang(s_OperServ, u, OPER_STATS_RESET);
00223 } else {
00224 notice_lang(s_OperServ, u, PERMISSION_DENIED);
00225 }
00226 return MOD_CONT;
00227 } else if (stricmp(extra, "MEMORY") && stricmp(extra, "UPLINK")) {
00228 notice_lang(s_OperServ, u, OPER_STATS_UNKNOWN_OPTION, extra);
00229 }
00230 }
00231
00232 if (!extra || ((stricmp(extra, "MEMORY") != 0)
00233 && (stricmp(extra, "UPLINK") != 0))) {
00234 notice_lang(s_OperServ, u, OPER_STATS_CURRENT_USERS, usercnt,
00235 opcnt);
00236 tm = localtime(&maxusertime);
00237 strftime_lang(timebuf, sizeof(timebuf), u,
00238 STRFTIME_DATE_TIME_FORMAT, tm);
00239 notice_lang(s_OperServ, u, OPER_STATS_MAX_USERS, maxusercnt,
00240 timebuf);
00241 if (days > 1) {
00242 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_DHMS,
00243 days, hours, mins, secs);
00244 } else if (days == 1) {
00245 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1DHMS,
00246 days, hours, mins, secs);
00247 } else {
00248 if (hours > 1) {
00249 if (mins != 1) {
00250 if (secs != 1) {
00251 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_HMS,
00252 hours, mins, secs);
00253 } else {
00254 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_HM1S,
00255 hours, mins, secs);
00256 }
00257 } else {
00258 if (secs != 1) {
00259 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_H1MS,
00260 hours, mins, secs);
00261 } else {
00262 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_H1M1S,
00263 hours, mins, secs);
00264 }
00265 }
00266 } else if (hours == 1) {
00267 if (mins != 1) {
00268 if (secs != 1) {
00269 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1HMS,
00270 hours, mins, secs);
00271 } else {
00272 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1HM1S,
00273 hours, mins, secs);
00274 }
00275 } else {
00276 if (secs != 1) {
00277 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1H1MS,
00278 hours, mins, secs);
00279 } else {
00280 notice_lang(s_OperServ, u,
00281 OPER_STATS_UPTIME_1H1M1S, hours, mins,
00282 secs);
00283 }
00284 }
00285 } else {
00286 if (mins != 1) {
00287 if (secs != 1) {
00288 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_MS,
00289 mins, secs);
00290 } else {
00291 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_M1S,
00292 mins, secs);
00293 }
00294 } else {
00295 if (secs != 1) {
00296 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1MS,
00297 mins, secs);
00298 } else {
00299 notice_lang(s_OperServ, u, OPER_STATS_UPTIME_1M1S,
00300 mins, secs);
00301 }
00302 }
00303 }
00304 }
00305 }
00306
00307 if (extra && ((stricmp(extra, "ALL") == 0)
00308 || (stricmp(extra, "UPLINK") == 0))
00309 && is_services_admin(u)) {
00310 buf[0] = '\0';
00311 buflen = 511;
00312 for (i = 0; capab_info[i].token; i++) {
00313 if (uplink_capab & capab_info[i].flag) {
00314 strncat(buf, " ", buflen);
00315 buflen--;
00316 strncat(buf, capab_info[i].token, buflen);
00317 buflen -= strlen(capab_info[i].token);
00318
00319 if (capab_info[i].flag == CAPAB_CHANMODE) {
00320 strncat(buf, "=", buflen);
00321 buflen--;
00322 strncat(buf, ircd->chanmodes, buflen);
00323 buflen -= strlen(ircd->chanmodes);
00324 }
00325 if (capab_info[i].flag == CAPAB_NICKCHARS) {
00326 strncat(buf, "=", buflen);
00327 buflen--;
00328 if (ircd->nickchars) {
00329 strncat(buf, ircd->nickchars, buflen);
00330 buflen -= strlen(ircd->nickchars);
00331 }
00332 }
00333 }
00334 }
00335 notice_lang(s_OperServ, u, OPER_STATS_UPLINK_SERVER,
00336 serv_uplink->name);
00337 notice_lang(s_OperServ, u, OPER_STATS_UPLINK_CAPAB, buf);
00338 notice_lang(s_OperServ, u, OPER_STATS_UPLINK_SERVER_COUNT,
00339 stats_count_servers(serv_uplink));
00340 }
00341
00342 if (extra && ((stricmp(extra, "ALL") == 0)
00343 || (stricmp(extra, "MEMORY") == 0))
00344 && is_services_admin(u)) {
00345 long count, mem;
00346
00347 notice_lang(s_OperServ, u, OPER_STATS_BYTES_READ,
00348 total_read / 1024);
00349 notice_lang(s_OperServ, u, OPER_STATS_BYTES_WRITTEN,
00350 total_written / 1024);
00351
00352 get_user_stats(&count, &mem);
00353 notice_lang(s_OperServ, u, OPER_STATS_USER_MEM, count,
00354 (mem + 512) / 1024);
00355 get_channel_stats(&count, &mem);
00356 notice_lang(s_OperServ, u, OPER_STATS_CHANNEL_MEM, count,
00357 (mem + 512) / 1024);
00358 get_core_stats(&count, &mem);
00359 notice_lang(s_OperServ, u, OPER_STATS_GROUPS_MEM, count,
00360 (mem + 512) / 1024);
00361 get_aliases_stats(&count, &mem);
00362 notice_lang(s_OperServ, u, OPER_STATS_ALIASES_MEM, count,
00363 (mem + 512) / 1024);
00364 get_chanserv_stats(&count, &mem);
00365 notice_lang(s_OperServ, u, OPER_STATS_CHANSERV_MEM, count,
00366 (mem + 512) / 1024);
00367 get_botserv_stats(&count, &mem);
00368 notice_lang(s_OperServ, u, OPER_STATS_BOTSERV_MEM, count,
00369 (mem + 512) / 1024);
00370 get_operserv_stats(&count, &mem);
00371 notice_lang(s_OperServ, u, OPER_STATS_OPERSERV_MEM, count,
00372 (mem + 512) / 1024);
00373 get_session_stats(&count, &mem);
00374 notice_lang(s_OperServ, u, OPER_STATS_SESSIONS_MEM, count,
00375 (mem + 512) / 1024);
00376 }
00377 return MOD_CONT;
00378 }
00379
00380 void get_operserv_stats(long *nrec, long *memuse)
00381 {
00382 int i;
00383 long mem = 0, count = 0, mem2 = 0, count2 = 0;
00384 Akill *ak;
00385 SXLine *sx;
00386
00387 count += akills.count;
00388 mem += akills.capacity;
00389 mem += akills.count * sizeof(Akill);
00390
00391 for (i = 0; i < akills.count; i++) {
00392 ak = akills.list[i];
00393 mem += strlen(ak->user) + 1;
00394 mem += strlen(ak->host) + 1;
00395 mem += strlen(ak->by) + 1;
00396 mem += strlen(ak->reason) + 1;
00397 }
00398
00399 if (ircd->sgline) {
00400 count += sglines.count;
00401 mem += sglines.capacity;
00402 mem += sglines.count * sizeof(SXLine);
00403
00404 for (i = 0; i < sglines.count; i++) {
00405 sx = sglines.list[i];
00406 mem += strlen(sx->mask) + 1;
00407 mem += strlen(sx->by) + 1;
00408 mem += strlen(sx->reason) + 1;
00409 }
00410 }
00411 if (ircd->sqline) {
00412 count += sqlines.count;
00413 mem += sqlines.capacity;
00414 mem += sqlines.count * sizeof(SXLine);
00415
00416 for (i = 0; i < sqlines.count; i++) {
00417 sx = sqlines.list[i];
00418 mem += strlen(sx->mask) + 1;
00419 mem += strlen(sx->by) + 1;
00420 mem += strlen(sx->reason) + 1;
00421 }
00422 }
00423 if (ircd->szline) {
00424 count += szlines.count;
00425 mem += szlines.capacity;
00426 mem += szlines.count * sizeof(SXLine);
00427
00428 for (i = 0; i < szlines.count; i++) {
00429 sx = szlines.list[i];
00430 mem += strlen(sx->mask) + 1;
00431 mem += strlen(sx->by) + 1;
00432 mem += strlen(sx->reason) + 1;
00433 }
00434 }
00435
00436
00437 get_news_stats(&count2, &mem2);
00438 count += count2;
00439 mem += mem2;
00440 get_exception_stats(&count2, &mem2);
00441 count += count2;
00442 mem += mem2;
00443
00444 *nrec = count;
00445 *memuse = mem;
00446 }