-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkconfig.py
133 lines (103 loc) · 4.71 KB
/
checkconfig.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import znc
class checkconfig(znc.Module):
module_types = [znc.CModInfo.GlobalModule]
description = "Checks that a module is loaded for a user"
def check_network(self, network):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
net = user[1].FindNetwork(network)
if not net:
self.PutModule("AddNetwork " + user[0] + " " + network)
count += 1
self.PutModule("Network check complete for network " + network +
" (" + str(count) + " missing)")
def check_chan(self, network, channel):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
net = user[1].FindNetwork(network)
if net:
chan = net.FindChan(channel)
if not chan:
self.PutModule("AddChan " + user[0] + " " +
network + " " + channel)
count += 1
self.PutModule("Channel check complete for channel " + channel +
" in network " + network +
" (" + str(count) + " missing)")
def check_user_module(self, module):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
loaded_user_mods = []
for mod in user[1].GetModules():
loaded_user_mods.append(mod.GetModName())
if module not in loaded_user_mods:
self.PutModule("LoadModule " + user[0] + " " + module)
count += 1
self.PutModule("User module check complete for module " +
module + " (" + str(count) + " missing)")
def uncheck_user_module(self, module):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
loaded_user_mods = []
for mod in user[1].GetModules():
loaded_user_mods.append(mod.GetModName())
if module in loaded_user_mods:
self.PutModule("UnLoadModule " + user[0] + " " + module)
count += 1
self.PutModule("User module check complete for module " +
module + " (" + str(count) + " loaded)")
def check_network_module(self, network, module):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
net = user[1].FindNetwork(network)
if net:
loaded_net_mods = []
for mod in net.GetModules():
loaded_net_mods.append(mod.GetModName())
if module not in loaded_net_mods:
self.PutModule("LoadNetModule " + user[0] +
" " + network + " " + module)
count += 1
self.PutModule("Network module check complete for module " + module +
" in network " + network +
" (" + str(count) + " missing)")
def uncheck_network_module(self, network, module):
users = znc.CZNC.Get().GetUserMap()
count = 0
for user in users.items():
net = user[1].FindNetwork(network)
if net:
loaded_net_mods = []
for mod in net.GetModules():
loaded_net_mods.append(mod.GetModName())
if module in loaded_net_mods:
self.PutModule("UnLoadNetModule " + user[0] +
" " + network + " " + module)
count += 1
self.PutModule("Network module check complete for module " + module +
" in network " + network +
" (" + str(count) + " loaded)")
def OnModCommand(self, command):
if self.GetUser().IsAdmin():
if command.split()[0] == "checknetwork":
self.check_network(command.split()[1])
elif command.split()[0] == "checkchan":
self.check_chan(command.split()[1],
command.split()[2])
elif command.split()[0] == "checkusermod":
self.check_user_module(command.split()[1])
elif command.split()[0] == "checknetmod":
self.check_network_module(command.split()[1],
command.split()[2])
elif command.split()[0] == "unchecknetmod":
self.uncheck_network_module(command.split()[1],
command.split()[2])
elif command.split()[0] == "uncheckmod":
self.uncheck_user_module(command.split()[1])
else:
self.PutModule("Access denied.")