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
00036
00037 #include <stdio.h>
00038 #include <string>
00039 #ifdef _WIN32
00040 # include <conio.h>
00041 # include <io.h>
00042 #else
00043 #include <unistd.h>
00044 #endif
00045 #include <vector>
00046 #include <list>
00047 #include <stdlib.h>
00048 #include <map>
00049 #include <sys/stat.h>
00050 #ifndef _MSC_VER
00051 # ifdef _WIN32
00052 # include <dir.h>
00053 # else
00054 # include <sys/types.h>
00055 # include <sys/stat.h>
00056 # endif
00057 #else
00058 # include <direct.h>
00059 # define mkdir _mkdir
00060 #endif
00061
00062 #include "log.h"
00063 #include "irc.h"
00064 #include "sock.h"
00065 #include "identd.h"
00066 #include "dcc.h"
00067 #include "lang.h"
00068 #include "conf.h"
00069 #include "exec.h"
00070 #include "botnet.h"
00071 #include "stats.h"
00072 #include "filesys.h"
00073
00074 #include "params.h"
00075
00076 #pragma hdrstop
00077
00078 #ifdef _MSC_VER
00079 # define __FUNC__ __FUNCTION__
00080 #endif
00081
00082 #ifdef __GNUC__
00083 #define __FUNC__ "<unknown>"
00084 #endif
00085
00086 #include "match.h"
00087
00088 #ifdef _WIN32
00089 # define FILE_SLASH "\\"
00090 #else
00091 # define FILE_SLASH "/"
00092 #endif
00093
00094 #include "logic.h"
00095
00096 #ifndef _MSC_VER
00097 #pragma package(smart_init)
00098 #endif
00099
00100 #include "shared.h"
00101
00102 using namespace std;
00103
00104 #ifndef _WIN32
00105 #ifndef HAVE_LTOA
00106 extern char *ltoa(long value, char *buffer, int radix);
00107 #endif
00108 #endif
00109
00110 extern void sleep(int ms);
00111
00112 extern s_socket irc_socket;
00113 extern vector<string> irc_nicks;
00114 extern vector<s_irc_server> irc_servers;
00115 extern vector<s_irc_server>::iterator irc_server_iterator;
00116 int last_nick_idx;
00117 extern char irc_fullname[512];
00118 extern char irc_nick[512];
00119 extern string irc_ident;
00120
00121 extern s_005 irc_isupport;
00122
00123 extern string irc_server_host;
00124 extern unsigned short irc_server_port;
00125
00126 extern s_msg_to_server last_msg;
00127
00128 extern list<s_msg_to_server> msgs_to_server;
00129
00130 extern string irc_recommended_server;
00131 extern unsigned short irc_recommended_port;
00132
00133 extern char botnet_botname[256];
00134
00135 extern vector<s_online_channel> irc_channels;
00136
00137 extern bool dcc_want_to_restart;
00138 extern bool dcc_want_to_die;
00139 extern string dcc_who_is_killing;
00140
00141 string ident_string;
00142
00143 time_t last_autobackup=0;
00144
00145
00146
00147
00148
00149
00150
00151 struct s_timer {
00152 bool once;
00153 string name;
00154 time_t set_at;
00155 time_t again_at;
00156 long duration;
00157
00158 string call_string;
00159 list<string> params;
00160
00161 map<string,string> vars;
00162
00163 s_timer()
00164 {
00165 once=false;
00166 name="";
00167 set_at=0;
00168 again_at=0;
00169 duration=0;
00170 call_string="";
00171 params.clear();
00172 vars.clear();
00173 }
00174 };
00175
00176
00177
00178
00179
00180
00181
00182 struct s_tmp_file {
00183 s_exec_handle* h;
00184 bool script;
00185
00186 int script_num;
00187
00188 char script_type[128];
00189
00190 char command_line[4096];
00191 char command_args[4096];
00192 char command_dir[1024];
00193 bool has_been_run;
00194
00195 time_t start_up_time;
00196
00197 s_tmp_file()
00198 {
00199 h=NULL;
00200 script=false;
00201 command_line[0]=0;
00202 command_args[0]=0;
00203 command_dir[0]=0;
00204 has_been_run=false;
00205 memset(script_type,0,sizeof(script_type));
00206 start_up_time=0;
00207 }
00208 };
00209
00210 vector<s_tmp_file> tmp_files;
00211
00212
00213
00214 vector<s_procedure> r_procedures;
00215 vector<s_user> r_users;
00216 vector<s_user> r_user_templates;
00217 vector<s_user> r_terminators;
00218 vector<s_channel> r_channels;
00219 vector<s_channel> r_channel_templates;
00220 vector<s_channel> r_channel_terminators;
00221 vector<s_timer> r_timers;
00222 vector<s_channel_def> r_channel_defs;
00223
00224 vector<s_group> r_all_groups;
00225
00226 s_private r_private;
00227
00228
00229
00230 s_procedure work_proc;
00231 map<string,string> work_vars;
00232
00233 map<int,string> severity_codes;
00234
00235
00236
00237
00238
00239
00240
00241 void logic_init_severities()
00242 {
00243 severity_codes.clear();
00244
00245 pair<int,string> p;
00246
00247 p.first=PRIVATE_EVENT_SEVERITY_CODE_NA;
00248 p.second="N/A";
00249 severity_codes.insert(p);
00250
00251 p.first=PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL;
00252 p.second="informational";
00253 severity_codes.insert(p);
00254
00255 p.first=PRIVATE_EVENT_SEVERITY_CODE_WARNING;
00256 p.second="warning";
00257 severity_codes.insert(p);
00258
00259 p.first=PRIVATE_EVENT_SEVERITY_CODE_ERROR;
00260 p.second="error";
00261 severity_codes.insert(p);
00262
00263 p.first=PRIVATE_EVENT_SEVERITY_CODE_CRITICAL_ERROR;
00264 p.second="critical error";
00265 severity_codes.insert(p);
00266
00267 p.first=PRIVATE_EVENT_SEVERITY_CODE_FATAL_ERROR;
00268 p.second="fatal error";
00269 severity_codes.insert(p);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 string logic_get_severity_text(int code)
00281 {
00282 if(severity_codes.empty())
00283 logic_init_severities();
00284
00285 map<int,string>::iterator i;
00286 i=severity_codes.find(code);
00287 if(i==severity_codes.end())
00288 return "?";
00289 return (*i).second;
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 string logic_to_upper(string str)
00301 {
00302 extern unsigned char touppertab[];
00303
00304 string res;
00305 for(unsigned int i1=0; i1<str.length(); i1++)
00306 res+=touppertab[str[i1]];
00307 return res;
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 string logic_to_lower(string str)
00319 {
00320 extern unsigned char tolowertab[];
00321
00322 string res;
00323 for(unsigned int i1=0; i1<str.length(); i1++)
00324 res+=tolowertab[str[i1]];
00325 return res;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 void logic_validate_chan_mode(string channel, string source_user, string source_nick, char prefix, char mode)
00340 {
00341 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
00342 return;
00343
00344 map<string,string> vars;
00345
00346 vector<s_channel_def>::iterator i1;
00347
00348 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00349 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
00350 s_user u;
00351 vector<s_channel> chs;
00352 logic_partyline_get_user(source_user,u,chs);
00353 vector<s_dynamic_rule>::iterator i2;
00354 for(i2=(*i1).allow_dynamic.begin(); i2!=(*i1).allow_dynamic.end(); i2++) {
00355 vector<s_group>::iterator i3;
00356 bool got=false;
00357 for(i3=u.groups.begin(); i3!=u.groups.end(); i3++) {
00358 if(!(*i2).group.compare((*i3).name)) {
00359 if((prefix=='-' && (*i2).minus_modes.find((string)""+mode,0)==string::npos))
00360 continue;
00361 if((prefix=='+' && (*i2).plus_modes.find((string)""+mode,0)==string::npos))
00362 continue;
00363 got=true;
00364 while((*i1).dynamic_plus_modes.find((string)""+mode,0)!=string::npos)
00365 (*i1).dynamic_plus_modes.erase((*i1).dynamic_plus_modes.find((string)""+mode,0),1);
00366 while((*i1).dynamic_minus_modes.find((string)""+mode,0)!=string::npos)
00367 (*i1).dynamic_minus_modes.erase((*i1).dynamic_minus_modes.find((string)""+mode,0),1);
00368 if(prefix=='-')
00369 (*i1).dynamic_minus_modes+=(string)""+mode;
00370 else
00371 (*i1).dynamic_plus_modes+=(string)""+mode;
00372 break;
00373 }
00374 }
00375 if(got)
00376 break;
00377 }
00378
00379 string proc=(*i1).on_mode;
00380
00381 map<string,string> vars;
00382 list<string> params;
00383 params.push_back(channel);
00384 params.push_back(source_user);
00385 params.push_back(source_nick);
00386
00387 string str="";
00388 if(prefix=='+')
00389 str=mode;
00390
00391 params.push_back(str);
00392
00393 str="";
00394 if(prefix=='-')
00395 str=mode;
00396
00397 params.push_back(str);
00398
00399 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
00400 case LOGIC_SOCKET_ERROR:
00401 case LOGIC_RESTART:
00402 return;
00403 default:
00404 break;
00405 }
00406 }
00407 }
00408 }
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 void logic_validate_chan_key(string channel, string source_user, string source_nick, char prefix, string key)
00422 {
00423 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
00424 return;
00425
00426 map<string,string> vars;
00427
00428 vector<s_channel_def>::iterator i1;
00429
00430 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00431 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
00432
00433 (*i1).keys.push_back(key);
00434
00435 string proc=(*i1).on_key;
00436
00437 map<string,string> vars;
00438 list<string> params;
00439 params.push_back(channel);
00440 params.push_back(source_user);
00441 params.push_back(source_nick);
00442
00443 params.push_back((string)""+prefix);
00444 params.push_back(key);
00445
00446 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
00447 case LOGIC_SOCKET_ERROR:
00448 case LOGIC_RESTART:
00449 return;
00450 default:
00451 break;
00452 }
00453 }
00454 }
00455 }
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 void logic_validate_chan_limit(string channel, string source_user, string source_nick, char prefix, string limit)
00469 {
00470 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
00471 return;
00472
00473 map<string,string> vars;
00474
00475 vector<s_channel_def>::iterator i1;
00476
00477 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00478 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
00479 string proc=(*i1).on_limit;
00480
00481 map<string,string> vars;
00482 list<string> params;
00483 params.push_back(channel);
00484 params.push_back(source_user);
00485 params.push_back(source_nick);
00486
00487 params.push_back((string)""+prefix);
00488 params.push_back(limit);
00489
00490 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
00491 case LOGIC_SOCKET_ERROR:
00492 case LOGIC_RESTART:
00493 return;
00494 default:
00495 break;
00496 }
00497 }
00498 }
00499 }
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 void logic_validate_topic(string channel, string source_user, string source_nick, string topic)
00512 {
00513 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
00514 return;
00515
00516 map<string,string> vars;
00517
00518 vector<s_channel_def>::iterator i1;
00519
00520 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00521 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
00522 string proc=(*i1).on_topic;
00523
00524 map<string,string> vars;
00525 list<string> params;
00526 params.push_back(channel);
00527 params.push_back(source_user);
00528 params.push_back(source_nick);
00529
00530 params.push_back(topic);
00531
00532 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
00533 case LOGIC_SOCKET_ERROR:
00534 case LOGIC_RESTART:
00535 return;
00536 default:
00537 break;
00538 }
00539 }
00540 }
00541 }
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 void logic_set_dynamic(string username, string from_user, char prefix, char mode)
00554 {
00555 vector<s_channel>::iterator i1;
00556 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
00557 if(!(*i1).username.compare(username)) {
00558 vector<s_dynamic_rule>::iterator i2;
00559 for(i2=(*i1).allow_dynamic.begin(); i2!=(*i1).allow_dynamic.end(); i2++) {
00560 vector<s_user>::iterator i3;
00561 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
00562 vector<s_group>::iterator i4;
00563 for(i4=(*i3).groups.begin(); i4!=(*i3).groups.end(); i4++) {
00564 if(!(*i4).name.compare((*i2).group) && (*i2).plus_modes.find(mode,0)!=string::npos) {
00565 string mp=(*i1).dynamic_plus_modes;
00566 while(mp.find(mode,0)!=string::npos)
00567 mp.erase(mp.find(mode,0),1);
00568 if(prefix=='+')
00569 mp+=mode;
00570 (*i1).dynamic_plus_modes=mp;
00571 }
00572 if(!(*i4).name.compare((*i2).group) && (*i2).minus_modes.find(mode,0)!=string::npos) {
00573 string mm=(*i1).dynamic_minus_modes;
00574 while(mm.find(mode,0)!=string::npos)
00575 mm.erase(mm.find(mode,0),1);
00576 if(prefix=='-')
00577 mm+=mode;
00578 (*i1).dynamic_minus_modes=mm;
00579 }
00580
00581 }
00582 }
00583 }
00584 }
00585 }
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 void logic_get_pull_users(string botname, vector<s_user>& users)
00597 {
00598 users.clear();
00599 vector<s_user>::iterator i1;
00600 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
00601 vector<s_replication>::iterator i2;
00602 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00603 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) {
00604 users.push_back(*i1);
00605 }
00606 }
00607 }
00608 for(i1=r_user_templates.begin(); i1!=r_user_templates.end(); i1++) {
00609 vector<s_replication>::iterator i2;
00610 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00611 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) {
00612 users.push_back(*i1);
00613 }
00614 }
00615 }
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 void logic_get_push_users(string botname, vector<s_user>& users)
00627 {
00628 users.clear();
00629 vector<s_user>::iterator i1;
00630 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
00631 vector<s_replication>::iterator i2;
00632 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00633 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) {
00634 users.push_back(*i1);
00635 }
00636 }
00637 }
00638 for(i1=r_user_templates.begin(); i1!=r_user_templates.end(); i1++) {
00639 vector<s_replication>::iterator i2;
00640 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00641 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) {
00642 users.push_back(*i1);
00643 }
00644 }
00645 }
00646 }
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656 void logic_get_pull_procs(string botname, vector<s_procedure>& procs)
00657 {
00658 procs.clear();
00659 vector<s_procedure>::iterator i1;
00660 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
00661 vector<s_replication>::iterator i2;
00662 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00663 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) {
00664 procs.push_back(*i1);
00665 }
00666 }
00667 }
00668 }
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678 void logic_get_push_procs(string botname, vector<s_procedure>& procs)
00679 {
00680 procs.clear();
00681 vector<s_procedure>::iterator i1;
00682 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
00683 vector<s_replication>::iterator i2;
00684 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00685 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) {
00686 procs.push_back(*i1);
00687 }
00688 }
00689 }
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 void logic_get_pull_chan_defs(string botname, vector<s_channel_def>& chans)
00701 {
00702 chans.clear();
00703 vector<s_channel_def>::iterator i1;
00704 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00705 vector<s_replication>::iterator i2;
00706 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00707 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PULL || (*i2).type==REPL_PUSHPULL)) {
00708 chans.push_back(*i1);
00709 }
00710 }
00711 }
00712 }
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 void logic_get_push_chan_defs(string botname, vector<s_channel_def>& chans)
00723 {
00724 chans.clear();
00725 vector<s_channel_def>::iterator i1;
00726 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
00727 vector<s_replication>::iterator i2;
00728 for(i2=(*i1).replication.begin(); i2!=(*i1).replication.end(); i2++) {
00729 if(!(*i2).partner.compare(botname) && ((*i2).type==REPL_PUSH || (*i2).type==REPL_PUSHPULL)) {
00730 chans.push_back(*i1);
00731 }
00732 }
00733 }
00734 }
00735
00736
00737
00738
00739
00740
00741
00742
00743 void logic_partyline_backup(string who)
00744 {
00745 filesys_flush();
00746
00747 extern bool dcc_want_to_upgrade;
00748 if(dcc_want_to_upgrade) {
00749 who=(string)"*** ";
00750 string log2="UPGRADE state, ignoring backup request by "+who;
00751 who+=log2;
00752 log_bot(who.c_str());
00753
00754 logic_on_internal_event("@backup@",who,"","","",PRIVATE_EVENT_SEVERITY_CODE_WARNING,log2,"");
00755 return;
00756 }
00757
00758 logic_on_internal_event("@backup@",who,"","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,"","");
00759
00760 who=(string)"*** Backup invoked by "+who;
00761 log_bot(who.c_str());
00762 {
00763 char tmp1[256], tmp2[256];
00764 for(int i1=999; i1>0; i1--) {
00765 sprintf(tmp1,"%s%03d","logic.txt.bak",i1);
00766 sprintf(tmp2,"%s%03d","logic.txt.bak",i1-1);
00767 remove(tmp1);
00768 rename(tmp2,tmp1);
00769 }
00770 remove(tmp2);
00771 rename("logic.txt",tmp2);
00772 }
00773
00774 FILE* f=fopen("logic.txt","w");
00775 if(!f)
00776 return;
00777 int indent=0;
00778 vector<s_user>::iterator i1;
00779 string ln;
00780 int ii;
00781 for(int iii=0; iii<3; iii++) {
00782 vector<s_user> users;
00783 if(iii==0)
00784 users=r_users;
00785 else
00786 if(iii==1)
00787 users=r_user_templates;
00788 else
00789 if(iii==2)
00790 users=r_terminators;
00791 for(i1=users.begin(); i1!=users.end(); i1++) {
00792 if(!(*i1).is_template) {
00793 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00794 ln+=(string)"user "+(*i1).name;
00795 fprintf(f,"%s\n",ln.c_str());
00796 } else {
00797 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00798 ln+=(string)"user_template "+(*i1).name;
00799 fprintf(f,"%s\n",ln.c_str());
00800 }
00801
00802 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00803 ln+="{";
00804 fprintf(f,"%s\n",ln.c_str());
00805 indent+=4;
00806
00807 if((*i1).host_unknown) {
00808 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00809 ln+="host_unknown";
00810 fprintf(f,"%s\n",ln.c_str());
00811 }
00812
00813 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00814 ln+="terminator ";
00815 fprintf(f,"%s%d\n",ln.c_str(),(*i1).terminator);
00816
00817 if((*i1).host_bot) {
00818 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00819 ln+="host_bot";
00820 fprintf(f,"%s\n",ln.c_str());
00821 }
00822
00823 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00824 ln+="last_changed ";
00825 char tmp[64];
00826 ltoa((long)(*i1).last_changed,tmp,10);
00827 ln+=tmp;
00828 fprintf(f,"%s\n",ln.c_str());
00829
00830 vector<string>::iterator i2;
00831 for(i2=(*i1).hostmask.begin(); i2!=(*i1).hostmask.end(); i2++) {
00832 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00833 ln+=(string)"host "+*i2;
00834 fprintf(f,"%s\n",ln.c_str());
00835 }
00836
00837 for(i2=(*i1).fullname.begin(); i2!=(*i1).fullname.end(); i2++) {
00838 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00839 ln+=(string)"full_name "+*i2;
00840 fprintf(f,"%s\n",ln.c_str());
00841 }
00842
00843 vector<s_replication>::iterator i8;
00844 for(i8=(*i1).replication.begin(); i8!=(*i1).replication.end(); i8++) {
00845 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00846 string type;
00847 if((*i8).type==REPL_PUSH)
00848 type="push";
00849 if((*i8).type==REPL_PULL)
00850 type="pull";
00851 if((*i8).type==REPL_PUSHPULL)
00852 type="pushpull";
00853 ln+=(string)"replication "+(*i8).partner+" "+type;
00854 fprintf(f,"%s\n",ln.c_str());
00855 }
00856
00857 if((*i1).replication_partner) {
00858 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00859 ln+=(string)"replication_partner";
00860 fprintf(f,"%s\n",ln.c_str());
00861 }
00862
00863 for(i2=(*i1).access_to_group.begin(); i2!=(*i1).access_to_group.end(); i2++) {
00864 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00865 ln+=(string)"access_to_group "+*i2;
00866 fprintf(f,"%s\n",ln.c_str());
00867 }
00868
00869 for(i2=(*i1).access_to_proc.begin(); i2!=(*i1).access_to_proc.end(); i2++) {
00870 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00871 ln+=(string)"access_to_procedure "+*i2;
00872 fprintf(f,"%s\n",ln.c_str());
00873 }
00874
00875 for(i2=(*i1).access_grant_procedure.begin(); i2!=(*i1).access_grant_procedure.end(); i2++) {
00876 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00877 ln+=(string)"access_grant_procedure "+*i2;
00878 fprintf(f,"%s\n",ln.c_str());
00879 }
00880
00881 for(i2=(*i1).access_usage_procedure.begin(); i2!=(*i1).access_usage_procedure.end(); i2++) {
00882 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00883 ln+=(string)"access_usage_procedure "+*i2;
00884 fprintf(f,"%s\n",ln.c_str());
00885 }
00886
00887 for(i2=(*i1).access_grant_group.begin(); i2!=(*i1).access_grant_group.end(); i2++) {
00888 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00889 ln+=(string)"access_grant_group "+*i2;
00890 fprintf(f,"%s\n",ln.c_str());
00891 }
00892
00893 for(i2=(*i1).access_to_channel.begin(); i2!=(*i1).access_to_channel.end(); i2++) {
00894 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00895 ln+=(string)"access_to_channel "+*i2;
00896 fprintf(f,"%s\n",ln.c_str());
00897 }
00898
00899 for(i2=(*i1).access_grant_channel.begin(); i2!=(*i1).access_grant_channel.end(); i2++) {
00900 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00901 ln+=(string)"access_grant_channel "+*i2;
00902 fprintf(f,"%s\n",ln.c_str());
00903 }
00904
00905 vector<s_group>::iterator i3;
00906 for(i3=(*i1).groups.begin(); i3!=(*i1).groups.end(); i3++) {
00907 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00908 ln+=(string)"member_of_group "+(*i3).name;
00909 fprintf(f,"%s\n",ln.c_str());
00910 }
00911
00912 vector<s_dcc_host>::iterator i4;
00913 for(i4=(*i1).dcc_hosts.begin(); i4!=(*i1).dcc_hosts.end(); i4++) {
00914 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00915 char tmp[64];
00916 ltoa((*i4).group,tmp,10);
00917 ln+=(string)"dcc_host ";
00918 ln+=tmp;
00919 ln+=" "+(*i4).host;
00920 fprintf(f,"%s\n",ln.c_str());
00921 }
00922
00923 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00924 ln+=((*i1).access_to_partyline?"access_to_partyline 1":"access_to_partyline 0");
00925 fprintf(f,"%s\n",ln.c_str());
00926
00927 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00928 ln+=((*i1).access_grant_partyline?"access_grant_partyline 1":"access_grant_partyline 0");
00929 fprintf(f,"%s\n",ln.c_str());
00930
00931
00932 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00933 ln+=((*i1).access_to_backup?"access_to_backup 1":"access_to_backup 0");
00934 fprintf(f,"%s\n",ln.c_str());
00935
00936 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00937 ln+=((*i1).access_to_rehash?"access_to_rehash 1":"access_to_rehash 0");
00938 fprintf(f,"%s\n",ln.c_str());
00939
00940 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00941 ln+=((*i1).access_grant_backup?"access_grant_backup 1":"access_grant_backup 0");
00942 fprintf(f,"%s\n",ln.c_str());
00943
00944 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00945 ln+=((*i1).access_grant_rehash?"access_grant_rehash 1":"access_grant_rehash 0");
00946 fprintf(f,"%s\n",ln.c_str());
00947
00948
00949
00950 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00951 ln+=((*i1).access_to_restart?"access_to_restart 1":"access_to_restart 0");
00952 fprintf(f,"%s\n",ln.c_str());
00953
00954 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00955 ln+=((*i1).access_grant_restart?"access_grant_restart 1":"access_grant_restart 0");
00956 fprintf(f,"%s\n",ln.c_str());
00957
00958 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00959 ln+=((*i1).access_to_die?"access_to_die 1":"access_to_die 0");
00960 fprintf(f,"%s\n",ln.c_str());
00961
00962 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00963 ln+=((*i1).access_grant_die?"access_grant_die 1":"access_grant_die 0");
00964 fprintf(f,"%s\n",ln.c_str());
00965
00966
00967 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00968 ln+=((*i1).access_to_plususer?"access_to_+user 1":"access_to_+user 0");
00969 fprintf(f,"%s\n",ln.c_str());
00970
00971 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00972 ln+=((*i1).access_grant_plususer?"access_grant_+user 1":"access_grant_+user 0");
00973 fprintf(f,"%s\n",ln.c_str());
00974
00975 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00976 ln+=((*i1).access_to_plusproc?"access_to_+proc 1":"access_to_+proc 0");
00977 fprintf(f,"%s\n",ln.c_str());
00978
00979 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00980 ln+=((*i1).access_grant_plusproc?"access_grant_+proc 1":"access_grant_+proc 0");
00981 fprintf(f,"%s\n",ln.c_str());
00982
00983 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00984 ln+=((*i1).access_to_replication?"access_to_replication 1":"access_to_replication 0");
00985 fprintf(f,"%s\n",ln.c_str());
00986
00987 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00988 ln+=((*i1).access_grant_replication?"access_grant_replication 1":"access_grant_replication 0");
00989 fprintf(f,"%s\n",ln.c_str());
00990
00991
00992 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00993 ln+=((*i1).access_to_filesystem?"access_to_filesystem 1":"access_to_filesystem 0");
00994 fprintf(f,"%s\n",ln.c_str());
00995
00996 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
00997 ln+=((*i1).access_grant_filesystem?"access_grant_filesystem 1":"access_grant_filesystem 0");
00998 fprintf(f,"%s\n",ln.c_str());
00999
01000
01001
01002 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01003 ln+=((*i1).access_to_private?"access_to_private 1":"access_to_private 0");
01004 fprintf(f,"%s\n",ln.c_str());
01005
01006 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01007 ln+=((*i1).access_grant_private?"access_grant_private 1":"access_grant_private 0");
01008 fprintf(f,"%s\n",ln.c_str());
01009
01010
01011
01012 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01013 ln+=((*i1).access_to_upgrade?"access_to_upgrade 1":"access_to_upgrade 0");
01014 fprintf(f,"%s\n",ln.c_str());
01015
01016 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01017 ln+=((*i1).access_grant_upgrade?"access_grant_upgrade 1":"access_grant_upgrade 0");
01018 fprintf(f,"%s\n",ln.c_str());
01019
01020
01021
01022 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01023 ln+=((*i1).access_to_apply?"access_to_apply 1":"access_to_apply 0");
01024 fprintf(f,"%s\n",ln.c_str());
01025
01026 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01027 ln+=((*i1).access_grant_apply?"access_grant_apply 1":"access_grant_apply 0");
01028 fprintf(f,"%s\n",ln.c_str());
01029
01030
01031 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01032 ln+=((*i1).access_to_can_send_all_users?"access_to_can_send_all_users 1":"access_to_can_send_all_users 0");
01033 fprintf(f,"%s\n",ln.c_str());
01034
01035 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01036 ln+=((*i1).access_grant_can_send_all_users?"access_grant_can_send_all_users 1":"access_grant_can_send_all_users 0");
01037 fprintf(f,"%s\n",ln.c_str());
01038
01039
01040 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01041 ln+=((*i1).access_to_can_send_unknown_users?"access_to_can_send_unknown_users 1":"access_to_can_send_unknown_users 0");
01042 fprintf(f,"%s\n",ln.c_str());
01043
01044 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01045 ln+=((*i1).access_grant_can_send_unknown_users?"access_grant_can_send_unknown_users 1":"access_grant_can_send_unknown_users 0");
01046 fprintf(f,"%s\n",ln.c_str());
01047
01048
01049
01050 map<string,string>::iterator i6;
01051 for(i6=(*i1).meta.begin(); i6!=(*i1).meta.end(); i6++) {
01052 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01053 ln+="meta ";
01054 ln+=(*i6).first;
01055 ln+=" ";
01056 ln+=(*i6).second;
01057 fprintf(f,"%s\n",ln.c_str());
01058 }
01059
01060
01061
01062 vector<s_channel> chans;
01063 if(iii==0)
01064 chans=r_channels;
01065 else
01066 chans=r_channel_templates;
01067 vector<s_channel>::iterator i5;
01068 for(i5=chans.begin(); i5!=chans.end(); i5++) {
01069 if(!(*i5).username.compare((*i1).name)) {
01070 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01071 ln+=(string)"channel "+(*i5).channel_name;
01072 fprintf(f,"%s\n",ln.c_str());
01073
01074 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01075 ln+="{";
01076 fprintf(f,"%s\n",ln.c_str());
01077 indent+=4;
01078
01079 for(i3=(*i5).groups.begin(); i3!=(*i5).groups.end(); i3++) {
01080 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01081 ln+=(string)"member_of_group "+(*i3).name;
01082 fprintf(f,"%s\n",ln.c_str());
01083 }
01084
01085 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01086 ln+="on_deop "+(*i5).on_deop;
01087 fprintf(f,"%s\n",ln.c_str());
01088
01089 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01090 ln+="on_ban "+(*i5).on_ban;
01091 fprintf(f,"%s\n",ln.c_str());
01092
01093 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01094 ln+="on_unban "+(*i5).on_unban;
01095 fprintf(f,"%s\n",ln.c_str());
01096
01097 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01098 ln+="on_kick "+(*i5).on_kick;
01099 fprintf(f,"%s\n",ln.c_str());
01100
01101 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01102 ln+="on_op "+(*i5).on_op;
01103 fprintf(f,"%s\n",ln.c_str());
01104
01105 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01106 ln+="on_voice "+(*i5).on_voice;
01107 fprintf(f,"%s\n",ln.c_str());
01108
01109 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01110 ln+="on_devoice "+(*i5).on_devoice;
01111 fprintf(f,"%s\n",ln.c_str());
01112
01113 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01114 ln+="on_creator "+(*i5).on_creator;
01115 fprintf(f,"%s\n",ln.c_str());
01116
01117 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01118 ln+="on_decreator "+(*i5).on_decreator;
01119 fprintf(f,"%s\n",ln.c_str());
01120
01121 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01122 ln+="on_join "+(*i5).on_join;
01123 fprintf(f,"%s\n",ln.c_str());
01124
01125 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01126 ln+="on_banned "+(*i5).on_banned;
01127 fprintf(f,"%s\n",ln.c_str());
01128
01129 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01130 ln+="on_flood "+(*i5).on_flood;
01131 fprintf(f,"%s\n",ln.c_str());
01132
01133 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01134 ln+="on_privmsg "+(*i5).on_privmsg;
01135 fprintf(f,"%s\n",ln.c_str());
01136
01137 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01138 ln+="on_notice "+(*i5).on_notice;
01139 fprintf(f,"%s\n",ln.c_str());
01140
01141 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01142 ln+="on_except "+(*i5).on_except;
01143 fprintf(f,"%s\n",ln.c_str());
01144
01145 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01146 ln+="on_unexcept "+(*i5).on_unexcept;
01147 fprintf(f,"%s\n",ln.c_str());
01148
01149 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01150 ln+="on_invite "+(*i5).on_invite;
01151 fprintf(f,"%s\n",ln.c_str());
01152
01153 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01154 ln+="on_uninvite "+(*i5).on_uninvite;
01155 fprintf(f,"%s\n",ln.c_str());
01156
01157 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01158 ln+="on_not_invited "+(*i5).on_not_invited;
01159 fprintf(f,"%s\n",ln.c_str());
01160
01161 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01162 ln+="on_not_in_reop "+(*i5).on_not_in_reop;
01163 fprintf(f,"%s\n",ln.c_str());
01164
01165 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01166 ln+="on_reop "+(*i5).on_reop;
01167 fprintf(f,"%s\n",ln.c_str());
01168
01169 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01170 ln+="on_other_mode "+(*i5).on_other_mode;
01171 fprintf(f,"%s\n",ln.c_str());
01172
01173 char tmp1[64], tmp2[64];
01174
01175 if((*i5).msg_flood.lines==0)
01176 (*i5).msg_flood.seconds=0;
01177 if((*i5).notice_flood.lines==0)
01178 (*i5).notice_flood.seconds=0;
01179 if((*i5).repeat_flood.lines==0)
01180 (*i5).repeat_flood.seconds=0;
01181 if((*i5).nick_flood.lines==0)
01182 (*i5).nick_flood.seconds=0;
01183 if((*i5).join_flood.lines==0)
01184 (*i5).join_flood.seconds=0;
01185 if((*i5).mode_flood.lines==0)
01186 (*i5).mode_flood.seconds=0;
01187 if((*i5).ctcp_flood.lines==0)
01188 (*i5).ctcp_flood.seconds=0;
01189
01190 ltoa((*i5).msg_flood.lines,tmp1,10);
01191 ltoa((long)(*i5).msg_flood.seconds,tmp2,10);
01192 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01193 ln+=(string)"msg_flood "+tmp1+" "+tmp2;
01194 fprintf(f,"%s\n",ln.c_str());
01195
01196 ltoa((*i5).notice_flood.lines,tmp1,10);
01197 ltoa((long)(*i5).notice_flood.seconds,tmp2,10);
01198 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01199 ln+=(string)"notice_flood "+tmp1+" "+tmp2;
01200 fprintf(f,"%s\n",ln.c_str());
01201
01202 ltoa((*i5).repeat_flood.lines,tmp1,10);
01203 ltoa((long)(*i5).repeat_flood.seconds,tmp2,10);
01204 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01205 ln+=(string)"repeat_flood "+tmp1+" "+tmp2;
01206 fprintf(f,"%s\n",ln.c_str());
01207
01208 ltoa((*i5).nick_flood.lines,tmp1,10);
01209 ltoa((long)(*i5).nick_flood.seconds,tmp2,10);
01210 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01211 ln+=(string)"nick_flood "+tmp1+" "+tmp2;
01212 fprintf(f,"%s\n",ln.c_str());
01213
01214 ltoa((*i5).join_flood.lines,tmp1,10);
01215 ltoa((long)(*i5).join_flood.seconds,tmp2,10);
01216 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01217 ln+=(string)"join_flood "+tmp1+" "+tmp2;
01218 fprintf(f,"%s\n",ln.c_str());
01219
01220 ltoa((*i5).mode_flood.lines,tmp1,10);
01221 ltoa((long)(*i5).mode_flood.seconds,tmp2,10);
01222 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01223 ln+=(string)"mode_flood "+tmp1+" "+tmp2;
01224 fprintf(f,"%s\n",ln.c_str());
01225
01226 ltoa((*i5).ctcp_flood.lines,tmp1,10);
01227 ltoa((long)(*i5).ctcp_flood.seconds,tmp2,10);
01228 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01229 ln+=(string)"ctcp_flood "+tmp1+" "+tmp2;
01230 fprintf(f,"%s\n",ln.c_str());
01231
01232 vector<s_dynamic_rule>::iterator i8;
01233 for(i8=(*i5).allow_dynamic.begin(); i8!=(*i5).allow_dynamic.end(); i8++) {
01234 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01235 ln+="allow_dynamic ";
01236 ln+=(*i8).group;
01237 ln+=" ";
01238 ln+=(*i8).plus_modes;
01239 ln+=" ";
01240 ln+=(*i8).minus_modes;
01241 fprintf(f,"%s\n",ln.c_str());
01242 }
01243
01244 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01245 ln+=(string)"dynamic1 "+(*i5).dynamic_plus_modes;
01246 fprintf(f,"%s\n",ln.c_str());
01247
01248 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01249 ln+=(string)"dynamic2 "+(*i5).dynamic_minus_modes;
01250 fprintf(f,"%s\n",ln.c_str());
01251
01252 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01253 ln+=(string)"can_send_unknown_users "+((*i5).can_send_unknown_users?"1":"0");
01254 fprintf(f,"%s\n",ln.c_str());
01255
01256 indent-=4;
01257 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01258 ln+="}";
01259 fprintf(f,"%s\n",ln.c_str());
01260 }
01261 }
01262 indent-=4;
01263 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01264 ln+="}";
01265 fprintf(f,"%s\n",ln.c_str());
01266 }
01267 }
01268
01269 vector<s_channel_def>::iterator i3;
01270 for(i3=r_channel_defs.begin(); i3!=r_channel_defs.end(); i3++) {
01271
01272 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01273 ln+=(string)"channel \""+(*i3).channel_name+"\"";
01274 fprintf(f,"%s\n",ln.c_str());
01275
01276 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01277 ln+="{";
01278 fprintf(f,"%s\n",ln.c_str());
01279 indent+=4;
01280
01281 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01282 ln+="last_changed ";
01283 char tmp[64];
01284 ltoa((long)(*i3).last_changed,tmp,10);
01285 ln+=tmp;
01286 fprintf(f,"%s\n",ln.c_str());
01287
01288 vector<s_group>::iterator i5;
01289 for(i5=(*i3).groups.begin(); i5!=(*i3).groups.end(); i5++) {
01290 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01291 ln+=(string)"member_of_group "+(*i5).name;
01292 fprintf(f,"%s\n",ln.c_str());
01293 }
01294
01295 vector<s_replication>::iterator i7;
01296 for(i7=(*i3).replication.begin(); i7!=(*i3).replication.end(); i7++) {
01297 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01298 string type;
01299 if((*i7).type==REPL_PUSH)
01300 type="push";
01301 if((*i7).type==REPL_PULL)
01302 type="pull";
01303 if((*i7).type==REPL_PUSHPULL)
01304 type="pushpull";
01305 ln+=(string)"replication "+(*i7).partner+" "+type;
01306 fprintf(f,"%s\n",ln.c_str());
01307 }
01308
01309 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01310 ln+="on_mode "+(*i3).on_mode;
01311 fprintf(f,"%s\n",ln.c_str());
01312
01313 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01314 ln+="on_key "+(*i3).on_key;
01315 fprintf(f,"%s\n",ln.c_str());
01316
01317 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01318 ln+="on_limit "+(*i3).on_limit;
01319 fprintf(f,"%s\n",ln.c_str());
01320
01321 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01322 ln+="on_topic "+(*i3).on_topic;
01323 fprintf(f,"%s\n",ln.c_str());
01324
01325 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01326 ln+="on_ircop "+(*i3).on_ircop;
01327 fprintf(f,"%s\n",ln.c_str());
01328
01329 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01330 ln+="on_ctcp "+(*i3).on_ctcp;
01331 fprintf(f,"%s\n",ln.c_str());
01332
01333 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01334 ln+="on_privmsg "+(*i3).on_privmsg;
01335 fprintf(f,"%s\n",ln.c_str());
01336
01337 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01338 ln+="on_notice "+(*i3).on_notice;
01339 fprintf(f,"%s\n",ln.c_str());
01340
01341 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01342 ln+="on_part "+(*i3).on_part;
01343 fprintf(f,"%s\n",ln.c_str());
01344
01345 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01346 ln+="on_dynamic_ban "+(*i3).on_dynamic_ban;
01347 fprintf(f,"%s\n",ln.c_str());
01348
01349 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01350 ln+="on_server_msg "+(*i3).on_server_msg;
01351 fprintf(f,"%s\n",ln.c_str());
01352
01353 {
01354 vector<string>::iterator i1;
01355 for(i1=(*i3).keys.begin(); i1!=(*i3).keys.end(); i1++) {
01356 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01357 ln+=(string)"key "+(*i1);
01358 fprintf(f,"%s\n",ln.c_str());
01359 }
01360 }
01361
01362 {
01363 map<string,string>::iterator i1;
01364 for(i1=(*i3).dynamic_bans.begin(); i1!=(*i3).dynamic_bans.end(); i1++) {
01365 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01366 ln+=(string)"dynamic_ban "+(*i1).first+" "+(*i1).second;
01367 fprintf(f,"%s\n",ln.c_str());
01368 }
01369 }
01370
01371 {
01372 vector<string>::iterator i1;
01373 for(i1=(*i3).dynbans_editors.begin(); i1!=(*i3).dynbans_editors.end(); i1++) {
01374 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01375 ln+=(string)"partyline_dynbans_editors "+(*i1);
01376 fprintf(f,"%s\n",ln.c_str());
01377 }
01378 }
01379
01380 vector<s_dynamic_rule>::iterator i8;
01381 for(i8=(*i3).allow_dynamic.begin(); i8!=(*i3).allow_dynamic.end(); i8++) {
01382 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01383 ln+="allow_dynamic ";
01384 ln+=(*i8).group;
01385 ln+=" ";
01386 ln+=(*i8).plus_modes;
01387 ln+=" ";
01388 ln+=(*i8).minus_modes;
01389 fprintf(f,"%s\n",ln.c_str());
01390 }
01391
01392 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01393 ln+=(string)"dynamic1 "+(*i3).dynamic_plus_modes;
01394 fprintf(f,"%s\n",ln.c_str());
01395
01396 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01397 ln+=(string)"dynamic2 "+(*i3).dynamic_minus_modes;
01398 fprintf(f,"%s\n",ln.c_str());
01399
01400 indent-=4;
01401 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01402 ln+="}";
01403 fprintf(f,"%s\n",ln.c_str());
01404 }
01405
01406 {
01407 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01408 ln+=(string)"private";
01409 fprintf(f,"%s\n",ln.c_str());
01410
01411 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01412 ln+="{";
01413 fprintf(f,"%s\n",ln.c_str());
01414 indent+=4;
01415
01416 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01417 ln+="last_changed ";
01418 char tmp[64];
01419 ltoa((long)r_private.last_changed,tmp,10);
01420 ln+=tmp;
01421 fprintf(f,"%s\n",ln.c_str());
01422
01423 vector<s_group>::iterator i5;
01424 for(i5=r_private.groups.begin(); i5!=r_private.groups.end(); i5++) {
01425 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01426 ln+=(string)"member_of_group "+(*i5).name;
01427 fprintf(f,"%s\n",ln.c_str());
01428 }
01429
01430 vector<s_replication>::iterator i7;
01431 for(i7=r_private.replication.begin(); i7!=r_private.replication.end(); i7++) {
01432 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01433 string type;
01434 if((*i7).type==REPL_PUSH)
01435 type="push";
01436 if((*i7).type==REPL_PULL)
01437 type="pull";
01438 if((*i7).type==REPL_PUSHPULL)
01439 type="pushpull";
01440 ln+=(string)"replication "+(*i7).partner+" "+type;
01441 fprintf(f,"%s\n",ln.c_str());
01442 }
01443
01444 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01445 ln+="on_privmsg "+r_private.on_privmsg;
01446 fprintf(f,"%s\n",ln.c_str());
01447
01448 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01449 ln+="on_notice "+r_private.on_notice;
01450 fprintf(f,"%s\n",ln.c_str());
01451
01452 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01453 ln+="on_ctcp "+r_private.on_ctcp;
01454 fprintf(f,"%s\n",ln.c_str());
01455
01456 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01457 ln+="on_filesys_got_new "+r_private.on_filesys_got_new;
01458 fprintf(f,"%s\n",ln.c_str());
01459
01460 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01461 ln+="on_fnc "+r_private.on_fnc;
01462 fprintf(f,"%s\n",ln.c_str());
01463
01464 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01465 ln+="on_broadcast "+r_private.on_broadcast;
01466 fprintf(f,"%s\n",ln.c_str());
01467
01468 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01469 ln+="on_server_msg "+r_private.on_server_msg;
01470 fprintf(f,"%s\n",ln.c_str());
01471
01472 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01473 ln+="on_internal_event "+r_private.on_internal_event;
01474 fprintf(f,"%s\n",ln.c_str());
01475
01476 indent-=4;
01477 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01478 ln+="}";
01479 fprintf(f,"%s\n",ln.c_str());
01480 }
01481
01482 vector<s_procedure>::iterator i2;
01483 for(i2=r_procedures.begin(); i2!=r_procedures.end(); i2++) {
01484
01485 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01486 ln+=(string)"procedure "+(*i2).name;
01487 fprintf(f,"%s\n",ln.c_str());
01488
01489 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01490 ln+="{";
01491 fprintf(f,"%s\n",ln.c_str());
01492 indent+=4;
01493
01494 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01495 ln+="last_changed ";
01496 char tmp[64];
01497 ltoa((long)(*i2).last_changed,tmp,10);
01498 ln+=tmp;
01499 fprintf(f,"%s\n",ln.c_str());
01500
01501 vector<s_group>::iterator i5;
01502 for(i5=(*i2).groups.begin(); i5!=(*i2).groups.end(); i5++) {
01503 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01504 ln+=(string)"member_of_group "+(*i5).name;
01505 fprintf(f,"%s\n",ln.c_str());
01506 }
01507
01508 vector<s_replication>::iterator i7;
01509 for(i7=(*i2).replication.begin(); i7!=(*i2).replication.end(); i7++) {
01510 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01511 string type;
01512 if((*i7).type==REPL_PUSH)
01513 type="push";
01514 if((*i7).type==REPL_PULL)
01515 type="pull";
01516 if((*i7).type==REPL_PUSHPULL)
01517 type="pushpull";
01518 ln+=(string)"replication "+(*i7).partner+" "+type;
01519 fprintf(f,"%s\n",ln.c_str());
01520 }
01521
01522 vector<s_rproc>::iterator i_rproc;
01523 for(i_rproc=(*i2).rproc.begin(); i_rproc!=(*i2).rproc.end(); i_rproc++) {
01524 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01525 ln+=(string)"remote_bot_call "+(*i_rproc).remote_bot;
01526 fprintf(f,"%s\n",ln.c_str());
01527 }
01528
01529 string name;
01530 for(unsigned int i7=0; i7<(*i2).name.length(); i7++) {
01531 if((*i2).name[i7]==0x20)
01532 break;
01533 name+=(*i2).name[i7];
01534 }
01535
01536 list<string> commands;
01537 vector<string> groups;
01538 logic_list_proc(name,commands,(*i2).name,groups);
01539 list<string>::iterator i6;
01540 for(i6=commands.begin(); i6!=commands.end(); i6++)
01541 fprintf(f,"%s\n",(*i6).c_str());
01542
01543 indent-=4;
01544 }
01545
01546 {
01547 fprintf(f,"groups\n");
01548
01549 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01550 ln+="{";
01551 fprintf(f,"%s\n",ln.c_str());
01552 indent+=4;
01553
01554 vector<string> got;
01555
01556 vector<s_group>::iterator i1;
01557 for(i1=r_all_groups.begin(); i1!=r_all_groups.end(); i1++) {
01558 if((*i1).name.empty())
01559 continue;
01560 vector<string>::iterator i2;
01561 for(i2=got.begin(); i2!=got.end(); i2++)
01562 if(!(*i1).name.compare(*i2))
01563 goto skip;
01564
01565 got.push_back((*i1).name);
01566
01567 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01568 ln+=(*i1).name;
01569 fprintf(f,"%s\n",ln.c_str());
01570 skip:
01571 ;
01572 }
01573
01574 indent-=4;
01575 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
01576 ln+="}";
01577 fprintf(f,"%s\n",ln.c_str());
01578 }
01579
01580 fclose(f);
01581 }
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593 int logic_cmp_strings_case_insensitive(string s1, string s2)
01594 {
01595 return cmp_strings_case_insensitive(s1,s2);
01596 }
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607 string logic_process_line_get_string(unsigned int &pos, string ln)
01608 {
01609 string res;
01610 bool in_string=false;
01611 for(; pos<ln.length(); pos++) {
01612 if(ln[pos]=='\"' && (pos==0 || (pos>0 && ln[pos-1]!='\\'))) {
01613 res+=ln[pos];
01614 in_string=!in_string;
01615 continue;
01616 }
01617 if(ln[pos]==0x20 && !in_string) {
01618 pos++;
01619 return res;
01620 }
01621 res+=ln[pos];
01622 }
01623 return res;
01624 }
01625
01626 int logic_get_priority(string class_)
01627 {
01628 if(!class_.compare("HIGH"))
01629 return HIGH_PRIORITY;
01630 if(!class_.compare("LOW"))
01631 return LOW_PRIORITY;
01632 if(!class_.compare("CRITICAL"))
01633 return CRITICAL_PRIORITY;
01634 return 0;
01635 }
01636
01637 string logic_set_priority(int priority)
01638 {
01639 switch(priority) {
01640 case LOW_PRIORITY:
01641 return "LOW";
01642 case HIGH_PRIORITY:
01643 return "HIGH";
01644 case CRITICAL_PRIORITY:
01645 return "CRITICAL";
01646 default:
01647 return "LOW";
01648 }
01649 }
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686 bool logic_process_line(string ln, const char* &error_reason, int& error_line, bool& b_user2, s_user& user, bool& b_channel, s_channel& channel, bool& b_user, int& i_brackets, bool& b_proc, s_procedure& procedure, list<s_lines>& lines, bool& b_smtp, s_smtp& smtp, bool& b_smtp_data, vector<s_procedure>& procedures, vector<s_user>& users, vector<s_channel>& channels, s_channel_def& chan, vector<s_channel_def>& channel_defs, bool& b_chan, vector<s_group>& all_groups, bool& b_groups, bool& b_prv, s_private& prv, vector<s_user>& terminators)
01687 {
01688 if(!ln.compare((string)""))
01689 return false;
01690
01691 string token;
01692 string result;
01693 for(unsigned int i1=0; i1<ln.length()+1; i1++) {
01694 unsigned int i2;
01695 if(i1<ln.length() && ln[i1]=='=') {
01696 result=token;
01697 token="";
01698 continue;
01699 }
01700 if(i1<ln.length() && ln[i1]!=0x20)
01701 token+=ln[i1];
01702 else {
01703 if((!token.compare((string)"user") || !token.compare((string)"user_template")) && !b_chan) {
01704 b_user=true;
01705 b_channel=false;
01706
01707 i1++;
01708 string name;
01709 for(i2=i1; i2<ln.length(); i2++, i1++) {
01710 if(ln[i2]==0x20 || ln[i2]=='\t') {
01711 error_reason="Name of user/group cannot contain space or TAB";
01712 return true;
01713 } else
01714 name+=ln[i2];
01715 }
01716
01717 user.name=name;
01718 user.host_unknown=false;
01719 user.host_bot=false;
01720 user.terminator=false;
01721 user.is_template=!token.compare((string)"user_template");
01722 user.hostmask.clear();
01723 user.fullname.clear();
01724 user.access_to_group.clear();
01725 user.access_to_proc.clear();
01726 user.access_usage_procedure.clear();
01727 user.access_grant_procedure.clear();
01728 user.access_grant_group.clear();
01729 user.access_to_channel.clear();
01730 user.access_grant_channel.clear();
01731 user.access_grant_partyline=false;
01732 user.access_to_backup=false;
01733 user.access_grant_backup=false;
01734 user.access_to_rehash=false;
01735 user.access_grant_rehash=false;
01736 user.access_to_plususer=false;
01737 user.access_grant_plususer=false;
01738 user.access_to_plusproc=false;
01739 user.access_grant_plusproc=false;
01740 user.access_to_replication=false;
01741 user.access_grant_replication=false;
01742 user.access_to_restart=false;
01743 user.access_grant_restart=false;
01744 user.access_to_die=false;
01745 user.access_grant_die=false;
01746 user.access_to_filesystem=false;
01747 user.access_to_can_send_all_users=false;
01748 user.access_grant_filesystem=false;
01749 user.access_to_partyline=false;
01750 user.access_to_private=false;
01751 user.access_grant_private=false;
01752 user.access_to_can_send_all_users=false;
01753 user.access_grant_can_send_all_users=false;
01754 user.access_to_can_send_unknown_users=false;
01755 user.access_grant_can_send_unknown_users=false;
01756 user.access_to_upgrade=false;
01757 user.access_grant_upgrade=false;
01758 user.access_to_apply=false;
01759 user.access_grant_apply=false;
01760 user.dcc_hosts.clear();
01761 user.groups.clear();
01762 user.replication.clear();
01763 user.last_changed=0;
01764 user.replication_partner=false;
01765 user.partyline_msg_flood.lines=0;
01766 user.partyline_msg_flood.seconds=0;
01767 user.meta.clear();
01768 b_user=false;
01769 b_user2=true;
01770
01771 return false;
01772 }
01773 if(!token.compare((string)"{") && b_user!=true && b_user2!=true && b_channel!=true && b_proc!=true && !b_chan && b_groups!=true && !b_prv) {
01774 error_reason="Unexpected '{'";
01775 return true;
01776 }
01777
01778 if(!token.compare((string)"{")) {
01779 i_brackets++;
01780 return false;
01781 }
01782
01783 if(b_user2 && !b_chan) {
01784 if(!token.compare((string)"replication")) {
01785 i1++;
01786 string partner=logic_process_line_get_string(i1,ln);
01787
01788 string type=logic_process_line_get_string(i1,ln);
01789
01790 s_replication r;
01791 r.partner=partner;
01792 r.type=REPL_INVALID;
01793 if(!type.compare("push"))
01794 r.type=REPL_PUSH;
01795 if(!type.compare("pull"))
01796 r.type=REPL_PULL;
01797 if(!type.compare("pushpull"))
01798 r.type=REPL_PUSHPULL;
01799 if(r.type==REPL_INVALID) {
01800 error_reason="Invalid replication type";
01801 return true;
01802 }
01803
01804 user.replication.push_back(r);
01805
01806 return false;
01807 }
01808
01809 if(!token.compare((string)"access_to_backup")) {
01810 i1++;
01811 string a=logic_process_line_get_string(i1,ln);
01812
01813 user.access_to_backup=atol(a.c_str())!=0;
01814
01815 return false;
01816 }
01817
01818 if(!token.compare((string)"access_grant_backup")) {
01819 i1++;
01820 string a=logic_process_line_get_string(i1,ln);
01821
01822 user.access_grant_backup=atol(a.c_str())!=0;
01823
01824 return false;
01825 }
01826
01827 if(!token.compare((string)"access_to_rehash")) {
01828 i1++;
01829 string a=logic_process_line_get_string(i1,ln);
01830
01831 user.access_to_rehash=atol(a.c_str())!=0;
01832
01833 return false;
01834 }
01835
01836 if(!token.compare((string)"access_grant_rehash")) {
01837 i1++;
01838 string a=logic_process_line_get_string(i1,ln);
01839
01840 user.access_grant_rehash=atol(a.c_str())!=0;
01841
01842 return false;
01843 }
01844
01845 if(!token.compare((string)"access_to_+user")) {
01846 i1++;
01847 string a=logic_process_line_get_string(i1,ln);
01848
01849 user.access_to_plususer=atol(a.c_str())!=0;
01850
01851 return false;
01852 }
01853
01854 if(!token.compare((string)"access_grant_+user")) {
01855 i1++;
01856 string a=logic_process_line_get_string(i1,ln);
01857
01858 user.access_grant_plususer=atol(a.c_str())!=0;
01859
01860 return false;
01861 }
01862
01863 if(!token.compare((string)"access_to_+proc")) {
01864 i1++;
01865 string a=logic_process_line_get_string(i1,ln);
01866
01867 user.access_to_plusproc=atol(a.c_str())!=0;
01868
01869 return false;
01870 }
01871
01872 if(!token.compare((string)"access_grant_+proc")) {
01873 i1++;
01874 string a=logic_process_line_get_string(i1,ln);
01875
01876 user.access_grant_plusproc=atol(a.c_str())!=0;
01877
01878 return false;
01879 }
01880
01881 if(!token.compare((string)"access_to_replication")) {
01882 i1++;
01883 string a=logic_process_line_get_string(i1,ln);
01884
01885 user.access_to_replication=atol(a.c_str())!=0;
01886
01887 return false;
01888 }
01889
01890 if(!token.compare((string)"access_grant_replication")) {
01891 i1++;
01892 string a=logic_process_line_get_string(i1,ln);
01893
01894 user.access_grant_replication=atol(a.c_str())!=0;
01895
01896 return false;
01897 }
01898
01899 if(!token.compare((string)"access_to_restart")) {
01900 i1++;
01901 string a=logic_process_line_get_string(i1,ln);
01902
01903 user.access_to_restart=atol(a.c_str())!=0;
01904
01905 return false;
01906 }
01907
01908 if(!token.compare((string)"access_grant_restart")) {
01909 i1++;
01910 string a=logic_process_line_get_string(i1,ln);
01911
01912 user.access_grant_restart=atol(a.c_str())!=0;
01913
01914 return false;
01915 }
01916
01917 if(!token.compare((string)"access_to_die")) {
01918 i1++;
01919 string a=logic_process_line_get_string(i1,ln);
01920
01921 user.access_to_die=atol(a.c_str())!=0;
01922
01923 return false;
01924 }
01925
01926 if(!token.compare((string)"access_grant_die")) {
01927 i1++;
01928 string a=logic_process_line_get_string(i1,ln);
01929
01930 user.access_grant_die=atol(a.c_str())!=0;
01931
01932 return false;
01933 }
01934
01935 if(!token.compare((string)"access_to_upgrade")) {
01936 i1++;
01937 string a=logic_process_line_get_string(i1,ln);
01938
01939 user.access_to_upgrade=atol(a.c_str())!=0;
01940
01941 return false;
01942 }
01943
01944 if(!token.compare((string)"access_grant_upgrade")) {
01945 i1++;
01946 string a=logic_process_line_get_string(i1,ln);
01947
01948 user.access_grant_upgrade=atol(a.c_str())!=0;
01949
01950 return false;
01951 }
01952
01953 if(!token.compare((string)"access_to_apply")) {
01954 i1++;
01955 string a=logic_process_line_get_string(i1,ln);
01956
01957 user.access_to_apply=atol(a.c_str())!=0;
01958
01959 return false;
01960 }
01961
01962 if(!token.compare((string)"access_grant_apply")) {
01963 i1++;
01964 string a=logic_process_line_get_string(i1,ln);
01965
01966 user.access_grant_apply=atol(a.c_str())!=0;
01967
01968 return false;
01969 }
01970
01971 if(!token.compare((string)"access_to_filesystem")) {
01972 i1++;
01973 string a=logic_process_line_get_string(i1,ln);
01974
01975 user.access_to_filesystem=atol(a.c_str())!=0;
01976
01977 return false;
01978 }
01979
01980 if(!token.compare((string)"access_to_can_send_all_users")) {
01981 i1++;
01982 string a=logic_process_line_get_string(i1,ln);
01983
01984 user.access_to_can_send_all_users=atol(a.c_str())!=0;
01985
01986 return false;
01987 }
01988
01989 if(!token.compare((string)"access_grant_can_send_all_users")) {
01990 i1++;
01991 string a=logic_process_line_get_string(i1,ln);
01992
01993 user.access_grant_can_send_all_users=atol(a.c_str())!=0;
01994
01995 return false;
01996 }
01997
01998 if(!token.compare((string)"access_to_can_send_unknown_users")) {
01999 i1++;
02000 string a=logic_process_line_get_string(i1,ln);
02001
02002 user.access_to_can_send_unknown_users=atol(a.c_str())!=0;
02003
02004 return false;
02005 }
02006
02007 if(!token.compare((string)"access_grant_can_send_unknown_users")) {
02008 i1++;
02009 string a=logic_process_line_get_string(i1,ln);
02010
02011 user.access_grant_can_send_unknown_users=atol(a.c_str())!=0;
02012
02013 return false;
02014 }
02015
02016 if(!token.compare((string)"access_grant_filesystem")) {
02017 i1++;
02018 string a=logic_process_line_get_string(i1,ln);
02019
02020 user.access_grant_filesystem=atol(a.c_str())!=0;
02021
02022 return false;
02023 }
02024
02025 if(!token.compare((string)"replication_partner")) {
02026 i1++;
02027
02028 user.replication_partner=true;
02029
02030 return false;
02031 }
02032
02033 if(!token.compare((string)"last_changed")) {
02034 i1++;
02035 string time=logic_process_line_get_string(i1,ln);
02036 user.last_changed=atol(time.c_str());
02037 return false;
02038 }
02039
02040 if(!token.compare((string)"meta")) {
02041 i1++;
02042 pair<string,string> p;
02043 p.first=logic_process_line_get_string(i1,ln);
02044 p.second=logic_process_line_get_string(i1,ln);
02045 user.meta.insert(p);
02046 return false;
02047 }
02048
02049 if(!token.compare((string)"terminator")) {
02050 i1++;
02051 string value=logic_process_line_get_string(i1,ln);
02052 user.terminator=atol(value.c_str())!=0;
02053 return false;
02054 }
02055
02056 if(!token.compare((string)"host")) {
02057 if(user.is_template) {
02058 error_reason="User template cannot have a host mask";
02059 return true;
02060 }
02061
02062 i1++;
02063 string hostmask;
02064 for(i2=i1; i2<ln.length(); i2++, i1++) {
02065 if(ln[i2]==0x20 || ln[i2]=='\t') {
02066 error_reason="Hostmask cannot contain space or TAB";
02067 return true;
02068 }
02069 hostmask+=ln[i2];
02070 }
02071 user.hostmask.push_back(hostmask);
02072
02073 {
02074 map<string,string> vars;
02075 string host=logic_eval(hostmask,vars);
02076 if(host.find("@",0)!=string::npos)
02077 host.erase(0,host.find("@",0)+1);
02078 if(host.find("*",0)==string::npos && host.find("?",0)==string::npos && host.find("/",0)==string::npos && host.find("#",0)==string::npos) {
02079 logic_resolve(host);
02080 logic_resolve6(host);
02081 }
02082 }
02083
02084 return false;
02085 }
02086
02087 if(!token.compare((string)"dcc_host")) {
02088 i1++;
02089 string dcc_group=logic_process_line_get_string(i1,ln);
02090
02091 string host=logic_process_line_get_string(i1,ln);
02092
02093 s_dcc_host h;
02094 h.group=atol(dcc_group.c_str());
02095 h.host=host;
02096
02097 user.dcc_hosts.push_back(h);
02098
02099 return false;
02100 }
02101
02102 if(!token.compare((string)"host_unknown")) {
02103 user.host_unknown=true;
02104 return false;
02105 }
02106
02107 if(!token.compare((string)"host_bot")) {
02108 user.host_bot=true;
02109 if(user.name.length()>255-1) {
02110 error_reason="Name of bot (host_bot) cannot be longer than 254 characters!";
02111 return true;
02112 }
02113 strcpy(botnet_botname,user.name.c_str());
02114 return false;
02115 }
02116
02117 if(!token.compare((string)"full_name")) {
02118 if(user.is_template) {
02119 error_reason="User template cannot have a full name";
02120 return true;
02121 }
02122 i1++;
02123 string fullname=logic_process_line_get_string(i1,ln);
02124 user.fullname.push_back(fullname);
02125 return false;
02126 }
02127
02128 if(!token.compare((string)"channel")) {
02129 i1++;
02130 string chan=logic_process_line_get_string(i1,ln);
02131 if(chan.length()>128) {
02132 error_reason="Name of channel cannot be longer than 128 characters";
02133 return true;
02134 }
02135
02136 channel.username=user.name;
02137 channel.is_template=user.is_template;
02138 channel.terminator=user.terminator;
02139 channel.channel_name=chan;
02140 channel.host_unknown=user.host_unknown;
02141 channel.groups.clear();
02142 channel.on_deop="";
02143 channel.on_ban="";
02144 channel.on_unban="";
02145 channel.on_kick="";
02146 channel.on_op="";
02147 channel.on_voice="";
02148 channel.on_devoice="";
02149 channel.on_creator="";
02150 channel.on_decreator="";
02151 channel.on_join="";
02152 channel.on_banned="";
02153 channel.on_flood="";
02154 channel.on_privmsg="";
02155 channel.on_notice="";
02156 channel.on_other_mode="";
02157
02158 channel.on_except="";
02159 channel.on_unexcept="";
02160 channel.on_invite="";
02161 channel.on_uninvite="";
02162 channel.on_not_invited="";
02163 channel.on_not_in_reop="";
02164 channel.on_reop="";
02165
02166 channel.msg_flood.lines=0;
02167 channel.notice_flood.lines=0;
02168 channel.repeat_flood.lines=0;
02169 channel.nick_flood.lines=0;
02170 channel.join_flood.lines=0;
02171 channel.mode_flood.lines=0;
02172 channel.ctcp_flood.lines=0;
02173
02174 channel.allow_dynamic.clear();
02175
02176 channel.dynamic_plus_modes="";
02177 channel.dynamic_minus_modes="";
02178
02179 channel.can_send_unknown_users=false;
02180
02181 b_channel=true;
02182 break;
02183 }
02184
02185 if(b_channel && !token.compare((string)"allow_dynamic")) {
02186 i1++;
02187 string group=logic_process_line_get_string(i1,ln);
02188
02189 string plus=logic_process_line_get_string(i1,ln);
02190
02191 string minus=logic_process_line_get_string(i1,ln);
02192
02193 s_dynamic_rule r;
02194 r.group=group;
02195 r.plus_modes=plus;
02196 r.minus_modes=minus;
02197
02198 channel.allow_dynamic.push_back(r);
02199
02200 return false;
02201 }
02202
02203 if(b_channel && !token.compare((string)"dynamic1")) {
02204 i1++;
02205 string modes=logic_process_line_get_string(i1,ln);
02206
02207 channel.dynamic_plus_modes=modes;
02208
02209 return false;
02210 }
02211
02212 if(b_channel && !token.compare((string)"dynamic2")) {
02213 i1++;
02214 string modes=logic_process_line_get_string(i1,ln);
02215
02216 channel.dynamic_minus_modes=modes;
02217
02218 return false;
02219 }
02220
02221 if(b_channel && !token.compare((string)"member_of_group")) {
02222 i1++;
02223 string grp=logic_process_line_get_string(i1,ln);
02224
02225 s_group g;
02226 g.name=grp;
02227 channel.groups.push_back(g);
02228
02229 all_groups.push_back(g);
02230
02231 break;
02232 }
02233
02234 if(!b_channel && !token.compare((string)"member_of_group")) {
02235 i1++;
02236 string grp=logic_process_line_get_string(i1,ln);
02237
02238 s_group g;
02239 g.name=grp;
02240 user.groups.push_back(g);
02241
02242 all_groups.push_back(g);
02243
02244 break;
02245 }
02246
02247 if(!token.compare((string)"on_deop")) {
02248 if(channel.on_deop.compare("")) {
02249 error_reason="Duplicate event";
02250 return true;
02251 }
02252
02253 i1++;
02254 string proc=logic_process_line_get_string(i1,ln);
02255
02256 channel.on_deop=proc;
02257
02258 break;
02259 }
02260
02261 if(!token.compare((string)"on_ban")) {
02262 if(channel.on_ban.compare("")) {
02263 error_reason="Duplicate event";
02264 return true;
02265 }
02266
02267 i1++;
02268 string proc=logic_process_line_get_string(i1,ln);
02269
02270 channel.on_ban=proc;
02271
02272 break;
02273 }
02274
02275 if(!token.compare((string)"on_unban")) {
02276 if(channel.on_unban.compare("")) {
02277 error_reason="Duplicate event";
02278 return true;
02279 }
02280
02281 i1++;
02282 string proc=logic_process_line_get_string(i1,ln);
02283
02284 channel.on_unban=proc;
02285
02286 break;
02287 }
02288
02289 if(!token.compare((string)"on_kick")) {
02290 if(channel.on_kick.compare("")) {
02291 error_reason="Duplicate event";
02292 return true;
02293 }
02294
02295 i1++;
02296 string proc=logic_process_line_get_string(i1,ln);
02297
02298 channel.on_kick=proc;
02299
02300 break;
02301 }
02302
02303 if(!token.compare((string)"on_op")) {
02304 if(channel.on_op.compare("")) {
02305 error_reason="Duplicate event";
02306 return true;
02307 }
02308
02309 i1++;
02310 string proc=logic_process_line_get_string(i1,ln);
02311
02312 channel.on_op=proc;
02313
02314 break;
02315 }
02316
02317 if(!token.compare((string)"on_voice")) {
02318 if(channel.on_voice.compare("")) {
02319 error_reason="Duplicate event";
02320 return true;
02321 }
02322
02323 i1++;
02324 string proc=logic_process_line_get_string(i1,ln);
02325
02326 channel.on_voice=proc;
02327
02328 break;
02329 }
02330
02331 if(!token.compare((string)"on_devoice")) {
02332 if(channel.on_devoice.compare("")) {
02333 error_reason="Duplicate event";
02334 return true;
02335 }
02336
02337 i1++;
02338 string proc=logic_process_line_get_string(i1,ln);
02339
02340 channel.on_devoice=proc;
02341
02342 break;
02343 }
02344
02345 if(!token.compare((string)"on_creator")) {
02346 if(channel.on_creator.compare("")) {
02347 error_reason="Duplicate event";
02348 return true;
02349 }
02350
02351 i1++;
02352 string proc=logic_process_line_get_string(i1,ln);
02353
02354 channel.on_creator=proc;
02355
02356 break;
02357 }
02358
02359 if(!token.compare((string)"on_decreator")) {
02360 if(channel.on_decreator.compare("")) {
02361 error_reason="Duplicate event";
02362 return true;
02363 }
02364
02365 i1++;
02366 string proc=logic_process_line_get_string(i1,ln);
02367
02368 channel.on_decreator=proc;
02369
02370 break;
02371 }
02372
02373 if(!token.compare((string)"on_join")) {
02374 if(channel.on_join.compare("")) {
02375 error_reason="Duplicate event";
02376 return true;
02377 }
02378
02379 i1++;
02380 string proc=logic_process_line_get_string(i1,ln);
02381
02382 channel.on_join=proc;
02383
02384 break;
02385 }
02386
02387 if(!token.compare((string)"on_banned")) {
02388 if(channel.on_banned.compare("")) {
02389 error_reason="Duplicate event";
02390 return true;
02391 }
02392
02393 i1++;
02394 string proc=logic_process_line_get_string(i1,ln);
02395
02396 channel.on_banned=proc;
02397
02398 break;
02399 }
02400
02401 if(!token.compare((string)"on_flood")) {
02402 if(channel.on_flood.compare("")) {
02403 error_reason="Duplicate event";
02404 return true;
02405 }
02406
02407 i1++;
02408 string proc=logic_process_line_get_string(i1,ln);
02409
02410 channel.on_flood=proc;
02411
02412 break;
02413 }
02414
02415 if(!token.compare((string)"on_privmsg")) {
02416 if(channel.on_privmsg.compare("")) {
02417 error_reason="Duplicate event";
02418 return true;
02419 }
02420
02421 i1++;
02422 string proc=logic_process_line_get_string(i1,ln);
02423
02424 channel.on_privmsg=proc;
02425
02426 break;
02427 }
02428
02429 if(!token.compare((string)"on_notice")) {
02430 if(channel.on_notice.compare("")) {
02431 error_reason="Duplicate event";
02432 return true;
02433 }
02434
02435 i1++;
02436 string proc=logic_process_line_get_string(i1,ln);
02437
02438 channel.on_notice=proc;
02439
02440 break;
02441 }
02442
02443 if(!token.compare((string)"on_except")) {
02444 if(channel.on_except.compare("")) {
02445 error_reason="Duplicate event";
02446 return true;
02447 }
02448
02449 i1++;
02450 string proc=logic_process_line_get_string(i1,ln);
02451
02452 channel.on_except=proc;
02453
02454 break;
02455 }
02456
02457 if(!token.compare((string)"on_unexcept")) {
02458 if(channel.on_unexcept.compare("")) {
02459 error_reason="Duplicate event";
02460 return true;
02461 }
02462
02463 i1++;
02464 string proc=logic_process_line_get_string(i1,ln);
02465
02466 channel.on_unexcept=proc;
02467
02468 break;
02469 }
02470
02471 if(!token.compare((string)"on_invite")) {
02472 if(channel.on_invite.compare("")) {
02473 error_reason="Duplicate event";
02474 return true;
02475 }
02476
02477 i1++;
02478 string proc=logic_process_line_get_string(i1,ln);
02479
02480 channel.on_invite=proc;
02481
02482 break;
02483 }
02484
02485 if(!token.compare((string)"on_uninvite")) {
02486 if(channel.on_uninvite.compare("")) {
02487 error_reason="Duplicate event";
02488 return true;
02489 }
02490
02491 i1++;
02492 string proc=logic_process_line_get_string(i1,ln);
02493
02494 channel.on_uninvite=proc;
02495
02496 break;
02497 }
02498
02499 if(!token.compare((string)"on_not_invited")) {
02500 if(channel.on_not_invited.compare("")) {
02501 error_reason="Duplicate event";
02502 return true;
02503 }
02504
02505 i1++;
02506 string proc=logic_process_line_get_string(i1,ln);
02507
02508 channel.on_not_invited=proc;
02509
02510 break;
02511 }
02512
02513 if(!token.compare((string)"on_not_in_reop")) {
02514 if(channel.on_not_in_reop.compare("")) {
02515 error_reason="Duplicate event";
02516 return true;
02517 }
02518
02519 i1++;
02520 string proc=logic_process_line_get_string(i1,ln);
02521
02522 channel.on_not_in_reop=proc;
02523
02524 break;
02525 }
02526
02527 if(!token.compare((string)"on_reop")) {
02528 if(channel.on_reop.compare("")) {
02529 error_reason="Duplicate event";
02530 return true;
02531 }
02532
02533 i1++;
02534 string proc=logic_process_line_get_string(i1,ln);
02535
02536 channel.on_reop=proc;
02537
02538 break;
02539 }
02540
02541 if(!token.compare((string)"on_other_mode")) {
02542 if(channel.on_other_mode.compare("")) {
02543 error_reason="Duplicate event";
02544 return true;
02545 }
02546
02547 i1++;
02548 string proc=logic_process_line_get_string(i1,ln);
02549
02550 channel.on_other_mode=proc;
02551
02552 break;
02553 }
02554
02555 if(!token.compare((string)"msg_flood")) {
02556 i1++;
02557 string lines=logic_process_line_get_string(i1,ln);
02558
02559 string seconds=logic_process_line_get_string(i1,ln);
02560
02561 channel.msg_flood.lines=atol(lines.c_str());
02562 channel.msg_flood.seconds=atol(seconds.c_str());
02563
02564 break;
02565 }
02566
02567 if(!token.compare((string)"notice_flood")) {
02568 i1++;
02569 string lines=logic_process_line_get_string(i1,ln);
02570
02571 string seconds=logic_process_line_get_string(i1,ln);
02572
02573 channel.notice_flood.lines=atol(lines.c_str());
02574 channel.notice_flood.seconds=atol(seconds.c_str());
02575
02576 break;
02577 }
02578
02579 if(!token.compare((string)"repeat_flood")) {
02580 i1++;
02581 string lines=logic_process_line_get_string(i1,ln);
02582
02583 string seconds=logic_process_line_get_string(i1,ln);
02584
02585 channel.repeat_flood.lines=atol(lines.c_str());
02586 channel.repeat_flood.seconds=atol(seconds.c_str());
02587
02588 break;
02589 }
02590
02591 if(!token.compare((string)"nick_flood")) {
02592 i1++;
02593 string lines=logic_process_line_get_string(i1,ln);
02594
02595 string seconds=logic_process_line_get_string(i1,ln);
02596
02597 channel.nick_flood.lines=atol(lines.c_str());
02598 channel.nick_flood.seconds=atol(seconds.c_str());
02599
02600 break;
02601 }
02602
02603 if(!token.compare((string)"join_flood")) {
02604 i1++;
02605 string lines=logic_process_line_get_string(i1,ln);
02606
02607 string seconds=logic_process_line_get_string(i1,ln);
02608
02609 channel.join_flood.lines=atol(lines.c_str());
02610 channel.join_flood.seconds=atol(seconds.c_str());
02611
02612 break;
02613 }
02614
02615 if(!token.compare((string)"mode_flood")) {
02616 i1++;
02617 string lines=logic_process_line_get_string(i1,ln);
02618
02619 string seconds=logic_process_line_get_string(i1,ln);
02620
02621 channel.mode_flood.lines=atol(lines.c_str());
02622 channel.mode_flood.seconds=atol(seconds.c_str());
02623
02624 break;
02625 }
02626
02627 if(!token.compare((string)"ctcp_flood")) {
02628 i1++;
02629 string lines=logic_process_line_get_string(i1,ln);
02630
02631 string seconds=logic_process_line_get_string(i1,ln);
02632
02633 channel.ctcp_flood.lines=atol(lines.c_str());
02634 channel.ctcp_flood.seconds=atol(seconds.c_str());
02635
02636 break;
02637 }
02638
02639 if(!token.compare((string)"can_send_unknown_users")) {
02640 i1++;
02641 string val=logic_process_line_get_string(i1,ln);
02642
02643 channel.can_send_unknown_users=atol(val.c_str())!=0;
02644
02645 break;
02646 }
02647
02648 if(!token.compare((string)"access_to_partyline") && !b_channel) {
02649 i1++;
02650 string s=logic_process_line_get_string(i1,ln);
02651 if(s.compare("0") && s.compare("1")) {
02652 error_reason="Token 'access_to_partyline' must be followed by '0' or '1'";
02653 return true;
02654 }
02655 user.access_to_partyline=!s.compare((string)"1");
02656 break;
02657 }
02658
02659 if(!token.compare((string)"access_to_private") && !b_channel) {
02660 i1++;
02661 string s=logic_process_line_get_string(i1,ln);
02662 if(s.compare("0") && s.compare("1")) {
02663 error_reason="Token 'access_to_private' must be followed by '0' or '1'";
02664 return true;
02665 }
02666 user.access_to_private=!s.compare((string)"1");
02667 break;
02668 }
02669
02670 if(!token.compare((string)"access_grant_private") && !b_channel) {
02671 i1++;
02672 string s=logic_process_line_get_string(i1,ln);
02673 if(s.compare("0") && s.compare("1")) {
02674 error_reason="Token 'access_grant_private' must be followed by '0' or '1'";
02675 return true;
02676 }
02677 user.access_grant_private=!s.compare((string)"1");
02678 break;
02679 }
02680
02681 if(!token.compare((string)"partyline_msg_flood") && !b_channel) {
02682 i1++;
02683 string lines=logic_process_line_get_string(i1,ln);
02684
02685 string seconds=logic_process_line_get_string(i1,ln);
02686
02687 user.partyline_msg_flood.lines=atol(lines.c_str());
02688 user.partyline_msg_flood.seconds=atol(seconds.c_str());
02689
02690 break;
02691 }
02692
02693 if(!token.compare((string)"access_to_group")) {
02694 i1++;
02695 string gr=logic_process_line_get_string(i1,ln);
02696 user.access_to_group.push_back(gr);
02697 return false;
02698 }
02699
02700 if(!token.compare((string)"access_grant_procedure")) {
02701 i1++;
02702 string proc=logic_process_line_get_string(i1,ln);
02703 user.access_grant_procedure.push_back(proc);
02704 return false;
02705 }
02706
02707 if(!token.compare((string)"access_usage_procedure")) {
02708 i1++;
02709 string proc=logic_process_line_get_string(i1,ln);
02710 user.access_usage_procedure.push_back(proc);
02711 return false;
02712 }
02713
02714 if(!token.compare((string)"access_grant_group")) {
02715 i1++;
02716 string gr=logic_process_line_get_string(i1,ln);
02717 user.access_grant_group.push_back(gr);
02718 return false;
02719 }
02720
02721 if(!token.compare((string)"access_to_procedure")) {
02722 i1++;
02723 string pr=logic_process_line_get_string(i1,ln);
02724 user.access_to_proc.push_back(pr);
02725 return false;
02726 }
02727
02728 if(!token.compare((string)"access_to_channel")) {
02729 i1++;
02730 string ch=logic_process_line_get_string(i1,ln);
02731 user.access_to_channel.push_back(ch);
02732 return false;
02733 }
02734
02735 if(!token.compare((string)"access_grant_channel")) {
02736 i1++;
02737 string ch=logic_process_line_get_string(i1,ln);
02738 user.access_grant_channel.push_back(ch);
02739 return false;
02740 }
02741
02742 if(!token.compare((string)"access_grant_partyline")) {
02743 i1++;
02744 string ch=logic_process_line_get_string(i1,ln);
02745 user.access_grant_partyline=!ch.compare((string)"1");
02746 return false;
02747 }
02748
02749 if(!token.compare((string)"}")) {
02750 if(i_brackets--<0) {
02751 error_reason="Unexpected '}'";
02752 return true;
02753 }
02754
02755 if(b_user2 && !b_channel) {
02756 if(!user.is_template) {
02757 if((!user.name.compare((string)"") || user.hostmask.begin()==user.hostmask.end() || user.fullname.begin()==user.fullname.end()) && !user.host_unknown) {
02758 error_reason="Username, or host mask, or full name was not specified";
02759 return true;
02760 }
02761 } else {
02762 if(!user.name.compare((string)"")) {
02763 error_reason="Username was not specified";
02764 return true;
02765 }
02766 }
02767 if(!user.terminator)
02768 users.push_back(user);
02769 else
02770 terminators.push_back(user);
02771 }
02772
02773 if(b_channel) {
02774 b_channel=false;
02775 channels.push_back(channel);
02776 } else
02777 if(b_user2)
02778 b_user2=false;
02779
02780 if(b_proc) {
02781
02782 s_command c;
02783 c.command=_label;
02784 c.line=error_line;
02785
02786 procedure.commands.push_back(c);
02787
02788 list<s_lines>::reverse_iterator i;
02789 i=lines.rbegin();
02790 i++;
02791
02792 list<s_command>::iterator i2;
02793 for(i2=procedure.commands.begin(); i2!=procedure.commands.end(); i2++)
02794 if((*i).line==(*i2).line) {
02795 (*i2)._goto_line=error_line;
02796 }
02797
02798 lines.pop_back();
02799 }
02800
02801 return false;
02802 }
02803 }
02804
02805 if(!token.compare((string)"procedure") && !b_chan) {
02806 i1++;
02807 string proc=logic_process_line_get_string(i1,ln);
02808
02809 {
02810 string n1=proc;
02811 if(n1.find("(",0)!=string::npos)
02812 n1.erase(n1.find("(",0),n1.length()-n1.find("(",0));
02813 vector<s_procedure>::iterator i1;
02814 for(i1=procedures.begin(); i1!=procedures.end(); i1++) {
02815 string n2=(*i1).name;
02816 if(n2.find("(",0)!=string::npos)
02817 n2.erase(n2.find("(",0),n2.length()-n2.find("(",0));
02818 if(!n1.compare(n2)) {
02819 error_reason="Procedure already defined";
02820 return true;
02821 }
02822 }
02823 }
02824
02825 procedure.name=proc;
02826 procedure.commands.clear();
02827 procedure.groups.clear();
02828 procedure.replication.clear();
02829 procedure.last_changed=0;
02830 procedure.minimal_botnet_version=1;
02831 procedure.rproc.clear();
02832
02833 b_proc=true;
02834 break;
02835 }
02836
02837 if(b_proc && !b_smtp && !b_chan) {
02838 if(!token.compare((string)"replication")) {
02839 i1++;
02840 string partner=logic_process_line_get_string(i1,ln);
02841
02842 string type=logic_process_line_get_string(i1,ln);
02843
02844 s_replication r;
02845 r.partner=partner;
02846 r.type=REPL_INVALID;
02847 if(!type.compare("push"))
02848 r.type=REPL_PUSH;
02849 if(!type.compare("pull"))
02850 r.type=REPL_PULL;
02851 if(!type.compare("pushpull"))
02852 r.type=REPL_PUSHPULL;
02853 if(r.type==REPL_INVALID) {
02854 error_reason="Invalid replication type";
02855 return true;
02856 }
02857
02858 procedure.replication.push_back(r);
02859
02860 return false;
02861 }
02862
02863 if(!token.compare((string)"remote_bot_call")) {
02864 i1++;
02865 string partner=logic_process_line_get_string(i1,ln);
02866
02867 s_rproc r;
02868 r.remote_bot=partner;
02869
02870 procedure.rproc.push_back(r);
02871
02872 procedure.minimal_botnet_version=3;
02873
02874 return false;
02875 }
02876
02877 if(!token.compare((string)"last_changed")) {
02878 i1++;
02879 string time=logic_process_line_get_string(i1,ln);
02880 procedure.last_changed=atol(time.c_str());
02881 return false;
02882 }
02883
02884 if(!token.compare((string)"link")) {
02885 i1++;
02886 string type=logic_process_line_get_string(i1,ln);
02887
02888 string botname=logic_process_line_get_string(i1,ln);
02889
02890 string local=logic_process_line_get_string(i1,ln);
02891
02892 string ip=logic_process_line_get_string(i1,ln);
02893
02894 string port=logic_process_line_get_string(i1,ln);
02895
02896 string unlink_proc=logic_process_line_get_string(i1,ln);
02897
02898 s_command c;
02899 c.command=_link;
02900 c.botname=botname;
02901 c.botlocalip=local;
02902 c.botip=ip;
02903 c.botport=(unsigned short)atol(port.c_str());
02904
02905 c.botlinktype="";
02906 if(!type.compare("telnet"))
02907 c.botlinktype="telnet";
02908 if(!type.compare("telnet_ssl"))
02909 c.botlinktype="telnet_ssl";
02910
02911 if(!c.botlinktype.compare("")) {
02912 error_reason="Invalid link type (telnet and telnet_ssl are only supported yet)";
02913 return true;
02914 }
02915
02916 c.botunlinkproc=unlink_proc;
02917
02918 map<string,string> vars;
02919 if(!c.botport)
02920 c.botport=4444;
02921
02922 procedure.commands.push_back(c);
02923
02924 break;
02925 }
02926
02927 if(!token.compare((string)"chan_mode")) {
02928 i1++;
02929 string priority=logic_process_line_get_string(i1,ln);
02930
02931 string chan=logic_process_line_get_string(i1,ln);
02932
02933 string mode=logic_process_line_get_string(i1,ln);
02934
02935 s_command c;
02936 c.command=_chan_mode;
02937 c.channel=chan;
02938 c.chan_mode=mode;
02939 if((c.priority=logic_get_priority(priority.c_str()))==0) {
02940 error_reason="Unknown priority class";
02941 return true;
02942 }
02943
02944 procedure.commands.push_back(c);
02945
02946 break;
02947 }
02948
02949 if(!token.compare((string)"member_of_group")) {
02950 i1++;
02951 string grp=logic_process_line_get_string(i1,ln);
02952
02953 s_group g;
02954 g.name=grp;
02955 procedure.groups.push_back(g);
02956
02957 all_groups.push_back(g);
02958
02959 break;
02960 }
02961
02962 if(!token.compare((string)"op")) {
02963 i1++;
02964 string priority=logic_process_line_get_string(i1,ln);
02965
02966 string chan=logic_process_line_get_string(i1,ln);
02967
02968 string nick=logic_process_line_get_string(i1,ln);
02969
02970 s_command c;
02971 c.whom=nick;
02972 c.command=_op;
02973 c.msg_text="";
02974 c.channel=chan;
02975 if((c.priority=logic_get_priority(priority.c_str()))==0) {
02976 error_reason="Unknown priority class";
02977 return true;
02978 }
02979
02980 procedure.commands.push_back(c);
02981
02982 break;
02983 }
02984
02985 if(!token.compare((string)"deop")) {
02986 i1++;
02987 string priority=logic_process_line_get_string(i1,ln);
02988
02989 string chan=logic_process_line_get_string(i1,ln);
02990
02991 string nick=logic_process_line_get_string(i1,ln);
02992
02993 s_command c;
02994 c.whom=nick;
02995 c.command=_deop;
02996 c.msg_text="";
02997 c.channel=chan;
02998 if((c.priority=logic_get_priority(priority.c_str()))==0) {
02999 error_reason="Unknown priority class";
03000 return true;
03001 }
03002
03003 procedure.commands.push_back(c);
03004
03005 break;
03006 }
03007
03008 if(!token.compare((string)"ban_mask")) {
03009 i1++;
03010 string chan=logic_process_line_get_string(i1,ln);
03011
03012 string mask=logic_process_line_get_string(i1,ln);
03013
03014 s_command c;
03015 c.whom=mask;
03016 c.command=_ban_mask;
03017 c.msg_text="";
03018 c.channel=chan;
03019
03020 procedure.commands.push_back(c);
03021
03022 break;
03023 }
03024
03025 if(!token.compare((string)"unban_mask")) {
03026 i1++;
03027 string chan=logic_process_line_get_string(i1,ln);
03028
03029 string mask=logic_process_line_get_string(i1,ln);
03030
03031 s_command c;
03032 c.whom=mask;
03033 c.command=_unban_mask;
03034 c.msg_text="";
03035 c.channel=chan;
03036
03037 procedure.commands.push_back(c);
03038
03039 break;
03040 }
03041
03042 if(!token.compare((string)"voice")) {
03043 i1++;
03044 string priority=logic_process_line_get_string(i1,ln);
03045
03046 string chan=logic_process_line_get_string(i1,ln);
03047
03048 string nick=logic_process_line_get_string(i1,ln);
03049
03050 s_command c;
03051 c.whom=nick;
03052 c.command=_voice;
03053 c.msg_text="";
03054 c.channel=chan;
03055 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03056 error_reason="Unknown priority class";
03057 return true;
03058 }
03059
03060 procedure.commands.push_back(c);
03061
03062 break;
03063 }
03064
03065 if(!token.compare((string)"devoice")) {
03066 i1++;
03067 string priority=logic_process_line_get_string(i1,ln);
03068
03069 string chan=logic_process_line_get_string(i1,ln);
03070
03071 string nick=logic_process_line_get_string(i1,ln);
03072
03073 s_command c;
03074 c.whom=nick;
03075 c.command=_devoice;
03076 c.msg_text="";
03077 c.channel=chan;
03078 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03079 error_reason="Unknown priority class";
03080 return true;
03081 }
03082
03083 procedure.commands.push_back(c);
03084
03085 break;
03086 }
03087
03088 if(!token.compare((string)"kick")) {
03089 i1++;
03090 string chan=logic_process_line_get_string(i1,ln);
03091
03092 string nick=logic_process_line_get_string(i1,ln);
03093
03094 string msg=logic_process_line_get_string(i1,ln);
03095
03096 s_command c;
03097 c.whom=nick;
03098 c.command=_kick;
03099 c.msg_text=msg;
03100 c.channel=chan;
03101
03102 procedure.commands.push_back(c);
03103
03104 break;
03105 }
03106
03107 if(!token.compare((string)"msg")) {
03108 i1++;
03109 string priority=logic_process_line_get_string(i1,ln);
03110
03111 string cmd=logic_process_line_get_string(i1,ln);
03112
03113 string msg=logic_process_line_get_string(i1,ln);
03114
03115 s_command c;
03116 c.whom=cmd;
03117 c.command=_msg;
03118 c.msg_text=msg;
03119 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03120 error_reason="Unknown priority class";
03121 return true;
03122 }
03123
03124 procedure.commands.push_back(c);
03125
03126 break;
03127 }
03128
03129 if(!token.compare((string)"msgq")) {
03130 i1++;
03131 string priority=logic_process_line_get_string(i1,ln);
03132
03133 string cmd=logic_process_line_get_string(i1,ln);
03134
03135 string msg=logic_process_line_get_string(i1,ln);
03136
03137 string msg2=logic_process_line_get_string(i1,ln);
03138
03139 s_command c;
03140 c.whom=cmd;
03141 c.command=_msgq;
03142 c.msg_text=msg;
03143 c.msg_quoted=msg2;
03144 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03145 error_reason="Unknown priority class";
03146 return true;
03147 }
03148
03149 procedure.commands.push_back(c);
03150
03151 break;
03152 }
03153
03154 if(!token.compare((string)"notice")) {
03155 i1++;
03156 string priority=logic_process_line_get_string(i1,ln);
03157
03158 string cmd=logic_process_line_get_string(i1,ln);
03159
03160 string msg=logic_process_line_get_string(i1,ln);
03161
03162 s_command c;
03163 c.whom=cmd;
03164 c.command=_notice;
03165 c.msg_text=msg;
03166 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03167 error_reason="Unknown priority class";
03168 return true;
03169 }
03170
03171 procedure.commands.push_back(c);
03172
03173 break;
03174 }
03175
03176 if(!token.compare((string)"noticeq")) {
03177 i1++;
03178 string priority=logic_process_line_get_string(i1,ln);
03179
03180 string cmd=logic_process_line_get_string(i1,ln);
03181
03182 string msg=logic_process_line_get_string(i1,ln);
03183
03184 string msg2=logic_process_line_get_string(i1,ln);
03185
03186 s_command c;
03187 c.whom=cmd;
03188 c.command=_noticeq;
03189 c.msg_text=msg;
03190 c.msg_quoted=msg2;
03191 if((c.priority=logic_get_priority(priority.c_str()))==0) {
03192 error_reason="Unknown priority class";
03193 return true;
03194 }
03195
03196 procedure.commands.push_back(c);
03197
03198 break;
03199 }
03200
03201 if(!token.compare((string)"if_in")) {
03202 i1++;
03203 string left=logic_process_line_get_string(i1,ln);
03204
03205 string right=logic_process_line_get_string(i1,ln);
03206
03207 s_command c;
03208 c.whom="";
03209 c.command=_if_in;
03210 c.msg_text="";
03211 c.left=left;
03212 c.right=right;
03213
03214 s_lines l;
03215 l.proc_name=procedure.name;
03216 l.line=error_line;
03217 c.line=error_line;
03218 lines.push_back(l);
03219
03220 procedure.commands.push_back(c);
03221
03222 break;
03223 }
03224
03225 if(!token.compare((string)"!if_in")) {
03226 i1++;
03227 string left=logic_process_line_get_string(i1,ln);
03228
03229 string right=logic_process_line_get_string(i1,ln);
03230
03231 s_command c;
03232 c.whom="";
03233 c.command=_if_n_in;
03234 c.msg_text="";
03235 c.left=left;
03236 c.right=right;
03237
03238 s_lines l;
03239 l.proc_name=procedure.name;
03240 l.line=error_line;
03241 c.line=error_line;
03242 lines.push_back(l);
03243
03244 procedure.commands.push_back(c);
03245
03246 break;
03247 }
03248
03249 if(!token.compare((string)"if_match")) {
03250 i1++;
03251 string left=logic_process_line_get_string(i1,ln);
03252
03253 string right=logic_process_line_get_string(i1,ln);
03254
03255 s_command c;
03256 c.whom="";
03257 c.command=_if_match;
03258 c.msg_text="";
03259 c.left=left;
03260 c.right=right;
03261
03262 s_lines l;
03263 l.proc_name=procedure.name;
03264 l.line=error_line;
03265 c.line=error_line;
03266 lines.push_back(l);
03267
03268 procedure.commands.push_back(c);
03269
03270 break;
03271 }
03272
03273 if(!token.compare((string)"!if_match")) {
03274 i1++;
03275 string left=logic_process_line_get_string(i1,ln);
03276
03277 string right=logic_process_line_get_string(i1,ln);
03278
03279 s_command c;
03280 c.whom="";
03281 c.command=_if_n_match;
03282 c.msg_text="";
03283 c.left=left;
03284 c.right=right;
03285
03286 s_lines l;
03287 l.proc_name=procedure.name;
03288 l.line=error_line;
03289 c.line=error_line;
03290 lines.push_back(l);
03291
03292 procedure.commands.push_back(c);
03293
03294 break;
03295 }
03296
03297 if(!token.compare((string)"if_match_case_insensitive")) {
03298 i1++;
03299 string left=logic_process_line_get_string(i1,ln);
03300
03301 string right=logic_process_line_get_string(i1,ln);
03302
03303 s_command c;
03304 c.whom="";
03305 c.command=_if_match_case_insensitive;
03306 c.msg_text="";
03307 c.left=left;
03308 c.right=right;
03309
03310 s_lines l;
03311 l.proc_name=procedure.name;
03312 l.line=error_line;
03313 c.line=error_line;
03314 lines.push_back(l);
03315
03316 procedure.commands.push_back(c);
03317
03318 break;
03319 }
03320
03321 if(!token.compare((string)"!if_match_case_insensitive")) {
03322 i1++;
03323 string left=logic_process_line_get_string(i1,ln);
03324
03325 string right=logic_process_line_get_string(i1,ln);
03326
03327 s_command c;
03328 c.whom="";
03329 c.command=_if_n_match_case_insensitive;
03330 c.msg_text="";
03331 c.left=left;
03332 c.right=right;
03333
03334 s_lines l;
03335 l.proc_name=procedure.name;
03336 l.line=error_line;
03337 c.line=error_line;
03338 lines.push_back(l);
03339
03340 procedure.commands.push_back(c);
03341
03342 break;
03343 }
03344
03345 if(!token.compare((string)"if_group")) {
03346 i1++;
03347 string left=logic_process_line_get_string(i1,ln);
03348
03349 string right=logic_process_line_get_string(i1,ln);
03350
03351 s_command c;
03352 c.whom="";
03353 c.command=_if_group;
03354 c.msg_text="";
03355 c.left=left;
03356 c.right=right;
03357
03358 s_lines l;
03359 l.proc_name=procedure.name;
03360 l.line=error_line;
03361 c.line=error_line;
03362 lines.push_back(l);
03363
03364 procedure.commands.push_back(c);
03365
03366 break;
03367 }
03368
03369 if(!token.compare((string)"!if_group")) {
03370 i1++;
03371 string left=logic_process_line_get_string(i1,ln);
03372
03373 string right=logic_process_line_get_string(i1,ln);
03374
03375 s_command c;
03376 c.whom="";
03377 c.command=_if_n_group;
03378 c.msg_text="";
03379 c.left=left;
03380 c.right=right;
03381
03382 s_lines l;
03383 l.proc_name=procedure.name;
03384 l.line=error_line;
03385 c.line=error_line;
03386 lines.push_back(l);
03387
03388 procedure.commands.push_back(c);
03389
03390 break;
03391 }
03392
03393 if(!token.compare((string)"wait_if_error")) {
03394 s_command c;
03395 c.command=_wait;
03396
03397 s_lines l;
03398 l.proc_name=procedure.name;
03399 l.line=error_line;
03400 c.line=error_line;
03401 lines.push_back(l);
03402
03403 procedure.commands.push_back(c);
03404
03405 break;
03406 }
03407
03408 if(!token.compare((string)"if_error")) {
03409 s_command c;
03410 c.command=_if_error;
03411
03412 s_lines l;
03413 l.proc_name=procedure.name;
03414 l.line=error_line;
03415 c.line=error_line;
03416 lines.push_back(l);
03417
03418 procedure.commands.push_back(c);
03419
03420 break;
03421 }
03422
03423 if(!token.compare((string)"return")) {
03424 s_command c;
03425 c.command=_return;
03426
03427 procedure.commands.push_back(c);
03428
03429 break;
03430 }
03431
03432 if(!token.compare((string)"work")) {
03433 s_command c;
03434 c.command=_work;
03435
03436 procedure.commands.push_back(c);
03437
03438 break;
03439 }
03440
03441 if(!token.compare((string)"timer_once") || !token.compare((string)"timer_every")) {
03442 i1++;
03443 string name=logic_process_line_get_string(i1,ln);
03444
03445 string time=logic_process_line_get_string(i1,ln);
03446
03447 string proc=logic_process_line_get_string(i1,ln);
03448
03449 int t=0;
03450 int mul=1;
03451 int mul2=1;
03452 for(size_t i4=time.length()-1; (signed)i4>=0; i4--) {
03453 if(time[i4]==':') {
03454 mul2=1;
03455 if(mul==1) {
03456 mul=60;
03457 continue;
03458 }
03459 if(mul==60) {
03460 mul*=60;
03461 continue;
03462 }
03463 if(mul==60*60) {
03464 mul*=24;
03465 continue;
03466 }
03467 error_reason="Invalid time (use syntax dd:hh:mm:ss)";
03468 return true;
03469 }
03470 if(!(time[i4]>='0' && time[i4]<='9')) {
03471 error_reason="Invalid time (use syntax dd:hh:mm:ss)";
03472 return true;
03473 }
03474 t+=mul*mul2*(time[i4]-'0');
03475 mul2*=10;
03476 }
03477
03478 s_command c;
03479 c.command=(!token.compare((string)"timer_once"))?_timer_once:_timer_every;
03480 c.timer_sec=t;
03481 c.timer_cmd=proc;
03482 c.timer_name=name;
03483
03484 procedure.commands.push_back(c);
03485
03486 break;
03487 }
03488
03489 if(!token.compare((string)"execute")) {
03490 i1++;
03491 string exec=logic_process_line_get_string(i1,ln);
03492
03493 s_command c;
03494 c.command=_execute;
03495 c.exec=exec;
03496
03497 procedure.commands.push_back(c);
03498
03499 break;
03500 }
03501
03502 if(!token.compare((string)"remote_execute")) {
03503 i1++;
03504
03505 string botname=logic_process_line_get_string(i1,ln);
03506 string exec=logic_process_line_get_string(i1,ln);
03507
03508 s_command c;
03509 c.command=_remote_execute;
03510 c.exec=exec;
03511 c.botname=botname;
03512 c.result=result;
03513
03514 procedure.commands.push_back(c);
03515
03516 procedure.minimal_botnet_version=3;
03517
03518 break;
03519 }
03520
03521 if(!token.compare((string)"kill_timers")) {
03522 i1++;
03523 string name=logic_process_line_get_string(i1,ln);
03524
03525 s_command c;
03526 c.command=_kill_timers;
03527 c.timer_name=name;
03528
03529 procedure.commands.push_back(c);
03530
03531 break;
03532 }
03533
03534 if(!token.compare((string)"ident")) {
03535 i1++;
03536 string nick=logic_process_line_get_string(i1,ln);
03537
03538 s_command c;
03539 c.command=_ident;
03540 c.msg_text="";
03541 c.nick=nick;
03542 c.result=result;
03543
03544 procedure.commands.push_back(c);
03545
03546 break;
03547 }
03548
03549 if(!token.compare((string)"host")) {
03550 i1++;
03551 string nick=logic_process_line_get_string(i1,ln);
03552
03553 s_command c;
03554 c.command=_host;
03555 c.msg_text="";
03556 c.nick=nick;
03557 c.result=result;
03558
03559 procedure.commands.push_back(c);
03560
03561 break;
03562 }
03563
03564 if(!token.compare((string)"get_chan_mode")) {
03565 i1++;
03566 string chan=logic_process_line_get_string(i1,ln);
03567
03568 s_command c;
03569 c.command=_get_chan_mode;
03570 c.msg_text="";
03571 c.channel=chan;
03572 c.result=result;
03573
03574 procedure.commands.push_back(c);
03575
03576 break;
03577 }
03578
03579 if(!token.compare((string)"get_chan_topic")) {
03580 i1++;
03581 string chan=logic_process_line_get_string(i1,ln);
03582
03583 s_command c;
03584 c.command=_get_chan_topic;
03585 c.msg_text="";
03586 c.channel=chan;
03587 c.result=result;
03588
03589 procedure.commands.push_back(c);
03590
03591 break;
03592 }
03593
03594 if(!token.compare((string)"topic")) {
03595 i1++;
03596 string chan=logic_process_line_get_string(i1,ln);
03597
03598 string topic;
03599 for(i2=i1; i2<ln.length() && ln[i2]!=' '; i2++, i1++)
03600 topic+=ln[i2];
03601
03602 s_command c;
03603 c.command=_topic;
03604 c.msg_text=topic;
03605 c.channel=chan;
03606 c.result=result;
03607
03608 procedure.commands.push_back(c);
03609
03610 break;
03611 }
03612
03613 if(!token.compare((string)"SCRIPT")) {
03614 i1++;
03615 string type=logic_process_line_get_string(i1,ln);
03616
03617 string num=logic_process_line_get_string(i1,ln);
03618
03619 string chan=logic_process_line_get_string(i1,ln);
03620
03621 string params=logic_process_line_get_string(i1,ln);
03622
03623 s_command c;
03624 c.command=_script;
03625 c.script_type=type;
03626 c.script_num=atol(num.c_str());
03627 c.script_channel=chan;
03628 c.script_params=params;
03629
03630 procedure.commands.push_back(c);
03631
03632 break;
03633 }
03634
03635 if(!token.compare((string)"SMTP")) {
03636 b_smtp=true;
03637 b_smtp_data=false;
03638
03639 smtp.server="127.0.0.1";
03640 smtp.port=25;
03641 smtp.helo="";
03642 smtp.mail_from="root";
03643 smtp.rcpt_to="root";
03644 smtp.data="";
03645 smtp.data_lines.clear();
03646
03647 break;
03648 }
03649
03650 if(!token.compare((string)"NET_SEND")) {
03651 i1++;
03652 string host=logic_process_line_get_string(i1,ln);
03653
03654 string msg=logic_process_line_get_string(i1,ln);
03655
03656 s_command c;
03657 c.command=_net_send;
03658 c.net_send_host=host;
03659 c.net_send_msg=msg;
03660
03661 procedure.commands.push_back(c);
03662
03663 break;
03664 }
03665
03666 if(!token.compare((string)"LOG")) {
03667 i1++;
03668 string log=logic_process_line_get_string(i1,ln);
03669
03670 s_command c;
03671 c.command=_log;
03672 c.log=log;
03673
03674 procedure.commands.push_back(c);
03675
03676 break;
03677 }
03678
03679 if(!token.compare((string)"join")) {
03680 i1++;
03681 string ch=logic_process_line_get_string(i1,ln);
03682
03683 string key=logic_process_line_get_string(i1,ln);
03684
03685 if(key.empty())
03686 key="\"\"";
03687
03688 s_command c;
03689 c.command=_join;
03690 c.channel=ch;
03691 c.channel_key=key;
03692
03693 procedure.commands.push_back(c);
03694
03695 break;
03696 }
03697
03698 if(!token.compare((string)"part")) {
03699 i1++;
03700 string ch=logic_process_line_get_string(i1,ln);
03701
03702 string reason=logic_process_line_get_string(i1,ln);
03703
03704 s_command c;
03705 c.command=_part;
03706 c.channel=ch;
03707 c.msg_text=reason;
03708
03709 procedure.commands.push_back(c);
03710
03711 break;
03712 }
03713
03714 if(!token.compare((string)"disconnect")) {
03715 s_command c;
03716 c.command=_disconnect;
03717
03718 procedure.commands.push_back(c);
03719
03720 break;
03721 }
03722
03723 if(!token.compare((string)"irc_server")) {
03724 i1++;
03725 string cmd=logic_process_line_get_string(i1,ln);
03726
03727 string port=logic_process_line_get_string(i1,ln);
03728
03729 s_command c;
03730 c.command=_irc_server;
03731 c.server=cmd;
03732 c.port=(unsigned short)atol(port.c_str());
03733 if(c.port==0)
03734 c.port=6667;
03735
03736 procedure.commands.push_back(c);
03737
03738 break;
03739 }
03740
03741 if(!token.compare((string)"try_connect")) {
03742 i1++;
03743
03744 s_command c;
03745 c.command=_try_connect;
03746
03747 procedure.commands.push_back(c);
03748
03749 break;
03750 }
03751
03752 if(!token.compare((string)"dcc_server")) {
03753 i1++;
03754 string group=logic_process_line_get_string(i1,ln);
03755
03756 string ip=logic_process_line_get_string(i1,ln);
03757
03758 string port=logic_process_line_get_string(i1,ln);
03759
03760 string server_type=logic_process_line_get_string(i1,ln);
03761
03762 s_command c;
03763 c.group=atol(group.c_str());
03764 c.command=_dcc_server;
03765 c.server=ip;
03766 c.port=(unsigned short)atol(port.c_str());
03767 c.server_type=server_type;
03768 if(c.port==0)
03769 c.port=2010;
03770
03771 procedure.commands.push_back(c);
03772
03773 break;
03774 }
03775
03776 if(!token.compare((string)"dcc_server_ipv6")) {
03777 i1++;
03778 string group=logic_process_line_get_string(i1,ln);
03779
03780 string ip=logic_process_line_get_string(i1,ln);
03781
03782 string port=logic_process_line_get_string(i1,ln);
03783
03784 string server_type=logic_process_line_get_string(i1,ln);
03785
03786 s_command c;
03787 c.group=atol(group.c_str());
03788 c.command=_dcc_server_ipv6;
03789 c.server=ip;
03790 c.port=(unsigned short)atol(port.c_str());
03791 c.server_type=server_type;
03792 if(c.port==0)
03793 c.port=2010;
03794
03795 procedure.commands.push_back(c);
03796
03797 break;
03798 }
03799
03800 if(!token.compare((string)"telnet_server")) {
03801 i1++;
03802 string ip=logic_process_line_get_string(i1,ln);
03803
03804 string port=logic_process_line_get_string(i1,ln);
03805
03806 s_command c;
03807 c.command=_telnet_server;
03808 c.server=ip;
03809 c.port=(unsigned short)atol(port.c_str());
03810 if(c.port==0)
03811 c.port=4444;
03812
03813 procedure.commands.push_back(c);
03814
03815 break;
03816 }
03817
03818 if(!token.compare((string)"telnet_server_ipv6")) {
03819 i1++;
03820 string ip=logic_process_line_get_string(i1,ln);
03821
03822 string port=logic_process_line_get_string(i1,ln);
03823
03824 s_command c;
03825 c.command=_telnet_server_ipv6;
03826 c.server=ip;
03827 c.port=(unsigned short)atol(port.c_str());
03828 if(c.port==0)
03829 c.port=4444;
03830
03831 procedure.commands.push_back(c);
03832
03833 break;
03834 }
03835
03836 if(!token.compare((string)"bot_nick")) {
03837 s_command c;
03838
03839 i1++;
03840 unsigned int i2=i1;
03841 while(i2<ln.length()) {
03842 string nick;
03843 for(; i2<ln.length() && ln[i2]!=' '; i2++, i1++)
03844 nick+=ln[i2];
03845 i2++;
03846 if(nick.compare(""))
03847 c.bot_nick.push_back(nick);
03848 }
03849
03850 c.command=_bot_nick;
03851
03852 procedure.commands.push_back(c);
03853
03854 break;
03855 }
03856
03857 if(!token.compare((string)"change_nick")) {
03858 s_command c;
03859
03860 i1++;
03861 string nick=logic_process_line_get_string(i1,ln);
03862
03863 c.command=_change_nick;
03864 c.nick=nick;
03865
03866 procedure.commands.push_back(c);
03867
03868 break;
03869 }
03870
03871 if(!token.compare((string)"bot_ident")) {
03872 i1++;
03873 string cmd=logic_process_line_get_string(i1,ln);
03874
03875 for(i2=0; i2<cmd.length(); i2++)
03876 if(cmd[i2]==0x20) {
03877 error_reason="Ident cannot conatin space";
03878 return true;
03879 }
03880
03881 s_command c;
03882 c.command=_bot_ident;
03883 c.bot_ident=cmd;
03884
03885 procedure.commands.push_back(c);
03886
03887 break;
03888 }
03889
03890 if(!token.compare((string)"bot_ident_ipv6")) {
03891 i1++;
03892 string cmd=logic_process_line_get_string(i1,ln);
03893
03894 for(i2=0; i2<cmd.length(); i2++)
03895 if(cmd[i2]==0x20) {
03896 error_reason="Ident cannot conatin space";
03897 return true;
03898 }
03899
03900 s_command c;
03901 c.command=_bot_ident_ipv6;
03902 c.bot_ident=cmd;
03903
03904 procedure.commands.push_back(c);
03905
03906 procedure.minimal_botnet_version=4;
03907
03908 break;
03909 }
03910
03911 if(!token.compare((string)"delete_irc_servers")) {
03912 i1++;
03913 string servers=logic_process_line_get_string(i1,ln);
03914
03915 s_command c;
03916 c.command=_delete_irc_servers;
03917 c.server=servers;
03918
03919 procedure.commands.push_back(c);
03920
03921 procedure.minimal_botnet_version=6;
03922
03923 break;
03924 }
03925
03926 if(!token.compare((string)"delete_nicks")) {
03927 i1++;
03928 string nicks=logic_process_line_get_string(i1,ln);
03929
03930 s_command c;
03931 c.command=_delete_nicks;
03932 c.nick=nicks;
03933
03934 procedure.commands.push_back(c);
03935
03936 procedure.minimal_botnet_version=6;
03937
03938 break;
03939 }
03940
03941 if(!token.compare((string)"bot_fullname")) {
03942 i1++;
03943 string cmd=logic_process_line_get_string(i1,ln);
03944
03945 s_command c;
03946 c.command=_bot_fullname;
03947 c.bot_fullname=cmd;
03948
03949 procedure.commands.push_back(c);
03950
03951 break;
03952 }
03953
03954 if(!token.compare((string)"bot_auth")) {
03955 s_command c;
03956 c.command=_bot_auth;
03957
03958 procedure.commands.push_back(c);
03959
03960 break;
03961 }
03962
03963 if(!token.compare((string)"label")) {
03964 i1++;
03965 string label=logic_process_line_get_string(i1,ln);
03966
03967 s_command c;
03968 c.command=_real_label;
03969 c.label=label;
03970 c.line=error_line;
03971
03972 procedure.commands.push_back(c);
03973
03974 break;
03975 }
03976
03977 if(!token.compare((string)"goto")) {
03978 i1++;
03979 string label=logic_process_line_get_string(i1,ln);
03980
03981 s_command c;
03982 c.command=_real_goto;
03983 c._goto_line=-1;
03984 c.label=label;
03985
03986 list<s_command>::iterator i2;
03987 for(i2=procedure.commands.begin(); i2!=procedure.commands.end(); i2++)
03988 if((*i2).command==_real_label && !(*i2).label.compare(label)) {
03989 c._goto_line=(*i2).line;
03990 break;
03991 }
03992
03993 if(c._goto_line==-1) {
03994 error_reason="goto command to unknown label";
03995 return true;
03996 }
03997
03998 procedure.commands.push_back(c);
03999
04000 break;
04001 }
04002
04003 if(!token.compare((string)"allow_redirect")) {
04004 i1++;
04005 string parm=logic_process_line_get_string(i1,ln);
04006
04007 s_command c;
04008 c.command=_bot_redir;
04009 c.bot_redir=(!parm.compare((string)"0"))?false:true;
04010
04011 procedure.commands.push_back(c);
04012
04013 break;
04014 }
04015
04016 if(!token.compare((string)"sleep")) {
04017 i1++;
04018 string parm=logic_process_line_get_string(i1,ln);
04019
04020 s_command c;
04021 c.command=_sleep_;
04022 c.sleep_secs=atol(parm.c_str());
04023
04024 procedure.commands.push_back(c);
04025
04026 break;
04027 }
04028
04029 if(!token.compare((string)"dynamic_ban") && !b_chan) {
04030 i1++;
04031 string chan=logic_process_line_get_string(i1,ln);
04032
04033 string prefix=logic_process_line_get_string(i1,ln);
04034
04035 string mask=logic_process_line_get_string(i1,ln);
04036
04037 string reason=logic_process_line_get_string(i1,ln);
04038
04039 s_command c;
04040 c.command=_dynamic_ban;
04041
04042 c.channel=chan;
04043 c.ban_prefix=prefix;
04044 c.ban_mask=mask;
04045 c.ban_reason=reason;
04046
04047 procedure.commands.push_back(c);
04048
04049 break;
04050 }
04051
04052 if(!token.compare((string)"process_on_banned")) {
04053 i1++;
04054 string chan=logic_process_line_get_string(i1,ln);
04055
04056 string mask=logic_process_line_get_string(i1,ln);
04057
04058 s_command c;
04059 c.command=_process_on_banned;
04060
04061 c.channel=chan;
04062 c.ban_mask=mask;
04063
04064 procedure.commands.push_back(c);
04065
04066 break;
04067 }
04068
04069 if(!token.compare((string)"check_dynamic_bans")) {
04070 i1++;
04071 string chan=logic_process_line_get_string(i1,ln);
04072
04073 string nick=logic_process_line_get_string(i1,ln);
04074
04075 string reason_var=logic_process_line_get_string(i1,ln);
04076
04077 s_command c;
04078 c.command=_check_dynamic_bans;
04079
04080 c.channel=chan;
04081 c.nick=nick;
04082 c.ban_reason=reason_var;
04083 c.result=result;
04084
04085 procedure.commands.push_back(c);
04086
04087 break;
04088 }
04089
04090 if(!token.compare((string)"restart")) {
04091 s_command c;
04092 c.command=_restart;
04093
04094 procedure.commands.push_back(c);
04095
04096 break;
04097 }
04098
04099 if(!token.compare((string)"raw")) {
04100 i1++;
04101 string priority=logic_process_line_get_string(i1,ln);
04102
04103 string raw=logic_process_line_get_string(i1,ln);
04104
04105 s_command c;
04106 c.command=_raw;
04107 c.msg_text=raw;
04108 if((c.priority=logic_get_priority(priority.c_str()))==0) {
04109 error_reason="Unknown priority class";
04110 return true;
04111 }
04112
04113 procedure.commands.push_back(c);
04114
04115 procedure.minimal_botnet_version=2;
04116
04117 break;
04118 }
04119
04120 if(!token.compare((string)"admin_msg")) {
04121 i1++;
04122 string type=logic_process_line_get_string(i1,ln);
04123
04124 string mask=logic_process_line_get_string(i1,ln);
04125
04126 string message=logic_process_line_get_string(i1,ln);
04127
04128 s_command c;
04129 c.command=_admin_msg;
04130 c.admin_msg_type=type;
04131 c.admin_msg_mask=mask;
04132 c.admin_msg_message=message;
04133
04134 procedure.commands.push_back(c);
04135
04136 procedure.minimal_botnet_version=10;
04137
04138 break;
04139 }
04140
04141 if(!token.compare((string)"}")) {
04142 if(i_brackets--<0) {
04143 error_reason="Unexpected '}'";
04144 return true;
04145 }
04146
04147 if(i_brackets==0)
04148 b_proc=false;
04149
04150 s_command c;
04151 c.command=_end_bracket;
04152 procedure.commands.push_back(c);
04153
04154 c.command=_label;
04155 c.line=error_line;
04156
04157 procedure.commands.push_back(c);
04158
04159 bool got_jump=false;
04160
04161 list<s_lines>::reverse_iterator i;
04162 for(i=lines.rbegin(); i!=lines.rend(); i++) {
04163 list<s_command>::reverse_iterator i2;
04164 for(i2=procedure.commands.rbegin(); i2!=procedure.commands.rend(); i2++)
04165 if((*i).line==(*i2).line) {
04166 (*i2)._goto_line=error_line;
04167 got_jump=true;
04168 break;
04169 }
04170 if(got_jump)
04171 break;
04172 }
04173
04174 if(lines.rbegin()!=lines.rend())
04175 lines.pop_back();
04176
04177 if(i_brackets==0) {
04178 procedures.push_back(procedure);
04179 }
04180
04181 break;
04182 }
04183
04184 }
04185
04186 if(b_smtp && !b_chan) {
04187 if(b_smtp_data) {
04188 if(!ln.compare((string)"-")) {
04189 smtp.data+="\r\n";
04190 smtp.data_lines.push_back("-");
04191 } else {
04192 smtp.data+=ln+"\r\n";
04193 smtp.data_lines.push_back(ln);
04194 }
04195 if(!ln.compare((string)".")) {
04196 b_smtp_data=false;
04197 }
04198
04199 break;
04200 }
04201
04202 if(!token.compare((string)"server")) {
04203 i1++;
04204 string data=logic_process_line_get_string(i1,ln);
04205
04206 smtp.server=data;
04207
04208 break;
04209 }
04210
04211 if(!token.compare((string)"port")) {
04212 i1++;
04213 string data=logic_process_line_get_string(i1,ln);
04214
04215 smtp.port=(unsigned short)atol(data.c_str());
04216 if(smtp.port==0)
04217 smtp.port=25;
04218
04219 break;
04220 }
04221
04222 if(!token.compare((string)"HELO")) {
04223 i1++;
04224 string data=logic_process_line_get_string(i1,ln);
04225
04226 smtp.helo=data;
04227
04228 break;
04229 }
04230
04231 if(!token.compare((string)"MAIL_FROM")) {
04232 i1++;
04233 string data=logic_process_line_get_string(i1,ln);
04234
04235 smtp.mail_from=data;
04236
04237 break;
04238 }
04239
04240 if(!token.compare((string)"RCPT_TO")) {
04241 i1++;
04242 string data=logic_process_line_get_string(i1,ln);
04243
04244 smtp.rcpt_to=data;
04245
04246 break;
04247 }
04248
04249 if(!token.compare((string)"DATA")) {
04250 smtp.data="";
04251
04252 b_smtp_data=true;
04253
04254 break;
04255 }
04256 }
04257
04258 if(!token.compare((string)"channel") && !b_chan) {
04259 i1++;
04260 string chan_;
04261 for(i2=i1; i2<ln.length(); i2++, i1++)
04262 chan_+=ln[i2];
04263
04264 if(chan_.length()>0 && chan_[0]=='\"')
04265 chan_.erase(0,1);
04266 if(chan_.length()>0 && chan_[chan_.length()-1]=='\"')
04267 chan_.erase(chan_.length()-1,1);
04268
04269 chan.channel_name=chan_;
04270 chan.on_mode="";
04271 chan.on_key="";
04272 chan.on_limit="";
04273 chan.on_topic="";
04274 chan.on_ircop="";
04275 chan.on_ctcp="";
04276 chan.on_privmsg="";
04277 chan.on_notice="";
04278 chan.on_part="";
04279 chan.on_dynamic_ban="";
04280 chan.on_server_msg="";
04281 chan.allow_dynamic.clear();
04282 chan.last_changed=0;
04283 chan.replication.clear();
04284 chan.keys.clear();
04285 chan.dynamic_minus_modes="";
04286 chan.dynamic_plus_modes="";
04287 chan.groups.clear();
04288 chan.keys.clear();
04289 chan.dynamic_bans.clear();
04290 chan.dynbans_editors.clear();
04291
04292 b_chan=true;
04293 break;
04294 }
04295
04296 if(b_chan) {
04297
04298 if(!token.compare((string)"last_changed")) {
04299 i1++;
04300 string time=logic_process_line_get_string(i1,ln);
04301 chan.last_changed=atol(time.c_str());
04302 return false;
04303 }
04304
04305 if(!token.compare((string)"member_of_group")) {
04306 i1++;
04307 string grp=logic_process_line_get_string(i1,ln);
04308
04309 s_group g;
04310 g.name=grp;
04311 chan.groups.push_back(g);
04312
04313 all_groups.push_back(g);
04314
04315 break;
04316 }
04317
04318 if(!token.compare((string)"replication")) {
04319 i1++;
04320 string partner=logic_process_line_get_string(i1,ln);
04321
04322 string type=logic_process_line_get_string(i1,ln);
04323
04324 s_replication r;
04325 r.partner=partner;
04326 r.type=REPL_INVALID;
04327 if(!type.compare("push"))
04328 r.type=REPL_PUSH;
04329 if(!type.compare("pull"))
04330 r.type=REPL_PULL;
04331 if(!type.compare("pushpull"))
04332 r.type=REPL_PUSHPULL;
04333 if(r.type==REPL_INVALID) {
04334 error_reason="Invalid replication type";
04335 return true;
04336 }
04337
04338 chan.replication.push_back(r);
04339
04340 return false;
04341 }
04342
04343 if(!token.compare((string)"on_mode")) {
04344 if(chan.on_mode.compare("")) {
04345 error_reason="Duplicate event";
04346 return true;
04347 }
04348
04349 i1++;
04350 string proc=logic_process_line_get_string(i1,ln);
04351
04352 chan.on_mode=proc;
04353
04354 break;
04355 }
04356
04357 if(!token.compare((string)"on_key")) {
04358 if(chan.on_key.compare("")) {
04359 error_reason="Duplicate event";
04360 return true;
04361 }
04362
04363 i1++;
04364 string proc=logic_process_line_get_string(i1,ln);
04365
04366 chan.on_key=proc;
04367
04368 break;
04369 }
04370
04371 if(!token.compare((string)"on_limit")) {
04372 if(chan.on_limit.compare("")) {
04373 error_reason="Duplicate event";
04374 return true;
04375 }
04376
04377 i1++;
04378 string proc=logic_process_line_get_string(i1,ln);
04379
04380 chan.on_limit=proc;
04381
04382 break;
04383 }
04384
04385 if(!token.compare((string)"on_topic")) {
04386 if(chan.on_topic.compare("")) {
04387 error_reason="Duplicate event";
04388 return true;
04389 }
04390
04391 i1++;
04392 string proc=logic_process_line_get_string(i1,ln);
04393
04394 chan.on_topic=proc;
04395
04396 break;
04397 }
04398
04399 if(!token.compare((string)"on_ircop")) {
04400 if(chan.on_ircop.compare("")) {
04401 error_reason="Duplicate event";
04402 return true;
04403 }
04404
04405 i1++;
04406 string proc=logic_process_line_get_string(i1,ln);
04407
04408 chan.on_ircop=proc;
04409
04410 break;
04411 }
04412
04413 if(!token.compare((string)"on_ctcp")) {
04414 if(chan.on_ctcp.compare("")) {
04415 error_reason="Duplicate event";
04416 return true;
04417 }
04418
04419 i1++;
04420 string proc=logic_process_line_get_string(i1,ln);
04421
04422 chan.on_ctcp=proc;
04423
04424 break;
04425 }
04426
04427 if(!token.compare((string)"on_privmsg")) {
04428 if(chan.on_privmsg.compare("")) {
04429 error_reason="Duplicate event";
04430 return true;
04431 }
04432
04433 i1++;
04434 string proc=logic_process_line_get_string(i1,ln);
04435
04436 chan.on_privmsg=proc;
04437
04438 break;
04439 }
04440
04441 if(!token.compare((string)"on_notice")) {
04442 if(chan.on_notice.compare("")) {
04443 error_reason="Duplicate event";
04444 return true;
04445 }
04446
04447 i1++;
04448 string proc=logic_process_line_get_string(i1,ln);
04449
04450 chan.on_notice=proc;
04451
04452 break;
04453 }
04454
04455 if(!token.compare((string)"on_part")) {
04456 if(chan.on_part.compare("")) {
04457 error_reason="Duplicate event";
04458 return true;
04459 }
04460
04461 i1++;
04462 string proc=logic_process_line_get_string(i1,ln);
04463
04464 chan.on_part=proc;
04465
04466 break;
04467 }
04468
04469 if(!token.compare((string)"on_dynamic_ban")) {
04470 if(chan.on_dynamic_ban.compare("")) {
04471 error_reason="Duplicate event";
04472 return true;
04473 }
04474
04475 i1++;
04476 string proc=logic_process_line_get_string(i1,ln);
04477
04478 chan.on_dynamic_ban=proc;
04479
04480 break;
04481 }
04482
04483 if(!token.compare((string)"on_server_msg")) {
04484 if(chan.on_server_msg.compare("")) {
04485 error_reason="Duplicate event";
04486 return true;
04487 }
04488
04489 i1++;
04490 string proc=logic_process_line_get_string(i1,ln);
04491
04492 chan.on_server_msg=proc;
04493
04494 break;
04495 }
04496
04497 if(!token.compare((string)"allow_dynamic")) {
04498 i1++;
04499 string group=logic_process_line_get_string(i1,ln);
04500
04501 string plus=logic_process_line_get_string(i1,ln);
04502
04503 string minus=logic_process_line_get_string(i1,ln);
04504
04505 s_dynamic_rule r;
04506 r.group=group;
04507 r.plus_modes=plus;
04508 r.minus_modes=minus;
04509
04510 chan.allow_dynamic.push_back(r);
04511
04512 return false;
04513 }
04514
04515 if(!token.compare((string)"dynamic1")) {
04516 i1++;
04517 string modes=logic_process_line_get_string(i1,ln);
04518
04519 chan.dynamic_plus_modes=modes;
04520
04521 return false;
04522 }
04523
04524 if(!token.compare((string)"dynamic2")) {
04525 i1++;
04526 string modes=logic_process_line_get_string(i1,ln);
04527
04528 chan.dynamic_minus_modes=modes;
04529
04530 return false;
04531 }
04532
04533 if(!token.compare((string)"key")) {
04534 i1++;
04535 string key=logic_process_line_get_string(i1,ln);
04536
04537 chan.keys.push_back(key);
04538
04539 break;
04540 }
04541
04542 if(!token.compare((string)"dynamic_ban")) {
04543 i1++;
04544 string mask=logic_process_line_get_string(i1,ln);
04545
04546 string reason=logic_process_line_get_string(i1,ln);
04547
04548 pair<string,string> p;
04549 p.first=mask;
04550 p.second=reason;
04551 chan.dynamic_bans.insert(p);
04552
04553 break;
04554 }
04555
04556 if(!token.compare((string)"partyline_dynbans_editors")) {
04557 i1++;
04558 string group=logic_process_line_get_string(i1,ln);
04559 chan.dynbans_editors.push_back(group);
04560
04561 break;
04562 }
04563 }
04564
04565 if(!token.compare((string)"groups") && !b_groups) {
04566 b_groups=true;
04567
04568 return false;
04569 }
04570
04571 if(b_groups && token.compare("}")) {
04572 i1++;
04573 string grp=logic_process_line_get_string(i1,ln);
04574
04575 s_group g;
04576 g.name=grp;
04577
04578 all_groups.push_back(g);
04579
04580 return false;
04581 }
04582
04583 if(!token.compare((string)"private") && !b_prv) {
04584 prv.on_privmsg="";
04585 prv.on_notice="";
04586 prv.on_ctcp="";
04587 prv.on_filesys_got_new="";
04588 prv.on_fnc="";
04589 prv.on_broadcast="";
04590 prv.on_server_msg="";
04591 prv.last_changed=0;
04592 prv.replication.clear();
04593
04594 b_prv=true;
04595 return false;
04596 }
04597
04598 if(b_prv && !token.compare((string)"member_of_group")) {
04599 i1++;
04600 string grp=logic_process_line_get_string(i1,ln);
04601
04602 s_group g;
04603 g.name=grp;
04604 prv.groups.push_back(g);
04605
04606 all_groups.push_back(g);
04607
04608 break;
04609 }
04610
04611 if(b_prv && !token.compare((string)"on_privmsg")) {
04612 i1++;
04613 string proc=logic_process_line_get_string(i1,ln);
04614
04615 prv.on_privmsg=proc;
04616
04617 return false;
04618 }
04619
04620 if(b_prv && !token.compare((string)"on_notice")) {
04621 i1++;
04622 string proc=logic_process_line_get_string(i1,ln);
04623
04624 prv.on_notice=proc;
04625
04626 return false;
04627 }
04628
04629 if(b_prv && !token.compare((string)"on_ctcp")) {
04630 i1++;
04631 string proc=logic_process_line_get_string(i1,ln);
04632
04633 prv.on_ctcp=proc;
04634
04635 return false;
04636 }
04637
04638 if(b_prv && !token.compare((string)"on_filesys_got_new")) {
04639 i1++;
04640 string proc=logic_process_line_get_string(i1,ln);
04641
04642 prv.on_filesys_got_new=proc;
04643
04644 return false;
04645 }
04646
04647 if(b_prv && !token.compare((string)"on_internal_event")) {
04648 i1++;
04649 string proc=logic_process_line_get_string(i1,ln);
04650
04651 prv.on_internal_event=proc;
04652
04653 return false;
04654 }
04655
04656 if(b_prv && !token.compare((string)"on_fnc")) {
04657 i1++;
04658 string proc=logic_process_line_get_string(i1,ln);
04659
04660 prv.on_fnc=proc;
04661
04662 return false;
04663 }
04664
04665 if(b_prv && !token.compare((string)"on_broadcast")) {
04666 i1++;
04667 string proc=logic_process_line_get_string(i1,ln);
04668
04669 prv.on_broadcast=proc;
04670
04671 return false;
04672 }
04673
04674 if(b_prv && !token.compare((string)"on_server_msg")) {
04675 i1++;
04676 string proc=logic_process_line_get_string(i1,ln);
04677
04678 prv.on_server_msg=proc;
04679
04680 return false;
04681 }
04682
04683 if(b_prv && !token.compare((string)"replication")) {
04684 i1++;
04685 string partner=logic_process_line_get_string(i1,ln);
04686
04687 string type=logic_process_line_get_string(i1,ln);
04688
04689 s_replication r;
04690 r.partner=partner;
04691 r.type=REPL_INVALID;
04692 if(!type.compare("push"))
04693 r.type=REPL_PUSH;
04694 if(!type.compare("pull"))
04695 r.type=REPL_PULL;
04696 if(!type.compare("pushpull"))
04697 r.type=REPL_PUSHPULL;
04698 if(r.type==REPL_INVALID) {
04699 error_reason="Invalid replication type";
04700 return true;
04701 }
04702
04703 prv.replication.push_back(r);
04704
04705 return false;
04706 }
04707
04708 if(b_prv && !token.compare((string)"last_changed")) {
04709 i1++;
04710 string time=logic_process_line_get_string(i1,ln);
04711 prv.last_changed=atol(time.c_str());
04712 return false;
04713 }
04714
04715 if(!token.compare((string)"}")) {
04716 if(i_brackets--<0) {
04717 error_reason="Unexpected '}'";
04718 return true;
04719 }
04720
04721 s_command c;
04722
04723 if(b_smtp) {
04724 b_smtp=false;
04725
04726 c.command=_smtp;
04727 c.smtp=smtp;
04728
04729 procedure.commands.push_back(c);
04730 }
04731
04732 if(b_chan) {
04733 b_chan=false;
04734 channel_defs.push_back(chan);
04735 }
04736
04737 if(b_groups) {
04738 b_groups=false;
04739 }
04740
04741 if(b_prv) {
04742 b_prv=false;
04743 }
04744
04745 c.command=_label;
04746 c.line=error_line;
04747
04748 procedure.commands.push_back(c);
04749
04750 list<s_lines>::reverse_iterator i;
04751 i=lines.rbegin();
04752 if(i!=lines.rend())
04753 i++;
04754
04755 if(i!=lines.rend()) {
04756 list<s_command>::iterator i2;
04757 for(i2=procedure.commands.begin(); i2!=procedure.commands.end(); i2++)
04758 if((*i).line==(*i2).line) {
04759 (*i2)._goto_line=error_line;
04760 lines.pop_back();
04761 }
04762 }
04763
04764 break;
04765 }
04766
04767 error_reason="Unknown token";
04768 return true;
04769 }
04770 }
04771
04772 if(b_user)
04773 return true;
04774
04775 return false;
04776 }
04777
04778
04779
04780
04781
04782
04783
04784
04785
04786
04787
04788
04789 bool logic_load_conf(const char* filename, int& error_on_line, const char* &error_reason)
04790 {
04791 {
04792 FILE* f=fopen(filename,"rt");
04793 if(f==NULL) {
04794 error_on_line=0;
04795 string err="Cannot open file \"";
04796 err+=filename;
04797 err+="\"!";
04798 static char err_[1024];
04799 strcpy(err_,err.c_str());
04800 error_reason=err_;
04801
04802 if(f)
04803 fclose(f);
04804
04805 return true;
04806 }
04807 fclose(f);
04808 }
04809
04810 error_on_line=1;
04811 error_reason=NULL;
04812
04813 bool b_user2=false;
04814 s_user user;
04815 bool b_channel=false;
04816 s_channel channel;
04817 bool b_user=false;
04818 int i_brackets=0;
04819 bool b_proc=false;
04820 s_procedure procedure;
04821 list<s_lines> lines;
04822 bool b_smtp=false;
04823 s_smtp smtp;
04824 bool b_smtp_data=false;
04825 bool b_chan=false;
04826 bool b_groups=false;
04827 bool b_prv=false;
04828
04829 s_channel_def chan;
04830
04831 vector<s_procedure> procedures;
04832 vector<s_user> users;
04833 vector<s_channel> channels;
04834 vector<s_channel_def> channel_defs;
04835 vector<s_user> terminators;
04836
04837 vector<s_group> all_groups;
04838
04839 s_private prv;
04840
04841 FILE* f=fopen((char*)filename,"r");
04842 char ln[10240+1];
04843 while(f && !feof(f)) {
04844 if(fgets(ln,1024*10-1,f)==NULL)
04845 break;
04846 ln[10240]=0;
04847 if(ln[strlen(ln)-1]=='\r')
04848 ln[strlen(ln)-1]=0;
04849 if(ln[strlen(ln)-1]=='\n')
04850 ln[strlen(ln)-1]=0;
04851 if(ln[strlen(ln)-1]=='\r')
04852 ln[strlen(ln)-1]=0;
04853 if(ln[strlen(ln)-1]=='\n')
04854 ln[strlen(ln)-1]=0;
04855
04856 if(ln[0]==0 || ln[0]=='\r' || ln[0]=='\n')
04857 continue;
04858
04859 if(atol(conf_getvar("log_echo_debug").c_str()))
04860 printf("%s\n",ln);
04861
04862 string s;
04863 bool space=true;
04864 for(int i1=0; ln[i1]!=0; i1++) {
04865 if(ln[i1]==0x20 || ln[i1]=='\t')
04866 if(space)
04867 continue;
04868 else
04869 space=true;
04870 if(s.compare("") && space)
04871 s.append("\x20");
04872 space=false;
04873 if(ln[i1]!=0x20 && ln[i1]!='\t')
04874 s+=ln[i1];
04875 }
04876 for(size_t i2=s.length()-1; (signed)i2>=0; i2--)
04877 if(s[i2]==0x20 || s[i2]=='\t')
04878 s=s.erase(i2,1);
04879 else
04880 break;
04881 if(logic_process_line(s,error_reason,error_on_line,b_user2,user,b_channel,channel,b_user,i_brackets,b_proc,procedure,lines,b_smtp,smtp,b_smtp_data,procedures,users,channels,chan,channel_defs,b_chan,all_groups,b_groups,b_prv,prv,terminators)) {
04882 if(f)
04883 fclose(f);
04884 return true;
04885 }
04886 error_on_line++;
04887 }
04888 if(f)
04889 fclose(f);
04890
04891
04892 {
04893 {
04894 r_procedures.clear();
04895 vector<s_procedure>::iterator i;
04896 for(i=procedures.begin(); i!=procedures.end(); i++)
04897 r_procedures.push_back(*i);
04898 procedures.clear();
04899 }
04900
04901 {
04902 r_users.clear();
04903 r_user_templates.clear();
04904 vector<s_user>::iterator i;
04905 for(i=users.begin(); i!=users.end(); i++) {
04906 if(!(*i).is_template)
04907 r_users.push_back(*i);
04908 else
04909 r_user_templates.push_back(*i);
04910 }
04911 users.clear();
04912 }
04913
04914 {
04915 r_terminators.clear();
04916 vector<s_user>::iterator i;
04917 for(i=terminators.begin(); i!=terminators.end(); i++) {
04918 r_terminators.push_back(*i);
04919 }
04920 terminators.clear();
04921 }
04922
04923 {
04924 r_channels.clear();
04925 r_channel_templates.clear();
04926 r_channel_terminators.clear();
04927 vector<s_channel>::iterator i;
04928 for(i=channels.begin(); i!=channels.end(); i++) {
04929 if(!(*i).is_template) {
04930 if(!(*i).terminator)
04931 r_channels.push_back(*i);
04932 else
04933 r_channel_terminators.push_back(*i);
04934 } else
04935 r_channel_templates.push_back(*i);
04936 }
04937 channels.clear();
04938 }
04939
04940 {
04941 r_channel_defs.clear();
04942 vector<s_channel_def>::iterator i;
04943 for(i=channel_defs.begin(); i!=channel_defs.end(); i++)
04944 r_channel_defs.push_back(*i);
04945 channel_defs.clear();
04946 }
04947
04948 {
04949 r_all_groups.clear();
04950 vector<s_group>::iterator i;
04951 for(i=all_groups.begin(); i!=all_groups.end(); i++)
04952 r_all_groups.push_back(*i);
04953 all_groups.clear();
04954 }
04955
04956 {
04957 r_private.clear();
04958 r_private=prv;
04959 }
04960 }
04961
04962 error_on_line=0;
04963 return false;
04964 }
04965
04966
04967
04968
04969
04970
04971
04972
04973
04974
04975 string logic_eval(string str, map<string,string>& vars)
04976 {
04977 string res;
04978
04979 bool b_str=false;
04980
04981 for(unsigned int i1=0; i1<str.length(); i1++) {
04982 if(str[i1]=='\"') {
04983 b_str=!b_str;
04984 continue;
04985 }
04986 if(b_str && str[i1]=='\\') {
04987 if(i1+1>=str.length()) {
04988 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\' at the end of the string \"";
04989 d+=str+"\"";
04990 log_debug(d.c_str());
04991 } else {
04992 if(i1+1>=str.length()) {
04993 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape sequence '\\' at the end of the string \"";
04994 d+=str+"\"";
04995 log_debug(d.c_str());
04996 }
04997 char x=str[++i1];
04998 switch(x) {
04999 case '\\':
05000 res+="\\";
05001 break;
05002 case '\"':
05003 res+="\"";
05004 break;
05005 case 'r':
05006 res+="\r";
05007 break;
05008 case 'n':
05009 res+="\n";
05010 break;
05011 case 't':
05012 res+="\t";
05013 break;
05014 case 'a':
05015 res+="\a";
05016 break;
05017 case 'b':
05018 res+="\b";
05019 break;
05020 case 'f':
05021 res+="\f";
05022 break;
05023 case 'v':
05024 res+="\v";
05025 break;
05026 case '\'':
05027 res+="\'";
05028 break;
05029 case '?':
05030 res+="\?";
05031 break;
05032 case 'x':
05033 {
05034 if(i1+1+2>=str.length()) {
05035 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\x' at the end of the string \"";
05036 d+=str+"\"";
05037 log_debug(d.c_str());
05038 } else {
05039 char x1[8];
05040 x1[0]=str[++i1];
05041 x1[1]=str[++i1];
05042 unsigned char x2=0;
05043 for(int i1=0; i1<2; i1++) {
05044 unsigned char nibble=0xff;
05045 if(x1[i1]>='0' && x1[i1]<='9')
05046 nibble=x1[i1]-'0';
05047 if(x1[i1]>='a' && x1[i1]<='f')
05048 nibble=x1[i1]+10-'a';
05049 if(x1[i1]>='A' && x1[i1]<='F')
05050 nibble=x1[i1]+10-'A';
05051 if(nibble==0xff) {
05052 nibble=0;
05053 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\x' - character not in HEX family \"";
05054 d+=str+"\"";
05055 log_debug(d.c_str());
05056 }
05057 x2|=nibble << (i1==0?4:0);
05058 }
05059 res.push_back(x2);
05060 }
05061 }
05062 break;
05063 case '0':
05064 case '1':
05065 case '2':
05066 case '3':
05067 case '4':
05068 case '5':
05069 case '6':
05070 case '7':
05071 {
05072 if(i1+1+3>=str.length()) {
05073 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\<octal_num>' at the end of the string \"";
05074 d+=str+"\"";
05075 log_debug(d.c_str());
05076 } else {
05077 char x1[8];
05078 x1[0]=x;
05079 x1[1]=str[++i1];
05080 x1[2]=str[++i1];
05081 unsigned char x2=0;
05082 for(int i1=0; i1<3; i1++) {
05083 unsigned char nibble=0xff;
05084 if(x1[i1]>='0' && x1[i1]<='7')
05085 nibble=x1[i1]-'0';
05086 if(nibble==0xff) {
05087 nibble=0;
05088 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\<octal_num>' - character not in OCTAL family \"";
05089 d+=str+"\"";
05090 log_debug(d.c_str());
05091 }
05092 if(i1==0)
05093 nibble<<=6;
05094 if(i1==1)
05095 nibble<<=3;
05096
05097
05098 x2|=nibble;
05099 }
05100 res.push_back(x2);
05101 }
05102 }
05103 break;
05104 default:
05105 {
05106 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\' - unknown next character \"";
05107 d+=str+"\"";
05108 log_debug(d.c_str());
05109 }
05110 break;
05111 }
05112 }
05113 continue;
05114 }
05115 if(str[i1]=='$') {
05116 string v="$";
05117 for(i1++; i1<str.length(); i1++) {
05118 if(!((str[i1]>='a' && str[i1]<='z') || (str[i1]>='A' && str[i1]<='Z') || (str[i1]>='0' && str[i1]<='9') || str[i1]=='_'))
05119 break;
05120 v+=str[i1];
05121 }
05122 i1--;
05123 map<string,string>::iterator i=vars.begin();
05124 for(; i!=vars.end(); i++)
05125 if(!(*i).first.compare(v))
05126 break;
05127 if(i!=vars.end() && !(*i).first.compare(v)) {
05128 if(!(*i).second.empty() && (*i).second[0]!=0)
05129 res+=(*i).second;
05130 } else {
05131 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: unknown variable ";
05132 d+=v;
05133 log_debug(d.c_str());
05134
05135 res+="";
05136 }
05137 continue;
05138 }
05139 if(b_str) {
05140 res+=str[i1];
05141 continue;
05142 }
05143 if(str[i1]==',') {
05144 res+=",";
05145 continue;
05146 }
05147 if(!b_str) {
05148 if(str[i1]!='.') {
05149 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: bad syntax in the string: ";
05150 d+=str;
05151 log_debug(d.c_str());
05152
05153 continue;
05154 }
05155 continue;
05156 }
05157 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: WHY IT GOES HERE?!";
05158 log_debug(d.c_str());
05159 }
05160
05161 return res;
05162 }
05163
05164
05165
05166
05167
05168
05169
05170
05171
05172
05173 void logic_process_script_output(string script_type, int script_num, s_exec_handle* h)
05174 {
05175
05176
05177
05178
05179
05180
05181 string orig_script_type=script_type;
05182
05183 if(!script_type.compare("php_2"))
05184 script_type="php";
05185
05186 char* line=new char[1024*10+1];
05187
05188 bool commands=false;
05189
05190 char tmp2[64];
05191 string fn="tmp_";
05192 ltoa(rand(),tmp2,16);
05193 fn+=tmp2;
05194 ltoa(rand(),tmp2,16);
05195 fn+=tmp2;
05196 ltoa(rand(),tmp2,16);
05197 fn+=tmp2;
05198 ltoa(rand(),tmp2,16);
05199 fn+=tmp2;
05200 fn+=".tmp";
05201 fn=conf_getvar(script_type+(string)"_script_dir")+fn;
05202
05203 FILE* f=fopen(fn.c_str(),"wb");
05204 if(f) {
05205 int size;
05206 char* buf=NULL;
05207 exec_read_output(h,buf,size);
05208 fwrite(buf,size,1,f);
05209 delete[] buf;
05210 fclose(f);
05211 }
05212
05213 exec_process_end(h);
05214 delete h;
05215
05216 s_file fl;
05217 fl.clear();
05218 s_access fl_a;
05219 fl_a.clear();
05220 bool in_filesys=false;
05221 bool in_filesys_access=false;
05222
05223 f=fopen(fn.c_str(),"r");
05224 while(f && !feof(f)) {
05225 if(fgets(line,1024*10-1,f)==NULL)
05226 break;
05227 line[1024*10-1]=0;
05228 if(line[strlen(line)-1]=='\r')
05229 line[strlen(line)-1]=0;
05230 if(line[strlen(line)-1]=='\n')
05231 line[strlen(line)-1]=0;
05232 if(line[strlen(line)-1]=='\r')
05233 line[strlen(line)-1]=0;
05234 if(line[strlen(line)-1]=='\n')
05235 line[strlen(line)-1]=0;
05236 if(!commands && !strcmp(line,"#####")) {
05237 commands=true;
05238 continue;
05239 }
05240 if(commands && !strcmp(line,"#####"))
05241 break;
05242 if(commands) {
05243 string orig=line;
05244 bool got=false;
05245 string cmd=line;
05246 if(!in_filesys) {
05247 if(cmd.length()>=8 && cmd[0]=='F' && cmd[1]=='I' && cmd[2]=='L' && cmd[3]=='E' && cmd[4]=='S' && cmd[5]=='Y' && cmd[6]=='S' && cmd[7]==0x20) {
05248 got=true;
05249 string internal_name=cmd;
05250 if(internal_name.find(' ',0)!=string::npos)
05251 internal_name.erase(0,internal_name.find(' ',0)+1);
05252 string c=internal_name;
05253 if(internal_name.find(' ',0)!=string::npos)
05254 internal_name.erase(0,internal_name.find(' ',0)+1);
05255 if(c.find(' ',0)!=string::npos)
05256 c.erase(c.find(' ',0),c.length());
05257 if(!c.compare("InternalName"))
05258 if(filesys_logic_get_file(internal_name,fl))
05259 in_filesys=true;
05260 }
05261 if(cmd.length()>=8 && cmd[0]=='P' && cmd[1]=='U' && cmd[2]=='T' && cmd[3]==0x20 && cmd[4]=='L' && cmd[5]=='O' && cmd[6]=='W' && cmd[7]==0x20) {
05262 got=true;
05263 cmd.erase(0,8);
05264 irc_put(cmd,LOW_PRIORITY);
05265 continue;
05266 }
05267 if(cmd.length()>=9 && cmd[0]=='P' && cmd[1]=='U' && cmd[2]=='T' && cmd[3]==0x20 && cmd[4]=='H' && cmd[5]=='I' && cmd[6]=='G' && cmd[7]=='H' && cmd[8]==0x20) {
05268 got=true;
05269 cmd.erase(0,9);
05270 irc_put(cmd,HIGH_PRIORITY);
05271 continue;
05272 }
05273 if(cmd.length()>=13 && cmd[0]=='P' && cmd[1]=='U' && cmd[2]=='T' && cmd[3]==0x20 && cmd[4]=='C' && cmd[5]=='R' && cmd[6]=='I' && cmd[7]=='T' && cmd[8]=='I' && cmd[9]=='C' && cmd[10]=='A' && cmd[11]=='L' && cmd[12]==0x20) {
05274 got=true;
05275 cmd.erase(0,13);
05276 irc_put(cmd,CRITICAL_PRIORITY);
05277 continue;
05278 }
05279 if(cmd.length()>=4 && cmd[0]=='L' && cmd[1]=='O' && cmd[2]=='G' && cmd[3]==0x20) {
05280 got=true;
05281 cmd.erase(0,4);
05282 string logtype;
05283 while(cmd.length()>0 && cmd[0]!=0x20) {
05284 logtype+=cmd[0];
05285 cmd.erase(0,1);
05286 }
05287 if(cmd.length()>0 && cmd[0]==0x20)
05288 cmd.erase(0,1);
05289 if(!logtype.compare("DEBUG")) {
05290 cmd="SCRIPT: "+cmd;
05291 log_debug(cmd.c_str());
05292 continue;
05293 }
05294 log_channel(logtype.c_str(),TYPE_SCRIPT,"","",cmd.c_str(),"");
05295 continue;
05296 }
05297 if(cmd.length()>=8 && cmd[0]=='E' && cmd[1]=='X' && cmd[2]=='E' && cmd[3]=='C' && cmd[4]=='U' && cmd[5]=='T' && cmd[6]=='E' && cmd[7]==0x20) {
05298 got=true;
05299 map<string,string> vars;
05300 cmd.erase(0,8);
05301 string call_string=cmd;
05302 string cs=call_string;
05303 unsigned int i2;
05304 for(i2=0; i2<cs.length(); i2++)
05305 if(cs[i2]=='(')
05306 break;
05307 cs.erase(i2,cs.length()-i2);
05308 vector<s_procedure>::iterator i1;
05309 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
05310 string s=(*i1).name;
05311 unsigned int i2;
05312 for(i2=0; i2<s.length(); i2++)
05313 if(s[i2]=='(')
05314 break;
05315 s.erase(i2,s.length()-i2);
05316 if(!s.compare(cs)) {
05317 call_string=(*i1).name;
05318 break;
05319 }
05320 }
05321 cs=cmd;
05322 for(i2=0; i2<cs.length(); i2++)
05323 if(cs[i2]=='(')
05324 break;
05325 cs.erase(0,i2+1);
05326 if(cs.length()>0 && cs[cs.length()-1]==')')
05327 cs.erase(cs.length()-1,1);
05328 cs+=",";
05329
05330 list<string> params;
05331 bool str=false;
05332 string p;
05333 for(i2=0; i2<cs.length() && cs.compare(","); i2++) {
05334 if(cs[i2]=='\"') {
05335 p+="\"";
05336
05337 str=!str;
05338 continue;
05339 }
05340 if(!str && cs[i2]==',') {
05341
05342
05343
05344
05345
05346
05347
05348
05349
05350 p=logic_eval(p,vars);
05351 params.push_back(p);
05352 p="";
05353 continue;
05354 }
05355 if(!str && cs[i2]==')') {
05356 if(p.compare("")) {
05357
05358
05359
05360
05361
05362
05363
05364
05365
05366 p=logic_eval(p,vars);
05367 params.push_back(p);
05368 }
05369 break;
05370 }
05371 p+=cs[i2];
05372 }
05373
05374 logic_call_proc_ex2(call_string.c_str(),vars,params);
05375 continue;
05376 }
05377 } else {
05378 string cmd=line;
05379 string c1, c2, c3, c4;
05380 int ctx=0;
05381 for(unsigned int i1=0; i1<cmd.length(); i1++) {
05382 if(ctx<3 && cmd[i1]==0x20) {
05383 ctx++;
05384 continue;
05385 }
05386 if(ctx==0)
05387 c1.push_back(cmd[i1]);
05388 if(ctx==1)
05389 c2.push_back(cmd[i1]);
05390 if(ctx==2)
05391 c3.push_back(cmd[i1]);
05392 if(ctx==3)
05393 c4.push_back(cmd[i1]);
05394 }
05395 if(!c1.compare("FILESYS")) {
05396 if(!in_filesys_access && !c2.compare("SET")) {
05397 if(!c3.compare("type")) {
05398 if(!c4.compare("ft_message")) {
05399 fl.file_type=ft_message;
05400 got=true;
05401 }
05402 if(!c4.compare("ft_file")) {
05403 fl.file_type=ft_file;
05404 got=true;
05405 }
05406 }
05407 if(!c3.compare("PublicName")) {
05408 got=true;
05409 fl.public_name=c4;
05410 }
05411 if(!c3.compare("Time")) {
05412 got=true;
05413 time_t t=atol(c4.c_str());
05414 fl.ftime=t;
05415 }
05416 if(!c3.compare("Published")) {
05417 got=true;
05418 int b=atol(c4.c_str());
05419 fl.published=b;
05420 }
05421 if(!c3.compare("Complete")) {
05422 got=true;
05423 int b=atol(c4.c_str());
05424 fl.complete=b;
05425 }
05426 if(!c3.compare("Expiration")) {
05427 got=true;
05428 time_t t=atol(c4.c_str());
05429 fl.expiration=t;
05430 }
05431 }
05432 if(!in_filesys_access && !c2.compare("ACCESS_BEGIN")) {
05433 got=true;
05434 in_filesys_access=true;
05435 fl.access.clear();
05436 fl_a.clear();
05437 continue;
05438 }
05439 if(in_filesys_access && !c2.compare("SET")) {
05440 if(!c3.compare("AllUsers")) {
05441 got=true;
05442 int b=atol(c4.c_str());
05443 fl_a.all_users=b;
05444 }
05445 if(!c3.compare("UserName")) {
05446 got=true;
05447 fl_a.user_name=c4;
05448 }
05449 if(!c3.compare("Owner")) {
05450 got=true;
05451 int b=atol(c4.c_str());
05452 fl_a.owner=b;
05453 }
05454 if(!c3.compare("Read")) {
05455 got=true;
05456 int b=atol(c4.c_str());
05457 fl_a.read=b;
05458 }
05459 if(!c3.compare("Delete")) {
05460 got=true;
05461 int b=atol(c4.c_str());
05462 fl_a.del=b;
05463 }
05464 if(!c3.compare("NotifyOwner")) {
05465 got=true;
05466 int b=atol(c4.c_str());
05467 fl_a.notify_owner=b;
05468 }
05469 if(!c3.compare("NotifyUser")) {
05470 got=true;
05471 int b=atol(c4.c_str());
05472 fl_a.notify_user=b;
05473 }
05474 if(!c3.compare("Secure")) {
05475 got=true;
05476 int b=atol(c4.c_str());
05477 fl_a.secure=b;
05478 }
05479 if(!c3.compare("AllOnChannel")) {
05480 got=true;
05481 fl_a.all_on_channel=c4;
05482 }
05483 if(!c3.compare("AlsoUnknown")) {
05484 got=true;
05485 int b=atol(c4.c_str());
05486 fl_a.also_unknown=b;
05487 }
05488 if(!c3.compare("NotifyOwnerMessage") || !c3.compare("NotifyUserMessage")) {
05489 string msg;
05490 bool got_backslash=false;
05491 for(unsigned int i1=0; i1<c4.length(); i1++) {
05492 if(!got_backslash && c4[i1]=='\\') {
05493 got_backslash=true;
05494 continue;
05495 }
05496 if(got_backslash) {
05497 if(i1+1>=c4.length()) {
05498 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape sequence '\\' at the end of the string \"";
05499 d+=c4+"\"";
05500 log_debug(d.c_str());
05501 }
05502 char x=c4[i1];
05503 switch(x) {
05504 case '\\':
05505 msg+="\\";
05506 got_backslash=false;
05507 break;
05508 case '\"':
05509 msg+="\"";
05510 got_backslash=false;
05511 break;
05512 case 'r':
05513 msg+="\r";
05514 got_backslash=false;
05515 break;
05516 case 'n':
05517 msg+="\n";
05518 got_backslash=false;
05519 break;
05520 case 't':
05521 msg+="\t";
05522 got_backslash=false;
05523 break;
05524 case 'a':
05525 msg+="\a";
05526 got_backslash=false;
05527 break;
05528 case 'b':
05529 msg+="\b";
05530 got_backslash=false;
05531 break;
05532 case 'f':
05533 msg+="\f";
05534 got_backslash=false;
05535 break;
05536 case 'v':
05537 msg+="\v";
05538 got_backslash=false;
05539 break;
05540 case '\'':
05541 msg+="\'";
05542 got_backslash=false;
05543 break;
05544 case '?':
05545 msg+="\?";
05546 got_backslash=false;
05547 break;
05548 case 'x':
05549 {
05550 got_backslash=false;
05551 if(i1+1+2>=c4.length()) {
05552 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\x' at the end of the string \"";
05553 d+=c4+"\"";
05554 log_debug(d.c_str());
05555 } else {
05556 char x1[8];
05557 x1[0]=c4[++i1];
05558 x1[1]=c4[++i1];
05559 unsigned char x2=0;
05560 for(int i1=0; i1<2; i1++) {
05561 unsigned char nibble=0xff;
05562 if(x1[i1]>='0' && x1[i1]<='9')
05563 nibble=x1[i1]-'0';
05564 if(x1[i1]>='a' && x1[i1]<='f')
05565 nibble=x1[i1]+10-'a';
05566 if(x1[i1]>='A' && x1[i1]<='F')
05567 nibble=x1[i1]+10-'A';
05568 if(nibble==0xff) {
05569 nibble=0;
05570 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\x' - character not in HEX family \"";
05571 d+=c4+"\"";
05572 log_debug(d.c_str());
05573 }
05574 x2|=nibble << (i1==0?4:0);
05575 }
05576 msg.push_back(x2);
05577 }
05578 }
05579 break;
05580 case '0':
05581 case '1':
05582 case '2':
05583 case '3':
05584 case '4':
05585 case '5':
05586 case '6':
05587 case '7':
05588 {
05589 got_backslash=false;
05590 if(i1+1+3>=c4.length()) {
05591 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\<octal_num>' at the end of the string \"";
05592 d+=c4+"\"";
05593 log_debug(d.c_str());
05594 } else {
05595 char x1[8];
05596 x1[0]=x;
05597 x1[1]=c4[++i1];
05598 x1[2]=c4[++i1];
05599 unsigned char x2=0;
05600 for(int i1=0; i1<3; i1++) {
05601 unsigned char nibble=0xff;
05602 if(x1[i1]>='0' && x1[i1]<='7')
05603 nibble=x1[i1]-'0';
05604 if(nibble==0xff) {
05605 nibble=0;
05606 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\<octal_num>' - character not in OCTAL family \"";
05607 d+=c4+"\"";
05608 log_debug(d.c_str());
05609 }
05610 if(i1==0)
05611 nibble<<=6;
05612 if(i1==1)
05613 nibble<<=3;
05614
05615
05616 x2|=nibble;
05617 }
05618 msg.push_back(x2);
05619 }
05620 }
05621 break;
05622 default:
05623 {
05624 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: errorneous escape character '\\' - unknown next character \"";
05625 d+=c4+"\"";
05626 log_debug(d.c_str());
05627 }
05628 break;
05629 }
05630 } else {
05631 msg.push_back(c4[i1]);
05632 }
05633 }
05634 if(!c3.compare("NotifyOwnerMessage")) {
05635 got=true;
05636 fl_a.notify_owner_message=msg;
05637 }
05638 if(!c3.compare("NotifyUserMessage")) {
05639 got=true;
05640 fl_a.notify_user_message=msg;
05641 }
05642 }
05643 }
05644 if(in_filesys_access && !c2.compare("ACCESS_END")) {
05645 got=true;
05646 fl.access.push_back(fl_a);
05647 fl_a.clear();
05648 in_filesys_access=false;
05649 continue;
05650 }
05651 if(!c2.compare("COMMIT")) {
05652 got=true;
05653 filesys_logic_set_file(fl.internal_name,fl);
05654 fl.clear();
05655 fl_a.clear();
05656 in_filesys=in_filesys_access=false;
05657 continue;
05658 }
05659 }
05660 }
05661 if(!got) {
05662 string msg="Invalid result of script: type=\"";
05663 msg+=orig_script_type;
05664 msg+="\", number=";
05665 char tmp[64];
05666 ltoa((long)script_num,tmp,10);
05667 msg+=tmp;
05668 msg+=": ";
05669 msg+=orig;
05670 log_debug(msg.c_str());
05671 }
05672 }
05673 }
05674
05675 if(f)
05676 fclose(f);
05677 remove(fn.c_str());
05678
05679 delete[] line;
05680 }
05681
05682 int logic_call_proc_ex(const char* call_string, map<string,string> vars);
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693 string logic_script_esc(string script_type, string str)
05694 {
05695 if(!script_type.compare("php") || !script_type.compare("php_2")) {
05696 string res;
05697 for(unsigned int i1=0; i1<str.length(); i1++) {
05698 if(str[i1]<32 || str[i1]=='$' || str[i1]=='\\' || str[i1]=='\'' || str[i1]=='\"') {
05699 res+="\\x";
05700 char tmp[64];
05701 ltoa((unsigned char)str[i1],tmp,16);
05702 res+=tmp;
05703 continue;
05704 }
05705 res+=str[i1];
05706 }
05707 return res;
05708 }
05709 return str;
05710 }
05711
05712
05713
05714
05715
05716
05717
05718
05719
05720
05721
05722 void logic_exec_script(string script_type, int script_num, string channel, list<string>& params)
05723 {
05724 if(script_type.compare("php") && script_type.compare("php_2")) {
05725 string d="in file " __FILE__ " in function " __FUNC__ " occurred error: unsupported script type (";
05726 d+=script_type;
05727 d+=")";
05728 log_debug(d.c_str());
05729 return;
05730 }
05731
05732 if(!script_type.compare("php")) {
05733 string tmp=script_type+(string)"_";
05734 char tmp2[64];
05735 ltoa(script_num,tmp2,10);
05736 tmp+=tmp2;
05737 string script=conf_getvar(script_type+(string)"_script_dir");
05738 script+=conf_getvar(tmp);
05739
05740 string fn="tmp_";
05741 ltoa(rand(),tmp2,16);
05742 fn+=tmp2;
05743 ltoa(rand(),tmp2,16);
05744 fn+=tmp2;
05745 ltoa(rand(),tmp2,16);
05746 fn+=tmp2;
05747 ltoa(rand(),tmp2,16);
05748 fn+=tmp2;
05749 string fn2=fn;
05750 fn+=(string)"."+script_type;
05751 fn2+=".tmp";
05752
05753 string tmp_fn1=conf_getvar(script_type+(string)"_script_dir");
05754 string tmp_fn2=tmp_fn1;
05755 tmp_fn1+=fn;
05756 tmp_fn2+=fn2;
05757
05758 FILE* out=fopen(tmp_fn1.c_str(),"w");
05759
05760 char* line=new char[1024*10+1];
05761
05762 if(script.empty())
05763 return;
05764 FILE* in=fopen(script.c_str(),"r");
05765 line[0]=0;
05766 while(in && !feof(in)) {
05767 if(fgets(line,1024*10-1,in)==NULL)
05768 break;
05769 line[1024*10-1]=0;
05770 if(line[strlen(line)-1]=='\r')
05771 line[strlen(line)-1]=0;
05772 if(line[strlen(line)-1]=='\n')
05773 line[strlen(line)-1]=0;
05774 if(line[strlen(line)-1]=='\r')
05775 line[strlen(line)-1]=0;
05776 if(line[strlen(line)-1]=='\n')
05777 line[strlen(line)-1]=0;
05778 if(!strcmp(line,"// INIT"))
05779 break;
05780 if(strlen(line))
05781 if(out)
05782 fprintf(out,"%s",line);
05783 string tmp="\n";
05784 if(out)
05785 fprintf(out,"%s",tmp.c_str());
05786 line[0]=0;
05787 }
05788
05789 strcpy(line," $using_irc_server_host=\"");
05790 if(out)
05791 fprintf(out,"%s",line);
05792 tmp=logic_script_esc(script_type,irc_server_host);
05793 tmp+="\";\n";
05794 if(out)
05795 fprintf(out,"%s",tmp.c_str());
05796
05797 strcpy(line," $using_irc_server_port=");
05798 if(out)
05799 fprintf(out,"%s",line);
05800 char _tmp_buff[64];
05801 tmp=ltoa(irc_server_port,_tmp_buff,10);
05802 tmp+=";\n";
05803 if(out)
05804 fprintf(out,"%s",tmp.c_str());
05805 strcpy(line,"\n");
05806 if(out)
05807 fprintf(out,"%s",line);
05808
05809 strcpy(line," $bot_nick=\"");
05810 if(out)
05811 fprintf(out,"%s",line);
05812 tmp=logic_script_esc(script_type,irc_nick);
05813 tmp+="\";\n";
05814 if(out)
05815 fprintf(out,"%s",tmp.c_str());
05816 strcpy(line,"\n");
05817 if(out)
05818 fprintf(out,"%s",line);
05819 strcpy(line," $channel=\"");
05820 if(out)
05821 fprintf(out,"%s",line);
05822 tmp=logic_script_esc(script_type,channel);
05823 tmp+="\";\n";
05824 if(out)
05825 fprintf(out,"%s",tmp.c_str());
05826 strcpy(line,"\n");
05827 if(out)
05828 fprintf(out,"%s",line);
05829 strcpy(line," $params=array();\n");
05830 if(out)
05831 fprintf(out,"%s",line);
05832
05833 {
05834 list<string>::iterator i1;
05835 int i2=0;
05836 for(i1=params.begin(); i1!=params.end(); i1++, i2++) {
05837 sprintf(line," $params[%d]=\"",i2);
05838 if(out)
05839 fprintf(out,"%s",line);
05840 tmp=logic_script_esc(script_type,*i1);
05841 if(out)
05842 fprintf(out,"%s",tmp.c_str());
05843 tmp="\";\n";
05844 if(out)
05845 fprintf(out,"%s",tmp.c_str());
05846 }
05847 strcpy(line,"\n");
05848 if(out)
05849 fprintf(out,"%s",line);
05850 }
05851
05852 {
05853 strcpy(line," $users=array();");
05854 if(out)
05855 fprintf(out,"%s",line);
05856 vector<s_online_channel>::iterator i9;
05857 for(i9=irc_channels.begin(); i9!=irc_channels.end(); i9++) {
05858 line[0]=0;
05859 if(i9==irc_channels.begin())
05860 strcpy(line,"\n\n");
05861 strcat(line," // channel ");
05862 strcat(line,(*i9).name.c_str());
05863 if(out)
05864 fprintf(out,"%s",line);
05865
05866 vector<s_online_user>::iterator i1;
05867 for(i1=(*i9).users.begin(); i1!=(*i9).users.end(); i1++) {
05868 strcpy(line,"\n");
05869 if(out)
05870 fprintf(out,"%s",line);
05871
05872 string nick=logic_script_esc(script_type,(*i1).nick);
05873
05874 strcpy(line," $users[\"");
05875 if(out)
05876 fprintf(out,"%s",line);
05877 tmp=nick;
05878 if(out)
05879 fprintf(out,"%s",tmp.c_str());
05880 tmp="\"]=Array(\"name\" => \"";
05881 if(out)
05882 fprintf(out,"%s",tmp.c_str());
05883 tmp=logic_script_esc(script_type,(*i1).in_logic_as);
05884 tmp+="\", ";
05885 if(out)
05886 fprintf(out,"%s",tmp.c_str());
05887
05888 string ident=logic_script_esc(script_type,(*i1).ident);
05889 string host=logic_script_esc(script_type,(*i1).host);
05890 string fullname=logic_script_esc(script_type,(*i1).fullname);
05891
05892 bool online=true;
05893
05894 sprintf(line,"\"online\" => %d, ",online?1:0);
05895 if(out)
05896 fprintf(out,"%s",line);
05897
05898 strcpy(line,"\"nick\" => \"");
05899 if(out)
05900 fprintf(out,"%s",line);
05901 if(out)
05902 fprintf(out,"%s",nick.c_str());
05903 tmp="\", ";
05904 if(out)
05905 fprintf(out,"%s",tmp.c_str());
05906
05907 strcpy(line,"\"ident\" => \"");
05908 if(out)
05909 fprintf(out,"%s",line);
05910 if(out)
05911 fprintf(out,"%s",ident.c_str());
05912 tmp="\", ";
05913 if(out)
05914 fprintf(out,"%s",tmp.c_str());
05915
05916 strcpy(line,"\"host\" => \"");
05917 if(out)
05918 fprintf(out,"%s",line);
05919 if(out)
05920 fprintf(out,"%s",host.c_str());
05921 tmp="\", ";
05922 if(out)
05923 fprintf(out,"%s",tmp.c_str());
05924
05925 strcpy(line,"\"fullname\" => \"");
05926 if(out)
05927 fprintf(out,"%s",line);
05928 if(out)
05929 fprintf(out,"%s",fullname.c_str());
05930 tmp="\", ";
05931 if(out)
05932 fprintf(out,"%s",tmp.c_str());
05933
05934 bool host_unknown=false;
05935 bool host_bot=false;
05936 bool got_i4=false;
05937 vector<s_user>::iterator i4;
05938 {
05939 vector<s_user>::iterator i2;
05940 for(i2=r_users.begin(); i2!=r_users.end(); i2++) {
05941 if((*i1).in_logic_as.compare((*i2).name))
05942 continue;
05943 i4=i2;
05944 got_i4=true;
05945 if((*i2).host_unknown && !(*i2).name.compare((*i1).in_logic_as)) {
05946 host_unknown=true;
05947 break;
05948 }
05949 if((*i2).host_bot && !(*i2).name.compare((*i1).in_logic_as)) {
05950 host_bot=true;
05951 break;
05952 }
05953 }
05954 }
05955 sprintf(line,"\"host_unknown\" => %d, ",host_unknown?1:0);
05956 if(out)
05957 fprintf(out,"%s",line);
05958 sprintf(line,"\"host_bot\" => %d, ",host_bot?1:0);
05959 if(out)
05960 fprintf(out,"%s",line);
05961 sprintf(line,"\"irc_op\" => %d, ",(*i1).irc_op?1:0);
05962 if(out)
05963 fprintf(out,"%s",line);
05964
05965 string mode=(*i1).mode;
05966 strcpy(line,"\"mode\" => \"");
05967 if(out)
05968 fprintf(out,"%s",line);
05969 if(out)
05970 fprintf(out,"%s",mode.c_str());
05971 tmp="\");\n";
05972 if(out)
05973 fprintf(out,"%s",tmp.c_str());
05974
05975 map<string,string> vars;
05976 {
05977 strcpy(line," $users[\"");
05978 if(out)
05979 fprintf(out,"%s",line);
05980
05981 tmp=logic_script_esc(script_type,irc_get_nick((*i1).nick));
05982 if(out)
05983 fprintf(out,"%s",tmp.c_str());
05984
05985 tmp="\"][\"hostmasks\"]=Array(";
05986 if(out)
05987 fprintf(out,"%s",tmp.c_str());
05988
05989 if(got_i4) {
05990 vector<string>::iterator i2;
05991 int i3=0;
05992 for(i2=(*i4).hostmask.begin(); i2!=(*i4).hostmask.end(); i2++, i3++) {
05993 if(i3) {
05994 strcpy(line,", ");
05995 if(out)
05996 fprintf(out,"%s",line);
05997 }
05998 sprintf(line,"%d => \"",i3);
05999 if(out)
06000 fprintf(out,"%s",line);
06001 tmp=logic_script_esc(script_type,logic_eval((*i2),vars));
06002 if(out)
06003 fprintf(out,"%s",tmp.c_str());
06004 strcpy(line,"\"");
06005 if(out)
06006 fprintf(out,"%s",line);
06007 }
06008 }
06009 }
06010 strcpy(line,");\n");
06011 if(out)
06012 fprintf(out,"%s",line);
06013
06014
06015
06016 strcpy(line," $users[\"");
06017 if(out)
06018 fprintf(out,"%s",line);
06019
06020 tmp=nick;
06021 if(out)
06022 fprintf(out,"%s",tmp.c_str());
06023
06024 tmp="\"][\"fullname_masks\"]=Array(";
06025 if(out)
06026 fprintf(out,"%s",tmp.c_str());
06027
06028 if(got_i4) {
06029 vector<string>::iterator i2;
06030 int i3=0;
06031 for(i2=(*i4).fullname.begin(); i2!=(*i4).fullname.end(); i2++, i3++) {
06032 if(i3) {
06033 strcpy(line,", ");
06034 if(out)
06035 fprintf(out,"%s",line);
06036 }
06037 sprintf(line,"%d => \"",i3);
06038 if(out)
06039 fprintf(out,"%s",line);
06040 tmp=logic_script_esc(script_type,logic_eval((*i2),vars));
06041 if(out)
06042 fprintf(out,"%s",tmp.c_str());
06043 strcpy(line,"\"");
06044 if(out)
06045 fprintf(out,"%s",line);
06046 }
06047 }
06048 strcpy(line,");\n");
06049 if(out)
06050 fprintf(out,"%s",line);
06051
06052 vector<s_online_channel>::iterator i2;
06053 for(i2=irc_channels.begin(); i2!=irc_channels.end(); i2++) {
06054 vector<s_online_user>::iterator i3;
06055 for(i3=(*i2).users.begin(); i3!=(*i2).users.end(); i3++) {
06056 if(!cmp_strings_case_insensitive((*i1).nick,(*i3).nick)) {
06057 tmp=" if(!isset($users[\"";
06058 tmp+=nick;
06059 tmp+="\"][\"channels\"])) $users[\"";
06060 tmp+=nick;
06061 tmp+="\"][\"channels\"]=array(); $tmp=array(); $tmp[\"channel\"]=\""+logic_script_esc(script_type,(*i2).name);
06062 tmp+="\"; $tmp[\"mode\"]=\""+(*i3).mode;
06063 tmp+="\"; array_push($users[\""+nick+"\"][\"channels\"],$tmp); unset($tmp);\n";
06064 if(out)
06065 fprintf(out,"%s",tmp.c_str());
06066 }
06067 }
06068 }
06069
06070 if(got_i4) {
06071 if(out)
06072 fprintf(out,"%s\n"," $groups=array();");
06073 vector<s_group>::iterator i7;
06074 for(i7=(*i4).groups.begin(); i7!=(*i4).groups.end(); i7++)
06075 if(out)
06076 fprintf(out,"%s%s%s\n"," array_push($groups,\"",logic_script_esc(script_type,logic_eval((*i7).name,vars)).c_str(),"\");");
06077 if(out)
06078 fprintf(out,"%s%s%s\n"," $users[\"",logic_script_esc(script_type,nick).c_str(),"\"][\"groups\"]=$groups; unset($groups);");
06079 }
06080 }
06081 strcpy(line,"\n");
06082 if(out)
06083 fprintf(out,"%s",line);
06084 }
06085 }
06086
06087 {
06088 map<string,string> vars;
06089
06090 vector<s_online_channel>::iterator i9;
06091 for(i9=irc_channels.begin(); i9!=irc_channels.end(); i9++) {
06092 vector<s_online_user>::iterator i1;
06093 for(i1=(*i9).users.begin(); i1!=(*i9).users.end(); i1++) {
06094 string nick=logic_script_esc(script_type,(*i1).nick);
06095
06096 s_user u;
06097 vector<s_channel> chs;
06098 logic_partyline_get_user((*i1).in_logic_as,u,chs);
06099 map<string,string>::iterator i2;
06100 for(i2=u.meta.begin(); i2!=u.meta.end(); i2++) {
06101 strcpy(line," $users[\"");
06102 if(out)
06103 fprintf(out,"%s",line);
06104
06105 tmp=nick;
06106 if(out)
06107 fprintf(out,"%s",tmp.c_str());
06108
06109 tmp="\"][\"meta\"][\"";
06110 tmp+=(string)logic_script_esc(script_type,logic_eval((*i2).first,vars))+"\"]=\""+logic_script_esc(script_type,logic_eval((*i2).second,vars))+"\";\n";
06111 if(out)
06112 fprintf(out,"%s",tmp.c_str());
06113 }
06114 }
06115 }
06116 }
06117 strcpy(line,"\n");
06118 if(out)
06119 fprintf(out,"%s",line);
06120
06121
06122 {
06123 map<string,string> vars;
06124
06125 tmp="";
06126
06127 vector<s_online_channel>::iterator i9;
06128 for(i9=irc_channels.begin(); i9!=irc_channels.end(); i9++) {
06129 string channel=logic_script_esc(script_type,(*i9).name);
06130
06131 {
06132 tmp+=" $channels[\"";
06133 tmp+=channel;
06134 tmp+="\"][\"key\"]=\"";
06135 tmp+=logic_script_esc(script_type,(*i9).key);
06136 tmp+="\";\n";
06137
06138 tmp+=" $channels[\"";
06139 tmp+=channel;
06140 tmp+="\"][\"limit\"]=\"";
06141 tmp+=logic_script_esc(script_type,(*i9).limit);
06142 tmp+="\";\n";
06143
06144 tmp+=" $channels[\"";
06145 tmp+=channel;
06146 tmp+="\"][\"mode\"]=\"";
06147 tmp+=logic_script_esc(script_type,(*i9).modes);
06148 tmp+="\";\n";
06149
06150 tmp+=" $channels[\"";
06151 tmp+=logic_script_esc(script_type,channel);
06152 tmp+="\"][\"topic\"]=\"";
06153 tmp+=logic_script_esc(script_type,(*i9).topic);
06154 tmp+="\";\n";
06155 }
06156
06157 tmp+=" $channels[\"";
06158 tmp+=channel;
06159 tmp+="\"][\"bans\"]=array();\n";
06160 {
06161 vector<string>::iterator i1;
06162 for(i1=(*i9).bans.begin(); i1!=(*i9).bans.end(); i1++) {
06163 tmp+=" array_push($channels[\"";
06164 tmp+=channel;
06165 tmp+="\"][\"bans\"],\"";
06166 tmp+=logic_script_esc(script_type,*i1);
06167 tmp+="\");\n";
06168 }
06169 }
06170
06171 tmp+=" $channels[\"";
06172 tmp+=channel;
06173 tmp+="\"][\"exceptions\"]=array();\n";
06174 {
06175 vector<string>::iterator i1;
06176 for(i1=(*i9).excepts.begin(); i1!=(*i9).excepts.end(); i1++) {
06177 tmp+=" array_push($channels[\"";
06178 tmp+=channel;
06179 tmp+="\"][\"exceptions\"],\"";
06180 tmp+=logic_script_esc(script_type,*i1);
06181 tmp+="\");\n";
06182 }
06183 }
06184
06185 tmp+=" $channels[\"";
06186 tmp+=channel;
06187 tmp+="\"][\"invites\"]=array();\n";
06188 {
06189 vector<string>::iterator i1;
06190 for(i1=(*i9).invites.begin(); i1!=(*i9).invites.end(); i1++) {
06191 tmp+=" array_push($channels[\"";
06192 tmp+=channel;
06193 tmp+="\"][\"invites\"],\"";
06194 tmp+=logic_script_esc(script_type,*i1);
06195 tmp+="\");\n";
06196 }
06197 }
06198
06199 tmp+=" $channels[\"";
06200 tmp+=channel;
06201 tmp+="\"][\"reops\"]=array();\n";
06202 {
06203 vector<string>::iterator i1;
06204 for(i1=(*i9).reops.begin(); i1!=(*i9).reops.end(); i1++) {
06205 tmp+=" array_push($channels[\"";
06206 tmp+=channel;
06207 tmp+="\"][\"reops\"],\"";
06208 tmp+=logic_script_esc(script_type,*i1);
06209 tmp+="\");\n";
06210 }
06211 }
06212
06213 if(out)
06214 fprintf(out,"%s",tmp.c_str());
06215 tmp="";
06216 }
06217 }
06218
06219
06220 {
06221 map<string,string> raw;
06222 string chm_a, chm_b, chm_c, chm_d;
06223 map<char,char> prefix;
06224 irc_get_005(raw,prefix,chm_a,chm_b,chm_c,chm_d);
06225 map<string,string>::iterator i1;
06226 tmp="\n $isupport=array();\n";
06227 for(i1=raw.begin(); i1!=raw.end(); i1++) {
06228 tmp+=(string)" $isupport[\"";
06229 tmp+=logic_script_esc(script_type,(*i1).first);
06230 tmp+=(string)"\"]=\"";
06231 tmp+=logic_script_esc(script_type,(*i1).second);
06232 tmp+=(string)"\";\n";
06233 }
06234 tmp+="\n";
06235 map<char,char>::iterator i2;
06236 tmp+=" $user_mode_prefix=array();\n";
06237 for(i2=prefix.begin(); i2!=prefix.end(); i2++) {
06238 tmp+=(string)" $user_mode_prefix[\"";
06239 tmp+=logic_script_esc(script_type,(string)""+(*i2).first);
06240 tmp+=(string)"\"]=\"";
06241 tmp+=logic_script_esc(script_type,(string)""+(*i2).second);
06242 tmp+=(string)"\";\n";
06243 }
06244 tmp+="\n";
06245
06246 tmp+=" $chan_modes_class_a=\"";
06247 tmp+=logic_script_esc(script_type,chm_a);
06248 tmp+="\";\n";
06249
06250 tmp+=" $chan_modes_class_b=\"";
06251 tmp+=logic_script_esc(script_type,chm_b);
06252 tmp+="\";\n";
06253
06254 tmp+=" $chan_modes_class_c=\"";
06255 tmp+=logic_script_esc(script_type,chm_c);
06256 tmp+="\";\n";
06257
06258 tmp+=" $chan_modes_class_d=\"";
06259 tmp+=logic_script_esc(script_type,chm_d);
06260 tmp+="\";\n";
06261
06262 tmp+="\n";
06263 if(out)
06264 fprintf(out,"%s",tmp.c_str());
06265 tmp="";
06266 }
06267
06268
06269 {
06270 tmp=filesys_get_script(script_type);
06271 if(out)
06272 fprintf(out,"%s",tmp.c_str());
06273 tmp="";
06274 }
06275
06276 while(in && !feof(in)) {
06277 if(fgets(line,1024*10-1,in)==NULL)
06278 break;
06279 line[1024*10-1]=0;
06280 if(line[strlen(line)-1]=='\r')
06281 line[strlen(line)-1]=0;
06282 if(line[strlen(line)-1]=='\n')
06283 line[strlen(line)-1]=0;
06284 if(line[strlen(line)-1]=='\r')
06285 line[strlen(line)-1]=0;
06286 if(line[strlen(line)-1]=='\n')
06287 line[strlen(line)-1]=0;
06288 if(!strcmp(line,"// RESULT"))
06289 break;
06290 if(out)
06291 fprintf(out,"%s",line);
06292 tmp="\n";
06293 if(out)
06294 fprintf(out,"%s",tmp.c_str());
06295 line[0]=0;
06296 }
06297
06298 tmp=" unlink(\"./";
06299 tmp+=fn;
06300 tmp+="\");\n\n";
06301 if(out)
06302 fprintf(out,"%s",tmp.c_str());
06303
06304 strcpy(line," echo \"#####\\n\";\n");
06305 if(out)
06306 fprintf(out,"%s",line);
06307 strcpy(line," foreach($result as $element)\n");
06308 if(out)
06309 fprintf(out,"%s",line);
06310 strcpy(line," echo $element.\"\\n\";\n");
06311 if(out)
06312 fprintf(out,"%s",line);
06313 strcpy(line," echo \"#####\\n\";\n\n");
06314 if(out)
06315 fprintf(out,"%s",line);
06316
06317 while(in && !feof(in)) {
06318 if(fgets(line,1024*10-1,in)==NULL)
06319 break;
06320 line[1024*10-1]=0;
06321 if(line[strlen(line)-1]=='\r')
06322 line[strlen(line)-1]=0;
06323 if(line[strlen(line)-1]=='\n')
06324 line[strlen(line)-1]=0;
06325 if(line[strlen(line)-1]=='\r')
06326 line[strlen(line)-1]=0;
06327 if(line[strlen(line)-1]=='\n')
06328 line[strlen(line)-1]=0;
06329 if(out)
06330 fprintf(out,"%s",line);
06331 tmp="\n";
06332 if(out)
06333 fprintf(out,"%s",tmp.c_str());
06334 line[0]=0;
06335 }
06336
06337 if(out)
06338 fclose(out);
06339 if(in)
06340 fclose(in);
06341
06342 s_tmp_file t;
06343 t.script=true;
06344 t.script_num=script_num;
06345 if(script_type.length()<sizeof(t.script_type))
06346 strcpy(t.script_type,script_type.c_str());
06347 else
06348 t.script_type[0]=0;
06349 strcpy(t.command_line,(conf_getvar(script_type+(string)"_processor")).c_str());
06350
06351 strcpy(t.command_args,"\"." FILE_SLASH);
06352 strcat(t.command_args,fn.c_str());
06353 strcat(t.command_args,"\"");
06354 if(!conf_getvar(script_type+(string)"_processor_args").empty()) {
06355 strcat(t.command_args," ");
06356 strcat(t.command_args,conf_getvar(script_type+(string)"_processor_args").c_str());
06357 }
06358 strcpy(t.command_dir,conf_getvar(script_type+(string)"_script_dir").c_str());
06359
06360 t.has_been_run=false;
06361 t.start_up_time=0;
06362 tmp_files.push_back(t);
06363
06364 delete[] line;
06365 line=NULL;
06366 }
06367
06368 if(!script_type.compare("php_2")) {
06369 string tmp=script_type+(string)"_";
06370 char tmp2[64];
06371 ltoa(script_num,tmp2,10);
06372 tmp+=tmp2;
06373 string script=conf_getvar("php_script_dir");
06374 script+=conf_getvar(tmp);
06375
06376 string fn="tmp_";
06377 ltoa(rand(),tmp2,16);
06378 fn+=tmp2;
06379 ltoa(rand(),tmp2,16);
06380 fn+=tmp2;
06381 ltoa(rand(),tmp2,16);
06382 fn+=tmp2;
06383 ltoa(rand(),tmp2,16);
06384 fn+=tmp2;
06385 string fn2=fn;
06386 fn+=(string)".php";
06387 fn2+=".tmp";
06388
06389 string tmp_fn1=conf_getvar("php_script_dir");
06390 string tmp_fn2=tmp_fn1;
06391 tmp_fn1+=fn;
06392 tmp_fn2+=fn2;
06393
06394 FILE* out=fopen(tmp_fn1.c_str(),"w");
06395
06396 char* line=new char[1024*10+1];
06397
06398 if(script.empty())
06399 return;
06400 FILE* in=fopen(script.c_str(),"r");
06401 line[0]=0;
06402 while(in && !feof(in)) {
06403 if(fgets(line,1024*10-1,in)==NULL)
06404 break;
06405 line[1024*10]=0;
06406 if(line[strlen(line)-1]=='\r')
06407 line[strlen(line)-1]=0;
06408 if(line[strlen(line)-1]=='\n')
06409 line[strlen(line)-1]=0;
06410 if(line[strlen(line)-1]=='\r')
06411 line[strlen(line)-1]=0;
06412 if(line[strlen(line)-1]=='\n')
06413 line[strlen(line)-1]=0;
06414 if(!strcmp(line,"// INIT"))
06415 break;
06416 if(strlen(line))
06417 if(out)
06418 fprintf(out,"%s",line);
06419 string tmp="\n";
06420 if(out)
06421 fprintf(out,"%s",tmp.c_str());
06422 line[0]=0;
06423 }
06424
06425
06426 string ln;
06427 char _tmp_buff[64];
06428
06429
06430 ln=" $server=new c_server; $server->init(\"";
06431 ln.append(logic_script_esc(script_type,irc_server_host));
06432 ln.append("\",");
06433 ln.append(ltoa(irc_server_port,_tmp_buff,10));
06434 ln.append(",\"");
06435 ln.append(logic_script_esc(script_type,irc_nick));
06436 ln.append("\");\n");
06437 if(out)
06438 fprintf(out,"%s",ln.c_str());
06439
06440
06441 {
06442 map<string,string> raw;
06443 string chm_a, chm_b, chm_c, chm_d;
06444 map<char,char> prefix;
06445 irc_get_005(raw,prefix,chm_a,chm_b,chm_c,chm_d);
06446 map<string,string>::iterator i1;
06447 tmp="\n";
06448 for(i1=raw.begin(); i1!=raw.end(); i1++) {
06449 tmp+=(string)" $server->isupport[\"";
06450 tmp+=logic_script_esc(script_type,(*i1).first);
06451 tmp+=(string)"\"]=\"";
06452 tmp+=logic_script_esc(script_type,(*i1).second);
06453 tmp+=(string)"\";\n";
06454 }
06455 tmp+="\n";
06456 map<char,char>::iterator i2;
06457 tmp+=" $user_mode_prefix=array();\n";
06458 for(i2=prefix.begin(); i2!=prefix.end(); i2++) {
06459 tmp+=(string)" $server->user_mode_prefix[\"";
06460 tmp+=logic_script_esc(script_type,(string)""+(*i2).first);
06461 tmp+=(string)"\"]=\"";
06462 tmp+=logic_script_esc(script_type,(string)""+(*i2).second);
06463 tmp+=(string)"\";\n";
06464 }
06465 tmp+="\n";
06466
06467 tmp+=" $server->chan_modes_class_a=\"";
06468 tmp+=logic_script_esc(script_type,chm_a);
06469 tmp+="\";\n";
06470
06471 tmp+=" $server->chan_modes_class_b=\"";
06472 tmp+=logic_script_esc(script_type,chm_b);
06473 tmp+="\";\n";
06474
06475 tmp+=" $server->chan_modes_class_c=\"";
06476 tmp+=logic_script_esc(script_type,chm_c);
06477 tmp+="\";\n";
06478
06479 tmp+=" $server->chan_modes_class_d=\"";
06480 tmp+=logic_script_esc(script_type,chm_d);
06481 tmp+="\";\n";
06482
06483 tmp+="\n";
06484 if(out)
06485 fprintf(out,"%s",tmp.c_str());
06486 tmp="";
06487 }
06488
06489
06490
06491 ln="\n $input=new c_input; $input->init(\"";
06492 ln.append(logic_script_esc(script_type,channel));
06493 ln.append("\");\n");
06494 if(out)
06495 fprintf(out,"%s",ln.c_str());
06496
06497 {
06498 list<string>::iterator i1;
06499 int i2=0;
06500 for(i1=params.begin(); i1!=params.end(); i1++, i2++) {
06501 ln=" $input->set_next_parameter(\"";
06502 ln.append(logic_script_esc(script_type,*i1));
06503 ln.append("\");\n");
06504 if(out)
06505 fprintf(out,"%s",ln.c_str());
06506 }
06507 strcpy(line,"\n");
06508 if(out)
06509 fprintf(out,"%s",line);
06510 }
06511
06512 {
06513 ln="\n $channels=array();\n\n";
06514 if(out)
06515 fprintf(out,"%s",ln.c_str());
06516
06517 map<string,string> vars;
06518
06519 vector<s_online_channel>::iterator i9;
06520 for(i9=irc_channels.begin(); i9!=irc_channels.end(); i9++) {
06521 vector<string>::iterator i1;
06522
06523 ln=" $bans=array();\n";
06524 if(out)
06525 fprintf(out,"%s",ln.c_str());
06526 for(i1=(*i9).bans.begin(); i1!=(*i9).bans.end(); i1++) {
06527 ln=" $x=\"";
06528 ln.append(logic_script_esc(script_type,*i1));
06529 ln.append("\"; array_push($bans,$x); unset($x);\n");
06530 if(out)
06531 fprintf(out,"%s",ln.c_str());
06532 }
06533
06534 ln=" $excepts=array();\n";
06535 if(out)
06536 fprintf(out,"%s",ln.c_str());
06537 for(i1=(*i9).excepts.begin(); i1!=(*i9).excepts.end(); i1++) {
06538 ln=" $x=\"";
06539 ln.append(logic_script_esc(script_type,*i1));
06540 ln.append("\"; array_push($excepts,$x); unset($x);\n");
06541 if(out)
06542 fprintf(out,"%s",ln.c_str());
06543 }
06544
06545 ln=" $invites=array();\n";
06546 if(out)
06547 fprintf(out,"%s",ln.c_str());
06548 for(i1=(*i9).invites.begin(); i1!=(*i9).invites.end(); i1++) {
06549 ln=" $x=\"";
06550 ln.append(logic_script_esc(script_type,*i1));
06551 ln.append("\"; array_push($invites,$x); unset($x);\n");
06552 if(out)
06553 fprintf(out,"%s",ln.c_str());
06554 }
06555
06556 ln=" $reops=array();\n";
06557 if(out)
06558 fprintf(out,"%s",ln.c_str());
06559 for(i1=(*i9).reops.begin(); i1!=(*i9).reops.end(); i1++) {
06560 ln=" $x=\"";
06561 ln.append(logic_script_esc(script_type,*i1));
06562 ln.append("\"; array_push($reops,$x); unset($x);\n");
06563 if(out)
06564 fprintf(out,"%s",ln.c_str());
06565 }
06566
06567 ln="\n $channel=new c_channel; $channel->init(\"";
06568 ln.append(logic_script_esc(script_type,(*i9).name));
06569 ln.append("\",$bans,$excepts,$invites,$reops);\n unset($bans); unset($excepts); unset($invites); unset($reops);\n");
06570 if(out)
06571 fprintf(out,"%s",ln.c_str());
06572
06573 {
06574 ln="";
06575
06576 ln+=" $channel->key=\"";
06577 ln+=logic_script_esc(script_type,(*i9).key);
06578 ln+="\";\n";
06579
06580 ln+=" $channel->limit=\"";
06581 ln+=logic_script_esc(script_type,(*i9).limit);
06582 ln+="\";\n";
06583
06584 ln+=" $channel->mode=\"";
06585 ln+=logic_script_esc(script_type,(*i9).modes);
06586 ln+="\";\n";
06587
06588 ln+=" $channel->topic=\"";
06589 ln+=logic_script_esc(script_type,(*i9).topic);
06590 ln+="\";\n";
06591
06592 if(out)
06593 fprintf(out,"%s",ln.c_str());
06594 ln="";
06595 }
06596
06597 vector<s_channel>::iterator i2;
06598 for(i2=r_channels.begin(); i2!=r_channels.end(); i2++) {
06599 if(cmp_strings_case_insensitive((*i9).name,logic_eval((*i2).channel_name,vars)))
06600 continue;
06601
06602 bool is_online=false;
06603 vector<s_online_user>::iterator i3;
06604 for(i3=(*i9).users.begin(); i3!=(*i9).users.end(); i3++) {
06605 if((*i3).in_logic_as.compare((*i2).username))
06606 continue;
06607 is_online=true;
06608
06609 vector<s_user>::iterator i4;
06610 for(i4=r_users.begin(); i4!=r_users.end(); i4++) {
06611 if((*i4).name.compare((*i3).in_logic_as))
06612 continue;
06613 break;
06614 }
06615 if(i4==r_users.end())
06616 break;
06617
06618 ln="\n $host_masks=array();\n";
06619 if(out)
06620 fprintf(out,"%s",ln.c_str());
06621 vector<string>::iterator i5;
06622 for(i5=(*i4).hostmask.begin(); i5!=(*i4).hostmask.end(); i5++) {
06623 ln=" $x=\"";
06624 ln.append(logic_script_esc(script_type,logic_eval(*i5,vars)));
06625 ln.append("\"; array_push($host_masks,$x);\n");
06626 if(out)
06627 fprintf(out,"%s",ln.c_str());
06628 }
06629 ln=" $fullname_masks=array();\n";
06630 if(out)
06631 fprintf(out,"%s",ln.c_str());
06632 for(i5=(*i4).fullname.begin(); i5!=(*i4).fullname.end(); i5++) {
06633 ln=" $x=\"";
06634 ln.append(logic_script_esc(script_type,logic_eval(*i5,vars)));
06635 ln.append("\"; array_push($fullname_masks,$x);\n");
06636 if(out)
06637 fprintf(out,"%s",ln.c_str());
06638 }
06639 ln=" unset($x);\n $meta=array();\n";
06640 if(out)
06641 fprintf(out,"%s",ln.c_str());
06642 map<string,string>::iterator i6;
06643 for(i6=(*i4).meta.begin(); i6!=(*i4).meta.end(); i6++) {
06644 ln=" $meta[\"";
06645 ln.append(logic_script_esc(script_type,logic_eval((*i6).first,vars)));
06646 ln.append("\"]=\"");
06647 ln.append(logic_script_esc(script_type,logic_eval((*i6).second,vars)));
06648 ln.append("\";\n");
06649 if(out)
06650 fprintf(out,"%s",ln.c_str());
06651 }
06652
06653 if(out)
06654 fprintf(out,"%s\n"," $groups=array();");
06655 vector<s_group>::iterator i7;
06656 for(i7=(*i4).groups.begin(); i7!=(*i4).groups.end(); i7++)
06657 if(out)
06658 fprintf(out,"%s%s%s\n"," array_push($groups,\"",logic_script_esc(script_type,logic_eval((*i7).name,vars)).c_str(),"\");");
06659
06660 ln=" $user=new c_user; $user->init(\"";
06661 ln.append(logic_script_esc(script_type,(*i3).nick));
06662 ln.append("\",\"");
06663 ln.append(logic_script_esc(script_type,(*i3).ident));
06664 ln.append("\",\"");
06665 ln.append(logic_script_esc(script_type,(*i3).host));
06666 ln.append("\",\"");
06667 ln.append(logic_script_esc(script_type,(*i3).fullname));
06668 ln.append("\",\"");
06669 ln.append(logic_script_esc(script_type,(*i3).in_logic_as));
06670 ln.append("\",TRUE,");
06671 if((*i2).host_unknown)
06672 ln.append("TRUE,");
06673 else
06674 ln.append("FALSE,");
06675 if((*i4).host_bot)
06676 ln.append("TRUE,");
06677 else
06678 ln.append("FALSE,");
06679 if((*i3).irc_op)
06680 ln.append("TRUE,");
06681 else
06682 ln.append("FALSE,");
06683 ln.append("\"");
06684 ln.append(logic_script_esc(script_type,(*i3).mode));
06685 ln.append("\",$host_masks,$full_name_masks,$meta,$groups);\n unset($host_masks); unset($fullname_masks); unset($meta); unset($groups);\n");
06686
06687 if(out)
06688 fprintf(out,"%s",ln.c_str());
06689
06690 ln=" $channel->add_user($user); unset($user);\n";
06691 if(out)
06692 fprintf(out,"%s",ln.c_str());
06693
06694
06695
06696 }
06697
06698 if(!is_online) {
06699 vector<s_user>::iterator i4;
06700 for(i4=r_users.begin(); i4!=r_users.end(); i4++) {
06701 if((*i4).name.compare((*i2).username))
06702 continue;
06703 break;
06704 }
06705 if(i4==r_users.end())
06706 continue;
06707
06708 ln="\n $host_masks=array();\n";
06709 if(out)
06710 fprintf(out,"%s",ln.c_str());
06711 vector<string>::iterator i5;
06712 for(i5=(*i4).hostmask.begin(); i5!=(*i4).hostmask.end(); i5++) {
06713 ln=" $x=\"";
06714 ln.append(logic_script_esc(script_type,logic_eval(*i5,vars)));
06715 ln.append("\"; array_push($host_masks,$x);\n");
06716 if(out)
06717 fprintf(out,"%s",ln.c_str());
06718 }
06719 ln=" $fullname_masks=array();\n";
06720 if(out)
06721 fprintf(out,"%s",ln.c_str());
06722 for(i5=(*i4).fullname.begin(); i5!=(*i4).fullname.end(); i5++) {
06723 ln=" $x=\"";
06724 ln.append(logic_script_esc(script_type,logic_eval(*i5,vars)));
06725 ln.append("\"; array_push($fullname_masks,$x);\n");
06726 if(out)
06727 fprintf(out,"%s",ln.c_str());
06728 }
06729 ln=" unset($x);\n $meta=array();\n";
06730 if(out)
06731 fprintf(out,"%s",ln.c_str());
06732 map<string,string>::iterator i6;
06733 for(i6=(*i4).meta.begin(); i6!=(*i4).meta.end(); i6++) {
06734 ln=" $meta[\"";
06735 ln.append(logic_script_esc(script_type,logic_eval((*i6).first,vars)));
06736 ln.append("\"]=\"");
06737 ln.append(logic_script_esc(script_type,logic_eval((*i6).second,vars)));
06738 ln.append("\";\n");
06739 if(out)
06740 fprintf(out,"%s",ln.c_str());
06741 }
06742
06743 if(out)
06744 fprintf(out,"%s\n"," $groups=array();");
06745 vector<s_group>::iterator i7;
06746 for(i7=(*i4).groups.begin(); i7!=(*i4).groups.end(); i7++)
06747 if(out)
06748 fprintf(out,"%s%s%s\n"," array_push($groups,\"",logic_script_esc(script_type,logic_eval((*i7).name,vars)).c_str(),"\");");
06749
06750 ln=" $user=new c_user; $user->init(\"";
06751
06752 ln.append("\",\"");
06753
06754 ln.append("\",\"");
06755
06756 ln.append("\",\"");
06757
06758 ln.append("\",\"");
06759 ln.append(logic_script_esc(script_type,(*i4).name));
06760 ln.append("\",FALSE,");
06761 if((*i2).host_unknown)
06762 ln.append("TRUE,");
06763 else
06764 ln.append("FALSE,");
06765 if((*i4).host_bot)
06766 ln.append("TRUE,");
06767 else
06768 ln.append("FALSE,");
06769 ln.append("FALSE,");
06770 ln.append("\"");
06771 ln.append("0");
06772 ln.append("\",$host_masks,$full_name_masks,$meta,$groups);\n unset($host_masks); unset($fullname_masks); unset($meta); unset($groups);\n");
06773
06774 if(out)
06775 fprintf(out,"%s",ln.c_str());
06776
06777 ln=" $channel->add_user($user); unset($user);\n";
06778 if(out)
06779 fprintf(out,"%s",ln.c_str());
06780 }
06781 }
06782 ln=" $channels[strtolower(\"";
06783 ln.append((*i9).name);
06784 ln.append("\")]=$channel; unset($channel);\n");
06785 if(out)
06786 fprintf(out,"%s",ln.c_str());
06787 }
06788 ln="\n";
06789 if(out)
06790 fprintf(out,"%s",ln.c_str());
06791 }
06792
06793
06794 {
06795 tmp=filesys_get_script(script_type);
06796 if(out)
06797 fprintf(out,"%s",tmp.c_str());
06798 tmp="";
06799 }
06800
06801 line[0]=0;
06802 while(in && !feof(in)) {
06803 if(fgets(line,1024*10-1,in)==NULL)
06804 break;
06805 line[1024*10]=0;
06806 if(line[strlen(line)-1]=='\r')
06807 line[strlen(line)-1]=0;
06808 if(line[strlen(line)-1]=='\n')
06809 line[strlen(line)-1]=0;
06810 if(line[strlen(line)-1]=='\r')
06811 line[strlen(line)-1]=0;
06812 if(line[strlen(line)-1]=='\n')
06813 line[strlen(line)-1]=0;
06814 if(!strcmp(line,"// RESULT"))
06815 break;
06816 if(strlen(line))
06817 if(out)
06818 fprintf(out,"%s",line);
06819 tmp="\n";
06820 if(out)
06821 fprintf(out,"%s",tmp.c_str());
06822 line[0]=0;
06823 }
06824
06825 tmp=" unlink(\"./";
06826 tmp+=fn;
06827 tmp+="\");\n\n";
06828 if(out)
06829 fprintf(out,"%s",tmp.c_str());
06830
06831 line[0]=0;
06832 while(in && !feof(in)) {
06833 if(fgets(line,1024*10-1,in)==NULL)
06834 break;
06835 line[1024*10]=0;
06836 if(line[strlen(line)-1]=='\r')
06837 line[strlen(line)-1]=0;
06838 if(line[strlen(line)-1]=='\n')
06839 line[strlen(line)-1]=0;
06840 if(line[strlen(line)-1]=='\r')
06841 line[strlen(line)-1]=0;
06842 if(line[strlen(line)-1]=='\n')
06843 line[strlen(line)-1]=0;
06844 if(strlen(line))
06845 if(out)
06846 fprintf(out,"%s",line);
06847 tmp="\n";
06848 if(out)
06849 fprintf(out,"%s",tmp.c_str());
06850 line[0]=0;
06851 }
06852
06853 if(out)
06854 fclose(out);
06855 if(in)
06856 fclose(in);
06857
06858 s_tmp_file t;
06859 t.script=true;
06860 t.script_num=script_num;
06861 if(script_type.length()<sizeof(t.script_type))
06862 strcpy(t.script_type,script_type.c_str());
06863 else
06864 t.script_type[0]=0;
06865 strcpy(t.command_line,(conf_getvar("php_processor")).c_str());
06866
06867 strcpy(t.command_args,"\"." FILE_SLASH);
06868 strcat(t.command_args,fn.c_str());
06869 strcat(t.command_args,"\"");
06870 if(!conf_getvar("php_processor_args").empty()) {
06871 strcat(t.command_args," ");
06872 strcat(t.command_args,conf_getvar("php_processor_args").c_str());
06873 }
06874 strcpy(t.command_dir,conf_getvar("php_script_dir").c_str());
06875
06876 t.has_been_run=false;
06877 t.start_up_time=0;
06878 tmp_files.push_back(t);
06879
06880 delete[] line;
06881 line=NULL;
06882 }
06883 }
06884
06885
06886
06887
06888
06889
06890
06891
06892
06893
06894
06895
06896
06897
06898 int logic_exec(const s_procedure& proc, map<string,string> vars, bool from_work=false)
06899 {
06900 static bool in_exception=false;
06901 if(in_exception)
06902 return 0;
06903
06904 extern char irc_server[1024];
06905 extern unsigned short irc_port;
06906
06907 string proc_name=proc.name;
06908
06909 try {
06910
06911 list<s_command>::const_iterator i=proc.commands.begin();
06912
06913 static list<s_command>::const_iterator redirect_checkpoint;
06914 if(0) {
06915 after_redirect:
06916 i=redirect_checkpoint;
06917 }
06918
06919 for(; i!=proc.commands.end(); i++) {
06920 if(from_work && (*i).command!=_work)
06921 continue;
06922 if(from_work && (*i).command==_work) {
06923 from_work=false;
06924 continue;
06925 }
06926 if((*i).command==_op || (*i).command==_deop || (*i).command==_voice || (*i).command==_devoice) {
06927 if(irc_got_op(logic_eval((*i).channel,vars))) {
06928 extern bool dcc_want_to_upgrade;
06929 if(dcc_want_to_upgrade) {
06930 string target_nick=logic_eval((*i).whom,vars);
06931 string ident=irc_get_ident(target_nick);
06932 string host=irc_get_host(target_nick);
06933 string fullname=irc_get_fullname(target_nick);
06934 string user=logic_find_user(target_nick, ident, host, fullname, irc_is_ircop(target_nick));
06935 vector<s_user>::iterator i1;
06936 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
06937 if((*i1).host_bot && !(*i1).name.compare(user)) {
06938 string channel=logic_eval((*i).channel,vars);
06939 char prefix='+';
06940 char action='0';
06941 if((*i).command==_op)
06942 action='o';
06943 if((*i).command==_voice)
06944 action='v';
06945 if((*i).command==_deop) {
06946 action='o';
06947 prefix='-';
06948 }
06949 if((*i).command==_devoice) {
06950 action='v';
06951 prefix='-';
06952 }
06953 string mode=(string)""+prefix;
06954 mode+=(string)""+action;
06955 dcc_upgrade_bot_mode(target_nick,ident,host,fullname,channel,mode);
06956 break;
06957 }
06958 }
06959 }
06960 }
06961 }
06962 switch((*i).command) {
06963 case _op:
06964 {
06965 if(!irc_got_op(logic_eval((*i).channel,vars)) || (atol(conf_getvar("smart_mode").c_str()) && irc_get_mode(logic_eval((*i).channel,vars),logic_eval((*i).whom,vars)).find((string)""+irc_isupport.get_prefix1('o'),0)!=string::npos))
06966 break;
06967 irc_op(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str(),(*i).priority);
06968 }
06969 break;
06970 case _deop:
06971 {
06972 if(!irc_got_op(logic_eval((*i).channel,vars)) || (atol(conf_getvar("smart_mode").c_str()) && irc_get_mode(logic_eval((*i).channel,vars),logic_eval((*i).whom,vars)).find((string)""+irc_isupport.get_prefix1('o'),0)==string::npos))
06973 break;
06974 irc_deop(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str(),(*i).priority);
06975 }
06976 break;
06977 case _voice:
06978 {
06979 if(!irc_got_op(logic_eval((*i).channel,vars)) || (atol(conf_getvar("smart_mode").c_str()) && irc_get_mode(logic_eval((*i).channel,vars),logic_eval((*i).whom,vars)).find('+',0)!=string::npos))
06980 break;
06981 irc_voice(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str(),(*i).priority);
06982 }
06983 break;
06984 case _devoice:
06985 {
06986 if(!irc_got_op(logic_eval((*i).channel,vars)) || (atol(conf_getvar("smart_mode").c_str()) && irc_get_mode(logic_eval((*i).channel,vars),logic_eval((*i).whom,vars)).find('+',0)==string::npos))
06987 break;
06988 irc_devoice(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str(),(*i).priority);
06989 }
06990 break;
06991 case _kick:
06992 if(!irc_got_op(logic_eval((*i).channel,vars)))
06993 break;
06994 irc_kick(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str(),logic_eval((*i).msg_text,vars).c_str());
06995 break;
06996 case _msg:
06997 irc_privmsg(logic_eval((*i).whom,vars).c_str(),logic_eval((*i).msg_text,vars).c_str(),(*i).priority);
06998 break;
06999 case _msgq:
07000 irc_privmsg(logic_eval((*i).whom,vars).c_str(),(logic_eval((*i).msg_text,vars)+"\x01"+logic_eval((*i).msg_quoted,vars)+"\x01").c_str(),(*i).priority);
07001 break;
07002 case _if_in:
07003 if(logic_eval((*i).left,vars).find(logic_eval((*i).right,vars),0)==string::npos) {
07004 int g=(*i)._goto_line;
07005 while(i!=proc.commands.end() && (*i).line!=g)
07006 i++;
07007 }
07008 break;
07009 case _if_n_in:
07010 if(logic_eval((*i).left,vars).find(logic_eval((*i).right,vars),0)!=string::npos) {
07011 int g=(*i)._goto_line;
07012 while(i!=proc.commands.end() && (*i).line!=g)
07013 i++;
07014 }
07015 break;
07016 case _if_match:
07017 if(logic_eval((*i).left,vars).compare(logic_eval((*i).right,vars))) {
07018 int g=(*i)._goto_line;
07019 while(i!=proc.commands.end() && (*i).line!=g)
07020 i++;
07021 }
07022 break;
07023 case _if_match_case_insensitive:
07024 if(logic_cmp_strings_case_insensitive(logic_eval((*i).left,vars),logic_eval((*i).right,vars))) {
07025 int g=(*i)._goto_line;
07026 while(i!=proc.commands.end() && (*i).line!=g)
07027 i++;
07028 }
07029 break;
07030 case _if_n_match:
07031 if(!logic_eval((*i).left,vars).compare(logic_eval((*i).right,vars))) {
07032 int g=(*i)._goto_line;
07033 while(i!=proc.commands.end() && (*i).line!=g)
07034 i++;
07035 }
07036 break;
07037 case _if_n_match_case_insensitive:
07038 if(!logic_cmp_strings_case_insensitive(logic_eval((*i).left,vars),logic_eval((*i).right,vars))) {
07039 int g=(*i)._goto_line;
07040 while(i!=proc.commands.end() && (*i).line!=g)
07041 i++;
07042 }
07043 break;
07044 case _if_group:
07045 case _if_n_group:
07046 {
07047 bool skip=(*i).command==_if_group;
07048 bool got=false;
07049 string obj=logic_eval((*i).left.c_str(),vars);
07050 string grp=logic_eval((*i).right.c_str(),vars);
07051 {
07052 vector<s_channel>::iterator i1;
07053 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
07054 if((*i1).username.compare(obj))
07055 continue;
07056 vector<s_group>::iterator i2;
07057 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
07058 if((*i).command==_if_group) {
07059 if(!logic_eval((*i2).name,vars).compare(grp)) {
07060 skip=false;
07061 got=true;
07062 break;
07063 }
07064 } else {
07065 if(!logic_eval((*i2).name,vars).compare(grp)) {
07066 skip=true;
07067 got=true;
07068 break;
07069 }
07070 }
07071 }
07072 if(got)
07073 break;
07074 }
07075 }
07076 if(!got) {
07077 vector<s_user>::iterator i1;
07078 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
07079 if((*i1).name.compare(obj))
07080 continue;
07081 vector<s_group>::iterator i2;
07082 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
07083 if((*i).command==_if_group) {
07084 if(!logic_eval((*i2).name,vars).compare(grp)) {
07085 skip=false;
07086 got=true;
07087 break;
07088 }
07089 } else {
07090 if(!logic_eval((*i2).name,vars).compare(grp)) {
07091 skip=true;
07092 got=true;
07093 break;
07094 }
07095 }
07096 }
07097 if(got)
07098 break;
07099 }
07100 }
07101 if(!got) {
07102 vector<s_procedure>::iterator i1;
07103 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
07104 if((*i1).name.compare(obj))
07105 continue;
07106 vector<s_group>::iterator i2;
07107 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
07108 if((*i).command==_if_group) {
07109 if(!logic_eval((*i2).name,vars).compare(grp)) {
07110 skip=false;
07111 got=true;
07112 break;
07113 }
07114 } else {
07115 if(!logic_eval((*i2).name,vars).compare(grp)) {
07116 skip=true;
07117 got=true;
07118 break;
07119 }
07120 }
07121 }
07122 if(got)
07123 break;
07124 }
07125 }
07126 if(skip) {
07127 int g=(*i)._goto_line;
07128 if(i!=proc.commands.end())
07129 while((*i).line!=g)
07130 i++;
07131 }
07132 }
07133 break;
07134 case _return:
07135 return 0;
07136 case _end_bracket:
07137 break;
07138 case _work:
07139 {
07140 work_proc=proc;
07141 work_vars=vars;
07142 return 0;
07143 }
07144 case _timer_once:
07145 case _timer_every:
07146 {
07147 s_timer t;
07148 t.once=(*i).command==_timer_once;
07149 t.name=logic_eval((*i).timer_name,vars);
07150 time(&t.set_at);
07151 time(&t.again_at);
07152 t.duration=(*i).timer_sec;
07153 t.again_at+=t.duration;
07154
07155 string cs=(*i).timer_cmd;
07156 unsigned int i2;
07157 for(i2=0; i2<cs.length(); i2++)
07158 if(cs[i2]=='(')
07159 break;
07160 cs.erase(i2,cs.length()-i2);
07161 vector<s_procedure>::iterator i1;
07162 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
07163 string s=(*i1).name;
07164 unsigned int i2;
07165 for(i2=0; i2<s.length(); i2++)
07166 if(s[i2]=='(')
07167 break;
07168 s.erase(i2,s.length()-i2);
07169 if(!s.compare(cs)) {
07170 cs=(*i1).name;
07171 break;
07172 }
07173 }
07174 t.call_string=cs;
07175
07176 cs=(*i).timer_cmd;
07177 for(i2=0; i2<cs.length(); i2++)
07178 if(cs[i2]=='(')
07179 break;
07180 cs.erase(0,i2+1);
07181
07182 list<string> params;
07183 bool str=false;
07184 string p;
07185 string var="";
07186 for(i2=0; i2<cs.length(); i2++) {
07187 if(cs[i2]=='\"') {
07188
07189 str=!str;
07190 continue;
07191 }
07192 if(!str && cs[i2]==',') {
07193 if(var.length()>0 && var[0]=='$') {
07194 map<string,string>::iterator i3;
07195 for(i3=vars.begin(); i3!=vars.end(); i3++) {
07196 if(!(*i3).first.compare(var)) {
07197 p+=(*i3).second;
07198 params.push_back(p);
07199 p="";
07200 var="";
07201 break;
07202 }
07203 }
07204 var="";
07205 }
07206 if(p.empty())
07207 p=var;
07208 if(!p.empty()) {
07209 if(p.length()>0 && p[0]=='\"')
07210 p=logic_eval(p,vars);
07211 params.push_back(p);
07212 }
07213 p="";
07214 var="";
07215 continue;
07216 }
07217 if(!str && cs[i2]==')') {
07218 if(var.length()>0) {
07219 if(var[0]=='$') {
07220 map<string,string>::iterator i3;
07221 for(i3=vars.begin(); i3!=vars.end(); i3++) {
07222 if(!(*i3).first.compare(var)) {
07223 p+=(*i3).second;
07224 params.push_back(p);
07225 p="";
07226 var="";
07227 break;
07228 }
07229 }
07230 }
07231 var="";
07232 }
07233 if(p.empty())
07234 p=var;
07235 if(!p.empty()) {
07236 if(p.length()>0 && p[0]=='\"')
07237 p=logic_eval(p,vars);
07238 params.push_back(p);
07239 }
07240 p="";
07241 var="";
07242 break;
07243 }
07244 if(!str && cs[i2]=='.') {
07245 if(var.length()>0) {
07246 if(var[0]=='$') {
07247 map<string,string>::iterator i3;
07248 for(i3=vars.begin(); i3!=vars.end(); i3++) {
07249 if(!(*i3).first.compare(var)) {
07250 p+=(*i3).second;
07251 break;
07252 }
07253 }
07254 }
07255 var="";
07256 }
07257 continue;
07258 }
07259 if(!str && (cs[i2]=='$' || var.length()>0)) {
07260 var+=cs[i2];
07261 continue;
07262 }
07263 p+=cs[i2];
07264 }
07265
07266 t.params=params;
07267 t.vars=vars;
07268 r_timers.push_back(t);
07269 }
07270 break;
07271 case _kill_timers:
07272 {
07273 string name=logic_eval((*i).timer_name,vars);
07274 vector<s_timer>::iterator i1;
07275 kt_l:
07276 for(i1=r_timers.begin(); i1!=r_timers.end(); i1++) {
07277 if(!match((char*)name.c_str(),(char*)(*i1).name.c_str())) {
07278 r_timers.erase(i1);
07279 goto kt_l;
07280 }
07281 }
07282 }
07283 break;
07284 case _execute:
07285 {
07286 logic_execute((*i).exec,vars);
07287 }
07288 break;
07289 case _remote_execute:
07290 {
07291 string call_string=(*i).exec;
07292 string cs=call_string;
07293 unsigned int i2;
07294 for(i2=0; i2<cs.length(); i2++)
07295 if(cs[i2]=='(')
07296 break;
07297 cs.erase(i2,cs.length()-i2);
07298
07299 string name_only=cs;
07300
07301 cs=(*i).exec;
07302 for(i2=0; i2<cs.length(); i2++)
07303 if(cs[i2]=='(')
07304 break;
07305 cs.erase(0,i2+1);
07306 if(cs.length()>0 && cs[cs.length()-1]==')')
07307 cs.erase(cs.length()-1,1);
07308 cs+=",";
07309
07310 list<string> params;
07311 bool str=false;
07312 string p;
07313 for(i2=0; i2<cs.length() && cs.compare(","); i2++) {
07314 if(cs[i2]=='\"') {
07315 p+="\"";
07316
07317 str=!str;
07318 continue;
07319 }
07320 if(!str && cs[i2]==',') {
07321
07322
07323
07324
07325
07326
07327
07328
07329
07330 p=logic_eval(p,vars);
07331 params.push_back(p);
07332 p="";
07333 continue;
07334 }
07335 if(!str && cs[i2]==')') {
07336 if(p.compare("")) {
07337
07338
07339
07340
07341
07342
07343
07344
07345
07346 p=logic_eval(p,vars);
07347 params.push_back(p);
07348 }
07349 break;
07350 }
07351 p+=cs[i2];
07352 }
07353
07354
07355 string result=botnet_remote_procedure_call(logic_eval((*i).botname,vars),name_only,params);
07356
07357 {
07358 pair<string,string> p;
07359 p.first=(*i).result;
07360 p.second=result;
07361 {
07362 map<string,string>::iterator i1;
07363 bool got=false;
07364 for(i1=vars.begin(); i1!=vars.end(); i1++)
07365 if(!(*i1).first.compare(p.first)) {
07366 (*i1).second=p.second;
07367 got=true;
07368 break;
07369 }
07370 if(!got)
07371 vars.insert(p);
07372 }
07373 }
07374 }
07375 break;
07376 case _smtp:
07377 {
07378 char tmp[64];
07379 string fn="." FILE_SLASH "sendmail" FILE_SLASH;
07380 ltoa(rand(),tmp,16);
07381 fn+=tmp;
07382 ltoa(rand(),tmp,16);
07383 fn+=tmp;
07384 ltoa(rand(),tmp,16);
07385 fn+=tmp;
07386 ltoa(rand(),tmp,16);
07387 fn+=tmp;
07388 fn+=".sendmail";
07389 FILE* f=fopen(fn.c_str(),"wb");
07390 if(f) {
07391 fprintf(f,"0.0.0.0\r\n");
07392 fprintf(f,"%s\r\n",logic_eval((*i).smtp.server,vars).c_str());
07393 fprintf(f,"%u\r\n",(*i).smtp.port);
07394 fprintf(f,"HELO %s\r\n",logic_eval((*i).smtp.helo,vars).c_str());
07395 fprintf(f,"MAIL FROM: %s\r\n",logic_eval((*i).smtp.mail_from,vars).c_str());
07396 fprintf(f,"RCPT TO: %s\r\n",logic_eval((*i).smtp.rcpt_to,vars).c_str());
07397 fprintf(f,"DATA\r\n");
07398 string data=(*i).smtp.data;
07399 data="\""+data+"\"";
07400 fprintf(f,"%s\r\n",logic_eval(data,vars).c_str());
07401 fclose(f);
07402
07403 string params=fn;
07404 params=(string)"\""+params+"\"";
07405
07406 #ifdef _WIN32
07407 fn="." FILE_SLASH "sendmail" FILE_SLASH "sendmail.exe";
07408 #else
07409 fn="." FILE_SLASH "sendmail" FILE_SLASH "sendmail";
07410 #endif
07411 s_tmp_file t;
07412 t.script=false;
07413 t.h=exec_async_exec(fn.c_str(),params.c_str(),NULL);
07414 t.start_up_time=time(NULL);
07415 tmp_files.push_back(t);
07416
07417 stats_mail_sent();
07418 }
07419 }
07420 break;
07421 case _net_send:
07422 {
07423 #ifdef _WIN32
07424 string fn="net";
07425 string param1=logic_eval((*i).net_send_host,vars);
07426 while(param1.find("\"",0)!=string::npos)
07427 param1.erase(param1.find("\"",0),1);
07428 string param2=logic_eval((*i).net_send_msg,vars);
07429 while(param2.find("\"",0)!=string::npos)
07430 param2.erase(param2.find("\"",0),1);
07431 string params=(string)"send \""+param1+"\" \""+param2+"\"";
07432 s_tmp_file t;
07433 t.script=false;
07434 t.h=exec_async_exec(fn.c_str(),params.c_str(),NULL);
07435 t.start_up_time=time(NULL);
07436 tmp_files.push_back(t);
07437 #endif
07438 }
07439 break;
07440 case _log:
07441 log_bot(logic_eval((*i).log,vars).c_str());
07442 break;
07443 case _join:
07444 {
07445 bool on_channel=false;
07446 vector<s_online_channel>::iterator i2;
07447 for(i2=irc_channels.begin(); i2!=irc_channels.end(); i2++)
07448 if(!cmp_strings_case_insensitive((*i2).name,logic_eval((*i).channel,vars))) {
07449 on_channel=true;
07450 break;
07451 }
07452
07453
07454 irc_join(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).channel_key,vars).c_str());
07455 }
07456 break;
07457 case _part:
07458 {
07459 bool on_channel=false;
07460 vector<s_online_channel>::iterator i2;
07461 for(i2=irc_channels.begin(); i2!=irc_channels.end(); i2++)
07462 if(!cmp_strings_case_insensitive((*i2).name,logic_eval((*i).channel,vars))) {
07463 on_channel=true;
07464 break;
07465 }
07466
07467
07468 irc_part(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).msg_text,vars).c_str());
07469 }
07470 break;
07471 case _disconnect:
07472 irc_disconnect();
07473 break;
07474 case _try_connect:
07475 irc_disconnect();
07476 dcc_loop();
07477 sock_send_cache();
07478 if(!irc_socket.cmp()) {
07479 if(irc_recommended_port==0) {
07480 if(irc_server_iterator==irc_servers.end()) {
07481 irc_server_iterator=irc_servers.begin();
07482 if(irc_server_iterator==irc_servers.end()) {
07483 log_bot("No server in the list! Fatal error.");
07484 return LOGIC_NO_SERVER;
07485 }
07486 }
07487 irc_server_host=(*irc_server_iterator).host;
07488 irc_server_port=(*irc_server_iterator).port;
07489 irc_connect("0.0.0.0",(*irc_server_iterator).host.c_str(),(*irc_server_iterator).port);
07490 irc_server_iterator++;
07491 dcc_loop();
07492 sock_send_cache();
07493 } else {
07494 unsigned short p=irc_recommended_port;
07495 irc_recommended_port=0;
07496 irc_connect("0.0.0.0",irc_recommended_server.c_str(),p);
07497 dcc_loop();
07498 sock_send_cache();
07499 }
07500 }
07501 break;
07502 case _irc_server:
07503 {
07504 s_irc_server s;
07505 s.host=logic_eval((*i).server,vars);
07506 s.port=(*i).port;
07507 if(s.port==0)
07508 s.port=6667;
07509 irc_servers.push_back(s);
07510 irc_server_iterator=irc_servers.begin();
07511 }
07512 break;
07513 case _bot_nick:
07514 {
07515 vector<string>::const_iterator ii=(*i).bot_nick.begin();
07516 while(ii!=(*i).bot_nick.end()) {
07517 irc_nicks.push_back(logic_eval(*ii,vars));
07518 ii++;
07519 }
07520 }
07521 break;
07522 case _delete_irc_servers:
07523 {
07524 vector<s_irc_server>::iterator ii;
07525 again_erase1:
07526 for(ii=irc_servers.begin(); ii!=irc_servers.end(); ii++) {
07527 string id="[";
07528 id+=(*ii).host;
07529 id+="]:";
07530 char tmp[64];
07531 ltoa((*ii).port,tmp,10);
07532 id+=tmp;
07533
07534 if(!match((char*)(*i).server.c_str(),(char*)id.c_str())) {
07535 irc_servers.erase(ii);
07536 goto again_erase1;
07537 }
07538 }
07539 irc_server_iterator=irc_servers.end();
07540 }
07541 break;
07542 case _delete_nicks:
07543 {
07544 vector<string>::iterator ii;
07545 again_erase2:
07546 for(ii=irc_nicks.begin(); ii!=irc_nicks.end(); ii++) {
07547 string id=*ii;;
07548
07549 if(!match((char*)(*i).nick.c_str(),(char*)id.c_str())) {
07550 irc_nicks.erase(ii);
07551 goto again_erase2;
07552 }
07553 }
07554 }
07555 break;
07556 case _change_nick:
07557 {
07558 if(!logic_eval((*i).nick,vars).compare(irc_nick))
07559 break;
07560
07561 string msg="NICK ";
07562 msg+=logic_eval((*i).nick,vars);
07563 irc_putserv(msg.c_str(),true,HIGH_PRIORITY);
07564 }
07565 break;
07566 case _bot_ident:
07567 {
07568 irc_ident=logic_eval((*i).bot_ident,vars);
07569 if(atol(conf_getvar("disable_ident_daemon").c_str()))
07570 break;
07571 identd_fail:
07572 in_addr a;
07573 memset(&a,0,sizeof(a));
07574 identd4_shutdown();
07575 bool ok=identd_startup(a,113);
07576 ident_string=": USERID : UNIX :";
07577 ident_string+=logic_eval((*i).bot_ident,vars);
07578 if(!ok && atol(conf_getvar("important_ident_daemon").c_str())) {
07579 dcc_loop();
07580 sock_send_cache();
07581 if(dcc_want_to_die || dcc_want_to_restart) {
07582 return 0;
07583 }
07584 sleep(500);
07585 goto identd_fail;
07586 }
07587 }
07588 break;
07589 case _bot_ident_ipv6:
07590 {
07591 irc_ident=logic_eval((*i).bot_ident,vars);
07592 if(atol(conf_getvar("disable_ident_daemon").c_str()))
07593 break;
07594 identd_fail6:
07595 char local[256];
07596 strcpy(local,"::");
07597 identd6_shutdown();
07598 bool ok=identd_startup(local,113);
07599 ident_string=": USERID : UNIX :";
07600 ident_string+=logic_eval((*i).bot_ident,vars);
07601 if(!ok && atol(conf_getvar("important_ident_daemon").c_str())) {
07602 dcc_loop();
07603 sock_send_cache();
07604 if(dcc_want_to_die || dcc_want_to_restart) {
07605 return 0;
07606 }
07607 sleep(500);
07608 goto identd_fail6;
07609 }
07610 }
07611 break;
07612 case _bot_fullname:
07613 strcpy(irc_fullname,logic_eval((*i).bot_fullname,vars).c_str());
07614 break;
07615 case _bot_auth:
07616 {
07617
07618
07619
07620
07621
07622
07623 }
07624 break;
07625 case _bot_redir:
07626 irc_set_redir((*i).bot_redir);
07627 break;
07628 case _if_error:
07629 redirect_checkpoint=i;
07630 if(irc_socket.cmp()) {
07631 int g=(*i)._goto_line;
07632 while(i!=proc.commands.end() && (*i).line!=g)
07633 i++;
07634 }
07635 break;
07636 case _wait:
07637 {
07638 int got_nick=0;
07639
07640 time_t first_try=time(NULL);
07641 int auth_state=0;
07642 vector<string>::iterator ii;
07643 bool error=false;
07644
07645 l2:
07646 {
07647 time_t now=time(NULL);
07648 extern list<char*> msgs_from_server;
07649 while(msgs_from_server.empty()) {
07650 if(now+10<=time(NULL))
07651 break;
07652 sleep(10);
07653 if(irc_loop_putserv()) {
07654 int reason=irc_loop_process_input();
07655 irc_socket.clear();
07656 if(reason==2)
07657 goto throttled;
07658 break;
07659 }
07660 logic_loop_identd();
07661 }
07662 }
07663
07664 ii=irc_nicks.begin();
07665 for(int i1=1; ii!=irc_nicks.end(); ii++, i1++) {
07666 if(i1<=last_nick_idx)
07667 continue;
07668 got_nick=1;
07669 irc_nick[0]=0;
07670 if((*ii).length()<sizeof(irc_nick))
07671 strcpy(irc_nick,(*ii).c_str());
07672 last_nick_idx++;
07673 break;
07674 }
07675 if(got_nick==0) {
07676 last_nick_idx=0;
07677 got_nick=2;
07678 goto l2;
07679 }
07680 if(got_nick==2) {
07681 last_nick_idx=0;
07682 log_bot("I don't have any nicks! I am dying now!");
07683 log_irc(false,"I don't have any nicks! I am dying now!");
07684 irc_disconnect();
07685
07686 dcc_want_to_die=true;
07687 dcc_who_is_killing="SELF";
07688 return 0;
07689 continue;
07690 }
07691
07692 first_try=time(NULL);
07693 auth_state=0;
07694 l1:
07695 extern time_t irc_last_keepalive_detection;
07696 time(&irc_last_keepalive_detection);
07697 if(dcc_want_to_die || dcc_want_to_restart) {
07698 return 0;
07699 }
07700 if(first_try+60*3<time(NULL)) {
07701 continue;
07702 }
07703 if(auth_state==0) {
07704
07705 auth_state++;
07706 }
07707 if(auth_state==1) {
07708 string msg="USER ";
07709 if(!irc_ident.compare("*")) {
07710 irc_ident=logic_to_lower(irc_nick);
07711 erase_again:
07712 for(unsigned int ii=0; ii<irc_ident.length(); ii++)
07713 if(irc_ident[ii]<'a' || irc_ident[ii]>'z') {
07714 irc_ident.erase(ii,1);
07715 goto erase_again;
07716 }
07717 if(irc_ident.empty())
07718 irc_ident=logic_to_lower(irc_nick);
07719 }
07720 msg+=irc_ident;
07721 msg+=" 0 \"";
07722 msg+=irc_server_host;
07723 msg+="\" :";
07724 msg+=irc_fullname;
07725 irc_put(msg,HIGH_PRIORITY);
07726
07727 auth_state++;
07728
07729 if(irc_loop_putserv()) {
07730 irc_socket.clear();
07731 continue;
07732 }
07733 }
07734 sleep(50);
07735 error=false;
07736 while(msgs_to_server.begin()!=msgs_to_server.end() ) {
07737 sleep(1);
07738 if(irc_loop_putserv()) {
07739 int reason=irc_loop_process_input();
07740 irc_socket.clear();
07741 if(reason==2)
07742 goto throttled;
07743 break;
07744 }
07745 logic_loop_identd();
07746 irc_loop_process_input();
07747 }
07748 if(error)
07749 break;
07750 logic_loop_identd();
07751 dcc_loop();
07752 sock_send_cache();
07753 if(irc_loop_process_input()==2) {
07754 throttled:
07755 last_nick_idx=0;
07756
07757 log_bot("Reconnecting too fast: sleeping for 60 seconds...");
07758 log_irc(false,"Reconnecting too fast: sleeping for 60 seconds...");
07759
07760 for(int i1=0; i1<60*1000; ) {
07761 dcc_loop();
07762 sock_send_cache();
07763 sleep(50);
07764 i1+=50;
07765 }
07766
07767 irc_connect("0.0.0.0",irc_server_host.c_str(),irc_server_port);
07768 goto after_redirect;
07769 }
07770
07771 if(!irc_socket.cmp() && last_msg.response[0]==0) {
07772 last_nick_idx=0;
07773 continue;
07774 }
07775 size_t i1_;
07776 for(i1_=0; i1_<strlen(last_msg.response); i1_++)
07777 if(last_msg.response[i1_]==0x20)
07778 break;
07779 int resp=-1;
07780 char redirect[1024*2];
07781 if(last_msg.response[i1_]==0x20 &&
07782 last_msg.response[i1_+1]>='0' && last_msg.response[i1_+1]<='9' &&
07783 last_msg.response[i1_+2]>='0' && last_msg.response[i1_+2]<='9' &&
07784 last_msg.response[i1_+3]>='0' && last_msg.response[i1_+3]<='9') {
07785 resp=(last_msg.response[i1_+1]-'0')*100+(last_msg.response[i1_+2]-'0')*10+(last_msg.response[i1_+3]-'0');
07786 redirect[0]=0;
07787 if(strlen(last_msg.response)<sizeof(redirect))
07788 strcpy(redirect,last_msg.response);
07789 last_msg.response[0]=0;
07790 }
07791
07792 if(resp==-1) {
07793 if(auth_state==4) {
07794 auth_state++;
07795 }
07796 if(auth_state==3) {
07797 for(int i1=0; i1<100; ) {
07798 dcc_loop();
07799 sock_send_cache();
07800 sleep(50);
07801 i1+=50;
07802 if(irc_loop_putserv())
07803 break;
07804 irc_loop_process_input();
07805 }
07806 if(irc_loop_putserv())
07807 break;
07808 string nick="NICK ";
07809 nick+=irc_nick;
07810 irc_put(nick,HIGH_PRIORITY);
07811 auth_state++;
07812 }
07813 if(auth_state==2) {
07814 auth_state++;
07815 for(int i1=0; i1<1*1000; ) {
07816 dcc_loop();
07817 sock_send_cache();
07818 sleep(50);
07819 i1+=50;
07820 if(irc_loop_putserv())
07821 break;
07822 irc_loop_process_input();
07823 }
07824 }
07825 if(irc_loop_putserv()) {
07826 irc_loop_process_input();
07827 sock_close(irc_socket);
07828 irc_socket.clear();
07829 last_nick_idx=0;
07830 break;
07831 }
07832 logic_loop_identd();
07833 irc_loop_process_input();
07834 dcc_loop();
07835 sock_send_cache();
07836 goto l1;
07837 }
07838 if(resp>=400 && resp<=599) {
07839
07840 if(resp==433 || resp==437) {
07841
07842 int got_nick=0;
07843 l3:
07844 vector<string>::iterator ii=irc_nicks.begin();
07845 for(int i1=1; ii!=irc_nicks.end(); ii++, i1++) {
07846 if(i1<=last_nick_idx)
07847 continue;
07848 got_nick=1;
07849 irc_nick[0]=0;
07850 if((*ii).length()<sizeof(irc_nick))
07851 strcpy(irc_nick,(*ii).c_str());
07852 last_nick_idx++;
07853 break;
07854 }
07855 if(got_nick==0) {
07856 last_nick_idx=0;
07857 got_nick=2;
07858 goto l3;
07859 }
07860 if(got_nick==2) {
07861 last_nick_idx=0;
07862 log_bot("I don't have any nicks! I am dying now!");
07863 log_irc(false,"I don't have any nicks! I am dying now!");
07864 irc_disconnect();
07865
07866 dcc_want_to_die=true;
07867 dcc_who_is_killing="SELF";
07868 return 0;
07869 }
07870 if(got_nick==1) {
07871 string nick="NICK ";
07872 nick+=irc_nick;
07873 irc_put(nick,HIGH_PRIORITY);
07874 auth_state=2;
07875 if(irc_loop_putserv()) {
07876 irc_socket.clear();
07877 break;
07878 }
07879 irc_loop_process_input();
07880 goto l1;
07881 }
07882
07883 return LOGIC_RESTART;
07884 }
07885 } else {
07886 if(resp==10) {
07887
07888 string msg="Received redirect message: ";
07889 msg+=redirect;
07890 log_bot(msg.c_str());
07891 log_irc(false,msg.c_str());
07892 extern bool irc_follow_redirs;
07893 if(irc_follow_redirs) {
07894 log_bot("Redirecting...");
07895 log_irc(false,"Redirecting...");
07896 string msg=redirect;
07897
07898 if(msg.find(" ")!=string::npos)
07899 msg.erase(0,msg.find(" ")+1);
07900 if(msg.find(" ")!=string::npos)
07901 msg.erase(0,msg.find(" ")+1);
07902 if(msg.find(" ")!=string::npos)
07903 msg.erase(0,msg.find(" ")+1);
07904 irc_recommended_server="";
07905 while(msg.length()>0 && msg[0]!=0x20) {
07906 irc_recommended_server+=msg[0];
07907 msg.erase(0,1);
07908 }
07909 msg.erase(0,1);
07910 string port;
07911 while(msg.length()>0 && msg[0]!=0x20) {
07912 port+=msg[0];
07913 msg.erase(0,1);
07914 }
07915 irc_recommended_port=(unsigned short)atol(port.c_str());
07916
07917 last_nick_idx=0;
07918
07919 {
07920 irc_disconnect();
07921 unsigned short p=irc_recommended_port;
07922 irc_recommended_port=0;
07923 irc_connect("0.0.0.0",irc_recommended_server.c_str(),p);
07924
07925 identd_renew();
07926
07927 goto after_redirect;
07928 }
07929 } else {
07930
07931
07932
07933
07934
07935
07936
07937
07938
07939 irc_disconnect();
07940 last_nick_idx=0;
07941 continue;
07942 }
07943 }
07944 if(first_try+60*3<time(NULL)) {
07945 last_nick_idx=0;
07946 continue;
07947 }
07948 bool got=false;
07949 if(resp>=1 && resp<=5)
07950 got=true;
07951 if(resp>=251 && resp<=255)
07952 got=true;
07953 if(resp==372 || resp==375)
07954 got=true;
07955 if(got)
07956 identd_shutdown();
07957 if(resp==20) {
07958
07959
07960
07961
07962 for(int i1=0; i1<500; ) {
07963 dcc_loop();
07964 sock_send_cache();
07965 sleep(50);
07966 i1+=50;
07967 }
07968 goto l1;
07969 }
07970 if(!got) {
07971 logic_loop_identd();
07972 irc_loop_process_input();
07973 goto l1;
07974 }
07975 int g=(*i)._goto_line;
07976 while(i!=proc.commands.end() && (*i).line!=g)
07977 i++;
07978 }
07979 }
07980 break;
07981 case _label:
07982 case _real_label:
07983 break;
07984 case _goto:
07985 case _real_goto:
07986 {
07987 int g=(*i)._goto_line;
07988 i=proc.commands.begin();
07989 while(i!=proc.commands.end() && (*i).line!=g)
07990 i++;
07991 }
07992 break;
07993 case _sleep_:
07994 {
07995 for(int s=(*i).sleep_secs; s>0; s--)
07996 sleep(1000);
07997 }
07998 break;
07999 case _restart:
08000 irc_disconnect();
08001 return LOGIC_RESTART;
08002 case _raw:
08003 irc_put(logic_eval((*i).msg_text,vars),(*i).priority);
08004 break;
08005 case _admin_msg:
08006 {
08007 string type=logic_eval((*i).admin_msg_type,vars);
08008 string mask=logic_eval((*i).admin_msg_mask,vars);
08009 string msg=logic_eval((*i).admin_msg_message,vars);
08010
08011 if(type.find("@telnet@",0)!=string::npos) {
08012 if(mask.find("@",0)==string::npos) {
08013
08014 dcc_broadcast(mask,msg,"","");
08015 } else {
08016
08017 string user, bot;
08018
08019 user=mask;
08020 user.erase(user.find("@",0),user.length()-user.find("@",0));
08021
08022 bot=mask;
08023 bot.erase(0,bot.find("@",0)+1);
08024
08025 botnet_admin_msg(user,bot,msg);
08026 }
08027 }
08028 }
08029 break;
08030 case _notice:
08031 irc_notice(logic_eval((*i).whom,vars).c_str(),logic_eval((*i).msg_text,vars).c_str(),(*i).priority);
08032 break;
08033 case _noticeq:
08034 irc_notice(logic_eval((*i).whom,vars).c_str(),(logic_eval((*i).msg_text,vars)+"\x01"+logic_eval((*i).msg_quoted,vars)+"\x01").c_str(),(*i).priority);
08035 break;
08036 case _unban_mask:
08037 if(!irc_got_op(logic_eval((*i).channel,vars)))
08038 break;
08039 {
08040 vector<s_online_channel>::iterator i1;
08041 for(i1=irc_channels.begin(); i1!=irc_channels.end(); i1++) {
08042 if(cmp_strings_case_insensitive((*i1).name,logic_eval((*i).channel,vars)))
08043 continue;
08044 vector<string>::iterator i2;
08045 for(i2=(*i1).bans.begin(); i2!=(*i1).bans.end(); i2++)
08046 if(!(*i2).compare(logic_eval((*i).whom,vars))) {
08047 (*i1).bans.erase(i2);
08048 break;
08049 }
08050 break;
08051 }
08052 }
08053 irc_unban(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str());
08054 break;
08055 case _ban_mask:
08056 if(!irc_got_op(logic_eval((*i).channel,vars)))
08057 break;
08058 irc_ban(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).whom,vars).c_str());
08059 break;
08060 case _dynamic_ban:
08061 {
08062 vector<s_channel_def>::iterator i1;
08063 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
08064 if(!cmp_strings_case_insensitive((*i1).channel_name,logic_eval((*i).channel,vars))) {
08065 string prefix=logic_eval((*i).ban_prefix,vars);
08066 if(prefix.compare("+") && prefix.compare("-"))
08067 break;
08068
08069 pair<string,string> p;
08070 p.first=logic_eval((*i).ban_mask,vars);
08071 p.second=logic_eval((*i).ban_reason,vars);
08072 p.first=(string)"\""+p.first+"\"";
08073 p.second=(string)"\""+p.second+"\"";
08074
08075 map<string,string>::iterator i2;
08076 erase_dyn_ban:
08077 for(i2=(*i1).dynamic_bans.begin(); i2!=(*i1).dynamic_bans.end(); i2++) {
08078 if(!p.first.compare((*i2).first)) {
08079 (*i1).dynamic_bans.erase(i2);
08080 goto erase_dyn_ban;
08081 }
08082 }
08083
08084 if(!prefix.compare("+")) {
08085 (*i1).dynamic_bans.insert(p);
08086 }
08087 if(!prefix.compare("-")) {
08088
08089 }
08090 break;
08091 }
08092 }
08093 }
08094 break;
08095 case _process_on_banned:
08096 {
08097 string chan=logic_eval((*i).channel,vars);
08098 string mask=logic_eval((*i).ban_mask,vars);
08099 vector<s_online_channel>::iterator i;
08100 for(i=irc_channels.begin(); i!=irc_channels.end(); i++) {
08101 if(!cmp_strings_case_insensitive((*i).name,chan)) {
08102 logic_on_banned(chan, mask,(*i).excepts,(*i).invites,(*i).bans);
08103 break;
08104 }
08105 }
08106 }
08107 break;
08108 case _check_dynamic_bans:
08109 {
08110 string result="0";
08111 string reason="";
08112
08113 vector<s_channel_def>::iterator i1;
08114 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
08115 if(!cmp_strings_case_insensitive((*i1).channel_name,logic_eval((*i).channel,vars))) {
08116 string nick=logic_eval((*i).nick,vars);
08117 string ident=irc_get_ident(nick);
08118 string host=irc_get_host(nick);
08119
08120 map<string,string>::iterator i2;
08121 for(i2=(*i1).dynamic_bans.begin(); i2!=(*i1).dynamic_bans.end(); i2++) {
08122 string mask=logic_eval((*i2).first,vars);
08123 if(logic_check_mask(mask,nick+"!"+ident+"@"+host,"*","*")) {
08124 result="1";
08125 reason=logic_eval((*i2).second,vars);
08126 break;
08127 }
08128 }
08129 break;
08130 }
08131 }
08132 pair<string,string> p;
08133 p.first=(*i).result;
08134 p.second=result;
08135 {
08136 map<string,string>::iterator i1;
08137 bool got=false;
08138 for(i1=vars.begin(); i1!=vars.end(); i1++)
08139 if(!(*i1).first.compare(p.first)) {
08140 (*i1).second=p.second;
08141 got=true;
08142 break;
08143 }
08144 if(!got)
08145 vars.insert(p);
08146 }
08147 p.first=(*i).ban_reason;
08148 p.second=reason;
08149 {
08150 map<string,string>::iterator i1;
08151 bool got=false;
08152 for(i1=vars.begin(); i1!=vars.end(); i1++)
08153 if(!(*i1).first.compare(p.first)) {
08154 (*i1).second=p.second;
08155 got=true;
08156 break;
08157 }
08158 if(!got)
08159 vars.insert(p);
08160 }
08161 }
08162 break;
08163 case _dcc_server:
08164 dcc_make_server(4,(*i).group,logic_eval((*i).server,vars).c_str(),(*i).port,(*i).server_type);
08165 break;
08166 case _dcc_server_ipv6:
08167 dcc_make_server(6,(*i).group,logic_eval((*i).server,vars).c_str(),(*i).port,(*i).server_type);
08168 break;
08169 case _telnet_server:
08170 dcc_make_telnet_server(4,logic_eval((*i).server,vars).c_str(),(*i).port);
08171 break;
08172 case _telnet_server_ipv6:
08173 dcc_make_telnet_server(6,logic_eval((*i).server,vars).c_str(),(*i).port);
08174 break;
08175 case _ident:
08176 {
08177 pair<string,string> p;
08178 p.first=(*i).result;
08179 p.second=irc_get_ident(logic_eval((*i).nick,vars).c_str());
08180 if(p.second.compare("")) {
08181 map<string,string>::iterator i1;
08182 bool got=false;
08183 for(i1=vars.begin(); i1!=vars.end(); i1++)
08184 if(!(*i1).first.compare(p.first)) {
08185 (*i1).second=p.second;
08186 got=true;
08187 break;
08188 }
08189 if(!got)
08190 vars.insert(p);
08191 }
08192 }
08193 break;
08194 case _host:
08195 {
08196 pair<string,string> p;
08197 p.first=(*i).result;
08198 p.second=irc_get_host(logic_eval((*i).nick,vars).c_str());
08199 if(p.second.compare("")) {
08200 map<string,string>::iterator i1;
08201 bool got=false;
08202 for(i1=vars.begin(); i1!=vars.end(); i1++)
08203 if(!(*i1).first.compare(p.first)) {
08204 (*i1).second=p.second;
08205 got=true;
08206 break;
08207 }
08208 if(!got)
08209 vars.insert(p);
08210 }
08211 }
08212 break;
08213 case _get_chan_mode:
08214 {
08215 pair<string,string> p;
08216 p.first=(*i).result;
08217 string topic;
08218 p.second=irc_get_chan_mode(logic_eval((*i).channel,vars),topic);
08219 map<string,string>::iterator i1;
08220 bool got=false;
08221 for(i1=vars.begin(); i1!=vars.end(); i1++)
08222 if(!(*i1).first.compare(p.first)) {
08223 (*i1).second=p.second;
08224 got=true;
08225 break;
08226 }
08227 if(!got)
08228 vars.insert(p);
08229 }
08230 break;
08231 case _topic:
08232 {
08233 string msg="TOPIC ";
08234 msg+=logic_eval((*i).channel,vars);
08235 msg+=" ";
08236 msg+=logic_eval((*i).msg_text,vars);
08237 irc_putserv(msg.c_str(),true,HIGH_PRIORITY);
08238 }
08239 break;
08240 case _get_chan_topic:
08241 {
08242 pair<string,string> p;
08243 p.first=(*i).result;
08244 string topic;
08245 irc_get_chan_mode(logic_eval((*i).channel,vars),topic);
08246 p.second=topic;
08247 map<string,string>::iterator i1;
08248 bool got=false;
08249 for(i1=vars.begin(); i1!=vars.end(); i1++)
08250 if(!(*i1).first.compare(p.first)) {
08251 (*i1).second=p.second;
08252 got=true;
08253 break;
08254 }
08255 if(!got)
08256 vars.insert(p);
08257 }
08258 break;
08259 case _script:
08260 {
08261 string cs=(*i).script_params;
08262 if(cs.length()>0 && cs[0]=='(')
08263 cs.erase(0,1);
08264
08265 list<string> params;
08266 bool str=false;
08267 string p;
08268 unsigned int i2;
08269 for(i2=0; i2<cs.length(); i2++) {
08270 if(cs[i2]=='\"') {
08271 str=!str;
08272 continue;
08273 }
08274 if(!str && cs[i2]==',') {
08275 if(p.length()>0 && p[0]=='$') {
08276 map<string,string>::iterator i3;
08277 for(i3=vars.begin(); i3!=vars.end(); i3++) {
08278 if(!(*i3).first.compare(p)) {
08279 p=(*i3).second;
08280 break;
08281 }
08282 }
08283 }
08284 params.push_back(p);
08285 p="";
08286 continue;
08287 }
08288 if(!str && cs[i2]==')') {
08289 if(p.compare("")) {
08290 if(p.length()>0 && p[0]=='$') {
08291 map<string,string>::iterator i3;
08292 for(i3=vars.begin(); i3!=vars.end(); i3++) {
08293 if(!(*i3).first.compare(p)) {
08294 p=(*i3).second;
08295 break;
08296 }
08297 }
08298 }
08299 params.push_back(p);
08300 }
08301 break;
08302 }
08303 p+=cs[i2];
08304 }
08305
08306 logic_exec_script(logic_eval((*i).script_type,vars),(*i).script_num,logic_eval((*i).script_channel,vars),params);
08307 }
08308 break;
08309 case _link:
08310 {
08311 string host=logic_eval((*i).botip,vars);
08312 if(host.find(":",0)==string::npos) {
08313 unsigned long ip=logic_resolve(host);
08314 if(ip) {
08315 char tmp[128];
08316 sprintf(tmp,"%u.%u.%u.%u",ip & 0xff, (ip>>8) & 0xff, (ip>>16) & 0xff, (ip>>24) & 0xff);
08317 botnet_link(logic_eval((*i).botname,vars),logic_eval((*i).botlocalip,vars),tmp,(*i).botport,dcc_get_password(logic_eval((*i).botname,vars)),(*i).botlinktype,(*i).botunlinkproc,vars);
08318 }
08319 } else {
08320 botnet_link(logic_eval((*i).botname,vars),logic_eval((*i).botlocalip,vars),host,(*i).botport,dcc_get_password(logic_eval((*i).botname,vars)),(*i).botlinktype,(*i).botunlinkproc,vars);
08321 }
08322 }
08323 break;
08324 case _chan_mode:
08325 irc_chan_mode(logic_eval((*i).channel,vars).c_str(),logic_eval((*i).chan_mode,vars).c_str(),(*i).priority);
08326 break;
08327 default:
08328 break;
08329 }
08330 }
08331 } catch(...) {
08332 in_exception=true;
08333 string log="Exception thrown while executing procedure ";
08334 log+=proc_name;
08335 log+=" in " __FUNC__ " in file " __FILE__ " - maybe .rehash'ing caused mess... The procedure execution terminated.";
08336 log_bot(log.c_str());
08337 log_debug(log.c_str());
08338 in_exception=false;
08339 }
08340 return 0;
08341 }
08342
08343
08344
08345
08346
08347
08348
08349
08350 int logic_exec_from_work()
08351 {
08352 return logic_exec(work_proc,work_vars,true);
08353 }
08354
08355
08356
08357
08358
08359
08360
08361 void logic_loop_identd()
08362 {
08363 if(identd_check(ident_string.c_str())) {
08364
08365
08366 }
08367 }
08368
08369
08370
08371
08372
08373
08374
08375
08376
08377
08378
08379
08380
08381
08382 int logic_call_proc(const char* call_string)
08383 {
08384 map<string,string> vars;
08385 return logic_call_proc_ex(call_string,vars);
08386 }
08387
08388
08389
08390
08391
08392
08393
08394
08395
08396
08397
08398
08399
08400
08401
08402 int logic_call_proc_ex(const char* call_string, map<string,string> vars)
08403 {
08404 string log=call_string;
08405
08406 string name;
08407 list<string> params;
08408
08409 int cnt=0;
08410
08411 for(unsigned int i1=0; i1<strlen(call_string); i1++) {
08412 if(cnt==0) {
08413 if(call_string[i1]=='(') {
08414 cnt++;
08415 continue;
08416 }
08417 name+=call_string[i1];
08418 continue;
08419 }
08420 if(cnt==1) {
08421 if(call_string[i1]==')') {
08422 cnt++;
08423 break;
08424 }
08425 if(call_string[i1]=='"') {
08426 string str;
08427 i1++;
08428 bool esc=false;
08429 for(; i1<strlen(call_string); i1++) {
08430 if(esc) {
08431 esc=false;
08432 if(call_string[i1]=='\\') {
08433 str+="\\";
08434 i1++;
08435 continue;
08436 }
08437 if(call_string[i1]=='"') {
08438 str+="\"";
08439 i1++;
08440 continue;
08441 }
08442 if(call_string[i1]=='\'') {
08443 str+="'";
08444 i1++;
08445 continue;
08446 }
08447 if(call_string[i1]=='\t') {
08448 str+="\t";
08449 i1++;
08450 continue;
08451 }
08452 if(call_string[i1]=='\r') {
08453 str+="\r";
08454 i1++;
08455 continue;
08456 }
08457 if(call_string[i1]=='\n') {
08458 str+="\n";
08459 i1++;
08460 continue;
08461 }
08462 if(call_string[i1]=='\a') {
08463 str+=0x07;
08464 i1++;
08465 continue;
08466 }
08467 string d="in file " __FILE__ " in function " __FUNC__ " occurred error LOGIC_PROC_BAD_TEXT with call_string: ";
08468 d+=log;
08469 log_debug(d.c_str());
08470 return LOGIC_PROC_BAD_TEXT;
08471 }
08472 if(call_string[i1]=='\\') {
08473 esc=true;
08474 i1++;
08475 continue;
08476 }
08477 if(call_string[i1]=='"') {
08478 params.push_back(str);
08479 i1++;
08480 if(call_string[i1]!=')' && call_string[i1]!=',') {
08481 string d="in file " __FILE__ " in function " __FUNC__ " occurred error LOGIC_PROC_BAD_SYNTAX with call_string: ";
08482 d+=log;
08483 log_debug(d.c_str());
08484 return LOGIC_PROC_BAD_SYNTAX;
08485 }
08486 if(call_string[i1]==',') {
08487 i1++;
08488 i1--;
08489 }
08490 if(call_string[i1]==')') {
08491 cnt++;
08492 break;
08493 }
08494 break;
08495 }
08496 str+=call_string[i1];
08497 }
08498 }
08499 if(call_string[i1]>='0' && call_string[i1]<='9') {
08500 string str;
08501 while(i1<strlen(call_string)) {
08502 if(call_string[i1]==',' || call_string[i1]==')') {
08503 break;
08504 }
08505 if(call_string[i1]<'0' || call_string[i1]>'9') {
08506 string d="in file " __FILE__ " in function " __FUNC__ " occurred error LOGIC_PROC_BAD_NUM with call_string: ";
08507 d+=log;
08508 log_debug(d.c_str());
08509 return LOGIC_PROC_BAD_NUM;
08510 }
08511 str+=call_string[i1++];
08512 }
08513 params.push_back(str);
08514 if(call_string[i1]==',')
08515 i1++;
08516 if(call_string[i1]==')') {
08517 cnt++;
08518 break;
08519 }
08520 }
08521 if(call_string[i1]=='$') {
08522 string str;
08523 str+=call_string[i1];
08524 i1++;
08525 for(; i1<strlen(call_string); i1++) {
08526 if(call_string[i1]==',' || call_string[i1]==')' || call_string[i1]==0x20)
08527 break;
08528 str+=call_string[i1];
08529 }
08530 params.push_back(str);
08531
08532 if(call_string[i1]==')'){
08533 cnt++;
08534 break;
08535 }
08536 }
08537 }
08538 }
08539
08540 if(cnt!=2) {
08541 string d="in file " __FILE__ " in function " __FUNC__ " occurred error LOGIC_PROC_BAD_SYNTAX with call_string: ";
08542 d+=log;
08543 log_debug(d.c_str());
08544 return LOGIC_PROC_BAD_SYNTAX;
08545 }
08546
08547 vector<s_procedure>::iterator i;
08548 for(i=r_procedures.begin(); i!=r_procedures.end(); i++) {
08549 string n;
08550 unsigned int i1;
08551 for(i1=0; i1<(*i).name.length(); i1++)
08552 if((*i).name[i1]=='(')
08553 break;
08554 else
08555 n+=(*i).name[i1];
08556 if(!n.compare(name)) {
08557 pair<string,string> p;
08558 p.first="";
08559 p.second="";
08560
08561 list<string>::iterator ipar=params.begin();
08562
08563 for(i1=0; i1<(*i).name.length(); i1++)
08564 if((*i).name[i1]=='(')
08565 break;
08566
08567 for(i1++; i1<(*i).name.length(); i1++) {
08568 if((*i).name[i1]!=',' && (*i).name[i1]!=')')
08569 p.first+=(*i).name[i1];
08570 if((*i).name[i1]==',' || (*i).name[i1]==')') {
08571 if(ipar!=params.end()) {
08572 p.second=*ipar;
08573 if(++ipar==params.end())
08574 break;
08575 map<string,string>::iterator i1;
08576 again1:
08577 for(i1=vars.begin(); i1!=vars.end(); i1++)
08578 if(!(*i1).first.compare(p.first)) {
08579 vars.erase(i1);
08580 goto again1;
08581 }
08582 vars.insert(p);
08583 }
08584 p.first="";
08585 p.second="";
08586 }
08587 if((*i).name[i1]==')')
08588 break;
08589 }
08590
08591 switch(logic_exec(*i,vars)) {
08592 case LOGIC_SOCKET_ERROR:
08593 return LOGIC_SOCKET_ERROR;
08594 default:
08595 break;
08596 }
08597 break;
08598 }
08599 }
08600 return LOGIC_OK;
08601 }
08602
08603
08604
08605
08606
08607
08608
08609
08610
08611
08612
08613
08614
08615
08616
08617
08618
08619 int logic_call_proc_ex2(const char* call_string, map<string,string>& vrs, list<string>& params, bool from_work)
08620 {
08621 string cs=call_string;
08622 if(cs.find("(",0)!=string::npos)
08623 cs.erase(cs.find("(",0),cs.length()-cs.find("(",0));
08624 vector<s_procedure>::iterator i3;
08625 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) {
08626 string s=(*i3).name;
08627 if(s.find("(",0)!=string::npos)
08628 s.erase(s.find("(",0),s.length()-s.find("(",0));
08629 if(!s.compare(cs)) {
08630 cs=(*i3).name;
08631 break;
08632 }
08633 }
08634 if(i3==r_procedures.end()) {
08635 return LOGIC_PROC_NOT_FOUND;
08636 }
08637
08638 map<string,string> vars=vrs;
08639 int pos=0;
08640 string p;
08641 list<string>::iterator i=params.begin();
08642 int num_par=0;
08643 if(i!=params.end()) {
08644 for(unsigned int i1=0; call_string[i1]!=0; i1++) {
08645 if(pos==0 && call_string[i1]=='(') {
08646 pos++;
08647 continue;
08648 }
08649 if(pos==1) {
08650 if(call_string[i1]==',' || call_string[i1]==')') {
08651 if(i!=params.end()) {
08652 pair<string,string> pa;
08653 pa.first=p;
08654 pa.second=*i;
08655 map<string,string>::iterator i1;
08656 again1:
08657 for(i1=vars.begin(); i1!=vars.end(); i1++)
08658 if(!(*i1).first.compare(pa.first)) {
08659 vars.erase(i1);
08660 goto again1;
08661 }
08662 vars.insert(pa);
08663 i++;
08664 } else {
08665 cs=(*i3).name;
08666 if(cs.find("(",0)!=string::npos)
08667 cs.erase(0,cs.find("(",0)+1);
08668 for(int i2=0; i2<num_par; i2++)
08669 if(cs.find(",",0)!=string::npos)
08670 cs.erase(0,cs.find(",",0)+1);
08671 if(cs.find(",",0)!=string::npos)
08672 cs.erase(cs.find(",",0),cs.length()-cs.find(",",0));
08673 if(cs.find(")",0)!=string::npos)
08674 cs.erase(cs.find(")",0),cs.length()-cs.find(")",0));
08675 pair<string,string> pa;
08676 pa.first=cs;
08677 pa.second=logic_eval(p,vars);
08678 map<string,string>::iterator i1;
08679 again2:
08680 for(i1=vars.begin(); i1!=vars.end(); i1++)
08681 if(!(*i1).first.compare(pa.first)) {
08682 vars.erase(i1);
08683 goto again2;
08684 }
08685 vars.insert(pa);
08686 }
08687 num_par++;
08688 p="";
08689 if(call_string[i1]==')')
08690 break;
08691 continue;
08692 }
08693 p+=call_string[i1];
08694 continue;
08695 }
08696 }
08697 }
08698 switch(logic_exec(*i3,vars,from_work)) {
08699 case LOGIC_SOCKET_ERROR:
08700 return LOGIC_SOCKET_ERROR;
08701 case LOGIC_NO_SERVER:
08702 return LOGIC_NO_SERVER;
08703 default:
08704 break;
08705 }
08706 return 0;
08707 }
08708
08709
08710
08711
08712
08713
08714
08715
08716
08717
08718
08719
08720
08721
08722
08723
08724 bool logic_match1(string hostmask, string fullname_mask, string nick, string ident, string host, string fullname)
08725 {
08726 string n, id, h, fn=fullname_mask;
08727 int pos=0;
08728 string hm=hostmask;
08729 for(unsigned int i1=0; i1<hm.length(); i1++) {
08730 if(pos==0) {
08731 if(hm[i1]=='!') {
08732 pos++;
08733 continue;
08734 }
08735 n+=hm[i1];
08736 }
08737 if(pos==1) {
08738 if(hm[i1]=='@') {
08739 pos++;
08740 continue;
08741 }
08742 id+=hm[i1];
08743 }
08744 if(pos==2)
08745 h+=hm[i1];
08746 }
08747 if(!match((char*)n.c_str(),(char*)nick.c_str()) &&
08748 !match((char*)id.c_str(),(char*)ident.c_str()) &&
08749 !match((char*)h.c_str(),(char*)host.c_str()) &&
08750 !match((char*)fn.c_str(),(char*)fullname.c_str())) {
08751 return true;
08752 }
08753 return false;
08754 }
08755
08756
08757
08758
08759
08760
08761
08762
08763
08764
08765
08766
08767
08768
08769 bool logic_match2(string hostmask, string fullname_mask, string hostname, string fullname)
08770 {
08771 string nick, ident, host;
08772 int pos=0;
08773 for(unsigned int i1=0; i1<hostname.length(); i1++) {
08774 if(pos==0) {
08775 if(hostname[i1]=='!') {
08776 pos++;
08777 continue;
08778 }
08779 nick+=hostname[i1];
08780 }
08781 if(pos==1) {
08782 if(hostname[i1]=='@') {
08783 pos++;
08784 continue;
08785 }
08786 ident+=hostname[i1];
08787 }
08788 if(pos==2)
08789 host+=hostname[i1];
08790 }
08791 return logic_match1(hostmask,fullname_mask,nick,ident,host,fullname);
08792 }
08793
08794 multimap<string,unsigned long> dns_ipv4_cache;
08795 multimap<string,in_addr6_> dns_ipv6_cache;
08796
08797
08798
08799
08800
08801
08802
08803
08804
08805 unsigned long logic_resolve(string host)
08806 {
08807 int i1, i2, i3, i4;
08808 int x=sscanf(host.c_str(),"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
08809 if(x==4)
08810 return (i4<<24)|(i3<<16)|(i2<<8)|i1;
08811
08812 multimap<string,unsigned long>::iterator ii;
08813 for(ii=dns_ipv4_cache.begin(); ii!=dns_ipv4_cache.end(); ii++) {
08814 if(!host.compare((*ii).first))
08815 return (*ii).second;
08816 }
08817 pair<string,unsigned long> p;
08818 p.first=host;
08819 #ifdef _WIN32
08820 p.second=sock_resolve(host.c_str(),NULL).S_un.S_addr;
08821 #else
08822 p.second=sock_resolve(host.c_str(),NULL).s_addr;
08823 #endif
08824 dns_ipv4_cache.insert(p);
08825 return p.second;
08826 }
08827
08828
08829
08830
08831
08832
08833
08834
08835
08836 in_addr6_ logic_resolve6(string host)
08837 {
08838 #ifdef IPv6
08839 multimap<string,in_addr6_>::iterator ii;
08840 for(ii=dns_ipv6_cache.begin(); ii!=dns_ipv6_cache.end(); ii++) {
08841 if(!host.compare((*ii).first))
08842 return (*ii).second;
08843 }
08844 pair<string,in_addr6_> p;
08845 p.first=host;
08846 p.second=sock_resolve6((char*)host.c_str());
08847 dns_ipv6_cache.insert(p);
08848 return p.second;
08849 #else
08850 in_addr6_ a6;
08851 memset(&a6,0,sizeof(a6));
08852 return a6;
08853 #endif
08854 }
08855
08856
08857
08858
08859
08860
08861
08862
08863
08864 string logic_hostmask_ipv6_decompress(string hostmask)
08865 {
08866 string first, host, cidr;
08867 int context=0;
08868 for(unsigned int i1=0; i1<hostmask.length(); i1++) {
08869 if(hostmask[i1]=='@' && context==0) {
08870 context++;
08871 continue;
08872 }
08873 if(hostmask[i1]=='/' && context==1) {
08874 context++;
08875 continue;
08876 }
08877 if(context==0)
08878 first+=hostmask[i1];
08879 if(context==1)
08880 host+=hostmask[i1];
08881 if(context==2)
08882 cidr+=hostmask[i1];
08883 }
08884 host=ipv6_decompress((char*)host.c_str());
08885 first=first+"@"+host;
08886 if(!cidr.empty())
08887 first+=(string)"/"+cidr;
08888 return first;
08889 }
08890
08891
08892
08893
08894
08895
08896
08897
08898
08899
08900
08901
08902
08903 bool logic_check_mask(string mask1, string mask2, string fnm1, string fnm2)
08904 {
08905 mask1=logic_hostmask_ipv6_decompress(mask1);
08906 mask2=logic_hostmask_ipv6_decompress(mask2);
08907
08908
08909 if(logic_match2(mask2,fnm2,mask1,fnm1) || logic_match2(mask1,fnm1,mask2,fnm2))
08910 return true;
08911
08912
08913 if(!logic_match2("*!*@*",fnm2,"*!*@*",fnm1) && !logic_match2("*!*@*",fnm1,"*!*@*",fnm2))
08914 return false;
08915
08916
08917 string h_mask1=mask1;
08918 string h_mask2=mask2;
08919 if(h_mask1.find("@",0)!=string::npos)
08920 h_mask1.erase(0,h_mask1.find("@",0)+1);
08921 if(h_mask2.find("@",0)!=string::npos)
08922 h_mask2.erase(0,h_mask2.find("@",0)+1);
08923
08924 if(h_mask1.length()==0 || h_mask2.length()==0)
08925 return false;
08926
08927
08928 string un1=mask1;
08929 if(un1.find("@",0)!=string::npos)
08930 un1.erase(un1.find("@",0),un1.length()-un1.find("@",0));
08931 string un2=mask2;
08932 if(un2.find("@",0)!=string::npos)
08933 un2.erase(un2.find("@",0),un2.length()-un2.find("@",0));
08934
08935
08936 unsigned long ip_mask1=0;
08937
08938
08939 if(h_mask1.find("?",0)==string::npos && h_mask1.find("*",0)==string::npos && h_mask1.find("#",0)==string::npos && h_mask1.find("/",0)==string::npos) {
08940 int i1, i2, i3, i4;
08941
08942 int x=sscanf(h_mask1.c_str(),"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
08943 if(x==4)
08944 ip_mask1=(i4<<24)|(i3<<16)|(i2<<8)|i1;
08945 else
08946 ip_mask1=0;
08947
08948 if(ip_mask1==0)
08949 ip_mask1=logic_resolve(h_mask1.c_str());
08950 }
08951
08952 unsigned long ip_mask2=0;
08953
08954 if(h_mask2.find("?",0)==string::npos && h_mask2.find("*",0)==string::npos && h_mask2.find("#",0)==string::npos && h_mask2.find("/",0)==string::npos) {
08955 int i1, i2, i3, i4;
08956
08957 int x=sscanf(h_mask2.c_str(),"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
08958 if(x==4)
08959 ip_mask2=(i4<<24)|(i3<<16)|(i2<<8)|i1;
08960 else
08961 ip_mask2=0;
08962
08963 if(ip_mask2==0)
08964 ip_mask2=logic_resolve(h_mask2.c_str());
08965 }
08966
08967 {
08968 {
08969
08970 int i1, i2, i3, i4;
08971 if(h_mask1.find(":",0)==string::npos) {
08972 int x=sscanf(h_mask1.c_str(),"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
08973 if(x==4) {
08974 h_mask1="0:0:0:0:0:ffff:"+h_mask1;
08975 string tmp=h_mask1;
08976 if(h_mask1.find("/",0)!=string::npos) {
08977 h_mask1.erase(h_mask1.find("/",0),h_mask1.length()-h_mask1.find("/",0));
08978 tmp.erase(0,tmp.find("/",0)+1);
08979 int j=atol(tmp.c_str());
08980 j+=(128-32);
08981 char tmp2[64];
08982 ltoa(j,tmp2,10);
08983 h_mask1+="/";
08984 h_mask1+=tmp2;
08985 }
08986 } else {
08987 char tmp[128];
08988 sprintf(tmp,"%u.%u.%u.%u",ip_mask1 & 0xff, (ip_mask1>>8) & 0xff, (ip_mask1>>16) & 0xff, (ip_mask1>>24) & 0xff);
08989 h_mask1=(string)"0:0:0:0:0:ffff:"+tmp;
08990 }
08991 }
08992
08993 if(h_mask2.find(":",0)==string::npos) {
08994 int x=sscanf(h_mask2.c_str(),"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
08995 if(x==4) {
08996 h_mask2="0:0:0:0:0:ffff:"+h_mask2;
08997 string tmp=h_mask2;
08998 if(h_mask2.find("/",0)!=string::npos) {
08999 h_mask2.erase(h_mask2.find("/",0),h_mask2.length()-h_mask2.find("/",0));
09000 tmp.erase(0,tmp.find("/",0)+1);
09001 int j=atol(tmp.c_str());
09002 j+=(128-32);
09003 char tmp2[64];
09004 ltoa(j,tmp2,10);
09005 h_mask2+="/";
09006 h_mask2+=tmp2;
09007 }
09008 } else {
09009 char tmp[128];
09010 sprintf(tmp,"%u.%u.%u.%u",ip_mask2 & 0xff, (ip_mask2>>8) & 0xff, (ip_mask2>>16) & 0xff, (ip_mask2>>24) & 0xff);
09011 h_mask2=(string)"0:0:0:0:0:ffff:"+tmp;
09012 }
09013 }
09014 }
09015
09016
09017 mask1=un1+"@"+h_mask1;
09018 mask2=un2+"@"+h_mask2;
09019
09020 in_addr6_ ip_mask6_1, ip_mask6_2;
09021 inetpton(AF_INET6,h_mask1.c_str(),&ip_mask6_1);
09022 inetpton(AF_INET6,h_mask2.c_str(),&ip_mask6_2);
09023
09024
09025 if(!match_ipmask((char*)(un1+"@"+h_mask1).c_str(),(char*)un2.c_str(),ip_mask6_2,true))
09026 return true;
09027 if(!match_ipmask((char*)(un2+"@"+h_mask2).c_str(),(char*)un1.c_str(),ip_mask6_1,true))
09028 return true;
09029 }
09030
09031
09032 in_addr6_ ip6_mask1;
09033 memset(&ip6_mask1,0,sizeof(ip6_mask1));
09034 in_addr6_ ip6_mask2;
09035 memset(&ip6_mask2,0,sizeof(ip6_mask2));
09036 if(h_mask1.find("/",0)==string::npos)
09037 ip6_mask1=sock_resolve6((char*)h_mask1.c_str());
09038 if(h_mask2.find("/",0)==string::npos)
09039 ip6_mask2=sock_resolve6((char*)h_mask2.c_str());
09040
09041 bool chance=false;
09042
09043
09044 if(ip6_mask1.bytes[0] || ip6_mask1.bytes[1] || ip6_mask1.bytes[2] || ip6_mask1.bytes[3] || ip6_mask1.bytes[4] ||
09045 ip6_mask1.bytes[5] || ip6_mask1.bytes[6] || ip6_mask1.bytes[7] || ip6_mask1.bytes[8] || ip6_mask1.bytes[9] ||
09046 ip6_mask1.bytes[10] || ip6_mask1.bytes[11] || ip6_mask1.bytes[12] || ip6_mask1.bytes[13] ||
09047 ip6_mask1.bytes[14] || ip6_mask1.bytes[15]) {
09048 char tmp[256];
09049
09050
09051 sprintf(tmp,"%x:%x:%x:%x:%x:%x:%x:%x", ((unsigned int)ip6_mask1.bytes[0])<<8 | ((unsigned int)ip6_mask1.bytes[1]),
09052 ((unsigned int)ip6_mask1.bytes[2])<<8 | ((unsigned int)ip6_mask1.bytes[3]),
09053 ((unsigned int)ip6_mask1.bytes[4])<<8 | ((unsigned int)ip6_mask1.bytes[5]),
09054 ((unsigned int)ip6_mask1.bytes[6])<<8 | ((unsigned int)ip6_mask1.bytes[7]),
09055 ((unsigned int)ip6_mask1.bytes[8])<<8 | ((unsigned int)ip6_mask1.bytes[9]),
09056 ((unsigned int)ip6_mask1.bytes[10])<<8 | ((unsigned int)ip6_mask1.bytes[11]),
09057 ((unsigned int)ip6_mask1.bytes[12])<<8 | ((unsigned int)ip6_mask1.bytes[13]),
09058 ((unsigned int)ip6_mask1.bytes[14])<<8 | ((unsigned int)ip6_mask1.bytes[15]));
09059 h_mask1=tmp;
09060 chance=true;
09061 }
09062 if(ip6_mask2.bytes[0] || ip6_mask2.bytes[1] || ip6_mask2.bytes[2] || ip6_mask2.bytes[3] || ip6_mask2.bytes[4] ||
09063 ip6_mask2.bytes[5] || ip6_mask2.bytes[6] || ip6_mask2.bytes[7] || ip6_mask2.bytes[8] || ip6_mask2.bytes[9] ||
09064 ip6_mask2.bytes[10] || ip6_mask2.bytes[11] || ip6_mask2.bytes[12] || ip6_mask2.bytes[13] ||
09065 ip6_mask2.bytes[14] || ip6_mask2.bytes[15]) {
09066 char tmp[256];
09067
09068
09069 sprintf(tmp,"%x:%x:%x:%x:%x:%x:%x:%x", ((unsigned int)ip6_mask2.bytes[0])<<8 | ((unsigned int)ip6_mask2.bytes[1]),
09070 ((unsigned int)ip6_mask2.bytes[2])<<8 | ((unsigned int)ip6_mask2.bytes[3]),
09071 ((unsigned int)ip6_mask2.bytes[4])<<8 | ((unsigned int)ip6_mask2.bytes[5]),
09072 ((unsigned int)ip6_mask2.bytes[6])<<8 | ((unsigned int)ip6_mask2.bytes[7]),
09073 ((unsigned int)ip6_mask2.bytes[8])<<8 | ((unsigned int)ip6_mask2.bytes[9]),
09074 ((unsigned int)ip6_mask2.bytes[10])<<8 | ((unsigned int)ip6_mask2.bytes[11]),
09075 ((unsigned int)ip6_mask2.bytes[12])<<8 | ((unsigned int)ip6_mask2.bytes[13]),
09076 ((unsigned int)ip6_mask2.bytes[14])<<8 | ((unsigned int)ip6_mask2.bytes[15]));
09077 h_mask2=tmp;
09078 chance=true;
09079 }
09080
09081
09082 if(!chance)
09083 return false;
09084
09085
09086 if(!match_ipmask((char*)(un1+"@"+h_mask1).c_str(),(char*)un2.c_str(),ip6_mask2,true))
09087 return true;
09088 if(!match_ipmask((char*)(un2+"@"+h_mask2).c_str(),(char*)un1.c_str(),ip6_mask1,true))
09089 return true;
09090
09091 return false;
09092 }
09093
09094
09095
09096
09097
09098
09099
09100
09101
09102
09103
09104 void logic_reverse(char* address, char* dns_name, unsigned int dns_max_size)
09105 {
09106 memset(dns_name,0,dns_max_size);
09107
09108 int i1, i2, i3, i4;
09109 int x=sscanf(address,"%u.%u.%u.%u", &i1, &i2, &i3, &i4);
09110 if(x!=4)
09111 return;
09112 unsigned long ip=(i4<<24)|(i3<<16)|(i2<<8)|i1;
09113
09114 multimap<string,unsigned long>::iterator ii;
09115 for(ii=dns_ipv4_cache.begin(); ii!=dns_ipv4_cache.end(); ii++) {
09116 if((*ii).second==ip) {
09117 strncpy(dns_name,(*ii).first.c_str(),((*ii).first.length()>dns_max_size)?dns_max_size:(*ii).first.length());
09118 return;
09119 }
09120 }
09121 char tmp[2048];
09122 memset(tmp,0,sizeof(tmp));
09123 sock_reverse(address,tmp,sizeof(tmp));
09124
09125 pair<string,unsigned long> p;
09126 p.first=tmp;
09127 p.second=ip;
09128 dns_ipv4_cache.insert(p);
09129 strncpy(dns_name,tmp,(strlen(tmp)>dns_max_size)?dns_max_size:strlen(tmp));
09130 }
09131
09132
09133
09134
09135
09136
09137
09138
09139
09140
09141
09142
09143
09144 string logic_find_user(string nick, string ident, string host, string fullname, bool irc_op)
09145 {
09146 if(!logic_cmp_strings_case_insensitive(nick,irc_nick)) {
09147 vector<s_user>::iterator i;
09148 for(i=r_users.begin(); i!=r_users.end(); i++) {
09149 if((*i).host_bot)
09150 return (*i).name;
09151 }
09152 }
09153
09154 map<string,string> vars;
09155
09156 bool trying_reverse=false;
09157 again:
09158
09159 vector<s_user>::iterator i;
09160 for(i=r_users.begin(); i!=r_users.end(); i++) {
09161 vector<string>::iterator is, ii;
09162 for(is=(*i).fullname.begin(); is!=(*i).fullname.end(); is++) {
09163 for(ii=(*i).hostmask.begin(); ii!=(*i).hostmask.end(); ii++) {
09164 if(!(*i).host_unknown && logic_check_mask(logic_eval(*ii,vars),nick+"!"+ident+"@"+host,logic_eval(*is,vars),fullname))
09165 return (*i).name;
09166 }
09167 }
09168 }
09169
09170 if(!trying_reverse && conf_getvar("try_reverse_lookup").compare("0")) {
09171 if(host.length() && host[0]>='0' && host[0]<='9') {
09172 char name[1024];
09173 logic_reverse((char*)host.c_str(),name,sizeof(name));
09174 if(name[0]!=0) {
09175 host=name;
09176 trying_reverse=true;
09177 goto again;
09178 }
09179 }
09180 }
09181
09182
09183 for(i=r_users.begin(); i!=r_users.end(); i++) {
09184 vector<string>::iterator is, ii;
09185 if((*i).host_unknown) {
09186 return (*i).name;
09187 }
09188 }
09189
09190 return "";
09191 }
09192
09193
09194
09195
09196
09197
09198
09199
09200
09201
09202
09203
09204
09205
09206 bool logic_access_to_partyline(string nick, string ident, string host, string fullname, bool irc_op, string& user_name_as_in_logic)
09207 {
09208 if(!logic_cmp_strings_case_insensitive(nick,irc_nick)) {
09209 return false;
09210 }
09211
09212 map<string,string> vars;
09213
09214 vector<s_user>::iterator i;
09215 for(i=r_users.begin(); i!=r_users.end(); i++) {
09216 vector<string>::iterator is, ii;
09217 for(is=(*i).fullname.begin(); is!=(*i).fullname.end(); is++) {
09218 for(ii=(*i).hostmask.begin(); ii!=(*i).hostmask.end(); ii++) {
09219 if(!(*i).host_unknown && logic_check_mask(logic_eval(*ii,vars),nick+"!"+ident+"@"+host,fullname,logic_eval(*is,vars))) {
09220 user_name_as_in_logic=(*i).name;
09221 return (*i).access_to_partyline;
09222 }
09223 }
09224 }
09225 }
09226
09227
09228 for(i=r_users.begin(); i!=r_users.end(); i++) {
09229 vector<string>::iterator is, ii;
09230 if((*i).host_unknown) {
09231 user_name_as_in_logic=(*i).name;
09232 return (*i).access_to_partyline;
09233 }
09234 }
09235
09236 return false;
09237 }
09238
09239
09240
09241
09242
09243
09244
09245
09246
09247
09248
09249
09250
09251
09252 void logic_validate(string channel, string source_user, string target_user, string source_nick, string target_nick, char prefix, char action)
09253 {
09254 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
09255 return;
09256
09257 extern bool dcc_want_to_upgrade;
09258 if(dcc_want_to_upgrade) {
09259 vector<s_user>::iterator i1;
09260 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
09261 if((*i1).host_bot && !(*i1).name.compare(target_user)) {
09262 string ident=irc_get_ident(target_nick);
09263 string host=irc_get_host(target_nick);
09264 string fullname=irc_get_fullname(target_nick);
09265 string mode=(string)""+prefix;
09266 mode+=(string)""+irc_isupport.get_prefix2(action);
09267 dcc_upgrade_bot_mode(target_nick,ident,host,fullname,channel,mode);
09268 break;
09269 }
09270 }
09271 }
09272
09273 vector<s_user>::iterator host_bot;
09274 bool b_host_bot=false;
09275
09276 bool got_user=false;
09277
09278 map<string,string> vars;
09279
09280 vector<s_channel>::iterator i1;
09281
09282 {
09283 for(host_bot=r_users.begin(); host_bot!=r_users.end(); host_bot++) {
09284 if((*host_bot).host_bot && !(*host_bot).name.compare(target_user)) {
09285 b_host_bot=true;
09286 goto l1;
09287 }
09288 }
09289 }
09290
09291 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09292 if(!(*i1).username.compare(target_user) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09293 if((prefix=='-' || prefix=='+') ) {
09294 string proc="";
09295 if(prefix=='-' && action=='@')
09296 proc=(*i1).on_deop;
09297 if(prefix=='+' && action=='@')
09298 proc=(*i1).on_op;
09299 if(prefix=='-' && action=='+')
09300 proc=(*i1).on_devoice;
09301 if(prefix=='+' && action=='+')
09302 proc=(*i1).on_voice;
09303 if(prefix=='-' && action=='O')
09304 proc=(*i1).on_decreator;
09305 if(prefix=='+' && action=='O')
09306 proc=(*i1).on_creator;
09307 if(action!='+' && action!='@' && action!='O')
09308 proc=(*i1).on_other_mode;
09309 if(!proc.compare((string)""))
09310 continue;
09311
09312
09313
09314
09315
09316
09317
09318
09319
09320
09321
09322
09323
09324
09325
09326
09327
09328 list<string> params;
09329 params.push_back(channel);
09330 params.push_back(source_user);
09331 params.push_back(target_user);
09332 params.push_back(source_nick);
09333 params.push_back(target_nick);
09334
09335 if(action!='+' && action!='@' && action!='O') {
09336 params.push_back((string)""+prefix);
09337 params.push_back((string)""+action);
09338 }
09339
09340 map<string,string> vars;
09341 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09342 case LOGIC_SOCKET_ERROR:
09343 case LOGIC_RESTART:
09344 return;
09345 default:
09346 break;
09347 }
09348 got_user=true;
09349 break;
09350 }
09351 }
09352 }
09353
09354 if(!got_user) {
09355
09356 l1:
09357 vector<s_user>::iterator i;
09358 if(b_host_bot)
09359 i=host_bot;
09360 else {
09361 for(i=r_users.begin(); i!=r_users.end(); i++) {
09362 if((*i).host_unknown) {
09363 got_user=true;
09364 break;
09365 }
09366 }
09367 if(!got_user)
09368 return;
09369 }
09370
09371 vector<s_channel>::iterator i1;
09372 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09373 if(cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel))
09374 continue;
09375 vector<string>::iterator is, ii;
09376 if(!(*i1).username.compare((*i).name)) {
09377 if((prefix=='-' || prefix=='+') ) {
09378 string proc="";
09379 if(prefix=='-' && action=='@')
09380 proc=(*i1).on_deop;
09381 if(prefix=='+' && action=='@')
09382 proc=(*i1).on_op;
09383 if(prefix=='-' && action=='+')
09384 proc=(*i1).on_devoice;
09385 if(prefix=='+' && action=='+')
09386 proc=(*i1).on_voice;
09387 if(prefix=='-' && action=='O')
09388 proc=(*i1).on_decreator;
09389 if(prefix=='+' && action=='O')
09390 proc=(*i1).on_creator;
09391 if(action!='+' && action!='@' && action!='O')
09392 proc=(*i1).on_other_mode;
09393 if(!proc.compare(""))
09394 continue;
09395
09396 list<string> params;
09397 params.push_back(channel);
09398 params.push_back(source_user);
09399 params.push_back(target_user);
09400 params.push_back(source_nick);
09401 params.push_back(target_nick);
09402
09403 if(action!='+' && action!='@' && action!='O') {
09404 params.push_back((string)""+prefix);
09405 params.push_back((string)""+action);
09406 }
09407
09408 map<string,string> vars;
09409 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09410 case LOGIC_SOCKET_ERROR:
09411 case LOGIC_RESTART:
09412 return;
09413 default:
09414 break;
09415 }
09416 break;
09417 }
09418 }
09419 }
09420 }
09421 }
09422
09423
09424
09425
09426
09427
09428
09429
09430
09431
09432
09433
09434
09435 void logic_validate_by_mask(string channel, string source_user, string source_nick, string mask, char prefix, char action)
09436 {
09437 if(!cmp_strings_case_insensitive(source_nick,irc_nick))
09438 return;
09439
09440 bool got_user=false;
09441
09442 map<string,string> vars;
09443
09444 vector<s_channel>::iterator i1;
09445 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09446 vector<s_user>::iterator i3;
09447 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
09448 if(!(*i3).name.compare((*i1).username)) {
09449 map<string,string> vars;
09450 vector<string>::iterator i2;
09451 for(i2=(*i3).hostmask.begin(); i2!=(*i3).hostmask.end(); i2++) {
09452 if(!(*i3).host_unknown && logic_check_mask(mask,logic_eval(*i2,vars),"*","*") && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09453 got_user=true;
09454 if((prefix=='-' || prefix=='+') && (action=='b' || action=='e' || action=='I' || action=='R')) {
09455 string proc="";
09456 if(prefix=='-' && action=='b')
09457 proc=(*i1).on_unban;
09458 if(prefix=='+' && action=='b')
09459 proc=(*i1).on_ban;
09460 if(prefix=='-' && action=='e')
09461 proc=(*i1).on_unexcept;
09462 if(prefix=='+' && action=='e')
09463 proc=(*i1).on_except;
09464 if(prefix=='-' && action=='I')
09465 proc=(*i1).on_uninvite;
09466 if(prefix=='+' && action=='I')
09467 proc=(*i1).on_invite;
09468 if(prefix=='-' && action=='R')
09469 proc=(*i1).on_reop;
09470 if(prefix=='+' && action=='R')
09471 proc=(*i1).on_reop;
09472 if(!proc.compare(""))
09473 continue;
09474
09475 list<string> params;
09476 params.push_back(channel);
09477 params.push_back(source_user);
09478 params.push_back((*i3).name);
09479 params.push_back(source_nick);
09480 params.push_back(irc_get_nick((*i3).name));
09481
09482 if(action=='b') {
09483 params.push_back(mask);
09484 }
09485 if(action=='e' || action=='I' || action=='R') {
09486 params.push_back((string)""+prefix);
09487 params.push_back(mask);
09488 }
09489
09490 map<string,string> vars;
09491 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09492 case LOGIC_SOCKET_ERROR:
09493 case LOGIC_RESTART:
09494 return;
09495 default:
09496 break;
09497 }
09498 break;
09499 }
09500 }
09501 }
09502
09503 }
09504 }
09505 }
09506
09507 if(!got_user) {
09508
09509 vector<s_user>::iterator i;
09510 for(i=r_users.begin(); i!=r_users.end(); i++) {
09511 if((*i).host_unknown) {
09512 vector<s_channel>::iterator i1;
09513 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09514 if(!(*i1).username.compare((*i).name) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09515 got_user=true;
09516 string proc="";
09517 if(prefix=='-' && action=='b')
09518 proc=(*i1).on_unban;
09519 if(prefix=='+' && action=='b')
09520 proc=(*i1).on_ban;
09521 if(prefix=='-' && action=='e')
09522 proc=(*i1).on_unexcept;
09523 if(prefix=='+' && action=='e')
09524 proc=(*i1).on_except;
09525 if(prefix=='-' && action=='I')
09526 proc=(*i1).on_uninvite;
09527 if(prefix=='+' && action=='I')
09528 proc=(*i1).on_invite;
09529 if(prefix=='-' && action=='R')
09530 proc=(*i1).on_reop;
09531 if(prefix=='+' && action=='R')
09532 proc=(*i1).on_reop;
09533 if(!proc.compare(""))
09534 break;
09535
09536 list<string> params;
09537 params.push_back(channel);
09538 params.push_back(source_user);
09539 params.push_back((*i).name);
09540 params.push_back(source_nick);
09541 params.push_back("");
09542
09543 if(action=='b') {
09544 params.push_back(mask);
09545 }
09546 if(action=='e' || action=='I' || action=='R') {
09547 params.push_back((string)""+prefix);
09548 params.push_back(mask);
09549 }
09550
09551 map<string,string> vars;
09552 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09553 case LOGIC_SOCKET_ERROR:
09554 case LOGIC_RESTART:
09555 return;
09556 default:
09557 break;
09558 }
09559 break;
09560 }
09561 }
09562 if(got_user)
09563 break;
09564 }
09565 }
09566 }
09567
09568 if(action=='b') {
09569 vector<s_channel_def>::iterator i1;
09570 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
09571 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
09572 string proc=(*i1).on_dynamic_ban;
09573 if(proc.empty())
09574 break;
09575 list<string> params;
09576 params.push_back(channel);
09577 params.push_back(source_user);
09578 params.push_back(source_nick);
09579 params.push_back((string)""+prefix);
09580 params.push_back(mask);
09581
09582 map<string,string> vars;
09583 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09584 case LOGIC_SOCKET_ERROR:
09585 case LOGIC_RESTART:
09586 return;
09587 default:
09588 break;
09589 }
09590 break;
09591 }
09592 }
09593 }
09594 }
09595
09596
09597
09598
09599
09600
09601
09602
09603
09604
09605
09606
09607
09608 void logic_on_join(string nick, string ident, string host, string fullname, string channel, bool irc_op)
09609 {
09610 bool got_user=false;
09611
09612 string user=logic_find_user(nick, ident, host, fullname, irc_op);
09613
09614 extern bool dcc_want_to_upgrade;
09615 if(dcc_want_to_upgrade) {
09616 vector<s_user>::iterator i1;
09617 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
09618 if((*i1).host_bot && !(*i1).name.compare(user)) {
09619 dcc_upgrade_bot_join(nick,ident,host,fullname,channel);
09620 break;
09621 }
09622 }
09623 }
09624
09625 map<string,string> vars;
09626
09627 vector<s_channel>::iterator i1;
09628 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09629 if(!(*i1).username.compare(user) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09630
09631 string proc=(*i1).on_join;
09632 if(!proc.compare(""))
09633 break;
09634
09635 list<string> params;
09636 params.push_back(channel);
09637 params.push_back(user);
09638 params.push_back(nick);
09639 params.push_back((*i1).dynamic_plus_modes);
09640 params.push_back((*i1).dynamic_minus_modes);
09641 params.push_back("0");
09642
09643 map<string,string> vars;
09644 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09645 case LOGIC_SOCKET_ERROR:
09646 case LOGIC_RESTART:
09647 return;
09648 default:
09649 break;
09650 }
09651 got_user=true;
09652 break;
09653 }
09654 }
09655
09656 if(!got_user) {
09657
09658 vector<s_user>::iterator i;
09659 for(i=r_users.begin(); i!=r_users.end(); i++) {
09660 if((*i).host_unknown) {
09661 got_user=true;
09662 break;
09663 }
09664 }
09665 if(!got_user)
09666 return;
09667
09668 vector<s_channel>::iterator i1;
09669 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09670 if(!(*i1).username.compare((*i).name) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09671
09672 string proc=(*i1).on_join;
09673 if(!proc.compare(""))
09674 break;
09675
09676 list<string> params;
09677 params.push_back(channel);
09678 params.push_back(user);
09679 params.push_back(nick);
09680 params.push_back((*i1).dynamic_plus_modes);
09681 params.push_back((*i1).dynamic_minus_modes);
09682 params.push_back("0");
09683
09684 map<string,string> vars;
09685 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09686 case LOGIC_SOCKET_ERROR:
09687 case LOGIC_RESTART:
09688 return;
09689 default:
09690 break;
09691 }
09692 }
09693 }
09694 }
09695 }
09696
09697
09698
09699
09700
09701
09702
09703
09704
09705
09706
09707
09708
09709
09710 void logic_on_nick_change(string nick, string ident, string host, string fullname, string channel, bool irc_op, string old_nick)
09711 {
09712 string user=logic_find_user(nick, ident, host, fullname, irc_op);
09713
09714 extern bool dcc_want_to_upgrade;
09715 if(dcc_want_to_upgrade) {
09716 vector<s_user>::iterator i1;
09717 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
09718 if((*i1).host_bot && !(*i1).name.compare(user)) {
09719 dcc_upgrade_bot_nick(old_nick,ident,host,fullname,nick);
09720 break;
09721 }
09722 }
09723 }
09724
09725 bool got_user=false;
09726
09727 string old_user=logic_find_user(old_nick, ident, host, fullname, irc_op);
09728
09729 map<string,string> vars;
09730
09731 vector<s_channel>::iterator i1;
09732 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09733 if(!(*i1).username.compare(user) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel) && old_user.compare(user)) {
09734
09735 string proc=(*i1).on_join;
09736 if(!proc.compare(""))
09737 break;
09738
09739 list<string> params;
09740 params.push_back(channel);
09741 params.push_back(user);
09742 params.push_back(nick);
09743 params.push_back((*i1).dynamic_plus_modes);
09744 params.push_back((*i1).dynamic_minus_modes);
09745 params.push_back(irc_get_mode(channel,nick));
09746
09747 map<string,string> vars;
09748 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09749 case LOGIC_SOCKET_ERROR:
09750 case LOGIC_RESTART:
09751 return;
09752 default:
09753 break;
09754 }
09755 break;
09756 }
09757 }
09758
09759 if(!got_user) {
09760
09761 vector<s_user>::iterator i;
09762 for(i=r_users.begin(); i!=r_users.end(); i++) {
09763 if((*i).host_unknown) {
09764 got_user=true;
09765 break;
09766 }
09767 }
09768 if(!got_user)
09769 return;
09770
09771 vector<s_channel>::iterator i1;
09772 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09773 if(!(*i1).username.compare((*i).name) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel) && old_user.compare(user)) {
09774
09775 string proc=(*i1).on_join;
09776 if(!proc.compare(""))
09777 break;
09778
09779 list<string> params;
09780 params.push_back(channel);
09781 params.push_back(user);
09782 params.push_back(nick);
09783 params.push_back((*i1).dynamic_plus_modes);
09784 params.push_back((*i1).dynamic_minus_modes);
09785 params.push_back(irc_get_mode(channel,nick));
09786
09787 map<string,string> vars;
09788 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09789 case LOGIC_SOCKET_ERROR:
09790 case LOGIC_RESTART:
09791 return;
09792 default:
09793 break;
09794 }
09795 }
09796 }
09797 }
09798 }
09799
09800
09801
09802
09803
09804
09805
09806
09807
09808
09809
09810
09811
09812
09813 void logic_on_nick_validate(string nick, string ident, string host, string fullname, string channel, bool irc_op, bool passive)
09814 {
09815 bool got_user=false;
09816
09817 string user=logic_find_user(nick, ident, host, fullname, irc_op);
09818
09819 map<string,string> vars;
09820
09821 vector<s_channel>::iterator i1;
09822 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09823 if(!(*i1).username.compare(user) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09824 got_user=true;
09825
09826 string proc=(*i1).on_join;
09827 if(!proc.compare(""))
09828 break;
09829
09830 list<string> params;
09831 params.push_back(channel);
09832 params.push_back(user);
09833 params.push_back(nick);
09834 params.push_back((*i1).dynamic_plus_modes);
09835 params.push_back((*i1).dynamic_minus_modes);
09836 if(passive)
09837 params.push_back((string)"1"+irc_get_mode(channel,nick));
09838 else
09839 params.push_back("0");
09840
09841 map<string,string> vars;
09842 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09843 case LOGIC_SOCKET_ERROR:
09844 case LOGIC_RESTART:
09845 return;
09846 default:
09847 break;
09848 }
09849 break;
09850 }
09851 }
09852
09853 if(!got_user) {
09854
09855 vector<s_user>::iterator i;
09856 for(i=r_users.begin(); i!=r_users.end(); i++) {
09857 if((*i).host_unknown) {
09858 got_user=true;
09859 break;
09860 }
09861 }
09862 if(!got_user)
09863 return;
09864
09865 vector<s_channel>::iterator i1;
09866 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09867 if(!(*i1).username.compare((*i).name) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09868
09869 string proc=(*i1).on_join;
09870 if(!proc.compare(""))
09871 break;
09872
09873 list<string> params;
09874 params.push_back(channel);
09875 params.push_back(user);
09876 params.push_back(nick);
09877 params.push_back((*i1).dynamic_plus_modes);
09878 params.push_back((*i1).dynamic_minus_modes);
09879 if(passive)
09880 params.push_back((string)"1"+irc_get_mode(channel,nick));
09881 else
09882 params.push_back("0");
09883
09884 map<string,string> vars;
09885 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09886 case LOGIC_SOCKET_ERROR:
09887 case LOGIC_RESTART:
09888 return;
09889 default:
09890 break;
09891 }
09892 }
09893 }
09894 }
09895 }
09896
09897
09898
09899
09900
09901
09902
09903
09904
09905
09906
09907
09908
09909
09910
09911
09912 void logic_mode_change_ex(string channel,char prefix,char mode,char class_,char user_prefix,string nick,string ident,string host,string param)
09913 {
09914 }
09915
09916
09917
09918
09919
09920
09921
09922
09923
09924
09925
09926
09927 void logic_on_banned(string channel, string ban_mask, vector<string> excepts, vector<string> invites, vector<string>& bans)
09928 {
09929 bool got_user=false;
09930
09931 map<string,string> vars;
09932
09933 vector<s_channel>::iterator i1;
09934 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09935 if(cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel))
09936 continue;
09937 vector<s_user>::iterator i3;
09938 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
09939 if((*i3).name.compare((*i1).username))
09940 continue;
09941 map<string,string> vars;
09942 vector<string>::iterator i2;
09943 for(i2=(*i3).hostmask.begin(); i2!=(*i3).hostmask.end(); i2++) {
09944 if(!(*i3).host_unknown && logic_check_mask(ban_mask,logic_eval(*i2,vars),"*","*") && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09945 vector<string>::iterator i4;
09946 bool in_except=false;
09947 for(i4=excepts.begin(); i4!=excepts.end(); i4++)
09948 if(logic_check_mask(*i4,logic_eval(*i2,vars),"*","*"))
09949 in_except=true;
09950 for(i4=invites.begin(); i4!=invites.end(); i4++)
09951 if(logic_check_mask(*i4,logic_eval(*i2,vars),"*","*"))
09952 in_except=true;
09953 if(!in_except) {
09954 got_user=true;
09955 string proc=(*i1).on_banned;
09956 if(!proc.compare(""))
09957 continue;
09958
09959 vector<string>::iterator i5;
09960 bool got=false;
09961 for(i5=bans.begin(); i5!=bans.end(); i5++)
09962 if(!(*i5).compare(ban_mask)) {
09963 got=true;
09964 break;
09965 }
09966 if(!got)
09967 continue;
09968
09969 list<string> params;
09970 params.push_back(channel);
09971 params.push_back((*i3).name);
09972 params.push_back(ban_mask);
09973
09974 map<string,string> vars;
09975 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
09976 case LOGIC_SOCKET_ERROR:
09977 case LOGIC_RESTART:
09978 return;
09979 default:
09980 break;
09981 }
09982
09983 }
09984 }
09985 }
09986 }
09987 }
09988
09989 if(!got_user) {
09990
09991 vector<s_channel>::iterator i1;
09992 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
09993 vector<s_user>::iterator i3;
09994 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
09995 map<string,string> vars;
09996 if(!(*i1).username.compare((*i3).name) && (*i3).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
09997 string proc=(*i1).on_banned;
09998 if(!proc.compare(""))
09999 continue;
10000
10001 vector<string>::iterator i5;
10002 bool got=false;
10003 for(i5=bans.begin(); i5!=bans.end(); i5++)
10004 if(!(*i5).compare(ban_mask)) {
10005 got=true;
10006 break;
10007 }
10008 if(!got)
10009 continue;
10010
10011 list<string> params;
10012 params.push_back(channel);
10013 params.push_back((*i3).name);
10014 params.push_back(ban_mask);
10015
10016 map<string,string> vars;
10017 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
10018 case LOGIC_SOCKET_ERROR:
10019 case LOGIC_RESTART:
10020 return;
10021 default:
10022 break;
10023 }
10024 }
10025 }
10026 }
10027 }
10028 }
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039 void logic_on_not_invited(string channel, string mask, string user_name)
10040 {
10041 bool got_user=false;
10042
10043 map<string,string> vars;
10044
10045 vector<s_channel>::iterator i1;
10046 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10047 vector<s_user>::iterator i3;
10048 if(!cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
10049 if(!(*i1).username.compare(user_name)) {
10050 got_user=true;
10051
10052 map<string,string> vars;
10053 vector<string>::iterator i2;
10054
10055 string proc=(*i1).on_not_invited;
10056 if(!proc.compare(""))
10057 break;
10058
10059 list<string> params;
10060 params.push_back(channel);
10061 params.push_back(user_name);
10062 params.push_back(mask);
10063
10064 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
10065 case LOGIC_SOCKET_ERROR:
10066 case LOGIC_RESTART:
10067 return;
10068 default:
10069 break;
10070 }
10071 break;
10072 }
10073 }
10074 }
10075
10076 if(!got_user) {
10077
10078 vector<s_channel>::iterator i1;
10079 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10080 vector<s_user>::iterator i3;
10081 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
10082 map<string,string> vars;
10083 if(!(*i1).username.compare((*i3).name) && (*i3).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
10084 map<string,string> vars;
10085 vector<string>::iterator i2;
10086
10087 string proc=(*i1).on_not_invited;
10088 if(!proc.compare(""))
10089 continue;
10090
10091 list<string> params;
10092 params.push_back(channel);
10093 params.push_back((*i1).username);
10094 params.push_back(mask);
10095
10096 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
10097 case LOGIC_SOCKET_ERROR:
10098 case LOGIC_RESTART:
10099 return;
10100 default:
10101 break;
10102 }
10103 }
10104 }
10105 }
10106 }
10107 }
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118 void logic_on_not_in_reop(string channel, string mask, string user_name)
10119 {
10120 bool got_user=false;
10121
10122 map<string,string> vars;
10123
10124 vector<s_channel>::iterator i1;
10125 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10126 vector<s_user>::iterator i3;
10127 if(!cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
10128 if(!(*i1).username.compare(user_name)) {
10129 got_user=true;
10130
10131 map<string,string> vars;
10132 vector<string>::iterator i2;
10133
10134 string proc=(*i1).on_not_in_reop;
10135 if(!proc.compare(""))
10136 break;
10137
10138 list<string> params;
10139 params.push_back(channel);
10140 params.push_back(user_name);
10141 params.push_back(mask);
10142
10143 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
10144 case LOGIC_SOCKET_ERROR:
10145 case LOGIC_RESTART:
10146 return;
10147 default:
10148 break;
10149 }
10150 break;
10151 }
10152 }
10153 }
10154
10155 if(!got_user) {
10156
10157 vector<s_channel>::iterator i1;
10158 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10159 vector<s_user>::iterator i3;
10160 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
10161 map<string,string> vars;
10162 if(!(*i1).username.compare((*i3).name) && (*i3).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
10163 map<string,string> vars;
10164 vector<string>::iterator i2;
10165
10166 string proc=(*i1).on_not_in_reop;
10167 if(!proc.compare(""))
10168 continue;
10169
10170 list<string> params;
10171 params.push_back(channel);
10172 params.push_back((*i1).username);
10173 params.push_back(mask);
10174
10175 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
10176 case LOGIC_SOCKET_ERROR:
10177 case LOGIC_RESTART:
10178 return;
10179 default:
10180 break;
10181 }
10182 }
10183 }
10184 }
10185 }
10186 }
10187
10188
10189
10190
10191
10192
10193
10194 void logic_loop()
10195 {
10196 time_t now;
10197 time(&now);
10198
10199 {
10200 time_t auto_backup_interval=atol(conf_getvar("auto_backup_interval").c_str());
10201 if(!last_autobackup)
10202 last_autobackup=now;
10203 if(auto_backup_interval!=0 && last_autobackup+auto_backup_interval<=now) {
10204 last_autobackup=now;
10205 logic_partyline_backup("self (autobackup)");
10206 }
10207 }
10208
10209 l1:
10210 vector<s_timer>::iterator i;
10211 for(i=r_timers.begin(); i!=r_timers.end(); i++) {
10212 if((*i).again_at<=now) {
10213 (*i).set_at=now;
10214 (*i).again_at=now+(*i).duration;
10215
10216 logic_call_proc_ex2((*i).call_string.c_str(),(*i).vars,(*i).params);
10217
10218 if((*i).once) {
10219 r_timers.erase(i);
10220 goto l1;
10221 }
10222 }
10223 }
10224
10225 l2:
10226 map<int,int> num_scripts;
10227 vector<s_tmp_file>::iterator i1;
10228 for(i1=tmp_files.begin(); i1!=tmp_files.end(); i1++) {
10229 if(!(*i1).script)
10230 continue;
10231 bool active=(*i1).h && exec_process_active((*i1).h);
10232 if(!(*i1).has_been_run)
10233 active=false;
10234 if(!active)
10235 continue;
10236 bool got=false;
10237 map<int,int>::iterator i2;
10238 for(i2=num_scripts.begin(); i2!=num_scripts.end(); i2++)
10239 if((*i2).first==(*i1).script_num) {
10240 got=true;
10241 (*i2).second++;
10242 }
10243 if(!got) {
10244 pair<int,int> p;
10245 p.first=(*i1).script_num;
10246 p.second=1;
10247 num_scripts.insert(p);
10248 }
10249 }
10250 for(i1=tmp_files.begin(); i1!=tmp_files.end(); i1++) {
10251 if((*i1).has_been_run && (*i1).h && !exec_process_active((*i1).h)) {
10252 if((*i1).script)
10253 logic_process_script_output((*i1).script_type,(*i1).script_num,(*i1).h);
10254 tmp_files.erase(i1);
10255 goto l2;
10256 }
10257 if((*i1).has_been_run && (*i1).start_up_time+10*60<time(NULL)) {
10258 exec_terminate_process((*i1).h,1);
10259 exec_process_end((*i1).h);
10260 delete (*i1).h;
10261 tmp_files.erase(i1);
10262 goto l2;
10263 }
10264 if(!(*i1).script)
10265 continue;
10266 map<int,int>::iterator i2;
10267 int i=0;
10268 for(i2=num_scripts.begin(); i2!=num_scripts.end(); i2++)
10269 if((*i2).first==(*i1).script_num) {
10270 i=(*i2).second;
10271 break;
10272 }
10273 if(!i && !(*i1).has_been_run) {
10274 (*i1).h=exec_async_exec((*i1).command_line,(*i1).command_args,(*i1).command_dir);
10275 (*i1).has_been_run=true;
10276 (*i1).start_up_time=time(NULL);
10277 break;
10278 }
10279 }
10280 }
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291 string logic_get_dcc_host(int dcc_group, string user_name_as_in_logic)
10292 {
10293 vector<s_user>::iterator i;
10294 for(i=r_users.begin(); i!=r_users.end(); i++) {
10295 if(!(*i).name.compare(user_name_as_in_logic)) {
10296 vector<s_dcc_host>::iterator i2;
10297 for(i2=(*i).dcc_hosts.begin(); i2!=(*i).dcc_hosts.end(); i2++) {
10298 if((*i2).group==dcc_group) {
10299 map<string,string> vars;
10300 return logic_eval((*i2).host,vars);
10301 }
10302 }
10303 }
10304 }
10305 return "0.0.0.0";
10306 }
10307
10308
10309
10310
10311
10312
10313
10314
10315 void logic_erase_duplicate_or_empty_string_in_vector(vector<string>& v)
10316 {
10317 vector<string>::iterator i1;
10318 again:
10319 for(i1=v.begin(); i1!=v.end(); i1++) {
10320 if((*i1).empty()) {
10321 v.erase(i1);
10322 goto again;
10323 }
10324 vector<string>::iterator i2;
10325 for(i2=v.begin(); i2!=v.end(); i2++) {
10326 if(i1==i2)
10327 continue;
10328 if(!(*i1).compare(*i2)) {
10329 v.erase(i2);
10330 goto again;
10331 }
10332 }
10333 }
10334 }
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383 void logic_partyline_access(string user, vector<string>& access_to_users, vector<string>& access_to_groups, vector<string>& access_grant_groups, vector<string>& access_to_proc_groups, vector<string>& access_grant_proc_groups, vector<string>& access_grant_proc, vector<string>& access_to_channel, vector<string>& access_grant_channel, bool& access_grant_partyline, vector<string>& access_to_procs, bool& access_to_backup, bool& access_grant_backup, bool& access_to_rehash, bool& access_grant_rehash, bool& access_to_plususer, bool& access_grant_plususer, bool& access_to_plusproc, bool& access_grant_plusproc, s_flood& partyline_msg_flood, bool& access_to_replication, bool& access_grant_replication, vector<string>& access_to_chan_defs, bool& access_to_restart, bool& access_grant_restart, bool& access_to_die, bool& access_grant_die, bool& access_to_filesystem, bool& access_grant_filesystem, bool& access_to_private, bool& access_grant_private, bool& access_to_can_send_all_users, bool& access_grant_can_send_all_users, bool& access_to_can_send_unknown_users, bool& access_grant_can_send_unknown_users, vector<string>& access_usage_proc, vector<string>& access_usage_proc_groups, bool& access_to_upgrade, bool& access_grant_upgrade, bool& access_to_apply, bool& access_grant_apply)
10384 {
10385 access_to_users.clear();
10386 access_to_groups.clear();
10387 access_grant_groups.clear();
10388 access_to_proc_groups.clear();
10389 access_grant_proc_groups.clear();
10390 access_grant_proc.clear();
10391 access_to_channel.clear();
10392 access_grant_channel.clear();
10393 access_grant_partyline=false;
10394 access_to_procs.clear();
10395 access_to_backup=access_grant_backup=access_to_rehash=access_grant_rehash=
10396 access_to_plususer=access_grant_plususer=access_to_plusproc=
10397 access_grant_plusproc=false;
10398 partyline_msg_flood.lines=0;
10399 partyline_msg_flood.seconds=0;
10400 access_to_replication=access_grant_replication=false;
10401 access_to_chan_defs.clear();
10402 access_to_restart=access_grant_restart=access_to_die=access_grant_die=
10403 access_to_filesystem=access_grant_filesystem=access_to_private=
10404 access_grant_private=access_to_can_send_all_users=
10405 access_grant_can_send_all_users=access_to_can_send_unknown_users=
10406 access_grant_can_send_unknown_users=false;
10407 access_usage_proc.clear();
10408 access_usage_proc_groups.clear();
10409 access_to_upgrade=access_grant_upgrade=false;
10410 access_to_apply=access_grant_apply=false;
10411
10412 vector<s_user>::iterator i1;
10413 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
10414 if(!(*i1).name.compare(user)) {
10415 bool all=false;
10416 vector<string>::iterator i2;
10417 for(i2=(*i1).access_to_group.begin(); i2!=(*i1).access_to_group.end(); i2++) {
10418 if((*i2).compare("*")) {
10419 vector<s_user>::iterator i3;
10420 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
10421 vector<s_group>::iterator i4;
10422 for(i4=(*i3).groups.begin(); i4!=(*i3).groups.end(); i4++) {
10423 if(!(*i4).name.compare(*i2)) {
10424 access_to_users.push_back((*i3).name);
10425 }
10426 }
10427 }
10428 } else {
10429 vector<s_user>::iterator i3;
10430 for(i3=r_users.begin(); i3!=r_users.end(); i3++) {
10431 access_to_users.push_back((*i3).name);
10432 }
10433 access_to_users.push_back("*");
10434 break;
10435 }
10436 }
10437 map<string,string> vars;
10438 all=false;
10439 for(i2=(*i1).access_to_group.begin(); i2!=(*i1).access_to_group.end(); i2++)
10440 if((*i2).compare("*"))
10441 access_to_groups.push_back(logic_eval(*i2,vars));
10442 else
10443 all=true;
10444 if(all) {
10445 vector<s_group>::iterator i4;
10446 for(i4=r_all_groups.begin(); i4!=r_all_groups.end(); i4++)
10447 access_to_groups.push_back(logic_eval((*i4).name,vars));
10448 access_to_groups.push_back("*");
10449 }
10450 all=false;
10451 for(i2=(*i1).access_grant_group.begin(); i2!=(*i1).access_grant_group.end(); i2++)
10452 if((*i2).compare("*"))
10453 access_grant_groups.push_back(logic_eval(*i2,vars));
10454 else
10455 all=true;
10456 if(all) {
10457 vector<s_group>::iterator i4;
10458 for(i4=r_all_groups.begin(); i4!=r_all_groups.end(); i4++)
10459 access_grant_groups.push_back(logic_eval((*i4).name,vars));
10460 access_grant_groups.push_back("*");
10461 }
10462
10463 all=false;
10464 for(i2=(*i1).access_to_proc.begin(); i2!=(*i1).access_to_proc.end(); i2++)
10465 if((*i2).compare("*"))
10466 access_to_proc_groups.push_back(logic_eval(*i2,vars));
10467 else
10468 all=true;
10469 if(all) {
10470 vector<string> got;
10471 vector<s_procedure>::iterator i1;
10472 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
10473 vector<s_group>::iterator i2;
10474 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
10475 vector<string>::iterator i3;
10476 bool got_=false;
10477 for(i3=got.begin(); i3!=got.end(); i3++) {
10478 if(!(*i3).compare(logic_eval((*i2).name,vars))) {
10479 got_=true;
10480 break;
10481 }
10482 }
10483 if(!got_)
10484 got.push_back(logic_eval((*i2).name,vars));
10485 }
10486 }
10487 vector<string>::iterator i3;
10488 for(i3=got.begin(); i3!=got.end(); i3++)
10489 access_to_proc_groups.push_back(*i3);
10490 access_to_proc_groups.push_back("*");
10491 }
10492 all=false;
10493 for(i2=(*i1).access_to_proc.begin(); i2!=(*i1).access_to_proc.end(); i2++)
10494 if((*i2).compare("*")) {
10495 string gr=logic_eval(*i2,vars);
10496 vector<s_procedure>::iterator i3;
10497 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) {
10498 vector<s_group>::iterator i4;
10499 for(i4=(*i3).groups.begin(); i4!=(*i3).groups.end(); i3++) {
10500 if(!(*i4).name.compare(gr)) {
10501 access_to_procs.push_back(gr);
10502 }
10503 }
10504 }
10505 } else {
10506 all=true;
10507 }
10508 if(all) {
10509 vector<string> got;
10510 vector<s_procedure>::iterator i1;
10511 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++)
10512 access_to_procs.push_back((*i1).name);
10513 access_to_procs.push_back("*");
10514 }
10515
10516 all=false;
10517 for(i2=(*i1).access_grant_procedure.begin(); i2!=(*i1).access_grant_procedure.end(); i2++)
10518 if((*i2).compare("*"))
10519 access_grant_proc_groups.push_back(logic_eval(*i2,vars));
10520 else
10521 all=true;
10522 if(all) {
10523 vector<string> got;
10524 vector<s_procedure>::iterator i1;
10525 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
10526 vector<s_group>::iterator i2;
10527 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
10528 vector<string>::iterator i3;
10529 bool got_=false;
10530 for(i3=got.begin(); i3!=got.end(); i3++) {
10531 if(!(*i3).compare(logic_eval((*i2).name,vars))) {
10532 got_=true;
10533 break;
10534 }
10535 }
10536 if(!got_)
10537 got.push_back(logic_eval((*i2).name,vars));
10538 }
10539 }
10540 vector<string>::iterator i3;
10541 for(i3=got.begin(); i3!=got.end(); i3++)
10542 access_grant_proc_groups.push_back(*i3);
10543 access_grant_proc_groups.push_back("*");
10544 }
10545 all=false;
10546 for(i2=(*i1).access_grant_procedure.begin(); i2!=(*i1).access_grant_procedure.end(); i2++)
10547 if((*i2).compare("*")) {
10548 string gr=logic_eval(*i2,vars);
10549 vector<s_procedure>::iterator i3;
10550 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) {
10551 vector<s_group>::iterator i4;
10552 for(i4=(*i3).groups.begin(); i4!=(*i3).groups.end(); i3++) {
10553 if(!(*i4).name.compare(gr)) {
10554 access_grant_proc.push_back(gr);
10555 }
10556 }
10557 }
10558 } else {
10559 all=true;
10560 }
10561 if(all) {
10562 vector<string> got;
10563 vector<s_procedure>::iterator i1;
10564 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++)
10565 access_to_procs.push_back((*i1).name);
10566 access_grant_proc.push_back("*");
10567 }
10568
10569 all=false;
10570 for(i2=(*i1).access_usage_procedure.begin(); i2!=(*i1).access_usage_procedure.end(); i2++)
10571 if((*i2).compare("*"))
10572 access_usage_proc_groups.push_back(logic_eval(*i2,vars));
10573 else
10574 all=true;
10575 if(all) {
10576 vector<string> got;
10577 vector<s_procedure>::iterator i1;
10578 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
10579 vector<s_group>::iterator i2;
10580 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
10581 vector<string>::iterator i3;
10582 bool got_=false;
10583 for(i3=got.begin(); i3!=got.end(); i3++) {
10584 if(!(*i3).compare(logic_eval((*i2).name,vars))) {
10585 got_=true;
10586 break;
10587 }
10588 }
10589 if(!got_)
10590 got.push_back(logic_eval((*i2).name,vars));
10591 }
10592 }
10593 vector<string>::iterator i3;
10594 for(i3=got.begin(); i3!=got.end(); i3++)
10595 access_usage_proc_groups.push_back(*i3);
10596 access_usage_proc_groups.push_back("*");
10597 }
10598 all=false;
10599 for(i2=(*i1).access_usage_procedure.begin(); i2!=(*i1).access_usage_procedure.end(); i2++)
10600 if((*i2).compare("*")) {
10601 string gr=logic_eval(*i2,vars);
10602 vector<s_procedure>::iterator i3;
10603 for(i3=r_procedures.begin(); i3!=r_procedures.end(); i3++) {
10604 vector<s_group>::iterator i4;
10605 for(i4=(*i3).groups.begin(); i4!=(*i3).groups.end(); i3++) {
10606 if(!(*i4).name.compare(gr)) {
10607 access_usage_proc.push_back(gr);
10608 }
10609 }
10610 }
10611 } else {
10612 all=true;
10613 }
10614 if(all) {
10615 vector<string> got;
10616 vector<s_procedure>::iterator i1;
10617 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++)
10618 access_usage_proc.push_back((*i1).name);
10619 access_usage_proc.push_back("*");
10620 }
10621
10622 all=false;
10623 for(i2=(*i1).access_to_channel.begin(); i2!=(*i1).access_to_channel.end(); i2++)
10624 if((*i2).compare("*"))
10625 access_to_channel.push_back(logic_eval(*i2,vars));
10626 else
10627 all=true;
10628 if(all) {
10629 vector<string> got;
10630 vector<s_channel>::iterator i1;
10631 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645 vector<string>::iterator i3;
10646 bool got_=false;
10647 for(i3=got.begin(); i3!=got.end(); i3++)
10648 if(!cmp_strings_case_insensitive(*i3,logic_eval((*i1).channel_name,vars))) {
10649 got_=true;
10650 break;
10651 }
10652 if(!got_)
10653 got.push_back(logic_eval((*i1).channel_name,vars));
10654 }
10655 vector<string>::iterator i3;
10656 for(i3=got.begin(); i3!=got.end(); i3++)
10657 access_to_channel.push_back(*i3);
10658 access_to_channel.push_back("*");
10659 }
10660 all=false;
10661 for(i2=(*i1).access_grant_channel.begin(); i2!=(*i1).access_grant_channel.end(); i2++)
10662 if((*i2).compare("*"))
10663 access_grant_channel.push_back(logic_eval(*i2,vars));
10664 else
10665 all=true;
10666 if(all) {
10667 vector<string> got;
10668 vector<s_channel>::iterator i1;
10669 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
10670 vector<string>::iterator i3;
10671 bool got_=false;
10672 for(i3=got.begin(); i3!=got.end(); i3++)
10673 if(!cmp_strings_case_insensitive(*i3,logic_eval((*i1).channel_name,vars))) {
10674 got_=true;
10675 break;
10676 }
10677 if(!got_)
10678 got.push_back(logic_eval((*i1).channel_name,vars));
10679 }
10680 vector<string>::iterator i3;
10681 for(i3=got.begin(); i3!=got.end(); i3++)
10682 access_grant_channel.push_back(*i3);
10683 access_grant_channel.push_back("*");
10684 }
10685 all=false;
10686 for(i2=(*i1).access_to_channel.begin(); i2!=(*i1).access_to_channel.end(); i2++)
10687 if((*i2).compare("*"))
10688 access_to_chan_defs.push_back(logic_eval(*i2,vars));
10689 else
10690 all=true;
10691 if(all) {
10692 vector<string> got;
10693 vector<s_channel_def>::iterator i1;
10694 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
10695 vector<s_group>::iterator i2;
10696 for(i2=(*i1).groups.begin(); i2!=(*i1).groups.end(); i2++) {
10697 vector<string>::iterator i3;
10698 bool got_=false;
10699 for(i3=got.begin(); i3!=got.end(); i3++)
10700 if(!cmp_strings_case_insensitive(*i3,(*i1).channel_name)) {
10701 got_=true;
10702 break;
10703 }
10704 if(!got_)
10705 got.push_back((*i1).channel_name);
10706 }
10707 }
10708 vector<string>::iterator i3;
10709 for(i3=got.begin(); i3!=got.end(); i3++)
10710 access_to_chan_defs.push_back(*i3);
10711 access_to_chan_defs.push_back("*");
10712 }
10713
10714 all=false;
10715 access_grant_partyline=(*i1).access_grant_partyline;
10716
10717 access_to_backup=(*i1).access_to_backup;
10718 access_grant_backup=(*i1).access_grant_backup;
10719 access_to_rehash=(*i1).access_to_rehash;
10720 access_grant_rehash=(*i1).access_grant_rehash;
10721
10722 access_to_plususer=(*i1).access_to_plususer;
10723 access_grant_plususer=(*i1).access_grant_plususer;
10724
10725 access_to_plusproc=(*i1).access_to_plusproc;
10726 access_grant_plusproc=(*i1).access_grant_plusproc;
10727
10728 partyline_msg_flood=(*i1).partyline_msg_flood;
10729
10730 access_to_replication=(*i1).access_to_replication;
10731 access_grant_replication=(*i1).access_grant_replication;
10732
10733 access_to_restart=(*i1).access_to_restart;
10734 access_grant_restart=(*i1).access_grant_restart;
10735 access_to_die=(*i1).access_to_die;
10736 access_grant_die=(*i1).access_grant_die;
10737
10738 access_to_filesystem=(*i1).access_to_filesystem;
10739 access_grant_filesystem=(*i1).access_grant_filesystem;
10740
10741 access_to_upgrade=(*i1).access_to_upgrade;
10742 access_grant_upgrade=(*i1).access_grant_upgrade;
10743
10744 access_to_apply=(*i1).access_to_apply;
10745 access_grant_apply=(*i1).access_grant_apply;
10746
10747 access_to_private=(*i1).access_to_private;
10748 access_grant_private=(*i1).access_grant_private;
10749
10750 access_to_can_send_all_users=(*i1).access_to_can_send_all_users;
10751 access_grant_can_send_all_users=(*i1).access_grant_can_send_all_users;
10752
10753 access_to_can_send_unknown_users=(*i1).access_to_can_send_unknown_users;
10754 access_grant_can_send_unknown_users=(*i1).access_grant_can_send_unknown_users;
10755
10756 break;
10757 }
10758 }
10759
10760 logic_erase_duplicate_or_empty_string_in_vector(access_to_users);
10761 logic_erase_duplicate_or_empty_string_in_vector(access_to_groups);
10762 logic_erase_duplicate_or_empty_string_in_vector(access_grant_groups);
10763 logic_erase_duplicate_or_empty_string_in_vector(access_to_proc_groups);
10764 logic_erase_duplicate_or_empty_string_in_vector(access_grant_proc_groups);
10765 logic_erase_duplicate_or_empty_string_in_vector(access_grant_proc);
10766 logic_erase_duplicate_or_empty_string_in_vector(access_to_channel);
10767 logic_erase_duplicate_or_empty_string_in_vector(access_grant_channel);
10768 logic_erase_duplicate_or_empty_string_in_vector(access_to_procs);
10769 logic_erase_duplicate_or_empty_string_in_vector(access_to_chan_defs);
10770 logic_erase_duplicate_or_empty_string_in_vector(access_usage_proc);
10771 logic_erase_duplicate_or_empty_string_in_vector(access_usage_proc_groups);
10772 }
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782 bool logic_access_to_filesystem(string user)
10783 {
10784 vector<s_user>::iterator i1;
10785 for(i1=r_users.begin(); i1!=r_users.end(); i1++)
10786 if(!(*i1).name.compare(user))
10787 return (*i1).access_to_filesystem;
10788 return false;
10789 }
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801 int logic_partyline_whois(string lang, string param1, list<string>& lines)
10802 {
10803 int cnt=0;
10804 map<string,string> vars;
10805 param1=logic_to_upper(param1);
10806 vector<s_user>::iterator i;
10807 for(i=r_users.begin(); i!=r_users.end(); i++) {
10808 bool got=false;
10809 if(!match((char*)param1.c_str(),(char*)logic_to_upper((*i).name).c_str()))
10810 got=true;
10811 vector<string>::iterator i2;
10812 if(!got)
10813 for(i2=(*i).hostmask.begin(); i2!=(*i).hostmask.end(); i2++)
10814 if(!match((char*)param1.c_str(),(char*)logic_to_upper(logic_eval(*i2,vars)).c_str()))
10815 got=true;
10816 if(got) {
10817 string l=lang_get_string(1,lang,9)+" "+(*i).name+" "+lang_get_string(1,lang,10)+" ";
10818 if((*i).host_unknown)
10819 l+=lang_get_string(1,lang,11)+" ";
10820 if((*i).host_bot)
10821 l+=lang_get_string(1,lang,12)+" ";
10822 l+=lang_get_string(1,lang,13);
10823 lines.push_back(l);
10824 vector<string>::iterator i3;
10825 bool got=false;
10826 for(i3=(*i).hostmask.begin(); i3!=(*i).hostmask.end(); i3++) {
10827 lines.push_back((string)" "+logic_eval(*i3,vars));
10828 got=true;
10829 }
10830 if(!got)
10831 lines.push_back(lang_get_string(1,lang,14));
10832 l=lang_get_string(1,lang,15);
10833 lines.push_back(l);
10834 got=false;
10835 for(i3=(*i).fullname.begin(); i3!=(*i).fullname.end(); i3++) {
10836 lines.push_back((string)" "+logic_eval(*i3,vars));
10837 got=true;
10838 }
10839 if(!got)
10840 lines.push_back(lang_get_string(1,lang,14));
10841 l=lang_get_string(1,lang,18);
10842 lines.push_back(l);
10843 vector<s_group>::iterator i4;
10844 got=false;
10845 for(i4=(*i).groups.begin(); i4!=(*i).groups.end(); i4++) {
10846 lines.push_back((string)" "+logic_eval((*i4).name,vars));
10847 got=true;
10848 }
10849 if(!got)
10850 lines.push_back(lang_get_string(1,lang,14));
10851 l=lang_get_string(1,lang,19);
10852 lines.push_back(l);
10853 vector<s_dcc_host>::iterator i5;
10854 got=false;
10855 for(i5=(*i).dcc_hosts.begin(); i5!=(*i).dcc_hosts.end(); i5++) {
10856 char tmp[64];
10857 ltoa((*i5).group,tmp,10);
10858 lines.push_back((string)" "+lang_get_string(1,lang,20)+(string)tmp+" "+lang_get_string(1,lang,21)+" "+(*i5).host);
10859 got=true;
10860 }
10861 if(!got)
10862 lines.push_back(lang_get_string(1,lang,14));
10863 l=lang_get_string(1,lang,22);
10864 lines.push_back(l);
10865 got=false;
10866 bool all=false;
10867 for(i3=(*i).access_to_group.begin(); i3!=(*i).access_to_group.end(); i3++) {
10868 if(!(*i3).compare("*")) {
10869 all=true;
10870 got=true;
10871 break;
10872 }
10873 lines.push_back((string)" "+logic_eval(*i3,vars));
10874 got=true;
10875 }
10876 if(!got)
10877 lines.push_back(lang_get_string(1,lang,14));
10878 if(all)
10879 lines.push_back(lang_get_string(1,lang,166));
10880 l=lang_get_string(1,lang,23);
10881 lines.push_back(l);
10882 got=false;
10883 all=false;
10884 for(i3=(*i).access_grant_group.begin(); i3!=(*i).access_grant_group.end(); i3++) {
10885 if(!(*i3).compare("*")) {
10886 all=true;
10887 got=true;
10888 break;
10889 }
10890 lines.push_back((string)" "+logic_eval(*i3,vars));
10891 got=true;
10892 }
10893 if(!got)
10894 lines.push_back(lang_get_string(1,lang,14));
10895 if(all)
10896 lines.push_back(lang_get_string(1,lang,166));
10897 l=lang_get_string(1,lang,24);
10898 lines.push_back(l);
10899 got=false;
10900 all=false;
10901 for(i3=(*i).access_to_proc.begin(); i3!=(*i).access_to_proc.end(); i3++) {
10902 if(!(*i3).compare("*")) {
10903 all=true;
10904 got=true;
10905 break;
10906 }
10907 lines.push_back((string)" "+logic_eval(*i3,vars));
10908 got=true;
10909 }
10910 if(!got)
10911 lines.push_back(lang_get_string(1,lang,14));
10912 if(all)
10913 lines.push_back(lang_get_string(1,lang,166));
10914 l=lang_get_string(1,lang,25);
10915 lines.push_back(l);
10916 got=false;
10917 all=false;
10918 for(i3=(*i).access_grant_procedure.begin(); i3!=(*i).access_grant_procedure.end(); i3++) {
10919 if(!(*i3).compare("*")) {
10920 all=true;
10921 got=true;
10922 break;
10923 }
10924 lines.push_back((string)" "+logic_eval(*i3,vars));
10925 got=true;
10926 }
10927 if(!got)
10928 lines.push_back(lang_get_string(1,lang,14));
10929 if(all)
10930 lines.push_back(lang_get_string(1,lang,166));
10931 l=lang_get_string(1,lang,589);
10932 lines.push_back(l);
10933 got=false;
10934 all=false;
10935 for(i3=(*i).access_usage_procedure.begin(); i3!=(*i).access_usage_procedure.end(); i3++) {
10936 if(!(*i3).compare("*")) {
10937 all=true;
10938 got=true;
10939 break;
10940 }
10941 lines.push_back((string)" "+logic_eval(*i3,vars));
10942 got=true;
10943 }
10944 if(!got)
10945 lines.push_back(lang_get_string(1,lang,14));
10946 if(all)
10947 lines.push_back(lang_get_string(1,lang,166));
10948 l=lang_get_string(1,lang,30);
10949 lines.push_back(l);
10950 got=false;
10951 all=false;
10952 for(i3=(*i).access_to_channel.begin(); i3!=(*i).access_to_channel.end(); i3++) {
10953 if(!(*i3).compare("*")) {
10954 all=true;
10955 break;
10956 }
10957 lines.push_back((string)" "+logic_eval(*i3,vars));
10958 got=true;
10959 }
10960 if(!got)
10961 lines.push_back(lang_get_string(1,lang,14));
10962 if(all)
10963 lines.push_back(lang_get_string(1,lang,166));
10964 l=lang_get_string(1,lang,31);
10965 lines.push_back(l);
10966 got=false;
10967 all=false;
10968 for(i3=(*i).access_grant_channel.begin(); i3!=(*i).access_grant_channel.end(); i3++) {
10969 if(!(*i3).compare("*")) {
10970 all=true;
10971 got=true;
10972 break;
10973 }
10974 lines.push_back((string)" "+logic_eval(*i3,vars));
10975 got=true;
10976 }
10977 if(!got)
10978 lines.push_back(lang_get_string(1,lang,14));
10979 if(all)
10980 lines.push_back(lang_get_string(1,lang,166));
10981
10982 if((*i).access_to_partyline)
10983 l=lang_get_string(1,lang,16);
10984 else
10985 l=lang_get_string(1,lang,17);
10986 lines.push_back(l);
10987
10988 if((*i).access_grant_partyline)
10989 l=lang_get_string(1,lang,41);
10990 else
10991 l=lang_get_string(1,lang,42);
10992 lines.push_back(l);
10993
10994 char tmp1[64];
10995 char tmp2[64];
10996
10997 ltoa((*i).partyline_msg_flood.lines,tmp1,10);
10998 ltoa((long)(*i).partyline_msg_flood.seconds,tmp2,10);
10999 l=lang_get_string(1,lang,202)+" "+tmp1+" "+tmp2;
11000 lines.push_back(l);
11001
11002 if((*i).access_grant_partyline)
11003 l=lang_get_string(1,lang,394);
11004 else
11005 l=lang_get_string(1,lang,395);
11006 lines.push_back(l);
11007
11008 if((*i).access_to_backup)
11009 l=lang_get_string(1,lang,175);
11010 else
11011 l=lang_get_string(1,lang,176);
11012 lines.push_back(l);
11013
11014 if((*i).access_grant_backup)
11015 l=lang_get_string(1,lang,177);
11016 else
11017 l=lang_get_string(1,lang,178);
11018 lines.push_back(l);
11019
11020 if((*i).access_to_rehash)
11021 l=lang_get_string(1,lang,179);
11022 else
11023 l=lang_get_string(1,lang,180);
11024 lines.push_back(l);
11025
11026 if((*i).access_grant_rehash)
11027 l=lang_get_string(1,lang,181);
11028 else
11029 l=lang_get_string(1,lang,182);
11030 lines.push_back(l);
11031
11032 if((*i).access_to_restart)
11033 l=lang_get_string(1,lang,256);
11034 else
11035 l=lang_get_string(1,lang,257);
11036 lines.push_back(l);
11037
11038 if((*i).access_grant_restart)
11039 l=lang_get_string(1,lang,258);
11040 else
11041 l=lang_get_string(1,lang,259);
11042 lines.push_back(l);
11043
11044 if((*i).access_to_die)
11045 l=lang_get_string(1,lang,263);
11046 else
11047 l=lang_get_string(1,lang,264);
11048 lines.push_back(l);
11049
11050 if((*i).access_grant_die)
11051 l=lang_get_string(1,lang,265);
11052 else
11053 l=lang_get_string(1,lang,266);
11054 lines.push_back(l);
11055
11056 if((*i).access_to_plususer)
11057 l=lang_get_string(1,lang,185);
11058 else
11059 l=lang_get_string(1,lang,184);
11060 lines.push_back(l);
11061
11062 if((*i).access_grant_plususer)
11063 l=lang_get_string(1,lang,186);
11064 else
11065 l=lang_get_string(1,lang,187);
11066 lines.push_back(l);
11067
11068 if((*i).access_to_plusproc)
11069 l=lang_get_string(1,lang,194);
11070 else
11071 l=lang_get_string(1,lang,193);
11072 lines.push_back(l);
11073
11074 if((*i).access_grant_plusproc)
11075 l=lang_get_string(1,lang,195);
11076 else
11077 l=lang_get_string(1,lang,196);
11078 lines.push_back(l);
11079
11080 if((*i).access_to_replication)
11081 l=lang_get_string(1,lang,209);
11082 else
11083 l=lang_get_string(1,lang,209);
11084 lines.push_back(l);
11085
11086 if(!(*i).access_grant_replication)
11087 l=lang_get_string(1,lang,598);
11088 else
11089 l=lang_get_string(1,lang,599);
11090 lines.push_back(l);
11091
11092 if((*i).access_to_filesystem)
11093 l=lang_get_string(1,lang,390);
11094 else
11095 l=lang_get_string(1,lang,391);
11096 lines.push_back(l);
11097
11098 if((*i).access_grant_filesystem)
11099 l=lang_get_string(1,lang,392);
11100 else
11101 l=lang_get_string(1,lang,393);
11102 lines.push_back(l);
11103
11104 if(!(*i).access_to_private)
11105 l=lang_get_string(1,lang,489);
11106 else
11107 l=lang_get_string(1,lang,490);
11108 lines.push_back(l);
11109
11110 if(!(*i).access_grant_private)
11111 l=lang_get_string(1,lang,491);
11112 else
11113 l=lang_get_string(1,lang,492);
11114 lines.push_back(l);
11115
11116 if((*i).access_to_upgrade)
11117 l=lang_get_string(1,lang,621);
11118 else
11119 l=lang_get_string(1,lang,622);
11120 lines.push_back(l);
11121
11122 if((*i).access_grant_upgrade)
11123 l=lang_get_string(1,lang,623);
11124 else
11125 l=lang_get_string(1,lang,624);
11126 lines.push_back(l);
11127
11128 if((*i).access_to_apply)
11129 l=lang_get_string(1,lang,683);
11130 else
11131 l=lang_get_string(1,lang,684);
11132 lines.push_back(l);
11133
11134 if((*i).access_grant_apply)
11135 l=lang_get_string(1,lang,685);
11136 else
11137 l=lang_get_string(1,lang,686);
11138 lines.push_back(l);
11139
11140 if(!(*i).access_to_can_send_all_users)
11141 l=lang_get_string(1,lang,493);
11142 else
11143 l=lang_get_string(1,lang,494);
11144 lines.push_back(l);
11145
11146 if(!(*i).access_grant_can_send_all_users)
11147 l=lang_get_string(1,lang,495);
11148 else
11149 l=lang_get_string(1,lang,496);
11150 lines.push_back(l);
11151
11152 if(!(*i).access_to_can_send_unknown_users)
11153 l=lang_get_string(1,lang,497);
11154 else
11155 l=lang_get_string(1,lang,498);
11156 lines.push_back(l);
11157
11158 if(!(*i).access_grant_can_send_unknown_users)
11159 l=lang_get_string(1,lang,499);
11160 else
11161 l=lang_get_string(1,lang,500);
11162 lines.push_back(l);
11163
11164 vector<s_channel>::iterator i6;
11165 for(i6=r_channels.begin(); i6!=r_channels.end(); i6++) {
11166 if(!(*i6).username.compare((*i).name)) {
11167 l=lang_get_string(1,lang,26)+" "+(*i6).channel_name;
11168 lines.push_back(l);
11169 l=(string)" "+lang_get_string(1,lang,27);
11170 lines.push_back(l);
11171 got=false;
11172 for(i4=(*i6).groups.begin(); i4!=(*i6).groups.end(); i4++) {
11173 l=" ";
11174 l+=logic_eval((*i4).name,vars);
11175 lines.push_back(l);
11176 got=true;
11177 }
11178 if(!got)
11179 lines.push_back(lang_get_string(1,lang,14));
11180 l=(string)" "+lang_get_string(1,lang,28)+" on_op = "+(*i6).on_op;
11181 lines.push_back(l);
11182 l=(string)" "+lang_get_string(1,lang,28)+" on_deop = "+(*i6).on_deop;
11183 lines.push_back(l);
11184 l=(string)" "+lang_get_string(1,lang,28)+" on_ban = "+(*i6).on_ban;
11185 lines.push_back(l);
11186 l=(string)" "+lang_get_string(1,lang,28)+" on_unban = "+(*i6).on_unban;
11187 lines.push_back(l);
11188 l=(string)" "+lang_get_string(1,lang,28)+" on_kick = "+(*i6).on_kick;
11189 lines.push_back(l);
11190 l=(string)" "+lang_get_string(1,lang,28)+" on_voice = "+(*i6).on_voice;
11191 lines.push_back(l);
11192 l=(string)" "+lang_get_string(1,lang,28)+" on_devoice = "+(*i6).on_devoice;
11193 lines.push_back(l);
11194 l=(string)" "+lang_get_string(1,lang,28)+" on_creator = "+(*i6).on_creator;
11195 lines.push_back(l);
11196 l=(string)" "+lang_get_string(1,lang,28)+" on_decreator = "+(*i6).on_decreator;
11197 lines.push_back(l);
11198 l=(string)" "+lang_get_string(1,lang,28)+" on_join = "+(*i6).on_join;
11199 lines.push_back(l);
11200 l=(string)" "+lang_get_string(1,lang,28)+" on_banned = "+(*i6).on_banned;
11201 lines.push_back(l);
11202 l=(string)" "+lang_get_string(1,lang,28)+" on_flood = "+(*i6).on_flood;
11203 lines.push_back(l);
11204 l=(string)" "+lang_get_string(1,lang,28)+" on_privmsg = "+(*i6).on_privmsg;
11205 lines.push_back(l);
11206 l=(string)" "+lang_get_string(1,lang,28)+" on_notice = "+(*i6).on_notice;
11207 lines.push_back(l);
11208 l=(string)" "+lang_get_string(1,lang,28)+" on_except = "+(*i6).on_except;
11209 lines.push_back(l);
11210 l=(string)" "+lang_get_string(1,lang,28)+" on_unexcept = "+(*i6).on_unexcept;
11211 lines.push_back(l);
11212 l=(string)" "+lang_get_string(1,lang,28)+" on_invite = "+(*i6).on_invite;
11213 lines.push_back(l);
11214 l=(string)" "+lang_get_string(1,lang,28)+" on_uninvite = "+(*i6).on_uninvite;
11215 lines.push_back(l);
11216 l=(string)" "+lang_get_string(1,lang,28)+" on_not_invited = "+(*i6).on_not_invited;
11217 lines.push_back(l);
11218 l=(string)" "+lang_get_string(1,lang,28)+" on_not_in_reop = "+(*i6).on_not_in_reop;
11219 lines.push_back(l);
11220 l=(string)" "+lang_get_string(1,lang,28)+" on_reop = "+(*i6).on_reop;
11221 lines.push_back(l);
11222 l=(string)" "+lang_get_string(1,lang,28)+" on_other_mode = "+(*i6).on_other_mode;
11223 lines.push_back(l);
11224
11225 char tmp1[64];
11226 char tmp2[64];
11227
11228 ltoa((*i6).msg_flood.lines,tmp1,10);
11229 ltoa((long)(*i6).msg_flood.seconds,tmp2,10);
11230 l=(string)" "+lang_get_string(1,lang,28)+" msg_flood "+tmp1+" "+tmp2;
11231 lines.push_back(l);
11232
11233 ltoa((*i6).notice_flood.lines,tmp1,10);
11234 ltoa((long)(*i6).notice_flood.seconds,tmp2,10);
11235 l=(string)" "+lang_get_string(1,lang,28)+" notice_flood "+tmp1+" "+tmp2;
11236 lines.push_back(l);
11237
11238 ltoa((*i6).repeat_flood.lines,tmp1,10);
11239 ltoa((long)(*i6).repeat_flood.seconds,tmp2,10);
11240 l=(string)" "+lang_get_string(1,lang,28)+" repeat_flood "+tmp1+" "+tmp2;
11241 lines.push_back(l);
11242
11243 ltoa((*i6).nick_flood.lines,tmp1,10);
11244 ltoa((long)(*i6).nick_flood.seconds,tmp2,10);
11245 l=(string)" "+lang_get_string(1,lang,28)+" nick_flood "+tmp1+" "+tmp2;
11246 lines.push_back(l);
11247
11248 ltoa((*i6).join_flood.lines,tmp1,10);
11249 ltoa((long)(*i6).join_flood.seconds,tmp2,10);
11250 l=(string)" "+lang_get_string(1,lang,28)+" join_flood "+tmp1+" "+tmp2;
11251 lines.push_back(l);
11252
11253 ltoa((*i6).mode_flood.lines,tmp1,10);
11254 ltoa((long)(*i6).mode_flood.seconds,tmp2,10);
11255 l=(string)" "+lang_get_string(1,lang,28)+" mode_flood "+tmp1+" "+tmp2;
11256 lines.push_back(l);
11257
11258 ltoa((*i6).ctcp_flood.lines,tmp1,10);
11259 ltoa((long)(*i6).ctcp_flood.seconds,tmp2,10);
11260 l=(string)" "+lang_get_string(1,lang,28)+" ctcp_flood "+tmp1+" "+tmp2;
11261 lines.push_back(l);
11262
11263 l=(string)" "+lang_get_string(1,lang,28)+" dynamic1 (plus modes) "+(*i6).dynamic_plus_modes;
11264 lines.push_back(l);
11265 l=(string)" "+lang_get_string(1,lang,28)+" dynamic2 (minus modes) "+(*i6).dynamic_minus_modes;
11266 lines.push_back(l);
11267
11268 if(!(*i6).can_send_unknown_users)
11269 l=(string)" "+lang_get_string(1,lang,501);
11270 else
11271 l=(string)" "+lang_get_string(1,lang,502);
11272 lines.push_back(l);
11273 }
11274 }
11275
11276 lines.push_back("----");
11277 cnt++;
11278 }
11279 }
11280 return cnt;
11281 }
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291 bool logic_partyline_user_exists(string name)
11292 {
11293 name=logic_to_upper(name);
11294 bool res=false;
11295 vector<s_user>::iterator i;
11296 for(i=r_users.begin(); i!=r_users.end(); i++) {
11297 if(!logic_to_upper((*i).name).compare(name)) {
11298 res=true;
11299 break;
11300 }
11301 }
11302 return res;
11303 }
11304
11305
11306
11307
11308
11309
11310
11311
11312 void logic_partyline_get_channels(vector<string>& channels)
11313 {
11314 channels.clear();
11315 vector<s_channel>::iterator i;
11316 for(i=r_channels.begin(); i!=r_channels.end(); i++)
11317 channels.push_back((*i).channel_name);
11318 for(i=r_channel_templates.begin(); i!=r_channel_templates.end(); i++)
11319 channels.push_back((*i).channel_name);
11320 }
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331 bool logic_partyline_get_channel_def(string channel_name, s_channel_def& chd)
11332 {
11333 vector<s_channel_def>::iterator i;
11334 for(i=r_channel_defs.begin(); i!=r_channel_defs.end(); i++) {
11335 if(!cmp_strings_case_insensitive((*i).channel_name,channel_name)) {
11336 chd=*i;
11337 return true;
11338 }
11339 }
11340 return false;
11341 }
11342
11343
11344
11345
11346
11347
11348
11349
11350 void logic_partyline_remove_channel_def(string channel_name)
11351 {
11352 vector<s_channel_def>::iterator i;
11353 for(i=r_channel_defs.begin(); i!=r_channel_defs.end(); i++) {
11354 if(!(*i).channel_name.compare(channel_name)) {
11355 r_channel_defs.erase(i);
11356 break;
11357 }
11358 }
11359 }
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369 bool logic_partyline_add_channel_def(s_channel_def& chd)
11370 {
11371 r_channel_defs.push_back(chd);
11372
11373 return true;
11374 }
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384 void logic_partyline_add_user(s_user& user, vector<s_channel>& channels)
11385 {
11386 if(user.is_template) {
11387 user.hostmask.clear();
11388 user.fullname.clear();
11389 vector<s_channel>::iterator i2;
11390 l2:
11391 for(i2=r_channel_templates.begin(); i2!=r_channel_templates.end(); i2++) {
11392 if(!(*i2).username.compare(user.name)) {
11393 r_channel_templates.erase(i2);
11394 goto l2;
11395 }
11396 }
11397
11398 time(&user.last_changed);
11399 r_user_templates.push_back(user);
11400
11401 for(i2=channels.begin(); i2!=channels.end(); i2++) {
11402 (*i2).is_template=true;
11403 if((*i2).channel_name.length()>0 && (*i2).channel_name[0]!='\"')
11404 (*i2).channel_name="\""+(*i2).channel_name+"\"";
11405 r_channel_templates.push_back(*i2);
11406 }
11407 } else {
11408 vector<s_channel>::iterator i2;
11409 l1:
11410 for(i2=r_channels.begin(); i2!=r_channels.end(); i2++) {
11411 if(!(*i2).username.compare(user.name)) {
11412 r_channels.erase(i2);
11413 goto l1;
11414 }
11415 }
11416
11417 time(&user.last_changed);
11418
11419 if(!user.terminator) {
11420 r_users.push_back(user);
11421 for(i2=channels.begin(); i2!=channels.end(); i2++) {
11422 (*i2).is_template=false;
11423 (*i2).terminator=false;
11424 if((*i2).channel_name.length()>0 && (*i2).channel_name[0]!='\"')
11425 (*i2).channel_name="\""+(*i2).channel_name+"\"";
11426 r_channels.push_back(*i2);
11427 }
11428 } else {
11429 r_terminators.push_back(user);
11430 for(i2=channels.begin(); i2!=channels.end(); i2++) {
11431 (*i2).is_template=false;
11432 (*i2).terminator=true;
11433 if((*i2).channel_name.length()>0 && (*i2).channel_name[0]!='\"')
11434 (*i2).channel_name="\""+(*i2).channel_name+"\"";
11435 r_channel_terminators.push_back(*i2);
11436 }
11437 }
11438 }
11439 }
11440
11441
11442
11443
11444
11445
11446
11447
11448 void logic_partyline_remove_user(string username)
11449 {
11450 vector<s_user>::iterator i1;
11451 bool template_=false;
11452 l1:
11453 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
11454 if(!(*i1).name.compare(username)) {
11455 if((*i1).is_template)
11456 template_=true;
11457 r_users.erase(i1);
11458 goto l1;
11459 }
11460 }
11461 if(template_) {
11462 vector<s_channel>::iterator i2;
11463 l2:
11464 for(i2=r_channel_templates.begin(); i2!=r_channel_templates.end(); i2++) {
11465 if(!(*i2).username.compare(username)) {
11466 r_channel_templates.erase(i2);
11467 goto l2;
11468 }
11469 }
11470 }
11471 l3:
11472 for(i1=r_terminators.begin(); i1!=r_terminators.end(); i1++) {
11473 if(!(*i1).name.compare(username)) {
11474 r_terminators.erase(i1);
11475 goto l3;
11476 }
11477 }
11478 vector<s_channel>::iterator i2;
11479 l4:
11480 for(i2=r_channel_terminators.begin(); i2!=r_channel_terminators.end(); i2++) {
11481 if(!(*i2).username.compare(username)) {
11482 r_channel_terminators.erase(i2);
11483 goto l4;
11484 }
11485 }
11486 }
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498 void logic_list_proc(string proc_name, list<string>& commands, string& declaration, vector<string>& groups)
11499 {
11500 commands.clear();
11501 groups.clear();
11502
11503 string ln;
11504 unsigned int ii;
11505 unsigned int indent=4;
11506
11507 vector<s_procedure>::iterator i2;
11508 for(i2=r_procedures.begin(); i2!=r_procedures.end(); i2++) {
11509 if(!(*i2).name.compare(proc_name)) {
11510 vector<s_group>::iterator i4;
11511 for(i4=(*i2).groups.begin(); i4!=(*i2).groups.end(); i4++)
11512 groups.push_back((*i4).name);
11513 declaration=(*i2).name;
11514 list<s_command>::iterator i3;
11515 for(i3=(*i2).commands.begin(); i3!=(*i2).commands.end(); i3++) {
11516 switch((*i3).command) {
11517 case _op:
11518 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11519 ln+=(string)"op "+logic_set_priority((*i3).priority)+" "+(*i3).channel+" "+(*i3).whom;
11520 commands.push_back(ln);
11521 break;
11522 case _deop:
11523 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11524 ln+=(string)"deop "+logic_set_priority((*i3).priority)+" "+(*i3).channel+" "+(*i3).whom;
11525 commands.push_back(ln);
11526 break;
11527 case _voice:
11528 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11529 ln+=(string)"voice "+logic_set_priority((*i3).priority)+" "+(*i3).channel+" "+(*i3).whom;
11530 commands.push_back(ln);
11531 break;
11532 case _devoice:
11533 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11534 ln+=(string)"devoice "+logic_set_priority((*i3).priority)+" "+(*i3).channel+" "+(*i3).whom;
11535 commands.push_back(ln);
11536 break;
11537 case _kick:
11538 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11539 ln+=(string)"kick "+(*i3).channel+" "+(*i3).whom+" "+(*i3).msg_text;
11540 commands.push_back(ln);
11541 break;
11542 case _msg:
11543 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11544 ln+=(string)"msg "+logic_set_priority((*i3).priority)+" "+(*i3).whom+" "+(*i3).msg_text;
11545 commands.push_back(ln);
11546 break;
11547 case _msgq:
11548 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11549 ln+=(string)"msgq "+logic_set_priority((*i3).priority)+" "+(*i3).whom+" "+(*i3).msg_text+" "+(*i3).msg_quoted;
11550 commands.push_back(ln);
11551 break;
11552 case _if_in:
11553 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11554 ln+=(string)"if_in "+(*i3).left+" "+(*i3).right;
11555 commands.push_back(ln);
11556
11557 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11558 ln+="{";
11559 commands.push_back(ln);
11560 indent+=4;
11561 break;
11562 case _if_n_in:
11563 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11564 ln+=(string)"!if_in "+(*i3).left+" "+(*i3).right;
11565 commands.push_back(ln);
11566
11567 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11568 ln+="{";
11569 commands.push_back(ln);
11570 indent+=4;
11571 break;
11572 case _if_match:
11573 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11574 ln+=(string)"if_match "+(*i3).left+" "+(*i3).right;
11575 commands.push_back(ln);
11576
11577 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11578 ln+="{";
11579 commands.push_back(ln);
11580 indent+=4;
11581 break;
11582 case _if_match_case_insensitive:
11583 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11584 ln+=(string)"if_match_case_insensitive "+(*i3).left+" "+(*i3).right;
11585 commands.push_back(ln);
11586
11587 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11588 ln+="{";
11589 commands.push_back(ln);
11590 indent+=4;
11591 break;
11592 case _if_group:
11593 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11594 ln+=(string)"if_group "+(*i3).left+" "+(*i3).right;
11595 commands.push_back(ln);
11596
11597 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11598 ln+="{";
11599 commands.push_back(ln);
11600 indent+=4;
11601 break;
11602 case _if_n_match:
11603 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11604 ln+=(string)"!if_match "+(*i3).left+" "+(*i3).right;
11605 commands.push_back(ln);
11606
11607 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11608 ln+="{";
11609 commands.push_back(ln);
11610 indent+=4;
11611 break;
11612 case _if_n_match_case_insensitive:
11613 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11614 ln+=(string)"!if_match_case_insensitive "+(*i3).left+" "+(*i3).right;
11615 commands.push_back(ln);
11616
11617 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11618 ln+="{";
11619 commands.push_back(ln);
11620 indent+=4;
11621 break;
11622 case _if_n_group:
11623 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11624 ln+=(string)"!if_group "+(*i3).left+" "+(*i3).right;
11625 commands.push_back(ln);
11626
11627 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11628 ln+="{";
11629 commands.push_back(ln);
11630 indent+=4;
11631 break;
11632 case _return:
11633 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11634 ln+="return";
11635 commands.push_back(ln);
11636 break;
11637 case _work:
11638 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11639 ln+="work";
11640 commands.push_back(ln);
11641 break;
11642 case _timer_once:
11643 case _timer_every:
11644 {
11645 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11646 if((*i3).command==_timer_once)
11647 ln+=(string)"timer_once "+(*i3).timer_name+" ";
11648 else
11649 ln+=(string)"timer_every "+(*i3).timer_name+" ";
11650 time_t duration=(*i3).timer_sec;
11651 string dur="";
11652
11653 time_t j;
11654
11655 j=duration%60;
11656 char tmp[64];
11657 char tmp2[2];
11658 tmp2[1]=0;
11659 ltoa((long)j,tmp,10);
11660 if(j<10)
11661 tmp2[0]='0';
11662 else
11663 tmp2[0]=0;
11664 dur=(string)":"+(string)tmp2+(string)tmp+dur;
11665
11666 duration/=60;
11667 j=duration%60;
11668 ltoa((long)j,tmp,10);
11669 if(j<10)
11670 tmp2[0]='0';
11671 else
11672 tmp2[0]=0;
11673 dur=(string)":"+(string)tmp2+(string)tmp+dur;
11674
11675 duration/=60;
11676 j=duration%24;
11677 ltoa((long)j,tmp,10);
11678 if(j<10)
11679 tmp2[0]='0';
11680 else
11681 tmp2[0]=0;
11682 dur=(string)":"+(string)tmp2+(string)tmp+dur;
11683
11684 duration/=24;
11685 ltoa((long)j,tmp,10);
11686 dur=(string)tmp+dur;
11687
11688 ln+=dur+" ";
11689 ln+=(*i3).timer_cmd;
11690
11691 commands.push_back(ln);
11692 }
11693 break;
11694 case _kill_timers:
11695 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11696 ln+=(string)"kill_timers "+(*i3).timer_name;
11697 commands.push_back(ln);
11698 break;
11699 case _execute:
11700 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11701 ln+=(string)"execute "+(*i3).exec;
11702 commands.push_back(ln);
11703 break;
11704 case _remote_execute:
11705 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11706 ln+=(*i3).result+"=remote_execute "+(*i3).botname+" "+(*i3).exec;
11707 commands.push_back(ln);
11708 break;
11709 case _smtp:
11710 {
11711 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11712 ln+="SMTP";
11713 commands.push_back(ln);
11714
11715 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11716 ln+="{";
11717 commands.push_back(ln);
11718 indent+=4;
11719
11720 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11721 ln+=(string)"server "+(*i3).smtp.server;
11722 commands.push_back(ln);
11723
11724 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11725 char tmp[64];
11726 ltoa((*i3).smtp.port,tmp,10);
11727 ln+=(string)"port "+tmp;
11728 commands.push_back(ln);
11729
11730 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11731 ln+=(string)"HELO "+(*i3).smtp.helo;
11732 commands.push_back(ln);
11733
11734 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11735 ln+=(string)"MAIL_FROM "+(*i3).smtp.mail_from;
11736 commands.push_back(ln);
11737
11738 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11739 ln+=(string)"RCPT_TO "+(*i3).smtp.rcpt_to;
11740 commands.push_back(ln);
11741
11742 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11743 ln+=(string)"DATA";
11744 commands.push_back(ln);
11745
11746 list<string>::iterator i4;
11747 for(i4=(*i3).smtp.data_lines.begin(); i4!=(*i3).smtp.data_lines.end(); i4++) {
11748 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11749 ln+=*i4;
11750 commands.push_back(ln);
11751 }
11752
11753 indent-=4;
11754 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11755 ln+="}";
11756 commands.push_back(ln);
11757 }
11758 break;
11759 case _net_send:
11760 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11761 ln+=(string)"NET_SEND "+(*i3).net_send_host+" "+(*i3).net_send_msg;
11762 commands.push_back(ln);
11763 break;
11764 case _log:
11765 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11766 ln+=(string)"LOG "+(*i3).log;
11767 commands.push_back(ln);
11768 break;
11769 case _join:
11770 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11771 ln+=(string)"join "+(*i3).channel+" "+(*i3).channel_key;
11772 commands.push_back(ln);
11773 break;
11774 case _part:
11775 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11776 ln+=(string)"part "+(*i3).channel+" "+(*i3).msg_text;
11777 commands.push_back(ln);
11778 break;
11779 case _disconnect:
11780 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11781 ln+="disconnect";
11782 commands.push_back(ln);
11783 break;
11784 case _irc_server:
11785 {
11786 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11787 char tmp[64];
11788 ltoa((*i3).port,tmp,10);
11789 ln+=(string)"irc_server "+(*i3).server+" "+tmp;
11790 commands.push_back(ln);
11791 }
11792 break;
11793 case _try_connect:
11794 {
11795 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11796 ln+=(string)"try_connect";
11797 commands.push_back(ln);
11798 }
11799 break;
11800 case _bot_nick:
11801 {
11802 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11803 ln+="bot_nick";
11804 vector<string>::iterator i4;
11805 for(i4=(*i3).bot_nick.begin(); i4!=(*i3).bot_nick.end(); i4++)
11806 ln+=(string)" "+*i4;
11807 commands.push_back(ln);
11808 }
11809 break;
11810 case _delete_irc_servers:
11811 {
11812 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11813 ln+="delete_irc_servers ";
11814 ln+=(*i3).server;
11815 commands.push_back(ln);
11816 }
11817 break;
11818 case _delete_nicks:
11819 {
11820 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11821 ln+="delete_nicks ";
11822 ln+=(*i3).nick;
11823 commands.push_back(ln);
11824 }
11825 break;
11826 case _change_nick:
11827 {
11828 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11829 ln+="change_nick ";
11830 ln+=(*i3).nick;
11831 commands.push_back(ln);
11832 }
11833 break;
11834 case _bot_ident:
11835 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11836 ln+=(string)"bot_ident "+(*i3).bot_ident;
11837 commands.push_back(ln);
11838 break;
11839 case _bot_ident_ipv6:
11840 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11841 ln+=(string)"bot_ident_ipv6 "+(*i3).bot_ident;
11842 commands.push_back(ln);
11843 break;
11844 case _bot_fullname:
11845 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11846 ln+=(string)"bot_fullname "+(*i3).bot_fullname;
11847 commands.push_back(ln);
11848 break;
11849 case _bot_auth:
11850 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11851 ln+=(string)"bot_auth";
11852 commands.push_back(ln);
11853 break;
11854 case _bot_redir:
11855 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11856 ln+=(string)"allow_redirect "+((*i3).bot_redir?"1":"0");
11857 commands.push_back(ln);
11858 break;
11859 case _if_error:
11860 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11861 ln+=(string)"if_error";
11862 commands.push_back(ln);
11863
11864 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11865 ln+=(string)"{";
11866 commands.push_back(ln);
11867 indent+=4;
11868 break;
11869 case _wait:
11870 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11871 ln+=(string)"wait_if_error";
11872 commands.push_back(ln);
11873
11874 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11875 ln+=(string)"{";
11876 commands.push_back(ln);
11877 indent+=4;
11878 break;
11879 case _label:
11880 break;
11881 case _goto:
11882 break;
11883 case _real_label:
11884 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11885 ln+=(string)"label "+(*i3).label;
11886 commands.push_back(ln);
11887 break;
11888 case _real_goto:
11889 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11890 ln+=(string)"goto "+(*i3).label;
11891 commands.push_back(ln);
11892 break;
11893 case _sleep_:
11894 {
11895 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11896 ln+=(string)"sleep ";
11897 char tmp[64];
11898 ltoa((*i3).sleep_secs,tmp,10);
11899 ln+=tmp;
11900 commands.push_back(ln);
11901 }
11902 break;
11903 case _dynamic_ban:
11904 {
11905 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11906 ln+=(string)"dynamic_ban ";
11907 ln+=(*i3).channel;
11908 ln+=" ";
11909 ln+=(*i3).ban_prefix;
11910 ln+=" ";
11911 ln+=(*i3).ban_mask;
11912 ln+=" ";
11913 ln+=(*i3).ban_reason;
11914 commands.push_back(ln);
11915 }
11916 break;
11917 case _process_on_banned:
11918 {
11919 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11920 ln+=(string)"process_on_banned ";
11921 ln+=(*i3).channel;
11922 ln+=" ";
11923 ln+=(*i3).ban_mask;
11924 commands.push_back(ln);
11925 }
11926 break;
11927 case _check_dynamic_bans:
11928 {
11929 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11930 ln+=(*i3).result;
11931 ln+="=check_dynamic_bans ";
11932 ln+=(*i3).channel;
11933 ln+=" ";
11934 ln+=(*i3).nick;
11935 ln+=" ";
11936 ln+=(*i3).ban_reason;
11937 commands.push_back(ln);
11938 }
11939 break;
11940 case _restart:
11941 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11942 ln+=(string)"restart";
11943 commands.push_back(ln);
11944 break;
11945 case _raw:
11946 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11947 ln+=(string)"raw "+logic_set_priority((*i3).priority)+" "+(*i3).msg_text;
11948 commands.push_back(ln);
11949 break;
11950 case _admin_msg:
11951 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11952 ln+=(string)"admin_msg "+(*i3).admin_msg_type+" "+(*i3).admin_msg_mask+" "+(*i3).admin_msg_message;
11953 commands.push_back(ln);
11954 break;
11955 case _notice:
11956 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11957 ln+=(string)"notice "+logic_set_priority((*i3).priority)+" "+(*i3).whom+" "+(*i3).msg_text;
11958 commands.push_back(ln);
11959 break;
11960 case _noticeq:
11961 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11962 ln+=(string)"noticeq "+logic_set_priority((*i3).priority)+" "+(*i3).whom+" "+(*i3).msg_text+" "+(*i3).msg_quoted;
11963 commands.push_back(ln);
11964 break;
11965 case _unban_mask:
11966 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11967 ln+=(string)"unban_mask "+(*i3).channel+" "+(*i3).whom;
11968 commands.push_back(ln);
11969 break;
11970 case _ban_mask:
11971 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11972 ln+=(string)"ban_mask "+(*i3).channel+" "+(*i3).whom;
11973 commands.push_back(ln);
11974 break;
11975 case _dcc_server:
11976 {
11977 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11978 ln+=(string)"dcc_server ";
11979 char tmp[64];
11980 ltoa((*i3).group,tmp,10);
11981 ln+=tmp;
11982 ln+=(string)" "+(*i3).server+" ";
11983 ltoa((*i3).port,tmp,10);
11984 ln+=tmp;
11985 ln+=" ";
11986 ln+=(*i3).server_type;
11987 commands.push_back(ln);
11988 }
11989 break;
11990 case _dcc_server_ipv6:
11991 {
11992 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
11993 ln+=(string)"dcc_server_ipv6 ";
11994 char tmp[64];
11995 ltoa((*i3).group,tmp,10);
11996 ln+=tmp;
11997 ln+=(string)" "+(*i3).server+" ";
11998 ltoa((*i3).port,tmp,10);
11999 ln+=tmp;
12000 ln+=" ";
12001 ln+=(*i3).server_type;
12002 commands.push_back(ln);
12003 }
12004 break;
12005 case _end_bracket:
12006 indent-=4;
12007 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12008 ln+="}";
12009 commands.push_back(ln);
12010 break;
12011 case _ident:
12012 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12013 ln+=(*i3).result+"=ident "+(*i3).nick;
12014 commands.push_back(ln);
12015 break;
12016 case _host:
12017 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12018 ln+=(*i3).result+"=host "+(*i3).nick;
12019 commands.push_back(ln);
12020 break;
12021 case _get_chan_mode:
12022 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12023 ln+=(*i3).result+"=get_chan_mode "+(*i3).channel;
12024 commands.push_back(ln);
12025 break;
12026 case _get_chan_topic:
12027 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12028 ln+=(*i3).result+"=get_chan_topic "+(*i3).channel;
12029 commands.push_back(ln);
12030 break;
12031 case _topic:
12032 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12033 ln+="topic "+(*i3).channel+" "+(*i3).msg_text;
12034 commands.push_back(ln);
12035 break;
12036 case _script:
12037 {
12038 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12039 ln+="SCRIPT ";
12040 ln+=(*i3).script_type;
12041 ln+=" ";
12042 char tmp[64];
12043 ltoa((*i3).script_num,tmp,10);
12044 ln+=tmp;
12045 ln+=" ";
12046 ln+=(*i3).script_channel;
12047 ln+=" ";
12048 ln+=(*i3).script_params;
12049 commands.push_back(ln);
12050 }
12051 break;
12052 case _link:
12053 {
12054 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12055 char tmp[64];
12056 ltoa((*i3).botport,tmp,10);
12057 string port=tmp;
12058 ln+=(string)"link "+(*i3).botlinktype+" "+(*i3).botname+" "+(*i3).botlocalip+" "+(*i3).botip+" "+port+" "+(*i3).botunlinkproc;
12059 commands.push_back(ln);
12060 }
12061 break;
12062 case _chan_mode:
12063 {
12064 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12065 ln+=(string)"chan_mode "+logic_set_priority((*i3).priority)+" "+(*i3).channel+" "+(*i3).chan_mode;
12066 commands.push_back(ln);
12067 }
12068 break;
12069 case _telnet_server:
12070 {
12071 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12072 char tmp[64];
12073 ltoa((*i3).port,tmp,10);
12074 string port=tmp;
12075 ln+=(string)"telnet_server "+(*i3).server+" "+port;
12076 commands.push_back(ln);
12077 }
12078 break;
12079 case _telnet_server_ipv6:
12080 {
12081 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12082 char tmp[64];
12083 ltoa((*i3).port,tmp,10);
12084 string port=tmp;
12085 ln+=(string)"telnet_server_ipv6 "+(*i3).server+" "+port;
12086 commands.push_back(ln);
12087 }
12088 break;
12089 default:
12090 log_debug("in file " __FILE__ " in function " __FUNC__ " occurred error: unknown command");
12091 break;
12092 }
12093 }
12094 while(indent>0) {
12095 indent-=4;
12096 ln=""; for(ii=0; ii<indent; ii++) ln+=" ";
12097 ln+="}";
12098 commands.push_back(ln);
12099 }
12100 }
12101 }
12102 }
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113 void logic_partyline_get_user(string user_name, s_user& user, vector<s_channel>& channels)
12114 {
12115 user.clear();
12116 channels.clear();
12117 vector<s_user>::iterator i;
12118 vector<s_user> usrs;
12119 for(int iii=0; iii<2; iii++) {
12120 switch(iii) {
12121 case 0:
12122 usrs=r_users;
12123 break;
12124 case 1:
12125 usrs=r_terminators;
12126 break;
12127 }
12128 for(i=usrs.begin(); i!=usrs.end(); i++) {
12129 if(!(*i).name.compare(user_name)) {
12130 user=*i;
12131 vector<string> all_channels;
12132 vector<string>::iterator i4;
12133
12134 vector<s_channel>::iterator i3;
12135 if(iii==0) {
12136 for(i3=r_channels.begin(); i3!=r_channels.end(); i3++) {
12137 bool got_channel=false;
12138 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12139 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12140 got_channel=true;
12141 break;
12142 }
12143 if(!got_channel)
12144 all_channels.push_back((*i3).channel_name);
12145
12146 if(!(*i3).username.compare((*i).name)) {
12147 s_channel ch=*i3;
12148 ch.configured=true;
12149 channels.push_back(ch);
12150 }
12151 }
12152 } else {
12153 for(i3=r_channel_terminators.begin(); i3!=r_channel_terminators.end(); i3++) {
12154 bool got_channel=false;
12155 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12156 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12157 got_channel=true;
12158 break;
12159 }
12160 if(!got_channel)
12161 all_channels.push_back((*i3).channel_name);
12162
12163 if(!(*i3).username.compare((*i).name)) {
12164 s_channel ch=*i3;
12165 ch.configured=true;
12166 channels.push_back(ch);
12167 }
12168 }
12169 }
12170 l1:
12171 if(iii==0) {
12172 for(i3=r_channels.begin(); i3!=r_channels.end(); i3++)
12173 if(!(*i3).username.compare((*i).name))
12174 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12175 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12176 all_channels.erase(i4);
12177 goto l1;
12178 }
12179 } else {
12180 for(i3=r_channel_terminators.begin(); i3!=r_channel_terminators.end(); i3++)
12181 if(!(*i3).username.compare((*i).name))
12182 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12183 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12184 all_channels.erase(i4);
12185 goto l1;
12186 }
12187 }
12188 vector<string>::iterator i1;
12189 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12190 for(i1=(*i).access_to_channel.begin(); i1!=(*i).access_to_channel.end(); i1++)
12191 if(!(*i4).compare(*i1)) {
12192 s_channel ch;
12193 ch.terminator=iii==1;
12194 ch.is_template=false;
12195 ch.configured=false;
12196 ch.can_send_unknown_users=false;
12197 ch.username=user_name;
12198 ch.channel_name=*i4;
12199 ch.host_unknown=false;
12200 ch.groups.clear();
12201 ch.on_deop="";
12202 ch.on_ban="";
12203 ch.on_unban="";
12204 ch.on_kick="";
12205 ch.on_op="";
12206 ch.on_voice="";
12207 ch.on_devoice="";
12208 ch.on_creator="";
12209 ch.on_decreator="";
12210 ch.on_join="";
12211 ch.on_banned="";
12212 ch.on_flood="";
12213 ch.on_privmsg="";
12214 ch.on_notice="";
12215 ch.on_other_mode="";
12216 ch.msg_flood.lines=0;
12217 ch.msg_flood.seconds=0;
12218 ch.notice_flood.lines=0;
12219 ch.notice_flood.seconds=0;
12220 ch.repeat_flood.lines=0;
12221 ch.repeat_flood.seconds=0;
12222 ch.nick_flood.lines=0;
12223 ch.nick_flood.seconds=0;
12224 ch.join_flood.lines=0;
12225 ch.join_flood.seconds=0;
12226 ch.mode_flood.lines=0;
12227 ch.mode_flood.seconds=0;
12228 ch.ctcp_flood.lines=0;
12229 ch.ctcp_flood.seconds=0;
12230 channels.push_back(ch);
12231 }
12232 }
12233 }
12234 }
12235 }
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246 void logic_partyline_get_user_template(string user_name, s_user& user, vector<s_channel>& channels)
12247 {
12248 channels.clear();
12249 vector<s_user>::iterator i;
12250 for(i=r_user_templates.begin(); i!=r_user_templates.end(); i++) {
12251 if(!(*i).name.compare(user_name)) {
12252 user=*i;
12253 user.is_template=false;
12254 vector<string> all_channels;
12255 vector<string>::iterator i4;
12256
12257 map<string,string> vars;
12258
12259 vector<s_channel>::iterator i3;
12260 for(i3=r_channel_templates.begin(); i3!=r_channel_templates.end(); i3++) {
12261 bool got_channel=false;
12262 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12263 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12264 got_channel=true;
12265 break;
12266 }
12267 if(!got_channel)
12268 all_channels.push_back((*i3).channel_name);
12269
12270 if(!(*i3).username.compare((*i).name)) {
12271 s_channel ch=*i3;
12272 ch.configured=true;
12273 ch.is_template=false;
12274 channels.push_back(ch);
12275 }
12276 }
12277 l1:
12278 for(i3=r_channel_templates.begin(); i3!=r_channel_templates.end(); i3++) {
12279 if(!(*i3).username.compare((*i).name))
12280 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12281 if(!logic_cmp_strings_case_insensitive((*i4),(*i3).channel_name)) {
12282 all_channels.erase(i4);
12283 goto l1;
12284 }
12285 }
12286 vector<string>::iterator i1;
12287 for(i4=all_channels.begin(); i4!=all_channels.end(); i4++)
12288 for(i1=(*i).access_to_channel.begin(); i1!=(*i).access_to_channel.end(); i1++)
12289 if(!(*i4).compare(*i1)) {
12290 s_channel ch;
12291 ch.is_template=true;
12292 ch.configured=false;
12293 ch.can_send_unknown_users=false;
12294 ch.username=user_name;
12295 ch.channel_name=*i4;
12296 ch.host_unknown=false;
12297 ch.groups.clear();
12298 ch.on_deop="";
12299 ch.on_ban="";
12300 ch.on_unban="";
12301 ch.on_kick="";
12302 ch.on_op="";
12303 ch.on_voice="";
12304 ch.on_devoice="";
12305 ch.on_creator="";
12306 ch.on_decreator="";
12307 ch.on_join="";
12308 ch.on_banned="";
12309 ch.on_flood="";
12310 ch.on_privmsg="";
12311 ch.on_notice="";
12312 ch.on_other_mode="";
12313 ch.msg_flood.lines=0;
12314 ch.msg_flood.seconds=0;
12315 ch.notice_flood.lines=0;
12316 ch.notice_flood.seconds=0;
12317 ch.repeat_flood.lines=0;
12318 ch.repeat_flood.seconds=0;
12319 ch.nick_flood.lines=0;
12320 ch.nick_flood.seconds=0;
12321 ch.join_flood.lines=0;
12322 ch.join_flood.seconds=0;
12323 ch.mode_flood.lines=0;
12324 ch.mode_flood.seconds=0;
12325 ch.ctcp_flood.lines=0;
12326 ch.ctcp_flood.seconds=0;
12327 channels.push_back(ch);
12328 }
12329 }
12330 }
12331 }
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345 void logic_parse_proc(const char* &error_reason, int& error_line, list<string> commands, bool copy_to_r_procedures, string declaration, vector<string> groups)
12346 {
12347 error_line=0;
12348 error_reason=NULL;
12349
12350 bool b_user2=false;
12351 s_user user;
12352 bool b_channel=false;
12353 s_channel channel;
12354 bool b_user=false;
12355 int i_brackets=0;
12356 bool b_proc=false;
12357 s_procedure procedure;
12358 list<s_lines> lines;
12359 bool b_smtp=false;
12360 s_smtp smtp;
12361 bool b_smtp_data=false;
12362 bool b_chan=false;
12363 bool b_groups=false;
12364 bool b_prv=false;
12365
12366 s_channel_def chan;
12367
12368 vector<s_procedure> procedures;
12369 vector<s_user> users;
12370 vector<s_channel> channels;
12371 vector<s_channel_def> channel_defs;
12372 vector<s_user> terminators;
12373
12374 vector<s_group> all_groups;
12375
12376 s_private prv;
12377
12378 bool error=false;
12379
12380 error=logic_process_line((string)"procedure "+declaration,error_reason,error_line,b_user2,user,b_channel,channel,b_user,i_brackets,b_proc,procedure,lines,b_smtp,smtp,b_smtp_data,procedures,users,channels,chan,channel_defs,b_chan,all_groups,b_groups,b_prv,prv,terminators);
12381 error=logic_process_line("{",error_reason,error_line,b_user2,user,b_channel,channel,b_user,i_brackets,b_proc,procedure,lines,b_smtp,smtp,b_smtp_data,procedures,users,channels,chan,channel_defs,b_chan,all_groups,b_groups,b_prv,prv,terminators);
12382
12383 int i3=1;
12384
12385 list<string>::iterator i1;
12386 for(i1=commands.begin(); i1!=commands.end(); i1++, i3++) {
12387 string s=*i1;
12388 size_t i2;
12389 for(i2=s.length()-1; (signed)i2>=0; i2--)
12390 if(s[i2]==0x20 || s[i2]=='\t')
12391 s=s.erase(i2,1);
12392 else
12393 break;
12394 while(s.length()>0 && (s[0]==0x20 || s[0]=='\t'))
12395 s=s.erase(0,1);
12396 error=logic_process_line(s,error_reason,error_line,b_user2,user,b_channel,channel,b_user,i_brackets,b_proc,procedure,lines,b_smtp,smtp,b_smtp_data,procedures,users,channels,chan,channel_defs,b_chan,all_groups,b_groups,b_prv,prv,terminators);
12397 if(error) {
12398 error_line=i3;
12399 return;
12400 }
12401 }
12402 error_line=0;
12403
12404 if(i_brackets!=1) {
12405 error_line=i3;
12406 error_reason="Mistake in brackets { }";
12407 }
12408
12409 if(error_line==0 && copy_to_r_procedures) {
12410 s_command c;
12411 c.command=_end_bracket;
12412 procedure.commands.push_back(c);
12413
12414 bool got=false;
12415 vector<s_procedure>::iterator i1;
12416 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
12417 if(!(*i1).name.compare(declaration)) {
12418 got=true;
12419 (*i1).groups.clear();
12420 vector<string>::iterator i2;
12421 for(i2=groups.begin(); i2!=groups.end(); i2++) {
12422 s_group g;
12423 g.name=*i2;
12424 (*i1).groups.push_back(g);
12425 }
12426 (*i1).commands=procedure.commands;
12427 (*i1).last_changed=procedure.last_changed;
12428 break;
12429 }
12430 }
12431 if(!got) {
12432 procedure.groups.clear();
12433 vector<string>::iterator i2;
12434 for(i2=groups.begin(); i2!=groups.end(); i2++) {
12435 s_group g;
12436 g.name=*i2;
12437 procedure.groups.push_back(g);
12438 }
12439 r_procedures.push_back(procedure);
12440 }
12441 }
12442 }
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455 void logic_validate_kick(string channel, string source_user, string target_user, string source_nick, string target_nick)
12456 {
12457 if(!source_nick.compare(irc_nick) && target_nick.compare(irc_nick))
12458 return;
12459
12460 vector<s_user>::iterator host_bot;
12461 bool b_host_bot=false;
12462
12463 bool got_user=false;
12464
12465 map<string,string> vars;
12466
12467 vector<s_channel>::iterator i1;
12468
12469 {
12470 for(host_bot=r_users.begin(); host_bot!=r_users.end(); host_bot++) {
12471 if((*host_bot).host_bot && !(*host_bot).name.compare(target_user)) {
12472 b_host_bot=true;
12473 goto l1;
12474 }
12475 }
12476 }
12477
12478 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12479 if(!(*i1).username.compare(target_user) && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
12480 string proc=(*i1).on_kick;
12481 if(!proc.compare(""))
12482 continue;
12483
12484 list<string> params;
12485 params.push_back(channel);
12486 params.push_back(source_user);
12487 params.push_back(target_user);
12488 params.push_back(source_nick);
12489 params.push_back(target_nick);
12490
12491 map<string,string> vars;
12492 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12493 case LOGIC_SOCKET_ERROR:
12494 case LOGIC_RESTART:
12495 return;
12496 default:
12497 break;
12498 }
12499 got_user=true;
12500 break;
12501 }
12502 }
12503
12504 if(!got_user) {
12505
12506 l1:
12507 vector<s_user>::iterator i;
12508 if(b_host_bot)
12509 i=host_bot;
12510 else {
12511 for(i=r_users.begin(); i!=r_users.end(); i++) {
12512 if((*i).host_unknown) {
12513 got_user=true;
12514 break;
12515 }
12516 }
12517 if(!got_user)
12518 return;
12519 }
12520
12521 vector<s_channel>::iterator i1;
12522 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12523 if(cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel))
12524 continue;
12525 vector<string>::iterator is, ii;
12526 if(!(*i1).username.compare((*i).name)) {
12527 string proc=(*i1).on_kick;
12528 if(!proc.compare(""))
12529 continue;
12530
12531 list<string> params;
12532 params.push_back(channel);
12533 params.push_back(source_user);
12534 params.push_back(target_user);
12535 params.push_back(source_nick);
12536 params.push_back(target_nick);
12537
12538 map<string,string> vars;
12539 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12540 case LOGIC_SOCKET_ERROR:
12541 case LOGIC_RESTART:
12542 return;
12543 default:
12544 break;
12545 }
12546 break;
12547 }
12548 }
12549 }
12550 }
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567 void logic_get_flood_limits(string channel, string user, s_flood& msg_flood, s_flood& notice_flood, s_flood& repeat_flood, s_flood& nick_flood, s_flood& join_flood, s_flood& mode_flood, s_flood& ctcp_flood)
12568 {
12569 msg_flood.lines=0;
12570 notice_flood.lines=0;
12571 repeat_flood.lines=0;
12572 nick_flood.lines=0;
12573 join_flood.lines=0;
12574 mode_flood.lines=0;
12575 ctcp_flood.lines=0;
12576
12577 map<string,string> vars;
12578
12579 vector<s_channel>::iterator i1;
12580 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12581 if(!user.compare((string)"") && !logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel) && (*i1).host_unknown) {
12582 msg_flood=(*i1).msg_flood;
12583 notice_flood=(*i1).notice_flood;
12584 repeat_flood=(*i1).repeat_flood;
12585 nick_flood=(*i1).nick_flood;
12586 join_flood=(*i1).join_flood;
12587 mode_flood=(*i1).mode_flood;
12588 ctcp_flood=(*i1).ctcp_flood;
12589 return;
12590 }
12591 if(!logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel) && !(*i1).username.compare(user)) {
12592 msg_flood=(*i1).msg_flood;
12593 notice_flood=(*i1).notice_flood;
12594 repeat_flood=(*i1).repeat_flood;
12595 nick_flood=(*i1).nick_flood;
12596 join_flood=(*i1).join_flood;
12597 mode_flood=(*i1).mode_flood;
12598 ctcp_flood=(*i1).ctcp_flood;
12599 return;
12600 }
12601 }
12602
12603
12604 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12605 if(!logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel) && (*i1).host_unknown) {
12606 msg_flood=(*i1).msg_flood;
12607 notice_flood=(*i1).notice_flood;
12608 repeat_flood=(*i1).repeat_flood;
12609 nick_flood=(*i1).nick_flood;
12610 join_flood=(*i1).join_flood;
12611 mode_flood=(*i1).mode_flood;
12612 ctcp_flood=(*i1).ctcp_flood;
12613 return;
12614 }
12615 }
12616 }
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631 void logic_on_flood(string channel, string user, string nick, int type, int stat_num, time_t stat_sec, time_t stat_sec_of)
12632 {
12633 bool got_user=false;
12634
12635 map<string,string> vars;
12636
12637 vector<s_channel>::iterator i1;
12638
12639 if(!user.compare((string)""))
12640 goto unknown;
12641
12642 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12643 if(!(*i1).username.compare(user) && !logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
12644 got_user=true;
12645
12646 string proc=(*i1).on_flood;
12647 if(!proc.compare(""))
12648 break;
12649
12650 list<string> params;
12651 params.push_back(channel);
12652 params.push_back(user);
12653 params.push_back(nick);
12654 switch(type) {
12655 case TYPE_PRIVMSG:
12656 params.push_back("message");
12657 break;
12658 case TYPE_NOTICE:
12659 params.push_back("notice");
12660 break;
12661 case TYPE_NICK:
12662 params.push_back("nick");
12663 break;
12664 case TYPE_MODE:
12665 params.push_back("mode");
12666 break;
12667 case TYPE_JOIN:
12668 params.push_back("join");
12669 break;
12670 case TYPE_REPEAT:
12671 params.push_back("repeat");
12672 break;
12673 case TYPE_CTCP:
12674 params.push_back("ctcp");
12675 break;
12676 default:
12677 params.push_back("other");
12678 break;
12679 }
12680
12681 char tmp[64];
12682 params.push_back(ltoa(stat_num,tmp,10));
12683 params.push_back(ltoa((long)stat_sec,tmp,10));
12684 params.push_back(ltoa((long)stat_sec_of,tmp,10));
12685
12686 map<string,string> vars;
12687 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12688 case LOGIC_SOCKET_ERROR:
12689 case LOGIC_RESTART:
12690 return;
12691 default:
12692 break;
12693 }
12694 break;
12695 }
12696 }
12697
12698 if(!got_user) {
12699
12700 unknown:
12701 vector<s_channel>::iterator i1;
12702 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
12703 if((*i1).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
12704 map<string,string> vars;
12705 string proc=(*i1).on_flood;
12706 if(!proc.compare(""))
12707 break;
12708
12709 list<string> params;
12710 params.push_back(channel);
12711 params.push_back(user);
12712 params.push_back(nick);
12713 switch(type) {
12714 case TYPE_PRIVMSG:
12715 params.push_back("message");
12716 break;
12717 case TYPE_NOTICE:
12718 params.push_back("notice");
12719 break;
12720 case TYPE_NICK:
12721 params.push_back("nick");
12722 break;
12723 case TYPE_MODE:
12724 params.push_back("mode");
12725 break;
12726 case TYPE_JOIN:
12727 params.push_back("join");
12728 break;
12729 case TYPE_REPEAT:
12730 params.push_back("repeat");
12731 break;
12732 case TYPE_CTCP:
12733 params.push_back("ctcp");
12734 break;
12735 default:
12736 params.push_back("other");
12737 break;
12738 }
12739
12740 char tmp[64];
12741 params.push_back(ltoa(stat_num,tmp,10));
12742 params.push_back(ltoa((long)stat_sec,tmp,10));
12743 params.push_back(ltoa((long)stat_sec_of,tmp,10));
12744
12745 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12746 case LOGIC_SOCKET_ERROR:
12747 case LOGIC_RESTART:
12748 return;
12749 default:
12750 break;
12751 }
12752 break;
12753 }
12754 }
12755 }
12756 }
12757
12758
12759
12760
12761
12762
12763
12764 struct s_nick_to_lag {
12765 string nick;
12766 int cnt;
12767 time_t last_try;
12768
12769 s_nick_to_lag() {
12770 nick="";
12771 cnt=0;
12772 last_try=0;
12773 }
12774 };
12775
12776 vector<s_nick_to_lag> nicks_to_lag;
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788 void logic_ctcp(string user, string nick, string channel, string msg)
12789 {
12790 if(msg.find("DCC ")!=0 && msg.find("ACTION")!=0) {
12791
12792 vector<s_nick_to_lag>::iterator i1;
12793 again:
12794 for(i1=nicks_to_lag.begin(); i1!=nicks_to_lag.end(); i1++) {
12795 if((*i1).last_try+atol(conf_getvar("ctcp_lag_user_seconds").c_str())<time(NULL)) {
12796 nicks_to_lag.erase(i1);
12797 goto again;
12798 }
12799 }
12800 bool got=false;
12801 for(i1=nicks_to_lag.begin(); i1!=nicks_to_lag.end(); i1++) {
12802 if(!(*i1).nick.compare(nick)) {
12803 (*i1).cnt++;
12804 (*i1).last_try=time(NULL);
12805 got=true;
12806 break;
12807 }
12808 }
12809 if(got) {
12810 if((*i1).cnt>atol(conf_getvar("ctcp_lag_user_msgs").c_str())) {
12811 time_t x=(*i1).last_try;
12812 time_t now=time(NULL);
12813 while((signed)x>0 && (*i1).cnt>0 && (signed)now-(signed)x>atol(conf_getvar("ctcp_lag_user_seconds").c_str())) {
12814 x-=atol(conf_getvar("ctcp_lag_user_seconds").c_str());
12815 (*i1).cnt--;
12816 }
12817 if((*i1).cnt>atol(conf_getvar("ctcp_lag_user_msgs").c_str())) {
12818 return;
12819 }
12820 if((*i1).cnt==0) {
12821 (*i1).cnt=1;
12822 }
12823 }
12824 } else {
12825 s_nick_to_lag u;
12826 u.cnt=1;
12827 u.last_try=time(NULL);
12828 u.nick=nick;
12829 nicks_to_lag.push_back(u);
12830 }
12831 }
12832
12833 if(msg.find("PING ")==0) {
12834 if(msg.length()>16) {
12835
12836 } else {
12837 string orig=msg;
12838 string m="PING ";
12839 msg.erase(0,m.length());
12840 m="NOTICE ";
12841 m+=nick;
12842 m+=" :\x01";
12843 m+="PING ";
12844 m+=msg;
12845 m+="\x01";
12846 irc_putserv(m.c_str(),false,LOW_PRIORITY);
12847 msg=orig;
12848 }
12849 }
12850 if(msg.find("TIME")==0) {
12851 string m;
12852 m="NOTICE ";
12853 m+=nick;
12854 m+=" :\x01";
12855 m+="TIME ";
12856 time_t now=time(NULL);
12857 m+=ctime(&now);
12858 if(m.find('\n',0)!=string::npos)
12859 m.erase(m.find('\n',0),1);
12860 m+="\x01";
12861 irc_putserv(m.c_str(),false,LOW_PRIORITY);
12862 }
12863
12864 string command;
12865 {
12866 while(msg.length()) {
12867 if(msg[0]!=0x20) {
12868 command+=msg[0];
12869 msg.erase(0,1);
12870 } else {
12871 msg.erase(0,1);
12872 break;
12873 }
12874 }
12875
12876 map<string,string> vars;
12877 string proc=r_private.on_ctcp;
12878 if(!proc.compare(""))
12879 return;
12880
12881 list<string> params;
12882 params.push_back(user);
12883 params.push_back(nick);
12884 params.push_back(channel);
12885 params.push_back(command);
12886 params.push_back(msg);
12887
12888 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12889 case LOGIC_SOCKET_ERROR:
12890 case LOGIC_RESTART:
12891 return;
12892 default:
12893 break;
12894 }
12895 }
12896
12897 vector<s_channel_def>::iterator i1;
12898 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
12899 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
12900 map<string,string> vars;
12901
12902 string proc=(*i1).on_ctcp;
12903 if(proc.empty())
12904 break;
12905
12906 list<string> params;
12907 params.push_back(user);
12908 params.push_back(nick);
12909 params.push_back(channel);
12910 params.push_back(command);
12911 params.push_back(msg);
12912
12913 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12914 case LOGIC_SOCKET_ERROR:
12915 case LOGIC_RESTART:
12916 return;
12917 default:
12918 break;
12919 }
12920 break;
12921 }
12922 }
12923 }
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936 void logic_filesys_got_new(string user_name, string nick, string ident, string host, string internal_name)
12937 {
12938 string proc=r_private.on_filesys_got_new;
12939 if(!proc.compare(""))
12940 return;
12941
12942 map<string,string> vars;
12943
12944 list<string> params;
12945 params.push_back(user_name);
12946 params.push_back(nick);
12947 params.push_back(ident);
12948 params.push_back(host);
12949 params.push_back(internal_name);
12950
12951 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12952 case LOGIC_SOCKET_ERROR:
12953 case LOGIC_RESTART:
12954 return;
12955 default:
12956 break;
12957 }
12958 }
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968 void logic_fnc(string old_nick, string new_nick)
12969 {
12970 string proc=r_private.on_fnc;
12971 if(!proc.compare(""))
12972 return;
12973
12974 map<string,string> vars;
12975
12976 list<string> params;
12977 params.push_back(old_nick);
12978 params.push_back(new_nick);
12979
12980 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
12981 case LOGIC_SOCKET_ERROR:
12982 case LOGIC_RESTART:
12983 return;
12984 default:
12985 break;
12986 }
12987 }
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999 void logic_on_privmsg(string channel, string user, string nick, string msg)
13000 {
13001 bool got_user=false;
13002
13003 map<string,string> vars;
13004
13005 vector<s_channel>::iterator i1;
13006
13007 if(!user.compare((string)""))
13008 goto unknown;
13009
13010 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
13011 if(!(*i1).username.compare(user) && !logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
13012 got_user=true;
13013 {
13014 map<string,string> vars;
13015 string proc=(*i1).on_privmsg;
13016 if(!proc.compare(""))
13017 break;
13018
13019 list<string> params;
13020 params.push_back(channel);
13021 params.push_back(user);
13022 params.push_back(nick);
13023 params.push_back(msg);
13024
13025 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13026 case LOGIC_SOCKET_ERROR:
13027 case LOGIC_RESTART:
13028 return;
13029 default:
13030 break;
13031 }
13032 break;
13033 }
13034 }
13035 }
13036
13037 if(!got_user) {
13038
13039 unknown:
13040 vector<s_channel>::iterator i1;
13041 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
13042 if((*i1).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
13043 {
13044 map<string,string> vars;
13045 string proc=(*i1).on_privmsg;
13046 if(!proc.compare(""))
13047 break;
13048
13049 list<string> params;
13050 params.push_back(channel);
13051 params.push_back(user);
13052 params.push_back(nick);
13053 params.push_back(msg);
13054
13055 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13056 case LOGIC_SOCKET_ERROR:
13057 case LOGIC_RESTART:
13058 return;
13059 default:
13060 break;
13061 }
13062 break;
13063 }
13064 }
13065 }
13066 }
13067
13068 vector<s_channel_def>::iterator i2;
13069 for(i2=r_channel_defs.begin(); i2!=r_channel_defs.end(); i2++)
13070 if(!cmp_strings_case_insensitive(channel,(*i2).channel_name)) {
13071 map<string,string> vars;
13072 string proc=(*i2).on_privmsg;
13073 if(!proc.compare(""))
13074 break;
13075 list<string> params;
13076 params.push_back(channel);
13077 params.push_back(user);
13078 params.push_back(nick);
13079 params.push_back(msg);
13080
13081 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13082 case LOGIC_SOCKET_ERROR:
13083 case LOGIC_RESTART:
13084 return;
13085 default:
13086 break;
13087 }
13088 break;
13089 }
13090 if(msg.find("\001",0)!=string::npos) {
13091 if(msg.find("\x01",0)!=string::npos) {
13092 msg.erase(msg.find("\x01",0),1);
13093 if(msg.find("\x01",0)!=string::npos)
13094 msg.erase(msg.find("\x01",0),1);
13095 }
13096 logic_ctcp(user,nick,channel,msg);
13097 }
13098 }
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110 void logic_on_notice(string channel, string user, string nick, string msg)
13111 {
13112 bool got_user=false;
13113
13114 map<string,string> vars;
13115
13116 vector<s_channel>::iterator i1;
13117
13118 if(!user.compare((string)""))
13119 goto unknown;
13120
13121 if(!channel.empty()) {
13122 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
13123 if(!(*i1).username.compare(user) && !logic_cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
13124 got_user=true;
13125 {
13126 map<string,string> vars;
13127 string proc=(*i1).on_notice;
13128 if(!proc.compare(""))
13129 break;
13130
13131 list<string> params;
13132 params.push_back(channel);
13133 params.push_back(user);
13134 params.push_back(nick);
13135 params.push_back(msg);
13136
13137 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13138 case LOGIC_SOCKET_ERROR:
13139 case LOGIC_RESTART:
13140 return;
13141 default:
13142 break;
13143 }
13144 break;
13145 }
13146 }
13147 }
13148
13149 if(!got_user) {
13150
13151 unknown:
13152
13153 {
13154 vector<s_user>::iterator i1;
13155 for(i1=r_users.begin(); i1!=r_users.end(); i1++)
13156 if((*i1).host_unknown) {
13157 user=(*i1).name;
13158 break;
13159 }
13160 }
13161
13162 vector<s_channel>::iterator i1;
13163 for(i1=r_channels.begin(); i1!=r_channels.end(); i1++) {
13164 if((*i1).host_unknown && !cmp_strings_case_insensitive(logic_eval((*i1).channel_name,vars),channel)) {
13165 {
13166 map<string,string> vars;
13167 string proc=(*i1).on_notice;
13168 if(!proc.compare(""))
13169 break;
13170
13171 list<string> params;
13172 params.push_back(channel);
13173 params.push_back(user);
13174 params.push_back(nick);
13175 params.push_back(msg);
13176
13177 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13178 case LOGIC_SOCKET_ERROR:
13179 case LOGIC_RESTART:
13180 return;
13181 default:
13182 break;
13183 }
13184 break;
13185 }
13186 }
13187 }
13188
13189 vector<s_channel_def>::iterator i2;
13190 for(i2=r_channel_defs.begin(); i2!=r_channel_defs.end(); i2++)
13191 if(!cmp_strings_case_insensitive(channel,(*i2).channel_name)) {
13192 map<string,string> vars;
13193 string proc=(*i2).on_notice;
13194 if(!proc.compare(""))
13195 break;
13196 list<string> params;
13197 params.push_back(channel);
13198 params.push_back(user);
13199 params.push_back(nick);
13200 params.push_back(msg);
13201
13202 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13203 case LOGIC_SOCKET_ERROR:
13204 case LOGIC_RESTART:
13205 return;
13206 default:
13207 break;
13208 }
13209 break;
13210 }
13211 }
13212 if(channel.empty())
13213 goto private_query;
13214 } else {
13215 private_query:
13216 map<string,string> vars;
13217 string proc=r_private.on_notice;
13218 if(!proc.compare(""))
13219 return;
13220
13221 list<string> params;
13222 params.push_back(user);
13223 params.push_back(nick);
13224 params.push_back(msg);
13225
13226 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13227 case LOGIC_SOCKET_ERROR:
13228 case LOGIC_RESTART:
13229 return;
13230 default:
13231 break;
13232 }
13233 }
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249 }
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260 void logic_on_privmsg_query(string user, string nick, string msg)
13261 {
13262 bool quoted=false;
13263
13264 if(msg.find("\x01",0)!=string::npos)
13265 quoted=true;
13266
13267
13268
13269 map<string,string> vars;
13270
13271 vector<s_channel>::iterator i1;
13272
13273 if(user.empty()) {
13274 vector<s_user>::iterator i1;
13275 for(i1=r_users.begin(); i1!=r_users.end(); i1++)
13276 if((*i1).host_unknown) {
13277 user=(*i1).name;
13278 break;
13279 }
13280
13281
13282 if(user.empty())
13283 return;
13284 }
13285
13286 {
13287 map<string,string> vars;
13288 string proc=r_private.on_privmsg;
13289 if(!proc.compare(""))
13290 return;
13291
13292 list<string> params;
13293 params.push_back(user);
13294 params.push_back(nick);
13295 params.push_back(msg);
13296
13297 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13298 case LOGIC_SOCKET_ERROR:
13299 case LOGIC_RESTART:
13300 return;
13301 default:
13302 break;
13303 }
13304 }
13305
13306 if(quoted) {
13307 if(msg.find("\x01",0)!=string::npos) {
13308 msg.erase(msg.find("\x01",0),1);
13309 if(msg.find("\x01",0)!=string::npos)
13310 msg.erase(msg.find("\x01",0),1);
13311 }
13312 logic_ctcp(user,nick,"",msg);
13313 }
13314 }
13315
13316
13317
13318
13319
13320
13321 bool logic_access_to_partyline(string user_name_as_in_logic)
13322 {
13323 map<string,string> vars;
13324
13325 vector<s_user>::iterator i;
13326 for(i=r_users.begin(); i!=r_users.end(); i++) {
13327 vector<string>::iterator is, ii;
13328 if(!(*i).host_unknown && !(*i).name.compare(user_name_as_in_logic)) {
13329 return (*i).access_to_partyline;
13330 }
13331 }
13332
13333
13334 for(i=r_users.begin(); i!=r_users.end(); i++) {
13335 vector<string>::iterator is, ii;
13336 if((*i).host_unknown) {
13337 return (*i).access_to_partyline;
13338 }
13339 }
13340
13341 return false;
13342 }
13343
13344
13345
13346
13347
13348
13349 bool logic_is_replication_partner(string user_name_as_in_logic)
13350 {
13351 map<string,string> vars;
13352
13353 vector<s_user>::iterator i;
13354 for(i=r_users.begin(); i!=r_users.end(); i++) {
13355 vector<string>::iterator is, ii;
13356 if(!(*i).host_unknown && !(*i).name.compare(user_name_as_in_logic)) {
13357 return (*i).replication_partner;
13358 }
13359 }
13360
13361
13362 for(i=r_users.begin(); i!=r_users.end(); i++) {
13363 vector<string>::iterator is, ii;
13364 if((*i).host_unknown) {
13365 return (*i).replication_partner;
13366 }
13367 }
13368
13369 return false;
13370 }
13371
13372
13373
13374
13375
13376
13377
13378 string logic_find_proc_by_name(string name)
13379 {
13380 vector<s_procedure>::iterator i1;
13381 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
13382 string s=(*i1).name;
13383 unsigned int i2;
13384 for(i2=0; i2<s.length(); i2++)
13385 if(s[i2]=='(')
13386 break;
13387 s.erase(i2,s.length()-i2);
13388 if(!s.compare(name))
13389 return (*i1).name;
13390 }
13391 return "";
13392 }
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403 bool logic_botnet_get_user(string name, s_user& user)
13404 {
13405 vector<s_user>::iterator i1;
13406 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
13407 if(!(*i1).name.compare(name)) {
13408 user=*i1;
13409 return true;
13410 }
13411 }
13412 for(i1=r_user_templates.begin(); i1!=r_user_templates.end(); i1++) {
13413 if(!(*i1).name.compare(name)) {
13414 user=*i1;
13415 return true;
13416 }
13417 }
13418 for(i1=r_terminators.begin(); i1!=r_terminators.end(); i1++) {
13419 if(!(*i1).name.compare(name)) {
13420 user=*i1;
13421 return true;
13422 }
13423 }
13424 return false;
13425 }
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436 bool logic_botnet_get_channel_def(string channel_name, s_channel_def& chd)
13437 {
13438 vector<s_channel_def>::iterator i1;
13439 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
13440 if(!(*i1).channel_name.compare(channel_name)) {
13441 chd=*i1;
13442 return true;
13443 }
13444 }
13445 return false;
13446 }
13447
13448
13449
13450
13451
13452
13453
13454
13455 void logic_botnet_remove_channel_def(string channel_name)
13456 {
13457 vector<s_channel_def>::iterator i1;
13458 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
13459 if(!(*i1).channel_name.compare(channel_name)) {
13460 r_channel_defs.erase(i1);
13461 break;
13462 }
13463 }
13464 }
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475 bool logic_botnet_get_proc(string name, s_procedure& proc)
13476 {
13477 vector<s_procedure>::iterator i1;
13478 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
13479 if(!(*i1).name.compare(name)) {
13480 proc=*i1;
13481 return true;
13482 }
13483 }
13484 return false;
13485 }
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496 bool logic_botnet_get_user_channels(string name, vector<s_channel>& channels)
13497 {
13498 channels.clear();
13499
13500 vector<s_user>::iterator i1;
13501 for(i1=r_users.begin(); i1!=r_users.end(); i1++) {
13502 if(!(*i1).name.compare(name)) {
13503 vector<s_channel>::iterator i2;
13504 for(i2=r_channels.begin(); i2!=r_channels.end(); i2++) {
13505 if(!(*i2).username.compare((*i1).name))
13506 channels.push_back(*i2);
13507 }
13508 return true;
13509 }
13510 }
13511 return false;
13512 }
13513
13514
13515
13516
13517
13518
13519
13520 void logic_botnet_backup(string who)
13521 {
13522 who+=" (BOTNET)";
13523 logic_partyline_backup(who);
13524 }
13525
13526
13527
13528
13529
13530
13531
13532
13533 void logic_botnet_remove_user(string username)
13534 {
13535 logic_partyline_remove_user(username);
13536 }
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553 bool logic_rehash(int& error_on_line, const char* &error_reason, string who, string who_only_name_of_user)
13554 {
13555 log_bot("Trying to rehash...");
13556 error_on_line=1;
13557 error_reason=NULL;
13558 logic_on_internal_event("@rehash@",who_only_name_of_user,"","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,"Trying to rehash...","");
13559 bool res=logic_load_conf("logic.txt",error_on_line,error_reason);
13560 char tmp[128];
13561 if(res)
13562 logic_on_internal_event("@rehash_done@",who_only_name_of_user,"ERROR",ltoa((long)error_on_line,tmp,10),"",PRIVATE_EVENT_SEVERITY_CODE_ERROR,error_reason,"");
13563 else
13564 logic_on_internal_event("@rehash_done@",who_only_name_of_user,"OK","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,"Rehashing succeeded.","");
13565 return res;
13566 }
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581 bool logic_rollback(string& log, string lang, string eol)
13582 {
13583 log="";
13584 char tmp1[256];
13585 for(int i1=0; i1<=999; i1++) {
13586 string private_event="";
13587
13588 sprintf(tmp1,"%s%03d","logic.txt.bak",i1);
13589 FILE* test=fopen(tmp1,"r");
13590 if(test) {
13591 fclose(test);
13592 {
13593 #ifdef _WIN32
13594 mkdir("bad_conf");
13595 #else
13596 mkdir("./bad_conf",0700);
13597 #endif
13598 time_t now=time(NULL);
13599 char tmp[128];
13600 strcpy(tmp,ctime(&now));
13601 tmp[strlen(tmp)-1]=0;
13602 for(int i1=0; tmp[i1]!=0; i1++)
13603 if(tmp[i1]==0x20 || tmp[i1]==':' || tmp[i1]=='/')
13604 tmp[i1]='_';
13605 string bad="." FILE_SLASH "bad_conf" FILE_SLASH;
13606 bad+=tmp;
13607 bad+=".";
13608 char tmp2[64];
13609 unsigned int rnd=rand();
13610 sprintf(tmp2,"%u",rnd);
13611 bad+=tmp2;
13612 bad+=".logic.txt";
13613 rename("." FILE_SLASH "logic.txt",bad.c_str());
13614 string log_=lang_get_string(1,lang,543)+(string)" "+bad;
13615 log_=(string)"Bad logic.txt was stored to file: "+bad;
13616
13617 private_event+=log_;
13618
13619 log+=log_+eol;
13620 log_bot(log_.c_str());
13621 unlink("logic.txt");
13622 }
13623 rename(tmp1,"logic.txt");
13624 char tmp2[1024];
13625 sprintf(tmp2,"%s%s",lang_get_string(1,lang,383).c_str(),tmp1);
13626 log+=tmp2;
13627 log+=eol;
13628 sprintf(tmp2,"%s%s","logic.txt rollback from backup file: ",tmp1);
13629 log_bot(tmp2);
13630
13631 private_event+=(string)"; "+tmp2;
13632
13633 {
13634 struct stat s;
13635 stat("logic.txt",&s);
13636
13637 char tch[128];
13638 strcpy(tch,ctime(&s.st_mtime));
13639 if(strlen(tch) && tch[strlen(tch)-1]=='\n')
13640 tch[strlen(tch)-1]=0;
13641
13642 sprintf(tmp2," %s %s",lang_get_string(1,lang,558).c_str(),tch);
13643 log+=tmp2;
13644 log+=eol;
13645 sprintf(tmp2," %s %s","Time of the file:",tch);
13646 log_bot(tmp2);
13647
13648 private_event+=(string)"; "+tmp2;
13649 }
13650 logic_on_internal_event("@rehash_rollback_ok@","","","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,private_event,"");
13651 return true;
13652 }
13653 }
13654 logic_on_internal_event("@rehash_rollback_error@","","","","",PRIVATE_EVENT_SEVERITY_CODE_ERROR,"Don't have any backup files for roll-back.","");
13655 return false;
13656 }
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669 void logic_rehash(string& log, string lang, string eol, string who_string, string who, string who_only_name_of_user)
13670 {
13671 log="";
13672 char tmp2[1024];
13673 for(;;) {
13674 sprintf(tmp2,"%s",lang_get_string(1,lang,378).c_str());
13675 log+=tmp2;
13676 log+=eol;
13677
13678 int error_on_line=0;
13679 const char* error_reason=NULL;
13680 bool error=logic_rehash(error_on_line,error_reason,who_string,who_only_name_of_user);
13681 if(error) {
13682 sprintf(tmp2,"%s%d%s%s",lang_get_string(1,lang,379).c_str(),error_on_line,lang_get_string(1,lang,380).c_str(),error_reason);
13683 log+=tmp2;
13684 log+=eol;
13685 sprintf(tmp2,"%s%d%s%s","Rehashing has failed, trying to perform rollback to previous configuration. Error on line #",error_on_line," error reason: ",error_reason);
13686 log_bot(tmp2);
13687 string log2;
13688 bool okay=logic_rollback(log2,lang,eol);
13689 log+=log2;
13690 if(okay==false) {
13691 strcpy(tmp2,lang_get_string(1,lang,381).c_str());
13692 log+=tmp2;
13693 log+=eol;
13694 strcpy(tmp2,"Fatal error: Rollback operation failed (no more backup files?) I am gonna DIE now!");
13695 log_bot(tmp2);
13696
13697 logic_on_internal_event("@rehash_rollback_error@","","","","",PRIVATE_EVENT_SEVERITY_CODE_FATAL_ERROR,tmp2,"");
13698
13699 extern bool dcc_want_to_restart;
13700 extern bool dcc_want_to_die;
13701 extern string dcc_who_is_killing;
13702
13703 dcc_want_to_die=true;
13704 dcc_who_is_killing=irc_nick;
13705 return;
13706 }
13707 continue;
13708 } else {
13709 strcpy(tmp2,lang_get_string(1,lang,382).c_str());
13710 log+=tmp2;
13711 log+=eol;
13712 strcpy(tmp2,"Rehashing succeeded.");
13713 log_bot(tmp2);
13714 break;
13715 }
13716 }
13717
13718 irc_rehashed();
13719 dcc_rehashed(who);
13720 }
13721
13722
13723
13724
13725
13726
13727
13728
13729 void logic_botnet_rehash(string who)
13730 {
13731 string log;
13732 string eol;
13733 string lang="en";
13734 string who_string=who;
13735 who_string+=" (BOTNET)";
13736 who+=" (BOTNET)";
13737 who_string=(string)"*** Rehash invoked by "+who_string;
13738 log_bot(who_string.c_str());
13739 logic_rehash(log,lang,eol,who_string,who,who);
13740 }
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752 string logic_partyline_rehash(string lang, string eol, string who)
13753 {
13754 string who_string=who;
13755 who_string=(string)"*** Rehash invoked by "+who_string;
13756 log_bot(who_string.c_str());
13757 string log;
13758 logic_rehash(log,lang,eol,who_string,who,who);
13759 return log;
13760 }
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771 void logic_on_ircop(string channel, string nick, bool on)
13772 {
13773 string user_name=logic_find_user(nick,irc_get_ident(nick),irc_get_host(nick),irc_get_fullname(nick),irc_is_ircop(nick));
13774
13775 {
13776 string host_mask=nick;
13777 host_mask+="!";
13778 host_mask+=irc_get_ident(nick);
13779 host_mask+="@";
13780 host_mask+=irc_get_host(nick);
13781 string _on=on==true?"ON":"OFF";
13782 logic_on_internal_event("@ircop@",nick,host_mask,channel,_on,PRIVATE_EVENT_SEVERITY_CODE_WARNING,"",irc_get_fullname(nick));
13783 }
13784
13785 vector<s_channel_def>::iterator i1;
13786 for(i1=r_channel_defs.begin(); i1!=r_channel_defs.end(); i1++) {
13787 if(!cmp_strings_case_insensitive((*i1).channel_name,channel)) {
13788 map<string,string> vars;
13789
13790 string proc=(*i1).on_ircop;
13791 if(proc.empty())
13792 break;
13793
13794 list<string> params;
13795 params.push_back(channel);
13796 params.push_back(user_name);
13797 params.push_back(nick);
13798 params.push_back(on?"1":"0");
13799
13800 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13801 case LOGIC_SOCKET_ERROR:
13802 case LOGIC_RESTART:
13803 return;
13804 default:
13805 break;
13806 }
13807 break;
13808 }
13809 }
13810 }
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822 void logic_on_part(string channel, string nick, string msg, int type)
13823 {
13824 string user=logic_find_user(nick,irc_get_ident(nick),irc_get_host(nick),irc_get_fullname(nick),irc_is_ircop(nick));
13825
13826 vector<s_channel_def>::iterator i2;
13827 for(i2=r_channel_defs.begin(); i2!=r_channel_defs.end(); i2++)
13828 if(!cmp_strings_case_insensitive(channel,(*i2).channel_name)) {
13829 map<string,string> vars;
13830 string proc=(*i2).on_part;
13831 if(!proc.compare(""))
13832 break;
13833 list<string> params;
13834 params.push_back(channel);
13835 params.push_back(user);
13836 params.push_back(nick);
13837 params.push_back(msg);
13838 switch(type) {
13839 case TYPE_PART:
13840 params.push_back("PART");
13841 break;
13842 case TYPE_QUIT:
13843 params.push_back("QUIT");
13844 break;
13845 case TYPE_KICK:
13846 params.push_back("KICK");
13847 break;
13848 default:
13849 params.push_back("");
13850 break;
13851 }
13852
13853 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
13854 case LOGIC_SOCKET_ERROR:
13855 case LOGIC_RESTART:
13856 return;
13857 default:
13858 break;
13859 }
13860 break;
13861 }
13862 }
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872 void logic_execute(string call_string, map<string,string>& vars)
13873 {
13874 string orig_call_string=call_string;
13875
13876 string cs=call_string;
13877 unsigned int i2;
13878 for(i2=0; i2<cs.length(); i2++)
13879 if(cs[i2]=='(')
13880 break;
13881 cs.erase(i2,cs.length()-i2);
13882 vector<s_procedure>::iterator i1;
13883 for(i1=r_procedures.begin(); i1!=r_procedures.end(); i1++) {
13884 string s=(*i1).name;
13885 unsigned int i2;
13886 for(i2=0; i2<s.length(); i2++)
13887 if(s[i2]=='(')
13888 break;
13889 s.erase(i2,s.length()-i2);
13890 if(!s.compare(cs)) {
13891 call_string=(*i1).name;
13892 break;
13893 }
13894 }
13895
13896 cs=orig_call_string;
13897 for(i2=0; i2<cs.length(); i2++)
13898 if(cs[i2]=='(')
13899 break;
13900 cs.erase(0,i2+1);
13901 if(cs.length()>0 && cs[cs.length()-1]==')')
13902 cs.erase(cs.length()-1,1);
13903 cs+=",";
13904
13905 list<string> params;
13906 bool str=false;
13907 string p;
13908 for(i2=0; i2<cs.length() && cs.compare(","); i2++) {
13909 if(cs[i2]=='\"') {
13910 p+="\"";
13911
13912 str=!str;
13913 continue;
13914 }
13915 if(!str && cs[i2]==',') {
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925 p=logic_eval(p,vars);
13926 params.push_back(p);
13927 p="";
13928 continue;
13929 }
13930 if(!str && cs[i2]==')') {
13931 if(p.compare("")) {
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941 p=logic_eval(p,vars);
13942 params.push_back(p);
13943 }
13944 break;
13945 }
13946 p+=cs[i2];
13947 }
13948
13949 logic_call_proc_ex2(call_string.c_str(),vars,params);
13950 }
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967 void logic_on_broadcast(string username, string nick, string ident, string host,
13968 string bcast_mask, int type, string msg,
13969 string server, unsigned short port)
13970 {
13971
13972
13973 if(username.empty()) {
13974 vector<s_user>::iterator i1;
13975 for(i1=r_users.begin(); i1!=r_users.end(); i1++)
13976 if((*i1).host_unknown) {
13977 username=(*i1).name;
13978 break;
13979 }
13980 }
13981
13982 map<string,string> vars;
13983 string proc=r_private.on_broadcast;
13984 if(!proc.compare(""))
13985 return;
13986
13987 list<string> params;
13988 params.push_back(username);
13989 params.push_back(nick);
13990 params.push_back(ident);
13991 params.push_back(host);
13992 params.push_back(bcast_mask);
13993 switch(type) {
13994 case TYPE_PRIVMSG:
13995 params.push_back("PRIVMSG");
13996 break;
13997 case TYPE_NOTICE:
13998 params.push_back("NOTICE");
13999 break;
14000 default:
14001
14002 params.push_back("?");
14003 break;
14004 }
14005 params.push_back(msg);
14006 params.push_back(server);
14007 char tmp[512];
14008 sprintf(tmp,"%u",(unsigned)port);
14009 params.push_back(tmp);
14010
14011 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
14012 case LOGIC_SOCKET_ERROR:
14013 case LOGIC_RESTART:
14014 return;
14015 default:
14016 break;
14017 }
14018
14019
14020 if(type==TYPE_PRIVMSG && msg.find("\001",0)!=string::npos) {
14021 if(msg.find("\x01",0)!=string::npos) {
14022 msg.erase(msg.find("\x01",0),1);
14023 if(msg.find("\x01",0)!=string::npos)
14024 msg.erase(msg.find("\x01",0),1);
14025 }
14026 logic_ctcp(username,nick,"",msg);
14027 }
14028 }
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042 void logic_on_server_msg(string channel, string source, int type, string msg, string server, unsigned short port)
14043 {
14044
14045
14046 string proc;
14047 if(channel.empty())
14048 proc=r_private.on_server_msg;
14049 else {
14050 vector<s_channel_def>::iterator i2;
14051 for(i2=r_channel_defs.begin(); i2!=r_channel_defs.end(); i2++)
14052 if(!cmp_strings_case_insensitive(channel,(*i2).channel_name)) {
14053 proc=(*i2).on_server_msg;
14054 break;
14055 }
14056 }
14057
14058 if(!proc.compare(""))
14059 return;
14060
14061 map<string,string> vars;
14062
14063 list<string> params;
14064 if(!channel.empty())
14065 params.push_back(channel);
14066 else
14067 params.push_back("");
14068 params.push_back(source);
14069 switch(type) {
14070 case TYPE_PRIVMSG:
14071 params.push_back("PRIVMSG");
14072 break;
14073 case TYPE_NOTICE:
14074 params.push_back("NOTICE");
14075 break;
14076 default:
14077
14078 params.push_back("?");
14079 break;
14080 }
14081 params.push_back(msg);
14082 params.push_back(server);
14083 char tmp[512];
14084 sprintf(tmp,"%u",(unsigned)port);
14085 params.push_back(tmp);
14086
14087 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
14088 case LOGIC_SOCKET_ERROR:
14089 case LOGIC_RESTART:
14090 return;
14091 default:
14092 break;
14093 }
14094 }
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104 string logic_kill_EOLs(string str)
14105 {
14106 string res;
14107 for(unsigned i1=0; i1<str.length(); i1++) {
14108 switch(str[i1]) {
14109 case '\r':
14110 res+="\\r";
14111 break;
14112 case '\n':
14113 res+="\\n";
14114 break;
14115 default:
14116 res+=(string)""+str[i1];
14117 break;
14118 }
14119 }
14120 return res;
14121 }
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137 void logic_on_internal_event(string type, string flags1, string flags2, string flags3, string flags4, int severity_numeric, string msg1, string msg2)
14138 {
14139 string proc=r_private.on_internal_event;
14140
14141 if(proc.empty())
14142 return;
14143
14144 static bool in_event=false;
14145 if(in_event)
14146 return;
14147 in_event=true;
14148
14149 type=logic_kill_EOLs(type);
14150 flags1=logic_kill_EOLs(flags1);
14151 flags2=logic_kill_EOLs(flags2);
14152 flags3=logic_kill_EOLs(flags3);
14153 flags4=logic_kill_EOLs(flags4);
14154 msg1=logic_kill_EOLs(msg1);
14155 msg2=logic_kill_EOLs(msg2);
14156
14157 map<string,string> vars;
14158
14159 list<string> params;
14160 params.push_back(type);
14161
14162 time_t now=time(NULL);
14163 char tmp[512];
14164 string time_string=ctime(&now);
14165 if(time_string.find("\n",0)!=string::npos)
14166 time_string.erase(time_string.find("\n",0),1);
14167
14168 params.push_back(ltoa((long)now,tmp,10));
14169 params.push_back(time_string);
14170 params.push_back(flags1);
14171 params.push_back(flags2);
14172 params.push_back(flags3);
14173 params.push_back(flags4);
14174 params.push_back(ltoa((long)severity_numeric,tmp,10));
14175 params.push_back(logic_get_severity_text(severity_numeric));
14176 params.push_back(msg1);
14177 params.push_back(msg2);
14178 params.push_back(irc_server_host);
14179 sprintf(tmp,"%u",(unsigned)irc_server_port);
14180 params.push_back(tmp);
14181
14182 switch(logic_call_proc_ex2(proc.c_str(),vars,params,false)) {
14183 case LOGIC_SOCKET_ERROR:
14184 case LOGIC_RESTART:
14185 in_event=false;
14186 return;
14187 default:
14188 break;
14189 }
14190
14191 in_event=false;
14192 }
14193