00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <list>
00036 #include <string>
00037 #include <time.h>
00038
00039 using namespace std;
00040
00041 #include "stats.h"
00042 #include "lang.h"
00043
00044 #include "params.h"
00045
00046 #ifndef _WIN32
00047 #ifndef HAVE_LTOA
00048 extern char *ltoa(long value, char *buffer, int radix);
00049 #endif
00050 #endif
00051
00052 time_t start_time=0;
00053
00054
00055
00056
00057
00058
00059
00060 struct s_stats {
00061 size_t all_bytes_sent;
00062 size_t all_bytes_received;
00063
00064 size_t irc_all_bytes_sent;
00065 size_t irc_all_bytes_received;
00066
00067 size_t irc_last_bytes_sent;
00068 size_t irc_last_bytes_received;
00069
00070 unsigned long irc_connections;
00071
00072 size_t dcc_chat_bytes_sent;
00073 size_t dcc_chat_bytes_received;
00074
00075 unsigned long dcc_chat_connections;
00076
00077 size_t dcc_send_bytes_sent;
00078 size_t dcc_send_bytes_received;
00079
00080 unsigned long dcc_send_connections;
00081
00082 size_t botnet_bytes_sent;
00083 size_t botnet_bytes_received;
00084
00085 unsigned long botnet_connections;
00086 unsigned long botnet_auth_ok;
00087 unsigned long botnet_auth_error;
00088 unsigned long botnet_auth_proto_error;
00089
00090 unsigned long botnet_objects_pushed;
00091 unsigned long botnet_objects_pulled;
00092
00093 unsigned long botnet_proc_pushed;
00094 unsigned long botnet_proc_pulled;
00095
00096 unsigned long botnet_user_pushed;
00097 unsigned long botnet_user_pulled;
00098
00099 unsigned long botnet_private_pushed;
00100 unsigned long botnet_private_pulled;
00101
00102 unsigned long botnet_chandef_pushed;
00103 unsigned long botnet_chandef_pulled;
00104
00105 unsigned long botnet_partyline_events;
00106
00107 unsigned long mail_sent;
00108
00109 size_t identd_bytes_sent;
00110 size_t identd_bytes_received;
00111 unsigned long identd_connections;
00112
00113 string current_irc_server_host;
00114 unsigned short current_irc_server_port;
00115
00116
00117
00118
00119
00120
00121
00122 void clear()
00123 {
00124 all_bytes_sent=all_bytes_received=irc_all_bytes_sent=irc_all_bytes_received=
00125 irc_last_bytes_sent=irc_last_bytes_received=dcc_chat_bytes_sent=
00126 dcc_chat_bytes_received=dcc_send_bytes_sent=dcc_send_bytes_received=
00127 botnet_bytes_sent=botnet_bytes_received=identd_bytes_sent=
00128 identd_bytes_received=0;
00129
00130 irc_connections=dcc_chat_connections=dcc_send_connections=botnet_connections=
00131 botnet_auth_ok=botnet_auth_error=botnet_auth_proto_error=botnet_objects_pushed=
00132 botnet_objects_pulled=botnet_proc_pushed=botnet_proc_pulled=
00133 botnet_user_pushed=botnet_user_pulled=botnet_private_pushed=
00134 botnet_private_pulled=botnet_chandef_pushed=botnet_chandef_pulled=
00135 botnet_partyline_events=mail_sent=identd_connections=0;
00136
00137 current_irc_server_host="";
00138 current_irc_server_port=0;
00139 }
00140
00141 s_stats()
00142 {
00143 clear();
00144 }
00145 };
00146
00147 s_stats stats;
00148
00149
00150
00151
00152
00153
00154
00155 void stats_init()
00156 {
00157 stats.clear();
00158 time(&start_time);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168 void stats_irc_bytes_sent(size_t bytes)
00169 {
00170 stats.all_bytes_sent+=bytes;
00171 stats.irc_all_bytes_sent+=bytes;
00172 stats.irc_last_bytes_sent+=bytes;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182 void stats_irc_bytes_received(size_t bytes)
00183 {
00184 stats.all_bytes_received+=bytes;
00185 stats.irc_all_bytes_received+=bytes;
00186 stats.irc_last_bytes_received+=bytes;
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 void stats_irc_new_connection(string irc_server_host, unsigned short irc_server_port)
00198 {
00199 stats.irc_last_bytes_received=0;
00200 stats.irc_last_bytes_sent=0;
00201 stats.irc_connections++;
00202 stats.current_irc_server_host=irc_server_host;
00203 stats.current_irc_server_port=irc_server_port;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 void stats_dcc_chat_bytes_sent(size_t bytes)
00214 {
00215 stats.all_bytes_sent+=bytes;
00216 stats.dcc_chat_bytes_sent+=bytes;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226 void stats_dcc_chat_bytes_received(size_t bytes)
00227 {
00228 stats.all_bytes_received+=bytes;
00229 stats.dcc_chat_bytes_received+=bytes;
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239 void stats_dcc_send_bytes_sent(size_t bytes)
00240 {
00241 stats.all_bytes_sent+=bytes;
00242 stats.dcc_send_bytes_sent+=bytes;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252 void stats_dcc_send_bytes_received(size_t bytes)
00253 {
00254 stats.all_bytes_received+=bytes;
00255 stats.dcc_send_bytes_received+=bytes;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264 void stats_dcc_chat_new_connection()
00265 {
00266 stats.dcc_chat_connections++;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 void stats_dcc_send_new_connection()
00276 {
00277 stats.dcc_send_connections++;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287 void stats_botnet_bytes_sent(size_t bytes)
00288 {
00289 stats.all_bytes_sent+=bytes;
00290 stats.botnet_bytes_sent+=bytes;
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300 void stats_botnet_bytes_received(size_t bytes)
00301 {
00302 stats.all_bytes_received+=bytes;
00303 stats.botnet_bytes_received+=bytes;
00304 }
00305
00306
00307
00308
00309
00310
00311
00312 void stats_identd_new_connection()
00313 {
00314 stats.identd_connections++;
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324 void stats_identd_bytes_sent(size_t bytes)
00325 {
00326 stats.all_bytes_sent+=bytes;
00327 stats.identd_bytes_sent+=bytes;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337 void stats_identd_bytes_received(size_t bytes)
00338 {
00339 stats.all_bytes_received+=bytes;
00340 stats.identd_bytes_received+=bytes;
00341 }
00342
00343
00344
00345
00346
00347
00348
00349 void stats_botnet_new_connection()
00350 {
00351 stats.botnet_connections++;
00352 }
00353
00354
00355
00356
00357
00358
00359
00360 void stats_botnet_proc_pushed()
00361 {
00362 stats.botnet_objects_pushed++;
00363 stats.botnet_proc_pushed++;
00364 }
00365
00366
00367
00368
00369
00370
00371
00372 void stats_botnet_proc_pulled()
00373 {
00374 stats.botnet_objects_pulled++;
00375 stats.botnet_proc_pulled++;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384 void stats_botnet_user_pushed()
00385 {
00386 stats.botnet_objects_pushed++;
00387 stats.botnet_user_pushed++;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396 void stats_botnet_user_pulled()
00397 {
00398 stats.botnet_objects_pulled++;
00399 stats.botnet_user_pulled++;
00400 }
00401
00402
00403
00404
00405
00406
00407
00408 void stats_botnet_private_pushed()
00409 {
00410 stats.botnet_objects_pushed++;
00411 stats.botnet_private_pushed++;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420 void stats_botnet_private_pulled()
00421 {
00422 stats.botnet_objects_pulled++;
00423 stats.botnet_private_pulled++;
00424 }
00425
00426
00427
00428
00429
00430
00431
00432 void stats_botnet_chandef_pushed()
00433 {
00434 stats.botnet_objects_pushed++;
00435 stats.botnet_chandef_pushed++;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444 void stats_botnet_chandef_pulled()
00445 {
00446 stats.botnet_objects_pulled++;
00447 stats.botnet_chandef_pulled++;
00448 }
00449
00450
00451
00452
00453
00454
00455
00456 void stats_botnet_partyline_event()
00457 {
00458 stats.botnet_partyline_events++;
00459 }
00460
00461
00462
00463
00464
00465
00466
00467 void stats_botnet_auth_ok()
00468 {
00469 stats.botnet_auth_ok++;
00470 }
00471
00472
00473
00474
00475
00476
00477
00478 void stats_botnet_auth_error()
00479 {
00480 stats.botnet_auth_error++;
00481 }
00482
00483
00484
00485
00486
00487
00488
00489 void stats_botnet_auth_proto_error()
00490 {
00491 stats.botnet_auth_proto_error++;
00492 }
00493
00494
00495
00496
00497
00498
00499
00500 void stats_mail_sent()
00501 {
00502 stats.mail_sent++;
00503 }
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 string stats_format_number(size_t number)
00514 {
00515 char tmp[64];
00516 ltoa((long)number,tmp,10);
00517 string str1=(string)"!"+tmp;
00518 string str2;
00519 int i2=0;
00520 for(size_t i1=str1.length()-1; (signed)i1>0; i1--, i2++) {
00521 if(i2==3) {
00522 str2=(string)","+str2;
00523 i2=0;
00524 }
00525 str2=(string)""+str1[i1]+str2;
00526 }
00527 return str2;
00528 }
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 void stats_display(list<string>& lines, string lang)
00539 {
00540 lines.clear();
00541
00542 string line;
00543
00544 {
00545 time_t now=time(NULL);
00546 if(!start_time)
00547 start_time=now;
00548
00549 time_t up=now-start_time;
00550
00551 time_t days=up/(24*60*60);
00552 up%=24*60*60;
00553 time_t hrs=up/(60*60);
00554 up%=60*60;
00555 time_t mins=up/(60);
00556 up%=60;
00557 time_t secs=up;
00558
00559 char tmp[64];
00560 if(!lang.empty()) {
00561 line+=lang_get_string(1,lang,552);
00562 line+=" ";
00563
00564 line+=ltoa((long)days,tmp,10);
00565 line+=" ";
00566 line+=lang_get_string(1,lang,553);
00567 line+=", ";
00568
00569 line+=ltoa((long)hrs,tmp,10);
00570 line+=" ";
00571 line+=lang_get_string(1,lang,554);
00572 line+=", ";
00573
00574 line+=ltoa((long)mins,tmp,10);
00575 line+=" ";
00576 line+=lang_get_string(1,lang,555);
00577 line+=", ";
00578
00579 line+=ltoa((long)secs,tmp,10);
00580 line+=" ";
00581 line+=lang_get_string(1,lang,556);
00582 } else {
00583 line+="Bot uptime: ";
00584
00585 line+=ltoa((long)days,tmp,10);
00586 line+=" day(s), ";
00587
00588 line+=ltoa((long)hrs,tmp,10);
00589 line+=" hour(s), ";
00590
00591 line+=ltoa((long)mins,tmp,10);
00592 line+=" minute(s), ";
00593
00594 line+=ltoa((long)secs,tmp,10);
00595 line+=" second(s)";
00596 }
00597 lines.push_back(line);
00598 }
00599
00600 line="";
00601 if(!lang.empty())
00602 line+=lang_get_string(1,lang,559);
00603 else
00604 line+="Using IRC server host/port:";
00605 line+=" ";
00606 if(stats.current_irc_server_host.find(":",0)!=string::npos)
00607 line+="[";
00608 line+=stats.current_irc_server_host;
00609 if(stats.current_irc_server_host.find(":",0)!=string::npos)
00610 line+="]";
00611 line+=":";
00612 {
00613 char tmp[64];
00614 ltoa(stats.current_irc_server_port,tmp,10);
00615 line+=tmp;
00616 }
00617 lines.push_back(line);
00618
00619 line="";
00620 if(!lang.empty())
00621 line+=lang_get_string(1,lang,503);
00622 else
00623 line+="All sent bytes:";
00624 line+=" ";
00625 line+=stats_format_number(stats.all_bytes_sent);
00626 lines.push_back(line);
00627
00628 line="";
00629 if(!lang.empty())
00630 line+=lang_get_string(1,lang,504);
00631 else
00632 line+="All received bytes:";
00633 line+=" ";
00634 line+=stats_format_number(stats.all_bytes_received);
00635 lines.push_back(line);
00636
00637 line="";
00638 if(!lang.empty())
00639 line+=lang_get_string(1,lang,505);
00640 else
00641 line+="All sent bytes to IRC server:";
00642 line+=" ";
00643 line+=stats_format_number(stats.irc_all_bytes_sent);
00644 lines.push_back(line);
00645
00646 line="";
00647 if(!lang.empty())
00648 line+=lang_get_string(1,lang,506);
00649 else
00650 line+="All received bytes from IRC server:";
00651 line+=" ";
00652 line+=stats_format_number(stats.irc_all_bytes_received);
00653 lines.push_back(line);
00654
00655 line="";
00656 if(!lang.empty())
00657 line+=lang_get_string(1,lang,507);
00658 else
00659 line+="All sent bytes to IRC server on last connection:";
00660 line+=" ";
00661 line+=stats_format_number(stats.irc_last_bytes_sent);
00662 lines.push_back(line);
00663
00664 line="";
00665 if(!lang.empty())
00666 line+=lang_get_string(1,lang,508);
00667 else
00668 line+="All received bytes from IRC server on last connection:";
00669 line+=" ";
00670 line+=stats_format_number(stats.irc_last_bytes_received);
00671 lines.push_back(line);
00672
00673 line="";
00674 if(!lang.empty())
00675 line+=lang_get_string(1,lang,509);
00676 else
00677 line+="Number of connections established to IRC server:";
00678 line+=" ";
00679 line+=stats_format_number(stats.irc_connections);
00680 lines.push_back(line);
00681
00682 line="";
00683 if(!lang.empty())
00684 line+=lang_get_string(1,lang,510);
00685 else
00686 line+="All sent bytes to DCC CHAT / telnet:";
00687 line+=" ";
00688 line+=stats_format_number(stats.dcc_chat_bytes_sent);
00689 lines.push_back(line);
00690
00691 line="";
00692 if(!lang.empty())
00693 line+=lang_get_string(1,lang,511);
00694 else
00695 line+="All received bytes from DCC CHAT / telnet:";
00696 line+=" ";
00697 line+=stats_format_number(stats.dcc_chat_bytes_received);
00698 lines.push_back(line);
00699
00700 line="";
00701 if(!lang.empty())
00702 line+=lang_get_string(1,lang,512);
00703 else
00704 line+="Number of DCC CHAT / telnet, or incomming BOTNET connections established:";
00705 line+=" ";
00706 line+=stats_format_number(stats.dcc_chat_connections);
00707 lines.push_back(line);
00708
00709 line="";
00710 if(!lang.empty())
00711 line+=lang_get_string(1,lang,513);
00712 else
00713 line+="All sent bytes to DCC SEND:";
00714 line+=" ";
00715 line+=stats_format_number(stats.dcc_send_bytes_sent);
00716 lines.push_back(line);
00717
00718 line="";
00719 if(!lang.empty())
00720 line+=lang_get_string(1,lang,514);
00721 else
00722 line+="All received bytes from DCC SEND:";
00723 line+=" ";
00724 line+=stats_format_number(stats.dcc_send_bytes_received);
00725 lines.push_back(line);
00726
00727 line="";
00728 if(!lang.empty())
00729 line+=lang_get_string(1,lang,515);
00730 else
00731 line+="Number of DCC SEND connections established:";
00732 line+=" ";
00733 line+=stats_format_number(stats.dcc_send_connections);
00734 lines.push_back(line);
00735
00736 line="";
00737 if(!lang.empty())
00738 line+=lang_get_string(1,lang,536);
00739 else
00740 line+="All sent bytes to IDENT requests:";
00741 line+=" ";
00742 line+=stats_format_number(stats.identd_bytes_sent);
00743 lines.push_back(line);
00744
00745 line="";
00746 if(!lang.empty())
00747 line+=lang_get_string(1,lang,537);
00748 else
00749 line+="All received bytes from IDENT requests:";
00750 line+=" ";
00751 line+=stats_format_number(stats.identd_bytes_received);
00752 lines.push_back(line);
00753
00754 line="";
00755 if(!lang.empty())
00756 line+=lang_get_string(1,lang,538);
00757 else
00758 line+="Number of IDENT connections established:";
00759 line+=" ";
00760 line+=stats_format_number(stats.identd_connections);
00761 lines.push_back(line);
00762
00763 line="";
00764 if(!lang.empty())
00765 line+=lang_get_string(1,lang,516);
00766 else
00767 line+="All sent bytes to BOTNET:";
00768 line+=" ";
00769 line+=stats_format_number(stats.botnet_bytes_sent);
00770 lines.push_back(line);
00771
00772 line="";
00773 if(!lang.empty())
00774 line+=lang_get_string(1,lang,517);
00775 else
00776 line+="All received bytes from BOTNET:";
00777 line+=" ";
00778 line+=stats_format_number(stats.botnet_bytes_received);
00779 lines.push_back(line);
00780
00781 line="";
00782 if(!lang.empty())
00783 line+=lang_get_string(1,lang,518);
00784 else
00785 line+="Number of BOTNET connections established:";
00786 line+=" ";
00787 line+=stats_format_number(stats.botnet_connections);
00788 lines.push_back(line);
00789
00790 line="";
00791 if(!lang.empty())
00792 line+=lang_get_string(1,lang,519);
00793 else
00794 line+="Number of successful BOTNET authentications:";
00795 line+=" ";
00796 line+=stats_format_number(stats.botnet_auth_ok);
00797 lines.push_back(line);
00798
00799 line="";
00800 if(!lang.empty())
00801 line+=lang_get_string(1,lang,520);
00802 else
00803 line+="Number of failed BOTNET authentications:";
00804 line+=" ";
00805 line+=stats_format_number(stats.botnet_auth_error);
00806 lines.push_back(line);
00807
00808 line="";
00809 if(!lang.empty())
00810 line+=lang_get_string(1,lang,521);
00811 else
00812 line+="Number of BOTNET protocol errors:";
00813 line+=" ";
00814 line+=stats_format_number(stats.botnet_auth_proto_error);
00815 lines.push_back(line);
00816
00817 line="";
00818 if(!lang.empty())
00819 line+=lang_get_string(1,lang,522);
00820 else
00821 line+="Number of all pushed BOTNET objects:";
00822 line+=" ";
00823 line+=stats_format_number(stats.botnet_objects_pushed);
00824 lines.push_back(line);
00825
00826 line="";
00827 if(!lang.empty())
00828 line+=lang_get_string(1,lang,523);
00829 else
00830 line+="Number of all pulled BOTNET objects:";
00831 line+=" ";
00832 line+=stats_format_number(stats.botnet_objects_pulled);
00833 lines.push_back(line);
00834
00835 line="";
00836 if(!lang.empty())
00837 line+=lang_get_string(1,lang,524);
00838 else
00839 line+="Number of pushed BOTNET procedures:";
00840 line+=" ";
00841 line+=stats_format_number(stats.botnet_proc_pushed);
00842 lines.push_back(line);
00843
00844 line="";
00845 if(!lang.empty())
00846 line+=lang_get_string(1,lang,525);
00847 else
00848 line+="Number of pulled BOTNET procedures:";
00849 line+=" ";
00850 line+=stats_format_number(stats.botnet_proc_pulled);
00851 lines.push_back(line);
00852
00853 line="";
00854 if(!lang.empty())
00855 line+=lang_get_string(1,lang,526);
00856 else
00857 line+="Number of pushed BOTNET users:";
00858 line+=" ";
00859 line+=stats_format_number(stats.botnet_user_pushed);
00860 lines.push_back(line);
00861
00862 line="";
00863 if(!lang.empty())
00864 line+=lang_get_string(1,lang,527);
00865 else
00866 line+="Number of pulled BOTNET users:";
00867 line+=" ";
00868 line+=stats_format_number(stats.botnet_user_pulled);
00869 lines.push_back(line);
00870
00871 line="";
00872 if(!lang.empty())
00873 line+=lang_get_string(1,lang,528);
00874 else
00875 line+="Number of pushed BOTNET private:";
00876 line+=" ";
00877 line+=stats_format_number(stats.botnet_private_pushed);
00878 lines.push_back(line);
00879
00880 line="";
00881 if(!lang.empty())
00882 line+=lang_get_string(1,lang,529);
00883 else
00884 line+="Number of pulled BOTNET private:";
00885 line+=" ";
00886 line+=stats_format_number(stats.botnet_private_pulled);
00887 lines.push_back(line);
00888
00889 line="";
00890 if(!lang.empty())
00891 line+=lang_get_string(1,lang,530);
00892 else
00893 line+="Number of pushed BOTNET channels:";
00894 line+=" ";
00895 line+=stats_format_number(stats.botnet_chandef_pushed);
00896 lines.push_back(line);
00897
00898 line="";
00899 if(!lang.empty())
00900 line+=lang_get_string(1,lang,531);
00901 else
00902 line+="Number of pulled BOTNET channels:";
00903 line+=" ";
00904 line+=stats_format_number(stats.botnet_chandef_pulled);
00905 lines.push_back(line);
00906
00907 line="";
00908 if(!lang.empty())
00909 line+=lang_get_string(1,lang,532);
00910 else
00911 line+="Number of BOTNET partyline events:";
00912 line+=" ";
00913 line+=stats_format_number(stats.botnet_partyline_events);
00914 lines.push_back(line);
00915
00916 line="";
00917 if(!lang.empty())
00918 line+=lang_get_string(1,lang,533);
00919 else
00920 line+="Number of e-mail(s) sent:";
00921 line+=" ";
00922 line+=stats_format_number(stats.mail_sent);
00923 lines.push_back(line);
00924 }
00925