const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen) { char* tp; uint i; uint ugrp; uint usub; long l; stats_t stats; node_t node; struct tm tm; str[0]=0; if(!strcmp(sp,"VER")) return(VERSION); if(!strcmp(sp,"REV")) { safe_snprintf(str,maxlen,"%c",REVISION); return(str); } if(!strcmp(sp,"FULL_VER")) { safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version); truncsp(str); #if defined(_DEBUG) strcat(str," Debug"); #endif return(str); } if(!strcmp(sp,"VER_NOTICE")) return(VERSION_NOTICE); if(!strcmp(sp,"OS_VER")) return(os_version(str)); #ifdef JAVASCRIPT if(!strcmp(sp,"JS_VER")) return((char *)JS_GetImplementationVersion()); #endif if(!strcmp(sp,"PLATFORM")) return(PLATFORM_DESC); if(!strcmp(sp,"COPYRIGHT")) return(COPYRIGHT_NOTICE); if(!strcmp(sp,"COMPILER")) { DESCRIBE_COMPILER(str); return(str); } if(!strcmp(sp,"UPTIME")) { extern volatile time_t uptime; time_t up=time(NULL)-uptime; if(up<0) up=0; char days[64]=""; if((up/(24*60*60))>=2) { sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L))); up%=(24*60*60); } safe_snprintf(str,maxlen,"%s%lu:%02lu" ,days ,(ulong)(up/(60L*60L)) ,(ulong)((up/60L)%60L) ); return(str); } if(!strcmp(sp,"SERVED")) { extern volatile ulong served; safe_snprintf(str,maxlen,"%lu",served); return(str); } if(!strcmp(sp,"SOCKET_LIB")) return(socklib_version(str,SOCKLIB_DESC)); if(!strcmp(sp,"MSG_LIB")) { safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver()); return(str); } if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME")) return(cfg.sys_name); if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) { safe_snprintf(str,maxlen,"%lu",cur_rate); return(str); } if(!strcmp(sp,"CONN")) return(connection); if(!strcmp(sp,"SYSOP")) return(cfg.sys_op); if(!strcmp(sp,"LOCATION")) return(cfg.sys_location); if(!strcmp(sp,"NODE")) { safe_snprintf(str,maxlen,"%u",cfg.node_num); return(str); } if(!strcmp(sp,"TNODE")) { safe_snprintf(str,maxlen,"%u",cfg.sys_nodes); return(str); } if(!strcmp(sp,"INETADDR")) return(cfg.sys_inetaddr); if(!strcmp(sp,"HOSTNAME")) return(startup->host_name); if(!strcmp(sp,"FIDOADDR")) { if(cfg.total_faddrs) return(smb_faddrtoa(&cfg.faddr[0],str)); return(nulstr); } if(!strcmp(sp,"EMAILADDR")) return(usermailaddr(&cfg, str ,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name)); if(!strcmp(sp,"QWKID")) return(cfg.sys_id); if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) { now=time(NULL); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); if(cfg.sys_misc&SM_MILITARY) safe_snprintf(str,maxlen,"%02d:%02d:%02d" ,tm.tm_hour,tm.tm_min,tm.tm_sec); else safe_snprintf(str,maxlen,"%02d:%02d %s" ,tm.tm_hour==0 ? 12 : tm.tm_hour>12 ? tm.tm_hour-12 : tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am"); return(str); } if(!strcmp(sp,"TIMEZONE")) return(smb_zonestr(sys_timezone(&cfg),str)); if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) { return(unixtodstr(&cfg,time32(NULL),str)); } if(!strcmp(sp,"DATETIME")) return(timestr(time(NULL))); if(!strcmp(sp,"TMSG")) { l=0; for(i=0;i<cfg.total_subs;i++) l+=getposts(&cfg,i); /* l=total posts */ safe_snprintf(str,maxlen,"%lu",l); return(str); } if(!strcmp(sp,"TUSER")) { safe_snprintf(str,maxlen,"%u",total_users(&cfg)); return(str); } if(!strcmp(sp,"TFILE")) { l=0; for(i=0;i<cfg.total_dirs;i++) l+=getfiles(&cfg,i); safe_snprintf(str,maxlen,"%lu",l); return(str); } if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) { getstats(&cfg,0,&stats); safe_snprintf(str,maxlen,"%lu",stats.logons); return(str); } if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE") || !strcmp(sp,"LASTCALLERSYSTEM")) return(lastuseron); if(!strcmp(sp,"CLS")) { CLS; return(nulstr); } if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) { pause(); return(nulstr); } if(!strcmp(sp,"RESETPAUSE")) { lncntr=0; return(nulstr); } if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) { sys_status^=SS_PAUSEOFF; return(nulstr); } if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) { sys_status^=SS_PAUSEON; return(nulstr); } /* NOSTOP */ /* STOP */ if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP")) return("\a"); if(!strcmp(sp,"EVENT")) { if(event_time==0) return("<none>"); return(timestr(event_time)); } /* LASTCALL */ if(!strncmp(sp,"NODE",4)) { i=atoi(sp+4); if(i && i<=cfg.sys_nodes) { getnodedat(i,&node,0); printnodedat(i,&node); } return(nulstr); } if(!strcmp(sp,"WHO")) { whos_online(true); return(nulstr); } /* User Codes */ if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME")) return(useron.alias); if(!strcmp(sp,"FIRST")) { safe_snprintf(str,maxlen,"%s",useron.alias); tp=strchr(str,' '); if(tp) *tp=0; return(str); } if(!strcmp(sp,"USERNUM")) { safe_snprintf(str,maxlen,"%u",useron.number); return(str); } if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE") || !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA")) return(useron.phone); if(!strcmp(sp,"ADDR1")) return(useron.address); if(!strcmp(sp,"FROM")) return(useron.location); if(!strcmp(sp,"CITY")) { safe_snprintf(str,maxlen,"%s",useron.location); char* p=strchr(str,','); if(p) { *p=0; return(str); } return(nulstr); } if(!strcmp(sp,"STATE")) { char* p=strchr(useron.location,','); if(p) { p++; if(*p==' ') p++; return(p); } return(nulstr); } if(!strcmp(sp,"CPU")) return(useron.comp); if(!strcmp(sp,"HOST")) return(client_name); if(!strcmp(sp,"BDATE")) return(useron.birth); if(!strcmp(sp,"AGE")) { safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth)); return(str); } if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) { safe_snprintf(str,maxlen,"%u",useron.logons); return(str); } if(!strcmp(sp,"MEMO")) return(unixtodstr(&cfg,useron.pwmod,str)); if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) { safe_snprintf(str,maxlen,"%u",useron.level); return(str); } if(!strcmp(sp,"SINCE")) return(unixtodstr(&cfg,useron.firston,str)); if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) { now=time(NULL); safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L); return(str); } if(!strcmp(sp,"TUSED")) { /* Synchronet only */ now=time(NULL); return(sectostr((uint)(now-logontime),str)+1); } if(!strcmp(sp,"TLEFT")) { /* Synchronet only */ gettimeleft(); return(sectostr(timeleft,str)+1); } if(!strcmp(sp,"TPERD")) /* Synchronet only */ return(sectostr(cfg.level_timeperday[useron.level],str)+1); if(!strcmp(sp,"TPERC")) /* Synchronet only */ return(sectostr(cfg.level_timepercall[useron.level],str)+1); if(!strcmp(sp,"TIMELIMIT")) { safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]); return(str); } if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) { gettimeleft(); safe_snprintf(str,maxlen,"%lu",timeleft/60); return(str); } if(!strcmp(sp,"LASTON")) return(timestr(useron.laston)); if(!strcmp(sp,"LASTDATEON")) return(unixtodstr(&cfg,useron.laston,str)); if(!strcmp(sp,"LASTTIMEON")) { memset(&tm,0,sizeof(tm)); localtime32(&useron.laston,&tm); if(cfg.sys_misc&SM_MILITARY) safe_snprintf(str,maxlen,"%02d:%02d:%02d" ,tm.tm_hour, tm.tm_min, tm.tm_sec); else safe_snprintf(str,maxlen,"%02d:%02d %s" ,tm.tm_hour==0 ? 12 : tm.tm_hour>12 ? tm.tm_hour-12 : tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am"); return(str); } if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) { safe_snprintf(str,maxlen,"%u",useron.posts); return(str); } if(!strcmp(sp,"MSGREAD")) { safe_snprintf(str,maxlen,"%lu",posts_read); return(str); } if(!strcmp(sp,"FREESPACE")) { safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0)); return(str); } if(!strcmp(sp,"FREESPACEK")) { safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024)); return(str); } if(!strcmp(sp,"UPBYTES")) { safe_snprintf(str,maxlen,"%lu",useron.ulb); return(str); } if(!strcmp(sp,"UPK")) { safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L); return(str); } if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) { safe_snprintf(str,maxlen,"%u",useron.uls); return(str); } if(!strcmp(sp,"DLBYTES")) { safe_snprintf(str,maxlen,"%lu",useron.dlb); return(str); } if(!strcmp(sp,"DOWNK")) { safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L); return(str); } if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) { safe_snprintf(str,maxlen,"%u",useron.dls); return(str); } if(!strcmp(sp,"LASTNEW")) return(unixtodstr(&cfg,(time32_t)ns_time,str)); if(!strcmp(sp,"NEWFILETIME")) return(timestr(ns_time)); /* MAXDL */ if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) { safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L); return(str); } if(!strcmp(sp,"DAYBYTES")) { /* amt of free cdts used today */ safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt); return(str); } if(!strcmp(sp,"BYTELIMIT")) { safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]); return(str); } if(!strcmp(sp,"KBLEFT")) { safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L); return(str); } if(!strcmp(sp,"BYTESLEFT")) { safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt); return(str); } if(!strcmp(sp,"CONF")) { safe_snprintf(str,maxlen,"%s %s" ,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr ,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr); return(str); } if(!strcmp(sp,"CONFNUM")) { safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1); return(str); } if(!strcmp(sp,"NUMDIR")) { safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0); return(str); } if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE")) return(unixtodstr(&cfg,useron.expire,str)); if(!strcmp(sp,"EXPDAYS")) { now=time(NULL); l=(long)(useron.expire-now); if(l<0) l=0; safe_snprintf(str,maxlen,"%lu",l/(1440L*60L)); return(str); } if(!strcmp(sp,"MEMO1")) return(useron.note); if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY")) return(useron.name); if(!strcmp(sp,"ZIP")) return(useron.zipcode); if(!strcmp(sp,"HANGUP")) { hangup(); return(nulstr); } /* Synchronet Specific */ if(!strncmp(sp,"SETSTR:",7)) { strcpy(main_csi.str,sp+7); return(nulstr); } if(!strncmp(sp,"EXEC:",5)) { exec_bin(sp+5,&main_csi); return(nulstr); } if(!strncmp(sp,"EXEC_XTRN:",10)) { for(i=0;i<cfg.total_xtrns;i++) if(!stricmp(cfg.xtrn[i]->code,sp+10)) break; if(i<cfg.total_xtrns) exec_xtrn(i); return(nulstr); } if(!strncmp(sp,"MENU:",5)) { menu(sp+5); return(nulstr); } if(!strncmp(sp,"TYPE:",5)) { printfile(cmdstr(sp+5,nulstr,nulstr,str),0); return(nulstr); } if(!strncmp(sp,"INCLUDE:",8)) { printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR); return(nulstr); } if(!strcmp(sp,"QUESTION")) return(question); if(!strcmp(sp,"HANDLE")) return(useron.handle); if(!strcmp(sp,"CID") || !strcmp(sp,"IP")) return(cid); if(!strcmp(sp,"LOCAL-IP")) return(local_addr); if(!strcmp(sp,"CRLF")) return("\r\n"); if(!strcmp(sp,"PUSHXY")) { ansi_save(); return(nulstr); } if(!strcmp(sp,"POPXY")) { ansi_restore(); return(nulstr); } if(!strncmp(sp,"UP:",3)) { cursor_up(atoi(sp+3)); return(str); } if(!strncmp(sp,"DOWN:",5)) { cursor_down(atoi(sp+5)); return(str); } if(!strncmp(sp,"LEFT:",5)) { cursor_left(atoi(sp+5)); return(str); } if(!strncmp(sp,"RIGHT:",6)) { cursor_right(atoi(sp+6)); return(str); } if(!strncmp(sp,"GOTOXY:",7)) { tp=strchr(sp,','); if(tp!=NULL) { tp++; ansi_gotoxy(atoi(sp+7),atoi(tp)); } return(nulstr); } if(!strcmp(sp,"GRP")) { if(SMB_IS_OPEN(&smb)) { if(smb.subnum==INVALID_SUB) return("Local"); if(smb.subnum<cfg.total_subs) return(cfg.grp[cfg.sub[smb.subnum]->grp]->sname); } return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr); } if(!strcmp(sp,"GRPL")) { if(SMB_IS_OPEN(&smb)) { if(smb.subnum==INVALID_SUB) return("Local"); if(smb.subnum<cfg.total_subs) return(cfg.grp[cfg.sub[smb.subnum]->grp]->lname); } return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr); } if(!strcmp(sp,"GN")) { if(SMB_IS_OPEN(&smb)) ugrp=getusrgrp(smb.subnum); else ugrp=usrgrps ? curgrp+1 : 0; safe_snprintf(str,maxlen,"%u",ugrp); return(str); } if(!strcmp(sp,"GL")) { if(SMB_IS_OPEN(&smb)) ugrp=getusrgrp(smb.subnum); else ugrp=usrgrps ? curgrp+1 : 0; safe_snprintf(str,maxlen,"%-4u",ugrp); return(str); } if(!strcmp(sp,"GR")) { if(SMB_IS_OPEN(&smb)) ugrp=getusrgrp(smb.subnum); else ugrp=usrgrps ? curgrp+1 : 0; safe_snprintf(str,maxlen,"%4u",ugrp); return(str); } if(!strcmp(sp,"SUB")) { if(SMB_IS_OPEN(&smb)) { if(smb.subnum==INVALID_SUB) return("Mail"); else if(smb.subnum<cfg.total_subs) return(cfg.sub[smb.subnum]->sname); } return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr); } if(!strcmp(sp,"SUBL")) { if(SMB_IS_OPEN(&smb)) { if(smb.subnum==INVALID_SUB) return("Mail"); else if(smb.subnum<cfg.total_subs) return(cfg.sub[smb.subnum]->lname); } return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr); } if(!strcmp(sp,"SN")) { if(SMB_IS_OPEN(&smb)) usub=getusrsub(smb.subnum); else usub=usrgrps ? cursub[curgrp]+1 : 0; safe_snprintf(str,maxlen,"%u",usub); return(str); } if(!strcmp(sp,"SL")) { if(SMB_IS_OPEN(&smb)) usub=getusrsub(smb.subnum); else usub=usrgrps ? cursub[curgrp]+1 : 0; safe_snprintf(str,maxlen,"%-4u",usub); return(str); } if(!strcmp(sp,"SR")) { if(SMB_IS_OPEN(&smb)) usub=getusrsub(smb.subnum); else usub=usrgrps ? cursub[curgrp]+1 : 0; safe_snprintf(str,maxlen,"%4u",usub); return(str); } if(!strcmp(sp,"LIB")) return(usrlibs ? cfg.lib[usrlib[curlib]]->sname : nulstr); if(!strcmp(sp,"LIBL")) return(usrlibs ? cfg.lib[usrlib[curlib]]->lname : nulstr); if(!strcmp(sp,"LN")) { safe_snprintf(str,maxlen,"%u",usrlibs ? curlib+1 : 0); return(str); } if(!strcmp(sp,"LL")) { safe_snprintf(str,maxlen,"%-4u",usrlibs ? curlib+1 : 0); return(str); } if(!strcmp(sp,"LR")) { safe_snprintf(str,maxlen,"%4u",usrlibs ? curlib+1 : 0); return(str); } if(!strcmp(sp,"DIR")) return(usrlibs ? cfg.dir[usrdir[curlib][curdir[curlib]]]->sname :nulstr); if(!strcmp(sp,"DIRL")) return(usrlibs ? cfg.dir[usrdir[curlib][curdir[curlib]]]->lname : nulstr); if(!strcmp(sp,"DN")) { safe_snprintf(str,maxlen,"%u",usrlibs ? curdir[curlib]+1 : 0); return(str); } if(!strcmp(sp,"DL")) { safe_snprintf(str,maxlen,"%-4u",usrlibs ? curdir[curlib]+1 : 0); return(str); } if(!strcmp(sp,"DR")) { safe_snprintf(str,maxlen,"%4u",usrlibs ? curdir[curlib]+1 : 0); return(str); } if(!strcmp(sp,"NOACCESS")) { if(noaccess_str==text[NoAccessTime]) safe_snprintf(str,maxlen,noaccess_str,noaccess_val/60,noaccess_val%60); else if(noaccess_str==text[NoAccessDay]) safe_snprintf(str,maxlen,noaccess_str,wday[noaccess_val]); else safe_snprintf(str,maxlen,noaccess_str,noaccess_val); return(str); } if(!strcmp(sp,"LAST")) { tp=strrchr(useron.alias,' '); if(tp) tp++; else tp=useron.alias; return(tp); } if(!strcmp(sp,"REAL") || !strcmp(sp,"FIRSTREAL")) { safe_snprintf(str,maxlen,"%s",useron.name); tp=strchr(str,' '); if(tp) *tp=0; return(str); } if(!strcmp(sp,"LASTREAL")) { tp=strrchr(useron.name,' '); if(tp) tp++; else tp=useron.name; return(tp); } if(!strcmp(sp,"MAILW")) { safe_snprintf(str,maxlen,"%u",getmail(&cfg,useron.number,0)); return(str); } if(!strcmp(sp,"MAILP")) { safe_snprintf(str,maxlen,"%u",getmail(&cfg,useron.number,1)); return(str); } if(!strncmp(sp,"MAILW:",6)) { safe_snprintf(str,maxlen,"%u",getmail(&cfg,atoi(sp+6),0)); return(str); } if(!strncmp(sp,"MAILP:",6)) { safe_snprintf(str,maxlen,"%u",getmail(&cfg,atoi(sp+6),1)); return(str); } if(!strcmp(sp,"MSGREPLY")) { safe_snprintf(str,maxlen,"%c",cfg.sys_misc&SM_RA_EMU ? 'R' : 'A'); return(str); } if(!strcmp(sp,"MSGREREAD")) { safe_snprintf(str,maxlen,"%c",cfg.sys_misc&SM_RA_EMU ? 'A' : 'R'); return(str); } if(!strncmp(sp,"STATS.",6)) { getstats(&cfg,0,&stats); sp+=6; if(!strcmp(sp,"LOGONS")) safe_snprintf(str,maxlen,"%lu",stats.logons); else if(!strcmp(sp,"LTODAY")) safe_snprintf(str,maxlen,"%lu",stats.ltoday); else if(!strcmp(sp,"TIMEON")) safe_snprintf(str,maxlen,"%lu",stats.timeon); else if(!strcmp(sp,"TTODAY")) safe_snprintf(str,maxlen,"%lu",stats.ttoday); else if(!strcmp(sp,"ULS")) safe_snprintf(str,maxlen,"%lu",stats.uls); else if(!strcmp(sp,"ULB")) safe_snprintf(str,maxlen,"%lu",stats.ulb); else if(!strcmp(sp,"DLS")) safe_snprintf(str,maxlen,"%lu",stats.dls); else if(!strcmp(sp,"DLB")) safe_snprintf(str,maxlen,"%lu",stats.dlb); else if(!strcmp(sp,"PTODAY")) safe_snprintf(str,maxlen,"%lu",stats.ptoday); else if(!strcmp(sp,"ETODAY")) safe_snprintf(str,maxlen,"%lu",stats.etoday); else if(!strcmp(sp,"FTODAY")) safe_snprintf(str,maxlen,"%lu",stats.ftoday); else if(!strcmp(sp,"NUSERS")) safe_snprintf(str,maxlen,"%u",stats.nusers); return(str); } /* Message header codes */ if(!strcmp(sp,"MSG_TO") && current_msg!=NULL) { if(current_msg->to==NULL) return(nulstr); if(current_msg->to_ext!=NULL) safe_snprintf(str,maxlen,"%s #%s",current_msg->to,current_msg->to_ext); else if(current_msg->to_net.type!=NET_NONE) { char tmp[128]; safe_snprintf(str,maxlen,"%s (%s)",current_msg->to ,smb_netaddrstr(¤t_msg->to_net,tmp)); } else return(current_msg->to); return(str); } if(!strcmp(sp,"MSG_TO_NAME") && current_msg!=NULL) return(current_msg->to==NULL ? nulstr : current_msg->to); if(!strcmp(sp,"MSG_TO_EXT") && current_msg!=NULL) { if(current_msg->to_ext==NULL) return(nulstr); return(current_msg->to_ext); } if(!strcmp(sp,"MSG_TO_NET") && current_msg!=NULL) return(smb_netaddrstr(¤t_msg->to_net,str)); if(!strcmp(sp,"MSG_FROM") && current_msg!=NULL) { if(current_msg->from==NULL) return(nulstr); if(current_msg->hdr.attr&MSG_ANONYMOUS && !SYSOP) return(text[Anonymous]); if(current_msg->from_ext!=NULL) safe_snprintf(str,maxlen,"%s #%s",current_msg->from,current_msg->from_ext); else if(current_msg->from_net.type!=NET_NONE) { char tmp[128]; safe_snprintf(str,maxlen,"%s (%s)",current_msg->from ,smb_netaddrstr(¤t_msg->from_net,tmp)); } else return(current_msg->from); return(str); } if(!strcmp(sp,"MSG_FROM_NAME") && current_msg!=NULL) { if(current_msg->from==NULL) return(nulstr); if(current_msg->hdr.attr&MSG_ANONYMOUS && !SYSOP) return(text[Anonymous]); return(current_msg->from); } if(!strcmp(sp,"MSG_FROM_EXT") && current_msg!=NULL) { if(!(current_msg->hdr.attr&MSG_ANONYMOUS) || SYSOP) if(current_msg->from_ext!=NULL) return(current_msg->from_ext); return(nulstr); } if(!strcmp(sp,"MSG_FROM_NET") && current_msg!=NULL) { if(current_msg->from_net.type!=NET_NONE && (!(current_msg->hdr.attr&MSG_ANONYMOUS) || SYSOP)) return(smb_netaddrstr(¤t_msg->from_net,str)); return(nulstr); } if(!strcmp(sp,"MSG_SUBJECT") && current_msg!=NULL) return(current_msg->subj==NULL ? nulstr : current_msg->subj); if(!strcmp(sp,"MSG_DATE") && current_msg!=NULL) return(timestr(current_msg->hdr.when_written.time)); if(!strcmp(sp,"MSG_TIMEZONE") && current_msg!=NULL) return(smb_zonestr(current_msg->hdr.when_written.zone,NULL)); if(!strcmp(sp,"MSG_ATTR") && current_msg!=NULL) { safe_snprintf(str,maxlen,"%s%s%s%s%s%s%s%s%s%s%s" ,current_msg->hdr.attr&MSG_PRIVATE ? "Private " :nulstr ,current_msg->hdr.attr&MSG_READ ? "Read " :nulstr ,current_msg->hdr.attr&MSG_DELETE ? "Deleted " :nulstr ,current_msg->hdr.attr&MSG_KILLREAD ? "Kill " :nulstr ,current_msg->hdr.attr&MSG_ANONYMOUS ? "Anonymous " :nulstr ,current_msg->hdr.attr&MSG_LOCKED ? "Locked " :nulstr ,current_msg->hdr.attr&MSG_PERMANENT ? "Permanent " :nulstr ,current_msg->hdr.attr&MSG_MODERATED ? "Moderated " :nulstr ,current_msg->hdr.attr&MSG_VALIDATED ? "Validated " :nulstr ,current_msg->hdr.attr&MSG_REPLIED ? "Replied " :nulstr ,current_msg->hdr.attr&MSG_NOREPLY ? "NoReply " :nulstr ); return(str); } if(!strcmp(sp,"MSG_ID") && current_msg!=NULL) return(current_msg->id==NULL ? nulstr : current_msg->id); if(!strcmp(sp,"MSG_REPLY_ID") && current_msg!=NULL) return(current_msg->reply_id==NULL ? nulstr : current_msg->reply_id); if(!strcmp(sp,"MSG_NUM") && current_msg!=NULL) { safe_snprintf(str,maxlen,"%lu",current_msg->hdr.number); return(str); } if(!strcmp(sp,"SMB_AREA")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) safe_snprintf(str,maxlen,"%s %s" ,cfg.grp[cfg.sub[smb.subnum]->grp]->sname ,cfg.sub[smb.subnum]->sname); return(str); } if(!strcmp(sp,"SMB_AREA_DESC")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) safe_snprintf(str,maxlen,"%s %s" ,cfg.grp[cfg.sub[smb.subnum]->grp]->lname ,cfg.sub[smb.subnum]->lname); return(str); } if(!strcmp(sp,"SMB_GROUP")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) return(cfg.grp[cfg.sub[smb.subnum]->grp]->sname); return(nulstr); } if(!strcmp(sp,"SMB_GROUP_DESC")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) return(cfg.grp[cfg.sub[smb.subnum]->grp]->lname); return(nulstr); } if(!strcmp(sp,"SMB_GROUP_NUM")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) safe_snprintf(str,maxlen,"%u",getusrgrp(smb.subnum)); return(str); } if(!strcmp(sp,"SMB_SUB")) { if(smb.subnum==INVALID_SUB) return("Mail"); else if(smb.subnum<cfg.total_subs) return(cfg.sub[smb.subnum]->sname); return(nulstr); } if(!strcmp(sp,"SMB_SUB_DESC")) { if(smb.subnum==INVALID_SUB) return("Mail"); else if(smb.subnum<cfg.total_subs) return(cfg.sub[smb.subnum]->lname); return(nulstr); } if(!strcmp(sp,"SMB_SUB_CODE")) { if(smb.subnum==INVALID_SUB) return("MAIL"); else if(smb.subnum<cfg.total_subs) return(cfg.sub[smb.subnum]->code); return(nulstr); } if(!strcmp(sp,"SMB_SUB_NUM")) { if(smb.subnum!=INVALID_SUB && smb.subnum<cfg.total_subs) safe_snprintf(str,maxlen,"%u",getusrsub(smb.subnum)); return(str); } if(!strcmp(sp,"SMB_MSGS")) { safe_snprintf(str,maxlen,"%ld",smb.msgs); return(str); } if(!strcmp(sp,"SMB_CURMSG")) { safe_snprintf(str,maxlen,"%ld",smb.curmsg+1); return(str); } if(!strcmp(sp,"SMB_LAST_MSG")) { safe_snprintf(str,maxlen,"%lu",smb.status.last_msg); return(str); } if(!strcmp(sp,"SMB_MAX_MSGS")) { safe_snprintf(str,maxlen,"%lu",smb.status.max_msgs); return(str); } if(!strcmp(sp,"SMB_MAX_CRCS")) { safe_snprintf(str,maxlen,"%lu",smb.status.max_crcs); return(str); } if(!strcmp(sp,"SMB_MAX_AGE")) { safe_snprintf(str,maxlen,"%hu",smb.status.max_age); return(str); } if(!strcmp(sp,"SMB_TOTAL_MSGS")) { safe_snprintf(str,maxlen,"%lu",smb.status.total_msgs); return(str); } return(NULL); }
void sbbs_t::telnet_gate(char* destaddr, ulong mode, char* client_user_name, char* server_user_name, char* term_type) { char* p; uchar buf[512]; int i; int rd; uint attempts; ulong l; bool gotline; ushort port; ulong ip_addr; ulong save_console; SOCKET remote_socket; SOCKADDR_IN addr; if(mode&TG_RLOGIN) port=513; else port=IPPORT_TELNET; p=strchr(destaddr,':'); if(p!=NULL) { *p=0; port=atoi(p+1); } ip_addr=resolve_ip(destaddr); if(ip_addr==INADDR_NONE) { lprintf(LOG_NOTICE,"!TELGATE Failed to resolve address: %s",destaddr); bprintf("!Failed to resolve address: %s\r\n",destaddr); return; } if((remote_socket = open_socket(SOCK_STREAM, client.protocol)) == INVALID_SOCKET) { errormsg(WHERE,ERR_OPEN,"socket",0); return; } memset(&addr,0,sizeof(addr)); addr.sin_addr.s_addr = htonl(startup->telnet_interface); addr.sin_family = AF_INET; if((i=bind(remote_socket, (struct sockaddr *) &addr, sizeof (addr)))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) binding to socket %d",i, ERROR_VALUE, remote_socket); bprintf("!ERROR %d (%d) binding to socket\r\n",i, ERROR_VALUE); close_socket(remote_socket); return; } memset(&addr,0,sizeof(addr)); addr.sin_addr.s_addr = ip_addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); if((i=connect(remote_socket, (struct sockaddr *)&addr, sizeof(addr)))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) connecting to server: %s" ,i,ERROR_VALUE, destaddr); bprintf("!ERROR %d (%d) connecting to server: %s\r\n" ,i,ERROR_VALUE, destaddr); close_socket(remote_socket); return; } l=1; if((i = ioctlsocket(remote_socket, FIONBIO, &l))!=0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d (%d) disabling socket blocking" ,i, ERROR_VALUE); close_socket(remote_socket); return; } lprintf(LOG_INFO,"Node %d %s gate to %s port %u on socket %d" ,cfg.node_num ,mode&TG_RLOGIN ? "RLogin" : "Telnet" ,destaddr,port,remote_socket); if(!(mode&TG_CTRLKEYS)) console|=CON_RAW_IN; if(mode&TG_RLOGIN) { p=(char*)buf; *(p++)=0; p+=sprintf(p,"%s",client_user_name==NULL ? useron.alias : client_user_name); p++; // Add NULL p+=sprintf(p,"%s",server_user_name==NULL ? useron.name : server_user_name); p++; // Add NULL if(term_type!=NULL) p+=sprintf(p,"%s",term_type); else p+=sprintf(p,"%s/%u",terminal, cur_rate); p++; // Add NULL l=p-(char*)buf; sendsocket(remote_socket,(char*)buf,l); mode|=TG_NOLF; /* Send LF (to remote host) when Telnet client sends CRLF (when not in binary mode) */ } /* This is required for gating to Unix telnetd */ if(mode&TG_NOTERMTYPE) request_telnet_opt(TELNET_DONT,TELNET_TERM_TYPE, 3000); // Re-negotiation of terminal type /* Text/NVT mode by default */ request_telnet_opt(TELNET_DONT,TELNET_BINARY_TX, 3000); if(!(telnet_mode&TELNET_MODE_OFF) && (mode&TG_PASSTHRU)) telnet_mode|=TELNET_MODE_GATE; // Pass-through telnet commands while(online) { if(!(mode&TG_NOCHKTIME)) gettimeleft(); rd=RingBufRead(&inbuf,buf,sizeof(buf)); if(rd) { #if 0 if(memchr(buf,TELNET_IAC,rd)) { char dump[2048]; dump[0]; p=dump; for(int i=0;i<rd;i++) p+=sprintf(p,"%u ",buf[i]); lprintf(LOG_DEBUG,"Node %d Telnet cmd from client: %s", cfg.node_num, dump); } #endif if(telnet_remote_option[TELNET_BINARY_TX]!=TELNET_WILL) { if(*buf==0x1d) { // ^] save_console=console; console&=~CON_RAW_IN; // Allow Ctrl-U/Ctrl-P CRLF; while(online) { SYNC; mnemonics("\1n\r\n\1h\1bTelnet Gate: \1y~D\1wisconnect, " "\1y~E\1wcho toggle, \1y~L\1wist Users, \1y~P\1wrivate message, " "\1y~Q\1wuit: "); switch(getkeys("DELPQ",0)) { case 'D': closesocket(remote_socket); break; case 'E': mode^=TG_ECHO; bprintf(text[EchoIsNow] ,mode&TG_ECHO ? text[ON]:text[OFF]); continue; case 'L': whos_online(true); continue; case 'P': nodemsg(); continue; } break; } attr(LIGHTGRAY); console=save_console; } else if(*buf<' ' && (mode&TG_CTRLKEYS)) handle_ctrlkey(*buf, K_NONE); gotline=false; if((mode&TG_LINEMODE) && buf[0]!='\r') { ungetkey(buf[0]); l=K_CHAT; if(!(mode&TG_ECHO)) l|=K_NOECHO; rd=getstr((char*)buf,sizeof(buf)-1,l); if(!rd) continue; strcat((char*)buf,crlf); rd+=2; gotline=true; } if((mode&TG_CRLF) && buf[rd-1]=='\r') buf[rd++]='\n'; else if((mode&TG_NOLF) && buf[rd-1]=='\n') rd--; if(!gotline && (mode&TG_ECHO) && rd) { RingBufWrite(&outbuf,buf,rd); } } /* Not Telnet Binary mode */ if(rd > 0) { for(attempts=0;attempts<60 && online; attempts++) /* added retry loop here, Jan-20-2003 */ { if((i=sendsocket(remote_socket,(char*)buf,rd))>=0) break; if(ERROR_VALUE!=EWOULDBLOCK) break; mswait(500); } if(i<0) { lprintf(LOG_NOTICE,"!TELGATE ERROR %d sending on socket %d",ERROR_VALUE,remote_socket); break; } } } rd=recv(remote_socket,(char*)buf,sizeof(buf),0); if(rd<0) { if(ERROR_VALUE==EWOULDBLOCK) { if(mode&TG_NODESYNC) { SYNC; } else { // Check if the node has been interrupted getnodedat(cfg.node_num,&thisnode,0); if(thisnode.misc&NODE_INTR) break; } YIELD(); continue; } lprintf(LOG_NOTICE,"!TELGATE ERROR %d receiving on socket %d",ERROR_VALUE,remote_socket); break; } if(!rd) { lprintf(LOG_INFO,"Node %d Telnet gate disconnected",cfg.node_num); break; } #if 0 if(memchr(buf,TELNET_IAC,rd)) { char dump[2048]; dump[0]; p=dump; for(int i=0;i<rd;i++) p+=sprintf(p,"%u ",buf[i]); lprintf(LOG_DEBUG,"Node %d Telnet cmd from server: %s", cfg.node_num, dump); } #endif RingBufWrite(&outbuf,buf,rd); } console&=~CON_RAW_IN; telnet_mode&=~TELNET_MODE_GATE; /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); close_socket(remote_socket); lprintf(LOG_INFO,"Node %d Telnet gate to %s finished",cfg.node_num,destaddr); }
// Displays a list of users on-line on the BBS. void listOnlineUsers() { whos_online(1); }