summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile48
-rw-r--r--README.md26
-rw-r--r--branding/README.txt28
-rw-r--r--branding/assets/riseup/riseupvpn.icnsbin0 -> 1359609 bytes
-rwxr-xr-xbranding/scripts/check-ca-crt.py1
-rwxr-xr-xbranding/scripts/generate-osx.py44
-rwxr-xr-xbranding/scripts/generate-vendor-make.py58
-rwxr-xr-xbranding/templates/makefile/Makefile129
-rw-r--r--branding/templates/osx/bitmask.pf.conf19
-rwxr-xr-xbranding/templates/osx/client.down.sh426
-rwxr-xr-xbranding/templates/osx/client.up.sh1522
-rw-r--r--branding/templates/osx/cross-compile.txt11
-rw-r--r--branding/templates/osx/generate.py153
-rwxr-xr-xbranding/templates/osx/quickpkg557
-rw-r--r--branding/templates/osx/signbundle11
-rw-r--r--branding/templates/osx/template-helper.plist26
-rw-r--r--branding/templates/osx/template-info.plist34
-rw-r--r--branding/templates/osx/template-postinstall14
-rw-r--r--branding/templates/osx/template-preinstall12
-rwxr-xr-xbranding/templates/windows/generate.py3
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--pkg/config/config.go2
-rw-r--r--pkg/helper/darwin.go10
24 files changed, 3109 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index d3568d2..8661568 100644
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,26 @@ PROVIDER_CONFIG ?= branding/config/vendor.conf
DEFAULT_PROVIDER = branding/assets/default/
VERSION ?= $(shell git describe)
+# detect OS, we use it for dependencies
+UNAME = `uname`
+
all: icon locales get build
+depends:
+ -@make depends$(UNAME)
+ go get -u golang.org/x/text/cmd/gotext github.com/cratonica/2goarray
+
+dependsLinux:
+ sudo apt install libgtk-3-dev libappindicator3-dev golang pkg-config cmake
+
+dependsDarwin:
+ # TODO - bootstrap homebrew if not there
+ brew install python3 golang make pkg-config upx
+ brew install --default-names gnu-sed
+
+dependsCygwin:
+ choco install -y golang python nssm nsis wget 7zip
+
get:
go get -tags $(TAGS) ./...
go get -tags "$(TAGS) bitmaskd" ./...
@@ -24,18 +42,32 @@ endif
prepare: generate relink_default
mkdir -p build/${PROVIDER}/bin/
+ cp branding/templates/makefile/Makefile build/${PROVIDER}/Makefile
+ VERSION=${VERSION} PROVIDER_CONFIG=${PROVIDER_CONFIG} branding/scripts/generate-vendor-make.py build/${PROVIDER}/vendor.mk
branding/scripts/check-ca-crt.py ${PROVIDER} ${PROVIDER_CONFIG}
+ -@make icon
prepare_win:
mkdir -p build/${PROVIDER}/windows/
cp -r branding/templates/windows build/${PROVIDER}
VERSION=${VERSION} PROVIDER_CONFIG=${PROVIDER_CONFIG} branding/scripts/generate-win.py build/${PROVIDER}/windows/data.json
cd build/${PROVIDER}/windows && python3 generate.py
- # TODO create build/PROVIDER/assets/
- # TODO create build/PROVIDER/staging/
+ # TODO create/copy build/PROVIDER/assets/
+ # TODO create/copy build/PROVIDER/staging/
prepare_osx:
- echo "osx..."
+ mkdir -p build/${PROVIDER}/osx/scripts
+ mkdir -p build/${PROVIDER}/staging
+ifeq (,$(wildcard build/${PROVIDER}/assets))
+ ln -s ../../branding/assets/default build/${PROVIDER}/assets
+endif
+ifeq (,$(wildcard build/${PROVIDER}/staging/openvpn-osx))
+ curl -L https://downloads.leap.se/thirdparty/osx/openvpn/openvpn -o build/${PROVIDER}/staging/openvpn-osx
+endif
+ cp -r branding/templates/osx build/${PROVIDER}
+ VERSION=${VERSION} PROVIDER_CONFIG=${PROVIDER_CONFIG} branding/scripts/generate-osx.py build/${PROVIDER}/osx/data.json
+ cd build/${PROVIDER}/osx && python3 generate.py
+ cd build/${PROVIDER}/osx/scripts && chmod +x preinstall postinstall
prepare_snap:
echo "snap..."
@@ -49,9 +81,12 @@ build: $(foreach path,$(wildcard cmd/*),build_$(patsubst cmd/%,%,$(path)))
build_%:
go build -tags $(TAGS) -ldflags "-X main.version=`git describe --tags`" -o $* ./cmd/$*
- strip $*
+ # FIXME does not work in osx
+ # strip $*
mkdir -p build/bin
mv $* build/bin/
+ mkdir -p build/${PROVIDER}/staging
+ ln -s ../../bin/$* build/${PROVIDER}/staging/$*
test:
go test -tags "integration $(TAGS)" ./...
@@ -64,15 +99,12 @@ build_win:
clean:
make -C icon clean
- rm -f build/bitmask-vpn
+ rm -f build/${PROVIDER}/bin/bitmask-*
unlink branding/assets/default
icon:
make -C icon
-get_deps:
- sudo apt install libgtk-3-dev libappindicator3-dev golang pkg-config
-
LANGS ?= $(foreach path,$(wildcard locales/*),$(patsubst locales/%,%,$(path)))
empty :=
diff --git a/README.md b/README.md
index 986f779..b0cd740 100644
--- a/README.md
+++ b/README.md
@@ -3,15 +3,14 @@ Install it
Install dependencies:
```
- # apt install libgtk-3-dev libappindicator3-dev golang pkg-config
+ # make depends
```
Build the systray:
```
- $ git clone 0xacab.org/leap/bitmask-vpn
- $ cd bitmask-systray
- $ go get .
- $ go build
+ $ git clone 0xacab.org/leap/bitmask-vpn && cd bitmask-vpn
+ $ make get
+ $ make build
```
To be able to build the assets you'll need:
@@ -24,12 +23,10 @@ OSX
Using homebrew:
```
- $ brew install golang zmq pkg-config
- $ brew install --default-names gnu-sed
- $ git clone 0xacab.org/leap/bitmask-vpn
- $ cd bitmask-systray
- $ go get .
- $ go build
+ $ make depends
+ $ git clone 0xacab.org/leap/bitmask-vpn && cd bitmask-vpn
+ $ make get
+ $ make build
```
@@ -56,8 +53,8 @@ for windows and OSX there is [a helper written in go](https://0xacab.org/leap/bi
To build and run it:
```
- $ go build
- $ ./bitmask-systray
+ $ make build
+ $ ./bitmask-vpn
```
@@ -71,7 +68,7 @@ Is also posible to compile the systray to use bitmask as backend:
In that case bitmask-systray assumes that you already have bitmaskd running. Run bitmask and the systray:
```
$ bitmaskd
- $ ./bitmask-systray
+ $ ./bitmask-vpn
```
@@ -97,6 +94,7 @@ Report an issue
-------------------
When you report an issue include the following information:
+
* what you expected to see
* what you got
* the version of the program. You can check the version on the about page.
diff --git a/branding/README.txt b/branding/README.txt
index dea4d76..c3d9482 100644
--- a/branding/README.txt
+++ b/branding/README.txt
@@ -12,21 +12,41 @@ Configure
- Copy your provider CA certificate to the same folder: 'branding/config/<provider>-ca.crt'
- Make sure that the folder 'branding/assets/<provider>' exists. Copy there all the needed assets.
+Checkout
+--------------------------------------------------------------------------------
+
+git clone https://0xacab.org/leap/bitmask-vpn
+cd bitmask-vpn
+git pull --tags
+
Build
--------------------------------------------------------------------------------
-Some of the following scripts need network access, since they will check
+make build
+
+
+Package
+--------------------------------------------------------------------------------
+
+NOTE: Some of the following scripts need network access, since they will check
whether the configuration published by your provider matches what is configured
before the build.
Run:
-PROVIDER=example.org make prepare
-make build
+PROVIDER=example make prepare_all
You can also specify a cusom config file:
-PROVIDER=example.org PROVIDER_CONFIG make prepare
+PROVIDER=example PROVIDER_CONFIG=/path/to/vendor.conf make prepare_all
make build
+After this, you will find the build scripts ready in the following folder:
+
+cd build/example
+
+make package_win
+make package_osx
+make package_snap
+make package_deb
diff --git a/branding/assets/riseup/riseupvpn.icns b/branding/assets/riseup/riseupvpn.icns
new file mode 100644
index 0000000..b4c9a20
--- /dev/null
+++ b/branding/assets/riseup/riseupvpn.icns
Binary files differ
diff --git a/branding/scripts/check-ca-crt.py b/branding/scripts/check-ca-crt.py
index 431d059..dbf9b40 100755
--- a/branding/scripts/check-ca-crt.py
+++ b/branding/scripts/check-ca-crt.py
@@ -20,6 +20,7 @@ def getLocalCert(provider):
def getRemoteCert(uri):
+ print("... checking cert from", uri)
fp = urllib.request.urlopen(uri)
remote_cert = fp.read().decode('utf-8').strip()
fp.close()
diff --git a/branding/scripts/generate-osx.py b/branding/scripts/generate-osx.py
new file mode 100755
index 0000000..4430762
--- /dev/null
+++ b/branding/scripts/generate-osx.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+import json
+import os
+import sys
+
+import configparser
+
+from provider import getDefaultProvider
+from provider import getProviderData
+
+
+VERSION = os.environ.get('VERSION', 'unknown')
+
+
+def writeOutput(data, outfile):
+
+ with open(outfile, 'w') as outf:
+ outf.write(json.dumps(data))
+
+
+if __name__ == "__main__":
+ env_provider_conf = os.environ.get('PROVIDER_CONFIG')
+ if env_provider_conf:
+ if os.path.isfile(env_provider_conf):
+ print("[+] Overriding provider config per "
+ "PROVIDER_CONFIG variable")
+ configfile = env_provider_conf
+
+ config = configparser.ConfigParser()
+ config.read(configfile)
+ provider = getDefaultProvider(config)
+ data = getProviderData(provider, config)
+
+ if len(sys.argv) != 2:
+ print('Usage: generate-osx.py <output_file>')
+ sys.exit(1)
+
+ outputf = sys.argv[1]
+
+ data['applicationNameLower'] = data.get('applicationName').lower()
+ data['URL'] = data.get('infoURL')
+ data['version'] = VERSION
+ writeOutput(data, outputf)
diff --git a/branding/scripts/generate-vendor-make.py b/branding/scripts/generate-vendor-make.py
new file mode 100755
index 0000000..e7794c3
--- /dev/null
+++ b/branding/scripts/generate-vendor-make.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+# Generates a simplified file with variables that
+# can be imported from the main vendorized Makefile.
+
+import os
+import sys
+
+import configparser
+
+from provider import getDefaultProvider
+from provider import getProviderData
+
+
+VERSION = os.environ.get('VERSION', 'unknown')
+
+TEMPLATE = """
+# Variables for the build of {applicationName}.
+# Generated automatically. Do not edit.
+APPNAME := {applicationName}
+BINNAME := {binaryName}
+VERSION := {version}
+"""
+
+
+def writeOutput(data, outfile):
+
+ configString = TEMPLATE.format(
+ binaryName=data['binaryName'],
+ applicationName=data['applicationName'],
+ version=data['version'],
+ )
+
+ with open(outfile, 'w') as outf:
+ outf.write(configString)
+
+
+if __name__ == "__main__":
+ env_provider_conf = os.environ.get('PROVIDER_CONFIG')
+ if env_provider_conf:
+ if os.path.isfile(env_provider_conf):
+ print("[+] Overriding provider config per "
+ "PROVIDER_CONFIG variable")
+ configfile = env_provider_conf
+
+ config = configparser.ConfigParser()
+ config.read(configfile)
+ provider = getDefaultProvider(config)
+ data = getProviderData(provider, config)
+
+ if len(sys.argv) != 2:
+ print('Usage: generate-vendor-make.py <output_file>')
+ sys.exit(1)
+
+ outputf = sys.argv[1]
+ data['version'] = VERSION
+
+ writeOutput(data, outputf)
diff --git a/branding/templates/makefile/Makefile b/branding/templates/makefile/Makefile
new file mode 100755
index 0000000..698b51f
--- /dev/null
+++ b/branding/templates/makefile/Makefile
@@ -0,0 +1,129 @@
+#########################################
+# (c) LEAP Encryption Access Project 2018
+include vendor.mk
+#########################################
+
+#
+# TODO review some of these targets, can go in the parent makefile
+#
+
+SYSTRAY := 0xacab.org/leap/bitmask-vpn
+STAGING := staging
+SYSTRAY_BIN := bitmask-vpn
+HELPER_BIN := bitmask_helper
+BUILD_RELEASE?=no
+WIN_CERT_PATH?=z:\leap\LEAP.pfx
+WIN_CERT_PASS?=
+OSX_CERT = "Developer ID Installer: LEAP Encryption Access Project"
+
+TGZ_PATH = $(shell pwd)/dist/$(BINNAME)-$(VERSION)
+tgz:
+ mkdir -p $(TGZ_PATH)
+ git -C `go env GOPATH`/src/$(SYSTRAY) archive HEAD | tar -x -C $(TGZ_PATH)
+ mkdir $(TGZ_PATH)/helpers
+ wget -O $(TGZ_PATH)/helpers/bitmask-root https://0xacab.org/leap/bitmask-dev/raw/master/src/leap/bitmask/vpn/helpers/linux/bitmask-root
+ chmod +x $(TGZ_PATH)/helpers/bitmask-root
+ wget -O $(TGZ_PATH)/helpers/se.leap.bitmask.policy https://0xacab.org/leap/bitmask-dev/raw/master/src/leap/bitmask/vpn/helpers/linux/se.leap.bitmask.policy
+ cd dist; tar cvzf $(BINNAME)-$(VERSION).tgz $(BINNAME)-$(VERSION)
+ rm -r $(TGZ_PATH)
+
+# -----------------------------------------------------------------------------
+# Windows
+# -----------------------------------------------------------------------------
+CROSS_FLAGS = CGO_ENABLED=1 GOARCH=386 GOOS=windows CC="/usr/bin/i686-w64-mingw32-gcc" CGO_LDFLAGS="-lssp" CXX="i686-w64-mingw32-c++"
+
+openvpn_win:
+ if not exist staging\openvpn mkdir staging\openvpn
+ wget https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe -O staging/openvpn/tap-windows.exe
+# eventually, this should be built statically and cross compiled in the same pipeline that we build the installer.
+ wget https://downloads.leap.se/thirdparty/windows/openvpn-x86_64-w64-mingw32.tar.bz2 -O staging/openvpn/openvpn.tar.bz2
+ 7z e -y -ostaging/openvpn/ staging/openvpn/openvpn.tar.bz2
+ 7z e -y -r -ostaging/openvpn/ staging/openvpn/openvpn.tar *.dll
+ 7z e -y -r -ostaging/openvpn/ staging/openvpn/openvpn.tar *.exe
+ copy .\staging\openvpn\openvpn.exe .\staging
+ copy .\staging\openvpn\*.dll .\staging
+openvpn_cross_win:
+ mkdir -p staging/openvpn
+ wget https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe -O $(STAGING)/openvpn/tap-windows.exe
+ wget https://downloads.leap.se/thirdparty/windows/openvpn-x86_64-w64-mingw32.tar.bz2 -O $(STAGING)/openvpn/openvpn.tar.bz2
+ tar xvjf $(STAGING)/openvpn/openvpn.tar.bz2 -C $(STAGING)/openvpn/
+ cp $(STAGING)/openvpn/bin/openvpn.exe $(STAGING)/openvpn
+ cp $(STAGING)/openvpn/bin/*.dll $(STAGING)
+ cp $(STAGING)/openvpn/lib/engines-1_1/*.dll $(STAGING)
+helper_win:
+ go build -ldflags "-s -w" -o $(STAGING)/$(HELPER_BIN).exe $(SYSTRAY)/cmd/bitmask-helper
+systray_win:
+ go get -u $(SYSTRAY)/cmd/bitmask-vpn
+ powershell '$$gopath=go env GOPATH;$$version=git -C $$gopath/src/$(SYSTRAY) describe --tags; go build -ldflags "-H windowsgui -s -w -X main.version=$$version" -o $(STAGING)/$(SYSTRAY_BIN).exe $(SYSTRAY)/cmd/bitmask-vpn'
+build_win: staging\nssm.exe helper_win systray_win
+# since it's tedious, I assume you did bootstrap openvpn_win manually already.
+ echo "[+] building windows"
+ if not exist dist mkdir dist
+ powershell '$$gopath=go env GOPATH;$$version=git -C $$gopath/src/$(SYSTRAY) describe --tags; $(MAKE) -C win VERSION=$$version'
+ "C:\Program Files (x86)\NSIS\makensis.exe" win/RiseupVPN-installer.nsi
+sign_win:
+ echo "[+] signing windows build"
+ python win/sign.py $(WIN_CERT_PATH) $(WIN_CERT_PASS)
+build_cross_win: staging/nssm.exe
+ echo "!define VERSION $(VERSION)" > $(STAGING)/version.nsh
+ $(CROSS_FLAGS) $(MAKE) helper_win
+ $(CROSS_FLAGS) go get $(SYSTRAY)/cmd/bitmask-vpn
+ $(CROSS_FLAGS) go build -ldflags "-H windowsgui -s -w -X main.version=$(VERSION)" -o $(STAGING)/$(SYSTRAY_BIN).exe $(SYSTRAY)/cmd/bitmask-vpn
+ mkdir -p dist
+ make -C win VERSION=$(VERSION)
+ makensis win/RiseupVPN-installer.nsi
+
+# -----------------------------------------------------------------------------
+# OSX
+# -----------------------------------------------------------------------------
+
+package_osx:
+ echo "[+] Building osx package..."
+ osx/quickpkg --output dist/$(APPNAME)-$(VERSION)_unsigned.pkg --scripts osx/scripts/ dist/$(APPNAME).app/
+ @if [ $(BUILD_RELEASE) = no ]; then\
+ echo "[!] BUILD_RELEASE=no, skipping signature";\
+ else\
+ echo "[+] Signing the bundle";\
+ productsign --sign $(OSX_CERT) dist/$(APPNAME)-$(VERSION)_unsigned.pkg dist/$(APPNAME)-$(VERSION).pkg;\
+ fi
+
+# -----------------------------------------------------------------------------
+# Linux
+# -----------------------------------------------------------------------------
+
+build_snap:
+ echo "[+] building snap..."
+ snapcraft build
+ snapcraft snap
+ mkdir -p dist
+ mv $(BINNAME)* dist/
+
+build_deb: tgz
+ echo "[+] building deb..."
+ @if [ $(BUILD_RELEASE) = no ]; then\
+ dch -v $(VERSION) -M "debian package generated from the git repository" && echo "[!] BUILD_RELEASE=no, incrementing changelog";\
+ else\
+ echo "[!] BUILD_RELEASE";\
+ fi
+ mkdir -p build
+ cp dist/$(BINNAME)-$(VERSION).tgz build/$(BINNAME)_$(shell echo ${VERSION} | cut -d '-' -f 1-2).orig.tar.gz
+ cd build && tar xzf $(BINNAME)_$(shell echo ${VERSION} | cut -d '-' -f 1-2).orig.tar.gz
+ cp -r debian/ build/$(BINNAME)-$(VERSION)/
+ cd build/$(BINNAME)-$(VERSION) && debuild -us -uc
+ cp build/*.deb dist/
+ git checkout -- debian/changelog
+
+# -----------------------------------------------------------------------------
+# Utils
+# -----------------------------------------------------------------------------
+
+clean:
+ rm -rf dist/ build/
+
+staging\nssm.exe:
+ xcopy /y "C:\ProgramData\chocolatey\lib\NSSM\tools\nssm.exe" $(STAGING)
+staging/nssm.exe:
+ wget https://nssm.cc/release/nssm-2.24.zip -O $(STAGING)/nssm.zip
+ unzip $(STAGING)/nssm.zip -d $(STAGING)
+ mv $(STAGING)/nssm-*/win32/nssm.exe $(STAGING)
+ rm -rf $(STAGING)/nssm-* $(STAGING)/nssm.zip
diff --git a/branding/templates/osx/bitmask.pf.conf b/branding/templates/osx/bitmask.pf.conf
new file mode 100644
index 0000000..8842328
--- /dev/null
+++ b/branding/templates/osx/bitmask.pf.conf
@@ -0,0 +1,19 @@
+default_device = "en99"
+
+set block-policy drop
+scrub in all
+set skip on lo0
+antispoof for $default_device
+
+# block all traffic on default device
+block out on $default_device all
+
+# allow traffic to gateways
+pass out on $default_device to <bitmask_gateways>
+
+# allow traffic to local networks over the default device
+pass out on $default_device to $default_device:network
+
+# block all DNS, except to the gateways
+block out proto udp to any port 53
+pass out proto udp to <bitmask_gateways> port 53
diff --git a/branding/templates/osx/client.down.sh b/branding/templates/osx/client.down.sh
new file mode 100755
index 0000000..1e173bb
--- /dev/null
+++ b/branding/templates/osx/client.down.sh
@@ -0,0 +1,426 @@
+#!/bin/bash -e
+# Note: must be bash; uses bash-specific tricks
+#
+# ******************************************************************************************************************
+# Copyright By Tunnelblick. Redistributed with Bitmask under the GPL.
+# This Tunnelblick script does everything! It handles TUN and TAP interfaces,
+# pushed configurations and DHCP leases. :)
+#
+# This is the "Down" version of the script, executed after the connection is
+# closed.
+#
+# Created by: Nick Williams (using original code and parts of old Tblk scripts)
+#
+# ******************************************************************************************************************
+
+# @param String message - The message to log
+logMessage()
+{
+ echo "${@}"
+}
+
+# @param String message - The message to log
+logDebugMessage()
+{
+ echo "${@}" > /dev/null
+}
+
+trim()
+{
+echo ${@}
+}
+
+# @param String list - list of network service names, output from disable_ipv6()
+restore_ipv6() {
+
+ # Undoes the actions performed by the disable_ipv6() routine in client.up.tunnelblick.sh by restoring the IPv6
+ # 'automatic' setting for each network service for which that routine disabled IPv6.
+ #
+ # $1 must contain the output from disable_ipv6() -- the list of network services.
+ #
+ # This routine outputs log messages describing its activities.
+
+ if [ "$1" = "" ] ; then
+ exit
+ fi
+
+ printf %s "$1
+" | \
+ while IFS= read -r ripv6_service ; do
+ networksetup -setv6automatic "$ripv6_service"
+ logMessage "Re-enabled IPv6 (automatic) for '$ripv6_service'"
+ done
+}
+
+##########################################################################################
+flushDNSCache()
+{
+ if ${ARG_FLUSH_DNS_CACHE} ; then
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ readonly OSVER="$(sw_vers | grep 'ProductVersion:' | grep -o '10\.[0-9]*')"
+ set -e # We instruct bash that it CAN again fail on errors
+ if [ "${OSVER}" = "10.4" ] ; then
+
+ if [ -f /usr/sbin/lookupd ] ; then
+ set +e # we will catch errors from lookupd
+ /usr/sbin/lookupd -flushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via lookupd"
+ else
+ logMessage "Flushed the DNS cache via lookupd"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/sbin/lookupd not present. Not flushing the DNS cache"
+ fi
+
+ else
+
+ if [ -f /usr/bin/dscacheutil ] ; then
+ set +e # we will catch errors from dscacheutil
+ /usr/bin/dscacheutil -flushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via dscacheutil"
+ else
+ logMessage "Flushed the DNS cache via dscacheutil"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/bin/dscacheutil not present. Not flushing the DNS cache via dscacheutil"
+ fi
+
+ if [ -f /usr/sbin/discoveryutil ] ; then
+ set +e # we will catch errors from discoveryutil
+ /usr/sbin/discoveryutil udnsflushcaches
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via discoveryutil udnsflushcaches"
+ else
+ logMessage "Flushed the DNS cache via discoveryutil udnsflushcaches"
+ fi
+ /usr/sbin/discoveryutil mdnsflushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via discoveryutil mdnsflushcache"
+ else
+ logMessage "Flushed the DNS cache via discoveryutil mdnsflushcache"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "/usr/sbin/discoveryutil not present. Not flushing the DNS cache via discoveryutil"
+ fi
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ hands_off_ps="$( ps -ax | grep HandsOffDaemon | grep -v grep.HandsOffDaemon )"
+ set -e # We instruct bash that it CAN again fail on errors
+ if [ "${hands_off_ps}" = "" ] ; then
+ if [ -f /usr/bin/killall ] ; then
+ set +e # ignore errors if mDNSResponder isn't currently running
+ /usr/bin/killall -HUP mDNSResponder
+ if [ $? != 0 ] ; then
+ logMessage "mDNSResponder not running. Not notifying it that the DNS cache was flushed"
+ else
+ logMessage "Notified mDNSResponder that the DNS cache was flushed"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/bin/killall not present. Not notifying mDNSResponder that the DNS cache was flushed"
+ fi
+ else
+ logMessage "WARNING: Hands Off is running. Not notifying mDNSResponder that the DNS cache was flushed"
+ fi
+
+ fi
+ fi
+}
+
+##########################################################################################
+resetPrimaryInterface()
+{
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ WIFI_INTERFACE="$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}')"
+ if [ "${WIFI_INTERFACE}" == "" ] ; then
+ WIFI_INTERFACE="$(networksetup -listallhardwareports | awk '$3=="AirPort" {getline; print $2}')"
+ fi
+ PINTERFACE="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/IPv4
+ quit
+EOF
+ grep PrimaryInterface | sed -e 's/.*PrimaryInterface : //'
+ )"
+ set -e # resume abort on error
+
+ if [ "${PINTERFACE}" != "" ] ; then
+ if [ "${PINTERFACE}" == "${WIFI_INTERFACE}" -a "${OSVER}" != "10.4" -a -f /usr/sbin/networksetup ] ; then
+ if [ "${OSVER}" == "10.5" ] ; then
+ logMessage "Resetting primary interface '${PINTERFACE}' via networksetup -setairportpower off/on..."
+ /usr/sbin/networksetup -setairportpower off
+ sleep 2
+ /usr/sbin/networksetup -setairportpower on
+ else
+ logMessage "Resetting primary interface '${PINTERFACE}' via networksetup -setairportpower ${PINTERFACE} off/on..."
+ /usr/sbin/networksetup -setairportpower "${PINTERFACE}" off
+ sleep 2
+ /usr/sbin/networksetup -setairportpower "${PINTERFACE}" on
+ fi
+ else
+ if [ -f /sbin/ifconfig ] ; then
+ logMessage "Resetting primary interface '${PINTERFACE}' via ifconfig ${PINTERFACE} down/up..."
+ /sbin/ifconfig "${PINTERFACE}" down
+ sleep 2
+ /sbin/ifconfig "${PINTERFACE}" up
+ else
+ logMessage "WARNING: Not resetting primary interface because /sbin/ifconfig does not exist."
+ fi
+ fi
+ else
+ logMessage "WARNING: Not resetting primary interface because it cannot be found."
+ fi
+}
+
+##########################################################################################
+trap "" TSTP
+trap "" HUP
+trap "" INT
+export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
+
+readonly OUR_NAME=$(basename "${0}")
+
+logMessage "**********************************************"
+logMessage "Start of output from ${OUR_NAME}"
+
+# Remove the flag file that indicates we need to run the down script
+
+if [ -e "/tmp/bitmask-downscript-needs-to-be-run.txt" ] ; then
+ rm -f "/tmp/bitmask-downscript-needs-to-be-run.txt"
+fi
+
+# Test for the "-r" Bitmask option (Reset primary interface after disconnecting) because we _always_ need its value.
+# Usually we get the value for that option (and the other options) from State:/Network/OpenVPN,
+# but that key may not exist (because, for example, there were no DNS changes).
+# So we get the value from the Bitmask options passed to this script by OpenVPN.
+#
+# We do the same thing for the -f Bitmask option (Flush DNS cache after connecting or disconnecting)
+ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="false"
+ARG_FLUSH_DNS_CACHE="false"
+while [ {$#} ] ; do
+ if [ "${1:0:1}" != "-" ] ; then # Bitmask arguments start with "-" and come first
+ break # so if this one doesn't start with "-" we are done processing Bitmask arguments
+ fi
+ if [ "$1" = "-r" ] ; then
+ ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="true"
+ else
+ if [ "$1" = "-f" ] ; then
+ ARG_FLUSH_DNS_CACHE="true"
+ fi
+ fi
+ shift # Shift arguments to examine the next option (if there is one)
+done
+
+# Quick check - is the configuration there?
+if ! scutil -w State:/Network/OpenVPN &>/dev/null -t 1 ; then
+ # Configuration isn't there
+ logMessage "WARNING: Not restoring DNS settings because no saved Bitmask DNS information was found."
+
+ flushDNSCache
+
+ if ${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT} ; then
+ resetPrimaryInterface
+ fi
+ logMessage "End of output from ${OUR_NAME}"
+ logMessage "**********************************************"
+ exit 0
+fi
+
+# Get info saved by the up script
+TUNNELBLICK_CONFIG="$( scutil <<-EOF
+ open
+ show State:/Network/OpenVPN
+ quit
+EOF
+)"
+
+ARG_MONITOR_NETWORK_CONFIGURATION="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*MonitorNetwork :' | sed -e 's/^.*: //g')"
+LEASEWATCHER_PLIST_PATH="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*LeaseWatcherPlistPath :' | sed -e 's/^.*: //g')"
+REMOVE_LEASEWATCHER_PLIST="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RemoveLeaseWatcherPlist :' | sed -e 's/^.*: //g')"
+PSID="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*Service :' | sed -e 's/^.*: //g')"
+# Don't need: SCRIPT_LOG_FILE="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*ScriptLogFile :' | sed -e 's/^.*: //g')"
+# Don't need: ARG_RESTORE_ON_DNS_RESET="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreOnDNSReset :' | sed -e 's/^.*: //g')"
+# Don't need: ARG_RESTORE_ON_WINS_RESET="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreOnWINSReset :' | sed -e 's/^.*: //g')"
+# Don't need: PROCESS="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*PID :' | sed -e 's/^.*: //g')"
+# Don't need: ARG_IGNORE_OPTION_FLAGS="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*IgnoreOptionFlags :' | sed -e 's/^.*: //g')"
+ARG_TAP="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*IsTapInterface :' | sed -e 's/^.*: //g')"
+ARG_FLUSH_DNS_CACHE="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*FlushDNSCache :' | sed -e 's/^.*: //g')"
+ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*ResetPrimaryInterface :' | sed -e 's/^.*: //g')"
+bRouteGatewayIsDhcp="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RouteGatewayIsDhcp :' | sed -e 's/^.*: //g')"
+bTapDeviceHasBeenSetNone="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*TapDeviceHasBeenSetNone :' | sed -e 's/^.*: //g')"
+bAlsoUsingSetupKeys="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*bAlsoUsingSetupKeys :' | sed -e 's/^.*: //g')"
+sTunnelDevice="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*TunnelDevice :' | sed -e 's/^.*: //g')"
+
+# Note: '\n' was translated into '\t', so we translate it back (it was done because grep and sed only work with single lines)
+sRestoreIpv6Services="$(echo "${TUNNELBLICK_CONFIG}" | grep -i '^[[:space:]]*RestoreIpv6Services :' | sed -e 's/^.*: //g' | tr '\t' '\n')"
+
+# Remove leasewatcher
+if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ launchctl unload "${LEASEWATCHER_PLIST_PATH}"
+ if ${REMOVE_LEASEWATCHER_PLIST} ; then
+ rm -f "${LEASEWATCHER_PLIST_PATH}"
+ fi
+ logMessage "Cancelled monitoring of system configuration changes"
+fi
+
+if ${ARG_TAP} ; then
+ if [ "$bRouteGatewayIsDhcp" == "true" ]; then
+ if [ "$bTapDeviceHasBeenSetNone" == "false" ]; then
+ if [ -z "$dev" ]; then
+ # If $dev is not defined, then use TunnelDevice, which was set from $dev by client.up.tunnelblick.sh
+ # ($def is not defined when this script is called from MenuController to clean up when exiting Bitmask)
+ if [ -n "${sTunnelDevice}" ]; then
+ logMessage "WARNING: \$dev not defined; using TunnelDevice: ${sTunnelDevice}"
+ set +e
+ ipconfig set "${sTunnelDevice}" NONE 2>/dev/null
+ set -e
+ logMessage "Released the DHCP lease via ipconfig set ${sTunnelDevice} NONE."
+ else
+ logMessage "WARNING: Cannot configure TAP interface to NONE without \$dev or State:/Network/OpenVPN/TunnelDevice being defined. Device may not have disconnected properly."
+ fi
+ else
+ set +e
+ ipconfig set "$dev" NONE 2>/dev/null
+ set -e
+ logMessage "Released the DHCP lease via ipconfig set $dev NONE."
+ fi
+ fi
+ fi
+fi
+
+# Issue warning if the primary service ID has changed
+set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
+PSID_CURRENT="$( scutil <<-EOF |
+ open
+ show State:/Network/OpenVPN
+ quit
+EOF
+grep 'Service : ' | sed -e 's/.*Service : //'
+)"
+set -e # resume abort on error
+if [ "${PSID}" != "${PSID_CURRENT}" ] ; then
+ logMessage "Ignoring change of Network Primary Service from ${PSID} to ${PSID_CURRENT}"
+fi
+
+# Restore configurations
+DNS_OLD="$( scutil <<-EOF
+ open
+ show State:/Network/OpenVPN/OldDNS
+ quit
+EOF
+)"
+SMB_OLD="$( scutil <<-EOF
+ open
+ show State:/Network/OpenVPN/OldSMB
+ quit
+EOF
+)"
+DNS_OLD_SETUP="$( scutil <<-EOF
+ open
+ show State:/Network/OpenVPN/OldDNSSetup
+ quit
+EOF
+)"
+TB_NO_SUCH_KEY="<dictionary> {
+ BitmaskNoSuchKey : true
+}"
+
+if [ "${DNS_OLD}" = "${TB_NO_SUCH_KEY}" ] ; then
+ scutil <<-EOF
+ open
+ remove State:/Network/Service/${PSID}/DNS
+ quit
+EOF
+else
+ scutil <<-EOF
+ open
+ get State:/Network/OpenVPN/OldDNS
+ set State:/Network/Service/${PSID}/DNS
+ quit
+EOF
+fi
+
+if [ "${DNS_OLD_SETUP}" = "${TB_NO_SUCH_KEY}" ] ; then
+ if ${bAlsoUsingSetupKeys} ; then
+ logDebugMessage "DEBUG: Removing 'Setup:' DNS key"
+ scutil <<-EOF
+ open
+ remove Setup:/Network/Service/${PSID}/DNS
+ quit
+EOF
+ else
+ logDebugMessage "DEBUG: Not removing 'Setup:' DNS key"
+ fi
+else
+ if ${bAlsoUsingSetupKeys} ; then
+ logDebugMessage "DEBUG: Restoring 'Setup:' DNS key"
+ scutil <<-EOF
+ open
+ get State:/Network/OpenVPN/OldDNSSetup
+ set Setup:/Network/Service/${PSID}/DNS
+ quit
+EOF
+ else
+ logDebugMessage "DEBUG: Not restoring 'Setup:' DNS key"
+ fi
+fi
+
+if [ "${SMB_OLD}" = "${TB_NO_SUCH_KEY}" ] ; then
+ scutil > /dev/null <<-EOF
+ open
+ remove State:/Network/Service/${PSID}/SMB
+ quit
+EOF
+else
+ scutil > /dev/null <<-EOF
+ open
+ get State:/Network/OpenVPN/OldSMB
+ set State:/Network/Service/${PSID}/SMB
+ quit
+EOF
+fi
+
+logMessage "Restored the DNS and SMB configurations"
+
+set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
+new_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
+set -e # resume abort on error
+logDebugMessage "DEBUG:"
+logDebugMessage "DEBUG: /etc/resolve = ${new_resolver_contents}"
+
+set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
+scutil_dns="$( scutil --dns)"
+set -e # resume abort on error
+logDebugMessage "DEBUG:"
+logDebugMessage "DEBUG: scutil --dns = ${scutil_dns}"
+logDebugMessage "DEBUG:"
+
+restore_ipv6 "$sRestoreIpv6Services"
+
+flushDNSCache
+
+# Remove our system configuration data
+scutil <<-EOF
+ open
+ remove State:/Network/OpenVPN/OldDNS
+ remove State:/Network/OpenVPN/OldSMB
+ remove State:/Network/OpenVPN/OldDNSSetup
+ remove State:/Network/OpenVPN/DNS
+ remove State:/Network/OpenVPN/SMB
+ remove State:/Network/OpenVPN
+ quit
+EOF
+
+if ${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT} ; then
+ resetPrimaryInterface
+fi
+
+logMessage "End of output from ${OUR_NAME}"
+logMessage "**********************************************"
+
+exit 0
diff --git a/branding/templates/osx/client.up.sh b/branding/templates/osx/client.up.sh
new file mode 100755
index 0000000..2f1a770
--- /dev/null
+++ b/branding/templates/osx/client.up.sh
@@ -0,0 +1,1522 @@
+#!/bin/bash -e
+# Note: must be bash; uses bash-specific tricks
+#
+# ******************************************************************************************************************
+# Copyright by Tunnelblick. Redistributed under GPL as part of Bitmask.
+# This Tunnelblick script does everything! It handles TUN and TAP interfaces,
+# pushed configurations, DHCP with DNS and SMB, and renewed DHCP leases. :)
+#
+# This is the "Up" version of the script, executed after the interface is
+# initialized.
+#
+# Created by: Nick Williams (using original code and parts of old Tblk scripts)
+# Modifed by: Jonathan K. Bullard for Mountain Lion
+# Adapted to use by Bitmask by: Kali Kaneko
+#
+# ******************************************************************************************************************
+
+
+##########################################################################################
+# @param String message - The message to log
+logMessage()
+{
+ echo "${@}"
+}
+
+##########################################################################################
+# @param String message - The message to log
+logDebugMessage()
+{
+ if ${ARG_EXTRA_LOGGING} ; then
+ echo "${@}"
+ fi
+}
+
+##########################################################################################
+# log a change to a setting
+# @param String filters - empty, or one or two '#' if not performing the change
+# @param String name of setting that is being changed
+# @param String new value
+# @param String old value
+logChange()
+{
+ if [ "$1" = "" ] ; then
+ if [ "$3" = "$4" ] ; then
+ echo "Did not change $2 setting of '$3' (but re-set it)"
+ else
+ echo "Changed $2 setting from '$4' to '$3'"
+ fi
+ else
+ echo "Did not change $2 setting of '$4'"
+ fi
+}
+
+##########################################################################################
+# @param String string - Content to trim
+trim()
+{
+ echo ${@}
+}
+
+##########################################################################################
+disable_ipv6() {
+
+# Disables IPv6 on each enabled (active) network service on which it is set to the OS X default "IPv6 Automatic".
+#
+# For each such service, outputs a line with the name of the service.
+# (A separate line is output for each name because a name may include spaces.)
+#
+# The 'restore_ipv6' routine in client.down.sh undoes the actions performed by this routine.
+#
+# NOTE: Done only for enabled services because some versions of OS X enable the service if this IPv6 setting is changed.
+#
+# This only works for OS X 10.5 and higher (10.4 does not implement IPv6.)
+
+ if [ "$OSVER" = "10.4" ] ; then
+ exit
+ fi
+
+ # Get list of services and remove the first line which contains a heading
+ dipv6_services="$( networksetup -listallnetworkservices | sed -e '1,1d')"
+
+ # Go through the list disabling IPv6 for enabled services, and outputting lines with the names of the services
+ printf %s "$dipv6_services
+" | \
+ while IFS= read -r dipv6_service ; do
+
+ # If first character of a line is an asterisk, the service is disabled, so we skip it
+ if [ "${dipv6_service:0:1}" != "*" ] ; then
+ dipv6_ipv6_status="$( networksetup -getinfo "$dipv6_service" | grep 'IPv6: ' | sed -e 's/IPv6: //')"
+ if [ "$dipv6_ipv6_status" = "Automatic" ] ; then
+ networksetup -setv6off "$dipv6_service"
+ echo "$dipv6_service"
+ fi
+ fi
+
+ done
+}
+
+##########################################################################################
+# @param String[] dnsServers - The name servers to use
+# @param String domainName - The domain name to use
+# @param \optional String[] winsServers - The SMB servers to use
+# @param \optional String[] searchDomains - The search domains to use
+#
+# Throughout this routine:
+# MAN_ is a prefix for manually set parameters
+# DYN_ is a prefix for dynamically set parameters (by a "push", config file, or command line option)
+# CUR_ is a prefix for the current parameters (as arbitrated by OS X between manual and DHCP data)
+# FIN_ is a prefix for the parameters we want to end up with
+# SKP_ is a prefix for an empty string or a "#" used to control execution of statements that set parameters in scutil
+#
+# DNS_SA is a suffix for the ServerAddresses value in a System Configuration DNS key
+# DNS_SD is a suffix for the SearchDomains value in a System Configuration DNS key
+# DNS_DN is a suffix for the DomainName value in a System Configuration DNS key
+#
+# SMB_NN is a suffix for the NetBIOSName value in a System Configuration SMB key
+# SMB_WG is a suffix for the Workgroup value in a System Configuration SMB key
+# SMB_WA is a suffix for the WINSAddresses value in a System Configuration SMB key
+#
+# So, for example, MAN_SMB_NN is the manually set NetBIOSName value (or the empty string if not set manually)
+
+setDnsServersAndDomainName()
+{
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+
+ PSID="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/IPv4
+ quit
+EOF
+grep PrimaryService | sed -e 's/.*PrimaryService : //'
+)"
+
+ set -e # resume abort on error
+
+ MAN_DNS_CONFIG="$( scutil <<-EOF |
+ open
+ show Setup:/Network/Service/${PSID}/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+ MAN_SMB_CONFIG="$( scutil <<-EOF |
+ open
+ show Setup:/Network/Service/${PSID}/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ CUR_DNS_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+ CUR_SMB_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+# Set up the DYN_... variables to contain what is asked for (dynamically, by a 'push' directive, for example)
+
+ declare -a vDNS=("${!1}")
+ declare -a vSMB=("${!3}")
+ declare -a vSD=("${!4}")
+
+ if [ ${#vDNS[*]} -eq 0 ] ; then
+ readonly DYN_DNS_SA=""
+ else
+ readonly DYN_DNS_SA="${!1}"
+ fi
+
+ if [ ${#vSMB[*]} -eq 0 ] ; then
+ readonly DYN_SMB_WA=""
+ else
+ readonly DYN_SMB_WA="${!3}"
+ fi
+
+ if [ ${#vSD[*]} -eq 0 ] ; then
+ readonly DYN_DNS_SD=""
+ else
+ readonly DYN_DNS_SD="${!4}"
+ fi
+
+ DYN_DNS_DN="$2"
+
+ # The variables
+ # DYN_SMB_WG
+ # DYN_SMB_NN
+ # are left empty. There isn't a way for OpenVPN to set them.
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: MAN_DNS_CONFIG = ${MAN_DNS_CONFIG}"
+ logDebugMessage "DEBUG: MAN_SMB_CONFIG = ${MAN_SMB_CONFIG}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: CUR_DNS_CONFIG = ${CUR_DNS_CONFIG}"
+ logDebugMessage "DEBUG: CUR_SMB_CONFIG = ${CUR_SMB_CONFIG}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: DYN_DNS_DN = ${DYN_DNS_DN}; DYN_DNS_SA = ${DYN_DNS_SA}; DYN_DNS_SD = ${DYN_DNS_SD}"
+ logDebugMessage "DEBUG: DYN_SMB_NN = ${DYN_SMB_NN}; DYN_SMB_WG = ${DYN_SMB_WG}; DYN_SMB_WA = ${DYN_SMB_WA}"
+
+# Set up the MAN_... variables to contain manual network settings
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+
+ if echo "${MAN_DNS_CONFIG}" | grep -q "DomainName" ; then
+ readonly MAN_DNS_DN="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*DomainName[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly MAN_DNS_DN="";
+ fi
+ if echo "${MAN_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
+ readonly MAN_DNS_SA="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly MAN_DNS_SA="";
+ fi
+ if echo "${MAN_DNS_CONFIG}" | grep -q "SearchDomains" ; then
+ readonly MAN_DNS_SD="$( trim "$( echo "${MAN_DNS_CONFIG}" | sed -e 's/^.*SearchDomains[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly MAN_DNS_SD="";
+ fi
+ if echo "${MAN_SMB_CONFIG}" | grep -q "NetBIOSName" ; then
+ readonly MAN_SMB_NN="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*NetBIOSName : \([^[:space:]]*\).*$/\1/g' )" )"
+ else
+ readonly MAN_SMB_NN="";
+ fi
+ if echo "${MAN_SMB_CONFIG}" | grep -q "Workgroup" ; then
+ readonly MAN_SMB_WG="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*Workgroup : \([^[:space:]]*\).*$/\1/g' )" )"
+ else
+ readonly MAN_SMB_WG="";
+ fi
+ if echo "${MAN_SMB_CONFIG}" | grep -q "WINSAddresses" ; then
+ readonly MAN_SMB_WA="$( trim "$( echo "${MAN_SMB_CONFIG}" | sed -e 's/^.*WINSAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly MAN_SMB_WA="";
+ fi
+
+ set -e # resume abort on error
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: MAN_DNS_DN = ${MAN_DNS_DN}; MAN_DNS_SA = ${MAN_DNS_SA}; MAN_DNS_SD = ${MAN_DNS_SD}"
+ logDebugMessage "DEBUG: MAN_SMB_NN = ${MAN_SMB_NN}; MAN_SMB_WG = ${MAN_SMB_WG}; MAN_SMB_WA = ${MAN_SMB_WA}"
+
+# Set up the CUR_... variables to contain the current network settings (from manual or DHCP, as arbitrated by OS X
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+
+ if echo "${CUR_DNS_CONFIG}" | grep -q "DomainName" ; then
+ readonly CUR_DNS_DN="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*DomainName : \([^[:space:]]*\).*$/\1/g' )")"
+ else
+ readonly CUR_DNS_DN="";
+ fi
+ if echo "${CUR_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
+ readonly CUR_DNS_SA="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
+ else
+ readonly CUR_DNS_SA="";
+ fi
+ if echo "${CUR_DNS_CONFIG}" | grep -q "SearchDomains" ; then
+ readonly CUR_DNS_SD="$(trim "$( echo "${CUR_DNS_CONFIG}" | sed -e 's/^.*SearchDomains[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
+ else
+ readonly CUR_DNS_SD="";
+ fi
+ if echo "${CUR_SMB_CONFIG}" | grep -q "NetBIOSName" ; then
+ readonly CUR_SMB_NN="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*NetBIOSName : \([^[:space:]]*\).*$/\1/g' )")"
+ else
+ readonly CUR_SMB_NN="";
+ fi
+ if echo "${CUR_SMB_CONFIG}" | grep -q "Workgroup" ; then
+ readonly CUR_SMB_WG="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*Workgroup : \([^[:space:]]*\).*$/\1/g' )")"
+ else
+ readonly CUR_SMB_WG="";
+ fi
+ if echo "${CUR_SMB_CONFIG}" | grep -q "WINSAddresses" ; then
+ readonly CUR_SMB_WA="$(trim "$( echo "${CUR_SMB_CONFIG}" | sed -e 's/^.*WINSAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )")"
+ else
+ readonly CUR_SMB_WA="";
+ fi
+
+ set -e # resume abort on error
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: CUR_DNS_DN = ${CUR_DNS_DN}; CUR_DNS_SA = ${CUR_DNS_SA}; CUR_DNS_SD = ${CUR_DNS_SD}"
+ logDebugMessage "DEBUG: CUR_SMB_NN = ${CUR_SMB_NN}; CUR_SMB_WG = ${CUR_SMB_WG}; CUR_SMB_WA = ${CUR_SMB_WA}"
+
+# set up the FIN_... variables with what we want to set things to
+
+ # Three FIN_... variables are simple -- no aggregation is done for them
+
+ if [ "${DYN_DNS_DN}" != "" ] ; then
+ if [ "${MAN_DNS_DN}" != "" ] ; then
+ logMessage "WARNING: Ignoring DomainName '$DYN_DNS_DN' because DomainName was set manually"
+ readonly FIN_DNS_DN="${MAN_DNS_DN}"
+ else
+ readonly FIN_DNS_DN="${DYN_DNS_DN}"
+ fi
+ else
+ readonly FIN_DNS_DN="${CUR_DNS_DN}"
+ fi
+
+ if [ "${DYN_SMB_NN}" != "" ] ; then
+ if [ "${MAN_SMB_NN}" != "" ] ; then
+ logMessage "WARNING: Ignoring NetBIOSName '$DYN_SMB_NN' because NetBIOSName was set manually"
+ readonly FIN_SMB_NN="${MAN_SMB_NN}"
+ else
+ readonly FIN_SMB_NN="${DYN_SMB_NN}"
+ fi
+ else
+ readonly FIN_SMB_NN="${CUR_SMB_NN}"
+ fi
+
+ if [ "${DYN_SMB_WG}" != "" ] ; then
+ if [ "${MAN_SMB_WG}" != "" ] ; then
+ logMessage "WARNING: Ignoring Workgroup '$DYN_SMB_WG' because Workgroup was set manually"
+ readonly FIN_SMB_WG="${MAN_SMB_WG}"
+ else
+ readonly FIN_SMB_WG="${DYN_SMB_WG}"
+ fi
+ else
+ readonly FIN_SMB_WG="${CUR_SMB_WG}"
+ fi
+
+ # DNS ServerAddresses (FIN_DNS_SA) are aggregated for 10.4 and 10.5
+ if [ ${#vDNS[*]} -eq 0 ] ; then
+ readonly FIN_DNS_SA="${CUR_DNS_SA}"
+ else
+ # BitmaskVPN: let's allow 10.4x.0.1 DNS providers
+ #if [ "${MAN_DNS_SA}" != "" ] ; then
+ # logMessage "WARNING: Ignoring ServerAddresses '$DYN_DNS_SA' because ServerAddresses was set manually"
+ # readonly FIN_DNS_SA="${CUR_DNS_SA}"
+ #else
+ case "${OSVER}" in
+ 10.4 | 10.5 )
+ # We need to remove duplicate DNS entries, so that our reference list matches MacOSX's
+ SDNS="$( echo "${DYN_DNS_SA}" | tr ' ' '\n' )"
+ (( i=0 ))
+ for n in "${vDNS[@]}" ; do
+ if echo "${SDNS}" | grep -q "${n}" ; then
+ unset vDNS[${i}]
+ fi
+ (( i++ ))
+ done
+ if [ ${#vDNS[*]} -gt 0 ] ; then
+ readonly FIN_DNS_SA="$( trim "${DYN_DNS_SA}" "${vDNS[*]}" )"
+ else
+ readonly FIN_DNS_SA="${DYN_DNS_SA}"
+ fi
+ logMessage "Aggregating ServerAddresses because running on OS X 10.4 or 10.5"
+ ;;
+ * )
+ # Do nothing - in 10.6 and higher -- we don't aggregate our configurations, apparently
+ readonly FIN_DNS_SA="${DYN_DNS_SA}"
+ logMessage "Not aggregating ServerAddresses because running on OS X 10.6 or higher"
+ ;;
+ esac
+ #fi
+ fi
+
+ # SMB WINSAddresses (FIN_SMB_WA) are aggregated for 10.4 and 10.5
+ if [ ${#vSMB[*]} -eq 0 ] ; then
+ readonly FIN_SMB_WA="${CUR_SMB_WA}"
+ else
+ if [ "${MAN_SMB_WA}" != "" ] ; then
+ logMessage "WARNING: Ignoring WINSAddresses '$DYN_SMB_WA' because WINSAddresses was set manually"
+ readonly FIN_SMB_WA="${MAN_SMB_WA}"
+ else
+ case "${OSVER}" in
+ 10.4 | 10.5 )
+ # We need to remove duplicate SMB entries, so that our reference list matches MacOSX's
+ SSMB="$( echo "${DYN_SMB_WA}" | tr ' ' '\n' )"
+ (( i=0 ))
+ for n in "${vSMB[@]}" ; do
+ if echo "${SSMB}" | grep -q "${n}" ; then
+ unset vSMB[${i}]
+ fi
+ (( i++ ))
+ done
+ if [ ${#vSMB[*]} -gt 0 ] ; then
+ readonly FIN_SMB_WA="$( trim "${DYN_SMB_WA}" "${vSMB[*]}" )"
+ else
+ readonly FIN_SMB_WA="${DYN_SMB_WA}"
+ fi
+ logMessage "Aggregating WINSAddresses because running on OS X 10.4 or 10.5"
+ ;;
+ * )
+ # Do nothing - in 10.6 and higher -- we don't aggregate our configurations, apparently
+ readonly FIN_SMB_WA="${DYN_SMB_WA}"
+ logMessage "Not aggregating WINSAddresses because running on OS X 10.6 or higher"
+ ;;
+ esac
+ fi
+ fi
+
+ # DNS SearchDomains (FIN_DNS_SD) is treated specially
+ #
+ # OLD BEHAVIOR:
+ # if SearchDomains was not set manually, we set SearchDomains to the DomainName
+ # else
+ # In OS X 10.4-10.5, we add the DomainName to the end of any manual SearchDomains (unless it is already there)
+ # In OS X 10.6+, if SearchDomains was entered manually, we ignore the DomainName
+ # else we set SearchDomains to the DomainName
+ #
+ # NEW BEHAVIOR (done if ARG_PREPEND_DOMAIN_NAME is "true"):
+ #
+ # if SearchDomains was entered manually, we do nothing
+ # else we PREpend new SearchDomains (if any) to the existing SearchDomains (NOT replacing them)
+ # and PREpend DomainName to that
+ #
+ # (done if ARG_PREPEND_DOMAIN_NAME is "false" and there are new SearchDomains from DOMAIN-SEARCH):
+ #
+ # if SearchDomains was entered manually, we do nothing
+ # else we PREpend any new SearchDomains to the existing SearchDomains (NOT replacing them)
+ #
+ # This behavior is meant to behave like Linux with Network Manager and Windows
+
+ if "${ARG_PREPEND_DOMAIN_NAME}" ; then
+ if [ "${MAN_DNS_SD}" = "" ] ; then
+ if [ "${DYN_DNS_SD}" != "" ] ; then
+ if ! echo "${CUR_DNS_SD}" | tr ' ' '\n' | grep -q "${DYN_DNS_SD}" ; then
+ logMessage "Prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were not set manually and 'Prepend domain name to search domains' was selected"
+ readonly TMP_DNS_SD="$( trim "${DYN_DNS_SD}" "${CUR_DNS_SD}" )"
+ else
+ logMessage "Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because it is already there"
+ readonly TMP_DNS_SD="${CUR_DNS_SD}"
+ fi
+ else
+ readonly TMP_DNS_SD="${CUR_DNS_SD}"
+ fi
+ if [ "${FIN_DNS_DN}" != "" -a "${FIN_DNS_DN}" != "localdomain" ] ; then
+ if ! echo "${TMP_DNS_SD}" | tr ' ' '\n' | grep -q "${FIN_DNS_DN}" ; then
+ logMessage "Prepending '${FIN_DNS_DN}' to search domains '${TMP_DNS_SD}' because the search domains were not set manually and 'Prepend domain name to search domains' was selected"
+ readonly FIN_DNS_SD="$( trim "${FIN_DNS_DN}" "${TMP_DNS_SD}" )"
+ else
+ logMessage "Not prepending '${FIN_DNS_DN}' to search domains '${TMP_DNS_SD}' because it is already there"
+ readonly FIN_DNS_SD="${TMP_DNS_SD}"
+ fi
+ else
+ readonly FIN_DNS_SD="${TMP_DNS_SD}"
+ fi
+ else
+ if [ "${DYN_DNS_SD}" != "" ] ; then
+ logMessage "WARNING: Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
+ fi
+ if [ "${FIN_DNS_DN}" != "" ] ; then
+ logMessage "WARNING: Not prepending domain '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
+ fi
+ readonly FIN_DNS_SD="${CUR_DNS_SD}"
+ fi
+ else
+ if [ "${DYN_DNS_SD}" != "" ] ; then
+ if [ "${MAN_DNS_SD}" = "" ] ; then
+ logMessage "Prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were not set manually but were set via OpenVPN and 'Prepend domain name to search domains' was not selected"
+ readonly FIN_DNS_SD="$( trim "${DYN_DNS_SD}" "${CUR_DNS_SD}" )"
+ else
+ logMessage "WARNING: Not prepending '${DYN_DNS_SD}' to search domains '${CUR_DNS_SD}' because the search domains were set manually"
+ readonly FIN_DNS_SD="${CUR_DNS_SD}"
+ fi
+ else
+ if [ "${FIN_DNS_DN}" != "" -a "${FIN_DNS_DN}" != "localdomain" ] ; then
+ case "${OSVER}" in
+ 10.4 | 10.5 )
+ if ! echo "${MAN_DNS_SD}" | tr ' ' '\n' | grep -q "${FIN_DNS_DN}" ; then
+ logMessage "Appending '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' that were set manually because running under OS X 10.4 or 10.5 and 'Prepend domain name to search domains' was not selected"
+ readonly FIN_DNS_SD="$( trim "${MAN_DNS_SD}" "${FIN_DNS_DN}" )"
+ else
+ logMessage "Not appending '${FIN_DNS_DN}' to search domains '${CUR_DNS_SD}' because it is already in the search domains that were set manually and 'Prepend domain name to search domains' was not selected"
+ readonly FIN_DNS_SD="${CUR_DNS_SD}"
+ fi
+ ;;
+ * )
+ if [ "${MAN_DNS_SD}" = "" ] ; then
+ logMessage "Setting search domains to '${FIN_DNS_DN}' because running under OS X 10.6 or higher and the search domains were not set manually and 'Prepend domain name to search domains' was not selected"
+ readonly FIN_DNS_SD="${FIN_DNS_DN}"
+ else
+ logMessage "Not replacing search domains '${CUR_DNS_SD}' with '${FIN_DNS_DN}' because the search domains were set manually and 'Prepend domain name to search domains' was not selected"
+ readonly FIN_DNS_SD="${CUR_DNS_SD}"
+ fi
+ ;;
+ esac
+ else
+ readonly FIN_DNS_SD="${CUR_DNS_SD}"
+ fi
+ fi
+ fi
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: FIN_DNS_DN = ${FIN_DNS_DN}; FIN_DNS_SA = ${FIN_DNS_SA}; FIN_DNS_SD = ${FIN_DNS_SD}"
+ logDebugMessage "DEBUG: FIN_SMB_NN = ${FIN_SMB_NN}; FIN_SMB_WG = ${FIN_SMB_WG}; FIN_SMB_WA = ${FIN_SMB_WA}"
+
+# Set up SKP_... variables to inhibit scutil from making some changes
+
+ # SKP_DNS_... and SKP_SMB_... are used to comment out individual items that are not being set
+ if [ "${FIN_DNS_DN}" = "" -o "${FIN_DNS_DN}" = "${CUR_DNS_DN}" ] ; then
+ SKP_DNS_DN="#"
+ else
+ SKP_DNS_DN=""
+ fi
+ if [ "${FIN_DNS_SA}" = "" -o "${FIN_DNS_SA}" = "${CUR_DNS_SA}" ] ; then
+ SKP_DNS_SA="#"
+ else
+ SKP_DNS_SA=""
+ fi
+ if [ "${FIN_DNS_SD}" = "" -o "${FIN_DNS_SD}" = "${CUR_DNS_SD}" ] ; then
+ SKP_DNS_SD="#"
+ else
+ SKP_DNS_SD=""
+ fi
+ if [ "${FIN_SMB_NN}" = "" -o "${FIN_SMB_NN}" = "${CUR_SMB_NN}" ] ; then
+ SKP_SMB_NN="#"
+ else
+ SKP_SMB_NN=""
+ fi
+ if [ "${FIN_SMB_WG}" = "" -o "${FIN_SMB_WG}" = "${CUR_SMB_WG}" ] ; then
+ SKP_SMB_WG="#"
+ else
+ SKP_SMB_WG=""
+ fi
+ if [ "${FIN_SMB_WA}" = "" -o "${FIN_SMB_WA}" = "${CUR_SMB_WA}" ] ; then
+ SKP_SMB_WA="#"
+ else
+ SKP_SMB_WA=""
+ fi
+
+ # if any DNS items should be set, set all that have values
+ if [ "${SKP_DNS_DN}${SKP_DNS_SA}${SKP_DNS_SD}" = "###" ] ; then
+ readonly SKP_DNS="#"
+ else
+ readonly SKP_DNS=""
+ if [ "${FIN_DNS_DN}" != "" ] ; then
+ SKP_DNS_DN=""
+ fi
+ if [ "${FIN_DNS_SA}" != "" ] ; then
+ SKP_DNS_SA=""
+ fi
+ if [ "${FIN_DNS_SD}" != "" ] ; then
+ SKP_DNS_SD=""
+ fi
+ fi
+
+ # if any SMB items should be set, set all that have values
+ if [ "${SKP_SMB_NN}${SKP_SMB_WG}${SKP_SMB_WA}" = "###" ] ; then
+ readonly SKP_SMB="#"
+ else
+ readonly SKP_SMB=""
+ if [ "${FIN_SMB_NN}" != "" ] ; then
+ SKP_SMB_NN=""
+ fi
+ if [ "${FIN_SMB_WG}" != "" ] ; then
+ SKP_SMB_WG=""
+ fi
+ if [ "${FIN_SMB_WA}" != "" ] ; then
+ SKP_SMB_WA=""
+ fi
+ fi
+
+ readonly SKP_DNS_SA SKP_DNS_SD SKP_DNS_DN
+ readonly SKP_SMB_NN SKP_SMB_WG SKP_SMB_WA
+
+# special-case fiddling:
+
+ # in 10.8 and higher, ServerAddresses and SearchDomains must be set via the Setup: key in addition to the State: key
+ # in 10.7 if ServerAddresses or SearchDomains are manually set, ServerAddresses and SearchDomains must be similarly set with the Setup: key in addition to the State: key
+ #
+ # we pass a flag indicating whether we've done that to the other scripts in 'bAlsoUsingSetupKeys'
+
+ case "${OSVER}" in
+ 10.4 | 10.5 | 10.6 )
+ logDebugMessage "DEBUG: OS X 10.4-10.6, so will modify settings using only State:"
+ readonly SKP_SETUP_DNS="#"
+ readonly bAlsoUsingSetupKeys="false"
+ ;;
+ 10.7 )
+ if [ "${MAN_DNS_SA}" = "" -a "${MAN_DNS_SD}" = "" ] ; then
+ logDebugMessage "DEBUG: OS X 10.7 and neither ServerAddresses nor SearchDomains were set manually, so will modify DNS settings using only State:"
+ readonly SKP_SETUP_DNS="#"
+ readonly bAlsoUsingSetupKeys="false"
+ else
+ logDebugMessage "DEBUG: OS X 10.7 and ServerAddresses or SearchDomains were set manually, so will modify DNS settings using Setup: in addition to State:"
+ readonly SKP_SETUP_DNS=""
+ readonly bAlsoUsingSetupKeys="true"
+ fi
+ ;;
+ * )
+ logDebugMessage "DEBUG: OS X 10.8 or higher, so will modify DNS settings using Setup: in addition to State:"
+ readonly SKP_SETUP_DNS=""
+ readonly bAlsoUsingSetupKeys="true"
+ ;;
+ esac
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: SKP_DNS = ${SKP_DNS}; SKP_DNS_SA = ${SKP_DNS_SA}; SKP_DNS_SD = ${SKP_DNS_SD}; SKP_DNS_DN = ${SKP_DNS_DN}"
+ logDebugMessage "DEBUG: SKP_SETUP_DNS = ${SKP_SETUP_DNS}"
+ logDebugMessage "DEBUG: SKP_SMB = ${SKP_SMB}; SKP_SMB_NN = ${SKP_SMB_NN}; SKP_SMB_WG = ${SKP_SMB_WG}; SKP_SMB_WA = ${SKP_SMB_WA}"
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
+ original_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
+ set -e # resume abort on error
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: /etc/resolve = ${original_resolver_contents}"
+ logDebugMessage "DEBUG:"
+
+ set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
+ scutil_dns="$( scutil --dns)"
+ set -e # resume abort on error
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: scutil --dns BEFORE CHANGES = ${scutil_dns}"
+ logDebugMessage "DEBUG:"
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: Configuration changes:"
+ logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_SA}ADD State: ServerAddresses ${FIN_DNS_SA}"
+ logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_SD}ADD State: SearchDomains ${FIN_DNS_SD}"
+ logDebugMessage "DEBUG: ${SKP_DNS}${SKP_DNS_DN}ADD State: DomainName ${FIN_DNS_DN}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SA}ADD Setup: ServerAddresses ${FIN_DNS_SA}"
+ logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SD}ADD Setup: SearchDomains ${FIN_DNS_SD}"
+ logDebugMessage "DEBUG: ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_DN}ADD Setup: DomainName ${FIN_DNS_DN}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_NN}ADD State: NetBIOSName ${FIN_SMB_NN}"
+ logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_WG}ADD State: Workgroup ${FIN_SMB_WG}"
+ logDebugMessage "DEBUG: ${SKP_SMB}${SKP_SMB_WA}ADD State: WINSAddresses ${FIN_SMB_WA}"
+
+ # Save the openvpn process ID and the Network Primary Service ID, leasewather.plist path, logfile path, and optional arguments from Bitmask,
+ # then save old and new DNS and SMB settings
+ # PPID is a script variable (defined by bash itself) that contains the process ID of the parent of the process running the script (i.e., OpenVPN's process ID)
+ # config is an environmental variable set to the configuration path by OpenVPN prior to running this up script
+
+ scutil <<-EOF > /dev/null
+ open
+
+ # Store our variables for the other scripts (leasewatch, down, etc.) to use
+ d.init
+ # The '#' in the next line does NOT start a comment; it indicates to scutil that a number follows it (as opposed to a string or an array)
+ d.add PID # ${PPID}
+ d.add Service ${PSID}
+ d.add LeaseWatcherPlistPath "${LEASEWATCHER_PLIST_PATH}"
+ d.add RemoveLeaseWatcherPlist "${REMOVE_LEASEWATCHER_PLIST}"
+ d.add ScriptLogFile "${SCRIPT_LOG_FILE}"
+ d.add MonitorNetwork "${ARG_MONITOR_NETWORK_CONFIGURATION}"
+ d.add RestoreOnDNSReset "${ARG_RESTORE_ON_DNS_RESET}"
+ d.add RestoreOnWINSReset "${ARG_RESTORE_ON_WINS_RESET}"
+ d.add IgnoreOptionFlags "${ARG_IGNORE_OPTION_FLAGS}"
+ d.add IsTapInterface "${ARG_TAP}"
+ d.add FlushDNSCache "${ARG_FLUSH_DNS_CACHE}"
+ d.add ResetPrimaryInterface "${ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT}"
+ d.add RouteGatewayIsDhcp "${bRouteGatewayIsDhcp}"
+ d.add bAlsoUsingSetupKeys "${bAlsoUsingSetupKeys}"
+ d.add TapDeviceHasBeenSetNone "false"
+ d.add TunnelDevice "$dev"
+ d.add RestoreIpv6Services "$ipv6_disabled_services_encoded"
+ set State:/Network/OpenVPN
+
+ # Back up the device's current DNS and SMB configurations,
+ # Indicate 'no such key' by a dictionary with a single entry: "BitmaskNoSuchKey : true"
+ # If there isn't a key, "BitmaskNoSuchKey : true" won't be removed.
+ # If there is a key, "BitmaskNoSuchKey : true" will be removed and the key's contents will be used
+
+ d.init
+ d.add BitmaskNoSuchKey true
+ get State:/Network/Service/${PSID}/DNS
+ set State:/Network/OpenVPN/OldDNS
+
+ d.init
+ d.add BitmaskNoSuchKey true
+ get Setup:/Network/Service/${PSID}/DNS
+ set State:/Network/OpenVPN/OldDNSSetup
+
+ d.init
+ d.add BitmaskNoSuchKey true
+ get State:/Network/Service/${PSID}/SMB
+ set State:/Network/OpenVPN/OldSMB
+
+ # Initialize the new DNS map via State:
+ ${SKP_DNS}d.init
+ ${SKP_DNS}${SKP_DNS_SA}d.add ServerAddresses * ${FIN_DNS_SA}
+ ${SKP_DNS}${SKP_DNS_SD}d.add SearchDomains * ${FIN_DNS_SD}
+ ${SKP_DNS}${SKP_DNS_DN}d.add DomainName ${FIN_DNS_DN}
+ ${SKP_DNS}set State:/Network/Service/${PSID}/DNS
+
+ # If necessary, initialize the new DNS map via Setup: also
+ ${SKP_SETUP_DNS}${SKP_DNS}d.init
+ ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SA}d.add ServerAddresses * ${FIN_DNS_SA}
+ ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_SD}d.add SearchDomains * ${FIN_DNS_SD}
+ ${SKP_SETUP_DNS}${SKP_DNS}${SKP_DNS_DN}d.add DomainName ${FIN_DNS_DN}
+ ${SKP_SETUP_DNS}${SKP_DNS}set Setup:/Network/Service/${PSID}/DNS
+
+ # Initialize the SMB map
+ ${SKP_SMB}d.init
+ ${SKP_SMB}${SKP_SMB_NN}d.add NetBIOSName ${FIN_SMB_NN}
+ ${SKP_SMB}${SKP_SMB_WG}d.add Workgroup ${FIN_SMB_WG}
+ ${SKP_SMB}${SKP_SMB_WA}d.add WINSAddresses * ${FIN_SMB_WA}
+ ${SKP_SMB}set State:/Network/Service/${PSID}/SMB
+
+ quit
+EOF
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: Pause for configuration changes to be propagated to State:/Network/Global/DNS and .../SMB"
+ sleep 1
+
+ scutil <<-EOF > /dev/null
+ open
+
+ # Initialize the maps that will be compared when a configuration change occurs
+ d.init
+ d.add BitmaskNoSuchKey true
+ get State:/Network/Global/DNS
+ set State:/Network/OpenVPN/DNS
+
+ d.init
+ d.add BitmaskNoSuchKey true
+ get State:/Network/Global/SMB
+ set State:/Network/OpenVPN/SMB
+
+ quit
+EOF
+
+ readonly NEW_DNS_SETUP_CONFIG="$( scutil <<-EOF |
+ open
+ show Setup:/Network/Service/${PSID}/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly NEW_SMB_SETUP_CONFIG="$( scutil <<-EOF |
+ open
+ show Setup:/Network/Service/${PSID}/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly NEW_DNS_STATE_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Service/${PSID}/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly NEW_SMB_STATE_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Service/${PSID}/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly NEW_DNS_GLOBAL_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly NEW_SMB_GLOBAL_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly EXPECTED_NEW_DNS_GLOBAL_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/OpenVPN/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+ readonly EXPECTED_NEW_SMB_GLOBAL_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/OpenVPN/SMB
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: Configurations as read back after changes:"
+ logDebugMessage "DEBUG: State:/.../DNS = ${NEW_DNS_STATE_CONFIG}"
+ logDebugMessage "DEBUG: State:/.../SMB = ${NEW_SMB_STATE_CONFIG}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: Setup:/.../DNS = ${NEW_DNS_SETUP_CONFIG}"
+ logDebugMessage "DEBUG: Setup:/.../SMB = ${NEW_SMB_SETUP_CONFIG}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: State:/Network/Global/DNS = ${NEW_DNS_GLOBAL_CONFIG}"
+ logDebugMessage "DEBUG: State:/Network/Global/SMB = ${NEW_SMB_GLOBAL_CONFIG}"
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: Expected by process-network-changes:"
+ logDebugMessage "DEBUG: State:/Network/OpenVPN/DNS = ${EXPECTED_NEW_DNS_GLOBAL_CONFIG}"
+ logDebugMessage "DEBUG: State:/Network/OpenVPN/SMB = ${EXPECTED_NEW_SMB_GLOBAL_CONFIG}"
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail if not found
+ new_resolver_contents="$( grep -v '#' < /etc/resolv.conf )"
+ set -e # resume abort on error
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: /etc/resolve = ${new_resolver_contents}"
+ logDebugMessage "DEBUG:"
+
+ set +e # scutil --dns will return error status in case dns is already down, so don't fail if no dns found
+ scutil_dns="$( scutil --dns )"
+ set -e # resume abort on error
+ logDebugMessage "DEBUG:"
+ logDebugMessage "DEBUG: scutil --dns AFTER CHANGES = ${scutil_dns}"
+ logDebugMessage "DEBUG:"
+
+ logMessage "Saved the DNS and SMB configurations so they can be restored"
+
+ logChange "${SKP_DNS}${SKP_DNS_SA}" "DNS ServerAddresses" "${FIN_DNS_SA}" "${CUR_DNS_SA}"
+ logChange "${SKP_DNS}${SKP_DNS_SD}" "DNS SearchDomains" "${FIN_DNS_SD}" "${CUR_DNS_SD}"
+ logChange "${SKP_DNS}${SKP_DNS_DN}" "DNS DomainName" "${FIN_DNS_DN}" "${CUR_DNS_DN}"
+ logChange "${SKP_SMB}${SKP_SMB_NN}" "SMB NetBIOSName" "${FIN_SMB_SA}" "${CUR_SMB_SA}"
+ logChange "${SKP_SMB}${SKP_SMB_WG}" "SMB Workgroup" "${FIN_SMB_WG}" "${CUR_SMB_WG}"
+ logChange "${SKP_SMB}${SKP_SMB_WA}" "SMB WINSAddresses" "${FIN_SMB_WA}" "${CUR_SMB_WA}"
+
+ logDnsInfo "${MAN_DNS_SA}" "${FIN_DNS_SA}"
+
+ flushDNSCache
+
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ if [ "${ARG_IGNORE_OPTION_FLAGS:0:2}" = "-p" ] ; then
+ logMessage "Setting up to monitor system configuration with process-network-changes"
+ else
+ logMessage "Setting up to monitor system configuration with leasewatch"
+ fi
+ if [ "${LEASEWATCHER_TEMPLATE_PATH}" != "" ] ; then
+ sed -e "s|/Applications/Bitmask/.app/Contents/Resources|${TB_RESOURCES_PATH}|g" "${LEASEWATCHER_TEMPLATE_PATH}" > "${LEASEWATCHER_PLIST_PATH}"
+ fi
+ launchctl load "${LEASEWATCHER_PLIST_PATH}"
+ fi
+}
+
+##########################################################################################
+# Used for TAP device which does DHCP
+configureDhcpDns()
+{
+ # whilst ipconfig will have created the neccessary Network Service keys, the DNS
+ # settings won't actually be used by OS X unless the SupplementalMatchDomains key
+ # is added
+ # ref. <http://lists.apple.com/archives/Macnetworkprog/2005/Jun/msg00011.html>
+ # - is there a way to extract the domains from the SC dictionary and re-insert
+ # as SupplementalMatchDomains? i.e. not requiring the ipconfig domain_name call?
+
+ # - wait until we get a lease before extracting the DNS domain name and merging into SC
+ # - despite it's name, ipconfig waitall doesn't (but maybe one day it will :-)
+ logDebugMessage "DEBUG: About to 'ipconfig waitall'"
+ ipconfig waitall
+ logDebugMessage "DEBUG: Completed 'ipconfig waitall'"
+
+ unset test_domain_name
+ unset test_name_server
+
+ set +e # We instruct bash NOT to exit on individual command errors, because if we need to wait longer these commands will fail
+
+ # usually takes at least a few seconds to get a DHCP lease
+ sleep 3
+ n=0
+ while [ -z "$test_domain_name" -a -z "$test_name_server" -a $n -lt 5 ]
+ do
+ logMessage "Sleeping for $n seconds to wait for DHCP to finish setup."
+ sleep $n
+ n="$( expr $n + 1 )"
+
+ if [ -z "$test_domain_name" ]; then
+ test_domain_name="$( ipconfig getoption "$dev" domain_name 2>/dev/null )"
+ fi
+
+ if [ -z "$test_name_server" ]; then
+ test_name_server="$( ipconfig getoption "$dev" domain_name_server 2>/dev/null )"
+ fi
+ done
+
+ logDebugMessage "DEBUG: Finished waiting for DHCP lease: test_domain_name = '$test_domain_name', test_name_server = '$test_name_server'"
+
+ logDebugMessage "DEBUG: About to 'ipconfig getpacket $dev'"
+ sGetPacketOutput="$( ipconfig getpacket "$dev" )"
+ logDebugMessage "DEBUG: Completed 'ipconfig getpacket $dev'; sGetPacketOutput = $sGetPacketOutput"
+
+ set -e # We instruct bash that it CAN again fail on individual errors
+
+ unset aNameServers
+ unset aWinsServers
+ unset aSearchDomains
+
+ nNameServerIndex=1
+ nWinsServerIndex=1
+ nSearchDomainIndex=1
+
+ if [ "$sGetPacketOutput" ]; then
+ sGetPacketOutput_FirstLine="$( echo "$sGetPacketOutput" | head -n 1 )"
+ logDebugMessage "DEBUG: sGetPacketOutput_FirstLine = $sGetPacketOutput_FirstLine"
+
+ if [ "$sGetPacketOutput_FirstLine" == "op = BOOTREPLY" ]; then
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+
+ for tNameServer in $( echo "$sGetPacketOutput" | grep "domain_name_server" | grep -Eo "\{([0-9\.]+)(, [0-9\.]+)*\}" | grep -Eo "([0-9\.]+)" ); do
+ aNameServers[nNameServerIndex-1]="$( trim "$tNameServer" )"
+ let nNameServerIndex++
+ done
+
+ for tWINSServer in $( echo "$sGetPacketOutput" | grep "nb_over_tcpip_name_server" | grep -Eo "\{([0-9\.]+)(, [0-9\.]+)*\}" | grep -Eo "([0-9\.]+)" ); do
+ aWinsServers[nWinsServerIndex-1]="$( trim "$tWINSServer" )"
+ let nWinsServerIndex++
+ done
+
+ for tSearchDomain in $( echo "$sGetPacketOutput" | grep "search_domain" | grep -Eo "\{([-A-Za-z0-9\-\.]+)(, [-A-Za-z0-9\-\.]+)*\}" | grep -Eo "([-A-Za-z0-9\-\.]+)" ); do
+ aSearchDomains[nSearchDomainIndex-1]="$( trim "$tSearchDomain" )"
+ let nSearchDomainIndex++
+ done
+
+ sDomainName="$( echo "$sGetPacketOutput" | grep "domain_name " | grep -Eo ": [-A-Za-z0-9\-\.]+" | grep -Eo "[-A-Za-z0-9\-\.]+" )"
+ sDomainName="$( trim "$sDomainName" )"
+
+ if [ ${#aNameServers[*]} -gt 0 -a "$sDomainName" ]; then
+ logMessage "Retrieved from DHCP/BOOTP packet: name server(s) [ ${aNameServers[@]} ], domain name [ $sDomainName ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ]"
+ setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
+ return 0
+ elif [ ${#aNameServers[*]} -gt 0 ]; then
+ logMessage "Retrieved from DHCP/BOOTP packet: name server(s) [ ${aNameServers[@]} ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ] and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
+ setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
+ return 0
+ else
+ # Should we return 1 here and indicate an error, or attempt the old method?
+ logMessage "No useful information extracted from DHCP/BOOTP packet. Attempting legacy configuration."
+ fi
+
+ set -e # We instruct bash that it CAN again fail on errors
+ else
+ # Should we return 1 here and indicate an error, or attempt the old method?
+ logMessage "No DHCP/BOOTP packet found on interface. Attempting legacy configuration."
+ fi
+ fi
+
+ unset sDomainName
+ unset sNameServer
+ unset aNameServers
+
+ set +e # We instruct bash NOT to exit on individual command errors, because if we need to wait longer these commands will fail
+
+ logDebugMessage "DEBUG: About to 'ipconfig getoption $dev domain_name'"
+ sDomainName="$( ipconfig getoption "$dev" domain_name 2>/dev/null )"
+ logDebugMessage "DEBUG: Completed 'ipconfig getoption $dev domain_name'"
+ logDebugMessage "DEBUG: About to 'ipconfig getoption $dev domain_name_server'"
+ sNameServer="$( ipconfig getoption "$dev" domain_name_server 2>/dev/null )"
+ logDebugMessage "DEBUG: Completed 'ipconfig getoption $dev domain_name_server'"
+
+ set -e # We instruct bash that it CAN again fail on individual errors
+
+ sDomainName="$( trim "$sDomainName" )"
+ sNameServer="$( trim "$sNameServer" )"
+
+ declare -a aWinsServers=( ) # Declare empty WINSServers array to avoid any useless error messages
+ declare -a aSearchDomains=( ) # Declare empty SearchDomains array to avoid any useless error messages
+
+ if [ "$sDomainName" -a "$sNameServer" ]; then
+ aNameServers[0]=$sNameServer
+ logMessage "Retrieved OpenVPN (DHCP): name server [ $sNameServer ], domain name [ $sDomainName ], and no SMB servers or search domains"
+ setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
+ elif [ "$sNameServer" ]; then
+ aNameServers[0]=$sNameServer
+ logMessage "Retrieved OpenVPN (DHCP): name server [ $sNameServer ] and no SMB servers or search domains, and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
+ setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
+ elif [ "$sDomainName" ]; then
+ logMessage "WARNING: Retrieved domain name [ $sDomainName ] but no name servers from OpenVPN via DHCP, which is not sufficient to make network/DNS configuration changes."
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ logMessage "WARNING: Will NOT monitor for other network configuration changes."
+ fi
+ logDnsInfoNoChanges
+ flushDNSCache
+ else
+ logMessage "WARNING: No DNS information received from OpenVPN via DHCP, so no network/DNS configuration changes need to be made."
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ logMessage "WARNING: Will NOT monitor for other network configuration changes."
+ fi
+ logDnsInfoNoChanges
+ flushDNSCache
+ fi
+
+ return 0
+}
+
+##########################################################################################
+# Configures using OpenVPN foreign_option_* instead of DHCP
+
+configureOpenVpnDns()
+{
+# Description of foreign_option_ parameters (from OpenVPN 2.3-alpha_2 man page):
+#
+# DOMAIN name -- Set Connection-specific DNS Suffix.
+#
+# DOMAIN-SEARCH name -- Set Connection-specific DNS Search Address. Repeat this option to
+# set additional search domains. (Bitmask-specific addition.)
+#
+# DNS addr -- Set primary domain name server address. Repeat this option to set
+# secondary DNS server addresses.
+#
+# WINS addr -- Set primary WINS server address (NetBIOS over TCP/IP Name Server).
+# Repeat this option to set secondary WINS server addresses.
+#
+# NBDD addr -- Set primary NBDD server address (NetBIOS over TCP/IP Datagram Distribution Server)
+# Repeat this option to set secondary NBDD server addresses.
+#
+# NTP addr -- Set primary NTP server address (Network Time Protocol). Repeat this option
+# to set secondary NTP server addresses.
+#
+# NBT type -- Set NetBIOS over TCP/IP Node type. Possible options: 1 = b-node
+# (broadcasts), 2 = p-node (point-to-point name queries to a WINS server), 4 = m-
+# node (broadcast then query name server), and 8 = h-node (query name server, then
+# broadcast).
+#
+# NBS scope-id -- Set NetBIOS over TCP/IP Scope. A NetBIOS Scope ID provides an
+# extended naming service for the NetBIOS over TCP/IP (Known as NBT) module. The
+# primary purpose of a NetBIOS scope ID is to isolate NetBIOS traffic on a single
+# network to only those nodes with the same NetBIOS scope ID. The NetBIOS scope ID
+# is a character string that is appended to the NetBIOS name. The NetBIOS scope ID
+# on two hosts must match, or the two hosts will not be able to communicate. The
+# NetBIOS Scope ID also allows computers to use the same computer name, as they have
+# different scope IDs. The Scope ID becomes a part of the NetBIOS name, making the
+# name unique. (This description of NetBIOS scopes courtesy of NeonSurge@abyss.com)
+#
+#DISABLE-NBT -- Disable Netbios-over-TCP/IP.
+
+ unset vForOptions
+ unset vOptions
+ unset aNameServers
+ unset aWinsServers
+ unset aSearchDomains
+
+ nOptionIndex=1
+ nNameServerIndex=1
+ nWinsServerIndex=1
+ nSearchDomainIndex=1
+
+ while vForOptions=foreign_option_$nOptionIndex; [ -n "${!vForOptions}" ]; do
+ vOptions[nOptionIndex-1]=${!vForOptions}
+ case ${vOptions[nOptionIndex-1]} in
+ *DOMAIN-SEARCH* )
+ aSearchDomains[nSearchDomainIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DOMAIN-SEARCH /}" )"
+ let nSearchDomainIndex++
+ ;;
+ *DOMAIN* )
+ sDomainName="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DOMAIN /}" )"
+ ;;
+ *DNS* )
+ aNameServers[nNameServerIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option DNS /}" )"
+ let nNameServerIndex++
+ ;;
+ *WINS* )
+ aWinsServers[nWinsServerIndex-1]="$( trim "${vOptions[nOptionIndex-1]//dhcp-option WINS /}" )"
+ let nWinsServerIndex++
+ ;;
+ * )
+ logMessage "WARNING: 'foreign_option_${nOptionIndex}' = '${vOptions[nOptionIndex-1]}' ignored"
+ ;;
+ esac
+ let nOptionIndex++
+ done
+
+ if [ ${#aNameServers[*]} -gt 0 -a "$sDomainName" ]; then
+ logMessage "Retrieved from OpenVPN: name server(s) [ ${aNameServers[@]} ], domain name [ $sDomainName ], search domain(s) [ ${aSearchDomains[@]} ], and SMB server(s) [ ${aWinsServers[@]} ]"
+ setDnsServersAndDomainName aNameServers[@] "$sDomainName" aWinsServers[@] aSearchDomains[@]
+ elif [ ${#aNameServers[*]} -gt 0 ]; then
+ logMessage "Retrieved from OpenVPN: name server(s) [ ${aNameServers[@]} ], search domain(s) [ ${aSearchDomains[@]} ] and SMB server(s) [ ${aWinsServers[@]} ] and using default domain name [ $DEFAULT_DOMAIN_NAME ]"
+ setDnsServersAndDomainName aNameServers[@] "$DEFAULT_DOMAIN_NAME" aWinsServers[@] aSearchDomains[@]
+ else
+ logMessage "WARNING: No DNS information received from OpenVPN, so no network configuration changes need to be made."
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ logMessage "WARNING: Will NOT monitor for other network configuration changes."
+ fi
+ logDnsInfoNoChanges
+ flushDNSCache
+ fi
+
+ return 0
+}
+
+##########################################################################################
+flushDNSCache()
+{
+ if ${ARG_FLUSH_DNS_CACHE} ; then
+ if [ "${OSVER}" = "10.4" ] ; then
+
+ if [ -f /usr/sbin/lookupd ] ; then
+ set +e # we will catch errors from lookupd
+ /usr/sbin/lookupd -flushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via lookupd"
+ else
+ logMessage "Flushed the DNS cache via lookupd"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/sbin/lookupd not present. Not flushing the DNS cache"
+ fi
+
+ else
+
+ if [ -f /usr/bin/dscacheutil ] ; then
+ set +e # we will catch errors from dscacheutil
+ /usr/bin/dscacheutil -flushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via dscacheutil"
+ else
+ logMessage "Flushed the DNS cache via dscacheutil"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/bin/dscacheutil not present. Not flushing the DNS cache via dscacheutil"
+ fi
+
+ if [ -f /usr/sbin/discoveryutil ] ; then
+ set +e # we will catch errors from discoveryutil
+ /usr/sbin/discoveryutil udnsflushcaches
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via discoveryutil udnsflushcaches"
+ else
+ logMessage "Flushed the DNS cache via discoveryutil udnsflushcaches"
+ fi
+ /usr/sbin/discoveryutil mdnsflushcache
+ if [ $? != 0 ] ; then
+ logMessage "WARNING: Unable to flush the DNS cache via discoveryutil mdnsflushcache"
+ else
+ logMessage "Flushed the DNS cache via discoveryutil mdnsflushcache"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "/usr/sbin/discoveryutil not present. Not flushing the DNS cache via discoveryutil"
+ fi
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ hands_off_ps="$( ps -ax | grep HandsOffDaemon | grep -v grep.HandsOffDaemon )"
+ set -e # We instruct bash that it CAN again fail on errors
+ if [ "${hands_off_ps}" = "" ] ; then
+ if [ -f /usr/bin/killall ] ; then
+ set +e # ignore errors if mDNSResponder isn't currently running
+ /usr/bin/killall -HUP mDNSResponder
+ if [ $? != 0 ] ; then
+ logMessage "mDNSResponder not running. Not notifying it that the DNS cache was flushed"
+ else
+ logMessage "Notified mDNSResponder that the DNS cache was flushed"
+ fi
+ set -e # bash should again fail on errors
+ else
+ logMessage "WARNING: /usr/bin/killall not present. Not notifying mDNSResponder that the DNS cache was flushed"
+ fi
+ else
+ logMessage "WARNING: Hands Off is running. Not notifying mDNSResponder that the DNS cache was flushed"
+ fi
+
+ fi
+ fi
+}
+
+
+##########################################################################################
+# log information about the DNS settings
+# @param String Manual DNS_SA
+# @param String New DNS_SA
+logDnsInfo() {
+
+ log_dns_info_manual_dns_sa="$1"
+ log_dns_info_new_dns_sa="$2"
+
+ if [ "${log_dns_info_manual_dns_sa}" != "" ] ; then
+ logMessage "DNS servers '${log_dns_info_manual_dns_sa}' were set manually"
+ if [ "${log_dns_info_manual_dns_sa}" != "${log_dns_info_new_dns_sa}" ] ; then
+ logMessage "WARNING: that setting is being ignored by OS X; '${log_dns_info_new_dns_sa}' is being used."
+ fi
+ fi
+
+ if [ "${log_dns_info_new_dns_sa}" != "" ] ; then
+ logMessage "DNS servers '${log_dns_info_new_dns_sa}' will be used for DNS queries when the VPN is active"
+ if [ "${log_dns_info_new_dns_sa}" == "127.0.0.1" ] ; then
+ logMessage "NOTE: DNS server 127.0.0.1 often is used inside virtual machines (e.g., 'VirtualBox', 'Parallels', or 'VMWare'). The actual VPN server may be specified by the host machine. This DNS server setting may cause DNS queries to fail or be intercepted or falsified. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
+ else
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ serversContainLoopback="$( echo "${log_dns_info_new_dns_sa}" | grep "127.0.0.1" )"
+ set -e # We instruct bash that it CAN again fail on errors
+ if [ "${serversContainLoopback}" != "" ] ; then
+ logMessage "NOTE: DNS server 127.0.0.1 often is used inside virtual machines (e.g., 'VirtualBox', 'Parallels', or 'VMWare'). The actual VPN server may be specified by the host machine. If used, 127.0.0.1 may cause DNS queries to fail or be intercepted or falsified. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
+ else
+ readonly knownPublicDnsServers="$( cat "${FREE_PUBLIC_DNS_SERVERS_LIST_PATH}" )"
+ knownDnsServerNotFound="true"
+ unknownDnsServerFound="false"
+ for server in ${log_dns_info_new_dns_sa} ; do
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+ serverIsKnown="$( echo "${knownPublicDnsServers}" | grep "${server}" )"
+ set -e # We instruct bash that it CAN again fail on errors
+ if [ "${serverIsKnown}" != "" ] ; then
+ knownDnsServerNotFound="false"
+ else
+ unknownDnsServerFound="true"
+ fi
+ done
+ if ${knownDnsServerNotFound} ; then
+ logMessage "NOTE: The DNS servers do not include any free public DNS servers known to Bitmask. This may cause DNS queries to fail or be intercepted or falsified even if they are directed through the VPN. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
+ else
+ if ${unknownDnsServerFound} ; then
+ logMessage "NOTE: The DNS servers include one or more free public DNS servers known to Bitmask and one or more DNS servers not known to Bitmask. If used, the DNS servers not known to Bitmask may cause DNS queries to fail or be intercepted or falsified even if they are directed through the VPN. Specify only known public DNS servers or DNS servers located on the VPN network to avoid such problems."
+ else
+ logMessage "The DNS servers include only free public DNS servers known to Bitmask."
+ fi
+ fi
+ fi
+ fi
+ else
+ logMessage "WARNING: There are no DNS servers in this computer's new network configuration. This computer or a DHCP server that this computer uses may be configured incorrectly."
+ fi
+}
+
+logDnsInfoNoChanges() {
+# log information about DNS settings if they are not changing
+
+ set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+
+ PSID="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/IPv4
+ quit
+EOF
+grep PrimaryService | sed -e 's/.*PrimaryService : //'
+)"
+
+ readonly LOGDNSINFO_MAN_DNS_CONFIG="$( scutil <<-EOF |
+ open
+ show Setup:/Network/Service/${PSID}/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+ readonly LOGDNSINFO_CUR_DNS_CONFIG="$( scutil <<-EOF |
+ open
+ show State:/Network/Global/DNS
+ quit
+EOF
+sed -e 's/^[[:space:]]*[[:digit:]]* : //g' | tr '\n' ' '
+)"
+
+ if echo "${LOGDNSINFO_MAN_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
+ readonly LOGDNSINFO_MAN_DNS_SA="$( trim "$( echo "${LOGDNSINFO_MAN_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly LOGDNSINFO_MAN_DNS_SA="";
+ fi
+
+ if echo "${LOGDNSINFO_CUR_DNS_CONFIG}" | grep -q "ServerAddresses" ; then
+ readonly LOGDNSINFO_CUR_DNS_SA="$( trim "$( echo "${LOGDNSINFO_CUR_DNS_CONFIG}" | sed -e 's/^.*ServerAddresses[^{]*{[[:space:]]*\([^}]*\)[[:space:]]*}.*$/\1/g' )" )"
+ else
+ readonly LOGDNSINFO_CUR_DNS_SA="";
+ fi
+
+ set -e # resume abort on error
+
+ logDnsInfo "${LOGDNSINFO_MAN_DNS_SA}" "${LOGDNSINFO_CUR_DNS_SA}"
+}
+
+##########################################################################################
+#
+# START OF SCRIPT
+#
+##########################################################################################
+
+trap "" TSTP
+trap "" HUP
+trap "" INT
+export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
+
+readonly OUR_NAME="$( basename "${0}" )"
+
+logMessage "**********************************************"
+logMessage "Start of output from ${OUR_NAME}"
+
+# Process optional arguments (if any) for the script
+# Each one begins with a "-"
+# They come from Bitmask, and come first, before the OpenVPN arguments
+# So we set ARG_ script variables to their values and shift them out of the argument list
+# When we're done, only the OpenVPN arguments remain for the rest of the script to use
+ARG_TAP="false"
+ARG_WAIT_FOR_DHCP_IF_TAP="false"
+ARG_RESTORE_ON_DNS_RESET="false"
+ARG_FLUSH_DNS_CACHE="false"
+ARG_IGNORE_OPTION_FLAGS=""
+ARG_EXTRA_LOGGING="false"
+ARG_MONITOR_NETWORK_CONFIGURATION="false"
+ARG_DO_NO_USE_DEFAULT_DOMAIN="false"
+ARG_PREPEND_DOMAIN_NAME="false"
+ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="false"
+ARG_TB_PATH="/Applications/Bitmask.app"
+ARG_RESTORE_ON_WINS_RESET="false"
+ARG_DISABLE_IPV6_ON_TUN="false"
+ARG_ENABLE_IPV6_ON_TAP="false"
+
+# Handle the arguments we know about by setting ARG_ script variables to their values, then shift them out
+while [ {$#} ] ; do
+ if [ "$1" = "-6" ] ; then # -6 = ARG_ENABLE_IPV6_ON_TAP (for TAP connections only)
+ ARG_ENABLE_IPV6_ON_TAP="true"
+ shift
+ elif [ "$1" = "-9" ] ; then # -9 = ARG_DISABLE_IPV6_ON_TUN (for TUN connections only)
+ ARG_DISABLE_IPV6_ON_TUN="true"
+ shift
+ elif [ "$1" = "-a" ] ; then # -a = ARG_TAP
+ ARG_TAP="true"
+ shift
+ elif [ "$1" = "-b" ] ; then # -b = ARG_WAIT_FOR_DHCP_IF_TAP
+ ARG_WAIT_FOR_DHCP_IF_TAP="true"
+ shift
+ elif [ "$1" = "-d" ] ; then # -d = ARG_RESTORE_ON_DNS_RESET
+ ARG_RESTORE_ON_DNS_RESET="true"
+ shift
+ elif [ "$1" = "-f" ] ; then # -f = ARG_FLUSH_DNS_CACHE
+ ARG_FLUSH_DNS_CACHE="true"
+ shift
+ elif [ "${1:0:2}" = "-i" ] ; then # -i arguments are for leasewatcher
+ ARG_IGNORE_OPTION_FLAGS="${1}"
+ shift
+ elif [ "$1" = "-l" ] ; then # -l = ARG_EXTRA_LOGGING
+ ARG_EXTRA_LOGGING="true"
+ shift
+ elif [ "$1" = "-m" ] ; then # -m = ARG_MONITOR_NETWORK_CONFIGURATION
+ ARG_MONITOR_NETWORK_CONFIGURATION="true"
+ shift
+ elif [ "$1" = "-n" ] ; then # -n = ARG_DO_NO_USE_DEFAULT_DOMAIN
+ ARG_DO_NO_USE_DEFAULT_DOMAIN="true"
+ shift
+ elif [ "$1" = "-p" ] ; then # -p = ARG_PREPEND_DOMAIN_NAME
+ ARG_PREPEND_DOMAIN_NAME="true"
+ shift
+ elif [ "${1:0:2}" = "-p" ] ; then # -p arguments are for process-network-changes
+ ARG_IGNORE_OPTION_FLAGS="${1}"
+ shift
+ elif [ "$1" = "-r" ] ; then # -r = ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT
+ ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT="true"
+ shift
+ elif [ "${1:0:2}" = "-t" ] ; then
+ ARG_TB_PATH="${1:2}" # -t path of Bitmask.app
+ shift
+ elif [ "$1" = "-w" ] ; then # -w = ARG_RESTORE_ON_WINS_RESET
+ ARG_RESTORE_ON_WINS_RESET="true"
+ shift
+ else
+ if [ "${1:0:1}" = "-" ] ; then # Shift out Bitmask arguments (they start with "-") that we don't understand
+ shift # so the rest of the script sees only the OpenVPN arguments
+ else
+ break
+ fi
+ fi
+done
+
+readonly ARG_MONITOR_NETWORK_CONFIGURATION ARG_RESTORE_ON_DNS_RESET ARG_RESTORE_ON_WINS_RESET ARG_TAP ARG_PREPEND_DOMAIN_NAME ARG_FLUSH_DNS_CACHE ARG_RESET_PRIMARY_INTERFACE_ON_DISCONNECT ARG_IGNORE_OPTION_FLAGS
+
+# Note: The script log path name is constructed from the path of the regular config file, not the shadow copy
+# if the config is shadow copy, e.g. /Library/Application Support/Bitmask/Users/Jonathan/Folder/Subfolder/config.ovpn
+# then convert to regular config /Users/Jonathan/Library/Application Support/Bitmask/Configurations/Folder/Subfolder/config.ovpn
+# to get the script log path
+# Note: "/Users/..." works even if the home directory has a different path; it is used in the name of the log file, and is not used as a path to get to anything.
+readonly TBALTPREFIX="/Library/Application Support/Bitmask/Users/"
+readonly TBALTPREFIXLEN="${#TBALTPREFIX}"
+readonly TBCONFIGSTART="${config:0:$TBALTPREFIXLEN}"
+if [ "$TBCONFIGSTART" = "$TBALTPREFIX" ] ; then
+ readonly TBBASE="${config:$TBALTPREFIXLEN}"
+ readonly TBSUFFIX="${TBBASE#*/}"
+ readonly TBUSERNAME="${TBBASE%%/*}"
+ readonly TBCONFIG="/Users/$TBUSERNAME/Library/Application Support/Bitmask/Configurations/$TBSUFFIX"
+else
+ readonly TBCONFIG="${config}"
+fi
+
+readonly CONFIG_PATH_DASHES_SLASHES="$( echo "${TBCONFIG}" | sed -e 's/-/--/g' | sed -e 's/\//-S/g' )"
+readonly SCRIPT_LOG_FILE="/Library/Application Support/Bitmask/Logs/${CONFIG_PATH_DASHES_SLASHES}.script.log"
+
+readonly TB_RESOURCES_PATH="${ARG_TB_PATH}/Contents/Resources"
+readonly FREE_PUBLIC_DNS_SERVERS_LIST_PATH="${TB_RESOURCES_PATH}/FreePublicDnsServersList.txt"
+
+# These scripts use a launchd .plist to set up to monitor the network configuration.
+#
+# If Bitmask.app is located in /Applications, we load the launchd .plist directly from within the .app.
+#
+# If Bitmask.app is not located in /Applications (i.e., we are debugging), we create a modified version of the launchd .plist and use
+# that modified copy in the 'launchctl load' command. (The modification is that the path to process-network-changes or leasewatch program
+# in the .plist is changed to point to the copy of the program that is inside the running Bitmask.)
+#
+# The variables involved in this are set up here:
+#
+# LEASEWATCHER_PLIST_PATH is the path of the .plist to use in the 'launchctl load' command
+# LEASEWATCHER_TEMPLATE_PATH is an empty string if we load the .plist directly from within the .app,
+# or it is the path to the original .plist inside the .app which we copy and modify
+# REMOVE_LEASEWATCHER_PLIST is "true" if a modified .plist was used and should be deleted after it is unloaded
+# or "false' if the plist was loaded directly from the .app
+#
+# LEASEWATCHER_PLIST_PATH and REMOVE_LEASEWATCHER_PLIST are passed to the other scripts via the scutil State:/Network/OpenVPN mechanism
+
+if [ "${ARG_IGNORE_OPTION_FLAGS:0:2}" = "-p" ] ; then
+ readonly LEASEWATCHER_PLIST="ProcessNetworkChanges.plist"
+else
+ readonly LEASEWATCHER_PLIST="LeaseWatch.plist"
+fi
+if [ "${ARG_TB_PATH}" = "/Applications/Bitmask.app" ] ; then
+ readonly LEASEWATCHER_PLIST_PATH="${TB_RESOURCES_PATH}/${LEASEWATCHER_PLIST}"
+ readonly LEASEWATCHER_TEMPLATE_PATH=""
+ readonly REMOVE_LEASEWATCHER_PLIST="false"
+else
+ readonly LEASEWATCHER_PLIST_PATH="/Library/Application Support/Bitmask/${LEASEWATCHER_PLIST}"
+ readonly LEASEWATCHER_TEMPLATE_PATH="${TB_RESOURCES_PATH}/${LEASEWATCHER_PLIST}"
+ readonly REMOVE_LEASEWATCHER_PLIST="true"
+fi
+
+set +e # "grep" will return error status (1) if no matches are found, so don't fail on individual errors
+readonly OSVER="$( sw_vers | grep 'ProductVersion:' | grep -o '10\.[0-9]*' )"
+set -e # We instruct bash that it CAN again fail on errors
+
+if ${ARG_DO_NO_USE_DEFAULT_DOMAIN} ; then
+ readonly DEFAULT_DOMAIN_NAME=""
+else
+ readonly DEFAULT_DOMAIN_NAME="openvpn"
+fi
+
+bRouteGatewayIsDhcp="false"
+
+# We sleep to allow time for OS X to process network settings
+sleep 2
+
+EXIT_CODE=0
+
+if ${ARG_TAP} ; then
+
+ # IPv6 should be re-enabled only for TUN, not TAP
+ readonly ipv6_disabled_services=""
+ readonly ipv6_disabled_services_encoded=""
+
+ # Still need to do: Look for route-gateway dhcp (TAP isn't always DHCP)
+ bRouteGatewayIsDhcp="false"
+ if [ -z "${route_vpn_gateway}" -o "$route_vpn_gateway" == "dhcp" -o "$route_vpn_gateway" == "DHCP" ]; then
+ bRouteGatewayIsDhcp="true"
+ fi
+
+ if [ "$bRouteGatewayIsDhcp" == "true" ]; then
+ logDebugMessage "DEBUG: bRouteGatewayIsDhcp is TRUE"
+ if [ -z "$dev" ]; then
+ logMessage "ERROR: Cannot configure TAP interface for DHCP without \$dev being defined. Exiting."
+ # We don't create the "/tmp/bitmask-downscript-needs-to-be-run.txt" file, because the down script does NOT need to be run since we didn't do anything
+ logMessage "End of output from ${OUR_NAME}"
+ logMessage "**********************************************"
+ exit 1
+ fi
+
+ logDebugMessage "DEBUG: About to 'ipconfig set \"$dev\" DHCP"
+ ipconfig set "$dev" DHCP
+ logMessage "Did 'ipconfig set \"$dev\" DHCP'"
+
+ if ${ARG_ENABLE_IPV6_ON_TAP} ; then
+ ipconfig set "$dev" AUTOMATIC-V6
+ logMessage "Did 'ipconfig set \"$dev\" AUTOMATIC-V6'"
+ fi
+
+ if ${ARG_WAIT_FOR_DHCP_IF_TAP} ; then
+ logMessage "Configuring tap DNS via DHCP synchronously"
+ configureDhcpDns
+ else
+ logMessage "Configuring tap DNS via DHCP asynchronously"
+ configureDhcpDns & # This must be run asynchronously; the DHCP lease will not complete until this script exits
+ EXIT_CODE=0
+ fi
+ elif [ "$foreign_option_1" == "" ]; then
+ logMessage "NOTE: No network configuration changes need to be made."
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ logMessage "WARNING: Will NOT monitor for other network configuration changes."
+ fi
+ if ${ARG_ENABLE_IPV6_ON_TAP} ; then
+ logMessage "WARNING: Will NOT set up IPv6 on TAP device because it does not use DHCP."
+ fi
+ logDnsInfoNoChanges
+ flushDNSCache
+ else
+ if ${ARG_ENABLE_IPV6_ON_TAP} ; then
+ logMessage "WARNING: Will NOT set up IPv6 on TAP device because it does not use DHCP."
+ fi
+ logMessage "Configuring tap DNS via OpenVPN"
+ configureOpenVpnDns
+ EXIT_CODE=$?
+ fi
+else
+ if [ "$foreign_option_1" == "" ]; then
+ logMessage "NOTE: No network configuration changes need to be made."
+ if ${ARG_MONITOR_NETWORK_CONFIGURATION} ; then
+ logMessage "WARNING: Will NOT monitor for other network configuration changes."
+ fi
+ if ${ARG_DISABLE_IPV6_ON_TUN} ; then
+ logMessage "WARNING: Will NOT disable IPv6 settings."
+ fi
+ logDnsInfoNoChanges
+ flushDNSCache
+ else
+
+ ipv6_disabled_services=""
+ if ${ARG_DISABLE_IPV6_ON_TUN} ; then
+ ipv6_disabled_services="$( disable_ipv6 )"
+ if [ "$ipv6_disabled_services" != "" ] ; then
+ printf %s "$ipv6_disabled_services
+" | \
+ while IFS= read -r dipv6_service ; do
+ logMessage "Disabled IPv6 for '$dipv6_service'"
+ done
+ fi
+ fi
+ readonly ipv6_disabled_services
+ # Note '\n' is translated into '\t' so it is all on one line, because grep and sed only work with single lines
+ readonly ipv6_disabled_services_encoded="$( echo "$ipv6_disabled_services" | tr '\n' '\t' )"
+
+ configureOpenVpnDns
+ EXIT_CODE=$?
+ fi
+fi
+
+touch "/tmp/bitmask-downscript-needs-to-be-run.txt"
+
+logMessage "End of output from ${OUR_NAME}"
+logMessage "**********************************************"
+
+exit $EXIT_CODE
diff --git a/branding/templates/osx/cross-compile.txt b/branding/templates/osx/cross-compile.txt
new file mode 100644
index 0000000..bf3b5ec
--- /dev/null
+++ b/branding/templates/osx/cross-compile.txt
@@ -0,0 +1,11 @@
+# some notes on cross-compiling for osx
+
+wget https://s3.dockerproject.org/darwin/v2/MacOSX10.10.sdk.tar.xz
+sha256sum 631b4144c6bf75bf7a4d480d685a9b5bda10ee8d03dbf0db829391e2ef858789
+git clone https://github.com/tpoechtrager/osxcross
+mv MacOSX* osxcross/tarballs
+sudo apt-get install -y --force-yes clang llvm-dev libxml2-dev uuid-dev \
+ libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev
+cd oscross
+./build.sh
+PATH=$PATH:/home/user/dev/osxcross/osxcross/target/bin/ MACOSX_DEPLOYMENT_TARGET=10.10 CGO_ENABLED=1 GOOS=darwin CC="o64-clang" go build 0xacab.org/leap/bitmask-systray
diff --git a/branding/templates/osx/generate.py b/branding/templates/osx/generate.py
new file mode 100644
index 0000000..528605d
--- /dev/null
+++ b/branding/templates/osx/generate.py
@@ -0,0 +1,153 @@
+#!/usr/bin/python
+
+# Generate bundles for brandable Bitmask Lite.
+
+# (c) LEAP Encryption Access Project
+# (c) Kali Kaneko 2018-2019
+
+import json
+import os
+import os.path
+import shutil
+import stat
+
+from string import Template
+
+here = os.path.split(os.path.abspath(__file__))[0]
+
+ENTRYPOINT = 'bitmask-vpn'
+HELPER = 'bitmask-helper'
+OPENVPN = 'openvpn-osx'
+TEMPLATE_INFO = 'template-info.plist'
+TEMPLATE_HELPER = 'template-helper.plist'
+
+TEMPLATE_PREINSTALL = 'template-preinstall'
+TEMPLATE_POSTINSTALL = 'template-postinstall'
+
+
+data = json.load(open(os.path.join(here, 'data.json')))
+APPNAME = data.get('applicationName')
+VERSION = data.get('version', 'unknown')
+
+APP_PATH = os.path.abspath(here + '/../dist/' + APPNAME + ".app")
+STAGING = os.path.abspath(here + '/../staging/')
+ASSETS = os.path.abspath(here + '/../assets/')
+ICON = os.path.join(ASSETS, APPNAME.lower() + '.icns')
+SCRIPTS = os.path.join(os.path.abspath(here), 'scripts')
+INFO_PLIST = APP_PATH + '/Contents/Info.plist'
+HELPER_PLIST = os.path.join(SCRIPTS, 'se.leap.bitmask-helper.plist')
+PREINSTALL = os.path.join(SCRIPTS, 'preinstall')
+POSTINSTALL = os.path.join(SCRIPTS, 'postinstall')
+RULEFILE = os.path.join(here, 'bitmask.pf.conf')
+VPN_UP = os.path.join(here, 'client.up.sh')
+VPN_DOWN = os.path.join(here, 'client.down.sh')
+
+try:
+ os.makedirs(APP_PATH + "/Contents/MacOS")
+except Exception:
+ pass
+try:
+ os.makedirs(APP_PATH + "/Contents/Resources")
+except Exception:
+ pass
+try:
+ os.makedirs(APP_PATH + "/Contents/helper")
+except Exception:
+ pass
+
+
+data['entrypoint'] = ENTRYPOINT
+data['info_string'] = APPNAME + " " + VERSION
+data['bundle_identifier'] = 'se.leap.' + data['applicationNameLower']
+data['bundle_name'] = APPNAME
+
+# utils
+
+
+def copy_payload(filename, destfile=None):
+ if destfile is None:
+ destfile = APP_PATH + "/Contents/MacOS/" + filename
+ else:
+ destfile = APP_PATH + destfile
+ shutil.copyfile(STAGING + '/' + filename, destfile)
+ cmode = os.stat(destfile).st_mode
+ os.chmod(destfile, cmode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+
+
+def generate_from_template(template, dest, data):
+ print("[+] File written from template to", dest)
+ template = Template(open(template).read())
+ with open(dest, 'w') as output:
+ output.write(template.substitute(data))
+
+
+# 1. Generation of the Bundle Info.plist
+# --------------------------------------
+
+generate_from_template(TEMPLATE_INFO, INFO_PLIST, data)
+
+
+# 2. Generate PkgInfo
+# -------------------------------------------
+
+with open(APP_PATH + "/Contents/PkgInfo", "w") as f:
+ # is this enough? See what PyInstaller does.
+ f.write("APPL????")
+
+
+# 3. Copy the binary payloads
+# --------------------------------------------
+
+copy_payload(ENTRYPOINT)
+copy_payload(HELPER)
+copy_payload(OPENVPN, destfile='/Contents/Resources/openvpn.leap')
+
+# 4. Copy the app icon from the assets folder
+# -----------------------------------------------
+
+shutil.copyfile(ICON, APP_PATH + '/Contents/Resources/app.icns')
+
+
+# 5. Generate the scripts for the installer
+# -----------------------------------------------
+
+# Watch out that, for now, all the brandings are sharing the same helper name.
+# This is intentional: I prefer not to have too many root helpers laying around
+# until we consolidate a way of uninstalling and/or updating them.
+# This also means that only one of the derivatives will work at a given time
+# (ie, uninstall bitmask legacy to use riseupvpn).
+# If this bothers you, and it should, let's work on improving uninstall and
+# updates.
+
+generate_from_template(TEMPLATE_HELPER, HELPER_PLIST, data)
+generate_from_template(TEMPLATE_PREINSTALL, PREINSTALL, data)
+generate_from_template(TEMPLATE_POSTINSTALL, POSTINSTALL, data)
+
+# 6. Copy helper pf rule file
+# ------------------------------------------------
+
+shutil.copy(RULEFILE, APP_PATH + '/Contents/helper/')
+
+# 7. Copy openvpn up/down scripts
+# ------------------------------------------------
+
+shutil.copy(VPN_UP, APP_PATH + '/Contents/helper/')
+shutil.copy(VPN_DOWN, APP_PATH + '/Contents/helper/')
+
+
+# 8. Generate uninstall script
+# -----------------------------------------------
+# TODO copy the uninstaller script from bitmask-dev
+# TODO substitute vars
+# this is a bit weak procedure for now.
+# To begin with, this assumes everything is hardcoded into
+# /Applications/APPNAME.app
+# We could consider moving the helpers into /usr/local/sbin,
+# so that the plist files always reference there.
+
+
+# We're all set!
+# -----------------------------------------------
+print("[+] Output written to build/{provider}/dist/{appname}.app".format(
+ provider=data['name'].lower(),
+ appname=APPNAME))
diff --git a/branding/templates/osx/quickpkg b/branding/templates/osx/quickpkg
new file mode 100755
index 0000000..a8d0498
--- /dev/null
+++ b/branding/templates/osx/quickpkg
@@ -0,0 +1,557 @@
+#!/usr/bin/python
+
+import argparse
+import string
+import os
+import subprocess
+import tempfile
+import shutil
+import stat
+
+# includes FoundationPlist since some apps store their Info.plist
+# as binary PropertyLists
+
+# FoundationPlist:
+
+# Copyright 2009-2014 Greg Neagle.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""FoundationPlist.py -- a tool to generate and parse MacOSX .plist files.
+
+This is intended as a drop-in replacement for Python's included plistlib,
+with a few caveats:
+ - readPlist() and writePlist() operate only on a filepath,
+ not a file object.
+ - there is no support for the deprecated functions:
+ readPlistFromResource()
+ writePlistToResource()
+ - there is no support for the deprecated Plist class.
+
+The Property List (.plist) file format is a simple XML pickle supporting
+basic object types, like dictionaries, lists, numbers and strings.
+Usually the top level object is a dictionary.
+
+To write out a plist file, use the writePlist(rootObject, filepath)
+function. 'rootObject' is the top level object, 'filepath' is a
+filename.
+
+To parse a plist from a file, use the readPlist(filepath) function,
+with a file name. It returns the top level object (again, usually a
+dictionary).
+
+To work with plist data in strings, you can use readPlistFromString()
+and writePlistToString().
+"""
+
+from Foundation import NSData, \
+ NSPropertyListSerialization, \
+ NSPropertyListMutableContainersAndLeaves, \
+ NSPropertyListXMLFormat_v1_0
+
+
+class FoundationPlistException(Exception):
+ '''Base error for this module'''
+ pass
+
+
+class NSPropertyListSerializationException(FoundationPlistException):
+ '''Read error for this module'''
+ pass
+
+
+class NSPropertyListWriteException(FoundationPlistException):
+ '''Write error for this module'''
+ pass
+
+
+# private functions
+def _dataToPlist(data):
+ '''low-level function that parses a data object into a propertyList object'''
+ darwin_vers = int(os.uname()[2].split('.')[0])
+ if darwin_vers > 10:
+ (plistObject, plistFormat, error) = (
+ NSPropertyListSerialization.propertyListWithData_options_format_error_(
+ data, NSPropertyListMutableContainersAndLeaves, None, None))
+ else:
+ # 10.5 doesn't support propertyListWithData:options:format:error:
+ # 10.6's PyObjC wrapper for propertyListWithData:options:format:error:
+ # is broken
+ # so use the older NSPropertyListSerialization function
+ (plistObject, plistFormat, error) = (
+ NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
+ data, NSPropertyListMutableContainersAndLeaves, None, None))
+ if plistObject is None:
+ if error is None:
+ error = "Plist data is invalid and could not be deserialized."
+ raise NSPropertyListSerializationException(error)
+ else:
+ return plistObject
+
+
+def _plistToData(plistObject):
+ '''low-level function that creates NSData from a plist object'''
+ darwin_vers = int(os.uname()[2].split('.')[0])
+ if darwin_vers > 10:
+ (data, error) = (
+ NSPropertyListSerialization.dataWithPropertyList_format_options_error_(
+ plistObject, NSPropertyListXMLFormat_v1_0, 0, None))
+ else:
+ # use the older NSPropertyListSerialization function on 10.6 and 10.5
+ (data, error) = (
+ NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_(
+ plistObject, NSPropertyListXMLFormat_v1_0, None))
+ if data is None:
+ if error is None:
+ error = "Property list invalid for format."
+ raise NSPropertyListSerializationException(error)
+ return data
+
+
+# public functions
+def readPlist(filepath):
+ '''Read a .plist file from filepath. Return the unpacked root object
+ (which is usually a dictionary).'''
+ try:
+ data = NSData.dataWithContentsOfFile_(filepath)
+ except NSPropertyListSerializationException, error:
+ # insert filepath info into error message
+ errmsg = (u'%s in %s' % (error, filepath))
+ raise NSPropertyListSerializationException(errmsg)
+ return _dataToPlist(data)
+
+
+def readPlistFromString(aString):
+ '''Read a plist data from a string. Return the root object.'''
+ data = buffer(aString)
+ return _dataToPlist(data)
+
+
+def writePlist(plistObject, filepath):
+ '''Write 'plistObject' as a plist to filepath.'''
+ plistData = _plistToData(plistObject)
+ if plistData.writeToFile_atomically_(filepath, True):
+ return
+ else:
+ raise NSPropertyListWriteException(
+ u"Failed to write plist data to %s" % filepath)
+
+
+def writePlistToString(plistObject):
+ '''Create a plist-formatted string from plistObject.'''
+ return str(_plistToData(plistObject))
+
+
+#
+# quickpkg
+#
+
+
+quickpkg_version = '0.5'
+supported_extensions = ['dmg', 'app', 'zip']
+
+
+# modeled after munkiimport but to build a pkg
+
+
+def logger(log, v=0):
+ if args.verbosity >= v:
+ print log
+
+
+def cmdexec(command, stdin=''):
+ """Execute a command."""
+ # if 'command' is a string, split the string into components
+ if isinstance(command, str):
+ command = command.split()
+
+ proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+ (stdout, stderr) = proc.communicate(stdin)
+
+ logger("cmdexec: %s, result: %s, error: %s" % (command, stdout, stderr), 3)
+
+ # strip trailing whitespace, which would mess with string comparisons
+ return {"return_code": proc.returncode, "stderr": stderr.rstrip(), "stdout": stdout.rstrip()}
+
+
+# from munkicommons.py
+def getFirstPlist(textString):
+ """Gets the next plist from a text string that may contain one or
+ more text-style plists.
+ Returns a tuple - the first plist (if any) and the remaining
+ string after the plist"""
+ plist_header = '<?xml version'
+ plist_footer = '</plist>'
+ plist_start_index = textString.find(plist_header)
+ if plist_start_index == -1:
+ # not found
+ return ("", textString)
+ plist_end_index = textString.find(
+ plist_footer, plist_start_index + len(plist_header))
+ if plist_end_index == -1:
+ # not found
+ return ("", textString)
+ # adjust end value
+ plist_end_index = plist_end_index + len(plist_footer)
+ return (textString[plist_start_index:plist_end_index],
+ textString[plist_end_index:])
+
+
+def dmg_has_sla(dmgpath):
+ has_sla = False
+ imageinfo_cmd = ['/usr/bin/hdiutil', 'imageinfo', dmgpath, '-plist']
+ result = cmdexec(imageinfo_cmd)
+ if result["return_code"] != 0:
+ print "error getting imageinfo! %s, %s" % (result["return_code"], result["stderr"])
+ return False
+ result_plist = result["stdout"]
+ imageinfo_dict = readPlistFromString(result_plist)
+ properties = imageinfo_dict.get('Properties')
+ if properties is not None:
+ has_sla = properties.get('Software License Agreement', False)
+ return has_sla
+
+
+def attachdmg(dmgpath):
+ global dmg_was_mounted
+ info_cmd = ["hdiutil", "info", "-plist"]
+ info_result = cmdexec(info_cmd)
+ if info_result["return_code"] == 0:
+ # parse the plist output
+ (theplist, alltext) = getFirstPlist(info_result["stdout"])
+ info_dict = readPlistFromString(theplist)
+ volpaths = []
+ if "images" in info_dict.keys():
+ for y in info_dict["images"]:
+ if "image-path" in y.keys():
+ if os.path.samefile(y["image-path"], dmgpath):
+ for x in y.get("system-entities"):
+ if "mount-point" in x.keys():
+ volpaths.append(x["mount-point"])
+ dmg_was_mounted = True
+ return volpaths
+ else:
+ print "error getting hdiutil info"
+ print "(%d, %s)" % (info_result["returncode"], info_result["stderr"])
+ cleanup_and_exit(1)
+
+ attachcmd = ["/usr/bin/hdiutil",
+ "attach",
+ dmgpath,
+ "-mountrandom",
+ "/private/tmp",
+ "-plist",
+ "-nobrowse"]
+ if dmg_has_sla(dmgpath):
+ stdin = "Y\n"
+ print "NOTE: Disk image %s has a license agreement!" % dmgpath
+ else:
+ stdin = ''
+ result = cmdexec(attachcmd, stdin)
+ if result["return_code"] == 0:
+ # parse the plist output
+ (theplist, alltext) = getFirstPlist(result["stdout"])
+ resultdict = readPlistFromString(theplist)
+ volpaths = []
+ for x in resultdict["system-entities"]:
+ if x["potentially-mountable"]:
+ if x["volume-kind"] == 'hfs':
+ volpaths.append(x["mount-point"])
+ # return the paths to mounted volume
+ return volpaths
+ else:
+ print "error mounting disk image"
+ print "(%d, %s)" % (result["returncode"], result["stderr"])
+ cleanup_and_exit(1)
+
+
+def detachpaths(volpaths):
+ for x in volpaths:
+ if os.path.exists(x):
+ if os.path.ismount(x):
+ detachcmd = ["/usr/bin/hdiutil", "detach", x]
+ cmdexec(detachcmd)
+
+
+def finditemswithextension(dirpath, item_extension):
+ foundapps = []
+ if os.path.exists(dirpath):
+ for x in os.listdir(dirpath):
+ (item_basename, item_extension) = os.path.splitext(x)
+ item_extension = string.lstrip(item_extension, '.')
+ if item_extension == 'app':
+ foundapps.append(os.path.join(dirpath, x))
+ else:
+ print "path %s does not exist" % dirpath
+ cleanup_and_exit(1)
+ return foundapps
+
+
+def appNameAndVersion(app_path):
+ info_path = os.path.join(app_path, "Contents/Info.plist")
+ if not os.path.exists(info_path):
+ print "Application at path %s does not have Info.plist" % app_path
+ # TODO: cleanup volumes here
+ cleanup_and_exit(1)
+ info_plist = readPlist(info_path)
+ app_name = info_plist.get("CFBundleName")
+ if app_name is None:
+ app_name = info_plist.get("CFBundleDisplayName")
+ if app_name is None:
+ (app_name, app_ext) = os.path.splitext(os.path.basename(app_path))
+ app_identifier = info_plist.get("CFBundleIdentifier")
+ app_version = info_plist.get("CFBundleShortVersionString")
+ if app_version is None:
+ app_version = info_plist.get("CFBundleVersion")
+ return (app_name, app_identifier, app_version)
+
+
+def cleanup_and_exit(returncode):
+ global dmgvolumepaths
+ global dmg_was_mounted
+ global tmp_path
+
+ if args.clean:
+ if not dmg_was_mounted:
+ detachpaths(dmgvolumepaths)
+ if tmp_path is not None:
+ shutil.rmtree(tmp_path)
+ exit(returncode)
+
+
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(description="""Attempts to build a pkg from the input.
+ Installer item can be a dmg, zip, or app.""",
+ epilog="""Example: quickpkg /path/to/installer_item""")
+
+ # takes a path as input
+ parser.add_argument('item_path', help="path to the installer item")
+
+ scripts_group = parser.add_argument_group('Installation Scripts',
+ '''These options will set the installation scripts. You pass an entire folder of scripts,
+ just like the option of `pkgbuild` or you can give a file for the preinstall or postinstall
+ scripts respectively. If you give both the --scripts and either one or both of --preinstall
+ and --postinstall, quickpkg will attempt to merge, but throw an error if it cannot.''')
+ scripts_group.add_argument('--scripts', help="path to a folder with scripts")
+ scripts_group.add_argument('--preinstall', '--pre', help="path to the preinstall script")
+ scripts_group.add_argument('--postinstall', '--post', help="path to the postinstall script")
+
+ parser.add_argument('--ownership', choices=['recommended', 'preserve', 'preserve-other'],
+ help="will be passed through to pkgbuild")
+ parser.add_argument('--output', '--out', '-o',
+ help='''path where the package file will be created. If you give the full filename
+ then you can use '{name}', '{version}' and '{identifier}' as placeholders.
+ If this is a directory, then the
+ package will be created with the default filename {name}-{version}.pkg''')
+
+ parser.add_argument('--clean', dest='clean', action='store_true', help="clean up temp files (DEFAULT)")
+ parser.add_argument('--no-clean', dest='clean', action='store_false', help=" do NOT clean up temp files")
+ parser.set_defaults(clean=True)
+
+ parser.add_argument('--relocatable', dest='relocatable', action='store_true',
+ help="sets BundleIsRelocatable in the PackageInfo to true")
+ parser.add_argument('--no-relocatable', dest='relocatable', action='store_false',
+ help="sets BundleIsRelocatable in the PackageInfo (DEFAULT is false)")
+ parser.set_defaults(relocatable=False)
+
+
+ parser.add_argument("-v", "--verbosity", action="count", default=0, help="controls amount of logging output (max -vvv)")
+ parser.add_argument('--version', help='prints the version', action='version', version=quickpkg_version)
+
+ args = parser.parse_args()
+
+ # remove trailing '/' from path
+ item_path = string.rstrip(args.item_path, '/')
+
+ if item_path.startswith('~'):
+ item_path = os.path.expanduser(item_path)
+ item_path = os.path.abspath(item_path)
+
+ # get file extension
+ (item_basename, item_extension) = os.path.splitext(item_path)
+ item_extension = string.lstrip(item_extension, '.')
+
+ # is extension supported
+ if item_extension not in supported_extensions:
+ print ".%s is not a supported extension!" % item_extension
+ exit(1)
+
+ foundapps = []
+
+ # if item is an app, just pass it on
+ if item_extension == 'app':
+ if not os.path.exists(item_path):
+ print "This does not seem to be an Application!"
+ exit(1)
+ foundapps.append(item_path)
+
+ dmgvolumepaths = []
+ tmp_path = None
+ dmg_was_mounted = False
+ tmp_scripts_path = None
+ tmp_path = tempfile.mkdtemp()
+ payload_path = os.path.join(tmp_path, "payload")
+ os.makedirs(payload_path)
+
+ # if item is a dmg, mount it and find useful contents
+ if item_extension == 'dmg':
+ dmgvolumepaths = attachdmg(item_path)
+ for x in dmgvolumepaths:
+ moreapps = finditemswithextension(x, 'app')
+ foundapps.extend(moreapps)
+ if len(foundapps) == 0:
+ print "Could not find an application!"
+ cleanup_and_exit(1)
+ elif len(foundapps) > 1:
+ print "Found too many Applications! Can't decide!"
+ print foundapps
+ cleanup_and_exit(1)
+
+ # if item is zip, unzip to tmp location and find useful contents
+ if item_extension == 'zip':
+ unarchive_path = os.path.join(tmp_path, "unarchive")
+ unzip_cmd = ["/usr/bin/unzip", "-d", unarchive_path, item_path]
+ result = cmdexec(unzip_cmd)
+ if result["return_code"] != 0:
+ print "An error occured while unzipping:"
+ print "%d, %s" % (result["return_code"], result["stderr"])
+ cleanup_and_exit(1)
+ foundapps = finditemswithextension(unarchive_path, 'app')
+ if len(foundapps) == 0:
+ print "Could not find an application!"
+ cleanup_and_exit(1)
+ elif len(foundapps) > 1:
+ print "Found too many Applications! Can't decide!"
+ print foundapps
+ cleanup_and_exit(1)
+
+ logger("Found application: %s" % foundapps[0], 1)
+
+ # copy found app to payload folder
+ app_name = os.path.basename(foundapps[0])
+ app_path = os.path.join(payload_path, app_name)
+ shutil.copytree(foundapps[0], app_path)
+
+ # extract version and other metadata
+ (app_name, app_identifier, app_version) = appNameAndVersion(app_path)
+
+ logger("Name: %s, ID: %s, Version: %s" % (app_name, app_identifier, app_version), 1)
+
+ # create the component plist
+ component_plist = os.path.join(tmp_path, app_identifier) + ".plist"
+ analyzecmd = ["/usr/bin/pkgbuild",
+ "--analyze",
+ "--root", payload_path,
+ "--identifier", app_identifier,
+ "--version", app_version,
+ "--install-location", "/Applications",
+ component_plist]
+ result = cmdexec(analyzecmd)
+
+ logger(result["stdout"], 1)
+ if result["return_code"] != 0:
+ print "Error Code: %d " % result["return_code"]
+ print result["stderr"]
+ cleanup_and_exit(1)
+
+ if not args.relocatable:
+ # read and change component plist
+ components = readPlist(component_plist)
+ # component plist is an array of components
+ for bundle in components:
+ if "BundleIsRelocatable" in bundle.keys():
+ bundle["BundleIsRelocatable"] = False
+ writePlist(components, component_plist)
+
+ pkg_name = "{name}-{version}.pkg"
+ if args.output:
+ if os.path.isdir(args.output):
+ pkg_path = os.path.join(args.output, pkg_name)
+ else:
+ pkg_path = args.output
+ else:
+ pkg_path = pkg_name
+ nospace_app_name = app_name.replace(' ', '') # remove spaces
+ pkg_path = pkg_path.format(name=nospace_app_name, version=app_version, identifier=app_identifier)
+
+ if not pkg_path.endswith('pkg'):
+ pkg_path += '.pkg'
+
+ # run pkgutil to build result
+ pkgcmd = ["/usr/bin/pkgbuild",
+ "--root", payload_path,
+ "--component-plist", component_plist,
+ "--identifier", app_identifier,
+ "--version", app_version,
+ "--install-location", "/Applications",
+ pkg_path]
+
+ if args.scripts and not os.path.exists(args.scripts):
+ print "scripts folder %s does not exist!" % args.scripts
+ cleanup_and_exit(1)
+
+ if args.postinstall or args.preinstall:
+ tmp_scripts_path = os.path.join(tmp_dir, "scripts")
+ os.makedirs(tmp_scripts_path)
+
+ if args.scripts:
+ logger("copying %s to tmp scripts folder %s" % (args.scripts, tmp_scripts_path), 1)
+ shutil.rmtree(tmp_scripts_path)
+ shutil.copytree(args.scripts, tmp_scripts_path)
+ if args.postinstall:
+ if not os.path.exists(args.postinstall):
+ print "postinstall file %s does not exist!" % args.postinstall
+ cleanup_and_exit(1)
+ postinstall_path = os.path.join(tmp_scripts_path, "postinstall")
+ if os.path.exists(postinstall_path):
+ print "postinstall script already exists in %s" % args.scripts
+ cleanup_and_exit(1)
+ logger("copying %s to %s" % (args.postinstall, postinstall_path), 1)
+ shutil.copy2(args.postinstall, postinstall_path)
+ os.chmod(postinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
+ stat.S_IRGRP | stat.S_IXGRP |
+ stat.S_IROTH | stat.S_IXOTH)
+ if args.preinstall:
+ if not os.path.exists(args.preinstall):
+ print "preinstall file %s does not exist!" % args.preinstall
+ cleanup_and_exit(1)
+ preinstall_path = os.path.join(tmp_scripts_path, "preinstall")
+ if os.path.exists(preinstall_path):
+ print "preinstall script already exists in %s" % args.scripts
+ cleanup_and_exit(1)
+ logger("copying %s to %s" % (args.preinstall, preinstall_path), 1)
+ shutil.copy2(args.preinstall, preinstall_path)
+ os.chmod(preinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
+ stat.S_IRGRP | stat.S_IXGRP |
+ stat.S_IROTH | stat.S_IXOTH)
+
+ if tmp_scripts_path:
+ logger("scripts path: %s" % tmp_scripts_path, 1)
+ pkgcmd.extend(["--scripts", tmp_scripts_path])
+ elif args.scripts:
+ logger("scripts path: %s" % args.scripts, 1)
+ pkgcmd.extend(["--scripts", args.scripts])
+
+ if args.ownership:
+ pkgcmd.extend(["--ownership", args.ownership])
+
+ result = cmdexec(pkgcmd)
+
+ logger(result["stdout"], 1)
+ if result["return_code"] != 0:
+ print "Error Code: %d " % result["return_code"]
+ print result["stderr"]
+ else:
+ print pkg_path
+
+ cleanup_and_exit(0)
diff --git a/branding/templates/osx/signbundle b/branding/templates/osx/signbundle
new file mode 100644
index 0000000..58c42ae
--- /dev/null
+++ b/branding/templates/osx/signbundle
@@ -0,0 +1,11 @@
+#!/bin/sh
+# --------------------------------------------
+# Signs a RiseupVPN pkg file
+# Usage: signbundle <file> <version>
+#
+# Use it when you have built it in a
+# machine with no access to the certificates.
+# --------------------------------------------
+OSX_CERT="Developer ID Installer: LEAP Encryption Access Project"
+productsign --sign "$OSX_CERT" $1 $1-signed.pkg
+mv $1-signed.pkg ../dist/$applicationName-OSX-$2-signed.pkg
diff --git a/branding/templates/osx/template-helper.plist b/branding/templates/osx/template-helper.plist
new file mode 100644
index 0000000..160d95c
--- /dev/null
+++ b/branding/templates/osx/template-helper.plist
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>WorkingDirectory</key>
+ <string>/tmp</string>
+ <key>StandardOutPath</key>
+ <string>bitmask-helper.log</string>
+ <key>StandardErrorPath</key>
+ <string>bitmask-helper-err.log</string>
+ <key>GroupName</key>
+ <string>daemon</string>
+ <key>RunAtLoad</key>
+ <true/>
+ <key>SessionCreate</key>
+ <true/>
+ <key>KeepAlive</key>
+ <true/>
+ <key>ThrottleInterval</key>
+ <integer>5</integer>
+ <key>Label</key>
+ <string>se.leap.BitmaskHelper</string>
+ <key>Program</key>
+ <string>/Applications/$applicationName.app/Contents/MacOS/bitmask-helper</string>
+</dict>
+</plist>
diff --git a/branding/templates/osx/template-info.plist b/branding/templates/osx/template-info.plist
new file mode 100644
index 0000000..e67ddcc
--- /dev/null
+++ b/branding/templates/osx/template-info.plist
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>$entrypoint</string>
+ <key>CFBundleGetInfoString</key>
+ <string>$info_string</string>
+ <key>CFBundleIconFile</key>
+ <string>app.icns</string>
+ <key>CFBundleIdentifier</key>
+ <string>$bundle_identifier</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$bundle_name</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>$info_string</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>$version</string>
+ <key>NSAppleScriptEnabled</key>
+ <string>YES</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
diff --git a/branding/templates/osx/template-postinstall b/branding/templates/osx/template-postinstall
new file mode 100644
index 0000000..377508c
--- /dev/null
+++ b/branding/templates/osx/template-postinstall
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Bitmask Post-Instalation script
+# (c) LEAP Encryption access Project
+# We copy the bitmask-helper plist to the LaunchDaemons folder, and load the bitmask-helper that runs as root.
+
+LOG=/tmp/$applicationName-install.log
+
+chmod +x /Applications/$applicationName.app/Contents/MacOS/bitmask-helper
+cp se.leap.bitmask-helper.plist /Library/LaunchDaemons/ \
+ && echo `date` ":: $applicationName post-install: copied bitmask-helper Plist." >> $$LOG
+launchctl load /Library/LaunchDaemons/se.leap.bitmask-helper.plist && echo `date` ":: $applicationName post-install: loaded bitmask-helper." >> $$LOG
+chown admin:wheel /Applications/$applicationName.app/Contents/helper
+echo `date` ":: $applicationName post-install: ok." >> $$LOG
+exit 0
diff --git a/branding/templates/osx/template-preinstall b/branding/templates/osx/template-preinstall
new file mode 100644
index 0000000..90fe7fe
--- /dev/null
+++ b/branding/templates/osx/template-preinstall
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Bitmask Pre-Instalation script
+# (c) LEAP Encryption access Project
+# We unload the bitmask-helper if it is running, because we can be installing an upgrade.
+
+LOG=/tmp/$applicationName-install.log
+
+ps aux | grep [b]itmask-helper \
+ && launchctl unload /Library/LaunchDaemons/se.leap.bitmask-helper.plist \
+ && echo `date` ":: $applicationName pre-install: unloaded bitmask-helper." >> $$LOG
+echo `date` ":: $applicationName pre-install: ok." >> $$LOG
+exit 0
diff --git a/branding/templates/windows/generate.py b/branding/templates/windows/generate.py
index 427b7a8..552f1a9 100755
--- a/branding/templates/windows/generate.py
+++ b/branding/templates/windows/generate.py
@@ -34,9 +34,6 @@ data = json.load(open(os.path.join(here, 'data.json')))
data['extra_install_files'] = get_files('install')
data['extra_uninstall_files'] = get_files('uninstall')
-import pprint
-pprint.pprint(data)
-
INSTALLER = data['applicationName'] + '-installer.nsi'
diff --git a/go.mod b/go.mod
index fdfaa17..2318bdf 100644
--- a/go.mod
+++ b/go.mod
@@ -18,7 +18,9 @@ require (
github.com/jmshal/go-locale v0.0.0-20161107082030-4f541412d67a
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
github.com/oxtoacart/bpool v0.0.0-20150712133111-4e1c5567d7c2
+ github.com/sevlyar/go-daemon v0.1.5 // indirect
github.com/skratchdot/open-golang v0.0.0-20190104022628-a2dfa6d0dab6
+ golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
golang.org/x/text v0.3.0
golang.org/x/tools v0.0.0-20190206221403-44bcb96178d3 // indirect
)
diff --git a/go.sum b/go.sum
index 965dae2..2213cc3 100644
--- a/go.sum
+++ b/go.sum
@@ -31,8 +31,12 @@ github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/oxtoacart/bpool v0.0.0-20150712133111-4e1c5567d7c2 h1:CXwSGu/LYmbjEab5aMCs5usQRVBGThelUKBNnoSOuso=
github.com/oxtoacart/bpool v0.0.0-20150712133111-4e1c5567d7c2/go.mod h1:L3UMQOThbttwfYRNFOWLLVXMhk5Lkio4GGOtw5UrxS0=
+github.com/sevlyar/go-daemon v0.1.5 h1:Zy/6jLbM8CfqJ4x4RPr7MJlSKt90f00kNM1D401C+Qk=
+github.com/sevlyar/go-daemon v0.1.5/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
github.com/skratchdot/open-golang v0.0.0-20190104022628-a2dfa6d0dab6 h1:cGT4dcuEyBwwu/v6tosyqcDp2yoIo/LwjMGixUvg3nU=
github.com/skratchdot/open-golang v0.0.0-20190104022628-a2dfa6d0dab6/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
+golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
+golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190206221403-44bcb96178d3 h1:M9mD7d4inzK0+YbTneZEs9Y+q1B1zLv8YxJDJ6hFgnY=
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 18f6667..c174b6b 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by vendorize.py
-// At 2019-07-09 18:54:26
+// At 2019-07-16 21:41:09
package config
diff --git a/pkg/helper/darwin.go b/pkg/helper/darwin.go
index 49924e5..a1e1f00 100644
--- a/pkg/helper/darwin.go
+++ b/pkg/helper/darwin.go
@@ -102,13 +102,21 @@ func firewallStart(gateways []string) error {
}
func firewallStop() error {
- return exec.Command(pfctl, "-a", bitmask_anchor, "-F", "all").Run()
+ out, err := exec.Command(pfctl, "-a", bitmask_anchor, "-F", "all").Output()
+ if err != nil {
+ log.Printf("An error ocurred stopping the firewall: %v", out)
+ /* TODO return error if different from anchor not exists */
+ /*return errors.New("Error while stopping firewall")*/
+ return nil
+ }
+ return nil
}
func firewallIsUp() bool {
out, err := exec.Command(pfctl, "-a", bitmask_anchor, "-sr").Output()
if err != nil {
log.Printf("An error ocurred getting the status of the firewall: %v", err)
+ log.Printf(string(out))
return false
}
return bytes.Contains(out, []byte("block out proto udp to any port 53"))