Roberto Berto il y a 4 ans
Parent
commit
e3b218e778

+ 2 - 4
README.md

@@ -101,6 +101,8 @@ EMAIL_USE_TLS = True
 - [ ] Discussion VyControl at VyOS forum https://forum.vyos.io/t/vycenter-alpha-stage-announcement-vyos-web-interface/5221/4
 
 # changelog
+- [x] create/read/update/delete users 
+- [x] create/read/update/delete groups
 - [x] create/read/update/delete DNS Resolver
 - [x] create/read/update/delete email/password in user profile
 - [x] create/read/update/delete interfaces and vlans
@@ -113,10 +115,6 @@ EMAIL_USE_TLS = True
 
 # roadmap
 
-## vycontrol configuration
-- [ ] finish users 
-- [ ] finish groups
-
 ## vpn services
 - [ ] openvpn
 - [ ] ipsec

+ 0 - 3
vycontrol/config/templates/config/group_edit.html

@@ -1,8 +1,5 @@
 {% extends "base.html" %}
 
-{% block header_title %}dnsresolver{% endblock %}
-{% block section_title %}dnsresolver{% endblock %}
-
 {% block content %}
 
 {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

+ 0 - 5
vycontrol/config/templates/config/groups_list.html

@@ -5,11 +5,6 @@
 {{ x }}
 {% endblock %}
 
-
-{% block header_title %}dnsresolver{% endblock %}
-{% block section_title %}dnsresolver{% endblock %}
-
-
 {% block content %}
 
 <p class="submenu1">

+ 1 - 1
vycontrol/config/templates/config/instance_add.html

@@ -9,7 +9,7 @@
 {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
 
 
-<p class="margin-topbottom">To add a new VyOS <a href="https://docs.vyos.io/" target="_blank">read documentation</a>.</p>
+<p class="margin-topbottom">VyOS vyos-api need to be configurated using vyos cli/ssh according <a href="https://docs.vyos.io/" target="_blank">VyOS documentation</a>.</p>
 
 <form action="{% url 'config:instance-add' %}" method="post">
 

+ 1 - 4
vycontrol/config/templates/config/instances.html

@@ -1,8 +1,5 @@
 {% extends "base.html" %}
 
-{% block header_title %}dnsresolver{% endblock %}
-{% block section_title %}dnsresolver{% endblock %}
-
 
 {% block debug %}
     {% for instance in instances %}
@@ -36,7 +33,7 @@
     {% for instance in instances %}
     <tr>
         <td>{{ instance.alias }}</td>
-        <td>{{ instance.hostname }}</td>
+        <td><a href="{% url 'config:instance-edit' instance.hostname %}">{{ instance.hostname }}</a></td>
         <td>{{ instance.port }}</td>
         <td>show</td>
         <td>{{ instance.https }}</td>

+ 4 - 2
vycontrol/config/urls.py

@@ -6,19 +6,21 @@ from . import views
 app_name = 'config'
 
 urlpatterns = [
-    path('instance-change/<str:hostname>', views.instance_change, name='instance-change'),
     path('users-list', views.users_list, name='users-list'),
     path('user-inactivate/<str:username>', views.user_inactivate, name='user-inactivate'),
     path('user-activate/<str:username>', views.user_activate, name='user-activate'),
     path('user-edit/<str:username>', views.user_edit, name='user-edit'),
+    path('user-add', views.user_add, name='user-add'),
+
     path('groups-list', views.groups_list, name='groups-list'),
     path('group-add', views.group_add, name='group-add'),
     path('group-edit/<str:group_name>', views.group_edit, name='group-edit'),
     path('group-activate/<str:group_name>', views.group_activate, name='group-activate'),
     path('group-inactivate/<str:group_name>', views.group_inactivate, name='group-inactivate'),
 
-    path('user-add', views.user_add, name='user-add'),
+    path('instance-change/<str:hostname>', views.instance_change, name='instance-change'),
     path('instance-add', views.instance_add, name='instance-add'),
+    path('instance-edit/<str:hostname>', views.instance_edit, name='instance-edit'),
     path('instance-conntry/<str:hostname>', views.instance_conntry, name='instance-conntry'),
     path('instance-remove/<str:hostname>', views.instance_remove, name='instance-remove'),
     path('instance-changegroup/<str:hostname>', views.instance_changegroup, name='instance-changegroup'),

+ 58 - 3
vycontrol/config/views.py

@@ -93,7 +93,7 @@ def users_list(request):
 @perms.is_superuser
 @is_authenticated
 def groups_list(request):
-    vinfo = viewinfo.prepare(request)
+    vinfo = viewinfo.prepare(request, title="Groups list")
 
     groups = Group.objects.all()
 
@@ -108,7 +108,7 @@ def groups_list(request):
 
 @is_authenticated
 def instances(request):
-    vinfo = viewinfo.prepare(request)
+    vinfo = viewinfo.prepare(request, "Instances List")
 
     if vinfo.hostname_default == None:
         if vinfo.all_instances.count() > 0:
@@ -376,6 +376,61 @@ def instance_changegroup(request, hostname):
 
     return redirect('config:instances')
 
+@perms.is_superuser
+@is_authenticated
+def instance_edit(request, hostname):
+
+    if not validators.domain(hostname) and not validators.ipv4(hostname):
+        return redirect('config:instances')
+
+    vinfo = viewinfo.prepare(request, "Instance edit " + hostname)
+
+    try:
+        instance = Instance.objects.get(hostname=hostname)
+    except Instance.DoesNotExist:
+        return redirect('config:instances')
+
+    if len(request.POST) > 0:
+        error = False
+
+        instance.alias = request.POST.get('alias').strip()
+        instance.hostname = request.POST.get('hostname').strip()
+        instance.port = request.POST.get('port').strip()
+        try:
+            port_number = int(instance.port)
+        except:
+            port_number = 0
+        instance.key = request.POST.get('key').strip()
+
+        if 'https' in request.POST:
+            instance.https = True
+        else:
+            instance.https = False
+
+        if not validator_letters_numbers(instance.alias):
+            error = True
+            vinfo.msg.add_error("Alias need to be letters and numbers only")
+        if not validators.domain(instance.hostname) and not validators.ipv4(instance.hostname):
+            error = True
+            vinfo.msg.add_error("Hostname need to be only domain or ipv4")
+        if not validator_letters_numbers(instance.key):
+            error = True
+            vinfo.msg.add_error("Key need to be letters and numbers only")
+        if not validators.between(port_number, 1, 65535):
+            error = True
+            vinfo.msg.add_error("Port need to be between 1 and 65535")
+
+        if error == False:
+            instance.save()
+
+    context = viewinfo.context(vinfo)    
+    localcontext = {
+        'instance':         instance,
+    }
+    context.update(localcontext)
+
+    return render(request, 'config/instance_edit.html', context) 
+
 
 @perms.is_superuser
 @is_authenticated    
@@ -403,7 +458,7 @@ def group_activate(request, group_name):
 @perms.is_superuser
 @is_authenticated    
 def group_edit(request, group_name):
-    vinfo = viewinfo.prepare(request)
+    vinfo = viewinfo.prepare(request, title="Group edit")
 
     if validator_group(group_name):
         group = Group.objects.get(name=group_name)

+ 6 - 1
vycontrol/viewinfo.py

@@ -10,8 +10,10 @@ class prepareClass:
     request = None
     msg = None
     debug = False
+    vycontrol_credits = False
+    title = ""
 
-def prepare(request):
+def prepare(request, title=None):
     p = prepareClass()
 
     p.all_instances = perms.instance_getall_by_group(request)
@@ -21,6 +23,8 @@ def prepare(request):
     p.msg = vmsg.msg()
     p.debug = settings.DEBUG
     p.vycontrol_credits = settings.VYCONTROL_CREDITS
+    if title != None:
+        p.title = title
 
     return p
 
@@ -33,6 +37,7 @@ def context(prepare):
         'msg' :                                     prepare.msg.get_all(),
         'debugactive' :                             prepare.debug,
         'vycontrol_credits' :                       prepare.vycontrol_credits,
+        'title' :                                   prepare.title,
                                
     }
     return contextPrepare

+ 2 - 2
vycontrol/vycontrol/templates/base.html

@@ -2,7 +2,7 @@
 <!doctype html>
 <html lang="en">
   <head>
-  <title>{% block header_title %}{% endblock %} - VyControl</title>
+  <title>{% if title %}{{ title }}{% else %}{% block header_title %}{% endblock %}{% endif %} - VyControl</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
@@ -96,7 +96,7 @@
 
     </div>
     <div class="col content">
-        <h2>{% block section_title %}{% endblock %}</h2>
+        <h2>{% if title %}{{ title }}{% else %}{% block section_title %}{% endblock %}{% endif %}</h2>
 
         {% block submenu %}{% endblock %}