unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

staff.c (3860B)

      1 /*
      2  *   cmd_staff: Displays a file(/URL) when the /STAFF command is used.
      3  *   (C) Copyright 2004-2016 Syzop <syzop@vulnscan.org>
      4  *   (C) Copyright 2003-2004 AngryWolf <angrywolf@flashmail.com>
      5  *
      6  *   This program is free software; you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 1, or (at your option)
      9  *   any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  *   GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program; if not, write to the Free Software
     18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     19  */
     20 
     21 #include "unrealircd.h"
     22 
     23 ModuleHeader MOD_HEADER
     24   = {
     25 	"staff",
     26 	"3.8",
     27 	"/STAFF command",
     28 	"UnrealIRCd Team",
     29 	"unrealircd-6",
     30     };
     31 
     32 #define MSG_STAFF	"STAFF"
     33 
     34 #define DEF_STAFF_FILE   CONFDIR "/network.staff"
     35 #define STAFF_FILE       (staff_file ? staff_file : DEF_STAFF_FILE)
     36 
     37 #define RPL_STAFF        ":%s 700 %s :- %s"
     38 #define RPL_STAFFSTART   ":%s 701 %s :- %s IRC Network Staff Information -"
     39 #define RPL_ENDOFSTAFF   ":%s 702 %s :End of /STAFF command."
     40 #define RPL_NOSTAFF      ":%s 703 %s :Network Staff File is missing"
     41 
     42 /* Forward declarations */
     43 static void unload_motd_file(MOTDFile *list);
     44 CMD_FUNC(cmd_staff);
     45 static int cb_test(ConfigFile *, ConfigEntry *, int, int *);
     46 static int cb_conf(ConfigFile *, ConfigEntry *, int);
     47 static int cb_stats(Client *client, const char *flag);
     48 static void FreeConf();
     49 
     50 static MOTDFile staff;
     51 static char *staff_file = NULL;
     52 
     53 MOD_TEST()
     54 {
     55 	HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, cb_test);
     56 	return MOD_SUCCESS;
     57 }
     58 
     59 MOD_INIT()
     60 {
     61 	MARK_AS_OFFICIAL_MODULE(modinfo);
     62 	memset(&staff, 0, sizeof(staff));
     63 
     64 	CommandAdd(modinfo->handle, MSG_STAFF, cmd_staff, MAXPARA, CMD_USER);
     65 	HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, cb_conf);
     66 	HookAdd(modinfo->handle, HOOKTYPE_STATS, 0, cb_stats);
     67 
     68 	return MOD_SUCCESS;
     69 }
     70 
     71 MOD_LOAD()
     72 {
     73 	return MOD_SUCCESS;
     74 }
     75 
     76 MOD_UNLOAD()
     77 {
     78 	FreeConf();
     79 	unload_motd_file(&staff);
     80 
     81 	return MOD_SUCCESS;
     82 }
     83 
     84 static void FreeConf()
     85 {
     86 	safe_free(staff_file);
     87 }
     88 
     89 static void unload_motd_file(MOTDFile *list)
     90 {
     91 	MOTDLine *old, *new;
     92 
     93 	if (!list)
     94 		return;
     95 
     96 	new = list->lines;
     97 
     98 	if (!new)
     99 		return;
    100 
    101 	while (new)
    102 	{
    103 		old = new->next;
    104 		safe_free(new->line);
    105 		safe_free(new);
    106 		new = old;
    107 	}
    108 }
    109 
    110 static int cb_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
    111 {
    112 	int errors = 0;
    113 
    114 	if (type == CONFIG_SET)
    115 	{
    116 		if (!strcmp(ce->name, "staff-file"))
    117 		{
    118 			*errs = errors;
    119 			return errors ? -1 : 1;
    120 		}
    121 	}
    122 
    123 	return 0;
    124 }
    125 
    126 static int cb_conf(ConfigFile *cf, ConfigEntry *ce, int type)
    127 {
    128 	if (type == CONFIG_SET)
    129 	{
    130 		if (!strcmp(ce->name, "staff-file"))
    131 		{
    132 			convert_to_absolute_path(&ce->value, CONFDIR);
    133 			read_motd(ce->value, &staff);
    134 			return 1;
    135 		}
    136 	}
    137 
    138 	return 0;
    139 }
    140 
    141 static int cb_stats(Client *client, const char *flag)
    142 {
    143 	if (*flag == 'S')
    144 	{
    145 		sendtxtnumeric(client, "staff-file: %s", STAFF_FILE);
    146 		return 1;
    147 	}
    148 
    149 	return 0;
    150 }
    151 
    152 /** The routine that actual does the /STAFF command */
    153 CMD_FUNC(cmd_staff)
    154 {
    155 	MOTDFile *temp;
    156 	MOTDLine *aLine;
    157 
    158 	if (!IsUser(client))
    159 		return;
    160 
    161 	if (hunt_server(client, recv_mtags, "STAFF", 1, parc, parv) != HUNTED_ISME)
    162 		return;
    163 
    164 	if (!staff.lines)
    165 	{
    166 		sendto_one(client, NULL, RPL_NOSTAFF, me.name, client->name);
    167 		return;
    168 	}
    169 
    170 	sendto_one(client, NULL, RPL_STAFFSTART, me.name, client->name, NETWORK_NAME);
    171 
    172 	temp = &staff;
    173 
    174 	for (aLine = temp->lines; aLine; aLine = aLine->next)
    175 		sendto_one(client, NULL, RPL_STAFF, me.name, client->name, aLine->line);
    176 
    177 	sendto_one(client, NULL, RPL_ENDOFSTAFF, me.name, client->name);
    178 }