Skip to content

Commit

Permalink
Continuous Release v1.0.1
Browse files Browse the repository at this point in the history
Merge pull request #9 from Splines/dev
  • Loading branch information
Splines authored Feb 24, 2024
2 parents b3d84f6 + b38d2f7 commit ead2280
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 308 deletions.
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"ms-python.pylint",
"ms-python.black-formatter"
]
}
48 changes: 48 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
//////////////////////////////////////
// Python (linting & formatting)
//////////////////////////////////////
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"pylint.importStrategy": "fromEnvironment",
//////////////////////////////////////
// Files
//////////////////////////////////////
"files.exclude": {
"**/__pycache__/": true,
},
//////////////////////////////////////
// Editor
//////////////////////////////////////
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 100, // toggle via Alt + Z shortcut
"editor.mouseWheelZoom": true,
"editor.rulers": [
{
"column": 80, // soft limit
"color": "#e5e5e5"
},
{
"column": 100, // hard limit
"color": "#c9c9c9"
}
],
//////////////////////////////////////
// Git
//////////////////////////////////////
"git.inputValidation": "warn",
"git.inputValidationSubjectLength": 50,
"git.inputValidationLength": 72,
//////////////////////////////////////
// Spell Checker
//////////////////////////////////////
"cSpell.words": [
"github",
"pylint"
],
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Splines
Copyright (c) 2022-2024 Splines

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<h3 align="center">Raspi Captive Portal</h3>
<p align="center">A Captive Portal & Access Point setup for use with the Raspberry Pi</p>
<p align="center"><sub>Tested on the Raspberry Pi 4, Raspbian GNU/Linux 11 (bullseye)</sub></p>
<p align="center">Tested on the Raspberry Pi 4, Raspberry Pi OS: Bullseye (11) & Bookworm (12) (64-bit)</p>
</p>


Expand All @@ -27,12 +27,15 @@ You probably want to use this repo in one of these ways:

## Setup

> [!tip]
> Raspberry Pi OS Bookworm (12) comes with a new [Network Manager](https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-networking). It might make the configuration easier instead of manually having to setup `dhcp`, `hostapd` etc. (the latter is what we do in this project, but automatically for you). Nevertheless, this project still works on Bookworm 😊
<details>
<summary><strong>Installation</strong></summary>

If you connect to the Raspberry Pi from remote, make sure to do so via Ethernet an NOT via WiFi as the setup script will create its own WiFi network and thus you won't be connected anymore (and maybe even lock yourself out of your Raspi). Python is installed by default on a Raspberry Pi, so clone this repository and execute the script via:

<sub>Note that the script needs to run as sudo user. Make sure that you agree with the commands executed beforehand by looking into the `.sh` scripts in the folder `access-point/`. Setup script was tested with a fresh install of Raspbian GNU/Linux 11 (bullseye) on the Raspberry Pi 4.</sub>
<sub>Note that the script needs to run as sudo user. Make sure that you agree with the commands executed beforehand by looking into the `.sh` scripts in the folder `access-point/`.</sub>

```
git clone https://github.com/Splines/raspi-captive-portal.git
Expand All @@ -45,7 +48,7 @@ You probably want to use this repo in one of these ways:
<details>
<summary><strong>Connection</strong></summary>

After the installation, you should be able to connect to the new WiFi network called `Splines Raspi AP` using the password `splines-raspi`. You should be redirected to a static welcome page. If you open a "normal" browser, type in any http URL (http**s** URLs are not working) and you should also get redirected to the static page. The URL is supposed to read `splines.portal`.
After the installation, you should be able to connect to the new WiFi network called `Splines Raspi AP` using the password `splinesraspi`. You should be redirected to a static welcome page. If you open a "normal" browser, type in any http URL (http**s** URLs are not working) and you should also get redirected to the static page. The URL is supposed to read `splines.portal` (but visiting any URL should redirect there). From here on you can build your custom captive portal webpage by customizing the code in the `server` folder of this project.

</details>

Expand All @@ -59,7 +62,7 @@ You probably want to use this repo in one of these ways:

- static ip for the raspi: `192.168.4.1/24`
- using `wlan0` as interface
- WiFi: SSID: `Splines Raspi AP`, password: `splines-raspi`, country code: `DE` (change if you are not living in Germany)
- WiFi: SSID: `Splines Raspi AP`, password: `splinesraspi`, country code: `DE` (change if you are not living in Germany)
- Server: port: `3000` (all request on port 80 (http) get redirected to this port), host name: `splines.portal`

</details>
Expand All @@ -72,7 +75,7 @@ If this first assistance does not help, feel free to open a new issue.

**I can't connect to the `Splines Raspi AP` WiFi or get thrown out**

Double check that you've entered the correct password: `splines-raspi`. Also, the Raspberry Pi won't provide Internet acceess to you, it will just serve a static HTML page for the game. This is why you might get thrown out of the WiFi network. If this is the case, there is usually an option to "Use this network without Internet access" (or the like). It might also help to disable mobile data.
Double check that you've entered the correct password: `splinesraspi`. Also, the Raspberry Pi won't provide Internet access to you, it will just serve a static HTML page as captive portal. This is why you might get thrown out of the WiFi network. If this is the case, there is usually an option to "Use this network without Internet access" (or the like). It might also help to disable mobile data.

**How can I use a "normal" browser when I have to click "Cancel" in the captive portal?**

Expand Down Expand Up @@ -120,13 +123,14 @@ sudo systemctl restart access-point-server

<details>
<summary><strong>Dependencies</strong></summary>
This project was developed and tested on the Raspberry Pi 4, Raspbian GNU/Linux 11 (bullseye). Meanwhile, some setup configs might have changed. Feel free to open a pull request with updated config files.
This project was developed and tested on the Raspberry Pi 4, Raspberry Pi OS: Bullseye (11) & Bookworm (12) (64-bit).

These are the principal dependencies used in this project:

*Captive Portal*
- `dhcpcd`: DHCP server (automatically assign IP addresses to clients)
- `hostapd`: Access Point (AP)
- `dnsmasq`: Provide DHCP server (automatically assign IP addresses to clients) and DNS server (name resolution)
- `dnsmasq`: DNS server (name resolution)
- `netfilter-persistent` & `iptables-persistent`: Save firewall rules and restore them when the Raspberry Pi boots

*Node.js Server*
Expand All @@ -137,12 +141,12 @@ sudo systemctl restart access-point-server
<details>
<summary><strong>License</strong></summary>

This program is licensed with the very permissive MIT license, see the [LICENSE file](https://github.com/Splines/raspi-captive-portal/blob/main/LICENSE) for details. As this is only a small project, I don't require you to include the license header in every source file, however you must include it at the root of your project. According to the MIT license you must also include a copyright notice, that is, link back to this project, e.g. in this way:
This program is licensed with the very permissive MIT license, see the [LICENSE file](https://github.com/Splines/raspi-captive-portal/blob/main/LICENSE) for details. As this is only a small project, I don't require you to include the license header in every source file. However, you must include a copyright notice in your project, that is, link back to this project, e.g. in this way:

> [Captive Portal & Access Point setup](https://github.com/Splines/raspi-captive-portal) - Copyright (c) 2022-23 Splines
> [Captive Portal & Access Point setup](https://github.com/Splines/raspi-captive-portal) - Copyright (c) 2022-2024 Splines
Any questions regarding the license? [This FAQ](https://www.tawesoft.co.uk/kb/article/mit-license-faq) might help.

The logo of this project is exempt from the MIT license and you must not use it in any of your work. Icons used in the logo are bought from thenounproject.com ([1](https://thenounproject.com/icon/raspberry-pi-1109535/) and [2](https://thenounproject.com/icon/wifi-170991/)).
The logo of this project is exempt from the MIT license and you must *not* use it in any of your work. Icons used in the logo are bought from thenounproject.com ([1](https://thenounproject.com/icon/raspberry-pi-1109535/) and [2](https://thenounproject.com/icon/wifi-170991/)).

</details>
2 changes: 1 addition & 1 deletion access-point/access-point-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Raspi Access Point Server Service
After=network.target

[Service]
WorkingDirectory=/home/domin/Desktop/dev/new/raspi-captive-portal/server
WorkingDirectory=/this/path/will/be/replaced
ExecStart=/usr/bin/npm start
Restart=on-failure
RestartSec=10
Expand Down
2 changes: 1 addition & 1 deletion access-point/hostapd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=splines-raspi
wpa_passphrase=splinesraspi
12 changes: 8 additions & 4 deletions access-point/setup-access-point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
# https://github.com/TomHumphries/RaspberryPiHotspot

# --- Install
sudo apt update
sudo apt-get update
# dhcpcd is a DHCP client. It should come pre-installed by default, but that
# was not the case for me when installing the new Bookworm Raspi OS. That's
# why we play it safe and install it here (again).
sudo apt-get install -y dhcpcd
# HostAPD access point software and DNS/DHCP via DNSMasq
sudo apt install -y dnsmasq
sudo apt install -y hostapd
sudo apt-get install -y dnsmasq
sudo apt-get install -y hostapd
# Utility to save firewall rules and restoring them when the Pi boots
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y netfilter-persistent iptables-persistent

# Stop services since configuration files are not ready yet
sudo systemctl stop dnsmasq
Expand Down
2 changes: 1 addition & 1 deletion access-point/setup-server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sudo cp ./access-point-server.service /etc/systemd/system
sudo cp ./access-point-server.service /etc/systemd/system/
sudo systemctl enable access-point-server

# Start service immediately
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is NOT published as PyPI package. We just use this file to declare
# some formatting/linting rules.

[tool.pylint."messages control"]
disable = [
"missing-module-docstring",
"missing-function-docstring",
"missing-class-docstring",
]

[tool.pylint.format]
max-line-length = 100
max-module-lines = 500

[tool.black]
line-length = 100
6 changes: 3 additions & 3 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/node": "^18.16.3",
"@types/node": "^20.11.20",
"kill-port": "^2.0.1",
"nodemon": "^2.0.22",
"nodemon": "^3.1.0",
"rimraf": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
Expand All @@ -23,4 +23,4 @@
"build-start": "npm run build && npm run start",
"test": "echo \"This has to be implemented by you. You might want to try out 'mocha' \" && exit 1"
}
}
}
2 changes: 1 addition & 1 deletion server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Yeah, this is the welcome screen, you've made it 🙌</h2>

<p>
<strong>Endpoint /api/ping test: </strong>
<span id="api-endpoint-test">...</span>
<span id="api-endpoint-test">Waiting for server response...</span>
</p>


Expand Down
5 changes: 3 additions & 2 deletions server/public/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const endpointTestParagraph = document.getElementById('api-endpoint-test');

// Try out axios as library, way easier than using the native fetch API
// I recommend to try out axios as library, which is easier to use
// than the native fetch API we're using here.
fetch('/api/ping')
.then(res => {
if (!res.ok) {
Expand All @@ -9,7 +10,7 @@ fetch('/api/ping')
throw err;
}
res.text().then(text => {
p.innerText = text;
endpointTestParagraph.innerText = text;
console.log(`got data: ${text}`);
});
})
Expand Down
Loading

0 comments on commit ead2280

Please sign in to comment.