Commit ed03b793 by Belákovics Ádám

added multi user support (thx to szebi)

parent 402cfbde
...@@ -9,7 +9,9 @@ The Client job is to help the ease of use of the cloud system. ...@@ -9,7 +9,9 @@ The Client job is to help the ease of use of the cloud system.
import argparse import argparse
import logging import logging
import platform import platform
import tempfile
from time import gmtime, strftime from time import gmtime, strftime
from windowsclasses import ClientRegistry from windowsclasses import ClientRegistry
...@@ -49,8 +51,8 @@ def parse_arguments(): ...@@ -49,8 +51,8 @@ def parse_arguments():
help="Explicit location of the wanted logfile location and name", help="Explicit location of the wanted logfile location and name",
type=unicode, type=unicode,
default=("%(directory)s\\%(file)s" % { default=("%(directory)s\\%(file)s" % {
'directory': ClientRegistry.directory(), 'directory': tempfile.gettempdir(),
'file': 'client.log'})) 'file': 'circle_client.log'}))
args = parser.parse_args() args = parser.parse_args()
return args return args
......
...@@ -11,12 +11,13 @@ import binascii ...@@ -11,12 +11,13 @@ import binascii
import glob import glob
import locale import locale
import logging import logging
import nxkey
import os import os
import subprocess import subprocess
import time import time
import win32crypt import tempfile
import nxkey
import win32crypt
from windowsclasses import ClientRegistry from windowsclasses import ClientRegistry
...@@ -76,36 +77,27 @@ def connect(vm): ...@@ -76,36 +77,27 @@ def connect(vm):
subprocess.Popen((u'"%s"' % config_file).encode( subprocess.Popen((u'"%s"' % config_file).encode(
locale.getpreferredencoding()), shell=True) locale.getpreferredencoding()), shell=True)
elif vm.protocol == "RDP": elif vm.protocol == "RDP":
logger.info('RDP protocol received') logger.debug('RDP protocol received')
listdir = ClientRegistry.directory() + "\\.rdp\\*.rdp"
found = False
full_address = "full address:s:%s:%s" % (vm.host, vm.port) full_address = "full address:s:%s:%s" % (vm.host, vm.port)
user = "username:s:%s" % vm.user user = "username:s:%s" % vm.user
for config_file in glob.glob(listdir): config_file = "%s%s" % (
with open(config_file) as f: tempfile.gettempdir(),
file = f.read() "\\circle_" + vm.user + str(int(time.time() * 1000)) + ".rdp")
if full_address in file and user in file: logger.info('Creating config file %s' % config_file)
found = True password = binascii.hexlify(win32crypt.CryptProtectData(
logger.info('Config file found: %s', config_file) u"%s" % vm.password, u'psw', None, None, None, 0))
break config = RPD_template % {'USERNAME': vm.user, 'PASSWORD': password,
if not found: 'HOST': vm.host, 'PORT': vm.port}
logger.info('No config file found, creating new one') f = open(config_file, 'w')
config_file = "%s%s%s" % (( f.write(config)
ClientRegistry.directory() + "\\.rdp\\"), f.close()
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()
logger.info('Config file created: %s', config_file)
logger.debug('Popen the config file: %s', config_file) logger.debug('Popen the config file: %s', config_file)
subprocess.Popen((u'"%s"' % config_file).encode( subprocess.Popen((u'"%s"' % config_file).encode(
locale.getpreferredencoding()), shell=True) locale.getpreferredencoding()), shell=True).wait()
os.remove(config_file)
logger.info('Client finished working') 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" >
<group name="General" > <group name="General" >
...@@ -125,4 +117,5 @@ NX_template = """<!DOCTYPE NXClientSettings> ...@@ -125,4 +117,5 @@ NX_template = """<!DOCTYPE NXClientSettings>
RPD_template = """username:s:%(USERNAME)s RPD_template = """username:s:%(USERNAME)s
full address:s:%(HOST)s:%(PORT)s full address:s:%(HOST)s:%(PORT)s
authentication level:i:0
password 51:b:%(PASSWORD)s""" password 51:b:%(PASSWORD)s"""
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