Skip to content

Commit

Permalink
support for multiple sites
Browse files Browse the repository at this point in the history
  • Loading branch information
sebpiq committed Nov 21, 2017
1 parent cd8d684 commit 5e39145
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -88,7 +88,7 @@ cd /mnt/PORTALKEY/FreedomPortal
Once inside the folder, run the following command :

```
lua configure.lua config
lua configure.lua parameters
```

Then, finalize the installation by running :
Expand Down
4 changes: 4 additions & 0 deletions configure.lua
Expand Up @@ -12,6 +12,10 @@ end
local lustache = require('lustache')
local config = require(arg[1])

-- Add `last` attribute to last site to help templates
config.sites[table.getn(config.sites)].last = true
config.first_site = config.sites[1]

-- Helpers
function run_command(cmd)
local process = assert(io.popen(cmd, 'r'))
Expand Down
36 changes: 18 additions & 18 deletions freedomportal/lighttpd.conf
Expand Up @@ -17,7 +17,7 @@ server.port = 80
{{# config.page_404_path }}
server.error-handler-404 = "{{{ config.page_404_path }}}"
{{/ config.page_404_path }}
server.document-root = "{{{ config.www_dir }}}"
server.document-root = "{{{ config.first_site.www_dir }}}"
server.pid-file = "/var/run/lighttpd.pid"
include "/etc/lighttpd/mime.conf"

Expand All @@ -28,39 +28,39 @@ index-file.names = ( "index.html" )
server.errorlog = "{{{ config.log_dir }}}/error.log"
# stderr output from CGI processes
server.breakagelog = "{{{ config.log_dir }}}/server-error.log"
# logging visitors
{{# config.log_visitors }}
$HTTP["host"] == "{{{ config.www_host }}}" {
$HTTP["url"] == "/" {
accesslog.filename = "{{{ config.log_dir }}}/visitors.log"
accesslog.format = "%t %h \"%{User-Agent}i\""
}
}
{{/ config.log_visitors }}

# Lua files are handled with cgi
cgi.assign = ( ".lua" => "{{{ wsapi_cgi_bin }}}" )

# Serve the redirection page to all requests that are made to a different host
# than "{{{ config.www_host }}}"
$HTTP["host"] !~ "^{{{ config.www_host }}}$" {
# Serve the redirection page to all requests that are made to an unknown host
$HTTP["host"] !~ "{{# config.sites }}(^{{{ www_host }}}$){{^last}}|{{/last}}{{/ config.sites }}" {
url.rewrite-once = (
"(.*)" => "/redirection.html"
)
alias.url = (
"" => "{{{ config.configured_dir }}}/pages/",
)

{{# config.log_visitors }}
$HTTP["url"] == "/redirection.html" {
accesslog.filename = "{{{ config.log_dir }}}/visitors.log"
accesslog.format = "%t %h \"%{User-Agent}i\""
}
{{/ config.log_visitors }}
}

# All static content is hosted at "{{{ config.www_host }}}"
# Routes under {{{ config.scripts_root_url }}} serve lua scripts
$HTTP["host"] == "{{{ config.www_host }}}" {
{{# config.sites }}
# All static content is hosted at {{{ www_host }}}/
# Routes under {{{ www_host }}}{{{ scripts_root_url }}} serve lua scripts
$HTTP["host"] == "{{{ www_host }}}" {
alias.url = (
"{{{ config.scripts_root_url }}}" => "{{{ config.configured_dir }}}/scripts",
"" => "{{{ config.www_dir }}}",
"{{{ scripts_root_url }}}" => "{{{ config.configured_dir }}}/scripts",
"" => "{{{ www_dir }}}",
)
}

{{/ config.sites }}

{{# config.ios_disable_cna }}
# Return `success.html` page if CaptiveNetworkSupport request, so iOS device
# thinks it's connected and won't pop-up the CNA.
Expand Down
4 changes: 2 additions & 2 deletions freedomportal/pages/redirection.html
Expand Up @@ -2,11 +2,11 @@
<html>
<head>
<title>Connecting ...</title>
<meta http-equiv="refresh" content="0; url=http://{{{ config.www_host }}}">
<meta http-equiv="refresh" content="0; url={{{ config.landing_page }}}">
</head>
<body>
<p>
To finish connecting, go to <a href="http://{{{ config.www_host }}}"> this page</a>.
To finish connecting, go to <a href="{{{ config.landing_page }}}"> this page</a>.
</p>
</body>
</html>
51 changes: 29 additions & 22 deletions parameters.lua.template
@@ -1,26 +1,44 @@
return {

-- Host on which lighttpd will serve custom web pages
www_host = 'freedomportal.com',
landing_page = 'http://freedomportal.com/',

-- Root url for serving scripts
scripts_root_url = '/_scripts',
sites = {
{
-- Host on which lighttpd will serve custom web pages
www_host = 'freedomportal.com',

-- Path where the configured files are saved
configured_dir = '/root/FreedomPortal_configured',
-- Root path for the custom web pages served on the static portal
www_dir = '/mnt/PORTALKEY/www',

-- Root path for the custom web pages served on the static portal
www_dir = '/mnt/PORTALKEY/www',
-- Root url for serving scripts
scripts_root_url = '/_scripts'
},
},

-- [Optional] path to a 404 page which will be displayed if the user
-- tries to load a non-existent page. The configured path is relative to `www_dir`.
page_404_path = '/404.html',
wireless = {
-- Public name of the wifi network.
-- NOTE : Max length of SSID is 32 characters!
ssid = 'FreedomPortal',

-- Encryption type of the network. Set to "psk-mixed" to setup a password.
encryption = 'none',

-- Password. Useless if encryption is 'none'
key = 'password'
},

-- Path where the configured files are saved
configured_dir = '/root/FreedomPortal_configured',

-- Root path for all log files
-- NOTE : files under /var are erased when the router reboots. If you don't want to loose
-- your logs, place them somewhere else, for example on the USB key (e.g. /mnt/PORTALKEY/log)
log_dir = '/var/log/lighttpd',

-- [Optional] path to a 404 page which will be displayed if the user
-- tries to load a non-existent page. The configured path is relative to `www_dir`.
page_404_path = '/404.html',

-- Set to true to log visitor's access
log_visitors = false,

Expand All @@ -37,15 +55,4 @@ return {
-- disable it, even if it means the user has to open their browser manually.
ios_disable_cna = false,

wireless = {
-- Public name of the wifi network.
-- NOTE : Max length of SSID is 32 characters!
ssid = 'FreedomPortal',

-- Encryption type of the network. Set to "psk-mixed" to setup a password.
encryption = 'none',

-- Password. Useless if encryption is 'none'
key = 'password'
}
}

0 comments on commit 5e39145

Please sign in to comment.