From 28f5a05cd7511454ee851f5b3bfee0c38466eff2 Mon Sep 17 00:00:00 2001 From: zhongyh16 Date: Fri, 16 Jun 2017 16:01:46 +0800 Subject: [PATCH] change the admin page to settings page move editable setting to settings page change the settings request from master to user add 2 editable settings:OPEN_REGISTRY and APPROVAL_RBT remove some setting from docklet.conf.template --- conf/docklet.conf.template | 4 - src/httprest.py | 15 - src/sysmgr.py | 2 +- user/user.py | 16 + web/templates/admin.html | 560 ------------------------------ web/templates/base_AdminLTE.html | 8 +- web/templates/logs.html | 53 +++ web/templates/settings.html | 571 +++++++++++++++++++++++++++++-- web/web.py | 25 +- web/webViews/admin.py | 39 ++- web/webViews/dockletrequest.py | 3 +- web/webViews/settings.py | 19 - web/webViews/syslogs.py | 13 + web/webViews/user/grouplist.py | 2 +- 14 files changed, 677 insertions(+), 653 deletions(-) delete mode 100644 web/templates/admin.html create mode 100644 web/templates/logs.html delete mode 100644 web/webViews/settings.py create mode 100644 web/webViews/syslogs.py diff --git a/conf/docklet.conf.template b/conf/docklet.conf.template index 76b86d9..d259e02 100644 --- a/conf/docklet.conf.template +++ b/conf/docklet.conf.template @@ -173,10 +173,6 @@ # same value on each machine. Please don't use the default value. # AUTH_KEY=docklet -# OPEN_REGISTRY: whether allow user to register new account or not. -# default:False -# OPEN_REGISTRY=False - # APPROVAL_RBT: whether to start the approval robot that will approve # beans applications from users automatically. # ON or OFF, default: ON. diff --git a/src/httprest.py b/src/httprest.py index 40925ee..1c95a8c 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -24,7 +24,6 @@ import http.server, cgi, json, sys, shutil import xmlrpc.client from socketserver import ThreadingMixIn import nodemgr, vclustermgr, etcdlib, network, imagemgr, notificationmgr -from settings import settings from logs import logs import userManager,beansapplicationmgr import monitor,traceback @@ -98,20 +97,6 @@ def isalive(user, beans, form): return json.dumps({'success':'true'}) -@app.route("/settings/list/", methods=['POST']) -@login_required -def settings_list(user, beans, form): - user_group = post_to_user('/user/selfQuery/', {'token': request.form.get("token", None)}).get('data', None).get('group', None) - return json.dumps(settings.list(user_group = user_group)) - -@app.route("/settings/update/", methods=['POST']) -@login_required -def settings_update(user, beans, form): - user_group = post_to_user('/user/selfQuery/', {'token': request.form.get("token", None)}).get('data', None).get('group', None) - newSetting = {} - newSetting['ADMIN_EMAIL_ADDRESS'] = form.get('ADMIN_EMAIL_ADDRESS', '') - newSetting['EMAIL_FROM_ADDRESS'] = form.get('EMAIL_FROM_ADDRESS', '') - return json.dumps(settings.update(user_group = user_group, newSetting = newSetting)) @app.route("/logs/list/", methods=['POST']) @login_required diff --git a/src/sysmgr.py b/src/sysmgr.py index f972c55..1d01b94 100755 --- a/src/sysmgr.py +++ b/src/sysmgr.py @@ -1,7 +1,7 @@ import re, string, os -editableParms = ["LOG_LEVEL"] +editableParms = ["LOG_LEVEL","ADMIN_EMAIL_ADDRESS","EMAIL_FROM_ADDRESS","OPEN_REGISTRY","APPROVAL_RBT"] configPath = {"docklet": os.environ.get("DOCKLET_CONF")+"/docklet.conf", "container": os.environ.get("DOCKLET_CONF")+"/container.conf"} #configPath = {"docklet": "../conf/docklet.conf", diff --git a/user/user.py b/user/user.py index b083f0d..d6af40b 100755 --- a/user/user.py +++ b/user/user.py @@ -33,6 +33,7 @@ import threading,traceback from model import User,db from httplib2 import Http from urllib.parse import urlencode +from settings import settings external_login = env.getenv('EXTERNAL_LOGIN') if(external_login == 'TRUE'): @@ -391,6 +392,21 @@ def chlxcsetting_user(cur_user, user, form): result = G_usermgr.chlxcsetting(cur_user = cur_user, form = form) return json.dumps(result) +@app.route("/settings/list/", methods=['POST']) +@login_required +def settings_list(cur_user, user, form): + return json.dumps(settings.list(user_group = 'admin')) + +@app.route("/settings/update/", methods=['POST']) +@login_required +def settings_update(user, beans, form): + newSetting = {} + newSetting['OPEN_REGISTRY'] = form.get('OPEN_REGISTRY','') + newSetting['APPROVAL_RBT'] = form.get('APPROVAL_RBT','') + newSetting['ADMIN_EMAIL_ADDRESS'] = form.get('ADMIN_EMAIL_ADDRESS', '') + newSetting['EMAIL_FROM_ADDRESS'] = form.get('EMAIL_FROM_ADDRESS', '') + return json.dumps(settings.update(user_group = 'admin', newSetting = newSetting)) + @app.route("/notification/list/", methods=['POST']) @login_required def list_notifications(cur_user, user, form): diff --git a/web/templates/admin.html b/web/templates/admin.html deleted file mode 100644 index 015d5a4..0000000 --- a/web/templates/admin.html +++ /dev/null @@ -1,560 +0,0 @@ -{% extends "base_AdminLTE.html"%} -{% block title %}Docklet | Admin{% endblock %} - -{% block panel_title %}Admin{% endblock %} - -{% block panel_list %} - -{% endblock %} - -{% block css_src %} - - - - - -{% endblock %} - - -{% block content %} -
-
-
-
-

Quota

- -
- - -
-
-
- - - - - - -
- - - - - {% for quota in quotas %} - - {% endfor %} - - - - - {% for group in groups %} - - - {% for quota in quotas %} - - {% endfor %} - - - - {% endfor %} - -
Name {{ quota['name'] }} Command
{{ group['name'] }} {{ group['quotas'][quota['name']] }} Edit  - {% if group['name'] in [ "root", "primary", "admin", "foundation" ] %} - Delete  - {% else %} - Delete  - {% endif %} - {% if group['name'] == defaultgroup %} - - {% endif %} -
-
-
-
-
-
-
-
-

Update Base Image

-
- - -
-
-
-
- - - - - - - - - - - {% for image in root_image %} - - - - - - {% endfor %} - -
ImageNameCreateTimeDescriptionOperation
{{image['name']}}{{image['time']}}{{image['description']}} - -
-
-
-
-
-
-
-
-

Container Default Setting

- -
- - -
-
-
-
-
- -
CORE
-
-
- -
MB
-
-
- -
MB
-
-
-
-
-
-
-
-
-
- - {% for field in ["docklet"] %} -
-
-
-
- {% if field == "docklet" %} -

Docklet Config

- {% else %} -

Container Config

- {% endif %} -
- - -
-
-
- -
- - - - - - - - - - - - {% for editable in [1,0] %} - {% for parm in parms[field] %} - {% if parm["editable"] == editable %} - - - {% if parm["parm"]|length > 20%} - - {% else %} - - {% endif %} - - {% if parm["val"] == "novalidvaluea" %} - - {% elif parm["val"]|length > 20 %} - - {% else %} - - {% endif %} - - - - {% if parm["default"]|length > 20 %} - - {% else %} - - {% endif %} - - - - - - {% endif %} - {% endfor %} - {% endfor %} - -
ParameterValueHistory (Click to Reuse)DefaultCommand
{{ parm["parm"]|truncate(20) }}{{ parm["parm"] }}No Valid Value{{ parm["val"]|truncate(20) }}{{ parm["val"] }} - {% for history in parm["history"] %} - {% if history|length > 20 %} - {{ history|truncate(20) }} - {% else %} - {{ history }} - {% endif %} - - - {% endfor %} - {{ parm["default"]|truncate(20) }} {{ parm["default"] }} - Details  - {% if parm["editable"] == 1 %} - Edit  - {% endif %} -
-
-
-
-
-
-{% endfor %} - -
-
-
-
-

Container Config

-
- - -
-
-
-
 {{ parms["container"] }} 
-
-
-
-
- -{% endblock %} - -{% block script_src %} - - - - - -{% endblock %} diff --git a/web/templates/base_AdminLTE.html b/web/templates/base_AdminLTE.html index 3c7a9e2..de4cf47 100644 --- a/web/templates/base_AdminLTE.html +++ b/web/templates/base_AdminLTE.html @@ -169,15 +169,15 @@ -
  • - Admin +
  • + Settings
  • -
  • - Settings +
  • + Logs
  • {% endif %} diff --git a/web/templates/logs.html b/web/templates/logs.html new file mode 100644 index 0000000..3c304ec --- /dev/null +++ b/web/templates/logs.html @@ -0,0 +1,53 @@ +{% extends "base_AdminLTE.html"%} +{% block title %}Docklet | Logs{% endblock %} + +{% block panel_title %}Logs{% endblock %} + +{% block panel_list %} + +{% endblock %} + +{% block css_src %} + + + +{% endblock %} + +{% block content %} + + +
    +
    +
    +
    +

    Logs

    +
    +
    + {% for filename in logs %} + + {% endfor %} +
    +
    +
    +
    +{% endblock %} diff --git a/web/templates/settings.html b/web/templates/settings.html index 48bb565..24df713 100644 --- a/web/templates/settings.html +++ b/web/templates/settings.html @@ -1,7 +1,7 @@ {% extends "base_AdminLTE.html"%} -{% block title %}Docklet | Settings{% endblock %} +{% block title %}Docklet | Admin{% endblock %} -{% block panel_title %}Settings{% endblock %} +{% block panel_title %}Admin{% endblock %} {% block panel_list %} {% endblock %} {% block css_src %} - + + + {% endblock %} + {% block content %}
    -
    +
    +
    +
    +

    Quota

    + +
    + + +
    +
    +
    + + + + + + +
    + + + + + {% for quota in quotas %} + + {% endfor %} + + + + + {% for group in groups %} + + + {% for quota in quotas %} + + {% endfor %} + + + + {% endfor %} + +
    Name {{ quota['name'] }} Command
    {{ group['name'] }} {{ group['quotas'][quota['name']] }} Edit  + {% if group['name'] in [ "root", "primary", "admin", "foundation" ] %} + Delete  + {% else %} + Delete  + {% endif %} + {% if group['name'] == defaultgroup %} + + {% endif %} +
    +
    +
    +
    +
    +
    +
    +
    +

    Update Base Image

    +
    + + +
    +
    +
    +
    + + + + + + + + + + + {% for image in root_image %} + + + + + + {% endfor %} + +
    ImageNameCreateTimeDescriptionOperation
    {{image['name']}}{{image['time']}}{{image['description']}} + +
    +
    +
    +
    +
    +
    +
    +
    +

    Container Default Setting

    + +
    + + +
    +
    +
    +
    +
    + +
    CORE
    +
    +
    + +
    MB
    +
    +
    + +
    MB
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +

    Modify Settings

    -
    +
    @@ -42,6 +311,18 @@

    if this address is "", no email will be sent out.

    +
    + +

    whether allow user to register a new account

    +

    if the value is True, it will allow.

    + +
    +
    + +

    whether to start the approval robot that will approve beans applications from users automatically

    +

    if the value is True, it will allow.

    + +
    - -
    -
    -
    + {% for field in ["docklet"] %} +
    +
    +
    -

    Logs

    + {% if field == "docklet" %} +

    Docklet Config

    + {% else %} +

    Container Config

    + {% endif %} +
    + + +
    -
    - {% for filename in logs %} -
    -
    - - + -
    +
    +
    +{% endfor %} + +
    +
    +
    +
    +

    Container Config

    +
    + + +
    +
    + +
    +
    +
    + +{% endblock %} + +{% block script_src %} + + + + + {% endblock %} diff --git a/web/web.py b/web/web.py index d364e8f..5c8d39f 100755 --- a/web/web.py +++ b/web/web.py @@ -27,7 +27,7 @@ from webViews.notification.notification import CreateNotificationView, Notificat QueryNotificationView, ModifyNotificationView, DeleteNotificationView from webViews.user.userinfo import userinfoView from webViews.user.userActivate import userActivateView -from webViews.settings import settingsView +from webViews.syslogs import logsView from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView from functools import wraps from webViews.dockletrequest import dockletRequest @@ -69,7 +69,7 @@ def home(): @app.route("/login/", methods=['GET', 'POST']) def login(): - loginView.open_registry = env.getenv("OPEN_REGISTRY") + loginView.open_registry = os.environ["OPEN_REGISTRY"] return loginView.as_view() @app.route(external_login_url, methods=['GET']) @@ -371,10 +371,10 @@ def monitorUserAll(): return monitorUserAllView.as_view() ''' -@app.route("/settings/", methods=['GET', 'POST']) +@app.route("/logs/", methods=['GET', 'POST']) @administration_required -def settings(): - return settingsView.as_view() +def logs(): + return logsView.as_view() @app.route("/logs//", methods=['GET']) @administration_required @@ -552,11 +552,16 @@ def systemdelete(): def systemresetall(): return systemresetallView.as_view() -@app.route("/admin/", methods=['GET', 'POST']) +@app.route("/settings/", methods=['GET', 'POST']) @administration_required def adminpage(): return adminView.as_view() +@app.route("/settings/update/", methods=['POST']) +@administration_required +def updatesettings(): + return updatesettingsView.as_view() + @app.route('/index/', methods=['GET']) def jupyter_control(): return redirect('/dashboard/') @@ -653,6 +658,14 @@ if __name__ == '__main__': secret_key_file.write(secret_key) secret_key_file.close() + try: + open_registryfile = open(env.getenv('FS_PREFIX') + '/local/settings.conf') + settings = jsobn.loads(open_registryfile.read()) + open_registryfile.close() + os.environ['OPEN_REGISTRY'] = settings.get('OPEN_REGISTRY',"False") + except: + os.environ['OPEN_REGISTRY'] = "False" + os.environ['APP_KEY'] = app.secret_key runcmd = sys.argv[0] app.runpath = runcmd.rsplit('/', 1)[0] diff --git a/web/webViews/admin.py b/web/webViews/admin.py index 2da3309..44ef238 100644 --- a/web/webViews/admin.py +++ b/web/webViews/admin.py @@ -2,10 +2,10 @@ from flask import session, render_template, redirect, request from webViews.view import normalView from webViews.dockletrequest import dockletRequest from webViews.dashboard import * -import time, re, json +import time, re, json, os class adminView(normalView): - template_path = "admin.html" + template_path = "settings.html" @classmethod def get(self): @@ -16,61 +16,70 @@ class adminView(normalView): parms = dockletRequest.post('/system/parmList/') rootimage = dockletRequest.post('/image/list/').get('images') lxcsetting = dockletRequest.post('/user/lxcsettingList/')['data'] - return self.render(self.template_path, groups = groups, quotas = quotas, defaultgroup = defaultgroup, parms = parms, lxcsetting = lxcsetting, root_image = rootimage['private']) + settings = dockletRequest.post('/settings/list/')['result'] + return self.render(self.template_path, groups = groups, quotas = quotas, defaultgroup = defaultgroup, parms = parms, lxcsetting = lxcsetting, root_image = rootimage['private'], settings=settings) + +class updatesettingsView(normalView): + + @classmethod + def post(self): + result = dockletRequest.post("/settings/update/", request.form) + os.environ['OPEN_REGISTRY'] = request.form.get('OPEN_REGISTRY') + return redirect('/settings/') class groupaddView(normalView): @classmethod def post(self): dockletRequest.post('/user/groupadd/', request.form) - return redirect('/admin/') + return redirect('/settings/') class systemmodifyView(normalView): @classmethod def post(self): dockletRequest.post('/system/modify/', request.form) - return redirect('/admin/') + return redirect('/settings/') class systemclearView(normalView): @classmethod def post(self): dockletRequest.post('/system/clear_history/', request.form) - return redirect('/admin/') + return redirect('/settings/') class systemaddView(normalView): @classmethod def post(self): dockletRequest.post('/system/add/', request.form) - return redirect('/admin/') + return redirect('/settings/') class systemdeleteView(normalView): @classmethod def post(self): dockletRequest.post('/system/delete/', request.form) - return redirect('/admin/') + return redirect('/settings/') class systemresetallView(normalView): @classmethod def post(self): dockletRequest.post('/system/reset_all/', request.form) - return redirect('/admin/') + return redirect('/settings/') class quotaaddView(normalView): @classmethod def post(self): dockletRequest.post('/user/quotaadd/', request.form) - return redirect('/admin/') + return redirect('/settings/') class chdefaultView(normalView): @classmethod def post(self): dockletRequest.post('/user/chdefault/', request.form) - return redirect('/admin/') + return redirect('/settings/') class chlxcsettingView(normalView): @classmethod def post(self): dockletRequest.post('/user/chlxcsetting/', request.form) - return redirect('/admin/') + return redirect('/settings/') class groupdelView(normalView): @classmethod @@ -79,7 +88,7 @@ class groupdelView(normalView): "name" : self.groupname, } dockletRequest.post('/user/groupdel/', data) - return redirect('/admin/') + return redirect('/settings/') @classmethod def get(self): @@ -94,7 +103,7 @@ class historydelView(normalView): @classmethod def post(self): dockletRequest.post('/system/historydel/', request.form) - return redirect('/admin/') + return redirect('/settings/') class updatebaseImageView(normalView): @classmethod @@ -103,4 +112,4 @@ class updatebaseImageView(normalView): "image": self.image } dockletRequest.post('/image/updatebase/', data) - return redirect("/admin/") + return redirect("/settings/") diff --git a/web/webViews/dockletrequest.py b/web/webViews/dockletrequest.py index 5575093..165c11b 100644 --- a/web/webViews/dockletrequest.py +++ b/web/webViews/dockletrequest.py @@ -38,7 +38,8 @@ class dockletRequest(): 'user', 'beans', 'notification', - 'cloud' + 'cloud', + 'settings' } if ":" not in endpoint: endpoint = "http://"+endpoint+":"+master_port diff --git a/web/webViews/settings.py b/web/webViews/settings.py deleted file mode 100644 index 59ad3fa..0000000 --- a/web/webViews/settings.py +++ /dev/null @@ -1,19 +0,0 @@ -from flask import session,render_template,redirect, request -from webViews.view import normalView -from webViews.dockletrequest import dockletRequest - -class settingsView(normalView): - template_path = "settings.html" - - @classmethod - def get(self): - settings = dockletRequest.post('/settings/list/')['result'] - logs = dockletRequest.post('/logs/list/')['result'] - logs.sort() - logs.sort(key = len) - return self.render(self.template_path, settings = settings, logs = logs) - - @classmethod - def post(self): - result = dockletRequest.post('/settings/update/', request.form) - return redirect('/settings/') diff --git a/web/webViews/syslogs.py b/web/webViews/syslogs.py new file mode 100644 index 0000000..cd8179a --- /dev/null +++ b/web/webViews/syslogs.py @@ -0,0 +1,13 @@ +from flask import session,render_template,redirect, request +from webViews.view import normalView +from webViews.dockletrequest import dockletRequest + +class logsView(normalView): + template_path = "logs.html" + + @classmethod + def get(self): + logs = dockletRequest.post('/logs/list/')['result'] + logs.sort() + logs.sort(key = len) + return self.render(self.template_path, logs = logs) diff --git a/web/webViews/user/grouplist.py b/web/webViews/user/grouplist.py index d096238..a0d8d35 100644 --- a/web/webViews/user/grouplist.py +++ b/web/webViews/user/grouplist.py @@ -20,4 +20,4 @@ class groupmodifyView(normalView): @classmethod def post(self): result = json.dumps(dockletRequest.post('/user/groupModify/', request.form)) - return redirect('/admin/') + return redirect('/settings/')