]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts_commands.c
1 #include "../control/control.h"
2 #include "../lib/irc_string.h"
5 int trusts_migration_start ( TrustDBMigrationCallback
, void *);
6 void trusts_migration_stop ( void );
7 static void registercommands ( int , void *);
8 static void deregistercommands ( int , void *);
10 static void migrate_status ( int errcode
, void * tag
) {
11 long sender
= ( long ) tag
;
12 nick
* np
= getnickbynumeric ( sender
);
17 if (! errcode
|| errcode
== MIGRATION_LASTERROR
) {
19 controlreply ( np
, "Migration complete." );
20 controlreply ( np
, "Attempting to reload database. . ." );
22 controlreply ( np
, "An error occured after the database was unloaded, attempting reload. . ." );
25 controlreply ( np
, "Database reloaded successfully." );
27 controlreply ( np
, "An error occured, please reload the module manually." );
30 controlreply ( np
, "Error %d occured during migration, commands reregistered." , errcode
);
31 registercommands ( 0 , NULL
);
35 static int trusts_cmdmigrate ( void * source
, int cargc
, char ** cargv
) {
36 nick
* sender
= source
;
39 /* iffy but temporary */
40 ret
= trusts_migration_start ( migrate_status
, ( void *)( sender
-> numeric
));
42 controlreply ( sender
, "Migration started, commands deregistered." );
43 deregistercommands ( 0 , NULL
);
45 controlreply ( sender
, "Error %d starting migration." , ret
);
51 static trustgroup
* tg_strtotg ( char * name
) {
57 id
= strtoul (& name
[ 1 ], NULL
, 10 );
61 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
66 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
67 if (! match ( name
, tg
-> name
-> content
))
70 id
= strtoul ( name
, NULL
, 10 );
75 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
82 static int trusts_cmdtrustlist ( void * source
, int cargc
, char ** cargv
) {
83 nick
* sender
= source
;
91 tg
= tg_strtotg ( cargv
[ 0 ]);
93 controlreply ( sender
, "Couldn't find a trustgroup with that id." );
99 controlreply ( sender
, "Name: : %s " , tg
-> name
-> content
);
100 controlreply ( sender
, "Trusted for : %d " , tg
-> trustedfor
);
101 controlreply ( sender
, "Currently using : %d " , tg
-> count
);
102 controlreply ( sender
, "Clients per user : %d ( %s enforcing ident)" , tg
-> maxperident
, tg
-> mode
? "" : "not " );
103 controlreply ( sender
, "Contact: : %s " , tg
-> contact
-> content
);
104 controlreply ( sender
, "Expires in : %s " , ( tg
-> expires
> t
)? longtoduration ( tg
-> expires
- t
, 2 ): "(in the past)" );
105 controlreply ( sender
, "Last changed by : %s " , tg
-> createdby
-> content
);
106 controlreply ( sender
, "Comment: : %s " , tg
-> comment
-> content
);
107 controlreply ( sender
, "ID: : %u " , tg
-> id
);
108 controlreply ( sender
, "Last used : %s " , ( tg
-> count
> 0 )? "(now)" : trusts_timetostr ( tg
-> lastseen
));
109 controlreply ( sender
, "Max usage : %d " , tg
-> maxusage
);
110 controlreply ( sender
, "Last max reset : %s " , tg
-> lastmaxuserreset
? trusts_timetostr ( tg
-> lastmaxuserreset
): "(never)" );
112 controlreply ( sender
, "Host Current Max Last seen" );
114 for ( th
= tg
-> hosts
; th
; th
= th
-> next
)
115 controlreply ( sender
, " %-20s %-10d %-10d %s " , trusts_cidr2str ( th
-> ip
, th
-> mask
), th
-> count
, th
-> maxusage
, ( th
-> count
> 0 )? "(now)" : trusts_timetostr ( th
-> lastseen
));
117 controlreply ( sender
, "End of list." );
122 static int commandsregistered
;
124 static void registercommands ( int hooknum
, void * arg
) {
125 if ( commandsregistered
)
127 commandsregistered
= 1 ;
129 registercontrolhelpcmd ( "trustmigrate" , NO_DEVELOPER
, 0 , trusts_cmdmigrate
, "Usage: trustmigrate \n Copies trust data from O and reloads the database." );
130 registercontrolhelpcmd ( "trustlist" , NO_OPER
, 1 , trusts_cmdtrustlist
, "Usage: trustlist <#id|name|id> \n Shows trust data for the specified trust group." );
133 static void deregistercommands ( int hooknum
, void * arg
) {
134 if (! commandsregistered
)
136 commandsregistered
= 0 ;
138 deregistercontrolcmd ( "trustmigrate" , trusts_cmdmigrate
);
139 deregistercontrolcmd ( "trustlist" , trusts_cmdtrustlist
);
143 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
144 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
147 registercommands ( 0 , NULL
);
151 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
152 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
154 trusts_migration_stop ();
156 deregistercommands ( 0 , NULL
);