1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-02-12 21:57:57 +03:00

added test to configuration tool

This commit is contained in:
Adolfo Gómez García 2014-10-10 10:24:00 +02:00
parent 01b47d128c
commit a38921975f
6 changed files with 91 additions and 39 deletions

View File

@ -34,9 +34,8 @@ from __future__ import unicode_literals
import sys
from PyQt4 import QtCore, QtGui
from store import checkPermissions
from store import readConfig
from store import writeConfig
from udsactor import store
from udsactor import REST
from setup_dialog_ui import Ui_UdsActorSetupDialog
@ -50,6 +49,9 @@ class MyForm(QtGui.QDialog):
self.ui.masterKey.setText(data['masterKey'])
self.ui.useSSl.setCurrentIndex(1 if data['ssl'] is True else 0)
def _getCfg(self):
return { 'host': unicode(self.ui.host.text()), 'masterKey': unicode(self.ui.masterKey.text()), 'ssl': self.ui.useSSl.currentIndex() == 1 }
def textChanged(self):
enableButtons = self.ui.host.text() != '' and self.ui.masterKey.text() != ''
self.ui.testButton.setEnabled(enableButtons)
@ -60,24 +62,30 @@ class MyForm(QtGui.QDialog):
self.close()
def testParameters(self):
pass
try:
cfg = self._getCfg()
api = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'], scrambledResponses=True)
api.test()
QtGui.QMessageBox.information(self, 'Test Passed', 'The test was executed successfully', QtGui.QMessageBox.Ok)
except Exception as e:
QtGui.QMessageBox.warning(self, 'Test Error', e.message.decode('windows-1250', 'ignore'), QtGui.QMessageBox.Ok)
def acceptAndSave(self):
data = { 'host': unicode(self.ui.host.text()), 'masterKey': unicode(self.ui.masterKey.text()), 'ssl': self.ui.useSSl.currentIndex() == 1 }
writeConfig(data)
cfg = self._getCfg()
store.writeConfig(cfg)
self.close()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
if checkPermissions() == False:
QtGui.QMessageBox.question(None, 'Notice', 'This Program must be executed as administrator', QtGui.QMessageBox.Ok)
if store.checkPermissions() == False:
QtGui.QMessageBox.critical(None, 'Notice', 'This Program must be executed as administrator', QtGui.QMessageBox.Ok)
sys.exit(1)
# Read configuration
data = readConfig()
cfg = store.readConfig()
myapp = MyForm(data)
myapp = MyForm(cfg)
myapp.show()
sys.exit(app.exec_())

View File

@ -33,17 +33,16 @@ from __future__ import unicode_literals
import win32serviceutil
import win32service
import win32api
import win32event
import pythoncom
import win32com.client
import servicemanager
from SENS import *
from store import readConfig
import REST
from windows_operations import *
from udsactor.windows.SENS import *
from udsactor import store
from udsactor import REST
from udsactor import operations
import socket
@ -74,36 +73,36 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
def reboot(self):
self.rebootRequested = True
def rename(self, name, user=None, oldPass=None, newPass=None):
hostName = getComputerName()
def rename(self, name, user=None, oldPassword=None, newPassword=None):
hostName = operations.getComputerName()
if hostName.lower() == name.lower():
servicemanager.LogInfoMsg('Computer name is now {}'.format(hostName))
r.setReady([(v.mac, v.ip) for v in getNetworkInfo()])
self.api.setReady([(v.mac, v.ip) for v in operations.getNetworkInfo()])
return
# Check for password change request for an user
if user is not None:
servicemanager.LogInfoMsg('Setting password for user {}'.format(user))
try:
changeUserPassword(user, oldPassword, newPassword)
operations.changeUserPassword(user, oldPassword, newPassword)
except Exception as e:
# We stop here without even renaming computer, because the process has failed
raise Exception('Could not change password for user {} (maybe invalid current password is configured at broker): {} '.format(unicode(e)))
raise Exception('Could not change password for user {} (maybe invalid current password is configured at broker): {} '.format(user, unicode(e)))
renameComputer(name)
operations.renameComputer(name)
# Reboot just after renaming
servicemanager.LogInfoMsg('Rebooting computer got activate new name {}'.format(name))
self.reboot()
def oneStepJoin(name, domain, ou, account, password):
def oneStepJoin(self, name, domain, ou, account, password):
pass
def multiStepJoin(self, name, domain, ou, account, password):
pass
def joinDomain(self, name, domain, ou, account, password):
ver = getWindowsVersion()
ver = operations.getWindowsVersion()
ver = ver[0]*10 + ver[1]
servicemanager.LogInfoMsg('Starting joining domain {} with name {} (detected operating version: {})'.format(domain, name, ver))
if ver >= 60: # Accepts one step joinDomain, also remember XP is no more supported by microsoft, but this also must works with it
@ -111,8 +110,6 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
else:
self.multiStepJoin(name, domain, ou, account, password)
def interactWithBroker(self):
'''
Returns True to continue to main loop, false to stop & exit service
@ -127,7 +124,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
counter = 0
while self.isAlive:
try:
netInfo = tuple(getNetworkInfo()) # getNetworkInfo is a generator function
netInfo = tuple(operations.getNetworkInfo()) # getNetworkInfo is a generator function
self.knownIps = dict(((i.mac, i.ip) for i in netInfo))
ids = ','.join([i.map for i in netInfo])
if ids == '':
@ -177,7 +174,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
if len(params) != 5:
servicemanager.LogErrorMsg('Got invalid parameters for domain message: {}'.format(params))
return False
self.joinDomain(parms[0], parms[1], parms[2], parms[3], parms[4])
self.joinDomain(params[0], params[1], params[2], params[3], params[4])
else:
servicemanager.LogErrorMsg('Unrecognized action sent from broker: {}'.format(data[0]))
return False # Stop running service
@ -192,11 +189,11 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
win32event.WaitForSingleObject(self.hWaitStop, 1000) # Wait a bit before next check
if self.rebootRequested:
reboot()
operations.reboot()
return False # Stops service
def checkIpsChanged(self):
netInfo = tuple(getNetworkInfo())
netInfo = tuple(operations.getNetworkInfo())
for i in netInfo:
if i.mac in self.knownIps and self.knownIps[i.mac] != i.ip: # If at least one ip has changed
servicemanager.LogInfoMsg('Notifying ip change to broker (mac {}, from {} to {})'.format(i.mac, self.knownIps[i.mac], i.ip))
@ -271,5 +268,5 @@ class UDSActorSvc(win32serviceutil.ServiceFramework):
if __name__ == '__main__':
cfg = readConfig()
cfg = store.readConfig()
win32serviceutil.HandleCommandLine(UDSActorSvc)

View File

@ -3,32 +3,33 @@ from __future__ import unicode_literals
from udsactor import operations
from udsactor import store
from store import readConfig
import REST
from udsactor import REST
cfg = readConfig()
cfg = store.readConfig()
print cfg
print "Intefaces: ", list(getNetworkInfo())
print "Joined Domain: ", getDomainName()
print "Intefaces: ", list(operations.getNetworkInfo())
print "Joined Domain: ", operations.getDomainName()
#renameComputer('win7-64')
#joinDomain('dom.dkmon.com', 'ou=pruebas_2,dc=dom,dc=dkmon,dc=com', 'administrador@dom.dkmon.com', 'Temporal2012', True)
#reboot()
r = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'], scrambledResponses=True)
print "Connected: {}".format(r.isConnected)
r.test()
try:
r.init('02:46:00:00:00:07')
except REST.UnmanagedHostError:
print 'Unmanaged host (confirmed)'
uuid = r.init('02:46:00:00:00:06')
print "Connected: {}".format(r.isConnected)
print 'uuid = {}'.format(uuid)
#print 'Login: {}'.format(r.login('test-user'))
#print 'Logout: {}'.format(r.logout('test-user'))
print r.information()
print r.setReady([(v.mac, v.ip) for v in getNetworkInfo()])
print r.setReady([(v.mac, v.ip) for v in operations.getNetworkInfo()])
print r.log(REST.ERROR, 'Test error message')

View File

@ -125,7 +125,7 @@ class Api(object):
r = r.json()
except requests.exceptions.ConnectionError as e:
raise ConnectionError(e.message.args[1].strerror)
raise ConnectionError(e.message.args[-1].strerror)
except Exception as e:
raise ConnectionError(unicode(e))
@ -140,6 +140,10 @@ class Api(object):
return r
@property
def isConnected(self):
return self.uuid is not None
def test(self):
url = self._getUrl('test', self.masterKey)
return self._request(url)['result']

View File

@ -0,0 +1,41 @@
# -*- 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 sys
if sys.platform == 'win32':
from udsactor.windows.store import *
else:
pass

View File

@ -36,11 +36,12 @@ import win32net
import win32security
import win32api
import win32con
import utils
import ctypes
from ctypes.wintypes import DWORD, LPCSTR, LPCWSTR
import sys
from udsactor import utils
def getErrorMessage(res=0):
msg = win32api.FormatMessage(res)
return msg.decode('windows-1250', 'ignore')