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 _getDefaultUsername(username=None): if username == None: if user.isRoot(): username = computer.hostname().upper() + "$" else: username = user.username() return username
def cleanTemplateUserGtkBookmarks(): logging.info("Cleaning {} gtk bookmarks".format(constants.templateUser)) gtkBookmarksFile = "/home/{0}/.config/gtk-3.0/bookmarks".format(user.username()) if not os.path.isfile(gtkBookmarksFile): logging.warning("Gtk bookmarks file not found, skipping!") return fileHelper.removeLinesInFileContainingString(gtkBookmarksFile, constants.templateUser)
def installPrinter(networkPath, name=None, username=None): if username == None: username = user.username() if user.isRoot(): return _installPrinter(username, networkPath, name) else: # This will call installPrinter() again with root privileges return _installPrinterWithoutRoot(networkPath, name) pass
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
def _appendToTmpEnvFile(mode, keyValuePair): if not _isApplicable(): return False tmpEnvironmentFilePath = constants.tmpEnvironmentFilePath.format( user.username()) fileOpenMode = "a" if os.path.exists(tmpEnvironmentFilePath) else "w" try: with open(tmpEnvironmentFilePath, fileOpenMode) as tmpEnvironmentFile: tmpEnvironmentFile.write("\n{0} '{1}'".format(mode, keyValuePair)) return True except Exception as e: logging.exception(e) return False
def installPrinter(networkPath, name=None, username=None): """ Installs a networked printer for a user :param networkPath: The network path of the printer :type networkPath: str :param name: The name for the printer, defaults to None :type name: str, optional :param username: The username of the user whom the is installed printer for. Defaults to the executing user :type username: str, optional :return: True on success, False otherwise :rtype: bool """ if username == None: username = user.username() if user.isRoot(): return _installPrinter(username, networkPath, name) else: # This will call installPrinter() again with root privileges return _installPrinterWithoutRoot(networkPath, name) pass
def readAttributes(): if not user.isInAD(): return False, None return ldapHelper.searchOne("(sAMAccountName={})".format(user.username()))