diff --git a/.gitignore b/.gitignore index d202f91..c84092f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ *.pyc static/static_root images/ +manager/hostname.py diff --git a/device-config/1/bin/heartbeat b/device-config/1/bin/heartbeat index 4cc35ab..9f0c44f 100755 --- a/device-config/1/bin/heartbeat +++ b/device-config/1/bin/heartbeat @@ -22,7 +22,7 @@ restartwifi(){ . /etc/vpnsecret -/usr/bin/wget -O/etc/hosts https://admin360.kumi.host/hosts --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1 +/usr/bin/wget -O/etc/hosts https://$HOSTNAME/hosts --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1 /sbin/uci set wireless.@wifi-iface[0].network="VPN360" /sbin/uci commit @@ -40,7 +40,7 @@ if [ $(ipaddr) ] sleep 10 if [ $(ipaddr) ] then - /usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash + /usr/bin/wget -O- https://$HOSTNAME/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash fi done else @@ -53,7 +53,7 @@ if [ $(ipaddr) ] while [ True ] do sleep 10 - /usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget | /bin/ash + /usr/bin/wget -O- https://$HOSTNAME/heartbeat --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget | /bin/ash done fi diff --git a/device-config/2/bin/heartbeat b/device-config/2/bin/heartbeat index d21601f..0605914 100755 --- a/device-config/2/bin/heartbeat +++ b/device-config/2/bin/heartbeat @@ -62,7 +62,7 @@ counter=0 while [ $counter -lt 60 ] do # Retrieve hosts file from server - if /usr/bin/wget -O/etc/hosts https://admin360.kumi.host/hosts --timeout=2 --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1 + if /usr/bin/wget -O/etc/hosts https://$HOSTNAME/hosts --timeout=2 --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1 then if pgrep "openvpn" >/dev/null @@ -87,7 +87,7 @@ while [ $counter -lt 60 ] # We assume that users will reboot the device if it doesn't work for extended periods of time if [ $(ipaddr) ] then - /usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash + /usr/bin/wget -O- https://$HOSTNAME/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash fi done @@ -122,6 +122,6 @@ startwifi while [ True ] do sleep 10 - /usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget | /bin/ash + /usr/bin/wget -O- https://$HOSTNAME/heartbeat --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget | /bin/ash done diff --git a/manager/hostname.dist.py b/manager/hostname.dist.py new file mode 100644 index 0000000..f3baf77 --- /dev/null +++ b/manager/hostname.dist.py @@ -0,0 +1 @@ +hostname="no.hostname.set" diff --git a/manager/tasks.py b/manager/tasks.py index d1d136d..8d57268 100644 --- a/manager/tasks.py +++ b/manager/tasks.py @@ -2,6 +2,7 @@ from celery import shared_task from distutils.dir_util import copy_tree from .views import makewificonfig +from .hostname import hostname import os import time @@ -38,7 +39,7 @@ def mkfirmware(device, path): # Write secret with open(tempdir.name + "/etc/vpnsecret", "w") as secret: - secret.write('SECRET="%s"' % device.secret) + secret.write('SECRET="%s"\nHOSTNAME="%s"' % (device.secret, hostname) # Write password diff --git a/setup.sh b/setup.sh index 7b10a0b..653815e 100644 --- a/setup.sh +++ b/setup.sh @@ -25,9 +25,11 @@ chmod +x misc/make_config sudo cp misc/make_config misc/base.conf /etc/openvpn/client-configs openvpn --genkey --secret /etc/openvpn/ca/keys/ta.key sudo chown vpn.vpn /etc/openvpn/client-configs -R +cp manager/hostname.dist.py manager/hostname.py +sudo chown vpn.vpn . -R sudo systemctl daemon-reload sudo systemctl enable vpnmanager sudo systemctl start vpnmanager sudo systemctl enable celery sudo systemctl start celery -echo "This should be working so far. Now point your webserver to uwsgi.sock using its WSGI options. Be sure to include the static files at static/static_root/" +echo "This should be working so far. Now point your webserver to uwsgi.sock using its WSGI options. Be sure to include the static files at static/static_root/ and don't forget to set the hostname in manager/hostname.py"