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 ldap
|
||||
import getpass
|
||||
import yunohost_messages as msg
|
||||
|
||||
class YunoHostLDAP:
|
||||
""" Specific LDAP functions for YunoHost """
|
||||
|
@ -12,11 +13,11 @@ class YunoHostLDAP:
|
|||
|
||||
self.conn = ldap.initialize('ldap://localhost:389')
|
||||
self.base = 'dc=yunohost,dc=org'
|
||||
self.pwd = getpass.getpass()
|
||||
self.pwd = getpass.getpass(_('LDAP Admin Password: '))
|
||||
try:
|
||||
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
|
||||
except ldap.INVALID_CREDENTIALS:
|
||||
print(_('Error: Wrong credentials'))
|
||||
print(msg.error + _('Wrong credentials'))
|
||||
sys.exit(1)
|
||||
|
||||
def disconnect(self):
|
||||
|
@ -30,9 +31,12 @@ class YunoHostLDAP:
|
|||
else:
|
||||
return True
|
||||
|
||||
def search(self, base, filter='(objectClass=*)', attrs=['dn']):
|
||||
def search(self, base=None, filter='(objectClass=*)', attrs=['dn']):
|
||||
""" Search in LDAP base """
|
||||
|
||||
if not base:
|
||||
base = self.base
|
||||
|
||||
try:
|
||||
result = self.conn.search_s(base, ldap.SCOPE_ONELEVEL, filter, attrs)
|
||||
except Exception:
|
||||
|
|
|
@ -1,12 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import ldap
|
||||
import ldap.modlist as modlist
|
||||
import yunohost_ldap
|
||||
import yunohost_messages as msg
|
||||
import getpass
|
||||
|
||||
# Initialize LDAP
|
||||
yldap = yunohost_ldap.YunoHostLDAP()
|
||||
|
||||
def user_list(args):
|
||||
result = yldap.search('ou=users,dc=gavoty,dc=org', attrs=['mail', 'dn', 'cn'])
|
||||
def user_list(args): # TODO : fix
|
||||
result = yldap.search()
|
||||
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
|
||||
sys.path.append('lib') # Local temporary hack
|
||||
gettext.install('YunoHost')
|
||||
|
||||
import yunohost_messages as msg
|
||||
|
||||
def str_to_func(astr):
|
||||
"""
|
||||
|
@ -48,7 +48,7 @@ def str_to_func(astr):
|
|||
try:
|
||||
func = getattr(mod, function)
|
||||
except NameError:
|
||||
print(_('Error: Function is not defined'))
|
||||
print(msg.error + _('Function is not defined'))
|
||||
sys.exit(1)
|
||||
else:
|
||||
return func
|
||||
|
@ -110,14 +110,25 @@ def parse_args(parsers):
|
|||
version='%(prog)s ' + __version__
|
||||
)
|
||||
|
||||
#####################
|
||||
# User #
|
||||
#####################
|
||||
|
||||
# User
|
||||
# user list
|
||||
parsers['user_list'].add_argument(
|
||||
'-a',
|
||||
'--all',
|
||||
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
|
||||
args = parsers['general'].parse_args()
|
||||
|
||||
|
@ -130,25 +141,26 @@ def main():
|
|||
|
||||
action_dict = {
|
||||
'user' : {
|
||||
'help' : 'manage users',
|
||||
'help' : 'Manage users',
|
||||
'actions' : {
|
||||
'list' : 'list users'
|
||||
'list' : 'List users',
|
||||
'add' : 'Add user'
|
||||
}
|
||||
},
|
||||
'domain' : {
|
||||
'help' : 'manage domains',
|
||||
'help' : 'Manage domains',
|
||||
'actions' : {}
|
||||
},
|
||||
'app' : {
|
||||
'help' : 'manage apps',
|
||||
'help' : 'Manage apps',
|
||||
'actions' : {}
|
||||
},
|
||||
'monitor' : {
|
||||
'help' : 'monitoring functions',
|
||||
'help' : 'Monitoring functions',
|
||||
'actions' : {}
|
||||
},
|
||||
'tools' : {
|
||||
'help' : 'specific tools',
|
||||
'help' : 'Specific tools',
|
||||
'actions' : {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue