瀏覽代碼

issues Address Group description #60 and Network Group description #61

Roberto Berto 5 年之前
父節點
當前提交
d2d78426f7

+ 43 - 0
vycontrol/firewall/templates/firewall/addressgroup-desc.html

@@ -0,0 +1,43 @@
+{% extends "base.html" %}
+
+{% block header_title %}Edit Addressgroup{% endblock %}
+{% block section_title %}Edit Addressgroup{% endblock %}
+{% block username %}{{ username }}{% endblock %}
+
+{% block debug %}
+{{ firewall_all }}
+{{ firewall_addressgroup }}
+{% endblock %}
+
+
+{% block content %}
+
+<p class="submenu1">
+    <a href="{% url 'firewall:firewall-list' %}">Firewall List</a> | 
+    <a href="{% url 'firewall:firewall-create' %}">Create new firewall</a> | 
+    <a href="{% url 'firewall:firewall-addressgroup-list' %}">Address Group</a> | 
+    <a href="{% url 'firewall:firewall-networkgroup-list' %}">Network Group</a> 
+</p>
+<p class="submenu2">
+    <a href="{% url 'firewall:firewall-networkgroup-add' %}">Add network Group</a>
+</p>
+
+<form action="{% url 'firewall:firewall-addressgroup-desc' groupname %}" method="post">
+    {% csrf_token %}
+    
+    <p>
+        <label for="alias">description</label><br>
+        <input type="text" name="description" id="description" value="{{ firewall_addressgroup.description }}" size="60">
+    </p>    
+    
+    
+    <input type="submit" value="Edit Group">
+    </form>
+
+    
+
+
+{% endblock %}
+
+
+

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

@@ -31,7 +31,7 @@
                 <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-desc' ifkey %}">Edit</a> | 
                     <a href="{% url 'firewall:firewall-addressgroup-del' ifkey %}">Remove</a>
                 </td>
             </tr>

+ 43 - 0
vycontrol/firewall/templates/firewall/networkgroup-desc.html

@@ -0,0 +1,43 @@
+{% extends "base.html" %}
+
+{% block header_title %}Edit Addressgroup{% endblock %}
+{% block section_title %}Edit Addressgroup{% endblock %}
+{% block username %}{{ username }}{% endblock %}
+
+{% block debug %}
+{{ firewall_all }}
+{{ firewall_networkgroup }}
+{% endblock %}
+
+
+{% block content %}
+
+<p class="submenu1">
+    <a href="{% url 'firewall:firewall-list' %}">Firewall List</a> | 
+    <a href="{% url 'firewall:firewall-create' %}">Create new firewall</a> | 
+    <a href="{% url 'firewall:firewall-addressgroup-list' %}">Address Group</a>     | 
+    <a href="{% url 'firewall:firewall-networkgroup-list' %}">Network Group</a> 
+</p>
+<p class="submenu2">
+    <a href="{% url 'firewall:firewall-networkgroup-add' %}">Add network Group</a>
+</p>
+
+<form action="{% url 'firewall:firewall-networkgroup-desc' groupname %}" method="post">
+    {% csrf_token %}
+    
+    <p>
+        <label for="alias">description</label><br>
+        <input type="text" name="description" id="description" value="{{ firewall_networkgroup.description }}" size="60">
+    </p>    
+    
+    
+    <input type="submit" value="Edit Group">
+    </form>
+
+    
+
+
+{% endblock %}
+
+
+

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

@@ -31,7 +31,7 @@
                 <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-desc' ifkey %}">Edit</a> | 
                     <a href="{% url 'firewall:firewall-networkgroup-del' ifkey %}">Remove</a>
                 </td>                
             </tr>

+ 41 - 5
vycontrol/firewall/views.py

@@ -274,10 +274,7 @@ def firewall_networkgroup_del(request, groupname):
     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
@@ -341,9 +338,48 @@ def firewall_addressgroup_del(request, groupname):
 @is_authenticated
 def firewall_addressgroup_desc(request, groupname):
     hostname_default = vyos.get_hostname_prefered(request)
+    firewall_addressgroup = vyos.get_firewall_addressgroup_one(hostname_default, groupname)
+    all_instances = vyos.instance_getall_by_group(request)
+    is_superuser = perms.get_is_superuser(request.user)
 
-    return redirect('firewall:firewall-addressgroup-list')
+    if request.POST.get('description', None) != None:
+        vyos.set_firewall_addressgroup_description(hostname_default, groupname, request.POST.get('description'))
+        return redirect('firewall:firewall-addressgroup-list')
+
+
+    template = loader.get_template('firewall/addressgroup-desc.html')
+    context = { 
+        'firewall_addressgroup': firewall_addressgroup,
+        'hostname_default': hostname_default,
+        'username': request.user,        
+        'instances': all_instances,
+        'is_superuser' : is_superuser,
+        'groupname': groupname,
+    }   
+    return HttpResponse(template.render(context, request))
+        
+
+@is_authenticated
+def firewall_networkgroup_desc(request, groupname):
+    hostname_default = vyos.get_hostname_prefered(request)
+    firewall_networkgroup = vyos.get_firewall_networkgroup_one(hostname_default, groupname)
+    all_instances = vyos.instance_getall_by_group(request)
+    is_superuser = perms.get_is_superuser(request.user)
+
+    if request.POST.get('description', None) != None:
+        vyos.set_firewall_networkgroup_description(hostname_default, groupname, request.POST.get('description'))
+        return redirect('firewall:firewall-networkgroup-list')
 
+    template = loader.get_template('firewall/networkgroup-desc.html')
+    context = { 
+        'firewall_networkgroup': firewall_networkgroup,
+        'hostname_default': hostname_default,
+        'username': request.user,        
+        'instances': all_instances,
+        'is_superuser' : is_superuser,
+        'groupname': groupname,
+    }   
+    return HttpResponse(template.render(context, request))
 
 
 

+ 23 - 2
vycontrol/vyos.py

@@ -233,18 +233,39 @@ def set_firewall_allping_disable(hostname):
     result1 = api_set(hostname, cmd)
     return result1  
 
+
 def get_firewall_addressgroup(hostname):
     cmd = {"op": "showConfig", "path": ["firewall","group","address-group"]}
-
     result1 = api_get(hostname, cmd)
-    return result1
+    return result1    
 
 def get_firewall_networkgroup(hostname):
     cmd = {"op": "showConfig", "path": ["firewall","group","network-group"]}
+    result1 = api_get(hostname, cmd)
+    return result1
 
+def get_firewall_addressgroup_one(hostname, group_name):
+    cmd = {"op": "showConfig", "path": ["firewall","group","address-group", group_name]}
     result1 = api_get(hostname, cmd)
     return result1
 
+def get_firewall_networkgroup_one(hostname, group_name):
+    cmd = {"op": "showConfig", "path": ["firewall","group","network-group", group_name]}
+    result1 = api_get(hostname, cmd)
+    return result1
+
+
+def set_firewall_networkgroup_description(hostname, group_name, description):
+    cmd = {"op": "set", "path": ["firewall","group",'network-group', group_name, "description", description]}
+    result1 = api_set(hostname, cmd)
+    return result1 
+
+def set_firewall_addressgroup_description(hostname, group_name, description):
+    cmd = {"op": "set", "path": ["firewall","group",'address-group', group_name, "description", description]}
+    result1 = api_set(hostname, cmd)
+    return result1     
+
+
 
 def set_firewall_addressgroup_add(hostname, group_name, address):
     cmd = {"op": "set", "path": ["firewall","group",'address-group', group_name, "address", address]}