2003-12-31 05:13:44 +00:00
|
|
|
/* NeoStats - IRC Statistical Services
|
2006-01-26 15:33:47 +00:00
|
|
|
** Copyright (c) 1999-2006 Adam Rutter, Justin Hammond, Mark Hetherington
|
2003-12-31 05:13:44 +00:00
|
|
|
** 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
|
2003-12-31 05:18:35 +00:00
|
|
|
** $Id$
|
2003-12-31 05:13:44 +00:00
|
|
|
*/
|
|
|
|
|
2005-02-22 00:38:12 +00:00
|
|
|
#include "neostats.h"
|
2005-05-22 22:03:08 +00:00
|
|
|
#include MODULECONFIG
|
2004-03-08 22:19:51 +00:00
|
|
|
#include "logserv.h"
|
2003-12-31 05:51:22 +00:00
|
|
|
|
2005-10-20 20:52:55 +00:00
|
|
|
LogServcfg LogServ;
|
2005-10-15 21:34:59 +00:00
|
|
|
hash_t *lschannelhash;
|
2005-10-17 22:04:14 +00:00
|
|
|
static Bot *ls_bot;
|
2004-08-01 21:23:58 +00:00
|
|
|
|
2003-12-31 05:51:22 +00:00
|
|
|
/* forward decl */
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_cmd_add( const CmdParams *cmdparams );
|
|
|
|
static int ls_cmd_del( const CmdParams *cmdparams );
|
|
|
|
static int ls_cmd_list( const CmdParams *cmdparams );
|
|
|
|
static int ls_cmd_url( const CmdParams *cmdparams );
|
2005-10-17 22:04:14 +00:00
|
|
|
static int ls_cmd_status( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_cprivate( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_cnotice( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_ctcpaction( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_newchan( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_emptychan( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_join( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_part( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_kick( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_topic( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_nick( const CmdParams *cmdparams );
|
|
|
|
static int ls_event_cmode( const CmdParams *cmdparams );
|
2003-12-31 05:51:22 +00:00
|
|
|
|
2004-08-01 21:23:58 +00:00
|
|
|
/** Copyright info */
|
2005-10-20 21:39:23 +00:00
|
|
|
static const char *ls_copyright[] =
|
2005-10-17 22:04:14 +00:00
|
|
|
{
|
2006-01-26 15:33:47 +00:00
|
|
|
"Copyright (c) 1999-2006, NeoStats",
|
2004-08-01 21:23:58 +00:00
|
|
|
"http://www.neostats.net/",
|
|
|
|
NULL
|
|
|
|
};
|
2003-12-31 05:13:44 +00:00
|
|
|
|
2005-10-14 21:49:36 +00:00
|
|
|
/** Module Info definition */
|
|
|
|
ModuleInfo module_info =
|
|
|
|
{
|
2003-12-31 05:18:35 +00:00
|
|
|
"LogServ",
|
|
|
|
"Channel Logging Bot",
|
2004-08-01 21:23:58 +00:00
|
|
|
ls_copyright,
|
|
|
|
ls_about,
|
|
|
|
NEOSTATS_VERSION,
|
2004-08-04 22:23:10 +00:00
|
|
|
MODULE_VERSION,
|
2003-12-31 05:13:44 +00:00
|
|
|
__DATE__,
|
2004-08-01 21:23:58 +00:00
|
|
|
__TIME__,
|
|
|
|
0,
|
|
|
|
0,
|
2005-10-14 21:49:36 +00:00
|
|
|
0,
|
2003-12-31 05:13:44 +00:00
|
|
|
};
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static bot_cmd ls_commands[]=
|
2003-12-31 05:13:44 +00:00
|
|
|
{
|
2008-02-21 13:15:50 +00:00
|
|
|
{"ADD", ls_cmd_add, 2, NS_ULEVEL_OPER, ls_help_add, 0, NULL, NULL},
|
2005-10-17 22:04:14 +00:00
|
|
|
{"DEL", ls_cmd_del, 1, NS_ULEVEL_OPER, ls_help_del, 0, NULL, NULL},
|
2005-10-15 22:34:33 +00:00
|
|
|
{"LIST", ls_cmd_list, 0, NS_ULEVEL_OPER, ls_help_list, 0, NULL, NULL},
|
2005-10-17 22:04:14 +00:00
|
|
|
{"URL", ls_cmd_url, 2, NS_ULEVEL_OPER, ls_help_url, 0, NULL, NULL},
|
|
|
|
{"STATUS", ls_cmd_status, 0, NS_ULEVEL_OPER, ls_help_status, 0, NULL, NULL},
|
2005-08-17 20:58:41 +00:00
|
|
|
NS_CMD_END()
|
2003-12-31 05:51:22 +00:00
|
|
|
};
|
|
|
|
|
2005-10-20 20:52:55 +00:00
|
|
|
static bot_setting ls_settings[]=
|
2003-12-31 05:51:22 +00:00
|
|
|
{
|
2005-10-17 22:04:14 +00:00
|
|
|
{"LOGTYPE", &LogServ.logtype, SET_TYPE_INT, 1, 3, NS_ULEVEL_ADMIN, NULL, ls_help_set_logtype, NULL, ( void * )1},
|
|
|
|
{"LOGSIZE", &LogServ.maxlogsize, SET_TYPE_INT, 0, 10000000, NS_ULEVEL_ADMIN, "Bytes", ls_help_set_logsize, NULL, ( void * )1000000},
|
|
|
|
{"LOGAGE", &LogServ.maxopentime, SET_TYPE_INT, 0, TS_ONE_DAY, NS_ULEVEL_ADMIN, "Seconds", ls_help_set_logtime, NULL, ( void * )TS_ONE_HOUR},
|
|
|
|
{"LOGDIR", LogServ.logdir, SET_TYPE_STRING, 0, MAXPATH, NS_ULEVEL_ADMIN, NULL, ls_help_set_logdir, NULL, ( void * )"logs/chanlogs"},
|
|
|
|
{"SAVEDIR", LogServ.savedir, SET_TYPE_STRING, 0, MAXPATH, NS_ULEVEL_ADMIN, NULL, ls_help_set_savedir, NULL, ( void * )"chanlogs"},
|
2005-08-17 20:58:41 +00:00
|
|
|
NS_SETTING_END()
|
2003-12-31 05:51:22 +00:00
|
|
|
};
|
2003-12-31 05:13:44 +00:00
|
|
|
|
2005-10-17 22:04:14 +00:00
|
|
|
/** Module event list
|
|
|
|
* What events we will act on
|
|
|
|
* This is required if you want your module to respond to events on IRC
|
|
|
|
* see modules.txt for a list of all events available
|
|
|
|
*/
|
|
|
|
ModuleEvent module_events[] =
|
|
|
|
{
|
|
|
|
{EVENT_CPRIVATE, ls_event_cprivate, 0},
|
|
|
|
{EVENT_CNOTICE, ls_event_cnotice, 0},
|
|
|
|
{EVENT_CTCPACTIONREQ,ls_event_ctcpaction, 0},
|
|
|
|
{EVENT_NEWCHAN, ls_event_newchan, 0},
|
|
|
|
{EVENT_EMPTYCHAN, ls_event_emptychan, 0},
|
|
|
|
{EVENT_JOIN, ls_event_join, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
{EVENT_PART, ls_event_part, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
{EVENT_KICK, ls_event_kick, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
{EVENT_TOPIC, ls_event_topic, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
{EVENT_NICK, ls_event_nick, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
{EVENT_CMODE, ls_event_cmode, EVENT_FLAG_EXCLUDE_MODME},
|
|
|
|
NS_EVENT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
/** BotInfo */
|
|
|
|
static BotInfo ls_botinfo =
|
|
|
|
{
|
|
|
|
"LogServ",
|
|
|
|
"LogServ1",
|
|
|
|
"LS",
|
|
|
|
BOT_COMMON_HOST,
|
|
|
|
"Channel Logging Bot",
|
|
|
|
BOT_FLAG_SERVICEBOT|BOT_FLAG_ONLY_OPERS,
|
|
|
|
ls_commands,
|
|
|
|
ls_settings,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ls_save_channel_data( ChannelLog *cl )
|
|
|
|
{
|
|
|
|
dlog( DEBUG1, "Saving Channel Data for %s", cl->channame );
|
|
|
|
DBAStore( "Channel", cl->channame, cl, sizeof( ChannelLog ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ls_join_logged_channel( Channel *c, ChannelLog *cl )
|
2003-12-31 09:04:45 +00:00
|
|
|
{
|
2008-10-05 02:01:42 +00:00
|
|
|
if( irc_join( ls_bot, cl->channame, me.servicescmode ) == NS_SUCCESS )
|
2005-10-17 22:04:14 +00:00
|
|
|
{
|
2004-08-16 20:59:18 +00:00
|
|
|
cl->flags |= LGSACTIVE;
|
2005-10-14 21:49:36 +00:00
|
|
|
nlog( LOG_NOTICE, "Activated logging on %s", cl->channame );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cl->statsurl[0] != '\0' )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_chanprivmsg( ls_bot, cl->channame, "Stats will be available at %s when Logs are processed next", cl->statsurl );
|
2004-08-16 20:59:18 +00:00
|
|
|
}
|
2003-12-31 09:04:45 +00:00
|
|
|
}
|
2005-10-14 21:49:36 +00:00
|
|
|
SetChannelModValue( c, cl );
|
2004-08-16 20:59:18 +00:00
|
|
|
cl->c = c;
|
2003-12-31 09:04:45 +00:00
|
|
|
}
|
|
|
|
|
2005-10-14 21:49:36 +00:00
|
|
|
static int LoadLogChannel( void *data, int size )
|
2003-12-31 05:13:44 +00:00
|
|
|
{
|
2003-12-31 08:21:26 +00:00
|
|
|
ChannelLog *cl;
|
2004-08-01 21:23:58 +00:00
|
|
|
Channel *c;
|
2004-09-22 21:36:35 +00:00
|
|
|
|
2005-10-14 21:49:36 +00:00
|
|
|
cl = ns_calloc( sizeof( ChannelLog ) );
|
|
|
|
os_memcpy( cl, data, sizeof( ChannelLog ) );
|
|
|
|
dlog( DEBUG1, "Loading Channel %s", cl->channame );
|
|
|
|
c = FindChannel( cl->channame );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( c )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_join_logged_channel( c, cl );
|
2004-01-12 12:57:11 +00:00
|
|
|
}
|
2005-10-15 21:34:59 +00:00
|
|
|
hnode_create_insert( lschannelhash, cl, cl->channame );
|
2005-02-14 22:04:09 +00:00
|
|
|
return NS_FALSE;
|
2004-09-22 21:36:35 +00:00
|
|
|
}
|
|
|
|
|
2005-10-20 21:39:23 +00:00
|
|
|
static void LoadLogChannels( void )
|
2004-09-22 21:36:35 +00:00
|
|
|
{
|
2005-10-14 21:49:36 +00:00
|
|
|
DBAFetchRows( "Channel", LoadLogChannel );
|
2004-08-08 22:46:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_cprivate( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_MSG, cmdparams->channel, cmdparams );
|
2004-08-16 20:59:18 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
2004-08-08 22:46:08 +00:00
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_cnotice( const CmdParams *cmdparams )
|
2004-08-08 22:46:08 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_NOTICE, cmdparams->channel, cmdparams );
|
2004-01-02 10:13:48 +00:00
|
|
|
return NS_SUCCESS;
|
2004-08-16 20:59:18 +00:00
|
|
|
}
|
2004-01-02 10:13:48 +00:00
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_ctcpaction( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_CTCPACTION, cmdparams->channel, cmdparams );
|
2004-08-16 20:59:18 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_part( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_PART, cmdparams->channel, cmdparams );
|
2004-08-16 20:59:18 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_emptychan( const CmdParams *cmdparams )
|
2004-08-01 21:23:58 +00:00
|
|
|
{
|
2004-01-02 10:13:48 +00:00
|
|
|
ChannelLog *cl;
|
2004-08-16 20:59:18 +00:00
|
|
|
|
2005-10-14 21:49:36 +00:00
|
|
|
cl =( ChannelLog * )GetChannelModValue( cmdparams->channel );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cl )
|
|
|
|
{
|
2004-08-16 20:59:18 +00:00
|
|
|
/*close/switch the logfile*/
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_switch_file( cl );
|
2005-10-14 21:49:36 +00:00
|
|
|
ClearChannelModValue( cl->c );
|
2004-08-16 20:59:18 +00:00
|
|
|
cl->c = NULL;
|
|
|
|
cl->flags &= ~LGSACTIVE;
|
|
|
|
}
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
2004-01-02 10:13:48 +00:00
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_join( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_JOIN, cmdparams->channel, cmdparams );
|
2004-01-02 10:13:48 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_newchan( const CmdParams *cmdparams )
|
2004-08-01 21:23:58 +00:00
|
|
|
{
|
2004-01-02 10:13:48 +00:00
|
|
|
ChannelLog *cl;
|
|
|
|
|
2005-10-15 21:34:59 +00:00
|
|
|
cl =( ChannelLog * )hnode_find( lschannelhash, cmdparams->channel );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cl )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_join_logged_channel( cmdparams->channel, cl );
|
2004-08-16 20:59:18 +00:00
|
|
|
}
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_kick( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_KICK, cmdparams->channel, cmdparams );
|
2004-08-16 20:59:18 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_topic( const CmdParams *cmdparams )
|
2004-08-16 20:59:18 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_TOPIC, cmdparams->channel, cmdparams );
|
2004-01-02 10:13:48 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_nick( const CmdParams *cmdparams )
|
2004-08-01 21:23:58 +00:00
|
|
|
{
|
2004-01-02 10:13:48 +00:00
|
|
|
lnode_t *cm;
|
|
|
|
|
|
|
|
/* ok, move through each of the channels */
|
2005-10-14 21:49:36 +00:00
|
|
|
cm = list_first( cmdparams->source->user->chans );
|
2005-10-17 22:04:14 +00:00
|
|
|
while( cm )
|
|
|
|
{
|
|
|
|
ls_send_to_logproc( LGSMSG_NICK, ( ( Channel * )FindChannel( lnode_get( cm ) ) ), cmdparams );
|
2005-10-14 21:49:36 +00:00
|
|
|
cm = list_next( cmdparams->source->user->chans, cm );
|
2004-01-02 10:13:48 +00:00
|
|
|
}
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_event_cmode( const CmdParams *cmdparams )
|
2004-08-01 21:23:58 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_send_to_logproc( LGSMSG_CHANMODE, cmdparams->channel, cmdparams );
|
2004-01-02 10:13:48 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_cmd_add( const CmdParams *cmdparams )
|
2004-08-01 21:23:58 +00:00
|
|
|
{
|
|
|
|
Channel *c;
|
2003-12-31 08:04:14 +00:00
|
|
|
ChannelLog *cl;
|
2004-08-01 21:23:58 +00:00
|
|
|
|
2005-10-17 22:04:14 +00:00
|
|
|
if( hash_lookup( lschannelhash, cmdparams->av[1] ) != NULL )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Already Logging %s.", cmdparams->av[0] );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_FAILURE;
|
2003-12-31 08:04:14 +00:00
|
|
|
}
|
2005-10-14 21:49:36 +00:00
|
|
|
cl = ns_calloc( sizeof( ChannelLog ) );
|
|
|
|
strlcpy( cl->channame, cmdparams->av[0], MAXCHANLEN );
|
2005-11-14 22:36:24 +00:00
|
|
|
if( ircstrcasecmp( cmdparams->av[1], "Public" ) == 0 )
|
2005-10-17 22:04:14 +00:00
|
|
|
{
|
2003-12-31 08:04:14 +00:00
|
|
|
cl->flags |= LGSPUBSTATS;
|
2005-10-17 22:04:14 +00:00
|
|
|
}
|
2005-11-14 22:36:24 +00:00
|
|
|
else if( ircstrcasecmp( cmdparams->av[1], "Private" ) == 0 )
|
2005-10-17 22:04:14 +00:00
|
|
|
{
|
2003-12-31 08:04:14 +00:00
|
|
|
cl->flags &= ~LGSPUBSTATS;
|
2005-10-17 22:04:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Unknown Public Type %s. Setting to Public", cmdparams->av[1] );
|
2003-12-31 08:04:14 +00:00
|
|
|
cl->flags |= LGSPUBSTATS;
|
|
|
|
}
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cmdparams->ac == 3 )
|
|
|
|
{
|
2003-12-31 08:04:14 +00:00
|
|
|
/* we have a URL */
|
2005-10-14 21:49:36 +00:00
|
|
|
strlcpy( cl->statsurl, cmdparams->av[2], MAXPATH );
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Stats URL is set to %s", cl->statsurl );
|
2005-10-17 22:04:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "No Stats URL is Set" );
|
2003-12-31 08:04:14 +00:00
|
|
|
}
|
2005-10-15 21:34:59 +00:00
|
|
|
hnode_create_insert( lschannelhash, cl, cl->channame );
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_save_channel_data( cl );
|
2005-10-14 21:49:36 +00:00
|
|
|
c = FindChannel( cmdparams->av[0] );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( c )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_join_logged_channel( c, cl );
|
|
|
|
irc_chanprivmsg( ls_bot, cl->channame, "%s activated logging on %s", cmdparams->source->name, cl->channame );
|
2003-12-31 08:04:14 +00:00
|
|
|
}
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Activated logging on %s", cl->channame );
|
|
|
|
CommandReport( ls_bot, "%s activated logging on %s", cmdparams->source->name, cl->channame );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_cmd_del( const CmdParams *cmdparams )
|
2004-08-08 22:46:08 +00:00
|
|
|
{
|
|
|
|
hnode_t *hn;
|
|
|
|
ChannelLog *cl;
|
|
|
|
|
2005-10-15 21:34:59 +00:00
|
|
|
hn = hash_lookup( lschannelhash, cmdparams->av[0] );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( !hn )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Can not find channel %s in Logging System", cmdparams->av[0] );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_FAILURE;
|
|
|
|
}
|
2005-10-15 21:34:59 +00:00
|
|
|
cl =( ChannelLog * ) hnode_find( lschannelhash, cmdparams->av[0] );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( !cl )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Can not find Channel %s in Logging System", cmdparams->av[0] );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_FAILURE;
|
|
|
|
}
|
|
|
|
/* rotate out the file */
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cl->flags & LGSACTIVE )
|
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
ls_switch_file( cl );
|
2004-08-08 22:46:08 +00:00
|
|
|
}
|
2005-10-17 22:04:14 +00:00
|
|
|
if( cl->c )
|
|
|
|
{
|
2005-10-14 21:49:36 +00:00
|
|
|
ClearChannelModValue( cl->c );
|
2004-08-08 22:46:08 +00:00
|
|
|
}
|
2005-10-15 21:34:59 +00:00
|
|
|
hash_delete( lschannelhash, hn );
|
2005-10-14 21:49:36 +00:00
|
|
|
hnode_destroy( hn );
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_part( ls_bot, cl->channame, NULL );
|
2005-10-14 21:49:36 +00:00
|
|
|
ns_free( cl );
|
2005-10-14 22:52:42 +00:00
|
|
|
DBADelete( "Channel", cmdparams->av[0] );
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Deleted channel %s", cmdparams->av[0] );
|
|
|
|
CommandReport( ls_bot, "%s deleted %s from logging", cmdparams->source->name, cmdparams->av[0] );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_cmd_list( const CmdParams *cmdparams )
|
2004-08-08 22:46:08 +00:00
|
|
|
{
|
|
|
|
hscan_t hs;
|
|
|
|
hnode_t *hn;
|
|
|
|
ChannelLog *cl;
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Log channel list:" );
|
2005-10-15 21:34:59 +00:00
|
|
|
hash_scan_begin( &hs, lschannelhash );
|
2005-10-17 22:04:14 +00:00
|
|
|
while( ( hn = hash_scan_next( &hs ) ) != NULL )
|
|
|
|
{
|
2005-10-14 21:49:36 +00:00
|
|
|
cl = hnode_get( hn );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( ( cl->flags & LGSPUBSTATS ) ||( UserLevel( cmdparams->source ) >= NS_ULEVEL_LOCOPER ) )
|
|
|
|
{
|
2004-08-08 22:46:08 +00:00
|
|
|
/* its a priv channel, only show to opers */
|
2005-10-17 22:04:14 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "%s( %c ) URL: %s", cl->channame, ( cl->flags & LGSACTIVE ) ? '*' : '-', ( cl->statsurl[0] != 0 ) ? cl->statsurl : "None" );
|
2004-08-08 22:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "End of list." );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:34:33 +00:00
|
|
|
static int ls_cmd_url( const CmdParams *cmdparams )
|
2004-08-08 22:46:08 +00:00
|
|
|
{
|
|
|
|
ChannelLog *cl;
|
|
|
|
|
2005-10-15 21:34:59 +00:00
|
|
|
cl =( ChannelLog * ) hnode_find( lschannelhash, cmdparams->av[0] );
|
2005-10-17 22:04:14 +00:00
|
|
|
if( !cl )
|
|
|
|
{
|
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Channel %s is not currently being logged", cmdparams->av[0] );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_FAILURE;
|
|
|
|
}
|
2005-10-14 21:49:36 +00:00
|
|
|
if( ValidateURL( cmdparams->av[1] ) != NS_SUCCESS )
|
2004-08-31 22:46:57 +00:00
|
|
|
{
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "%s is an invalid URL", cmdparams->av[1] );
|
2004-08-31 22:46:57 +00:00
|
|
|
return NS_FAILURE;
|
|
|
|
}
|
2005-10-14 21:49:36 +00:00
|
|
|
ircsnprintf( cl->statsurl, MAXPATH, "%s", cmdparams->av[1] );
|
2005-10-15 22:34:33 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Changed URL for %s to: %s", cl->channame, cl->statsurl );
|
|
|
|
CommandReport( ls_bot, "%s changed the URL for %s to: %s", cmdparams->source->name, cl->channame, cl->statsurl );
|
|
|
|
ls_save_channel_data( cl );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @brief Send some very simple stats to the user
|
|
|
|
*
|
|
|
|
* @param u The user requesting stats data
|
|
|
|
* @returns NS_SUCCESS or NS_FAILURE
|
|
|
|
*/
|
2005-10-17 22:04:14 +00:00
|
|
|
static int ls_cmd_status( const CmdParams *cmdparams )
|
2004-08-08 22:46:08 +00:00
|
|
|
{
|
2005-10-17 22:04:14 +00:00
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Status:" );
|
|
|
|
irc_prefmsg( ls_bot, cmdparams->source, "Logging %d channels", ( int )hash_count( lschannelhash ) );
|
2004-08-08 22:46:08 +00:00
|
|
|
return NS_SUCCESS;
|
2003-12-31 08:04:14 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 22:04:14 +00:00
|
|
|
/** Init module
|
|
|
|
* This is required if you need to do initialisation of your module when
|
|
|
|
* first loaded
|
|
|
|
*/
|
|
|
|
int ModInit( void )
|
|
|
|
{
|
|
|
|
ModuleConfig( ls_settings );
|
|
|
|
lschannelhash = hash_create( HASHCOUNT_T_MAX, 0,0 );
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief ModSynch
|
|
|
|
*
|
|
|
|
* Startup handler
|
|
|
|
*
|
|
|
|
* @param none
|
|
|
|
*
|
|
|
|
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ModSynch( void )
|
|
|
|
{
|
|
|
|
/* Introduce a bot onto the network */
|
|
|
|
ls_bot = AddBot( &ls_botinfo );
|
|
|
|
if( !ls_bot )
|
|
|
|
{
|
|
|
|
return NS_FAILURE;
|
|
|
|
}
|
|
|
|
/* load Channels and join them */
|
|
|
|
LoadLogChannels();
|
|
|
|
/* start a timer to scan the logs for rotation */
|
|
|
|
(void)AddTimer( TIMER_TYPE_INTERVAL, ls_rotate_logs, "ls_rotate_logs", 300, NULL );
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Init module
|
|
|
|
* This is required if you need to do cleanup of your module when it ends
|
|
|
|
*/
|
|
|
|
int ModFini( void )
|
|
|
|
{
|
|
|
|
/* close the log files */
|
|
|
|
ls_close_logs();
|
|
|
|
/* delete the hash */
|
|
|
|
hash_destroy( lschannelhash );
|
|
|
|
return NS_SUCCESS;
|
|
|
|
}
|