Skip to content

Commit

Permalink
python 3.10 not compatible with nose
Browse files Browse the repository at this point in the history
  • Loading branch information
ab77 committed Dec 3, 2023
1 parent 85004af commit 65b6232
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 252 deletions.
4 changes: 2 additions & 2 deletions unzoner/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --- build stage
FROM balenalib/%%BALENA_ARCH%%-ubuntu-python:3.10-build AS build
FROM balenalib/%%BALENA_ARCH%%-ubuntu-python:3.9-build AS build

LABEL maintainer=team@belodetek.io

Expand Down Expand Up @@ -165,7 +165,7 @@ COPY systemd/* ./systemd/


# --- runtime
FROM balenalib/%%BALENA_ARCH%%-ubuntu-python:3.10
FROM balenalib/%%BALENA_ARCH%%-ubuntu-python:3.9

LABEL maintainer=team@belodetek.io

Expand Down
17 changes: 0 additions & 17 deletions unzoner/functions
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,6 @@ function download_ipasn_db() {
}


# start WANProxy server
function start_wanproxy_server() {
local temp_file=$(mktemp) && \
($(which wanproxy) -c ${WORKDIR}/server.conf &>${temp_file}&) && \
sleep 5 && \
local port=$(grep -Po "[0-9]+$" ${temp_file}) && \
rm ${temp_file} && \
local pid=$(netstat -a -n -p | grep ${port} | grep -Po "[0-9]+/wanproxy" | awk -F'/' '{print $1}') && \

if [[ "${WANPROXY}" == "SOCAT" ]]; then
$(which socat) TCP${AF}-LISTEN:${SOCAT_PORT},su=nobody,fork,reuseaddr TCP${AF}:localhost:${port} &
fi

echo ${pid} ${port}
}


# get remote ping host
function get_ping_host() {
for rtnum in 5; do
Expand Down
2 changes: 0 additions & 2 deletions unzoner/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
VPN_TCP_MGMT_PORT = int(os.getenv('VPN_TCP_MGMT_PORT', 7506))
VPN_UDP_MGMT_PORT = int(os.getenv('VPN_UDP_MGMT_PORT', 7505))
VPN_USERNAME = os.getenv('VPN_USERNAME', None)
WANPROXY = os.getenv('WANPROXY', None) # proxy transports: SOCAT or SSH
WANPROXY_PORT= os.getenv('WANPROXY_PORT', '3300')

ON_POSIX = '' in sys.builtin_module_names

Expand Down
156 changes: 0 additions & 156 deletions unzoner/src/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
ipaddr = None
qtype = None
c_proto = None
c_wpid = None
s_wpid = None
s_wport = None


@retry(Exception, cdata='method={}'.format(stack()[0][3]))
Expand Down Expand Up @@ -110,35 +107,11 @@ def get_openvpn_binary(default='/usr/sbin/openvpn'):
def connect_node(family=AF):
global PROTOS
global c_proto
global c_wpid
global s_wpid
global s_wport
global ipaddr
global country
global host
global qtype

try:
log('os.kill: {}'.format(c_wpid))
os.kill(int(c_wpid), signal.SIGKILL)
except:
pass

c_wpid = None

try:
log('kill_remote_pid: {}'.format(
kill_remote_pid(
ipaddr=ipaddr,
family=family,
pid=s_wpid
)
))
except:
pass

s_wpid = None
s_wport = None
ipaddr = None

if len(PROTOS) <= 0: PROTOS = list(TUN_PROTO) # start again
Expand Down Expand Up @@ -331,39 +304,6 @@ def connect_node(family=AF):
ipaddr
))

##################################
# (deprecated) WANProxy override #
##################################
if WANPROXY:
(c_wpid, s_wpid, s_wport) = start_wanproxy_server(
ipaddr=ipaddr,
family=family,
local_pid=c_wpid,
remote_pid=s_wpid,
port=s_wport
)

log('start_wanproxy_server: ipaddr={} af={} local_pid={} remote_pid={} remote_port={} transport={}'.format(
ipaddr,
family,
c_wpid,
s_wpid,
s_wport,
WANPROXY
))

port = WANPROXY_PORT
ipaddr = 'localhost'
tun_proto = 'tcp'
if family == 6: tun_proto = '{}{}'.format(tun_proto, family)
log('{}: wan_proxy={} proto={} ipaddr={} port={}'.format(
stack()[0][3],
WANPROXY,
tun_proto,
ipaddr,
port
))

if FRAGMENT and tun_proto == 'udp':
cmd.append('--tun-mtu')
cmd.append(TUN_MTU)
Expand Down Expand Up @@ -789,102 +729,6 @@ def restart_stunnel_client(
return run_shell_cmd(['%s' % stunnel_bin, '%s' % conf])


def start_wanproxy_server(
ipaddr=None,
family=4,
local_pid=None,
remote_pid=None,
port=None,
ssh_port=DOCKER_SSH_PORT
):
if WANPROXY == 'SSH':
remote_guid = get_guid_by_public_ipaddr(ipaddr=ipaddr, family=family)
assert remote_guid
if DEBUG: print( 'get_guid_by_public_ipaddr: ipaddr={} family={} remote_guid={}'.format(
ipaddr,
family,
remote_guid
))

if not (port and remote_pid):
if WANPROXY == 'SSH':
# start WANProxy server instance and get remote port for forwarding
result = run_shell_cmd(
[
'ssh', '-i', '%s/id_rsa' % WORKDIR,
'-o StrictHostKeyChecking=no',
'root@%s' % ipaddr,
'-p', '%s' % str(ssh_port),
'bash',
'-c',
'"source %s/functions; source %s/.env; start_wanproxy_server"' % (
WORKDIR,
TEMPDIR
)
]
)
if DEBUG: print(result)
remote_pid = result[1].split()[0]
port = result[1].split()[1]

if not local_pid:
if WANPROXY == 'SSH':
# start SSH tunnel
result = run_background_shell_cmd(
[
'ssh', '-i', '%s/id_rsa' % WORKDIR,
'-fN','-o StrictHostKeyChecking=no',
'-L 3301:localhost:%s' % str(port),
'-p', '%s' % str(ssh_port),
'root@%s' % ipaddr
]
)
if DEBUG: print(result.__dict__)
local_pid = str(int(result.pid) + 1)

if WANPROXY == 'SOCAT':
# start SOCAT local listener
result = run_shell_cmd_nowait(
[
'/usr/bin/socat',
'TCP%s-LISTEN:3301,bind=localhost,su=nobody,fork,reuseaddr' % str(
family
),
'TCP%s:%s:%s' % (str(family), ipaddr, SOCAT_PORT)
]
)
if DEBUG: print(result.__dict__)
local_pid = str(result.pid)

return (local_pid, remote_pid, port)


def kill_remote_pid(ipaddr=None, family=4, pid=None, ssh_port=DOCKER_SSH_PORT):
if WANPROXY == 'SSH':
remote_guid = get_guid_by_public_ipaddr(ipaddr=ipaddr, family=family)
assert remote_guid
if DEBUG: print('get_guid_by_public_ipaddr: ipaddr={} family={} remote_guid={}'.format(
ipaddr,
family,
remote_guid
))

result = None
if pid and WANPROXY == 'SSH':
# kill remote pid
result = run_shell_cmd(
[
'ssh', '-i', '%s/id_rsa' % WORKDIR,
'-o StrictHostKeyChecking=no',
'root@%s' % ipaddr,
'-p', '%s' % str(ssh_port),
'bash', '-c', '"kill -9 %s"' % str(pid)
]
)
if DEBUG: print(result)
return result


@retry(Exception, cdata='method={}'.format(stack()[0][3]))
def disconnect_clients():
disconnected = list()
Expand Down
75 changes: 0 additions & 75 deletions unzoner/start
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ declare -x TUN_PASSWD=${TUN_PASSWD:-$(${WORKDIR}/scripts/pyboot.sh gen_hash)}
declare -x REQUESTS_CA_BUNDLE=${REQUESTS_CA_BUNDLE:-${DATADIR}/cacert.pem}
declare -x STUNNEL=${STUNNEL:-0}
declare -x STUNNEL_PORT=${STUNNEL_PORT:-443}
declare -x WANPROXY=${WANPROXY}
declare -x WANPROXY_PORT=${WANPROXY_PORT:-3300}
declare -x SOCAT_PORT=${SOCAT_PORT:-3302}
declare -x UPNP_TCP_PORT_FORWARD=${UPNP_TCP_PORT_FORWARD:-${OPENVPN_PORT} ${STUNNEL_PORT} ${SOCAT_PORT}}
declare -x UPNP_UDP_PORT_FORWARD=${UPNP_UDP_PORT_FORWARD:-${OPENVPN_PORT}}
Expand Down Expand Up @@ -831,79 +829,6 @@ EOF
fi
fi

if [[ ${WANPROXY} ]]; then
if [[ "${DEVICE_TYPE}" == "1" ]] || [[ "${DEVICE_TYPE}" == "3" ]] || [[ "${DEVICE_TYPE}" == "4" ]]; then
log 'generating WANProxy server config...'
cat << EOF > ${WORKDIR}/server.conf
create codec codec0
set codec0.codec XCodec
set codec0.compressor zlib
set codec0.compressor_level 6
activate codec0
create interface $(get_iface)
set $(get_iface).family IPv${AF}
set $(get_iface).host "localhost"
set $(get_iface).port "0"
activate $(get_iface)
create peer peer0
set peer0.family IPv${AF}
set peer0.host "localhost"
set peer0.port "${OPENVPN_PORT}"
activate peer0
create proxy proxy0
set proxy0.interface $(get_iface)
set proxy0.interface_codec codec0
set proxy0.peer peer0
set proxy0.peer_codec None
activate proxy0
EOF

if [[ "${WANPROXY}" == "SOCAT" ]]; then
ipt_add_rule flter I "INPUT -i ${EXT_IFACE} -p tcp -m tcp --dport ${SOCAT_PORT} -j ACCEPT"
if [[ "${AF}" == "6" ]] && [[ $(ip6tables -t nat -L) ]]; then
ip6t_add_rule filter I "INPUT -i ${EXT_IFACE} -p tcp -m tcp --dport ${SOCAT_PORT}"
fi
start_wanproxy_server
fi
fi

if [[ "${DEVICE_TYPE}" == "2" ]] || [[ "${DEVICE_TYPE}" == "3" ]]; then
log 'generating WANProxy client config...'
cat << EOF > ${WORKDIR}/client.conf
create codec codec0
set codec0.codec XCodec
set codec0.compressor zlib
set codec0.compressor_level 6
activate codec0
create interface $(get_iface)
set $(get_iface).family IPv${AF}
set $(get_iface).host "localhost"
set $(get_iface).port "${WANPROXY_PORT}"
activate $(get_iface)
create peer peer0
set peer0.family IPv${AF}
set peer0.host "localhost"
set peer0.port "3301"
activate peer0
create proxy proxy0
set proxy0.interface $(get_iface)
set proxy0.interface_codec None
set proxy0.peer peer0
set proxy0.peer_codec codec0
activate proxy0
EOF

log 'starting WANProxy client...'
(nohup $(which wanproxy) -c ${WORKDIR}/client.conf) &
cat "${WORKDIR}/id_rsa.pub" >> "${HOME}/.ssh/authorized_keys"
fi
fi

if [[ ${VPN_PROVIDER} ]] && [[ ${VPN_LOCATION_GROUP} ]] && [[ ${VPN_LOCATION} ]]; then
log 'generating custom VPN client configuration...'
Expand Down

0 comments on commit 65b6232

Please sign in to comment.