Ver código fonte

fixing first login

Roberto Berto 4 anos atrás
pai
commit
a56869591a

+ 2 - 5
vycontrol/accounts/views.py

@@ -39,11 +39,8 @@ def index(request):
         if 'username' in request.POST and 'password' in request.POST:
             user = User.objects.create_superuser(username=request.POST['username'], email='', password=request.POST['password'])
             user.save()
-            return redirect('interface:interface-list')
-
-    context = { 
-        'users_admin': users_admin.all(),
-    }   
+            return redirect('instances')
+ 
     return render(request, 'accounts/start.html', context)
 
 

+ 4 - 0
vycontrol/config/views.py

@@ -120,10 +120,14 @@ def instances(request):
 
     groups = Group.objects.filter(active=True)
 
+
     context = viewinfo.context(vinfo)    
     localcontext = {
         'groups' : groups,
     }
+    if len(vinfo.all_instances) == 0:
+        localcontext['noinstance'] = True
+        
     context.update(localcontext)
 
     return render(request, 'config/instances.html', context)   

+ 3 - 2
vycontrol/perms.py

@@ -29,7 +29,8 @@ def is_authenticated(func):
         
         # check if return a valid hostname
         hostname = get_hostname_prefered(request)
-        if hostname == None:
+        userdata = user[0]
+        if hostname == None and userdata.is_superuser == False:
             return redirect('%s?next=%s' % (reverse('accounts-login'), request.path))
 
         value = func(*args, **kwargs)
@@ -188,4 +189,4 @@ def get_hostname_prefered(request):
             except Instance.DoesNotExist:
                 pass
    
-    return hostname
+    return hostname

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

@@ -67,33 +67,33 @@
         <h1 align="center"><a href="/"><img src="https://storage.googleapis.com/vycontrol/logos/logotxt.png?x" width="170"  height="30" alt="vycontrol"></a></h1>
       </p>
 
-
-    <h2>Router</h2>
-
-    <ul class="menuleft">
-    <li><a href="{% url 'interface:interface-list' %}">Interfaces</a></li>
-    <li><a href="{% url 'firewall:firewall-list' %}">Firewall</a></li>
-    <li><a href="{% url 'static:static-list' %}">Static Routes</a></li>
-    <li><a href="{% url 'dnsresolver:dnsresolver-list' %}">DNS resolver</a></li>
-    <li><a href="{% url 'ntp:ntp-list' %}">NTP</a></li>
-    </ul>
-    
- 
-    {% if is_superuser %}
-    <h2>VyControl Administrator</h2>
-    <ul class="menuleft">
-    <li><a href="{% url 'config:instances' %}">Instances</a></li>
-    <li><a href="{% url 'config:users-list' %}">Users</a></li>
-    <li><a href="{% url 'config:groups-list' %}">Groups</a></li>
-    </ul>
-    {% else %}
-    <h2>VyControl</h2>
-    <ul class="menuleft">
-    <li><a href="{% url 'config:instances' %}">Instances</a></li>
-    </ul>
+    {% if not noinstance %}
+      <h2>Router</h2>
+
+      <ul class="menuleft">
+      <li><a href="{% url 'interface:interface-list' %}">Interfaces</a></li>
+      <li><a href="{% url 'firewall:firewall-list' %}">Firewall</a></li>
+      <li><a href="{% url 'static:static-list' %}">Static Routes</a></li>
+      <li><a href="{% url 'dnsresolver:dnsresolver-list' %}">DNS resolver</a></li>
+      <li><a href="{% url 'ntp:ntp-list' %}">NTP</a></li>
+      </ul>
+      
+  
+      {% if is_superuser %}
+      <h2>VyControl Administrator</h2>
+      <ul class="menuleft">
+      <li><a href="{% url 'config:instances' %}">Instances</a></li>
+      <li><a href="{% url 'config:users-list' %}">Users</a></li>
+      <li><a href="{% url 'config:groups-list' %}">Groups</a></li>
+      </ul>
+      {% else %}
+      <h2>VyControl</h2>
+      <ul class="menuleft">
+      <li><a href="{% url 'config:instances' %}">Instances</a></li>
+      </ul>
+      {% endif %}
     {% endif %}
 
-
     </div>
     <div class="col content">
         <h2>{% if title %}{{ title }}{% else %}{% block section_title %}{% endblock %}{% endif %}</h2>

+ 10 - 3
vycontrol/vyos.py

@@ -15,7 +15,11 @@ def repvar(s):
 
 def get_url(hostname):
     # permcheck
-    instance = Instance.objects.get(hostname=hostname)
+    try:
+        instance = Instance.objects.get(hostname=hostname)
+    except Instance.DoesNotExist:
+        return ''
+
     if instance.https == True:
         protocol = "https"
     else:
@@ -45,8 +49,11 @@ def get_url_retrieve(hostname):
     return url
 
 def get_key(hostname):
-    # permcheck
-    instance = Instance.objects.get(hostname=hostname)
+    try:
+        instance = Instance.objects.get(hostname=hostname)
+    except Instance.DoesNotExist:
+        return None
+
     return instance.key
 
 def api(type, hostname, cmd):