Ver código fonte

prepare to vycontrol public SDN

Roberto Berto 4 anos atrás
pai
commit
bf41c826d9

+ 2 - 0
.gitignore

@@ -141,3 +141,5 @@ db.sqlite3
 vycontrol/vycontrol/settings/development.py
 migrations
 vycontrol/vycontrol/settings_available
+vycontrol/users
+vycontrol/on*.sh

+ 2 - 0
requirements.txt

@@ -6,3 +6,5 @@ requests==2.25.1
 python-slugify==4.0.1
 validators==0.18.2
 python-memcached==1.59
+password_strength==0.0.3.post2
+django-utils-six==2.0

+ 1 - 1
vycontrol/config/models.py

@@ -1,6 +1,6 @@
 from django.db import models
 from django.contrib.auth.models import Group
-
+from django.contrib.auth.models import User
 
 class Instance(models.Model):
     hostname = models.CharField(max_length=120, primary_key=True)

+ 5 - 1
vycontrol/config/templates/config/user_edit.html

@@ -14,10 +14,14 @@
 <form method="post" action="{% url 'config:user-edit' user %}">
 {% csrf_token %}
 <table width="100%" border="1">
+    <tr>
+        <th width="50%">name</th>
+        <td>{{ user.last_name }}</td>
+    </tr>
     <tr>
         <th width="50%">username</th>
         <td>{{ user }}</td>
-    </tr>
+    </tr>    
     <tr>
         <th width="50%">email</th>
         <td><input type="text" name="email" id="email" value="{{ user.email }}"></td>

+ 1 - 1
vycontrol/config/views.py

@@ -287,7 +287,7 @@ def user_edit(request, username):
 
     context = viewinfo.context(vinfo)    
     localcontext = {
-        'user':             user
+        'user':             user,
     }
     context.update(localcontext)
 

+ 0 - 1
vycontrol/devstart.sh

@@ -1 +0,0 @@
-python manage.py runserver --settings=vycontrol.settings_available.development

+ 13 - 1
vycontrol/libs/vycontrol_validators.py

@@ -1,6 +1,7 @@
 import validators
 from validators.utils import *
 import re
+from password_strength import PasswordPolicy
 
 
 @validator
@@ -16,4 +17,15 @@ def validator_group(value):
 @validator
 def validator_ipv4_cidr(value):
     if re.match("^(?:\d{1,3}\.){3}\d{1,3}(?:/\d\d?)?$", value):
-        return True
+        return True
+
+@validator
+def validator_password(value):
+    policy = PasswordPolicy.from_names(
+        length=8,  # min length: 8
+        uppercase=1,  # need min. 2 uppercase letters
+        numbers=1,  # need min. 2 digits
+        special=1,  # need min. 2 special characters
+    )
+    if len(policy.test(value)) == 0:
+        return True

+ 9 - 1
vycontrol/vmsg.py

@@ -41,7 +41,15 @@ class msg:
     def get_all(self):
         return self.msgs
 
-
+    def count(self, t=None):
+        if t == None:
+            return len(self.msgs)
+        else:
+            n = 0
+            for m in self.msgs:
+                if m['msg_type'] == t:
+                    n+= 1
+            return n
 
 def log(area, value = [], end = True):
     print("\n\n")

+ 2 - 1
vycontrol/vycontrol/settings.py

@@ -159,4 +159,5 @@ STATIC_URL = '/s/'
 
 
 # show footer link to VyControl
-VYCONTROL_CREDITS = True
+VYCONTROL_CREDITS = True
+VYCONTROL_CRYSPY = False

+ 2 - 2
vycontrol/vycontrol/settings_example/development.py

@@ -12,7 +12,7 @@ CACHES = {
 #    }
     'default': {
         'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
-        'LOCATION': 'my_cache_table',
+        'LOCATION': 'cache_table',
     }
 }
 
@@ -34,7 +34,7 @@ DATABASES = {
 }
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'change me warning'
+SECRET_KEY = 'e80f24280d6a7fe09c91a661b21c49c7ea5cce2cf3b81609a986310ea9a1dda9'
 
 # show footer link to VyControl
 VYCONTROL_CREDITS = True

+ 2 - 2
vycontrol/vycontrol/settings_example/production.py

@@ -12,7 +12,7 @@ CACHES = {
 #    }
     'default': {
         'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
-        'LOCATION': 'my_cache_table',
+        'LOCATION': 'cache_table',
     }
 }
 
@@ -34,7 +34,7 @@ DATABASES = {
 }
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'change me warning'
+SECRET_KEY = '281c8847762153b12d1f2a637ea1885ae6d6c4b5b3ed45232e09f3a11bb29974'
 
 # show footer link to VyControl
 VYCONTROL_CREDITS = True

+ 15 - 3
vycontrol/vycontrol/templates/base_not_logged.html

@@ -2,7 +2,7 @@
 <!doctype html>
 <html lang="en">
   <head>
-    <title>{% block header_title %}{% endblock %} - VyControl</title>
+    <title>{% if header_title %}{{ header_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">
@@ -20,7 +20,6 @@
     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" 
     integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" 
     crossorigin="anonymous"></script>
-  
     <link rel="stylesheet" href="{% static "main.css" %}?{% random_int 100000 500000 %} ">
     <script src="{% static "vycontrol.js" %}?{% random_int 100000 500000 %} "></script>  
     </head>
@@ -59,7 +58,20 @@
 
     </div>
     <div class="col content">
-        <h2>{% block section_title %}{% endblock %}</h2>
+        <h2>{% if header_title %}{{ header_title }}{% else %}{% block section_title %}{% endblock %}{% endif %}</h2>
+
+        {% for m in msg %}
+          {% if forloop.first %}  
+          <h2 id="msgs-header">Save result</h2>
+          <ul id="msgs">
+          {% endif %}
+            <li class="msgs_{{ m.msg_type }}">{{ m.msg_type }} - {{ m.msg }}</li>
+          {% if forloop.last %}  
+          </ul>
+          {% endif %}        
+        {% endfor %}
+
+        
         {% block content %}{% endblock %}
     </div>
   </div>

+ 6 - 0
vycontrol/vycontrol/urls.py

@@ -50,3 +50,9 @@ urlpatterns = [
     path('ntp/', include('ntp.urls')),
     path('dnsresolver/', include('dnsresolver.urls')),
 ]
+
+
+if settings.VYCONTROL_CRYSPY:
+    urlpatterns += [
+        path('users/', include('users.urls')),
+    ]