]>
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 );
113 if ( sender
!= target
&& ( IsService ( wnp
) || IsOper ( wnp
) || NickOnServiceServer ( wnp
))) {
114 controlreply ( sender
, "Target user ' %s ' is an oper or a service. Not setting G-Lines." , wnp
-> nick
);
118 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
119 reason
= cargv
[ coff
+ 2 ];
122 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
124 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
126 glinebufinit (& gbuf
, 0 );
127 glinebufcommentv (& gbuf
, "BLOCK" , cargc
+ coff
- 1 , cargv
);
128 glinebufaddbywhowas (& gbuf
, ww
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
130 glinebufspew (& gbuf
, sender
);
132 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
133 glinebufabort (& gbuf
);
136 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
141 glinebufabort (& gbuf
);
144 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
148 glinebufcounthits (& gbuf
, & hits
, NULL
);
149 id
= glinebufcommit (& gbuf
, 1 );
151 controlwall ( NO_OPER
, NL_GLINES
, " %s BLOCK'ed user ' %s ! %s @ %s ' for %s with reason ' %s ' ( %d hits)" , controlid ( sender
),
152 wnp
-> nick
, wnp
-> ident
, wnp
-> host
-> name
-> content
,
153 longtoduration ( duration
, 0 ), reason
, hits
);
158 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
163 static int glines_cmdgline ( void * source
, int cargc
, char ** cargv
) {
164 nick
* sender
= source
;
165 int duration
, users
, channels
, id
;
168 int coff
, overridesanity
, overridelimit
, simulate
;
170 #if SNIRCD_VERSION < 140
172 #endif /* SNIRCD_VERSION */
177 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
180 if ( cargc
< 3 + coff
)
185 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
188 controlreply ( sender
, "Invalid duration specified." );
192 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
193 reason
= cargv
[ coff
+ 2 ];
195 #if SNIRCD_VERSION < 140
196 gl
= findgline ( mask
);
199 /* warn opers that they can't modify this gline */
200 if ( gl
-> flags
& GLINE_ACTIVE
) {
201 controlreply ( sender
, "Active G-Line already exists on %s - unable to modify" , mask
);
205 controlreply ( sender
, "Reactivating existing gline on %s " , mask
);
207 #endif /* SNIRCD_VERSION */
210 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
212 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
214 glinebufinit (& gbuf
, 0 );
215 glinebufcommentv (& gbuf
, "GLINE" , cargc
+ coff
- 1 , cargv
);
217 if (! glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
)) {
218 controlreply ( sender
, "Invalid G-Line mask." );
222 glinebufspew (& gbuf
, sender
);
224 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
225 glinebufabort (& gbuf
);
226 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
231 glinebufabort (& gbuf
);
232 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
236 glinebufcounthits (& gbuf
, & users
, & channels
);
237 id
= glinebufcommit (& gbuf
, 1 );
239 controlwall ( NO_OPER
, NL_GLINES
, " %s GLINE'd mask ' %s ' for %s with reason ' %s ' (hits %d users/ %d channels)" ,
240 controlid ( sender
), mask
, longtoduration ( duration
, 0 ), reason
, users
, channels
);
242 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
247 static int glines_cmdsmartgline ( void * source
, int cargc
, char ** cargv
) {
248 nick
* sender
= source
;
251 char * p
, * user
, * host
;
252 struct irc_in_addr ip
;
255 int coff
, overridesanity
, overridelimit
, simulate
, id
;
263 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
266 if ( cargc
< 3 + coff
)
269 origmask
= cargv
[ coff
];
271 if ( origmask
[ 0 ] == '#' || origmask
[ 0 ] == '&' || origmask
[ 0 ] == '$' ) {
272 controlreply ( sender
, "Please use \" gline \" for badchan or realname glines." );
276 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
279 controlreply ( sender
, "Invalid duration specified." );
283 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
284 reason
= cargv
[ coff
+ 2 ];
286 strncpy ( mask
, origmask
, sizeof ( mask
));
288 if ( strchr ( mask
, '!' )) {
289 controlreply ( sender
, "Use \" gline \" to place nick glines." );
293 p
= strchr ( mask
, '@' );
296 controlreply ( sender
, "Mask must contain a username (e.g. user@ip)." );
304 if ( strchr ( user
, '*' ) || strchr ( user
, '?' )) {
305 controlreply ( sender
, "Usernames may not contain wildcards." );
309 if (! ipmask_parse ( host
, & ip
, & bits
)) {
310 controlreply ( sender
, "Invalid CIDR mask." );
315 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
317 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
319 glinebufinit (& gbuf
, 0 );
320 glinebufcommentv (& gbuf
, "SMARTGLINE" , cargc
+ coff
- 1 , cargv
);
321 glinebufaddbyip (& gbuf
, user
, & ip
, 128 , 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
323 glinebufspew (& gbuf
, sender
);
325 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
326 glinebufabort (& gbuf
);
327 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
332 glinebufabort (& gbuf
);
333 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
337 glinebufcounthits (& gbuf
, & hits
, NULL
);
338 id
= glinebufcommit (& gbuf
, 1 );
340 controlwall ( NO_OPER
, NL_GLINES
, " %s SMARTGLINE'd mask ' %s ' for %s with reason ' %s ' ( %d hits)" ,
341 controlid ( sender
), cargv
[ 0 ], longtoduration ( duration
, 0 ), reason
, hits
);
343 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
348 static int glines_cmdungline ( void * source
, int cargc
, char ** cargv
) {
349 nick
* sender
= source
;
355 gl
= findgline ( cargv
[ 0 ]);
358 controlreply ( sender
, "No such G-Line." );
362 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
363 controlreply ( sender
, "G-Line was already deactivated." );
367 gline_deactivate ( gl
, 0 , 1 );
369 controlwall ( NO_OPER
, NL_GLINES
, " %s UNGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
371 controlreply ( sender
, "G-Line deactivated." );
376 static int glines_cmddestroygline ( void * source
, int cargc
, char ** cargv
) {
377 nick
* sender
= source
;
383 gl
= findgline ( cargv
[ 0 ]);
386 controlreply ( sender
, "No such G-Line." );
390 gline_destroy ( gl
, 0 , 1 );
392 controlwall ( NO_OPER
, NL_GLINES
, " %s DESTROYGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
394 controlreply ( sender
, "G-Line destroyed." );
399 static int glines_cmdclearchan ( void * source
, int cargc
, char ** cargv
) {
400 nick
* sender
= source
;
403 char * reason
= "Clearing channel." ;
404 int mode
, duration
, i
, slot
, hits
, id
;
405 int coff
, overridesanity
, overridelimit
, simulate
;
413 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
416 if ( cargc
< 2 + coff
)
419 cp
= findchannel ( cargv
[ coff
]);
422 controlreply ( sender
, "Couldn't find that channel." );
426 if ( strcmp ( cargv
[ coff
+ 1 ], "kick" ) == 0 )
428 else if ( strcmp ( cargv
[ coff
+ 1 ], "kill" ) == 0 )
430 else if ( strcmp ( cargv
[ coff
+ 1 ], "gline" ) == 0 )
432 else if ( strcmp ( cargv
[ coff
+ 1 ], "glineall" ) == 0 )
437 if ( mode
== 0 || mode
== 1 ) {
439 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
440 reason
= cargv
[ coff
+ 2 ];
443 if ( cargc
< 3 + coff
)
446 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
449 controlreply ( sender
, "Invalid duration specified." );
453 if ( cargc
>= 4 + coff
) {
454 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
455 reason
= cargv
[ coff
+ 3 ];
459 array_init (& victims
, sizeof ( nick
*));
461 /* we need to make a list of the channel users here because
462 * kicking/killing them will affect their position in the channel's
464 for ( i
= 0 ; i
< cp
-> users
-> hashsize
; i
++) {
465 if ( cp
-> users
-> content
[ i
] == nouser
)
468 np
= getnickbynumeric ( cp
-> users
-> content
[ i
]);
473 if ( IsService ( np
) || IsOper ( np
) || NickOnServiceServer ( np
))
476 slot
= array_getfreeslot (& victims
);
477 ((( nick
**) victims
. content
)[ slot
]) = np
;
481 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
483 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
485 glinebufinit (& gbuf
, 0 );
486 glinebufcommentv (& gbuf
, "CLEARCHAN" , cargc
+ coff
- 1 , cargv
);
488 for ( i
= 0 ; i
< victims
. cursi
; i
++) {
489 np
= (( nick
**) victims
. content
)[ i
];
494 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
496 localkickuser ( NULL
, cp
, np
, reason
);
501 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
503 killuser ( NULL
, np
, " %s " , reason
);
511 glinebufaddbynick (& gbuf
, np
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
518 if ( mode
!= 0 && mode
!= 1 ) {
519 glinebufspew (& gbuf
, sender
);
521 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
522 glinebufabort (& gbuf
);
523 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
529 glinebufabort (& gbuf
);
530 controlreply ( sender
, "Simulation complete. Not clearing channel." );
534 glinebufmerge (& gbuf
);
535 glinebufcounthits (& gbuf
, & hits
, NULL
);
536 id
= glinebufcommit (& gbuf
, 1 );
538 array_free (& victims
);
540 if ( mode
== 0 || mode
== 1 ) {
541 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ' and reason ' %s '" ,
542 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], reason
);
543 controlreply ( sender
, "Done." );
545 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ', duration %s and reason ' %s ' ( %d hits)" ,
546 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], longtoduration ( duration
, 0 ), reason
, hits
);
547 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
553 static int glines_cmdtrustgline ( void * source
, int cargc
, char ** cargv
) {
554 nick
* sender
= source
;
558 int coff
, overridesanity
, overridelimit
, simulate
, id
;
567 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
570 if ( cargc
< 4 + coff
)
573 tg
= tg_strtotg ( cargv
[ coff
]);
575 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
576 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
580 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
583 controlreply ( sender
, "Invalid duration specified." );
587 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
588 reason
= cargv
[ coff
+ 3 ];
591 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
593 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
595 glinebufinit (& gbuf
, 0 );
596 glinebufcommentv (& gbuf
, "TRUSTGLINE" , cargc
+ coff
- 1 , cargv
);
598 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
599 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
600 glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
603 glinebufspew (& gbuf
, sender
);
605 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
606 glinebufabort (& gbuf
);
607 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
612 glinebufabort (& gbuf
);
613 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
617 glinebufcounthits (& gbuf
, & hits
, NULL
);
618 id
= glinebufcommit (& gbuf
, 1 );
620 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTGLINE'd user ' %s ' on trust group ' %s ' for %s with reason ' %s ' ( %d hits)" ,
621 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, longtoduration ( duration
, 0 ), reason
, hits
);
623 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
628 static int glines_cmdtrustungline ( void * source
, int cargc
, char ** cargv
) {
629 nick
* sender
= source
;
639 tg
= tg_strtotg ( cargv
[ 0 ]);
641 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
642 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
648 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
649 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
651 gl
= findgline ( mask
);
653 if ( gl
&& ( gl
-> flags
& GLINE_ACTIVE
)) {
654 gline_deactivate ( gl
, 0 , 1 );
659 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTUNGLINE'd user ' %s ' on trust group ' %s ' ( %d G-Lines deactivated)" ,
660 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, count
);
662 controlreply ( sender
, "Done." );
667 static int glines_cmdglstats ( void * source
, int cargc
, char ** cargv
) {
668 nick
* sender
= ( nick
*) source
;
670 time_t curtime
= getnettime ();
671 int glinecount
= 0 , hostglinecount
= 0 , ipglinecount
= 0 , badchancount
= 0 , rnglinecount
= 0 ;
672 int deactivecount
= 0 , activecount
= 0 ;
674 for ( gl
= glinelist
; gl
; gl
= next
) {
677 if ( gl
-> lifetime
<= curtime
) {
680 } else if ( gl
-> expire
<= curtime
) {
681 gl
-> flags
&= ~ GLINE_ACTIVE
;
684 if ( gl
-> flags
& GLINE_ACTIVE
) {
690 if ( gl
-> flags
& GLINE_IPMASK
)
692 else if ( gl
-> flags
& GLINE_HOSTMASK
)
694 else if ( gl
-> flags
& GLINE_REALNAME
)
696 else if ( gl
-> flags
& GLINE_BADCHAN
)
701 controlreply ( sender
, "Total G-Lines set: %d " , glinecount
);
702 controlreply ( sender
, "Hostmask G-Lines: %d " , hostglinecount
);
703 controlreply ( sender
, "IPMask G-Lines: %d " , ipglinecount
);
704 controlreply ( sender
, "Channel G-Lines: %d " , badchancount
);
705 controlreply ( sender
, "Realname G-Lines: %d " , rnglinecount
);
707 controlreply ( sender
, "Active G-Lines: %d " , activecount
);
708 controlreply ( sender
, "Inactive G-Lines: %d " , deactivecount
);
710 /* TODO show top 10 creators here */
711 /* TODO show unique creators count */
712 /* TODO show glines per create %8.1f", ccount?((float)gcount/(float)ccount):0 */
716 static int glines_cmdglist ( void * source
, int cargc
, char ** cargv
) {
717 nick
* sender
= ( nick
*) source
;
719 time_t curtime
= time ( NULL
);
724 char expirestr
[ 250 ], idstr
[ 250 ];
726 if ( cargc
< 1 || ( cargc
== 1 && cargv
[ 0 ][ 0 ] == '-' )) {
727 controlreply ( sender
, "Syntax: glist [-flags] <mask>" );
728 controlreply ( sender
, "Valid flags are:" );
729 controlreply ( sender
, "-c: Count G-Lines." );
730 controlreply ( sender
, "-f: Find G-Lines active on <mask>." );
731 controlreply ( sender
, "-x: Find G-Lines matching <mask> exactly." );
732 controlreply ( sender
, "-R: Find G-lines on realnames." );
733 controlreply ( sender
, "-o: Search for glines by owner." );
734 controlreply ( sender
, "-r: Search for glines by reason." );
735 controlreply ( sender
, "-i: Include inactive glines." );
748 flags
|= GLIST_COUNT
;
756 flags
|= GLIST_EXACT
;
760 flags
|= GLIST_REASON
;
763 flags
|= GLIST_OWNER
;
767 flags
|= GLIST_REALNAME
;
771 flags
|= GLIST_INACTIVE
;
775 controlreply ( sender
, "Invalid flag ' %c '." , * ch
);
784 if (( flags
& ( GLIST_EXACT
| GLIST_FIND
)) == ( GLIST_EXACT
| GLIST_FIND
)) {
785 controlreply ( sender
, "You cannot use -x and -f flags together." );
789 if (!( flags
& GLIST_COUNT
))
790 controlreply ( sender
, "%-50s %-19s %-15s %-25s %s " , "Mask:" , "Expires in:" , "Transaction ID:" , "Creator:" , "Reason:" );
792 gline
* searchgl
= makegline ( mask
);
794 for ( gl
= glinelist
; gl
; gl
= next
) {
797 if ( gl
-> lifetime
<= curtime
) {
800 } else if ( gl
-> expire
<= curtime
) {
801 gl
-> flags
&= ~ GLINE_ACTIVE
;
804 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
805 if (!( flags
& GLIST_INACTIVE
)) {
810 if ( flags
& GLIST_REALNAME
) {
811 if (!( gl
-> flags
& GLINE_REALNAME
))
813 if ( flags
& GLIST_EXACT
) {
814 if (! glineequal ( searchgl
, gl
))
816 } else if ( flags
& GLIST_FIND
) {
817 if (! gline_match_mask ( gl
, searchgl
))
820 if (! match2strings ( mask
, glinetostring ( gl
)))
824 if ( gl
-> flags
& GLINE_REALNAME
)
827 if ( flags
& GLIST_REASON
) {
828 if ( flags
& GLIST_EXACT
) {
829 if (! gl
-> reason
|| ircd_strcmp ( mask
, gl
-> reason
-> content
) != 0 )
831 } else if ( flags
& GLIST_FIND
) {
832 if (! gl
-> reason
|| ! match2strings ( gl
-> reason
-> content
, mask
))
834 } else if (! gl
-> reason
|| ! match2strings ( mask
, gl
-> reason
-> content
))
836 } else if ( flags
& GLIST_OWNER
) {
837 if ( flags
& GLIST_EXACT
) {
838 if (! gl
-> creator
|| ircd_strcmp ( mask
, gl
-> creator
-> content
) != 0 )
840 } else if ( flags
& GLIST_FIND
) {
841 if (! gl
-> creator
|| ! match2strings ( gl
-> creator
-> content
, mask
))
843 } else if (! gl
-> creator
|| ! match2strings ( mask
, gl
-> creator
-> content
))
846 if ( flags
& GLIST_EXACT
) {
847 if (! glineequal ( searchgl
, gl
))
849 } else if ( flags
& GLIST_FIND
) {
850 if (! gline_match_mask ( gl
, searchgl
))
853 if (! match2strings ( mask
, glinetostring ( gl
)))
859 if ( count
== limit
&& !( flags
& GLIST_COUNT
))
860 controlreply ( sender
, "More than %d matches, list truncated." , limit
);
864 if (!( flags
& GLIST_COUNT
) && count
< limit
) {
865 snprintf ( expirestr
, sizeof ( expirestr
), " %s " , glinetostring ( gl
));
866 snprintf ( idstr
, sizeof ( idstr
), " %d " , gl
-> glinebufid
);
867 controlreply ( sender
, " %s %-49s %-19s %-15s %-25s %s " ,
868 ( gl
-> flags
& GLINE_ACTIVE
) ? "+" : "-" ,
870 ( gl
-> flags
& GLINE_ACTIVE
) ? ( char *) longtoduration ( gl
-> expire
- curtime
, 0 ) : "<inactive>" ,
871 gl
-> glinebufid
? idstr
: "" ,
872 gl
-> creator
? gl
-> creator
-> content
: "" ,
873 gl
-> reason
? gl
-> reason
-> content
: "" );
877 controlreply ( sender
, " %s%d G-Line %s found." , ( flags
& GLIST_COUNT
) ? "" : "End of list - " , count
, count
== 1 ? "" : "s" );
882 static int glines_cmdglinelog ( void * source
, int cargc
, char ** cargv
) {
883 nick
* sender
= source
;
895 controlreply ( sender
, "Invalid log ID." );
900 controlreply ( sender
, "Time ID G-Lines User Hits Channel Hits Comment" );
902 for ( i
= 0 ; i
< MAXGLINELOG
; i
++) {
903 gbl
= glinebuflog
[( i
+ glinebuflogoffset
+ 1 ) % MAXGLINELOG
];
908 if ( id
== 0 || gbl
-> id
== id
) {
911 for ( gl
= gbl
-> glines
; gl
; gl
= gl
-> next
)
914 strftime ( timebuf
, sizeof ( timebuf
), " %d / %m / %y %H : %M : %S " , localtime (( gbl
-> amend
) ? & gbl
-> amend
: & gbl
-> commit
));
915 strncat ( timebuf
, ( gbl
-> amend
) ? "*" : " " , sizeof ( timebuf
));
916 controlreply ( sender
, "%-20s %-10d %-10d %-15d %-15d %s " , timebuf
, gbl
-> id
, count
, gbl
-> userhits
, gbl
-> channelhits
, gbl
-> comment
? gbl
-> comment
-> content
: "(no comment)" );
919 if ( id
!= 0 && gbl
-> id
== id
) {
920 glinebufspew ( gbl
, sender
);
921 controlreply ( sender
, "Done." );
927 controlreply ( sender
, "Done." );
929 controlreply ( sender
, "Log entry for ID %d not found." , id
);
935 static int glines_cmdglineundo ( void * source
, int cargc
, char ** cargv
) {
936 nick
* sender
= source
;
944 if ( id
== 0 || ! glinebufundo ( id
)) {
945 controlreply ( sender
, "Invalid log ID." );
949 controlreply ( sender
, "Done." );
954 static int glines_cmdsyncglines ( void * source
, int cargc
, char ** cargv
) {
955 nick
* sender
= source
;
961 for ( gl
= glinelist
; gl
; gl
= gl
-> next
) {
966 controlwall ( NO_OPER
, NL_GLINES
, " %s SYNCGLINE'd %d G-Lines." ,
967 controlid ( sender
), count
);
969 controlreply ( sender
, "Done." );
974 static int glines_cmdcleanupglines ( void * source
, int cargc
, char ** cargv
) {
975 nick
* sender
= source
;
983 for ( pnext
= & glinelist
; * pnext
;) {
986 /* Remove inactivate glines that have been last changed more than a week ago */
987 if (!( gl
-> flags
& GLINE_ACTIVE
) && gl
-> lastmod
< now
- 7 * 24 * 60 * 60 ) {
988 gline_destroy ( gl
, 0 , 1 );
991 pnext
= &((* pnext
)-> next
);
998 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEANUPGLINES'd %d G-Lines." ,
999 controlid ( sender
), count
);
1001 controlreply ( sender
, "Done." );
1006 static int commandsregistered
;
1008 static void registercommands ( int hooknum
, void * arg
) {
1009 if ( commandsregistered
)
1011 commandsregistered
= 1 ;
1013 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" );
1014 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" );
1015 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" );
1016 registercontrolhelpcmd ( "ungline" , NO_OPER
, 1 , glines_cmdungline
, "Usage: ungline <mask> \n Deactivates a gline." );
1017 registercontrolhelpcmd ( "destroygline" , NO_DEVELOPER
, 1 , glines_cmddestroygline
, "Usage: destroygline <mask> \n Destroys a gline." );
1018 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" );
1019 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" );
1020 registercontrolhelpcmd ( "trustungline" , NO_OPER
, 2 , glines_cmdtrustungline
, "Usage: trustungline <#id|name> <user> \n Removes a gline that was previously set with trustgline." );
1021 registercontrolhelpcmd ( "glstats" , NO_OPER
, 0 , glines_cmdglstats
, "Usage: glstat \n Shows statistics about G-Lines." );
1022 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." );
1023 registercontrolhelpcmd ( "glinelog" , NO_OPER
, 1 , glines_cmdglinelog
, "Usage: glinelog ?id? \n Shows information about previous gline transactions." );
1024 registercontrolhelpcmd ( "glineundo" , NO_OPER
, 1 , glines_cmdglineundo
, "Usage: glineundo ?id? \n Undoes a gline transaction." );
1025 registercontrolhelpcmd ( "syncglines" , NO_DEVELOPER
, 0 , glines_cmdsyncglines
, "Usage: syncglines \n Sends all G-Lines to all other servers." );
1026 registercontrolhelpcmd ( "cleanupglines" , NO_DEVELOPER
, 0 , glines_cmdcleanupglines
, "Usage: cleanupglines \n Destroys all deactivated G-Lines." );
1029 static void deregistercommands ( int hooknum
, void * arg
) {
1030 if (! commandsregistered
)
1032 commandsregistered
= 0 ;
1034 deregistercontrolcmd ( "block" , glines_cmdblock
);
1035 deregistercontrolcmd ( "gline" , glines_cmdgline
);
1036 deregistercontrolcmd ( "smartgline" , glines_cmdsmartgline
);
1037 deregistercontrolcmd ( "ungline" , glines_cmdungline
);
1038 deregistercontrolcmd ( "destroygline" , glines_cmddestroygline
);
1039 deregistercontrolcmd ( "clearchan" , glines_cmdclearchan
);
1040 deregistercontrolcmd ( "trustgline" , glines_cmdtrustgline
);
1041 deregistercontrolcmd ( "trustungline" , glines_cmdtrustungline
);
1042 deregistercontrolcmd ( "glstats" , glines_cmdglstats
);
1043 deregistercontrolcmd ( "glist" , glines_cmdglist
);
1044 deregistercontrolcmd ( "glinelog" , glines_cmdglinelog
);
1045 deregistercontrolcmd ( "glineundo" , glines_cmdglineundo
);
1046 deregistercontrolcmd ( "syncglines" , glines_cmdsyncglines
);
1047 deregistercontrolcmd ( "cleanupglines" , glines_cmdcleanupglines
);
1051 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1052 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1055 registercommands ( 0 , NULL
);
1059 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1060 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1062 deregistercommands ( 0 , NULL
);