fix postinstall

This commit is contained in:
Kload 2013-11-20 23:40:20 +01:00
parent c16c9160b3
commit 8ca9f69691
2 changed files with 33 additions and 30 deletions

View file

@ -277,17 +277,21 @@ class YunoHostLDAP(Singleton):
elif self.pwd:
pass
else:
need_password = True
while need_password:
try:
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
except ldap.INVALID_CREDENTIALS:
print(_('Invalid password... Try again'))
else:
need_password = False
try:
with open('/etc/yunohost/passwd') as f:
self.pwd = f.read()
except IOError:
need_password = True
while need_password:
try:
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
except ldap.INVALID_CREDENTIALS:
print(_('Invalid password... Try again'))
else:
need_password = False
try:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)

View file

@ -112,24 +112,23 @@ def http_exec(request, **kwargs):
raise YunoHostError(168, _('Function not yet implemented : ') + dict['function'].split('.')[1])
# Execute requested function
with YunoHostLDAP(password=request.getPassword()):
try:
with open('/var/run/yunohost.pid', 'r'):
raise YunoHostError(1, _("A YunoHost command is already running"))
except IOError:
with open('/var/run/yunohost.pid', 'w') as f:
f.write('ldap')
os.system('chmod 400 /var/run/yunohost.pid')
with open('/etc/yunohost/passwd', 'w') as f:
f.write(request.getPassword())
os.system('chmod 400 /etc/yunohost/passwd')
try:
with open('/var/run/yunohost.pid', 'r'):
raise YunoHostError(1, _("A YunoHost command is already running"))
except IOError:
with open('/var/run/yunohost.pid', 'w') as f:
f.write('ldap')
os.system('chmod 400 /var/run/yunohost.pid')
with open('/etc/yunohost/passwd', 'w') as f:
f.write(request.getPassword())
os.system('chmod 400 /etc/yunohost/passwd')
try:
result = func(**validated_args)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
finally:
os.remove('/etc/yunohost/passwd')
os.remove('/var/run/yunohost.pid')
result = func(**validated_args)
except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted"))
finally:
os.remove('/etc/yunohost/passwd')
os.remove('/var/run/yunohost.pid')
if result is None:
result = {}
if len(yunohost.win) > 0: