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)
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)
def Main(): formAction = os.environ['SCRIPT_NAME'] cgiArguments = cgi.FieldStorage() credFilename = os.path.normpath(lib_credentials.credentials_filename()) page_title = "Edit Survol credentials in %s" % 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) try: addrRemote = os.environ['REMOTE_ADDR'] except KeyError: #ERROR("edit_credentials.py: Cannot get REMOTE_ADDR") sys.stderr.write("edit_credentials.py: Cannot get REMOTE_ADDR\n") raise if addrRemote not in ["82.45.12.63","192.168.0.14","127.0.0.1"]: lib_common.ErrorMessageHtml("Access forbidden from %s"% addrRemote ) InsertedCredMap(cgiArguments) credMap = UpdatedCredMap(cgiArguments) credTypesWellKnown = CredDefinitions() credTypeList=sorted(credTypesWellKnown.keys()) if lib_util.GetJinja2(): MainJinja(page_title,currHostNam,currHostAddr,addrRemote,credMap,formAction,credTypeList) else: MainNoJinja(page_title,currHostNam,currHostAddr,addrRemote,credMap,formAction,credTypeList)
def output_rdf_graph_as_html(theCgi, top_url, error_msg, gbl_cgi_env_list): """The list gbl_cgi_env_list contains a list of URL which are merged into the current URLs. There are displayed for informational purpose. """ lib_util.WrtHeader('text/html') if lib_util.GetJinja2(): output_rdf_graph_as_html_jinja(theCgi, top_url, error_msg, gbl_cgi_env_list) else: _output_rdf_graph_as_html_no_jinja(theCgi, top_url, error_msg, gbl_cgi_env_list)
def Main(): lib_common.set_events_credentials() url_supervisor_control = daemon_factory.supervisorctl_url() logging.info("url_supervisor_control=%s" % url_supervisor_control) try: urls_daemons_dict = _get_daemons_data() except Exception as exc: logging.error("Caught exc=%s" % exc) lib_common.ErrorMessageHtml("Supervisor %s display: Caught:%s" % (url_supervisor_control, exc)) if lib_util.GetJinja2(): MainJinja(url_supervisor_control, urls_daemons_dict) else: MainNoJinja(url_supervisor_control, urls_daemons_dict)
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)
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)
def Grph2Html(theCgi, topUrl, error_msg, isSubServer, gblCgiEnvList): lib_util.WrtHeader('text/html') if lib_util.GetJinja2(): Grph2HtmlJinja(theCgi, topUrl, error_msg, isSubServer, gblCgiEnvList) else: Grph2HtmlNoJinja(theCgi, topUrl, error_msg, isSubServer, gblCgiEnvList)
def Main(): form_action = os.environ['SCRIPT_NAME'] cgi_arguments = cgi.FieldStorage() cred_filename = os.path.normpath(lib_credentials.credentials_filename()) page_title = "Edit Survol credentials in %s" % cred_filename # Hostname=Unknown-30-b5-c2-02-0c-b5-2.home # Host address=192.168.0.17 # Remote client=82.45.12.63 curr_host_nam = socket.gethostname() curr_host_addr = lib_util.GlobalGetHostByName(curr_host_nam) try: addr_remote = os.environ['REMOTE_ADDR'] except KeyError: logging.error("Cannot get REMOTE_ADDR") raise # Hard-coded protection. if addr_remote not in ["82.45.12.63", "192.168.0.14", "192.168.1.10", "192.168.56.1", "127.0.0.1"]: lib_common.ErrorMessageHtml("Access forbidden from %s" % addr_remote) _inserted_cred_map(cgi_arguments) cred_map = _updated_cred_map(cgi_arguments) cred_types_well_known = _cred_definitions() cred_type_list = sorted(cred_types_well_known.keys()) 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>") 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) if lib_util.GetJinja2(): main_jinja() else: main_no_jinja()
def Main(): if lib_util.GetJinja2(): MainJinja() else: MainNoJinja()