-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
151 lines (126 loc) · 5.12 KB
/
password.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8
#
# The MIT License (MIT)
#
# Copyright (c) 2016 betriebsrat
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# password.py
# This module allows you to dynamically generate mumble server passwords
#
import re
import uuid
from threading import Timer
from mumo_module import MumoModule, commaSeperatedBool, commaSeperatedIntegers
class password(MumoModule):
default_config = {'password': (
('servers', commaSeperatedIntegers, []),
),
lambda x: re.match('(all)|(server_\d+)', x): (
('welcometext', str, 'Welcome to Mumble'),
('genpassword', str, '!pass'),
('delpassword', str, '!clearpass'),
('interval', int, 1800),
)
}
def __init__(self, name, manager, configuration=None):
MumoModule.__init__(self, name, manager, configuration)
self.murmur = manager.getMurmurModule()
self.watchdog = None
def sendMessage(self, server, user, message, msg):
server.sendMessage(user.session, msg)
def cleartoken(self):
cfg = self.cfg()
log = self.log()
try:
meta = self.manager().getMeta()
if not cfg.password.servers:
servers = meta.getBootedServers()
else:
servers = [meta.getServer(server)
for server in cfg.password.servers]
for server in servers:
if not server:
continue
if server:
try:
scfg = getattr(self.cfg(), 'server_%d' %
int(server.id()))
except AttributeError:
scfg = self.cfg().all
server.setConf("password", uuid.uuid4().hex[:24])
server.setConf("welcometext", cfg.all.welcometext)
log.debug("Serverpassword cleared after 30minutes.")
except:
pass
def connected(self):
manager = self.manager()
log = self.log()
cfg = self.cfg()
log.debug("Register for Server callbacks")
servers = self.cfg().password.servers
if not servers:
servers = manager.SERVERS_ALL
manager.subscribeServerCallbacks(self, servers)
if not self.watchdog:
self.watchdog = Timer(cfg.all.interval, self.cleartoken)
self.watchdog.start()
def disconnected(self):
if self.watchdog:
self.watchdog.stop()
self.watchdog = None
# --- Server callback functions
#
def userTextMessage(self, server, user, message, current=None):
log = self.log()
cfg = self.cfg()
try:
scfg = getattr(self.cfg(), 'server_%d' % server.id())
except AttributeError:
scfg = self.cfg().all
# Only allow registered Users to use command
if user.userid > 0:
if message.text.startswith(scfg.delpassword):
msg = "Password cleared"
self.sendMessage(server, user, message, msg)
self.cleartoken()
if message.text.startswith(scfg.genpassword):
token = uuid.uuid4().hex[:12]
server.setConf("password", token)
server.setConf("welcometext",
cfg.all.welcometext + ", the current server password is: \"%s\" , it will expire in 30 minutes.\n Generated by %s" % (token, user.name))
log.debug("A new serverpassword got generated by %s" %
user.name)
# refresh timer
self.watchdog = Timer(scfg.interval, self.cleartoken)
self.watchdog.start()
def userConnected(self, server, state, context=None):
pass
def userDisconnected(self, server, state, context=None):
pass
def userStateChanged(self, server, state, context=None):
pass
def channelCreated(self, server, state, context=None):
pass
def channelRemoved(self, server, state, context=None):
pass
def channelStateChanged(self, server, state, context=None):
pass