Example #1
0
def Main():
	cgiEnv = lib_common.CgiEnv()
	pid_as_integer = int(cgiEnv.GetId())

	grph = cgiEnv.GetGraph()

	node_process = lib_common.gUriGen.PidUri(pid_as_integer)

	dict_regex_sql = lib_sql.SqlRegularExpressions()

	arr_props = []

	# TODO: Unfortunately it scans several times the memory process.
	for rgx_key in dict_regex_sql:
		rgx_sql = dict_regex_sql[rgx_key]
		regex_predicate = lib_common.MakeProp(rgx_key)
		arr_props.append(regex_predicate)

		try:
			# https://docs.python.org/3/library/re.html
			# re.MULTILINE | re.ASCII | re.IGNORECASE
			matched_sqls = memory_regex_search.GetRegexMatches(pid_as_integer, rgx_sql, re.IGNORECASE)
		except Exception as exc:
			lib_common.ErrorMessageHtml("Error:%s. Protection ?" % str(exc))

		all_queries_set = set()

		for sql_idx in matched_sqls:
			sql_qry = matched_sqls[sql_idx]
			_process_scanned_sql_query(sql_qry, all_queries_set)

		_generate_from_sql_queries(grph, node_process, regex_predicate, all_queries_set, pid_as_integer)

	cgiEnv.OutCgiRdf("LAYOUT_RECT",arr_props)
Example #2
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    filNam = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    nodeFile = lib_common.gUriGen.FileUri(filNam)

    try:
        # The regular expressions are indexed with a key such as "INSERT", "SELECT" etc...
        # which gives a hint about what the query does, and is transformed into a RDF property.
        # TODO: Store the compiled regular expressions.
        # This creates a dictionary mapping the RDF property to the compiled regular expression.
        dictRegexSQL = lib_sql.SqlRegularExpressions()

        arrProps = []
        for rgxKey in dictRegexSQL:
            rgxSQL = dictRegexSQL[rgxKey]
            rgxProp = lib_common.MakeProp(rgxKey)
            arrProps.append(rgxProp)

            compiledRgx = re.compile(rgxSQL, re.IGNORECASE)

            opFil = open(filNam, 'r')
            for linFil in opFil:
                matchedSqls = compiledRgx.findall(linFil)

                # TODO: For the moment, we just print the query. How can it be related to a database ?
                for sqlQry in matchedSqls:
                    # grph.add( ( node_process, pc.property_rdf_data_nolist1, nodePortalWbem ) )
                    grph.add(
                        (nodeFile, rgxProp, lib_common.NodeLiteral(sqlQry)))

    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Error:%s. Protection ?" % str(exc))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", arrProps)
Example #3
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    fil_nam = cgiEnv.GetId()

    grph = cgiEnv.GetGraph()

    node_file = lib_uris.gUriGen.FileUri(fil_nam)

    try:
        # The regular expressions are indexed with a key such as "INSERT", "SELECT" etc...
        # which gives a hint about what the query does, and is transformed into a RDF property.
        # TODO: Store the compiled regular expressions.
        # This creates a dictionary mapping the RDF property to the compiled regular expression.
        dict_regex_sql = lib_sql.SqlRegularExpressions()

        arr_props = []
        for rgx_key in dict_regex_sql:
            rgx_sql = dict_regex_sql[rgx_key]
            rgx_prop = lib_common.MakeProp(rgx_key)
            arr_props.append(rgx_prop)

            compiled_rgx = re.compile(rgx_sql, re.IGNORECASE)

            op_fil = open(fil_nam, 'r')
            for lin_fil in op_fil:
                matched_sqls = compiled_rgx.findall(lin_fil)

                # TODO: For the moment, we just print the query. How can it be related to a database ?
                for sql_qry in matched_sqls:
                    grph.add((node_file, rgx_prop, lib_util.NodeLiteral(sql_qry)))
            op_fil.close()

    except Exception as exc:
        lib_common.ErrorMessageHtml("Error:%s. Protection ?" % str(exc))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", arr_props)
Example #4
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    pidint = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    node_process = lib_common.gUriGen.PidUri(pidint)

    dictRegexSQL = lib_sql.SqlRegularExpressions()

    arrProps = []

    # TODO: Unfortunately it scans several times the memory process.
    for rgxKey in dictRegexSQL:
        rgxSQL = dictRegexSQL[rgxKey]
        rgxProp = lib_common.MakeProp(rgxKey)
        arrProps.append(rgxProp)

        try:
            # https://docs.python.org/3/library/re.html
            # re.MULTILINE | re.ASCII | re.IGNORECASE
            matchedSqls = memory_regex_search.GetRegexMatches(
                pidint, rgxSQL, re.IGNORECASE)
        except Exception:
            exc = sys.exc_info()[1]
            lib_common.ErrorMessageHtml("Error:%s. Protection ?" % str(exc))

        setQrys = set()

        for sqlIdx in matchedSqls:
            sqlQry = matchedSqls[sqlIdx]
            ProcessScannedSqlQuery(sqlQry, setQrys)

        GenerateFromSqlQrys(grph, node_process, rgxProp, setQrys, pidint)

    cgiEnv.OutCgiRdf("LAYOUT_RECT", arrProps)