diff --git a/action_map.yml b/action_map.yml index 22ad571f..d092dad7 100644 --- a/action_map.yml +++ b/action_map.yml @@ -28,7 +28,7 @@ # Don't forget to turn argument yaml style (setting: value) # ########################################################################## - + ############################# # General args # ############################# @@ -38,60 +38,60 @@ general_arguments: help: Display YunoHost version action: version version: YunoHost 2.0 beta1 - + ############################# # User # ############################# -user: +user: category_help: Manage users - actions: + actions: ### user_list() - list: + list: action_help: List users - arguments: - --fields: + arguments: + --fields: help: fields to fetch nargs: "+" - -f: + -f: full: --filter help: LDAP filter used to search - -l: + -l: full: --limit - help: Maximum number of user fetched - -o: + help: Maximum number of user fetched + -o: full: --offset - help: Starting number for user fetching - + help: Starting number for user fetching + ### user_create() - create: + create: action_help: Create user - arguments: - -u: + arguments: + -u: full: --username help: Must be unique ask: "Username" pattern: '^[a-z0-9_]+$' - -f: + -f: full: --firstname ask: "Firstname" - -l: + -l: full: --lastname ask: "Lastname" - -m: + -m: full: --mail help: Main mail address must be unique ask: "Mail address" pattern: '^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$' - -p: + -p: full: --password ask: "User password" password: yes - + ### user_delete() - delete: + delete: action_help: Delete user - arguments: + arguments: -u: full: --users help: Username of users to delete @@ -100,273 +100,269 @@ user: nargs: "*" --purge: action: store_true - + ### user_update() - update: + update: action_help: Update user informations - arguments: - username: + arguments: + username: help: Username of user to update - -f: + -f: full: --firstname - -l: + -l: full: --lastname - -m: + -m: full: --mail - -p: + -p: full: --change-password help: New password to set metavar: PASSWORD - --add-mailforward: + --add-mailforward: help: Mailforward addresses to add nargs: "+" metavar: MAIL - --remove-mailforward: + --remove-mailforward: help: Mailforward addresses to remove nargs: "+" metavar: MAIL - --add-mailalias: + --add-mailalias: help: Mail aliases to add nargs: "+" metavar: MAIL - --remove-mailalias: + --remove-mailalias: help: Mail aliases to remove nargs: "+" metavar: MAIL - + ### user_info() - info: + info: action_help: Get user informations - arguments: - -u: - full: --username - ask: "Username" - pattern: '^[a-z0-9_]+$' - -m: - full: --mail - + arguments: + user-or-mail: + help: Username or mail to get informations + ############################# # Domain # ############################# -domain: +domain: category_help: Manage domains - actions: - + actions: + ### domain_list() - list: + list: action_help: List domains - arguments: - -f: + arguments: + -f: full: --filter help: LDAP filter used to search - -l: + -l: full: --limit - help: Maximum number of domain fetched - -o: + help: Maximum number of domain fetched + -o: full: --offset - help: Starting number for domain fetching - + help: Starting number for domain fetching + ### domain_add() - add: + add: action_help: Create a custom domain - arguments: - domains: + arguments: + domains: help: Domain name to add nargs: '*' 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])*)$' - + ### domain_remove() - remove: + remove: action_help: Delete domains - arguments: - domains: + arguments: + domains: help: Domain(s) to delete nargs: "*" 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])*)$' - + ### domain_info() - info: + info: action_help: Get domain informations - arguments: - domain: + arguments: + domain: 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])*)$' ### domain_renewcert() - renewcert: + renewcert: action_help: Renew domain certificate - arguments: - domain: + arguments: + domain: 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])*)$' ############################# # App # ############################# -app: +app: category_help: Manage apps - actions: - + actions: + ### app_updatelist() updatelist: action_help: Fetch application list from app server arguments: -u: 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() - list: + list: action_help: List apps - arguments: - --fields: + arguments: + --fields: help: fields to fetch nargs: "+" - -f: + -f: full: --filter help: LDAP filter used to search - -l: + -l: full: --limit - help: Maximum number of app fetched - -o: + help: Maximum number of app fetched + -o: full: --offset - help: Starting number for app fetching - + help: Starting number for app fetching + ### app_install() TODO: Write help - install: + install: action_help: Install apps - arguments: - app: + arguments: + app: help: App to install - -d: + -d: full: --domain - -p: + -p: full: --path - -l: + -l: full: --label - --public: + --public: action: store_true - --protected: + --protected: action: store_true - + ### app_remove() TODO: Write help - remove: + remove: action_help: Remove app - arguments: - app: + arguments: + app: help: App(s) to delete nargs: "+" - + ### app_upgrade() - upgrade: + upgrade: action_help: Upgrade app - arguments: - app: + arguments: + app: help: App(s) to upgrade (default all) nargs: "*" - + ### app_info() TODO: Write help - info: + info: action_help: Get app informations - arguments: - app: + arguments: + app: help: "" - + ### app_addaccess() TODO: Write help - addaccess: + addaccess: action_help: Grant access right to users (everyone by default) - arguments: - app: + arguments: + app: nargs: "+" - -u: + -u: full: --user nargs: "+" - + ### app_removeaccess() TODO: Write help - removeaccess: + removeaccess: action_help: Revoke access right to users (everyone by default) - arguments: - app: + arguments: + app: nargs: "+" - -u: + -u: full: --user nargs: "+" - + ############################# # Repository # ############################# -repo: +repo: category_help: Manage app repositories - actions: + actions: ### repo_list() - list: + list: action_help: List repositories - arguments: - -f: + arguments: + -f: full: --filter help: LDAP filter used to search - -l: + -l: full: --limit - help: Maximum number of repository fetched - -o: + help: Maximum number of repository fetched + -o: full: --offset - help: Starting number for repository fetching - + help: Starting number for repository fetching + ### repo_add() - add: + add: action_help: Add app repository - arguments: - url: + arguments: + url: help: URL of the repository - -n: + -n: full: --name help: Unique name of the repository - + ### repo_remove() - remove: + remove: action_help: Remove repository - arguments: - repo: + arguments: + repo: help: Name or URL of the repository - + ### repo_update() - update: + update: action_help: Update app list from the repositories ############################# # Monitor # ############################# -monitor: +monitor: category_help: Monitoring functions - actions: - + actions: + ### monitor_info() - info: + info: action_help: Check System - arguments: - -m: + arguments: + -m: full: --memory help: Check Memory action: store_true - -c: + -c: full: --cpu help: Check CPU action: store_true - -d: + -d: full: --disk help: Check Disk action: store_true - -i: + -i: full: --ifconfig help: Show Ip and MAC Adress action: store_true - -u: + -u: full: --uptime help: Show Uptime action: store_true @@ -377,7 +373,7 @@ monitor: process: action_help: Check Process arguments: - -e: + -e: full: --enable help: Enable process metavar: PROCESS @@ -399,63 +395,63 @@ monitor: full: --info help: Process info action: store_true - + ############################# # Firewall # ############################# -firewall: +firewall: category_help: Manage firewall rules - actions: + actions: ### firewall_list() - list: + list: action_help: List all firewall rules - + ### firewall_allow() - allow: + allow: action_help: Allow connection port/protocol - arguments: - port: + arguments: + port: help: Port to open - protocol: + protocol: help: Protocol associated with port - choices: - - UDP - - TCP + choices: + - UDP + - TCP - Both - name: + name: help: Reference name of the rule - + ### firewall_disallow() - disallow: + disallow: action_help: Disallow connection - arguments: - name: + arguments: + name: help: Reference name of the rule to delete - + ############################# # Tools # ############################# -tools: +tools: category_help: Specific tools - actions: + actions: ### tools_ldapinit() - ldapinit: + ldapinit: action_help: YunoHost LDAP initialization arguments: - -d: + -d: full: --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])*)$' ### tools_adminpw() - adminpw: + adminpw: action_help: Change admin password - arguments: - -o: + arguments: + -o: full: --old-password ask: "Actual admin password" password: yes @@ -467,7 +463,7 @@ tools: ### tools_maindomain() maindomain: action_help: Main domain change tool - arguments: + arguments: -o: 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])*)$' @@ -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])*)$' ### tools_postinstall() - postinstall: + postinstall: action_help: YunoHost post-install - arguments: - -d: + arguments: + -d: full: --domain help: YunoHost main domain ask: "Main domain" diff --git a/parse_args b/parse_args index 0b41caed..cf5f09c7 100755 --- a/parse_args +++ b/parse_args @@ -166,7 +166,14 @@ def main(): try: 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: if not __debug__ : traceback.print_exc() @@ -175,7 +182,7 @@ def main(): except YunoHostError, error: display_error(error) return error.code - else: + else: if result is None: pass elif os.isatty(1): diff --git a/yunohost_user.py b/yunohost_user.py index 94ef4084..809ff4e8 100644 --- a/yunohost_user.py +++ b/yunohost_user.py @@ -32,17 +32,17 @@ def user_list(fields=None, filter=None, limit=None, offset=None): else: limit = 1000 if not filter: filter = 'uid=*' if fields: - for attr in fields: + for attr in fields.items(): if attr in user_attrs: attrs.append(attr) continue else: - raise YunoHostError(22, _("Invalid field : ") + attr) + raise YunoHostError(22, _("Invalid field : ") + attr) else: attrs = user_attrs result = yldap.search('ou=users,dc=yunohost,dc=org', filter, attrs) - + if result and len(result) > (0 + offset) and limit > 0: i = 0 + offset 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:] if 'mailalias' in user: entry['Mail Aliases'] = user['mailalias'] - - result_dict[str(i)] = entry + + result_dict[str(i)] = entry i += 1 else: 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")) 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): """ 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:]: user['mail'].remove(mail) else: - raise YunoHostError(22, _("Invalid mail forward : ") + mail) + raise YunoHostError(22, _("Invalid mail forward : ") + mail) new_attr_dict['mail'] = user['mail'] 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']: user['mailalias'].remove(mail) else: - raise YunoHostError(22, _("Invalid mail alias : ") + mail) + raise YunoHostError(22, _("Invalid mail alias : ") + mail) new_attr_dict['mailalias'] = user['mailalias'] if yldap.update('uid=' + username + ',ou=users', new_attr_dict): win_msg(_("User successfully updated")) - return user_info(username=username) + return user_info(username) else: 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 @@ -287,13 +287,18 @@ def user_info(username=None, mail=None): with YunoHostLDAP() as yldap: user_attrs = ['cn', 'mail', 'uid', 'mailAlias'] - if mail: - filter = 'mail=' + mail + if len(user_or_mail.split('@')) is 2: + filter = '(|(mail='+ user_or_mail +')(mailalias='+ user_or_mail +'))' else: - filter = 'uid=' + username + filter = 'uid='+ user_or_mail 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 = { 'Username': user['uid'], 'Fullname': user['cn'], @@ -310,4 +315,4 @@ def user_info(username=None, mail=None): return result_dict else: raise YunoHostError(167, _("No user found")) - +