add support for default ports
This commit is contained in:
parent
810adc864d
commit
45124e818c
4 changed files with 111 additions and 107 deletions
12
exempts.c
12
exempts.c
|
@ -68,9 +68,8 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
strlcpy(exempts->who, cmdparams->source->name, MAXNICK);
|
||||
buf = joinbuf(cmdparams->av, cmdparams->ac, 3);
|
||||
strlcpy(exempts->reason, buf, MAXHOST);
|
||||
free(buf);
|
||||
lnode = lnode_create(exempts);
|
||||
list_append(exempt, lnode);
|
||||
ns_free(buf);
|
||||
lnode_create_append(exempt, exempts);
|
||||
DBAStore ("Exempt", exempts->host, exempts, sizeof(exemptinfo));
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Added %s (%s) exception to list", exempts->host, (exempts->server ? "(Server)" : "(Client)"));
|
||||
irc_chanalert (opsb_bot, "%s added %s (%s) exception to list", cmdparams->source->name, exempts->host, (exempts->server ? "(Server)" : "(Client)"));
|
||||
|
@ -87,6 +86,7 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
exempts = lnode_get(lnode);
|
||||
DBADelete ("Exempt", exempts->host);
|
||||
list_delete(exempt, lnode);
|
||||
lnode_destroy(lnode);
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Deleted %s %s out of exception list", exempts->host, (exempts->server ? "(Server)" : "(Client)"));
|
||||
irc_chanalert (opsb_bot, "%s deleted %s %s out of exception list", cmdparams->source->name, exempts->host, (exempts->server ? "(Server)" : "(Client)"));
|
||||
ns_free(exempts);
|
||||
|
@ -110,14 +110,12 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
|
||||
void new_exempt (void *data)
|
||||
{
|
||||
lnode_t *node;
|
||||
exemptinfo *exempts;
|
||||
|
||||
exempts = malloc(sizeof(exemptinfo));
|
||||
os_memcpy (exempts, data, sizeof(exemptinfo));
|
||||
free (data);
|
||||
node = lnode_create(exempts);
|
||||
list_prepend(exempt, node);
|
||||
ns_free (data);
|
||||
lnode_create_append(exempt, exempts);
|
||||
dlog (DEBUG2, "Adding %s (%d) Set by %s for %s to Exempt List", exempts->host, exempts->server, exempts->who, exempts->reason);
|
||||
}
|
||||
|
||||
|
|
105
opsb.c
105
opsb.c
|
@ -90,7 +90,6 @@ int ports_sort(const void *key1, const void *key2) {
|
|||
|
||||
int opsb_cmd_lookup (CmdParams* cmdparams)
|
||||
{
|
||||
lnode_t *lnode;
|
||||
scaninfo *scandata;
|
||||
int lookuptype;
|
||||
|
||||
|
@ -102,12 +101,11 @@ int opsb_cmd_lookup (CmdParams* cmdparams)
|
|||
if (list_isfull(opsbl)) {
|
||||
if (list_isfull(opsbq)) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Too Busy. Try again Later");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "OPSB list is full, queuing your request");
|
||||
lnode = lnode_create(scandata);
|
||||
list_append(opsbq, lnode);
|
||||
lnode_create_append(opsbq, scandata);
|
||||
}
|
||||
if (inet_aton(scandata->lookup, NULL) > 0) {
|
||||
lookuptype = adns_r_ptr;
|
||||
|
@ -129,11 +127,10 @@ int opsb_cmd_lookup (CmdParams* cmdparams)
|
|||
}
|
||||
if (dns_lookup(scandata->lookup, lookuptype, reportdns, scandata->who) != 1) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "DnsLookup Failed.");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return NS_FAILURE;
|
||||
}
|
||||
lnode = lnode_create(scandata);
|
||||
list_append(opsbl, lnode);
|
||||
lnode_create_append(opsbl, scandata);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -160,7 +157,7 @@ int opsb_cmd_check (CmdParams* cmdparams)
|
|||
/* don't scan users from my server */
|
||||
if (IsMe(u2)) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Error, Can not scan NeoStats Bots");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return -1;
|
||||
}
|
||||
strlcpy(scandata->who, u2->name, MAXHOST);
|
||||
|
@ -172,7 +169,7 @@ int opsb_cmd_check (CmdParams* cmdparams)
|
|||
} else {
|
||||
/* if its here, we don't have the IP address yet */
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Error: We don't have a IP address for %s yet. Try again soon", u2->name);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
|
@ -226,7 +223,7 @@ int opsb_cmd_ports_add (CmdParams* cmdparams)
|
|||
return NS_SUCCESS;
|
||||
}
|
||||
if (!atoi(cmdparams->av[2])) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Port field does not contain a vaild port");
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Port field does not contain a valid port");
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
if (get_proxy_by_name(cmdparams->av[1]) < 1) {
|
||||
|
@ -247,8 +244,7 @@ int opsb_cmd_ports_add (CmdParams* cmdparams)
|
|||
pl->type = get_proxy_by_name(cmdparams->av[1]);
|
||||
pl->port = atoi(cmdparams->av[2]);
|
||||
|
||||
lnode = lnode_create(pl);
|
||||
list_append(opsb.ports, lnode);
|
||||
lnode_create_append(opsb.ports, pl);
|
||||
list_sort(opsb.ports, ports_sort);
|
||||
save_ports();
|
||||
add_port(pl->type, pl->port);
|
||||
|
@ -274,10 +270,11 @@ int opsb_cmd_ports_del (CmdParams* cmdparams)
|
|||
/* delete the entry */
|
||||
pl = lnode_get(lnode);
|
||||
list_delete(opsb.ports, lnode);
|
||||
lnode_destroy(lnode);
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Deleted Port %d of Protocol %s out of Ports list", pl->port, type_of_proxy(pl->type));
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "You need to Restart OPSB for the changes to take effect");
|
||||
irc_chanalert (opsb_bot, "%s deleted port %d of Protocol %s out of Ports list", cmdparams->source->name, pl->port, type_of_proxy(pl->type));
|
||||
free(pl);
|
||||
ns_free(pl);
|
||||
/* just to be sure, lets sort the list */
|
||||
list_sort(opsb.ports, ports_sort);
|
||||
save_ports();
|
||||
|
@ -392,35 +389,6 @@ static int unconf(void)
|
|||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
void save_ports()
|
||||
{
|
||||
lnode_t *pn;
|
||||
port_list *pl;
|
||||
char confpath[512];
|
||||
char ports[512];
|
||||
char tmpports[512];
|
||||
int lasttype = -1;
|
||||
pn = list_first(opsb.ports);
|
||||
while (pn) {
|
||||
pl = lnode_get(pn);
|
||||
/* if the port is different from the last round, and its not the first round, save it */
|
||||
if ((pl->type != lasttype) && (lasttype != -1)) {
|
||||
strlcpy(confpath, type_of_proxy(lasttype), 512);
|
||||
DBAStoreConfigStr (confpath, ports, 512);
|
||||
}
|
||||
if (pl->type != lasttype) {
|
||||
ircsnprintf(ports, 512, "%d", pl->port);
|
||||
} else {
|
||||
ircsnprintf(tmpports, 512, "%s %d", ports, pl->port);
|
||||
strlcpy(ports, tmpports, 512);
|
||||
}
|
||||
lasttype = pl->type;
|
||||
pn = list_next(opsb.ports, pn);
|
||||
}
|
||||
strlcpy(confpath, type_of_proxy(lasttype), 512);
|
||||
DBAStoreConfigStr (confpath, ports, 512);
|
||||
}
|
||||
|
||||
void checkqueue()
|
||||
{
|
||||
lnode_t *scannode;
|
||||
|
@ -453,7 +421,7 @@ void addtocache(unsigned long ip)
|
|||
cachenode = list_del_last(cache);
|
||||
ce = lnode_get(cachenode);
|
||||
lnode_destroy(cachenode);
|
||||
free(ce);
|
||||
ns_free(ce);
|
||||
}
|
||||
cachenode = list_first(cache);
|
||||
while (cachenode) {
|
||||
|
@ -468,8 +436,7 @@ void addtocache(unsigned long ip)
|
|||
ce = malloc(sizeof(cache_entry));
|
||||
ce->ip = ip;
|
||||
ce->when = time(NULL);
|
||||
cachenode = lnode_create(ce);
|
||||
list_prepend(cache, cachenode);
|
||||
lnode_create_append(cache, ce);
|
||||
}
|
||||
|
||||
int checkcache(scaninfo *scandata)
|
||||
|
@ -493,7 +460,7 @@ int checkcache(scaninfo *scandata)
|
|||
node2 = list_next(cache, node);
|
||||
list_delete(cache, node);
|
||||
lnode_destroy(node);
|
||||
free(ce);
|
||||
ns_free(ce);
|
||||
node = node2;
|
||||
break;
|
||||
}
|
||||
|
@ -571,7 +538,7 @@ int startscan(scaninfo *scandata)
|
|||
if (scandata->dnsstate == DO_OPM_LOOKUP) {
|
||||
i = checkcache(scandata);
|
||||
if ((i > 0) && (scandata->reqclient == NULL)) {
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -582,24 +549,22 @@ int startscan(scaninfo *scandata)
|
|||
irc_chanalert (opsb_bot, "Warning, Both Current and queue lists are full. Not Adding additional scans");
|
||||
dlog (DEBUG1, "OPSB: dropped scaning of %s, as queue is full", scandata->who);
|
||||
if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "To Busy. Try again later");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return 0;
|
||||
}
|
||||
scannode = lnode_create(scandata);
|
||||
list_append(opsbq, scannode);
|
||||
lnode_create_append(opsbq, scandata);
|
||||
dlog (DEBUG1, "DNS: Added %s to dns queue", scandata->who);
|
||||
if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Your Request has been added to the Queue");
|
||||
return 1;
|
||||
}
|
||||
if (dns_lookup(scandata->lookup, adns_r_a, dnsblscan, scandata->who) != 1) {
|
||||
nlog (LOG_WARNING, "DNS: startscan() DO_DNS_HOST_LOOKUP dns_lookup() failed");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
checkqueue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
scannode = lnode_create(scandata);
|
||||
list_append(opsbl, scannode);
|
||||
lnode_create_append(opsbl, scandata);
|
||||
dlog (DEBUG1, "DNS: Added getnickip to DNS active list");
|
||||
return 1;
|
||||
break;
|
||||
|
@ -608,11 +573,10 @@ int startscan(scaninfo *scandata)
|
|||
if(list_isfull(opsbq)) {
|
||||
irc_chanalert (opsb_bot, "Warning, Both Current and Queue lists are full, Not adding Scan");
|
||||
if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Too Busy. Try again Later");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return 0;
|
||||
}
|
||||
scannode = lnode_create(scandata);
|
||||
list_append(opsbq, scannode);
|
||||
lnode_create_append(opsbq, scandata);
|
||||
dlog (DEBUG1, "DNS: Added OPM lookup to queue: %s", scandata->who);
|
||||
return 1;
|
||||
}
|
||||
|
@ -628,22 +592,21 @@ int startscan(scaninfo *scandata)
|
|||
ircsnprintf(buf, buflen, "%d.%d.%d.%d.%s", d, c, b, a, opsb.opmdomain);
|
||||
if (dns_lookup(buf, adns_r_a, dnsblscan, scandata->who) != 1) {
|
||||
nlog (LOG_WARNING, "DNS: startscan() DO_OPM_LOOKUP dns_lookup() failed");
|
||||
free(scandata);
|
||||
free(buf);
|
||||
ns_free(scandata);
|
||||
ns_free(buf);
|
||||
checkqueue();
|
||||
return 0;
|
||||
}
|
||||
scannode = lnode_create(scandata);
|
||||
list_append(opsbl, scannode);
|
||||
lnode_create_append(opsbl, scandata);
|
||||
dlog (DEBUG1, "DNS: Added OPM %s lookup to DNS active list", buf);
|
||||
free(buf);
|
||||
start_proxy_scan(lnode_get(scannode));
|
||||
ns_free(buf);
|
||||
start_proxy_scan(scandata);
|
||||
++opsb.scanned;
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
nlog (LOG_WARNING, "Warning, Unknown Status in startscan()");
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -673,7 +636,7 @@ void dnsblscan(char *data, adns_answer *a)
|
|||
if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "No A record for %s. Aborting Scan", scandata->lookup);
|
||||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
checkqueue();
|
||||
break;
|
||||
}
|
||||
|
@ -695,7 +658,7 @@ void dnsblscan(char *data, adns_answer *a)
|
|||
irc_chanalert (opsb_bot, "Warning, Couldn't get the address for %s", scandata->who);
|
||||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
checkqueue();
|
||||
}
|
||||
|
||||
|
@ -704,10 +667,10 @@ void dnsblscan(char *data, adns_answer *a)
|
|||
irc_chanalert (opsb_bot, "Warning, Couldnt get the address for %s. rr_info failed", scandata->who);
|
||||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
checkqueue();
|
||||
}
|
||||
free(show);
|
||||
ns_free(show);
|
||||
break;
|
||||
case DO_OPM_LOOKUP:
|
||||
if (a->nrrs > 0) {
|
||||
|
@ -731,7 +694,7 @@ void dnsblscan(char *data, adns_answer *a)
|
|||
nlog (LOG_WARNING, "Warning, Unknown Status in dnsblscan()");
|
||||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
@ -739,7 +702,7 @@ void dnsblscan(char *data, adns_answer *a)
|
|||
nlog (LOG_CRITICAL, "OPSP() Answer is Empty!");
|
||||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -768,7 +731,7 @@ void reportdns(char *data, adns_answer *a) {
|
|||
} else {
|
||||
irc_prefmsg (opsb_bot, find_user (data), "DNS error %s", adns_strerror(ri));
|
||||
}
|
||||
free(show);
|
||||
ns_free(show);
|
||||
}
|
||||
if (a->nrrs < 1) {
|
||||
irc_prefmsg (opsb_bot, find_user (data), "%s Does not resolve", dnsinfo->lookup);
|
||||
|
@ -779,7 +742,7 @@ void reportdns(char *data, adns_answer *a) {
|
|||
|
||||
list_delete(opsbl, dnslookup);
|
||||
lnode_destroy(dnslookup);
|
||||
free(dnsinfo);
|
||||
ns_free(dnsinfo);
|
||||
checkqueue();
|
||||
}
|
||||
|
||||
|
|
1
opsb.h
1
opsb.h
|
@ -142,6 +142,7 @@ char *type_of_proxy(int type);
|
|||
int get_proxy_by_name(const char *name);
|
||||
void add_port(int type, int port);
|
||||
int load_ports();
|
||||
void save_ports();
|
||||
|
||||
/* help text */
|
||||
extern const char *opsb_help_lookup[];
|
||||
|
|
100
proxy.c
100
proxy.c
|
@ -52,7 +52,16 @@ void scan_error(OPM_T *scanner, OPM_REMOTE_T *remote, int opmerr, void *unused);
|
|||
|
||||
|
||||
OPM_T *scanner;
|
||||
|
||||
|
||||
char *defaultports[] = {
|
||||
"80 8080 8000 3128",
|
||||
"1080",
|
||||
"1080",
|
||||
"23",
|
||||
"23",
|
||||
"80 8080 8000 3128",
|
||||
};
|
||||
|
||||
proxy_type proxy_list[] = {
|
||||
{ OPM_TYPE_HTTP, "HTTP" },
|
||||
{ OPM_TYPE_SOCKS4, "SOCKS4" },
|
||||
|
@ -79,39 +88,72 @@ void add_port(int type, int port) {
|
|||
opm_addtype(scanner, type, port);
|
||||
}
|
||||
|
||||
void save_ports()
|
||||
{
|
||||
lnode_t *pn;
|
||||
port_list *pl;
|
||||
static char ports[512];
|
||||
static char tmpports[512];
|
||||
int lasttype = -1;
|
||||
pn = list_first(opsb.ports);
|
||||
while (pn) {
|
||||
pl = lnode_get(pn);
|
||||
/* if the port is different from the last round, and its not the first round, save it */
|
||||
if ((pl->type != lasttype) && (lasttype != -1)) {
|
||||
DBAStoreConfigStr(type_of_proxy(lasttype), ports, 512);
|
||||
}
|
||||
if (pl->type != lasttype) {
|
||||
ircsnprintf(ports, 512, "%d", pl->port);
|
||||
} else {
|
||||
ircsnprintf(tmpports, 512, "%s %d", ports, pl->port);
|
||||
strlcpy(ports, tmpports, 512);
|
||||
}
|
||||
lasttype = pl->type;
|
||||
pn = list_next(opsb.ports, pn);
|
||||
}
|
||||
DBAStoreConfigStr(type_of_proxy(lasttype), ports, 512);
|
||||
}
|
||||
|
||||
void load_port(char *type, char *portname)
|
||||
{
|
||||
char **av;
|
||||
int j, ac;
|
||||
port_list *prtlst;
|
||||
|
||||
ac = split_buf(portname, &av, 0);
|
||||
for (j = 0; j < ac; j++) {
|
||||
if (atoi(av[j]) == 0) {
|
||||
nlog (LOG_WARNING, "Invalid port %s for proxy type %s", av[j], type);
|
||||
continue;
|
||||
}
|
||||
if (list_isfull(opsb.ports)) {
|
||||
nlog (LOG_WARNING, "Ports list is full.");
|
||||
break;
|
||||
}
|
||||
prtlst = malloc(sizeof(port_list));
|
||||
prtlst->type = proxy_list[i].type;
|
||||
prtlst->port = atoi(av[j]);
|
||||
prtlst->noopen = 0;
|
||||
lnode_create_append (opsb.ports, prtlst);
|
||||
dlog (DEBUG1, "Added port %d for protocol %s", prtlst->port, proxy_list[i].name);
|
||||
}
|
||||
ns_free(av);
|
||||
}
|
||||
|
||||
int load_ports() {
|
||||
static char portname[512];
|
||||
char **av;
|
||||
int i, j, ac, ok;
|
||||
port_list *prtlst;
|
||||
lnode_t *pn;
|
||||
int i;
|
||||
int ok = 0;
|
||||
|
||||
ok = 0;
|
||||
for (i = 0; proxy_list[i].type != 0; i++) {
|
||||
if (DBAFetchConfigStr (proxy_list[i].name, portname, 512) != NS_SUCCESS) {
|
||||
nlog (LOG_WARNING, "Warning, No Ports defined for Protocol %s", proxy_list[i].name);
|
||||
nlog (LOG_WARNING, "Warning, no ports defined for protocol %s, using defaults", proxy_list[i].name);
|
||||
load_port(proxy_list[i].name, defaultports[i]);
|
||||
DBAStoreConfigStr(proxy_list[i].name, defaultports[i], 512);
|
||||
ok = 1;
|
||||
} else {
|
||||
ac = split_buf(portname, &av, 0);
|
||||
for (j = 0; j < ac; j++) {
|
||||
if (atoi(av[j]) == 0) {
|
||||
nlog (LOG_WARNING, "Invalid Port %s for Proxy Type %s", av[j], proxy_list[i].name);
|
||||
continue;
|
||||
}
|
||||
if (list_isfull(opsb.ports)) {
|
||||
nlog (LOG_WARNING, "Ports List is Full.");
|
||||
break;
|
||||
}
|
||||
prtlst = malloc(sizeof(port_list));
|
||||
prtlst->type = proxy_list[i].type;
|
||||
prtlst->port = atoi(av[j]);
|
||||
prtlst->noopen = 0;
|
||||
pn = lnode_create(prtlst);
|
||||
list_append(opsb.ports, pn);
|
||||
dlog (DEBUG1, "Added Port %d for Protocol %s", prtlst->port, proxy_list[i].name);
|
||||
ok = 1;
|
||||
}
|
||||
free(av);
|
||||
free(portname);
|
||||
load_port(proxy_list[i].name, portname);
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
|
@ -372,7 +414,7 @@ void check_scan_free(scaninfo *scandata) {
|
|||
list_delete(opsbl, scannode);
|
||||
lnode_destroy(scannode);
|
||||
scandata->reqclient = NULL;
|
||||
free(scandata);
|
||||
ns_free(scandata);
|
||||
} else {
|
||||
nlog (LOG_WARNING, "Damn, Can't find ScanNode %s. Something is fubar", scandata->who);
|
||||
}
|
||||
|
|
Reference in a new issue