Issue #004 [Fixed/closed] - [Server] Config file

Posted by trouch

Add a config file :


Comment 1

Posted by trouch

/etc/webiopi/passwd added that contains sha256(base64("user:password"))


Comment 2

Posted by trouch

Here is a config and server extension proposal

/etc/webiopi/webiopi.conf: {{{ port = 8000 share_gpio = true

true /etc/webiopi/passwd *

<expert>
    <enabled>true</enabled>
    <auth-file>/etc/webiopi/passwd</script>
    <export>\*</export>
</expert>

<custom>
    <context>myapp1</context>
    <docroot>/home/pi/webiopi/myapp1/htdocs</docroot>
    <welcome-file>index.html</welcome-file>
    <script>/home/pi/webiopi/myapp1/script.py</script>
    <auth-file>/home/pi/webiopi/myapp1/passwd</script>
</custom>

<custom>
    <context>myapp2</context>
    <docroot>/home/pi/webiopi/myapp2/htdocs</docroot>
    <welcome>myapp2.html</welcome>
    <export>0, 1, 3, 4</export>
    <values>0, 0, 0, 0</values>
</custom>

}}}

/home/pi/webiopi/myapp1/script.py: {{{ def setup(): # called at server start, optional ...

def loop(): # called in webiopi loop, optional ...

def destroy(): # called at server stop, optional ...

def myMacro(): # automatically registered macro ...

def __myFunction__(): # __ denotes private functions ... }}}

then, access with Header : http://ip:port/(webiopi/) MyApp1 : http://ip:port/(webiopi/)myapp1/ MyApp2 : http://ip:port/(webiopi/)myapp2/

Macro registering can be automated, using __ pre/suffix or decorators to denote privates functions. Or it can be manual, using declarations in the config file. I'm not sure about the syntax to sure, XML, JSON, something else...

Need advice


Comment 3

Posted by trouch

example script.py with decorator to denote macros :

def setup(): # called at server start, optional ...

def loop(): # called in webiopi loop, optional ...

def destroy(): # called at server stop, optional ...

@macro def myMacro(): # automatically registered macro ...

def myFunction(): # private functions ...


Comment 4

Posted by trouch

key/value pair based config file:

port = 8000 share_gpio = true

apps.header.enabled = true apps.header.auth-file = /etc/webiopi/passwd apps.header.export = *

apps.expert.enabled = true apps.expert.auth-file = /etc/webiopi/passwd apps.expert.export = *

apps.custom.1.context = myapp1 apps.custom.1.docroot = /home/pi/webiopi/myapp1/htdocs apps.custom.1.welcome-file = index.html apps.custom.1.script = /home/pi/webiopi/myapp1/script.py apps.custom.1.auth-file = /home/pi/webiopi/myapp1/passwd

apps.custom.2.context = myapp2 apps.custom.2.docroot = /home/pi/webiopi/myapp2/htdocs apps.custom.2.welcome-file = myapp2.html apps.custom.2.export = 0, 1, 3, 4 apps.custom.2.values = 0, 0, 0, 0


Comment 5

Posted by trouch

Finally use INI file format, custom app support will be added later

[HTTP] enabled = true port = 8000 passwd-file = /etc/webiopi/passwd

[COAP] enabled = true port = 5683 multicast = true


Comment 6

Posted by trouch