def html_traceroute_details_geek(field_names, result_list, link_to, generic_headers_link_to, specific_headers_link_to): html = xml_utils() doc = '' doc += html.tag("table") doc += html.tag("tr") for field in field_names[1:]: if field != 'rtt_ms' and not re.search(r'[Rr]ound.?[Tt]rip', field): doc += html.tagged_text("th", field) else: doc += html.tagged_text("th colspan='4'", field) doc += html.end_tag("/tr") result_list = convert_attempts_to_hops(result_list) for record in result_list: doc += html.tag("tr") for field in record[1:]: doc += html.tagged_text("td", field) doc += html.end_tag("/tr") doc += html.end_tag("/table") return doc
def html_traceroute_details_geek (field_names, result_list, link_to, generic_headers_link_to, specific_headers_link_to ): html = xml_utils ( ) doc = '' doc += html.tag ("table") doc += html.tag ("tr") for field in field_names[1:]: if field != 'rtt_ms' and not re.search(r'[Rr]ound.?[Tt]rip', field): doc += html.tagged_text ("th", field) else: doc += html.tagged_text ("th colspan='4'", field) doc += html.end_tag ("/tr") result_list = convert_attempts_to_hops (result_list) for record in result_list: doc += html.tag ("tr") for field in record[1:]: doc += html.tagged_text ("td", field) doc += html.end_tag ("/tr") doc += html.end_tag ("/table") return doc
def html_traceroute_details_page(query_info, arg=None): route_overview = ixmaps.get_traceroute(conn, int(arg)) html = xml_utils() doc = '' if query_info.title: doc += html.tagged_text('h1', query_info.title) if query_info.header: # doc += html.text (query_info.header % ( (instances_of_strings(query_info.header),) * instances_of_strings (query_info.header) ) ) doc += html.text(query_info.header % ( (arg, route_overview['sub_time'], arg, route_overview['submitter'], route_overview['zip_code'], route_overview['dest'], route_overview['dest'], route_overview['dest_ip']))) # instances_of_arg = instances_of_strings (query_info.query) # query = query_info.query % ((arg, ) * instances_of_arg) query = query_info.query % ( (arg, ) * instances_of_strings(query_info.query)) q_result = conn.query(query) field_names = q_result.listfields() result_list = q_result.getresult() if (query_info.custom_table_function): doc += html.indent( query_info.custom_table_function( field_names, result_list, query_info.link_to, query_info.generic_headers_link_to, query_info.specific_headers_link_to)) else: doc += html.indent( html_generic_query_results_table( field_names, result_list, query_info.link_to, query_info.generic_headers_link_to, query_info.specific_headers_link_to)) # doc += html.tag ('p') # doc += html.tagged_text ('b', 'SQL Query') # doc += html.tag ('ul') # doc += query # doc += html.end_tag ('/ul') # doc += html.end_tag ('/p') # doc += html.empty_tag ('hr') if query_info.footer: doc += html.text(query_info.footer % ((arg, ) * instances_of_strings(query_info.footer))) return doc
def html_traceroute_details(field_names, orig_result_list, link_to, generic_headers_link_to, specific_headers_link_to): html = xml_utils() doc = '' conn = ixmaps.DBConnect.getConnection() chotels = ixmaps.CHotels(conn=conn) # --- Note: there should be a function to auto-generate these values (es) --- attempt_col = 0 hop_col = 1 ip_col = 2 country_col = 3 rtt_col = 4 city_col = 6 override_col = 7 lat_col = 9 long_col = 10 region_col = 11 result_list = convert_attempts_to_hops_no_rtt(orig_result_list) nattempts = len(orig_result_list) nhops = result_list[-1][hop_col] # nhops = len(result_list) rtt = array_2d(nhops, 4) ipaddrs = array_2d(nhops, nattempts) for probe in orig_result_list: hop = probe[hop_col] - 1 attempt = probe[attempt_col] - 1 rtt[hop][attempt] = probe[rtt_col] ipaddrs[hop][attempt] = probe[ip_col] doc += html.tag('table') doc += html.tag("tr") for field in field_names[1:lat_col]: if (field in specific_headers_link_to): if specific_headers_link_to[field]: field = ("<a href='" + specific_headers_link_to[field] + "'>" + field + "</a>") elif generic_headers_link_to: field = ("<a href='" + generic_headers_link_to + urllib.quote_plus(str(field)) + "'>" + field + "</a>") doc += html.tagged_text('th', field) doc += html.end_tag("/tr") for hop in range(len(result_list)): record = result_list[hop] doc += html.tag('tr') min_latency = get_min_latency(hop, rtt, nhops) country_img = ICON_PREFIX + "clear" + ICON_SUFFIX chotel_img = ICON_PREFIX + "clear" + ICON_SUFFIX nsa_img = ICON_PREFIX + "clear" + ICON_SUFFIX is_chotel = ixmaps.is_chotel(conn=conn, long_lat=(record[long_col], record[lat_col])) # --- Assign row-icons --- if record[country_col]: country_img = ICON_PREFIX + record[country_col] + ICON_SUFFIX if is_chotel: chotel_img = ICON_PREFIX + "carrierhotel" + ICON_SUFFIX nsa_img = ICON_PREFIX + get_nsa_flag( conn=conn, long_lat=(record[long_col], record[lat_col])) + ICON_SUFFIX for item_num in range(1, len(record)): if item_num == country_col: doc += html.tag('td align="center" style="white-space:nowrap"') doc += html.empty_tag( 'img width="10" src="' + country_img + '"', 'img width="10" src="' + chotel_img + '"', 'img width="10" src="' + nsa_img + '"') doc += html.end_tag("/td") elif item_num == rtt_col: doc += html.tag('td') doc += html.indent(min_latency) doc += html.end_tag("/td") elif item_num == city_col: doc += html.tag('td') doc += html.text(record[city_col]) doc += html.text(record[region_col]) doc += html.end_tag("/td") elif item_num == override_col: geo_precision = get_geo_precision(record[override_col], record[lat_col], record[long_col]) doc += html.tag('td') doc += html.indent(geo_precision) # doc += html.indent (record[override_col] ) # doc += html.indent (record[lat_col] ) # doc += html.indent (record[long_col] ) doc += html.end_tag("/td") elif (item_num >= lat_col): pass else: doc += html.tagged_text('td', record[item_num]) doc += html.end_tag("/tr") doc += html.end_tag("/table") return doc
def html_submitter_table(field_names, result_list, link_to, generic_headers_link_to='', specific_headers_link_to={}): # --- Note: these numbers should be auto generated by this function --- country_col = 1 traceroute_col = 0 dest_col = 4 nsa_col = 6 hotel_col = 7 itag = 'img width="10" src=' icons = [0, 1, 2, 3] html = xml_utils() doc = '' doc += html.tag("table") doc += html.tag("tr") for field in field_names[:nsa_col]: doc += html.tagged_text("th", field) doc += html.end_tag("/tr") result_list = list(result_list) # for record_id in range ( len(result_list) ): record_id = 0 while record_id < len(result_list): record = result_list[record_id] doc += html.tag("tr") # --- Determine which countries this route goes through --- is_canada = False is_us = False traceroute_id = record[traceroute_col] counter = 0 while True: if record[country_col] == "CA": is_canada = True elif record[country_col] == "US": is_us = True if (len(result_list) > (record_id + 1) and result_list[record_id + 1][traceroute_col] == traceroute_id): record_id = record_id + 1 record = result_list[record_id] else: break # --- Determine whether this route goes through NSA-posts or C-Hotels --- is_nsa = True if (record[nsa_col] == 't') else False is_hotel = True if (record[hotel_col] == 't') else False if link_to: field0 = record[0] link = ("tr-query.cgi?query_type=" + link_to + "&arg=" + urllib.quote_plus(str(field0))) doc += html.tagged_text("td", 'a href="' + link + '"', field0) else: doc += html.tagged_text('td', record[0]) for item_num in range(1, nsa_col): if item_num == country_col: doc += html.tag("td") icons[0] = "nsa_class_A" if is_nsa else "clear" icons[1] = "carrierhotel" if is_hotel else "clear" icons[2] = "US" if is_us else "clear" icons[3] = "CA" if is_canada else "clear" for i in range(len(icons)): icons[i] = ICON_PREFIX + icons[i] + ICON_SUFFIX # doc += html.empty_tag ( itag + icons[0], itag + icons[1], # itag + icons[2], itag + icons[3]) doc += html.empty_tag(itag + icons[0]) doc += html.empty_tag(itag + icons[1]) doc += html.empty_tag(itag + icons[2]) doc += html.empty_tag(itag + icons[3]) doc += html.end_tag("/td") else: doc += html.tagged_text("td", record[item_num]) doc += html.end_tag("/tr") record_id += 1 doc += html.end_tag("/table") return doc
def html_traceroute_details (field_names, orig_result_list, link_to, generic_headers_link_to, specific_headers_link_to): html = xml_utils ( ) doc = '' conn = ixmaps.DBConnect.getConnection ( ) chotels = ixmaps.CHotels (conn=conn) # --- Note: there should be a function to auto-generate these values (es) --- attempt_col = 0 hop_col = 1 ip_col = 2 country_col = 3 rtt_col = 4 city_col = 6 override_col = 7 lat_col = 9 long_col = 10 region_col = 11 result_list = convert_attempts_to_hops_no_rtt (orig_result_list) nattempts = len(orig_result_list) nhops = result_list[-1][hop_col] # nhops = len(result_list) rtt = array_2d(nhops,4) ipaddrs = array_2d(nhops, nattempts) for probe in orig_result_list: hop = probe[hop_col]-1 attempt = probe[attempt_col]-1 rtt[hop][attempt] = probe[rtt_col] ipaddrs[hop][attempt] = probe[ip_col] doc += html.tag ("table") doc += html.tag ("tr") for field in field_names[1:lat_col]: if (field in specific_headers_link_to): if specific_headers_link_to[field]: field = ("<a href='" + specific_headers_link_to[field] + "'>" + field + "</a>") elif generic_headers_link_to: field = ("<a href='" + generic_headers_link_to + urllib.quote_plus ( str(field) ) + "'>" + field + "</a>") doc += html.tagged_text ("th", field) doc += html.end_tag ("/tr") for hop in range ( len (result_list) ): record = result_list[hop] doc += html.tag ("tr") min_latency = get_min_latency(hop, rtt, nhops) country_img = ICON_PREFIX + "clear" + ICON_SUFFIX chotel_img = ICON_PREFIX + "clear" + ICON_SUFFIX nsa_img = ICON_PREFIX + "clear" + ICON_SUFFIX is_chotel = ixmaps.is_chotel ( conn=conn, long_lat=(record[long_col],record[lat_col] ) ) # --- Assign row-icons --- if record[country_col]: country_img = ICON_PREFIX + record[country_col] + ICON_SUFFIX if is_chotel: chotel_img = ICON_PREFIX + "carrierhotel" + ICON_SUFFIX nsa_img = ICON_PREFIX + get_nsa_flag ( conn=conn, long_lat=(record[long_col],record[lat_col] ) ) + ICON_SUFFIX for item_num in range (1, len(record) ): if item_num == country_col: doc += html.tag ('td align="center" style="white-space:nowrap"') doc += html.empty_tag ('img width="10" src="' + country_img + '"', 'img width="10" src="' + chotel_img + '"', 'img width="10" src="' + nsa_img + '"') doc += html.end_tag ("/td") elif item_num == rtt_col: doc += html.tag ("td") doc += html.indent (min_latency) doc += html.end_tag ("/td") elif item_num == city_col: doc += html.tag ("td") doc += html.text ( record[city_col] ) doc += html.text ( record[region_col] ) doc += html.end_tag ("/td") elif item_num == override_col: geo_precision = get_geo_precision ( record[override_col], record[lat_col], record[long_col] ) doc += html.tag ("td") doc += html.indent (geo_precision) # doc += html.indent (record[override_col] ) # doc += html.indent (record[lat_col] ) # doc += html.indent (record[long_col] ) doc += html.end_tag ("/td") elif (item_num >= lat_col): pass else: doc += html.tagged_text ("td", record[item_num]) doc += html.end_tag ("/tr") doc += html.end_tag ("/table") return doc
def html_traceroute_details_page (query_info, arg=None): route_overview = ixmaps.get_traceroute (conn, int(arg) ) html = xml_utils ( ) doc = '' if query_info.title: doc += html.tagged_text ('h1', query_info.title) if query_info.header: # doc += html.text (query_info.header % ( (instances_of_strings(query_info.header),) * instances_of_strings (query_info.header) ) ) doc += html.text (query_info.header % ( (arg, arg, route_overview['zip_code'], route_overview['dest'], route_overview['dest_ip'], route_overview['submitter'], route_overview['sub_time'], ) ) ) # instances_of_arg = instances_of_strings (query_info.query) # query = query_info.query % ((arg, ) * instances_of_arg) query = query_info.query % ( (arg, ) * instances_of_strings (query_info.query) ) q_result = conn.query (query) field_names = q_result.listfields ( ) result_list = q_result.getresult ( ) if (query_info.custom_table_function): doc += html.indent ( query_info.custom_table_function ( field_names, result_list, query_info.link_to, query_info.generic_headers_link_to, query_info.specific_headers_link_to) ) else: doc += html.indent ( html_generic_query_results_table ( field_names, result_list, query_info.link_to, query_info.generic_headers_link_to, query_info.specific_headers_link_to) ) doc += html.tag ('p') doc += html.tagged_text ('b', 'SQL Query') doc += html.tag ('ul') doc += query doc += html.end_tag ('/ul') doc += html.end_tag ('/p') doc += html.empty_tag ('hr') if query_info.footer: doc += html.text (query_info.footer % ( (arg,) * instances_of_strings (query_info.footer) ) ) return doc
def html_submitter_table (field_names, result_list, link_to, generic_headers_link_to='', specific_headers_link_to={} ): # --- Note: these numbers should be auto generated by this function --- country_col = 1 traceroute_col = 0 dest_col = 4 nsa_col = 6 hotel_col = 7 itag = 'img width="10" src=' icons = [0,1,2,3] html = xml_utils ( ) doc = '' doc += html.tag ("table") doc += html.tag ("tr") for field in field_names[:nsa_col]: doc += html.tagged_text ("th", field) doc += html.end_tag ("/tr") result_list = list(result_list) # for record_id in range ( len(result_list) ): record_id = 0 while record_id < len(result_list): record = result_list[record_id] doc += html.tag ("tr") # --- Determine which countries this route goes through --- is_canada = False is_us = False traceroute_id = record[traceroute_col] counter = 0 while True: if record[country_col] == "CA": is_canada = True elif record[country_col] == "US": is_us = True if ( len(result_list) > (record_id+1) and result_list[record_id+1][traceroute_col] == traceroute_id ): record_id = record_id + 1 record = result_list[record_id] else: break # --- Determine whether this route goes through NSA-posts or C-Hotels --- is_nsa = True if (record[nsa_col]=='t') else False is_hotel = True if (record[hotel_col]=='t') else False if link_to: field0 = record[0] link = ("tr-query.cgi?query_type=" + link_to + "&arg=" + urllib.quote_plus (str(field0) ) ) doc += html.tagged_text ("td", 'a href="' + link + '"', field0) else: doc += html.tagged_text ('td', record[0]) for item_num in range ( 1, nsa_col ): if item_num == country_col: doc += html.tag ("td") icons[0] = "nsa_class_A" if is_nsa else "clear" icons[1] = "carrierhotel" if is_hotel else "clear" icons[2] = "US" if is_us else "clear" icons[3] = "CA" if is_canada else "clear" for i in range ( len(icons) ): icons[i] = ICON_PREFIX + icons[i] + ICON_SUFFIX # doc += html.empty_tag ( itag + icons[0], itag + icons[1], # itag + icons[2], itag + icons[3]) doc += html.empty_tag ( itag + icons[0]) doc += html.empty_tag ( itag + icons[1]) doc += html.empty_tag ( itag + icons[2]) doc += html.empty_tag ( itag + icons[3]) doc += html.end_tag ("/td") else: doc += html.tagged_text ("td", record[item_num]) doc += html.end_tag ("/tr") record_id += 1 doc += html.end_tag ("/table") return doc