Commit 1fa0050b by Csók Tamás

client: pythonw.exe instead of python.exe

parent 2a754440
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
# Passes Python2.7's test suite and incorporates all the latest updates.
# flake8: noqa
try:
from thread import get_ident as _get_ident
......
......@@ -8,8 +8,6 @@ The Client job is to help the ease of use of the cloud system.
import platform
import argparse
import sys
import time
try:
from selenium import webdriver
from selenium.webdriver.common.by import By
......@@ -49,13 +47,14 @@ def parse_arguments():
parser.add_argument("-p", "--password", type=str)
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
help = "Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str,
choices=['firefox', 'chrome', 'ie', 'opera'],
default="firefox")
choices = ['firefox', 'chrome', 'ie', 'opera'],
default = "firefox")
args = parser.parse_args()
return args
class Browser:
"""
Browser initialisation
......@@ -92,7 +91,6 @@ class Browser:
driver.find_element_by_css_selector(
"input[type='submit']").click()
def main(self):
"""
Use of the https://cloud.bme.hu/
......@@ -142,7 +140,7 @@ def main():
args = parse_arguments()
if args.uri is not None:
vm = Struct()
vm.protocol,vm.user,vm.password,vm.host,vm.port = \
vm.protocol, vm.user, vm.password, vm.host, vm.port = \
args.uri.split(':',4)
vm.protocol = vm.protocol.upper()
vm.state = "RUN"
......
......@@ -29,8 +29,9 @@ def connect(vm):
vm.password -- Password used for the connection
"""
if vm.protocol == "SSH":
arguments = "-ssh -P %s -pw %s %s@%s" % (vm.port, vm.password, vm.user, vm.host)
subprocess.Popen("putty.exe "+arguments, shell = True)
arguments = ("-ssh -P %s -pw %s" % (vm.port, vm.password)
+ "%s@%s" % (vm.user, vm.host))
subprocess.Popen("putty.exe "+arguments, shell=True)
elif vm.protocol == "NX":
listdir = os.path.expanduser("~\\.nx\\config\\*.nxs")
found = False
......@@ -43,13 +44,15 @@ def connect(vm):
found = True
break
if not found:
config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"), str(int(time.time()*1000)), ".nxs")
config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"),
str(int(time.time()*1000)), ".nxs")
password = nxkey.NXKeyGen(vm.password).getEncrypted()
config = NX_template % {'USERNAME' : vm.user, 'PASSWORD' : password, 'HOST' : vm.host, 'PORT' : vm.port}
config = NX_template % {'USERNAME': vm.user, 'PASSWORD': password,
'HOST': vm.host, 'PORT': vm.port}
f = open(config_file, 'w')
f.write(config)
f.close()
subprocess.Popen(config_file, shell = True)
subprocess.Popen(config_file, shell=True)
elif vm.protocol == "RDP":
listdir = os.path.dirname(os.path.realpath(__file__))+"\\.rdp\\*.rdp"
found = False
......@@ -62,13 +65,17 @@ def connect(vm):
found = True
break
if not found:
config_file = "%s%s%s" % (os.path.dirname(os.path.realpath(__file__))+"\\.rdp\\", str(int(time.time()*1000)), ".rdp")
password = binascii.hexlify(win32crypt.CryptProtectData(u"%s" % vm.password,u'psw',None,None,None,0))
config = RPD_template % {'USERNAME' : vm.user, 'PASSWORD' : password, 'HOST' : vm.host, 'PORT' : vm.port}
config_file = "%s%s%s" % ((os.path.dirname(
os.path.realpath(__file__))+"\\.rdp\\"),
str(int(time.time()*1000)), ".rdp")
password = binascii.hexlify(win32crypt.CryptProtectData(
u"%s" % vm.password, u'psw', None, None, None, 0))
config = RPD_template % {'USERNAME': vm.user, 'PASSWORD': password,
'HOST': vm.host, 'PORT': vm.port}
f = open(config_file, 'w')
f.write(config)
f.close()
subprocess.Popen(config_file, shell = True)
subprocess.Popen(config_file, shell=True)
NX_template = """<!DOCTYPE NXClientSettings>
......
......@@ -18,6 +18,7 @@
#
# If you're wondering how this is created, the secret is
# "contrib/build-installer" from the pip repository.
# flake8: noqa
ZIPFILE = b"""
UEsDBBQAAAAIAHeDxEQMVWtseQwAAOokAAAPAAAAcGlwL19faW5pdF9fLnB5pRprb+M28rt/BTdp
......@@ -24,10 +24,10 @@ def parse_arguments():
parser = argparse.ArgumentParser()
if windowsclasses.DecideArchitecture.Is64Windows():
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
else:
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
......@@ -38,17 +38,17 @@ def parse_arguments():
args = parser.parse_args()
return args
def main():
try:
args = parse_arguments()
nx_install_location = None
while nx_install_location is None:
print "Checking whether NX Client for Windows is installed"
handler = windowsclasses.RegistryHandler()
try:
nx_install_location = handler.get_key_value(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"+
"Uninstall\\nxclient_is1",
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
+ "Uninstall\\nxclient_is1",
"InstallLocation", "key")
print ("NX Client for Windows is found at "
"'%s'" % nx_install_location)
......@@ -60,8 +60,8 @@ def main():
print "NX Client for Windows isn't installed on the system."
print "\tCommencing the install"
subprocess.Popen(os.path.dirname(
os.path.realpath(__file__))+
"\\nxclient-3.5.0-9.exe").wait()
os.path.realpath(__file__))
+ "\\nxclient-3.5.0-9.exe").wait()
except:
pass
......
......@@ -8,9 +8,9 @@ https://www.nomachine.com/AR01C00125
import sys
import random
import re
from xml.sax.saxutils import escape
class NXKeyGen:
"""
NXKeyGen class
......@@ -18,6 +18,7 @@ class NXKeyGen:
"""
numValidCharList = 85
dummyString = "{{{{"
def __init__(self, password):
"""
Initialize the class
......@@ -53,8 +54,7 @@ class NXKeyGen:
"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", "{", "|", "}"
]
"y", "z", "{", "|", "}"]
return validcharlist[pos]
def encodePassword(self, p):
......@@ -71,7 +71,7 @@ class NXKeyGen:
for i in range(len(p)):
c = p[i:i+1]
a = ord(c)
sTmp = str( a + i + 1) + ":"
sTmp = str(a + i + 1) + ":"
sPass += sTmp
sTmp = ""
return sPass
......@@ -86,7 +86,7 @@ class NXKeyGen:
"""
i = -1
for j in range(self.numValidCharList):
randchar = self.getvalidCharList(j);
randchar = self.getvalidCharList(j)
if randchar == c:
i = j
return i
......@@ -99,7 +99,7 @@ class NXKeyGen:
Keyword arguments:
@return char -- Valid character placed 0-60 in the valid list
"""
return self.getvalidCharList(random.randint(0,60))
return self.getvalidCharList(random.randint(0, 60))
def scrambleString(self, s):
"""
......@@ -124,13 +124,13 @@ class NXKeyGen:
l = k + len(sRet) - 2
sRet = app + sRet
for i1 in range(1, len(sRet)):
app2 = sRet[i1 : i1 + 1]
app2 = sRet[i1: i1 + 1]
j = self.findCharInList(app2)
if j == -1:
return sRet
i = (j + l * (i1 + 1)) % self.numValidCharList
car = self.getvalidCharList(i)
sRet = self.substr_replace(sRet,car,i1,1)
sRet = self.substr_replace(sRet, car, i1, 1)
c = (ord(self.getRandomValidCharFromList())) + 2
c2 = chr(c)
sRet = sRet + c2
......@@ -141,8 +141,8 @@ class NXKeyGen:
Replace a character at a special position
"""
clist = list(in_str)
count = 0;
tmp_str = '';
count = 0
tmp_str = ''
for key in clist:
if count != pos:
tmp_str += key
......@@ -156,4 +156,3 @@ if __name__ == "__main__":
NXPass = NXKeyGen(sys.argv[1])
print NXPass.password
print NXPass.getEncrypted()
......@@ -13,11 +13,9 @@ import shutil
from win32com.shell import shell, shellcon
import windowsclasses
try:
from collections import *
from collections import * # noqa
except ImportError:
from OrderedDict import *
from OrderedDict import * # noqa
def parse_arguments():
"""
......@@ -35,13 +33,13 @@ def parse_arguments():
'iexplore', 'opera'])
if windowsclasses.DecideArchitecture.Is64Windows():
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
else:
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
+"\\CIRCLE\\")
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
+ "\\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)
......@@ -60,6 +58,7 @@ def parse_arguments():
args = parser.parse_args()
return args
def custom_protocol_register(custom_protocol):
"""
Custom protocol register based on RegistryHandler module
......@@ -92,13 +91,13 @@ def main():
"""
try:
args = parse_arguments()
shortcut = pythoncom.CoCreateInstance (
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
desktop_path = shell.SHGetFolderPath (
desktop_path = shell.SHGetFolderPath(
0, shellcon.CSIDL_DESKTOP, 0, 0)
if args.remove:
location = os.path.join(desktop_path, "Cloud GUI")
......@@ -117,15 +116,15 @@ def main():
shortcut.write('URL='+args.target)
shortcut.close()
else:
shortcut.SetPath (args.location+"cloud.py")
shortcut.SetPath(args.location+"cloud.py")
if args.driver == "chrome":
shortcut.SetArguments("-d chrome")
elif args.driver == "iexplore":
shortcut.SetArguments("-d ie")
elif args.driver == "opera":
shortcut.SetArguments("-d opera")
shortcut.SetDescription ("Tool to use CIRCLE Cloud")
shortcut.SetIconLocation (args.location+"cloud.ico", 0)
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(
......@@ -137,28 +136,37 @@ def main():
print "Creating custom URL protocol handlers"
try:
custom_ssh = OrderedDict(
[('ssh', ["default", "URL:ssh Protocol", "URL Protocol", ""]),
[('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\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_ssh)
custom_rdp = OrderedDict(
[('rdp', ["default", "URL:rdp Protocol", "URL Protocol", ""]),
[('rdp', ["default",
"URL:rdp Protocol",
"URL Protocol",
""]),
('rdp\\URL Protocol', ""),
('rdp\\DefaultIcon', args.location+"cloud.ico"),
('rdp\\DefaultIcon', args.location + "cloud.ico"),
('rdp\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_rdp)
custom_nx = OrderedDict(
[('nx', ["default", "URL:nx Protocol", "URL Protocol", ""]),
[('nx', ["default",
"URL:nx Protocol",
"URL Protocol",
""]),
('nx\\URL Protocol', ""),
('nx\\DefaultIcon', args.location+"cloud.ico"),
('nx\\DefaultIcon', args.location + "cloud.ico"),
('nx\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_nx)
except:
print "Error! URL Protocol handler installation aborted!"
......
......@@ -11,11 +11,12 @@ Currently here:
import os
import argparse
import errno
from _winreg import *
from _winreg import * # noqa
try:
from collections import *
from collections import * # noqa
except ImporError:
from OrderedDict import *
from OrderedDict import * # noqa
def parse_arguments():
"""
......@@ -41,9 +42,11 @@ def parse_arguments():
args = parser.parse_args()
return args
def main():
return RegistryHandler(parse_arguments())
class Struct:
"""
Parameter bypassing struct
......@@ -59,7 +62,7 @@ class RegistryHandler:
differently (default)
"""
def __init__(self, args = None):
def __init__(self, args=None):
"""Initialise RegistryHandler
Keyword arguments:
......@@ -96,7 +99,7 @@ class RegistryHandler:
elif self.args.registry == "HKCC":
self.args.registry = HKEY_CURRENT_CONFIG
else:
#print "Non supported registry type"
# print "Non supported registry type"
raise AttributeError
def connect_registry(self):
......@@ -107,11 +110,11 @@ class RegistryHandler:
@return connected_registy -- Reference to the newly opened
registry
"""
return ConnectRegistry(None,self.args.registry)
return ConnectRegistry(None, self.args.registry)
def create_registry_from_dict_chain(
self, dict_chain, both = False, architect = KEY_WOW64_64KEY,
needed_rights = KEY_ALL_ACCESS):
self, dict_chain, both=False, architect=KEY_WOW64_64KEY,
needed_rights=KEY_ALL_ACCESS):
""""
Create registry key and value multilevel tree by chained
dictionaries.
......@@ -208,8 +211,8 @@ class RegistryHandler:
return [key, architect]
def get_key_values(
self, key_name, subkey_list, subroutine = False,
depth = "subkeys"):
self, key_name, subkey_list, subroutine=False,
depth="subkeys"):
"""
Getting registry subkeys value by it's key's name and subkeys
name
......@@ -243,9 +246,9 @@ class RegistryHandler:
key = key_and_architect[0]
architect = key_and_architect[1]
except KeyError:
#print "%s doesn't exist in the registry" % key_name
# print "%s doesn't exist in the registry" % key_name
raise LookupError
#print "%s found in the registry" % key_name
# print "%s found in the registry" % key_name
results = {}
if int_depth >= 1:
for i in xrange(0, QueryInfoKey(key)[0]-1):
......@@ -261,7 +264,7 @@ class RegistryHandler:
skey, subkey_name)[0]
except OSError as e:
if e.errno == errno.ENOENT:
#print ("%s doesn't exist in this" % subkey_name
# print ("%s doesn't exist in this" % subkey_name
# " subkey")
pass
skey.Close()
......@@ -273,12 +276,12 @@ class RegistryHandler:
pass
key.Close()
if len(results) != len(subkey_list):
#print "We are missing important variables"
# print "We are missing important variables"
raise LookupError
return results
def get_key_value(
self, key_name, subkey_name, subroutine = None, depth = None):
self, key_name, subkey_name, subroutine=None, depth=None):
"""
This is a wrapper for the get_key_values to be easier to use
for single subkeys.
......@@ -296,14 +299,14 @@ class RegistryHandler:
"""
try:
if subroutine is None:
return self.get_key_values(key_name,
[subkey_name])[subkey_name]
return self.get_key_values(
key_name, [subkey_name])[subkey_name]
elif depth is None:
return self.get_key_values(key_name, [subkey_name],
subroutine)[subkey_name]
return self.get_key_values(
key_name, [subkey_name], subroutine)[subkey_name]
else:
return self.get_key_values(key_name, [subkey_name],
subroutine, depth)[subkey_name]
return self.get_key_values(
key_name, [subkey_name], subroutine, depth)[subkey_name]
except:
raise
......@@ -313,15 +316,18 @@ class DecideArchitecture:
Helper class to get the true ProgramFiles directory.
This class doesn't depend on Phyton or Windows architecture.
"""
@staticmethod
def Is64Windows():
return 'PROGRAMFILES(X86)' in os.environ
@staticmethod
def GetProgramFiles32():
if DecideArchitecture.Is64Windows():
return os.environ['PROGRAMFILES(X86)']
else:
return os.environ['PROGRAMFILES']
@staticmethod
def GetProgramFiles64():
if DecideArchitecture.Is64Windows():
......
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
# Passes Python2.7's test suite and incorporates all the latest updates.
# flake8: noqa
try:
from thread import get_ident as _get_ident
......
......@@ -8,8 +8,6 @@ The Client job is to help the ease of use of the cloud system.
import platform
import argparse
import sys
import time
try:
from selenium import webdriver
from selenium.webdriver.common.by import By
......@@ -49,13 +47,14 @@ def parse_arguments():
parser.add_argument("-p", "--password", type=str)
parser.add_argument(
"-d", "--driver",
help="Select webdriver. Aside from Firefox, you have to install "+
help = "Select webdriver. Aside from Firefox, you have to install "+
"first the proper driver.", type=str,
choices=['firefox', 'chrome', 'ie', 'opera'],
default="firefox")
choices = ['firefox', 'chrome', 'ie', 'opera'],
default = "firefox")
args = parser.parse_args()
return args
class Browser:
"""
Browser initialisation
......@@ -92,7 +91,6 @@ class Browser:
driver.find_element_by_css_selector(
"input[type='submit']").click()
def main(self):
"""
Use of the https://cloud.bme.hu/
......@@ -142,7 +140,7 @@ def main():
args = parse_arguments()
if args.uri is not None:
vm = Struct()
vm.protocol,vm.user,vm.password,vm.host,vm.port = \
vm.protocol, vm.user, vm.password, vm.host, vm.port = \
args.uri.split(':',4)
vm.protocol = vm.protocol.upper()
vm.state = "RUN"
......
......@@ -29,8 +29,9 @@ def connect(vm):
vm.password -- Password used for the connection
"""
if vm.protocol == "SSH":
arguments = "-ssh -P %s -pw %s %s@%s" % (vm.port, vm.password, vm.user, vm.host)
subprocess.Popen("putty.exe "+arguments, shell = True)
arguments = ("-ssh -P %s -pw %s" % (vm.port, vm.password)
+ "%s@%s" % (vm.user, vm.host))
subprocess.Popen("putty.exe "+arguments, shell=True)
elif vm.protocol == "NX":
listdir = os.path.expanduser("~\\.nx\\config\\*.nxs")
found = False
......@@ -43,13 +44,15 @@ def connect(vm):
found = True
break
if not found:
config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"), str(int(time.time()*1000)), ".nxs")
config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"),
str(int(time.time()*1000)), ".nxs")
password = nxkey.NXKeyGen(vm.password).getEncrypted()
config = NX_template % {'USERNAME' : vm.user, 'PASSWORD' : password, 'HOST' : vm.host, 'PORT' : vm.port}
config = NX_template % {'USERNAME': vm.user, 'PASSWORD': password,
'HOST': vm.host, 'PORT': vm.port}
f = open(config_file, 'w')
f.write(config)
f.close()
subprocess.Popen(config_file, shell = True)
subprocess.Popen(config_file, shell=True)
elif vm.protocol == "RDP":
listdir = os.path.dirname(os.path.realpath(__file__))+"\\.rdp\\*.rdp"
found = False
......@@ -62,13 +65,17 @@ def connect(vm):
found = True
break
if not found:
config_file = "%s%s%s" % (os.path.dirname(os.path.realpath(__file__))+"\\.rdp\\", str(int(time.time()*1000)), ".rdp")
password = binascii.hexlify(win32crypt.CryptProtectData(u"%s" % vm.password,u'psw',None,None,None,0))
config = RPD_template % {'USERNAME' : vm.user, 'PASSWORD' : password, 'HOST' : vm.host, 'PORT' : vm.port}
config_file = "%s%s%s" % ((os.path.dirname(
os.path.realpath(__file__))+"\\.rdp\\"),
str(int(time.time()*1000)), ".rdp")
password = binascii.hexlify(win32crypt.CryptProtectData(
u"%s" % vm.password, u'psw', None, None, None, 0))
config = RPD_template % {'USERNAME': vm.user, 'PASSWORD': password,
'HOST': vm.host, 'PORT': vm.port}
f = open(config_file, 'w')
f.write(config)
f.close()
subprocess.Popen(config_file, shell = True)
subprocess.Popen(config_file, shell=True)
NX_template = """<!DOCTYPE NXClientSettings>
......
......@@ -18,6 +18,7 @@
#
# If you're wondering how this is created, the secret is
# "contrib/build-installer" from the pip repository.
# flake8: noqa
ZIPFILE = b"""
UEsDBBQAAAAIAHeDxEQMVWtseQwAAOokAAAPAAAAcGlwL19faW5pdF9fLnB5pRprb+M28rt/BTdp
......@@ -24,10 +24,10 @@ def parse_arguments():
parser = argparse.ArgumentParser()
if windowsclasses.DecideArchitecture.Is64Windows():
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
else:
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
......@@ -38,17 +38,17 @@ def parse_arguments():
args = parser.parse_args()
return args
def main():
try:
args = parse_arguments()
nx_install_location = None
while nx_install_location is None:
print "Checking whether NX Client for Windows is installed"
handler = windowsclasses.RegistryHandler()
try:
nx_install_location = handler.get_key_value(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"+
"Uninstall\\nxclient_is1",
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
+ "Uninstall\\nxclient_is1",
"InstallLocation", "key")
print ("NX Client for Windows is found at "
"'%s'" % nx_install_location)
......@@ -60,8 +60,8 @@ def main():
print "NX Client for Windows isn't installed on the system."
print "\tCommencing the install"
subprocess.Popen(os.path.dirname(
os.path.realpath(__file__))+
"\\nxclient-3.5.0-9.exe").wait()
os.path.realpath(__file__))
+ "\\nxclient-3.5.0-9.exe").wait()
except:
pass
......
......@@ -8,9 +8,9 @@ https://www.nomachine.com/AR01C00125
import sys
import random
import re
from xml.sax.saxutils import escape
class NXKeyGen:
"""
NXKeyGen class
......@@ -18,6 +18,7 @@ class NXKeyGen:
"""
numValidCharList = 85
dummyString = "{{{{"
def __init__(self, password):
"""
Initialize the class
......@@ -53,8 +54,7 @@ class NXKeyGen:
"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", "{", "|", "}"
]
"y", "z", "{", "|", "}"]
return validcharlist[pos]
def encodePassword(self, p):
......@@ -71,7 +71,7 @@ class NXKeyGen:
for i in range(len(p)):
c = p[i:i+1]
a = ord(c)
sTmp = str( a + i + 1) + ":"
sTmp = str(a + i + 1) + ":"
sPass += sTmp
sTmp = ""
return sPass
......@@ -86,7 +86,7 @@ class NXKeyGen:
"""
i = -1
for j in range(self.numValidCharList):
randchar = self.getvalidCharList(j);
randchar = self.getvalidCharList(j)
if randchar == c:
i = j
return i
......@@ -99,7 +99,7 @@ class NXKeyGen:
Keyword arguments:
@return char -- Valid character placed 0-60 in the valid list
"""
return self.getvalidCharList(random.randint(0,60))
return self.getvalidCharList(random.randint(0, 60))
def scrambleString(self, s):
"""
......@@ -124,13 +124,13 @@ class NXKeyGen:
l = k + len(sRet) - 2
sRet = app + sRet
for i1 in range(1, len(sRet)):
app2 = sRet[i1 : i1 + 1]
app2 = sRet[i1: i1 + 1]
j = self.findCharInList(app2)
if j == -1:
return sRet
i = (j + l * (i1 + 1)) % self.numValidCharList
car = self.getvalidCharList(i)
sRet = self.substr_replace(sRet,car,i1,1)
sRet = self.substr_replace(sRet, car, i1, 1)
c = (ord(self.getRandomValidCharFromList())) + 2
c2 = chr(c)
sRet = sRet + c2
......@@ -141,8 +141,8 @@ class NXKeyGen:
Replace a character at a special position
"""
clist = list(in_str)
count = 0;
tmp_str = '';
count = 0
tmp_str = ''
for key in clist:
if count != pos:
tmp_str += key
......@@ -156,4 +156,3 @@ if __name__ == "__main__":
NXPass = NXKeyGen(sys.argv[1])
print NXPass.password
print NXPass.getEncrypted()
......@@ -13,11 +13,9 @@ import shutil
from win32com.shell import shell, shellcon
import windowsclasses
try:
from collections import *
from collections import * # noqa
except ImportError:
from OrderedDict import *
from OrderedDict import * # noqa
def parse_arguments():
"""
......@@ -35,13 +33,13 @@ def parse_arguments():
'iexplore', 'opera'])
if windowsclasses.DecideArchitecture.Is64Windows():
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
+"\\CIRCLE\\")
+ "\\CIRCLE\\")
else:
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
+"\\CIRCLE\\")
if (not os.path.exists(local_default[:-1])
and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
local_default = os.environ['APPDATA']+"\\CIRCLE\\"
+ "\\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)
......@@ -60,6 +58,7 @@ def parse_arguments():
args = parser.parse_args()
return args
def custom_protocol_register(custom_protocol):
"""
Custom protocol register based on RegistryHandler module
......@@ -92,13 +91,13 @@ def main():
"""
try:
args = parse_arguments()
shortcut = pythoncom.CoCreateInstance (
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
desktop_path = shell.SHGetFolderPath (
desktop_path = shell.SHGetFolderPath(
0, shellcon.CSIDL_DESKTOP, 0, 0)
if args.remove:
location = os.path.join(desktop_path, "Cloud GUI")
......@@ -117,15 +116,15 @@ def main():
shortcut.write('URL='+args.target)
shortcut.close()
else:
shortcut.SetPath (args.location+"cloud.py")
shortcut.SetPath(args.location+"cloud.py")
if args.driver == "chrome":
shortcut.SetArguments("-d chrome")
elif args.driver == "iexplore":
shortcut.SetArguments("-d ie")
elif args.driver == "opera":
shortcut.SetArguments("-d opera")
shortcut.SetDescription ("Tool to use CIRCLE Cloud")
shortcut.SetIconLocation (args.location+"cloud.ico", 0)
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(
......@@ -137,28 +136,37 @@ def main():
print "Creating custom URL protocol handlers"
try:
custom_ssh = OrderedDict(
[('ssh', ["default", "URL:ssh Protocol", "URL Protocol", ""]),
[('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\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_ssh)
custom_rdp = OrderedDict(
[('rdp', ["default", "URL:rdp Protocol", "URL Protocol", ""]),
[('rdp', ["default",
"URL:rdp Protocol",
"URL Protocol",
""]),
('rdp\\URL Protocol', ""),
('rdp\\DefaultIcon', args.location+"cloud.ico"),
('rdp\\DefaultIcon', args.location + "cloud.ico"),
('rdp\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_rdp)
custom_nx = OrderedDict(
[('nx', ["default", "URL:nx Protocol", "URL Protocol", ""]),
[('nx', ["default",
"URL:nx Protocol",
"URL Protocol",
""]),
('nx\\URL Protocol', ""),
('nx\\DefaultIcon', args.location+"cloud.ico"),
('nx\\DefaultIcon', args.location + "cloud.ico"),
('nx\\shell', {'open': {
'command': "\"python.exe\" \"%s" % args.location+
"cloud.py\" \"%1\""}})])
'command': "\"pythonw.exe\" \"%s" % args.location
+ "cloud.py\" \"%1\""}})])
custom_protocol_register(custom_nx)
except:
print "Error! URL Protocol handler installation aborted!"
......
......@@ -11,11 +11,12 @@ Currently here:
import os
import argparse
import errno
from _winreg import *
from _winreg import * # noqa
try:
from collections import *
from collections import * # noqa
except ImporError:
from OrderedDict import *
from OrderedDict import * # noqa
def parse_arguments():
"""
......@@ -41,9 +42,11 @@ def parse_arguments():
args = parser.parse_args()
return args
def main():
return RegistryHandler(parse_arguments())
class Struct:
"""
Parameter bypassing struct
......@@ -59,7 +62,7 @@ class RegistryHandler:
differently (default)
"""
def __init__(self, args = None):
def __init__(self, args=None):
"""Initialise RegistryHandler
Keyword arguments:
......@@ -96,7 +99,7 @@ class RegistryHandler:
elif self.args.registry == "HKCC":
self.args.registry = HKEY_CURRENT_CONFIG
else:
#print "Non supported registry type"
# print "Non supported registry type"
raise AttributeError
def connect_registry(self):
......@@ -107,11 +110,11 @@ class RegistryHandler:
@return connected_registy -- Reference to the newly opened
registry
"""
return ConnectRegistry(None,self.args.registry)
return ConnectRegistry(None, self.args.registry)
def create_registry_from_dict_chain(
self, dict_chain, both = False, architect = KEY_WOW64_64KEY,
needed_rights = KEY_ALL_ACCESS):
self, dict_chain, both=False, architect=KEY_WOW64_64KEY,
needed_rights=KEY_ALL_ACCESS):
""""
Create registry key and value multilevel tree by chained
dictionaries.
......@@ -208,8 +211,8 @@ class RegistryHandler:
return [key, architect]
def get_key_values(
self, key_name, subkey_list, subroutine = False,
depth = "subkeys"):
self, key_name, subkey_list, subroutine=False,
depth="subkeys"):
"""
Getting registry subkeys value by it's key's name and subkeys
name
......@@ -243,9 +246,9 @@ class RegistryHandler:
key = key_and_architect[0]
architect = key_and_architect[1]
except KeyError:
#print "%s doesn't exist in the registry" % key_name
# print "%s doesn't exist in the registry" % key_name
raise LookupError
#print "%s found in the registry" % key_name
# print "%s found in the registry" % key_name
results = {}
if int_depth >= 1:
for i in xrange(0, QueryInfoKey(key)[0]-1):
......@@ -261,7 +264,7 @@ class RegistryHandler:
skey, subkey_name)[0]
except OSError as e:
if e.errno == errno.ENOENT:
#print ("%s doesn't exist in this" % subkey_name
# print ("%s doesn't exist in this" % subkey_name
# " subkey")
pass
skey.Close()
......@@ -273,12 +276,12 @@ class RegistryHandler:
pass
key.Close()
if len(results) != len(subkey_list):
#print "We are missing important variables"
# print "We are missing important variables"
raise LookupError
return results
def get_key_value(
self, key_name, subkey_name, subroutine = None, depth = None):
self, key_name, subkey_name, subroutine=None, depth=None):
"""
This is a wrapper for the get_key_values to be easier to use
for single subkeys.
......@@ -296,14 +299,14 @@ class RegistryHandler:
"""
try:
if subroutine is None:
return self.get_key_values(key_name,
[subkey_name])[subkey_name]
return self.get_key_values(
key_name, [subkey_name])[subkey_name]
elif depth is None:
return self.get_key_values(key_name, [subkey_name],
subroutine)[subkey_name]
return self.get_key_values(
key_name, [subkey_name], subroutine)[subkey_name]
else:
return self.get_key_values(key_name, [subkey_name],
subroutine, depth)[subkey_name]
return self.get_key_values(
key_name, [subkey_name], subroutine, depth)[subkey_name]
except:
raise
......@@ -313,15 +316,18 @@ class DecideArchitecture:
Helper class to get the true ProgramFiles directory.
This class doesn't depend on Phyton or Windows architecture.
"""
@staticmethod
def Is64Windows():
return 'PROGRAMFILES(X86)' in os.environ
@staticmethod
def GetProgramFiles32():
if DecideArchitecture.Is64Windows():
return os.environ['PROGRAMFILES(X86)']
else:
return os.environ['PROGRAMFILES']
@staticmethod
def GetProgramFiles64():
if DecideArchitecture.Is64Windows():
......
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