mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Rename files
This commit is contained in:
parent
45fcc5bed8
commit
c5edde0053
3 changed files with 30 additions and 19 deletions
|
@ -31,7 +31,6 @@ if not __debug__:
|
||||||
gettext.install('YunoHost')
|
gettext.install('YunoHost')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sys.path.append('lib')
|
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict
|
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict
|
||||||
except ImportError:
|
except ImportError:
|
||||||
sys.stderr.write('Require YunoHost lib')
|
sys.stderr.write('Require YunoHost lib')
|
||||||
|
@ -342,6 +341,18 @@ def parse_dict(action_dict):
|
||||||
args = parsers['general'].parse_args()
|
args = parsers['general'].parse_args()
|
||||||
return { 'ldap' : ldap, 'args' : args }
|
return { 'ldap' : ldap, 'args' : args }
|
||||||
|
|
||||||
|
def display_error(error):
|
||||||
|
"""
|
||||||
|
Nice error displaying
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not __debug__ :
|
||||||
|
traceback.print_exc()
|
||||||
|
if os.isatty(1):
|
||||||
|
print('\n' + colorize(_("Error: "), 'red') + error.message)
|
||||||
|
else:
|
||||||
|
print(json.dumps({ 'error' : error.message }))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
Main instructions
|
Main instructions
|
||||||
|
@ -355,25 +366,24 @@ def main():
|
||||||
"""
|
"""
|
||||||
action = parse_dict(action_dict)
|
action = parse_dict(action_dict)
|
||||||
|
|
||||||
# Connect to LDAP if the action is requiring it
|
try:
|
||||||
if action['ldap']:
|
# Connect to LDAP if the action is requiring it
|
||||||
yldap = YunoHostLDAP()
|
if action['ldap']:
|
||||||
|
yldap = YunoHostLDAP()
|
||||||
|
except YunoHostError, error:
|
||||||
|
display_error(error)
|
||||||
|
return error.code
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if action['ldap']:
|
if action['ldap']:
|
||||||
result = action['args'].func(vars(action['args']), yldap)
|
result = action['args'].func(vars(action['args']), yldap)
|
||||||
else:
|
else:
|
||||||
result = action['args'].func(vars(action['args']))
|
result = action['args'].func(vars(action['args']))
|
||||||
#except TypeError:
|
except TypeError:
|
||||||
#print(_("Not (yet) implemented function"))
|
print(_("Not (yet) implemented function"))
|
||||||
#return 1
|
return 1
|
||||||
except YunoHostError, error:
|
except YunoHostError, error:
|
||||||
if not __debug__ :
|
display_error(error)
|
||||||
traceback.print_exc()
|
|
||||||
if os.isatty(1):
|
|
||||||
print('\n' + colorize(_("Error: "), 'red') + error.message)
|
|
||||||
else:
|
|
||||||
print(json.dumps({ 'error' : error.message }))
|
|
||||||
return error.code
|
return error.code
|
||||||
else:
|
else:
|
||||||
if os.isatty(1):
|
if os.isatty(1):
|
|
@ -6,7 +6,6 @@ import ldap
|
||||||
import ldap.modlist as modlist
|
import ldap.modlist as modlist
|
||||||
import re
|
import re
|
||||||
import getpass
|
import getpass
|
||||||
sys.path.append('./') # Local temporary hack
|
|
||||||
|
|
||||||
|
|
||||||
def colorize(astr, color):
|
def colorize(astr, color):
|
||||||
|
@ -141,7 +140,7 @@ class YunoHostLDAP:
|
||||||
"""
|
"""
|
||||||
self.conn = ldap.initialize('ldap://localhost:389')
|
self.conn = ldap.initialize('ldap://localhost:389')
|
||||||
self.base = 'dc=yunohost,dc=org'
|
self.base = 'dc=yunohost,dc=org'
|
||||||
self.pwd = getpass.getpass(_('LDAP Admin Password: '))
|
self.pwd = getpass.getpass(colorize(_('LDAP Admin Password: '), 'yellow'))
|
||||||
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:
|
except ldap.INVALID_CREDENTIALS:
|
|
@ -32,14 +32,14 @@ def user_create(args, yldap):
|
||||||
for arg in required_args:
|
for arg in required_args:
|
||||||
if not args[arg]:
|
if not args[arg]:
|
||||||
if os.isatty(1):
|
if os.isatty(1):
|
||||||
args[arg] = raw_input(colorize(arg.capitalize()+': ', 'yellow'))
|
args[arg] = raw_input(colorize(arg.capitalize()+': ', 'cyan'))
|
||||||
else:
|
else:
|
||||||
raise Exception
|
raise Exception
|
||||||
# Password
|
# Password
|
||||||
if not args['password']:
|
if not args['password']:
|
||||||
if os.isatty(1):
|
if os.isatty(1):
|
||||||
args['password'] = getpass.getpass(colorize('Password: ', 'yellow'))
|
args['password'] = getpass.getpass(colorize('Password: ', 'cyan'))
|
||||||
pwd2 = getpass.getpass(colorize('Retype password:', 'yellow'))
|
pwd2 = getpass.getpass(colorize('Retype password:', 'cyan'))
|
||||||
if args['password'] != pwd2:
|
if args['password'] != pwd2:
|
||||||
raise YunoHostError(22, _("Passwords doesn't match"))
|
raise YunoHostError(22, _("Passwords doesn't match"))
|
||||||
else:
|
else:
|
||||||
|
@ -78,8 +78,10 @@ def user_create(args, yldap):
|
||||||
'mailalias' : args['mail']
|
'mailalias' : args['mail']
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#TODO: check if mail belongs to a domain
|
||||||
|
|
||||||
if yldap.add(rdn, attr_dict):
|
if yldap.add(rdn, attr_dict):
|
||||||
win_msg(_("User successfully created"))
|
win_msg(_("User successfully created"))
|
||||||
return attr_dict
|
return { _("Fullname") : fullname, _("Username") : args['username'], _("Mail") : args['mail'] }
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(169, _('An error occured during user creation'))
|
raise YunoHostError(169, _('An error occured during user creation'))
|
Loading…
Reference in a new issue