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