Exemplo n.º 1
0
def main(argv):
    port = 8000
    configfile = None
    logfile = None

    i = 1
    while i < len(argv):
        if argv[i] in ["-c", "-C", "--config-file"]:
            configfile = argv[i + 1]
            i += 1
        elif argv[i] in ["-l", "-L", "--log-file"]:
            logfile = argv[i + 1]
            i += 1
        elif argv[i] in ["-s", "-S", "--script-file"]:
            scriptfile = argv[i + 1]
            scriptname = scriptfile.split("/")[-1].split(".")[0]
            loadScript(scriptname, scriptfile)
            i += 1
        elif argv[i] in ["-h", "-H", "--help"]:
            displayHelp()
        elif argv[i] in ["-d", "--debug"]:
            setDebug()
        else:
            try:
                port = int(argv[i])
            except ValueError:
                displayHelp()
        i += 1

    if logfile:
        logToFile(logfile)

    info("Starting %s" % VERSION_STRING)
    server = Server(port=port, configfile=configfile)
    runLoop()
    server.stop()
Exemplo n.º 2
0
def main(argv):
    port = 8000
    configfile = None
    logfile = None
    
    i = 1
    while i < len(argv):
        if argv[i] in ["-c", "-C", "--config-file"]:
            configfile = argv[i+1]
            i+=1
        elif argv[i] in ["-l", "-L", "--log-file"]:
            logfile = argv[i+1]
            i+=1
        elif argv[i] in ["-s", "-S", "--script-file"]:
            scriptfile = argv[i+1]
            scriptname = scriptfile.split("/")[-1].split(".")[0]
            loadScript(scriptname, scriptfile)
            i+=1
        elif argv[i] in ["-h", "-H", "--help"]:
            displayHelp()
        elif argv[i] in ["-d", "--debug"]:
            setDebug()
        else:
            try:
                port = int(argv[i])
            except ValueError:
                displayHelp()
        i+=1
    
    if logfile:
        logToFile(logfile)

    info("Starting %s" % VERSION_STRING)
    server = Server(port=port, configfile=configfile)
    runLoop()
    server.stop()
Exemplo n.º 3
0
    def __init__(self, port=8000, coap_port=5683, login=None, password=None, passwdfile=None, configfile=None, scriptfile=None):
        self.host = getLocalIP()
        self.gpio = NativeGPIO()
        self.restHandler = rest.RESTHandler()
        manager.addDeviceInstance("GPIO", self.gpio, [])

        if configfile != None:
            logger.info("Loading configuration from %s" % configfile)
            config = Config(configfile)
        else:
            config = Config()
            
        self.gpio.addSetups(config.items("GPIO"))
        self.gpio.addResets(config.items("~GPIO"))
        self.gpio.setup()
        
        #ADDED OVK
        self.gpiox = ExtendedGPIO()
        manager.addDeviceInstance("GPIOX", self.gpiox, [])
        self.gpiox.addCards(config.get("GPIOX", "cards", None))
        #TODO Add setup and reset to set initial state, if needed
        #self.gpiox.addSetups(config.items("GPIOX"))
        #self.gpiox.addResets(config.items("~GPIOX"))
        #self.gpiox.setup()
        #ADDED OVK

        devices = config.items("DEVICES")
        for (name, params) in devices:
            values = params.split(" ")
            driver = values[0];
            args = {}
            i = 1
            while i < len(values):
                (arg, val) = values[i].split(":")
                args[arg] = val
                i+=1
            manager.addDevice(name, driver, args)
        

        if scriptfile != None:
            scriptname = scriptfile.split("/")[-1].split(".")[0]
            loader.loadScript(scriptname, scriptfile, self.restHandler)    
        
        scripts = config.items("SCRIPTS")
        for (name, source) in scripts:
            loader.loadScript(name, source, self.restHandler)
        
        self.restHandler.device_mapping = config.getboolean("REST", "device-mapping", True)
        self.gpio.post_value = config.getboolean("REST", "gpio-post-value", True)
        self.gpio.post_function = config.getboolean("REST", "gpio-post-function", True)

        #ADDED OVK
        self.gpiox.post_value = True
        self.gpiox.post_function = True
        #ADDED OVK

        exports = config.get("REST", "gpio-export", None)
        if exports != None:
            self.gpio.export = [int(s) for s in exports.split(",")]
        self.restHandler.export = self.gpio.export
        
        http_port = config.getint("HTTP", "port", port)
        http_enabled = config.getboolean("HTTP", "enabled", http_port > 0)
        http_passwdfile = config.get("HTTP", "passwd-file", passwdfile)
        context = config.get("HTTP", "context", None)
        docroot = config.get("HTTP", "doc-root", None)
        index = config.get("HTTP", "welcome-file", None)
            
        coap_port = config.getint("COAP", "port", coap_port)
        coap_enabled = config.getboolean("COAP", "enabled", coap_port > 0)
        coap_multicast = config.getboolean("COAP", "multicast", coap_enabled)

        routes = config.items("ROUTES")
        for (source, destination) in routes:
            self.restHandler.addRoute(source, destination)
    
        auth = None
        if http_passwdfile != None:
            if os.path.exists(http_passwdfile):
                f = open(http_passwdfile)
                auth = f.read().strip(" \r\n")
                f.close()
                if len(auth) > 0:
                    logger.info("Access protected using %s" % http_passwdfile)
                else:
                    logger.info("Passwd file %s is empty" % http_passwdfile)
            else:
                logger.error("Passwd file %s not found" % http_passwdfile)
            
        elif login != None or password != None:
            auth = crypto.encryptCredentials(login, password)
            logger.info("Access protected using login/password")
            
        if auth == None or len(auth) == 0:
            logger.warn("Access unprotected")
        
        realm = config.get("HTTP", "prompt", None)
        
        if http_enabled:
            self.http_server = http.HTTPServer(self.host, http_port, self.restHandler, context, docroot, index, auth, realm)
        else:
            self.http_server = None
        
        if coap_enabled:
            self.coap_server = coap.COAPServer(self.host, coap_port, self.restHandler)
            if coap_multicast:
                self.coap_server.enableMulticast()
        else:
            self.coap_server = None
Exemplo n.º 4
0
    def __init__(self, port=8000, coap_port=5683, login=None, password=None, passwdfile=None, configfile=None):
        self.host = getLocalIP()
        self.gpio = NativeGPIO()
        self.restHandler = rest.RESTHandler()
        manager.addDeviceInstance("GPIO", self.gpio, [])

        if configfile != None:
            logger.info("Loading configuration from %s" % configfile)
            config = Config(configfile)
        else:
            config = Config()
            
        self.gpio.addSetups(config.items("GPIO"))
        self.gpio.addResets(config.items("~GPIO"))
        self.gpio.setup()
        
        devices = config.items("DEVICES")
        for (name, params) in devices:
            values = params.split(" ")
            driver = values[0];
            args = {}
            i = 1
            while i < len(values):
                (arg, val) = values[i].split(":")
                args[arg] = val
                i+=1
            manager.addDevice(name, driver, args)
                
        scripts = config.items("SCRIPTS")
        for (name, source) in scripts:
            loader.loadScript(name, source, self.restHandler)
        
        self.restHandler.device_mapping = config.getboolean("REST", "device-mapping", True)
        self.gpio.post_value = config.getboolean("REST", "gpio-post-value", True)
        self.gpio.post_function = config.getboolean("REST", "gpio-post-function", True)
        exports = config.get("REST", "gpio-export", None)
        if exports != None:
            self.gpio.export = [int(s) for s in exports.split(",")]
        self.restHandler.export = self.gpio.export
        
        http_port = config.getint("HTTP", "port", port)
        http_enabled = config.getboolean("HTTP", "enabled", http_port > 0)
        http_passwdfile = config.get("HTTP", "passwd-file", passwdfile)
        context = config.get("HTTP", "context", None)
        docroot = config.get("HTTP", "doc-root", None)
        index = config.get("HTTP", "welcome-file", None)
            
        coap_port = config.getint("COAP", "port", coap_port)
        coap_enabled = config.getboolean("COAP", "enabled", coap_port > 0)
        coap_multicast = config.getboolean("COAP", "multicast", coap_enabled)

        routes = config.items("ROUTES")
        for (source, destination) in routes:
            self.restHandler.addRoute(source, destination)
    
        auth = None
        if http_passwdfile != None:
            if os.path.exists(http_passwdfile):
                f = open(http_passwdfile)
                auth = f.read().strip(" \r\n")
                f.close()
                if len(auth) > 0:
                    logger.info("Access protected using %s" % http_passwdfile)
                else:
                    logger.info("Passwd file %s is empty" % http_passwdfile)
            else:
                logger.error("Passwd file %s not found" % http_passwdfile)
            
        elif login != None or password != None:
            auth = crypto.encryptCredentials(login, password)
            logger.info("Access protected using login/password")
            
        if auth == None or len(auth) == 0:
            logger.warn("Access unprotected")
        
        if http_enabled:
            self.http_server = http.HTTPServer(self.host, http_port, self.restHandler, context, docroot, index, auth)
        else:
            self.http_server = None
        
        if coap_enabled:
            self.coap_server = coap.COAPServer(self.host, coap_port, self.restHandler)
            if coap_multicast:
                self.coap_server.enableMulticast()
        else:
            self.coap_server = None