Exemplo n.º 1
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.º 2
0
        print("\tfile\tSave hash to file")
        sys.exit()
else:
    file = "/etc/webiopi/passwd"

f = open(file, "w")
_LOGIN = "******"
_PASSWORD = "******"
_CONFIRM = "Confirm password: "******"Passwords don't match !"

import getpass
try:
    login = raw_input(_LOGIN)
except NameError:
    login = input(_LOGIN)
password = getpass.getpass(_PASSWORD)
password2 = getpass.getpass(_CONFIRM)
while password != password2:
    print(_DONTMATCH)
    password = getpass.getpass(_PASSWORD)
    password2 = getpass.getpass(_CONFIRM)

from webiopi.utils.crypto import encryptCredentials
auth = encryptCredentials(login, password)
print("\nHash: %s" % auth)
if file:
    f.write(auth)
    f.close()
    print("Saved to %s" % file)
Exemplo n.º 3
0
        print("\tfile\tSave hash to file")
        sys.exit()
else:
    file = "/etc/webiopi/passwd"       

f = open(file, "w")
_LOGIN      = "******"
_PASSWORD   = "******"
_CONFIRM    = "Confirm password: "******"Passwords don't match !"

import getpass
try:
    login = raw_input(_LOGIN)
except NameError:
    login = input(_LOGIN)
password = getpass.getpass(_PASSWORD)
password2 = getpass.getpass(_CONFIRM)
while password != password2:
    print(_DONTMATCH)
    password = getpass.getpass(_PASSWORD)
    password2 = getpass.getpass(_CONFIRM)

from webiopi.utils.crypto import encryptCredentials
auth = encryptCredentials(login, password)
print("\nHash: %s" % auth)
if file:
    f.write(auth)
    f.close()
    print("Saved to %s" % file)
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