Commit 0233105b authored by Nicolas Wavrant's avatar Nicolas Wavrant

stack-monitor: added cgi interface for control

parent 950a004a
......@@ -53,12 +53,20 @@ download-only = true
filename = monitor.py.in
mode = 0644
[cgi-bin]
[monitor-cgi]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
#md5sum =
filename = index.cgi
filename = monitor.cgi.in
mode = 0644
[control-cgi]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
#md5sum =
filename = control.cgi.in
mode = 0644
[rss-bin]
......
#!{{ python_executable }}
import cgi
import cgitb
import ConfigParser
cgitb.enable(display=0, logdir="/tmp/cgi.log")
# Headers
print "Content-Type: text/html"
print
# Body content
form = cgi.FieldStorage()
if "password" not in form:
print """<html>
<body>
<h1>This is the monitoring interface</h1>
<p>Please enter the monitor_password in the next field to access the data</p>
<form action="/{{ this_filename }}" method="post">
Password : <input type="password" name="password">
<input type="submit" value="Access">
</form></body></html>"""
elif form['password'].value != '{{ password }}':
print "<html><body><h1>Error</h1><p>Wrong password</p></body></html>"
else:
parser = ConfigParser.ConfigParser()
parser.read("{{ config_cfg }}")
if len(form) > 1:
for name in form:
if name != 'password':
parser.set('public', name, form[name].value)
with open("{{ config_cfg }}", 'w') as file:
parser.write(file)
print "<html><body>"
print "<h1>Values to be defined by the user</h1>"
print "<form action=\"/control.cgi\" method=\"post\">"
print "<input type=\"hidden\" name=\"password\" value=\"{{ password }}\">"
for option in parser.options("public"):
print "%s : <input type=\"text\" name=\"%s\" \
value=\"%s\"><br>"% (option, option, parser.get('public', option))
print "<input type=\"submit\" value=\"Save\"></form>"
print "<h1>Other values:</h1>"
for section in parser.sections():
if section != 'public':
for option in parser.options(section):
print "<b>%s</b> : value=\"%s\"<br>" % (option,
parser.get(section, option))
print "</body></html>"
\ No newline at end of file
......@@ -6,4 +6,4 @@ PYTHON=${buildout:directory}/bin/${extra-eggs:interpreter}
STATUS2RSS=${rss-bin:location}/${rss-bin:filename}
NAME=`basename $STATUS`
cat $STATUS/* | $PYTHON $STATUS2RSS "Monitoring RSS feed" "https://[$${slap-parameters:ipv6-random}]:$${cgi-httpd-configuration-file:listening-port}/$${deploy-cgi-script:filename}" > $RSS_FILE
\ No newline at end of file
cat $STATUS/* | $PYTHON $STATUS2RSS "Monitoring RSS feed" "https://[$${slap-parameters:ipv6-random}]:$${cgi-httpd-configuration-file:listening-port}/$${deploy-monitor-cgi:filename}" > $RSS_FILE
\ No newline at end of file
......@@ -7,7 +7,7 @@ key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
[monitor-parameters]
monitor-dir = $${directory:monitor-result}
monitor-dir = $${directory:var}/monitor
result-dir = $${:monitor-dir}/bool
json-filename = monitor.json
json-path = $${:monitor-dir}/$${:json-filename}
......@@ -27,7 +27,7 @@ crontabs = $${:etc}/crontabs
cronstamps = $${:etc}/cronstamps
log = $${:var}/log
monitor = $${:etc}/monitor
monitor-result = $${:var}/monitor
monitor-result = $${monitor-parameters:monitor-dir}
monitor-result-bool = $${monitor-parameters:result-dir}
promise = $${:etc}/promise
run = $${:var}/run
......@@ -64,16 +64,29 @@ name = build-rss
frequency = * * * * *
command = $${make-rss:output}
[deploy-cgi-script]
[deploy-monitor-cgi]
recipe = slapos.recipe.template:jinja2
template = ${cgi-bin:location}/${cgi-bin:filename}
template = ${monitor-cgi:location}/${monitor-cgi:filename}
rendered = $${directory:www}/$${:filename}
filename = index.cgi
filename = monitor.cgi
mode = 0744
context =
key json_file monitor-parameters:json-path
key password cgi-password:passwd
raw python_executable ${buildout:executable}
key this_filename :filename
[deploy-control-cgi]
recipe = slapos.recipe.template:jinja2
template = ${control-cgi:location}/${control-cgi:filename}
rendered = $${directory:www}/$${:filename}
filename = control.cgi
mode = 0744
context =
raw config_cfg $${buildout:directory}/knowledge0.cfg
key password cgi-password:passwd
raw python_executable ${buildout:executable}
key this_filename :filename
[deploy-monitor-script]
recipe = slapos.recipe.template:jinja2
......
......@@ -21,7 +21,7 @@ if "password" not in form:
<body>
<h1>This is the monitoring interface</h1>
<p>Please enter the monitor_password in the next field to access the data</p>
<form action="/index.cgi" method="post">
<form action="/{{ this_filename }}" method="post">
Password : <input type="password" name="password">
<input type="submit" value="Access">
</form></body></html>"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment