-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrant.pm
110 lines (79 loc) · 2.53 KB
/
grant.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl
# Copyright (c) 2011, Mitchell Cooper
# adds GRANT command.
# parameters: <nick> <priv> [<priv>] [...]
# adds UNGRANT command.
# parameters: <nick> <priv> [<priv>] [...]
# adds PRIVS command.
# parameters: <nick>
# all three of these commands require the 'grant' oper flag.
# this module requires 1.0.6 and above
package module::grant;
use warnings;
use strict;
use API::Module;
use API::Command;
use utils 'snotice';
# register the module to API::Module
register_module('grant', 0.7, 'Easily manage your oper flags.', \&init, sub { return 1 });
sub init {
# register commands
register_command('grant', 'Grant oper privs to a user.', \&handle_grant, {
params => 2,
flag => 'grant'
}) or return;
register_command('ungrant', 'Remove oper privs from a user.', \&handle_ungrant, {
params => 2,
flag => 'grant'
}) or return;
register_command('privs', 'View a user\'s oper flags.', \&handle_privs, {
params => 1,
flag => 'grant'
}) or return;
return 1
}
sub handle_grant {
my ($user, @args) = (shift, (split /\s+/, shift));
# check for existing nick
my $target = user::nickexists($args[1]);
if (!$target) {
$user->numeric(401, $args[1]);
return
}
# add the privs
my @privs = @args[2..$#args];
$target->add_privs(@privs);
# success
snotice("$$user{nick} granted privs on $$target{nick}: ".(join q. ., @privs));
$user->snt('grant', $target->nick.' now has privs: '.(scalar @{$target->{privs}} ? join q. ., @{$target->{privs}} : '(none)'));
return 1
}
sub handle_ungrant {
my ($user, @args) = (shift, (split /\s+/, shift));
# check for existing nick
my $target = user::nickexists($args[1]);
if (!$target) {
$user->numeric(401, $args[1]);
return
}
# add the privs
my @privs = @args[2..$#args];
$target->del_privs(@privs);
# success
snotice("$$user{nick} ungranted privs from $$target{nick}: ".(join q. ., @privs));
$user->snt('ungrant', $target->nick.' now has privs: '.(scalar @{$target->{privs}} ? join q. ., @{$target->{privs}} : '(none)'));
return 1
}
sub handle_privs {
my ($user, @args) = (shift, (split /\s+/, shift));
# check for existing nick
my $target = user::nickexists($args[1]);
if (!$target) {
$user->numeric(401, $args[1]);
return
}
$user->snt('privs', $target->nick.' has privs: '.(scalar @{$target->{privs}} ? join q. ., @{$target->{privs}} : '(none)'));
# success
return 1
}
1