Ejemplo n.º 1
0
def DisplayHtmlTextHeader(page_title):
    """
	This is the common Survol header, ideally for all HTML documents.
	"""

    lib_util.WrtHeader('text/html')
    WrtAsUtf("<head>")

    # TODO: Encode HTML special characters.
    WrtAsUtf("<title>%s</title>" % page_title)

    # The href must be absolute so it will work with any script.
    # We must calculate its prefix.
    # In the mean time, this solution adapts to our three kind of different hosting types:
    # - OVH mutialised hosting, with a specific CGI script survol.cgi
    # - With the Python class HttpServer as Web server.
    # - Hosted with Apache.

    WrtAsUtf("""
		<link rel='stylesheet' type='text/css' href=/ui/css/html_exports.css>
		<link rel='stylesheet' type='text/css' href='/survol/www/css/html_exports.css'>
		<link rel='stylesheet' type='text/css' href='../survol/www/css/html_exports.css'>
		""")

    WrtAsUtf('</head>')
Ejemplo n.º 2
0
def MainNoJinja():
    lib_util.WrtHeader('text/html')
    lib_export_html.DisplayHtmlTextHeader("Configuration")

    WrtAsUtf("""
    <body><h2>Edit Survol configuration</h2>
    """)

    WrtAsUtf("""
    <form method="post" action="edit_configuration.py" name="ServerConfiguration">
    <table border="0">
    <tr>
    <td>CGI server port number:</td>
    <td>&nbsp;<input name="server_port" value="8000"></td>
    </tr>
    <tr>
    <td>Bookmarks file or URL:</td>
    <td>&nbsp;<input name="bookmark_url" value="bookmarks.htm"></td>
    </tr>
    <tr>
    <td>HTML Jinja2 templates:</td>
    <td><input type="checkbox" name="html_jinja2"></td>
    </tr>
    <tr>
    <td colspan="2"><input value="Submit configuration" name="Hello" type="submit"></td>
    </tr>
    </table>
    </form>
    """)

    htmlFooter = "".join(lib_export_html.DisplayHtmlTextFooter())
    WrtAsUtf(htmlFooter)

    WrtAsUtf("</body></html>")
Ejemplo n.º 3
0
def Main():
    lib_export_html.DisplayHtmlTextHeader("Configuration")

    WrtAsUtf("""
    <body><h2>Edit Survol configuration</h2>
    """)

    WrtAsUtf("""
    <form method="post" action="edit_configuration.py" name="ServerConfiguration">
    <table border="0">
    <tr>
    <td>CGI server port number:</td>
    <td><input name="server_port" value="8000"></td>
    </tr>
    <tr>
    <td>Bookmarks file or URL:</td>
    <td><input name="bookmark_url" value="bookmarks.htm"></td>
    </tr>
    <tr>
    <td colspan="2"><input value="Submit configuration" name="Hello" type="submit"></td>
    </tr>
    </table>
    </form>
    """)

    lib_export_html.DisplayHtmlTextFooter()

    #WrtAsUtf('<br><a href="edit_credentials.py">Credentials</a>')
    #WrtAsUtf('<br><a href="edit_configuration.py">Configuration</a>')

    #urlIndex = lib_exports.UrlWWW("index.htm")
    #WrtAsUtf('<br><a href="' + urlIndex + '">Return to Survol</a>')

    WrtAsUtf("</body></html>")
Ejemplo n.º 4
0
    def main_jinja():
        THIS_DIR = os.path.dirname(os.path.abspath(__file__))
        template_file_name = "www/edit_credentials.template.htm"

        # Create the jinja2 environment.
        # Notice the use of trim_blocks, which greatly helps control whitespace.
        jinja2 = lib_util.GetJinja2()
        jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(THIS_DIR), trim_blocks=True)
        jinja_template = jinja_env.get_template(template_file_name)

        ordered_map = collections.OrderedDict()
        for cred_type in sorted(cred_map):
            sub_ordered_map = collections.OrderedDict()
            for cred_nam in sorted(cred_map[cred_type]):
                sub_ordered_map[cred_nam] = cred_map[cred_type][cred_nam]
            ordered_map[cred_type] = sub_ordered_map

        jinja_render = jinja_template.render(
            page_title=page_title,
            currHostNam=curr_host_nam,
            currHostAddr=curr_host_addr,
            addrRemote=addr_remote,
            credMap=ordered_map,
            credTypeList=cred_type_list )
        lib_util.WrtHeader('text/html')
        WrtAsUtf(jinja_render)
Ejemplo n.º 5
0
def Grph2HtmlJinja(theCgi, topUrl, error_msg, isSubServer, gblCgiEnvList):
    this_dir = os.path.dirname(os.path.abspath(__file__))
    template_file_name = "www/export_html.template.htm"

    # The current URL is used to calculate the base href.
    current_uri = lib_util.RequestUri()

    parsed_url = lib_util.survol_urlparse(current_uri)
    path_url = parsed_url.path

    # Something like "/survol" or "survol/sources_types"
    url_dir = os.path.dirname(path_url)

    num_slashes = len(url_dir.split("/")) - 2
    base_href = ("../" * num_slashes) + "www/"

    # Create the jinja2 environment.
    # Notice the use of trim_blocks, which greatly helps control whitespace.
    jinja2 = lib_util.GetJinja2()
    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(this_dir),
                                   trim_blocks=True)
    jinja_template = jinja_env.get_template(template_file_name)

    script_information_html = "".join(
        _script_information_html_iterator(theCgi, gblCgiEnvList))
    object_information_html = "".join(
        _object_information_html_iterator(theCgi))

    errors_table_html = "".join(_write_errors_no_jinja(error_msg, isSubServer))

    dictClassSubjPropObj = _create_objects_list(theCgi.m_graph)

    all_objects_list = []
    for (urlClass_with_mode, entity_graphic_class, colorClass,
         dictSubjPropObj) in _objects_triplets(dictClassSubjPropObj):
        one_class_html = "".join(
            _display_class_objects_no_jinja(dictSubjPropObj))
        all_objects_list.append((urlClass_with_mode, entity_graphic_class,
                                 colorClass, one_class_html))

    parameters_edition_html = "".join(
        _parameters_edition_html_iterator(theCgi))

    scripts_tree_html = "".join(_scripts_tree_html_iterator(theCgi))

    list_other_urls = _other_urls(topUrl)
    html_cim_urls = "".join(_cim_urls_html_iterator())

    jinja_render = jinja_template.render(
        base_href=base_href,
        page_title=theCgi.m_page_title,
        script_information=script_information_html,
        object_information=object_information_html,
        errors_table_html=errors_table_html,
        all_objects_list=all_objects_list,
        parameters_edition_html=parameters_edition_html,
        scripts_tree_html=scripts_tree_html,
        list_other_urls=list(list_other_urls),
        html_cim_urls=html_cim_urls)
    WrtAsUtf(jinja_render)
Ejemplo n.º 6
0
def WriteErrors(error_msg, isSubServer):
    if error_msg or isSubServer:
        # TODO: Use style-sheets.
        WrtAsUtf('<table border="0">')

        if error_msg:
            WrtAsUtf(
                '<tr><td bgcolor="#DDDDDD" align="center" color="#FF0000"><b></b></td></tr>'
            )
            WrtAsUtf(
                '<tr><td bgcolor="#DDDDDD"><b>ERROR MESSAGE:%s</b></td></tr>' %
                error_msg)

        if isSubServer:
            WrtAsUtf('<tr><td><a href="' + lib_exports.ModedUrl("stop") +
                     '">Stop subserver</a></td></tr>')
        WrtAsUtf(" </table><br>")
Ejemplo n.º 7
0
def display_html_text_header(page_title):
    """
    This is the common Survol header, ideally for all HTML documents.
    """
    WrtAsUtf("""
    <head>
        <title>%s</title>
        <link rel='stylesheet' type='text/css' href='/survol/www/css/html_exports.css'>
        <link rel='stylesheet' type='text/css' href='../survol/www/css/html_exports.css'>
    </head>
    """ % page_title)
Ejemplo n.º 8
0
    def main_no_jinja():
        """Simple HTML page if jinja2 is not installed."""
        lib_util.WrtHeader('text/html')
        lib_export_html.display_html_text_header(page_title)

        WrtAsUtf("""
        <body><h2>%s</h2>
        """ % page_title)

        WrtAsUtf("""
        <table border="1" width='100%%'>
        <tr><td><b>Host name</b></td><td>%s</td></tr>
        <tr><td><b>Host address</b></td><td>%s</td></tr>
        <tr><td><b>Remote address</b></td><td>%s</td></tr>
        """ % (curr_host_nam, curr_host_addr, addr_remote))

        WrtAsUtf("""<table border="1" width='100%%'>""")
        if cred_map:
            _form_update_credentials_no_jinja(form_action, cred_map)

        _form_insert_credentials_no_jinja(form_action, cred_type_list)
        WrtAsUtf("""</table>""")

        html_footer = "".join(lib_export_html.display_html_text_footer())
        WrtAsUtf(html_footer)

        WrtAsUtf("</body></html>")
Ejemplo n.º 9
0
def MainNoJinja(page_title,currHostNam,currHostAddr,addrRemote,credMap,formAction,credTypeList):
    lib_util.WrtHeader('text/html')
    lib_export_html.DisplayHtmlTextHeader(page_title)

    WrtAsUtf("""
    <body><h2>%s</h2>
    """ % page_title)

    WrtAsUtf("""
    <table border="1" width='100%%'>
    <tr><td><b>Host name</b></td><td>%s</td></tr>
    <tr><td><b>Host address</b></td><td>%s</td></tr>
    <tr><td><b>Remote address</b></td><td>%s</td></tr>
    """ %(currHostNam,currHostAddr,addrRemote))

    WrtAsUtf("""<table border="1" width='100%%'>""")
    if credMap:
        FormUpdateCredentialsNoJinja(formAction,credMap)

    FormInsertCredentialsNoJinja(formAction, credTypeList)
    WrtAsUtf("""</table>""")

    htmlFooter = "".join( lib_export_html.DisplayHtmlTextFooter() )
    WrtAsUtf(htmlFooter)

    WrtAsUtf("</body></html>")
Ejemplo n.º 10
0
def MainJinja():
    THIS_DIR = os.path.dirname(os.path.abspath(__file__))
    template_file_name = "www/edit_configuration.template.htm"

    jinja2 = lib_util.GetJinja2()

    # Create the jinja2 environment.
    # Notice the use of trim_blocks, which greatly helps control whitespace.
    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(THIS_DIR),
                                   trim_blocks=True)
    jinja_template = jinja_env.get_template(template_file_name)

    jinja_render = jinja_template.render()
    lib_util.WrtHeader('text/html')
    WrtAsUtf(jinja_render)
Ejemplo n.º 11
0
def Main():
    formAction = os.environ['SCRIPT_NAME']

    cgiArguments = cgi.FieldStorage()

    credFilename = os.path.normpath(lib_credentials.CredFilNam())
    page_title = "Edit Survol credentials in %s" % credFilename

    lib_export_html.DisplayHtmlTextHeader(page_title)

    WrtAsUtf("""
    <body><h2>Edit Survol credentials in %s</h2>
    """ % credFilename)

    # Hostname=Unknown-30-b5-c2-02-0c-b5-2.home
    # Host address=192.168.0.17
    # Remote client=82.45.12.63

    currHostNam = socket.gethostname()
    currHostAddr = lib_util.GlobalGetHostByName(currHostNam)
    addrRemote = os.environ['REMOTE_ADDR']

    WrtAsUtf("""
    <table border="1" width='100%%'>
    <tr><td><b>Host name</b></td><td>%s</td></tr>
    <tr><td><b>Host address</b></td><td>%s</td></tr>
    <tr><td><b>Remote address</b></td><td>%s</td></tr>
    """ % (currHostNam, currHostAddr, addrRemote))

    if addrRemote in ["82.45.12.63", "192.168.0.14", "127.0.0.1"]:
        InsertedCredMap(cgiArguments)

        credMap = UpdatedCredMap(cgiArguments)

        credTypesWellKnown = CredDefinitions()

        WrtAsUtf("""<table border="1" width='100%%'>""")
        if credMap:
            FormUpdateCredentials(formAction, credMap, credTypesWellKnown)

        FormInsertCredentials(formAction, sorted(credTypesWellKnown.keys()))
        WrtAsUtf("""</table>""")
    else:
        WrtAsUtf("<b>ACCESS FORBIDDEN</b><br>")

    lib_export_html.DisplayHtmlTextFooter()

    #WrtAsUtf('<br><a href="edit_configuration.py">Configuration</a>')

    #urlIndex = lib_exports.UrlWWW("index.htm")
    #WrtAsUtf('<br><a href="' + urlIndex + '">Return to Survol</a>')

    WrtAsUtf("</body></html>")
Ejemplo n.º 12
0
def MainJinja(url_supervisor_control, urls_daemons_dict):
    MainNoJinja(url_supervisor_control, urls_daemons_dict)
    return
    lib_common.ErrorMessageHtml("Not implemented yet")

    THIS_DIR = os.path.dirname(os.path.abspath(__file__))
    template_file_name = "www/edit_supervisor.template.htm"

    jinja2 = lib_util.GetJinja2()

    # Create the jinja2 environment.
    # Notice the use of trim_blocks, which greatly helps control whitespace.
    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(THIS_DIR),
                                   trim_blocks=True)
    jinja_template = jinja_env.get_template(template_file_name)

    jinja_render = jinja_template.render()
    lib_util.WrtHeader('text/html')
    WrtAsUtf(jinja_render)
Ejemplo n.º 13
0
def DisplayHtmlTextFooter():
    """
	This is the common Survol footer.
	"""

    # See lib_exports.LegendFooter, similar footer.

    # This needs a directory which depends on the HTTP hosting, such as on OVH.
    urlIndex = lib_exports.UrlWWW("index.htm")
    urlEdtConfiguration = lib_util.uriRoot + "/edit_configuration.py"
    urlEdtCredentials = lib_util.uriRoot + "/edit_credentials.py"

    wrtFmt = """
	<br>
	<table width="100%%"><tr>
	<td><a href="%s">Survol home</a></td>
	<td><a href="%s">Configuration</a></td>
	<td><a href="%s">Credentials</a></td>
	<td align="right">&copy; <a href="http://www.primhillcomputers.com">Primhill Computers</a> 2017</i></td>
	</tr></table>
	"""

    wrtTxt = wrtFmt % (urlIndex, urlEdtConfiguration, urlEdtCredentials)
    WrtAsUtf(wrtTxt)
Ejemplo n.º 14
0
def MainNoJinja(url_supervisor_control, urls_daemons_dict):
    lib_util.WrtHeader('text/html')
    lib_export_html.display_html_text_header("Events generators")

    WrtAsUtf("""
    <body><h2>Display events generators</h2>
    """)

    if url_supervisor_control:
        WrtAsUtf("""
        <a href="%s">Supervisor Control</a>
        """ % url_supervisor_control)

    WrtAsUtf("""
    <br><br>
    
    <table border="1" width="100%">
    <tr><td>Daemon url</td><td>Object url</td><td>Triples number</td><td>Start time</td><td>State</td><td>Pid</td></tr>
    """)

    for daemon_url, daemon_object in urls_daemons_dict.items():
        WrtAsUtf("""
        <tr><td><a href="%s">%s</a></td><td><a href="%s">%s</a></td><td>%d</td><td>%s</td><td>%s</td><td>%d</td></tr>
        """ % (daemon_url, daemon_object['url_title'],
               daemon_object['object_url'], daemon_object['object_title'],
               daemon_object['triples_number'], daemon_object['start_time'],
               daemon_object['statename'], daemon_object['pid']))

    WrtAsUtf("""
    </table>
    <br><br>
    """)

    html_footer = "".join(lib_export_html.display_html_text_footer())
    WrtAsUtf(html_footer)

    WrtAsUtf("</body></html>")
Ejemplo n.º 15
0
def Grph2Html(theCgi, topUrl, error_msg, isSubServer, gblCgiEnvList):
    """
		This transforms an internal data graph into a HTML document.
	"""
    page_title = theCgi.m_page_title
    grph = theCgi.m_graph

    DisplayHtmlTextHeader(page_title)

    WrtAsUtf('<body>')

    WriteScriptInformation(theCgi, gblCgiEnvList)

    WriteErrors(error_msg, isSubServer)

    # WrtAsUtf("<h2>Objects</h2>")
    WriteAllObjects(grph)

    if len(theCgi.m_parameters) > 0:
        WrtAsUtf("<h2>Script parameters</h2>")
        WriteParameters(theCgi)

    # Scripts do not apply when displaying a class.
    # TODO: When in a enumerate script such as enumerate_CIM_LogicalDisk.py,
    # it should assume the same: No id but a class.
    if (theCgi.m_entity_type == "") or (theCgi.m_entity_id != ""):
        WrtAsUtf("<h2>Related data scripts</h2>")
        WriteScriptsTree(theCgi)

    WrtAsUtf("<h2>Other related urls</h2>")
    WriteOtherUrls(topUrl)

    DisplayHtmlTextFooter()

    WrtAsUtf("</body>")

    WrtAsUtf("</html> ")
Ejemplo n.º 16
0
def _output_rdf_graph_as_html_no_jinja(theCgi, top_url, error_msg,
                                       gbl_cgi_env_list):
    """
        This transforms an internal data graph into a HTML document.
    """
    page_title = theCgi.m_page_title
    grph = theCgi.m_graph

    display_html_text_header(page_title)

    WrtAsUtf('<body>')

    script_information = "".join(
        _script_information_html_iterator(theCgi, gbl_cgi_env_list))
    WrtAsUtf(script_information)
    object_information = "".join(_object_information_html_iterator(theCgi))
    WrtAsUtf(object_information)

    WrtAsUtf("".join(_write_errors_no_jinja(error_msg)))

    dict_class_subj_prop_obj = _create_objects_list(grph)

    WrtAsUtf("".join(_write_all_objects_no_jinja(dict_class_subj_prop_obj)))

    parameters_edition_html = "".join(
        _parameters_edition_html_iterator(theCgi))
    if parameters_edition_html:
        WrtAsUtf("<h2>Script parameters</h2>")
        WrtAsUtf(parameters_edition_html)

    # Scripts do not apply when displaying a class.
    # TODO: When in a enumerate script such as enumerate_CIM_LogicalDisk.py,
    # it should assume the same: No id but a class.
    if (theCgi.m_entity_type == "") or (theCgi.m_entity_id != ""):
        WrtAsUtf("<h2>Related data scripts</h2>")
        WrtAsUtf("".join(_scripts_tree_html_iterator(theCgi)))

    WrtAsUtf("<h2>Other related urls</h2>")
    WrtAsUtf('<table class="other_urls">')
    WrtAsUtf("".join(_other_urls_html_iterator(top_url)))
    WrtAsUtf("".join(_cim_urls_html_iterator()))
    WrtAsUtf('</table>')

    html_footer = "".join(display_html_text_footer())
    WrtAsUtf(html_footer)

    WrtAsUtf("</body>")

    WrtAsUtf("</html> ")
Ejemplo n.º 17
0
def _form_insert_credentials_no_jinja(form_action, cred_type_list):
    WrtAsUtf("""
    <form method="post" action="edit_credentials.py" name="ServerCredentials">
    """)

    cred_input_add_prefix = "credentials_add_"
    cred_input_add_type = cred_input_add_prefix + "type"
    cred_input_add_name = cred_input_add_prefix + "name"
    cred_input_add_usr = cred_input_add_prefix + "usr"
    cred_input_add_pwd = cred_input_add_prefix + "pwd"

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""<td colspan=4><b>Credentials creation</b></td>""")
    WrtAsUtf("""</tr>""")

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""<td colspan=4><select name="%s">""" % cred_input_add_type)
    for cred_type in cred_type_list:
        WrtAsUtf("""<option value='%s'>%s</option>""" % (cred_type, cred_type))
    WrtAsUtf("""</select></td>""")
    WrtAsUtf("""</tr>""")

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""
    <td><input name="%s"></td>
    <td><input name="%s"></td>
    <td><input name="%s"></td>
    </tr>
    """ % (cred_input_add_name, cred_input_add_usr, cred_input_add_pwd))

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""<td colspan=4>""")
    WrtAsUtf("""
    <input type="hidden" value="HiddenValue" name="HiddenName">
    <input value="Insert new credential" name="SubmitCredAddName" type="submit">
    """)
    WrtAsUtf("""</td>""")
    WrtAsUtf("""</tr>""")
    WrtAsUtf("""
    </form>
    """)
Ejemplo n.º 18
0
def _form_update_credentials_no_jinja(form_action, cred_map):
    """This applies only if the jinja2 module is not there."""
    WrtAsUtf("""
    <form method="post" action="%s" name="ServerCredentials">
    """ % (form_action))

    WrtAsUtf("""<tr>
    <td><b>Resource</b></td>
    <td><b>Account</b></td>
    <td><b>Password</b></td>
    <td><b>Del</b></td>
    </tr>
    """)

    for cred_type in sorted(cred_map):
        # This is a type of access: Oracle databse, Linux machine, Windows account etc...
        WrtAsUtf("<tr><td colspan=4><b>%s</b></td></tr>" % cred_type)

        # This is a homogeneous list, for example of machines names, or databases.
        cred_nams = cred_map[cred_type]
        for cred_name in sorted(cred_nams):
            # For a machine, this accepts only one user.
            # Same for a given database: Only one user. The reason is that the scripts
            # do not have to chosse when they need to display information about something.
            # Read-only access rights are enough.
            cred = cred_nams[cred_name]

            cred_name_url = cred[4]

            if cred_name_url:
                WrtAsUtf("""<tr>
                <td><a href="%s">%s</a></td>
                <td>%s</td>
                <td><input name="%s" value="%s"></td>
                <td><input type="checkbox" name="%s"></td>
                </tr>
                """ % (cred_name_url, cred_name, cred[0], cred[2], cred[1], cred[3]))
            else:
                # If no URL can be created. For example of the map misses a function
                # for a given credential type.
                WrtAsUtf("""<tr>
                <td>%s</td>
                <td>%s</td>
                <td><input name="%s" value="%s"></td>
                <td><input type="checkbox" name="%s"></td>
                </tr>
                """ % (cred_name, cred[0], cred[2], cred[1], cred[3]))

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""<td colspan=4>""")
    WrtAsUtf("""
    <input value="Update / delete credential" name="SubmitCredUpdName" type="submit"><br>
    """)
    WrtAsUtf("""</td>""")
    WrtAsUtf("""</tr>""")
    WrtAsUtf("""
    </form>
    """)
Ejemplo n.º 19
0
def DispClassObjects(dictSubjPropObj):
    listPropsTdDoubleColSpan = [
        pc.property_information, pc.property_rdf_data_nolist2,
        pc.property_rdf_data_nolist1
    ]

    WrtAsUtf('<table class="class_objects">')

    # The subjects must be sorted by their title.
    lstTuplesSubjects = []
    for aSubj in dictSubjPropObj:
        subj_str = str(aSubj)
        (subj_title, entity_graphic_class,
         entity_id) = lib_naming.ParseEntityUri(subj_str)
        lstTuplesSubjects.append(
            (aSubj, subj_str, subj_title, entity_graphic_class, entity_id))

    # Sorted by the title of the subject, which is the third value of the tuple.
    lib_util.natural_sort_list(lstTuplesSubjects, key=lambda tup: tup[2])

    # Now it iterates on the sorted list.
    # This reuses all the intermediate values.
    for aSubj, subj_str, subj_title, entity_graphic_class, entity_id in lstTuplesSubjects:
        dictPred = dictSubjPropObj[aSubj]

        arrayGraphParams = lib_patterns.TypeToGraphParams(entity_graphic_class)
        # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded"
        colorClass = arrayGraphParams[1]

        # Total number of lines.
        cntPreds = 0
        for aPred in dictPred:
            lstObjs = dictPred[aPred]
            cntPreds += len(lstObjs)

        mustWriteColOneSubj = True

        subj_str_with_mode = UrlInHtmlMode(subj_str)

        # The predicates, i.e. the properties associated a subject with an object,
        # must be alphabetically sorted.
        for aPred in lib_util.natural_sorted(dictPred):
            lstObjs = dictPred[aPred]

            predStr = lib_exports.AntiPredicateUri(str(aPred))
            cntObjs = len(lstObjs)
            mustWriteColOnePred = True

            # The objects must be sorted by title.
            lstTuplesObjs = []
            for anObj in lstObjs:
                obj_str = str(anObj)
                obj_str = DesHex(obj_str)
                obj_title = lib_naming.ParseEntityUri(obj_str)[0]
                lstTuplesObjs.append((anObj, obj_str, obj_title))

            # Sorted by the title of the object, which is the third value of the tuple.
            lib_util.natural_sort_list(lstTuplesObjs, key=lambda tup: tup[2])

            for anObj, obj_str, obj_title in lstTuplesObjs:

                WrtAsUtf('<tr bgcolor="%s">' % colorClass)

                if mustWriteColOneSubj:
                    WrtAsUtf(
                        '<td valign="top" rowspan="%s"><a href="%s">%s</a></td>'
                        % (str(cntPreds), subj_str_with_mode, subj_title))
                    mustWriteColOneSubj = False

                if mustWriteColOnePred:
                    if aPred not in listPropsTdDoubleColSpan:
                        WrtAsUtf('<td valign="top" rowspan="%s">%s</td>' %
                                 (str(cntObjs), predStr))
                    mustWriteColOnePred = False

                if aPred in listPropsTdDoubleColSpan:
                    colSpan = 2
                else:
                    colSpan = 1

                dispMimeUrls = True

                WrtAsUtf('<td colspan="%d">' % (colSpan))
                if dispMimeUrls:
                    if lib_kbase.IsLink(anObj):
                        objStrClean = lib_util.UrlNoAmp(obj_str)
                        mimeType = lib_mime.GetMimeTypeFromUrl(objStrClean)
                        if mimeType:
                            if mimeType.startswith("image/"):
                                WrtAsUtf(
                                    """<a href="%s"><img src="%s" alt="%s" height="42" width="42"></a>"""
                                    % (obj_str, obj_str, obj_title))
                            else:
                                WrtAsUtf("""<a href="%s">%s</a>""" %
                                         (obj_str, obj_title))
                        else:
                            url_with_mode = lib_util.AnyUriModed(
                                obj_str, "html")
                            WrtAsUtf("""<a href="%s">%s</a>""" %
                                     (url_with_mode, obj_title))
                    else:
                        WrtAsUtf('%s' % (obj_str))
                else:
                    if lib_kbase.IsLink(anObj):
                        url_with_mode = UrlInHtmlMode(obj_str)
                        WrtAsUtf('<a href="%s">%s</a>' %
                                 (url_with_mode, obj_title))
                    else:
                        WrtAsUtf('%s' % (obj_str))

                WrtAsUtf("</td>")

                WrtAsUtf("</tr>")

    WrtAsUtf(" </table>")
Ejemplo n.º 20
0
def WriteAllObjects(grph):
    """
		This displays all the objects returend by this scripts.
		Other scripts are not here, so we do not have to eliminate them.
		This is therefore simpler than in the SVG (Graphviz) output,
		where all objects are mixed together.
	"""

    # This groups data by subject, then predicate, then object.
    dictClassSubjPropObj = dict()

    # TODO: Group objects by type, then display the count, some info about each type etc...
    for aSubj, aPred, anObj in grph:
        # No point displaying some keys if there is no value.
        if aPred == pc.property_information:
            try:
                if str(anObj) == "":
                    continue
            # 'ascii' codec can't encode character u'\xf3' in position 17: ordinal not in range(128)
            # u'SDK de comprobaci\xf3n de Visual Studio 2012 - esn'
            except UnicodeEncodeError:
                exc = sys.exc_info()[1]
                sys.stderr.write("Exception %s\n" % str(exc))
                continue

        subj_str = str(aSubj)
        (subj_title, entity_graphic_class,
         entity_id) = lib_naming.ParseEntityUri(subj_str)

        try:
            dictSubjPropObj = dictClassSubjPropObj[entity_graphic_class]
            try:
                dictPred = dictSubjPropObj[aSubj]
                try:
                    dictPred[aPred].append(anObj)
                except KeyError:
                    # First time this object has this predicate.
                    dictPred[aPred] = [anObj]
            except KeyError:
                # First time we see this object.
                dictSubjPropObj[aSubj] = {aPred: [anObj]}
        except KeyError:
            # First object of this class.
            dictClassSubjPropObj[entity_graphic_class] = {
                aSubj: {
                    aPred: [anObj]
                }
            }

    # Group objects by class.
    # Display list of classes with an indexs and a link to the class.
    # "NO TITLE" is wrong

    # TODO: Create a "difference mode". Periodic display, of only the difference between successive data sets.
    # Ajouter mode "difference": On recalcule periodiquement et on affiche la difference.

    # No need to use natural sort, because these are no filenames or strings containing numbres.
    for entity_graphic_class in sorted(dictClassSubjPropObj):

        urlClass = lib_util.EntityClassUrl(entity_graphic_class)
        urlClass_with_mode = UrlInHtmlMode(urlClass)
        WrtAsUtf("<h3>Class <a href='%s'>%s</a></h3>" %
                 (urlClass_with_mode, entity_graphic_class))
        dictSubjPropObj = dictClassSubjPropObj[entity_graphic_class]

        DispClassObjects(dictSubjPropObj)
Ejemplo n.º 21
0
def WriteScriptInformation(theCgi, gblCgiEnvList):
    """
		This displays general information about this script and the object if there is one.
	"""
    sys.stderr.write("WriteScriptInformation entity_type=%s\n" %
                     (theCgi.m_entity_type))

    # This is already called in lib_common, when creating CgiEnv.
    # It does not matter because this is very fast.
    callingUrl = lib_util.RequestUri()
    (entity_label, entity_graphic_class,
     entity_id) = lib_naming.ParseEntityUri(callingUrl, longDisplay=True)
    sys.stderr.write("entity_label=%s entity_graphic_class=%s entity_id=%s\n" %
                     (entity_label, entity_graphic_class, entity_id))

    # WrtAsUtf('<table class="list_of_merged_scripts">')
    WrtAsUtf('<table border="0">')
    if len(gblCgiEnvList):
        sys.stderr.write("gblCgiEnvList=%s\n" % str(gblCgiEnvList))
        # This step is dedicated to the merging of several scripts.

        WrtAsUtf(
            "<tr align=left><td colspan=2 align=left><h2>Fusion of data from %d scripts</h2></td></tr>"
            % len(gblCgiEnvList))
        for aCgiEnv in gblCgiEnvList:
            sys.stderr.write("aCgiEnv=%s\n" % str(aCgiEnv))
            sys.stderr.write("aCgiEnv.m_page_title=%s\n" %
                             str(aCgiEnv.m_page_title))
            sys.stderr.write("aCgiEnv.m_calling_url=%s\n" %
                             str(aCgiEnv.m_calling_url))
            (page_title_first, page_title_rest) = lib_util.SplitTextTitleRest(
                aCgiEnv.m_page_title)
            WrtAsUtf(
                "<tr><td><a href='%s'>%s</td><td><i>%s</i></td></tr>" %
                (aCgiEnv.m_calling_url, page_title_first, page_title_rest))

    else:
        (page_title_first,
         page_title_rest) = lib_util.SplitTextTitleRest(theCgi.m_page_title)
        WrtAsUtf("<tr><td colspan=2><h2>%s</h2></td></tr>" %
                 (page_title_first))
        if page_title_rest:
            WrtAsUtf("<tr><td colspan=2>%s</td></tr>" % (page_title_rest))

    WrtAsUtf('</table>')

    if theCgi.m_entity_type:
        # WrtAsUtf('m_entity_id: %s<br>'%(theCgi.m_entity_id))

        WrtAsUtf('<table class="table_script_information">')

        entity_module = lib_util.GetEntityModule(theCgi.m_entity_type)
        entDoc = entity_module.__doc__
        if not entDoc:
            entDoc = ""

        urlClass = lib_util.EntityClassUrl(theCgi.m_entity_type)
        urlClass_with_mode = UrlInHtmlMode(urlClass)
        WrtAsUtf("""
		<tr>
			<td><a href='%s'>%s</a></td>
			<td>%s</td>
		</tr>
		""" % (urlClass_with_mode, theCgi.m_entity_type, entDoc))

        for keyProp in theCgi.m_entity_id_dict:
            keyVal = theCgi.m_entity_id_dict[keyProp]

            WrtAsUtf("""
			<tr>
				<td>%s</td>
				<td>%s</td>
			</tr>
			""" % (keyProp, keyVal))

        WrtAsUtf('</table>')
Ejemplo n.º 22
0
    def DisplayLevelTable(subj, depthMenu=1):
        """
			Top-level should always be none.
			TODO: Have another version which formats all cells the same way.
			For this, have a first pass which counts, at each node, the number of sub-nodes.
			Then a second pass which uses thiese counts and the current depth,
			to calculate the rowspan and colspan of each cell.
			Although elegant, it is not garanteed to work.
		"""
        WrtAsUtf('<table class="table_scripts_titles">')
        try:
            mapProps = dictScripts[subj]
        except KeyError:
            return

        def ExtractTitleFromMapProps(mapProps):
            if len(mapProps) != 1:
                return None
            for oneProp in mapProps:
                if oneProp != pc.property_information:
                    return None

                lstStr = mapProps[oneProp]
                if len(lstStr) != 1:
                    return None
                retStr = lstStr[0]
                if lib_kbase.IsLink(retStr):
                    return None

                return str(retStr)

        WrtAsUtf('<tr>')
        depthMenu += 1

        subj_uniq_title = ExtractTitleFromMapProps(mapProps)

        if subj:
            subj_str = str(subj)
            WrtAsUtf("<td valign='top' rowspan='%d'>" % len(mapProps))
            if lib_kbase.IsLink(subj):
                url_with_mode = UrlInHtmlMode(subj_str)
                if subj_uniq_title:
                    subj_uniq_title_not_none = subj_uniq_title
                else:
                    subj_uniq_title_not_none = "No title"
                WrtAsUtf('<a href="' + url_with_mode + '">' +
                         subj_uniq_title_not_none + "</a>")
            else:
                WrtAsUtf(subj_str)
            WrtAsUtf("</td>")

        if not subj_uniq_title:
            for oneProp in mapProps:
                lstObjs = mapProps[oneProp]

                WrtAsUtf('<td>')
                WrtAsUtf('<table class="table_scripts_links">')
                for oneObj in lstObjs:
                    if oneObj is None:
                        continue
                    WrtAsUtf('<tr>')
                    WrtAsUtf('<td>')
                    try:
                        mapPropsSub = dictScripts[oneObj]
                        DisplayLevelTable(oneObj, depthMenu)
                    except KeyError:
                        WrtAsUtf("Script error: " + str(oneObj))
                    WrtAsUtf('</td>')
                    WrtAsUtf('</tr>')
                WrtAsUtf('</table>')
                WrtAsUtf('</td>')

        WrtAsUtf('</tr>')
        WrtAsUtf("</table>")
Ejemplo n.º 23
0
 def WMapToHtml(theMap, propData):
     sys.stderr.write("WMapToHtml len=%d\n" % len(theMap))
     for urlSubj in theMap:
         (subjText, subjEntityGraphClass,
          subjEntityId) = lib_naming.ParseEntityUri(
              lib_util.urllib_unquote(urlSubj))
         WrtAsUtf("<tr>")
         WrtAsUtf("<td valign='top'><a href='%s'>%s</a></td>" %
                  (str(urlSubj), subjText))
         WrtAsUtf("<td>")
         WrtAsUtf("<table>")
         for theProp, urlObj in theMap[urlSubj]:
             WrtAsUtf("<tr>")
             propNam = lib_exports.PropToShortPropNam(theProp)
             WrtAsUtf("<td><i>%s</i></td>" % propNam)
             if lib_kbase.IsLiteral(urlObj):
                 WrtAsUtf("<td>%s</td>" % (str(urlObj)))
             else:
                 (objText, objEntityGraphClass,
                  objEntityId) = lib_naming.ParseEntityUri(
                      lib_util.urllib_unquote(urlObj))
                 WrtAsUtf("<td><a href='%s'>%s</a></td>" %
                          (str(urlObj), objText))
             WrtAsUtf("</tr>")
         WrtAsUtf("</table>")
         WrtAsUtf("</td>")
     WrtAsUtf("</tr>")
Ejemplo n.º 24
0
def WriteOtherUrls(topUrl):
    """
		This displays the URL to view the same document, in other ouput formats.
	"""

    WrtAsUtf('<table class="other_urls">')

    if topUrl:
        topUrl_with_mode = UrlInHtmlMode(topUrl)
        WrtAsUtf("""
		<tr><td align="left" colspan="2"><a href="%s"><b>Home</b></a></td></tr>
		""" % topUrl_with_mode)

    # Because Graphviz is not available on OVH platform.
    if not lib_util.modeOVH:
        WrtAsUtf("""
		<tr>
			<td class="other_urls"><a href="%s">SVG format</a></td>
			<td>Graphviz&trade; generated</td>
		</tr>
		""" % lib_exports.ModedUrl("svg"))

    WrtAsUtf("""
	<tr>
		<td class="other_urls"><a href="%s">RDF format</a></td>
		<td>Semantic Web, OWL standard / Prot&eacute;g&eacute;&trade;...</td>
	</tr>
	""" % lib_exports.ModedUrl("rdf"))

    urlD3 = lib_exports.UrlToMergeD3()

    WrtAsUtf("""
	<tr>
		<td class="other_urls"><a href="%s">D3</a></td>
		<td>Javascript D3 library</td>
	</tr>
	""" % urlD3)

    host_wbem_wmi = lib_util.currentHostname

    # This callback receives a RDF property (WBEM or WMI) and a map
    # which represents the CIM links associated to the current object.
    def WMapToHtml(theMap, propData):
        sys.stderr.write("WMapToHtml len=%d\n" % len(theMap))
        for urlSubj in theMap:
            (subjText, subjEntityGraphClass,
             subjEntityId) = lib_naming.ParseEntityUri(
                 lib_util.urllib_unquote(urlSubj))
            WrtAsUtf("<tr>")
            WrtAsUtf("<td valign='top'><a href='%s'>%s</a></td>" %
                     (str(urlSubj), subjText))
            WrtAsUtf("<td>")
            WrtAsUtf("<table>")
            for theProp, urlObj in theMap[urlSubj]:
                WrtAsUtf("<tr>")
                propNam = lib_exports.PropToShortPropNam(theProp)
                WrtAsUtf("<td><i>%s</i></td>" % propNam)
                if lib_kbase.IsLiteral(urlObj):
                    WrtAsUtf("<td>%s</td>" % (str(urlObj)))
                else:
                    (objText, objEntityGraphClass,
                     objEntityId) = lib_naming.ParseEntityUri(
                         lib_util.urllib_unquote(urlObj))
                    WrtAsUtf("<td><a href='%s'>%s</a></td>" %
                             (str(urlObj), objText))
                WrtAsUtf("</tr>")
            WrtAsUtf("</table>")
            WrtAsUtf("</td>")
        WrtAsUtf("</tr>")

    callingUrl = lib_util.RequestUri()
    (entity_label, entity_type,
     entity_id) = lib_naming.ParseEntityUri(callingUrl, longDisplay=True)
    nameSpace = ""

    mapWbem = CIM_ComputerSystem.AddWbemServers(host_wbem_wmi, nameSpace,
                                                entity_type, entity_id)
    WMapToHtml(mapWbem, pc.property_wbem_data)
    mapWmi = CIM_ComputerSystem.AddWmiServers(host_wbem_wmi, nameSpace,
                                              entity_type, entity_id)
    WMapToHtml(mapWmi, pc.property_wmi_data)
    mapSurvol = CIM_ComputerSystem.AddSurvolServers(host_wbem_wmi, nameSpace,
                                                    entity_type, entity_id)
    WMapToHtml(mapSurvol, pc.property_survol_agent)

    WrtAsUtf('</table>')
Ejemplo n.º 25
0
def FormUpdateCredentials(formAction, credMap, credTypesWellKnown):
    WrtAsUtf("""
    <form method="post" action="%s" name="ServerCredentials">
    """ % (formAction))

    WrtAsUtf("""<tr>
    <td><b>Resource</b></td>
    <td><b>Account</b></td>
    <td><b>Password</b></td>
    <td><b>Del</b></td>
    </tr>
    """)

    for credType in sorted(credMap):
        # This is a type of access: Oracle databse, Linux machine, Windows account etc...
        WrtAsUtf("<tr><td colspan=4><b>%s</b></td></tr>" % (credType))

        # This is a homogeneous list, for example of machines names, or databases.
        credNams = credMap[credType]
        for credName in sorted(credNams):
            # For a machine, this accepts only one user.
            # Same for a given database: Only one user. The reason is that the scripts
            # do not have to chosse when they need to display information about something.
            # Read-only access rights are enough.
            cred = credNams[credName]

            try:
                # Maybe we can create a URL for a credName of a given credType.
                # For example a machine name if 'Login', a database if 'Oracle',
                # an access to a WBEM server if 'WBEM' etc...
                nodeGenerator = credTypesWellKnown[credType]
                credNameUrl = nodeGenerator(credName)
            except:
                # Maybe the key is not defined ...
                # ... or the generator does not work
                exc = sys.exc_info()[1]
                sys.stderr.write("nodeGenerator exception:%s\n" % str(exc))
                credNameUrl = None

            if credNameUrl:
                WrtAsUtf("""<tr>
                <td><a href="%s">%s</a></td>
                <td>%s</td>
                <td><input name="%s" value="%s"></td>
                <td><input type="checkbox" name="%s"></td>
                </tr>
                """ % (credNameUrl, credName, cred[0], cred[2], cred[1],
                       cred[3]))
            else:
                # If no URL can be created. For example of the map misses a function
                # for a given credential type.
                WrtAsUtf("""<tr>
                <td>%s</td>
                <td>%s</td>
                <td><input name="%s" value="%s"></td>
                <td><input type="checkbox" name="%s"></td>
                </tr>
                """ % (credName, cred[0], cred[2], cred[1], cred[3]))

    WrtAsUtf("""<tr>""")
    WrtAsUtf("""<td colspan=4>""")
    WrtAsUtf("""
    <input value="Update / delete credential" name="SubmitCredUpdName" type="submit"><br>
    </form>
    """)
    WrtAsUtf("""</td>""")
    WrtAsUtf("""</tr>""")