]>
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." );
706 flags
|= GLIST_COUNT
;
714 flags
|= GLIST_EXACT
;
718 flags
|= GLIST_REASON
;
721 flags
|= GLIST_OWNER
;
725 flags
|= GLIST_REALNAME
;
729 flags
|= GLIST_INACTIVE
;
733 controlreply ( sender
, "Invalid flag ' %c '." , * ch
);
742 if (( flags
& ( GLIST_EXACT
| GLIST_FIND
)) == ( GLIST_EXACT
| GLIST_FIND
)) {
743 controlreply ( sender
, "You cannot use -x and -f flags together." );
747 if (!( flags
& GLIST_COUNT
))
748 controlreply ( sender
, "%-50s %-19s %-15s %-25s %s " , "Mask:" , "Expires in:" , "Transaction ID:" , "Creator:" , "Reason:" );
750 gline
* searchgl
= makegline ( mask
);
752 for ( gl
= glinelist
; gl
; gl
= next
) {
755 if ( gl
-> lifetime
<= curtime
) {
758 } else if ( gl
-> expire
<= curtime
) {
759 gl
-> flags
&= ~ GLINE_ACTIVE
;
762 if (!( gl
-> flags
& GLINE_ACTIVE
)) {
763 if (!( flags
& GLIST_INACTIVE
)) {
768 if ( flags
& GLIST_REALNAME
) {
769 if (!( gl
-> flags
& GLINE_REALNAME
))
771 if ( flags
& GLIST_EXACT
) {
772 if (! glineequal ( searchgl
, gl
)) {
775 } else if ( flags
& GLIST_FIND
) {
776 if (! gline_match_mask ( searchgl
, gl
)) {
781 if ( gl
-> flags
& GLINE_REALNAME
)
784 if ( flags
& GLIST_REASON
) {
785 if ( flags
& GLIST_EXACT
) {
786 if (! gl
-> reason
|| ircd_strcmp ( mask
, gl
-> reason
-> content
) != 0 )
788 } else if ( flags
& GLIST_FIND
) {
789 if (! gl
-> reason
|| match ( gl
-> reason
-> content
, mask
))
791 } else if (! gl
-> reason
|| match ( mask
, gl
-> reason
-> content
))
793 } else if ( flags
& GLIST_OWNER
) {
794 if ( flags
& GLIST_EXACT
) {
795 if (! gl
-> creator
|| ircd_strcmp ( mask
, gl
-> creator
-> content
) != 0 )
797 } else if ( flags
& GLIST_FIND
) {
798 if (! gl
-> creator
|| match ( gl
-> creator
-> content
, mask
))
800 } else if (! gl
-> creator
|| match ( mask
, gl
-> creator
-> content
))
803 if ( flags
& GLIST_EXACT
) {
804 if (! glineequal ( searchgl
, gl
)) {
807 } else if ( flags
& GLIST_FIND
) {
808 if (! gline_match_mask ( searchgl
, gl
)) {
815 if ( count
== limit
&& !( flags
& GLIST_COUNT
))
816 controlreply ( sender
, "More than %d matches, list truncated." , limit
);
820 if (!( flags
& GLIST_COUNT
) && count
< limit
) {
821 snprintf ( expirestr
, sizeof ( expirestr
), " %s " , glinetostring ( gl
));
822 snprintf ( idstr
, sizeof ( idstr
), " %d " , gl
-> glinebufid
);
823 controlreply ( sender
, " %s %-49s %-19s %-15s %-25s %s " ,
824 ( gl
-> flags
& GLINE_ACTIVE
) ? "+" : "-" ,
826 ( gl
-> flags
& GLINE_ACTIVE
) ? ( char *) longtoduration ( gl
-> expire
- curtime
, 0 ) : "<inactive>" ,
827 gl
-> glinebufid
? idstr
: "" ,
828 gl
-> creator
? gl
-> creator
-> content
: "" ,
829 gl
-> reason
? gl
-> reason
-> content
: "" );
833 controlreply ( sender
, " %s%d G-Line %s found." , ( flags
& GLIST_COUNT
) ? "" : "End of list - " , count
, count
== 1 ? "" : "s" );
838 static int glines_cmdglinelog ( void * source
, int cargc
, char ** cargv
) {
839 nick
* sender
= source
;
851 controlreply ( sender
, "Invalid log ID." );
856 controlreply ( sender
, "Time ID G-Lines User Hits Channel Hits Comment" );
858 for ( i
= 0 ; i
< MAXGLINELOG
; i
++) {
859 gbl
= glinebuflog
[( i
+ glinebuflogoffset
+ 1 ) % MAXGLINELOG
];
864 if ( id
== 0 || gbl
-> id
== id
) {
867 for ( gl
= gbl
-> glines
; gl
; gl
= gl
-> next
)
870 strftime ( timebuf
, sizeof ( timebuf
), " %d / %m / %y %H : %M : %S " , localtime (( gbl
-> amend
) ? & gbl
-> amend
: & gbl
-> commit
));
871 strncat ( timebuf
, ( gbl
-> amend
) ? "*" : " " , sizeof ( timebuf
));
872 controlreply ( sender
, "%-20s %-10d %-10d %-15d %-15d %s " , timebuf
, gbl
-> id
, count
, gbl
-> userhits
, gbl
-> channelhits
, gbl
-> comment
? gbl
-> comment
-> content
: "(no comment)" );
875 if ( id
!= 0 && gbl
-> id
== id
) {
876 glinebufspew ( gbl
, sender
);
877 controlreply ( sender
, "Done." );
883 controlreply ( sender
, "Done." );
885 controlreply ( sender
, "Log entry for ID %d not found." , id
);
891 static int glines_cmdglineundo ( void * source
, int cargc
, char ** cargv
) {
892 nick
* sender
= source
;
900 if ( id
== 0 || ! glinebufundo ( id
)) {
901 controlreply ( sender
, "Invalid log ID." );
905 controlreply ( sender
, "Done." );
910 static int glines_cmdsyncglines ( void * source
, int cargc
, char ** cargv
) {
911 nick
* sender
= source
;
917 for ( gl
= glinelist
; gl
; gl
= gl
-> next
) {
922 controlwall ( NO_OPER
, NL_GLINES
, " %s SYNCGLINE'd %d G-Lines." ,
923 controlid ( sender
), count
);
925 controlreply ( sender
, "Done." );
930 static int glines_cmdcleanupglines ( void * source
, int cargc
, char ** cargv
) {
931 nick
* sender
= source
;
939 for ( pnext
= & glinelist
; * pnext
;) {
942 /* Remove inactivate glines that have been last changed more than a week ago */
943 if (!( gl
-> flags
& GLINE_ACTIVE
) && gl
-> lastmod
< now
- 7 * 24 * 60 * 60 ) {
944 gline_destroy ( gl
, 0 , 1 );
947 pnext
= &((* pnext
)-> next
);
954 controlwall ( NO_OPER
, NL_GLINES
, " %s CLEANUPGLINES'd %d G-Lines." ,
955 controlid ( sender
), count
);
957 controlreply ( sender
, "Done." );
962 static int commandsregistered
;
964 static void registercommands ( int hooknum
, void * arg
) {
965 if ( commandsregistered
)
967 commandsregistered
= 1 ;
969 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" );
970 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" );
971 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" );
972 registercontrolhelpcmd ( "ungline" , NO_OPER
, 1 , glines_cmdungline
, "Usage: ungline <mask> \n Deactivates a gline." );
973 registercontrolhelpcmd ( "destroygline" , NO_DEVELOPER
, 1 , glines_cmddestroygline
, "Usage: destroygline <mask> \n Destroys a gline." );
974 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" );
975 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" );
976 registercontrolhelpcmd ( "trustungline" , NO_OPER
, 2 , glines_cmdtrustungline
, "Usage: trustungline <#id|name> <user> \n Removes a gline that was previously set with trustgline." );
977 registercontrolhelpcmd ( "glstats" , NO_OPER
, 0 , glines_cmdglstats
, "Usage: glstat \n Shows statistics about G-Lines." );
978 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." );
979 registercontrolhelpcmd ( "glinelog" , NO_OPER
, 1 , glines_cmdglinelog
, "Usage: glinelog ?id? \n Shows information about previous gline transactions." );
980 registercontrolhelpcmd ( "glineundo" , NO_OPER
, 1 , glines_cmdglineundo
, "Usage: glineundo ?id? \n Undoes a gline transaction." );
981 registercontrolhelpcmd ( "syncglines" , NO_DEVELOPER
, 0 , glines_cmdsyncglines
, "Usage: syncglines \n Sends all G-Lines to all other servers." );
982 registercontrolhelpcmd ( "cleanupglines" , NO_DEVELOPER
, 0 , glines_cmdcleanupglines
, "Usage: cleanupglines \n Destroys all deactivated G-Lines." );
985 static void deregistercommands ( int hooknum
, void * arg
) {
986 if (! commandsregistered
)
988 commandsregistered
= 0 ;
990 deregistercontrolcmd ( "block" , glines_cmdblock
);
991 deregistercontrolcmd ( "gline" , glines_cmdgline
);
992 deregistercontrolcmd ( "smartgline" , glines_cmdsmartgline
);
993 deregistercontrolcmd ( "ungline" , glines_cmdungline
);
994 deregistercontrolcmd ( "destroygline" , glines_cmddestroygline
);
995 deregistercontrolcmd ( "clearchan" , glines_cmdclearchan
);
996 deregistercontrolcmd ( "trustgline" , glines_cmdtrustgline
);
997 deregistercontrolcmd ( "trustungline" , glines_cmdtrustungline
);
998 deregistercontrolcmd ( "glstats" , glines_cmdglstats
);
999 deregistercontrolcmd ( "glist" , glines_cmdglist
);
1000 deregistercontrolcmd ( "glinelog" , glines_cmdglinelog
);
1001 deregistercontrolcmd ( "glineundo" , glines_cmdglineundo
);
1002 deregistercontrolcmd ( "syncglines" , glines_cmdsyncglines
);
1003 deregistercontrolcmd ( "cleanupglines" , glines_cmdcleanupglines
);
1007 registerhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1008 registerhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1011 registercommands ( 0 , NULL
);
1015 deregisterhook ( HOOK_TRUSTS_DB_LOADED
, registercommands
);
1016 deregisterhook ( HOOK_TRUSTS_DB_CLOSED
, deregistercommands
);
1018 deregistercommands ( 0 , NULL
);