Can not find "session_ttl" parametr. Check into config, "main" section
')
-
-if form.getvalue('logout') is not None:
- cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
- user_id = cookie.get('uuid')
+if create_db.check_db():
+ if create_db.create_table():
+ create_db.update_all()
+ db_create = 'Please check the config for the presence of the parameter - "log_path".
')
try:
- log = open(log_path + viewlog, "r")
+ log = open(log_path + viewlog, "r",encoding='utf-8', errors='ignore')
except IOError:
print('
+
+
+
+
+
+
+
+
+
+
+
+
+ {% if add %}
+
+
{{ add }} was success added
+ {{ conf_add }}
+
+ {% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/admin.html b/app/templates/admin.html
new file mode 100644
index 00000000..446ebaed
--- /dev/null
+++ b/app/templates/admin.html
@@ -0,0 +1,303 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+
+
+
+
+
+
+
+ Name
+ Desciption
+
+
+
+
+ {% for role in roles %}
+
+ {{role.1}}
+ {{role.2}}
+
+ {% endfor %}
+
+
+
+
+
+ Upload SSH Key
+
+ Key(?)
+
+
+
+
+
+ Note: Paste pem file content here
+
+
+
+ Upload
+
+
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/base.html b/app/templates/base.html
new file mode 100644
index 00000000..53af6b40
--- /dev/null
+++ b/app/templates/base.html
@@ -0,0 +1,188 @@
+
+
+
{{title}} - HAproxy-WI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {% if h2 %}
+
+ {{title}}
+ {% if autorefresh %}
+
+
+
+ Auto-refresh
+ Auto-refresh
+
+ {% endif %}
+
+ {% endif %}
+ {% if autorefresh %}
+
+
+ Refresh Interval
+
+
+
+ {% endif %}
+ {% block content %}{% endblock %}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/templates/config.html b/app/templates/config.html
new file mode 100644
index 00000000..f0ed74c3
--- /dev/null
+++ b/app/templates/config.html
@@ -0,0 +1,67 @@
+{% extends "base.html" %}
+{% block content %}
+
+ Choose server
+
+
+
+ Choose server
+ {% for select in selects %}
+ {% if keepalived %}
+ {% if select.1 == serv %}
+ {{ select.0 }}
+ {% else %}
+ {{ select.0 }}
+ {% endif %}
+ {% if select.3 == serv %}
+ {{ select.2 }}
+ {% else %}
+ {{ select.2 }}
+ {% endif %}
+ {% else %}
+ {% if select.2 == serv %}
+ {{ select.1 }}
+ {% else %}
+ {{ select.1 }}
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+
+ {% if onclick %}
+ Show
+ {% else %}
+ Open
+ {% endif %}
+
+
+ {% if note %}
+ Note: If you reconfigure Master server, Slave will reconfigured automatically
+ {% endif %}
+ {% if config %}
+ Config from {{ serv }}
+
+
+
+ {{ config }}
+
+ Just save
+ Save and restart
+
+
+ {% endif %}
+ {% if aftersave %}
+ New config was saved as: {{ cfg }}
+ Go to view stats
+ {% if stderr %}
+
+ Some errors:
+
+
+ {{stderr}}
+
+ {% else %}
+ Config ok
+ {% endif %}
+ {% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/configver.html b/app/templates/configver.html
new file mode 100644
index 00000000..2bb4d2cf
--- /dev/null
+++ b/app/templates/configver.html
@@ -0,0 +1,56 @@
+{% extends "base.html" %}
+{% block content %}
+
+ Choose server
+
+
+
+ Choose server
+ {% for select in selects %}
+ {% if select.2 == serv %}
+ {{ select.1 }}
+ {% else %}
+ {{ select.1 }}
+ {% endif %}
+ {% endfor %}
+
+ Open
+
+
+ {% if note %}
+ Note: If you reconfigure Master server, Slave will reconfigured automatically
+ {% endif %}
+ {% if open %}
+
+ Choose old version
+
+
+
+ Choose version
+ {% for file in return_files %}
+ {{file}}
+ {% endfor %}
+
+
+
+ Select
+
+
+
+ {% endif %}
+ {% if aftersave %}
+ Uploaded old config ver: {{ configver }}
+ Go to view stats
+ {% if stderr %}
+
+ Some errors:
+
+
+ {{stderr}}
+
+ {% else %}
+ Config ok
+ {% endif %}
+ {% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/delver.html b/app/templates/delver.html
new file mode 100644
index 00000000..6f4aad7a
--- /dev/null
+++ b/app/templates/delver.html
@@ -0,0 +1,59 @@
+{% extends "base.html" %}
+{% block content %}
+
+ Choose server
+
+
+
+ Choose server
+ {% for select in selects %}
+ {% if select.2 == serv %}
+ {{ select.1 }}
+ {% else %}
+ {{ select.1 }}
+ {% endif %}
+ {% endfor %}
+
+ Open
+
+
+ {% if note %}
+ Note: If you reconfigure Master server, Slave will reconfigured automatically
+ {% endif %}
+ {% if open %}
+
+ Choose old version
+
+ Select all
+
+ {% for file in return_files %}
+ {{file}}
+ {% endfor %}
+
+
+
+
+ Delete
+
+
+
+ {% endif %}
+ {% if aftersave %}
+ The following files were deleted:
+ {% if stderr %}
+
+ Some errors:
+
+
+ {{stderr}}
+
+ {% else %}
+
+ {% for f in file %}
+ {{f}}
+ {% endfor %}
+
+ {% endif %}
+ {% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/ha.html b/app/templates/ha.html
new file mode 100644
index 00000000..d3c7f237
--- /dev/null
+++ b/app/templates/ha.html
@@ -0,0 +1,88 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/ihap.html b/app/templates/ihap.html
new file mode 100644
index 00000000..4b7639c5
--- /dev/null
+++ b/app/templates/ihap.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+
+ Note
+ Server
+
+
+
+
+ Haproxy-WI will try install haproxy-1.18.5, if it does not work then haproxy-1.15
+
+
+
+ Choose server
+ {% for select in selects %}
+ {{ select.1 }}
+ {% endfor %}
+
+
+
+ Install
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/login.html b/app/templates/login.html
new file mode 100644
index 00000000..c1e30f3b
--- /dev/null
+++ b/app/templates/login.html
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+ {{error_log}}
+ {{error}}
+ {{db_create}}
+
+ Login:
+ Pass:
+
+ Sign Up
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/logs.html b/app/templates/logs.html
new file mode 100644
index 00000000..0a0bf9f6
--- /dev/null
+++ b/app/templates/logs.html
@@ -0,0 +1,43 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/overview.html b/app/templates/overview.html
new file mode 100644
index 00000000..5c0f967b
--- /dev/null
+++ b/app/templates/overview.html
@@ -0,0 +1,53 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+ Login
+ Email
+ Group
+ Role
+
+
+
+ Show all
+
+
+
+
+ {% for user in users %}
+
+ {{ user.1 }}
+ {{ user.2 }}
+ {{ user.5 }}
+ {{ user.4 }}
+
+
+ {% endfor %}
+
+
+
+ Server
+
+ HAproxy status
+
+
+ Action
+
+
+ Last edit
+
+
+ {% for server in servers %}
+
+ {{ server.1 }}
+ {{ server.7 }}
+
+
+
+
+
+
+
+ {% endfor %}
+
+{% endblock %}
diff --git a/app/templates/ovw.html b/app/templates/ovw.html
new file mode 100644
index 00000000..22cbf46d
--- /dev/null
+++ b/app/templates/ovw.html
@@ -0,0 +1,10 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/runtimeapi.html b/app/templates/runtimeapi.html
new file mode 100644
index 00000000..1ebbc3cd
--- /dev/null
+++ b/app/templates/runtimeapi.html
@@ -0,0 +1,46 @@
+{% extends "base.html" %}
+{% block content %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/viewlogs.html b/app/templates/viewlogs.html
new file mode 100644
index 00000000..42e94d83
--- /dev/null
+++ b/app/templates/viewlogs.html
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+{% block content %}
+
+ Choose server
+
+
+
+ Choose server
+ {% for select in selects %}
+ {% if select == serv %}
+ {{ select }}
+ {% else %}
+ {{ select }}
+ {% endif %}
+ {% endfor %}
+
+ {% if onclick %}
+ Show
+ {% else %}
+ Open
+ {% endif %}
+
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/viewsettings.html b/app/templates/viewsettings.html
new file mode 100644
index 00000000..1a7af7c6
--- /dev/null
+++ b/app/templates/viewsettings.html
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+{% block content %}
+
Only view, edit you can here: {{ fullpath }}/haproxy-webintarface.config
+
+ {% for name, value in config_items_section_name|dictsort(false) %}
+
Section: {{name}}
+
+ {% for param, value2 in value|dictsort(false) %}
+ {{param}} = {{value2}}
+ {% endfor %}
+
+ {% endfor %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/templates/viewstats.html b/app/templates/viewstats.html
new file mode 100644
index 00000000..b6054403
--- /dev/null
+++ b/app/templates/viewstats.html
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+
+ Choose server
+ {% for select in selects %}
+ {% if select.2 == serv %}
+ {{ select.1 }}
+ {% else %}
+ {{ select.1 }}
+ {% endif %}
+ {% endfor %}
+
+ Show
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/users.py b/app/users.py
index 51480075..0891d984 100644
--- a/app/users.py
+++ b/app/users.py
@@ -1,220 +1,32 @@
#!/usr/bin/env python3
-import html
+import html, http
import cgi
import sys
import os
import funct
import sql
-
-funct.head("Admin area: users manage")
-funct.check_config()
-funct.check_login()
-funct.page_for_admin()
-
+from jinja2 import Environment, FileSystemLoader
+env = Environment(loader=FileSystemLoader('templates/'))
+template = env.get_template('admin.html')
form = cgi.FieldStorage()
-USERS = sql.select_users()
-GROUPS = sql.select_groups()
-SERVERS = sql.select_servers(full=1)
-ROLES = sql.select_roles()
+print('Content-type: text/html\n')
+funct.check_login()
+funct.page_for_admin()
+try:
+ cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
+ user_id = cookie.get('uuid')
+ user = sql.get_user_name_by_uuid(user_id.value)
+ servers = sql.get_dick_permit()
+except:
+ pass
-print(''
- '
'
- '
'
- '
'
- '
'
- '
+ Add ')
-
-print('
')
-
-print('
'
- '
'
- '
+ Add ')
-
-print('
'
-'
'
-'
'
- '
'
- '
+ Add '
- '
')
-
-print('
'
- '
'
- ''
- 'Name '
- 'Desciption '
- ' '
- ' '
- ' ')
-for role in ROLES:
- print(' ' % role[0])
- print('%s ' % ( role[1]))
- print('%s ' % (role[2]))
- print(' ')
-
-print('
'
- '
'
- '
'
- '
'
- ''
- 'Upload SSH Key '
- ''
- 'Key(?) '
- ' '
- ' '
- ' '
- ''
- ''
- 'Note: Paste pem file content here'
- ' '
- ''
- ' '
- 'Upload '
- ' '
- ' '
- '
'
- '
'
- '
')
\ No newline at end of file
+output_from_parsed_template = template.render(title = "Admin area: users manage",
+ role = sql.get_user_role_by_uuid(user_id.value),
+ user = user,
+ users = sql.select_users(),
+ groups = sql.select_groups(),
+ servers = sql.select_servers(full=1),
+ roles = sql.select_roles(),
+ masters = sql.select_servers(get_master_servers=1))
+print(output_from_parsed_template)
diff --git a/app/viewlogs.py b/app/viewlogs.py
index 2d608ee5..2ae414df 100644
--- a/app/viewlogs.py
+++ b/app/viewlogs.py
@@ -1,39 +1,32 @@
#!/usr/bin/env python3
-import html
-import cgi
-import os, sys
+import os
+import sql
+import http, cgi
import funct
-from configparser import ConfigParser, ExtendedInterpolation
+import sql
import glob
import datetime
+from configparser import ConfigParser, ExtendedInterpolation
+from jinja2 import Environment, FileSystemLoader
+env = Environment(loader=FileSystemLoader('templates/'))
+template = env.get_template('viewlogs.html')
form = cgi.FieldStorage()
-viewlog = form.getvalue('viewlogs')
-
-funct.head("View logs")
-funct.check_login()
-funct.page_for_admin()
-funct.get_auto_refresh("View logs")
-
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
+print('Content-type: text/html\n')
try:
if config.get('main', 'log_path'):
log_path = config.get('main', 'log_path')
time_storage = config.getint('logs', 'log_time_storage')
except:
print('
Can not find "log_path" and "log_time_storage" parametrs. Check into config
')
-try:
- os.chdir(log_path)
-except IOError:
- print('No such file or directory: "%s". Please check "log_path" in config and exist directory
' % log_path)
- sys.exit()
-
-print(''
- ' '
- 'Choose log file ')
+
+
+funct.check_login()
+funct.page_for_admin()
try:
time_storage_hours = time_storage * 24
for dirpath, dirnames, filenames in os.walk(log_path):
@@ -46,22 +39,27 @@ except:
print('Can\'t delete old logs file. Please check "log_time_storage" in config and exist directory
')
pass
-print(''
- 'Choose log ')
+try:
+ cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
+ user_id = cookie.get('uuid')
+ user = sql.get_user_name_by_uuid(user_id.value)
+ servers = sql.get_dick_permit()
+except:
+ pass
-for files in sorted(glob.glob('*.log'), reverse=True):
- if files == viewlog:
- selected = 'selected'
- else:
- selected = ''
- print('%s ' % (files, selected, files))
-
-print(' '
- 'Show '
- ' '
- '
'
- '')
-
-funct.footer()
\ No newline at end of file
+def get_files():
+ file = set()
+ for files in glob.glob(os.path.join(log_path,'*.log')):
+ file.add(files.split('/')[5])
+ return sorted(file, reverse=True)
+
+output_from_parsed_template = template.render(h2 = 1,
+ autorefresh = 1,
+ title = "View logs",
+ role = sql.get_user_role_by_uuid(user_id.value),
+ user = user,
+ onclick = "viewLogs()",
+ serv = form.getvalue('viewlogs'),
+ select_id = "viewlogs",
+ selects = get_files())
+print(output_from_parsed_template)
diff --git a/app/viewsttats.py b/app/viewsttats.py
index 81b88842..1b2f6670 100644
--- a/app/viewsttats.py
+++ b/app/viewsttats.py
@@ -1,39 +1,41 @@
#!/usr/bin/env python3
-import html
+import html, http, os
import cgi
import requests
import funct
import sql
-from configparser import ConfigParser, ExtendedInterpolation
from requests_toolbelt.utils import dump
-
-print("Content-type: text/html\n")
-
+from jinja2 import Environment, FileSystemLoader
+env = Environment(loader=FileSystemLoader('templates/'))
+template = env.get_template('viewstats.html')
form = cgi.FieldStorage()
-serv = form.getvalue('serv')
+serv = form.getvalue('serv')
if serv is None:
first_serv = sql.get_dick_permit()
for i in first_serv:
serv = i[2]
break
-print('')
+print('Content-type: text/html\n')
+funct.check_login()
-funct.get_auto_refresh("HAproxy statistics")
+try:
+ cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
+ user_id = cookie.get('uuid')
+ user = sql.get_user_name_by_uuid(user_id.value)
+ servers = sql.get_dick_permit(virt=1)
+except:
+ pass
-print('
'
- '
'
- ''
- 'Choose server ')
+output_from_parsed_template = template.render(h2 = 1,
+ autorefresh = 1,
+ title = "HAProxy statistics",
+ role = sql.get_user_role_by_uuid(user_id.value),
+ user = user,
+ onclick = "showStats()",
+ select_id = "serv",
+ selects = servers,
+ serv = serv)
+print(output_from_parsed_template)
-funct.choose_only_select(serv, virt=1)
-
-print(' '
- 'Show '
- ' '
- '
')
-
-funct.head("Stats HAproxy configs")
-print('
')
-funct.footer()
diff --git a/requirements.txt b/requirements.txt
index 5e842c0f..274bfc71 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,4 +10,5 @@ numpy==1.14.0
matplotlib==2.1.2
urllib3==1.22
future==0.13.1
-mysql-connector-python==8.0.11
\ No newline at end of file
+mysql-connector-python==8.0.11
+Jinja2==2.10
\ No newline at end of file
diff --git a/update.sh b/update.sh
index 8d197830..977354a3 100644
--- a/update.sh
+++ b/update.sh
@@ -10,6 +10,8 @@ chown -R apache:apache *
cd app/
./update_db.py
+pip install -r requirements.txt
+
echo ""
echo "#################"
echo "Change in config:"