]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_commands.c
4 #include "../lib/version.h"
5 #include "../control/control.h"
6 #include "../lib/irc_string.h"
7 #include "../lib/splitline.h"
8 #include "../lib/strlfunc.h"
9 #include "../core/nsmalloc.h"
10 #include "../irc/irc.h"
11 #include "../localuser/localuser.h"
12 #include "../localuser/localuserchannel.h"
14 #include "../trusts/trusts.h"
18 static void registercommands ( int , void *);
19 static void deregistercommands ( int , void *);
21 static int parse_gline_flags ( nick
* sender
, const char * flagparam
, int * overridesanity
, int * overridelimit
, int * simulate
, int * chase
, int * coff
) {
32 if ( flagparam
[ 0 ] == '-' ) {
35 for ( pos
= flagparam
+ 1 ; * pos
; pos
++) {
61 controlreply ( sender
, "Invalid flag specified: %c " , * pos
);
65 static int glines_cmdblock ( void * source
, int cargc
, char ** cargv
) {
66 nick
* sender
= source
;
69 int hits
, duration
, id
;
70 int coff
, overridesanity
, overridelimit
, simulate
, chase
;
79 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & chase
, & coff
))
85 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
88 controlreply ( sender
, "Invalid duration specified." );
92 target
= getnickbynick ( cargv
[ coff
]);
95 ww
= whowas_chase ( cargv
[ coff
], 1800 );
98 controlreply ( sender
, "Sorry, couldn't find that user." );
104 controlreply ( sender
, "Found matching whowas record:" );
105 controlreply ( sender
, " %s " , whowas_format ( ww
));
107 ww
= whowas_fromnick ( target
, 1 );
111 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
112 reason
= cargv
[ coff
+ 2 ];
115 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
117 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
119 glinebufinit (& gbuf
, 0 );
120 glinebufcommentv (& gbuf
, "BLOCK" , cargc
+ coff
- 1 , cargv
);
121 glinebufaddbywhowas (& gbuf
, ww
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
123 glinebufspew (& gbuf
, sender
);
125 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
126 glinebufabort (& gbuf
);
129 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
134 glinebufabort (& gbuf
);
137 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
141 glinebufcounthits (& gbuf
, & hits
, NULL
);
142 id
= glinebufcommit (& gbuf
, 1 );
145 controlwall ( NO_OPER
, NL_GLINES
, " %s BLOCK'ed user ' %s ! %s @ %s ' for %s with reason ' %s ' ( %d hits)" , controlid ( sender
),
146 wnp
-> nick
, wnp
-> ident
, wnp
-> host
-> name
-> content
,
147 longtoduration ( duration
, 0 ), reason
, hits
);
152 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
157 static int glines_cmdgline ( void * source
, int cargc
, char ** cargv
) {
158 nick
* sender
= source
;
159 int duration
, users
, channels
, id
;
162 int coff
, overridesanity
, overridelimit
, simulate
;
164 #if SNIRCD_VERSION < 140
166 #endif /* SNIRCD_VERSION */
171 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
174 if ( cargc
< 3 + coff
)
179 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
182 controlreply ( sender
, "Invalid duration specified." );
186 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
187 reason
= cargv
[ coff
+ 2 ];
189 #if SNIRCD_VERSION < 140
190 gl
= findgline ( mask
);
193 /* warn opers that they can't modify this gline */
194 if ( gl
-> flags
& GLINE_ACTIVE
) {
195 controlreply ( sender
, "Active G-Line already exists on %s - unable to modify" , mask
);
199 controlreply ( sender
, "Reactivating existing gline on %s " , mask
);
201 #endif /* SNIRCD_VERSION */
204 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
206 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
208 glinebufinit (& gbuf
, 0 );
209 glinebufcommentv (& gbuf
, "GLINE" , cargc
+ coff
- 1 , cargv
);
211 if (! glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
)) {
212 controlreply ( sender
, "Invalid G-Line mask." );
216 glinebufspew (& gbuf
, sender
);
218 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
219 glinebufabort (& gbuf
);
220 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
225 glinebufabort (& gbuf
);
226 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
230 glinebufcounthits (& gbuf
, & users
, & channels
);
231 id
= glinebufcommit (& gbuf
, 1 );
233 controlwall ( NO_OPER
, NL_GLINES
, " %s GLINE'd mask ' %s ' for %s with reason ' %s ' (hits %d users/ %d channels)" ,
234 controlid ( sender
), mask
, longtoduration ( duration
, 0 ), reason
, users
, channels
);
236 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
241 static int glines_cmdsmartgline ( void * source
, int cargc
, char ** cargv
) {
242 nick
* sender
= source
;
245 char * p
, * user
, * host
;
246 struct irc_in_addr ip
;
249 int coff
, overridesanity
, overridelimit
, simulate
, id
;
257 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
260 if ( cargc
< 3 + coff
)
263 origmask
= cargv
[ coff
];
265 if ( origmask
[ 0 ] == '#' || origmask
[ 0 ] == '&' || origmask
[ 0 ] == '$' ) {
266 controlreply ( sender
, "Please use \" gline \" for badchan or realname glines." );
270 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
273 controlreply ( sender
, "Invalid duration specified." );
277 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
278 reason
= cargv
[ coff
+ 2 ];
280 strncpy ( mask
, origmask
, sizeof ( mask
));
282 if ( strchr ( mask
, '!' )) {
283 controlreply ( sender
, "Use \" gline \" to place nick glines." );
287 p
= strchr ( mask
, '@' );
290 controlreply ( sender
, "Mask must contain a username (e.g. user@ip)." );
298 if ( strchr ( user
, '*' ) || strchr ( user
, '?' )) {
299 controlreply ( sender
, "Usernames may not contain wildcards." );
303 if (! ipmask_parse ( host
, & ip
, & bits
)) {
304 controlreply ( sender
, "Invalid CIDR mask." );
309 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
311 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
313 glinebufinit (& gbuf
, 0 );
314 glinebufcommentv (& gbuf
, "SMARTGLINE" , cargc
+ coff
- 1 , cargv
);
315 glinebufaddbyip (& gbuf
, user
, & ip
, 128 , 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
317 glinebufspew (& gbuf
, sender
);
319 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
320 glinebufabort (& gbuf
);
321 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
326 glinebufabort (& gbuf
);
327 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
331 glinebufcounthits (& gbuf
, & hits
, NULL
);
332 id
= glinebufcommit (& gbuf
, 1 );
334 controlwall ( NO_OPER
, NL_GLINES
, " %s SMARTGLINE'd mask ' %s ' for %s with reason ' %s ' ( %d hits)" ,
335 controlid ( sender
), cargv
[ 0 ], longtoduration ( duration
, 0 ), reason
, hits
);
337 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
342 static int glines_cmdungline ( void * source
, int cargc
, char ** cargv
) {
343 nick
* sender
= source
;
349 gl
= findgline ( cargv
[ 0 ]);
352 controlreply ( sender
, "No such G-Line." );
356 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
357 controlreply ( sender
, "G-Line was already deactivated." );
361 gline_deactivate ( gl
, 0 , 1 );
363 controlwall ( NO_OPER
, NL_GLINES
, " %s UNGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
365 controlreply ( sender
, "G-Line deactivated." );
370 static int glines_cmddestroygline ( void * source
, int cargc
, char ** cargv
) {
371 nick
* sender
= source
;
377 gl
= findgline ( cargv
[ 0 ]);
380 controlreply ( sender
, "No such G-Line." );
384 gline_destroy ( gl
, 0 , 1 );
386 controlwall ( NO_OPER
, NL_GLINES
, " %s DESTROYGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
388 controlreply ( sender
, "G-Line destroyed." );
393 static int glines_cmdclearchan ( void * source
, int cargc
, char ** cargv
) {
394 nick
* sender
= source
;
397 char * reason
= "Clearing channel." ;
398 int mode
, duration
, i
, slot
, hits
, id
;
399 int coff
, overridesanity
, overridelimit
, simulate
;
407 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
410 if ( cargc
< 2 + coff
)
413 cp
= findchannel ( cargv
[ coff
]);
416 controlreply ( sender
, "Couldn't find that channel." );
420 if ( strcmp ( cargv
[ coff
+ 1 ], "kick" ) == 0 )
422 else if ( strcmp ( cargv
[ coff
+ 1 ], "kill" ) == 0 )
424 else if ( strcmp ( cargv
[ coff
+ 1 ], "gline" ) == 0 )
426 else if ( strcmp ( cargv
[ coff
+ 1 ], "glineall" ) == 0 )
431 if ( mode
== 0 || mode
== 1 ) {
433 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
434 reason
= cargv
[ coff
+ 2 ];
437 if ( cargc
< 3 + coff
)
440 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
443 controlreply ( sender
, "Invalid duration specified." );
447 if ( cargc
>= 4 + coff
) {
448 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
449 reason
= cargv
[ coff
+ 3 ];
453 array_init (& victims
, sizeof ( nick
*));
455 /* we need to make a list of the channel users here because
456 * kicking/killing them will affect their position in the channel's
458 for ( i
= 0 ; i
< cp
-> users
-> hashsize
; i
++) {
459 if ( cp
-> users
-> content
[ i
] == nouser
)
462 np
= getnickbynumeric ( cp
-> users
-> content
[ i
]);
467 if ( IsService ( np
) || IsOper ( np
) || NickOnServiceServer ( np
))
470 slot
= array_getfreeslot (& victims
);
471 ((( nick
**) victims
. content
)[ slot
]) = np
;
475 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
477 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
479 glinebufinit (& gbuf
, 0 );
480 glinebufcommentv (& gbuf
, "CLEARCHAN" , cargc
+ coff
- 1 , cargv
);
482 for ( i
= 0 ; i
< victims
. cursi
; i
++) {
483 np
= (( nick
**) victims
. content
)[ i
];
488 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
490 localkickuser ( NULL
, cp
, np
, reason
);
495 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
497 killuser ( NULL
, np
, " %s " , reason
);
505 glinebufaddbynick (& gbuf
, np
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
512 if ( mode
!= 0 && mode
!= 1 ) {
513 glinebufspew (& gbuf
, sender
);
515 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
516 glinebufabort (& gbuf
);
517 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
523 glinebufabort (& gbuf
);
524 controlreply ( sender
, "Simulation complete. Not clearing channel." );
528 glinebufmerge (& gbuf
);
529 glinebufcounthits (& gbuf
, & hits
, NULL
);
530 id
= glinebufcommit (& gbuf
, 1 );
532 array_free (& victims
);
534 if ( mode
== 0 || mode
== 1 ) {
535 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ' and reason ' %s '" ,
536 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], reason
);
537 controlreply ( sender
, "Done." );
539 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ', duration %s and reason ' %s ' ( %d hits)" ,
540 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], longtoduration ( duration
, 0 ), reason
, hits
);
541 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
547 static int glines_cmdtrustgline ( void * source
, int cargc
, char ** cargv
) {
548 nick
* sender
= source
;
552 int coff
, overridesanity
, overridelimit
, simulate
, id
;
561 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
564 if ( cargc
< 4 + coff
)
567 tg
= tg_strtotg ( cargv
[ coff
]);
569 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
570 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
574 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
577 controlreply ( sender
, "Invalid duration specified." );
581 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
582 reason
= cargv
[ coff
+ 3 ];
585 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
587 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
589 glinebufinit (& gbuf
, 0 );
590 glinebufcommentv (& gbuf
, "TRUSTGLINE" , cargc
+ coff
- 1 , cargv
);
592 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
593 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
594 glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
597 glinebufspew (& gbuf
, sender
);
599 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
600 glinebufabort (& gbuf
);
601 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
606 glinebufabort (& gbuf
);
607 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
611 glinebufcounthits (& gbuf
, & hits
, NULL
);
612 id
= glinebufcommit (& gbuf
, 1 );
614 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTGLINE'd user ' %s ' on trust group ' %s ' for %s with reason ' %s ' ( %d hits)" ,
615 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, longtoduration ( duration
, 0 ), reason
, hits
);
617 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
622 static int glines_cmdtrustungline ( void * source
, int cargc
, char ** cargv
) {
623 nick
* sender
= source
;
633 tg
= tg_strtotg ( cargv
[ 0 ]);
635 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
636 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
642 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
643 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
645 gl
= findgline ( mask
);
647 if ( gl
&& ( gl
-> flags
& GLINE_ACTIVE
)) {
648 gline_deactivate ( gl
, 0 , 1 );
653 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTUNGLINE'd user ' %s ' on trust group ' %s ' ( %d G-Lines deactivated)" ,
654 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, count
);
656 controlreply ( sender
, "Done." );
661 static int glines_cmdglstats ( void * source
, int cargc
, char ** cargv
) {
662 nick
* sender
= ( nick
*) source
;
664 time_t curtime
= getnettime ();
665 int glinecount
= 0 , hostglinecount
= 0 , ipglinecount
= 0 , badchancount
= 0 , rnglinecount
= 0 ;
666 int deactivecount
= 0 , activecount
= 0 ;
668 for ( gl
= glinelist
; gl
; gl
= next
) {
671 if ( gl
-> lifetime
<= curtime
) {
674 } else if ( gl
-> expire
<= curtime
) {
675 gl
-> flags
&= ~ GLINE_ACTIVE
;
678 if ( gl
-> flags
& GLINE_ACTIVE
) {
684 if ( gl
-> flags
& GLINE_IPMASK
)
686 else if ( gl
-> flags
& GLINE_HOSTMASK
)
688 else if ( gl
-> flags
& GLINE_REALNAME
)
690 else if ( gl
-> flags
& GLINE_BADCHAN
)
695 controlreply ( sender
, "Total G-Lines set: %d " , glinecount
);
696 controlreply ( sender
, "Hostmask G-Lines: %d " , hostglinecount
);
697 controlreply ( sender
, "IPMask G-Lines: %d " , ipglinecount
);
698 controlreply ( sender
, "Channel G-Lines: %d " , badchancount
);
699 controlreply ( sender
, "Realname G-Lines: %d " , rnglinecount
);
701 controlreply ( sender
, "Active G-Lines: %d " , activecount
);
702 controlreply ( sender
, "Inactive G-Lines: %d " , deactivecount
);
704 /* TODO show top 10 creators here */
705 /* TODO show unique creators count */
706 /* TODO show glines per create %8.1f", ccount?((float)gcount/(float)ccount):0 */
710 static int glines_cmdglist ( void * source
, int cargc
, char ** cargv
) {
711 nick
* sender
= ( nick
*) source
;
713 time_t curtime
= time ( NULL
);
718 char expirestr
[ 250 ], idstr
[ 250 ];
720 if ( cargc
< 1 || ( cargc
== 1 && cargv
[ 0 ][ 0 ] == '-' )) {
721 controlreply ( sender
, "Syntax: glist [-flags] <mask>" );
722 controlreply ( sender
, "Valid flags are:" );
723 controlreply ( sender
, "-c: Count G-Lines." );
724 controlreply ( sender
, "-f: Find G-Lines active on <mask>." );
725 controlreply ( sender
, "-x: Find G-Lines matching <mask> exactly." );
726 controlreply ( sender
, "-R: Find G-lines on realnames." );
727 controlreply ( sender
, "-o: Search for glines by owner." );
728 controlreply ( sender
, "-r: Search for glines by reason." );
729 controlreply ( sender
, "-i: Include inactive glines." );
742 flags
|= GLIST_COUNT
;
750 flags
|= GLIST_EXACT
;
754 flags
|= GLIST_REASON
;
757 flags
|= GLIST_OWNER
;
761 flags
|= GLIST_REALNAME
;
765 flags
|= GLIST_INACTIVE
;
769 controlreply ( sender
, "Invalid flag ' %c '." , * ch
);
778 if (( flags
& ( GLIST_EXACT
| GLIST_FIND
)) == ( GLIST_EXACT
| GLIST_FIND
)) {
779 controlreply ( sender
, "You cannot use -x and -f flags together." );
783 if (!( flags
& GLIST_COUNT
))
784 controlreply ( sender
, "%-50s %-19s %-15s %-25s %s " , "Mask:" , "Expires in:" , "Transaction ID:" , "Creator:" , "Reason:" );
786 gline
* searchgl
= makegline ( mask
);
788 for ( gl
= glinelist
; gl
; gl
= next
) {
791 if ( gl
-> lifetime
<= curtime
) {
794 } else if ( gl
-> expire
<= curtime
) {
795 gl
-> flags
&= ~ GLINE_ACTIVE
;
798 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
799 if (!( flags
& GLIST_INACTIVE
)) {
804 if ( flags
& GLIST_REALNAME
) {
805 if (!( gl
-> flags
& GLINE_REALNAME
))
807 if ( flags
& GLIST_EXACT
) {
808 if (! glineequal ( searchgl
, gl
))
810 } else if ( flags
& GLIST_FIND
) {
811 if (! gline_match_mask ( gl
, searchgl
))
814 if (! match2strings ( mask
, glinetostring ( gl
)))
818 if ( gl
-> flags
& GLINE_REALNAME
)
821 if ( flags
& GLIST_REASON
) {
822 if ( flags
& GLIST_EXACT
) {
823 if (! gl
-> reason
|| ircd_strcmp ( mask
, gl
-> reason
-> content
) != 0 )
825 } else if ( flags
& GLIST_FIND
) {
826 if (! gl
-> reason
|| ! match2strings ( gl
-> reason
-> content
, mask
))
828 } else if (! gl
-> reason
|| ! match2strings ( mask
, gl
-> reason
-> content
))
830 } else if ( flags
& GLIST_OWNER
) {
831 if ( flags
& GLIST_EXACT
) {
832 if (! gl
-> creator
|| ircd_strcmp ( mask
, gl
-> creator
-> content
) != 0 )
834 } else if ( flags
& GLIST_FIND
) {
835 if (! gl
-> creator
|| ! match2strings ( gl
-> creator
-> content
, mask
))
837 } else if (! gl
-> creator
|| ! match2strings ( mask
, gl
-> creator
-> content
))
840 if ( flags
& GLIST_EXACT
) {
841 if (! glineequal ( searchgl
, gl
))
843 } else if ( flags
& GLIST_FIND
) {
844 if (! gline_match_mask ( gl
, searchgl
))
847 if (! match2strings ( mask
, glinetostring ( gl
)))
853 if ( count
== limit
&& !( flags
& GLIST_COUNT
))
854 controlreply ( sender
, "More than %d matches, list truncated." , limit
);
858 if (!( flags
& GLIST_COUNT
) && count
< limit
) {
859 snprintf ( expirestr
, sizeof ( expirestr
), " %s " , glinetostring ( gl
));
860 snprintf ( idstr
, sizeof ( idstr
), " %d " , gl
-> glinebufid
);
861 controlreply ( sender
, " %s %-49s %-19s %-15s %-25s %s " ,
862 ( gl
-> flags
& GLINE_ACTIVE
) ? "+" : "-" ,
864 ( gl
-> flags
& GLINE_ACTIVE
) ? ( char *) longtoduration ( gl
-> expire
- curtime
, 0 ) : "<inactive>" ,
865 gl
-> glinebufid
? idstr
: "" ,
866 gl
-> creator
? gl
-> creator
-> content
: "" ,
867 gl
-> reason
? gl
-> reason
-> content
: "" );
871 controlreply ( sender
, " %s%d G-Line %s found." , ( flags
& GLIST_COUNT
) ? "" : "End of list - " , count
, count
== 1 ? "" : "s" );
876 static int glines_cmdglinelog ( void * source
, int cargc
, char ** cargv
) {
877 nick
* sender
= source
;
889 controlreply ( sender
, "Invalid log ID." );
894 controlreply ( sender
, "Time ID G-Lines User Hits Channel Hits Comment" );
896 for ( i
= 0 ; i
< MAXGLINELOG
; i
++) {
897 gbl
= glinebuflog
[( i
+ glinebuflogoffset
+ 1 ) % MAXGLINELOG
];
902 if ( id
== 0 || gbl
-> id
== id
) {
905 for ( gl
= gbl
-> glines
; gl
; gl
= gl
-> next
)
908 strftime ( timebuf
, sizeof ( timebuf
), " %d / %m / %y %H : %M : %S " , localtime (( gbl
-> amend
) ? & gbl
-> amend
: & gbl
-> commit
));
909 strncat ( timebuf
, ( gbl
-> amend
) ? "*" : " " , sizeof ( timebuf
));
910 controlreply ( sender
, "%-20s %-10d %-10d %-15d %-15d %s " , timebuf
, gbl
-> id
, count
, gbl
-> userhits
, gbl
-> channelhits
, gbl
-> comment
? gbl
-> comment
-> content
: "(no comment)" );
913 if ( id
!= 0 && gbl
-> id
== id
) {
914 glinebufspew ( gbl
, sender
);
915 controlreply ( sender
, "Done." );
921 controlreply ( sender
, "Done." );
923 controlreply ( sender
, "Log entry for ID %d not found." , id
);
929 static int glines_cmdglineundo ( void * source
, int cargc
, char ** cargv
) {
930 nick
* sender
= source
;
938 if ( id
== 0 || ! glinebufundo ( id
)) {
939 controlreply ( sender
, "Invalid log ID." );
943 controlreply ( sender
, "Done." );
948 static int glines_cmdsyncglines ( void * source
, int cargc
, char ** cargv
) {
949 nick
* sender
= source
;
955 for ( gl
= glinelist
; gl
; gl
= gl
-> next
) {
960 controlwall ( NO_OPER
, NL_GLINES
, " %s SYNCGLINE'd %d G-Lines." ,
961 controlid ( sender
), count
);
963 controlreply ( sender
, "Done." );
968 static int glines_cmdcleanupglines ( void * source
, int cargc
, char ** cargv
) {
969 nick
* sender
= source
;
977 for ( pnext
= & glinelist
; * pnext
;) {
980 /* Remove inactivate glines that have been last changed more than a week ago */
981 if (!( gl
-> flags
& GLINE_ACTIVE
) && gl
-> lastmod
< now
- 7 * 24 * 60 * 60 ) {
982 gline_destroy ( gl
, 0 , 1 );
985 pnext
= &((* pnext
)-> next
);
992 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEANUPGLINES'd %d G-Lines." ,
993 controlid ( sender
), count
);
995 controlreply ( sender
, "Done." );
1000 static int commandsregistered
;
1002 static void registercommands ( int hooknum
, void * arg
) {
1003 if ( commandsregistered
)
1005 commandsregistered
= 1 ;
1007 registercontrolhelpcmd ( "block" , NO_OPER
, 4 , glines_cmdblock
, "Usage: block ?flags? <nick> <duration> <reason> \n Sets a gline using an appropriate mask given the user's nickname. \n Flags can be one or more of: \n -f - bypass sanity checks \n -l - bypass hit limits \n -S - simulate who the glines would hit \n -c - chase nick across quits/kills/nick changes" );
1008 registercontrolhelpcmd ( "gline" , NO_OPER
, 4 , glines_cmdgline
, "Usage: gline ?flags? <mask> <duration> <reason> \n Sets a gline. \n Flags can be one or more of: \n -f - bypass sanity checks \n -l - bypass hit limits \n -S - simulate who the glines would hit" );
1009 registercontrolhelpcmd ( "smartgline" , NO_OPER
, 4 , glines_cmdsmartgline
, "Usage: smartgline ?flags? <user@host> <duration> <reason> \n Sets a gline. Automatically adjusts the mask depending on whether the specified mask is trusted. \n Flags can be one or more of: \n -f - bypass sanity checks \n -l - bypass hit limits \n -S - simulate who the glines would hit" );
1010 registercontrolhelpcmd ( "ungline" , NO_OPER
, 1 , glines_cmdungline
, "Usage: ungline <mask> \n Deactivates a gline." );
1011 registercontrolhelpcmd ( "destroygline" , NO_DEVELOPER
, 1 , glines_cmddestroygline
, "Usage: destroygline <mask> \n Destroys a gline." );
1012 registercontrolhelpcmd ( "clearchan" , NO_OPER
, 5 , glines_cmdclearchan
, "Usage: clearchan ?flags? <#channel> <how> <duration> ?reason? \n Clears a channel. \n how can be one of: \n kick - Kicks users. \n kill - Kills users. \n gline - Glines non-authed users (using an appropriate mask). \n glineall - Glines users. \n Duration is only valid when glining users. Reason defaults to \" Clearing channel. \" . \n Flags (for glines) can be one or more of: \n -f - bypass sanity checks \n -l - bypass hit limits \n -S - simulate who the glines would hit" );
1013 registercontrolhelpcmd ( "trustgline" , NO_OPER
, 5 , glines_cmdtrustgline
, "Usage: trustgline ?flags? <#id|name> <user> <duration> <reason> \n Sets a gline on the specified username for each host in the specified trust group. The username may contain wildcards. \n Flags can be one or more of: \n -f - bypass sanity checks \n -l - bypass hit limits \n -S - simulate who the glines would hit" );
1014 registercontrolhelpcmd ( "trustungline" , NO_OPER
, 2 , glines_cmdtrustungline
, "Usage: trustungline <#id|name> <user> \n Removes a gline that was previously set with trustgline." );
1015 registercontrolhelpcmd ( "glstats" , NO_OPER
, 0 , glines_cmdglstats
, "Usage: glstat \n Shows statistics about G-Lines." );
1016 registercontrolhelpcmd ( "glist" , NO_OPER
, 2 , glines_cmdglist
, "Usage: glist [-flags] <mask> \n Lists matching G-Lines. \n Valid flags are: \n -c: Count G-Lines. \n -f: Find G-Lines active on <mask>. \n -x: Find G-Lines matching <mask> exactly. \n -R: Find G-lines on realnames. \n -o: Search for glines by owner. \n -r: Search for glines by reason. \n -i: Include inactive glines." );
1017 registercontrolhelpcmd ( "glinelog" , NO_OPER
, 1 , glines_cmdglinelog
, "Usage: glinelog ?id? \n Shows information about previous gline transactions." );
1018 registercontrolhelpcmd ( "glineundo" , NO_OPER
, 1 , glines_cmdglineundo
, "Usage: glineundo ?id? \n Undoes a gline transaction." );
1019 registercontrolhelpcmd ( "syncglines" , NO_DEVELOPER
, 0 , glines_cmdsyncglines
, "Usage: syncglines \n Sends all G-Lines to all other servers." );
1020 registercontrolhelpcmd ( "cleanupglines" , NO_DEVELOPER
, 0 , glines_cmdcleanupglines
, "Usage: cleanupglines \n Destroys all deactivated G-Lines." );
1023 static void deregistercommands ( int hooknum
, void * arg
) {
1024 if (! commandsregistered
)
1026 commandsregistered
= 0 ;
1028 deregistercontrolcmd ( "block" , glines_cmdblock
);
1029 deregistercontrolcmd ( "gline" , glines_cmdgline
);
1030 deregistercontrolcmd ( "smartgline" , glines_cmdsmartgline
);
1031 deregistercontrolcmd ( "ungline" , glines_cmdungline
);
1032 deregistercontrolcmd ( "destroygline" , glines_cmddestroygline
);
1033 deregistercontrolcmd ( "clearchan" , glines_cmdclearchan
);
1034 deregistercontrolcmd ( "trustgline" , glines_cmdtrustgline
);
1035 deregistercontrolcmd ( "trustungline" , glines_cmdtrustungline
);
1036 deregistercontrolcmd ( "glstats" , glines_cmdglstats
);
1037 deregistercontrolcmd ( "glist" , glines_cmdglist
);
1038 deregistercontrolcmd ( "glinelog" , glines_cmdglinelog
);
1039 deregistercontrolcmd ( "glineundo" , glines_cmdglineundo
);
1040 deregistercontrolcmd ( "syncglines" , glines_cmdsyncglines
);
1041 deregistercontrolcmd ( "cleanupglines" , glines_cmdcleanupglines
);
1045 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1046 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1049 registercommands ( 0 , NULL
);
1053 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1054 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1056 deregistercommands ( 0 , NULL
);