#2 добавил страницу иниализации установки
This commit is contained in:
parent
974e35cfc3
commit
1e35e778f0
5 changed files with 109 additions and 11 deletions
|
@ -1,8 +1,9 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from hashlib import md5
|
||||||
import validators
|
import validators
|
||||||
|
from datetime import datetime
|
||||||
from flask import Blueprint, flash, g, jsonify, redirect, render_template, request, session, url_for
|
from flask import Blueprint, flash, g, jsonify, redirect, render_template, request, session, url_for
|
||||||
from SWSCloudAdministrator.Administrator.common import requires_login
|
from SWSCloudAdministrator.Administrator.common import requires_login
|
||||||
|
|
||||||
|
@ -12,12 +13,14 @@ from SWSCloudCore.controllers.common import ControllerMessagesEmail
|
||||||
from SWSCloudCore.controllers.datacenters.manage import ControllerManageDatacenters
|
from SWSCloudCore.controllers.datacenters.manage import ControllerManageDatacenters
|
||||||
from SWSCloudCore.controllers.ips.manage import ControllerManageIPs
|
from SWSCloudCore.controllers.ips.manage import ControllerManageIPs
|
||||||
from SWSCloudCore.controllers.servers.manage import ControllerManageServer
|
from SWSCloudCore.controllers.servers.manage import ControllerManageServer
|
||||||
|
from SWSCloudCore.controllers.settings import ControllerSettings
|
||||||
# from SWSCloudCore.controllers.users.manage import ControllerManageUsers
|
# from SWSCloudCore.controllers.users.manage import ControllerManageUsers
|
||||||
# from SWSCloudCore.controllers.users.manage import ControllerManageUsersBalance
|
# from SWSCloudCore.controllers.users.manage import ControllerManageUsersBalance
|
||||||
# from SWSCloudCore.controllers.users.manage import ControllerManageUsersDetails
|
# from SWSCloudCore.controllers.users.manage import ControllerManageUsersDetails
|
||||||
from SWSCloudCore.controllers.plans import ControllerPlans
|
from SWSCloudCore.controllers.plans import ControllerPlans
|
||||||
from SWSCloudCore import models
|
from SWSCloudCore import models
|
||||||
|
|
||||||
|
|
||||||
viewAdministrator = Blueprint('administrator', __name__, url_prefix='/administrator')
|
viewAdministrator = Blueprint('administrator', __name__, url_prefix='/administrator')
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +31,7 @@ def login():
|
||||||
|
|
||||||
@viewAdministrator.route('/login.html', methods=['POST'])
|
@viewAdministrator.route('/login.html', methods=['POST'])
|
||||||
def login_post():
|
def login_post():
|
||||||
admin_email = request.form.get('email').encode('utf-8')
|
admin_email = request.form.get('email')
|
||||||
admin_password = request.form.get('password').encode('utf-8')
|
admin_password = request.form.get('password').encode('utf-8')
|
||||||
|
|
||||||
# validation entered data
|
# validation entered data
|
||||||
|
@ -51,7 +54,7 @@ def login_post():
|
||||||
|
|
||||||
# redirect to rules list
|
# redirect to rules list
|
||||||
return redirect(url_for('administrator.dashboard'))
|
return redirect(url_for('administrator.dashboard'))
|
||||||
|
# return ""
|
||||||
|
|
||||||
@viewAdministrator.route('/logout.html')
|
@viewAdministrator.route('/logout.html')
|
||||||
def logout():
|
def logout():
|
||||||
|
@ -408,3 +411,40 @@ def plan_edit(plan_id):
|
||||||
return render_template(
|
return render_template(
|
||||||
'administrator/plans/edit.html',
|
'administrator/plans/edit.html',
|
||||||
plan_details=models.PlansVMs.select().where(models.PlansVMs.id == plan_id).get())
|
plan_details=models.PlansVMs.select().where(models.PlansVMs.id == plan_id).get())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@viewAdministrator.route('/setup', methods=['GET', 'POST'])
|
||||||
|
# @requires_login
|
||||||
|
def setup():
|
||||||
|
# # check exists plan
|
||||||
|
# if models.PlansVMs.select().where(models.PlansVMs.id == plan_id).count() == 0:
|
||||||
|
# return redirect(url_for('administrator.plans_index'))
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
|
||||||
|
admin_id = uuid4()
|
||||||
|
admin_email = request.form.get('email')
|
||||||
|
admin_password = md5(request.form.get('password').encode()).hexdigest()
|
||||||
|
|
||||||
|
# models.database.connect()
|
||||||
|
|
||||||
|
if models.Admins.select().where(models.Admins.email == admin_email).count() == 0:
|
||||||
|
models.Admins.create(id=admin_id, email=admin_email, password=admin_password, status=1)
|
||||||
|
|
||||||
|
cs = ControllerSettings()
|
||||||
|
cs.create('_setup_finish', str(datetime.now()))
|
||||||
|
|
||||||
|
return redirect(url_for('administrator.login'))
|
||||||
|
|
||||||
|
_setup_finish = models.Settings.select().where(
|
||||||
|
models.Settings.key == "_setup_finish"
|
||||||
|
).count()
|
||||||
|
|
||||||
|
if _setup_finish != 0:
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'administrator/setup/index.html'
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
{% extends 'administrator/_layout.noauth.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="large-12 columns">
|
||||||
|
<h1>Setup</h1>
|
||||||
|
<h2>Create an administrator</h2>
|
||||||
|
{% with messages = get_flashed_messages() %}
|
||||||
|
{% if messages %}
|
||||||
|
<div class="alert-box alert">
|
||||||
|
<ul>
|
||||||
|
{% for message in messages %}
|
||||||
|
<li>{{ message }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
<form action="{{ url_for('administrator.setup') }}" method="post">
|
||||||
|
<label for="email">email</label>
|
||||||
|
<input type="text" name="email" value="" id="email" />
|
||||||
|
<label for="password">password</label>
|
||||||
|
<input type="password" name="password" value="" id="password" />
|
||||||
|
<input type="submit" value="login" class="button" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -3,9 +3,14 @@ import datetime
|
||||||
from SWSCloudCore import models
|
from SWSCloudCore import models
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerServerServers:
|
class ControllerServerServers:
|
||||||
def get_secret(self, server_id):
|
def get_secret(self, server_id):
|
||||||
return models.Servers.select(models.Servers.secret).where(models.Servers.id == server_id).get().secret
|
return models.Servers.select(
|
||||||
|
models.Servers.secret
|
||||||
|
).where(
|
||||||
|
models.Servers.id == server_id
|
||||||
|
).get().secret
|
||||||
|
|
||||||
def exists(self, server_id):
|
def exists(self, server_id):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
"""Stack Web Services LLC."""
|
"""Stack Web Services LLC."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
from flask import Blueprint, jsonify, request, g
|
from flask import Blueprint, jsonify, request, g
|
||||||
from flask_httpauth import HTTPBasicAuth
|
from flask_httpauth import HTTPBasicAuth
|
||||||
from SWSCloudCore.controllers.servers.server import ControllerServerStatistics
|
from SWSCloudCore.controllers.servers.server import ControllerServerStatistics
|
||||||
|
@ -8,30 +11,52 @@ from SWSCloudCore.controllers.servers.server import ControllerServerServers
|
||||||
from SWSCloudCore.controllers.tasks.server import ControllerTasksServer
|
from SWSCloudCore.controllers.tasks.server import ControllerTasksServer
|
||||||
from SWSCloudCore.controllers.containers.server import ControllerContainersServer
|
from SWSCloudCore.controllers.containers.server import ControllerContainersServer
|
||||||
|
|
||||||
|
|
||||||
|
FORMAT = '%(asctime)-15s NODEAGENT %(levelname)s: %(message)s'
|
||||||
|
|
||||||
|
logging.basicConfig(format=FORMAT)
|
||||||
|
|
||||||
|
logger = logging.getLogger('tcpserver')
|
||||||
|
|
||||||
api_auth = HTTPBasicAuth()
|
api_auth = HTTPBasicAuth()
|
||||||
viewServerAPI = Blueprint('ServerAPI', __name__, url_prefix='/server_api')
|
viewServerAPI = Blueprint('ServerAPI', __name__, url_prefix='/server_api')
|
||||||
|
|
||||||
|
|
||||||
@api_auth.get_password
|
@api_auth.get_password
|
||||||
def get_pw(server_id):
|
def get_pw(server_id):
|
||||||
|
logger.error(f"{server_id}")
|
||||||
if ControllerServerServers().exists(server_id):
|
if ControllerServerServers().exists(server_id):
|
||||||
g.server_id = server_id
|
g.server_id = server_id
|
||||||
return ControllerServerServers().get_secret(g.server_id)
|
return ControllerServerServers().get_secret(server_id)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@api_auth.error_handler
|
@api_auth.error_handler
|
||||||
def auth_error():
|
def auth_error():
|
||||||
return jsonify(status='error', description='Unauthorized'), 403
|
description = 'Unauthorized'
|
||||||
|
return jsonify(
|
||||||
|
status='error',
|
||||||
|
description=description
|
||||||
|
), 403
|
||||||
|
|
||||||
|
|
||||||
@viewServerAPI.route('/ping')
|
@viewServerAPI.route('/ping')
|
||||||
@api_auth.login_required
|
# @api_auth.login_required
|
||||||
def ping():
|
def ping():
|
||||||
"""
|
"""
|
||||||
Тест. Проверка соединения и авторизации
|
Тест. Проверка соединения и авторизации
|
||||||
"""
|
"""
|
||||||
return jsonify(ping='pong', server_id=g.server_id), 200
|
|
||||||
|
hhh = dict()
|
||||||
|
for i in request.headers:
|
||||||
|
hhh[i[0]] = str(i[1])
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify(
|
||||||
|
ping='pong',
|
||||||
|
cnt='1',
|
||||||
|
h=hhh
|
||||||
|
), 200
|
||||||
|
|
||||||
|
|
||||||
# TASKS
|
# TASKS
|
||||||
|
@ -65,9 +90,10 @@ def task_item():
|
||||||
"""
|
"""
|
||||||
sapi = ControllerTasksServer(g.server_id)
|
sapi = ControllerTasksServer(g.server_id)
|
||||||
|
|
||||||
# Если задач нет, то надо вернуть ответ с кодом 204 (no content)
|
# Если задач нет,
|
||||||
|
# то надо вернуть ответ с кодом 204 (no content)
|
||||||
if sapi.count() == 0:
|
if sapi.count() == 0:
|
||||||
return '', 204
|
return jsonify(status='nothing'), 204
|
||||||
|
|
||||||
task = sapi.queue_item_oldest_get(status=0)
|
task = sapi.queue_item_oldest_get(status=0)
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,6 @@ app.register_blueprint(viewServerAPI)
|
||||||
# /administrator
|
# /administrator
|
||||||
app.register_blueprint(viewAdministrator)
|
app.register_blueprint(viewAdministrator)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
return render_template('errors/404.html'), 404
|
return render_template('errors/404.html'), 404
|
||||||
|
|
Loading…
Add table
Reference in a new issue