def _clearUserHomes(unattended=False):
    print("\nCAUTION! This will delete all userhomes of AD users!")
    if not unattended and not _askStep("clear all user homes now", False):
        return True

    if not _checkLoggedInUsers():
        return False

    if not _unmountAllCifsMounts():
        logging.info("Aborting deletion of user homes to prevent deleting data on the server.")
        return False

    userHomes = os.listdir("/home")

    logging.info("Deleting all user homes now!")
    for userHome in userHomes:
        if not user.isUserInAD(userHome):
            logging.info("* {} [SKIPPED]".format(userHome))
            continue

        logging.info("* {}".format(userHome))
        try:
            shutil.rmtree("/home/{}".format(userHome))
        except Exception as e:
            logging.error("* FAILED!")
            logging.exception(e)
        
        try:
            shutil.rmtree(constants.hiddenShareMountBasepath.format(userHome))
        except:
            pass
    
    logging.info("Done.")
    return True
def shouldHooksBeExecuted(overrideUsername=None):
    """Check if hooks should be executed

    :param overrideUsername: Override the username to check, defaults to None
    :type overrideUsername: str, optional
    :return: True if hooks should be executed, fale otherwise
    :rtype: bool
    """
    # check if linuxmuster-linuxclient7 is setup
    if not setup.isSetup():
        logging.info(
            "==== Linuxmuster-linuxclient7 is not setup, exiting ====")
        return False

    # check if the computer is joined
    if not computer.isInAD():
        logging.info(
            "==== This Client is not joined to any domain, exiting ====")
        return False

    # Check if the user is an AD user
    if overrideUsername == None:
        overrideUsername = user.username()

    if not user.isUserInAD(overrideUsername):
        logging.info("==== {0} is not an AD user, exiting ====".format(
            user.username()))
        return False

    return True
def _checkLoggedInUsers():
    result = subprocess.run("who -s | awk '{ print $1 }'", stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)

    if result.returncode != 0:
        logging.error("Failed to get logged in users!")
        return False, None

    loggedInUsers = list(filter(None, result.stdout.split("\n")))

    for loggedInUser in loggedInUsers:
        if user.isUserInAD(loggedInUser):
            logging.error("User {} is still logged in, please log out first! Aborting!".format(loggedInUser))
            return False

    return True
Exemple #4
0
def shouldHooksBeExecuted(overrideUsername=None):
    # check if linuxmuster-linuxclient7 is setup
    if not setup.isSetup():
        logging.info(
            "==== Linuxmuster-linuxclient7 is not setup, exiting ====")
        return False

    # check if the computer is joined
    if not computer.isInAD():
        logging.info(
            "==== This Client is not joined to any domain, exiting ====")
        return False

    # Check if the user is an AD user
    if overrideUsername == None:
        overrideUsername = user.username()

    if not user.isUserInAD(overrideUsername):
        logging.info("==== {0} is not an AD user, exiting ====".format(
            user.username()))
        return False

    return True