]>
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 hooknum
, void * arg
);
8 static void deregistercommands ( void );
10 static void migrate_status ( int errcode
, void * tag
) {
11 long sender
= ( long ) tag
;
12 nick
* np
= getnickbynumeric ( sender
);
18 controlreply ( np
, "Migration complete." );
20 /* stops flush destroying the database */
24 controlreply ( np
, "All functionality disabled, database unloaded -- please reload the module." );
26 controlreply ( np
, "Error %d occured during migration, commands reregistered." , errcode
);
27 registercommands ( 0 , NULL
);
31 static int trusts_cmdmigrate ( void * source
, int cargc
, char ** cargv
) {
32 nick
* sender
= source
;
35 /* iffy but temporary */
36 ret
= trusts_migration_start ( migrate_status
, ( void *)( sender
-> numeric
));
38 controlreply ( sender
, "Migration started, commands deregistered." );
41 controlreply ( sender
, "Error %d starting migration." , ret
);
47 static trustgroup
* tg_strtotg ( char * name
) {
53 id
= strtoul (& name
[ 1 ], NULL
, 10 );
57 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
62 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
63 if (! match ( name
, tg
-> name
-> content
))
66 id
= strtoul ( name
, NULL
, 10 );
71 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
78 static int trusts_cmdtrustlist ( void * source
, int cargc
, char ** cargv
) {
79 nick
* sender
= source
;
87 tg
= tg_strtotg ( cargv
[ 0 ]);
89 controlreply ( sender
, "Couldn't find a trustgroup with that id." );
95 controlreply ( sender
, "Name: : %s " , tg
-> name
-> content
);
96 controlreply ( sender
, "Trusted for : %d " , tg
-> trustedfor
);
97 controlreply ( sender
, "Currently using : %d " , tg
-> count
);
98 controlreply ( sender
, "Clients per user : %d ( %s enforcing ident)" , tg
-> maxperident
, tg
-> mode
? "" : "not " );
99 controlreply ( sender
, "Contact: : %s " , tg
-> contact
-> content
);
100 controlreply ( sender
, "Expires in : %s " , ( tg
-> expires
> t
)? longtoduration ( tg
-> expires
- t
, 2 ): "(in the past)" );
101 controlreply ( sender
, "Last changed by : %s " , tg
-> createdby
-> content
);
102 controlreply ( sender
, "Comment: : %s " , tg
-> comment
-> content
);
103 controlreply ( sender
, "ID: : %u " , tg
-> id
);
104 controlreply ( sender
, "Last used : %s " , ( tg
-> count
> 0 )? "(now)" : trusts_timetostr ( tg
-> lastseen
));
105 controlreply ( sender
, "Max usage : %d " , tg
-> maxusage
);
106 controlreply ( sender
, "Last max reset : %s " , tg
-> lastmaxuserreset
? trusts_timetostr ( tg
-> lastmaxuserreset
): "(never)" );
108 controlreply ( sender
, "Host Current Max Last seen" );
110 for ( th
= tg
-> hosts
; th
; th
= th
-> next
)
111 controlreply ( sender
, " %-20s %-10d %-10d %s " , trusts_cidr2str ( th
-> ip
, th
-> mask
), th
-> count
, th
-> maxusage
, ( th
-> count
> 0 )? "(now)" : trusts_timetostr ( th
-> lastseen
));
113 controlreply ( sender
, "End of list." );
118 static int commandsregistered
;
120 static void registercommands ( int hooknum
, void * arg
) {
121 if ( commandsregistered
)
123 commandsregistered
= 1 ;
125 registercontrolhelpcmd ( "trustmigrate" , NO_DEVELOPER
, 0 , trusts_cmdmigrate
, "Usage: trustmigrate \n Copies trust data from O and reloads the database." );
126 registercontrolhelpcmd ( "trustlist" , NO_OPER
, 1 , trusts_cmdtrustlist
, "Usage: trustlist <#id|name|id> \n Shows trust data for the specified trust group." );
129 static void deregistercommands ( void ) {
130 if (! commandsregistered
)
132 commandsregistered
= 0 ;
134 deregistercontrolcmd ( "trustmigrate" , trusts_cmdmigrate
);
135 deregistercontrolcmd ( "trustlist" , trusts_cmdtrustlist
);
139 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
142 registercommands ( 0 , NULL
);
146 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
147 deregistercommands ();
149 trusts_migration_stop ();