#include "module.h" #include #define AUTHOR "{x3d}" #define VERSION "Hostserv Request 1.53" /* Memo options, if oper/setter memo's are enabled, MSMemoDelay time is used to try and * prevent silly flooding */ #define SEND_USER_MEMO 1 #define SEND_OPER_MEMO 0 #define SEND_SETTERS_MEMO 0 #define SEND_CHAN "#ircop" /* Language Strings - Translate if you like, but keep the %s's there! */ #define REQUEST_TXT "[Auto Reply] vHost \002%s\002 requested." #define REQUEST_SYNTAX "Syntax: /msg %s REQUEST " #define REQUESTED "Your vHost request has been forwarded to Chatpinoy Hostserv Admin." #define REQUESTED_WAIT "Please wait %d seconds before requesting a new vHost" #define ACTIVATED_SYNTAX "Syntax: /msg %s ACTIVATE " #define ACTIVATED "vHost %s for %s has been activated" #define ACTIVATED_TXT "[Auto Reply] Chatpinoy Hostserv Admin has approved Your Vhost. type /hs on " #define REJECTED_SYNTAX "Syntax: /msg %s REJECT " #define REJECTED "vHost for %s has been rejected" #define REJECTED_TXT "[Auto Reply] Chatpinoy Hostserv Admin has rejected Your Vhost. Reason: " #define NO_REQUEST "No request for nick %s found." #define REQUEST_HELP_1 "Syntax: REQUEST vhost" #define REQUEST_HELP_2 "Request to the network admins the given vhost " #define REQUEST_HELP_3 "be activated for your nick." #define REQUEST_HELP_4 "Please be patient while we consider your request." #define REQUEST_ACT_1 "Syntax: ACTIVATE nick" #define REQUEST_ACT_2 "Activates the requested vhost for the given nick " #define REQUEST_ACT_3 "If configured, a memo informing the user will also" #define REQUEST_ACT_4 "be sent." #define REQUEST_REJ_1 "Syntax: REJECT nick reason" #define REQUEST_REJ_2 "Rejects the requested vhost for the given nick" #define REQUEST_REJ_3 "if configured, a memo informing the user will also" #define REQUEST_REJ_4 "be sent." #define REQUEST_WAIT_1 "Syntax: WAITING" #define REQUEST_WAIT_2 "This is provided for convenience, it is essentiaily" #define REQUEST_WAIT_3 "the same as a /msg hostserv list +req" #define REQUEST_INFO_1 "Syntax: INFO nick" #define REQUEST_INFO_2 "Information of requested vhost for the given nick" #define REQUEST_EDIT_1 "Syntax: EDIT nick new vhost" #define REQUEST_EDIT_2 "Change user vhost." #define REQUEST_HELP_INFO " INFO Information about the nick's vhost" #define REQUEST_HELP_REQ " REQUEST Requests a vhost for your nick" #define REQUEST_HELP_ACT " ACTIVATE Approve a users requested vhost" #define REQUEST_HELP_REJ " REJECT Reject a users requested vhost" #define REQUEST_HELP_WAT " WAITING Convinence command for /hs list +req" #define REQUEST_HELP_EDIT " EDIT Edit vhost for other user. " char *HS_REQ_DELAY ="7d"; /* End of Language Section */ HostCore *head = NULL; int hs_do_request(User * u); int hs_do_activate(User * u); int hs_do_reject(User * u); int hs_do_listOut(User * u); int hs_do_edit(User * u); int hsRequestHelp(User * u); int hsActivateHelp(User * u); int hsRejectHelp(User * u); int hsWaitingHelp(User * u); int hsInfoHelp(User * u); void hsMainHelp(User * u); int do_info(User * u); void xdo_info(char *key); extern char *myStrGetOnlyToken(const char *str, const char dilim, int token_number); extern char *myStrSubString(const char *src, int start, int end); extern char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number); extern HostCore *createHostCorelist(HostCore * next, char *nick, char *vIdent, char *vHost, char *creator, int32 tmp_time); extern HostCore *findHostCore(HostCore * head, char *nick, boolean * found); extern HostCore *insertHostCore(HostCore * head, HostCore * prev, char *nick, char *vIdent, char *vHost, char *creator, int32 tmp_time); extern HostCore *deleteHostCore(HostCore * head, HostCore * prev); extern void addHostCore(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time); extern void memo_send(User * u, char *name, char *text, int z); extern int is_host_setter(User * u); void my_addHostRequest(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time); void req_send_memos(User * u, char *vHost); void show_list(User * u); int hs_do_waiting(User * u); int ns_do_drop(User * u); HostCore *hs_request_head; int AnopeInit(int argc, char **argv) { Command *c; c = createCommand("request", hs_do_request, NULL, -1, -1, -1, -1, -1); moduleAddHelp(c, hsRequestHelp); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("activate", hs_do_activate, is_host_setter, -1, -1, -1, -1, -1); moduleAddHelp(c, hsActivateHelp); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("reject", hs_do_reject, is_host_setter, -1, -1, -1, -1, -1); moduleAddHelp(c, hsRejectHelp); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("waiting", hs_do_waiting, is_host_setter, -1, -1, -1, -1, -1); moduleAddHelp(c, hsWaitingHelp); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("list", hs_do_listOut, is_services_oper, -1, -1, -1, -1, -1); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("drop", ns_do_drop, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_HEAD); c = createCommand("INFO", do_info, is_services_oper, -1, -1, -1, -1, -1); moduleAddHelp(c, hsInfoHelp); moduleAddCommand(HOSTSERV, c, MOD_HEAD); c = createCommand("edit", hs_do_edit, is_host_setter, -1, -1, -1, -1, -1); moduleAddCommand(HOSTSERV, c, MOD_HEAD); moduleSetHostHelp(hsMainHelp); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); hs_request_head = NULL; alog("hs_request.so loaded"); return MOD_CONT; } void AnopeFini(void) { alog("hs_request.so un-loaded"); } int hs_do_edit(User * u) { char *nick = strtok(NULL," "); char *rawhostmask = strtok(NULL, " "); char *hostmask = smalloc(HOSTMAX); char *vIdent = NULL; NickAlias *na; if (!rawhostmask || !nick) { notice(s_HostServ,u->nick, REQUEST_EDIT_1); return MOD_STOP; } vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (vIdent) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ if (!rawhostmask) { notice(s_HostServ, u->nick, REQUEST_SYNTAX, s_HostServ); return MOD_STOP; } if (strlen(vIdent) > USERMAX - 1) { notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); return MOD_STOP; } else { } #ifndef HAS_VIDENT notice_lang(s_HostServ, u, HOST_NO_VIDENT); return MOD_STOP; #endif } if (strlen(rawhostmask) < HOSTMAX - 1) snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); else { notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); return MOD_STOP; } na = findnick(nick); if(na) { addHostCore(nick, vIdent, hostmask, u->nick, time(NULL)); notice(s_HostServ, u->nick,"Successfull: Nick:%s Vhost:%s" , nick, hostmask); } else { notice_lang(s_HostServ, u, HOST_NOREG, nick); return MOD_STOP; } free(hostmask); return MOD_STOP; } int hs_do_request(User * u) { char *nick = u->nick; char *rawhostmask = strtok(NULL, " "); char *hostmask = smalloc(HOSTMAX); char *vIdent = NULL; int t, extime, days_left, hours_left, minutes_left; int32 tmp_time = time(NULL); time_t now = time(NULL); NickAlias *na; HostCore *current; if (!nick || !rawhostmask) { notice(s_HostServ, u->nick, REQUEST_SYNTAX, s_HostServ); return MOD_STOP; } current = head; if (current == NULL) { notice_lang(s_HostServ, u, HOST_EMPTY); } else { if (!is_services_oper(u)) { while (current != NULL) { if (u->nick) { if (match_wild_nocase(u->nick, current->nick)) { if (dotime(HS_REQ_DELAY) > 0 && current->time+dotime(HS_REQ_DELAY) < now){ notice(s_HostServ, u->nick, "Valid Nick \002%s\002",current->nick); } else { t = current->time; extime = current->time+dotime(HS_REQ_DELAY); days_left = ((extime - now)/86400); hours_left = ((extime - now)/3600) % 24; minutes_left = ((extime - now)/60) % 60; notice(s_HostServ, u->nick, "Access Denied for a new vhost. Please wait for %d day(s), %d hour(s) and %d minute(s), before u can request for another vhost.", days_left, hours_left, minutes_left); return MOD_STOP; } } } current = current->next; } } } vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (vIdent) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ if (!rawhostmask) { notice(s_HostServ, u->nick, REQUEST_SYNTAX, s_HostServ); return MOD_STOP; } if (strlen(vIdent) > USERMAX - 1) { notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); return MOD_STOP; } else { } #ifndef HAS_VIDENT notice_lang(s_HostServ, u, HOST_NO_VIDENT); return MOD_STOP; #endif } if (strlen(rawhostmask) < HOSTMAX - 1) snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); else { notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); return MOD_STOP; } if ((na = findnick(nick))) { if (SEND_OPER_MEMO || SEND_SETTERS_MEMO) { if (MSSendDelay > 0 && u && u->lastmemosend + MSSendDelay > now) { notice(s_HostServ, u->nick, REQUESTED_WAIT, MSSendDelay); u->lastmemosend = now; return MOD_STOP; } } my_addHostRequest(nick, vIdent, hostmask, u->nick, tmp_time); notice(s_HostServ, u->nick, REQUESTED); req_send_memos(u, hostmask); send_cmd(s_HostServ, "PRIVMSG %s :8,1[Host Request] by %s Vhost:[%s] 0,3[Approved] /hs activate %s 0,4[Reject] /hs reject %s ", SEND_CHAN, nick, hostmask, nick, nick); xdo_info(nick); alog("New vHost Requested by %s", nick); } else { notice_lang(s_HostServ, u, HOST_NOREG, nick); } free(hostmask); return MOD_STOP; } int do_info(User * u) { char *key = strtok(NULL, ""); struct tm *tm; char buf[BUFSIZE]; int counter = 1; int from = 0, to = 0; char *tmp = NULL; char *s = NULL; int display_counter = 0; NickAlias *na; HostCore *current; if(!key) { return MOD_STOP; } if(!(na = findnick(key))) { notice_lang(s_HostServ,u,NICK_X_NOT_REGISTERED,key); return MOD_STOP; } current = head; if (current == NULL) notice_lang(s_HostServ, u, HOST_EMPTY); else { if (key) { if (key[0] == '#') { tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */ if (!tmp) { return MOD_CONT; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { return MOD_CONT; } } from = atoi(tmp); tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */ if (!tmp) { return MOD_CONT; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { return MOD_CONT; } } to = atoi(tmp); key = NULL; } } while (current != NULL) { if (key) { if (((match_wild_nocase(key, current->nick)) || (match_wild_nocase(key, current->vHost))) && (display_counter < NSListMax)) { display_counter++; tm = localtime(¤t->time); strftime(buf, sizeof(buf), getstring(NULL, STRFTIME_DATE_TIME_FORMAT), tm); if (current->vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); } else { notice_lang(s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); } } } counter++; current = current->next; } } return MOD_STOP; } void xdo_info(char *key) { struct tm *tm; char buf[BUFSIZE]; int counter = 1; int from = 0, to = 0; char *tmp = NULL; char *s = NULL; int display_counter = 0; NickAlias *na; HostCore *current; if(!key) { return; } if(!(na = findnick(key))) { send_cmd(s_HostServ, "PRIVMSG %s :8,1[Host Information] for [%s] is not a registered nick.",SEND_CHAN, key); return; } current = head; if (current == NULL) send_cmd(s_HostServ, "PRIVMSG %s :8,1[Host Information] 0 Record database.", SEND_CHAN); else { if (key) { if (key[0] == '#') { tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */ if (!tmp) { return; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { return; } } from = atoi(tmp); tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */ if (!tmp) { return; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { return; } } to = atoi(tmp); key = NULL; } } while (current != NULL) { if (key) { if (((match_wild_nocase(key, current->nick)) || (match_wild_nocase(key, current->vHost))) && (display_counter < NSListMax)) { display_counter++; tm = localtime(¤t->time); strftime(buf, sizeof(buf), getstring(NULL, STRFTIME_SHORT_DATE_FORMAT), tm); if (current->vIdent) { send_cmd(s_HostServ, "PRIVMSG %s :8,1[Host Information] for [%s] Ident:[%s] Vhost:[%s] Creator:[%s] Date:[%s]", SEND_CHAN, current->nick, current->vIdent, current->vHost, current->creator, buf); } else { send_cmd(s_HostServ, "PRIVMSG %s :8,1[Host Information] for [%s] Vhost:[%s] Creator:[%s] Date:[%s]", SEND_CHAN, current->nick, current->vHost, current->creator, buf); } } } counter++; current = current->next; } } return; } void req_send_memos(User * u, char *vHost) { int i; int z = 2; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, REQUEST_TXT, vHost); /* Prepare the formatted string */ if (checkDefCon(DEFCON_NO_NEW_MEMOS)) { return; } if (SEND_OPER_MEMO == 1) { for (i = 0; i < servopers.count; i++) { memo_send(u, (((NickCore *) servopers.list[i])->display), buf, z); } for (i = 0; i < servadmins.count; i++) { memo_send(u, (((NickCore *) servadmins.list[i])->display), buf, z); } for (i = 0; i < RootNumber; i++) { memo_send(u, ServicesRoots[i], buf, z); } } if (SEND_SETTERS_MEMO == 1) { for (i = 0; i < HostNumber; i++) { memo_send(u, HostSetters[i], buf, z); } } } int ns_do_drop(User * u) { HostCore *tmp; boolean found = false; NickAlias *na=NULL; na = findnick(u->nick); tmp = findHostCore(hs_request_head, u->nick, &found); if (found && na) { hs_request_head = deleteHostCore(hs_request_head, tmp); } return MOD_CONT; } int hs_do_reject(User * u) { char *nick = strtok(NULL, " "); char *reason = strtok(NULL, ""); HostCore *tmp, *hc; boolean found = false; if (!nick || !reason) { notice(s_HostServ, u->nick, REJECTED_SYNTAX, s_HostServ); return MOD_STOP; } tmp = findHostCore(hs_request_head, nick, &found); if (found) { if (tmp == NULL) hc = hs_request_head; else hc = tmp->next; if (SEND_USER_MEMO) memo_send(u, hc->nick, REJECTED_TXT, 2); memo_send(u, hc->nick, reason, 2); hs_request_head = deleteHostCore(hs_request_head, tmp); notice(s_HostServ, u->nick, REJECTED, nick); send_cmd(s_HostServ, "PRIVMSG %s :0,4 Rejected  by:[%s] nick:[%s] Vhost:[%s] Reason:[%s]", SEND_CHAN, u->nick, nick, hc->vHost, reason); alog("Host Request for %s rejected by %s", nick, u->nick); } else { notice(s_HostServ, u->nick, NO_REQUEST, nick); } return MOD_STOP; } int hs_do_activate(User * u) { char *nick = strtok(NULL, " "); NickAlias *na; HostCore *tmp, *hc; boolean found = false; if (!nick) { notice(s_HostServ, u->nick, ACTIVATED_SYNTAX, s_HostServ); return MOD_STOP; } if ((na = findnick(nick))) { tmp = findHostCore(hs_request_head, nick, &found); if (found) { if (tmp == NULL) hc = hs_request_head; else hc = tmp->next; addHostCore(hc->nick, hc->vIdent, hc->vHost, u->nick, time(NULL)); if (SEND_USER_MEMO) memo_send(u, hc->nick, ACTIVATED_TXT, 2); hs_request_head = deleteHostCore(hs_request_head, tmp); notice(s_HostServ, u->nick, ACTIVATED, hc->vHost, nick); send_cmd(s_HostServ, "PRIVMSG %s :0,3 Approved  by:[%s] nick:[%s] Vhost:[%s]", SEND_CHAN, u->nick, nick, hc->vHost); alog("Host Request for %s activated by %s", nick, u->nick); } else { notice(s_HostServ, u->nick, NO_REQUEST, nick); } } else { notice(s_HostServ, u->nick, ACTIVATED_SYNTAX, s_HostServ); } return MOD_STOP; } void my_addHostRequest(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time) { HostCore *tmp; boolean found = false; if (hs_request_head == NULL) { hs_request_head = createHostCorelist(hs_request_head, nick, vIdent, vhost, creator, tmp_time); } else { tmp = findHostCore(hs_request_head, nick, &found); if (!found) { hs_request_head = insertHostCore(hs_request_head, tmp, nick, vIdent, vhost, creator, tmp_time); } else { hs_request_head = deleteHostCore(hs_request_head, tmp); /* delete the old entry */ my_addHostRequest(nick, vIdent, vhost, creator, tmp_time); /* recursive call to add new entry */ } } } int hs_do_listOut(User * u) { char *key; key = moduleGetLastBuffer(); if (!key) { return MOD_CONT; } if (stricmp(key, "+req") != 0) { return MOD_CONT; } key = NULL; show_list(u); return MOD_STOP; } int hs_do_waiting(User * u) { show_list(u); return MOD_CONT; } void show_list(User * u) { struct tm *tm; char buf[BUFSIZE]; int counter = 1; int from = 0, to = 0; int display_counter = 0; HostCore *current = NULL; current = hs_request_head; while (current) { if ((((counter >= from) && (counter <= to)) || ((from == 0) && (to == 0))) && (display_counter < NSListMax)) { display_counter++; tm = localtime(¤t->time); strftime(buf, sizeof(buf), getstring(NULL, STRFTIME_DATE_TIME_FORMAT), tm); if (current->vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); } else { notice_lang(s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); } } counter++; current = current->next; } notice_lang(s_HostServ, u, HOST_LIST_FOOTER, display_counter); } int hsRequestHelp(User * u) { #ifdef REQUEST_HELP_1 notice(s_HostServ, u->nick, REQUEST_HELP_1); #endif #ifdef REQUEST_HELP_2 notice(s_HostServ, u->nick, REQUEST_HELP_2); #endif #ifdef REQUEST_HELP_3 notice(s_HostServ, u->nick, REQUEST_HELP_3); #endif #ifdef REQUEST_HELP_4 notice(s_HostServ, u->nick, REQUEST_HELP_4); #endif #ifdef REQUEST_HELP_5 notice(s_HostServ, u->nick, REQUEST_HELP_5); #endif return MOD_CONT; } int hsActivateHelp(User * u) { if (is_host_setter(u)) { #ifdef REQUEST_ACT_1 notice(s_HostServ, u->nick, REQUEST_ACT_1); #endif #ifdef REQUEST_ACT_2 notice(s_HostServ, u->nick, REQUEST_ACT_2); #endif #ifdef REQUEST_ACT_3 notice(s_HostServ, u->nick, REQUEST_ACT_3); #endif #ifdef REQUEST_ACT_4 notice(s_HostServ, u->nick, REQUEST_ACT_4); #endif #ifdef REQUEST_ACT_5 notice(s_HostServ, u->nick, REQUEST_ACT_5); #endif } else { notice_lang(s_HostServ, u, NO_HELP_AVAILABLE, "ACTIVATE"); } return MOD_CONT; } int hsRejectHelp(User * u) { if (is_host_setter(u)) { #ifdef REQUEST_REJ_1 notice(s_HostServ, u->nick, REQUEST_REJ_1); #endif #ifdef REQUEST_REJ_2 notice(s_HostServ, u->nick, REQUEST_REJ_2); #endif #ifdef REQUEST_REJ_3 notice(s_HostServ, u->nick, REQUEST_REJ_3); #endif #ifdef REQUEST_REJ_4 notice(s_HostServ, u->nick, REQUEST_REJ_4); #endif #ifdef REQUEST_REJ_5 notice(s_HostServ, u->nick, REQUEST_REJ_5); #endif } else { notice_lang(s_HostServ, u, NO_HELP_AVAILABLE, "REJECT"); } return MOD_CONT; } int hsWaitingHelp(User * u) { if (is_host_setter(u)) { #ifdef REQUEST_WAIT_1 notice(s_HostServ, u->nick, REQUEST_WAIT_1); #endif #ifdef REQUEST_WAIT_2 notice(s_HostServ, u->nick, REQUEST_WAIT_2); #endif #ifdef REQUEST_WAIT_3 notice(s_HostServ, u->nick, REQUEST_WAIT_3); #endif #ifdef REQUEST_WAIT_4 notice(s_HostServ, u->nick, REQUEST_WAIT_4); #endif #ifdef REQUEST_WAIT_5 notice(s_HostServ, u->nick, REQUEST_WAIT_5); #endif } else { notice_lang(s_HostServ, u, NO_HELP_AVAILABLE, "WAITING"); } return MOD_CONT; } int hsInfoHelp(User * u) { if (is_host_setter(u)) { notice(s_HostServ, u->nick, REQUEST_INFO_1); notice(s_HostServ, u->nick, REQUEST_INFO_2); } else { notice_lang(s_HostServ, u, NO_HELP_AVAILABLE, "INFO"); } return MOD_CONT; } void hsMainHelp(User * u) { notice(s_HostServ, u->nick, REQUEST_HELP_REQ); if (is_host_setter(u)) { notice(s_HostServ, u->nick, REQUEST_HELP_INFO); notice(s_HostServ, u->nick, REQUEST_HELP_ACT); notice(s_HostServ, u->nick, REQUEST_HELP_REJ); notice(s_HostServ, u->nick, REQUEST_HELP_WAT); notice(s_HostServ, u->nick, REQUEST_HELP_EDIT); } } /* EOF */