/***************************************************************************/ /** ircd_version.c **************** Author: GeniusDex ** Version: 2.0.0 **/ /***************************************************************************/ /* */ /* With this module you can change or disable the version reply of the */ /* services. You can add or remove a personal text, compile flags, and */ /* build info. */ /* */ /***************************************************************************/ /***************************************************************************/ /** CHANGES ***************************************** VERSION HISTORY **/ /***************************************************************************/ /*** 2.0.0 ************************************************** 2004/01/09 ***/ /* -Initial release of the v2 series */ /***************************************************************************/ /***************************************************************************/ /** CONFIGURATION ************************************* CONFIGURATION **/ /***************************************************************************/ /* IRCD_VERSION_ACCESS_CHANGE **********************************************/ /****************************** */ /* Set this directive to the minimum services oper level required to */ /* change or disable the services version reply. */ /* */ /* Available oper levels are: */ /* OPER_OPER User is a Services Operator */ /* OPER_ADMIN User is a Services Admin */ /* OPER_ROOT User is a Services Root */ /***************************************************************************/ #define IRCD_VERSION_ACCESS_CHANGE OPER_ROOT /***************************************************************************/ /* IRCD_VERSION_DB_FILE ****************************************************/ /************************ */ /* Set this directive to the name of the ircd_version dbase/settings file */ /***************************************************************************/ #define IRCD_VERSION_DB_FILE "version.db" /***************************************************************************/ /** END OF CONFIGURATION *************************** END OF CONFIGURATION **/ /****************** Don't change anything below this line ******************/ /***************************************************************************/ #include "module.h" #define AUTHOR "GeniusDex" #define VERSION "2.0.0" #define OPER_NOREG 0 #define OPER_USER 1 #define OPER_OPER 2 #define OPER_ADMIN 3 #define OPER_ROOT 4 #define OPTION_DISPLAY 1 #define OPTION_SHOW_FLAGS 2 #define OPTION_SHOW_BUILD 4 #define OPTION_SHOW_MSG 8 #define DB_VERSION 10 #define DB_OK 1 #define DB_ERR 0 extern User *mod_current_user; char *build_version(); int my_version(char *source, int ac, char **av); int my_os_version(User *u); int my_os_version_syntax(User *u); int my_os_version_help(User *u); void ircd_version_help(User *u); int my_os_update(User *u); int my_os_update_callback(int argc, char **argv); int ircd_version_db_save(); int ircd_version_db_load(); /* SETTINGS! */ unsigned char my_version_flags = OPTION_DISPLAY | OPTION_SHOW_FLAGS | OPTION_SHOW_BUILD; char *my_version_msg = NULL; int AnopeInit(int argc, char **argv) { Command *c; Command *c_update; Message *m; #if (IRCD_VERSION_ACCESS_CHANGE == OPER_OPER) c = createCommand("version", my_os_version, is_services_oper, -1, -1, -1, -1, -1); moduleAddOperHelp(c, my_os_version_help); moduleAddAdminHelp(c, my_os_version_help); moduleAddRootHelp(c, my_os_version_help); #elif (IRCD_VERSION_ACCESS_CHANGE == OPER_ADMIN) c = createCommand("version", my_os_version, is_services_admin, -1, -1, -1, -1, -1); moduleAddAdminHelp(c, my_os_version_help); moduleAddRootHelp(c, my_os_version_help); //#elif (IRCD_VERSION_ACCESS_CHANGE == OPER_ROOT) #else c = createCommand("version", my_os_version, is_services_root, -1, -1, -1, -1, -1); moduleAddRootHelp(c, my_os_version_help); #endif c_update = createCommand("update", my_os_update, is_services_admin, -1, -1, -1, -1, -1); moduleSetOperHelp(ircd_version_help); alog("[MOD|ircd_version] Adding command version(%d) update(%d)", moduleAddCommand(OPERSERV, c, MOD_HEAD) , moduleAddCommand(OPERSERV, c_update, MOD_HEAD)); m = createMessage("version", my_version); alog("[MOD|ircd_version] Adding message version(%d)", moduleAddMessage(m, MOD_HEAD)); alog("[MOD|ircd_version] Adding callback(%d)", moduleAddCallback("ircd_version_update_callback", time(NULL)+dotime("30m"), my_os_update_callback, 0, NULL)); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); if ((ircd_version_db_load() == DB_ERR) && mod_current_user) { notice(s_OperServ, mod_current_user->nick, "Unable to load ircd_version settings"); alog("[MOD|ircd_version] Unable to load settings"); } return MOD_CONT; } void AnopeFini(void) { if ((ircd_version_db_save() == DB_ERR) && mod_current_user) { notice(s_OperServ, mod_current_user->nick, "Unable to save ircd_version settings"); alog("[MOD|ircd_version] Unable to save settings"); } } char *build_version() { char *version; int malloc_size; malloc_size = 8 + strlen(version_number) + strlen(ServerName) + (((my_version_flags & (OPTION_SHOW_FLAGS | OPTION_SHOW_BUILD)) || ((my_version_flags & OPTION_SHOW_MSG) && my_version_msg)) ? 2 : 0) + ((my_version_flags & OPTION_SHOW_FLAGS) ? strlen(version_flags) : 0) + (((my_version_flags & OPTION_SHOW_FLAGS) && (my_version_flags & OPTION_SHOW_BUILD)) ? 4 : 0) + ((my_version_flags & OPTION_SHOW_BUILD) ? strlen(version_build) : 0) + (((my_version_flags & (OPTION_SHOW_FLAGS | OPTION_SHOW_BUILD)) || ((my_version_flags & OPTION_SHOW_MSG) && my_version_msg)) ? 4 : 0) + (((my_version_flags & OPTION_SHOW_MSG) && my_version_msg) ? strlen(my_version_msg) : 0); version = smalloc(malloc_size); sprintf(version,"Anope-%s %s%s%s%s%s%s%s", version_number, ServerName, (((my_version_flags & (OPTION_SHOW_FLAGS | OPTION_SHOW_BUILD)) || ((my_version_flags & OPTION_SHOW_MSG) && my_version_msg)) ? " :" : ""), ((my_version_flags & OPTION_SHOW_FLAGS) ? version_flags : ""), (((my_version_flags & OPTION_SHOW_FLAGS) && (my_version_flags & OPTION_SHOW_BUILD)) ? " -- " : ""), ((my_version_flags & OPTION_SHOW_BUILD) ? version_build : ""), (((my_version_flags & (OPTION_SHOW_FLAGS | OPTION_SHOW_BUILD)) && ((my_version_flags & OPTION_SHOW_MSG) && my_version_msg)) ? " -- " : ""), (((my_version_flags & OPTION_SHOW_MSG) && my_version_msg) ? my_version_msg : "")); return version; } int my_version(char *source, int ac, char **av) { User *u; if (source && (u = finduser(source)) && ((my_version_flags & OPTION_DISPLAY) || is_services_oper(u) || is_services_admin(u) || is_services_oper(u))) send_cmd(ServerName, "351 %s %s", source, build_version()); return MOD_STOP; } int my_os_version(User *u) { char *action; char *option; char *value; action = strtok(NULL, " "); option = strtok(NULL, " "); value = strtok(NULL, ""); if (action == NULL) { return my_os_version_syntax(u); } else if (stricmp(action,"set") == 0) { if ((option == NULL) || ((value == NULL) && (stricmp(option, "MSG") != 0))) { return my_os_version_syntax(u); } else if (stricmp(option, "SHOW") == 0) { if (stricmp(value, "ON") == 0) { my_version_flags |= OPTION_DISPLAY; notice(s_OperServ, u->nick, "Services will now reply to a VERSION message"); } else if (stricmp(value, "OFF") == 0) { my_version_flags &= ~OPTION_DISPLAY; notice(s_OperServ, u->nick, "Services won't reply to a VERSION message now"); } else { return my_os_version_syntax(u); } } else if (stricmp(option, "FLAGS") == 0) { if (stricmp(value, "ON") == 0) { my_version_flags |= OPTION_SHOW_FLAGS; notice(s_OperServ, u->nick, "Services will now show version flags in a VERSION reply"); } else if (stricmp(value, "OFF") == 0) { my_version_flags &= ~OPTION_SHOW_FLAGS; notice(s_OperServ, u->nick, "Services won't show version flags in a VERSION reply now"); } else { return my_os_version_syntax(u); } } else if (stricmp(option, "BUILD") == 0) { if (stricmp(value, "ON") == 0) { my_version_flags |= OPTION_SHOW_BUILD; notice(s_OperServ, u->nick, "Services will now show build info in a VERSION reply"); } else if (stricmp(value, "OFF") == 0) { my_version_flags &= ~OPTION_SHOW_BUILD; notice(s_OperServ, u->nick, "Services won't show build info in a VERSION reply now"); } else { return my_os_version_syntax(u); } } else if (stricmp(option, "MSG") == 0) { if (value && stricmp(value, "ON") == 0) { my_version_flags |= OPTION_SHOW_MSG; notice(s_OperServ, u->nick, "Services will now show your custom message in a VERSION reply"); } else if (value && stricmp(value, "OFF") == 0) { my_version_flags &= ~OPTION_SHOW_MSG; notice(s_OperServ, u->nick, "Services won't show your custom message in a VERSION reply now"); } else { if (value == NULL) { my_version_msg = NULL; notice(s_OperServ, u->nick, "Your custom message has been cleared"); } else { my_version_msg = sstrdup(value); notice(s_OperServ, u->nick, "Your custom message has been changed into \002%s\002", my_version_msg); } } } else { return my_os_version_syntax(u); } } else if (stricmp(action, "view") == 0) { notice(s_OperServ, u->nick, "Showing version reply: %s", ((my_version_flags & OPTION_DISPLAY) ? "YES" : "NO")); notice(s_OperServ, u->nick, "Showing version flags: %s", ((my_version_flags & OPTION_SHOW_FLAGS) ? "YES" : "NO (deprecated)")); notice(s_OperServ, u->nick, "Showing build info: %s", ((my_version_flags & OPTION_SHOW_BUILD) ? "YES" : "NO")); notice(s_OperServ, u->nick, "Showing custom message: %s", ((my_version_flags & OPTION_SHOW_MSG) ? "YES" : "NO")); notice(s_OperServ, u->nick, "Current custom message: %s", (my_version_msg ? my_version_msg : "(none)")); notice(s_OperServ, u->nick, "Current version reply:"); notice(s_OperServ, u->nick, build_version()); } else { return my_os_version_syntax(u); } return MOD_CONT; } int my_os_version_syntax(User *u) { notice(s_OperServ, u->nick, "Syntax: VERSION \002{SET|VIEW} [SHOW|FLAGS|BUILD|MSG] [ON|OFF|\037text\037]\002"); return MOD_CONT; } int my_os_version_help(User *u) { my_os_version_syntax(u); notice(s_OperServ, u->nick, " "); notice(s_OperServ, u->nick, "This command enables you to change the version reply of the"); notice(s_OperServ, u->nick, "services, or to completely disable any reaction."); notice(s_OperServ, u->nick, " "); notice(s_OperServ, u->nick, "Using \002SET\002 you can enable or disable various options."); notice(s_OperServ, u->nick, "All options take the \002ON\002 argument to turn them on, and"); notice(s_OperServ, u->nick, "the \002OFF\002 argument for turning them off. The \002SHOW\002"); notice(s_OperServ, u->nick, "option enables or disables a reply to a version requestion"); notice(s_OperServ, u->nick, "from non-opered users. The \002FLAGS\002 option displays or"); notice(s_OperServ, u->nick, "hides the version flags from the version reply. This is"); notice(s_OperServ, u->nick, "deprecated because the compile flags are required for getting"); notice(s_OperServ, u->nick, "support on services. The \002BUILD\002 options displays or hides"); notice(s_OperServ, u->nick, "the build flags from the version reply. The \002MSG\002 option"); notice(s_OperServ, u->nick, "displays, hides, or (un)sets a custom message to be displayed"); notice(s_OperServ, u->nick, "with the version reply. If neither \002ON\002 nor \002OFF\002 is"); notice(s_OperServ, u->nick, "giving as a value for this option, the custom message is set"); notice(s_OperServ, u->nick, "to the given value. If the value is empty the custom message"); notice(s_OperServ, u->nick, "is cleared."); notice(s_OperServ, u->nick, " "); notice(s_OperServ, u->nick, "With \002VIEW\002 you can view the current status of all of the"); notice(s_OperServ, u->nick, "\002SET\002 options and the current version reply."); notice(s_OperServ, u->nick, " "); #if (IRCD_VERSION_ACCESS_CHANGE == OPER_OPER) notice(s_OperServ, u->nick, "Limited to Services Operators"); #elif (IRCD_VERSION_ACCESS_CHANGE == OPER_ADMIN) notice(s_OperServ, u->nick, "Limited to Services Admins"); #else notice(s_OperServ, u->nick, "Limited to Services Roots"); #endif return MOD_CONT; } void ircd_version_help(User *u) { #if (IRCD_VERSION_ACCESS_CHANGE == OPER_OPER) if (is_services_oper(u)) notice(s_OperServ, u->nick, " VERSION Change the services version reply"); #elif (IRCD_VERSION_ACCESS_CHANGE == OPER_ADMIN) if (is_services_admin(u)) notice(s_OperServ, u->nick, " VERSION Change the services version reply"); #else if (is_services_root(u)) notice(s_OperServ, u->nick, " VERSION Change the services version reply"); #endif } int my_os_update(User *u) { if (ircd_version_db_save() == DB_ERR) alog("[MOD|ircd_version] Unable to save settings"); return MOD_CONT; } int my_os_update_callback(int argc, char **argv) { moduleAddCallback("ircd_version_update_callback", time(NULL)+dotime("30m"), my_os_update_callback, 0, NULL); if (ircd_version_db_save() == DB_ERR) alog("[MOD|ircd_version] Unable to save settings"); return MOD_CONT; } int ircd_version_db_save() { int msg_len; FILE *fp; if ((fp = fopen(IRCD_VERSION_DB_FILE, "w")) == NULL) return DB_ERR; msg_len = ((my_version_msg) ? strlen(my_version_msg) : 0); fprintf(fp, "%c%c%d%s", DB_VERSION, my_version_flags, msg_len, ((my_version_msg) ? my_version_msg : "")); fclose(fp); return DB_OK; } int ircd_version_db_load() { int msg_len; char *in; FILE *fp; if ((fp = fopen(IRCD_VERSION_DB_FILE, "r")) == NULL) return DB_ERR; if (getc(fp) != DB_VERSION) { fclose(fp); return DB_ERR; } my_version_flags = (unsigned char) getc(fp); in = smalloc(sizeof(int) + 1); if (!fgets(in, sizeof(int), fp)) { fclose(fp); return DB_ERR; } msg_len = atoi(in); free(in); if (msg_len) { in = smalloc(msg_len + 1); if (!fgets(in, msg_len, fp)) { fclose(fp); return DB_ERR; } my_version_msg = in; } else { my_version_msg = NULL; } fclose(fp); return DB_OK; } /* EOF */