diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index ca395ed9f..5d55cf58b 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -179,7 +179,9 @@ class StatusBar(common.WWrap): scheme += "2https" if dst[1] else "http" r.append("[dest:%s]"%utils.unparse_url(scheme, *self.master.server.config.get_upstream_server.dst[2:])) if self.master.scripts: - r.append("[scripts:%s]"%len(self.master.scripts)) + r.append("[") + r.append(("heading_key", "s")) + r.append("cripts:%s]"%len(self.master.scripts)) # r.append("[lt:%0.3f]"%self.master.looptime) if self.master.stream: @@ -784,8 +786,14 @@ class ConsoleMaster(flow.FlowMaster): else: self.view_flowlist() - def edit_scripts(self, *args, **kwargs): - pass + def edit_scripts(self, scripts): + commands = [x[0] for x in scripts] # remove outer array + if commands == [s.command for s in self.scripts]: + return + + self.unload_scripts() + for command in commands: + self.load_script(command) def loop(self): changed = True @@ -878,7 +886,7 @@ class ConsoleMaster(flow.FlowMaster): self.view_grideditor( grideditor.ScriptEditor( self, - [[i.argv[0]] for i in self.scripts], + [[i.command] for i in self.scripts], self.edit_scripts ) ) diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 086710bc5..343466e2b 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -494,8 +494,11 @@ class FlowMaster(controller.Master): def unload_scripts(self): for s in self.scripts[:]: - s.unload() - self.scripts.remove(s) + self.unload_script(s) + + def unload_script(self, script): + script.unload() + self.scripts.remove(script) def load_script(self, command): """ diff --git a/libmproxy/script.py b/libmproxy/script.py index f5fb6b413..79151f157 100644 --- a/libmproxy/script.py +++ b/libmproxy/script.py @@ -55,6 +55,8 @@ class Script: @classmethod def parse_command(klass, command): + if not command or not command.strip(): + raise ScriptError("Empty script command.") if os.name == "nt": # Windows: escape all backslashes in the path. backslashes = shlex.split(command, posix=False)[0].count("\\") command = command.replace("\\", "\\\\", backslashes)