

def __init__(self, server=None, conf=None, dummy=False):
    'The :class:`burpui.misc.backend.burp1.Burp` class provides a consistent\n        backend for ``burp-1`` servers.\n\n        It implements the :class:`burpui.misc.backend.interface.BUIbackend` class\n        in order to have consistent data whatever backend is used.\n\n        :param server: ``Burp-UI`` server instance in order to access logger\n                       and/or some global settings\n        :type server: :class:`burpui.server.BUIServer`\n\n        :param conf: Configuration file to use\n        :type conf: str\n\n        :param dummy: Does not instanciate the object (used for development\n                      purpose)\n        :type dummy: boolean\n        '
    if dummy:
        return
    self.client_version = None
    self.server_version = None
    self.app = None
    self.zip64 = False
    self.logger = logging.getLogger('burp-ui')
    if server:
        if hasattr(server, 'zip64'):
            self.zip64 = server.zip64
    self.host = G_BURPHOST
    self.port = int(G_BURPPORT)
    self.burpbin = G_BURPBIN
    self.stripbin = G_STRIPBIN
    self.burpconfcli = G_BURPCONFCLI
    self.burpconfsrv = G_BURPCONFSRV
    self.tmpdir = G_TMPDIR
    self.running = []
    self.defaults = {
        'bport': G_BURPPORT,
        'bhost': G_BURPHOST,
        'burpbin': G_BURPBIN,
        'stripbin': G_STRIPBIN,
        'bconfcli': G_BURPCONFCLI,
        'bconfsrv': G_BURPCONFSRV,
        'tmpdir': G_TMPDIR,
    }
    if conf:
        config = ConfigParser.ConfigParser(self.defaults)
        with codecs.open(conf, 'r', 'utf-8') as fileobj:
            config.readfp(fileobj)
            self.port = self._safe_config_get(config.getint, 'bport', cast=int)
            self.host = self._safe_config_get(config.get, 'bhost')
            bbin = self._safe_config_get(config.get, 'burpbin')
            strip = self._safe_config_get(config.get, 'stripbin')
            confcli = self._safe_config_get(config.get, 'bconfcli')
            confsrv = self._safe_config_get(config.get, 'bconfsrv')
            tmpdir = self._safe_config_get(config.get, 'tmpdir')
            if (tmpdir and os.path.exists(tmpdir) and (not os.path.isdir(tmpdir))):
                self._logger('warning', "'%s' is not a directory", tmpdir)
                tmpdir = G_TMPDIR
            if (confcli and (not os.path.isfile(confcli))):
                self._logger('warning', "The file '%s' does not exist", confcli)
                confcli = None
            if (confsrv and (not os.path.isfile(confsrv))):
                self._logger('warning', "The file '%s' does not exist", confsrv)
                confsrv = None
            if (self.host not in ['127.0.0.1', '::1']):
                self._logger('warning', "Invalid value for 'bhost'. Must be '127.0.0.1' or '::1'. Falling back to '%s'", G_BURPHOST)
                self.host = G_BURPHOST
            if (strip and (not strip.startswith('/'))):
                self._logger('warning', "Please provide an absolute path for the 'stripbin' option. Fallback to '%s'", G_STRIPBIN)
                strip = G_STRIPBIN
            elif (strip and (not re.match('^\\S+$', strip))):
                self._logger('warning', "Incorrect value for the 'stripbin' option. Fallback to '%s'", G_STRIPBIN)
                strip = G_STRIPBIN
            elif (strip and ((not os.path.isfile(strip)) or (not os.access(strip, os.X_OK)))):
                self._logger('warning', "'%s' does not exist or is not executable. Fallback to '%s'", strip, G_STRIPBIN)
                strip = G_STRIPBIN
            if (strip and ((not os.path.isfile(strip)) or (not os.access(strip, os.X_OK)))):
                self._logger('error', "Ooops, '%s' not found or is not executable", strip)
                strip = None
            if (bbin and (not bbin.startswith('/'))):
                self._logger('warning', "Please provide an absolute path for the 'burpbin' option. Fallback to '%s'", G_BURPBIN)
                bbin = G_BURPBIN
            elif (bbin and (not re.match('^\\S+$', bbin))):
                self._logger('warning', "Incorrect value for the 'burpbin' option. Fallback to '%s'", G_BURPBIN)
                bbin = G_BURPBIN
            elif (bbin and ((not os.path.isfile(bbin)) or (not os.access(bbin, os.X_OK)))):
                self._logger('warning', "'%s' does not exist or is not executable. Fallback to '%s'", bbin, G_BURPBIN)
                bbin = G_BURPBIN
            if (bbin and ((not os.path.isfile(bbin)) or (not os.access(bbin, os.X_OK)))):
                self._logger('error', "Ooops, '%s' not found or is not executable", bbin)
                bbin = None
            self.burpbin = bbin
            self.stripbin = strip
            self.burpconfcli = confcli
            self.burpconfsrv = confsrv
            self.tmpdir = tmpdir
    self.parser = Parser(self.burpconfsrv)
    self.family = Burp._get_inet_family(self.host)
    self._test_burp_server_address(self.host)
    try:
        cmd = [self.burpbin, '-v']
        self.client_version = subprocess.check_output(cmd, universal_newlines=True).rstrip().replace('burp-', '')
    except:
        pass
    try:
        cmd = [self.burpbin, '-a', 'l']
        if self.burpconfcli:
            cmd += ['-c', self.burpconfcli]
        for line in subprocess.check_output(cmd, universal_newlines=True).split('\n'):
            result = re.search('^.*Server version:\\s+(\\d+\\.\\d+\\.\\d+)', line)
            if result:
                self.server_version = result.group(1)
                break
    except:
        pass
    self._logger('info', 'burp port: %d', self.port)
    self._logger('info', 'burp host: %s', self.host)
    self._logger('info', 'burp binary: %s', self.burpbin)
    self._logger('info', 'strip binary: %s', self.stripbin)
    self._logger('info', 'burp conf cli: %s', self.burpconfcli)
    self._logger('info', 'burp conf srv: %s', self.burpconfsrv)
    self._logger('info', 'tmpdir: %s', self.tmpdir)
    try:
        self.status()
    except BUIserverException:
        pass

dataset/ETHPy150Open ziirish/burp-ui/burpui/misc/backend/burp1.py Burp.__init__/original