Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos
Commits
ec580565
Commit
ec580565
authored
Dec 31, 2013
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stack-monitor: status and settings now use cookies for connection
parent
5284682f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
37 deletions
+72
-37
stack/monitor/settings.cgi.in
stack/monitor/settings.cgi.in
+35
-18
stack/monitor/status.cgi.in
stack/monitor/status.cgi.in
+37
-19
No files found.
stack/monitor/settings.cgi.in
View file @
ec580565
...
@@ -4,28 +4,46 @@ import os
...
@@ -4,28 +4,46 @@ import os
import cgi
import cgi
import cgitb
import cgitb
import ConfigParser
import ConfigParser
import Cookie
cgitb.enable(display=0, logdir="/tmp/cgi.log")
cgitb.enable(display=0, logdir="/tmp/cgi.log")
# Headers
form = cgi.FieldStorage()
cookie = Cookie.SimpleCookie()
print "Content-Type: text/html"
print "Content-Type: text/html"
if "password" in form:
password = form['password'].value
if password == '{{ password }}' :
cookie['password'] = password
print cookie
else:
cookie_string = os.environ.get('HTTP_COOKIE')
if cookie_string:
cookie.load(cookie_string)
try:
password = cookie['password'].value
except KeyError:
password = None
else:
password = None
print
print
# Body content
if not password or password != '{{ password }}':
form = cgi.FieldStorage()
print "
<html><body>
"
if "password" not in form:
if password is None:
print """
<html>
print "
<h1>
This is the monitoring interface
</h1>
"
<body>
else:
<h1>
This is the monitoring interface
</h1>
print "
<h1>
Error
</h1><p>
Wrong password
</p>
"
print """
<p>
Please enter the monitor_password in the next field to access the data
</p>
<p>
Please enter the monitor_password in the next field to access the data
</p>
<form
action=
"/
{{ this_filename }}"
method=
"post"
>
<form
action=
"/
settings.cgi"
method=
"post"
>
Password :
<input
type=
"password"
name=
"password"
>
Password :
<input
type=
"password"
name=
"password"
>
<input
type=
"submit"
value=
"Access"
>
<input
type=
"submit"
value=
"Access"
>
</form></body></html>
"""
</form></body></html>
"""
elif form['password'].value != '{{ password }}':
print "
<html><body><h1>
Error
</h1><p>
Wrong password
</p></body></html>
"
else:
else:
config_file = "{{ config_cfg }}"
config_file = "{{ config_cfg }}"
if not os.path.exists(config_file):
if not os.path.exists(config_file):
...
@@ -42,7 +60,7 @@ else:
...
@@ -42,7 +60,7 @@ else:
parser.write(file)
parser.write(file)
print "
<html><body>
"
print "
<html><body>
"
print "
<h1>
Values that can be defined by the user :
</h1>
"
print "
<h1>
Values that can be defined by the user :
</h1>
"
print "
<form
action=
\"/
control.cgi
\"
method=
\"post\"
>
"
print "
<form
action=
\"/
{{
this_filename
}}
\"
method=
\"post\"
>
"
print "
<input
type=
\"hidden\"
name=
\"password\"
value=
\"{{
password
}}\"
>
"
print "
<input
type=
\"hidden\"
name=
\"password\"
value=
\"{{
password
}}\"
>
"
for option in parser.options("public"):
for option in parser.options("public"):
print "%s :
<input
type=
\"text\"
name=
\"%s\"
\
print "%s :
<input
type=
\"text\"
name=
\"%s\"
\
...
@@ -56,5 +74,4 @@ else:
...
@@ -56,5 +74,4 @@ else:
print "
<b>
%s
</b>
: value=\"%s\"
<br>
" % (option,
print "
<b>
%s
</b>
: value=\"%s\"
<br>
" % (option,
parser.get(section, option))
parser.get(section, option))
print "
<br><br><p><a
href=
\"/monitor.cgi\"
>
Monitor interface
</a></p>
"
print "
</body></html>
"
print "
</body></html>
"
stack/monitor/status.cgi.in
View file @
ec580565
...
@@ -2,34 +2,53 @@
...
@@ -2,34 +2,53 @@
import cgi
import cgi
import cgitb
import cgitb
import Cookie
import json
import json
import os
import sys
import sys
cgitb.enable(display=0, logdir="/tmp/cgi.log")
cgitb.enable(display=0, logdir="/tmp/cgi.log")
json_file = "{{ json_file }}"
form = cgi.FieldStorage()
result = json.load(open(json_file))
cookie = Cookie.SimpleCookie()
# Headers
print "Content-Type: text/html"
print "Content-Type: text/html"
if "password" in form:
password = form['password'].value
if password == '{{ password }}' :
cookie['password'] = password
print cookie
else:
cookie_string = os.environ.get('HTTP_COOKIE')
if cookie_string:
cookie.load(cookie_string)
try:
password = cookie['password'].value
except KeyError:
password = None
else:
password = None
print
print
# Body content
if not password or password != '{{ password }}':
form = cgi.FieldStorage()
print "
<html><body>
"
if "password" not in form:
if password is None:
print """
<html>
print "
<h1>
This is the monitoring interface
</h1>
"
<body>
else:
<h1>
This is the monitoring interface
</h1>
print "
<h1>
Error
</h1><p>
Wrong password
</p>
"
print """
<p>
Please enter the monitor_password in the next field to access the data
</p>
<p>
Please enter the monitor_password in the next field to access the data
</p>
<form
action=
"/
{{ this_filename }}"
method=
"post"
>
<form
action=
"/
settings.cgi"
method=
"post"
>
Password :
<input
type=
"password"
name=
"password"
>
Password :
<input
type=
"password"
name=
"password"
>
<input
type=
"submit"
value=
"Access"
>
<input
type=
"submit"
value=
"Access"
>
</form></body></html>
"""
</form></body></html>
"""
elif form['password'].value != '{{ password }}':
print "
<html><body><h1>
Error
</h1><p>
Wrong password
</p></body></html>
"
else:
else:
json_file = "{{ json_file }}"
result = json.load(open(json_file))
print "
<html><body>
"
print "
<html><body>
"
print "
<h1>
Monitoring :
</h1>
"
print "
<h1>
Monitoring :
</h1>
"
print "
<p><em>
Last time of monitoring process : %s
</em></p>
" % (result['datetime'])
print "
<p><em>
Last time of monitoring process : %s
</em></p>
" % (result['datetime'])
...
@@ -46,5 +65,4 @@ else:
...
@@ -46,5 +65,4 @@ else:
for r in result:
for r in result:
if result[r] == '':
if result[r] == '':
print "
<h3>
%s
</h3><p>
%s
</p>
" % (r, result[r])
print "
<h3>
%s
</h3><p>
%s
</p>
" % (r, result[r])
print "
<br><br><p><a
href=
\"/control.cgi\"
>
Control interface
</a></p>
"
print "
</body></html>
"
print "
</body></html>
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment