(self, *args, **kwargs)
| 80 | self.fh.write(self._HTML_HEADER) |
| 81 | |
| 82 | def write(self, *args, **kwargs): |
| 83 | if not self.format_is_set: |
| 84 | if 'clientip' in kwargs: |
| 85 | self.set_format(self._CONNECTION_FORMAT) |
| 86 | else: |
| 87 | self.set_format(self._PACKET_FORMAT) |
| 88 | self.format_is_set = True |
| 89 | |
| 90 | # a template string for data output |
| 91 | colorformat = '<span style="color:%s;">%s</span>' |
| 92 | |
| 93 | # Iterate over the args and try to parse out any raw data strings |
| 94 | rawdata = [] |
| 95 | for arg in args: |
| 96 | if type(arg) == dshell.core.Blob: |
| 97 | if arg.data: |
| 98 | rawdata.append((arg.data, arg.direction)) |
| 99 | elif type(arg) == dshell.core.Connection: |
| 100 | for blob in arg.blobs: |
| 101 | if blob.data: |
| 102 | rawdata.append((blob.data, blob.direction)) |
| 103 | elif type(arg) == dshell.core.Packet: |
| 104 | rawdata.append((arg.pkt.body_bytes, kwargs.get('direction', '--'))) |
| 105 | elif type(arg) == tuple: |
| 106 | rawdata.append(arg) |
| 107 | else: |
| 108 | rawdata.append((arg, kwargs.get('direction', '--'))) |
| 109 | |
| 110 | # Clean up the rawdata into something more presentable |
| 111 | if self.hexmode: |
| 112 | cleanup_func = dshell.util.hex_plus_ascii |
| 113 | else: |
| 114 | cleanup_func = dshell.util.printable_text |
| 115 | for k, v in enumerate(rawdata): |
| 116 | newdata = cleanup_func(v[0]) |
| 117 | newdata = escape(newdata) |
| 118 | rawdata[k] = (newdata, v[1]) |
| 119 | |
| 120 | # Convert the raw data strings into color-coded output |
| 121 | data = [] |
| 122 | for arg in rawdata: |
| 123 | datastring = colorformat % (self.colors.get(arg[1], ''), arg[0]) |
| 124 | data.append(datastring) |
| 125 | |
| 126 | super().write(counter=self.counter, *data, **kwargs) |
| 127 | self.counter += 1 |
| 128 | |
| 129 | def close(self): |
| 130 | self.fh.write(self._HTML_FOOTER) |
no test coverage detected