(plugin_args=None, **kwargs)
| 164 | |
| 165 | |
| 166 | def main(plugin_args=None, **kwargs): |
| 167 | global plugin_chain |
| 168 | |
| 169 | if not plugin_args: |
| 170 | plugin_args = {} |
| 171 | |
| 172 | # dictionary of all available plugins: {name: module path} |
| 173 | plugin_map = get_plugins() |
| 174 | |
| 175 | # Attempt to catch segfaults caused when certain linktypes (e.g. 204) are |
| 176 | # given to pcapy |
| 177 | faulthandler.enable() |
| 178 | |
| 179 | if not plugin_chain: |
| 180 | logger.error("No plugin selected") |
| 181 | sys.exit(1) |
| 182 | |
| 183 | plugin_chain[0].defrag_ip = kwargs.get("defrag", False) |
| 184 | |
| 185 | # Setup logging |
| 186 | log_format = "%(levelname)s (%(name)s) - %(message)s" |
| 187 | if kwargs.get("verbose", False): |
| 188 | log_level = logging.INFO |
| 189 | elif kwargs.get("debug", False): |
| 190 | log_level = logging.DEBUG |
| 191 | elif kwargs.get("quiet", False): |
| 192 | log_level = logging.CRITICAL |
| 193 | else: |
| 194 | log_level = logging.WARNING |
| 195 | logging.basicConfig(format=log_format, level=log_level) |
| 196 | |
| 197 | # since pypacker handles its own exceptions (loudly), this attempts to keep |
| 198 | # it quiet |
| 199 | logging.getLogger("pypacker").setLevel(logging.CRITICAL) |
| 200 | |
| 201 | if kwargs.get("allcc", False): |
| 202 | # Activate all country code (allcc) mode to display all 3 GeoIP2 country |
| 203 | # codes |
| 204 | dshell.core.geoip.acc = True |
| 205 | |
| 206 | dshell.core.geoip.check_file_dates() |
| 207 | |
| 208 | # If alternate output module is selected, tell each plugin to use that |
| 209 | # instead |
| 210 | if kwargs.get("omodule", None): |
| 211 | try: |
| 212 | # TODO: Create a factory classmethod in the base Output class (e.g. "from_name()") instead. |
| 213 | omodule = import_module("dshell.output."+kwargs["omodule"]) |
| 214 | omodule = omodule.obj |
| 215 | for plugin in plugin_chain: |
| 216 | # TODO: Should we have a single instance of the Output module used by all plugins? |
| 217 | oomodule = omodule() |
| 218 | plugin.out = oomodule |
| 219 | except ImportError as e: |
| 220 | logger.error("Could not import module named '{}'. Use --list-output flag to see available modules".format(kwargs["omodule"])) |
| 221 | sys.exit(1) |
| 222 | |
| 223 | # Check if any user-defined output arguments are provided |
no test coverage detected