mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Modify no-ldap option
This commit is contained in:
parent
15f85746cd
commit
2c93b811c7
2 changed files with 35 additions and 25 deletions
12
yunohost
12
yunohost
|
@ -64,7 +64,7 @@ def main():
|
||||||
|
|
||||||
admin_password_provided = False
|
admin_password_provided = False
|
||||||
json_print = False
|
json_print = False
|
||||||
no_ldap = False
|
write_ldap = True
|
||||||
|
|
||||||
for key, arg in enumerate(sys.argv):
|
for key, arg in enumerate(sys.argv):
|
||||||
if arg == '--admin-password':
|
if arg == '--admin-password':
|
||||||
|
@ -72,11 +72,9 @@ def main():
|
||||||
admin_password = sys.argv[key+1]
|
admin_password = sys.argv[key+1]
|
||||||
sys.argv.pop(key)
|
sys.argv.pop(key)
|
||||||
sys.argv.pop(key)
|
sys.argv.pop(key)
|
||||||
|
|
||||||
if arg == '--no-ldap':
|
if arg == '--no-ldap':
|
||||||
no_ldap = True
|
write_ldap = False
|
||||||
sys.argv.pop(key)
|
sys.argv.pop(key)
|
||||||
|
|
||||||
if arg == '--json':
|
if arg == '--json':
|
||||||
json_print = True
|
json_print = True
|
||||||
sys.argv.pop(key)
|
sys.argv.pop(key)
|
||||||
|
@ -104,7 +102,8 @@ def main():
|
||||||
if admin_password_provided:
|
if admin_password_provided:
|
||||||
with YunoHostLDAP(password=admin_password):
|
with YunoHostLDAP(password=admin_password):
|
||||||
result = args.func(**args_dict)
|
result = args.func(**args_dict)
|
||||||
elif os.isatty(1) and not no_ldap:
|
elif os.isatty(1) and write_ldap:
|
||||||
|
print('meh')
|
||||||
admin_password = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
|
admin_password = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
|
||||||
with YunoHostLDAP(password=admin_password):
|
with YunoHostLDAP(password=admin_password):
|
||||||
try:
|
try:
|
||||||
|
@ -125,7 +124,8 @@ def main():
|
||||||
os.remove('/etc/yunohost/passwd')
|
os.remove('/etc/yunohost/passwd')
|
||||||
os.remove('/var/run/yunohost.pid')
|
os.remove('/var/run/yunohost.pid')
|
||||||
else:
|
else:
|
||||||
result = args.func(**args_dict)
|
with YunoHostLDAP(anonymous=True):
|
||||||
|
result = args.func(**args_dict)
|
||||||
#except TypeError, error:
|
#except TypeError, error:
|
||||||
#if not __debug__ :
|
#if not __debug__ :
|
||||||
#traceback.print_exc()
|
#traceback.print_exc()
|
||||||
|
|
48
yunohost.py
48
yunohost.py
|
@ -251,6 +251,7 @@ class Singleton(object):
|
||||||
class YunoHostLDAP(Singleton):
|
class YunoHostLDAP(Singleton):
|
||||||
""" Specific LDAP functions for YunoHost """
|
""" Specific LDAP functions for YunoHost """
|
||||||
pwd = False
|
pwd = False
|
||||||
|
connected = False
|
||||||
conn = ldap.initialize('ldap://localhost:389')
|
conn = ldap.initialize('ldap://localhost:389')
|
||||||
base = 'dc=yunohost,dc=org'
|
base = 'dc=yunohost,dc=org'
|
||||||
level = 0
|
level = 0
|
||||||
|
@ -258,33 +259,42 @@ class YunoHostLDAP(Singleton):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __init__(self, password=False):
|
def __init__(self, password=False, anonymous=False):
|
||||||
"""
|
"""
|
||||||
Connect to LDAP base
|
Connect to LDAP base
|
||||||
|
|
||||||
Initialize to localhost, base yunohost.org, prompt for password
|
Initialize to localhost, base yunohost.org, prompt for password
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if password: self.pwd = password
|
if anonymous:
|
||||||
elif self.pwd: pass
|
self.conn.simple_bind_s()
|
||||||
|
self.connected = True
|
||||||
|
elif self.connected:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
need_password = True
|
if password:
|
||||||
while need_password:
|
self.pwd = password
|
||||||
try:
|
elif self.pwd:
|
||||||
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
|
pass
|
||||||
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
|
else:
|
||||||
except KeyboardInterrupt, EOFError:
|
need_password = True
|
||||||
raise YunoHostError(125, _("Interrupted"))
|
while need_password:
|
||||||
except ldap.INVALID_CREDENTIALS:
|
try:
|
||||||
print(_('Invalid password... Try again'))
|
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
|
||||||
else:
|
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
|
||||||
need_password = False
|
except KeyboardInterrupt, EOFError:
|
||||||
|
raise YunoHostError(125, _("Interrupted"))
|
||||||
|
except ldap.INVALID_CREDENTIALS:
|
||||||
|
print(_('Invalid password... Try again'))
|
||||||
|
else:
|
||||||
|
need_password = False
|
||||||
|
|
||||||
self.level = self.level+1
|
self.level = self.level+1
|
||||||
try:
|
try:
|
||||||
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
|
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
|
||||||
except ldap.INVALID_CREDENTIALS:
|
self.connected = True
|
||||||
raise YunoHostError(13, _('Invalid credentials'))
|
except ldap.INVALID_CREDENTIALS:
|
||||||
|
raise YunoHostError(13, _('Invalid credentials'))
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
self.level = self.level-1
|
self.level = self.level-1
|
||||||
|
|
Loading…
Add table
Reference in a new issue