database API updates
This commit is contained in:
parent
0f4e0d7480
commit
6f6007a777
8 changed files with 47 additions and 92 deletions
|
@ -1,6 +1,7 @@
|
|||
Open Proxy Scanning Bot Module for NeoStats Changelog.
|
||||
==============================================================================
|
||||
* Version 3.0 * * Mark (M)
|
||||
3.0prealpha1 - Mark (M)
|
||||
- Removed splittime setting which is now handled by core. (M)
|
||||
- Changes for Win32 compatibility. (M)
|
||||
- Split exempt code into seperate files. (M)
|
||||
- Port to 3.0 API (M)
|
||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -1299,7 +1299,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
|||
|
||||
PACKAGE=OPSB
|
||||
MODULE_MAJOR=3
|
||||
MODULE_MINOR=0prealpha1
|
||||
MODULE_MINOR=0prealpha2
|
||||
VERSION=$MODULE_MAJOR.$MODULE_MINOR
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
|
|
|
@ -3,7 +3,7 @@ AC_INIT(opsb.c)
|
|||
AC_CONFIG_HEADER(modconfig.h)
|
||||
PACKAGE=OPSB
|
||||
MODULE_MAJOR=3
|
||||
MODULE_MINOR=0prealpha1
|
||||
MODULE_MINOR=0prealpha2
|
||||
VERSION=$MODULE_MAJOR.$MODULE_MINOR
|
||||
AC_DEFINE_UNQUOTED(MODULE_VERSION, "$VERSION", "Module Version")
|
||||
AC_DEFINE_UNQUOTED(MODULE_MAJOR, "$MODULE_MAJOR", "Major Version")
|
||||
|
|
69
exempts.c
69
exempts.c
|
@ -71,8 +71,7 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
free(buf);
|
||||
lnode = lnode_create(exempts);
|
||||
list_append(exempt, lnode);
|
||||
SaveExempts(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)"));
|
||||
} else if (!ircstrcasecmp (cmdparams->av[0], "DEL")) {
|
||||
|
@ -86,14 +85,11 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
if (i == atoi(cmdparams->av[1])) {
|
||||
/* delete the entry */
|
||||
exempts = lnode_get(lnode);
|
||||
buf = malloc(BUFSIZE);
|
||||
ircsnprintf(buf, BUFSIZE, "Exempt/%s", exempts->host);
|
||||
DelConf(buf);
|
||||
free(buf);
|
||||
DBADelete ("Exempt", exempts->host);
|
||||
list_delete(exempt, 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)"));
|
||||
free(exempts);
|
||||
ns_free(exempts);
|
||||
return 1;
|
||||
}
|
||||
++i;
|
||||
|
@ -112,62 +108,23 @@ int opsb_cmd_exclude (CmdParams* cmdparams)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void SaveExempts (exemptinfo *exempts)
|
||||
void new_exempt (void *data)
|
||||
{
|
||||
char path[255];
|
||||
lnode_t *node;
|
||||
exemptinfo *exempts;
|
||||
|
||||
dlog (DEBUG1, "Saving Exempt List %s", exempts->host);
|
||||
ircsnprintf (path, 255, "Exempt/%s/Who", exempts->host);
|
||||
SetConf ((void *)exempts->who, CFGSTR, path);
|
||||
ircsnprintf (path, 255, "Exempt/%s/Reason", exempts->host);
|
||||
SetConf ((void *)exempts->reason, CFGSTR, path);
|
||||
ircsnprintf (path, 255, "Exempt/%s/Server", exempts->host);
|
||||
SetConf ((void *)exempts->server, CFGINT, path);
|
||||
exempts = malloc(sizeof(exemptinfo));
|
||||
os_memcpy (exempts, data, sizeof(exemptinfo));
|
||||
free (data);
|
||||
node = lnode_create(exempts);
|
||||
list_prepend(exempt, node);
|
||||
dlog (DEBUG2, "Adding %s (%d) Set by %s for %s to Exempt List", exempts->host, exempts->server, exempts->who, exempts->reason);
|
||||
}
|
||||
|
||||
void LoadExempts (void)
|
||||
{
|
||||
int i;
|
||||
lnode_t *node;
|
||||
char **data;
|
||||
char *tmp;
|
||||
char datapath[BUFSIZE];
|
||||
exemptinfo *exempts;
|
||||
|
||||
exempt = list_create(MAX_EXEMPTS);
|
||||
if (GetDir ("Exempt", &data) > 0) {
|
||||
/* try */
|
||||
for (i = 0; data[i] != NULL; i++) {
|
||||
exempts = malloc(sizeof(exemptinfo));
|
||||
strlcpy(exempts->host, data[i], MAXHOST);
|
||||
|
||||
ircsnprintf(datapath, CONFBUFSIZE, "Exempt/%s/Who", data[i]);
|
||||
if (GetConf((void *)&tmp, CFGSTR, datapath) <= 0) {
|
||||
free(exempts);
|
||||
continue;
|
||||
} else {
|
||||
strlcpy(exempts->who, tmp, MAXNICK);
|
||||
free(tmp);
|
||||
}
|
||||
ircsnprintf(datapath, CONFBUFSIZE, "Exempt/%s/Reason", data[i]);
|
||||
if (GetConf((void *)&tmp, CFGSTR, datapath) <= 0) {
|
||||
free(exempts);
|
||||
continue;
|
||||
} else {
|
||||
strlcpy(exempts->reason, tmp, MAXREASON);
|
||||
free(tmp);
|
||||
}
|
||||
ircsnprintf(datapath, CONFBUFSIZE, "Exempt/%s/Server", data[i]);
|
||||
if (GetConf((void *)&exempts->server, CFGINT, datapath) <= 0) {
|
||||
free(exempts);
|
||||
continue;
|
||||
}
|
||||
dlog (DEBUG2, "Adding %s (%d) Set by %s for %s to Exempt List", exempts->host, exempts->server, exempts->who, exempts->reason);
|
||||
node = lnode_create(exempts);
|
||||
list_prepend(exempt, node);
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
DBAFetchRows ("Exempt", new_exempt);
|
||||
}
|
||||
|
||||
int IsServerExempt (char *nick, char *host)
|
||||
|
|
48
opsb.c
48
opsb.c
|
@ -35,7 +35,7 @@
|
|||
|
||||
void reportdns(char *data, adns_answer *a);
|
||||
void dnsblscan(char *data, adns_answer *a);
|
||||
static int ScanNick (CmdParams* cmdparams);
|
||||
static int ss_event_signon (CmdParams* cmdparams);
|
||||
int startscan(scaninfo *scandata);
|
||||
void save_ports();
|
||||
static int unconf(void);
|
||||
|
@ -308,7 +308,7 @@ int opsb_cmd_ports (CmdParams* cmdparams)
|
|||
|
||||
int do_set_cb (CmdParams* cmdparams, SET_REASON reason)
|
||||
{
|
||||
SetConf((void *)1, CFGINT, "Confed");
|
||||
DBAStoreConfigInt ("Confed", 1);
|
||||
del_timer("unconf");
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
@ -334,7 +334,6 @@ static bot_setting opsb_settings[]=
|
|||
{"MAXBYTES", &opsb.maxbytes, SET_TYPE_INT, 0, 100000, NS_ULEVEL_ADMIN, "MaxBytes", NULL, opsb_help_set_maxbytes, do_set_cb, (void*)500 },
|
||||
{"TIMEOUT", &opsb.timeout, SET_TYPE_INT, 0, 120, NS_ULEVEL_ADMIN, "TimeOut", NULL, opsb_help_set_timeout, do_set_cb, (void*)30 },
|
||||
{"OPENSTRING", &opsb.lookforstring,SET_TYPE_MSG, 0, BUFSIZE, NS_ULEVEL_ADMIN, "TriggerString",NULL, opsb_help_set_openstring, do_set_cb, (void*)"*** Looking up your hostname..." },
|
||||
{"SPLITTIME", &opsb.timedif, SET_TYPE_INT, 0, 900, NS_ULEVEL_ADMIN, "SplitTime", NULL, opsb_help_set_splittime, do_set_cb, (void*)600 },
|
||||
{"SCANMSG", &opsb.scanmsg, SET_TYPE_MSG, 0, BUFSIZE, NS_ULEVEL_ADMIN, "ScanMsg", NULL, opsb_help_set_scanmsg, do_set_cb, (void*)"Your Host is being Scanned for Open Proxies" },
|
||||
{"BANTIME", &opsb.bantime, SET_TYPE_INT, 0, 360000, NS_ULEVEL_ADMIN, "BanTime", NULL, opsb_help_set_bantime, do_set_cb, (void*)86400 },
|
||||
{"CACHETIME", &opsb.cachetime, SET_TYPE_INT, 0, 86400, NS_ULEVEL_ADMIN, "CacheTime", NULL, opsb_help_set_cachetime, do_set_cb, (void*)3600 },
|
||||
|
@ -397,30 +396,29 @@ void save_ports()
|
|||
{
|
||||
lnode_t *pn;
|
||||
port_list *pl;
|
||||
char confpath[CONFBUFSIZE];
|
||||
char ports[CONFBUFSIZE];
|
||||
char tmpports[CONFBUFSIZE];
|
||||
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), CONFBUFSIZE);
|
||||
SetConf((void *)ports, CFGSTR, confpath);
|
||||
strlcpy(confpath, type_of_proxy(lasttype), 512);
|
||||
DBAStoreConfigStr (confpath, ports, 512);
|
||||
}
|
||||
if (pl->type != lasttype) {
|
||||
ircsnprintf(ports, CONFBUFSIZE, "%d", pl->port);
|
||||
ircsnprintf(ports, 512, "%d", pl->port);
|
||||
} else {
|
||||
ircsnprintf(tmpports, CONFBUFSIZE, "%s %d", ports, pl->port);
|
||||
strlcpy(ports, tmpports, CONFBUFSIZE);
|
||||
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), CONFBUFSIZE);
|
||||
SetConf((void *)ports, CFGSTR, confpath);
|
||||
flush_keeper();
|
||||
strlcpy(confpath, type_of_proxy(lasttype), 512);
|
||||
DBAStoreConfigStr (confpath, ports, 512);
|
||||
}
|
||||
|
||||
void checkqueue()
|
||||
|
@ -512,12 +510,12 @@ int checkcache(scaninfo *scandata)
|
|||
|
||||
ModuleEvent module_events[] =
|
||||
{
|
||||
{ EVENT_NICKIP, ScanNick, EVENT_FLAG_EXCLUDE_ME},
|
||||
{ EVENT_NICKIP, ss_event_signon, EVENT_FLAG_EXCLUDE_ME},
|
||||
{ EVENT_NULL, NULL}
|
||||
};
|
||||
|
||||
/* this function kicks of a scan of a user that just signed on the network */
|
||||
static int ScanNick (CmdParams* cmdparams)
|
||||
static int ss_event_signon (CmdParams* cmdparams)
|
||||
{
|
||||
scaninfo *scandata;
|
||||
lnode_t *scannode;
|
||||
|
@ -529,14 +527,14 @@ static int ScanNick (CmdParams* cmdparams)
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
if (time(NULL) - cmdparams->source->tsconnect > opsb.timedif) {
|
||||
dlog (DEBUG1, "Netsplit Nick %s, Not Scanning", cmdparams->source->name);
|
||||
if (IsNetSplit(cmdparams->source)) {
|
||||
dlog (DEBUG1, "Ignoring netsplit nick %s", cmdparams->source->name);
|
||||
return -1;
|
||||
}
|
||||
scannode = list_find(opsbl, cmdparams->source->name, findscan);
|
||||
if (!scannode) scannode = list_find(opsbq, cmdparams->source->name, findscan);
|
||||
if (scannode) {
|
||||
dlog (DEBUG1, "ScanNick(): Not scanning %s as we are already scanning them", cmdparams->source->name);
|
||||
dlog (DEBUG1, "ss_event_signon(): Not scanning %s as we are already scanning them", cmdparams->source->name);
|
||||
return -1;
|
||||
}
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "%s", opsb.scanmsg);
|
||||
|
@ -551,7 +549,7 @@ static int ScanNick (CmdParams* cmdparams)
|
|||
scandata->dnsstate = DO_OPM_LOOKUP;
|
||||
if (!startscan(scandata)) {
|
||||
irc_chanalert (opsb_bot, "Warning Can't scan %s", cmdparams->source->name);
|
||||
nlog (LOG_WARNING, "OBSB ScanNick(): Can't scan %s. Check logs for possible errors", cmdparams->source->name);
|
||||
nlog (LOG_WARNING, "OBSB ss_event_signon(): Can't scan %s. Check logs for possible errors", cmdparams->source->name);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -790,7 +788,7 @@ int ModInit (Module *mod_ptr)
|
|||
strlcpy(opsb.targethost, me.uplink, MAXHOST);
|
||||
opsb.targetport = me.port;
|
||||
opsb.confed = 0;
|
||||
GetConf((void *)&opsb.confed, CFGINT, "Confed");
|
||||
DBAFetchConfigInt ("Confed", &opsb.confed);
|
||||
ModuleConfig (opsb_settings);
|
||||
/* we have to be careful here. Currently, we have 7 sockets that get opened per connection. Soooo.
|
||||
* we check that MAX_SCANS is not greater than the maxsockets available / 7
|
||||
|
@ -826,3 +824,11 @@ int ModInit (Module *mod_ptr)
|
|||
void ModFini()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef WIN32 /* temp */
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
1
opsb.h
1
opsb.h
|
@ -168,7 +168,6 @@ extern const char *opsb_help_set_opmdomain [];
|
|||
extern const char *opsb_help_set_maxbytes [];
|
||||
extern const char *opsb_help_set_timeout [];
|
||||
extern const char *opsb_help_set_openstring [];
|
||||
extern const char *opsb_help_set_splittime [];
|
||||
extern const char *opsb_help_set_scanmsg [];
|
||||
extern const char *opsb_help_set_bantime [];
|
||||
extern const char *opsb_help_set_cachetime [];
|
||||
|
|
|
@ -142,15 +142,6 @@ const char *opsb_help_set_openstring [] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
const char *opsb_help_set_splittime [] = {
|
||||
"\2SPLITTIME\2",
|
||||
"This is used to determine if users connecting to the network",
|
||||
"are part of a net join (when two servers link together)",
|
||||
"This setting should not be changed unless you know the",
|
||||
"effects in full",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *opsb_help_set_scanmsg [] = {
|
||||
"\2SCANMSG\2",
|
||||
"Message sent to a user when we scan their hosts",
|
||||
|
|
5
proxy.c
5
proxy.c
|
@ -80,14 +80,15 @@ void add_port(int type, int port) {
|
|||
}
|
||||
|
||||
int load_ports() {
|
||||
char *portname, **av;
|
||||
static char portname[512];
|
||||
char **av;
|
||||
int i, j, ac, ok;
|
||||
port_list *prtlst;
|
||||
lnode_t *pn;
|
||||
|
||||
ok = 0;
|
||||
for (i = 0; proxy_list[i].type != 0; i++) {
|
||||
if (GetConf((void *)&portname, CFGSTR, proxy_list[i].name) <= 0) {
|
||||
if (DBAFetchConfigStr (proxy_list[i].name, portname, 512) != NS_SUCCESS) {
|
||||
nlog (LOG_WARNING, "Warning, No Ports defined for Protocol %s", proxy_list[i].name);
|
||||
} else {
|
||||
ac = split_buf(portname, &av, 0);
|
||||
|
|
Reference in a new issue