Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ytl-linux-digabi2-examnet/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME := ytl-linux-digabi2-examnet
VERSION := 0.0.19
VERSION := 0.0.20

DEPENDENCIES := \
--depends apt \
Expand Down
54 changes: 42 additions & 12 deletions packages/ytl-linux-digabi2-examnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@

This is a proof-of-concept of a procedure which creates proper network settings
for Abitti 2 exam server. The setup requires that the server has two network devices
* A WAN device connected to the internet. At the moment this is used to get a
SSL certificate and DNS address for the server. According to the initial plans
it might be later used e.g. to download exam items and upload candidate data.
At the moment a wireless device is good enough for a WAN connection.
* A LAN device connected to the closed local area network. This is an Abitti 1
style network without any external DHCP/DNS servers. After executing the script
the server starts working as a DHCP/DNS server for the LAN.

- A WAN device connected to the internet. At the moment this is used to get a
SSL certificate and DNS address for the server. According to the initial plans
it might be later used e.g. to download exam items and upload candidate data.
At the moment a wireless device is good enough for a WAN connection.
- A LAN device connected to the closed local area network. This is an Abitti 1
style network without any external DHCP/DNS servers. After executing the script
the server starts working as a DHCP/DNS server for the LAN.

## Usage

The script is executed from command line:

`$ sudo ytl-linux-digabi2-examnet`
```bash
sudo ytl-linux-digabi2-examnet
```

If executed without parameters, it asks the WAN and LAN devices as well as the
server number. It is possible to run multiple servers in one LAN but they must have
different server numbers.

It is possible to supply the three parameters in command line:

`ytl-linux-digabi2-examnet wan-device lan-device server-number`
```bash
ytl-linux-digabi2-examnet wan-device lan-device server-number`
```

Example:

`$ sudo ytl-linux-digabi2-examnet wlo1 eth0 1`
```bash
sudo ytl-linux-digabi2-examnet wlo1 eth0 1
```

It is also possible to run the script in GUI mode (parameter `--gui`). In this case the
parameters are asked with Zenity.
Expand All @@ -37,7 +44,9 @@ parameters are asked with Zenity.

Following command should restore the system to pristine state:

`$ sudo ytl-linux-digabi2-examnet --remove`
```bash
sudo ytl-linux-digabi2-examnet --remove
```

It removes the settings files created by this script. It also removes all NetworkManager
connections which have a name starting with `yo-`. This is the prefix used by the
Expand All @@ -47,6 +56,27 @@ script to create the static connection for the local network.

The debugging messages can be printed to a given file:

`$ DEBUG=/tmp/whatta.log sudo ytl-linux-digabi2-examnet`
```bash
DEBUG=/tmp/whatta.log sudo ytl-linux-digabi2-examnet
```

The list of exit codes can be found in the script.

## Building locally

For macOS, install fpm e.g. with Ruby gem:

```bash
# Install Ruby and gem, set path
brew install ruby
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="$(gem environment gemdir)/bin:$PATH"' >> ~/.zshrc
# Install fpm
gem install fpm
```

Then build the Debian package:

```bash
make deb
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"dns": ["${DOCKER_BRIDGE_NETWORK_DNS_RESOLVER_IP}"]
"dns": ["${DOCKER_NETWORK_DNS_RESOLVER_IP}"],
"default-address-pools":
[
{"base": "${DOCKER_NETWORK_POOL_BASE_IP}/16", "size":26}
]
}
36 changes: 26 additions & 10 deletions packages/ytl-linux-digabi2-examnet/ytl-linux-digabi2-examnet
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ readonly PARAM_SERVER_NUMBER=$3
readonly PARAM_SERVER_FRIENDLY_NAME=$4

readonly NETWORK_DEVICE_FILTER_RE="^docker|^br|^veth|^lo$"
readonly DOCKER_BRIDGE_NETWORK_DNS_RESOLVER_IP="172.17.0.1"

readonly PATH_TEMPLATES=/etc/ytl-linux-digabi2-examnet/templates
readonly PATH_RESOLVED=/etc/systemd/resolved.conf.d
Expand Down Expand Up @@ -283,14 +282,27 @@ function check_server_number() {
fi
}

function get_lan_ip_prefix() {
_IP_WAN=$1
function get_ip_prefix() {
echo "${1%.*.*}."
}

if [[ "$_IP_WAN" =~ ^192\.168\. ]]; then
$BIN_ECHO "10.0."
else
$BIN_ECHO "192.168."
fi
function get_available_ip_range() {
_ALLOWED_IP_RANGES=("10.0." "192.168." "172.17.")

for range in "${_ALLOWED_IP_RANGES[@]}"; do
_USED=false
for reserved in "$@"; do
if [[ $reserved == $range* ]]; then
_USED=true
break
fi
done
if [[ "$_USED" == false ]]; then
# return the first available
echo "$range"
return
fi
done
}

function write_file() {
Expand Down Expand Up @@ -674,10 +686,14 @@ export IP_WAN
export IP_LAN
export SERVER_NUMBER

IP_LAN_PREFIX=$(get_lan_ip_prefix "$IP_WAN")
IP_LAN_PREFIX=$(get_ip_prefix "$IP_LAN")
export IP_LAN_PREFIX

export DOCKER_BRIDGE_NETWORK_DNS_RESOLVER_IP
DOCKER_NETWORK_PREFIX=$(get_available_ip_range "$IP_WAN" "$IP_LAN")
DOCKER_NETWORK_DNS_RESOLVER_IP="$DOCKER_NETWORK_PREFIX".0.1
export DOCKER_NETWORK_DNS_RESOLVER_IP
DOCKER_NETWORK_POOL_BASE_IP="$DOCKER_NETWORK_PREFIX".0.0
export DOCKER_NETWORK_POOL_BASE_IP

debug "SUBNETS_PER_SERVER: $CONST_SUBNETS_PER_SERVER"

Expand Down