Browse Source

Merge pull request #127 from jibaku/feature/ntp

very basic ntp module (list ntp server)
Roberto Bertó 5 years ago
parent
commit
02ea287090

+ 0 - 0
vycontrol/ntp/__init__.py


+ 3 - 0
vycontrol/ntp/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 5 - 0
vycontrol/ntp/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class NtpConfig(AppConfig):
+    name = 'ntp'

+ 0 - 0
vycontrol/ntp/migrations/__init__.py


+ 3 - 0
vycontrol/ntp/models.py

@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.

+ 18 - 0
vycontrol/ntp/templates/ntp/list.html

@@ -0,0 +1,18 @@
+{% extends "base.html" %}
+
+{% block header_title %}NTP{% endblock %}
+{% block section_title %}NTP{% endblock %}
+
+{% block debug %}
+{% endblock %}
+
+{% block content %}
+<h3>Servers</h3>
+
+<ul>
+{% for server in ntp_servers %}
+    <li>{{ server }}</li>
+{% endfor %}
+</ul>
+{% endblock %}
+

+ 3 - 0
vycontrol/ntp/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 12 - 0
vycontrol/ntp/urls.py

@@ -0,0 +1,12 @@
+from django.urls import path
+
+from . import views
+
+app_name = 'ntp'
+
+
+urlpatterns = [
+    path('', views.index, name='ntp-list'),
+]
+
+

+ 20 - 0
vycontrol/ntp/views.py

@@ -0,0 +1,20 @@
+from django.shortcuts import render
+from django.http import HttpResponse
+from django.template import loader
+from django.shortcuts import redirect
+from django.conf import settings
+from django.urls import reverse
+from django.contrib.auth.decorators import login_required
+
+import vyos
+import vycontrol_vyos_api as vapi
+
+@login_required
+def index(request):
+    all_instances = vyos.instance_getall()
+    hostname_default = vyos.get_hostname_prefered(request)
+    ntp_srv = vapi.get_ntp(hostname_default)
+    context = {'instances': all_instances,
+               'hostname_default': hostname_default,
+               'ntp_servers': ntp_srv.data['server']}
+    return render(request, 'ntp/list.html', context)

+ 2 - 1
vycontrol/vycontrol/settings.py

@@ -54,6 +54,7 @@ INSTALLED_APPS = [
     'dhcp.apps.DhcpConfig',
     'dhcp.apps.DhcpConfig',
     'ipsec.apps.IpsecConfig',
     'ipsec.apps.IpsecConfig',
     'nat.apps.NatConfig',
     'nat.apps.NatConfig',
+    'ntp.apps.NtpConfig',
     'qos.apps.QosConfig',
     'qos.apps.QosConfig',
     'openvpn.apps.OpenvpnConfig',
     'openvpn.apps.OpenvpnConfig',
     'ospf.apps.OspfConfig',
     'ospf.apps.OspfConfig',
@@ -148,7 +149,7 @@ AUTH_PASSWORD_VALIDATORS = [
         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
     },
     },
 ]
 ]
-
+LOGIN_URL = '/login/'
 
 
 # Internationalization
 # Internationalization
 # https://docs.djangoproject.com/en/3.0/topics/i18n/
 # https://docs.djangoproject.com/en/3.0/topics/i18n/

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

@@ -95,12 +95,15 @@
     <li><a href="{% url 'ipsec:ipsec-list' %}">IPSEC</a></li>
     <li><a href="{% url 'ipsec:ipsec-list' %}">IPSEC</a></li>
     </ul>
     </ul>
 
 
+    <h2>Manage NTP</h2>
+    <ul>
+      <li><a href="{% url 'ntp:ntp-list' %}">NTP</a></li>
+    </ul>
 
 
     <h2>Manage NAT</h2>
     <h2>Manage NAT</h2>
     <ul>
     <ul>
       <li><a href="{% url 'nat:nat-list' %}">NAT</a></li>
       <li><a href="{% url 'nat:nat-list' %}">NAT</a></li>
-    </ul>    
-
+    </ul>
     <h2>Manage QoS</h2>
     <h2>Manage QoS</h2>
     <ul>
     <ul>
     <li><a href="{% url 'qos:qos-list' %}">QoS</a></li>
     <li><a href="{% url 'qos:qos-list' %}">QoS</a></li>

+ 3 - 5
vycontrol/vycontrol/urls.py

@@ -45,19 +45,17 @@ urlpatterns = [
 
 
     path('interface/', include('interface.urls')),
     path('interface/', include('interface.urls')),
 
 
-    path('firewall/', include('firewall.urls')),
-    path('static/', include('static.urls')),
     path('arp/', include('arp.urls')),
     path('arp/', include('arp.urls')),
     path('bgp/', include('bgp.urls')),
     path('bgp/', include('bgp.urls')),
     path('dhcp/', include('dhcp.urls')),
     path('dhcp/', include('dhcp.urls')),
+    path('firewall/', include('firewall.urls')),
     path('ipsec/', include('ipsec.urls')),
     path('ipsec/', include('ipsec.urls')),
     path('nat/', include('nat.urls')),
     path('nat/', include('nat.urls')),
+    path('ntp/', include('ntp.urls')),
     path('openvpn/', include('openvpn.urls')),
     path('openvpn/', include('openvpn.urls')),
     path('ospf/', include('ospf.urls')),
     path('ospf/', include('ospf.urls')),
     path('qos/', include('qos.urls')),
     path('qos/', include('qos.urls')),
     path('ssh/', include('ssh.urls')),
     path('ssh/', include('ssh.urls')),
+    path('static/', include('static.urls')),
     path('wanlb/', include('wanlb.urls')),
     path('wanlb/', include('wanlb.urls')),
 ]
 ]
-
-
-

+ 10 - 1
vycontrol/vycontrol_vyos_api.py

@@ -446,7 +446,6 @@ def get_firewall_zones(hostname):
     )
     )
     return v
     return v
 
 
-
 def get_firewall_zone(hostname, zone):
 def get_firewall_zone(hostname, zone):
     v = vapilib.api (
     v = vapilib.api (
         hostname=   hostname,
         hostname=   hostname,
@@ -531,3 +530,13 @@ def delete_interface_firewall_zone_rule_firewall(hostname, dstzone, srczone, fir
         description = "delete_interface_firewall_zone_rule",
         description = "delete_interface_firewall_zone_rule",
     )
     )
     return v  
     return v  
+
+def get_ntp(hostname):
+    v = vapilib.api (
+        hostname=   hostname,
+        api =       "get",
+        op =        "showConfig",
+        cmd =       ["system","ntp"],
+        description = "get_ntp",
+    )
+    return v