Commit 26dd59fd by Csók Tamás

client: windows connect method logging added

parent cf4478e8
...@@ -14,6 +14,7 @@ import glob ...@@ -14,6 +14,7 @@ import glob
import win32crypt import win32crypt
import binascii import binascii
import nxkey import nxkey
import logging
def connect(vm): def connect(vm):
...@@ -28,7 +29,10 @@ def connect(vm): ...@@ -28,7 +29,10 @@ def connect(vm):
vm.user -- Username used for the connection vm.user -- Username used for the connection
vm.password -- Password used for the connection vm.password -- Password used for the connection
""" """
logger = logging.getLogger()
logger.info('Connect methods started')
if vm.protocol == "SSH": if vm.protocol == "SSH":
logger.debug('SSH protocol received')
arguments = ("-ssh -P %(port)s -pw %(password)s" arguments = ("-ssh -P %(port)s -pw %(password)s"
" %(user)s@%(host)s" % { " %(user)s@%(host)s" % {
'port': vm.port, 'port': vm.port,
...@@ -36,10 +40,13 @@ def connect(vm): ...@@ -36,10 +40,13 @@ def connect(vm):
'user': vm.user, 'user': vm.user,
'host': vm.host}) 'host': vm.host})
directory = os.path.dirname(os.path.abspath(__file__)) directory = os.path.dirname(os.path.abspath(__file__))
logger.debug('Popen: %s\\putty.exe', directory)
logger.info('Determined arguments: %s', arguments)
subprocess.Popen("%(path)s\\putty.exe %(arguments)s" % { subprocess.Popen("%(path)s\\putty.exe %(arguments)s" % {
'path': directory, 'path': directory,
'arguments': arguments}, shell=True) 'arguments': arguments}, shell=True)
elif vm.protocol == "NX": elif vm.protocol == "NX":
logger.debug('NX protocol received')
listdir = os.path.expanduser("~\\.nx\\config\\*.nxs") listdir = os.path.expanduser("~\\.nx\\config\\*.nxs")
found = False found = False
server = "\"Server host\" value=\"%s\"" % vm.host server = "\"Server host\" value=\"%s\"" % vm.host
...@@ -49,8 +56,10 @@ def connect(vm): ...@@ -49,8 +56,10 @@ def connect(vm):
file = f.read() file = f.read()
if server in file and port in file: if server in file and port in file:
found = True found = True
logger.info('Config file found: %s', config_file)
break break
if not found: if not found:
logger.info('No config file found, creating new one')
config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"), config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"),
str(int(time.time() * 1000)), ".nxs") str(int(time.time() * 1000)), ".nxs")
password = nxkey.NXKeyGen(vm.password).getEncrypted() password = nxkey.NXKeyGen(vm.password).getEncrypted()
...@@ -59,8 +68,11 @@ def connect(vm): ...@@ -59,8 +68,11 @@ def connect(vm):
f = open(config_file, 'w') f = open(config_file, 'w')
f.write(config) f.write(config)
f.close() f.close()
logger.info('Config file created: %s', config_file)
logger.debug('Popen the config file: %s', config_file)
subprocess.Popen(config_file, shell=True) subprocess.Popen(config_file, shell=True)
elif vm.protocol == "RDP": elif vm.protocol == "RDP":
logger.debug('NX protocol received')
listdir = os.path.dirname(os.path.realpath(__file__)) + "\\.rdp\\*.rdp" listdir = os.path.dirname(os.path.realpath(__file__)) + "\\.rdp\\*.rdp"
found = False found = False
full_address = "full address:s:%s:%s" % (vm.host, vm.port) full_address = "full address:s:%s:%s" % (vm.host, vm.port)
...@@ -70,8 +82,10 @@ def connect(vm): ...@@ -70,8 +82,10 @@ def connect(vm):
file = f.read() file = f.read()
if full_address in file and user in file: if full_address in file and user in file:
found = True found = True
logger.info('Config file found: %s', config_file)
break break
if not found: if not found:
logger.info('No config file found, creating new one')
config_file = "%s%s%s" % ((os.path.dirname( config_file = "%s%s%s" % ((os.path.dirname(
os.path.realpath(__file__)) + "\\.rdp\\"), os.path.realpath(__file__)) + "\\.rdp\\"),
str(int(time.time() * 1000)), ".rdp") str(int(time.time() * 1000)), ".rdp")
...@@ -82,8 +96,10 @@ def connect(vm): ...@@ -82,8 +96,10 @@ def connect(vm):
f = open(config_file, 'w') f = open(config_file, 'w')
f.write(config) f.write(config)
f.close() f.close()
logger.info('Config file created: %s', config_file)
logger.debug('Popen the config file: %s', config_file)
subprocess.Popen(config_file, shell=True) subprocess.Popen(config_file, shell=True)
logger.info('Client finished working')
NX_template = """<!DOCTYPE NXClientSettings> NX_template = """<!DOCTYPE NXClientSettings>
<NXClientSettings application="nxclient" version="1.3" > <NXClientSettings application="nxclient" version="1.3" >
......
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