Commit cbf7078e by Csók Tamás

fix style to better match pep8, solved some compatibility issues

parent 65959e4c
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# A cloudban létrehozott virtuális gépekhez történő kapcsolódást segítő program
##
"""
A cloudban létrehozott virtuális gépekhez történő kapcsolódást segítő
program
"""
import platform, argparse, sys, time
import platform
import argparse
import sys
import time
try:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
except ImporError:
pass
##
# Paraméterek átadására használt struktúra
# state A virtuális gép állapota, azt figyeljük, hogy fut-e
# protocol SSH, NX és RDP lehetséges
# host A virtuális gép címe
# port Ezen a porton csatlakozunk a virtuális géphez
# user Csatlakozáshoz használt név
# password Csatlakozáshoz használt jelszó
class Struct:
"""
Paraméterek átadására használt struktúra
Keyword arguments:
state -- A virtuális gép állapota, azt figyeljük, hogy fut-e
protocol -- SSH, NX és RDP lehetséges
host -- A virtuális gép címe
port -- Ezen a porton csatlakozunk a virtuális géphez
user -- Csatlakozáshoz használt név
password -- Csatlakozáshoz használt jelszó
"""
pass
##
# Argument parser, argparse modulon alapszik
# @return args
#
def pars_arguments():
parser = argparse.ArgumentParser();
parser.add_argument("uri", type=str, help="Specific schema handler", nargs='?', default=None)
def parse_arguments():
"""
Argument parser, argparse modulon alapszik
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"uri", type=str, help="Specific schema handler", nargs='?',
default=None)
parser.add_argument("-u", "--username", type=str)
parser.add_argument("-p", "--password", type=str)
parser.add_argument("-d", "--driver", help="Select webdriver. Aside from Firefox, you have to install first the proper driver.", \
type=str, choices=['firefox', 'chrome', 'ie', 'opera'], default="firefox")
parser.add_argument("-o", "--old", help="Use old interface", action="store_true")
args = parser.parse_args();
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str,
choices=['firefox', 'chrome', 'ie', 'opera'],
default="firefox")
parser.add_argument(
"-o", "--old", help="Use old interface", action="store_true")
args = parser.parse_args()
return args
class Browser:
##
# Browser inicializálás
# @param args Az args.driver paraméterrel meghatározhatjuk, melyik böngészőt akarjuk használni.
#
"""
Browser inicializálás
Keyword arguments:
@param args -- Az args.driver paraméterrel meghatározhatjuk,
melyik böngészőt akarjuk használni.
"""
def __init__(self, args):
self.args = args
if args.driver == "firefox":
......@@ -52,10 +78,11 @@ class Browser:
self.driver = webdriver.Opera()
self.driver.implicitly_wait(10)
##
# Címtáras beléptetés a parancssorban megadott paraméterek alapján
#
def login(self):
"""
Címtáras beléptetés a parancssorban megadott paraméterek
alapján
"""
driver = self.driver
args = self.args
if args.username is not None:
......@@ -65,13 +92,17 @@ class Browser:
driver.find_element_by_name("j_password").clear()
driver.find_element_by_name("j_password").send_keys(args.password)
if args.username is not None and args.password is not None:
driver.find_element_by_css_selector("input[type='submit']").click()
driver.find_element_by_css_selector(
"input[type='submit']").click()
##
# A régi webes felület használata
# @return vm Virtuális gép csatlakozásához szükséges paraméterek
#
def old_main(self):
"""
A régi webes felület használata
Keyword arguments:
@return vm -- Virtuális gép csatlakozásához szükséges
paraméterek
"""
vm = Struct()
driver = self.driver
driver.maximize_window()
......@@ -81,23 +112,36 @@ class Browser:
vm.state, vm.protocol = "", "NONE"
try:
while vm.state.upper()[:3] not in ("FUT", "RUN"):
element = WebDriverWait(driver, 7200).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.hidden-password.shown[type='text']")))
element = WebDriverWait(driver, 7200).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
"input.hidden-password.shown[type='text']")))
vm.password = element.get_attribute("value")
vm.state = driver.find_element_by_css_selector("#state > div > p").text
vm.protocol = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(1) > td").text
vm.host,vm.port = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(2) > td").text.split(':')
vm.user = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(4) > td").text
vm.state = driver.find_element_by_css_selector(
"#state > div > p").text
vm.protocol = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(1) > td").text
vm.host,vm.port = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(2) > td").text.split(':')
vm.user = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(4) > td").text
driver.find_element_by_css_selector("a[href*='/logout/']").click()
except:
print "Browser session timed out!"
raise
return vm
##
# Az új webes felület használata
# @return vm Virtuális gép csatlakozásához szükséges paraméterek
#
def main(self):
"""
Az új webes felület használata
Keyword arguments:
@return vm -- Virtuális gép csatlakozásához szükséges
paraméterek
"""
vm = Struct()
driver = self.driver
driver.maximize_window()
......@@ -107,10 +151,16 @@ class Browser:
vm.state, vm.protocol = "", "NONE"
try:
while vm.state.upper()[:3] not in ("FUT", "RUN"):
element = WebDriverWait(driver,7200).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#vm-details-pw-eye.icon-eye-close")))
vm.state = driver.find_element_by_css_selector("#vm-details-state > span").text
element = WebDriverWait(driver,7200).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
"#vm-details-pw-eye.fa.fa-eye-slash")))
vm.state = driver.find_element_by_css_selector(
"#vm-details-state > span").text
#cl: connection string converted to list
cl = driver.find_element_by_css_selector("#vm-details-connection-string").get_attribute("value").split()
cl = driver.find_element_by_css_selector(
"#vm-details-connection-string").get_attribute(
"value").split()
if cl[0] == "sshpass":
vm.protocol = "SSH"
vm.user, vm.host = cl[6].split("@")
......@@ -125,27 +175,26 @@ class Browser:
raise
return vm
##
# Főprogram
# beolvassuk a paramétereket
# megnyitjuk a kiválasztott böngészőben a weboldalt
# bejelentkezünk a címtárba
# kiválasztjuk a futtatni kívánt klienst
# kapcsolódunk a klienshez
def main():
"""
Főprogram
Job:
beolvassuk a paramétereket
megnyitjuk a kiválasztott böngészőben a weboldalt
bejelentkezünk a címtárba
kiválasztjuk a futtatni kívánt klienst
kapcsolódunk a klienshez
"""
try:
args = pars_arguments()
args = parse_arguments()
if args.uri is not None:
vm = Struct()
vm.protocol, vm.user, vm.password, vm.host, vm.port = args.uri.split(':',4)
vm.protocol,vm.user,vm.password,vm.host,vm.port = \
args.uri.split(':',4)
vm.protocol = vm.protocol.upper()
vm.state = "RUN"
else:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = Browser(args)
try:
if args.old:
......@@ -163,5 +212,7 @@ def main():
connect(vm)
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
......@@ -4,7 +4,14 @@
# Távoli klienshez csatlakozás windows OS alól
##
import sys, os, time, subprocess, glob, nxkey, win32crypt, binascii
import time
import os
import subprocess
import glob
import win32crypt
import binascii
import nxkey
##
# A távoli klienshez csatlakozás valósítja majd meg windows alól
# @param vm Paraméterek a csatlakozáshoz
......
......@@ -162,9 +162,9 @@ IF NOT "!output_on_screen!"=="False" (
goto loop
) else (
set test=%install_path:~0,-1%
call %running_directory%inPath test && (IF NOT "!output_on_screen!"=="False" (@echo %test% is already in PATH)) || (call %running_directory%addPath test & setx>nul PATH "%PATH%;%test%" & IF NOT "!output_on_screen!"=="False" ( @echo %test% set to local PATH))
call %running_directory%inPath test && (IF NOT "!output_on_screen!"=="False" (@echo %test% is already in PATH)) || (call %running_directory%addPath test & setx>nul PATH "%PATH%;%test%" /m & IF NOT "!output_on_screen!"=="False" ( @echo %test% set to PATH))
set test=%install_path%Scripts
call %running_directory%inPath test && (IF NOT "!output_on_screen!"=="False" (@echo %test% is already in PATH)) || (call %running_directory%addPath test & setx>nul PATH "%PATH%;%test%" & IF NOT "!output_on_screen!"=="False" ( @echo %test% set to local PATH))
call %running_directory%inPath test && (IF NOT "!output_on_screen!"=="False" (@echo %test% is already in PATH)) || (call %running_directory%addPath test & setx>nul PATH "%PATH%;%test%" /m & IF NOT "!output_on_screen!"=="False" ( @echo %test% set to PATH))
)
GOTO PIP_CHECK
......@@ -395,7 +395,7 @@ if "!browserToUse!"=="None" (
call :Split "%browser_path%" test
set myTest=!test:~0,-1!
rem Set that path in the PATH environment variable
call %running_directory%inPath myTest && (IF NOT "!output_on_screen!"=="False" ( @echo !myTest! is already in PATH)) || (call %running_directory%addPath myTest & setx>nul PATH "%PATH%;!myTest!" & IF NOT "!output_on_screen!"=="False" ( @echo !myTest! set to local PATH) )
call %running_directory%inPath myTest && (IF NOT "!output_on_screen!"=="False" ( @echo !myTest! is already in PATH)) || (call %running_directory%addPath myTest & setx>nul PATH "%PATH%;!myTest!" /m & IF NOT "!output_on_screen!"=="False" ( @echo !myTest! set to PATH) )
:install_driver
IF NOT "%install_selenium%"=="False" (
if NOT "!selenium_driver_name!"=="" (
......@@ -448,7 +448,7 @@ rem Create folder if needed and set it to PATH
IF NOT "!output_on_screen!"=="False" (
@echo Checking wheter ^'%install_location%^\^' exists already
)
call %running_directory%inPath install_location && (IF NOT "!output_on_screen!"=="False" ( @echo !install_location! is already in PATH)) || (call %running_directory%addPath install_location & setx>nul PATH "%PATH%;!install_location!" & IF NOT "!output_on_screen!"=="False" ( @echo !install_location! set to local PATH))
call %running_directory%inPath install_location && (IF NOT "!output_on_screen!"=="False" ( @echo !install_location! is already in PATH)) || (call %running_directory%addPath install_location & setx>nul PATH "%PATH%;!install_location!" /m & IF NOT "!output_on_screen!"=="False" ( @echo !install_location! set to PATH))
if not exist "%install_location%\" (
mkdir "%install_location%"
)
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Generating NoMachine NX scrambled key according to https://www.nomachine.com/AR01C00125
##
"""
Generating NoMachine NX scrambled key according to
https://www.nomachine.com/AR01C00125
"""
import sys
import random
import re
from xml.sax.saxutils import escape
##
# NXKeyGen class
# Creates NoMachine NX scrambled keys
#
class NXKeyGen:
"""
NXKeyGen class
Creates NoMachine NX scrambled keys
"""
numValidCharList = 85
dummyString = "{{{{"
##
# Initialize the class
# @param password Password that will be scrambled
#
def __init__(self, password):
"""
Initialize the class
Keyword arguments:
@param password -- Password that will be scrambled
"""
self.password = password
##
# Encrypt (scramble) the given password
# @return scrambleString Scrambled version of the original password
#
def getEncrypted(self):
"""
Encrypt (scramble) the given password
Keyword arguments:
@return scrambleString -- Scrambled version of the original
password
"""
return self.scrambleString(self.password)
##
# Valid character list
# @return validcharlist List of the valid characters
#
def getvalidCharList(self, pos):
"""
Valid character list
Keyword arguments:
@return validcharlist -- List of the valid characters
"""
validcharlist = [
"!", "#", "$", "%", "&", "(", ")", "*", "+", "-",
".", "0", "1", "2", "3", "4", "5", "6", "7", "8",
......@@ -47,11 +57,13 @@ class NXKeyGen:
]
return validcharlist[pos]
##
# Password encoder
# @return sPass Encoded password
#
def encodePassword(self, p):
"""
Password encoder
Keyword arguments:
@return sPass -- Encoded password
"""
sPass = ":"
sTmp = ""
if not p:
......@@ -64,12 +76,14 @@ class NXKeyGen:
sTmp = ""
return sPass
##
# Character position finder
# @param c Character that needs to be matched if valid
# @return i Place where the character is in the valid list
#
def findCharInList(self, c):
"""
Character position finder
Keyword arguments:
@param c -- Character that needs to be matched if valid
@return i -- Place where the character is in the valid list
"""
i = -1
for j in range(self.numValidCharList):
randchar = self.getvalidCharList(j);
......@@ -78,19 +92,23 @@ class NXKeyGen:
return i
return i
##
# Random valid character getter
# @return char Valid character placed 0-60 in the valid list
#
def getRandomValidCharFromList(self):
"""
Random valid character getter
Keyword arguments:
@return char -- Valid character placed 0-60 in the valid list
"""
return self.getvalidCharList(random.randint(0,60))
##
# Password scrambler
# @param s Password that needs to be scrambled
# @return sRet NoMachine NX scrambled password
#
def scrambleString(self, s):
"""
Password scrambler
Keyword arguments:
@param s -- Password that needs to be scrambled
@return sRet -- NoMachine NX scrambled password
"""
sRet = ""
if not s:
return s
......@@ -118,10 +136,10 @@ class NXKeyGen:
sRet = sRet + c2
return escape(sRet)
##
# Replace a character at a special position
#
def substr_replace(self,in_str,ch,pos,qt):
"""
Replace a character at a special position
"""
clist = list(in_str)
count = 0;
tmp_str = '';
......@@ -134,7 +152,6 @@ class NXKeyGen:
return tmp_str
if __name__ == "__main__":
NXPass = NXKeyGen(sys.argv[1])
print NXPass.password
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Pywin32 installer for CIRCLE client application
##
"""
Pywin32 installer for CIRCLE client application
"""
import os, sys, subprocess
import os
import sys
import subprocess
from nx_client_installer import DecideArchitecture
##
# Main program
# Install Pywin32 to the computer
#
def main():
"""
Main program
Job:
Install Pywin32 to the computer
"""
if sys.hexversion < 0x02060000:
print "Not a 2.6+ version Python is running, commencing update"
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\no_root_install.bat")
subprocess.Popen(
"%s\\no_root_install.bat" % os.path.dirname(
os.path.realpath(__file__)))
sys.exit(1)
else:
pywin32_version = str(219)
if sys.hexversion < 0x02070000:
if DecideArchitecture.Is64Windows():
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x64\\pywin32-"+pywin32_version+".win-amd64-py2.6.exe").wait()
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x86\\pywin32-"+pywin32_version+".win32-py2.6.exe").wait()
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
elif sys.hexversion < 0x02080000:
if DecideArchitecture.Is64Windows():
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x64\\pywin32-"+pywin32_version+".win-amd64-py2.7.exe").wait()
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x86\\pywin32-"+pywin32_version+".win32-py2.7.exe").wait()
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
print "Unsupported Python version is found!"
if __name__ == "__main__":
main()
\ No newline at end of file
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Windows icon installer for CIRCLE client application
##
"""
Windows icon installer for CIRCLE client application
"""
import os, sys, argparse, subprocess
if sys.hexversion > 0x02070000:
from collections import *
else:
from OrderedDict import *
import os
import argparse
import subprocess
import pythoncom
from win32com.shell import shell, shellcon
from nx_client_installer import DecideArchitecture, RegistryHandler, Struct
try:
from collections import *
except ImporError:
from OrderedDict import *
##
# Argument parser, based on argparse module
# @return args
#
def pars_arguments():
parser = argparse.ArgumentParser();
parser.add_argument("-d", "--driver", help="Select webdriver. Aside from Firefox, you have to install first the proper driver.", \
type=str, choices=['firefox', 'chrome', 'iexplore', 'opera'], default="firefox", required=False)
def parse_arguments():
"""
Argument parser, based on argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str, default="firefox",
required=False, choices=['firefox', 'chrome',
'iexplore', 'opera'])
if DecideArchitecture.Is64Windows():
local_default = DecideArchitecture.GetProgramFiles64()+"\\CIRCLE\\"
else:
local_default = DecideArchitecture.GetProgramFiles32()+"\\CIRCLE\\"
if not os.path.exists(local_default[:-1]) and os.path.exists(os.environ['APPDATA']+"\\CIRCLE"):
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
parser.add_argument("-l", "--location", help="Location of the client files in the system", default=local_default, required=False)
parser.add_argument("-r", "--remove", help="Remove installed files instead of creating them", action="store_true", required=False)
parser.add_argument("-u", "--url", help="Whether we installed and we want to use selenium or not", action="store_true", required=False)
parser.add_argument("-t", "--target", help="If this is an URL icon, where should it point", default="https://pc3.szgt.uni-miskolc.hu/", required=False)
args = parser.parse_args();
parser.add_argument(
"-l", "--location", help="Location of the client files in the system",
default=local_default, required=False)
parser.add_argument(
"-r", "--remove",
help="Remove installed files instead of creating them",
action="store_true", required=False)
parser.add_argument(
"-u", "--url",
help="Whether we installed and we want to use selenium or not",
action="store_true", required=False)
parser.add_argument(
"-t", "--target",
help="If this is an URL icon, where should it point",
default="https://pc3.szgt.uni-miskolc.hu/", required=False)
args = parser.parse_args()
return args
##
# Custom protocol register based on RegistryHandler module
# Can raise AttributeError on wrongly provided dictionary chain
# @param dict_chain OrderedDictionary chain of the registry tree
#
def custom_protocol_register(custom_protocol):
"""
Custom protocol register based on RegistryHandler module
Can raise AttributeError on wrongly provided dictionary chain
Keyword arguments:
@param dict_chain -- OrderedDictionary chain of the registry tree
"""
if not isinstance(custom_protocol, OrderedDict):
raise AttributeError
print "\t"+custom_protocol.iterkeys().next()
......@@ -53,14 +77,18 @@ def custom_protocol_register(custom_protocol):
except:
raise
##
# Main program
# read the parameters
# create a proper icon with the proper driver
# call the nx_client_installer
def main():
#try:
args = pars_arguments()
"""
Main program
Jobs:
read the parameters
create a proper icon with the proper driver (or delete)
call the nx_client_installer
"""
try:
args = parse_arguments()
shortcut = pythoncom.CoCreateInstance (
shell.CLSID_ShellLink,
None,
......@@ -75,7 +103,9 @@ def main():
if os.path.isfile("%s%s" % (location, ".url")):
os.remove("%s%s" % (location, ".url"))
else:
subprocess.call("python "+os.path.dirname(os.path.realpath(__file__))+"\\nx_client_installer.py")
subprocess.call(
"python %s\\nx_client_installer.py" % os.path.dirname(
os.path.realpath(__file__)))
if args.url:
location = os.path.join(desktop_path, "Cloud GUI.url")
shortcut = file(location, 'w')
......@@ -92,27 +122,44 @@ def main():
shortcut.SetArguments("-d opera")
shortcut.SetDescription ("Tool to use CIRCLE Cloud")
shortcut.SetIconLocation (args.location+"cloud.ico", 0)
desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
persist_file.Save (os.path.join (desktop_path, "Cloud GUI.lnk"), 0)
desktop_path = shell.SHGetFolderPath(
0, shellcon.CSIDL_DESKTOP, 0, 0)
persist_file = shortcut.QueryInterface(
pythoncom.IID_IPersistFile)
persist_file.Save(
os.path.join(desktop_path, "Cloud GUI.lnk"), 0)
print "Icon successfully created on desktop"
print "Creating custom URL protocol handlers"
try:
custom_ssh = OrderedDict([('ssh', "URL:CIRCLE-SSH Protocol"), ('ssh\\URL Protocol', ""),\
('ssh\\DefaultIcon', args.location+"cloud.ico"),\
('ssh\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_ssh = OrderedDict(
[('ssh', ["default", "URL:ssh Protocol", "URL Protocol", ""]),
('ssh\\URL Protocol', ""),
('ssh\\DefaultIcon', args.location+"cloud.ico"),
('ssh\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_ssh)
custom_rdp = OrderedDict([('rdp', "URL:CIRCLE-RDP Protocol"), ('rdp\\URL Protocol', ""),\
('rdp\\DefaultIcon', args.location+"cloud.ico"),\
('rdp\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_rdp = OrderedDict(
[('rdp', ["default", "URL:rdp Protocol", "URL Protocol", ""]),
('rdp\\URL Protocol', ""),
('rdp\\DefaultIcon', args.location+"cloud.ico"),
('rdp\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_rdp)
custom_nx = OrderedDict([('nx', "URL:CIRCLE-NX Protocol"), ('nx\\URL Protocol', ""),\
('nx\\DefaultIcon', args.location+"cloud.ico"),\
('nx\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_nx = OrderedDict(
[('nx', ["default", "URL:nx Protocol", "URL Protocol", ""]),
('nx\\URL Protocol', ""),
('nx\\DefaultIcon', args.location+"cloud.ico"),
('nx\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_nx)
except:
print "Error! URL Protocol handler installation aborted!"
#except:
# print "Unknown error occurred! Please contact the developers!"
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
\ No newline at end of file
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# A cloudban létrehozott virtuális gépekhez történő kapcsolódást segítő program
##
"""
A cloudban létrehozott virtuális gépekhez történő kapcsolódást segítő
program
"""
import platform, argparse, sys, time
import platform
import argparse
import sys
import time
try:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
except ImporError:
pass
##
# Paraméterek átadására használt struktúra
# state A virtuális gép állapota, azt figyeljük, hogy fut-e
# protocol SSH, NX és RDP lehetséges
# host A virtuális gép címe
# port Ezen a porton csatlakozunk a virtuális géphez
# user Csatlakozáshoz használt név
# password Csatlakozáshoz használt jelszó
class Struct:
"""
Paraméterek átadására használt struktúra
Keyword arguments:
state -- A virtuális gép állapota, azt figyeljük, hogy fut-e
protocol -- SSH, NX és RDP lehetséges
host -- A virtuális gép címe
port -- Ezen a porton csatlakozunk a virtuális géphez
user -- Csatlakozáshoz használt név
password -- Csatlakozáshoz használt jelszó
"""
pass
##
# Argument parser, argparse modulon alapszik
# @return args
#
def pars_arguments():
parser = argparse.ArgumentParser();
parser.add_argument("uri", type=str, help="Specific schema handler", nargs='?', default=None)
def parse_arguments():
"""
Argument parser, argparse modulon alapszik
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"uri", type=str, help="Specific schema handler", nargs='?',
default=None)
parser.add_argument("-u", "--username", type=str)
parser.add_argument("-p", "--password", type=str)
parser.add_argument("-d", "--driver", help="Select webdriver. Aside from Firefox, you have to install first the proper driver.", \
type=str, choices=['firefox', 'chrome', 'ie', 'opera'], default="firefox")
parser.add_argument("-o", "--old", help="Use old interface", action="store_true")
args = parser.parse_args();
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str,
choices=['firefox', 'chrome', 'ie', 'opera'],
default="firefox")
parser.add_argument(
"-o", "--old", help="Use old interface", action="store_true")
args = parser.parse_args()
return args
class Browser:
##
# Browser inicializálás
# @param args Az args.driver paraméterrel meghatározhatjuk, melyik böngészőt akarjuk használni.
#
"""
Browser inicializálás
Keyword arguments:
@param args -- Az args.driver paraméterrel meghatározhatjuk,
melyik böngészőt akarjuk használni.
"""
def __init__(self, args):
self.args = args
if args.driver == "firefox":
......@@ -52,10 +78,11 @@ class Browser:
self.driver = webdriver.Opera()
self.driver.implicitly_wait(10)
##
# Címtáras beléptetés a parancssorban megadott paraméterek alapján
#
def login(self):
"""
Címtáras beléptetés a parancssorban megadott paraméterek
alapján
"""
driver = self.driver
args = self.args
if args.username is not None:
......@@ -65,13 +92,17 @@ class Browser:
driver.find_element_by_name("j_password").clear()
driver.find_element_by_name("j_password").send_keys(args.password)
if args.username is not None and args.password is not None:
driver.find_element_by_css_selector("input[type='submit']").click()
driver.find_element_by_css_selector(
"input[type='submit']").click()
##
# A régi webes felület használata
# @return vm Virtuális gép csatlakozásához szükséges paraméterek
#
def old_main(self):
"""
A régi webes felület használata
Keyword arguments:
@return vm -- Virtuális gép csatlakozásához szükséges
paraméterek
"""
vm = Struct()
driver = self.driver
driver.maximize_window()
......@@ -81,23 +112,36 @@ class Browser:
vm.state, vm.protocol = "", "NONE"
try:
while vm.state.upper()[:3] not in ("FUT", "RUN"):
element = WebDriverWait(driver, 7200).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.hidden-password.shown[type='text']")))
element = WebDriverWait(driver, 7200).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
"input.hidden-password.shown[type='text']")))
vm.password = element.get_attribute("value")
vm.state = driver.find_element_by_css_selector("#state > div > p").text
vm.protocol = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(1) > td").text
vm.host,vm.port = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(2) > td").text.split(':')
vm.user = driver.find_element_by_css_selector("#vm-credentials > div > table > tbody > tr:nth-child(4) > td").text
vm.state = driver.find_element_by_css_selector(
"#state > div > p").text
vm.protocol = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(1) > td").text
vm.host,vm.port = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(2) > td").text.split(':')
vm.user = driver.find_element_by_css_selector(
"#vm-credentials > div > table > tbody > "+
"tr:nth-child(4) > td").text
driver.find_element_by_css_selector("a[href*='/logout/']").click()
except:
print "Browser session timed out!"
raise
return vm
##
# Az új webes felület használata
# @return vm Virtuális gép csatlakozásához szükséges paraméterek
#
def main(self):
"""
Az új webes felület használata
Keyword arguments:
@return vm -- Virtuális gép csatlakozásához szükséges
paraméterek
"""
vm = Struct()
driver = self.driver
driver.maximize_window()
......@@ -107,10 +151,16 @@ class Browser:
vm.state, vm.protocol = "", "NONE"
try:
while vm.state.upper()[:3] not in ("FUT", "RUN"):
element = WebDriverWait(driver,7200).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#vm-details-pw-eye.icon-eye-close")))
vm.state = driver.find_element_by_css_selector("#vm-details-state > span").text
element = WebDriverWait(driver,7200).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
"#vm-details-pw-eye.fa.fa-eye-slash")))
vm.state = driver.find_element_by_css_selector(
"#vm-details-state > span").text
#cl: connection string converted to list
cl = driver.find_element_by_css_selector("#vm-details-connection-string").get_attribute("value").split()
cl = driver.find_element_by_css_selector(
"#vm-details-connection-string").get_attribute(
"value").split()
if cl[0] == "sshpass":
vm.protocol = "SSH"
vm.user, vm.host = cl[6].split("@")
......@@ -125,27 +175,26 @@ class Browser:
raise
return vm
##
# Főprogram
# beolvassuk a paramétereket
# megnyitjuk a kiválasztott böngészőben a weboldalt
# bejelentkezünk a címtárba
# kiválasztjuk a futtatni kívánt klienst
# kapcsolódunk a klienshez
def main():
"""
Főprogram
Job:
beolvassuk a paramétereket
megnyitjuk a kiválasztott böngészőben a weboldalt
bejelentkezünk a címtárba
kiválasztjuk a futtatni kívánt klienst
kapcsolódunk a klienshez
"""
try:
args = pars_arguments()
args = parse_arguments()
if args.uri is not None:
vm = Struct()
vm.protocol, vm.user, vm.password, vm.host, vm.port = args.uri.split(':',4)
vm.protocol,vm.user,vm.password,vm.host,vm.port = \
args.uri.split(':',4)
vm.protocol = vm.protocol.upper()
vm.state = "RUN"
else:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = Browser(args)
try:
if args.old:
......@@ -163,5 +212,7 @@ def main():
connect(vm)
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
......@@ -4,7 +4,14 @@
# Távoli klienshez csatlakozás windows OS alól
##
import sys, os, time, subprocess, glob, nxkey, win32crypt, binascii
import time
import os
import subprocess
import glob
import win32crypt
import binascii
import nxkey
##
# A távoli klienshez csatlakozás valósítja majd meg windows alól
# @param vm Paraméterek a csatlakozáshoz
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Generating NoMachine NX scrambled key according to https://www.nomachine.com/AR01C00125
##
"""
Generating NoMachine NX scrambled key according to
https://www.nomachine.com/AR01C00125
"""
import sys
import random
import re
from xml.sax.saxutils import escape
##
# NXKeyGen class
# Creates NoMachine NX scrambled keys
#
class NXKeyGen:
"""
NXKeyGen class
Creates NoMachine NX scrambled keys
"""
numValidCharList = 85
dummyString = "{{{{"
##
# Initialize the class
# @param password Password that will be scrambled
#
def __init__(self, password):
"""
Initialize the class
Keyword arguments:
@param password -- Password that will be scrambled
"""
self.password = password
##
# Encrypt (scramble) the given password
# @return scrambleString Scrambled version of the original password
#
def getEncrypted(self):
"""
Encrypt (scramble) the given password
Keyword arguments:
@return scrambleString -- Scrambled version of the original
password
"""
return self.scrambleString(self.password)
##
# Valid character list
# @return validcharlist List of the valid characters
#
def getvalidCharList(self, pos):
"""
Valid character list
Keyword arguments:
@return validcharlist -- List of the valid characters
"""
validcharlist = [
"!", "#", "$", "%", "&", "(", ")", "*", "+", "-",
".", "0", "1", "2", "3", "4", "5", "6", "7", "8",
......@@ -47,11 +57,13 @@ class NXKeyGen:
]
return validcharlist[pos]
##
# Password encoder
# @return sPass Encoded password
#
def encodePassword(self, p):
"""
Password encoder
Keyword arguments:
@return sPass -- Encoded password
"""
sPass = ":"
sTmp = ""
if not p:
......@@ -64,12 +76,14 @@ class NXKeyGen:
sTmp = ""
return sPass
##
# Character position finder
# @param c Character that needs to be matched if valid
# @return i Place where the character is in the valid list
#
def findCharInList(self, c):
"""
Character position finder
Keyword arguments:
@param c -- Character that needs to be matched if valid
@return i -- Place where the character is in the valid list
"""
i = -1
for j in range(self.numValidCharList):
randchar = self.getvalidCharList(j);
......@@ -78,19 +92,23 @@ class NXKeyGen:
return i
return i
##
# Random valid character getter
# @return char Valid character placed 0-60 in the valid list
#
def getRandomValidCharFromList(self):
"""
Random valid character getter
Keyword arguments:
@return char -- Valid character placed 0-60 in the valid list
"""
return self.getvalidCharList(random.randint(0,60))
##
# Password scrambler
# @param s Password that needs to be scrambled
# @return sRet NoMachine NX scrambled password
#
def scrambleString(self, s):
"""
Password scrambler
Keyword arguments:
@param s -- Password that needs to be scrambled
@return sRet -- NoMachine NX scrambled password
"""
sRet = ""
if not s:
return s
......@@ -118,10 +136,10 @@ class NXKeyGen:
sRet = sRet + c2
return escape(sRet)
##
# Replace a character at a special position
#
def substr_replace(self,in_str,ch,pos,qt):
"""
Replace a character at a special position
"""
clist = list(in_str)
count = 0;
tmp_str = '';
......@@ -134,7 +152,6 @@ class NXKeyGen:
return tmp_str
if __name__ == "__main__":
NXPass = NXKeyGen(sys.argv[1])
print NXPass.password
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Pywin32 installer for CIRCLE client application
##
"""
Pywin32 installer for CIRCLE client application
"""
import os, sys, subprocess
import os
import sys
import subprocess
from nx_client_installer import DecideArchitecture
##
# Main program
# Install Pywin32 to the computer
#
def main():
"""
Main program
Job:
Install Pywin32 to the computer
"""
if sys.hexversion < 0x02060000:
print "Not a 2.6+ version Python is running, commencing update"
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\no_root_install.bat")
subprocess.Popen(
"%s\\no_root_install.bat" % os.path.dirname(
os.path.realpath(__file__)))
sys.exit(1)
else:
pywin32_version = str(219)
if sys.hexversion < 0x02070000:
if DecideArchitecture.Is64Windows():
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x64\\pywin32-"+pywin32_version+".win-amd64-py2.6.exe").wait()
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x86\\pywin32-"+pywin32_version+".win32-py2.6.exe").wait()
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
elif sys.hexversion < 0x02080000:
if DecideArchitecture.Is64Windows():
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x64\\pywin32-"+pywin32_version+".win-amd64-py2.7.exe").wait()
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(os.path.dirname(os.path.realpath(__file__))+"\\x86\\pywin32-"+pywin32_version+".win32-py2.7.exe").wait()
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
print "Unsupported Python version is found!"
if __name__ == "__main__":
main()
\ No newline at end of file
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Windows icon installer for CIRCLE client application
##
"""
Windows icon installer for CIRCLE client application
"""
import os, sys, argparse, subprocess
if sys.hexversion > 0x02070000:
from collections import *
else:
from OrderedDict import *
import os
import argparse
import subprocess
import pythoncom
from win32com.shell import shell, shellcon
from nx_client_installer import DecideArchitecture, RegistryHandler, Struct
try:
from collections import *
except ImporError:
from OrderedDict import *
##
# Argument parser, based on argparse module
# @return args
#
def pars_arguments():
parser = argparse.ArgumentParser();
parser.add_argument("-d", "--driver", help="Select webdriver. Aside from Firefox, you have to install first the proper driver.", \
type=str, choices=['firefox', 'chrome', 'iexplore', 'opera'], default="firefox", required=False)
def parse_arguments():
"""
Argument parser, based on argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str, default="firefox",
required=False, choices=['firefox', 'chrome',
'iexplore', 'opera'])
if DecideArchitecture.Is64Windows():
local_default = DecideArchitecture.GetProgramFiles64()+"\\CIRCLE\\"
else:
local_default = DecideArchitecture.GetProgramFiles32()+"\\CIRCLE\\"
if not os.path.exists(local_default[:-1]) and os.path.exists(os.environ['APPDATA']+"\\CIRCLE"):
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
parser.add_argument("-l", "--location", help="Location of the client files in the system", default=local_default, required=False)
parser.add_argument("-r", "--remove", help="Remove installed files instead of creating them", action="store_true", required=False)
parser.add_argument("-u", "--url", help="Whether we installed and we want to use selenium or not", action="store_true", required=False)
parser.add_argument("-t", "--target", help="If this is an URL icon, where should it point", default="https://pc3.szgt.uni-miskolc.hu/", required=False)
args = parser.parse_args();
parser.add_argument(
"-l", "--location", help="Location of the client files in the system",
default=local_default, required=False)
parser.add_argument(
"-r", "--remove",
help="Remove installed files instead of creating them",
action="store_true", required=False)
parser.add_argument(
"-u", "--url",
help="Whether we installed and we want to use selenium or not",
action="store_true", required=False)
parser.add_argument(
"-t", "--target",
help="If this is an URL icon, where should it point",
default="https://pc3.szgt.uni-miskolc.hu/", required=False)
args = parser.parse_args()
return args
##
# Custom protocol register based on RegistryHandler module
# Can raise AttributeError on wrongly provided dictionary chain
# @param dict_chain OrderedDictionary chain of the registry tree
#
def custom_protocol_register(custom_protocol):
"""
Custom protocol register based on RegistryHandler module
Can raise AttributeError on wrongly provided dictionary chain
Keyword arguments:
@param dict_chain -- OrderedDictionary chain of the registry tree
"""
if not isinstance(custom_protocol, OrderedDict):
raise AttributeError
print "\t"+custom_protocol.iterkeys().next()
......@@ -53,14 +77,18 @@ def custom_protocol_register(custom_protocol):
except:
raise
##
# Main program
# read the parameters
# create a proper icon with the proper driver
# call the nx_client_installer
def main():
#try:
args = pars_arguments()
"""
Main program
Jobs:
read the parameters
create a proper icon with the proper driver (or delete)
call the nx_client_installer
"""
try:
args = parse_arguments()
shortcut = pythoncom.CoCreateInstance (
shell.CLSID_ShellLink,
None,
......@@ -75,7 +103,9 @@ def main():
if os.path.isfile("%s%s" % (location, ".url")):
os.remove("%s%s" % (location, ".url"))
else:
subprocess.call("python "+os.path.dirname(os.path.realpath(__file__))+"\\nx_client_installer.py")
subprocess.call(
"python %s\\nx_client_installer.py" % os.path.dirname(
os.path.realpath(__file__)))
if args.url:
location = os.path.join(desktop_path, "Cloud GUI.url")
shortcut = file(location, 'w')
......@@ -92,27 +122,44 @@ def main():
shortcut.SetArguments("-d opera")
shortcut.SetDescription ("Tool to use CIRCLE Cloud")
shortcut.SetIconLocation (args.location+"cloud.ico", 0)
desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
persist_file.Save (os.path.join (desktop_path, "Cloud GUI.lnk"), 0)
desktop_path = shell.SHGetFolderPath(
0, shellcon.CSIDL_DESKTOP, 0, 0)
persist_file = shortcut.QueryInterface(
pythoncom.IID_IPersistFile)
persist_file.Save(
os.path.join(desktop_path, "Cloud GUI.lnk"), 0)
print "Icon successfully created on desktop"
print "Creating custom URL protocol handlers"
try:
custom_ssh = OrderedDict([('ssh', "URL:CIRCLE-SSH Protocol"), ('ssh\\URL Protocol', ""),\
('ssh\\DefaultIcon', args.location+"cloud.ico"),\
('ssh\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_ssh = OrderedDict(
[('ssh', ["default", "URL:ssh Protocol", "URL Protocol", ""]),
('ssh\\URL Protocol', ""),
('ssh\\DefaultIcon', args.location+"cloud.ico"),
('ssh\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_ssh)
custom_rdp = OrderedDict([('rdp', "URL:CIRCLE-RDP Protocol"), ('rdp\\URL Protocol', ""),\
('rdp\\DefaultIcon', args.location+"cloud.ico"),\
('rdp\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_rdp = OrderedDict(
[('rdp', ["default", "URL:rdp Protocol", "URL Protocol", ""]),
('rdp\\URL Protocol', ""),
('rdp\\DefaultIcon', args.location+"cloud.ico"),
('rdp\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_rdp)
custom_nx = OrderedDict([('nx', "URL:CIRCLE-NX Protocol"), ('nx\\URL Protocol', ""),\
('nx\\DefaultIcon', args.location+"cloud.ico"),\
('nx\\shell', {'open': {'command': "\"python.exe\" \""+args.location+"cloud.py\" \"%1\""}})])
custom_nx = OrderedDict(
[('nx', ["default", "URL:nx Protocol", "URL Protocol", ""]),
('nx\\URL Protocol', ""),
('nx\\DefaultIcon', args.location+"cloud.ico"),
('nx\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
custom_protocol_register(custom_nx)
except:
print "Error! URL Protocol handler installation aborted!"
#except:
# print "Unknown error occurred! Please contact the developers!"
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
\ No newline at end of file
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