summaryrefslogtreecommitdiff
path: root/src/core/os_set.c
blob: 90d9806e6e254b769014d6e6ada96dfa3dd1f2d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/* OperServ core functions
 *
 * (C) 2003-2014 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church. 
 * 
 *
 */
/*************************************************************************/

#include "module.h"

static int do_set(User * u);
static void myOperServHelp(User * u);

/**
 * Create the command, and tell anope about it.
 * @param argc Argument count
 * @param argv Argument list
 * @return MOD_CONT to allow the module, MOD_STOP to stop it
 **/
int AnopeInit(int argc, char **argv)
{
    Command *c;

    moduleAddAuthor("Anope");
    moduleAddVersion(VERSION_STRING);
    moduleSetType(CORE);

    c = createCommand("SET", do_set, is_services_root, OPER_HELP_SET, -1,
                      -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET LIST", NULL, NULL, OPER_HELP_SET_LIST, -1, -1,
                      -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET READONLY", NULL, NULL, OPER_HELP_SET_READONLY,
                      -1, -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET LOGCHAN", NULL, NULL, OPER_HELP_SET_LOGCHAN, -1,
                      -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET DEBUG", NULL, NULL, OPER_HELP_SET_DEBUG, -1, -1,
                      -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET NOEXPIRE", NULL, NULL, OPER_HELP_SET_NOEXPIRE,
                      -1, -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET IGNORE", NULL, NULL, OPER_HELP_SET_IGNORE, -1,
                      -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
    c = createCommand("SET SUPERADMIN", NULL, NULL,
                      OPER_HELP_SET_SUPERADMIN, -1, -1, -1, -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
#ifdef USE_MYSQL
    c = createCommand("SET SQL", NULL, NULL, OPER_HELP_SET_SQL, -1, -1, -1,
                      -1);
    moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
#endif

    moduleSetOperHelp(myOperServHelp);

    return MOD_CONT;
}

/**
 * Unload the module
 **/
void AnopeFini(void)
{

}


/**
 * Add the help response to anopes /os help output.
 * @param u The user who is requesting help
 **/
static void myOperServHelp(User * u)
{
    if (is_services_root(u)) {
        notice_lang(s_OperServ, u, OPER_HELP_CMD_SET);
    }
}

/**
 * The /os set command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_set(User * u)
{
    char *option = strtok(NULL, " ");
    char *setting = strtok(NULL, " ");
    int index;
    Channel *c;

    if (!option) {
        syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
    } else if (stricmp(option, "LIST") == 0) {
        index =
            (allow_ignore ? OPER_SET_LIST_OPTION_ON :
             OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "IGNORE");
        index =
            (readonly ? OPER_SET_LIST_OPTION_ON :
             OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "READONLY");
        index =
            (logchan ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "LOGCHAN");
        index =
            (debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "DEBUG");
        index =
            (noexpire ? OPER_SET_LIST_OPTION_ON :
             OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "NOEXPIRE");
#ifdef USE_MYSQL
        index =
            (do_mysql ? OPER_SET_LIST_OPTION_ON :
             OPER_SET_LIST_OPTION_OFF);
        notice_lang(s_OperServ, u, index, "SQL");
#endif
    } else if (!setting) {
        syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
    } else if (stricmp(option, "IGNORE") == 0) {
        if (stricmp(setting, "on") == 0) {
            allow_ignore = 1;
            notice_lang(s_OperServ, u, OPER_SET_IGNORE_ON);
        } else if (stricmp(setting, "off") == 0) {
            allow_ignore = 0;
            notice_lang(s_OperServ, u, OPER_SET_IGNORE_OFF);
        } else {
            notice_lang(s_OperServ, u, OPER_SET_IGNORE_ERROR);
        }
#ifdef USE_MYSQL
    } else if (stricmp(option, "SQL") == 0) {
        if (stricmp(setting, "on") == 0) {
            if (!MysqlHost) {
                notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
            } else {
                if (rdb_init()) {
                    notice_lang(s_OperServ, u, OPER_SET_SQL_ON);
                } else {
                    notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_INIT);
                }
            }
        } else if (stricmp(setting, "off") == 0) {
            if (!MysqlHost) {
                notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
            } else {
                /* could call rdb_close() but that does nothing - TSL */
                do_mysql = 0;
                notice_lang(s_OperServ, u, OPER_SET_SQL_OFF);
            }
        } else {
            notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR);
        }
#endif
    } else if (stricmp(option, "READONLY") == 0) {
        if (stricmp(setting, "on") == 0) {
            readonly = 1;
            alog("Read-only mode activated");
            close_log();
            notice_lang(s_OperServ, u, OPER_SET_READONLY_ON);
        } else if (stricmp(setting, "off") == 0) {
            readonly = 0;
            open_log();
            alog("Read-only mode deactivated");
            notice_lang(s_OperServ, u, OPER_SET_READONLY_OFF);
        } else {
            notice_lang(s_OperServ, u, OPER_SET_READONLY_ERROR);
        }

    } else if (stricmp(option, "LOGCHAN") == 0) {
        /* Unlike the other SET commands where only stricmp is necessary,
         * we also have to ensure that LogChannel is defined or we can't
         * send to it.
         *
         * -jester
         */
        if (LogChannel && (stricmp(setting, "on") == 0)) {
            if (ircd->join2msg) {
                c = findchan(LogChannel);
                anope_cmd_join(s_GlobalNoticer, LogChannel, c ? c->creation_time : time(NULL));
            }
            logchan = 1;
            alog("Now sending log messages to %s", LogChannel);
            notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ON, LogChannel);
        } else if (LogChannel && (stricmp(setting, "off") == 0)) {
            alog("No longer sending log messages to a channel");
            if (ircd->join2msg) {
                anope_cmd_part(s_GlobalNoticer, LogChannel, NULL);
            }
            logchan = 0;
            notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_OFF);
        } else {
            notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ERROR);
        }
        /**
         * Allow the user to turn super admin on/off
	 *
	 * Rob
         **/
    } else if (stricmp(option, "SUPERADMIN") == 0) {
        if (!SuperAdmin) {
            notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED);
        } else if (stricmp(setting, "on") == 0) {
            u->isSuperAdmin = 1;
            notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ON);
            alog("%s: %s is a SuperAdmin ", s_OperServ, u->nick);
            anope_cmd_global(s_OperServ,
                             getstring2(NULL, OPER_SUPER_ADMIN_WALL_ON),
                             u->nick);
        } else if (stricmp(setting, "off") == 0) {
            u->isSuperAdmin = 0;
            notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_OFF);
            alog("%s: %s is no longer a SuperAdmin", s_OperServ, u->nick);
            anope_cmd_global(s_OperServ,
                             getstring2(NULL, OPER_SUPER_ADMIN_WALL_OFF),
                             u->nick);
        } else {
            notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_SYNTAX);
        }
    } else if (stricmp(option, "DEBUG") == 0) {
        if (stricmp(setting, "on") == 0) {
            debug = 1;
            alog("Debug mode activated");
            notice_lang(s_OperServ, u, OPER_SET_DEBUG_ON);
        } else if (stricmp(setting, "off") == 0 ||
                   (*setting == '0' && atoi(setting) == 0)) {
            alog("Debug mode deactivated");
            debug = 0;
            notice_lang(s_OperServ, u, OPER_SET_DEBUG_OFF);
        } else if (isdigit(*setting) && atoi(setting) > 0) {
            debug = atoi(setting);
            alog("Debug mode activated (level %d)", debug);
            notice_lang(s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug);
        } else {
            notice_lang(s_OperServ, u, OPER_SET_DEBUG_ERROR);
        }

    } else if (stricmp(option, "NOEXPIRE") == 0) {
        if (stricmp(setting, "ON") == 0) {
            noexpire = 1;
            alog("No expire mode activated");
            notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ON);
        } else if (stricmp(setting, "OFF") == 0) {
            noexpire = 0;
            alog("No expire mode deactivated");
            notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_OFF);
        } else {
            notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ERROR);
        }
    } else {
        notice_lang(s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option);
    }
    return MOD_CONT;
}