PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_license.py

"""
This module allows you to manage windows licensing via slmgr.vbs

.. code-block:: bash

    salt '*' license.install XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
"""

import logging
import re

import salt.utils.platform

log = logging.getLogger(__name__)
__virtualname__ = "license"


def __virtual__():
    """
    Only work on Windows
    """
    if salt.utils.platform.is_windows():
        return __virtualname__
    return (False, "Module win_license: module only works on Windows systems.")


def installed(product_key):
    """
    Check to see if the product key is already installed.

    Note: This is not 100% accurate as we can only see the last
     5 digits of the license.

    CLI Example:

    .. code-block:: bash

        salt '*' license.installed XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
    """
    cmd = r"cscript C:\Windows\System32\slmgr.vbs /dli"
    out = __salt__["cmd.run"](cmd)
    return product_key[-5:] in out


def install(product_key):
    """
    Install the given product key

    CLI Example:

    .. code-block:: bash

        salt '*' license.install XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
    """
    cmd = rf"cscript C:\Windows\System32\slmgr.vbs /ipk {product_key}"
    return __salt__["cmd.run"](cmd)


def uninstall():
    """
    Uninstall the current product key

    CLI Example:

    .. code-block:: bash

        salt '*' license.uninstall
    """
    cmd = r"cscript C:\Windows\System32\slmgr.vbs /upk"
    return __salt__["cmd.run"](cmd)


def activate():
    """
    Attempt to activate the current machine via Windows Activation

    CLI Example:

    .. code-block:: bash

        salt '*' license.activate
    """
    cmd = r"cscript C:\Windows\System32\slmgr.vbs /ato"
    return __salt__["cmd.run"](cmd)


def licensed():
    """
    Return true if the current machine is licensed correctly

    CLI Example:

    .. code-block:: bash

        salt '*' license.licensed
    """
    cmd = r"cscript C:\Windows\System32\slmgr.vbs /dli"
    out = __salt__["cmd.run"](cmd)
    return "License Status: Licensed" in out


def info():
    """
    Return information about the license, if the license is not
    correctly activated this will return None.

    CLI Example:

    .. code-block:: bash

        salt '*' license.info
    """
    cmd = r"cscript C:\Windows\System32\slmgr.vbs /dli"
    out = __salt__["cmd.run"](cmd)

    match = re.search(
        r"Name: (.*)\r\nDescription: (.*)\r\nPartial Product Key: (.*)\r\nLicense"
        r" Status: (.*)",
        out,
        re.MULTILINE,
    )

    if match is not None:
        groups = match.groups()
        return {
            "name": groups[0],
            "description": groups[1],
            "partial_key": groups[2],
            "licensed": "Licensed" in groups[3],
        }

    return None