bug fixes & improvments

This commit is contained in:
Kload 2012-12-01 15:33:56 +01:00
parent 7d3a25108d
commit cda0099808
3 changed files with 203 additions and 195 deletions

View file

@ -28,7 +28,7 @@
# Don't forget to turn argument yaml style (setting: value) # Don't forget to turn argument yaml style (setting: value)
# #
########################################################################## ##########################################################################
############################# #############################
# General args # # General args #
############################# #############################
@ -38,60 +38,60 @@ general_arguments:
help: Display YunoHost version help: Display YunoHost version
action: version action: version
version: YunoHost 2.0 beta1 version: YunoHost 2.0 beta1
############################# #############################
# User # # User #
############################# #############################
user: user:
category_help: Manage users category_help: Manage users
actions: actions:
### user_list() ### user_list()
list: list:
action_help: List users action_help: List users
arguments: arguments:
--fields: --fields:
help: fields to fetch help: fields to fetch
nargs: "+" nargs: "+"
-f: -f:
full: --filter full: --filter
help: LDAP filter used to search help: LDAP filter used to search
-l: -l:
full: --limit full: --limit
help: Maximum number of user fetched help: Maximum number of user fetched
-o: -o:
full: --offset full: --offset
help: Starting number for user fetching help: Starting number for user fetching
### user_create() ### user_create()
create: create:
action_help: Create user action_help: Create user
arguments: arguments:
-u: -u:
full: --username full: --username
help: Must be unique help: Must be unique
ask: "Username" ask: "Username"
pattern: '^[a-z0-9_]+$' pattern: '^[a-z0-9_]+$'
-f: -f:
full: --firstname full: --firstname
ask: "Firstname" ask: "Firstname"
-l: -l:
full: --lastname full: --lastname
ask: "Lastname" ask: "Lastname"
-m: -m:
full: --mail full: --mail
help: Main mail address must be unique help: Main mail address must be unique
ask: "Mail address" ask: "Mail address"
pattern: '^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$' pattern: '^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$'
-p: -p:
full: --password full: --password
ask: "User password" ask: "User password"
password: yes password: yes
### user_delete() ### user_delete()
delete: delete:
action_help: Delete user action_help: Delete user
arguments: arguments:
-u: -u:
full: --users full: --users
help: Username of users to delete help: Username of users to delete
@ -100,273 +100,269 @@ user:
nargs: "*" nargs: "*"
--purge: --purge:
action: store_true action: store_true
### user_update() ### user_update()
update: update:
action_help: Update user informations action_help: Update user informations
arguments: arguments:
username: username:
help: Username of user to update help: Username of user to update
-f: -f:
full: --firstname full: --firstname
-l: -l:
full: --lastname full: --lastname
-m: -m:
full: --mail full: --mail
-p: -p:
full: --change-password full: --change-password
help: New password to set help: New password to set
metavar: PASSWORD metavar: PASSWORD
--add-mailforward: --add-mailforward:
help: Mailforward addresses to add help: Mailforward addresses to add
nargs: "+" nargs: "+"
metavar: MAIL metavar: MAIL
--remove-mailforward: --remove-mailforward:
help: Mailforward addresses to remove help: Mailforward addresses to remove
nargs: "+" nargs: "+"
metavar: MAIL metavar: MAIL
--add-mailalias: --add-mailalias:
help: Mail aliases to add help: Mail aliases to add
nargs: "+" nargs: "+"
metavar: MAIL metavar: MAIL
--remove-mailalias: --remove-mailalias:
help: Mail aliases to remove help: Mail aliases to remove
nargs: "+" nargs: "+"
metavar: MAIL metavar: MAIL
### user_info() ### user_info()
info: info:
action_help: Get user informations action_help: Get user informations
arguments: arguments:
-u: user-or-mail:
full: --username help: Username or mail to get informations
ask: "Username"
pattern: '^[a-z0-9_]+$'
-m:
full: --mail
############################# #############################
# Domain # # Domain #
############################# #############################
domain: domain:
category_help: Manage domains category_help: Manage domains
actions: actions:
### domain_list() ### domain_list()
list: list:
action_help: List domains action_help: List domains
arguments: arguments:
-f: -f:
full: --filter full: --filter
help: LDAP filter used to search help: LDAP filter used to search
-l: -l:
full: --limit full: --limit
help: Maximum number of domain fetched help: Maximum number of domain fetched
-o: -o:
full: --offset full: --offset
help: Starting number for domain fetching help: Starting number for domain fetching
### domain_add() ### domain_add()
add: add:
action_help: Create a custom domain action_help: Create a custom domain
arguments: arguments:
domains: domains:
help: Domain name to add help: Domain name to add
nargs: '*' nargs: '*'
ask: "New domain" ask: "New domain"
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
### domain_remove() ### domain_remove()
remove: remove:
action_help: Delete domains action_help: Delete domains
arguments: arguments:
domains: domains:
help: Domain(s) to delete help: Domain(s) to delete
nargs: "*" nargs: "*"
ask: "Domain to remove" ask: "Domain to remove"
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
### domain_info() ### domain_info()
info: info:
action_help: Get domain informations action_help: Get domain informations
arguments: arguments:
domain: domain:
help: "" help: ""
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
### domain_renewcert() ### domain_renewcert()
renewcert: renewcert:
action_help: Renew domain certificate action_help: Renew domain certificate
arguments: arguments:
domain: domain:
help: "" help: ""
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
############################# #############################
# App # # App #
############################# #############################
app: app:
category_help: Manage apps category_help: Manage apps
actions: actions:
### app_updatelist() ### app_updatelist()
updatelist: updatelist:
action_help: Fetch application list from app server action_help: Fetch application list from app server
arguments: arguments:
-u: -u:
full: --url full: --url
help: URL of remote JSON list (default http://fapp.yunohost.org/app/list/raw) help: URL of remote JSON list (default http://fapp.yunohost.org/app/list/raw)
### app_list() ### app_list()
list: list:
action_help: List apps action_help: List apps
arguments: arguments:
--fields: --fields:
help: fields to fetch help: fields to fetch
nargs: "+" nargs: "+"
-f: -f:
full: --filter full: --filter
help: LDAP filter used to search help: LDAP filter used to search
-l: -l:
full: --limit full: --limit
help: Maximum number of app fetched help: Maximum number of app fetched
-o: -o:
full: --offset full: --offset
help: Starting number for app fetching help: Starting number for app fetching
### app_install() TODO: Write help ### app_install() TODO: Write help
install: install:
action_help: Install apps action_help: Install apps
arguments: arguments:
app: app:
help: App to install help: App to install
-d: -d:
full: --domain full: --domain
-p: -p:
full: --path full: --path
-l: -l:
full: --label full: --label
--public: --public:
action: store_true action: store_true
--protected: --protected:
action: store_true action: store_true
### app_remove() TODO: Write help ### app_remove() TODO: Write help
remove: remove:
action_help: Remove app action_help: Remove app
arguments: arguments:
app: app:
help: App(s) to delete help: App(s) to delete
nargs: "+" nargs: "+"
### app_upgrade() ### app_upgrade()
upgrade: upgrade:
action_help: Upgrade app action_help: Upgrade app
arguments: arguments:
app: app:
help: App(s) to upgrade (default all) help: App(s) to upgrade (default all)
nargs: "*" nargs: "*"
### app_info() TODO: Write help ### app_info() TODO: Write help
info: info:
action_help: Get app informations action_help: Get app informations
arguments: arguments:
app: app:
help: "" help: ""
### app_addaccess() TODO: Write help ### app_addaccess() TODO: Write help
addaccess: addaccess:
action_help: Grant access right to users (everyone by default) action_help: Grant access right to users (everyone by default)
arguments: arguments:
app: app:
nargs: "+" nargs: "+"
-u: -u:
full: --user full: --user
nargs: "+" nargs: "+"
### app_removeaccess() TODO: Write help ### app_removeaccess() TODO: Write help
removeaccess: removeaccess:
action_help: Revoke access right to users (everyone by default) action_help: Revoke access right to users (everyone by default)
arguments: arguments:
app: app:
nargs: "+" nargs: "+"
-u: -u:
full: --user full: --user
nargs: "+" nargs: "+"
############################# #############################
# Repository # # Repository #
############################# #############################
repo: repo:
category_help: Manage app repositories category_help: Manage app repositories
actions: actions:
### repo_list() ### repo_list()
list: list:
action_help: List repositories action_help: List repositories
arguments: arguments:
-f: -f:
full: --filter full: --filter
help: LDAP filter used to search help: LDAP filter used to search
-l: -l:
full: --limit full: --limit
help: Maximum number of repository fetched help: Maximum number of repository fetched
-o: -o:
full: --offset full: --offset
help: Starting number for repository fetching help: Starting number for repository fetching
### repo_add() ### repo_add()
add: add:
action_help: Add app repository action_help: Add app repository
arguments: arguments:
url: url:
help: URL of the repository help: URL of the repository
-n: -n:
full: --name full: --name
help: Unique name of the repository help: Unique name of the repository
### repo_remove() ### repo_remove()
remove: remove:
action_help: Remove repository action_help: Remove repository
arguments: arguments:
repo: repo:
help: Name or URL of the repository help: Name or URL of the repository
### repo_update() ### repo_update()
update: update:
action_help: Update app list from the repositories action_help: Update app list from the repositories
############################# #############################
# Monitor # # Monitor #
############################# #############################
monitor: monitor:
category_help: Monitoring functions category_help: Monitoring functions
actions: actions:
### monitor_info() ### monitor_info()
info: info:
action_help: Check System action_help: Check System
arguments: arguments:
-m: -m:
full: --memory full: --memory
help: Check Memory help: Check Memory
action: store_true action: store_true
-c: -c:
full: --cpu full: --cpu
help: Check CPU help: Check CPU
action: store_true action: store_true
-d: -d:
full: --disk full: --disk
help: Check Disk help: Check Disk
action: store_true action: store_true
-i: -i:
full: --ifconfig full: --ifconfig
help: Show Ip and MAC Adress help: Show Ip and MAC Adress
action: store_true action: store_true
-u: -u:
full: --uptime full: --uptime
help: Show Uptime help: Show Uptime
action: store_true action: store_true
@ -377,7 +373,7 @@ monitor:
process: process:
action_help: Check Process action_help: Check Process
arguments: arguments:
-e: -e:
full: --enable full: --enable
help: Enable process help: Enable process
metavar: PROCESS metavar: PROCESS
@ -399,63 +395,63 @@ monitor:
full: --info full: --info
help: Process info help: Process info
action: store_true action: store_true
############################# #############################
# Firewall # # Firewall #
############################# #############################
firewall: firewall:
category_help: Manage firewall rules category_help: Manage firewall rules
actions: actions:
### firewall_list() ### firewall_list()
list: list:
action_help: List all firewall rules action_help: List all firewall rules
### firewall_allow() ### firewall_allow()
allow: allow:
action_help: Allow connection port/protocol action_help: Allow connection port/protocol
arguments: arguments:
port: port:
help: Port to open help: Port to open
protocol: protocol:
help: Protocol associated with port help: Protocol associated with port
choices: choices:
- UDP - UDP
- TCP - TCP
- Both - Both
name: name:
help: Reference name of the rule help: Reference name of the rule
### firewall_disallow() ### firewall_disallow()
disallow: disallow:
action_help: Disallow connection action_help: Disallow connection
arguments: arguments:
name: name:
help: Reference name of the rule to delete help: Reference name of the rule to delete
############################# #############################
# Tools # # Tools #
############################# #############################
tools: tools:
category_help: Specific tools category_help: Specific tools
actions: actions:
### tools_ldapinit() ### tools_ldapinit()
ldapinit: ldapinit:
action_help: YunoHost LDAP initialization action_help: YunoHost LDAP initialization
arguments: arguments:
-d: -d:
full: --domain full: --domain
help: YunoHost main domain help: YunoHost main domain
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
### tools_adminpw() ### tools_adminpw()
adminpw: adminpw:
action_help: Change admin password action_help: Change admin password
arguments: arguments:
-o: -o:
full: --old-password full: --old-password
ask: "Actual admin password" ask: "Actual admin password"
password: yes password: yes
@ -467,7 +463,7 @@ tools:
### tools_maindomain() ### tools_maindomain()
maindomain: maindomain:
action_help: Main domain change tool action_help: Main domain change tool
arguments: arguments:
-o: -o:
full: --old-domain full: --old-domain
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
@ -477,10 +473,10 @@ tools:
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
### tools_postinstall() ### tools_postinstall()
postinstall: postinstall:
action_help: YunoHost post-install action_help: YunoHost post-install
arguments: arguments:
-d: -d:
full: --domain full: --domain
help: YunoHost main domain help: YunoHost main domain
ask: "Main domain" ask: "Main domain"

View file

@ -166,7 +166,14 @@ def main():
try: try:
args = parse_dict(action_map) args = parse_dict(action_map)
result = args.func(args) args_dict = vars(args).copy()
for key in args_dict.keys():
sanitized_key = key.replace('-', '_')
if sanitized_key is not key:
args_dict[sanitized_key] = args_dict[key]
del args_dict[key]
del args_dict['func']
result = args.func(**args_dict)
except TypeError, error: except TypeError, error:
if not __debug__ : if not __debug__ :
traceback.print_exc() traceback.print_exc()
@ -175,7 +182,7 @@ def main():
except YunoHostError, error: except YunoHostError, error:
display_error(error) display_error(error)
return error.code return error.code
else: else:
if result is None: if result is None:
pass pass
elif os.isatty(1): elif os.isatty(1):

View file

@ -32,17 +32,17 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
else: limit = 1000 else: limit = 1000
if not filter: filter = 'uid=*' if not filter: filter = 'uid=*'
if fields: if fields:
for attr in fields: for attr in fields.items():
if attr in user_attrs: if attr in user_attrs:
attrs.append(attr) attrs.append(attr)
continue continue
else: else:
raise YunoHostError(22, _("Invalid field : ") + attr) raise YunoHostError(22, _("Invalid field : ") + attr)
else: else:
attrs = user_attrs attrs = user_attrs
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, attrs) result = yldap.search('ou=users,dc=yunohost,dc=org', filter, attrs)
if result and len(result) > (0 + offset) and limit > 0: if result and len(result) > (0 + offset) and limit > 0:
i = 0 + offset i = 0 + offset
for user in result[i:]: for user in result[i:]:
@ -56,8 +56,8 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
entry['Mail Forward'] = user['mail'][1:] entry['Mail Forward'] = user['mail'][1:]
if 'mailalias' in user: if 'mailalias' in user:
entry['Mail Aliases'] = user['mailalias'] entry['Mail Aliases'] = user['mailalias']
result_dict[str(i)] = entry result_dict[str(i)] = entry
i += 1 i += 1
else: else:
raise YunoHostError(167, _("No user found")) raise YunoHostError(167, _("No user found"))
@ -161,11 +161,11 @@ def user_delete(users, purge=None):
raise YunoHostError(169, _("An error occured during user deletion")) raise YunoHostError(169, _("An error occured during user deletion"))
win_msg(_("User(s) successfully deleted")) win_msg(_("User(s) successfully deleted"))
return result return result
def user_update(username, firstname=None, lastname=None, mail=None, change_password=None,
add_mailforward=None, remove_mailforward=None, def user_update(username, firstname=None, lastname=None, mail=None, change_password=None,
add_mailforward=None, remove_mailforward=None,
add_mailalias=None, remove_mailalias=None): add_mailalias=None, remove_mailalias=None):
""" """
Update user informations Update user informations
@ -238,7 +238,7 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
if len(user['mail']) > 1 and mail in user['mail'][1:]: if len(user['mail']) > 1 and mail in user['mail'][1:]:
user['mail'].remove(mail) user['mail'].remove(mail)
else: else:
raise YunoHostError(22, _("Invalid mail forward : ") + mail) raise YunoHostError(22, _("Invalid mail forward : ") + mail)
new_attr_dict['mail'] = user['mail'] new_attr_dict['mail'] = user['mail']
if add_mailalias: if add_mailalias:
@ -262,18 +262,18 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
if 'mailalias' in user and mail in user['mailalias']: if 'mailalias' in user and mail in user['mailalias']:
user['mailalias'].remove(mail) user['mailalias'].remove(mail)
else: else:
raise YunoHostError(22, _("Invalid mail alias : ") + mail) raise YunoHostError(22, _("Invalid mail alias : ") + mail)
new_attr_dict['mailalias'] = user['mailalias'] new_attr_dict['mailalias'] = user['mailalias']
if yldap.update('uid=' + username + ',ou=users', new_attr_dict): if yldap.update('uid=' + username + ',ou=users', new_attr_dict):
win_msg(_("User successfully updated")) win_msg(_("User successfully updated"))
return user_info(username=username) return user_info(username)
else: else:
raise YunoHostError(169, _("An error occured during user update")) raise YunoHostError(169, _("An error occured during user update"))
def user_info(username=None, mail=None):
def user_info(user_or_mail):
""" """
Fetch user informations from LDAP Fetch user informations from LDAP
@ -287,13 +287,18 @@ def user_info(username=None, mail=None):
with YunoHostLDAP() as yldap: with YunoHostLDAP() as yldap:
user_attrs = ['cn', 'mail', 'uid', 'mailAlias'] user_attrs = ['cn', 'mail', 'uid', 'mailAlias']
if mail: if len(user_or_mail.split('@')) is 2:
filter = 'mail=' + mail filter = '(|(mail='+ user_or_mail +')(mailalias='+ user_or_mail +'))'
else: else:
filter = 'uid=' + username filter = 'uid='+ user_or_mail
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs) result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs)
user = result[0]
if result:
user = result[0]
else:
raise YunoHostError(22, _("Unknown user/mail"))
result_dict = { result_dict = {
'Username': user['uid'], 'Username': user['uid'],
'Fullname': user['cn'], 'Fullname': user['cn'],
@ -310,4 +315,4 @@ def user_info(username=None, mail=None):
return result_dict return result_dict
else: else:
raise YunoHostError(167, _("No user found")) raise YunoHostError(167, _("No user found"))