def settings_ws(data): if data['module'] in modules: try: cls = get_class(data['module']) except (AttributeError, ImportError): send_msg("Settings for that module cannot be modified.", "warning") return try: cls.set_setting(data['key'], data['value']) except Exception as e: send_msg("There was an error updating settings.", "danger") log(str(e), style="danger") else: send_msg("Settings updated.", "success") elif data['module'] == 'redbot.core': try: set_core_setting(data['key'], data['value']) except Exception as e: raise e send_msg("There was an error updating settings.", "danger") log(str(e), style="danger") else: send_msg("Settings updated.", "success") else: send_msg("Selected module does not exist.", "warning")
def log(cls, text: str, style: str = "info") -> None: """ Wrapper for the log utility function, simply adds module name to log call. :param text: The body of the log message. :param style: The CSS class suffix for Bootstrap theming, e.g. info, warning, danger, success, etc. """ from redbot.core.utils import log log(text, cls.name, style)
def admin_ws(data): command = data['command'] if command == 'restart': restart_redbot() elif command == 'clear': from redbot.modules.discovery import clear_targets clear_targets() send_msg("Targets cleared.", "warning") log("Targets cleared.", style="warning") for key in storage.smembers('notes'): storage.delete('notes:' + key) elif command == 'clearlogs': storage.delete('log') send_msg("Logs cleared.", "warning") elif command == 'testattack': if data.get('attack'): r = get_class(data['attack']) else: r = get_random_attack() try: result, targets = r.run_attack() except NoTargetsError: send_msg( "There are no hosts to target! Ensure that discovery is properly configured and has been run " "first.", "danger") log("Test attack {} failed with no hosts to target.".format( r.name), style="danger") except Exception as e: send_msg("Failed running attack module '{}': {}".format(r.name, e), "danger") log("Test attack {} failed with {}".format(r.name, e), style="danger") else: send_msg( "Running attack module '{}' against {} targets.".format( r.name, len(targets)), "success") elif command == 'reload': parse('config.yml') emit('reload')
def nmap(): from redbot.modules.discovery import do_discovery log("Discovery scan invoked from web.", "web") send_msg("Running scan.") do_discovery(force=True)
def push_update(cls, data): if data.get('status') == 'RESULTS': log("Completed nmap scan against " + data['result']['target'], "nmap", "success") socketio.emit('nmap progress', data, broadcast=True)