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.forward import forward
|
||||
from uds.log import logger
|
||||
from uds import tools
|
||||
from uds import VERSION
|
||||
|
||||
@ -198,6 +199,7 @@ def done(data):
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger.debug('Initializing connector')
|
||||
# Initialize app
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
|
||||
@ -206,40 +208,50 @@ if __name__ == "__main__":
|
||||
QtCore.QCoreApplication.setApplicationName('UDS Connector')
|
||||
|
||||
if 'darwin' not in sys.platform:
|
||||
logger.debug('Mac OS *NOT* Detected')
|
||||
app.setStyle('plastique')
|
||||
|
||||
if six.PY3 is False:
|
||||
logger.debug('Fixing threaded execution of commands')
|
||||
import threading
|
||||
threading._DummyThread._Thread__stop = lambda x: 42
|
||||
|
||||
# First parameter must be url
|
||||
try:
|
||||
uri = sys.argv[1]
|
||||
logger.debug('URI: {}'.format(uri))
|
||||
if uri[:6] != 'uds://' and uri[:7] != 'udss://':
|
||||
raise Exception()
|
||||
|
||||
ssl = uri[3] == 's'
|
||||
host, UDSClient.ticket, UDSClient.scrambler = uri.split('//')[1].split('/')
|
||||
logger.debug('ssl: {}, host:{}, ticket:{}, scrambler:{}'.format(ssl, host, UDSClient.ticket, UDSClient.scrambler))
|
||||
|
||||
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)
|
||||
sys.exit(1)
|
||||
|
||||
# Setup REST api endpoint
|
||||
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'
|
||||
|
||||
try:
|
||||
logger.debug('Starting execution')
|
||||
win = UDSClient()
|
||||
win.show()
|
||||
win.start()
|
||||
|
||||
exitVal = app.exec_()
|
||||
logger.debug('Execution finished correctly')
|
||||
|
||||
except Exception as e:
|
||||
logger.exception('Got an exception executing client:')
|
||||
exitVal = 128
|
||||
QtGui.QMessageBox.critical(None, 'Error', six.text_type(e), QtGui.QMessageBox.Ok)
|
||||
|
||||
logger.debug('Exiting')
|
||||
sys.exit(exitVal)
|
||||
|
||||
# Build base REST
|
||||
|
@ -12,8 +12,7 @@ import threading
|
||||
import random
|
||||
import time
|
||||
|
||||
g_verbose = True
|
||||
|
||||
from .log import logger
|
||||
|
||||
class ForwardServer (SocketServer.ThreadingTCPServer):
|
||||
daemon_threads = True
|
||||
@ -30,16 +29,16 @@ class Handler (SocketServer.BaseRequestHandler):
|
||||
(self.chain_host, self.chain_port),
|
||||
self.request.getpeername())
|
||||
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,
|
||||
repr(e)))
|
||||
return
|
||||
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))
|
||||
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)))
|
||||
try:
|
||||
while self.event.is_set() is False:
|
||||
@ -62,7 +61,7 @@ class Handler (SocketServer.BaseRequestHandler):
|
||||
peername = self.request.getpeername()
|
||||
chan.close()
|
||||
self.request.close()
|
||||
verbose('Tunnel closed from %r' % (peername,))
|
||||
logger.debug('Tunnel closed from %r' % (peername,))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@ -71,12 +70,6 @@ class Handler (SocketServer.BaseRequestHandler):
|
||||
|
||||
self.thread.isConnected = False
|
||||
|
||||
|
||||
def verbose(s):
|
||||
if g_verbose:
|
||||
print s
|
||||
|
||||
|
||||
class ForwardThread(threading.Thread):
|
||||
status = 0 # Connecting
|
||||
|
||||
@ -104,7 +97,7 @@ class ForwardThread(threading.Thread):
|
||||
|
||||
def _timerFnc(self):
|
||||
self.timer = None
|
||||
verbose('Timer fnc: {}'.format(self.isConnected))
|
||||
logger.debug('Timer fnc: {}'.format(self.isConnected))
|
||||
self.stoppable = True
|
||||
if self.isConnected is False:
|
||||
self.stop()
|
||||
@ -114,12 +107,12 @@ class ForwardThread(threading.Thread):
|
||||
self.client.load_system_host_keys()
|
||||
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:
|
||||
self.client.connect(self.server, self.port, username=self.username, password=self.password, timeout=5)
|
||||
except Exception as e:
|
||||
verbose('Exception connecting: {}'.format(e))
|
||||
logger.exception('Exception connecting: ')
|
||||
self.status = 2 # Error
|
||||
return
|
||||
|
||||
@ -130,7 +123,7 @@ class ForwardThread(threading.Thread):
|
||||
event = self.stopEvent
|
||||
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.start()
|
||||
|
||||
@ -150,6 +143,7 @@ class ForwardThread(threading.Thread):
|
||||
if self.client is not None:
|
||||
self.client.close()
|
||||
except Exception:
|
||||
logger.exception('Exception stopping')
|
||||
pass
|
||||
|
||||
|
||||
@ -163,7 +157,7 @@ def forward(server, port, username, password, redirectHost, redirectPort, localP
|
||||
if localPort is None:
|
||||
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))
|
||||
|
||||
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