示例#1
0
 def _get_env_var_from_java(name):
     name = name if isinstance(name, basestring) else unic(name)
     value_set_before_execution = System.getenv(name)
     if value_set_before_execution is None:
         return None
     current_value = String(os.environ[name]).toString()
     if value_set_before_execution != current_value:
         return None
     return value_set_before_execution
示例#2
0
 def _get_env_var_from_java(name):
     name = name if isinstance(name, basestring) else unic(name)
     value_set_before_execution = System.getenv(name)
     if value_set_before_execution is None:
         return None
     current_value = String(os.environ[name]).toString()
     if value_set_before_execution != current_value:
         return None
     return value_set_before_execution
示例#3
0
def getCmd():
    classPath = System.getProperties().get('java.class.path').split(':')
    cmd = System.getenv("pgm")
    if cmd == None:
        jarPath = classPath[1]
        print jarPath
        dir = os.path.dirname(jarPath)
        dir = os.path.dirname(dir)
        print dir
        cmd = os.path.join(dir, 'nmrfxs')
    return cmd
示例#4
0
def tts_converter(content):
    LOG.debug(u"start:\n{}".format(content).decode('utf-8'))
    
    # Get the file object for the appropriate prefix sound and if the content
    # always changes, then don't save the file (recycle it)
    openhab_conf = System.getenv("OPENHAB_CONF")
    alert_prefix = File.separator.join([openhab_conf, "html", "TTS", "Alert_Prefix.mp3"])
    recycled = False
    if "Weather Alert:" in content:
        alert_prefix = File.separator.join([openhab_conf, "html", "TTS", "Alert_Weather.mp3"])
        recycled = True
    elif any(alert_type in content for alert_type in FLITE_TTS_CONFIGURATION["recycle"]):
        recycled = True
    file_name = "recycled.wav"
    if not recycled:
        # Since the file is being saved, truncate the filename to 150 allowed characters
        file_name = re.sub("[^a-zA-Z0-9_.-]", "", content)
        if len(file_name) > 149:
            file_name = file_name[0:149]
        file_name = "{}.wav".format(file_name)
    
    # Substitute text to help TTS pronounce some words
    content_scrubbed = content
    for key, value in FLITE_TTS_CONFIGURATION["substitutions"].items():
        content_scrubbed = content_scrubbed.replace(key, value)
    
    # Set paths and files, creating them if they do not exist
    voice = File(FLITE_TTS_CONFIGURATION["path_to_voice"]).getName()
    directory_path_name = File.separator.join([openhab_conf, "html", "TTS", voice])
    directory_path = File(directory_path_name)
    if not directory_path.exists():
        directory_path.mkdir()
    file_path_name = File.separator.join([directory_path_name, file_name])
    file_path = File(file_path_name.replace(".wav", ".mp3"))
    
    # If it does not yet exist, generate the TTS
    if recycled or not file_path.exists():
        Exec.executeCommandLine(u"{}@@-voice@@{}@@-t@@{}@@-o@@{}".format(FLITE_TTS_CONFIGURATION["path_to_flite"], FLITE_TTS_CONFIGURATION["path_to_voice"], content_scrubbed, file_path_name), 60000)
        Exec.executeCommandLine(u"{}@@-y@@-i@@{}@@-af@@volume=10, highpass=f=500, lowpass=f=3000@@{}".format(FLITE_TTS_CONFIGURATION["path_to_ffmpeg"], file_path_name, file_path_name.replace(".wav", ".mp3")), 60000)
        Exec.executeCommandLine(u"{} -y -i \"concat:{}|{}\" -c copy {}".format(FLITE_TTS_CONFIGURATION["path_to_ffmpeg"], alert_prefix, file_path_name.replace(".wav", ".mp3"), file_path_name.replace(".wav", ".combined.mp3")), 60000)
    
    # Create the URL used in the PlayURI
    result = "http://{}:{}/static/TTS/{}/{}".format(HOST_PORT_CONFIGURATION.get("openhab").get("host"), HOST_PORT_CONFIGURATION.get("openhab").get("port"), voice, file_name.replace(".wav", ".combined.mp3"))
    LOG.debug(u"complete:\n{}".format(content).decode('utf-8'))
    return result
示例#5
0
from java.io import File, PrintWriter, BufferedWriter, FileWriter, PrintStream
from java.lang import System
from java.math import BigInteger
from org.zamia import ERManager, FSCache, SourceFile, SourceLocation, ZamiaException, ZamiaProject, ZamiaLogger, ExceptionLogger, Toplevel, ToplevelPath
from org.zamia.analysis import SourceLocation2IG, SourceLocation2AST
from org.zamia.analysis.ig import IGReferencesSearch
from org.zamia.analysis.ast import ASTDeclarationSearch, ASTReferencesSearch
from org.zamia.vhdl.ast import DMUID, AST2DOT
from org.zamia.instgraph import IG2DOT, IGOperationObject
from org.zamia.instgraph.sim.ref import IGSimRef
from org.zamia.rtl import RTLVisualGraphContentProvider, RTLVisualGraphLabelProvider, RTLVisualGraphSelectionProvider
from org.zamia.util import PathName, FileUtils
from org.zamia.vg import VGLayout, VGGCSVG
import sys
sys.path.append(System.getenv().get("PYTHONPATH"))

import os

logger = ZamiaLogger.getInstance()
el = ExceptionLogger.getInstance()


def printf(format, *args):
    ##    sys.stdout.write(format % args)
    logger.info(format, args)


def help():
    print "zamiaCAD builtin python functions:"
    print "=================================="
    print ""
示例#6
0
文件: boot.py 项目: crwulff/zamiacad
from java.io import File, PrintWriter, BufferedWriter, FileWriter, PrintStream
from java.lang import System
from java.math import BigInteger
from org.zamia import ERManager, FSCache, SourceFile, SourceLocation, ZamiaException, ZamiaProject, ZamiaLogger, ExceptionLogger, Toplevel, ToplevelPath
from org.zamia.analysis import SourceLocation2IG, SourceLocation2AST
from org.zamia.analysis.ig import IGReferencesSearch
from org.zamia.analysis.ast import ASTDeclarationSearch, ASTReferencesSearch
from org.zamia.vhdl.ast import DMUID,AST2DOT
from org.zamia.instgraph import IG2DOT, IGOperationObject
from org.zamia.instgraph.sim.ref import IGSimRef
from org.zamia.rtl import RTLVisualGraphContentProvider,RTLVisualGraphLabelProvider,RTLVisualGraphSelectionProvider
from org.zamia.util import PathName, FileUtils
from org.zamia.vg import VGLayout, VGGCSVG
import sys
sys.path.append(System.getenv().get("PYTHONPATH"))

import os

logger = ZamiaLogger.getInstance()
el = ExceptionLogger.getInstance()

def printf(format, *args):
##    sys.stdout.write(format % args)
    logger.info(format, args)

def help():
  print "zamiaCAD builtin python functions:"
  print "=================================="
  print ""
  print "Builtins:"
示例#7
0
def main():

    parser, options, args = getCommandLineOpts()

    # Check command line options
    if options.server is None:
        parser.error("You must provide a server")

    username = options.username                 or \
               System.getenv('VMWARE_USERNAME') or \
               System.getProperty('user.name')
    
    if username is None:
        parser.error("You must provide a username")

    password = options.password or \
               System.getenv('VMWARE_PASSWORD')

    if password is None:
        password = getpass.getpass('Enter password for %s: ' % username)

    if (options.name and options.uuid):
        parser.error("A single filter must be specified at a time")
        
    if options.query and (options.delete or options.create or options.modify):
        parser.error("A single action must be specified at a time")
    if options.delete and (options.query or options.create or options.modify):
        parser.error("A single action must be specified at a time")
    if options.create and (options.query or options.delete or options.modify):
        parser.error("A single action must be specified at a time")
    if options.modify and (options.query or options.create or options.delete):
        parser.error("A single action must be specified at a time")
    
    # Get esx service instance
    si = getServiceInstance(options.server,username,password,options.skipSSL)

    # Query Datacenter
    if options.query and options.datacenter:
        dcs = getDatacenters(si)
        if dcs:
            listDatacenters(dcs)

    # Query Host Systems
    if options.query and options.host:
        hss = getHostSystems(si)
        if hss:
            listHostSystems(hss)

    # Query Resource Pools
    if options.query and options.resource:
        rps = getResourcePools(si)
        if rps:
            listResourcePools(rps)

    # Query Virtual Machine by name
    if options.query and options.name and options.vm:
        vm = getVirtualMachineByName(si,options.name)
        if vm:
            listVirtualMachines(vm)
    # Query Virtual Machine by uuid
    elif options.query and options.uuid and options.vm:
        vm = getVirtualMachineByUUID(si,options.uuid)
        if vm:
            listVirtualMachines(vm)
    # Query all Virtual Machines
    elif options.query and options.vm:
        vms = getVirtualMachines(si)
        if vms:
            listVirtualMachines(vms)

    # Modify Virtual Machine power state by name
    if options.name and options.power and options.modify:
        vm = getVirtualMachineByName(si,options.name)
        if vm:
            if options.reset:
                resetVm(vm)
            elif options.off:
                powerOffVm(vm)
            elif options.on:
                powerOnVm(vm)
    # Modify Virtual Machine power state by uuid
    elif options.uuid and options.power and options.modify:
        vm = getVirtualMachineByUUID(si,options.uuid)
        if vm:
            if options.reset:
                resetVm(vm)
            elif options.off:
                powerOffVm(vm)
            elif options.on:
                powerOnVm(vm)
    # Modify power state for all Virual Machines on a host
    elif options.all and options.power and options.modify:
        vms = getVirtualMachines(si)
        if vms:
            if options.reset:
                resetAllVms(vms)
            elif options.off:
                powerOffAllVms(vms)
            elif options.on:
                powerOnAllVms(vms)

    # Delete VMs
    if options.name and options.delete and options.vm:
        vm = getVirtualMachineByName(si,options.name)
        if vm:
            deleteVm(vm)
    elif options.uuid and options.delete and options.vm:
        vm = getVirtualMachineByUUID(si,options.uuid)
        if vm:
            deleteVm(vm)

    # Create VMs
    if options.create and options.vm:
        resourcePool = getResourcePools(si)[0]
        datacenter = getDatacenters(si)[0]
        vmFolder = datacenter.getVmFolder()

        # Create virtual devices
        configSpecs = []
        scsiBusKey = 0
        scsiBusNum = 0      # Limited to 3 ScsiControllers (i think)
        diskKey = 0
        diskUnitNum = 0
        diskMode = "persistent" # Changes are immediately and permanently written to the virtual disk.
        nicKey = 0
       
        if options.disk:
            scsiSpec = createScsiSpec(scsiBusKey,scsiBusNum)
            configSpecs.append(scsiSpec)

            # Limited to 15 virtual disks per ScsiController
            for disk in options.disk:
                size = int(disk)
                diskSpec = createDiskSpec(scsiBusKey,diskKey,diskUnitNum,size,diskMode,options.datastore)
                configSpecs.append(diskSpec)
                diskKey = diskKey + 1
                diskUnitNum = diskUnitNum + 1
                # Skip the unit number assigned to the scsi controller (7)
                if diskUnitNum == 7:
                    diskUnitNum = 8

        if options.nic:
            for nic in options.nic:
                netName, macAddress = nic   # Note: MacAddress validation doesn't happen through the api
                if macAddress.lower() == "generated":
                    macAddress = None
                nicSpec = createNicSpec(nicKey,netName,macAddress)
                configSpecs.append(nicSpec)
                nicKey = nicKey + 1

        vmSpec = createVmSpec(options.name,options.cpucount,options.memorysize,options.guestos,options.annotation,options.datastore,configSpecs)

        # Call the createVM_Task method on the vm folder
        task = vmFolder.createVM_Task(vmSpec, resourcePool, None)
        if task.waitForMe() == "success":
            print "%s is being created" % options.name
        else:
            print "%s was not created" % options.name

    si.getServerConnection().logout()
示例#8
0
    def modifyResponse(self, responseAsJsonObject, context):
        print "Inside modifyResponse method of introspection script ...."
        try:
            # Getting user-info-jwt
            ujwt = context.getHttpRequest().getParameter("ujwt")
            print ujwt
            jwks_url = System.getenv("ADMIN_UI_JWKS")
            print jwks_url
            if not ujwt:
                print "UJWT is empty or null"
            # Parse jwt
            userInfoJwt = Jwt.parse(ujwt)
            # Get auth-server keys
            url = URL(jwks_url)
            conn = url.openConnection()
            conn.setDoOutput(True)
            conn.setRequestMethod("GET")
            conn.setRequestProperty("Content-type", "application/json")
            if conn.getResponseCode() != 200:
                print "Failed!!"
                print conn.getResponseCode()
                print conn.getResponseMessage()
            else:
                print "Success!! Able to connect for auth-server jwks"
                print conn.getResponseCode()
                print conn.getResponseMessage()

            instr = conn.getInputStream()
            instrreader = InputStreamReader(instr)
            breader = BufferedReader(instrreader)
            output = breader.readLine()
            jsonResult = ""
            while output != None:
                if output != None:
                    jsonResult += output
                output = breader.readLine()
            # JWKS
            jwks = JSONObject(jsonResult)
            conn.disconnect()

            # Validate JWT
            authCryptoProvider = AuthCryptoProvider()
            validJwt = authCryptoProvider.verifySignature(userInfoJwt.getSigningInput(), userInfoJwt.getEncodedSignature(), userInfoJwt.getHeader().getKeyId(), jwks, None, userInfoJwt.getHeader().getSignatureAlgorithm())
            print validJwt

            if validJwt == True:
                print "user-info jwt is valid"
                # Get claims from parsed JWT
                jwtClaims = userInfoJwt.getClaims()
                jansAdminUIRole = jwtClaims.getClaim("jansAdminUIRole")
                print jansAdminUIRole.getString(0)
                # role-scope mapping
                scope = []
                if jansAdminUIRole.getString(0) == 'api-viewer':
                    scope.append("https://jans.io/oauth/config/attributes.readonly")
                    scope.append("https://jans.io/oauth/config/acrs.readonly")
                    scope.append("https://jans.io/oauth/config/scopes.readonly")
                    scope.append("https://jans.io/oauth/config/scripts.readonly")
                    scope.append("https://jans.io/oauth/config/openid/clients.readonly")
                    scope.append("https://jans.io/oauth/config/smtp.readonly")
                    scope.append("https://jans.io/oauth/config/logging.readonly")
                    scope.append("https://jans.io/oauth/config/uma/resources.readonly")
                    scope.append("https://jans.io/oauth/config/database/ldap.readonly")
                    scope.append("https://jans.io/oauth/config/jwks.readonly")
                    scope.append("https://jans.io/oauth/config/fido2.readonly")
                    scope.append("https://jans.io/oauth/config/cache.readonly")
                    scope.append("https://jans.io/oauth/jans-auth-server/config/properties.readonly")
                    scope.append("https://jans.io/oauth/config/database/couchbase.readonly")
                elif jansAdminUIRole.getString(0) == 'api-editor':
                    scope.append("https://jans.io/oauth/config/attributes.readonly")
                    scope.append("https://jans.io/oauth/config/attributes.write")
                    scope.append("https://jans.io/oauth/config/acrs.readonly")
                    scope.append("https://jans.io/oauth/config/acrs.write")
                    scope.append("https://jans.io/oauth/config/scopes.readonly")
                    scope.append("https://jans.io/oauth/config/scopes.write")
                    scope.append("https://jans.io/oauth/config/scripts.readonly")
                    scope.append("https://jans.io/oauth/config/scripts.write")
                    scope.append("https://jans.io/oauth/config/openid/clients.readonly")
                    scope.append("https://jans.io/oauth/config/openid/clients.write")
                    scope.append("https://jans.io/oauth/config/smtp.readonly")
                    scope.append("https://jans.io/oauth/config/smtp.write")
                    scope.append("https://jans.io/oauth/config/logging.readonly")
                    scope.append("https://jans.io/oauth/config/logging.write")
                    scope.append("https://jans.io/oauth/config/uma/resources.readonly")
                    scope.append("https://jans.io/oauth/config/uma/resources.write")
                    scope.append("https://jans.io/oauth/config/database/ldap.readonly")
                    scope.append("https://jans.io/oauth/config/database/ldap.write")
                    scope.append("https://jans.io/oauth/config/jwks.readonly")
                    scope.append("https://jans.io/oauth/config/jwks.write")
                    scope.append("https://jans.io/oauth/config/fido2.readonly")
                    scope.append("https://jans.io/oauth/config/fido2.write")
                    scope.append("https://jans.io/oauth/config/cache.readonly")
                    scope.append("https://jans.io/oauth/config/cache.write")
                    scope.append("https://jans.io/oauth/config/database/couchbase.readonly")
                    scope.append("https://jans.io/oauth/config/database/couchbase.write")
                    scope.append("https://jans.io/oauth/jans-auth-server/config/properties.readonly")
                elif jansAdminUIRole.getString(0) == 'api-manager':
                    scope.append("https://jans.io/oauth/config/attributes.readonly")
                    scope.append("https://jans.io/oauth/config/attributes.write")
                    scope.append("https://jans.io/oauth/config/attributes.delete")
                    scope.append("https://jans.io/oauth/config/acrs.readonly")
                    scope.append("https://jans.io/oauth/config/acrs.write")
                    scope.append("https://jans.io/oauth/config/acrs.delete")
                    scope.append("https://jans.io/oauth/config/scopes.readonly")
                    scope.append("https://jans.io/oauth/config/scopes.write")
                    scope.append("https://jans.io/oauth/config/scopes.delete")
                    scope.append("https://jans.io/oauth/config/scripts.readonly")
                    scope.append("https://jans.io/oauth/config/scripts.write")
                    scope.append("https://jans.io/oauth/config/scripts.delete")
                    scope.append("https://jans.io/oauth/config/openid/clients.readonly")
                    scope.append("https://jans.io/oauth/config/openid/clients.write")
                    scope.append("https://jans.io/oauth/config/openid/clients.delete")
                    scope.append("https://jans.io/oauth/config/smtp.readonly")
                    scope.append("https://jans.io/oauth/config/smtp.write")
                    scope.append("https://jans.io/oauth/config/smtp.delete")
                    scope.append("https://jans.io/oauth/config/logging.readonly")
                    scope.append("https://jans.io/oauth/config/logging.write")
                    scope.append("https://jans.io/oauth/config/uma/resources.readonly")
                    scope.append("https://jans.io/oauth/config/uma/resources.write")
                    scope.append("https://jans.io/oauth/config/uma/resources.delete")
                    scope.append("https://jans.io/oauth/config/database/ldap.readonly")
                    scope.append("https://jans.io/oauth/config/database/ldap.write")
                    scope.append("https://jans.io/oauth/config/database/ldap.delete")
                    scope.append("https://jans.io/oauth/config/jwks.readonly")
                    scope.append("https://jans.io/oauth/config/jwks.write")
                    scope.append("https://jans.io/oauth/config/fido2.readonly")
                    scope.append("https://jans.io/oauth/config/fido2.write")
                    scope.append("https://jans.io/oauth/config/cache.readonly")
                    scope.append("https://jans.io/oauth/config/cache.write")
                    scope.append("https://jans.io/oauth/config/database/couchbase.readonly")
                    scope.append("https://jans.io/oauth/config/database/couchbase.write")
                    scope.append("https://jans.io/oauth/jans-auth-server/config/properties.readonly")
                elif jansAdminUIRole.getString(0) == 'api-admin':
                    scope.append("https://jans.io/oauth/config/attributes.readonly")
                    scope.append("https://jans.io/oauth/config/attributes.write")
                    scope.append("https://jans.io/oauth/config/attributes.delete")
                    scope.append("https://jans.io/oauth/config/acrs.readonly")
                    scope.append("https://jans.io/oauth/config/acrs.write")
                    scope.append("https://jans.io/oauth/config/acrs.delete")
                    scope.append("https://jans.io/oauth/config/scopes.readonly")
                    scope.append("https://jans.io/oauth/config/scopes.write")
                    scope.append("https://jans.io/oauth/config/scopes.delete")
                    scope.append("https://jans.io/oauth/config/scripts.readonly")
                    scope.append("https://jans.io/oauth/config/scripts.write")
                    scope.append("https://jans.io/oauth/config/scripts.delete")
                    scope.append("https://jans.io/oauth/config/openid/clients.readonly")
                    scope.append("https://jans.io/oauth/config/openid/clients.write")
                    scope.append("https://jans.io/oauth/config/openid/clients.delete")
                    scope.append("https://jans.io/oauth/config/smtp.readonly")
                    scope.append("https://jans.io/oauth/config/smtp.write")
                    scope.append("https://jans.io/oauth/config/smtp.delete")
                    scope.append("https://jans.io/oauth/config/logging.readonly")
                    scope.append("https://jans.io/oauth/config/logging.write")
                    scope.append("https://jans.io/oauth/config/uma/resources.readonly")
                    scope.append("https://jans.io/oauth/config/uma/resources.write")
                    scope.append("https://jans.io/oauth/config/uma/resources.delete")
                    scope.append("https://jans.io/oauth/config/database/ldap.readonly")
                    scope.append("https://jans.io/oauth/config/database/ldap.write")
                    scope.append("https://jans.io/oauth/config/database/ldap.delete")
                    scope.append("https://jans.io/oauth/config/jwks.readonly")
                    scope.append("https://jans.io/oauth/config/jwks.write")
                    scope.append("https://jans.io/oauth/config/fido2.readonly")
                    scope.append("https://jans.io/oauth/config/fido2.write")
                    scope.append("https://jans.io/oauth/config/cache.readonly")
                    scope.append("https://jans.io/oauth/config/cache.write")
                    scope.append("https://jans.io/oauth/config/database/couchbase.readonly")
                    scope.append("https://jans.io/oauth/config/database/couchbase.write")
                    scope.append("https://jans.io/oauth/jans-auth-server/config/properties.write")
                    scope.append("https://jans.io/oauth/jans-auth-server/config/properties.readonly")
            responseAsJsonObject.accumulate("scope", scope)
        except Exception as e:
                print "Exception occured. Unable to resolve role/scope mapping."
                print e
        return True