
    Vh{                     t    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d Zd Zd	 Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: awall
short_description: Manage awall policies
author: Ted Trask (@tdtrask) <ttrask01@yahoo.com>
description:
  - This modules allows for enable/disable/activate of C(awall) policies.
  - Alpine Wall (C(awall)) generates a firewall configuration from the enabled policy files and activates the configuration
    on the system.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - One or more policy names.
    type: list
    elements: str
  state:
    description:
      - Whether the policies should be enabled or disabled.
    type: str
    choices: [disabled, enabled]
    default: enabled
  activate:
    description:
      - Activate the new firewall rules.
      - Can be run with other steps or on its own.
      - Idempotency is affected if O(activate=true), as the module will always report a changed state.
    type: bool
    default: false
notes:
  - At least one of O(name) and O(activate) is required.
an  
- name: Enable "foo" and "bar" policy
  community.general.awall:
    name: [foo bar]
    state: enabled

- name: Disable "foo" and "bar" policy and activate new rules
  community.general.awall:
    name:
      - foo
      - bar
    state: disabled
    activate: false

- name: Activate currently enabled firewall rules
  community.general.awall:
    activate: true
z # N)AnsibleModulec                 t    dt         z  }| j                  |      \  }}}|dk(  ry| j                  d||       y )Nz%s activate --forcer   Tzcould not activate new rulesmsgstdoutstderr)
AWALL_PATHrun_command	fail_json)modulecmdrcr
   r   s        k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/awall.pyactivater   K   sD    
:
.C++C0B	Qw;FSYZ    c                     dt         z  }| j                  |      \  }}}t        j                  d|z  |t        j                        ryy)N%s listz^%s\s+enabledTF)r   r   research	MULTILINE)r   namer   r   r
   r   s         r   is_policy_enabledr   T   sC    
z
"C++C0B	yy!D(&",,?r   c                    g }|D ]   }t        | |      r|j                  |       " |s| j                  dd       dj                  |      }| j                  r
dt
        z  }nt
        d|}| j                  |      \  }}}|dk7  r| j                  d|z  ||	       |r| j                  st        |        | j                  d
d|z         y )NFzpolicy(ies) already enabledchangedr	    r   z enable r   zfailed to enable %sr   Tzenabled awall policy(ies): %s	r   append	exit_jsonjoin
check_moder   r   r   r   	r   namesactpoliciesr   r   r   r
   r   s	            r   enable_policyr)   \   s    H " .OOD!" ,IJHHXE:& *E2++C0B	Qw2U:6RXY
6$$
T'F'NOr   c                    g }|D ]   }t        | |      s|j                  |       " |s| j                  dd       dj                  |      }| j                  r
dt
        z  }nt
        d|}| j                  |      \  }}}|dk7  r| j                  d|z  ||	       |r| j                  st        |        | j                  d
d|z         y )NFzpolicy(ies) already disabledr   r   r   z	 disable r   zfailed to disable %sr   Tzdisabled awall policy(ies): %sr    r%   s	            r   disable_policyr+   p   s    H "VT*OOD!" ,JKHHXE:&!+U3++C0B	Qw3e;FSYZ
6$$
T'G%'OPr   c            
         t        t        t        ddddg      t        dd      t        dd	      
      ddggd      } | j                  dd      a| j                  }|d   r7|d   dk(  rt        | |d   |d          n|d   dk(  rt        | |d   |d          |d   r*| j                  st        |        | j                  dd       | j                  d       y )Nstrenableddisabled)typedefaultchoiceslist)r0   elementsboolF)r0   r1   )stater   r   r   r   T)argument_specrequired_one_ofsupports_check_modeawall)requiredr6   zactivated awall rulesr   zno action defined)r	   )r   dictget_bin_pathr   paramsr)   r+   r$   r   r"   r   )r   ps     r   mainr@      s    E9z9>UV6E2vu5

 !*-. F $$Wt$<JAyW:"&!F)Qz];wZ:%61V9a
m<}  V+BC
,-r   __main__)
__future__r   r   r   r0   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   r   r   r)   r+   r@   __name__ r   r   <module>rJ      s_    A @$L& 
 	 4[P(Q(.< zF r   