1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-08 21:18:00 +03:00

Advancing on thin client & thinstation

This commit is contained in:
Adolfo Gómez García 2017-05-31 15:34:50 +02:00
parent d1b6891ca7
commit f773cb5ecc
4 changed files with 58 additions and 18 deletions

View File

@ -32,10 +32,12 @@
from __future__ import unicode_literals
from uds import ui
from uds import browser
from uds.rest import RestRequest
from uds.forward import forward
from uds import VERSION
from uds.log import logger # @UnresolvedImport
from uds import tools
import six
import sys
@ -105,5 +107,22 @@ if __name__ == "__main__":
ui.message('UDS Client', 'UDS Client Version {}'.format(VERSION))
sys.exit(1)
RestRequest.restApiUrl = '{}://{}/rest/client'.format(['http', 'https'][ssl], host)
logger.debug('Setting request URL to {}'.format(RestRequest.restApiUrl))
rest = RestRequest('{}://{}/rest/client'.format(['http', 'https'][ssl], host))
logger.debug('Setting request URL to {}'.format(rest.restApiUrl))
# Main requests part
# First, get version
try:
res = rest.get('')['result']
if res['requiredVersion'] > VERSION:
ui.message("New UDS Client available", "A new uds version is needed in order to access this version of UDS. A browser will be openend for this download.")
webbrowser.open(res['downloadUrl'])
sys.exit(1)
# Now get ticket
res = rest.get('/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})
except KeyError as e:
logger.error('Got an exception access RESULT: {}'.format(e))
except Exception as e:
logger.error('Got an unexpected exception: {}'.format(e))

View File

@ -30,5 +30,29 @@
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
import random
import os
import tempfile
import string
import webbrowser
raise Exception('not available')
TEMPLATE = '''<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
<p>{message}<P>
</body>
</html>
'''
def _htmlFilename():
return os.path.join(tempfile.gettempdir(), ''.join([random.choice(string.ascii_lowercase) for i in range(22)]) + '.html')
def message(title, message):
filename = _htmlFilename()
with open(filename, 'w') as f:
f.write(TEMPLATE.format(title=title, message=message))
webbrowser.open('file://' + filename, new=0, autoraise=False)

View File

@ -36,32 +36,32 @@ import requests
from . import VERSION
import json
import osDetector
import six
import urllib
from .log import logger
class RestRequest(object):
restApiUrl = '' #
restApiUrl = ''
def __init__(self, url, params=None): # parent not used
def __init__(self, restURL): # parent not used
super(RestRequest, self).__init__()
# private
self.restApiUrl = restURL
def get(self, url, params=None):
url = self.restApiUrl + url
if params is not None:
url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v).encode('utf8'))) for k, v in params.iteritems())
self.url = RestRequest.restApiUrl + url
# connect asynchronous result, when a request finishes
def get(self):
try:
r = requests.get(self.url)
logger.debug('Requesting {}'.format(url))
r = requests.get(url, headers={'Content-type': 'application/json'})
if r.ok:
logger.debug('Request was OK. {}'.format(r.text))
data = json.loads(r.text)
else:
logger.error('Error requesting {}: {}, {}'.format(url, r.code. r.text))
raise Exception('Error {}: {}'.format(r.code, r.text))
except Exception as e:
data = {

View File

@ -34,10 +34,7 @@ from __future__ import unicode_literals
try:
import gtkui as theUI
except Exception:
try:
import browserui as theUI
except Exception:
import consoleui as theUI
import consoleui as theUI
def message(title, message):
theUI.message(title, message)