Commit 06c3b682 by Őry Máté

remove laborclient

parent d4aef292
include cloud.svg
include cloud.desktop
#!/usr/bin/python
import cloudgui
if __name__ == '__main__':
try:
browser = cloudgui.gui.Browser()
browser.main()
finally:
browser.umount_sshfs_folder()
[Desktop Entry]
Version=0.1
Name=Cloud GUI
Comment=Tool to use IK Cloud
Exec=cloud
Icon=/usr/share/icons/cloud.svg
Terminal=false
Type=Application
Categories=Utility;Application;
#!/usr/bin/env python
import gtk
import webkit
import gobject
import base64
import os
import sys
import rdp
from multiprocessing import Process
import subprocess
import tempfile
class KeyGen:
"""Attributes:
private_key
public_key
"""
def __init__(self):
self.private_key, self.public_key = self.keygen(2048)
def keygen(self,length=1024):
"""Generate Keypair for SSH
(private_key, public_key)
"""
import os, base64
from datetime import date
from Crypto.PublicKey import RSA
key = RSA.generate(length, os.urandom)
try:
pub = key.exportKey('OpenSSH')
if not pub.startswith("ssh-"):
raise ValueError(pub)
except:
ssh_rsa = '00000007' + base64.b16encode('ssh-rsa')
exponent = '%x' % (key.e, )
if len(exponent) % 2:
exponent = '0' + exponent
ssh_rsa += '%08x' % (len(exponent) / 2, )
ssh_rsa += exponent
modulus = '%x' % (key.n, )
if len(modulus) % 2:
modulus = '0' + modulus
if modulus[0] in '89abcdef':
modulus = '00' + modulus
ssh_rsa += '%08x' % (len(modulus) / 2, )
ssh_rsa += modulus
pub = 'ssh-rsa %s' % (
base64.b64encode(base64.b16decode(ssh_rsa.upper())), )
return key.exportKey(), "%s %s" % (pub, "cloud-%s" % date.today())
class Browser:
version = "0.1"
mounted = False
neptun = ""
host = ""
private_key_file = ""
public_key_b64 = ""
params = {}
def __init__(self):
#Init window components
gobject.threads_init()
self.window = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
#Register window events
self.window.connect("destroy", self.destroy)
#DEBUG
self.window.set_decorated(True)
self.window.set_title("IK CloudStore Login")
self.window.set_default_size(1024,600)
self.window.set_position(gtk.WIN_POS_CENTER)
#Init browser
self.webview = webkit.WebView()
self.webview.connect('onload-event', self.load_committed_cb)
self.webview.open("https://cloud.ik.bme.hu/store/gui/")
self.webview.connect("navigation-requested", self.on_navigation_requested)
settings = webkit.WebSettings()
settings.set_property('user-agent', settings.get_property('user-agent')+' cloud-gui '+self.version)
settings.set_property('enable-accelerated-compositing', True)
settings.set_property("enable-default-context-menu", False)
self.webview.set_settings(settings)
#Connect things
self.scrolledwindow = gtk.ScrolledWindow()
self.scrolledwindow.add(self.webview)
self.window.add(self.scrolledwindow)
self.window.maximize()
self.window.show_all()
def init_keypair(self):
keygen = KeyGen()
private_key = keygen.private_key
public_key = keygen.public_key
#Saver private_key to KEY_FILE
with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
f.write(private_key)
self.private_key_file = f.name
self.public_key_b64 = base64.b64encode(public_key)
def destroy(self, dummy):
try:
os.unlink(self.private_key_file)
except:
pass
try:
self.umount_sshfs_folder()
except:
pass
gtk.main_quit()
def on_navigation_requested(self, view, frame, req, data=None):
uri = req.get_uri()
if uri == "https://login.bme.hu/admin/":
gobject.threads_init()
window = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
browser = webkit.WebView()
browser.open(uri)
window.add(browser)
window.show_all()
return True
elif uri == "https://cloud.ik.bme.hu/logout/":
self.umount_sshfs_folder()
try:
scheme, rest = uri.split(":", 1)
if scheme == "nx" or scheme == "rdp" or scheme == "sshterm":
subprocess.Popen(["/usr/local/bin/rdp",uri])
return True
elif scheme == "cloudfile":
file_path = os.path.normpath(rest)
subprocess.call(["xdg-open","file://"+self.folder+file_path])
return True
else:
return False
except:
False
def mount_sshfs_folder(self):
self.folder = os.path.expanduser("~/sshfs")
neptun = self.params["neptun"]
host = self.params["host"]
try:
os.makedirs(self.folder)
except:
pass
result = subprocess.call(['/usr/bin/sshfs', '-o', 'IdentityFile='+self.private_key_file+',StrictHostKeyChecking=no', neptun+"@"+host+":home", self.folder])
#print result
def umount_sshfs_folder(self):
try:
result = subprocess.call(['/bin/fusermount', '-u', self.folder])
except:
pass
def post_key(self,key = None):
if key != None:
js = '''
$.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):
uri = frame.get_uri()
#print uri
try:
self.webview.execute_script('document.getElementsByTagName("a")[0].target="";')
except:
pass
### Send keys via JavaScript ###
if uri == "https://cloud.ik.bme.hu/store/gui/":
self.init_keypair()
### JS
self.post_key(self.public_key_b64)
### Parse values and do mounting ###
elif uri.startswith("https://cloud.ik.bme.hu/home/?"):
if self.mounted != True:
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
self.mounted = True
except:
pass
finally:
os.unlink(self.private_key_file)
return True
def main(self):
gtk.main()
if __name__ == "__main__":
browser = Browser()
browser.main()
#!/usr/bin/python
import sys
import random
import re
from xml.sax.saxutils import escape
class NXKeyGen:
numValidCharList = 85
dummyString = "{{{{"
def __init__(self, password):
self.password = password
def getEncrypted(self):
return self.scrambleString(self.password)
def getvalidCharList(self, pos):
validcharlist = [
"!", "#", "$", "%", "&", "(", ")", "*", "+", "-",
".", "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", ":", ";", "<", ">", "?", "@", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "[", "]", "_", "a", "b", "c", "d",
"e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z", "{", "|", "}"
]
return validcharlist[pos]
def encodePassword(self, p):
sPass = ":"
sTmp = ""
if not p:
return ""
for i in range(len(p)):
c = p[i:i+1]
a = ord(c)
sTmp = str( a + i + 1) + ":"
sPass += sTmp
sTmp = ""
return sPass
def findCharInList(self, c):
i = -1
for j in range(self.numValidCharList):
randchar = self.getvalidCharList(j);
if randchar == c:
i = j
return i
return i
def getRandomValidCharFromList(self):
return self.getvalidCharList(random.randint(0,60))
#return self.getvalidCharList(0)
def scrambleString(self, s):
sRet = ""
if not s:
return s
strp = self.encodePassword(s)
if len(strp) < 32:
sRet += self.dummyString
#print "Added dummy "+sRet
for iR in reversed(range(len(strp))):
sRet += strp[iR:iR+1]
#print "Reverse: "+sRet
if len(sRet) < 32:
sRet += self.dummyString
#print "Added dummy2 "+sRet
app = self.getRandomValidCharFromList()
#print "Random valid char: "+app
k = ord(app)
l = k + len(sRet) - 2
sRet = app + sRet
#print "Random "+sRet+"\n"
for i1 in range(1, len(sRet)):
app2 = sRet[i1 : i1 + 1]
#print "For cycle app2= "+str(app2)
j = self.findCharInList(app2)
#print "For cycle j= "+str(j)
if j == -1:
return sRet
i = (j + l * (i1 + 1)) % self.numValidCharList
#print "For cycle i= "+str(i)
car = self.getvalidCharList(i)
sRet = self.substr_replace(sRet,car,i1,1)
#print "For cycle sRet: "+sRet+"\n"
c = (ord(self.getRandomValidCharFromList())) + 2
c2 = chr(c)
sRet = sRet + c2
return escape(sRet)
def substr_replace(self,in_str,ch,pos,qt):
clist = list(in_str)
count = 0;
tmp_str = '';
for key in clist:
if count != pos:
tmp_str += key
else:
tmp_str += ch
count = count+1
return tmp_str
if __name__ == "__main__":
NXPass = NXKeyGen(sys.argv[1])
print NXPass.password
print NXPass.getEncrypted()
#!/usr/bin/python
import nxkey
import tempfile
import subprocess
import os
import sys
import gtk
import gobject
from multiprocessing import Manager, Process
import threading
import signal
import time
class RDP:
def __init__(self, uri):
gobject.threads_init()
self.scheme, self.username, self.password, self.host, self.port = uri.split(':',4)
self.manager = Manager()
self.global_vars = self.manager.Namespace()
self.global_vars.pid = 0
self.box = gtk.MessageDialog(parent=None, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CANCEL, message_format="Connecting to RDP...")
def dialog_box(self,text):
# Window = gtk.Window()
# Window.set_size_request(250, 100)
# Window.set_position(gtk.WIN_POS_CENTER)
# Window.connect("destroy", gtk.main_quit)
# window.set_title("Message dialogs")
md = gtk.MessageDialog(parent=None, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE, message_format=text)
md.run()
print "After run"
md.destroy()
def connect(self):
#rdp:cloud:qYSv3eQJYY:152.66.243.62:23037
if self.scheme == "rdp":
#print self.global_vars.pid
p = threading.Thread(target=self.connect_rdp, args=[self.global_vars])
p.start()
while self.global_vars.pid == 0:
time.sleep(1)
#print "Rdesktop pid: "+str(self.global_vars.pid)
#print self.box
return_value = self.box.run()
#print "Box return value: "+str(return_value)
if return_value != -5:
#p.terminate()
if self.global_vars.pid > 0:
os.kill(self.global_vars.pid, signal.SIGKILL)
#print "Join"
p.join()
elif self.scheme == "nx":
self.connect_nx()
elif self.scheme == "sshterm":
self.connect_sshterm()
else:
return False
def get_temporary_file(self):
tmpfile = tempfile.NamedTemporaryFile(mode='w', delete=False)
if not "_" in tmpfile.name:
return tmpfile
else:
tmpfile.close()
os.unlink(tmpfile.name)
return self.get_temporary_file()
def connect_sshterm(self):
try:
ssh_subcommand = 'sshpass -p "%(password)s" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %(username)s@%(host)s -p%(port)s' \
% {'username' : self.username, 'password' : self.password, 'host' : self.host, 'port' : self.port}
ssh_command = ["gnome-terminal", "-e", ssh_subcommand]
proc = subprocess.check_call(ssh_command, stdout = subprocess.PIPE)
except:
self.dialog_box("Unable to connect to host: "+self.host+" at port "+self.port)
def connect_rdp(self,global_vars):
rdp_command = ["rdesktop", "-khu", "-E", "-P", "-0", "-f", "-u", self.username, "-p", self.password, self.host+":"+self.port]
proc = subprocess.Popen(rdp_command, stdout = subprocess.PIPE)
global_vars.pid = proc.pid
proc.wait()
self.box.response(-5)
global_vars.pid = 0
def connect_nx(self):
#Generate temproary config
password_enc = nxkey.NXKeyGen(self.password).getEncrypted()
tmpfile = self.get_temporary_file()
nx_config = """
<!DOCTYPE NXClientSettings>
<NXClientSettings application="nxclient" version="1.3" >
<group name="Advanced" >
<option key="Cache size" value="16" />
<option key="Cache size on disk" value="64" />
<option key="Current keyboard" value="true" />
<option key="Custom keyboard layout" value="" />
<option key="Disable DirectDraw" value="false" />
<option key="Disable ZLIB stream compression" value="false" />
<option key="Disable deferred updates" value="false" />
<option key="Enable HTTP proxy" value="false" />
<option key="Enable SSL encryption" value="true" />
<option key="Enable response time optimisations" value="false" />
<option key="Grab keyboard" value="false" />
<option key="HTTP proxy host" value="" />
<option key="HTTP proxy port" value="8080" />
<option key="HTTP proxy username" value="" />
<option key="Remember HTTP proxy password" value="false" />
<option key="Restore cache" value="true" />
<option key="StreamCompression" value="" />
</group>
<group name="Environment" >
<option key="CUPSD path" value="/usr/sbin/cupsd" />
</group>
<group name="General" >
<option key="Automatic reconnect" value="true" />
<option key="Command line" value="" />
<option key="Custom Unix Desktop" value="console" />
<option key="Desktop" value="gnome" />
<option key="Disable SHM" value="false" />
<option key="Disable emulate shared pixmaps" value="false" />
<option key="Link speed" value="lan" />
<option key="Remember password" value="true" />
<option key="Resolution" value="fullscreen" />
<option key="Resolution height" value="600" />
<option key="Resolution width" value="800" />
<option key="Server host" value="%(host)s" />
<option key="Server port" value="%(port)s" />
<option key="Session" value="unix" />
<option key="Spread over monitors" value="false" />
<option key="Use default image encoding" value="0" />
<option key="Use render" value="true" />
<option key="Use taint" value="true" />
<option key="Virtual desktop" value="false" />
<option key="XAgent encoding" value="true" />
<option key="displaySaveOnExit" value="true" />
<option key="xdm broadcast port" value="177" />
<option key="xdm list host" value="localhost" />
<option key="xdm list port" value="177" />
<option key="xdm mode" value="server decide" />
<option key="xdm query host" value="localhost" />
<option key="xdm query port" value="177" />
</group>
<group name="Images" >
<option key="Disable JPEG Compression" value="0" />
<option key="Disable all image optimisations" value="false" />
<option key="Disable backingstore" value="false" />
<option key="Disable composite" value="false" />
<option key="Image Compression Type" value="3" />
<option key="Image Encoding Type" value="0" />
<option key="Image JPEG Encoding" value="false" />
<option key="JPEG Quality" value="6" />
<option key="RDP Image Encoding" value="3" />
<option key="RDP JPEG Quality" value="6" />
<option key="RDP optimization for low-bandwidth link" value="false" />
<option key="Reduce colors to" value="" />
<option key="Use PNG Compression" value="true" />
<option key="VNC JPEG Quality" value="6" />
<option key="VNC images compression" value="3" />
</group>
<group name="Login" >
<option key="Auth" value="%(password)s" />
<option key="Guest Mode" value="false" />
<option key="Guest password" value="" />
<option key="Guest username" value="" />
<option key="Login Method" value="nx" />
<option key="User" value="%(username)s" />
</group>
<group name="Services" >
<option key="Audio" value="false" />
<option key="IPPPort" value="631" />
<option key="IPPPrinting" value="false" />
<option key="Shares" value="false" />
</group>
<group name="VNC Session" >
<option key="Display" value="0" />
<option key="Remember" value="false" />
<option key="Server" value="" />
</group>
<group name="Windows Session" >
<option key="Application" value="" />
<option key="Authentication" value="2" />
<option key="Color Depth" value="8" />
<option key="Domain" value="" />
<option key="Image Cache" value="true" />
<option key="Password" value="EMPTY_PASSWORD" />
<option key="Remember" value="true" />
<option key="Run application" value="false" />
<option key="Server" value="" />
<option key="User" value="" />
</group>
<group name="share chosen" >
<option key="Share number" value="0" />
</group>
</NXClientSettings>
""" % {'username' : self.username, 'password' : password_enc, 'host' : self.host, 'port' : self.port}
tmpfile.write(nx_config)
tmpfile.close()
try:
subprocess.check_call(["/usr/NX/bin/nxclient", "--session", tmpfile.name])
except:
pass
os.unlink(tmpfile.name)
return
if __name__ == "__main__":
uri = sys.argv[1]
connection = RDP(uri)
connection.connect()
#!/usr/bin/python
import sys
import cloudgui
if __name__ == '__main__':
try:
uri = sys.argv[1]
except:
print "No URI presented!"
sys.exit()
rdp = cloudgui.rdp.RDP(uri)
rdp.connect()
from setuptools import setup, find_packages
setup(
name = "CloudGUI",
version = "0.3",
data_files = [('/usr/share/icons', ['cloud.svg']),
('/usr/share/applications', ['cloud.desktop'])],
include_package_data = True,
packages = ['cloudgui',],
scripts = ['cloud','rdp',],
)
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 sign in to comment