Skip to content

Commit 43fd781

Browse files
authored
Merge pull request #138 from dappnode/v0.2.3
v0.2.3 Release
2 parents 06e0ccf + d317728 commit 43fd781

61 files changed

Lines changed: 940 additions & 6001 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

VPN-min.png

-5.38 KB
Loading

build/Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ RUN ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \
4343
# (Docker) Necessary dependencies
4444
RUN apk add --no-cache libltdl
4545
RUN ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" && \
46-
ALPINE_GLIBC_PACKAGE_VERSION="2.28-r0" && \
46+
ALPINE_GLIBC_PACKAGE_VERSION="2.30-r0" && \
4747
ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
4848
ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
4949
ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
@@ -96,15 +96,10 @@ ENV EASYRSA=/usr/share/easy-rsa \
9696
OPENVPN_CCD_DIR=$OPENVPN/ccd \
9797
OPENVPN_CRED_PORT=8090 \
9898
# VPN management parameters - Node paths
99-
DB_PATH=/usr/src/app/secrets/vpndb.json \
10099
LOGIN_MSG_PATH=/usr/src/app/secrets/loginMsgFile.txt \
101100
INSTALLATION_STATIC_IP=/usr/src/app/config/static_ip \
102-
KEYPAIR_PATH=/usr/src/app/secrets/keypair \
103-
PUBLIC_IP_PATH=/usr/src/app/secrets/server-ip \
101+
SALT_PATH=/usr/src/app/secrets/salt \
104102
SERVER_NAME_PATH=/etc/vpnname \
105-
INTERNAL_IP_PATH=/usr/src/app/secrets/internal-ip \
106-
EXTERNAL_IP_PATH=/usr/src/app/secrets/external-ip \
107-
PUBLIC_IP_RESOLVED_PATH=/usr/src/app/secrets/public-ip_resolved \
108103
# VPN management parameters - URLs
109104
DYNDNS_HOST=https://ns.dappnode.io \
110105
DYNDNS_DOMAIN=dyndns.dappnode.io \
@@ -122,7 +117,6 @@ VOLUME ["/etc/openvpn"]
122117
EXPOSE 1194/udp
123118

124119
RUN ln -s /usr/src/app/src/getAdminCredentials.js /usr/local/bin/getAdminCredentials && \
125-
ln -s /usr/src/app/src/migrateOldUsers.js /usr/local/bin/migrateOldUsers && \
126120
ln -s /usr/src/app/src/vpncli.js /usr/local/bin/vpncli
127121

128122
ADD build/bin /usr/local/bin

build/bin/ovpn_client_up

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
# Import global variables first
66
source /etc/env.sh
77

8-
SALT=$(jq -r ".salt" ${DB_PATH})
8+
SALT=$(cat ${SALT_PATH})
99
FILE=$(echo -n ${SALT}${common_name} | sha256sum | cut -c -16)
1010

11-
if [ -e ${OPENVPN_CRED_DIR}/${FILE} ]; then
12-
rm ${OPENVPN_CRED_DIR}/${FILE}
11+
if [ -e "${OPENVPN_CRED_DIR}/${FILE}" ]; then
12+
rm "${OPENVPN_CRED_DIR}/${FILE}"
1313
fi
1414

1515
# Reset login text
16-
if [ ${common_name} = ${DEFAULT_ADMIN_USER} ]; then
17-
echo "The admin credentials expired. Use the command below to generate a new download link:" > $LOGIN_MSG_PATH
18-
echo "dappnode_get ${DEFAULT_ADMIN_USER}" >> $LOGIN_MSG_PATH
16+
if [ "${common_name}" = "${DEFAULT_ADMIN_USER}" ]; then
17+
echo "The admin credentials expired. Use the command below to generate a new download link:" > "$LOGIN_MSG_PATH"
18+
echo "dappnode_get ${DEFAULT_ADMIN_USER}" >> "$LOGIN_MSG_PATH"
1919
fi
2020

2121
exit 0

build/bin/ovpn_genconfig

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,16 @@ fi
141141
if [ -z "${EASYRSA_PKI:-}" ]; then
142142
export EASYRSA_PKI="$OPENVPN/pki"
143143
fi
144+
if [ -z "${OVPN_CN:-}" ]; then
145+
export OVPN_CN="dappnode.eth"
146+
fi
147+
144148

145149
OVPN_AUTH=''
146150
OVPN_CIPHER=''
147151
OVPN_CLIENT_TO_CLIENT=''
148-
OVPN_CN=''
152+
#OVPN_CN='' // Don't clear it, grab from entrypoint
153+
OVPN_HOSTNAME='localhost'
149154
OVPN_COMP_LZO=0
150155
OVPN_DEFROUTE=1
151156
OVPN_DEVICE="tun"
@@ -274,7 +279,7 @@ done
274279
# Server name is in the form "udp://vpn.example.com:1194"
275280
if [[ "${OVPN_SERVER_URL:-}" =~ ^((udp|tcp|udp6|tcp6)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
276281
OVPN_PROTO=${BASH_REMATCH[2]};
277-
OVPN_CN=${BASH_REMATCH[3]};
282+
OVPN_HOSTNAME=${BASH_REMATCH[3]};
278283
OVPN_PORT=${BASH_REMATCH[5]};
279284
else
280285
set +x
@@ -288,27 +293,28 @@ set +u
288293
[ -z "$OVPN_DNS_SERVERS" ] && OVPN_DNS_SERVERS=("8.8.8.8" "8.8.4.4")
289294
[ -z "$OVPN_PROTO" ] && OVPN_PROTO=udp
290295
[ -z "$OVPN_PORT" ] && OVPN_PORT=1194
296+
[ -z "$OVPN_HOSTNAME" ] && OVPN_HOSTNAME=localhost
291297
set -u
292298
[ "${#OVPN_ROUTES[@]}" == "0" ] && [ "$OVPN_DEFROUTE" == "1" ] && OVPN_ROUTES+=("192.168.254.0/24")
293299

294-
# Preserve config
295-
if [ -f "$OVPN_ENV" ]; then
296-
bak_env=$OVPN_ENV.$(date +%s).bak
297-
echo "Backing up $OVPN_ENV -> $bak_env"
298-
mv "$OVPN_ENV" "$bak_env"
299-
fi
300+
# Dont' backup, regenerated at every boot
301+
# if [ -f "$OVPN_ENV" ]; then
302+
# bak_env=$OVPN_ENV.$(date +%s).bak
303+
# echo "Backing up $OVPN_ENV -> $bak_env"
304+
# mv "$OVPN_ENV" "$bak_env"
305+
# fi
300306

301307
# Save the current OVPN_ vars to the ovpn_env.sh file
302308
(set | grep '^OVPN_') | while read -r var; do
303309
echo "declare -x $var" >> "$OVPN_ENV"
304310
done
305311

306312
conf=${OPENVPN:-}/openvpn.conf
307-
if [ -f "$conf" ]; then
308-
bak=$conf.$(date +%s).bak
309-
echo "Backing up $conf -> $bak"
310-
mv "$conf" "$bak"
311-
fi
313+
# if [ -f "$conf" ]; then
314+
# bak=$conf.$(date +%s).bak
315+
# echo "Backing up $conf -> $bak"
316+
# mv "$conf" "$bak"
317+
# fi
312318

313319
# Echo extra client configurations
314320
if [ ${#OVPN_EXTRA_CLIENT_CONFIG[@]} -gt 0 ]; then

build/bin/ovpn_getclient

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ nobind
3737
dev $OVPN_DEVICE
3838
remote-cert-tls server
3939
40-
remote $OVPN_CN $OVPN_PORT $OVPN_PROTO"
40+
remote $OVPN_HOSTNAME $OVPN_PORT $OVPN_PROTO"
41+
4142
if [ "$OVPN_PROTO" == "udp6" ]; then
42-
echo "remote $OVPN_CN $OVPN_PORT udp"
43+
echo "remote $OVPN_HOSTNAME $OVPN_PORT udp"
4344
fi
4445
if [ "$OVPN_PROTO" == "tcp6" ]; then
45-
echo "remote $OVPN_CN $OVPN_PORT tcp"
46+
echo "remote $OVPN_HOSTNAME $OVPN_PORT tcp"
4647
fi
4748
for i in "${OVPN_EXTRA_CLIENT_CONFIG[@]}"; do
48-
echo "$i"
49+
echo "$i"
4950
done
5051
if [ "$mode" == "combined" ]; then
5152
echo "
@@ -62,45 +63,45 @@ key-direction 1
6263
<tls-auth>
6364
$(cat $EASYRSA_PKI/ta.key)
6465
</tls-auth>
65-
"
66-
elif [ "$mode" == "separated" ]; then
66+
"
67+
elif [ "$mode" == "separated" ]; then
6768
echo "
6869
key ${cn}.key
6970
ca ca.crt
7071
cert ${cn}.crt
7172
tls-auth ta.key 1
72-
"
73+
"
7374
fi
74-
75+
7576
if [ "$OVPN_DEFROUTE" != "0" ];then
7677
echo "redirect-gateway def1"
7778
fi
78-
79+
7980
if [ -n "$OVPN_MTU" ]; then
8081
echo "tun-mtu $OVPN_MTU"
8182
fi
82-
83+
8384
if [ -n "$OVPN_TLS_CIPHER" ]; then
8485
echo "tls-cipher $OVPN_TLS_CIPHER"
8586
fi
86-
87+
8788
if [ -n "$OVPN_CIPHER" ]; then
8889
echo "cipher $OVPN_CIPHER"
8990
fi
90-
91+
9192
if [ -n "$OVPN_AUTH" ]; then
9293
echo "auth $OVPN_AUTH"
9394
fi
94-
95+
9596
if [ -n "$OVPN_OTP_AUTH" ]; then
9697
echo "auth-user-pass"
9798
echo "auth-nocache"
9899
fi
99-
100+
100101
if [ "$OVPN_COMP_LZO" == "1" ]; then
101102
echo "comp-lzo"
102103
fi
103-
104+
104105
if [ -n "$OVPN_OTP_AUTH" ]; then
105106
echo reneg-sec 0
106107
fi
@@ -115,18 +116,18 @@ case "$parm" in
115116
cp "$EASYRSA_PKI/ca.crt" "$dir/ca.crt"
116117
cp "$EASYRSA_PKI/issued/${cn}.crt" "$dir/${cn}.crt"
117118
cp "$EASYRSA_PKI/ta.key" "$dir/ta.key"
118-
;;
119+
;;
119120
"" | "combined")
120121
get_client_config "combined"
121-
;;
122+
;;
122123
"combined-save")
123124
mkdir -p "$dir"
124125
get_client_config "combined" > "$dir/${cn}-combined.ovpn"
125-
;;
126+
;;
126127
*)
127128
echo "This script can produce the client configuration in two formats:" >&2
128129
echo " 1. combined (default): All needed configuration and cryptographic material is in one file (Use \"combined-save\" to write the configuration file in the same path as the separated parameter does)." >&2
129130
echo " 2. separated: Separated files." >&2
130131
echo "Please specify one of those options as second parameter." >&2
131-
;;
132+
;;
132133
esac

build/src/entrypoint.sh

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,44 @@
22

33
# Initialize APP
44
echo "Initializing App..."
5-
node src/initializeApp.js
6-
echo "Initialized App"
75

8-
# Check in db if node has a static IP, use dynamic DNS domain instead.
9-
export PUBLIC_ENDPOINT="$(node src/getPublicEndpointCommand)"
10-
echo "Fetched public endpoint: $PUBLIC_ENDPOINT"
11-
VPNHOSTNAME=${PUBLIC_ENDPOINT}
6+
[ -z "$_DAPPNODE_GLOBAL_HOSTNAME" ] || echo "Global variables not loaded yet. Waiting to be restarted by DAPPMANAGER..."
7+
while [ -z "$_DAPPNODE_GLOBAL_HOSTNAME" ]; do
8+
sleep 5
9+
done
10+
[ -n "$_DAPPNODE_GLOBAL_HOSTNAME" ] || echo "Public hostname loaded: ${_DAPPNODE_GLOBAL_HOSTNAME}"
11+
# check and generate random seed
12+
if [ ! -f "${SALT_PATH}" ]; then
13+
head /dev/urandom | tr -dc a-f0-9 | head -c 16 > "${SALT_PATH}"
14+
fi
15+
OVPN_CN="${_DAPPNODE_GLOBAL_HOSTNAME}"
16+
export OVPN_CN
17+
echo "Initialized App"
1218

13-
# Initialize config and PKI
19+
# Initialize config and PKI
1420
# -c: Client to Client
1521
# -d: disable default route (disables NAT without '-N')
1622
# -p "route 172.33.0.0 255.255.0.0": Route to push to the client
17-
18-
if [ ! -e "${OPENVPN_CONF}" ]; then
19-
ovpn_genconfig -c -d -u udp://${VPNHOSTNAME} -s 172.33.8.0/22 \
20-
-p "route 172.33.0.0 255.255.0.0" \
21-
-n "172.33.1.2"
22-
EASYRSA_REQ_CN=${VPNHOSTNAME} ovpn_initpki nopass
23+
# -n "172.33.1.2": DNS server (BIND)
24+
ovpn_genconfig -c -d -u udp://"${_DAPPNODE_GLOBAL_HOSTNAME}" -s 172.33.8.0/22 \
25+
-p "route 172.33.0.0 255.255.0.0" -n "172.33.1.2"
26+
27+
# check if PKI is initalized already, if not use hostname as CN
28+
if [ ! -d "${OPENVPN}/pki/reqs" ] || [ ! "$(ls -A ${OPENVPN}/pki/reqs)" ]; then
29+
echo "Initializing PKI"
30+
EASYRSA_REQ_CN=${OVPN_CN} ovpn_initpki nopass
2331
fi
2432

2533
# Create admin user
2634
if [ ! -e "${OPENVPN_ADMIN_PROFILE}" ]; then
27-
vpncli add ${DEFAULT_ADMIN_USER}
28-
vpncli get ${DEFAULT_ADMIN_USER}
29-
echo "ifconfig-push 172.33.10.1 255.255.252.0" > ${OPENVPN_CCD_DIR}/${DEFAULT_ADMIN_USER}
35+
vpncli add "${DEFAULT_ADMIN_USER}"
36+
vpncli get "${DEFAULT_ADMIN_USER}"
37+
echo "ifconfig-push 172.33.10.1 255.255.252.0" > "${OPENVPN_CCD_DIR}/${DEFAULT_ADMIN_USER}"
3038
fi
3139

3240
# Enable Proxy ARP (needs privileges)
3341
echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
3442

35-
# Migrate users from v1
36-
migrateOldUsers
37-
3843
# Save environment
3944
env | sed '/affinity/d' > /etc/env.sh
4045

build/src/package.json

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,27 @@
1717
"author": "dappLion & vdo",
1818
"license": "ISC",
1919
"dependencies": {
20-
"autobahn": "^18.10.2",
21-
"base64url": "^3.0.0",
20+
"autobahn": "^19.9.2",
2221
"chalk": "^2.4.2",
23-
"cmd": "^0.1.0",
24-
"create-error": "^0.3.1",
25-
"eth-crypto": "^1.2.4",
26-
"file-system": "^2.2.2",
27-
"generate-password": "^1.4.1",
28-
"is-ip": "^2.0.0",
22+
"commander": "^3.0.1",
2923
"ip": "^1.1.5",
30-
"ip-regex": "^3.0.0",
31-
"lowdb": "^1.0.0",
32-
"node-fetch": "^2.1.2",
24+
"is-ip": "^3.1.0",
25+
"node-fetch": "^2.6.0",
3326
"prettyjson": "^1.2.1",
3427
"qrcode-terminal": "^0.12.0",
35-
"tweetnacl": "^1.0.0",
36-
"winston": "^3.0.0"
28+
"tweetnacl": "^1.0.1",
29+
"winston": "^3.2.1"
3730
},
3831
"devDependencies": {
3932
"chai": "^4.1.2",
40-
"coveralls": "^3.0.2",
41-
"eslint": "^5.16.0",
33+
"coveralls": "^3.0.6",
34+
"eslint": "^6.4.0",
4235
"husky": "^1.3.1",
43-
"mocha": "^5.2.0",
44-
"nyc": "^12.0.2",
36+
"mocha": "^6.2.0",
37+
"nyc": "^14.1.1",
4538
"prettier": "^1.16.4",
46-
"proxyquire": "^2.1.0",
47-
"sinon": "^5.1.0",
39+
"proxyquire": "^2.1.3",
40+
"sinon": "^7.4.2",
4841
"sinon-chai": "^3.1.0"
4942
},
5043
"husky": {

build/src/src/calls/addDevice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function addDevice({ id }) {
2424
);
2525
}
2626

27-
let userArray = await getUserList();
27+
const userArray = await getUserList();
2828

2929
if (userArray.length >= userLimit) {
3030
throw Error(`You have reached the maximum user limit (${userLimit})`);

0 commit comments

Comments
 (0)