Beispiel #1
0
    def __init__(self, driver=None, settings=None):
        self.driver = webdriver.Chrome(
            chrome_options=get_chrome_options()) if driver is None else driver
        self.settings = Settings().read() if settings is None else settings
        self.connector = Connector(self.driver, self.settings)

        self.result = defaultdict(lambda: 0)
Beispiel #2
0
def sign(project):
    try:
        project.signjars
    except:
        project.signjars = []

    try:
        project.output
    except:
        print "Nothing to sign."
        return
    if not project.output:
        print "Nothing to sign."
        return
    
    timestamp_flags = "-tsa http://tsa.starfieldtech.com"
    digest_flags = "-digestalg SHA1"
    alias = Settings.get("keystore_name")
    alias = alias if alias else ""

    print "Signing %s..." % project.output
    cmd = "%s -storepass %s %s %s %s %s" % (
        os.path.join(project.javapath,"jarsigner"),
        Settings.get("keystore_pass"),
        timestamp_flags,
        digest_flags,
        project.output,
        alias
    )
    print cmd
    os.system(cmd)

    # sign libs too (TODO: make optional)
    for signjars in project.signjars:
        print "signjars dir: %s" % signjars
        if os.path.isdir(signjars):
            for fn in os.listdir(signjars):
                #if fn.lower().endswith(".%s" % project.bin_ext):
                if fn.lower().endswith(".jar"):
                    #print "Signing %s..." % fn
                    cmd = "%s -storepass %s %s %s %s %s" % (
                        os.path.join(project.javapath, "jarsigner"),
                        Settings.get("keystore_pass"),
                        timestamp_flags,
                        digest_flags,
                        os.path.join(signjars,fn),
                        alias
                    )
                    print cmd
                    os.system(cmd)
        # TODO: if system call returns with error, then return Status.FAILURE, regardless of --strict
        #return Status.FAILURE if Args.option("strict") else Status.UNSUPPORTED

    return Status.SUCCESS
Beispiel #3
0
def update(project):
    try:
        project.makepath = os.path.abspath(
            os.path.expanduser(Settings.get('make_path')))
    except:
        project.makepath = ""
    # make sure theres a make step after cmake

    make_step = Plugin("steps", "make", "makefile")
    conf_step = Plugin("steps", "make", "configure")
    project.clean_commands = [
        "%s clean" % os.path.join(project.makepath, "make")
    ]
    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)
    if conf_step in project.steps:
        project.steps.remove(conf_step)

    i = 0
    for s in project.steps:
        if s.type == "make" and s.name == "cmake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i + 2, make_step)
            else:
                project.steps.insert(i + 1, make_step)
            break
        i += 1
Beispiel #4
0
def update(project):
    try:
        project.makepath = os.path.abspath(os.path.expanduser(Settings.get('make_path')))
    except:
        project.makepath = ""
    # make sure theres a make step after cmake

    make_step = Plugin("steps", "make", "makefile")
    project.clean_commands = ["%s clean" % os.path.join(project.makepath,"make")]
    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)

    i = 0
    for s in project.steps:
        if s.type == "make" and s.name == "cmake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i+2, make_step)
            else:
                project.steps.insert(i+1, make_step)
            break
        i += 1
Beispiel #5
0
def parse_arguments(arguments):
    usage = 'check-translation.py -m <module> -l <lang>'
    parser = OptionParser(usage=usage)
    parser.add_option('-m', '--module', dest='module')
    parser.add_option('-l', '--lang', dest='lang')

    (option, arguments) = parser.parse_args(arguments)

    settings = Settings()

    if option.module and option.lang:
        settings.module = option.module
        settings.lang = option.lang
    else:
        print usage
    return settings
Beispiel #6
0
def make(project):
    import psutil

    # relink a broken tmpfs-based obj dir
    if os.path.islink("obj") and not os.path.exists("obj"):
        os.unlink("obj")
        prefix = "sg-" + os.environ.get("LOGNAME") + "-" + project.name + "-"
        os.symlink(tempfile.mkdtemp(prefix=prefix), "obj")

    try:
        project.makepath = os.path.abspath(os.path.expanduser(Settings.get("make_path")))
    except:
        project.makepath = ""

    try:
        project.makefile_params
    except:
        project.makefile_params = []

    cores = multiprocessing.cpu_count()
    threads = int(cores * 1.5 + 0.5)
    # to prevent ram overusage (and thus HD hits), cap thread count to # GB of ram / 2
    threads = int(min(threads, math.ceil(psutil.virtual_memory().total / 1024 / 1024 / 1024.0) / 1.5))
    project.makefile_params += ["-j" + str(threads)]

    # example makefile params (add in project sg file):
    # makefile_params="CXX=\'clang++\'"
    # makefile_params="CXX=\'gccfilter -c -a g++\'"

    cmdline = [os.path.join(project.makepath, "make")]
    if project.makefile_params:
        cmdline += project.makefile_params

    try:
        os.chdir(project.build_dir)
    except:
        pass

    try:
        subprocess.check_call(cmdline)
    except subprocess.CalledProcessError:
        try:
            if project.build_dir:
                os.chdir("..")
        except:
            pass
        return Status.FAILURE

    try:
        if project.build_dir:
            os.chdir("..")
    except:
        pass

    # os.system("%s%s" %
    #    (os.path.join(project.makepath,"make"),
    #        " %s" % project.makefile_params
    #    )
    # )
    return Status.SUCCESS
Beispiel #7
0
def make(project):
    try:
        project.npmpath = os.path.abspath(os.path.expanduser(Settings.get('npm_path')))
    except:
        project.npmpath = ""

    if os.path.isfile("package.json.ls") or os.path.isfile("package.lson"):
        
        try:
            project.lscpath = os.path.abspath(os.path.expanduser(Settings.get('lsc_path')))
        except:
            project.lscpath = ""
        
        if os.path.isfile("package.json.ls") :
            lscmd = [
                os.path.join(project.lscpath,"lsc"),
                "-jc", "package.json.ls"
            ]
        elif os.path.isfile("package.lson"):
            
            lscmd = [
                os.path.join(project.lscpath,"lsc"),
                "-jc", "package.lson"
            ]

        try:
            call(lscmd)
        except subprocess.CalledProcessError:
            return Status.FAILURE

    #try:
    #    project.npm_params
    #except:
    #    project.npm_params = []

    cmdline = [os.path.join(project.npmpath,"npm"), "install"]
    #if project.npm_params:
    #    cmdline += project.npm_params

    #print " ".join(cmdline)

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #8
0
def make(project):
    try:
        project.npmpath = os.path.abspath(
            os.path.expanduser(Settings.get('npm_path')))
    except:
        project.npmpath = ""

    if os.path.isfile("package.json.ls") or os.path.isfile("package.lson"):

        try:
            project.lscpath = os.path.abspath(
                os.path.expanduser(Settings.get('lsc_path')))
        except:
            project.lscpath = ""

        if os.path.isfile("package.json.ls"):
            lscmd = [
                os.path.join(project.lscpath, "lsc"), "-jc", "package.json.ls"
            ]
        elif os.path.isfile("package.lson"):

            lscmd = [
                os.path.join(project.lscpath, "lsc"), "-jc", "package.lson"
            ]

        try:
            call(lscmd)
        except subprocess.CalledProcessError:
            return Status.FAILURE

    #try:
    #    project.npm_params
    #except:
    #    project.npm_params = []

    cmdline = [os.path.join(project.npmpath, "npm"), "install"]
    #if project.npm_params:
    #    cmdline += project.npm_params

    #print " ".join(cmdline)

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #9
0
def sign(project):
    try:
        project.signjars
    except:
        project.signjars = []

    try:
        project.output
    except:
        print "Nothing to sign."
        return
    if not project.output:
        print "Nothing to sign."
        return

    timestamp_flags = "-tsa http://tsa.starfieldtech.com"
    digest_flags = "-digestalg SHA1"
    alias = Settings.get("keystore_name")
    alias = alias if alias else ""

    print "Signing %s..." % project.output
    cmd = "%s -storepass %s %s %s %s %s" % (os.path.join(
        project.javapath, "jarsigner"), Settings.get("keystore_pass"),
                                            timestamp_flags, digest_flags,
                                            project.output, alias)
    print cmd
    os.system(cmd)

    # sign libs too (TODO: make optional)
    for signjars in project.signjars:
        print "signjars dir: %s" % signjars
        if os.path.isdir(signjars):
            for fn in os.listdir(signjars):
                #if fn.lower().endswith(".%s" % project.bin_ext):
                if fn.lower().endswith(".jar"):
                    #print "Signing %s..." % fn
                    cmd = "%s -storepass %s %s %s %s %s" % (
                        os.path.join(project.javapath, "jarsigner"),
                        Settings.get("keystore_pass"), timestamp_flags,
                        digest_flags, os.path.join(signjars, fn), alias)
                    print cmd
                    os.system(cmd)
        # TODO: if system call returns with error, then return Status.FAILURE, regardless of --strict
        #return Status.FAILURE if Args.option("strict") else Status.UNSUPPORTED

    return Status.SUCCESS
Beispiel #10
0
def make(project):
    try:
        project.sconspath = os.path.abspath(os.path.expanduser(Settings.get('scons_path')))
    except:
        project.sconspath = ""

    os.system(os.path.join(project.sconspath,"scons"))
    return Status.SUCCESS
Beispiel #11
0
def update(project):
    try:
        project.generate
    except:
        project.generate = []
    
    if "premake" in project.generate:
        generate(project) # can throw
    
    try:
        project.makepath = os.path.abspath(os.path.expanduser(Settings.get('make_path')))
    except:
        project.makepath = ""
    # make sure theres a make step after premake

    make_step = Plugin("steps", "make", "makefile")
    conf_step = Plugin("steps", "make", "configure")
    if os.name == "nt":
        msb_step = Plugin("steps", "make", "msbuild")
    project.clean_commands = ["%s clean" % os.path.join(project.makepath,"make")]
    try:
        project.makefile_params
    except:
        project.makefile_params = []
    
    if Args.option("debug"):
        project.makefile_params += ["config=debug"]
    else:
        project.makefile_params += ["config=release"]
    
    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if conf_step in project.steps:
        project.steps.remove(conf_step)
    if os.name == "nt":
        if msb_step in project.steps:
            project.steps.remove(msb_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)

    i = 0
    
    if os.name == "nt":
        make_step = msb_step
        
    for s in project.steps:
        if s.type == "make" and s.name == "premake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i+2, make_step)
            else:
                project.steps.insert(i+1, make_step)
            break
        i += 1

    make_step.call("update", project)
Beispiel #12
0
def compatible(project):
    # always deny compatibility, step can be added only by registered by another other addon or user script
    support = Support.PROJECT | Support.ENVIRONMENT

    #if(Settings.get("keystore_pass") and Settings.get("keystore_name")):
    if Settings.get("keystore_pass"):
        support |= Support.USER

    return support
Beispiel #13
0
def make(project):
    try:
        project.sconspath = os.path.abspath(
            os.path.expanduser(Settings.get('scons_path')))
    except:
        project.sconspath = ""

    os.system(os.path.join(project.sconspath, "scons"))
    return Status.SUCCESS
Beispiel #14
0
def compatible(project):
    # always deny compatibility, step can be added only by registered by another other addon or user script
    support = Support.PROJECT | Support.ENVIRONMENT

    #if(Settings.get("keystore_pass") and Settings.get("keystore_name")):
    if Settings.get("keystore_pass"):
        support |= Support.USER
        
    return support
Beispiel #15
0
def obfuscate(project):
    obf_path = Settings.get("allatori_path")
    if not obf_path:
        return Status.UNSUPPORTED
    obf_path = os.path.abspath(os.path.expanduser(obf_path))
    if not os.path.isfile(obf_path):
        return Status.FAILURE
    os.system("%s -jar %s %s" % (os.path.join(project.javapath, "java"), obf_path, os.path.join(os.getcwd(), "allatori.xml")))
    return Status.SUCCESS
Beispiel #16
0
def obfuscate(project):
    obf_path = Settings.get("allatori_path")
    if not obf_path:
        return Status.UNSUPPORTED
    obf_path = os.path.abspath(os.path.expanduser(obf_path))
    if not os.path.isfile(obf_path):
        return Status.FAILURE
    os.system("%s -jar %s %s" %
              (os.path.join(project.javapath, "java"), obf_path,
               os.path.join(os.getcwd(), "allatori.xml")))
    return Status.SUCCESS
Beispiel #17
0
def make(project):
    try:
        project.gruntpath = os.path.abspath(os.path.expanduser(Settings.get('grunt_path')))
    except:
        project.gruntpath = ""

    if os.path.isfile("Gruntfile.ls"):
        try:
            project.lscpath = os.path.abspath(os.path.expanduser(Settings.get('lsc_path')))
        except:
            project.lscpath = ""
        lscmd = [
            os.path.join(project.lscpath,"lsc"),
            "-c", "Gruntfile.ls"
        ]
        try:
            subprocess.check_call(lscmd)
        except subprocess.CalledProcessError:
            return Status.FAILURE


    #try:
    #    project.grunt_params
    #except:
    #    project.grunt_params = []

    cmdline = [os.path.join(project.gruntpath,"grunt")]
    #if project.grunt_params:
    #    cmdline += project.grunt_params

    #print " ".join(cmdline)

    try:
        subprocess.check_call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #18
0
def make(project):
    try:
        project.bowerpath = os.path.abspath(os.path.expanduser(Settings.get('bower_path')))
    except:
        project.bowerpath = ""

    cmdline = [os.path.join(project.bowerpath,"bower"), "install"]

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #19
0
def make(project):
    try:
        project.yarnpath = os.path.abspath(
            os.path.expanduser(Settings.get('yarn_path')))
    except:
        project.yarnpath = ""

    cmdline = [os.path.join(project.yarnpath, "yarn")]

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #20
0
def make(project):
    try:
        project.bowerpath = os.path.abspath(
            os.path.expanduser(Settings.get('bower_path')))
    except:
        project.bowerpath = ""

    cmdline = [os.path.join(project.bowerpath, "bower"), "install"]

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
def update(project):
    try:
        project.qmake
    except:
        project.qmake = "qmake"
    #project.qmake = Settings.get('qmake')
    #if not project.qmake:
    #    project.qmake = "qmake"

    project.qmakepath = Settings.get('qmake_path')
    if project.qmakepath:
        project.qmakepath = os.path.abspath(project.qmakepath)
    else:
        project.qmakepath = ""

    make_step = Plugin("steps", "make", "makefile")

    try:
        project.makepath
    except:
        project.makepath = ""

    project.clean_commands = [
        "%s clean" % os.path.join(project.makepath, "make")
    ]
    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)

    i = 0
    for s in project.steps:
        if s.type == "make" and s.name == "qmake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i + 2, make_step)
            else:
                project.steps.insert(i + 1, make_step)
            break
        i += 1
Beispiel #22
0
def make(project):

    try:
        project.makepath = os.path.abspath(os.path.expanduser(Settings.get('make_path')))
    except:
        project.makepath = ""

    # TODO: detect a suitable vcvars if the environment isn't init

    cmdline = [os.path.join(project.makepath,"msbuild")]
    cmdline += ["/p:Platform=Win32"]
    if Args.option("debug"):
        cmdline += ["/p:Configuration=Debug"]
    else:
        cmdline += ["/p:Configuration=Release"]
    if project.msbuild_params:
        cmdline += project.msbuild_params

    try:
        os.chdir(project.build_dir)
    except:
        pass
    
    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        try:
            if project.build_dir:
                os.chdir("..")
        except:
            pass
        return Status.FAILURE
    
    try:
        if project.build_dir:
            os.chdir("..")
    except:
        pass

    return Status.SUCCESS
Beispiel #23
0
def update(project):
    try:
        project.qmake
    except:
        project.qmake = "qmake"
    #project.qmake = Settings.get('qmake')
    #if not project.qmake:
    #    project.qmake = "qmake"
        
    project.qmakepath= Settings.get('qmake_path')
    if project.qmakepath:
        project.qmakepath = os.path.abspath(project.qmakepath)
    else:
        project.qmakepath = ""

    make_step = Plugin("steps", "make", "makefile")
    
    try:
        project.makepath
    except:
        project.makepath = ""
        
    project.clean_commands = ["%s clean" % os.path.join(project.makepath,"make")]
    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)

    i = 0
    for s in project.steps:
        if s.type == "make" and s.name == "qmake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i+2, make_step)
            else:
                project.steps.insert(i+1, make_step)
            break
        i += 1
def make(project):
    try:
        project.dockerpath = os.path.abspath(
            os.path.expanduser(Settings.get('docker_path')))
    except:
        project.dockerpath = ""

    #try:
    #    project.sudocmd = os.path.abspath(os.path.expanduser(Settings.get('sudo_command')))
    #except:
    #    project.sudo_command = "sudo"

    cmdline = [
        os.path.join(project.dockerpath, "docker"),
        "-D=true",
        "build",
        "--no-cache",
        "-t=%s" % project.name,
        ".",
    ]

    #try:
    #    call(os.path.join(project.dockerpath,"docker"), stdout=None, stderr=None)
    #except subprocess.CalledProcessError:
    #    pass

    # TODO: only do this next block if current user is not part of docker group
    #  or is not root
    #print "Docker needs root permissions (C-c to cancel)"
    #cmdline = [project.sudo_command] + cmdline
    #project.event("status", "preauth")

    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #25
0
def make(project):
    try:
        project.dockerpath = os.path.abspath(os.path.expanduser(Settings.get('docker_path')))
    except:
        project.dockerpath = ""
    
    #try:
    #    project.sudocmd = os.path.abspath(os.path.expanduser(Settings.get('sudo_command')))
    #except:
    #    project.sudo_command = "sudo"

    cmdline = [
        os.path.join(project.dockerpath,"docker"),
        "-D=true",
        "build",
        "--no-cache",
        "-t=%s"%project.name,
        ".",
    ]

    #try:
    #    call(os.path.join(project.dockerpath,"docker"), stdout=None, stderr=None)
    #except subprocess.CalledProcessError:
    #    pass

    # TODO: only do this next block if current user is not part of docker group
    #  or is not root 
    #print "Docker needs root permissions (C-c to cancel)"
    #cmdline = [project.sudo_command] + cmdline
    #project.event("status", "preauth")
    
    try:
        call(cmdline)
    except subprocess.CalledProcessError:
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #26
0
def parse_arguments(arguments):
    usage = 'export_translation.py  -d <database> -m <module> -l <lang>'
    parser = OptionParser(usage=usage)
    parser.add_option('-u', '--url', dest='url')
    parser.add_option('-d', '--database', dest='database')
    parser.add_option('-m', '--module', dest='module')
    parser.add_option('-l', '--lang', dest='lang')
    parser.add_option('-p', '--path', dest='path')

    (option, arguments) = parser.parse_args(arguments)

    settings = Settings()

    if (option.database or option.url) and option.module and option.lang:
        settings.database = option.database
        settings.module = option.module
        settings.lang = option.lang
        settings.url = option.url
        settings.path = option.path
    else:
        print usage
    return settings
Beispiel #27
0
def parse_arguments(arguments):
    usage = 'translate.py  -m <module> -l <lang>'
    parser = OptionParser(usage=usage)
    parser.add_option('-g', '--generate-tmx', dest='tmx', action="store_true",
        default=False)
    parser.add_option('-m', '--module', dest='module')
    parser.add_option('-l', '--lang', dest='lang')

    (option, arguments) = parser.parse_args(arguments)

    settings = Settings()

    if option.module and option.lang:
        settings.module = option.module
        settings.lang = option.lang
    else:
        print usage

    settings.tmx = False
    if option.tmx:
        settings.tmx = True

    return settings
Beispiel #28
0
def initialize_cortex_instance(keywords, settings, logger_name="script"):
    """ This function is used to initialize a Cortex instance """

    logger = setup_logging(logger_name)

    # Check the existence of the instance_id
    if len(keywords) == 1:
        instance_id = keywords[0]
    else:
        logger.error("[C1-ERROR] No instance ID was given to the script")
        exit(4)

    # Initialiaze settings
    spl = client.connect(app="TA-thehive-cortex",
                         owner="nobody",
                         token=settings["sessionKey"])
    logger.debug("[C5] Connection to Splunk done")
    configuration = Settings(spl, settings, logger)
    logger.debug("[C6] Settings recovered")

    defaults = {
        "MAX_JOBS_DEFAULT": configuration.getCortexJobsMax(),
        "SORT_JOBS_DEFAULT": configuration.getCortexJobsSort()
    }

    # Create the Cortex instance
    (cortex_username,
     cortex_api_key) = configuration.getInstanceUsernameApiKey(instance_id)
    cortex_url = configuration.getInstanceURL(instance_id)
    cortex = Cortex(url=cortex_url,
                    apiKey=cortex_api_key,
                    sid=settings["sid"],
                    logger=logger)
    logger.debug("[C10] Cortex instance created")

    return (cortex, configuration, defaults, logger)
Beispiel #29
0
def create_thehive_instance(instance_id, settings, logger):
    """ This function is used to create an instance of TheHive """
    # Initialize settings
    token = settings["sessionKey"] if "sessionKey" in settings else settings["session_key"]
    spl = client.connect(app="TA-thehive-cortex",owner="nobody",token=token)
    logger.debug("[TH5] Connection to Splunk done")
    configuration = Settings(spl, settings, logger)
    logger.debug("[TH6] Settings recovered")

    defaults = {
        "MAX_CASES_DEFAULT": configuration.getTheHiveCasesMax(),
        "SORT_CASES_DEFAULT": configuration.getTheHiveCasesSort(),
        "MAX_ALERTS_DEFAULT": configuration.getTheHiveAlertsMax(),
        "SORT_ALERTS_DEFAULT": configuration.getTheHiveAlertsSort()
    }

    # Create the TheHive instance
    (thehive_username, thehive_secret) = configuration.getInstanceUsernameApiKey(instance_id)
    thehive_url = configuration.getInstanceURL(instance_id)
    thehive_authentication_type = configuration.getInstanceSetting(instance_id,"authentication_type")
    thehive_proxies = configuration.getInstanceSetting(instance_id,"proxies")
    thehive_cert = configuration.getInstanceSetting(instance_id,"cert")
    thehive_organisation = configuration.getInstanceSetting(instance_id,"organisation")
    thehive_version = configuration.getInstanceSetting(instance_id,"type") 
    thehive = None

    if (thehive_authentication_type == "password"):
        logger.debug("[TH15] TheHive instance will be initialized with a password (not an API key)")
        thehive = TheHive(url=thehive_url, username=thehive_username, password=thehive_secret, proxies=thehive_proxies, cert=thehive_cert, organisation=thehive_organisation, version=thehive_version, sid=settings["sid"], logger=logger)
    elif (thehive_authentication_type == "api_key"):
        logger.debug("[TH16] TheHive instance will be initialized with an API Key (not a password)")
        thehive = TheHive(url=thehive_url, apiKey=thehive_secret, proxies=thehive_proxies, cert=thehive_cert, organisation=thehive_organisation, version=thehive_version, sid=settings["sid"], logger=logger)
    else:
        logger.error("[TH20-ERROR] WRONG_AUTHENTICATION_TYPE - Authentication type is not one of the expected values (password or api_key), given value: "+thehive_authentication_type)
        exit(20)

    return (thehive, configuration, defaults, logger) 
Beispiel #30
0
def make(project):

    for folder in (project.classdir, project.output_path):
        try:
            os.mkdir(os.path.join(os.getcwd(), folder))
        except OSError:
            pass

    classpath = ""
    # classpathlist = os.pathsep.join(project.classpath)

    for entry in project.classpath:
        if os.path.isfile(entry):
            if classpath:
                classpath += os.pathsep + entry
            else:
                classpath = entry
            continue
        for (path, dirs, files) in os.walk(os.path.join(os.getcwd(), entry)):
            for fn in files:
                if fn.lower().endswith(".jar"):
                    rel_path = os.path.relpath(path, fn)
                    rel_path = rel_path[len(os.pardir) + len(os.sep) : len(rel_path)]
                    if classpath:
                        classpath = os.pathsep.join((classpath, os.path.join(rel_path, fn)))
                    else:
                        classpath = os.path.join(rel_path, fn)

    if classpath:
        classpath = os.pathsep.join((classpath, os.pathsep.join(project.classpath)))
    else:
        classpath = os.pathsep.join(project.classpath)

    sourcepath = ""

    for entry in project.sourcepath:
        if os.path.isfile(entry):
            if sourcepath:
                sourcepath = sourcepath + os.linesep + os.path.join(rel_path, fn)
            else:
                sourcepath = os.path.join(rel_path, fn)
            continue
        for (path, dirs, files) in os.walk(os.path.join(os.getcwd(), entry)):
            for fn in files:
                for ext in project.src_ext:
                    if fn.lower().endswith(".%s" % ext):
                        rel_path = os.path.relpath(path, fn)
                        rel_path = rel_path[len(os.pardir) + len(os.sep) : len(rel_path)]
                        if sourcepath:
                            sourcepath = "%s %s" % (sourcepath, os.path.join(rel_path, fn))
                        else:
                            sourcepath = os.path.join(rel_path, fn)

    project.javapath = Settings.get("java_path")
    if project.javapath:
        project.javapath = os.path.abspath(project.javapath)
    else:
        project.javapath = ""

    # if project.javapath:
    #    if project.javapath[-1] != os.sep and os.altsep and Settings.get('java_path')[-1] != os.altsep:
    #        project.javapath += os.sep
    # else:
    #    project.javapath = ""

    project.output = os.path.join(project.output_path, project.name + ".jar")

    # TODO: boostrap class path
    # removed: -source 1.6 -target 1.6
    misc_params = " ".join(project.javac_params)
    os.system(
        "%s %s -d %s %s -cp %s"
        % (os.path.join(project.javapath, "javac"), misc_params, project.classdir, sourcepath, classpath)
    )
    os.system(
        "%s cmf %s %s -C %s ."
        % (os.path.join(project.javapath, "jar"), project.manifest, project.output, project.classdir)
    )
    # TODO wrap stdout from above commands and detect errors

    if not os.path.isfile(project.output):
        return Status.FAILURE

    return Status.SUCCESS
Beispiel #31
0
def create_cortex_instance(instance_id, settings, logger):
    """ This function is used to create an instance of TheHive """
    # Initialize settings
    token = settings["sessionKey"] if "sessionKey" in settings else settings[
        "session_key"]
    spl = client.connect(app="TA-thehive-cortex", owner="nobody", token=token)
    logger.debug("[C5] Connection to Splunk done")
    configuration = Settings(spl, settings, logger)
    logger.debug("[C6] Settings recovered")

    defaults = {
        "MAX_JOBS_DEFAULT": configuration.getCortexJobsMax(),
        "SORT_JOBS_DEFAULT": configuration.getCortexJobsSort()
    }

    # Create the Cortex instance
    (cortex_username,
     cortex_secret) = configuration.getInstanceUsernameApiKey(instance_id)
    cortex_url = configuration.getInstanceURL(instance_id)
    cortex_authentication_type = configuration.getInstanceSetting(
        instance_id, "authentication_type")
    cortex_proxies = configuration.getInstanceSetting(instance_id, "proxies")
    cortex_cert = configuration.getInstanceSetting(instance_id, "client_cert")
    cortex_cert = None if cortex_cert == "-" else cortex_cert
    cortex_verify = configuration.getInstanceSetting(instance_id, "verify")
    cortex_organisation = configuration.getInstanceSetting(
        instance_id, "organisation")
    cortex_version = configuration.getInstanceSetting(instance_id, "type")
    cortex = None

    if (cortex_authentication_type == "password"):
        logger.error(
            "[C7-ERROR] Cortex instance will be initialized with a password (not an API key) - This is not supported for Cortex"
        )
    elif (cortex_authentication_type == "api_key"):
        logger.debug(
            "[C8] Cortex instance will be initialized with an API Key (not a password)"
        )
        cortex = Cortex(url=cortex_url,
                        apiKey=cortex_secret,
                        sid=settings["sid"],
                        logger=logger)
    else:
        logger.error(
            "[C9-ERROR] WRONG_AUTHENTICATION_TYPE - Authentication type is not one of the expected values (password or api_key), given value: "
            + cortex_authentication_type)
        exit(20)

    return (cortex, configuration, defaults, logger)
Beispiel #32
0
setdefaultencoding = getattr(sys, "setdefaultencoding")

if setdefaultencoding:
    setdefaultencoding("utf8")

# init flask app ---begin

from flask import Flask, g, request, Response, url_for, redirect
import os

from flask.ext.bootstrap import Bootstrap
from common import cacheManager, Settings
from werkzeug.routing import BaseConverter

Settings.setOptions(configFile="setting")


class RegexConverter(BaseConverter):
    def __init__(self, map, *args):
        self.map = map
        self.regex = args[0]


app = Flask(__name__, template_folder="_templates", static_folder="_static")
app.config["SECRET_KEY"] = "123456"
app.url_map.converters["regex"] = RegexConverter
app.debug = True


bootstrap = Bootstrap(app)
Beispiel #33
0
def create_domains():
    objid = User.add_root_domain(domain="<root>")
    Settings.accounts["root_domain_id"] = str(objid)
    Settings.save()
def make(project):

    for folder in (project.classdir, project.output_path):
        try:
            os.mkdir(os.path.join(os.getcwd(), folder))
        except OSError:
            pass

    classpath = ""
    #classpathlist = os.pathsep.join(project.classpath)

    for entry in project.classpath:
        if os.path.isfile(entry):
            if classpath:
                classpath += os.pathsep + entry
            else:
                classpath = entry
            continue
        for (path, dirs, files) in os.walk(os.path.join(os.getcwd(), entry)):
            for fn in files:
                if fn.lower().endswith(".jar"):
                    rel_path = os.path.relpath(path, fn)
                    rel_path = rel_path[len(os.pardir) +
                                        len(os.sep):len(rel_path)]
                    if classpath:
                        classpath = os.pathsep.join(
                            (classpath, os.path.join(rel_path, fn)))
                    else:
                        classpath = os.path.join(rel_path, fn)

    if classpath:
        classpath = os.pathsep.join(
            (classpath, os.pathsep.join(project.classpath)))
    else:
        classpath = os.pathsep.join(project.classpath)

    sourcepath = ""

    for entry in project.sourcepath:
        if os.path.isfile(entry):
            if sourcepath:
                sourcepath = sourcepath + os.linesep + os.path.join(
                    rel_path, fn)
            else:
                sourcepath = os.path.join(rel_path, fn)
            continue
        for (path, dirs, files) in os.walk(os.path.join(os.getcwd(), entry)):
            for fn in files:
                for ext in project.src_ext:
                    if fn.lower().endswith(".%s" % ext):
                        rel_path = os.path.relpath(path, fn)
                        rel_path = rel_path[len(os.pardir) +
                                            len(os.sep):len(rel_path)]
                        if sourcepath:
                            sourcepath = "%s %s" % (sourcepath,
                                                    os.path.join(rel_path, fn))
                        else:
                            sourcepath = os.path.join(rel_path, fn)

    project.javapath = Settings.get('java_path')
    if project.javapath:
        project.javapath = os.path.abspath(project.javapath)
    else:
        project.javapath = ""

    #if project.javapath:
    #    if project.javapath[-1] != os.sep and os.altsep and Settings.get('java_path')[-1] != os.altsep:
    #        project.javapath += os.sep
    #else:
    #    project.javapath = ""

    project.output = os.path.join(project.output_path, project.name + ".jar")

    # TODO: boostrap class path
    # removed: -source 1.6 -target 1.6
    misc_params = " ".join(project.javac_params)
    os.system("%s %s -d %s %s -cp %s" %
              (os.path.join(project.javapath, "javac"), misc_params,
               project.classdir, sourcepath, classpath))
    os.system("%s cmf %s %s -C %s ." %
              (os.path.join(project.javapath, "jar"), project.manifest,
               project.output, project.classdir))
    # TODO wrap stdout from above commands and detect errors

    if not os.path.isfile(project.output):
        return Status.FAILURE

    return Status.SUCCESS
def update(project):
    try:
        project.generate
    except:
        project.generate = []

    if "premake" in project.generate:
        generate(project)  # can throw

    try:
        project.makepath = os.path.abspath(
            os.path.expanduser(Settings.get('make_path')))
    except:
        project.makepath = ""
    # make sure theres a make step after premake

    make_step = Plugin("steps", "make", "makefile")
    conf_step = Plugin("steps", "make", "configure")
    if os.name == "nt":
        msb_step = Plugin("steps", "make", "msbuild")
    project.clean_commands = [
        "%s clean" % os.path.join(project.makepath, "make")
    ]
    try:
        project.makefile_params
    except:
        project.makefile_params = []

    if Args.option("debug"):
        project.makefile_params += ["config=debug"]
    else:
        project.makefile_params += ["config=release"]

    clean_step = Plugin("steps", "clean", "clean")
    if make_step in project.steps:
        project.steps.remove(make_step)
    if conf_step in project.steps:
        project.steps.remove(conf_step)
    if os.name == "nt":
        if msb_step in project.steps:
            project.steps.remove(msb_step)
    if clean_step in project.steps:
        project.steps.remove(clean_step)

    i = 0

    if os.name == "nt":
        make_step = msb_step

    for s in project.steps:
        if s.type == "make" and s.name == "premake":
            # TODO: check for user support (because of -r flag)
            if clean.clean.compatible(project) & Support.USER:
                project.steps.insert(i, clean_step)
                project.steps.insert(i + 2, make_step)
            else:
                project.steps.insert(i + 1, make_step)
            break
        i += 1

    make_step.call("update", project)
Beispiel #36
0
class PopUpper:
    def __init__(self, driver=None, settings=None):
        self.driver = webdriver.Chrome(
            chrome_options=get_chrome_options()) if driver is None else driver
        self.settings = Settings().read() if settings is None else settings
        self.connector = Connector(self.driver, self.settings)

        self.result = defaultdict(lambda: 0)

    def pop_up_ads(self):
        ads_container = self.driver.find_element_by_css_selector(
            "div.order-items")
        # here we exclude the first and the last row, since those are just table header and footer
        ads_rows = ads_container.find_elements_by_css_selector("a.item")
        if len(ads_rows) == 0:
            warning = "No ads found for this account"
            logging.warning(warning)
            self.result["warning"] = warning
            return self.result

        ads_links = [r.get_attribute("href") for r in ads_rows]
        for ad_link in ads_links:
            self.driver.get(ad_link)
            try:
                pop_up_btn = self.driver.find_element_by_class_name("jump")
            except NoSuchElementException:
                # should not happen..., button was not found at all.., maybe selectors where changed or whatever
                self.result["internal_error"] += 1

            if "grayout" in pop_up_btn.get_attribute("class"):
                self.result["already_popped_up"] += 1
            else:
                # yeah :)
                pop_up_btn.click()
                # let the request to be sent, before we continue in a loop
                try:
                    WebDriverWait(
                        self.driver,
                        self.settings.getint("Misc", "alert_timeout")
                    ).until(
                        expected_conditions.alert_is_present(),
                        'Timed out waiting for confirmation popup to appear.')

                    alert = self.driver.switch_to_alert()
                    alert.accept()
                    logging.info("alert accepted")
                    self.result["popped_up"] += 1
                except TimeoutException:
                    self.result["pop_up_timeout"] += 1

        return self.result

    def run(self):
        try:
            self.connector.login()
            res = self.pop_up_ads()
            self.connector.logout()
        except:
            raise
        finally:
            self.driver.close()
        return res