Anope IRC Services  Version 1.8
os_set.c
Go to the documentation of this file.
1 /* OperServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_set(User * u);
18 static void myOperServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("SET", do_set, is_services_root, OPER_HELP_SET, -1,
35  -1, -1, -1);
37  c = createCommand("SET LIST", NULL, NULL, OPER_HELP_SET_LIST, -1, -1,
38  -1, -1);
40  c = createCommand("SET READONLY", NULL, NULL, OPER_HELP_SET_READONLY,
41  -1, -1, -1, -1);
43  c = createCommand("SET LOGCHAN", NULL, NULL, OPER_HELP_SET_LOGCHAN, -1,
44  -1, -1, -1);
46  c = createCommand("SET DEBUG", NULL, NULL, OPER_HELP_SET_DEBUG, -1, -1,
47  -1, -1);
49  c = createCommand("SET NOEXPIRE", NULL, NULL, OPER_HELP_SET_NOEXPIRE,
50  -1, -1, -1, -1);
52  c = createCommand("SET IGNORE", NULL, NULL, OPER_HELP_SET_IGNORE, -1,
53  -1, -1, -1);
55  c = createCommand("SET SUPERADMIN", NULL, NULL,
56  OPER_HELP_SET_SUPERADMIN, -1, -1, -1, -1);
58 #ifdef USE_MYSQL
59  c = createCommand("SET SQL", NULL, NULL, OPER_HELP_SET_SQL, -1, -1, -1,
60  -1);
62 #endif
63 
65 
66  return MOD_CONT;
67 }
68 
72 void AnopeFini(void)
73 {
74 
75 }
76 
77 
82 static void myOperServHelp(User * u)
83 {
84  if (is_services_root(u)) {
85  notice_lang(s_OperServ, u, OPER_HELP_CMD_SET);
86  }
87 }
88 
94 static int do_set(User * u)
95 {
96  char *option = strtok(NULL, " ");
97  char *setting = strtok(NULL, " ");
98  int index;
99  Channel *c;
100 
101  if (!option) {
102  syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
103  } else if (stricmp(option, "LIST") == 0) {
104  index =
105  (allow_ignore ? OPER_SET_LIST_OPTION_ON :
106  OPER_SET_LIST_OPTION_OFF);
107  notice_lang(s_OperServ, u, index, "IGNORE");
108  index =
109  (readonly ? OPER_SET_LIST_OPTION_ON :
110  OPER_SET_LIST_OPTION_OFF);
111  notice_lang(s_OperServ, u, index, "READONLY");
112  index =
113  (logchan ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
114  notice_lang(s_OperServ, u, index, "LOGCHAN");
115  index =
116  (debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
117  notice_lang(s_OperServ, u, index, "DEBUG");
118  index =
119  (noexpire ? OPER_SET_LIST_OPTION_ON :
120  OPER_SET_LIST_OPTION_OFF);
121  notice_lang(s_OperServ, u, index, "NOEXPIRE");
122 #ifdef USE_MYSQL
123  index =
124  (do_mysql ? OPER_SET_LIST_OPTION_ON :
125  OPER_SET_LIST_OPTION_OFF);
126  notice_lang(s_OperServ, u, index, "SQL");
127 #endif
128  } else if (!setting) {
129  syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
130  } else if (stricmp(option, "IGNORE") == 0) {
131  if (stricmp(setting, "on") == 0) {
132  allow_ignore = 1;
133  notice_lang(s_OperServ, u, OPER_SET_IGNORE_ON);
134  } else if (stricmp(setting, "off") == 0) {
135  allow_ignore = 0;
136  notice_lang(s_OperServ, u, OPER_SET_IGNORE_OFF);
137  } else {
138  notice_lang(s_OperServ, u, OPER_SET_IGNORE_ERROR);
139  }
140 #ifdef USE_MYSQL
141  } else if (stricmp(option, "SQL") == 0) {
142  if (stricmp(setting, "on") == 0) {
143  if (!MysqlHost) {
144  notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
145  } else {
146  if (rdb_init()) {
147  notice_lang(s_OperServ, u, OPER_SET_SQL_ON);
148  } else {
149  notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_INIT);
150  }
151  }
152  } else if (stricmp(setting, "off") == 0) {
153  if (!MysqlHost) {
154  notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
155  } else {
156  /* could call rdb_close() but that does nothing - TSL */
157  do_mysql = 0;
158  notice_lang(s_OperServ, u, OPER_SET_SQL_OFF);
159  }
160  } else {
161  notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR);
162  }
163 #endif
164  } else if (stricmp(option, "READONLY") == 0) {
165  if (stricmp(setting, "on") == 0) {
166  readonly = 1;
167  alog("Read-only mode activated");
168  close_log();
169  notice_lang(s_OperServ, u, OPER_SET_READONLY_ON);
170  } else if (stricmp(setting, "off") == 0) {
171  readonly = 0;
172  open_log();
173  alog("Read-only mode deactivated");
174  notice_lang(s_OperServ, u, OPER_SET_READONLY_OFF);
175  } else {
176  notice_lang(s_OperServ, u, OPER_SET_READONLY_ERROR);
177  }
178 
179  } else if (stricmp(option, "LOGCHAN") == 0) {
180  /* Unlike the other SET commands where only stricmp is necessary,
181  * we also have to ensure that LogChannel is defined or we can't
182  * send to it.
183  *
184  * -jester
185  */
186  if (LogChannel && (stricmp(setting, "on") == 0)) {
187  if (ircd->join2msg) {
188  c = findchan(LogChannel);
190  }
191  logchan = 1;
192  alog("Now sending log messages to %s", LogChannel);
193  notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ON, LogChannel);
194  } else if (LogChannel && (stricmp(setting, "off") == 0)) {
195  alog("No longer sending log messages to a channel");
196  if (ircd->join2msg) {
198  }
199  logchan = 0;
200  notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_OFF);
201  } else {
202  notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ERROR);
203  }
209  } else if (stricmp(option, "SUPERADMIN") == 0) {
210  if (!SuperAdmin) {
211  notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED);
212  } else if (stricmp(setting, "on") == 0) {
213  u->isSuperAdmin = 1;
214  notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ON);
215  alog("%s: %s is a SuperAdmin ", s_OperServ, u->nick);
217  getstring2(NULL, OPER_SUPER_ADMIN_WALL_ON),
218  u->nick);
219  } else if (stricmp(setting, "off") == 0) {
220  u->isSuperAdmin = 0;
221  notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_OFF);
222  alog("%s: %s is no longer a SuperAdmin", s_OperServ, u->nick);
224  getstring2(NULL, OPER_SUPER_ADMIN_WALL_OFF),
225  u->nick);
226  } else {
227  notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_SYNTAX);
228  }
229  } else if (stricmp(option, "DEBUG") == 0) {
230  if (stricmp(setting, "on") == 0) {
231  debug = 1;
232  alog("Debug mode activated");
233  notice_lang(s_OperServ, u, OPER_SET_DEBUG_ON);
234  } else if (stricmp(setting, "off") == 0 ||
235  (*setting == '0' && atoi(setting) == 0)) {
236  alog("Debug mode deactivated");
237  debug = 0;
238  notice_lang(s_OperServ, u, OPER_SET_DEBUG_OFF);
239  } else if (isdigit(*setting) && atoi(setting) > 0) {
240  debug = atoi(setting);
241  alog("Debug mode activated (level %d)", debug);
242  notice_lang(s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug);
243  } else {
244  notice_lang(s_OperServ, u, OPER_SET_DEBUG_ERROR);
245  }
246 
247  } else if (stricmp(option, "NOEXPIRE") == 0) {
248  if (stricmp(setting, "ON") == 0) {
249  noexpire = 1;
250  alog("No expire mode activated");
251  notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ON);
252  } else if (stricmp(setting, "OFF") == 0) {
253  noexpire = 0;
254  alog("No expire mode deactivated");
255  notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_OFF);
256  } else {
257  notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ERROR);
258  }
259  } else {
260  notice_lang(s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option);
261  }
262  return MOD_CONT;
263 }
E void close_log(void)
Definition: log.c:109
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
E void anope_cmd_part(char *nick, char *chan, const char *fmt,...)
Definition: ircd.c:367
E IRCDVar * ircd
Definition: extern.h:39
E int allow_ignore
Definition: extern.h:1021
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E void anope_cmd_join(char *user, char *channel, time_t chantime)
Definition: ircd.c:352
#define getstring2(nc, index)
Definition: extern.h:733
int isSuperAdmin
Definition: services.h:896
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
int AnopeInit(int argc, char **argv)
Definition: os_set.c:26
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
char * MysqlHost
Definition: config.c:311
E Channel * findchan(const char *chan)
Definition: channels.c:394
E int is_services_root(User *u)
Definition: operserv.c:577
E int SuperAdmin
Definition: extern.h:437
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
E int open_log(void)
Definition: log.c:89
time_t creation_time
Definition: services.h:1002
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
char * setting
Definition: hs_conf.c:14
int rdb_init()
Definition: rdb.c:18
Command * c
Definition: ns_recover.c:17
E void alog(const char *fmt,...) FORMAT(printf
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
E int debug
Definition: extern.h:775
int join2msg
Definition: services.h:319
E int logchan
Definition: extern.h:777
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E char * LogChannel
Definition: extern.h:280
void AnopeFini(void)
Definition: os_set.c:72
static void myOperServHelp(User *u)
Definition: os_set.c:82
static int do_set(User *u)
Definition: os_set.c:94
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E int noexpire
Definition: extern.h:782
E char * s_GlobalNoticer
Definition: extern.h:290
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506