Wiki source code of ZenseHome with Websupport (for Webhooks)
Version 5.1 by Normann P. Nielsen on 2026/11/15 15:43
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{info}}Join the "[[Danske ZenseHome Brugere>>https://www.facebook.com/groups/zensehomeusers/]]" Facebook grooup{{/info}} | ||
| 2 | |||
| 3 | To use the ZenseHome installation from outside, we need some "service manager" at the home LAN to send API commands to the ZenseHome box. | ||
| 4 | |||
| 5 | {{error}}This is a POC - Proof Of Concept - It has various security problems and stupid static scripts - that could be improved and parameter parameterized (so much...){{/error}} | ||
| 6 | |||
| 7 | {{success}}A Pre-requsite is reading / installing from [[ZenseHome API interfacing>>Main.information-technology.zensehome-api-interfacing]]{{/success}} | ||
| 8 | |||
| 9 | = Installing the basics = | ||
| 10 | |||
| 11 | As I have an Ubuntu server (with [[PLEX>>Main.information-technology.plex-media-server]]) in the house already (located at IP 10.0.0.150), I add the webserver apache2 to the installation. : | ||
| 12 | |||
| 13 | |||
| 14 | {{code}} | ||
| 15 | sudo apt-get install apache2 | ||
| 16 | sudo a2enmod cgi | ||
| 17 | sudo service apache2 restart | ||
| 18 | {{/code}} | ||
| 19 | |||
| 20 | then changing the default Apache2 config file: | ||
| 21 | |||
| 22 | |||
| 23 | {{code language="/etc/apache2/sites-available/000-default.conf"}} | ||
| 24 | <VirtualHost *:80> | ||
| 25 | # The ServerName directive sets the request scheme, hostname and port that | ||
| 26 | # the server uses to identify itself. This is used when creating | ||
| 27 | # redirection URLs. In the context of virtual hosts, the ServerName | ||
| 28 | # specifies what hostname must appear in the request's Host: header to | ||
| 29 | # match this virtual host. For the default virtual host (this file) this | ||
| 30 | # value is not decisive as it is used as a last resort host regardless. | ||
| 31 | # However, you must set it for any further virtual host explicitly. | ||
| 32 | #ServerName www.example.com | ||
| 33 | |||
| 34 | ServerAdmin webmaster@localhost | ||
| 35 | DocumentRoot /var/www/html | ||
| 36 | |||
| 37 | ScriptAlias /cgi-bin/ /var/www/cgi-bin/ | ||
| 38 | <Directory "/var/www/cgi-bin/"> | ||
| 39 | Options +ExecCGI | ||
| 40 | AddHandler cgi-script .cgi .pl .sh .exp | ||
| 41 | </Directory> | ||
| 42 | |||
| 43 | # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, | ||
| 44 | # error, crit, alert, emerg. | ||
| 45 | # It is also possible to configure the loglevel for particular | ||
| 46 | # modules, e.g. | ||
| 47 | #LogLevel info ssl:warn | ||
| 48 | |||
| 49 | ErrorLog ${APACHE_LOG_DIR}/error.log | ||
| 50 | CustomLog ${APACHE_LOG_DIR}/access.log combined | ||
| 51 | |||
| 52 | # For most configuration files from conf-available/, which are | ||
| 53 | # enabled or disabled at a global level, it is possible to | ||
| 54 | # include a line for only one particular virtual host. For example the | ||
| 55 | # following line enables the CGI configuration for this host only | ||
| 56 | # after it has been globally disabled with "a2disconf". | ||
| 57 | #Include conf-available/serve-cgi-bin.conf | ||
| 58 | </VirtualHost> | ||
| 59 | {{/code}} | ||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | = Adding Zensehome /expect scipts = | ||
| 64 | |||
| 65 | In the /var/www/cgi-bin/ I place 2 files: | ||
| 66 | |||
| 67 | |||
| 68 | {{code language="turnon-office.exp"}} | ||
| 69 | #!/usr/bin/expect | ||
| 70 | spawn telnet 10.0.0.110 10001 | ||
| 71 | expect "'^]'." | ||
| 72 | send ">>Login 32010<<\r" | ||
| 73 | expect ">>Login Ok<<" | ||
| 74 | sleep .1; | ||
| 75 | send ">>Set 10604 1<<" | ||
| 76 | sleep .1; | ||
| 77 | send ">>Logout<<\r" | ||
| 78 | expect ">>Logout Ok<<" | ||
| 79 | exit | ||
| 80 | {{/code}} | ||
| 81 | |||
| 82 | |||
| 83 | {{code language="turnoff-office.exp"}} | ||
| 84 | #!/usr/bin/expect | ||
| 85 | spawn telnet 10.0.0.110 10001 | ||
| 86 | expect "'^]'." | ||
| 87 | send ">>Login 32010<<\r" | ||
| 88 | expect ">>Login Ok<<" | ||
| 89 | sleep .1; | ||
| 90 | send ">>Set 10604 0<<" | ||
| 91 | sleep .1; | ||
| 92 | send ">>Logout<<\r" | ||
| 93 | expect ">>Logout Ok<<" | ||
| 94 | exit | ||
| 95 | {{/code}} | ||
| 96 | |||
| 97 | And now its possible to turn on the Office light at the URL: [[http://10.0.0.150/cgi-bin/turnon-office.exp]] | ||
| 98 | |||
| 99 | And off at [[http://10.0.0.150/cgi-bin/turnoff-office.exp>>http://10.0.0.150/cgi-bin/turnon-office.exp]] | ||
| 100 | |||
| 101 | {{success}}As there is not output, the Apache will return a 500 Error. Theres room for improvement - [[https://docstore.mik.ua/orelly/linux/cgi/ch03_03.htm]]{{/success}} | ||
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | = Access from outside = | ||
| 108 | |||
| 109 | The next step is to make a port forward in my Icotera Router: | ||
| 110 | |||
| 111 | [[image:Screenshot 2018-11-17 at 13.59.50.png||width="800"||alt="Screenshot 2018-11-17 at 13.59.50.png"]] | ||
| 112 | |||
| 113 | And now its accessible from the world!! | ||
| 114 | |||
| 115 | {{info}}Here, we should consider to make some (at least) IP restrictions in the Apache. Currently, the whole world can potentionally turn the office light on/off | ||
| 116 | |||
| 117 | |||
| 118 | {{code}} | ||
| 119 | <Location /> | ||
| 120 | Order deny,allow | ||
| 121 | Deny from all | ||
| 122 | Allow from 77.243.62.62 | ||
| 123 | </Location> | ||
| 124 | {{/code}}{{/info}} |