示例#1
0
    def determineBroVersion(self):
        version = None
        bro = self.subst("${bindir}/bro")
        if execute.exists(None, bro):
            (success, output) = execute.captureCmd("%s -v 2>&1" % bro)
            if success:
                version = output[len(output) - 1]

        if not version:
            # Ok if it's already set.
            if "broversion" in self.state:
                return

            util.error("cannot find Bro binary to determine version")

        m = re.search(".* version ([^ ]*).*$", version)
        if not m:
            util.error("cannot determine Bro version [%s]" % version.strip())

        version = m.group(1)
        if version.endswith("-debug"):
            version = version[:-6]

        self.state["broversion"] = version
        self.state["bro"] = self.subst("${bindir}/bro")
示例#2
0
文件: config.py 项目: decanio/broctl
    def determineBroVersion(self):
        version = None
        bro = self.subst("${bindir}/bro")
        if execute.exists(None, bro):
            (success, output) = execute.captureCmd("%s -v 2>&1" % bro)
            if success:
                version = output[len(output)-1]

        if not version:
            # Ok if it's already set.
            if "broversion" in self.state:
                return

            util.error("cannot find Bro binary to determine version")

        m = re.search(".* version ([^ ]*).*$", version)
        if not m:
            util.error("cannot determine Bro version [%s]" % version.strip())

        version = m.group(1)
        if version.endswith("-debug"):
            version = version[:-6]

        self.state["broversion"] = version
        self.state["bro"] = self.subst("${bindir}/bro")
示例#3
0
    def _getBroVersion(self):
        version = ""
        bro = self.subst("${bindir}/bro")
        if execute.exists(None, bro):
            (success, output) = execute.runLocalCmd("%s -v" % bro)
            if success and output:
                version = output[-1]
        else:
            util.error("cannot find Bro binary to determine version")

        m = re.search(".* version ([^ ]*).*$", version)
        if not m:
            util.error("cannot determine Bro version [%s]" % version.strip())

        version = m.group(1)
        # If bro is built with the "--enable-debug" configure option, then it
        # appends "-debug" to the version string.
        if version.endswith("-debug"):
            version = version[:-6]

        return version
示例#4
0
def install(local_only, make_install):
    if config.Config.devmode == "1":
        make_install = True

    config.Config.determineBroVersion()

    manager = config.Config.manager()

    # Delete previously installed policy files to not mix things up.
    policies = [config.Config.policydirsiteinstall, config.Config.policydirsiteinstallauto]

    if make_install:
        policies += [config.Config.subst("${policydir}/broctl")]

    for p in policies:
        if os.path.isdir(p):
            util.output("removing old policies in %s ..." % p, False)
            execute.rmdir(manager, p)
            util.output(" done.")


    util.output("creating policy directories ...", False)
    for p in policies:
        execute.mkdir(manager, p)
    util.output(" done.")

    custom = [(os.path.expanduser(file), "${bindir}", True, False) for file in config.Config.custominstallbin.split()]
    pp = [(os.path.expanduser(file), "${postprocdir}", True, False) for file in config.Config.auxpostprocessors.split()]

    targets = Targets
    if config.Config.devmode == "1":
        targets += TargetsDev

    mandatory = [(src, dst, replace, False) for (src, dst, replace) in targets]
    optional  = [(src, dst, replace, True) for (src, dst, replace) in OptionalTargets]

    if config.Config.standalone == "0":
        mandatory += [("${distdir}/aux/broctl/etc/node.cfg.cluster.in", "${cfgdir}/node.cfg.example", False, False)]
        mandatory += [("${distdir}/aux/broctl/etc/broctl.cfg.cluster.in", "${cfgdir}/broctl.cfg.example", False, False)]
        mandatory += [("${distdir}/aux/broctl/etc/networks.cfg.in", "${cfgdir}/networks.cfg.example", False, True)]
        mandatory += [("${distdir}/aux/broctl/policy/local/cluster.local-manager.bro-template", "${defsitepolicypath}/local-manager.bro", False, True)]
        mandatory += [("${distdir}/aux/broctl/policy/local/cluster.local-worker.bro-template", "${defsitepolicypath}/local-worker.bro", False, True)]
        mandatory += [("${distdir}/aux/broctl/policy/local/cluster.local.bro-template", "${defsitepolicypath}/local.bro", False, True)]
    else:
        mandatory += [("${distdir}/aux/broctl/etc/node.cfg.standalone.in", "${cfgdir}/node.cfg", False, False)]
        mandatory += [("${distdir}/aux/broctl/etc/broctl.cfg.standalone.in", "${cfgdir}/broctl.cfg", False, False)]
        mandatory += [("${distdir}/aux/broctl/etc/networks.cfg.in", "${cfgdir}/networks.cfg", False, True)]
        mandatory += [("${distdir}/aux/broctl/policy/local/standalone.local.bro-template", "${defsitepolicypath}/local.bro", False, True)]

    all_targets = mandatory + optional + custom + pp

    if make_install:
        util.output("creating installation directories ...", False)
        # Install the static parts of the broctl distribution. 
        dirs = Dirs
        if config.Config.devmode == "1":
            dirs += DirsDev

        for (dir, clean) in dirs:
            dir = config.Config.subst(dir)
            if clean:
                execute.rmdir(manager, dir)

            execute.mkdir(manager, dir)

        util.output(" done.")

        # Copy files.
        util.output("installing files ...", False)

        for (src, dst, replace, optional) in all_targets:
            src = config.Config.subst(src)
            dst = config.Config.subst(dst)

            files = glob.glob(src)
            if not files and not optional: 
                util.warn("file does not exist: %s" % src)
                continue

            for file in files:
                (target, subst) = _canonTarget(file, dst)

                if not replace and execute.exists(manager, target):
                    continue

                if subst:
                    # Installation copies to template directory only.
                    # Substitution will be performed later. 
                    target = config.Config.templatedir

                if not execute.install(manager, file, target):
                    continue

        if manager:
            if not execute.mkdir(manager, manager.cwd()):
                util.warn("cannot create %s on manager" % manager.cwd())

        util.output(" done.")

    # Processing the templates by substitung all variables.
    for (src, dst, replace, optional) in all_targets:
        # Doesn't work with globs!

        src = config.Config.subst(src)
        dst = config.Config.subst(dst)
        file = os.path.join(config.Config.templatedir, os.path.basename(src))

        if not execute.exists(manager, file):
            continue

        (target, subst) = _canonTarget(file, dst)

        assert subst

        if not replace and execute.exists(manager, target):
            continue

        if not execute.install(manager, file, target):
            continue

        for line in fileinput.input(target, inplace=1):
            print config.Config.subst(line, make_dest=False),
        fileinput.close()

    # Install local site policy.

    if config.Config.sitepolicypath:
        util.output("installing site policies ...", False)
        dst = config.Config.policydirsiteinstall
        for dir in config.Config.sitepolicypath.split(":"):
            dir = config.Config.subst(dir)
            for file in glob.glob(os.path.join(dir, "*")):
                if execute.isfile(manager, file):
                    execute.install(manager, file, dst)
        util.output(" done.")

    if not config.Config.nodes():
        if config.Config.standalone == "0":
            return

        # The standalone installs default configs. Start over to read those.
        util.output("[second install pass]")
        os.system(config.Config.subst("${bindir}/broctl install"))
        config.Config.readState()
        config.Config._readNodes()
        return

    makeLayout()
    makeAnalysisPolicy()
    makeLocalNetworks()

    current = config.Config.subst(os.path.join(config.Config.logdir, "current"), make_dest=False)
    if not execute.exists(manager, current):
        try:
            os.symlink(manager.cwd(), current)
        except (IOError, OSError), e:
            util.warn("cannot link %s to %s: %s" % (manager.cwd(), current, e))