comparison src/plugins/plugin_misc_account.py @ 948:abd3a75d629c

plugin account: prosody gid is used to spawn prosodyctl process
author Goffi <goffi@goffi.org>
date Mon, 31 Mar 2014 12:23:10 +0200
parents fc7e0828b18e
children 5925c9ebfcd2
comparison
equal deleted inserted replaced
947:61c4755f0394 948:abd3a75d629c
62 pass 62 pass
63 63
64 64
65 class ProsodyRegisterProtocol(protocol.ProcessProtocol): 65 class ProsodyRegisterProtocol(protocol.ProcessProtocol):
66 """ Try to register an account with prosody """ 66 """ Try to register an account with prosody """
67 prosody_gid = None
67 68
68 def __init__(self, password=None, deferred=None): 69 def __init__(self, password=None, deferred=None):
69 """ 70 """
70 @param password: new user password 71 @param password: new user password
71 @param deferred 72 @param deferred
72 """ 73 """
73 self.password = password 74 self.password = password
74 self.deferred = deferred 75 self.deferred = deferred
75 self.data = '' 76 self.data = ''
77 if ProsodyRegisterProtocol.prosody_gid is None:
78 try:
79 import grp
80 ProsodyRegisterProtocol.prosody_gid = grp.getgrnam("prosody").gr_gid
81 info("prosody gid found: %s" % ProsodyRegisterProtocol.prosody_gid)
82 except:
83 warning("Can't find prosody gid")
84
76 85
77 def connectionMade(self): 86 def connectionMade(self):
78 if self.password is None: 87 if self.password is None:
79 return 88 return
80 self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),) * 2)) 89 self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),) * 2))
105 """ 114 """
106 d = defer.Deferred() 115 d = defer.Deferred()
107 prosody_reg = ProsodyRegisterProtocol(password, d) 116 prosody_reg = ProsodyRegisterProtocol(password, d)
108 prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl')) 117 prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl'))
109 # TODO delete account which are not on the same host 118 # TODO delete account which are not on the same host
110 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, command, "%s@%s" % (profile, plugin.getConfig('new_account_domain'))], path=plugin._prosody_path) 119 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, command, "%s@%s" % (profile, plugin.getConfig('new_account_domain'))], path=plugin._prosody_path, gid=ProsodyRegisterProtocol.prosody_gid)
111 return d 120 return d
112 121
113 122
114 class MiscAccount(object): 123 class MiscAccount(object):
115 """Account plugin: create a SàT + Prosody account, used by Libervia""" 124 """Account plugin: create a SàT + Prosody account, used by Libervia"""