]>
Commit | Line | Data |
---|---|---|
be2823bc | 1 | #include "../control/control.h" |
2d4ba67d | 2 | #include "../lib/irc_string.h" |
be2823bc CP |
3 | #include "trusts.h" |
4 | ||
5 | int trusts_migration_start(TrustDBMigrationCallback, void *); | |
6 | void trusts_migration_stop(void); | |
83bccee3 CP |
7 | static void registercommands(int, void *); |
8 | static void deregistercommands(int, void *); | |
be2823bc | 9 | |
be2823bc CP |
10 | static void migrate_status(int errcode, void *tag) { |
11 | long sender = (long)tag; | |
12 | nick *np = getnickbynumeric(sender); | |
13 | ||
14 | if(!np) | |
15 | return; | |
16 | ||
e00bb3fb CP |
17 | if(!errcode || errcode == MIGRATION_LASTERROR) { |
18 | if(!errcode) { | |
19 | controlreply(np, "Migration complete."); | |
20 | controlreply(np, "Attempting to reload database. . ."); | |
21 | } else { | |
22 | controlreply(np, "An error occured after the database was unloaded, attempting reload. . ."); | |
23 | } | |
24 | if(trusts_loaddb()) { | |
25 | controlreply(np, "Database reloaded successfully."); | |
26 | } else { | |
27 | controlreply(np, "An error occured, please reload the module manually."); | |
28 | } | |
be2823bc | 29 | } else { |
bf5b66e5 | 30 | controlreply(np, "Error %d occured during migration, commands reregistered.", errcode); |
a99a2041 | 31 | registercommands(0, NULL); |
be2823bc CP |
32 | } |
33 | } | |
34 | ||
35 | static int trusts_cmdmigrate(void *source, int cargc, char **cargv) { | |
36 | nick *sender = source; | |
37 | int ret; | |
38 | ||
39 | /* iffy but temporary */ | |
40 | ret = trusts_migration_start(migrate_status, (void *)(sender->numeric)); | |
41 | if(!ret) { | |
bf5b66e5 | 42 | controlreply(sender, "Migration started, commands deregistered."); |
83bccee3 | 43 | deregistercommands(0, NULL); |
be2823bc CP |
44 | } else { |
45 | controlreply(sender, "Error %d starting migration.", ret); | |
46 | } | |
47 | ||
48 | return CMD_OK; | |
49 | } | |
50 | ||
2d4ba67d CP |
51 | static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) { |
52 | nick *sender = source; | |
53 | trustgroup *tg; | |
54 | trusthost *th; | |
55 | time_t t; | |
56 | ||
57 | if(cargc < 1) | |
58 | return CMD_USAGE; | |
59 | ||
60 | tg = tg_strtotg(cargv[0]); | |
61 | if(!tg) { | |
62 | controlreply(sender, "Couldn't find a trustgroup with that id."); | |
63 | return CMD_ERROR; | |
64 | } | |
65 | ||
66 | t = time(NULL); | |
67 | ||
4b003d19 | 68 | controlreply(sender, "Name: : %s", tg->name->content); |
2d4ba67d | 69 | controlreply(sender, "Trusted for : %d", tg->trustedfor); |
1bbe1ac3 | 70 | controlreply(sender, "Currently using : %d", tg->count); |
2d4ba67d | 71 | controlreply(sender, "Clients per user : %d (%senforcing ident)", tg->maxperident, tg->mode?"":"not "); |
4b003d19 | 72 | controlreply(sender, "Contact: : %s", tg->contact->content); |
2d4ba67d | 73 | controlreply(sender, "Expires in : %s", (tg->expires>t)?longtoduration(tg->expires - t, 2):"(in the past)"); |
4b003d19 CP |
74 | controlreply(sender, "Last changed by : %s", tg->createdby->content); |
75 | controlreply(sender, "Comment: : %s", tg->comment->content); | |
2d4ba67d | 76 | controlreply(sender, "ID: : %u", tg->id); |
4be1aaf2 CP |
77 | controlreply(sender, "Last used : %s", (tg->count>0)?"(now)":trusts_timetostr(tg->lastseen)); |
78 | controlreply(sender, "Max usage : %d", tg->maxusage); | |
2d4ba67d CP |
79 | controlreply(sender, "Last max reset : %s", tg->lastmaxuserreset?trusts_timetostr(tg->lastmaxuserreset):"(never)"); |
80 | ||
4be1aaf2 | 81 | controlreply(sender, "Host Current Max Last seen"); |
2d4ba67d CP |
82 | |
83 | for(th=tg->hosts;th;th=th->next) | |
4be1aaf2 | 84 | controlreply(sender, " %-20s %-10d %-10d %s", trusts_cidr2str(th->ip, th->mask), th->count, th->maxusage, (th->count>0)?"(now)":trusts_timetostr(th->lastseen)); |
2d4ba67d CP |
85 | |
86 | controlreply(sender, "End of list."); | |
87 | ||
88 | return CMD_OK; | |
89 | } | |
90 | ||
a99a2041 CP |
91 | static int commandsregistered; |
92 | ||
93 | static void registercommands(int hooknum, void *arg) { | |
94 | if(commandsregistered) | |
95 | return; | |
96 | commandsregistered = 1; | |
97 | ||
98 | registercontrolhelpcmd("trustmigrate", NO_DEVELOPER, 0, trusts_cmdmigrate, "Usage: trustmigrate\nCopies trust data from O and reloads the database."); | |
99 | registercontrolhelpcmd("trustlist", NO_OPER, 1, trusts_cmdtrustlist, "Usage: trustlist <#id|name|id>\nShows trust data for the specified trust group."); | |
100 | } | |
101 | ||
83bccee3 | 102 | static void deregistercommands(int hooknum, void *arg) { |
a99a2041 CP |
103 | if(!commandsregistered) |
104 | return; | |
105 | commandsregistered = 0; | |
106 | ||
107 | deregistercontrolcmd("trustmigrate", trusts_cmdmigrate); | |
108 | deregistercontrolcmd("trustlist", trusts_cmdtrustlist); | |
be2823bc CP |
109 | } |
110 | ||
111 | void _init(void) { | |
a99a2041 | 112 | registerhook(HOOK_TRUSTS_DB_LOADED, registercommands); |
83bccee3 | 113 | registerhook(HOOK_TRUSTS_DB_CLOSED, deregistercommands); |
be2823bc CP |
114 | |
115 | if(trustsdbloaded) | |
a99a2041 | 116 | registercommands(0, NULL); |
be2823bc CP |
117 | } |
118 | ||
119 | void _fini(void) { | |
a99a2041 | 120 | deregisterhook(HOOK_TRUSTS_DB_LOADED, registercommands); |
83bccee3 | 121 | deregisterhook(HOOK_TRUSTS_DB_CLOSED, deregistercommands); |
be2823bc CP |
122 | |
123 | trusts_migration_stop(); | |
be2823bc | 124 | |
83bccee3 CP |
125 | deregistercommands(0, NULL); |
126 | } |