Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
035f93af
authored
Jul 27, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notify: setuid+fork for webbrowser
parent
6f8ffbbc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
31 deletions
+32
-31
notify.py
+32
-31
No files found.
notify.py
View file @
035f93af
...
@@ -9,11 +9,11 @@ import cookielib
...
@@ -9,11 +9,11 @@ import cookielib
import
errno
import
errno
import
json
import
json
import
logging
import
logging
import
multiprocessing
import
os
import
os
import
platform
import
platform
import
subprocess
import
subprocess
import
urllib2
import
urllib2
import
webbrowser
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
file_name
=
"vm_renewal.json"
file_name
=
"vm_renewal.json"
...
@@ -40,6 +40,8 @@ def get_temp_dir():
...
@@ -40,6 +40,8 @@ def get_temp_dir():
def
wall
(
text
):
def
wall
(
text
):
if
platform
.
system
()
==
"Windows"
:
return
if
text
is
None
:
if
text
is
None
:
logger
.
error
(
"Incorrect function call"
)
logger
.
error
(
"Incorrect function call"
)
else
:
else
:
...
@@ -80,35 +82,35 @@ def accept():
...
@@ -80,35 +82,35 @@ def accept():
def
notify
(
url
):
def
notify
(
url
):
olddisplay
=
os
.
environ
.
get
(
"DISPLAY"
)
file_path
=
os
.
path
.
join
(
get_temp_dir
(),
file_name
)
try
:
if
file_already_exists
(
file_path
)
:
file_path
=
os
.
path
.
join
(
get_temp_dir
(),
file_name
)
os
.
remove
(
file_path
)
if
file_already_exists
(
file_path
):
if
file_already_exists
(
file_path
):
os
.
remove
(
file_path
)
raise
Exception
(
"Couldn't create file
%
s as new"
%
file_path
)
if
file_already_exists
(
file_path
):
with
open
(
file_path
,
"w"
)
as
f
:
raise
Exception
(
"Couldn't create file
%
s as new"
%
file_path
)
json
.
dump
(
url
,
f
)
with
open
(
file_path
,
"w"
)
as
f
:
wall
(
"This virtual machine is going to expire! Please type
\n
"
json
.
dump
(
url
,
f
)
" vm_renewal
\n
"
"command to keep it running."
)
if
platform
.
system
()
!=
"Windows"
:
p
=
multiprocessing
.
Process
(
target
=
open_in_browser
,
args
=
(
url
,
))
display
=
search_display
()
p
.
start
()
if
display
:
os
.
environ
[
'DISPLAY'
]
=
display
def
open_in_browser
(
url
):
wall
(
"This virtual machine is going to expire! Please type
\n
"
if
platform
.
system
()
!=
"Windows"
:
" vm_renewal
\n
"
display
=
search_display
()
"command to keep it running."
)
else
:
display
=
True
if
display
:
if
display
:
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
display
,
uid
,
gid
=
display
finally
:
os
.
setgid
(
gid
)
if
olddisplay
:
os
.
setuid
(
uid
)
os
.
environ
[
"DISPLAY"
]
=
olddisplay
os
.
environ
[
'DISPLAY'
]
=
display
elif
'DISPLAY'
in
os
.
environ
:
logger
.
debug
(
"DISPLAY=
%
s"
,
display
)
del
os
.
environ
[
"DISPLAY"
]
else
:
display
=
True
if
display
:
import
webbrowser
webbrowser
.
open
(
url
,
new
=
2
,
autoraise
=
True
)
def
file_already_exists
(
name
,
mode
=
0644
):
def
file_already_exists
(
name
,
mode
=
0644
):
...
@@ -143,15 +145,14 @@ def search_display():
...
@@ -143,15 +145,14 @@ def search_display():
with
open
(
env
,
"r"
)
as
f
:
with
open
(
env
,
"r"
)
as
f
:
envs
=
dict
(
line
.
split
(
"="
,
1
)
envs
=
dict
(
line
.
split
(
"="
,
1
)
for
line
in
f
.
read
()
.
split
(
"
\0
"
)
if
"="
in
line
)
for
line
in
f
.
read
()
.
split
(
"
\0
"
)
if
"="
in
line
)
if
"DISPLAY"
in
envs
and
":"
in
envs
[
"DISPLAY"
]:
p
=
os
.
stat
(
os
.
path
.
join
(
"/proc"
,
pid
))
return
envs
[
"DISPLAY"
],
p
.
st_uid
,
p
.
st_gid
except
:
except
:
continue
continue
else
:
if
"DISPLAY"
in
envs
and
":"
in
envs
[
"DISPLAY"
]:
return
envs
[
"DISPLAY"
]
return
None
return
None
def
main
():
def
main
():
args
=
parse_arguments
()
args
=
parse_arguments
()
notify
(
args
.
url
)
notify
(
args
.
url
)
...
...
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