389 lines
8.5 KiB
C
389 lines
8.5 KiB
C
/*
|
|
* binkleyforce -- unix FTN mailer project
|
|
*
|
|
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "confread.h"
|
|
#include "logger.h"
|
|
#include "util.h"
|
|
#include "nodelist.h"
|
|
#define DEF_DOMAIN "fidonet.org"
|
|
/*
|
|
* Our fake expressions checker. Allways return FALSE (?)
|
|
*/
|
|
bool eventexpr(s_expr *expr)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
static void usage(void)
|
|
{
|
|
printf_usage("nodelist lookup utility",
|
|
"usage: nlookup [-C config] [-romh] <address>\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -r show nodelist string\n"
|
|
" -m show email address\n"
|
|
" -o show overrides\n"
|
|
" -t show calltable\n"
|
|
" -h show this help message\n"
|
|
" -C config use config file\n"
|
|
"\n"
|
|
);
|
|
}
|
|
|
|
void print_nodemail(const s_node *node)
|
|
{
|
|
char abuf[BF_MAXADDRSTR+1];
|
|
|
|
if( *node->sysop && strcmp(node->sysop, "<none>") )
|
|
{
|
|
char username[BNI_MAXSYSOP+1];
|
|
|
|
strnxcpy(username, node->sysop, sizeof(node->sysop));
|
|
string_replchar(username, ' ', '_');
|
|
|
|
printf("%s@%s.fidonet.org\n", username,
|
|
ftn_addrstr_inet(abuf, node->addr));
|
|
}
|
|
|
|
fflush(stdout);
|
|
}
|
|
|
|
void print_nodeinfo(const s_node *node)
|
|
{
|
|
char abuf[BF_MAXADDRSTR+1];
|
|
char status[6]; /* Maximum size for node keyword, see
|
|
* nodelist.c for details */
|
|
|
|
printf("Address : %s\n", ftn_addrstr(abuf, node->addr));
|
|
printf("System : %s\n", node->name);
|
|
printf("Phone : %s\n", node->phone);
|
|
printf("Sysop : %s\n", node->sysop);
|
|
printf("Location : %s\n", node->location);
|
|
printf("Speed : %ld\n", node->speed);
|
|
printf("Flags : %s\n", node->flags);
|
|
|
|
if( node->worktime.num )
|
|
{
|
|
char timebuf[80];
|
|
time_t unixtime = time(NULL);
|
|
struct tm *now = localtime(&unixtime);
|
|
|
|
timevec_string(timebuf, &node->worktime, sizeof(timebuf));
|
|
|
|
printf("Work time : %s (%s)\n", timebuf,
|
|
timevec_check(&node->worktime, now) ? "false" : "true");
|
|
}
|
|
|
|
if( (node->keyword != KEYWORD_POINT) && *node->sysop && strcmp(node->sysop, "<none>") )
|
|
{
|
|
char username[BNI_MAXSYSOP+1];
|
|
|
|
strnxcpy(username, node->sysop, sizeof(node->sysop));
|
|
string_replchar(username, ' ', '_');
|
|
|
|
printf("E-mail : %s@%s\n", username,
|
|
ftn_addrstr_inet(abuf, node->addr));
|
|
}
|
|
switch( node->keyword ) {
|
|
case KEYWORD_HOLD :
|
|
strcpy(status,"Hold");
|
|
break;
|
|
case KEYWORD_DOWN :
|
|
strcpy(status,"Down");
|
|
break;
|
|
case KEYWORD_HUB :
|
|
strcpy(status,"Hub");
|
|
break;
|
|
case KEYWORD_HOST :
|
|
strcpy(status,"Host");
|
|
break;
|
|
case KEYWORD_PVT :
|
|
strcpy(status,"Pvt");
|
|
break;
|
|
case KEYWORD_BOSS :
|
|
strcpy(status,"Boss");
|
|
break;
|
|
case KEYWORD_POINT :
|
|
strcpy(status,"Point");
|
|
break;
|
|
default:
|
|
strcpy(status,"Node");
|
|
break;
|
|
}
|
|
printf("Type : %s\n",status);
|
|
fflush(stdout);
|
|
}
|
|
|
|
void print_overrides(const s_override *override_info)
|
|
{
|
|
s_override *p;
|
|
char abuf[BF_MAXADDRSTR+1];
|
|
int lin = 0;
|
|
printf("----------- Overrides ------------\n");
|
|
printf("Address : %s\n", ftn_addrstr(abuf, override_info->addr));
|
|
printf("IpAddr : %s\n", override_info->sIpaddr);
|
|
printf("Phone : %s\n", override_info->sPhone);
|
|
printf("Flags : %s\n", override_info->sFlags);
|
|
printf("Run before: %s\n", override_info->run);
|
|
p = override_info->hidden;
|
|
if (p) {
|
|
printf("Hidden lines:\n");
|
|
|
|
while( p )
|
|
{
|
|
printf(" %5d: ",++lin);
|
|
if (p->sIpaddr) printf("IpAddr: %s, ", p->sIpaddr);
|
|
if (p->sPhone) printf("Phone: %s", p->sPhone);
|
|
if (p->sFlags) printf("Flags: %s", p->sFlags);
|
|
printf("\n");
|
|
p = p->hidden;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool check_phone(const char *str)
|
|
{
|
|
if( !str || !str[0] )
|
|
return FALSE;
|
|
|
|
if( str[0] == '-' && str[1] == '\0' )
|
|
return FALSE;
|
|
|
|
if( string_casestr(str, "unpublished") )
|
|
return FALSE;
|
|
|
|
if( string_casestr(str, "unknown") )
|
|
return FALSE;
|
|
|
|
if( string_casestr(str, "none") )
|
|
return FALSE;
|
|
|
|
if( string_casestr(str, "00-00-000000") )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void print_calltable(s_faddr addr){
|
|
s_node nnode;
|
|
s_override *ovr, *tmpovr;
|
|
char *tmphost, *tmpphone;
|
|
int rc,ln = 0;
|
|
|
|
|
|
if( nodelist_lookup(&nnode, addr) == 0 )
|
|
{
|
|
// we got nodelist string
|
|
ovr = conf_override(cf_override, addr);
|
|
// be aware - ovr may not be, but second INA may
|
|
if (ovr) {
|
|
ovr->addr = addr;
|
|
if (ovr->sIpaddr) strcpy (nnode.host, ovr->sIpaddr);
|
|
if (ovr->sPhone) strcpy (nnode.phone, ovr->sPhone);
|
|
if (ovr->sFlags) strcpy (nnode.flags, ovr->sFlags);
|
|
} else {
|
|
ovr = xmalloc(sizeof(s_override));
|
|
memset(ovr,'\0',sizeof(s_override));
|
|
ovr->addr=addr;
|
|
ovr->hidden=NULL;
|
|
ovr->sIpaddr=NULL;
|
|
}
|
|
rc = nodelist_parsehiddenina(&nnode, ovr);
|
|
|
|
} else {
|
|
// we have no nodelist string - only overrides
|
|
ovr = conf_override(cf_override, addr);
|
|
if (ovr) {
|
|
ovr->addr = addr;
|
|
if (ovr->sIpaddr) strcpy (nnode.host, ovr->sIpaddr);
|
|
if (ovr->sPhone) strcpy (nnode.phone, ovr->sPhone);
|
|
if (ovr->sFlags) strcpy (nnode.flags, ovr->sFlags);
|
|
}
|
|
}
|
|
// Let's print this table
|
|
// begin with HOST itself
|
|
ln = 0;
|
|
if (nnode.host[0]) {
|
|
tmphost = nnode.host;
|
|
}
|
|
if (!nodelist_checkflag(nnode.flags, "IBN")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:binkp\n", ln, tmphost);
|
|
}
|
|
if (!nodelist_checkflag(nnode.flags, "IFC")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:ifcico\n", ln, tmphost);
|
|
}
|
|
if (!nodelist_checkflag(nnode.flags, "ITN")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:telnet\n", ln, tmphost);
|
|
}
|
|
if (ovr->hidden) {
|
|
tmpovr = ovr;
|
|
while (ovr->hidden != NULL) {
|
|
ovr = ovr->hidden;
|
|
if (ovr->sIpaddr) {
|
|
tmphost = ovr->sIpaddr;
|
|
if (!nodelist_checkflag(nnode.flags, "IBN")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:binkp\n", ln, tmphost);
|
|
}
|
|
if (!nodelist_checkflag(nnode.flags, "IFC")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:ifcico\n", ln, tmphost);
|
|
}
|
|
if (!nodelist_checkflag(nnode.flags, "ITN")) {
|
|
ln +=1;
|
|
printf ("%5d. %s:telnet\n", ln, tmphost);
|
|
}
|
|
}
|
|
}
|
|
ovr = tmpovr;
|
|
}
|
|
|
|
// Calltable for pstn
|
|
if (nnode.phone[0] && check_phone(nnode.phone) ) {
|
|
tmpphone = nnode.phone;
|
|
ln +=1;
|
|
printf ("%5d. PSTN %s\n", ln, tmpphone);
|
|
if (ovr->hidden) {
|
|
tmpovr = ovr;
|
|
while (ovr->hidden != NULL) {
|
|
ovr = ovr->hidden;
|
|
if (ovr->sPhone && check_phone(ovr->sPhone)) {
|
|
tmpphone = ovr->sPhone;
|
|
ln +=1;
|
|
printf ("%5d. PSTN %s\n", ln, tmpphone);
|
|
}
|
|
}
|
|
ovr = tmpovr;
|
|
}
|
|
}
|
|
// free ovr elements
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
s_node node;
|
|
s_faddr addr;
|
|
s_override *ovr;
|
|
char ch;
|
|
int rc = 0;
|
|
char *confname = NULL;
|
|
bool rawstring = FALSE;
|
|
bool emailaddr = FALSE;
|
|
bool overrides = FALSE;
|
|
bool calltable = FALSE;
|
|
|
|
/* Initialise random number generation */
|
|
(void)srand((unsigned)time(0));
|
|
/* Initialise current locale */
|
|
(void)setlocale(LC_ALL, "");
|
|
|
|
while( (ch=getopt(argc, argv, "hdrtmoC:")) != (char)-1 )
|
|
{
|
|
switch( ch ) {
|
|
case 'h':
|
|
usage();
|
|
exit(BFERR_NOERROR);
|
|
case 'r':
|
|
rawstring = TRUE;
|
|
break;
|
|
case 'm':
|
|
emailaddr = TRUE;
|
|
break;
|
|
case 't':
|
|
calltable = TRUE;
|
|
break;
|
|
case 'o':
|
|
overrides = TRUE;
|
|
break;
|
|
case 'C':
|
|
if( confname || !optarg ) { usage(); exit(BFERR_FATALERROR); }
|
|
confname = (char *)xstrcpy(optarg);
|
|
break;
|
|
default:
|
|
usage();
|
|
exit(BFERR_FATALERROR);
|
|
}
|
|
}
|
|
|
|
if( optind >= argc || ftn_addrparse(&addr, argv[optind], FALSE) )
|
|
{
|
|
usage();
|
|
exit(BFERR_FATALERROR);
|
|
}
|
|
|
|
if( confname && *confname )
|
|
rc = conf_readconf(confname, 0, false);
|
|
else
|
|
rc = conf_readconf(conf_getconfname(), 0, false);
|
|
|
|
if( rc )
|
|
{
|
|
DEB((D_NODELIST,"nlookup: Can not find config"));
|
|
exit(BFERR_FATALERROR);
|
|
}
|
|
|
|
DEB((D_NODELIST,"Starting nlookup"));
|
|
|
|
if( rawstring )
|
|
{
|
|
char buf[512];
|
|
|
|
if( nodelist_lookup_string(buf, sizeof(buf), addr) == 0 )
|
|
printf("%s\n", buf);
|
|
}
|
|
else if( nodelist_lookup(&node, addr) == 0 )
|
|
{
|
|
// Overrides
|
|
ovr = conf_override(cf_override, addr);
|
|
|
|
if (addr.point == 0) {
|
|
if( emailaddr )
|
|
print_nodemail(&node);
|
|
else
|
|
print_nodeinfo(&node);
|
|
}
|
|
else
|
|
{
|
|
print_nodeinfo(&node);
|
|
}
|
|
if (overrides && ovr) {
|
|
print_overrides(ovr);
|
|
}
|
|
if (calltable) {
|
|
printf ("----------- Calltable ------------\n");
|
|
print_calltable(addr);
|
|
}
|
|
} else {
|
|
if (overrides) {
|
|
ovr = conf_override(cf_override, addr);
|
|
if (ovr) {
|
|
printf ("-------- No nodelist info --------");
|
|
print_overrides(ovr);
|
|
if (calltable) {
|
|
printf ("----- Calltable-on-overrides -----\n");
|
|
print_calltable(addr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
deinit_conf();
|
|
|
|
exit(0);
|
|
}
|