Ejemplo n.º 1
0
def authenticate():
    """
    Method to authenticate with shiftleft inspect cloud when the required tokens gets passed via
    environment variables
    """
    if is_authenticated():
        return
    sl_org = config.get("SHIFTLEFT_ORG_ID")
    sl_token = config.get("SHIFTLEFT_ACCESS_TOKEN")
    sl_cmd = config.get("SHIFTLEFT_INSPECT_CMD")
    if sl_org and sl_token and sl_cmd:
        inspect_login_args = [
            sl_cmd,
            "auth",
            "--no-auto-update",
            "--no-diagnostic",
            "--org",
            sl_org,
            "--token",
            sl_token,
        ]
        cp = exec_tool(inspect_login_args)
        if cp.returncode != 0:
            LOG.warning(
                "ShiftLeft Inspect authentication has failed. Please check the credentials"
            )
        else:
            LOG.info("Successfully authenticated with inspect cloud")
Ejemplo n.º 2
0
def main():
    # establish a wifi connection
    device_id = config.get(config_file="config/device_config.json",
                           key="device_id")
    device_name = config.get(config_file="config/device_config.json",
                             key="device_name")
    ssid = config.get(config_file="config/device_config.json", key="ssid")
    password = config.get(config_file="config/device_config.json",
                          key="password")
    url = config.get(config_file="config/device_config.json", key="url")

    if ssid in wifi.scan():
        wifi.connect(ssid, password)
        wifi.status()

        while wifi.status():
            gpio.toggle_leds()
            temperature, humidity = gpio.read_sensor()

            print("Temp: {0:.2f}, Humidity {1:.2f}".format(
                temperature, humidity))

            http.emit_sensor(url, device_id, device_name, temperature,
                             humidity)
            sleep(60)
Ejemplo n.º 3
0
def format_issue(kind_id):
    kind = CrashKind.get(id=kind_id)
    crashes = Crash.select().where(Crash.kind_id == kind_id)
    reporter_table = ""
    additional = []
    for c in crashes:
        stack_url = config.get("external_url") + "/crash/" + str(c.id)
        reporter_table += reporter_row.format(
            stack_url=stack_url, **model_to_dict(c)).replace("\n", " ") + "\n"
        if c.description:
            additional.append(c.description)
    v = {
        "stack": crashes[0].stack,
        "type": kind.type,
        "exc_string": crashes[0].exc_string,
        "reporter_table": reporter_table,
        "user_count": len(crashes),
        "app_name": config.get("app_name")
    }
    report = template.format(**v)
    if additional:
        for a in additional:
            report += "\n> ".join([""] + a.splitlines())
            report += "\n\n---\n\n"
    else:
        report += no_info
    title = kind.type + ": " + crashes[0].exc_string
    if len(title) > 400:
        title = title[:400] + "..."
    return title, report
Ejemplo n.º 4
0
def authenticate():
    """
    Method to authenticate with ShiftLeft NG SAST cloud when the required tokens gets passed via
    environment variables
    """
    if is_authenticated():
        return
    sl_org = config.get("SHIFTLEFT_ORG_ID", config.get("SHIFTLEFT_ORGANIZATION_ID"))
    sl_token = config.get("SHIFTLEFT_ACCESS_TOKEN")
    sl_cmd = config.get("SHIFTLEFT_NGSAST_CMD")
    run_uuid = config.get("run_uuid")
    if sl_org and sl_token and sl_cmd and utils.check_command(sl_cmd):
        inspect_login_args = [
            sl_cmd,
            "auth",
            "--no-auto-update",
            "--no-diagnostic",
            "--org",
            sl_org,
            "--token",
            sl_token,
        ]
        cp = exec_tool("NG SAST", inspect_login_args)
        if cp.returncode != 0:
            LOG.warning(
                "ShiftLeft NG SAST authentication has failed. Please check the credentials"
            )
        else:
            LOG.info("Successfully authenticated with NG SAST cloud")
        track({"id": run_uuid, "scan_mode": "ng-sast", "sl_org": sl_org})
Ejemplo n.º 5
0
def fetch_findings(app_name, version, report_fname):
    """
    Fetch findings from the Inspect Cloud
    """
    sl_org = config.get("SHIFTLEFT_ORG_ID")
    sl_org_token = config.get("SHIFTLEFT_ORG_TOKEN")
    findings_api = config.get("SHIFTLEFT_VULN_API")
    findings_list = []
    if sl_org and sl_org_token:
        findings_api = findings_api % dict(
            sl_org=sl_org, app_name=app_name, version=version)
        query_obj = {
            "query": {
                "returnRuntimeData": False,
                "orderByDirection": "VULNERABILITY_ORDER_DIRECTION_DESC",
            }
        }
        headers = {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + sl_org_token,
        }
        try:
            r = requests.post(findings_api, headers=headers, json=query_obj)
            if r.status_code == 200:
                findings_data = r.json()
                if findings_data:
                    findings_list += findings_data.get("vulnerabilities", [])
                    nextPageBookmark = findings_data.get("nextPageBookmark")
                    # Recurse and fetch all pages
                    while nextPageBookmark:
                        LOG.info("Retrieving findings from next page")
                        r = requests.post(
                            findings_api,
                            headers=headers,
                            json={"pageBookmark": nextPageBookmark},
                        )
                        if r.status_code == 200:
                            findings_data = r.json()
                            if findings_data:
                                findings_list += findings_data.get(
                                    "vulnerabilities", [])
                                nextPageBookmark = findings_data.get(
                                    "nextPageBookmark")
                            else:
                                nextPageBookmark = None
                    with open(report_fname, mode="w") as rp:
                        json.dump({"vulnerabilities": findings_list}, rp)
                        LOG.info("Data written to {}, {}".format(
                            report_fname, len(findings_list)))
                return findings_list
            else:
                LOG.warning(
                    "Unable to retrieve findings from Inspect Cloud. Status {}"
                    .format(r.status_code))
                return findings_list
        except Exception as e:
            logging.error(e)
    else:
        return findings_list
Ejemplo n.º 6
0
 def setConfig(self, config, section="MEOS"):
     self.ColorButton.setColor(
         config.get(section, self.confSection + 'Color'))
     self.Grosor.setValue(
         config.getfloat(section, self.confSection + 'lineWidth'))
     self.Linea.setCurrentValue(
         config.get(section, self.confSection + 'lineStyle'))
     self.Marca.setCurrentValue(
         config.get(section, self.confSection + 'marker'))
Ejemplo n.º 7
0
def create_result(tool_name,
                  issue,
                  rules,
                  rule_indices,
                  file_path_list=None,
                  working_dir=None):
    """Method to convert a single issue into result schema with rules

    :param tool_name: tool name
    :param issue: Issues object
    :param rules: List of rules
    :param rule_indices: Indices of referred rules
    :param file_path_list: Full file path for any manipulation
    :param working_dir: Working directory
    """
    WORKSPACE_PREFIX = config.get("WORKSPACE", None)
    if isinstance(issue, dict):
        issue = issue_from_dict(issue)

    issue_dict = issue.as_dict()

    rule, rule_index = create_or_find_rule(tool_name, issue_dict, rules,
                                           rule_indices)

    # Substitute workspace prefix
    # Override file path prefix with workspace
    filename = issue_dict["filename"]
    if working_dir:
        # Issue 5 fix. Convert relative to full path automatically
        if not filename.startswith(working_dir):
            filename = os.path.join(working_dir, filename)
        if WORKSPACE_PREFIX:
            filename = re.sub(r"^" + working_dir, WORKSPACE_PREFIX, filename)

    physical_location = om.PhysicalLocation(
        artifact_location=om.ArtifactLocation(uri=to_uri(filename)))

    add_region_and_context_region(physical_location, issue_dict["line_number"],
                                  issue_dict["code"])
    issue_severity = issue_dict["issue_severity"]
    issue_severity = tweak_severity(tool_name, issue_severity)
    return om.Result(
        rule_id=rule.id,
        rule_index=rule_index,
        message=om.Message(text=issue_dict["issue_text"]),
        level=level_from_severity(issue_severity),
        locations=[om.Location(physical_location=physical_location)],
        properties={
            "issue_confidence": issue_dict["issue_confidence"],
            "issue_severity": issue_severity,
        },
        hosted_viewer_uri=config.get("hosted_viewer_uri", ""),
    )
Ejemplo n.º 8
0
    def __init__(self):
        """初始化"""
        # 个人配置初始化
        utils.mkdir(self.USER_PATH)
        utils.mkdir(self.TEMP_PATH)
        utils.mkdir(self.FACE_ID_PATH)
        print(self.CONF_FILE)
        if os.path.exists(self.CONF_FILE) is False:
            for name in ['config.yml', '八戒.pmdl', '小白.pmdl']:
                utils.cp(CUR_PATH + '/conf/' + name,
                         self.USER_PATH + '/' + name)
        self.CONFIG_DATA = utils.load_conf(self.CONF_FILE)
        # print(self.CONFIG_DATA)
        # 主人初始化状态(status: 1face已确认;2名字已确认)
        self.master = {
            'status': 0,
            'time': 0,
            'face': '',
            'morning': 0,
            'noon': 0,
            'evening': 0,
            'lastask': 0
        }
        self.guest = {
            'status': 0,
            'time': 0,
            'face': '',
            'morning': 0,
            'noon': 0,
            'evening': 0,
            'lastask': 0
        }
        # self.master.update(self.CONFIG_DATA['master'])
        # print(self.master)

        # 初始化语音合成
        self.saying = ''  # 是否正在播放
        self.tts = TTS.get_engine_by_slug(config.get('tts_engine',
                                                     'baidu-tts'))

        # 初始化语音识别
        self.listening = ''  # 是否正在收音
        self.asr = ASR.get_engine_by_slug(
            config.get('asr_engine', 'tencent-asr'))

        # 启动摄像头人脸识别
        self.camera = camera.Face(faceid_path=self.FACE_ID_PATH,
                                  temp_path=self.TEMP_PATH)
        #self.camera.get_camera_face(camera_data=self.CAMERA_DATA, callback=camera.show_camera_face_window)
        self.camera.get_camera_face(camera_data=self.CAMERA_DATA,
                                    callback=self.patrol)
Ejemplo n.º 9
0
def test_override():
    build_break_rules = config.get("build_break_rules").copy()
    golang_cmd = config.get("scan_tools_args_map").get("go")
    assert list(golang_cmd.keys()) == ["source-go", "staticcheck"]
    test_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")
    config.set("SAST_SCAN_SRC_DIR", test_data_dir)
    config.reload()
    # Test if we are able to override the whole dict
    new_rules = config.get("build_break_rules")
    assert build_break_rules != new_rules
    # Test if we are able to override a command
    golang_cmd = config.get("scan_tools_args_map").get("go")
    assert golang_cmd[0] == "echo"
    assert config.get("scan_type") == "credscan,java"
Ejemplo n.º 10
0
    def user_registered(self, user):
        if config.get(user, 'user'):
            self.trigger('send_to_opers', '%s connecting as %s' %
                (config.get(user, 'user'), user.info['nick']))
        else:
            self.trigger('send_to_opers', '%s connecting on port %d' %
                (user.info['nick'], user.saddr[1]))

        self.trigger('welcome', user)
        self.trigger('welcome_version', user)
        self.trigger('isupport', user)

        self.run_command('lusers', user, [])
        self.run_command('motd', user, [])
Ejemplo n.º 11
0
def find_app_name(src, repo_context):
    """
    Method to retrieve the app name for inspect

    :param src: Source directory
    :param repo_context: Repo context
    :return: App name string
    """
    app_name = config.get("SHIFTLEFT_PROJECT_NAME")
    if not app_name:
        app_name = config.get("SHIFTLEFT_APP",
                              repo_context.get("repositoryName"))
    if not app_name:
        app_name = os.path.dirname(src)
    return app_name
Ejemplo n.º 12
0
def is_authenticated():
    """
    Method to check if we are authenticated
    """
    sl_home = config.get("SHIFTLEFT_HOME")
    sl_cmd = config.get("SHIFTLEFT_NGSAST_CMD")
    if utils.check_command(sl_cmd):
        sl_config_json = os.path.join(sl_home, "config.json")
        if os.path.exists(sl_config_json):
            return True
    else:
        sl_org = config.get("SHIFTLEFT_ORG_ID", config.get("SHIFTLEFT_ORGANIZATION_ID"))
        sl_token = config.get("SHIFTLEFT_ACCESS_TOKEN")
        return sl_org is not None and sl_token is not None
    return False
Ejemplo n.º 13
0
def setup_windows():
    from windows import main_window
    main_window.Window()

    winpath = os.path.join(config['execdir'], 'source/gui/windows')
    for fn in os.listdir(winpath):
        if not fn.endswith('_window.py') or fn == 'main_window.py':
            continue

        dir, fn = os.path.split(fn)
        classname = os.path.splitext(fn)[0]

        if config.get('exclude_%s' % classname, False):
            logging.info('Skipping class %s', classname)
            continue

        logging.info('Loading class %s...', classname)
        start = time.time()
        codestr = "from windows import %s\n%s.Window()" % (classname,
                                                           classname)
        try:
            exec codestr
        except Exception, e:
            print 'Error loading window %s' % classname
            TB()

        delta = time.time() - start
        logging.info('   Time = %.03s', delta)
Ejemplo n.º 14
0
def enable_aenea():
    config = lib.config.get_config()
    if config.get("aenea.enabled", False) == False:
        config["aenea.enabled"] = True
        lib.config.save_config()
        print("<<< Aenea enabled, reload required. >>>")
        print("<<< Don't forget, start the server and the client window. >>>")
Ejemplo n.º 15
0
    def _parse_spec(self, spec):
        """Overrides the normal Text class behavior. To handle dictation of
        special characters like / . _
        Unfortunately, I have not found a better place to solve this.

        """
        parts = re.split("\%\([a-z_0-9]+\)s", self._spec)
        if len(parts) > 2:
            raise Exception("SCText only supports one variable, yet.")
        start = len(parts[0])
        end = len(spec) - len(parts[1])
        work = spec[start:end]
        for text, char in specialCharacterTranslations.items():
            work = work.replace(" %s " % text, char)
            work = work.replace(" %s" % text, char)
            work = work.replace("%s " % text, char)
            work = work.replace("%s" % text, char)
        spec = parts[0] + work + parts[1]
        if config.get("aenea.enabled", False) == True:
            return spec
        events = []
        for character in spec:
            if character in self._specials:
                typeable = self._specials[character]
            else:
                typeable = Keyboard.get_typeable(character)
            events.extend(typeable.events(self._pause))
        return events
Ejemplo n.º 16
0
def enable_aenea():
    config = lib.config.get_config()
    if config.get("aenea.enabled", False) == False:
        config["aenea.enabled"] = True
        lib.config.save_config()
        print("<<< Aenea enabled, reload required. >>>")
        print("<<< Don't forget, start the server and the client window. >>>")
Ejemplo n.º 17
0
 def __init__(self, db_password=os.environ.get("DB_PASSWORD")):
     db_config = config.get('DATABASE')
     self.db_host = db_config['host']
     self.db_port = int(db_config['port'])
     self.db_user = db_config['user']
     self.db_database = db_config['dbname']
     self.db_password = str(db_password)
Ejemplo n.º 18
0
    def _parse_spec(self, spec):
        """Overrides the normal Text class behavior. To handle dictation of
        special characters like / . _
        Unfortunately, I have not found a better place to solve this.

        """
        parts = re.split("\%\([a-z_0-9]+\)s", self._spec)
        if len(parts) > 2:
            raise Exception("SCText only supports one variable, yet.")
        start = len(parts[0])
        end = len(spec) - len(parts[1])
        work = spec[start:end]
        for text, char in specialCharacterTranslations.items():
            work = work.replace(" %s " % text, char)
            work = work.replace(" %s" % text, char)
            work = work.replace("%s " % text, char)
            work = work.replace("%s" % text, char)
        spec = parts[0] + work + parts[1]
        if config.get("aenea.enabled", False) == True:
            return spec
        events = []
        for character in spec:
            if character in self._specials:
                typeable = self._specials[character]
            else:
                typeable = Keyboard.get_typeable(character)
            events.extend(typeable.events(self._pause))
        return events
Ejemplo n.º 19
0
 def create_review(self, pull_requests, findings, github_context,
                   report_summary, build_status):
     repo = g.get_repo(github_context.get("repoFullname"))
     for pr in pull_requests:
         revisionId = github_context.get("revisionId")
         summary = "| Tool | Critical | High | Medium | Low | Status |\n"
         summary = summary + "| ---- | ------- | ------ | ----- | ---- | ---- |\n"
         for rk, rv in report_summary.items():
             summary = f'{summary}| {rv.get("tool")} | {rv.get("critical")} | {rv.get("high")} | {rv.get("medium")} | {rv.get("low")} | {rv.get("status")} |\n'
         template = config.get("PR_COMMENT_TEMPLATE")
         recommendation = (
             """Please review the findings from Code scanning alerts before approving this pull request. You can also configure the [build rules](https://slscan.io/en/latest/integrations/tips/#config-file) or add [suppressions](https://slscan.io/en/latest/getting-started/#suppression) to customize this bot :+1:"""
             if build_status == "fail" else "Looks good :heavy_check_mark:")
         body = template % dict(summary=summary,
                                recommendation=recommendation)
         exis_reviews = pr.get_reviews()
         review_comment_made = False
         if exis_reviews:
             for ereview in exis_reviews:
                 if ereview.body == body:
                     review_comment_made = True
         # Only make one comment at any time
         if not review_comment_made:
             pr.create_review(commit=repo.get_commit((revisionId)),
                              body=body,
                              event="COMMENT")
         if build_status == "fail":
             pr.add_to_labels("security findings")
         else:
             pr.remove_from_labels("security findings")
Ejemplo n.º 20
0
    def _parse_spec(self, spec):
        """Overrides the normal Text class behavior. To handle dictation of
        special characters like / . _
        Unfortunately, I have not found a better place to solve this.

        """
        events = []
        try:
            parts = re.split("\%\([a-z_0-9]+\)s", self._spec)
            if len(parts) > 2:
                raise Exception("SCText only supports one variable, yet.")
            start = len(parts[0])
            end = len(spec) - len(parts[1])
            words = spec[start:end]
            words = lib.format.strip_dragon_info(words)
            newText = ""
            for word in words:
                if (newText != "" and newText[-1:].isalnum() and
                        word[-1:].isalnum()):
                    word = " " + word  # Adds spacing between normal words.
                newText += word
            spec = parts[0] + newText + parts[1]
            if config.get("aenea.enabled", False) == True:
                return spec
            for character in spec:
                if character in self._specials:
                    typeable = self._specials[character]
                else:
                    typeable = Keyboard.get_typeable(character)
                events.extend(typeable.events(self._pause))
        except Exception as e:
            print self._spec, parts
            print("Error: %s" % e)
        return events
Ejemplo n.º 21
0
    def banned(self, user, channel):
        ban = False

        deny = config.get(user, 'chan_deny')
        if deny:
            for chan in deny:
                if re.match(chan, channel):
                    ban = True

        allow = config.get(user, 'chan_allow')
        if allow:
            for chan in allow:
                if re.match(chan, channel):
                    ban = False

        return ban
Ejemplo n.º 22
0
def setup_windows():
    from windows import main_window
    main_window.Window()

    winpath = os.path.join(config['execdir'], 'source/gui/windows')
    for fn in os.listdir(winpath):
        if not fn.endswith('_window.py') or fn == 'main_window.py':
            continue

        dir, fn = os.path.split(fn)
        classname = os.path.splitext(fn)[0]

        if config.get('exclude_%s' % classname, False):
            logging.info('Skipping class %s', classname)
            continue

        logging.info('Loading class %s...', classname)
        start = time.time()
        codestr = "from windows import %s\n%s.Window()" % (classname, classname)
        try:
            exec codestr
        except Exception, e:
            print 'Error loading window %s' % classname
            TB()

        delta = time.time() - start
        logging.info('   Time = %.03s', delta)
Ejemplo n.º 23
0
 def send(self, to, content):
     conf = config.get('SMS')
     with SMS() as sms:
         sms.client.messages.create(
                  body=content,
                  from_=conf['from'],
                  to=to
              )
Ejemplo n.º 24
0
    def banish(self):
        if not self.exists:
            return
        make_request(TORRC_PREFIX + self.user, "delete")

        ports = []

        block = get_block({"user": self.user})
        ports.append((block["bind_address"], block["bind_port"]))
        config.get(None, "listen").remove(block)

        block = get_block({"user": self.user, "ssl": 1})
        ports.append((block["bind_address"], block["bind_port"]))
        config.get(None, "listen").remove(block)

        config.write_config()
        return ports
Ejemplo n.º 25
0
 def send(self, to, content):
     conf = config.get('EMAIL_NOTIFICATION')
     with Gmail(conf['account']) as mail:
         msg = MIMEText(content)
         msg['Content-Type'] = conf['content_type']
         msg['Subject'] = conf['title']
         msg['From'] = conf['account']
         msg['To'] = to
         mail.server.sendmail(conf['account'], to, msg.as_string())
Ejemplo n.º 26
0
    def list_chans(self, user, line):
        if not config.get(user, 'oper') or utilities.validate(line, 2):
            return

        allow_chans = config.get(line[1], 'chan_allow', True) or []
        deny_chans = config.get(line[1], 'chan_deny', True) or []

        for chan in allow_chans:
            if chan in deny_chans:
                deny_chans.remove(chan)

        user.srv_notice('%s : [*] Allowed channels:' % (user.info['nick']))
        for chan in allow_chans:
            user.srv_notice('%s : - %s' % (user.info['nick'], chan))

        user.srv_notice('%s : [*] Denied channels:' % (user.info['nick']))
        for chan in deny_chans:
            user.srv_notice('%s : - %s' % (user.info['nick'], chan))
Ejemplo n.º 27
0
def get_block(where):
    for listen in config.get(None, "listen"):
        match = True
        for key in where:
            if key not in listen or listen[key] != where[key]:
                match = False
                break
        if match:
            return listen
Ejemplo n.º 28
0
    def manage_chan(self, user, line, deny=True):
        if not config.get(user, 'oper') or utilities.validate(line, 2):
            return

        allow_chans = Set([])
        deny_chans  = Set([])
        blocks      = []

        for listen in config.get(None, 'listen'):
            if 'user' in listen and listen['user'] == line[1]:
                blocks.append(listen)

        if not blocks:
            user.srv_notice('%s: [!] User not found: %s' % (user.info['nick'], line[1]))
            return

        action = 'Allow'
        if deny:
            action = 'Deny'

        user.srv_notice('%s : [*] %sing channel: %s' % (user.info['nick'], action, line[2]))

        for block in blocks:
            def merge(elem, chans):
                if elem not in block:
                    return
                chans.update(block[elem])

            merge('chan_allow', allow_chans)
            merge('chan_deny', deny_chans)

        if deny:
            allow_chans.discard(line[2])
            deny_chans.add(line[2])
        else:
            allow_chans.add(line[2])
            deny_chans.discard(line[2])

        for block in blocks:
            block['chan_allow'] = list(allow_chans)
            block['chan_deny'] = list(deny_chans)

        config.write_config()
Ejemplo n.º 29
0
def track(track_obj):
    """
    Method to send a track message to the telemetry api
    :param track_obj:
    :return:
    """
    # Check if telemetry is disabled
    disable_telemetry = config.get("DISABLE_TELEMETRY", False)
    if (disable_telemetry == "true" or disable_telemetry == "1"
            or not config.get("TELEMETRY_URL")):
        disable_telemetry = True
    else:
        disable_telemetry = False
    if track_obj and not disable_telemetry:
        try:
            track_obj["tool"] = "@ShiftLeft/scan"
            requests.post(config.get("TELEMETRY_URL"), json=track_obj)
        except Exception:
            LOG.debug("Unable to send telemetry")
Ejemplo n.º 30
0
def discover_packages():
    """
    Simple mechanism for discoverability of the packages we build.

    A discoverable package, and thus potentially buildable, will be assumed as
    any directory name under the packages metadata git repository directory containing
    a yaml file with the same name.
    Considering the example:

    versions
    +-- kernel
    |   +-- kernel.yaml
    +-- libvirt
    |   +-- libvirt.yaml
    |   +-- someother_file_or_directory
    +-- not-a-package
    |   +-- not-following-standards.yaml
    +-- file

    "kernel" and "libvirt" will be discovered, "not-a-package" and "file"
    will not.
    """
    config = CONF.get('common')
    versions_repo_url = config.get('packages_metadata_repo_url')
    versions_repo_name = os.path.basename(
        os.path.splitext(versions_repo_url)[0])
    versions_repo_target_path = os.path.join(config.get('work_dir'),
                                             REPOSITORIES_DIR,
                                             versions_repo_name)
    package_list = []
    try:
        package_list = [
            package for package in os.listdir(versions_repo_target_path)
            if os.path.isdir(os.path.join(versions_repo_target_path, package))
            and os.path.isfile(
                os.path.join(versions_repo_target_path, package, "".join(
                    [package, ".yaml"])))
        ]
    except OSError:
        LOG.error("No packages found in versions repository directory")
        raise

    return package_list
Ejemplo n.º 31
0
 def __init__(self, ip_address, timeout=5):
     """
     Initialize camera object.
     :param ip_address: the camera ip
     :param timeout: timeout of http calls
     """
     self.url = 'http://%s' % ip_address
     self.timeout = timeout
     self.save_all = config.get('save_all_snapshots', False)
     self.count = 0
Ejemplo n.º 32
0
def is_authenticated():
    """
    Method to check if we are authenticated
    """
    sl_home = config.get("SHIFTLEFT_HOME")
    sl_config_json = os.path.join(sl_home, "config.json")
    if os.path.exists(sl_config_json):
        return True
    else:
        LOG.debug("ShiftLeft config {} not found".format(sl_config_json))
Ejemplo n.º 33
0
    def get_code(self,
                 max_lines=config.get("CODE_SNIPPET_MAX_LINES"),
                 tabbed=False):
        """Gets lines of code from a file the generated this issue.

        :param max_lines: Max lines of context to return
        :param tabbed: Use tabbing in the output
        :return: strings of code
        """
        if not self.fname:
            return ""
        lines = []
        max_lines = max(max_lines, 1)
        if not self.snippet_based:
            lmin = max(1, self.lineno - max_lines // 2)
            lmax = lmin + len(self.linerange) + max_lines - 1

            tmplt = "%i\t%s" if tabbed else "%i %s"
            for line in moves.xrange(lmin, lmax):
                text = self._get_code_line(self.fname, line)
                if isinstance(text, bytes):
                    text = text.decode("utf-8", "ignore")

                if not len(text):
                    break
                lines.append(tmplt % (line, text))
            if lines:
                return "".join(lines)
            elif self.code:
                # Validate if the code snippet is in the right format
                orig_lines = self.code.split("\n")
                if orig_lines:
                    orig_first_line = orig_lines[0]
                    firstword = orig_first_line.split(" ", 1)[0]
                    if firstword and str(firstword).isdigit():
                        return self.code
                return ""
            else:
                return ""
        else:
            lineno = self.lineno
            try:
                tmplineno = 1
                with open(self.fname, mode="r") as fp:
                    for aline in fp:
                        if aline.strip() == self.code.strip():
                            lineno = tmplineno
                            # Fix the line number
                            self.lineno = lineno
                            break
                        tmplineno = tmplineno + 1
            except Exception as e:
                LOG.debug(e)
            tmplt = "%i\t%s" if tabbed else "%i %s"
            return tmplt % (lineno, self.code)
Ejemplo n.º 34
0
def should_send_to_aenea():
    """Utility function for determining whether commands should be sent to Aenea.  Commands will be sent if
    Aenea is enabled and the Aenea global context application (the one capturing text on behalf of Aenea) is
    the foreground window."""

    if config.get("aenea.enabled", False) == True:
        win = dragonfly.Window.get_foreground()

        return aenea.global_context.matches(win.executable, win.title, win.handle)
    else:
        return False
Ejemplo n.º 35
0
 def listen(self):
     """收音并识别为文字"""
     if self.listening == '':
         self.listening = str(int(time.time()))
     # Player.play(constants.getData('./media/beep_hi.wav'))
     audio.play(constants.getData('./media/on.wav'))
     hotword_model = constants.getHotwordModel(
         config.get('hotword', 'default.pmdl'))
     # print(hotword_model)
     listener = snowboydecoder.ActiveListener([hotword_model])
     voice = listener.listen(
         silent_count_threshold=config.get('silent_threshold', 15),
         recording_timeout=config.get('recording_timeout', 5) * 4)
     # Player.play(constants.getData('./media/beep_lo.wav'))
     Player.play(constants.getData('./media/off.wav'))
     query = self.asr.transcribe(voice)
     utils.rmdir(voice)
     logging.debug("listen: " + query)
     self.listening = ''
     return query
Ejemplo n.º 36
0
    def user_who(self, user, t, target):
        if hasattr(t, 'name'):
            t = t.name
        else:
            target = self.trigger('find_user', target)
            if not target:
                return

        self.trigger('send_user_who', user, t, target.info['user'],
            target.info['hostname'], config.get(target, 'server_name'),
            target.info['nick'], target.info['realname'])
Ejemplo n.º 37
0
def should_send_to_aenea():
    """Utility function for determining whether commands should be sent to Aenea.  Commands will be sent if
    Aenea is enabled and the Aenea global context application (the one capturing text on behalf of Aenea) is
    the foreground window."""

    if config.get("aenea.enabled", False) == True:
        win = dragonfly.Window.get_foreground()

        return aenea.ProxyPlatformContext('linux').matches(win.executable, win.title, win.handle)
    else:
        return False
Ejemplo n.º 38
0
 def __init__(self, ip_address, timeout=5):
     """
     Initialize camera object.
     :param ip_address: the camera ip
     :param timeout: timeout of http calls
     """
     # self.url = 'http://%s' % ip_address
     self.url = 'http://192.168.0.50/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=foo&user=admin&password='******'save_all_snapshots', False)
     self.count = 0
Ejemplo n.º 39
0
def create_database():
    if engine == PooledSqliteDatabase:
        return
    while True:
        try:
            if engine == PooledMySQLDatabase:
                conn = pymysql.connect(user=config.get('db_user'), password=config.get("db_password"),
                    host=config.get("db_host"), port=int(config.get("db_port")))
            elif engine == PooledPostgresqlDatabase:
                conn = psycopg2.connect(user=config.get('db_user'), password=config.get("db_password"),
                    host=config.get("db_host"), port=int(config.get("db_port")))
        except (pymysql.OperationalError, psycopg2.OperationalError):
            print('db not connected, wait for 5 seconds')
            time.sleep(5)
            continue
        conn.cursor().execute('create database if not exists {} '.format(config.get('db_name')))
        return
Ejemplo n.º 40
0
def suppress_issues(issues):
    """Suppress issues based on the presence of certain tags and ignore logic

    :param issues: List of issues to be checked

    :return Filtered issues, Suppressed list
    """
    suppress_list = []
    filtered_list = []
    supress_markers = config.get("suppress_markers", [])
    for issue in issues:
        suppressed = False
        issue_dict = issue_from_dict(issue).as_dict()
        rule_id = issue_dict.get("test_id")
        filename = issue_dict.get("filename")
        code = issue_dict.get("code", "").replace("\n", " ").replace("\t", " ")
        # Is this rule ignored globally?
        if rule_id in config.ignored_rules:
            suppressed = True
        # Is there an ignore marker
        if not suppressed and code:
            for marker in supress_markers:
                if marker in code:
                    suppressed = True
                    break
        if not suppressed and filename:
            if is_ignored_file(None, file_name=filename):
                suppressed = True
            else:
                for igdir in config.get("ignore_directories"):
                    if filename.startswith(f"{igdir}/"):
                        suppressed = True
                        break
        if suppressed:
            suppress_list.append(issue)
        else:
            filtered_list.append(issue)
    return filtered_list, suppress_list
Ejemplo n.º 41
0
    def create(self):
        if self.exists:
            return
        standard_port = find_sock()
        ssl_port = find_sock([standard_port])

        make_request(TORRC_PREFIX + self.user, "create")
        make_request(TORRC_PREFIX + self.user, "map", 6667, config.get(None, "default_address"), standard_port)
        make_request(TORRC_PREFIX + self.user, "map", 6697, config.get(None, "default_address"), ssl_port)

        config.get(None, "listen").append(
            {"bind_address": config.get(None, "default_address"), "bind_port": standard_port, "user": self.user}
        )

        config.get(None, "listen").append(
            {"bind_address": config.get(None, "default_address"), "bind_port": ssl_port, "user": self.user, "ssl": 1}
        )

        config.write_config()
        return [
            (config.get(None, "default_address"), standard_port, 0),
            (config.get(None, "default_address"), ssl_port, 1),
        ]
Ejemplo n.º 42
0
def import_dynamic_modules():
    global moduleMapping
    config = lib.config.get_config()
    path = dynamics.__path__
    prefix = dynamics.__name__ + "."
    print("Loading dynamic grammar modules:")
    for importer, package_name, _ in pkgutil.iter_modules(path, prefix):
        if package_name not in sys.modules:
            module = importer.find_module(package_name).load_module(
                package_name)
            moduleMapping[module.DYN_MODULE_NAME] = module
            enabled = config.get("dynamics.%s" % module.DYN_MODULE_NAME, False)
            print("    %s" % package_name)
            if enabled == True:
                enable_module(module, useSound=False)
Ejemplo n.º 43
0
def import_dynamic_modules():
    global moduleMapping
    config = lib.config.get_config()
    path = dynamics.__path__
    prefix = dynamics.__name__ + "."
    print("Loading dynamic grammar modules:")
    for importer, package_name, _ in pkgutil.iter_modules(path, prefix):
        if package_name not in sys.modules:
            module = importer.find_module(package_name).load_module(
                package_name)
            moduleMapping[module.DYN_MODULE_NAME] = module
            enabled = config.get("dynamics.%s" % module.DYN_MODULE_NAME, False)
            print("    %s" % package_name)
            if enabled == True:
                enable_module(module, useSound=False)
Ejemplo n.º 44
0
def track(track_obj):
    """
    Method to send a track message to the telemetry api
    :param track_obj:
    :return:
    """
    # Check if telemetry is disabled
    disable_telemetry = config.get("DISABLE_TELEMETRY", False)
    if disable_telemetry == "true" or disable_telemetry == "1":
        disable_telemetry = True
    else:
        disable_telemetry = False
    if track_obj and not disable_telemetry:
        # configure your telemetry api server here
        logging.debug(track_obj)
Ejemplo n.º 45
0
    def spawn(self, user, line):
        if not config.get(user, "oper") or utilities.validate(line, 2):
            return

        def _spawn():
            user.srv_notice("%s : [*] Spawning onion for %s" % (user.info["nick"], line[1]))

            u = GetUser(line[1])
            if not u.exists:
                u.create()
                user.srv_notice("%s : - Added user %s onion: %s" % (user.info["nick"], line[1], u.onion()))
            else:
                user.srv_notice("%s : - User %s already exists!" % (user.info["nick"], line[1]))
            self.thread = None

        if hasattr(self, "thread") and self.thread:
            user.srv_notice("%s : [!] Spawn or banish already in progress." % user.info["nick"])
        else:
            self.thread = threading.Thread(target=_spawn)
            self.thread.start()
Ejemplo n.º 46
0
    def banish(self, user, line):
        if not config.get(user, "oper") or utilities.validate(line, 2):
            return

        def _banish():
            user.srv_notice("%s : [*] Banishing %s!" % (user.info["nick"], line[1]))
            u = GetUser(line[1])
            if u.exists:
                for port in u.banish():
                    self.trigger("close_server_sock", port[0], port[1])
                user.srv_notice("%s : - Banished %s!" % (user.info["nick"], line[1]))
            else:
                user.srv_notice("%s : - User %s does not exist!" % (user.info["nick"], line[1]))
            self.thread = None

        if hasattr(self, "thread") and self.thread:
            user.srv_notice("%s : [!] Spawn or banish already in progress." % user.info["nick"])
        else:
            user.thread = threading.Thread(target=_banish)
            user.thread.start()
Ejemplo n.º 47
0
    def spawn_all(self):
        for server in config.get(None, 'listen'):
            if self.server.sock_by_address(server['bind_address'], server['bind_port']):
                continue

            ssl = False
            if 'ssl' in server:
                ssl = server['ssl']

            s = linechat.Server(User, port=server['bind_port'],
                hostname=server['bind_address'], ssl=ssl)
            self.server.add_sock(s)

        for server in self.server.socks:
            try:
                sock = server.sock.getsockname()
            except:
                return

            if not config.get_listen_by_host_port(sock):
                self.server.rm_sock_by_address(*sock)
Ejemplo n.º 48
0
from os import environ, listdir
from os.path import isfile,join
from glob import glob

from lib.keystone import KeyStone
from lib.nova import Nova
from lib.cinder import Cinder
from lib.neutron import Neutron
from lib import log
from lib import config



#### Get settings from INI
pfd = config.get('yaml_project_dir')
auth_url = 'http://' + config.get('admin_endpoint_ip') + ':35357/v3'
auth_url_v2 = 'http://' + config.get('admin_endpoint_ip') + ':35357/v2.0'
ks_username = config.get('os_username')
ks_password = config.get('os_password')
project_name = config.get('os_project_name')
gateway_id = config.get('gateway_network_id')
ca_bundle = config.get('ca_bundle_file')

### End Settings
### start API's
keystone = KeyStone(auth_url,ks_username,ks_password,project_name)
nova = Nova(auth_url_v2,ks_username,ks_password,project_name,ca_bundle)
cinder = Cinder(auth_url_v2,ks_username,ks_password,project_name,ca_bundle)
neutron = Neutron(auth_url_v2,ks_username,ks_password,project_name,ca_bundle)
Ejemplo n.º 49
0
#!/usr/bin/env python2.7

from keystoneclient.auth.identity import v2
from keystoneclient import session
from novaclient import client
from os import environ
import sys
import yaml
from lib import config
from lib import log


auth_url = 'http://' + config.get('admin_endpoint_ip') + ':35357/v2.0'
ks_username = config.get('os_username')
ks_password = config.get('os_password')
project_name = config.get('os_project_name')
yaml_file = config.get('flavor_yaml_file')
ca_bundle = config.get('ca_bundle_file')


with open(yaml_file) as f:
    flavors = yaml.safe_load(f)
    f.close()

auth = v2.Password(auth_url=auth_url, username=ks_username, password=ks_password, tenant_name=project_name)

sess = session.Session(auth=auth,verify=ca_bundle)

nova = client.Client("2",session=sess)

current = []
Ejemplo n.º 50
0
 def motd(self, user, line):
     self.trigger('motd_start', user)
     self.trigger('motd_text', user, open(config.get(user, 'motd')).readlines())
     self.trigger('motd_end', user)
Ejemplo n.º 51
0
from dragonfly import (
    CompoundRule,
    MappingRule,
    RuleRef,
    Repetition,
    Dictation,
    IntegerRef,
    Grammar,
    Text,  # @UnusedImport
    Key  # @UnusedImport
)

import lib.config
config = lib.config.get_config()
if config.get("aenea.enabled", False) == True:
    from proxy_nicknames import Key, Text  # @Reimport
    import aenea


class SeriesMappingRule(CompoundRule):

    def __init__(self, mapping, extras=None, defaults=None):
        mapping_rule = MappingRule(mapping=mapping, extras=extras,
                                   defaults=defaults, exported=False)
        single = RuleRef(rule=mapping_rule)
        series = Repetition(single, min=1, max=16, name="series")

        compound_spec = "<series>"
        compound_extras = [series]
        CompoundRule.__init__(self, spec=compound_spec,
                              extras=compound_extras, exported=True)
Ejemplo n.º 52
0
    def reload_command(self, user, line):
        if not config.get(user, 'oper'):
            return

        user.srv_notice('%s : [*] Reloading config.' % user.info['nick'])
        self.reload()
Ejemplo n.º 53
0
 def setConfig(self, config, section="MEOS"):
     self.ColorButton.setColor(config.get(section, self.confSection + "Color"))
     self.Grosor.setValue(config.getfloat(section, self.confSection + "lineWidth"))
     self.Linea.setCurrentValue(config.get(section, self.confSection + "lineStyle"))
     self.Marca.setCurrentValue(config.get(section, self.confSection + "marker"))
Ejemplo n.º 54
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from lib import config
import os

config.load()
policies_dir = config.get('global', 'policies_dir')
policies_ext = config.get('global', 'policies_ext')

for f in os.listdir(policies_dir):
    dirname = os.path.join(policies_dir, f)
    if os.path.isdir(dirname):
        for f in os.listdir(dirname):
            if f.endswith(policies_ext):
                filename = os.path.join(dirname, f)
                lines = open(filename).readlines()
                blocks = filter(lambda x: x.startswith('block('), lines)
                if blocks:
                    print filename, 'containes the following block lines:'
                    # write each block rule in new line; [:-1] removes last newline
                    print ''.join(map(lambda x: x.strip() + "\n", blocks))[:-1]
Ejemplo n.º 55
0
 def numeric(self, num, message):
     self.send(':%s %03d %s %s' % (config.get(self, 'server_name'), num,
         self.info['nick'], message))
Ejemplo n.º 56
0
 def srv_notice(self, message):
     self.send(':%s NOTICE %s' % (config.get(self, 'server_name'), message))
Ejemplo n.º 57
0
        "(add|fix) missing space": Key("c-left/3, space, c-right/3"),
        "(delete|remove) (double|extra) (space|whitespace)": Key("c-left/3, backspace, c-right/3"),  # @IgnorePep8
        "(delete|remove) (double|extra) (type|char|character)": Key("c-left/3, del, c-right/3"),  # @IgnorePep8
        # Microphone sleep/cancel started dictation.
        "[<text>] (go to sleep|cancel and sleep) [<text2>]": Function(cancel_and_sleep),  # @IgnorePep8
        # Reload Natlink.
        "reload Natlink": Function(reload_natlink),
    },
    namespace={
        "Key": Key,
        "Text": Text,
    }
)


if config.get("aenea.enabled") == True:
    # Keypresses, to get that working better in Linux.
    grammarCfg.cmd.map.update({
        "press <modifierSingle>": Key("%(modifierSingle)s"),
        "press <modifier1> <pressKey> [<n>]": Key("%(modifier1)s-%(pressKey)s:%(n)d"),  # @IgnorePep8
        "press <modifier1> <modifier2> <pressKey> [<n>]": Key("%(modifier1)s%(modifier2)s-%(pressKey)s:%(n)d"),  # @IgnorePep8
    })


class KeystrokeRule(MappingRule):
    exported = False
    mapping = grammarCfg.cmd.map
    extras = [
        IntegerRef("n", 1, 100),
        Dictation("text"),
        Dictation("text2"),
Ejemplo n.º 58
0
#!/usr/bin/python
from modules.Module import Module

import lib.utilities as utilities
import lib.config as config
import socket
import urllib
import threading

TORRC_PREFIX = config.get(None, "torrc_prefix")


def make_request(*args):
    args = "/".join([str(arg) for arg in args])
    auth = "user:password"
    onion = "127.0.0.1:5000"
    url = "http://%s@%s/onion/%s" % (auth, onion, args)

    while 1:
        try:
            output = urllib.urlopen(url).read()
            break
        except Exception as e:
            print("[!] Request failed: %s, retrying." % e)

    if len(output) > 1:
        return output
    if output == "1":
        return True
    else:
        return False
Ejemplo n.º 59
0
#!/usr/bin/python2.7

from os import environ


from lib import ad as ad
from lib import ks as ks
from lib import log as log
from lib import config as config


auth_url = 'http://' + config.get('admin_endpoint_ip') + ':35357/v3'
ks_username = config.get('os_username')
ks_password = config.get('os_password')
project_name = config.get('os_project_name')
user = config.get('ad_user')
password = config.get('ad_password')
domain = config.get('ad_domain') + '\\'
to_address = config.get('account_mail_to')
host = config.get('ad_host')
ks_ad_group_sync_id = config.get('ks_ad_group_sync_id')

c = ad.connect(host,domain+user,password)
ksclient = ks.connect(auth_url,ks_username,ks_password,project_name)


def sync_users():

    all_users = ad.openstack_users(c)
    ks_users = [u.name for u in ksclient.users.list(group=ks_ad_group_sync_id,enabled=True)]
    ks_users_disabled = [u.name for u in ksclient.users.list(group=ks_ad_group_sync_id,enabled=False)]
Ejemplo n.º 60
0
 def send_to_opers(self, message):
     for user in users:
         if config.get(user, 'oper'):
             user.srv_notice('%s : - %s' % (user.info['nick'], message))