Browse Source

done add msg feature to static add/edit/list to increase user msg output #101

Roberto Berto 5 years ago
parent
commit
99da7ee81a

+ 1 - 8
vycontrol/firewall/templates/firewall/editrule.html

@@ -21,14 +21,11 @@
 
 
 {% block debug %}
-
 {{ ruledata_pretty }}
-
-
 {% endblock %}
 
-{% block content %}
 
+{% block content %}
 
 
 <script type="text/javascript">
@@ -37,10 +34,6 @@
 
 
 
-
-
-
-
 {% if mode == "editrule" %}
 <form action="{% url 'firewall:editrule' firewall_name rulenumber %}" method="post" id="form_change">
 {% elif mode == "addrule" %}

+ 0 - 1
vycontrol/static/templates/static/add.html

@@ -19,7 +19,6 @@
 </p>
 
 
-{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
 
 
 <h2>Create new static route</h2>

+ 16 - 14
vycontrol/static/views.py

@@ -6,6 +6,10 @@ from django.conf import settings
 from django.urls import reverse
 
 import vyos
+import vycontrol_messages as vmsg
+import vycontrol_vyos_api_lib as vapilib
+import vycontrol_vyos_api as vapi
+
 from perms import is_authenticated
 from filters.vycontrol_filters import routeunpack
 import perms
@@ -38,32 +42,30 @@ def static_list(request):
 
 @is_authenticated    
 def static_add(request):
-        
+    msg = vmsg.msg()
+
     all_instances = vyos.instance_getall()
     hostname_default = vyos.get_hostname_prefered(request)
     static_list = vyos.get_route_static(hostname_default)
     is_superuser = perms.get_is_superuser(request.user)
 
-
-    error_message = None
     if 'subnet' in request.POST and 'nexthop' in request.POST:
-        return1 = vyos.set_route_static(hostname_default, request.POST['subnet'], request.POST['nexthop'])
-        if return1 == False: 
-            error_message = 'Cannot add static route.'
+        v = vapi.set_route_static(hostname_default, request.POST['subnet'], request.POST['nexthop'])
+        if v.success == False: 
+            msg.add_error("Static route add fail - " + v.reason)
         else:
-           return redirect('static:static-list')
-
+            msg.add_success("Static route added")
 
     ippath = vyos.ip_route(hostname_default)
 
     template = loader.get_template('static/add.html')
     context = { 
-        'instances': all_instances,
-        'hostname_default': hostname_default,
-        'static_list' : static_list,
-        'error_message' : error_message,
-        'username': request.user,
-        'is_superuser' : is_superuser,     
+        'instances':                        all_instances,
+        'hostname_default':                 hostname_default,
+        'static_list' :                     static_list,
+        'username':                         request.user,
+        'is_superuser' :                    is_superuser,     
+        'msg' :                             msg.get_all(),
     }   
     return HttpResponse(template.render(context, request))
 

+ 11 - 0
vycontrol/vycontrol_vyos_api.py

@@ -361,3 +361,14 @@ def set_firewall_rule_packetstate_delete(hostname, firewall_name, rulenumber, pa
         description = "delete packetstate",
     )
     return v
+
+
+def set_route_static(hostname, subnet, nexthop):
+    v = vapilib.api (
+        hostname=   hostname,
+        api =       "post",
+        op =        "set",
+        cmd =       ["protocols", "static", "route", subnet, "next-hop", nexthop],
+        description = "set_route_static",
+    )
+    return v

+ 0 - 6
vycontrol/vyos.py

@@ -201,12 +201,6 @@ def get_route_static(hostname):
     result1 = api_get(hostname, cmd)
     return result1
 
-def set_route_static(hostname, subnet, nexthop):
-    cmd = {"op": "set", "path": ["protocols","static","route", subnet, "next-hop", nexthop]}
-
-    result1 = api_set(hostname, cmd)
-    return result1  
-
 
 def set_firewall_syncookies_enable(hostname):
     cmd = {"op": "set", "path": ["firewall","syn-cookies",'enable']}