mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
messages, add arguments, prompt
This commit is contained in:
parent
daa28fdf4b
commit
e527bf71f6
3 changed files with 56 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
||||||
import sys
|
import sys
|
||||||
import ldap
|
import ldap
|
||||||
import getpass
|
import getpass
|
||||||
|
import yunohost_messages as msg
|
||||||
|
|
||||||
class YunoHostLDAP:
|
class YunoHostLDAP:
|
||||||
""" Specific LDAP functions for YunoHost """
|
""" Specific LDAP functions for YunoHost """
|
||||||
|
@ -12,11 +13,11 @@ 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()
|
self.pwd = getpass.getpass(_('LDAP Admin Password: '))
|
||||||
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:
|
||||||
print(_('Error: Wrong credentials'))
|
print(msg.error + _('Wrong credentials'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
@ -30,9 +31,12 @@ class YunoHostLDAP:
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def search(self, base, filter='(objectClass=*)', attrs=['dn']):
|
def search(self, base=None, filter='(objectClass=*)', attrs=['dn']):
|
||||||
""" Search in LDAP base """
|
""" Search in LDAP base """
|
||||||
|
|
||||||
|
if not base:
|
||||||
|
base = self.base
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = self.conn.search_s(base, ldap.SCOPE_ONELEVEL, filter, attrs)
|
result = self.conn.search_s(base, ldap.SCOPE_ONELEVEL, filter, attrs)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -1,12 +1,38 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
import ldap
|
import ldap
|
||||||
import ldap.modlist as modlist
|
import ldap.modlist as modlist
|
||||||
import yunohost_ldap
|
import yunohost_ldap
|
||||||
|
import yunohost_messages as msg
|
||||||
|
import getpass
|
||||||
|
|
||||||
# Initialize LDAP
|
# Initialize LDAP
|
||||||
yldap = yunohost_ldap.YunoHostLDAP()
|
yldap = yunohost_ldap.YunoHostLDAP()
|
||||||
|
|
||||||
def user_list(args):
|
def user_list(args): # TODO : fix
|
||||||
result = yldap.search('ou=users,dc=gavoty,dc=org', attrs=['mail', 'dn', 'cn'])
|
result = yldap.search()
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
|
def user_add(args):
|
||||||
|
required_args = ['username', 'mail', 'firstname', 'lastname']
|
||||||
|
|
||||||
|
try:
|
||||||
|
for arg in required_args:
|
||||||
|
if not args[arg]:
|
||||||
|
args[arg] = raw_input(arg.capitalize()+': ')
|
||||||
|
|
||||||
|
if not args['password']:
|
||||||
|
args['password'] = getpass.getpass()
|
||||||
|
pwd2 = getpass.getpass('Retype password:')
|
||||||
|
if args['password'] != pwd2:
|
||||||
|
print(msg.error + _("Passwords doesn't match"))
|
||||||
|
sys.exit(1)
|
||||||
|
except KeyboardInterrupt, EOFError:
|
||||||
|
print("\n" + msg.interrupt + _("User not created"))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
print(args)
|
||||||
|
|
||||||
|
|
30
yunohost
30
yunohost
|
@ -25,7 +25,7 @@ import argparse
|
||||||
import gettext
|
import gettext
|
||||||
sys.path.append('lib') # Local temporary hack
|
sys.path.append('lib') # Local temporary hack
|
||||||
gettext.install('YunoHost')
|
gettext.install('YunoHost')
|
||||||
|
import yunohost_messages as msg
|
||||||
|
|
||||||
def str_to_func(astr):
|
def str_to_func(astr):
|
||||||
"""
|
"""
|
||||||
|
@ -48,7 +48,7 @@ def str_to_func(astr):
|
||||||
try:
|
try:
|
||||||
func = getattr(mod, function)
|
func = getattr(mod, function)
|
||||||
except NameError:
|
except NameError:
|
||||||
print(_('Error: Function is not defined'))
|
print(msg.error + _('Function is not defined'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
return func
|
return func
|
||||||
|
@ -110,14 +110,25 @@ def parse_args(parsers):
|
||||||
version='%(prog)s ' + __version__
|
version='%(prog)s ' + __version__
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# User #
|
||||||
|
#####################
|
||||||
|
|
||||||
# User
|
# user list
|
||||||
parsers['user_list'].add_argument(
|
parsers['user_list'].add_argument(
|
||||||
'-a',
|
'-a',
|
||||||
'--all',
|
'--all',
|
||||||
action='store'
|
action='store'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# user add
|
||||||
|
parsers['user_add'].add_argument('-u', '--username')
|
||||||
|
parsers['user_add'].add_argument('-m', '--mail')
|
||||||
|
parsers['user_add'].add_argument('-f', '--firstname')
|
||||||
|
parsers['user_add'].add_argument('-l', '--lastname')
|
||||||
|
parsers['user_add'].add_argument('-p', '--password')
|
||||||
|
|
||||||
|
|
||||||
# Call arguments parsing
|
# Call arguments parsing
|
||||||
args = parsers['general'].parse_args()
|
args = parsers['general'].parse_args()
|
||||||
|
|
||||||
|
@ -130,25 +141,26 @@ def main():
|
||||||
|
|
||||||
action_dict = {
|
action_dict = {
|
||||||
'user' : {
|
'user' : {
|
||||||
'help' : 'manage users',
|
'help' : 'Manage users',
|
||||||
'actions' : {
|
'actions' : {
|
||||||
'list' : 'list users'
|
'list' : 'List users',
|
||||||
|
'add' : 'Add user'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'domain' : {
|
'domain' : {
|
||||||
'help' : 'manage domains',
|
'help' : 'Manage domains',
|
||||||
'actions' : {}
|
'actions' : {}
|
||||||
},
|
},
|
||||||
'app' : {
|
'app' : {
|
||||||
'help' : 'manage apps',
|
'help' : 'Manage apps',
|
||||||
'actions' : {}
|
'actions' : {}
|
||||||
},
|
},
|
||||||
'monitor' : {
|
'monitor' : {
|
||||||
'help' : 'monitoring functions',
|
'help' : 'Monitoring functions',
|
||||||
'actions' : {}
|
'actions' : {}
|
||||||
},
|
},
|
||||||
'tools' : {
|
'tools' : {
|
||||||
'help' : 'specific tools',
|
'help' : 'Specific tools',
|
||||||
'actions' : {}
|
'actions' : {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue