Skip to content

Commit

Permalink
Added captive portal functionality to the ap when disconnected (all h…
Browse files Browse the repository at this point in the history
…ttp requests redirect to ap ip address)
  • Loading branch information
plchampigny committed Mar 5, 2017
1 parent 92bd459 commit 3646c9e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function log_error_send_success_with(success_obj, error, response) {
response.end();
}

function redirectUnmatched(req, res) {
res.redirect(config.access_point.ip_addr + ':' + config.server.port);
}

/*****************************************************************************\
Returns a function which sets up the app and our various routes.
\*****************************************************************************/
Expand Down Expand Up @@ -72,6 +76,8 @@ module.exports = function(wifi_manager, callback) {
});
});

app.all('*', redirectUnmatched);

// Listen on our server
app.listen(config.server.port);
}
2 changes: 1 addition & 1 deletion assets/etc/dnsmasq/dnsmasq.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# web-server.
#address=/double-click.net/127.0.0.1
address=/#/192.168.1.1

# --address (and --server) work with IPv6 addresses too.
#address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83
Expand Down
18 changes: 9 additions & 9 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"access_point": {
"force_reconfigure": true,
"wifi_interface": "wlan0",
"ssid": "rpi-config-ap",
"passphrase": "zzzzzzzz",
"domain": "rpi.config",
"ip_addr": "192.168.44.1",
"ssid": "Prism",
"passphrase": "12345678",
"domain": "prism.config",
"ip_addr": "192.168.1.1",
"netmask": "255.255.255.0",
"subnet_ip": "192.168.44.0",
"broadcast_address": "192.168.44.255",
"subnet_ip": "192.168.1.0",
"broadcast_address": "192.168.1.255",
"subnet_range": {
"start": "192.168.44.10",
"end": "192.168.44.50"
"start": "192.168.1.10",
"end": "192.168.1.50"
}
},

"server": {
"port": 88
"port": 80
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"scripts": {
"test": "npm test",
"provision": "apt-get update -y && apt-get install dnsmasq hostapd iw -y && echo '##########\n COPY DEFAULT CONFIG FILE\n ##########' && cp -f /etc/wpa_supplicant/wpa_supplicant.conf ./assets/etc/default/wpa_supplicant.conf && cp -f /etc/network/interfaces ./assets/etc/default/interfaces && cp -f /etc/dhcpcd.conf ./assets/etc/default/dhcpcd.conf && cp -f /etc/dnsmasq.conf ./assets/etc/default/dnsmasq.conf && cp -f /etc/default/hostapd ./assets/etc/default/hostapd",
"reset": "cp -f ./assets/etc/default/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf && cp -f ./assets/etc/default/interfaces /etc/network/interfaces && cp -f ./assets/etc/default/dhcpcd.conf /etc/dhcpcd.conf && cp -f ./assets/etc/default/dnsmasq.conf /etc/dnsmasq.conf && cp -f ./assets/etc/default/hostapd /etc/default/hostapd && rm /etc/hostapd/hostapd.conf",
"bootstrap": "wget http://treebeard.home.net:1234/bootstrap/pifi-conf -O bootstrap.sh && chmod u+x bootstrap.sh && ./bootstrap.sh"
"reset": "cp -f ./assets/etc/default/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf && cp -f ./assets/etc/default/interfaces /etc/network/interfaces && cp -f ./assets/etc/default/dhcpcd.conf /etc/dhcpcd.conf && cp -f ./assets/etc/default/dnsmasq.conf /etc/dnsmasq.conf && cp -f ./assets/etc/default/hostapd /etc/default/hostapd && rm /etc/hostapd/hostapd.conf && rm /etc/init.d/raspberry-wifi-conf && update-rc.d raspberry-wifi-conf remove",
"bootstrap": "wget http://treebeard.home.net:1234/bootstrap/pifi-conf -O bootstrap.sh && chmod u+x bootstrap.sh && ./bootstrap.sh",
"install-service": "cp assets/init.d/raspberry-wifi-conf /etc/init.d/raspberry-wifi-conf && chmod +x /etc/init.d/raspberry-wifi-conf && update-rc.d raspberry-wifi-conf defaults"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 3646c9e

Please sign in to comment.