def display_site_landing(request): """ Display a list of all the available sites """ page_renderer = get_renderer("../templates/site_landing.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "modals/modal.js", "modals/iteminfo_modal.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during item request") return None # get all sites that are in a source mesh, or that have a test scheduled # with them as the sources sources = ampy.get_amp_sources() sourcenames = [x["ampname"] for x in sources] sources.extend([x for x in ampy.get_amp_site_endpoints() if x["ampname"] not in sourcenames]) sources.sort(key=lambda x: (x["longname"], x["ampname"])) # get all sites that are in a destination mesh, or are not in a mesh destinations = ampy.get_amp_destinations() destinations.extend(ampy.get_amp_meshless_sites()) destinations.sort(key=lambda x: (x["longname"], x["ampname"])) # exclude any sources from the destinations list sourcenames = [x["ampname"] for x in sources] destinations = [x for x in destinations if x["ampname"] not in sourcenames] banopts = getBannerOptions(request) # TODO can this be done automatically when generating the lists? for source in sources: source["urlname"] = escapeURIComponent(source["ampname"]) for destination in destinations: destination["urlname"] = escapeURIComponent(destination["ampname"]) return { "title": "AMP Measurement Sites", "body": body, "scripts": SCRIPTS, "styles": ["bootstrap.min.css"], "sources": sources, "destinations": destinations, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def display_member_modal(request, ampname, category): """ Generate the content for the mesh membership modification modal """ # TODO make sure all templates are in sensible places request.override_renderer = "../templates/member.pt" ampy = initAmpy(request) if ampy is None: print("Error starting ampy during mesh membership request") return None ampname = urllib.parse.unquote(ampname) if category == "site": members = ampy.get_meshes(None, site=ampname) available = ampy.get_meshes(None) else: members = get_mesh_members(ampy, ampname) available = ampy.get_amp_sites() # XXX exclude members return { "title": "Modify mesh membership", "ampname": ampname, "urlname": escapeURIComponent(ampname), "category": category, "members": members, "available": available, # XXX exclude members }
def create_item(request): ampy = initAmpy(request) if ampy is None: return HTTPInternalServerError() try: body = request.json_body ampname = body["ampname"] longname = body["longname"] description = body["description"] if request.matched_route.name == "allsites": location = body["location"] elif request.matched_route.name == "allmeshes": public = body["public"] issource = body["issource"] except (ValueError, KeyError): return HTTPBadRequest(body=json.dumps({"error": "missing value"})) if re.search("[^.:/a-zA-Z0-9_-]", ampname) is not None: return HTTPBadRequest( body=json.dumps({"error": "bad characters in ampname"})) if request.matched_route.name == "allsites": result = ampy.add_amp_site(ampname, longname, location, description) url = request.route_url("onesite", name=escapeURIComponent(ampname)) label = "site" elif request.matched_route.name == "allmeshes": result = ampy.add_amp_mesh(ampname, longname, description, public, issource) url = request.route_url("onemesh", mesh=escapeURIComponent(ampname)) label = "mesh" else: return HTTPBadRequest() if result: return HTTPCreated(headers=[("Location", url)], body=json.dumps( {label: { "ampname": ampname, "url": url, }})) return HTTPBadRequest()
def convert_schedule_item(source, item, mesh_info, site_info): item["period"] = _period_string(item["start"], item["end"], item["frequency"], item["period"]) item["raw_frequency"] = item["frequency"] item["frequency"] = _frequency_string(item["frequency"]) item["fullargs"] = _full_arg_strings(item["test"], item["args"]) item["source"] = { "ampname": source["ampname"], "longname": source["longname"], "urlname": escapeURIComponent(source["ampname"]) } item["meshes"] = [] item["sites"] = [] for target in item["dest_mesh"]: item["meshes"].append(mesh_info[target]) for target in item["dest_site"]: # strip any address family suffixes that might be present prefix = target.split("!", 1)[0] if target == prefix: info = site_info[prefix] else: # copy the info so we can overwrite the ampname and longname info = site_info[prefix].copy() info["ampname"] = target suffixes = target.split("!")[1:] count = None family = None # print extra human readable information about the suffixes used for suffix in suffixes: if suffix == "v4": family = "IPv4" elif suffix == "v6": family = "IPv6" elif suffix == "1": count = suffix + " address" else: # XXX this assumes suffix is a useful number count = suffix + " addresses" info["longname"] += " (%s)" % ( ",".join(x for x in [count, family] if x)) item["sites"].append(info) return item
def display_mesh_landing(request): """ Display a list of all the available meshes """ page_renderer = get_renderer("../templates/mesh_landing.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "modals/modal.js", "modals/iteminfo_modal.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during item request") return None meshes = ampy.get_meshes(None) banopts = getBannerOptions(request) for mesh in meshes: mesh["urlname"] = escapeURIComponent(mesh["ampname"]) return { "title": "AMP Measurement Meshes", "body": body, "scripts": SCRIPTS, "styles": ["bootstrap.min.css"], "meshes": meshes, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def display_item_info(request, ampname, category): """ Display an information page about a single site or mesh """ page_renderer = get_renderer("../templates/item.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "lib/bootstrap-datetimepicker.min.js", "modals/modal.js", "modals/member_modal.js", "modals/iteminfo_modal.js", "modals/schedule_modal.js", "pages/item.js", ] STYLES = [ "bootstrap-datetimepicker.min.css", "bootstrap.min.css", ] ampname = urllib.parse.unquote(ampname) ampy = initAmpy(request) if ampy is None: print("Error starting ampy during schedule request") return None if category == "site": source = ampy.get_amp_site_info(ampname) members = meshes = ampy.get_meshes(None, site=ampname) else: meshes = {} source = ampy.get_amp_mesh_info(ampname) members = get_mesh_members(ampy, ampname) for member in members: member["urlname"] = escapeURIComponent(member["ampname"]) if "unknown" in source and source["unknown"] is True: return HTTPNotFound() # turn the list of dicts into a dict of dicts, keyed by ampname full_mesh_info = dict((x["ampname"], x) for x in ampy.get_meshes(None)) # XXX for mesh in full_mesh_info: full_mesh_info[mesh]["urlname"] = escapeURIComponent( full_mesh_info[mesh]["ampname"]) # get full info for any possible destinations that we have destinations = ampy.get_amp_destinations() destinations.extend(ampy.get_amp_meshless_sites()) full_dest_info = dict((x["ampname"], x) for x in destinations) # XXX for dest in full_dest_info: full_dest_info[dest]["urlname"] = escapeURIComponent( full_dest_info[dest]["ampname"]) # load the schedule for this particular source schedule = ampy.get_amp_source_schedule(ampname) schedule = [convert_schedule_item( source, x, full_mesh_info, full_dest_info) for x in schedule] # if it belongs to any meshes, then load those schedules too for mesh in meshes: mesh_schedule = ampy.get_amp_source_schedule(mesh["ampname"]) mesh_schedule = [convert_schedule_item( mesh, x, full_mesh_info, full_dest_info) for x in mesh_schedule] schedule.extend(mesh_schedule) # sort the schedule by test, then from most frequent to less frequent schedule.sort(key=lambda x: x["end"]) schedule.sort(key=lambda x: x["start"]) schedule.sort(key=lambda x: x["raw_frequency"]) schedule.sort(key=lambda x: x["test"]) # report on the current certificate status if possible if category == "site": source["pki"] = get_certificate_status(ampname) banopts = getBannerOptions(request) return { "title": "AMP Measurement Schedules for %s" % ampname, "page": "schedule", "body": body, "scripts": SCRIPTS, "styles": STYLES, "category": category, "ampname": ampname, "urlname": escapeURIComponent(ampname), "item": source, "members": members, "schedule": schedule, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }