Esempio n. 1
0
def privileges_check(user):
    # Print and log a critical database access error if the database has not been initialized.
    if not GS.mumble_db_string:
        dprint(
            f"The JJMumbleBot database has not been initialized, but a user privilege check is trying to access it!\nTrying to initialize database..."
        )
        log(CRITICAL,
            f"The JJMumbleBot database has not been initialized, but a user privilege check is trying to access it!\nTrying to initalize database...",
            origin=L_DATABASE)
        return -1
    # Retrieve the user information in the database.
    user_data = GetDB.get_user_data(db_cursor=get_memory_db().cursor(),
                                    user_name=user['name'])
    # Create a new user entry if the user does not already exist in the database.
    if not user_data:
        InsertDB.insert_new_user(db_conn=get_memory_db(),
                                 username=user['name'])
        InsertDB.insert_new_permission(
            db_conn=get_memory_db(),
            username=user['name'],
            permission_level=Privileges.DEFAULT.value)
        # save_memory_db_to_file(get_memory_db())

        # Retrieve the user information in the database.
        user_data = GetDB.get_user_data(db_cursor=get_memory_db().cursor(),
                                        user_name=user['name'])
        return int(user_data['level'])
    return int(user_data['level'])
Esempio n. 2
0
def set_privileges(username, level, sender):
    all_user_data = GetDB.get_all_user_data(get_memory_db().cursor())
    user_names_list = [x[0] for x in all_user_data]
    if username in user_names_list:
        for user in all_user_data:
            if user[0] == username and username == sender:
                dprint(
                    f"This user: [{username}] tried to modify their own user privileges. Modification denied.",
                    origin=L_USER_PRIV)
                log(WARNING,
                    f"This user: [{username}] tried to modify their own user privileges, the modification was denied.",
                    origin=L_USER_PRIV)
                return False
            if user[0] == username and privileges_check(sender) <= user[1]:
                dprint(
                    f"This user: [{sender['name']}] tried to modify privileges for a user with equal/higher privileges: [{username}]",
                    origin=L_USER_PRIV)
                log(WARNING,
                    f"This user: [{sender['name']}] tried to modify privileges for a user with equal/higher privileges: [{username}]",
                    origin=L_USER_PRIV)
                return False
    if UpdateDB.update_user_privileges(db_conn=get_memory_db(),
                                       user_name=username,
                                       level=int(level)):
        return True
    return False
Esempio n. 3
0
def remove_from_blacklist(username):
    all_user_data = GetDB.get_all_user_data(get_memory_db().cursor())
    user_names_list = [x[0] for x in all_user_data]
    if username in user_names_list:
        for user in all_user_data:
            if user[0] == username and user[1] == Privileges.BLACKLIST.value:
                if UpdateDB.update_user_privileges(db_conn=get_memory_db(), user_name=username, level=int(Privileges.DEFAULT.value)):
                    return True
    return False
Esempio n. 4
0
def get_blacklist():
    blklist_txt = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>Blacklisted Users:</font>"
    counter = 0
    all_user_data = GetDB.get_all_user_data(get_memory_db().cursor())
    for i, user in enumerate(all_user_data):
        if int(user[1]) == int(Privileges.BLACKLIST.value):
            blklist_txt += f"<br><font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}'>[{counter}]</font> - {user[0]}"
            counter += 1
    if counter == 0:
        blklist_txt += " The blacklist is empty!"
    return blklist_txt
Esempio n. 5
0
def add_to_blacklist(username):
    all_user_data = GetDB.get_all_user_data(get_memory_db().cursor())
    user_names_list = [x[0] for x in all_user_data]
    if username in user_names_list:
        for user in all_user_data:
            if user[0] == username and user[1] == Privileges.BLACKLIST.value:
                rprint(f"The user: {username} is already in the blacklist.", origin=L_USER_PRIV)
                log(INFO, f"The user: {username} is already in the blacklist.", origin=L_USER_PRIV)
                return False
        if UpdateDB.update_user_privileges(db_conn=get_memory_db(), user_name=username, level=int(Privileges.BLACKLIST.value)):
            return True
    return False
Esempio n. 6
0
def add_to_blacklist(username):
    all_user_data = GetDB.get_all_user_data(get_memory_db().cursor())
    user_names_list = [x[0] for x in all_user_data]
    if username in user_names_list:
        for user in all_user_data:
            if user[0] == username and user[1] == Privileges.BLACKLIST.value:
                log(WARNING,
                    f"Could not add the user: {username} to the blacklist since the user is already in the blacklist.",
                    origin=L_USER_PRIV, error_type=GEN_PROCESS_WARN, print_mode=PrintMode.VERBOSE_PRINT.value)
                return False
        if UpdateDB.update_user_privileges(db_conn=get_memory_db(), user_name=username, level=int(Privileges.BLACKLIST.value)):
            return True
    return False
Esempio n. 7
0
def plugin_privileges_check(command, plugin_name):
    if not gs.mumble_db_string:
        log(CRITICAL,
            f"The JJMumbleBot database has not been initialized, but a user privilege check is trying to access it!",
            origin=L_DATABASE, error_type=GEN_PROCESS_ERR, print_mode=PrintMode.VERBOSE_PRINT.value)
        return -1
    # Retrieve the command information in the database.
    command_data = GetDB.get_plugin_data(db_cursor=get_memory_db().cursor(), plugin_name=plugin_name)
    # Return the command permission level if available.
    if command_data is not None:
        for item in command_data:
            if item[0] == command:
                return int(item[1])
    # Return -1 if the command is not found.
    return -1
Esempio n. 8
0
def plugin_privileges_check(command, plugin_name):
    if not GS.mumble_db_string:
        dprint(
            f"The JJMumbleBot database has not been initialized, but a user privilege check is trying to access it!\nTrying to initialize database...")
        log(CRITICAL,
            f"The JJMumbleBot database has not been initialized, but a user privilege check is trying to access it!\nTrying to initalize database...",
            origin=L_DATABASE)
        return -1
    # Retrieve the command information in the database.
    command_data = GetDB.get_plugin_data(db_cursor=get_memory_db().cursor(), plugin_name=plugin_name)
    # Return the command permission level if available.
    if command_data is not None:
        for item in command_data:
            if item[0] == command:
                return int(item[1])
    # Return -1 if the command is not found.
    return -1
Esempio n. 9
0
    def cmd_cmdsearch(self, data):
        all_data = data.message.strip().split(' ', 1)
        if len(all_data) != 2:
            log(ERROR,
                CMD_INVALID_CMD_SEARCH,
                origin=L_COMMAND,
                error_type=CMD_INVALID_ERR,
                print_mode=PrintMode.VERBOSE_PRINT.value)
            gs.gui_service.quick_gui(
                CMD_INVALID_CMD_SEARCH,
                text_type='header',
                box_align='left',
                user=gs.mumble_inst.users[data.actor]['name'],
                ignore_whisper=True)
            return
        search_query = all_data[1].strip()
        all_cmds = GetDB.get_all_commands(db_cursor=get_memory_db().cursor())
        if not all_cmds:
            gs.gui_service.quick_gui(ERR_DATABASE_CMD,
                                     text_type='header',
                                     text_align='left',
                                     box_align='left')
            return
        cmd_list = [f"{cmd_item[0]}" for cmd_item in all_cmds]
        cmd_ratios = process.extract(search_query, cmd_list)
        match_list = []
        for cmd_item in cmd_ratios:
            if cmd_item[1] > 80 and len(match_list) < 10:
                match_list.append(cmd_item[0])

        match_str = f"Command Search Results for <font color={gs.cfg[C_PGUI_SETTINGS][P_TXT_SUBHEAD_COL]}>{search_query}</font>: "
        if len(match_list) > 0:
            for i, clip in enumerate(match_list):
                match_str += f"<br><font color={gs.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{i + 1}]</font> - {clip}"
        else:
            match_str += "None"
        gs.gui_service.quick_gui(match_str,
                                 text_type='header',
                                 text_align='left',
                                 box_align='left')
        log(INFO,
            INFO_DISPLAYED_CMD_SEARCH,
            origin=L_COMMAND,
            print_mode=PrintMode.VERBOSE_PRINT.value)
Esempio n. 10
0
    def cmd_cmdsearch(self, data):
        all_data = data.message.strip().split(' ', 1)
        if len(all_data) != 2:
            rprint(
                f"Incorrect format! Format: {rutils.get_command_token()}cmdsearch 'command'"
            )
            gs.gui_service.quick_gui(
                f"Incorrect format! Format: {rutils.get_command_token()}cmdsearch 'command'",
                text_type='header',
                box_align='left',
                user=gs.mumble_inst.users[data.actor]['name'],
                ignore_whisper=True)
            return
        search_query = all_data[1].strip()

        all_cmds = GetDB.get_all_commands(db_cursor=get_memory_db().cursor())
        if not all_cmds:
            gs.gui_service.quick_gui(
                "There was an error retrieving the commands from the database.",
                text_type='header',
                text_align='left',
                box_align='left')
            return
        cmd_list = [f"{cmd_item[0]}" for cmd_item in all_cmds]
        file_ratios = process.extract(search_query, cmd_list)
        match_list = []
        for file_item in file_ratios:
            if file_item[1] > 80 and len(match_list) < 10:
                match_list.append(file_item[0])

        match_str = f"Search Results for <font color={gs.cfg[C_PGUI_SETTINGS][P_TXT_SUBHEAD_COL]}>{search_query}</font>: "
        if len(match_list) > 0:
            for i, clip in enumerate(match_list):
                match_str += f"<br><font color={gs.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}>[{i + 1}]</font> - {clip}"
        else:
            match_str += "None"
        gs.gui_service.quick_gui(match_str,
                                 text_type='header',
                                 text_align='left',
                                 box_align='left')
Esempio n. 11
0
def get_all_privileges():
    priv_text = f"<font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_HEAD_COL]}'>All User Privileges:</font>"
    for i, user in enumerate(GetDB.get_all_user_data(get_memory_db().cursor())):
        priv_text += f"<br><font color='{GS.cfg[C_PGUI_SETTINGS][P_TXT_IND_COL]}'>[{user[0]}]</font> - {user[1]}"
    return priv_text
Esempio n. 12
0
 def process_help(db_cursor, plugin_name: str):
     plugin_help_data = GetDB.get_plugin_help(db_cursor=db_cursor,
                                              plugin_name=plugin_name)
     if plugin_help_data:
         return plugin_help_data
     return None
Esempio n. 13
0
def alias_check(alias):
    alias_dict = GetDB.get_alias(db_cursor=get_memory_db().cursor(), alias_name=alias)
    if alias_dict:
        return alias_dict['alias']
    return None
Esempio n. 14
0
def get_all_aliases():
    alias_list = GetDB.get_all_aliases(db_cursor=get_memory_db().cursor())
    if alias_list is not None:
        return alias_list
    log(INFO, "Could not retrieve all the aliases from registered aliases.", origin=L_ALIASES, print_mode=PrintMode.VERBOSE_PRINT.value)
    return []