--- sbbs/src/sbbs3/answer.cpp 2018/04/24 16:41:23 1.1.1.1 +++ sbbs/src/sbbs3/answer.cpp 2018/04/24 16:42:42 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet answer "caller" function */ -/* $Id: answer.cpp,v 1.1.1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: answer.cpp,v 1.1.1.2 2018/04/24 16:42:42 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -38,6 +38,8 @@ #include "sbbs.h" #include "telnet.h" +extern "C" void client_on(SOCKET sock, client_t* client, BOOL update); + bool sbbs_t::answer() { char str[MAX_PATH+1],str2[MAX_PATH+1],c; @@ -45,13 +47,11 @@ bool sbbs_t::answer() char path[MAX_PATH+1]; int i,l,in; struct tm tm; - struct in_addr addr; useron.number=0; answertime=logontime=starttime=now=time(NULL); /* Caller ID is IP address */ - addr.s_addr=client_addr; - SAFECOPY(cid,inet_ntoa(addr)); + SAFECOPY(cid,inet_ntoa(client_addr.sin_addr)); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); @@ -106,16 +106,17 @@ bool sbbs_t::answer() ,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str2 : str); SAFECOPY(rlogin_pass ,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str : str2); - useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0); + useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); - useron.misc&=~(ANSI|COLOR|RIP|WIP); + useron.misc&=~TERM_FLAGS; SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir); if(!findstr(client.addr,path)) { SAFECOPY(tmp ,rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { + badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) @@ -124,7 +125,7 @@ bool sbbs_t::answer() else sprintf(str,"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); - logline("+!",str); + logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); @@ -146,6 +147,7 @@ bool sbbs_t::answer() } if(i) { if(stricmp(tmp,useron.pass)) { + badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'" @@ -153,19 +155,20 @@ bool sbbs_t::answer() else sprintf(str,"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); - logline("+!",str); + logline(LOG_NOTICE,"+!",str); } - lprintf(LOG_WARNING,"%04d !CLIENT IP NOT LISTED in %s",client_socket,path); + lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s" + ,cfg.node_num,path); useron.number=0; hangup(); } } } else - lprintf(LOG_DEBUG,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); + lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); } if(rlogin_name[0]==0) { - lprintf(LOG_DEBUG,"Node %d !RLogin: No user name received",cfg.node_num); + lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num); sys_status&=~SS_RLOGIN; } } @@ -175,8 +178,11 @@ bool sbbs_t::answer() request_telnet_opt(TELNET_WILL,TELNET_ECHO); /* Will suppress Go Ahead */ request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); - /* Retrieve terminal type from telnet client --RS */ + /* Retrieve terminal type and speed from telnet client --RS */ request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE); + request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED); + request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION); + request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE); } #ifdef USE_CRYPTLIB if(sys_status&SS_SSH) { @@ -186,14 +192,15 @@ bool sbbs_t::answer() rlogin_pass[i]=0; lprintf(LOG_DEBUG,"Node %d SSH login: '%s'" ,cfg.node_num, rlogin_name); - useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0); + useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); - useron.misc&=~(ANSI|COLOR|RIP|WIP); + useron.misc&=~TERM_FLAGS; SAFECOPY(tmp ,rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { + badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) @@ -202,7 +209,13 @@ bool sbbs_t::answer() else sprintf(str,"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); - logline("+!",str); + /* crash here Sept-12-2010 + str 0x06b3fc4c "(0000) Guest FAILED Password attempt: 'alex2010@sdf.lonestar.org'" + + and Oct-6-2010 + str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261] + */ + logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); @@ -224,6 +237,7 @@ bool sbbs_t::answer() } if(i) { if(stricmp(tmp,useron.pass)) { + badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'" @@ -231,14 +245,14 @@ bool sbbs_t::answer() else sprintf(str,"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); - logline("+!",str); + logline(LOG_NOTICE,"+!",str); } useron.number=0; hangup(); } } else - lprintf(LOG_DEBUG,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); + lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); } #endif @@ -247,12 +261,13 @@ bool sbbs_t::answer() rioctl(IOFI); /* flush input buffer */ putcom( "\r\n" /* locate cursor at column 1 */ "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */ - "\x1b[99B_" /* locate cursor as far down as possible */ + "\x1b[255B" /* locate cursor as far down as possible */ + "\x1b[255C" /* locate cursor as far right as possible */ + "\b_" /* need a printable at this location to actually move cursor */ "\x1b[6n" /* Get cursor position */ "\x1b[u" /* restore cursor position */ "\x1b[!_" /* RIP? */ - "\x1b[0t_" /* WIP? */ - "\2\2?HTML?"/* HTML? */ + "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm? "\x1b[0m_" /* "Normal" colors */ "\x1b[2J" /* clear screen */ "\x1b[H" /* home cursor */ @@ -265,7 +280,7 @@ bool sbbs_t::answer() strcpy(str,VERSION_NOTICE); strcat(str," "); strcat(str,COPYRIGHT_NOTICE); - strip_ctrl(str); + strip_ctrl(str, str); center(str); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ @@ -287,14 +302,22 @@ bool sbbs_t::answer() str[l]=0; if(l) { - if(str[0]==ESC && str[1]=='[') { + c_escape_str(str,tmp,sizeof(tmp),TRUE); + lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'" + ,cfg.node_num,tmp); + if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') { + int x,y; + if(terminal[0]==0) SAFECOPY(terminal,"ANSI"); autoterm|=(ANSI|COLOR); - rows=atoi(str+2); - lprintf(LOG_DEBUG,"Node %d ANSI cursor position report: %u rows" - ,cfg.node_num, rows); - if(rows<10 || rows>99) rows=24; + if(sscanf(str+2,"%u;%u",&y,&x)==2) { + lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u" + ,cfg.node_num, x, y); + /* Sanity check the coordinates in the response: */ + if(x>=40 && x<=255) cols=x; + if(y>=10 && y<=255) rows=y; + } } truncsp(str); if(strstr(str,"RIPSCRIP")) { @@ -302,16 +325,10 @@ bool sbbs_t::answer() SAFECOPY(terminal,"RIP"); logline("@R",strstr(str,"RIPSCRIP")); autoterm|=(RIP|COLOR|ANSI); } - else if(strstr(str,"DC-TERM") - && toupper(*(strstr(str,"DC-TERM")+12))=='W') { - if(terminal[0]==0) - SAFECOPY(terminal,"WIP"); - logline("@W",strstr(str,"DC-TERM")); - autoterm|=(WIP|COLOR|ANSI); } - else if(strstr(str,"!HTML!")) { + else if(strstr(str,"Are you the gatekeeper?")) { if(terminal[0]==0) SAFECOPY(terminal,"HTML"); - logline("@H",strstr(str,"!HTML!")); + logline("@H",strstr(str,"Are you the gatekeeper?")); autoterm|=HTML; } } @@ -321,22 +338,15 @@ bool sbbs_t::answer() rioctl(IOFI); /* flush left-over or late response chars */ if(!autoterm && str[0]) { - lputs(LOG_DEBUG,"Terminal Auto-detect failed, Response: "); - str2[0]=0; - for(i=0;str[i];i++) { - if(str[i]>=' ' && str[i]<='~') - sprintf(tmp,"%c", str[i]); - else - sprintf(tmp,"<%02X>", (uchar)str[i]); - strcat(str2,tmp); - } - lputs(LOG_DEBUG,str2); + c_escape_str(str,tmp,sizeof(tmp),TRUE); + lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'" + ,cfg.node_num, tmp); } /* AutoLogon via IP or Caller ID here */ if(!useron.number && !(sys_status&SS_RLOGIN) && startup->options&BBS_OPT_AUTO_LOGON && cid[0]) { - useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid, 0); + useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid); if(useron.number) { getuserdat(&cfg, &useron); if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V'))) @@ -347,7 +357,37 @@ bool sbbs_t::answer() if(!online) return(false); - useron.misc&=~(ANSI|COLOR|RIP|WIP); + if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */ + SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate); + logline("@S",str); + node_connection = (ushort)cur_rate; + SAFEPRINTF(connection,"%lu",cur_rate); + SAFECOPY(cid,"Unknown"); + SAFECOPY(client_name,"Unknown"); + if(telnet_location[0]) { /* Caller-ID info provided */ + SAFEPRINTF(str, "CID: %s", telnet_location); + logline("@*",str); + SAFECOPY(cid,telnet_location); + truncstr(cid," "); /* Only include phone number in CID */ + char* p=telnet_location; + FIND_WHITESPACE(p); + SKIP_WHITESPACE(p); + if(*p) { + SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */ + } + } + SAFECOPY(client.addr,cid); + SAFECOPY(client.host,client_name); + client_on(client_socket,&client,TRUE /* update */); + } else { + if(telnet_location[0]) { /* Telnet Location info provided */ + SAFEPRINTF(str, "Telnet Location: %s", telnet_location); + logline("@*",str); + } + } + + + useron.misc&=~TERM_FLAGS; useron.misc|=autoterm; SAFECOPY(useron.comp,client_name); @@ -360,11 +400,11 @@ bool sbbs_t::answer() /* Display ANSWER screen */ sprintf(str,"%sanswer",cfg.text_dir); - sprintf(tmp,"%s.%s",str,autoterm&WIP ? "wip":"rip"); + sprintf(tmp,"%s.rip",str); sprintf(path,"%s.html",str); sprintf(str2,"%s.ans",str); - if(autoterm&(RIP|WIP) && fexist(tmp)) - strcat(str,autoterm&WIP ? ".wip":".rip"); + if(autoterm&RIP && fexist(tmp)) + strcat(str,".rip"); else if(autoterm&HTML && fexist(path)) strcat(str,".html"); else if(autoterm&ANSI && fexist(str2)) @@ -383,8 +423,6 @@ bool sbbs_t::answer() if(!useron.number) hangup(); - if(!online) - return(false); /* Save the IP to the user's note */ if(cid[0]) { @@ -398,10 +436,17 @@ bool sbbs_t::answer() putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp); } + if(!online) + return(false); + if(!(sys_status&SS_USERON)) { errormsg(WHERE,ERR_CHK,"User not logged on",0); hangup(); - return(false); } + return(false); + } + + if(useron.pass[0]) + loginSuccess(startup->login_attempt_list, &client_addr); return(true); }