os_set.c

Go to the documentation of this file.
00001 /* OperServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  *
00012  */
00013 /*************************************************************************/
00014 
00015 #include "module.h"
00016 
00017 static int do_set(User * u);
00018 static void myOperServHelp(User * u);
00019 
00026 int AnopeInit(int argc, char **argv)
00027 {
00028     Command *c;
00029 
00030     moduleAddAuthor("Anope");
00031     moduleAddVersion(VERSION_STRING);
00032     moduleSetType(CORE);
00033 
00034     c = createCommand("SET", do_set, is_services_root, OPER_HELP_SET, -1,
00035                       -1, -1, -1);
00036     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00037     c = createCommand("SET LIST", NULL, NULL, OPER_HELP_SET_LIST, -1, -1,
00038                       -1, -1);
00039     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00040     c = createCommand("SET READONLY", NULL, NULL, OPER_HELP_SET_READONLY,
00041                       -1, -1, -1, -1);
00042     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00043     c = createCommand("SET LOGCHAN", NULL, NULL, OPER_HELP_SET_LOGCHAN, -1,
00044                       -1, -1, -1);
00045     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00046     c = createCommand("SET DEBUG", NULL, NULL, OPER_HELP_SET_DEBUG, -1, -1,
00047                       -1, -1);
00048     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00049     c = createCommand("SET NOEXPIRE", NULL, NULL, OPER_HELP_SET_NOEXPIRE,
00050                       -1, -1, -1, -1);
00051     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00052     c = createCommand("SET IGNORE", NULL, NULL, OPER_HELP_SET_IGNORE, -1,
00053                       -1, -1, -1);
00054     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00055     c = createCommand("SET SUPERADMIN", NULL, NULL,
00056                       OPER_HELP_SET_SUPERADMIN, -1, -1, -1, -1);
00057     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00058 #ifdef USE_MYSQL
00059     c = createCommand("SET SQL", NULL, NULL, OPER_HELP_SET_SQL, -1, -1, -1,
00060                       -1);
00061     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00062 #endif
00063 
00064     moduleSetOperHelp(myOperServHelp);
00065 
00066     return MOD_CONT;
00067 }
00068 
00072 void AnopeFini(void)
00073 {
00074 
00075 }
00076 
00077 
00082 static void myOperServHelp(User * u)
00083 {
00084     if (is_services_root(u)) {
00085         notice_lang(s_OperServ, u, OPER_HELP_CMD_SET);
00086     }
00087 }
00088 
00094 static int do_set(User * u)
00095 {
00096     char *option = strtok(NULL, " ");
00097     char *setting = strtok(NULL, " ");
00098     int index;
00099     Channel *c;
00100 
00101     if (!option) {
00102         syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
00103     } else if (stricmp(option, "LIST") == 0) {
00104         index =
00105             (allow_ignore ? OPER_SET_LIST_OPTION_ON :
00106              OPER_SET_LIST_OPTION_OFF);
00107         notice_lang(s_OperServ, u, index, "IGNORE");
00108         index =
00109             (readonly ? OPER_SET_LIST_OPTION_ON :
00110              OPER_SET_LIST_OPTION_OFF);
00111         notice_lang(s_OperServ, u, index, "READONLY");
00112         index =
00113             (logchan ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
00114         notice_lang(s_OperServ, u, index, "LOGCHAN");
00115         index =
00116             (debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF);
00117         notice_lang(s_OperServ, u, index, "DEBUG");
00118         index =
00119             (noexpire ? OPER_SET_LIST_OPTION_ON :
00120              OPER_SET_LIST_OPTION_OFF);
00121         notice_lang(s_OperServ, u, index, "NOEXPIRE");
00122 #ifdef USE_MYSQL
00123         index =
00124             (do_mysql ? OPER_SET_LIST_OPTION_ON :
00125              OPER_SET_LIST_OPTION_OFF);
00126         notice_lang(s_OperServ, u, index, "SQL");
00127 #endif
00128     } else if (!setting) {
00129         syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX);
00130     } else if (stricmp(option, "IGNORE") == 0) {
00131         if (stricmp(setting, "on") == 0) {
00132             allow_ignore = 1;
00133             notice_lang(s_OperServ, u, OPER_SET_IGNORE_ON);
00134         } else if (stricmp(setting, "off") == 0) {
00135             allow_ignore = 0;
00136             notice_lang(s_OperServ, u, OPER_SET_IGNORE_OFF);
00137         } else {
00138             notice_lang(s_OperServ, u, OPER_SET_IGNORE_ERROR);
00139         }
00140 #ifdef USE_MYSQL
00141     } else if (stricmp(option, "SQL") == 0) {
00142         if (stricmp(setting, "on") == 0) {
00143             if (!MysqlHost) {
00144                 notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
00145             } else {
00146                 if (rdb_init()) {
00147                     notice_lang(s_OperServ, u, OPER_SET_SQL_ON);
00148                 } else {
00149                     notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_INIT);
00150                 }
00151             }
00152         } else if (stricmp(setting, "off") == 0) {
00153             if (!MysqlHost) {
00154                 notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED);
00155             } else {
00156                 /* could call rdb_close() but that does nothing - TSL */
00157                 do_mysql = 0;
00158                 notice_lang(s_OperServ, u, OPER_SET_SQL_OFF);
00159             }
00160         } else {
00161             notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR);
00162         }
00163 #endif
00164     } else if (stricmp(option, "READONLY") == 0) {
00165         if (stricmp(setting, "on") == 0) {
00166             readonly = 1;
00167             alog("Read-only mode activated");
00168             close_log();
00169             notice_lang(s_OperServ, u, OPER_SET_READONLY_ON);
00170         } else if (stricmp(setting, "off") == 0) {
00171             readonly = 0;
00172             open_log();
00173             alog("Read-only mode deactivated");
00174             notice_lang(s_OperServ, u, OPER_SET_READONLY_OFF);
00175         } else {
00176             notice_lang(s_OperServ, u, OPER_SET_READONLY_ERROR);
00177         }
00178 
00179     } else if (stricmp(option, "LOGCHAN") == 0) {
00180         /* Unlike the other SET commands where only stricmp is necessary,
00181          * we also have to ensure that LogChannel is defined or we can't
00182          * send to it.
00183          *
00184          * -jester
00185          */
00186         if (LogChannel && (stricmp(setting, "on") == 0)) {
00187             if (ircd->join2msg) {
00188                 c = findchan(LogChannel);
00189                 anope_cmd_join(s_GlobalNoticer, LogChannel, c ? c->creation_time : time(NULL));
00190             }
00191             logchan = 1;
00192             alog("Now sending log messages to %s", LogChannel);
00193             notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ON, LogChannel);
00194         } else if (LogChannel && (stricmp(setting, "off") == 0)) {
00195             alog("No longer sending log messages to a channel");
00196             if (ircd->join2msg) {
00197                 anope_cmd_part(s_GlobalNoticer, LogChannel, NULL);
00198             }
00199             logchan = 0;
00200             notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_OFF);
00201         } else {
00202             notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ERROR);
00203         }
00209     } else if (stricmp(option, "SUPERADMIN") == 0) {
00210         if (!SuperAdmin) {
00211             notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED);
00212         } else if (stricmp(setting, "on") == 0) {
00213             u->isSuperAdmin = 1;
00214             notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ON);
00215             alog("%s: %s is a SuperAdmin ", s_OperServ, u->nick);
00216             anope_cmd_global(s_OperServ,
00217                              getstring2(NULL, OPER_SUPER_ADMIN_WALL_ON),
00218                              u->nick);
00219         } else if (stricmp(setting, "off") == 0) {
00220             u->isSuperAdmin = 0;
00221             notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_OFF);
00222             alog("%s: %s is no longer a SuperAdmin", s_OperServ, u->nick);
00223             anope_cmd_global(s_OperServ,
00224                              getstring2(NULL, OPER_SUPER_ADMIN_WALL_OFF),
00225                              u->nick);
00226         } else {
00227             notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_SYNTAX);
00228         }
00229     } else if (stricmp(option, "DEBUG") == 0) {
00230         if (stricmp(setting, "on") == 0) {
00231             debug = 1;
00232             alog("Debug mode activated");
00233             notice_lang(s_OperServ, u, OPER_SET_DEBUG_ON);
00234         } else if (stricmp(setting, "off") == 0 ||
00235                    (*setting == '0' && atoi(setting) == 0)) {
00236             alog("Debug mode deactivated");
00237             debug = 0;
00238             notice_lang(s_OperServ, u, OPER_SET_DEBUG_OFF);
00239         } else if (isdigit(*setting) && atoi(setting) > 0) {
00240             debug = atoi(setting);
00241             alog("Debug mode activated (level %d)", debug);
00242             notice_lang(s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug);
00243         } else {
00244             notice_lang(s_OperServ, u, OPER_SET_DEBUG_ERROR);
00245         }
00246 
00247     } else if (stricmp(option, "NOEXPIRE") == 0) {
00248         if (stricmp(setting, "ON") == 0) {
00249             noexpire = 1;
00250             alog("No expire mode activated");
00251             notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ON);
00252         } else if (stricmp(setting, "OFF") == 0) {
00253             noexpire = 0;
00254             alog("No expire mode deactivated");
00255             notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_OFF);
00256         } else {
00257             notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ERROR);
00258         }
00259     } else {
00260         notice_lang(s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option);
00261     }
00262     return MOD_CONT;
00263 }