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

@ -106,7 +106,7 @@ def win_msg(astr):
global win global win
if os.isatty(1): if os.isatty(1):
print('\n' + colorize(_("Success: "), 'green') + astr + '\n') print('\n' + colorize(_("Success: "), 'green') + astr + '\n')
win.append(astr) win.append(astr)
@ -277,18 +277,22 @@ class YunoHostLDAP(Singleton):
elif self.pwd: elif self.pwd:
pass pass
else: else:
need_password = True try:
while need_password: with open('/etc/yunohost/passwd') as f:
try: self.pwd = f.read()
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow')) except IOError:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) need_password = True
except KeyboardInterrupt, EOFError: while need_password:
raise YunoHostError(125, _("Interrupted")) try:
except ldap.INVALID_CREDENTIALS: self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
print(_('Invalid password... Try again')) self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
else: except KeyboardInterrupt, EOFError:
need_password = False raise YunoHostError(125, _("Interrupted"))
except ldap.INVALID_CREDENTIALS:
print(_('Invalid password... Try again'))
else:
need_password = False
try: try:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
self.connected = True self.connected = True

View file

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