Exemple #1
0
    def execute(self):
        """Executes an external shell command"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
        except:
            print(coloured("shell command not found", "red"))
Exemple #2
0
    def execute(self):
        """Executes an external shell command"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
        except:
            print(coloured("shell command not found", "red"))
Exemple #3
0
def createnewuser(username):
    """ Создание базового пользователя для сайта.
    Возвращает словать {username, uid, gid, homedir}
    """
    userhome = os.path.join(USERDIRBASE, username)
    if os.path.exists(userhome):
        raise Error, "Папка пользователя '%s' уже существует" %  userhome
    
    TESTING or sh("adduser -m -U %s" % username)
    pw = TESTING or pwd.getpwnam(username)
    TESTING or os.chmod(userhome, 0750)
    TESTING or sh("setfacl -m u:nginx:x %s" % userhome)
    os.mkdir( os.path.join(userhome, 'sites') )
    TESTING or os.chown(os.path.join(userhome, 'sites'), pw[2], pw[3])

    return {'username': username, 'uid': pw[2], 'gid': pw[3], 'homedir': userhome}
Exemple #4
0
    def execute(self):
        """Executes an external shell command

        returns whether or not the shell command executed successfully
        """
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
            return True
        except:
            print(coloured("shell command not found", "red"))
            return False
Exemple #5
0
def su(suuser,
       perm):  # Define su function with user to switch to and permission check
    if init.database.get(
            suuser) == None:  # If given user not exists, print that out
        print(f"User {suuser} not found.")

    elif perm == True:  # If permission check successes, substitute user immediatelly
        shell.shell(suuser)

    else:  # Else check if account isn't locked, if so print that out
        password = init.database.get(suuser)[0]
        if password == "!":
            print(f"Account {suuser} is locked.")

        else:  # Ask for a password, if correct substitute user, if not print that out
            loginpassword = input(f"Password for {suuser}: ")
            if loginpassword == password:
                shell.sh(suuser)
            else:
                print("Login incorrect.")
Exemple #6
0
def __shell(cmd):
    try:
        s = sh(cmd)
        errors = s.errors(raw=True)
        if errors:
            response = u'{} FAIL: {}'.format(emoji(Emoji.PILE_OF_POO), errors)
        else:
            response = s.output(raw=True)
    except OSError as e:
        response = '{} That did\'t go well: {}'.format(emoji(Emoji.CROSS_MARK), e)
    return response
Exemple #7
0
def __shell(cmd):
    try:
        s = sh(cmd)
        errors = s.errors(raw=True)
        if errors:
            response = u'{} FAIL: {}'.format(emoji(Emoji.PILE_OF_POO), errors)
        else:
            response = s.output(raw=True)
    except OSError as e:
        response = '{} That did\'t go well: {}'.format(emoji(Emoji.CROSS_MARK),
                                                       e)
    return response