commit
51b1fda651
|
@ -422,7 +422,10 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler):
|
||||||
result = G_usermgr.register(user = user, cur_user = cur_user)
|
result = G_usermgr.register(user = user, cur_user = cur_user)
|
||||||
self.response(200, result)
|
self.response(200, result)
|
||||||
elif cmds[1] == 'groupadd':
|
elif cmds[1] == 'groupadd':
|
||||||
result = G_usermgr.groupadd(name = form.getvalue('name', None), cur_user = cur_user)
|
result = G_usermgr.groupadd(form = form, cur_user = cur_user)
|
||||||
|
self.response(200, result)
|
||||||
|
elif cmds[1] == 'groupdel':
|
||||||
|
result = G_usermgr.groupdel(name = form.getvalue('name', None), cur_user = cur_user)
|
||||||
self.response(200, result)
|
self.response(200, result)
|
||||||
elif cmds[1] == 'data':
|
elif cmds[1] == 'data':
|
||||||
logger.info("handle request: user/data")
|
logger.info("handle request: user/data")
|
||||||
|
@ -435,7 +438,7 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler):
|
||||||
result = G_usermgr.groupList(cur_user = cur_user)
|
result = G_usermgr.groupList(cur_user = cur_user)
|
||||||
self.response(200, result)
|
self.response(200, result)
|
||||||
elif cmds[1] == 'groupQuery':
|
elif cmds[1] == 'groupQuery':
|
||||||
result = G_usermgr.groupQuery(ID = form.getvalue("ID", '3'), cur_user = cur_user)
|
result = G_usermgr.groupQuery(name = form.getvalue("name"), cur_user = cur_user)
|
||||||
if (result.get('success', None) == None or result.get('success', None) == "false"):
|
if (result.get('success', None) == None or result.get('success', None) == "false"):
|
||||||
self.response(301,result)
|
self.response(301,result)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -96,10 +96,7 @@ class User(db.Model):
|
||||||
self.register_date = date
|
self.register_date = date
|
||||||
else:
|
else:
|
||||||
self.register_date = datetime.utcnow()
|
self.register_date = datetime.utcnow()
|
||||||
if (UserGroup.query.filter_by(name=usergroup).first() != None):
|
self.user_group = usergroup
|
||||||
self.user_group = usergroup
|
|
||||||
else:
|
|
||||||
self.user_group = "primary"
|
|
||||||
self.auth_method = auth_method
|
self.auth_method = auth_method
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -19,10 +19,12 @@ from email.mime.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import json
|
||||||
|
|
||||||
email_from_address = env.getenv('EMAIL_FROM_ADDRESS')
|
email_from_address = env.getenv('EMAIL_FROM_ADDRESS')
|
||||||
admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS')
|
admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS')
|
||||||
PAM = pam.pam()
|
PAM = pam.pam()
|
||||||
|
fspath = env.getenv('FS_PREFIX')
|
||||||
|
|
||||||
if (env.getenv('EXTERNAL_LOGIN').lower() == 'true'):
|
if (env.getenv('EXTERNAL_LOGIN').lower() == 'true'):
|
||||||
from plugin import external_receive
|
from plugin import external_receive
|
||||||
|
@ -123,12 +125,8 @@ class userManager:
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
User.query.all()
|
User.query.all()
|
||||||
UserGroup.query.all()
|
|
||||||
except:
|
except:
|
||||||
db.create_all()
|
db.create_all()
|
||||||
root = UserGroup('root')
|
|
||||||
db.session.add(root)
|
|
||||||
db.session.commit()
|
|
||||||
if password == None:
|
if password == None:
|
||||||
#set a random password
|
#set a random password
|
||||||
password = os.urandom(16)
|
password = os.urandom(16)
|
||||||
|
@ -147,11 +145,14 @@ class userManager:
|
||||||
path = env.getenv('DOCKLET_LIB')
|
path = env.getenv('DOCKLET_LIB')
|
||||||
subprocess.call([path+"/userinit.sh", username])
|
subprocess.call([path+"/userinit.sh", username])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
admin = UserGroup('admin')
|
if not os.path.exists(fspath+"/global/group"):
|
||||||
primary = UserGroup('primary')
|
groupfile = open(fspath+"/global/group",'w')
|
||||||
db.session.add(admin)
|
groups = []
|
||||||
db.session.add(primary)
|
groups.append({'name':'root', 'cpu':'100000', 'memory':'2000', 'imageQuantity':'10', 'lifeCycle':'24'})
|
||||||
db.session.commit()
|
groups.append({'name':'admin', 'cpu':'100000', 'memory':'2000', 'imageQuantity':'10', 'lifeCycle':'24'})
|
||||||
|
groups.append({'name':'primary', 'cpu':'100000', 'memory':'2000', 'imageQuantity':'10', 'lifeCycle':'24'})
|
||||||
|
groupfile.write(json.dumps(groups))
|
||||||
|
groupfile.close()
|
||||||
|
|
||||||
def auth_local(self, username, password):
|
def auth_local(self, username, password):
|
||||||
password = hashlib.sha512(password.encode('utf-8')).hexdigest()
|
password = hashlib.sha512(password.encode('utf-8')).hexdigest()
|
||||||
|
@ -355,7 +356,19 @@ class userManager:
|
||||||
List informantion for oneself
|
List informantion for oneself
|
||||||
'''
|
'''
|
||||||
user = kwargs['cur_user']
|
user = kwargs['cur_user']
|
||||||
group = UserGroup.query.filter_by(name = user.user_group).first()
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
|
group = None
|
||||||
|
for one_group in groups:
|
||||||
|
if one_group['name'] == user.user_group:
|
||||||
|
group = one_group
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
for one_group in groups:
|
||||||
|
if one_group['name'] == "primary":
|
||||||
|
group = one_group
|
||||||
|
break
|
||||||
result = {
|
result = {
|
||||||
"success": 'true',
|
"success": 'true',
|
||||||
"data":{
|
"data":{
|
||||||
|
@ -373,10 +386,10 @@ class userManager:
|
||||||
"register_date" : "%s"%(user.register_date),
|
"register_date" : "%s"%(user.register_date),
|
||||||
"group" : user.user_group,
|
"group" : user.user_group,
|
||||||
"groupinfo": {
|
"groupinfo": {
|
||||||
"cpu": group.cpu,
|
"cpu": group['cpu'],
|
||||||
"memory": group.memory,
|
"memory": group['memory'],
|
||||||
"imageQuantity": group.imageQuantity,
|
"imageQuantity": group['imageQuantity'],
|
||||||
"lifeCycle":group.lifeCycle,
|
"lifeCycle":group['lifeCycle'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -445,44 +458,50 @@ class userManager:
|
||||||
Usage: list(cur_user = token_from_auth)
|
Usage: list(cur_user = token_from_auth)
|
||||||
List all groups for an administrator
|
List all groups for an administrator
|
||||||
'''
|
'''
|
||||||
allgroup = UserGroup.query.all()
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
result = {
|
result = {
|
||||||
"success": 'true',
|
"success": 'true',
|
||||||
"data":[]
|
"data":[]
|
||||||
}
|
}
|
||||||
for group in allgroup:
|
for group in groups:
|
||||||
groupinfo = [
|
groupinfo = [
|
||||||
group.id,
|
group['name'],
|
||||||
group.name,
|
group['cpu'],
|
||||||
group.cpu,
|
group['memory'],
|
||||||
group.memory,
|
group['imageQuantity'],
|
||||||
group.imageQuantity,
|
group['lifeCycle'],
|
||||||
group.lifeCycle,
|
|
||||||
'',
|
'',
|
||||||
]
|
]
|
||||||
result["data"].append(groupinfo)
|
result["data"].append(groupinfo)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@administration_required
|
@administration_required
|
||||||
def groupQuery(*args, **kwargs):
|
def groupQuery(*args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Usage: groupQuery(id = XXX, cur_user = token_from_auth)
|
Usage: groupQuery(name = XXX, cur_user = token_from_auth)
|
||||||
List a group for an administrator
|
List a group for an administrator
|
||||||
'''
|
'''
|
||||||
group = UserGroup.query.filter_by(id = kwargs['ID']).first()
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
if (group == None):
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
|
for group in groups:
|
||||||
|
if group['name'] == kwargs['name']:
|
||||||
|
result = {
|
||||||
|
"success":'true',
|
||||||
|
"data":{
|
||||||
|
"name" : group['name'] ,
|
||||||
|
"cpu" : group['cpu'] ,
|
||||||
|
"memory" : group['memory'],
|
||||||
|
"imageQuantity" : group['imageQuantity'],
|
||||||
|
"lifeCycle" : group['lifeCycle'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
else:
|
||||||
return {"success":False, "reason":"Group does not exist"}
|
return {"success":False, "reason":"Group does not exist"}
|
||||||
result = {
|
|
||||||
"success":'true',
|
|
||||||
"data":{
|
|
||||||
"name" : group.name ,
|
|
||||||
"cpu" : group.cpu ,
|
|
||||||
"memory" : group.memory,
|
|
||||||
"imageQuantity" : group.imageQuantity,
|
|
||||||
"lifeCycle" : group.lifeCycle,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
|
|
||||||
@administration_required
|
@administration_required
|
||||||
def groupListName(*args, **kwargs):
|
def groupListName(*args, **kwargs):
|
||||||
|
@ -490,12 +509,14 @@ class userManager:
|
||||||
Usage: grouplist(cur_user = token_from_auth)
|
Usage: grouplist(cur_user = token_from_auth)
|
||||||
List all group names for an administrator
|
List all group names for an administrator
|
||||||
'''
|
'''
|
||||||
groups = UserGroup.query.all()
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
result = {
|
result = {
|
||||||
"groups": [],
|
"groups": [],
|
||||||
}
|
}
|
||||||
for group in groups:
|
for group in groups:
|
||||||
result["groups"].append(group.name)
|
result["groups"].append(group['name'])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@administration_required
|
@administration_required
|
||||||
|
@ -503,16 +524,22 @@ class userManager:
|
||||||
'''
|
'''
|
||||||
Usage: groupModify(newValue = dict_from_form, cur_user = token_from_auth)
|
Usage: groupModify(newValue = dict_from_form, cur_user = token_from_auth)
|
||||||
'''
|
'''
|
||||||
group_modify = UserGroup.query.filter_by(name = kwargs['newValue'].getvalue('groupname', None)).first()
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
if (group_modify == None):
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
|
for group in groups:
|
||||||
|
if group['name'] == kwargs['newValue'].getvalue('groupname',None):
|
||||||
|
form = kwargs['newValue']
|
||||||
|
group['cpu'] = form.getvalue('cpu', '')
|
||||||
|
group['memory'] = form.getvalue('memory', '')
|
||||||
|
group['imageQuantity'] = form.getvalue('image', '')
|
||||||
|
group['lifeCycle'] = form.getvalue('lifecycle', '')
|
||||||
|
groupfile = open(fspath+"/global/group",'w')
|
||||||
|
groupfile.write(json.dumps(groups))
|
||||||
|
groupfile.close()
|
||||||
|
return {"success":'true'}
|
||||||
|
else:
|
||||||
return {"success":'false', "reason":"UserGroup does not exist"}
|
return {"success":'false', "reason":"UserGroup does not exist"}
|
||||||
form = kwargs['newValue']
|
|
||||||
group_modify.cpu = form.getvalue('cpu', '')
|
|
||||||
group_modify.memory = form.getvalue('memory', '')
|
|
||||||
group_modify.imageQuantity = form.getvalue('image', '')
|
|
||||||
group_modify.lifeCycle = form.getvalue('lifecycle', '')
|
|
||||||
db.session.commit()
|
|
||||||
return {"success":'true'}
|
|
||||||
|
|
||||||
@administration_required
|
@administration_required
|
||||||
def modify(*args, **kwargs):
|
def modify(*args, **kwargs):
|
||||||
|
@ -596,12 +623,33 @@ class userManager:
|
||||||
|
|
||||||
@administration_required
|
@administration_required
|
||||||
def groupadd(*args, **kwargs):
|
def groupadd(*args, **kwargs):
|
||||||
|
form = kwargs.get('form')
|
||||||
|
if (form.getvalue("name") == None):
|
||||||
|
return {"success":'false', "reason": "Empty group name"}
|
||||||
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
|
groups = json.loads(groupfile.read())
|
||||||
|
groupfile.close()
|
||||||
|
groups.append({'name':form.getvalue("name"), 'cpu':form.getvalue("cpu"), 'memory':form.getvalue("memory"), 'imageQuantity':form.getvalue("image"), 'lifeCycle':form.getvalue("lifecycle")})
|
||||||
|
groupfile = open(fspath+"/global/group",'w')
|
||||||
|
groupfile.write(json.dumps(groups))
|
||||||
|
groupfile.close()
|
||||||
|
return {"success":'true'}
|
||||||
|
|
||||||
|
@administration_required
|
||||||
|
def groupdel(*args, **kwargs):
|
||||||
name = kwargs.get('name', None)
|
name = kwargs.get('name', None)
|
||||||
if (name == None):
|
if (name == None):
|
||||||
return {"success":'false', "reason": "Empty group name"}
|
return {"success":'false', "reason": "Empty group name"}
|
||||||
group_new = UserGroup(name)
|
groupfile = open(fspath+"/global/group",'r')
|
||||||
db.session.add(group_new)
|
groups = json.loads(groupfile.read())
|
||||||
db.session.commit()
|
groupfile.close()
|
||||||
|
for group in groups:
|
||||||
|
if group['name'] == name:
|
||||||
|
groups.remove(group)
|
||||||
|
break
|
||||||
|
groupfile = open(fspath+"/global/group",'w')
|
||||||
|
groupfile.write(json.dumps(groups))
|
||||||
|
groupfile.close()
|
||||||
return {"success":'true'}
|
return {"success":'true'}
|
||||||
|
|
||||||
def queryForDisplay(*args, **kwargs):
|
def queryForDisplay(*args, **kwargs):
|
||||||
|
|
|
@ -52,6 +52,22 @@
|
||||||
<label>Group Name</label>
|
<label>Group Name</label>
|
||||||
<input type = "text" placeholder="Enter GroupName" class="form-control" name="name" id="mymyname">
|
<input type = "text" placeholder="Enter GroupName" class="form-control" name="name" id="mymyname">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>CPU Quota</label>
|
||||||
|
<input type = "text" placeholder="Enter CPU Quota" class="form-control" name="cpu" id="myCpu" value="100000">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Memory Quota</label>
|
||||||
|
<input type="text" placeholder="Enter Memory Quota" class="form-control" name="memory" id="myMemory" value="2000">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Image Quantity</label>
|
||||||
|
<input type = "text" placeholder="Enter Image Quantity" class="form-control" name="image" id="myImage" value="10">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Life Cycle</label>
|
||||||
|
<input type = "text" placeholder="Enter Life Cycle" class="form-control" name="lifecycle" id="myLifecycle" value="24">
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -66,7 +82,6 @@
|
||||||
<table id="myGroupTable" class="table table-striped table-bordered">
|
<table id="myGroupTable" class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>CPU</th>
|
<th>CPU</th>
|
||||||
<th>Memory</th>
|
<th>Memory</th>
|
||||||
|
@ -141,9 +156,10 @@
|
||||||
"columnDefs": [
|
"columnDefs": [
|
||||||
{
|
{
|
||||||
"render": function ( data, type, row ) {
|
"render": function ( data, type, row ) {
|
||||||
return '<a class="btn btn-info btn-sm" data-toggle="modal" data-target="#ModifyGroupModal" onClick="javascript:setFormGroup(' + row[0] + ');">' + 'Edit' + '</a>';
|
return '<a class="btn btn-info btn-sm" data-toggle="modal" data-target="#ModifyGroupModal" onClick="javascript:setFormGroup('+ "'" + row[0] + "'" + ');">' + 'Edit' + '</a>'
|
||||||
|
+ '<a class="btn btn-danger btn-sm" href="/group/delete/' + row[0] +'">' + 'Delete' + '</a>';
|
||||||
},
|
},
|
||||||
"targets": 6
|
"targets": 5
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -158,7 +174,7 @@
|
||||||
function setFormGroup(arg){
|
function setFormGroup(arg){
|
||||||
$.post("/group/query/",
|
$.post("/group/query/",
|
||||||
{
|
{
|
||||||
ID: arg,
|
name: arg
|
||||||
},
|
},
|
||||||
function(data,status){
|
function(data,status){
|
||||||
var result = eval("("+data+")").data;
|
var result = eval("("+data+")").data;
|
||||||
|
|
|
@ -255,19 +255,5 @@
|
||||||
$("#mDescription").val(result.description);
|
$("#mDescription").val(result.description);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function setFormGroup(arg){
|
|
||||||
$.post("/group/query/",
|
|
||||||
{
|
|
||||||
ID: arg,
|
|
||||||
},
|
|
||||||
function(data,status){
|
|
||||||
var result = eval("("+data+")").data;
|
|
||||||
$("#mGroupname").val(result.name);
|
|
||||||
$("#mCpu").val(result.cpu);
|
|
||||||
$("#mMemory").val(result.memory);
|
|
||||||
$("#mImage").val(result.imageQuantity);
|
|
||||||
$("#mLifecycle").val(result.lifeCycle);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -20,7 +20,7 @@ from webViews.log import logger
|
||||||
|
|
||||||
from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort
|
from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort
|
||||||
from webViews.dashboard import dashboardView
|
from webViews.dashboard import dashboardView
|
||||||
from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, userdataView, userqueryView
|
from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, groupdelView, userdataView, userqueryView
|
||||||
from webViews.user.userinfo import userinfoView
|
from webViews.user.userinfo import userinfoView
|
||||||
from webViews.user.userActivate import userActivateView
|
from webViews.user.userActivate import userActivateView
|
||||||
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
|
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
|
||||||
|
@ -328,6 +328,12 @@ def usermodify():
|
||||||
def groupadd():
|
def groupadd():
|
||||||
return groupaddView.as_view()
|
return groupaddView.as_view()
|
||||||
|
|
||||||
|
@app.route("/group/delete/<groupname>/", methods=['POST', 'GET'])
|
||||||
|
@administration_required
|
||||||
|
def groupdel(groupname):
|
||||||
|
groupdelView.groupname = groupname
|
||||||
|
return groupdelView.as_view()
|
||||||
|
|
||||||
@app.route("/user/info/", methods=['GET', 'POST'])
|
@app.route("/user/info/", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def userinfo():
|
def userinfo():
|
||||||
|
|
|
@ -54,3 +54,16 @@ class groupaddView(normalView):
|
||||||
def post(self):
|
def post(self):
|
||||||
dockletRequest.post('/user/groupadd', request.form)
|
dockletRequest.post('/user/groupadd', request.form)
|
||||||
return redirect('/admin/')
|
return redirect('/admin/')
|
||||||
|
|
||||||
|
class groupdelView(normalView):
|
||||||
|
@classmethod
|
||||||
|
def post(self):
|
||||||
|
data = {
|
||||||
|
"name" : self.groupname,
|
||||||
|
}
|
||||||
|
dockletRequest.post('/user/groupdel', data)
|
||||||
|
return redirect('/admin/')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get(self):
|
||||||
|
return self.post()
|
||||||
|
|
Loading…
Reference in New Issue