Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
6b408ef8
Commit
6b408ef8
authored
Jan 14, 2016
by
mike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use utils.shell instead of subprocess.Popen
parent
8932aaf4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
10 deletions
+17
-10
daemon.py
management/daemon.py
+17
-10
No files found.
management/daemon.py
View file @
6b408ef8
...
@@ -530,24 +530,31 @@ def munin_cgi(filename=""):
...
@@ -530,24 +530,31 @@ def munin_cgi(filename=""):
support infrastructure like spawn-fcgi.
support infrastructure like spawn-fcgi.
"""
"""
COMMAND
=
'su - munin --preserve-environment --shell=/bin/bash -c
"/usr/lib/munin/cgi/munin-cgi-graph
\'
%
s
\'
"'
COMMAND
=
'su - munin --preserve-environment --shell=/bin/bash -c
/usr/lib/munin/cgi/munin-cgi-graph "
%
s
"'
# su changes user, we use the munin user here
# su changes user, we use the munin user here
# --preserve-environment retains the environment, which is where Popen's `env` data is
# --preserve-environment retains the environment, which is where Popen's `env` data is
# --shell=/bin/bash ensures the shell used is bash
# --shell=/bin/bash ensures the shell used is bash
# -c "/usr/lib/munin/cgi/munin-cgi-graph" passes the command to run as munin
# -c "/usr/lib/munin/cgi/munin-cgi-graph" passes the command to run as munin
#
\'%s\'
is a placeholder for where the request's querystring will be added
#
"%s"
is a placeholder for where the request's querystring will be added
if
filename
==
""
:
if
filename
==
""
:
return
(
"a path must be specified"
,
404
)
return
(
"a path must be specified"
,
404
)
query_str
=
request
.
query_string
.
decode
(
"utf-8"
,
'ignore'
)
query_str
=
request
.
query_string
.
decode
(
"utf-8"
,
'ignore'
)
query_str
=
query_str
[
1
:]
if
query_str
.
startswith
(
'&'
)
else
query_str
[
1
:]
# I don't know if this is strictly necessary
env
=
{
'PATH_INFO'
:
'/
%
s/'
%
filename
,
'QUERY_STRING'
:
query_str
}
env
=
{
'PATH_INFO'
:
'/
%
s/'
%
filename
,
'QUERY_STRING'
:
query_str
}
cmd
=
COMMAND
%
(
query_str
if
not
query_str
.
startswith
(
'&'
)
else
query_str
[
1
:])
cmd
=
COMMAND
%
query_str
process
=
subprocess
.
Popen
(
cmd
,
env
=
env
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
close_fds
=
True
)
code
,
binout
=
utils
.
shell
(
'check_output'
,
stdout
,
stderr
=
process
.
communicate
()
cmd
.
split
(
' '
,
5
),
# Using a maxsplit of 5 keeps the last 2 arguments together
if
process
.
returncode
!=
0
:
input
=
query_str
.
encode
(
'UTF-8'
),
env
=
env
,
return_bytes
=
True
,
trap
=
True
)
if
code
!=
0
:
# nonzero returncode indicates error
# nonzero returncode indicates error
app
.
logger
.
error
(
"munin_cgi: munin-cgi-graph returned nonzero exit code,
%
s"
,
process
.
returncode
)
app
.
logger
.
error
(
"munin_cgi: munin-cgi-graph returned nonzero exit code,
%
s"
,
process
.
returncode
)
return
(
"error processing graph image"
,
500
)
return
(
"error processing graph image"
,
500
)
...
@@ -556,10 +563,10 @@ def munin_cgi(filename=""):
...
@@ -556,10 +563,10 @@ def munin_cgi(filename=""):
# Per http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html PNG files always start
# Per http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html PNG files always start
# with the same 8 bytes (137 80 78 71 13 10 26 10) or b'\x89PNG\r\n\x1a\n' So we split
# with the same 8 bytes (137 80 78 71 13 10 26 10) or b'\x89PNG\r\n\x1a\n' So we split
# the output of munin-cgi-graph where the PNG begins
# the output of munin-cgi-graph where the PNG begins
bin_start
=
std
out
.
find
(
b
'
\x89
PNG
\r\n\x1a\n
'
)
bin_start
=
bin
out
.
find
(
b
'
\x89
PNG
\r\n\x1a\n
'
)
str_headers
=
std
out
[:
bin_start
]
.
decode
(
"utf-8"
)
str_headers
=
bin
out
[:
bin_start
]
.
decode
(
"utf-8"
)
# decode the byte str containing response headers
# decode the byte str containing response headers
bin_image
=
std
out
[
bin_start
:]
bin_image
=
bin
out
[
bin_start
:]
response
=
make_response
(
bin_image
)
response
=
make_response
(
bin_image
)
for
line
in
str_headers
.
splitlines
():
for
line
in
str_headers
.
splitlines
():
if
line
:
if
line
:
...
...
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