]>
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 ];
121 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
123 glinebufinit (& gbuf
, 0 );
124 glinebufcommentv (& gbuf
, "BLOCK" , cargc
+ coff
- 1 , cargv
);
125 glinebufaddbywhowas (& gbuf
, ww
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
127 glinebufspew (& gbuf
, sender
);
129 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
130 glinebufabort (& gbuf
);
133 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
138 glinebufabort (& gbuf
);
141 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
145 glinebufcounthits (& gbuf
, & hits
, NULL
);
146 id
= glinebufcommit (& gbuf
, 1 );
148 controlwall ( NO_OPER
, NL_GLINES
, " %s BLOCK'ed user ' %s ! %s @ %s ' for %s with reason ' %s ' ( %d hits)" , controlid ( sender
),
149 wnp
-> nick
, wnp
-> ident
, wnp
-> host
-> name
-> content
,
150 longtoduration ( duration
, 0 ), reason
, hits
);
155 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
160 static int glines_cmdgline ( void * source
, int cargc
, char ** cargv
) {
161 nick
* sender
= source
;
162 int duration
, users
, channels
, id
;
165 int coff
, overridesanity
, overridelimit
, simulate
;
167 #if SNIRCD_VERSION < 140
169 #endif /* SNIRCD_VERSION */
174 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
177 if ( cargc
< 3 + coff
)
182 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
185 controlreply ( sender
, "Invalid duration specified." );
189 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
190 reason
= cargv
[ coff
+ 2 ];
192 #if SNIRCD_VERSION < 140
193 gl
= findgline ( mask
);
196 /* warn opers that they can't modify this gline */
197 if ( gl
-> flags
& GLINE_ACTIVE
) {
198 controlreply ( sender
, "Active G-Line already exists on %s - unable to modify" , mask
);
202 controlreply ( sender
, "Reactivating existing gline on %s " , mask
);
204 #endif /* SNIRCD_VERSION */
206 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
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." );
308 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
310 glinebufinit (& gbuf
, 0 );
311 glinebufcommentv (& gbuf
, "SMARTGLINE" , cargc
+ coff
- 1 , cargv
);
312 glinebufaddbyip (& gbuf
, user
, & ip
, 128 , 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
314 glinebufspew (& gbuf
, sender
);
316 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
317 glinebufabort (& gbuf
);
318 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
323 glinebufabort (& gbuf
);
324 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
328 glinebufcounthits (& gbuf
, & hits
, NULL
);
329 id
= glinebufcommit (& gbuf
, 1 );
331 controlwall ( NO_OPER
, NL_GLINES
, " %s SMARTGLINE'd mask ' %s ' for %s with reason ' %s ' ( %d hits)" ,
332 controlid ( sender
), cargv
[ 0 ], longtoduration ( duration
, 0 ), reason
, hits
);
334 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
339 static int glines_cmdungline ( void * source
, int cargc
, char ** cargv
) {
340 nick
* sender
= source
;
346 gl
= findgline ( cargv
[ 0 ]);
349 controlreply ( sender
, "No such G-Line." );
353 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
354 controlreply ( sender
, "G-Line was already deactivated." );
358 gline_deactivate ( gl
, 0 , 1 );
360 controlwall ( NO_OPER
, NL_GLINES
, " %s UNGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
362 controlreply ( sender
, "G-Line deactivated." );
367 static int glines_cmddestroygline ( void * source
, int cargc
, char ** cargv
) {
368 nick
* sender
= source
;
374 gl
= findgline ( cargv
[ 0 ]);
377 controlreply ( sender
, "No such G-Line." );
381 gline_destroy ( gl
, 0 , 1 );
383 controlwall ( NO_OPER
, NL_GLINES
, " %s DESTROYGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
385 controlreply ( sender
, "G-Line destroyed." );
390 static int glines_cmdclearchan ( void * source
, int cargc
, char ** cargv
) {
391 nick
* sender
= source
;
394 char * reason
= "Clearing channel." ;
395 int mode
, duration
, i
, slot
, hits
, id
;
396 int coff
, overridesanity
, overridelimit
, simulate
;
404 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
407 if ( cargc
< 2 + coff
)
410 cp
= findchannel ( cargv
[ coff
]);
413 controlreply ( sender
, "Couldn't find that channel." );
417 if ( strcmp ( cargv
[ coff
+ 1 ], "kick" ) == 0 )
419 else if ( strcmp ( cargv
[ coff
+ 1 ], "kill" ) == 0 )
421 else if ( strcmp ( cargv
[ coff
+ 1 ], "gline" ) == 0 )
423 else if ( strcmp ( cargv
[ coff
+ 1 ], "glineall" ) == 0 )
428 if ( mode
== 0 || mode
== 1 ) {
430 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
431 reason
= cargv
[ coff
+ 2 ];
434 if ( cargc
< 3 + coff
)
437 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
440 controlreply ( sender
, "Invalid duration specified." );
444 if ( cargc
>= 4 + coff
) {
445 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
446 reason
= cargv
[ coff
+ 3 ];
450 array_init (& victims
, sizeof ( nick
*));
452 /* we need to make a list of the channel users here because
453 * kicking/killing them will affect their position in the channel's
455 for ( i
= 0 ; i
< cp
-> users
-> hashsize
; i
++) {
456 if ( cp
-> users
-> content
[ i
] == nouser
)
459 np
= getnickbynumeric ( cp
-> users
-> content
[ i
]);
464 if ( IsService ( np
) || IsOper ( np
) || NickOnServiceServer ( np
))
467 slot
= array_getfreeslot (& victims
);
468 ((( nick
**) victims
. content
)[ slot
]) = np
;
471 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
473 glinebufinit (& gbuf
, 0 );
474 glinebufcommentv (& gbuf
, "CLEARCHAN" , cargc
+ coff
- 1 , cargv
);
476 for ( i
= 0 ; i
< victims
. cursi
; i
++) {
477 np
= (( nick
**) victims
. content
)[ i
];
482 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
484 localkickuser ( NULL
, cp
, np
, reason
);
489 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
491 killuser ( NULL
, np
, " %s " , reason
);
499 glinebufaddbynick (& gbuf
, np
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
506 if ( mode
!= 0 && mode
!= 1 ) {
507 glinebufspew (& gbuf
, sender
);
509 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
510 glinebufabort (& gbuf
);
511 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
517 glinebufabort (& gbuf
);
518 controlreply ( sender
, "Simulation complete. Not clearing channel." );
522 glinebufmerge (& gbuf
);
523 glinebufcounthits (& gbuf
, & hits
, NULL
);
524 id
= glinebufcommit (& gbuf
, 1 );
526 array_free (& victims
);
528 if ( mode
== 0 || mode
== 1 ) {
529 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ' and reason ' %s '" ,
530 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], reason
);
531 controlreply ( sender
, "Done." );
533 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ', duration %s and reason ' %s ' ( %d hits)" ,
534 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], longtoduration ( duration
, 0 ), reason
, hits
);
535 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
541 static int glines_cmdtrustgline ( void * source
, int cargc
, char ** cargv
) {
542 nick
* sender
= source
;
546 int coff
, overridesanity
, overridelimit
, simulate
, id
;
555 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, NULL
, & coff
))
558 if ( cargc
< 4 + coff
)
561 tg
= tg_strtotg ( cargv
[ coff
]);
563 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
564 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
568 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
571 controlreply ( sender
, "Invalid duration specified." );
575 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
576 reason
= cargv
[ coff
+ 3 ];
578 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
580 glinebufinit (& gbuf
, 0 );
581 glinebufcommentv (& gbuf
, "TRUSTGLINE" , cargc
+ coff
- 1 , cargv
);
583 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
584 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
585 glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
588 glinebufspew (& gbuf
, sender
);
590 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
591 glinebufabort (& gbuf
);
592 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
597 glinebufabort (& gbuf
);
598 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
602 glinebufcounthits (& gbuf
, & hits
, NULL
);
603 id
= glinebufcommit (& gbuf
, 1 );
605 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTGLINE'd user ' %s ' on trust group ' %s ' for %s with reason ' %s ' ( %d hits)" ,
606 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, longtoduration ( duration
, 0 ), reason
, hits
);
608 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
613 static int glines_cmdtrustungline ( void * source
, int cargc
, char ** cargv
) {
614 nick
* sender
= source
;
624 tg
= tg_strtotg ( cargv
[ 0 ]);
626 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
627 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
633 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
634 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], CIDRtostr ( th
-> ip
, th
-> bits
));
636 gl
= findgline ( mask
);
638 if ( gl
&& ( gl
-> flags
& GLINE_ACTIVE
)) {
639 gline_deactivate ( gl
, 0 , 1 );
644 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTUNGLINE'd user ' %s ' on trust group ' %s ' ( %d G-Lines deactivated)" ,
645 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, count
);
647 controlreply ( sender
, "Done." );
652 static int glines_cmdglstats ( void * source
, int cargc
, char ** cargv
) {
653 nick
* sender
= ( nick
*) source
;
655 time_t curtime
= getnettime ();
656 int glinecount
= 0 , hostglinecount
= 0 , ipglinecount
= 0 , badchancount
= 0 , rnglinecount
= 0 ;
657 int deactivecount
= 0 , activecount
= 0 ;
659 for ( gl
= glinelist
; gl
; gl
= next
) {
662 if ( gl
-> lifetime
<= curtime
) {
665 } else if ( gl
-> expire
<= curtime
) {
666 gl
-> flags
&= ~ GLINE_ACTIVE
;
669 if ( gl
-> flags
& GLINE_ACTIVE
) {
675 if ( gl
-> flags
& GLINE_IPMASK
)
677 else if ( gl
-> flags
& GLINE_HOSTMASK
)
679 else if ( gl
-> flags
& GLINE_REALNAME
)
681 else if ( gl
-> flags
& GLINE_BADCHAN
)
686 controlreply ( sender
, "Total G-Lines set: %d " , glinecount
);
687 controlreply ( sender
, "Hostmask G-Lines: %d " , hostglinecount
);
688 controlreply ( sender
, "IPMask G-Lines: %d " , ipglinecount
);
689 controlreply ( sender
, "Channel G-Lines: %d " , badchancount
);
690 controlreply ( sender
, "Realname G-Lines: %d " , rnglinecount
);
692 controlreply ( sender
, "Active G-Lines: %d " , activecount
);
693 controlreply ( sender
, "Inactive G-Lines: %d " , deactivecount
);
695 /* TODO show top 10 creators here */
696 /* TODO show unique creators count */
697 /* TODO show glines per create %8.1f", ccount?((float)gcount/(float)ccount):0 */
701 static int glines_cmdglist ( void * source
, int cargc
, char ** cargv
) {
702 nick
* sender
= ( nick
*) source
;
704 time_t curtime
= time ( NULL
);
709 char expirestr
[ 250 ], idstr
[ 250 ];
711 if ( cargc
< 1 || ( cargc
== 1 && cargv
[ 0 ][ 0 ] == '-' )) {
712 controlreply ( sender
, "Syntax: glist [-flags] <mask>" );
713 controlreply ( sender
, "Valid flags are:" );
714 controlreply ( sender
, "-c: Count G-Lines." );
715 controlreply ( sender
, "-f: Find G-Lines active on <mask>." );
716 controlreply ( sender
, "-x: Find G-Lines matching <mask> exactly." );
717 controlreply ( sender
, "-R: Find G-lines on realnames." );
718 controlreply ( sender
, "-o: Search for glines by owner." );
719 controlreply ( sender
, "-r: Search for glines by reason." );
720 controlreply ( sender
, "-i: Include inactive glines." );
733 flags
|= GLIST_COUNT
;
741 flags
|= GLIST_EXACT
;
745 flags
|= GLIST_REASON
;
748 flags
|= GLIST_OWNER
;
752 flags
|= GLIST_REALNAME
;
756 flags
|= GLIST_INACTIVE
;
760 controlreply ( sender
, "Invalid flag ' %c '." , * ch
);
769 if (( flags
& ( GLIST_EXACT
| GLIST_FIND
)) == ( GLIST_EXACT
| GLIST_FIND
)) {
770 controlreply ( sender
, "You cannot use -x and -f flags together." );
774 if (!( flags
& GLIST_COUNT
))
775 controlreply ( sender
, "%-50s %-19s %-15s %-25s %s " , "Mask:" , "Expires in:" , "Transaction ID:" , "Creator:" , "Reason:" );
777 gline
* searchgl
= makegline ( mask
);
780 controlreply ( sender
, "Invalid G-line mask specified." );
784 for ( gl
= glinelist
; gl
; gl
= next
) {
787 if ( gl
-> lifetime
<= curtime
) {
790 } else if ( gl
-> expire
<= curtime
) {
791 gl
-> flags
&= ~ GLINE_ACTIVE
;
794 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
795 if (!( flags
& GLIST_INACTIVE
)) {
800 if ( flags
& GLIST_REALNAME
) {
801 if (!( gl
-> flags
& GLINE_REALNAME
))
803 if ( flags
& GLIST_EXACT
) {
804 if (! glineequal ( searchgl
, gl
))
806 } else if ( flags
& GLIST_FIND
) {
807 if (! gline_match_mask ( gl
, searchgl
))
810 if (! match2strings ( mask
, glinetostring ( gl
)))
814 if ( gl
-> flags
& GLINE_REALNAME
)
817 if ( flags
& GLIST_REASON
) {
818 if ( flags
& GLIST_EXACT
) {
819 if (! gl
-> reason
|| ircd_strcmp ( mask
, gl
-> reason
-> content
) != 0 )
821 } else if ( flags
& GLIST_FIND
) {
822 if (! gl
-> reason
|| ! match2strings ( gl
-> reason
-> content
, mask
))
824 } else if (! gl
-> reason
|| ! match2strings ( mask
, gl
-> reason
-> content
))
826 } else if ( flags
& GLIST_OWNER
) {
827 if ( flags
& GLIST_EXACT
) {
828 if (! gl
-> creator
|| ircd_strcmp ( mask
, gl
-> creator
-> content
) != 0 )
830 } else if ( flags
& GLIST_FIND
) {
831 if (! gl
-> creator
|| ! match2strings ( gl
-> creator
-> content
, mask
))
833 } else if (! gl
-> creator
|| ! match2strings ( mask
, gl
-> creator
-> content
))
836 if ( flags
& GLIST_EXACT
) {
837 if (! glineequal ( searchgl
, gl
))
839 } else if ( flags
& GLIST_FIND
) {
840 if (! gline_match_mask ( gl
, searchgl
))
843 if (! match2strings ( mask
, glinetostring ( gl
)))
849 if ( count
== limit
&& !( flags
& GLIST_COUNT
))
850 controlreply ( sender
, "More than %d matches, list truncated." , limit
);
854 if (!( flags
& GLIST_COUNT
) && count
< limit
) {
855 snprintf ( expirestr
, sizeof ( expirestr
), " %s " , glinetostring ( gl
));
856 snprintf ( idstr
, sizeof ( idstr
), " %d " , gl
-> glinebufid
);
857 controlreply ( sender
, " %s %-49s %-19s %-15s %-25s %s " ,
858 ( gl
-> flags
& GLINE_ACTIVE
) ? "+" : "-" ,
860 ( gl
-> flags
& GLINE_ACTIVE
) ? ( char *) longtoduration ( gl
-> expire
- curtime
, 0 ) : "<inactive>" ,
861 gl
-> glinebufid
? idstr
: "" ,
862 gl
-> creator
? gl
-> creator
-> content
: "" ,
863 gl
-> reason
? gl
-> reason
-> content
: "" );
867 controlreply ( sender
, " %s%d G-Line %s found." , ( flags
& GLIST_COUNT
) ? "" : "End of list - " , count
, count
== 1 ? "" : "s" );
872 static int glines_cmdglinelog ( void * source
, int cargc
, char ** cargv
) {
873 nick
* sender
= source
;
885 controlreply ( sender
, "Invalid log ID." );
890 controlreply ( sender
, "Time ID G-Lines User Hits Channel Hits Comment" );
892 for ( i
= 0 ; i
< MAXGLINELOG
; i
++) {
893 gbl
= glinebuflog
[( i
+ glinebuflogoffset
+ 1 ) % MAXGLINELOG
];
898 if ( id
== 0 || gbl
-> id
== id
) {
901 for ( gl
= gbl
-> glines
; gl
; gl
= gl
-> next
)
904 strftime ( timebuf
, sizeof ( timebuf
), " %d / %m / %y %H : %M : %S " , localtime (( gbl
-> amend
) ? & gbl
-> amend
: & gbl
-> commit
));
905 strncat ( timebuf
, ( gbl
-> amend
) ? "*" : " " , sizeof ( timebuf
));
906 controlreply ( sender
, "%-20s %-10d %-10d %-15d %-15d %s " , timebuf
, gbl
-> id
, count
, gbl
-> userhits
, gbl
-> channelhits
, gbl
-> comment
? gbl
-> comment
-> content
: "(no comment)" );
909 if ( id
!= 0 && gbl
-> id
== id
) {
910 glinebufspew ( gbl
, sender
);
911 controlreply ( sender
, "Done." );
917 controlreply ( sender
, "Done." );
919 controlreply ( sender
, "Log entry for ID %d not found." , id
);
925 static int glines_cmdglineundo ( void * source
, int cargc
, char ** cargv
) {
926 nick
* sender
= source
;
934 if ( id
== 0 || ! glinebufundo ( id
)) {
935 controlreply ( sender
, "Invalid log ID." );
939 controlreply ( sender
, "Done." );
944 static int glines_cmdsyncglines ( void * source
, int cargc
, char ** cargv
) {
945 nick
* sender
= source
;
951 for ( gl
= glinelist
; gl
; gl
= gl
-> next
) {
956 controlwall ( NO_OPER
, NL_GLINES
, " %s SYNCGLINE'd %d G-Lines." ,
957 controlid ( sender
), count
);
959 controlreply ( sender
, "Done." );
964 static int glines_cmdcleanupglines ( void * source
, int cargc
, char ** cargv
) {
965 nick
* sender
= source
;
973 for ( pnext
= & glinelist
; * pnext
;) {
976 /* Remove inactivate glines that have been last changed more than a week ago */
977 if (!( gl
-> flags
& GLINE_ACTIVE
) && gl
-> lastmod
< now
- 7 * 24 * 60 * 60 ) {
978 gline_destroy ( gl
, 0 , 1 );
981 pnext
= &((* pnext
)-> next
);
988 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEANUPGLINES'd %d G-Lines." ,
989 controlid ( sender
), count
);
991 controlreply ( sender
, "Done." );
996 static int commandsregistered
;
998 static void registercommands ( int hooknum
, void * arg
) {
999 if ( commandsregistered
)
1001 commandsregistered
= 1 ;
1003 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" );
1004 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" );
1005 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" );
1006 registercontrolhelpcmd ( "ungline" , NO_OPER
, 1 , glines_cmdungline
, "Usage: ungline <mask> \n Deactivates a gline." );
1007 registercontrolhelpcmd ( "destroygline" , NO_DEVELOPER
, 1 , glines_cmddestroygline
, "Usage: destroygline <mask> \n Destroys a gline." );
1008 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" );
1009 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" );
1010 registercontrolhelpcmd ( "trustungline" , NO_OPER
, 2 , glines_cmdtrustungline
, "Usage: trustungline <#id|name> <user> \n Removes a gline that was previously set with trustgline." );
1011 registercontrolhelpcmd ( "glstats" , NO_OPER
, 0 , glines_cmdglstats
, "Usage: glstat \n Shows statistics about G-Lines." );
1012 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." );
1013 registercontrolhelpcmd ( "glinelog" , NO_OPER
, 1 , glines_cmdglinelog
, "Usage: glinelog ?id? \n Shows information about previous gline transactions." );
1014 registercontrolhelpcmd ( "glineundo" , NO_OPER
, 1 , glines_cmdglineundo
, "Usage: glineundo ?id? \n Undoes a gline transaction." );
1015 registercontrolhelpcmd ( "syncglines" , NO_DEVELOPER
, 0 , glines_cmdsyncglines
, "Usage: syncglines \n Sends all G-Lines to all other servers." );
1016 registercontrolhelpcmd ( "cleanupglines" , NO_DEVELOPER
, 0 , glines_cmdcleanupglines
, "Usage: cleanupglines \n Destroys all deactivated G-Lines." );
1019 static void deregistercommands ( int hooknum
, void * arg
) {
1020 if (! commandsregistered
)
1022 commandsregistered
= 0 ;
1024 deregistercontrolcmd ( "block" , glines_cmdblock
);
1025 deregistercontrolcmd ( "gline" , glines_cmdgline
);
1026 deregistercontrolcmd ( "smartgline" , glines_cmdsmartgline
);
1027 deregistercontrolcmd ( "ungline" , glines_cmdungline
);
1028 deregistercontrolcmd ( "destroygline" , glines_cmddestroygline
);
1029 deregistercontrolcmd ( "clearchan" , glines_cmdclearchan
);
1030 deregistercontrolcmd ( "trustgline" , glines_cmdtrustgline
);
1031 deregistercontrolcmd ( "trustungline" , glines_cmdtrustungline
);
1032 deregistercontrolcmd ( "glstats" , glines_cmdglstats
);
1033 deregistercontrolcmd ( "glist" , glines_cmdglist
);
1034 deregistercontrolcmd ( "glinelog" , glines_cmdglinelog
);
1035 deregistercontrolcmd ( "glineundo" , glines_cmdglineundo
);
1036 deregistercontrolcmd ( "syncglines" , glines_cmdsyncglines
);
1037 deregistercontrolcmd ( "cleanupglines" , glines_cmdcleanupglines
);
1041 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1042 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1045 registercommands ( 0 , NULL
);
1049 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1050 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1052 deregistercommands ( 0 , NULL
);