Beispiel #1
0
int chatlog_init(char *remname,ftnaddr_t *ra,int side)
{
	FILE *chatlog=NULL;
	time_t tt;struct tm *t;
	char str[MAX_STRING]={0};
	write_log("Chat opened%s",side?" by remote side":"");
	adr=&cfgal(CFG_ADDRESS)->addr;
	if(cfgs(CFG_RUNONCHAT)&&side)execnowait("/bin/sh","-c",ccs,ftnaddrtoa(adr));
	if(cfgi(CFG_CHATLOGNETMAIL)) {
		snprintf(pktname,MAX_PATH-1,"%s/tmp/%08lx.pkt",cfgs(CFG_INBOUND),sequencer());
		cpkt=openpktmsg(adr,adr,"qico chat-log poster",xstrdup(cfgs(CFG_SYSOP)),"log of chat",NULL,pktname,137);
		if(!cpkt)write_log("can't open '%s' for writing",pktname);
	}
	if(cfgs(CFG_CHATTOEMAIL)) {
		snprintf(str,MAX_PATH,"/tmp/qlemail.%04lx",(long)getpid());
		lemail=fopen(str,"wt");
		if(!lemail)write_log("can't crearte temporary email-log file");
	}
	if(cfgs(CFG_CHATLOG))chatlog=fopen(ccs,"at");
	if(ccs&&!chatlog)write_log("can't open chat log %s",ccs);
	tt=time(NULL);t=localtime(&tt);
	snprintf(str,MAX_STRING,"[Chat with: %s (%u:%u/%u.%u) open by %s at ",remname,ra->z,ra->n,ra->f,ra->p,side?"remote":"my");
	strftime(str+strlen(str),MAX_STRING-1,"%d %b %y %H:%M:%S]\n",t);
	if(chatlog){fwrite(str,strlen(str),1,chatlog);fclose(chatlog);}
	if(lemail)fwrite(str,strlen(str),1,lemail);
	if(cpkt) {
		if(cfgi(CFG_RECODEPKTS))recode_to_remote(str);
		strtr(str,'\n','\r');
		fwrite(str,strlen(str),1,cpkt);
		runtoss=1;
	}
	mcpos=rcpos=0;*rchat=0;*mchat=0;
	return(cpkt!=NULL||chatlog!=NULL||lemail!=NULL);
}
Beispiel #2
0
int freq_ifextrp(slist_t *reqs)
{
    FILE *f, *g, *r;
    char s[MAX_PATH], fn[MAX_PATH], sfn[MAX_PATH], *ss;
    char priv = 'a', *p, *sprt = "UNPROTEC", *slst = "UNLIS";
    int got = 0, wz = cfgs( CFG_EXTRP ) ? 1 : 0, kil;
    long tpid = (long) getpid();
    ftnaddr_t *ma = akamatch( &rnode->addrs->addr, cfgal( CFG_ADDRESS ));

    DEBUG(('R',1,"Freq received"));

    if ( rnode->options & O_LST ) {
        priv = 'l';
        slst += 2;
    }
    if( rnode->options & O_PWD ) {
        priv = 'p';
        sprt += 2;
    }
    
    snprintf( fn, MAX_PATH, "/tmp/qreq.%04lx", tpid );
    if( !( f = fopen( fn, "wt" ))) {
        write_log( "can't open '%s' for writing: %s", fn, strerror( errno ));
        return 0;
    }

    while( reqs ) {
        if ( cfgs( CFG_MAPIN ) && strchr( ccs, 'r' ))
            recode_to_local( reqs->str );
        DEBUG(('R',1,"requested '%s'", reqs->str));
        fprintf( f, "%s\n", reqs->str );
        reqs = reqs->next;
    }
    fclose( f );
    if(!wz) {
        falist_t *ra;
        snprintf(sfn,MAX_PATH,"/tmp/qsrif.%04lx",tpid);
        if(!(r=fopen(sfn,"wt"))){write_log("can't open '%s' for writing: %s",sfn,strerror(errno));return 0;}
        fprintf(r,"SessionType %s\n",bink?"OTHER":"EMSI");
        fprintf(r,"Sysop %s\n",rnode->sysop);
        for(ra=rnode->addrs;ra;ra=ra->next)fprintf(r,"AKA %s\n",ftnaddrtoa(&ra->addr));
        if(!is_ip)fprintf(r,"Baud %d\n",rnode->realspeed);
        fprintf(r,"Time -1\n");
        fprintf(r,"RemoteStatus %sTED\n",sprt);
        fprintf(r,"SystemStatus %sTED\n",slst);
        fprintf(r,"RequestList /tmp/qreq.%04lx\n",tpid);
        fprintf(r,"ResponseList /tmp/qfls.%04lx\n",tpid);
        fprintf(r,"Location %s\n",rnode->place);
        if(rnode->phone&&*rnode->phone)fprintf(r,"Phone %s\n",rnode->phone);
        if(rnode->options&O_PWD)fprintf(r,"Password %s\n",rnode->pwd);
        fprintf(r,"Mailer %s\n",rnode->mailer);
        fprintf(r,"Site %s\n",rnode->name);
        if(!is_ip&&(ss=getenv("CALLER_ID"))&&strcasecmp(ss,"none")&&strlen(ss)>3)fprintf(r,"CallerID %s\n",ss);
        fprintf(r,"OurAKA %s\n",ftnaddrtoa(ma));
        fprintf(r,"TRANX %08lu\n",time(NULL));
        fclose(r);
        snprintf(s,MAX_PATH,"%s %s",cfgs(CFG_SRIFRP),sfn);
    } else snprintf(s,MAX_PATH,"%s -wazoo -%c -s%d %s /tmp/qreq.%04lx /tmp/qfls.%04lx /tmp/qrep.%04lx",
            cfgs(CFG_EXTRP),priv,rnode->realspeed,ftnaddrtoa(&rnode->addrs->addr),tpid,tpid,tpid);
    write_log("exec '%s' returned rc=%d",s,execsh(s));
    lunlink(fn);lunlink(sfn);
    snprintf(fn,MAX_PATH,"/tmp/qfls.%04lx",tpid);
    if(!(f=fopen(fn,"rt"))) {
        snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid);
        lunlink(fn);
        snprintf(fn,MAX_PATH,"/tmp/qfls.%04lx",tpid);
        lunlink(fn);
        write_log("can't open '%s' for reading",fn);
        return 0;
    }
    while(fgets(s,MAX_PATH-1,f)) {
        if(*s=='\n'||*s=='\r'||*s==' '||!*s)continue;
        ss=s;kil=0;got=1;
        if(*s=='='||*s=='-'){ss++;kil=1;}
            else if(*s=='+')ss++;
        p=ss+strlen(ss)-1;
        while(*p=='\r'||*p=='\n')*p--=0;
        p=strrchr(ss,' ');
        if(p)*p++=0;else p=ss;
        DEBUG(('R',1,"sending '%s' as '%s'%s",ss,qbasename((p!=ss)?p:ss),kil?" and kill":""));
        addflist(&fl,xstrdup(ss),xstrdup(qbasename((p!=ss)?p:ss)),kil?'^':' ',0,NULL,0);
    }
    fclose(f);lunlink(fn);
    snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid);
    if(!(f=fopen(fn,"rt"))&&wz)write_log("can't open '%s' for reading",fn);
    snprintf(fn,MAX_PATH,"/tmp/qpkt.%04lx%02x",tpid,++freq_pktcount);
    g=openpktmsg(ma,&rnode->addrs->addr,cfgs(CFG_FREQFROM),rnode->sysop,cfgs(CFG_FREQSUBJ),NULL,fn,1);
    if(!g) {
        write_log("can't open '%s' for writing: %s",fn,strerror(errno));
        if(f)fclose(f);
        freq_pktcount--;
    }
    if(f&&g) {
        while(fgets(s,MAX_PATH-1,f)) {
            p=s+strlen(s)-1;
            while(*p=='\r'||*p=='\n')*p--=0;
            if(cfgi(CFG_RECODEPKTS))recode_to_remote(s);
            fputs(s,g);fputc('\r',g);
        }
        fclose(f);
        closeqpkt(g,ma);
        snprintf(s,MAX_PATH,"/tmp/qpkt.%04lx%02x",tpid,freq_pktcount);
        p=xstrdup(s);
        snprintf(s,MAX_PATH,"%08lx.pkt",sequencer());
        addflist(&fl,p,xstrdup(s),'^',0,NULL,1);
    }
    snprintf(fn,MAX_PATH,"/tmp/qrep.%04lx",tpid);
    lunlink(fn);
    return got;
}