#import SOAPpy import mws #from SOAPpy.Types import faultType, voidType, simplify, booleanType #import mwsManager class Management(mws.mwsAuthentication,mws.mwsGeneral): version = "v1.0" author = "Magnus Agust Skulason, maggias@gmail.com" def installService(self, location, service, classname, receiptRequest): import mwsManager import mwsConstants # Check if service is installed managerObj = mwsManager.mwsManager() installedServices = managerObj.getInstalledService() serviceInstalled = False for row in installedServices: if row['servicename'] == service or row['classname'] == classname: serviceInstalled = True if serviceInstalled == False: # Fetch the files and save them to a temp location leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("installServiceUI") leto.addParameter("location",location) leto.addParameter("service",service) leto.addParameter("classname", classname) leto.addParameter("webservicehost", self.getWebserviceHost()) leto.addParameter("user", self.getUser()) leto.addParameter("receiptRequest", receiptRequest) mws.launchExternalThread(leto) return "Request sent" else: return "Service or class already installed" def installServiceUI(self, location, service, classname, webservicehost, user, receiptRequest): import sys import appuifw import mwsManager import os import mwsConstants import urllib import SOAPpy # Parse info about receipt location endpoint = receiptRequest['endpoint'] correlator = receiptRequest['correlator'] # Ask if user wishes to install the service try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to install service: %s in class: %s, from location: %s. Allow?' % (unicode(user), unicode(service), unicode(classname), unicode(location)) else: queryString = u'Incoming request to install service: %s in class: %s, from location: %s. Allow?' % (unicode(service), unicode(classname), unicode(location)) result = appuifw.query(queryString, 'query') if (result == True): classfile = location + "/modules/" + classname wsdlfile = location + "/wsdl/" + service + ".wsdl" tempclassfile = mwsConstants.tempservicefiles + "\\" + classname tempwsdlfile = mwsConstants.tempservicefiles + "\\" + service + ".wsdl" urllib.urlretrieve(classfile, tempclassfile) urllib.urlretrieve(wsdlfile, tempwsdlfile) # Move files from the temp location to the actual location # service file fin = open(mwsConstants.tempservicefiles + "\\" + classname, "r") classInstream = fin.read() fin.close() sourcefile = {'filename': classname, 'filedata': str(classInstream)} # wsdl file fin = open(mwsConstants.tempservicefiles + "\\" + service + ".wsdl", "r") wsdlInstream = fin.read() fin.close() wsdlfile = {'filename': service + ".wsdl", 'filedata': str(wsdlInstream)} # Delete temp location files os.remove(mwsConstants.tempservicefiles + "\\" + classname) os.remove(mwsConstants.tempservicefiles + "\\" + service + ".wsdl") managerObj.installservices(sourcefile, wsdlfile, webservicehost) appuifw.note(u'Service installed, restart web server for the changes to take effect.', 'info') receiptServer = SOAPpy.SOAPProxy(endpoint) receiptServer.getUserConfirmationResult("success", correlator) else: # Delete the files from the temp location os.remove(mwsConstants.tempservicefiles + "\\" + classname) os.remove(mwsConstants.tempservicefiles + "\\" + service + ".wsdl") appuifw.note(u'Service instal aborted', 'info') receiptServer = SOAPpy.SOAPProxy(endpoint) receiptServer.getUserConfirmationResult("declined", correlator) except Exception, e: print e appuifw.note(u'Error encountered while installing service.', 'error') receiptServer = SOAPpy.SOAPProxy(endpoint) receiptServer.getUserConfirmationResult("failed", correlator) sys.exit() def deleteService(self,service): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("deleteServiceUI") leto.addParameter("service",service) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def deleteServiceUI(self, service, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to delete service: %s. Allow?' % (unicode(user), unicode(service)) else: queryString = u'Incoming request to delete service: %s. Allow?' % unicode(service) result = appuifw.query(queryString, 'query') if (result == True): managerObj.deleteService(service) appuifw.note(u'Service deleted', 'info') except Exception, e: print e appuifw.note(u'Error encountered while deleting service.', 'error') sys.exit() def updateService(self, location, service, classname): import mwsManager import urllib import mwsConstants # Check if service is installed managerObj = mwsManager.mwsManager() installedServices = managerObj.getInstalledService() serviceInstalled = False for row in installedServices: if row['servicename'] == service or row['classname'] == classname: serviceInstalled = True if serviceInstalled == True: # Fetch the files and save them to a temp location classfile = location + "/modules/" + classname wsdlfile = location + "/wsdl/" + service + ".wsdl" tempclassfile = mwsConstants.tempservicefiles + "\\" + classname tempwsdlfile = mwsConstants.tempservicefiles + "\\" + service + ".wsdl" urllib.urlretrieve(classfile, tempclassfile) urllib.urlretrieve(wsdlfile, tempwsdlfile) leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("updateServiceUI") leto.addParameter("location",location) leto.addParameter("service",service) leto.addParameter("classname", classname) leto.addParameter("webservicehost", self.getWebserviceHost()) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" else: return "Service or class not already installed" def updateServiceUI(self, location, service, classname, webservicehost, user): import sys import appuifw import mwsManager import os import mwsConstants # Ask if user wishes to update the service try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to update service: %s in class: %s, from location: %s. Allow?' % (unicode(user), unicode(service), unicode(classname), unicode(location)) else: queryString = u'Incoming request to update service: %s in class: %s, from location: %s. Allow?' % (unicode(service), unicode(classname), unicode(location)) result = appuifw.query(queryString, 'query') if (result == True): # Delete the service managerObj.deleteService(service) # Move files from the temp location to the actual location # service file fin = open(mwsConstants.tempservicefiles + "\\" + classname, "r") classInstream = fin.read() fin.close() sourcefile = {'filename': classname, 'filedata': str(classInstream)} # wsdl file fin = open(mwsConstants.tempservicefiles + "\\" + service + ".wsdl", "r") wsdlInstream = fin.read() fin.close() wsdlfile = {'filename': service + ".wsdl", 'filedata': str(wsdlInstream)} managerObj.installservices(sourcefile, wsdlfile, webservicehost) appuifw.note(u'Service updated, restart web server for the changes to take effect.', 'info') else: # Delete the files from the temp location os.remove(mwsConstants.tempservicefiles + "\\" + classname) os.remove(mwsConstants.tempservicefiles + "\\" + service + ".wsdl") appuifw.note(u'Service update aborted', 'info') except Exception, e: print e appuifw.note(u'Error encountered while installing service.', 'error') sys.exit() def createUser(self,username,password): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("createUserUI") leto.addParameter("username",username) leto.addParameter("password",password) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def createUserUI(self,username,password, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to create user: %s. Allow?' % (unicode(user), username) else: queryString = u'Incoming request to create user: %s. Allow?' % username result = appuifw.query(queryString, 'query') if (result == True): managerObj.createUser(username,password,password) appuifw.note(u'User created', 'info') except Exception, e: #print e appuifw.note(u'Error encountered while creating user.', 'error') sys.exit() def deleteUser(self,username): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("deleteUserUI") leto.addParameter("username",username) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def deleteUserUI(self, username, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to delete user: %s. Allow?' % (unicode(user), username) else: queryString = u'Incoming request to delete user: %s. Allow?' % username result = appuifw.query(queryString, 'query') if (result == True): managerObj.deleteUser(username) appuifw.note(u'User deleted', 'info') except Exception, e: appuifw.note(u'Error encountered while deleting user.', 'error') sys.exit() def grantUserAccess(self,username,service,operation = ''): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("grantUserAccessUI") leto.addParameter("username",username) leto.addParameter("service",service) leto.addParameter("operation",operation) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def grantUserAccessUI(self,username,service,operation, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if operation == None or operation == '': if user != None and user != '': queryString = u'Incoming request from user: %s to grant user: %s access to service: %s. Allow?' % (unicode(user), username, service) else: queryString = u'Incoming request to grant user: %s access to service: %s. Allow?' % (username, service) result = appuifw.query(queryString, 'query') if (result == True): managerObj.grantUserAccessToService(username, service) appuifw.note(u'Access granted', 'info') else: if user != None and user != '': queryString = u'Incoming request from user: %s to grant user: %s access to operation: %s in service: %s. Allow?' % (unicode(user), username, operation, service) else: queryString = u'Incoming request to grant user: %s access to operation: %s in service: %s. Allow?' % (username, operation, service) result = appuifw.query(queryString, 'query') returnValue = "" if (result == True): managerObj.grantUserAccessToOperation(username, operation, service) appuifw.note(u'Access granted', 'info') except Exception, e: print e appuifw.note(u'Error encountered while granting access.', 'error') sys.exit() def deleteUserAccess(self,username,service,operation=''): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("deleteUserAccessUI") leto.addParameter("username",username) leto.addParameter("service",service) leto.addParameter("operation",operation) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def deleteUserAccessUI(self,username,service,operation, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if operation == None or operation == '': if user != None and user != '': queryString = u'Incoming request from user: %s to delete user: %s access to service: %s. Allow?' % (unicode(user), username, service) else: queryString = u'Incoming request to delete user: %s access to service: %s. Allow?' % (username, service) result = appuifw.query(queryString, 'query') if (result == True): managerObj.deleteUserAccessToService(username, service) appuifw.note(u'Access deleted', 'info') else: if user != None and user != '': queryString = u'Incoming request from user: %s to delete user: %s access to operation: %s in service: %s. Allow?' % (unicode(user), username, operation, service) else: queryString = u'Incoming request to delete user: %s access to operation: %s in service: %s. Allow?' % (username, operation, service) result = appuifw.query(queryString, 'query') returnValue = "" if (result == True): managerObj.deleteUserAccessToOperation(username, operation, service) appuifw.note(u'Access deleted', 'info') except Exception, e: print e appuifw.note(u'Error encountered while deleting access.', 'error') sys.exit() def changePassword(self,newPassword): import SOAPpy import mwsManager from SOAPpy.Types import faultType, voidType, simplify, booleanType if self.getUser() != None and self.getUser() != "": managerObj = mwsManager.mwsManager() managerObj.createUser(self.getUser(),newPassword,newPassword) return "Password changed" else: raise faultType("SOAP-ENV:Server","Operation needs to called with proper authentication.","") def checkIfUserExists(self,username): import mwsManager import SOAPpy from SOAPpy.Types import faultType, voidType, simplify, booleanType try: managerObj = mwsManager.mwsManager() return SOAPpy.booleanType(managerObj.checkIfUserExists(username)) except Exception, e: raise faultType("SOAP-ENV:Server","checkIfUserExists failed.",e) def getServicePolicy(self, service, operation = ''): pass def setServicePublic(self, service): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("setServicePublicUI") leto.addParameter("service",service) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def setServicePublicUI(self, service, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to set service: %s to public. Allow?' % (unicode(user), unicode(service)) else: queryString = u'Incoming request to set service: %s to public. Allow?' % unicode(service) result = appuifw.query(queryString, 'query') if (result == True): managerObj.setServicePublic(service) appuifw.note(u'Service set to public', 'info') except Exception, e: appuifw.note(u'Error encountered while setting service to public', 'error') sys.exit() def setOperationPublic(self,service,operation): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("setOperationPublicUI") leto.addParameter("service",service) leto.addParameter("operation",operation) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def setOperationPublicUI(self,service,operation,user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() #result = managerObj.getServiceAndOperationName(service, operation) if user != None and user != '': queryString = u'Incoming request from user: %s to set operation: %s in service: %s to public. Allow?' % (unicode(user), unicode(operation), unicode(service)) else: queryString = u'Incoming request to set operation: %s in service: %s to public. Allow?' % (unicode(operation), unicode(service)) result = appuifw.query(queryString, 'query') if (result == True): managerObj.setPublic(managerObj.getOperationId(service,operation)) appuifw.note(u'Operation set to public', 'info') except Exception, e: appuifw.note(u'Error encountered while setting service to private', 'error') sys.exit() def setServicePrivate(self, service): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("setServicePrivateUI") leto.addParameter("service",service) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def setServicePrivateUI(self, service, user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() if user != None and user != '': queryString = u'Incoming request from user: %s to set service: %s to private. Allow?' % (unicode(user), unicode(service)) else: queryString = u'Incoming request to set service: %s to private. Allow?' % unicode(service) result = appuifw.query(queryString, 'query') if (result == True): managerObj.setServicePrivate(service) appuifw.note(u'Service set to private', 'info') except Exception, e: appuifw.note(u'Error encountered while setting service to private', 'error') sys.exit() def setOperationPrivate(self,service,operation): leto = mws.launchExternalThreadObject() leto.setModule("Management") leto.setObject("Management") leto.setFunction("setOperationPrivateUI") leto.addParameter("service",service) leto.addParameter("operation",operation) leto.addParameter("user", self.getUser()) mws.launchExternalThread(leto) return "Request sent" def setOperationPrivateUI(self,service,operation,user): import sys import appuifw import mwsManager try: managerObj = mwsManager.mwsManager() #result = managerObj.getServiceAndOperationName(service, operation) if user != None and user != '': queryString = u'Incoming request from user: %s to set operation: %s in service: %s to private. Allow?' % (unicode(user), unicode(operation), unicode(service)) else: queryString = u'Incoming request to set operation: %s in service: %s to private. Allow?' % (unicode(operation), unicode(service)) result = appuifw.query(queryString, 'query') if (result == True): print "before calling getOperationId" operationId = managerObj.getOperationId(service,operation) print operationId managerObj.setPrivate(operationId) appuifw.note(u'Operation set to private', 'info') except Exception, e: print e appuifw.note(u'Error encountered while setting service to private', 'error') sys.exit() def getUsers(self): import mwsManager managerObj = mwsManager.mwsManager() return managerObj.getUsers() def getInstalledServices(self): import mwsManager managerObj = mwsManager.mwsManager() return managerObj.getInstalledService() def getInstalledOperations(self,services): import mwsManager managerObj = mwsManager.mwsManager() return managerObj.getInstalledOperations(services)