update to new core module exclusion API
This commit is contained in:
parent
781d7edae9
commit
997bd647eb
8 changed files with 9 additions and 229 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -8,8 +8,6 @@
|
|||
/aclocal.m4 -text
|
||||
/configure -text
|
||||
/configure.in -text
|
||||
/exempts.c -text
|
||||
/exempts.h -text
|
||||
/html.css -text
|
||||
/install-sh -text
|
||||
libopm/.cvsignore -text
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
Open Proxy Scanning Bot Module for NeoStats Changelog.
|
||||
==============================================================================
|
||||
3.0prealpha1 - Mark (M)
|
||||
- Update module to use new core module exclusion support. (M)
|
||||
- Removed splittime setting which is now handled by core. (M)
|
||||
- Changes for Win32 compatibility. (M)
|
||||
- Split exempt code into seperate files. (M)
|
||||
|
|
10
Makefile.in
10
Makefile.in
|
@ -8,15 +8,13 @@ INSTALL_DATA = @INSTALL_DATA@
|
|||
DIRECTORY = @DIRINST@/modules/
|
||||
INCLUDES = -I@DIRINST@/include/ -I. -Ilibopm
|
||||
|
||||
SRCS= opsb.c proxy.c opsb_help.c exempts.c
|
||||
SRCS= opsb.c proxy.c opsb_help.c
|
||||
OBJS= ${SRCS:.c=.o}
|
||||
TARGET= opsb.so
|
||||
DOCS=README.opsb README.opsb.html opsb.Settings
|
||||
DOCS=README.opsb README.opsb.html
|
||||
DISTFILES = $(SRCS) $(DOCS) modconfig.h.in configure install-sh ChangeLog Makefile.in opsb.h libopm/*.c libopm/*.h libopm/README libopm/LICENSE LICENSE libopm/*.in
|
||||
DISTDIR = @PACKAGE@-@VERSION@
|
||||
|
||||
|
||||
|
||||
all: module
|
||||
|
||||
.c.o:
|
||||
|
@ -35,8 +33,7 @@ clean:
|
|||
install: module
|
||||
$(INSTALL) -m 644 $(TARGET) $(DIRECTORY)
|
||||
$(INSTALL) -m 644 $(DOCS) $(DIRECTORY)../doc/
|
||||
@cd $(DIRECTORY)..; \
|
||||
if ! test -f $(DIRECTORY)../kpconf/OPSB ; then ./kptool -i doc/opsb.Settings; fi
|
||||
|
||||
dist:
|
||||
@echo -n "Creating Directories"
|
||||
@-rm -rf $(DISTDIR)
|
||||
|
@ -57,5 +54,4 @@ $(OBJS): Makefile
|
|||
opsb.o: opsb.h opsb.c modconfig.h
|
||||
proxy.o: opsb.h proxy.c modconfig.h
|
||||
opsb_help.o: opsb.h
|
||||
exempts.o: opsb.h exempts.c exempts.h
|
||||
|
||||
|
|
171
exempts.c
171
exempts.c
|
@ -1,171 +0,0 @@
|
|||
/* NeoStats - IRC Statistical Services
|
||||
** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond, Mark Hetherington
|
||||
** http://www.neostats.net/
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
** USA
|
||||
**
|
||||
** NeoStats CVS Identification
|
||||
** $Id$
|
||||
*/
|
||||
|
||||
#include "neostats.h"
|
||||
#include "opsb.h"
|
||||
#include "exempts.h"
|
||||
|
||||
/* this is the list of exempted hosts/servers */
|
||||
list_t *exempt;
|
||||
|
||||
int opsb_cmd_exclude (CmdParams* cmdparams)
|
||||
{
|
||||
char *buf;
|
||||
exemptinfo *exempts;
|
||||
int i;
|
||||
lnode_t *lnode;
|
||||
|
||||
if (!ircstrcasecmp (cmdparams->av[0], "LIST")) {
|
||||
lnode = list_first(exempt);
|
||||
i = 1;
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Exception List:");
|
||||
while (lnode) {
|
||||
exempts = lnode_get(lnode);
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "%d) %s %s Added by %s for %s", i, exempts->host, (exempts->server ? "(Server)" : "(Client)"), exempts->who, exempts->reason);
|
||||
++i;
|
||||
lnode = list_next(exempt, lnode);
|
||||
}
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "End of list.");
|
||||
irc_chanalert (opsb_bot, "%s requested Exception List", cmdparams->source->name);
|
||||
} else if (!ircstrcasecmp (cmdparams->av[0], "ADD")) {
|
||||
if (cmdparams->ac < 6) {
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
if (list_isfull(exempt)) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Error, Exception list is full");
|
||||
return 0;
|
||||
}
|
||||
if (!index(cmdparams->av[1], '.')) {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Host field does not contain a vaild host");
|
||||
return 0;
|
||||
}
|
||||
exempts = malloc(sizeof(exemptinfo));
|
||||
strlcpy(exempts->host, cmdparams->av[1], MAXHOST);
|
||||
if (atoi(cmdparams->av[2]) > 0)
|
||||
exempts->server = 1;
|
||||
else
|
||||
exempts->server = 0;
|
||||
strlcpy(exempts->who, cmdparams->source->name, MAXNICK);
|
||||
buf = joinbuf(cmdparams->av, cmdparams->ac, 3);
|
||||
strlcpy(exempts->reason, buf, MAXHOST);
|
||||
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)"));
|
||||
} else if (!ircstrcasecmp (cmdparams->av[0], "DEL")) {
|
||||
if (cmdparams->ac < 1) {
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
if (atoi(cmdparams->av[1]) != 0) {
|
||||
lnode = list_first(exempt);
|
||||
i = 1;
|
||||
while (lnode) {
|
||||
if (i == atoi(cmdparams->av[1])) {
|
||||
/* delete the entry */
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
++i;
|
||||
lnode = list_next(exempt, lnode);
|
||||
}
|
||||
/* if we get here, then we can't find the entry */
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Error, Can't find entry %d. /msg %s exclude list", atoi(cmdparams->av[1]), opsb_bot->name);
|
||||
return 0;
|
||||
} else {
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Error, Out of Range");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void new_exempt (void *data)
|
||||
{
|
||||
exemptinfo *exempts;
|
||||
|
||||
exempts = malloc(sizeof(exemptinfo));
|
||||
os_memcpy (exempts, data, sizeof(exemptinfo));
|
||||
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);
|
||||
}
|
||||
|
||||
void LoadExempts (void)
|
||||
{
|
||||
exempt = list_create(MAX_EXEMPTS);
|
||||
DBAFetchRows ("Exempt", new_exempt);
|
||||
}
|
||||
|
||||
int IsServerExempt (char *nick, char *host)
|
||||
{
|
||||
lnode_t *node;
|
||||
exemptinfo *exempts;
|
||||
|
||||
node = list_first(exempt);
|
||||
while (node) {
|
||||
exempts = lnode_get(node);
|
||||
if (exempts->server == 1) {
|
||||
/* match a server */
|
||||
if (match(exempts->host, host)) {
|
||||
dlog (DEBUG1, "OPSB: User %s exempt. Matched host entry %s in Exemptions", nick, exempts->host);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
node = list_next(exempt, node);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IsUserExempt (char *nick, char *host)
|
||||
{
|
||||
lnode_t *node;
|
||||
exemptinfo *exempts;
|
||||
|
||||
node = list_first(exempt);
|
||||
while (node) {
|
||||
exempts = lnode_get(node);
|
||||
if (exempts->server == 1) {
|
||||
/* match a server */
|
||||
if (match(exempts->host, host)) {
|
||||
dlog (DEBUG1, "OPSB: User %s exempt. Matched server entry %s in Exemptions", nick, exempts->host);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
node = list_next(exempt, node);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetExemptCount (void)
|
||||
{
|
||||
return list_count(exempt);
|
||||
}
|
34
exempts.h
34
exempts.h
|
@ -1,34 +0,0 @@
|
|||
/* NeoStats - IRC Statistical Services
|
||||
** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond, Mark Hetherington
|
||||
** http://www.neostats.net/
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
** USA
|
||||
**
|
||||
** NetStats CVS Identification
|
||||
** $Id$
|
||||
*/
|
||||
|
||||
#ifndef EXEMPTS_H
|
||||
#define EXEMPTS_H
|
||||
|
||||
void LoadExempts (void);
|
||||
void SaveExempts (exemptinfo *exempts);
|
||||
int opsb_cmd_exclude (CmdParams* cmdparams);
|
||||
int IsServerExempt (char *nick, char *host);
|
||||
int IsUserExempt (char *nick, char *host);
|
||||
int GetExemptCount (void);
|
||||
|
||||
#endif /* EXEMPTS_H */
|
11
opsb.c
11
opsb.c
|
@ -31,7 +31,6 @@
|
|||
#endif
|
||||
#include "neostats.h"
|
||||
#include "opsb.h"
|
||||
#include "exempts.h"
|
||||
|
||||
void reportdns(char *data, adns_answer *a);
|
||||
void dnsblscan(char *data, adns_answer *a);
|
||||
|
@ -62,7 +61,7 @@ ModuleInfo module_info = {
|
|||
MODULE_VERSION,
|
||||
__DATE__,
|
||||
__TIME__,
|
||||
0,
|
||||
MODULE_FLAG_LOCAL_EXCLUDES,
|
||||
0,
|
||||
};
|
||||
|
||||
|
@ -320,7 +319,6 @@ static bot_cmd opsb_commands[]=
|
|||
{"LOOKUP", opsb_cmd_lookup, 1, NS_ULEVEL_OPER, opsb_help_lookup, opsb_help_lookup_oneline},
|
||||
{"REMOVE", opsb_cmd_remove, 1, NS_ULEVEL_OPER, opsb_help_remove, opsb_help_remove_oneline},
|
||||
{"CHECK", opsb_cmd_check, 1, NS_ULEVEL_OPER, opsb_help_check, opsb_help_check_oneline},
|
||||
{"EXCLUDE", opsb_cmd_exclude, 1, NS_ULEVEL_ADMIN,opsb_help_exclude, opsb_help_exclude_oneline},
|
||||
{"PORTS", opsb_cmd_ports, 1, NS_ULEVEL_ADMIN,opsb_help_ports, opsb_help_ports_oneline},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
@ -449,9 +447,9 @@ int checkcache(scaninfo *scandata)
|
|||
cache_entry *ce;
|
||||
|
||||
SET_SEGV_LOCATION();
|
||||
if (scandata->server && IsServerExempt (scandata->who, scandata->server))
|
||||
if (scandata->server && ModIsServerExcluded (scandata->who, scandata->server))
|
||||
return 1;
|
||||
if (IsUserExempt (scandata->who, scandata->lookup))
|
||||
if (ModIsUserExcluded (scandata->who, scandata->lookup))
|
||||
return 2;
|
||||
node = list_first(cache);
|
||||
while (node) {
|
||||
|
@ -494,7 +492,7 @@ static int ss_event_signon (CmdParams* cmdparams)
|
|||
SET_SEGV_LOCATION();
|
||||
|
||||
/* don't scan users from a server that is excluded */
|
||||
if (IsServerExempt (cmdparams->source->name, cmdparams->source->uplink->name))
|
||||
if (ModIsServerExcluded (cmdparams->source->uplink))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -772,7 +770,6 @@ int ModInit (Module *mod_ptr)
|
|||
/* scan cache is MAX_QUEUE size (why not?) */
|
||||
cache = list_create(MAX_QUEUE);
|
||||
opsb.ports = list_create(MAX_PORTS);
|
||||
LoadExempts();
|
||||
opsb.open = 0;
|
||||
opsb.scanned = 0;
|
||||
opsb.cachehits = 1;
|
||||
|
|
|
@ -123,9 +123,6 @@
|
|||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\exempts.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\opsb.c">
|
||||
</File>
|
||||
|
@ -140,9 +137,6 @@
|
|||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath=".\exempts.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\opsb.h">
|
||||
</File>
|
||||
|
|
3
proxy.c
3
proxy.c
|
@ -34,7 +34,6 @@
|
|||
#endif
|
||||
#include "neostats.h"
|
||||
#include "opsb.h"
|
||||
#include "exempts.h"
|
||||
#include "opm.h"
|
||||
#include "opm_types.h"
|
||||
#include "opm_error.h"
|
||||
|
@ -312,7 +311,7 @@ int opsb_cmd_status (CmdParams* cmdparams)
|
|||
SET_SEGV_LOCATION();
|
||||
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Proxy Results:");
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Hosts Scanned: %d Hosts found Open: %d Exceptions %d", opsb.scanned, opsb.open, GetExemptCount ());
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Hosts Scanned: %d Hosts found Open: %d", opsb.scanned, opsb.open);
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Cache Entries: %d", (int)list_count(cache));
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Cache Hits: %d", opsb.cachehits);
|
||||
irc_prefmsg (opsb_bot, cmdparams->source, "Blacklist Hits: %d", opsb.opmhits);
|
||||
|
|
Reference in a new issue