]>
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 * coff
) {
29 if ( flagparam
[ 0 ] == '-' ) {
32 for ( pos
= flagparam
+ 1 ; * pos
; pos
++) {
44 controlreply ( sender
, "Invalid flag specified: %c " , * pos
);
53 static int glines_cmdblock ( void * source
, int cargc
, char ** cargv
) {
54 nick
* sender
= source
;
56 int hits
, duration
, id
;
57 int coff
, overridesanity
, overridelimit
, simulate
;
65 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & coff
))
71 target
= getnickbynick ( cargv
[ coff
]);
74 controlreply ( sender
, "Sorry, couldn't find that user." );
78 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
81 controlreply ( sender
, "Invalid duration specified." );
85 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
86 reason
= cargv
[ coff
+ 2 ];
89 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
91 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
93 glinebufinit (& gbuf
, 0 );
94 glinebufcommentv (& gbuf
, "BLOCK" , cargc
+ coff
- 1 , cargv
);
95 glinebufaddbynick (& gbuf
, target
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
97 glinebufspew (& gbuf
, sender
);
99 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
100 glinebufabort (& gbuf
);
101 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
106 glinebufabort (& gbuf
);
107 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
111 glinebufcounthits (& gbuf
, & hits
, NULL
);
112 id
= glinebufcommit (& gbuf
, 1 );
114 controlwall ( NO_OPER
, NL_GLINES
, " %s BLOCK'ed user ' %s ! %s @ %s ' for %s with reason ' %s ' ( %d hits)" , controlid ( sender
), target
-> nick
, target
-> ident
, target
-> host
-> name
-> content
, longtoduration ( duration
, 0 ), reason
, hits
);
116 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
121 static int glines_cmdgline ( void * source
, int cargc
, char ** cargv
) {
122 nick
* sender
= source
;
123 int duration
, users
, channels
, id
;
126 int coff
, overridesanity
, overridelimit
, simulate
;
128 #if SNIRCD_VERSION < 140
130 #endif /* SNIRCD_VERSION */
135 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & coff
))
138 if ( cargc
< 3 + coff
)
143 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
146 controlreply ( sender
, "Invalid duration specified." );
150 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
151 reason
= cargv
[ coff
+ 2 ];
153 #if SNIRCD_VERSION < 140
154 gl
= findgline ( mask
);
157 /* warn opers that they can't modify this gline */
158 if ( gl
-> flags
& GLINE_ACTIVE
) {
159 controlreply ( sender
, "Active G-Line already exists on %s - unable to modify" , mask
);
163 controlreply ( sender
, "Reactivating existing gline on %s " , mask
);
165 #endif /* SNIRCD_VERSION */
168 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
170 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
172 glinebufinit (& gbuf
, 0 );
173 glinebufcommentv (& gbuf
, "GLINE" , cargc
+ coff
- 1 , cargv
);
175 if (! glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
)) {
176 controlreply ( sender
, "Invalid G-Line mask." );
180 glinebufspew (& gbuf
, sender
);
182 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
183 glinebufabort (& gbuf
);
184 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
189 glinebufabort (& gbuf
);
190 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
194 glinebufcounthits (& gbuf
, & users
, & channels
);
195 id
= glinebufcommit (& gbuf
, 1 );
197 controlwall ( NO_OPER
, NL_GLINES
, " %s GLINE'd mask ' %s ' for %s with reason ' %s ' (hits %d users/ %d channels)" ,
198 controlid ( sender
), mask
, longtoduration ( duration
, 0 ), reason
, users
, channels
);
200 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
205 static int glines_cmdsmartgline ( void * source
, int cargc
, char ** cargv
) {
206 nick
* sender
= source
;
209 char * p
, * user
, * host
;
210 struct irc_in_addr ip
;
213 int coff
, overridesanity
, overridelimit
, simulate
, id
;
221 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & coff
))
224 if ( cargc
< 3 + coff
)
227 origmask
= cargv
[ coff
];
229 if ( origmask
[ 0 ] == '#' || origmask
[ 0 ] == '&' || origmask
[ 0 ] == '$' ) {
230 controlreply ( sender
, "Please use \" gline \" for badchan or realname glines." );
234 duration
= durationtolong ( cargv
[ coff
+ 1 ]);
237 controlreply ( sender
, "Invalid duration specified." );
241 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
242 reason
= cargv
[ coff
+ 2 ];
244 strncpy ( mask
, origmask
, sizeof ( mask
));
246 if ( strchr ( mask
, '!' )) {
247 controlreply ( sender
, "Use \" gline \" to place nick glines." );
251 p
= strchr ( mask
, '@' );
254 controlreply ( sender
, "Mask must contain a username (e.g. user@ip)." );
262 if ( strchr ( user
, '*' ) || strchr ( user
, '?' )) {
263 controlreply ( sender
, "Usernames may not contain wildcards." );
267 if (! ipmask_parse ( host
, & ip
, & bits
)) {
268 controlreply ( sender
, "Invalid CIDR mask." );
273 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
275 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
277 glinebufinit (& gbuf
, 0 );
278 glinebufcommentv (& gbuf
, "SMARTGLINE" , cargc
+ coff
- 1 , cargv
);
279 glinebufaddbyip (& gbuf
, user
, & ip
, 128 , 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
281 glinebufspew (& gbuf
, sender
);
283 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
284 glinebufabort (& gbuf
);
285 controlreply ( sender
, "G-Lines failed sanity checks. Not setting G-Lines." );
290 glinebufabort (& gbuf
);
291 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
295 glinebufcounthits (& gbuf
, & hits
, NULL
);
296 id
= glinebufcommit (& gbuf
, 1 );
298 controlwall ( NO_OPER
, NL_GLINES
, " %s SMARTGLINE'd mask ' %s ' for %s with reason ' %s ' ( %d hits)" ,
299 controlid ( sender
), cargv
[ 0 ], longtoduration ( duration
, 0 ), reason
, hits
);
301 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
306 static int glines_cmdungline ( void * source
, int cargc
, char ** cargv
) {
307 nick
* sender
= source
;
313 gl
= findgline ( cargv
[ 0 ]);
316 controlreply ( sender
, "No such G-Line." );
320 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
321 controlreply ( sender
, "G-Line was already deactivated." );
325 gline_deactivate ( gl
, 0 , 1 );
327 controlwall ( NO_OPER
, NL_GLINES
, " %s UNGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
329 controlreply ( sender
, "G-Line deactivated." );
334 static int glines_cmddestroygline ( void * source
, int cargc
, char ** cargv
) {
335 nick
* sender
= source
;
341 gl
= findgline ( cargv
[ 0 ]);
344 controlreply ( sender
, "No such G-Line." );
348 gline_destroy ( gl
, 0 , 1 );
350 controlwall ( NO_OPER
, NL_GLINES
, " %s DESTROYGLINE'd mask ' %s '" , controlid ( sender
), cargv
[ 0 ]);
352 controlreply ( sender
, "G-Line destroyed." );
357 static int glines_cmdclearchan ( void * source
, int cargc
, char ** cargv
) {
358 nick
* sender
= source
;
361 char * reason
= "Clearing channel." ;
362 int mode
, duration
, i
, slot
, hits
, id
;
363 int coff
, overridesanity
, overridelimit
, simulate
;
371 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & coff
))
374 if ( cargc
< 2 + coff
)
377 cp
= findchannel ( cargv
[ coff
]);
380 controlreply ( sender
, "Couldn't find that channel." );
384 if ( strcmp ( cargv
[ coff
+ 1 ], "kick" ) == 0 )
386 else if ( strcmp ( cargv
[ coff
+ 1 ], "kill" ) == 0 )
388 else if ( strcmp ( cargv
[ coff
+ 1 ], "gline" ) == 0 )
390 else if ( strcmp ( cargv
[ coff
+ 1 ], "glineall" ) == 0 )
395 if ( mode
== 0 || mode
== 1 ) {
397 rejoinline ( cargv
[ coff
+ 2 ], cargc
- coff
- 2 );
398 reason
= cargv
[ coff
+ 2 ];
401 if ( cargc
< 3 + coff
)
404 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
407 controlreply ( sender
, "Invalid duration specified." );
411 if ( cargc
>= 4 + coff
) {
412 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
413 reason
= cargv
[ coff
+ 3 ];
417 array_init (& victims
, sizeof ( nick
*));
419 /* we need to make a list of the channel users here because
420 * kicking/killing them will affect their position in the channel's
422 for ( i
= 0 ; i
< cp
-> users
-> hashsize
; i
++) {
423 if ( cp
-> users
-> content
[ i
] == nouser
)
426 np
= getnickbynumeric ( cp
-> users
-> content
[ i
]);
431 if ( IsService ( np
) || IsOper ( np
) || NickOnServiceServer ( np
))
434 slot
= array_getfreeslot (& victims
);
435 ((( nick
**) victims
. content
)[ slot
]) = np
;
439 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
441 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
443 glinebufinit (& gbuf
, 0 );
444 glinebufcommentv (& gbuf
, "CLEARCHAN" , cargc
+ coff
- 1 , cargv
);
446 for ( i
= 0 ; i
< victims
. cursi
; i
++) {
447 np
= (( nick
**) victims
. content
)[ i
];
452 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
454 localkickuser ( NULL
, cp
, np
, reason
);
459 controlreply ( sender
, "user: %s ! %s @ %s r( %s )" , np
-> nick
, np
-> ident
, np
-> host
-> name
-> content
, np
-> realname
-> name
-> content
);
461 killuser ( NULL
, np
, " %s " , reason
);
469 glinebufaddbynick (& gbuf
, np
, 0 , creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
476 if ( mode
!= 0 && mode
!= 1 ) {
477 glinebufspew (& gbuf
, sender
);
479 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
480 glinebufabort (& gbuf
);
481 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
487 glinebufabort (& gbuf
);
488 controlreply ( sender
, "Simulation complete. Not clearing channel." );
492 glinebufmerge (& gbuf
);
493 glinebufcounthits (& gbuf
, & hits
, NULL
);
494 id
= glinebufcommit (& gbuf
, 1 );
496 array_free (& victims
);
498 if ( mode
== 0 || mode
== 1 ) {
499 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ' and reason ' %s '" ,
500 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], reason
);
501 controlreply ( sender
, "Done." );
503 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEARCHAN'd channel ' %s ' with mode ' %s ', duration %s and reason ' %s ' ( %d hits)" ,
504 controlid ( sender
), cp
-> index
-> name
-> content
, cargv
[ 1 ], longtoduration ( duration
, 0 ), reason
, hits
);
505 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
511 static int glines_cmdtrustgline ( void * source
, int cargc
, char ** cargv
) {
512 nick
* sender
= source
;
516 int coff
, overridesanity
, overridelimit
, simulate
, id
;
525 if (! parse_gline_flags ( sender
, cargv
[ 0 ], & overridesanity
, & overridelimit
, & simulate
, & coff
))
528 if ( cargc
< 4 + coff
)
531 tg
= tg_strtotg ( cargv
[ coff
]);
533 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
534 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
538 duration
= durationtolong ( cargv
[ coff
+ 2 ]);
541 controlreply ( sender
, "Invalid duration specified." );
545 rejoinline ( cargv
[ coff
+ 3 ], cargc
- coff
- 3 );
546 reason
= cargv
[ coff
+ 3 ];
549 snprintf ( creator
, sizeof ( creator
), "# %s " , sender
-> authname
);
551 strncpy ( creator
, controlid ( sender
), sizeof ( creator
));
553 glinebufinit (& gbuf
, 0 );
554 glinebufcommentv (& gbuf
, "TRUSTGLINE" , cargc
+ coff
- 1 , cargv
);
556 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
557 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], trusts_cidr2str (& th
-> ip
, th
-> bits
));
558 glinebufadd (& gbuf
, mask
, creator
, reason
, getnettime () + duration
, getnettime (), getnettime () + duration
);
561 glinebufspew (& gbuf
, sender
);
563 if (! glinebufchecksane (& gbuf
, sender
, overridesanity
, overridelimit
)) {
564 glinebufabort (& gbuf
);
565 controlreply ( sender
, "G-Line failed sanity checks. Not setting G-Line." );
570 glinebufabort (& gbuf
);
571 controlreply ( sender
, "Simulation complete. Not setting G-Lines." );
575 glinebufcounthits (& gbuf
, & hits
, NULL
);
576 id
= glinebufcommit (& gbuf
, 1 );
578 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTGLINE'd user ' %s ' on trust group ' %s ' for %s with reason ' %s ' ( %d hits)" ,
579 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, longtoduration ( duration
, 0 ), reason
, hits
);
581 controlreply ( sender
, "Done. G-Line transaction ID: %d " , id
);
586 static int glines_cmdtrustungline ( void * source
, int cargc
, char ** cargv
) {
587 nick
* sender
= source
;
597 tg
= tg_strtotg ( cargv
[ 0 ]);
599 if (!( tg
-> flags
& TRUST_RELIABLE_USERNAME
)) {
600 controlreply ( sender
, "Sorry, that trust group does not have the \" reliable username \" flag." );
606 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
607 snprintf ( mask
, sizeof ( mask
), "*! %s @ %s " , cargv
[ 1 ], trusts_cidr2str (& th
-> ip
, th
-> bits
));
609 gl
= findgline ( mask
);
611 if ( gl
&& ( gl
-> flags
& GLINE_ACTIVE
)) {
612 gline_deactivate ( gl
, 0 , 1 );
617 controlwall ( NO_OPER
, NL_GLINES
, " %s TRUSTUNGLINE'd user ' %s ' on trust group ' %s ' ( %d G-Lines deactivated)" ,
618 controlid ( sender
), cargv
[ 1 ], tg
-> name
-> content
, count
);
620 controlreply ( sender
, "Done." );
625 static int glines_cmdglstats ( void * source
, int cargc
, char ** cargv
) {
626 nick
* sender
= ( nick
*) source
;
628 time_t curtime
= getnettime ();
629 int glinecount
= 0 , hostglinecount
= 0 , ipglinecount
= 0 , badchancount
= 0 , rnglinecount
= 0 ;
630 int deactivecount
= 0 , activecount
= 0 ;
632 for ( gl
= glinelist
; gl
; gl
= next
) {
635 if ( gl
-> lifetime
<= curtime
) {
638 } else if ( gl
-> expire
<= curtime
) {
639 gl
-> flags
&= ~ GLINE_ACTIVE
;
642 if ( gl
-> flags
& GLINE_ACTIVE
) {
648 if ( gl
-> flags
& GLINE_IPMASK
)
650 else if ( gl
-> flags
& GLINE_HOSTMASK
)
652 else if ( gl
-> flags
& GLINE_REALNAME
)
654 else if ( gl
-> flags
& GLINE_BADCHAN
)
659 controlreply ( sender
, "Total G-Lines set: %d " , glinecount
);
660 controlreply ( sender
, "Hostmask G-Lines: %d " , hostglinecount
);
661 controlreply ( sender
, "IPMask G-Lines: %d " , ipglinecount
);
662 controlreply ( sender
, "Channel G-Lines: %d " , badchancount
);
663 controlreply ( sender
, "Realname G-Lines: %d " , rnglinecount
);
665 controlreply ( sender
, "Active G-Lines: %d " , activecount
);
666 controlreply ( sender
, "Inactive G-Lines: %d " , deactivecount
);
668 /* TODO show top 10 creators here */
669 /* TODO show unique creators count */
670 /* TODO show glines per create %8.1f", ccount?((float)gcount/(float)ccount):0 */
674 static int glines_cmdglist ( void * source
, int cargc
, char ** cargv
) {
675 nick
* sender
= ( nick
*) source
;
677 time_t curtime
= time ( NULL
);
682 char expirestr
[ 250 ], idstr
[ 250 ];
684 if ( cargc
< 1 || ( cargc
== 1 && cargv
[ 0 ][ 0 ] == '-' )) {
685 controlreply ( sender
, "Syntax: glist [-flags] <mask>" );
686 controlreply ( sender
, "Valid flags are:" );
687 controlreply ( sender
, "-c: Count G-Lines." );
688 controlreply ( sender
, "-f: Find G-Lines active on <mask>." );
689 controlreply ( sender
, "-x: Find G-Lines matching <mask> exactly." );
690 controlreply ( sender
, "-R: Find G-lines on realnames." );
691 controlreply ( sender
, "-o: Search for glines by owner." );
692 controlreply ( sender
, "-r: Search for glines by reason." );
693 controlreply ( sender
, "-i: Include inactive glines." );
708 flags
|= GLIST_COUNT
;
716 flags
|= GLIST_EXACT
;
720 flags
|= GLIST_REASON
;
723 flags
|= GLIST_OWNER
;
727 flags
|= GLIST_REALNAME
;
731 flags
|= GLIST_INACTIVE
;
735 controlreply ( sender
, "Invalid flag ' %c '." , * ch
);
744 if (( flags
& ( GLIST_EXACT
| GLIST_FIND
)) == ( GLIST_EXACT
| GLIST_FIND
)) {
745 controlreply ( sender
, "You cannot use -x and -f flags together." );
749 if (!( flags
& GLIST_COUNT
))
750 controlreply ( sender
, "%-50s %-19s %-15s %-25s %s " , "Mask:" , "Expires in:" , "Transaction ID:" , "Creator:" , "Reason:" );
752 gline
* searchgl
= makegline ( mask
);
754 for ( gl
= glinelist
; gl
; gl
= next
) {
757 if ( gl
-> lifetime
<= curtime
) {
760 } else if ( gl
-> expire
<= curtime
) {
761 gl
-> flags
&= ~ GLINE_ACTIVE
;
764 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
765 if (!( flags
& GLIST_INACTIVE
)) {
770 if ( flags
& GLIST_REALNAME
) {
771 if (!( gl
-> flags
& GLINE_REALNAME
))
773 if ( flags
& GLIST_EXACT
) {
774 if (! glineequal ( searchgl
, gl
)) {
777 } else if ( flags
& GLIST_FIND
) {
778 if (! gline_match_mask ( searchgl
, gl
)) {
783 if ( gl
-> flags
& GLINE_REALNAME
)
786 if ( flags
& GLIST_REASON
) {
787 if ( flags
& GLIST_EXACT
) {
788 if (! gl
-> reason
|| ircd_strcmp ( mask
, gl
-> reason
-> content
) != 0 )
790 } else if ( flags
& GLIST_FIND
) {
791 if (! gl
-> reason
|| match ( gl
-> reason
-> content
, mask
))
793 } else if (! gl
-> reason
|| match ( mask
, gl
-> reason
-> content
))
795 } else if ( flags
& GLIST_OWNER
) {
796 if ( flags
& GLIST_EXACT
) {
797 if (! gl
-> creator
|| ircd_strcmp ( mask
, gl
-> creator
-> content
) != 0 )
799 } else if ( flags
& GLIST_FIND
) {
800 if (! gl
-> creator
|| match ( gl
-> creator
-> content
, mask
))
802 } else if (! gl
-> creator
|| match ( mask
, gl
-> creator
-> content
))
805 if ( flags
& GLIST_EXACT
) {
806 if (! glineequal ( searchgl
, gl
)) {
809 } else if ( flags
& GLIST_FIND
) {
810 if (! gline_match_mask ( searchgl
, gl
)) {
817 if ( count
== limit
&& !( flags
& GLIST_COUNT
))
818 controlreply ( sender
, "More than %d matches, list truncated." , limit
);
822 if (!( flags
& GLIST_COUNT
) && count
< limit
) {
823 snprintf ( expirestr
, sizeof ( expirestr
), " %s " , glinetostring ( gl
));
824 snprintf ( idstr
, sizeof ( idstr
), " %d " , gl
-> glinebufid
);
825 controlreply ( sender
, " %s %-49s %-19s %-15s %-25s %s " ,
826 ( gl
-> flags
& GLINE_ACTIVE
) ? "+" : "-" ,
828 ( gl
-> flags
& GLINE_ACTIVE
) ? ( char *) longtoduration ( gl
-> expire
- curtime
, 0 ) : "<inactive>" ,
829 gl
-> glinebufid
? idstr
: "" ,
830 gl
-> creator
? gl
-> creator
-> content
: "" ,
831 gl
-> reason
? gl
-> reason
-> content
: "" );
835 controlreply ( sender
, " %s%d G-Line %s found." , ( flags
& GLIST_COUNT
) ? "" : "End of list - " , count
, count
== 1 ? "" : "s" );
840 static int glines_cmdglinelog ( void * source
, int cargc
, char ** cargv
) {
841 nick
* sender
= source
;
853 controlreply ( sender
, "Invalid log ID." );
858 controlreply ( sender
, "Time ID G-Lines User Hits Channel Hits Comment" );
860 for ( i
= 0 ; i
< MAXGLINELOG
; i
++) {
861 gbl
= glinebuflog
[( i
+ glinebuflogoffset
+ 1 ) % MAXGLINELOG
];
866 if ( id
== 0 || gbl
-> id
== id
) {
869 for ( gl
= gbl
-> glines
; gl
; gl
= gl
-> next
)
872 strftime ( timebuf
, sizeof ( timebuf
), " %d / %m / %y %H : %M : %S " , localtime (( gbl
-> amend
) ? & gbl
-> amend
: & gbl
-> commit
));
873 strncat ( timebuf
, ( gbl
-> amend
) ? "*" : " " , sizeof ( timebuf
));
874 controlreply ( sender
, "%-20s %-10d %-10d %-15d %-15d %s " , timebuf
, gbl
-> id
, count
, gbl
-> userhits
, gbl
-> channelhits
, gbl
-> comment
? gbl
-> comment
-> content
: "(no comment)" );
877 if ( id
!= 0 && gbl
-> id
== id
) {
878 glinebufspew ( gbl
, sender
);
879 controlreply ( sender
, "Done." );
885 controlreply ( sender
, "Done." );
887 controlreply ( sender
, "Log entry for ID %d not found." , id
);
893 static int glines_cmdglineundo ( void * source
, int cargc
, char ** cargv
) {
894 nick
* sender
= source
;
902 if ( id
== 0 || ! glinebufundo ( id
)) {
903 controlreply ( sender
, "Invalid log ID." );
907 controlreply ( sender
, "Done." );
912 static int glines_cmdsyncglines ( void * source
, int cargc
, char ** cargv
) {
913 nick
* sender
= source
;
919 for ( gl
= glinelist
; gl
; gl
= gl
-> next
) {
924 controlwall ( NO_OPER
, NL_GLINES
, " %s SYNCGLINE'd %d G-Lines." ,
925 controlid ( sender
), count
);
927 controlreply ( sender
, "Done." );
932 static int glines_cmdcleanupglines ( void * source
, int cargc
, char ** cargv
) {
933 nick
* sender
= source
;
941 for ( pnext
= & glinelist
; * pnext
;) {
944 /* Remove inactivate glines that have been last changed more than a week ago */
945 if (!( gl
-> flags
& GLINE_ACTIVE
) && gl
-> lastmod
< now
- 7 * 24 * 60 * 60 ) {
946 gline_destroy ( gl
, 0 , 1 );
949 pnext
= &((* pnext
)-> next
);
956 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEANUPGLINES'd %d G-Lines." ,
957 controlid ( sender
), count
);
959 controlreply ( sender
, "Done." );
964 static int commandsregistered
;
966 static void registercommands ( int hooknum
, void * arg
) {
967 if ( commandsregistered
)
969 commandsregistered
= 1 ;
971 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" );
972 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" );
973 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" );
974 registercontrolhelpcmd ( "ungline" , NO_OPER
, 1 , glines_cmdungline
, "Usage: ungline <mask> \n Deactivates a gline." );
975 registercontrolhelpcmd ( "destroygline" , NO_DEVELOPER
, 1 , glines_cmddestroygline
, "Usage: destroygline <mask> \n Destroys a gline." );
976 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" );
977 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" );
978 registercontrolhelpcmd ( "trustungline" , NO_OPER
, 2 , glines_cmdtrustungline
, "Usage: trustungline <#id|name> <user> \n Removes a gline that was previously set with trustgline." );
979 registercontrolhelpcmd ( "glstats" , NO_OPER
, 0 , glines_cmdglstats
, "Usage: glstat \n Shows statistics about G-Lines." );
980 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." );
981 registercontrolhelpcmd ( "glinelog" , NO_OPER
, 1 , glines_cmdglinelog
, "Usage: glinelog ?id? \n Shows information about previous gline transactions." );
982 registercontrolhelpcmd ( "glineundo" , NO_OPER
, 1 , glines_cmdglineundo
, "Usage: glineundo ?id? \n Undoes a gline transaction." );
983 registercontrolhelpcmd ( "syncglines" , NO_DEVELOPER
, 0 , glines_cmdsyncglines
, "Usage: syncglines \n Sends all G-Lines to all other servers." );
984 registercontrolhelpcmd ( "cleanupglines" , NO_DEVELOPER
, 0 , glines_cmdcleanupglines
, "Usage: cleanupglines \n Destroys all deactivated G-Lines." );
987 static void deregistercommands ( int hooknum
, void * arg
) {
988 if (! commandsregistered
)
990 commandsregistered
= 0 ;
992 deregistercontrolcmd ( "block" , glines_cmdblock
);
993 deregistercontrolcmd ( "gline" , glines_cmdgline
);
994 deregistercontrolcmd ( "smartgline" , glines_cmdsmartgline
);
995 deregistercontrolcmd ( "ungline" , glines_cmdungline
);
996 deregistercontrolcmd ( "destroygline" , glines_cmddestroygline
);
997 deregistercontrolcmd ( "clearchan" , glines_cmdclearchan
);
998 deregistercontrolcmd ( "trustgline" , glines_cmdtrustgline
);
999 deregistercontrolcmd ( "trustungline" , glines_cmdtrustungline
);
1000 deregistercontrolcmd ( "glstats" , glines_cmdglstats
);
1001 deregistercontrolcmd ( "glist" , glines_cmdglist
);
1002 deregistercontrolcmd ( "glinelog" , glines_cmdglinelog
);
1003 deregistercontrolcmd ( "glineundo" , glines_cmdglineundo
);
1004 deregistercontrolcmd ( "syncglines" , glines_cmdsyncglines
);
1005 deregistercontrolcmd ( "cleanupglines" , glines_cmdcleanupglines
);
1009 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1010 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1013 registercommands ( 0 , NULL
);
1017 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1018 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1020 deregistercommands ( 0 , NULL
);