def interface_show(request, interface_type, interface_name): all_instances = perms.instance_getall_by_group(request) hostname_default = perms.get_hostname_prefered(request) is_superuser = perms.get_is_superuser(request.user) firewall_all = vyos.get_firewall_all(hostname_default) interface = vyos.get_interface(interface_type, interface_name, hostname=hostname_default) interface_detail = vyos.detail_interface(interface_type, interface_name) interface_vif = interface_detail['vlan_id'] interface_name_short = interface_detail['interface_name'] interface_children = vyos.get_interface_children(hostname_default, interface_name_short) template = loader.get_template('interface/show.html') context = { 'interface_children': interface_children, 'interface': interface, 'interface_vif': interface_vif, 'instances': all_instances, 'interface_type': interface_type, 'interface_name': interface_name, 'hostname_default': hostname_default, 'firewall_all': firewall_all, 'username': request.user, 'is_superuser': is_superuser, } return HttpResponse(template.render(context, request))
def interface_set_firewall(request, interface_type, interface_name): hostname_default = perms.get_hostname_prefered(request) interface = vyos.get_interface(interface_type, interface_name, hostname=hostname_default) interface_detail = vyos.detail_interface(interface_type, interface_name) interface_vif = interface_detail['vlan_id'] interface_name_short = interface_detail['interface_name'] actual_firewall_in = None if 'firewall' in interface: if 'in' in interface['firewall']: if 'name' in interface['firewall']['in']: actual_firewall_in = interface['firewall']['in']['name'] actual_firewall_out = None if 'firewall' in interface: if 'out' in interface['firewall']: if 'name' in interface['firewall']['out']: actual_firewall_out = interface['firewall']['out']['name'] if request.POST.get('firewall-ipv4-in', None) != None and request.POST.get( 'firewall-ipv4-out', None) != None: if request.POST.get('firewall-ipv4-in') == '': v = vapi.delete_interface_firewall_ipv4(hostname_default, interface_type, interface_name_short, "in", interface_vif) elif actual_firewall_in == None or request.POST.get( 'firewall-ipv4-in') != interface['firewall']['in']['name']: v = vapi.set_interface_firewall_ipv4( hostname_default, interface_type, interface_name_short, "in", request.POST.get('firewall-ipv4-in'), interface_vif) if request.POST.get('firewall-ipv4-out') == '': v = vapi.delete_interface_firewall_ipv4(hostname_default, interface_type, interface_name_short, "out", interface_vif) elif actual_firewall_out == None or request.POST.get( 'firewall-ipv4-out') != interface['firewall']['out']['name']: v = vapi.set_interface_firewall_ipv4( hostname_default, interface_type, interface_name_short, "out", request.POST.get('firewall-ipv4-out'), interface_vif) return redirect('interface:interface-show', interface_type=interface_type, interface_name=interface_name)
def interfacefirewall(request, interface_type, interface_name): all_instances = vyos.instance_getall() is_superuser = perms.get_is_superuser(request.user) hostname_default = vyos.get_hostname_prefered(request) interface = vyos.get_interface(interface_type, interface_name, hostname=hostname_default) template = loader.get_template('interface/show.html') context = { 'interface': interface, 'instances': all_instances, 'hostname_default': hostname_default, 'interface_type': interface_type, 'interface_name': interface_name, 'username': request.user, 'is_superuser': is_superuser, } return HttpResponse(template.render(context, request))