2014-10-14 16:02:12 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
. /usr/lib/whonix/utility_functions
|
|
|
|
|
2014-10-25 16:49:49 +00:00
|
|
|
# Search though files and updates IP address to the current
|
2014-11-02 21:14:36 +00:00
|
|
|
# IP address(es)
|
2014-10-25 16:49:49 +00:00
|
|
|
|
|
|
|
FILES=(
|
|
|
|
'/usr/lib/leaktest-workstation/simple_ping.py'
|
|
|
|
'/usr/lib/whonixcheck/preparation'
|
|
|
|
'/usr/share/anon-kde-streamiso/share/config/kioslaverc'
|
|
|
|
'/usr/bin/whonix_firewall'
|
|
|
|
'/etc/whonix_firewall.d/30_default'
|
|
|
|
'/usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh'
|
|
|
|
'/usr/bin/uwt'
|
|
|
|
'/etc/uwt.d/30_uwt_default'
|
|
|
|
'/usr/share/tor/tor-service-defaults-torrc.anondist'
|
|
|
|
'/usr/bin/update-torbrowser'
|
|
|
|
'/etc/network/interfaces.whonix'
|
|
|
|
'/etc/resolv.conf.anondist'
|
|
|
|
'/etc/sdwdate.d/31_anon_dist_stream_isolation_plugin'
|
|
|
|
'/etc/rinetd.conf.anondist'
|
|
|
|
'/etc/network/interfaces.whonix'
|
|
|
|
'/usr/share/anon-torchat/.torchat/torchat.ini'
|
|
|
|
)
|
|
|
|
|
|
|
|
# sed search and replace. return 0 if replace happened, otherwise 1
|
|
|
|
search_replace() {
|
2014-10-28 08:09:55 +00:00
|
|
|
local search="${1}"
|
|
|
|
local replace="${2}"
|
|
|
|
local file="${3}"
|
2014-10-25 16:49:49 +00:00
|
|
|
local retval=1
|
|
|
|
|
|
|
|
if ! [ -L "${file}" ]; then
|
|
|
|
ls_attrs="$(lsattr "${file}")"
|
|
|
|
ls_attrs=${ls_attrs:4:1}
|
|
|
|
if [ "${ls_attrs}" == "i" ]; then
|
|
|
|
chattr -i "${file}"
|
|
|
|
fi
|
|
|
|
fi
|
2014-10-28 08:09:55 +00:00
|
|
|
|
2014-10-25 16:49:49 +00:00
|
|
|
sed -i.bak '/'"${search}"'/,${s//'"${replace}"'/;b};$q1' "${file}"
|
|
|
|
retval=$?
|
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
if [ "${ls_attrs}" = "i" ]; then
|
2014-10-25 16:49:49 +00:00
|
|
|
chattr +i "${file}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
function replace_ips()
|
|
|
|
{
|
2014-10-25 16:49:49 +00:00
|
|
|
local search_ip="${1}"
|
|
|
|
local replace_ip="${2}"
|
|
|
|
local files=("${!3}")
|
2014-10-29 16:53:35 +00:00
|
|
|
local retval=1
|
2014-10-14 16:02:12 +00:00
|
|
|
|
2014-10-25 16:49:49 +00:00
|
|
|
# If IP is 10.152.152.10, network is 10.152.152.0
|
2014-10-28 08:09:55 +00:00
|
|
|
search_network="${search_ip%[.]*}.0"
|
|
|
|
replace_network="${replace_ip%[.]*}.0"
|
2014-10-25 16:49:49 +00:00
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
if ! [ "${search_ip}" = "${replace_ip}" ]; then
|
2014-10-25 16:49:49 +00:00
|
|
|
for file in "${files[@]}"; do
|
2014-10-14 16:02:12 +00:00
|
|
|
if [ -f "$file" ]; then
|
2014-10-29 16:53:35 +00:00
|
|
|
search_replace "${search_ip}" "${replace_ip}" "${file}" && retval=0
|
|
|
|
search_replace "${search_network}" "${replace_network}" "${file}" && retval=0
|
2014-10-14 16:02:12 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2014-10-29 16:53:35 +00:00
|
|
|
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
update_ip() {
|
|
|
|
ip=${1}
|
|
|
|
|
|
|
|
echo "${ip}" > /etc/whonix-netvm-gateway
|
|
|
|
grep '^DisableNetwork 0$' /etc/tor/torrc && {
|
2014-11-02 21:14:36 +00:00
|
|
|
service tor status && {
|
|
|
|
service tor reload || true;
|
|
|
|
}
|
2014-10-29 16:53:35 +00:00
|
|
|
}
|
2014-10-14 16:02:12 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
if [ "${WHONIX}" == "gateway" ]; then
|
|
|
|
ip="$(xenstore-read qubes-netvm-gateway)"
|
|
|
|
if [ x${ip} != x ]; then
|
|
|
|
# Compare to current IP address assiged by Qubes
|
|
|
|
replace_ips "$(cat /etc/whonix-netvm-gateway)" "${ip}" FILES[@] && update_ip "${ip}"
|
|
|
|
|
|
|
|
# Do again; checking for original 10.152.152.10 incase of update
|
|
|
|
replace_ips "10.152.152.10" "${ip}" FILES[@] && update_ip "${ip}"
|
2014-10-25 16:49:49 +00:00
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
# Do again; checking for original 10.152.152.11 incase of update
|
|
|
|
replace_ips "10.152.152.11" "${ip}" FILES[@] && update_ip "${ip}"
|
|
|
|
fi
|
2014-10-14 16:02:12 +00:00
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
elif [ "${WHONIX}" == "workstation" ]; then
|
|
|
|
ip="$(xenstore-read qubes-ip)"
|
|
|
|
gateway="$(xenstore-read qubes-gateway)"
|
2014-10-14 16:02:12 +00:00
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
if [ x${ip} != x ]; then
|
|
|
|
# Compare to current IP address assiged by Qubes
|
|
|
|
replace_ips "$(cat /etc/whonix-ip)" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip
|
2014-10-14 16:02:12 +00:00
|
|
|
|
2014-11-02 21:14:36 +00:00
|
|
|
# Do again; checking for original 10.152.152.11 incase of update
|
|
|
|
replace_ips "10.152.152.11" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ x${gateway} != x ]; then
|
|
|
|
# Compare to current gateway IP address assiged by Qubes
|
|
|
|
replace_ips "$(cat /etc/whonix-netvm-gateway)" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway
|
|
|
|
|
|
|
|
# Do again; checking for original 10.152.152.10 incase of update
|
|
|
|
replace_ips "10.152.152.10" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway
|
|
|
|
fi
|
|
|
|
fi
|