Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
40623433
authored
Feb 08, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
laborclient: Automatic mount/umount
parent
55a0c9ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
85 deletions
+79
-85
miscellaneous/laborclient/cloudgui/gui.py
+79
-85
No files found.
miscellaneous/laborclient/cloudgui/gui.py
View file @
40623433
...
@@ -8,10 +8,9 @@ import os
...
@@ -8,10 +8,9 @@ import os
import
sys
import
sys
import
rdp
import
rdp
from
multiprocessing
import
Process
from
multiprocessing
import
Process
### Settings ###
import
subprocess
KEY_DIR
=
"/tmp/"
import
tempfile
KEY_FILE
=
KEY_DIR
+
"/id_rsa"
import
getpass
class
KeyGen
:
class
KeyGen
:
"""Attributes:
"""Attributes:
...
@@ -61,10 +60,12 @@ class KeyGen:
...
@@ -61,10 +60,12 @@ class KeyGen:
class
Browser
:
class
Browser
:
version
=
"0.1"
neptun
=
""
neptun
=
""
host
=
""
host
=
""
private_key_file
=
""
private_key_file
=
""
public_key_b64
=
""
public_key_b64
=
""
params
=
{}
def
__init__
(
self
):
def
__init__
(
self
):
#Init window components
#Init window components
gobject
.
threads_init
()
gobject
.
threads_init
()
...
@@ -74,46 +75,28 @@ class Browser:
...
@@ -74,46 +75,28 @@ class Browser:
#DEBUG
#DEBUG
print
self
.
window
.
get_resizable
()
self
.
window
.
set_decorated
(
True
)
self
.
window
.
set_decorated
(
True
)
#self.window.connect(
self
.
window
.
set_title
(
"IK CloudStore Login"
)
self
.
window
.
set_title
(
"IK CloudStore Login"
)
self
.
window
.
set_default_size
(
1024
,
600
)
self
.
window
.
set_default_size
(
1024
,
600
)
self
.
window
.
set_position
(
gtk
.
WIN_POS_CENTER
)
self
.
window
.
set_position
(
gtk
.
WIN_POS_CENTER
)
#Init toolbar
self
.
toolbar
=
gtk
.
Toolbar
()
#Init browser
#Init browser
self
.
webview
=
webkit
.
WebView
()
self
.
webview
=
webkit
.
WebView
()
self
.
webview
.
connect
(
'onload-event'
,
self
.
load_committed_cb
)
self
.
webview
.
connect
(
'onload-event'
,
self
.
load_committed_cb
)
# self.webview.open("http://10.9.1.86:8080")
self
.
webview
.
open
(
"https://cloud.ik.bme.hu/store/gui/"
)
self
.
webview
.
open
(
"https://cloud.ik.bme.hu/store/gui/"
)
self
.
webview
.
connect
(
"navigation-requested"
,
self
.
on_navigation_requested
)
self
.
webview
.
connect
(
"navigation-requested"
,
self
.
on_navigation_requested
)
#self.webview.open("http://index.hu")
settings
=
webkit
.
WebSettings
()
settings
.
set_property
(
'user-agent'
,
'cloud-gui '
+
self
.
version
)
#Sample button
self
.
webview
.
set_settings
(
settings
)
self
.
help_button
=
gtk
.
ToolButton
(
gtk
.
STOCK_HELP
)
self
.
help_button
.
connect
(
"clicked"
,
self
.
hello
)
self
.
store_button
=
gtk
.
ToolButton
(
gtk
.
STOCK_HOME
)
self
.
store_button
.
connect
(
"clicked"
,
self
.
store
)
#Connect things
#Connect things
self
.
toolbar
.
add
(
self
.
store_button
)
self
.
toolbar
.
add
(
self
.
help_button
)
self
.
vbox
=
gtk
.
VBox
(
False
,
0
)
#self.vbox.pack_start(self.toolbar, False, True, 0)
self
.
scrolledwindow
=
gtk
.
ScrolledWindow
()
self
.
scrolledwindow
=
gtk
.
ScrolledWindow
()
self
.
scrolledwindow
.
add
(
self
.
webview
)
self
.
scrolledwindow
.
add
(
self
.
webview
)
self
.
vbox
.
add
(
self
.
scrolledwindow
)
self
.
window
.
add
(
self
.
scrolledwindow
)
self
.
window
.
add
(
self
.
vbox
)
#self.window.add(self.webview)
self
.
window
.
maximize
()
self
.
window
.
maximize
()
self
.
window
.
show_all
()
self
.
window
.
show_all
()
def
init_keypair
():
def
init_keypair
(
self
):
keygen
=
KeyGen
()
keygen
=
KeyGen
()
private_key
=
keygen
.
private_key
private_key
=
keygen
.
private_key
public_key
=
keygen
.
public_key
public_key
=
keygen
.
public_key
...
@@ -125,73 +108,86 @@ class Browser:
...
@@ -125,73 +108,86 @@ class Browser:
self
.
public_key_b64
=
base64
.
b64encode
(
public_key
)
self
.
public_key_b64
=
base64
.
b64encode
(
public_key
)
def
destroy
(
self
,
dummy
):
def
destroy
(
self
,
dummy
):
self
.
webview
.
execute_script
(
"resetKey()"
)
self
.
umount_sshfs_folder
(
)
gtk
.
main_quit
()
gtk
.
main_quit
()
def
on_navigation_requested
(
self
,
view
,
frame
,
req
,
data
=
None
):
def
on_navigation_requested
(
self
,
view
,
frame
,
req
,
data
=
None
):
uri
=
req
.
get_uri
()
uri
=
req
.
get_uri
()
print
"On nav: "
+
uri
if
uri
==
"https://cloud.ik.bme.hu/logout/"
:
scheme
,
rest
=
uri
.
split
(
':'
,
1
)
self
.
umount_sshfs_folder
()
#print scheme
try
:
scheme
,
rest
=
uri
.
split
(
":"
,
1
)
if
scheme
==
"nx"
or
scheme
==
"rdp"
or
scheme
==
"sshterm"
:
connection
=
rdp
.
RDP
(
uri
)
Process
(
target
=
connection
.
connect
)
.
start
()
return
True
else
:
return
False
except
:
False
def
mount_sshfs_folder
(
self
):
user
=
getpass
.
getuser
()
neptun
=
self
.
params
[
"neptun"
]
host
=
self
.
params
[
"host"
]
try
:
try
:
self
.
neptun
,
rest
=
rest
.
split
(
':'
,
1
)
os
.
makedirs
(
"/home/"
+
user
+
"/sshfs"
,
0644
)
#print "Nep: "+neptun
self
.
host
,
values
=
rest
.
split
(
'?'
,
1
)
#print "Host: "+host
#print "Values: "+values
except
:
except
:
pass
pass
if
scheme
==
'login'
:
result
=
subprocess
.
call
([
'/usr/bin/sshfs'
,
'-o'
,
'IdentityFile='
+
self
.
private_key_file
,
neptun
+
"@"
+
host
+
":home"
,
"/home/"
+
user
+
"/sshfs"
])
self
.
webview
.
execute_script
(
"postKey(
\"
%
s
\"
)"
%
self
.
public_key_b64
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
login_button
\"
).hidden=true ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
logout_button
\"
).hidden=false ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
mount_button
\"
).hidden=false ;"
)
return
True
elif
scheme
==
'logout'
:
self
.
webview
.
execute_script
(
"resetKey()"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
logout_button
\"
).hidden=true ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
login_button
\"
).hidden=false ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
mount_button
\"
).hidden=true ;"
)
return
True
elif
scheme
==
"mount"
:
self
.
mount_sshfs_folder
(
self
.
neptun
,
self
.
host
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
mount_button
\"
).hidden=true ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
umount_button
\"
).hidden=false ;"
)
return
True
elif
scheme
==
"umount"
:
self
.
umount_sshfs_folder
()
self
.
webview
.
execute_script
(
"document.getElementById(
\"
mount_button
\"
).hidden=false ;"
)
self
.
webview
.
execute_script
(
"document.getElementById(
\"
umount_button
\"
).hidden=true ;"
)
return
True
elif
scheme
==
"nx"
or
scheme
==
"rdp"
or
scheme
==
"sshterm"
:
connection
=
rdp
.
RDP
(
uri
)
Process
(
target
=
connection
.
connect
)
.
start
()
return
True
else
:
return
False
def
mount_sshfs_folder
(
self
,
neptun
,
host
):
with
open
(
os
.
devnull
,
"w"
)
as
fnull
:
result
=
subprocess
.
call
([
'/usr/bin/sshfs'
,
'-o'
,
'IdentityFile='
+
KEY_DIR
+
"/id_rsa"
,
neptun
+
"@"
+
host
+
":home"
,
"/home/tarokkk/sshfs"
])
#print result
#print result
def
umount_sshfs_folder
(
self
):
def
umount_sshfs_folder
(
self
):
with
open
(
os
.
devnull
,
"w"
)
as
fnull
:
try
:
result
=
subprocess
.
call
([
'/bin/fusermount'
,
'-u'
,
"/home/tarokkk/sshfs"
])
result
=
subprocess
.
call
([
'/bin/fusermount'
,
'-u'
,
"/home/tarokkk/sshfs"
])
except
:
def
hello
(
self
,
widget
):
pass
self
.
webview
.
open
(
"https://login.bme.hu/admin/"
)
def
post_key
(
self
,
key
=
None
):
if
key
!=
None
:
def
store
(
self
,
widget
):
js
=
'''
self
.
webview
.
open
(
"https://cloud.ik.bme.hu/"
)
$.post("/store/gui/", { "KEY" : "
%(key)
s" },
function (respond) {
window.location = respond;
}
)
.error(function (respond) { alert(JSON.stringify(respond)); });
'''
%
{
"key"
:
key
}
else
:
js
=
'''
$.post("/store/gui/", "",
function (respond) {
window.alert(respond);
}
)
.error(function (respond) { alert(JSON.stringify(respond)); });
'''
self
.
webview
.
execute_script
(
js
)
def
load_committed_cb
(
self
,
web_view
,
frame
):
def
load_committed_cb
(
self
,
web_view
,
frame
):
self
.
webview
.
execute_script
(
'document.getElementsByTagName("a")[0].target="";'
)
try
:
self
.
webview
.
execute_script
(
'document.getElementsByTagName("a")[0].target="";'
)
except
:
pass
uri
=
frame
.
get_uri
()
uri
=
frame
.
get_uri
()
if
str
(
uri
)
==
"https://cloud.ik.bme.hu/store/gui/"
:
### Send keys via JavaScript ###
self
.
webview
.
execute_script
(
"postKey(
\"
%
s
\"
)"
%
self
.
public_key_b64
)
if
uri
==
"https://cloud.ik.bme.hu/store/gui/"
:
print
"Mounting"
self
.
init_keypair
()
#print uri
### JS
#print web_view.get_title()
self
.
post_key
(
self
.
public_key_b64
)
return
### Parse values and do mounting ###
try
:
uri
,
params
=
uri
.
split
(
'?'
,
1
)
values
=
params
.
split
(
'&'
)
for
p
in
values
:
key
,
value
=
p
.
split
(
'='
,
1
)
self
.
params
[
key
]
=
value
try
:
self
.
mount_sshfs_folder
()
except
Exception
as
e
:
print
e
finally
:
os
.
unlink
(
self
.
private_key_file
)
except
:
pass
return
True
def
main
(
self
):
def
main
(
self
):
gtk
.
main
()
gtk
.
main
()
...
@@ -199,5 +195,3 @@ if __name__ == "__main__":
...
@@ -199,5 +195,3 @@ if __name__ == "__main__":
browser
=
Browser
()
browser
=
Browser
()
browser
.
main
()
browser
.
main
()
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