forked from shaba/openuds
Added logging capability to client, in windows, take a look at https://github.com/paramiko/paramiko/issues/613 because some issues on windows 32 bits
This commit is contained in:
parent
0187b94768
commit
a352059ddc
@ -38,6 +38,7 @@ import six
|
|||||||
|
|
||||||
from uds.rest import RestRequest
|
from uds.rest import RestRequest
|
||||||
from uds.forward import forward
|
from uds.forward import forward
|
||||||
|
from uds.log import logger
|
||||||
from uds import tools
|
from uds import tools
|
||||||
from uds import VERSION
|
from uds import VERSION
|
||||||
|
|
||||||
@ -198,6 +199,7 @@ def done(data):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
logger.debug('Initializing connector')
|
||||||
# Initialize app
|
# Initialize app
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|
||||||
@ -206,40 +208,50 @@ if __name__ == "__main__":
|
|||||||
QtCore.QCoreApplication.setApplicationName('UDS Connector')
|
QtCore.QCoreApplication.setApplicationName('UDS Connector')
|
||||||
|
|
||||||
if 'darwin' not in sys.platform:
|
if 'darwin' not in sys.platform:
|
||||||
|
logger.debug('Mac OS *NOT* Detected')
|
||||||
app.setStyle('plastique')
|
app.setStyle('plastique')
|
||||||
|
|
||||||
if six.PY3 is False:
|
if six.PY3 is False:
|
||||||
|
logger.debug('Fixing threaded execution of commands')
|
||||||
import threading
|
import threading
|
||||||
threading._DummyThread._Thread__stop = lambda x: 42
|
threading._DummyThread._Thread__stop = lambda x: 42
|
||||||
|
|
||||||
# First parameter must be url
|
# First parameter must be url
|
||||||
try:
|
try:
|
||||||
uri = sys.argv[1]
|
uri = sys.argv[1]
|
||||||
|
logger.debug('URI: {}'.format(uri))
|
||||||
if uri[:6] != 'uds://' and uri[:7] != 'udss://':
|
if uri[:6] != 'uds://' and uri[:7] != 'udss://':
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
ssl = uri[3] == 's'
|
ssl = uri[3] == 's'
|
||||||
host, UDSClient.ticket, UDSClient.scrambler = uri.split('//')[1].split('/')
|
host, UDSClient.ticket, UDSClient.scrambler = uri.split('//')[1].split('/')
|
||||||
|
logger.debug('ssl: {}, host:{}, ticket:{}, scrambler:{}'.format(ssl, host, UDSClient.ticket, UDSClient.scrambler))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
logger.debug('Detected execution without valid URI, exiting')
|
||||||
QtGui.QMessageBox.critical(None, 'Notice', 'This program is designed to be used by UDS', QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.critical(None, 'Notice', 'This program is designed to be used by UDS', QtGui.QMessageBox.Ok)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Setup REST api endpoint
|
# Setup REST api endpoint
|
||||||
RestRequest.restApiUrl = '{}://{}/rest/client'.format(['http', 'https'][ssl], host)
|
RestRequest.restApiUrl = '{}://{}/rest/client'.format(['http', 'https'][ssl], host)
|
||||||
|
logger.debug('Setting requert URL to {}'.format(RestRequest.restApiUrl))
|
||||||
# RestRequest.restApiUrl = 'https://172.27.0.1/rest/client'
|
# RestRequest.restApiUrl = 'https://172.27.0.1/rest/client'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Starting execution')
|
||||||
win = UDSClient()
|
win = UDSClient()
|
||||||
win.show()
|
win.show()
|
||||||
win.start()
|
win.start()
|
||||||
|
|
||||||
exitVal = app.exec_()
|
exitVal = app.exec_()
|
||||||
|
logger.debug('Execution finished correctly')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.exception('Got an exception executing client:')
|
||||||
exitVal = 128
|
exitVal = 128
|
||||||
QtGui.QMessageBox.critical(None, 'Error', six.text_type(e), QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.critical(None, 'Error', six.text_type(e), QtGui.QMessageBox.Ok)
|
||||||
|
|
||||||
|
logger.debug('Exiting')
|
||||||
sys.exit(exitVal)
|
sys.exit(exitVal)
|
||||||
|
|
||||||
# Build base REST
|
# Build base REST
|
||||||
|
@ -12,8 +12,7 @@ import threading
|
|||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
g_verbose = True
|
from .log import logger
|
||||||
|
|
||||||
|
|
||||||
class ForwardServer (SocketServer.ThreadingTCPServer):
|
class ForwardServer (SocketServer.ThreadingTCPServer):
|
||||||
daemon_threads = True
|
daemon_threads = True
|
||||||
@ -30,16 +29,16 @@ class Handler (SocketServer.BaseRequestHandler):
|
|||||||
(self.chain_host, self.chain_port),
|
(self.chain_host, self.chain_port),
|
||||||
self.request.getpeername())
|
self.request.getpeername())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
logger.exception('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
||||||
self.chain_port,
|
self.chain_port,
|
||||||
repr(e)))
|
repr(e)))
|
||||||
return
|
return
|
||||||
if chan is None:
|
if chan is None:
|
||||||
verbose('Incoming request to %s:%d was rejected by the SSH server.' %
|
logger.error('Incoming request to %s:%d was rejected by the SSH server.' %
|
||||||
(self.chain_host, self.chain_port))
|
(self.chain_host, self.chain_port))
|
||||||
return
|
return
|
||||||
|
|
||||||
verbose('Connected! Tunnel open %r -> %r -> %r' % (self.request.getpeername(),
|
logger.debug('Connected! Tunnel open %r -> %r -> %r' % (self.request.getpeername(),
|
||||||
chan.getpeername(), (self.chain_host, self.chain_port)))
|
chan.getpeername(), (self.chain_host, self.chain_port)))
|
||||||
try:
|
try:
|
||||||
while self.event.is_set() is False:
|
while self.event.is_set() is False:
|
||||||
@ -62,7 +61,7 @@ class Handler (SocketServer.BaseRequestHandler):
|
|||||||
peername = self.request.getpeername()
|
peername = self.request.getpeername()
|
||||||
chan.close()
|
chan.close()
|
||||||
self.request.close()
|
self.request.close()
|
||||||
verbose('Tunnel closed from %r' % (peername,))
|
logger.debug('Tunnel closed from %r' % (peername,))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -71,12 +70,6 @@ class Handler (SocketServer.BaseRequestHandler):
|
|||||||
|
|
||||||
self.thread.isConnected = False
|
self.thread.isConnected = False
|
||||||
|
|
||||||
|
|
||||||
def verbose(s):
|
|
||||||
if g_verbose:
|
|
||||||
print s
|
|
||||||
|
|
||||||
|
|
||||||
class ForwardThread(threading.Thread):
|
class ForwardThread(threading.Thread):
|
||||||
status = 0 # Connecting
|
status = 0 # Connecting
|
||||||
|
|
||||||
@ -104,7 +97,7 @@ class ForwardThread(threading.Thread):
|
|||||||
|
|
||||||
def _timerFnc(self):
|
def _timerFnc(self):
|
||||||
self.timer = None
|
self.timer = None
|
||||||
verbose('Timer fnc: {}'.format(self.isConnected))
|
logger.debug('Timer fnc: {}'.format(self.isConnected))
|
||||||
self.stoppable = True
|
self.stoppable = True
|
||||||
if self.isConnected is False:
|
if self.isConnected is False:
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -114,12 +107,12 @@ class ForwardThread(threading.Thread):
|
|||||||
self.client.load_system_host_keys()
|
self.client.load_system_host_keys()
|
||||||
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
|
||||||
verbose('Connecting to ssh host %s:%d ...' % (self.server, self.port))
|
logger.debug('Connecting to ssh host %s:%d ...' % (self.server, self.port))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.connect(self.server, self.port, username=self.username, password=self.password, timeout=5)
|
self.client.connect(self.server, self.port, username=self.username, password=self.password, timeout=5)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose('Exception connecting: {}'.format(e))
|
logger.exception('Exception connecting: ')
|
||||||
self.status = 2 # Error
|
self.status = 2 # Error
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -130,7 +123,7 @@ class ForwardThread(threading.Thread):
|
|||||||
event = self.stopEvent
|
event = self.stopEvent
|
||||||
thread = self
|
thread = self
|
||||||
|
|
||||||
verbose('Wait Time: {}'.format(self.waitTime))
|
logger.debug('Wait Time: {}'.format(self.waitTime))
|
||||||
self.timer = threading.Timer(self.waitTime, self._timerFnc)
|
self.timer = threading.Timer(self.waitTime, self._timerFnc)
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
@ -150,6 +143,7 @@ class ForwardThread(threading.Thread):
|
|||||||
if self.client is not None:
|
if self.client is not None:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
logger.exception('Exception stopping')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -163,7 +157,7 @@ def forward(server, port, username, password, redirectHost, redirectPort, localP
|
|||||||
if localPort is None:
|
if localPort is None:
|
||||||
localPort = random.randrange(40000, 50000)
|
localPort = random.randrange(40000, 50000)
|
||||||
|
|
||||||
verbose('Connecting to {}:{} using {}/{} redirecting to {}:{}, listening on 127.0.0.1:{}'.format(
|
logger.debug('Connecting to {}:{} using {}/{} redirecting to {}:{}, listening on 127.0.0.1:{}'.format(
|
||||||
server, port, username, password, redirectHost, redirectPort, localPort))
|
server, port, username, password, redirectHost, redirectPort, localPort))
|
||||||
|
|
||||||
ft = ForwardThread(server, port, username, password, localPort, redirectHost, redirectPort, waitTime)
|
ft = ForwardThread(server, port, username, password, localPort, redirectHost, redirectPort, waitTime)
|
||||||
|
45
client/src/uds/log.py
Normal file
45
client/src/uds/log.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014 Virtual Cable S.L.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
# are permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer in the documentation
|
||||||
|
# and/or other materials provided with the distribution.
|
||||||
|
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||||
|
# may be used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
'''
|
||||||
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
|
'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
filename=os.path.join(tempfile.gettempdir(), 'udsclient.log'),
|
||||||
|
filemode='a',
|
||||||
|
format='%(levelname)s %(asctime)s %(message)s',
|
||||||
|
level=logging.INFO
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger('udsclient')
|
Loading…
Reference in New Issue
Block a user