Limit the privileges one can get via the admin page.
This commit is contained in:
parent
e9175e08fb
commit
603662a350
|
@ -1,9 +1,11 @@
|
|||
import re, string, os
|
||||
|
||||
|
||||
editableParms = ["ADMIN_EMAIL_ADDRESS","LOG_LEVEL"]
|
||||
configPath = {"docklet": os.environ.get("DOCKLET_CONF")+"/docklet.conf",
|
||||
"container": os.environ.get("DOCKLET_CONF")+"/container.conf"}
|
||||
#configPath = "../conf/docklet.conf"
|
||||
#lxcconfigPath = "../conf/container.conf"
|
||||
#configPath = {"docklet": "../conf/docklet.conf",
|
||||
# "container": "../conf/container.conf"}
|
||||
defaultPattern = re.compile(u'# *\S+ *= *\S+')
|
||||
activePattern = re.compile(u'\S+ *= *\S+')
|
||||
historyPattern = re.compile(u'## *\S+ *= *\S+')
|
||||
|
@ -27,29 +29,53 @@ def parse_line(line):
|
|||
class SystemManager():
|
||||
|
||||
def getParmList(*args, **kwargs):
|
||||
#result = {"docklet": "", "container": ""}
|
||||
result = {"docklet": "", "container": ""}
|
||||
for field in ["docklet", "container"]:
|
||||
for field in ["docklet"]:
|
||||
configFile = open(configPath[field])
|
||||
lines = configFile.readlines()
|
||||
configFile.close()
|
||||
configFile = open(configPath[field])
|
||||
wholeFile = configFile.read()
|
||||
configFile.close()
|
||||
conf = {}
|
||||
segs = wholeFile.split("\n\n")
|
||||
for line in lines:
|
||||
[linekind, lineparm, lineval] = parse_line(line)
|
||||
if lineparm in editableParms:
|
||||
editable = 1
|
||||
else:
|
||||
editable = 0
|
||||
if linekind == "default":
|
||||
conf[lineparm] = {"val": "novalidvaluea", "default": lineval, "history": []}
|
||||
conf[lineparm] = {"val": "novalidvaluea", "default": lineval,
|
||||
"history": [], "editable": editable, "details": ""}
|
||||
for line in lines:
|
||||
[linekind, lineparm, lineval] = parse_line(line)
|
||||
if linekind == "active":
|
||||
try:
|
||||
conf[lineparm]["val"] = lineval
|
||||
except:
|
||||
conf[lineparm] = {"val": lineval, "default": lineval, "history": []}
|
||||
if lineparm in editableParms:
|
||||
editable = 1
|
||||
else:
|
||||
editable = 0
|
||||
conf[lineparm] = {"val": lineval, "default": lineval,
|
||||
"history": [], "editable": editable, "details": ""}
|
||||
for line in lines:
|
||||
[linekind, lineparm, lineval] = parse_line(line)
|
||||
if linekind == "history":
|
||||
conf[lineparm]["history"].append(lineval)
|
||||
for parm in conf.keys():
|
||||
for seg in segs:
|
||||
if parm in seg:
|
||||
conf[parm]["details"] = seg
|
||||
result[field] = [({'parm': parm, 'val': conf[parm]['val'],
|
||||
'default': conf[parm]['default'], "history": conf[parm]['history']}) for parm in sorted(conf.keys())]
|
||||
'default': conf[parm]['default'], "history": conf[parm]['history'],
|
||||
"editable": conf[parm]['editable'], "details": conf[parm]['details']}) for parm in sorted(conf.keys())]
|
||||
configFile = open(configPath["container"])
|
||||
wholeFile = configFile.read()
|
||||
configFile.close()
|
||||
result["container"] = wholeFile
|
||||
return result
|
||||
|
||||
# 1. def and not act 2. act and not def 3. def and act
|
||||
|
|
|
@ -202,7 +202,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% for field in ["docklet", "container"] %}
|
||||
{% for field in ["docklet"] %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-info">
|
||||
|
@ -220,58 +220,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#AddParmModal_{{field}}"><i class="fa fa-plus"></i>Add Parameter</button>
|
||||
<div class="modal inmodal" id="AddParmModal_{{field}}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4 class="modal-title">Add Parameter</h4>
|
||||
<small class="font-bold">Add a parameter to Docklet</small>
|
||||
</div>
|
||||
<form action="/system/add/" method="POST" >
|
||||
<div class="modal-body">
|
||||
<div style="display:none">
|
||||
<input type="text" placeholder="" class="" name="field" value={{field}} />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Parameter Name</label>
|
||||
<input type="text" placeholder="Enter Parameter Name" class="form-control" name="parm" value="" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Default value</label>
|
||||
<input type="text" placeholder="Enter Default Value" class="form-control" name="val" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#ResetAllModal_{{field}}"><i class="fa fa-plus"></i> Reset All to Default</button>
|
||||
<div class="modal inmodal" id="ResetAllModal_{{field}}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>Sure to reset all parameters to default ?</h4>
|
||||
</div>
|
||||
<form action="/system/resetall/" method="POST">
|
||||
<div style="display:none">
|
||||
<input type="text" placeholder="" class="" name="field" value={{field}} />
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Yes</button>
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">No</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table table-responsive">
|
||||
<table id="myGroupTable" class="table table-striped table-bordered">
|
||||
<thead>
|
||||
|
@ -284,7 +233,9 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for editable in [1,0] %}
|
||||
{% for parm in parms[field] %}
|
||||
{% if parm["editable"] == editable %}
|
||||
<tr>
|
||||
|
||||
{% if parm["parm"]|length > 20%}
|
||||
|
@ -312,6 +263,15 @@
|
|||
<div class="modal inmodal" id="UseHistoryModal_{{field}}_{{ parm["parm"]|replace(".","") }}_{{ loop.indexo }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
{% if parm["editable"] == 0 %}
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>The parameter <strong> {{ parm["parm"] }} </strong> is non-editable!</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">Well</button>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>Sure to set <strong> {{ parm["parm"] }} </strong>to <strong>{{ history }} </strong>?</h4>
|
||||
|
@ -335,6 +295,7 @@
|
|||
<button type="button" class="btn btn-white" data-dismiss="modal">No</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -347,10 +308,26 @@
|
|||
<th><a class="btn btn-xs btn-default" data-toggle="modal" data-target="#UseDefaultModal_{{field}}_{{ parm["parm"]|replace(".","") }}"> {{ parm["default"] }}</a></th>
|
||||
{% endif %}
|
||||
<th>
|
||||
<a class="btn btn-xs btn-success" data-toggle="modal" data-target="#ViewParmModal_{{field}}_{{ parm["parm"]|replace(".","") }}">Details</a>
|
||||
{% if parm["editable"] == 1 %}
|
||||
<a class="btn btn-xs btn-info" data-toggle="modal" data-target="#ModifyParmModal_{{field}}_{{ parm["parm"]|replace(".","") }}">Edit</a>
|
||||
<a class="btn btn-xs btn-default" data-toggle="modal" data-target="#ClearHistoryModal_{{field}}_{{ parm["parm"]|replace(".","") }}">Clear History</a>
|
||||
<a class="btn btn-xs btn-danger" data-toggle="modal" data-target="#DeleteParmModal_{{field}}_{{ parm["parm"]|replace(".","")}}">Delete</a>
|
||||
{% endif %}
|
||||
</th>
|
||||
<div class="modal inmodal" id="ViewParmModal_{{field}}_{{ parm["parm"]|replace(".","") }}" tabindex="-1" role="dialog" aria-hidden="true" class="container">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<h4>Details of {{parm['parm']}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<pre>{{ parm['details'] }}</pre>
|
||||
</div>
|
||||
<div class="modal-footer"> <button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal inmodal" id="ModifyParmModal_{{field}}_{{ parm["parm"]|replace(".","") }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
|
@ -389,6 +366,15 @@
|
|||
<div class="modal inmodal" id="UseDefaultModal_{{field}}_{{ parm["parm"]|replace(".","") }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
{% if parm["editable"] == 0 %}
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>The parameter <strong> {{ parm["parm"] }} </strong> is non-editable!</h4>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">Well</button>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>Sure to set <strong> {{ parm["parm"] }} </strong> to <strong> {{ parm["default"] }} </strong> ?</h4>
|
||||
|
@ -412,60 +398,13 @@
|
|||
<button type="button" class="btn btn-white" data-dismiss="modal">No</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal inmodal" id="ClearHistoryModal_{{field}}_{{ parm["parm"]|replace(".","") }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>Sure to clear history for <strong> {{ parm["parm"] }} </strong> ?</h4>
|
||||
</div>
|
||||
<form action="/system/clear_history/" method="POST">
|
||||
<div style="display:none">
|
||||
<input type="text" placeholder="" class="" name="field" value={{field}} />
|
||||
</div>
|
||||
<div class="modal-body" style="display:none">
|
||||
<div class="form-group">
|
||||
<label>Parameter</label>
|
||||
<input type="text" placeholder="Enter Parameter" class="form-control" name="parm" value="{{ parm['parm'] }}" readonly="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Yes</button>
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">No</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal inmodal" id="DeleteParmModal_{{field}}_{{parm["parm"]|replace(".","") }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
<div class="modal-header">
|
||||
<i class="fa fa-laptop modal-icon"></i>
|
||||
<h4>Sure to delete the parameter <strong> {{ parm["parm"] }} </strong> ?</h4>
|
||||
</div>
|
||||
<form action="/system/delete/" method="POST">
|
||||
<div style="display:none">
|
||||
<input type="text" placeholder="" class="" name="field" value={{field}} />
|
||||
</div>
|
||||
<div class="modal-body" style="display:none">
|
||||
<div class="form-group">
|
||||
<label>Parameter</label>
|
||||
<input type="text" placeholder="Enter Parameter" class="form-control" name="parm" value="{{ parm['parm'] }}" readonly="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Yes</button>
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">No</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -476,6 +415,25 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-info">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Container Config</h3>
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<pre> {{ parms["container"] }} </pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script_src %}
|
||||
|
|
Loading…
Reference in New Issue