494 lines
12 KiB
C
Executable File
494 lines
12 KiB
C
Executable File
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <time.h>
|
||
#include "config.h"
|
||
|
||
char UPLINK[255];
|
||
#ifdef USE_DCC
|
||
struct aDccClient MyClient[MAXCLIENTS];
|
||
#endif
|
||
|
||
char *snoop[]={"FA-Q","leet ","haxor",""};
|
||
|
||
int SNOOP=0;
|
||
extern int DccCtr; /* from socket.c */
|
||
char *SuspendChan[MAXSUSPENDOPER];
|
||
time_t SuspendChanTime[MAXSUSPENDOPER];
|
||
char *SuspendOper[MAXSUSPENDOPER];
|
||
time_t SuspendOperTime[MAXSUSPENDOPER];
|
||
extern char *mynicks[];
|
||
|
||
char *NoGlineHost[MAXNOGLINES],*GlineHost[MAXGLINEHOST];
|
||
char *MultiUserHost[MAXMHOST],*SingleUserHost[MAXMHOST];
|
||
char sockbuf[MAXBUFSIZE],buf[MAXBUFSIZE],storebuf[MAXBUFSIZE];
|
||
char input_buffer[3][3*MAXBUFSIZE],*input_start,*input_end;
|
||
char *token[256];
|
||
int sevsck,botsck;
|
||
FILE *fludfile = NULL;
|
||
char lastkill[255]="\0";
|
||
extern char *operchan[],*invitekiller[],*invitehosts[],*killchan[];
|
||
char LastKlr[20];
|
||
long D_JOIN=0,D_NICK=0,D_PART=0,D_MODE=0,D_KICK=0,D_SERVER=0,D_QUIT=0,D_USER=0;
|
||
long N_JOIN=0,N_NICK=0,N_PART=0,N_MODE=0,N_KICK=0,N_SERVER=0,N_QUIT=0,N_USER=0;
|
||
long D_TOTAL=0,N_TOTAL=0,D_SQUIT,N_SQUIT,N_OTHER=0,D_OTHER=0;
|
||
long D_KILL=0,N_KILL=0,FLOODLOGS=0;
|
||
long D_TOPIC=0,N_TOPIC=0;
|
||
int CLONE_UP=3,CLONE_LO=3,CLONE_DIG=3,LOGHOST=0;
|
||
int DO_AUTOKICK=0,DO_CORE=1;
|
||
time_t S_TIME=0;
|
||
int MAX_SESSIONS=5,MAX_ALLOWED=8;
|
||
time_t NOWTIME,BotIdle,ServIdle;
|
||
int SITE_CLONE=3,KILL_NICKFLOOD=1,num_servs=0;
|
||
char server_list[40][100];
|
||
char controlbot[255];
|
||
int NETBURST=0,FLOODPROTECTION=1;
|
||
|
||
|
||
|
||
main(int argc, char **argv)
|
||
{ int loop,loop2;
|
||
char *envptr;
|
||
|
||
if (argc <2) goto_bg();
|
||
strcpy(UPLINK,MYSERVER);
|
||
|
||
if( (envptr=getenv("UPLINK")) != NULL) strcpy(UPLINK,envptr);
|
||
|
||
#ifdef USE_DCC
|
||
for(loop=0;loop<MAXCLIENTS;loop++)
|
||
{ MyClient[loop].fd=-1;
|
||
MyClient[loop].status=S_FREE;
|
||
}
|
||
#endif
|
||
|
||
InitOperchan();
|
||
InitKillchan();
|
||
read_operchan(OPERCHANFILE);
|
||
read_killchan(KILLCHANFILE);
|
||
|
||
InitGlines();
|
||
read_glines(GLINEFILE);
|
||
|
||
|
||
S_TIME=time(NULL);
|
||
NOWTIME=S_TIME;
|
||
#ifdef DEBUG
|
||
srandom(S_TIME);
|
||
open_debug();
|
||
#endif
|
||
fludfile=fopen(FLUDFILE,"a");
|
||
sprintf(controlbot,"%s@%s",CHANSVR,SERVERNAME);
|
||
load_myuser("user.file");
|
||
load_serv("servers.admin");
|
||
clear_clients();
|
||
startlog();
|
||
sevsck = sev_login(UPLINK);
|
||
botsck = bot_login(UPLINK);
|
||
do_bots();
|
||
|
||
read_noglines(EGLINEFILE);
|
||
read_glinehost(AGLINEFILE);
|
||
read_mhost(MHOSTFILE);
|
||
read_shost(SHOSTFILE);
|
||
read_suspend(SUSPENDFILE);
|
||
read_Csuspend(CHANSUSPENDFILE);
|
||
|
||
for(loop=0;operchan[loop];loop++)
|
||
{
|
||
sprintf(buf,":CHANSVR JOIN #%s\n",operchan[loop]);
|
||
writeln(sevsck,buf);
|
||
sprintf(buf,"MODE #%s +pnoti Chansvr\n",operchan[loop]);
|
||
writeln(sevsck,buf);
|
||
}
|
||
|
||
sprintf(buf,":%s MODE %s +kido\n",CHANSVR,CHANSVR);
|
||
writeln(sevsck,buf);
|
||
|
||
#ifdef JUPE_BUGS
|
||
for(loop=0;*mynicks[loop];loop++)
|
||
makehelp(sevsck,mynicks[loop],"!JUPE Illegal nickname on this network");
|
||
#endif
|
||
makehelp(sevsck,"ChanLock","CHANNEL LOCKING SYSTEM");
|
||
makehelp(sevsck,"ChanServ","Undernet Juping Service");
|
||
writeln(sevsck,":ChanLock MODE Chanlock +kid\n");
|
||
|
||
#ifdef WASTEDUMP
|
||
StartWastedump();
|
||
sprintf(buf,":wastetest MODE wastetest +kid\n");
|
||
writeln(sevsck,buf);
|
||
#endif
|
||
|
||
loop2=0;
|
||
for(loop=0;*invitekiller[loop];loop++)
|
||
{ if(!(*invitehosts[loop2])) loop2=0;
|
||
makedecoy(sevsck,invitekiller[loop],invitehosts[loop2++],
|
||
invitekiller[loop]);
|
||
}
|
||
strcpy(LastKlr,"none");
|
||
|
||
readin();
|
||
}
|
||
|
||
spitout(int sckfd)
|
||
{ int i,num,k,loopcnt;
|
||
int bf,helpsv=0;
|
||
char *fromhost;
|
||
char *temp;
|
||
char *end_of_line;
|
||
int length,position=0,nbc=0;
|
||
static squit_loop=0;
|
||
static time_t last_squit=0;
|
||
char tempbuf[1024];
|
||
char killbuf[255];
|
||
char *ptr;
|
||
int ctr,ilp;
|
||
|
||
if(sckfd == sevsck) bf = 0; /* sevsck */
|
||
else if(sckfd == botsck) bf = 1; /* botsck */
|
||
else bf = 2; /* DccCtr */
|
||
|
||
/* BUFFER INPUT */
|
||
strcat(input_buffer[bf],sockbuf);
|
||
input_buffer[bf][strlen(input_buffer[bf])+1]='\0';
|
||
|
||
/* CHECK FOR NEWLINE */
|
||
input_start=input_buffer[bf];
|
||
length=strlen(input_buffer[bf]);
|
||
while( (input_end=strchr(input_start,'\n')) )
|
||
{ loopcnt++;
|
||
*input_end='\0';
|
||
position+= strlen(input_start);
|
||
|
||
if(strncmp(input_start,"PI",2)==0)
|
||
{ strcpy(buf,input_start);
|
||
strncpy(buf,"PO",2);
|
||
writeln(sckfd,strcat(buf,"\n"));
|
||
input_start=input_end+1;
|
||
continue;
|
||
} /* ping - pong */
|
||
|
||
if(*(input_start+strlen(input_start)-1) == '\r')
|
||
*(input_start+strlen(input_start)-1) = '\0';
|
||
|
||
strcpy(storebuf,input_start);
|
||
|
||
if(SNOOP)
|
||
{ for(ilp=0;*snoop[ilp];ilp++)
|
||
if(strstr(storebuf,snoop[ilp]))
|
||
{ FILE *ofp;
|
||
if( (ofp=fopen("Stats.log","a"))!=NULL)
|
||
{ fprintf(ofp,"%ld %s\n",NOWTIME,storebuf);
|
||
fclose(ofp);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if((FLOODLOGS) && (fludfile != NULL))
|
||
fprintf(fludfile,"%s\n",storebuf);
|
||
|
||
token[i=0]=strtok(input_start," ");
|
||
while(token[++i]=strtok(NULL, " ")); token[i]=NULL;
|
||
|
||
input_start=input_end+1;
|
||
|
||
if(!token[0]) continue;
|
||
if(!token[1]) continue;
|
||
if(i > 2) do_count();
|
||
|
||
k=chk_num(0);
|
||
if(temp=strchr(token[0],'!'))
|
||
{
|
||
*temp='\0'; fromhost=temp+1;
|
||
if((k>3) && (FLOODPROTECTION)) FloodProtect(token[0]+1,token[2]);
|
||
parse(fromhost);
|
||
continue;
|
||
}
|
||
|
||
nbc=0;
|
||
|
||
if((!NETBURST) && (k>3) && ((!strcmp(token[nbc++],"SERVER")) ||
|
||
(!strcmp(token[nbc++],"SERVER")) ))
|
||
{ if(!NETBURST)
|
||
{ sprintf(buf,":%s PRIVMSG #uworld.floods :PROCESSING NETBURST %d\n",
|
||
CHANSVR,nbc);
|
||
writeln(sevsck,buf);
|
||
}
|
||
NETBURST=nbc;
|
||
}
|
||
|
||
if((!NETBURST) && (FLOODPROTECTION) && (!strchr(token[0],'.')))
|
||
{
|
||
if((k>3) && ((*token[1]=='P') || (*token[1]=='I') ||
|
||
(!strncmp(token[1],"NO",2))))
|
||
FloodProtect(token[0]+1,token[2]);
|
||
}
|
||
|
||
|
||
if((!strcmp(token[0],"ERROR")) &&
|
||
(!strcmp(token[1],":Closing")))
|
||
{
|
||
if(sckfd==sevsck)
|
||
{ close(sevsck);
|
||
writelog("SQUIT");
|
||
destroy_nickhash();
|
||
squit_loop++;
|
||
if(squit_loop > 5)
|
||
{ writelog("EXITING SQUIT LOOP");
|
||
exit(1);
|
||
}
|
||
if(NOWTIME - last_squit < 120) continue;
|
||
last_squit = NOWTIME;
|
||
if(k>5)
|
||
{
|
||
*token[5]++;
|
||
if(*token[5] != '!')
|
||
{
|
||
clear_clients();
|
||
sevsck=sev_login(UPLINK);
|
||
do_bots();
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
else /* client squit */
|
||
{ close(botsck);
|
||
botsck=bot_login(UPLINK);
|
||
continue;
|
||
}
|
||
}
|
||
if(k > 3)
|
||
{
|
||
if(!strcmp(token[3],":remakeuworld"))
|
||
{
|
||
close( botsck);
|
||
botsck=bot_login(UPLINK);
|
||
}
|
||
else if(atoi(token[1])) { sevnum(atoi(token[1])); continue; }
|
||
else if(!match(token[1],"KILL")) { record_kill(); continue; }
|
||
else if(strcasecmp(token[0],":helpbot"))
|
||
{ if(strlen(token[3])>80) continue;
|
||
if(strchr(token[3],'@')) continue;/* Should stop the silence bug */
|
||
if(!match(token[2],IRCHELP)) {do_helpirc(sevsck); continue; }
|
||
else if(!strcasecmp(token[2],controlbot))
|
||
{ OperCom(token[0]+1);
|
||
continue;
|
||
}
|
||
else if( (*token[1]=='P') || (*token[1]=='I') ||
|
||
(!strncmp(token[1],"NO",2)))
|
||
{
|
||
for(ctr=0;*invitekiller[ctr];ctr++)
|
||
{ if(!strcasecmp(token[2],invitekiller[ctr]))
|
||
{ GetFromhost(token[0]+1,killbuf);
|
||
sprintf(tempbuf,"MMG[%d] <%s!%s>",ctr,token[0]+1,killbuf);
|
||
for(ctr=3;token[ctr];ctr++)
|
||
{ strcat(tempbuf," ");
|
||
strcat(tempbuf,token[ctr]);
|
||
}
|
||
strcat(tempbuf,"\n");
|
||
mmg_log(tempbuf);
|
||
|
||
if((!strcasecmp(lastkill,killbuf)) &&
|
||
(strcasecmp(LastKlr,token[2])))
|
||
{ /*We've heard from this idiot already */
|
||
char ttbuf[1024],*tpt;
|
||
|
||
tpt=killbuf;
|
||
while( (*tpt=='*') ) tpt++;
|
||
if( (!match("*telnet@*.wildstar.net",tpt)) ||
|
||
(!match("*telnet@*.wildstar.com",tpt)) )
|
||
{
|
||
dump_nicklist(token[0]+1,"TELNET.FLOODERS");
|
||
}
|
||
else
|
||
{
|
||
/*
|
||
sprintf(ttbuf,"*%s",killbuf);
|
||
do_gline(ttbuf,"MASSMESSAGE",
|
||
"Unsolicited Mass Advertisements are prohibited - [Auto]",
|
||
3600);
|
||
*/
|
||
sprintf(ttbuf,
|
||
"KILL %s Uworld!uworld.undernet.org :MASS MESSAGE KILL FROM %s\n",
|
||
token[0]+1,killbuf);
|
||
writeln(sevsck,ttbuf);
|
||
}
|
||
|
||
}
|
||
strcpy(lastkill,killbuf);
|
||
strcpy(LastKlr,token[2]);
|
||
|
||
DccGlobal(tempbuf,DCC_MMG);
|
||
sprintf(buf,":%s PRIVMSG #uworld.floods :%s",CHANSVR,tempbuf);
|
||
writeln(sevsck,buf);
|
||
break;
|
||
}
|
||
}
|
||
continue;
|
||
}
|
||
else if(!strcasecmp(token[2],"chansvr"))
|
||
{ sprintf(buf,
|
||
":Chansvr NOTICE %s :Please use %s\n",token[0]+1,controlbot);
|
||
writeln(sevsck,buf);
|
||
continue;
|
||
}
|
||
else if(!match(token[2],USHELP)) {do_ushelp(sevsck); continue; }
|
||
else if((!match(token[2],HELPBOT)) &&
|
||
(!match(token[3],":help"))) {do_helpem(sevsck); continue; }
|
||
}
|
||
}
|
||
if(!helpsv) sevstuff(sevsck,fromhost);
|
||
} /* END BUFFER INPUT */
|
||
|
||
strcpy(input_buffer[bf],input_start);
|
||
}
|
||
|
||
|
||
finishline(start)
|
||
int start; { int i; i=start; while (token[i]) printf(" %s",token[i++]); }
|
||
|
||
int chk_num(int start)
|
||
{
|
||
int j;
|
||
j=start;
|
||
while (token[j]) {
|
||
j++;
|
||
}
|
||
return j;
|
||
}
|
||
|
||
do_scmd(int sck)
|
||
{int i,j,k;
|
||
char temp[512];
|
||
if(!i) i = 4;
|
||
j=chk_num(0);
|
||
strcpy(temp,"");
|
||
if (j>4)
|
||
for(i=4;i<j;i++) {
|
||
strcat(temp,token[i]);
|
||
strcat(temp," ");
|
||
}
|
||
sprintf(buf,"%s\n",temp); writeln(sck,buf);
|
||
}
|
||
|
||
Gline(fromhost)
|
||
char *fromhost;
|
||
{
|
||
static int counter=0;
|
||
*token[0]++;
|
||
if(match(fromhost,lastkill)) {
|
||
sprintf(buf,"463 %s :Global Kill Line\n",token[0]);
|
||
writeln(sevsck,buf);
|
||
sprintf(buf,"352 %s \n",token[0]);
|
||
writeln(sevsck,buf);
|
||
}
|
||
else {
|
||
counter++;
|
||
sprintf(buf,"352 %s \n",token[0]);
|
||
writeln(sevsck,buf);
|
||
sprintf(buf,"463 %s :Global Kill Line\n",token[0]);
|
||
writeln(sevsck,buf);
|
||
}
|
||
strcpy(lastkill,fromhost);
|
||
if(counter > 8) {
|
||
sprintf(buf,"NICK %s :1\n",token[0]);
|
||
writeln(sevsck,buf);
|
||
counter = 0;
|
||
}
|
||
if(counter = 5) {
|
||
sprintf(buf,"KILL %s :GLOBAL KILL LINE \n",token[0]);
|
||
writeln(sevsck,buf);
|
||
}
|
||
}
|
||
|
||
do_count()
|
||
{ if(!strcmp(token[1],"KICK"))
|
||
{ D_KICK += strlen(storebuf);
|
||
N_KICK++;
|
||
}
|
||
else if(!strcmp(token[1],"JOIN"))
|
||
{ D_JOIN += strlen(storebuf);
|
||
N_JOIN++;
|
||
}
|
||
else if(!strcmp(token[1],"PART"))
|
||
{ D_PART += strlen(storebuf);
|
||
N_PART++;
|
||
}
|
||
else if(!strcmp(token[1],"MODE"))
|
||
{ D_MODE += strlen(storebuf);
|
||
N_MODE++;
|
||
if((NETBURST) && strchr(token[0],'.'))
|
||
{ NETBURST=0;
|
||
sprintf(buf,":%s PRIVMSG #uworld.floods :Netburst Complete\n",
|
||
CHANSVR);
|
||
writeln(sevsck,buf);
|
||
}
|
||
}
|
||
else if(!strcmp(token[1],"SQUIT"))
|
||
{ D_SQUIT += strlen(storebuf);
|
||
N_SQUIT++;
|
||
}
|
||
else if(!strcmp(token[1],"QUIT"))
|
||
{ D_QUIT += strlen(storebuf);
|
||
N_QUIT++;
|
||
}
|
||
else if(!strcmp(token[1],"SERVER"))
|
||
{ D_SERVER += strlen(storebuf);
|
||
N_SERVER++;
|
||
}
|
||
else if(!strcmp(token[1],"USER"))
|
||
{ D_USER += strlen(storebuf);
|
||
N_USER++;
|
||
}
|
||
else if(!strcmp(token[1],"NICK"))
|
||
{ D_NICK += strlen(storebuf);
|
||
N_NICK++;
|
||
}
|
||
else if(!strcmp(token[0],"NICK"))
|
||
{ D_NICK += strlen(storebuf);
|
||
N_NICK++;
|
||
}
|
||
else if(!strcmp(token[1],"KILL"))
|
||
{ D_KILL += strlen(storebuf);
|
||
N_KILL++;
|
||
}
|
||
else if(!strcmp(token[1],"TOPIC"))
|
||
{ D_TOPIC += strlen(storebuf);
|
||
N_TOPIC++;
|
||
}
|
||
else
|
||
{ N_OTHER++;
|
||
D_OTHER += strlen(storebuf);
|
||
}
|
||
}
|
||
|
||
int load_serv(char *file)
|
||
{
|
||
FILE *infile;
|
||
char line[500];
|
||
|
||
|
||
if( (infile=fopen(file,"r")) == NULL) return;
|
||
|
||
for(num_servs=0;fgets(line,99,infile);num_servs++)
|
||
{
|
||
line[strlen(line)-1]='\0';
|
||
strcpy(server_list[num_servs],line);
|
||
}
|
||
fclose(infile);
|
||
return;
|
||
}
|
||
|
||
int join_opchan(char *channel)
|
||
{ int loop;
|
||
for(loop=0;operchan[loop];loop++)
|
||
{ if(strcasecmp(operchan[loop],channel)) continue;
|
||
sprintf(buf,":CHANSVR JOIN #%s\n",operchan[loop]);
|
||
writeln(sevsck,buf);
|
||
sprintf(buf,"MODE #%s +pnotil Chansvr 1\n",operchan[loop]);
|
||
writeln(sevsck,buf);
|
||
}
|
||
|
||
}
|
||
|