Esempio n. 1
0
 def write(self):
     with open(self.filePath, 'w') as f:
         jsonEncoded = json.dumps(self.configuration, sort_keys=True, indent=4)
         f.write(jsonEncoded)
         f.flush()
         f.close()
         LOGGER.write(log.LOGTAGS[0],'Default config is written to "' + self.filePath + '"')           
Esempio n. 2
0
def waitForCtrlC():
    try:
        while True:
            pass
    except KeyboardInterrupt:
        LOGGER.write(log.LOGTAGS[0],'ShareLockHomes','shutting down...')
        quit(False, logTag=0, message='Exiting by user.')
Esempio n. 3
0
 def denyStation(self, stationIdentifier):
     LOGGER.write(log.LOGTAGS[0],'Deny Station "'+ stationIdentifier +'"', 'to read "' + self.filePath + '"')
     if not stationIdentifier in self.allowedStations:
         LOGGER.write(log.LOGTAGS[1],'Station "'+ stationIdentifier +'"', 'already denied.')
         self.lastChange = False
         return False
     del self.allowedStations[self.getStationPosition(stationIdentifier)]
     self.updateInformation('allowedStations', self.allowedStations)
     self.lastChange = True
     return True
Esempio n. 4
0
 def allowStation(self, stationIdentifier):
     LOGGER.write(log.LOGTAGS[0],'Allow Station "'+ stationIdentifier +'"', 'to read "' + self.filePath + '"')
     if stationIdentifier in self.allowedStations: 
         LOGGER.write(log.LOGTAGS[1],'Station "'+ stationIdentifier +'"', 'already allowed.')
         self.lastChange = False
         return False
     self.allowedStations.append(stationIdentifier)
     self.updateInformation('allowedStations', self.allowedStations)
     self.lastChange = True
     return True
Esempio n. 5
0
def quit(noError=True, **keyWordArgs):
    try: 
        logTagID = keyWordArgs['logTag']
    except KeyError:
        logTagID = 2
    try: 
        message = keyWordArgs['message']
    except KeyError:
        message = 'unknown error!'       

    if noError == False:
        LOGGER.write(log.LOGTAGS[logTagID],message)
        sys.exit(1)
    LOGGER.write(log.LOGTAGS[0],'Exiting without error')
    sys.exit()
Esempio n. 6
0
    def __init__(self, RequestHandlerClass, configuration):
        listenaddress = configuration["listen"]
        listenport = configuration["port"]
        x509cert = configuration["cert"]
        x509key = configuration["key"]

        LOGGER.write(LOGTAGS[0], "Starting SockServer on " + listenaddress + ":" + str(listenport) + " TCP")
        SocketServer.BaseServer.__init__(self, (listenaddress, listenport), RequestHandlerClass)
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_certificate_file(x509cert)
        ctx.use_privatekey_file(x509key)

        self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.server_bind()
        self.server_activate()
Esempio n. 7
0
def initiateParameterAndConfig():
    parameters = getParameters()
    configFilePath = getParameter('config', 'sharelockhomes.conf')
    logFilePath = getParameter('log')
    if not logFilePath == False:
        LOGGER.activateFileMode(logFilePath)
    LOGGER.write(log.LOGTAGS[0],'Try to use config from file "' + configFilePath + '"')
    configuration = Config(configFilePath)
    logging = getConfigValue(configuration, 'logging')
    logFilePath = getConfigValue(configuration, 'logFilePath', 'sharelockhomes.log')
    if logging == True and LOGGER.writeToFile == False:
        LOGGER.activateFileMode(logFilePath)
    dbPathParameter = getParameter('db')
    dbPathConfig = getConfigValue(configuration, 'databasePath','db')
    dbPath = useParameterIfExistsElseUseConfig(dbPathParameter, dbPathConfig)
    createDirectories(dbPath)      
    return configuration 
Esempio n. 8
0
def createDirectories(*dirs):
    for path in dirs:
        LOGGER.write(log.LOGTAGS[0],'Try to create directory "' + path + '"')
        try:
            os.makedirs(path, 0664)
            LOGGER.write(log.LOGTAGS[0],'Directory "' + path + '" created.')
        except OSError as error:
            errorCode, errorMessage = getOSErrorMessage(error)
            logTagID = errorCodeToLogTagID(errorCode)
            LOGGER.write(log.LOGTAGS[logTagID],'Not able to create directory "' + path + '":',errorMessage+'!')
Esempio n. 9
0
 def getConfigFromFile(self, filePath):
     if not os.path.isfile(filePath):
         LOGGER.write(log.LOGTAGS[1],'Configfile "' + filePath + '" does not exists! Will use default config.')
         return {}
     if not isJsonFile(filePath):
         LOGGER.write(log.LOGTAGS[1],'Configfile "' + filePath + '" is no valid json file! Will use default config.')
         return {}
     with open(filePath, 'r') as f:
         LOGGER.write(log.LOGTAGS[0],'Configfile "' + filePath + '" is valid.')
         return json.load(f)