Przeglądaj źródła

remove Address Group and Network Group #67

Roberto Berto 5 lat temu
rodzic
commit
856ed9fc3c

+ 1 - 1
vycontrol/filters/vycontrol_filters.py

@@ -9,4 +9,4 @@ def routepack(value):
 @register.filter
 def routeunpack(value): 
     """UnpPack a route into a string"""
-    return str(value).replace("!","/")
+    return str(value).replace("!","/")

+ 5 - 1
vycontrol/firewall/templates/firewall/addressgroup-list.html

@@ -22,7 +22,7 @@
 
 {% if firewall_addressgroup %}
     <table border="1" width="100%">
-        <tr><th width="25%">name</th><th width="25%">address</th><th width="50%">description</th></tr>
+        <tr><th width="25%">name</th><th width="20%">address</th><th width="30%">description</th><th width="25%">actions</th></tr>
 
     {% for key, value in firewall_addressgroup.items %}       
         {% for ifkey, ifvalue in value.items %}
@@ -30,6 +30,10 @@
                 <td>{{ ifkey }}</a></td>
                 <td>{{ ifvalue.address }}</td>
                 <td>{{ ifvalue.description }}</td>
+                <td>
+                    <a href="{% url 'firewall:firewall-addressgroup-desc' ifkey %}">Edit Description</a> | 
+                    <a href="{% url 'firewall:firewall-addressgroup-del' ifkey %}">Remove</a>
+                </td>
             </tr>
         {% endfor %}
         

+ 5 - 1
vycontrol/firewall/templates/firewall/networkgroup-list.html

@@ -22,7 +22,7 @@
 
 {% if firewall_networkgroup %}
     <table border="1" width="100%">
-        <tr><th width="25%">name</th><th width="25%">network</th><th width="50%">description</th></tr>
+        <tr><th width="25%">name</th><th width="20%">address</th><th width="30%">description</th><th width="25%">actions</th></tr>
 
     {% for key, value in firewall_networkgroup.items %}       
         {% for ifkey, ifvalue in value.items %}
@@ -30,6 +30,10 @@
                 <td>{{ ifkey }}</a></td>
                 <td>{{ ifvalue.network }}</td>
                 <td>{{ ifvalue.description }}</td>
+                <td>
+                    <a href="{% url 'firewall:firewall-networkgroup-desc' ifkey %}">Edit Description</a> | 
+                    <a href="{% url 'firewall:firewall-networkgroup-del' ifkey %}">Remove</a>
+                </td>                
             </tr>
         {% endfor %}
         

+ 5 - 0
vycontrol/firewall/urls.py

@@ -14,11 +14,16 @@ urlpatterns = [
     path('firewall-edit/<str:firewall_name>', views.firewall_edit, name='firewall-edit'),
     path('firewall-config/<str:firewall_name>', views.firewall_config, name='firewall-config'),
     path('firewall-global', views.firewall_global, name='firewall-global'),
+
     path('firewall-addressgroup-list', views.firewall_addressgroup_list, name='firewall-addressgroup-list'),
     path('firewall-addressgroup-add', views.firewall_addressgroup_add, name='firewall-addressgroup-add'),
+    path('firewall-addressgroup-del/<str:groupname>', views.firewall_addressgroup_del, name='firewall-addressgroup-del'),
+    path('firewall-addressgroup-desc/<str:groupname>', views.firewall_addressgroup_desc, name='firewall-addressgroup-desc'),
 
     path('firewall-networkgroup-list', views.firewall_networkgroup_list, name='firewall-networkgroup-list'),
     path('firewall-networkgroup-add', views.firewall_networkgroup_add, name='firewall-networkgroup-add'),
+    path('firewall-networkgroup-del/<str:groupname>', views.firewall_networkgroup_del, name='firewall-networkgroup-del'),
+    path('firewall-networkgroup-desc/<str:groupname>', views.firewall_networkgroup_desc, name='firewall-networkgroup-desc'),    
 
 
 

+ 25 - 3
vycontrol/firewall/views.py

@@ -268,6 +268,18 @@ def firewall_networkgroup_add(request):
     return HttpResponse(template.render(context, request))
 
 
+@is_authenticated
+def firewall_networkgroup_del(request, groupname):
+    hostname_default = vyos.get_hostname_prefered(request)
+    vyos.set_firewall_networkgroup_del(hostname_default, groupname)
+    return redirect('firewall:firewall-networkgroup-list')
+
+@is_authenticated
+def firewall_networkgroup_desc(request, groupname):
+    hostname_default = vyos.get_hostname_prefered(request)
+    return redirect('firewall:firewall-networkgroup-list')
+
+
 @is_authenticated
 def firewall_addressgroup_list(request):
         
@@ -320,9 +332,19 @@ def firewall_addressgroup_add(request):
     }   
     return HttpResponse(template.render(context, request))
 
-#@is_authenticated
-#def firewall_networkbook(request):
-#    return redirect('firewall:firewall-list')
+@is_authenticated
+def firewall_addressgroup_del(request, groupname):
+    hostname_default = vyos.get_hostname_prefered(request)
+    vyos.set_firewall_addressgroup_del(hostname_default, groupname)
+    return redirect('firewall:firewall-addressgroup-list')
+
+@is_authenticated
+def firewall_addressgroup_desc(request, groupname):
+    hostname_default = vyos.get_hostname_prefered(request)
+
+    return redirect('firewall:firewall-addressgroup-list')
+
+
 
 
 @is_authenticated

+ 13 - 6
vycontrol/vyos.py

@@ -19,8 +19,6 @@ def get_hostname_prefered(*args, **kwargs):
 def instance_getall_by_group(*args, **kwargs):
     return perms.instance_getall_by_group(*args, **kwargs)
 
-
-
 def repvar(s):
     return s.replace("-", "_")
 
@@ -136,10 +134,6 @@ def conntry(hostname):
     return False
 
 
-
-
-
-
 def get_firewall_all(hostname):
     cmd = {"op": "showConfig", "path": ["firewall"]}
     firewall_list = api_get(hostname, cmd)
@@ -258,6 +252,19 @@ def set_firewall_addressgroup_add(hostname, group_name, address):
     result1 = api_set(hostname, cmd)
     return result1 
 
+def set_firewall_addressgroup_del(hostname, group_name):
+    cmd = {"op": "delete", "path": ["firewall","group",'address-group', group_name]}
+    result1 = api_set(hostname, cmd)
+    return result1 
+
+def set_firewall_networkgroup_del(hostname, group_name):
+    cmd = {"op": "delete", "path": ["firewall","group",'network-group', group_name]}
+    result1 = api_set(hostname, cmd)
+    return result1 
+
+
+
+
 def set_firewall_addressgroup_rangeadd(hostname, group_name, address_start, address_end):
     address = str(address_start) + "-" + str(address_end)
     cmd = {"op": "set", "path": ["firewall","group",'address-group', group_name, "address", address]}