1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-24 02:04:09 +03:00

Merge remote-tracking branch 'origin/v1.9'

This commit is contained in:
Adolfo Gómez García 2015-11-16 12:45:12 +01:00
commit d94cc70eff
7 changed files with 93 additions and 24 deletions

View File

@ -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

View File

@ -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
View 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')

View File

@ -97,6 +97,9 @@ class Login(Handler):
else:
auth = Authenticator.objects.get(small_name=authSmallName)
if password == '':
password = 'xdaf44tgas4xd5ñasdłe4g€@#½|«ð2' # Extrange password if credential leaved empty
logger.debug('Auth obj: {0}'.format(auth))
user = authenticate(username, password, auth)
if user is None: # invalid credentials

View File

@ -129,9 +129,17 @@ class DeployedServiceRemover(Job):
if len(rems) > 0:
logger.debug('Found a deployed service marked for removal. Starting removal of {0}'.format(rems))
for ds in rems:
# Skips checking deployed services in maintenance mode
if ds.service.provider.maintenance_mode is False:
self.startRemovalOf(ds)
try:
# Skips checking deployed services in maintenance mode
if ds.service.provider.maintenance_mode is False:
self.startRemovalOf(ds)
except Exception as e1:
logger.error('Error removing {}: {}'.format(ds, e1))
try:
ds.delete()
except Exception as e2:
logger.error('Could not delete {}'.format(e2))
rems = DeployedService.objects.filter(state=State.REMOVING)[:10]
if len(rems) > 0:

View File

@ -72,7 +72,7 @@
{% endfor %}
<div class="form-group">
<input id="id_{{form.user.name}}" name="{{form.user.name}}" type="text" class="form-control" placeholder="{% trans 'username'|capfirst %}" autofocus required>
<input id="id_{{form.password.name}}" name="{{form.password.name}}" type="password" class="form-control" placeholder="{% trans 'password'|capfirst %}">
<input id="id_{{form.password.name}}" name="{{form.password.name}}" type="password" class="form-control" placeholder="{% trans 'password'|capfirst %}" required>
{{ form.authenticator }}
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit"><span class="fa fa-sign-in"></span> {% trans 'Sign in' %}</button>

View File

@ -34,6 +34,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext
from uds.core.auths.auth import webLogin, authenticate, authLogLogin, authLogLogout, getUDSCookie, webLoginRequired, webLogout
from uds.models import Authenticator
@ -48,7 +49,7 @@ import uds.web.errors as errors
import logging
logger = logging.getLogger(__name__)
__updated__ = '2015-05-12'
__updated__ = '2015-11-16'
def login(request, tag=None):
@ -100,14 +101,18 @@ def login(request, tag=None):
form.add_form_error('Too many authentication errors. User temporarily blocked.')
authLogLogin(request, authenticator, userName, 'Temporarily blocked')
else:
user = authenticate(userName, form.cleaned_data['password'], authenticator)
password = form.cleaned_data['password']
user = None
if password == '':
password = 'axd56adhg466jasd6q8sadñ€sáé--v'
user = authenticate(userName, password, authenticator)
logger.debug('User: {}'.format(user))
if user is None:
logger.debug("Invalid credentials for user {0}".format(userName))
tries += 1
cache.put(cacheKey, tries, GlobalConfig.LOGIN_BLOCK.getInt())
form.add_form_error('Invalid credentials')
form.add_form_error(ugettext('Invalid credentials'))
authLogLogin(request, authenticator, userName, 'Invalid credentials')
else:
logger.debug('User {} has logged in'.format(userName))
@ -118,6 +123,8 @@ def login(request, tag=None):
request.session['OS'] = os
authLogLogin(request, authenticator, user.name)
return response
else:
logger.info('Invalid form received')
else:
form = LoginForm(tag=tag)