
    VhL4                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
Z
d d
lmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZ d Zd Zd Zedk(  r e        y	y	)    )absolute_importdivisionprint_functionz1.1preview	community)metadata_versionstatussupported_bya?  
---
module: cpm_user
version_added: "2.7.0"
author: "Western Telematic Inc. (@wtinetworkgear)"
short_description: Get various status and parameters from WTI OOB and PDU devices
description:
    - "Get/Add/Edit Delete Users from WTI OOB and PDU devices"
options:
    cpm_action:
        description:
            - This is the Action to send the module.
        required: true
        type: str
        choices: [ "getuser", "adduser", "edituser", "deleteuser" ]
    cpm_url:
        description:
            - This is the URL of the WTI device to send the module.
        type: str
        required: true
    cpm_username:
        description:
            - This is the Basic Authentication Username of the WTI device to send the module.
        type: str
        required: true
    cpm_password:
        description:
            - This is the Basic Authentication Password of the WTI device to send the module.
        type: str
        required: true
    use_https:
        description:
            - Designates to use an https connection or http connection.
        required: false
        default: true
        type: bool
    validate_certs:
        description:
            - If false, SSL certificates will not be validated. This should only be used
            - on personally controlled sites using self-signed certificates.
        type: bool
        required: false
        default: true
    use_proxy:
        description: Flag to control if the lookup will observe HTTP proxy environment variables when present.
        type: bool
        required: false
        default: false
    user_name:
        description:
            - This is the User Name that needs to be create/modified/deleted
        type: str
        required: true
    user_pass:
        description:
            - This is the User Password that needs to be create/modified/deleted
            - If the user is being Created this parameter is required
        type: str
        required: false
    user_accesslevel:
        description:
            - This is the access level that needs to be create/modified/deleted
            - 0 View, 1 User, 2 SuperUser, 3 Administrator
        type: int
        required: false
        choices: [ 0, 1, 2, 3 ]
    user_accessssh:
        description:
            - If the user has access to the WTI device via SSH
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_accessserial:
        description:
            - If the user has access to the WTI device via Serial ports
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_accessweb:
        description:
            - If the user has access to the WTI device via Web
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_accessapi:
        description:
            - If the user has access to the WTI device via RESTful APIs
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_accessmonitor:
        description:
            - If the user has ability to monitor connection sessions
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_accessoutbound:
        description:
            - If the user has ability to initiate Outbound connection
            - 0 No , 1 Yes
        type: int
        required: false
        choices: [ 0, 1 ]
    user_portaccess:
        description:
            - If AccessLevel is lower than Administrator, which ports the user has access
        type: str
        required: false
    user_plugaccess:
        description:
            - If AccessLevel is lower than Administrator, which plugs the user has access
        type: str
        required: false
    user_groupaccess:
        description:
            - If AccessLevel is lower than Administrator, which Groups the user has access
        type: str
        required: false
    user_callbackphone:
        description:
            - This is the Call Back phone number used for POTS modem connections
        type: str
        required: false
 a  
# Get User Parameters
- name: Get the User Parameters for the given user of a WTI device
  cpm_user:
    cpm_action: "getuser"
    cpm_url: "rest.wti.com"
    cpm_username: "restuser"
    cpm_password: "restfuluserpass12"
    use_https: true
    validate_certs: true
    user_name: "usernumberone"

# Create User
- name: Create a User on a given WTI device
  cpm_user:
    cpm_action: "adduser"
    cpm_url: "rest.wti.com"
    cpm_username: "restuser"
    cpm_password: "restfuluserpass12"
    use_https: true
    validate_certs: false
    user_name: "usernumberone"
    user_pass: "complicatedpassword"
    user_accesslevel: 2
    user_accessssh: 1
    user_accessserial: 1
    user_accessweb: 0
    user_accessapi: 1
    user_accessmonitor: 0
    user_accessoutbound: 0
    user_portaccess: "10011111"
    user_plugaccess: "00000111"
    user_groupaccess: "00000000"

# Edit User
- name: Edit a User on a given WTI device
  cpm_user:
    cpm_action: "edituser"
    cpm_url: "rest.wti.com"
    cpm_username: "restuser"
    cpm_password: "restfuluserpass12"
    use_https: true
    validate_certs: false
    user_name: "usernumberone"
    user_pass: "newpasswordcomplicatedpassword"

# Delete User
- name: Delete a User from a given WTI device
  cpm_user:
    cpm_action: "deleteuser"
    cpm_url: "rest.wti.com"
    cpm_username: "restuser"
    cpm_password: "restfuluserpass12"
    use_https: true
    validate_certs: true
    user_name: "usernumberone"
zk
data:
    description: The output JSON returned from the commands sent
    returned: always
    type: str
N)AnsibleModule)to_textto_bytes	to_native)	HTTPErrorURLError)open_urlConnectionErrorSSLValidationErrorc                    dt        | j                  d         z  }| j                  d   9t        | j                  d         dkD  r|dt        | j                  d         d}| j                  d   |dt        | j                  d         }| j                  d	   |d
t        | j                  d	         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         }| j                  d   |dt        | j                  d         d}d|z  }|S )Nz{"users":{"username": "%s"	user_name	user_passr   z,"newpasswd": ""user_accesslevelz,"accesslevel": user_portaccessz,"portaccess": user_plugaccessz,"plugaccess": user_groupaccessz,"groupaccess": user_accessserialz,"accessserial": user_accesssshz,"accessssh": user_accesswebz,"accessweb": user_accessoutboundz,"accessoutbound": user_accessapiz,"accessapi": user_accessmonitorz,"accessmonitor": user_callbackphonez,"callbackphone": "z%s}})r   paramslen)	cpmmodule	json_loads     g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/wti/remote/plugins/modules/cpm_user.pyassemble_jsonr(      sa   ,y):J:J;:W/YYI $0c):J:J;:W6X[\6\.79CSCST_C`9ab	*+7.79CSCSTfCg9hi	)*6-6	)BRBRSdBe8fg	)*6-6	)BRBRSdBe8fg	*+7.79CSCSTfCg9hi	+,8/8)IDTDTUhDi:jk	()5,5yAQAQRbAc7de	()5,5yAQAQRbAc7de	-.:1:IiFVFVWlFm<no	()5,5yAQAQRbAc7de	,-9099YEUEUVjEk;lm	,-92;YyGWGWXlGm=no	)$I    c                  	   t        dDi dt        g dd      dt        dd      dt        ddd	
      dt        ddd
      dt        dd      dt        dd	d d      dt        dd	d g d      dt        dd	d ddg      dt        dd	d ddg      dt        dd	d ddg      dt        dd	d ddg      dt        dd	d ddg      dt        dd	d ddg      dt        dd	d       dt        dd	d       dt        dd	d       dt        dd	d       d t        d!d"      d#t        d!d"      d$t        d!d	"      } t        d	d%&      }t        | d'      }|j                  r|S t        t	        j
                  t        d(j                  t        |j                  d         t        |j                  d               d)*                  }|j                  d    du rd+}nd,}d }|j                  d   d-k(  r9|t        |j                  d         d.t        |j                  d         }d/}n|j                  d   d0k(  ri|j                  d   t        |j                  d         dk(  r |j                  dDd1d2i| t        |      }|t        |j                  d         d3}d4}n|j                  d   d5k(  r+t        |      }|t        |j                  d         d3}d6}nI|j                  d   d7k(  r7|t        |j                  d         d.t        |j                  d         }d8}	 t        ||j                  d#   |j                  d$   d9d:|z  d;<      }|d/k7  rd|d=<   t        j%                               |dC<    |j&                  dDi | y # t        $ rB}	t        d>j                  t        |	            d	?      }
 |j                  dDi |
 Y d }	~	ud }	~	wt        $ rB}	t        d@j                  t        |	            d	?      }
 |j                  dDi |
 Y d }	~	d }	~	wt         $ rC}	t        dAj                  t        |	            d	?      }
 |j                  dDi |
 Y d }	~	d }	~	wt"        $ rC}	t        dBj                  t        |	            d	?      }
 |j                  dDi |
 Y d }	~	Rd }	~	ww xY w)EN
cpm_action)getuseradduseredituser
deleteuserT)choicesrequiredcpm_urlstr)typer1   cpm_usernameF)r4   r1   no_logcpm_passwordr   r   )r4   r1   defaultr6   r   int)r            )r4   r1   r8   r0   r   r   r:   r   r   r    r!   r   r   )r4   r1   r8   r   r   r"   	use_httpsbool)r4   r8   validate_certs	use_proxy )changeddata)argument_specsupports_check_modez{0}:{1}surrogate_or_strict)errorszhttps://zhttp://r,   z/api/v2/config/users?username=GETr-   msgzuser_pass not defined.z/api/v2/config/usersPOSTr.   PUTr/   DELETEzapplication/jsonzBasic %s)zContent-TypeAuthorization)rC   methodr?   r@   headersrB   z!Received HTTP error for {0} : {1})rI   rB   zFailed lookup url for {0} : {1}z6Error validating the servers certificate for {0} : {1}z"Error connecting to  for {0} : {1}rC    )dictr   
check_moder   base64	b64encoder   formatr   r#   r$   	fail_jsonr(   r   r   r   r   r   read	exit_json)module_argsresultmoduleauthprotocolpayloadfullurlrN   responseerV   s              r'   
run_modulerb   	  sj     P[_`%$/ utEB utDA	
 ED1 EE4M 55$P\] qRSfU EE4RSUVQWX qRSfU qRSfU  UUDSTVWRXY !eeTTUWXSYZ %%F %%F  55$G!"  UUDI#$ FD1%& 6'( FE2)K. F
 $OF6##HY-=-=iVdHe>fhqrxrr  AO  sP  iQ  .R/%1 2 3D }}[!T)Gl#y0=EyQWQ^Q^_hQiGjluv|  wD  wD  EP  wQ  mR  S
--
%
2==%-#fmmK6P2QUV2VFD!9DVD'199V]]S\E];^_
--
%
3'199V]]S\E];^_
--
%
5=EyQWQ^Q^_hQiGjluv|  wD  wD  EP  wQ  mR  S&G'&QWQ^Q^_oQp  }C  }J  }J  KV  }W5GZdgkZk$lneO $F9 X]]_-F6NFv  &@GGQZ[\Q]^hmn	%9% &>EEgyYZ|\fkl	%9% &W^^_fhqrshtu  @E  F	%9%% &AHHR[\]R^_ino	%9%%&s<   :;N$ $	S-8O**S68P33S?8Q==S	8SSc                      t                y )N)rb   rP   r)   r'   mainrd   ^  s    Lr)   __main__)
__future__r   r   r   r4   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNrS   ansible.module_utils.basicr   ansible.module_utils._textr   r   r   +ansible.module_utils.six.moves.urllib.errorr   r   ansible.module_utils.urlsr   r   r   r(   rb   rd   __name__rP   r)   r'   <module>rq      s}   & A @ k @D8t
  4 C C K S SDRj zF r)   