mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-24 11:16:51 +00:00
tinc: initial addon
This commit is contained in:
parent
8b0c9525c9
commit
287e2dbcbe
2
packages/addons/service/tinc/changelog.txt
Executable file
2
packages/addons/service/tinc/changelog.txt
Executable file
@ -0,0 +1,2 @@
|
||||
8.0.100
|
||||
- Initial addon
|
BIN
packages/addons/service/tinc/icon/icon.png
Normal file
BIN
packages/addons/service/tinc/icon/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
59
packages/addons/service/tinc/package.mk
Normal file
59
packages/addons/service/tinc/package.mk
Normal file
@ -0,0 +1,59 @@
|
||||
################################################################################
|
||||
# This file is part of LibreELEC - https://libreelec.tv
|
||||
# Copyright (C) 2016 Team LibreELEC
|
||||
#
|
||||
# LibreELEC is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LibreELEC is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
|
||||
################################################################################
|
||||
|
||||
PKG_NAME="tinc"
|
||||
PKG_VERSION="1.1pre12"
|
||||
PKG_REV="100"
|
||||
PKG_ARCH="any"
|
||||
PKG_LICENSE="GPLv2"
|
||||
PKG_SITE="http://www.tinc-vpn.org/"
|
||||
PKG_URL="${PKG_SITE}/packages/$PKG_NAME-$PKG_VERSION.tar.gz"
|
||||
PKG_DEPENDS_TARGET="toolchain libressl lzo"
|
||||
PKG_PRIORITY="optional"
|
||||
PKG_SECTION="service/system"
|
||||
PKG_SHORTDESC="tinc Virtual Private Network Daemon"
|
||||
PKG_LONGDESC="tinc is a virtual private network (VPN) daemon that uses tunnelling and encryption to create a secure private network between hosts on the Internet. Because the VPN appears to the IP level network code as a normal network device, there is no need to adapt any existing software. This allows VPN sites to share information with each other over the Internet without exposing any information to others."
|
||||
|
||||
PKG_AUTORECONF="yes"
|
||||
|
||||
PKG_IS_ADDON="yes"
|
||||
PKG_ADDON_TYPE="xbmc.service"
|
||||
PKG_ADDON_PROVIDES=""
|
||||
PKG_ADDON_REPOVERSION="8.0"
|
||||
PKG_MAINTAINER="Anton Voyl (awiouy at gmail dot com)"
|
||||
|
||||
PKG_CONFIGURE_OPTS_TARGET="--disable-curses \
|
||||
--disable-readline \
|
||||
--sysconfdir=/storage/.cache"
|
||||
|
||||
pre_configure_target() {
|
||||
# tinc fails to build in subdirs
|
||||
cd $ROOT/$PKG_BUILD
|
||||
rm -rf .$TARGET_NAME
|
||||
}
|
||||
|
||||
makeinstall_target() {
|
||||
:
|
||||
}
|
||||
|
||||
addon() {
|
||||
mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/bin
|
||||
cp $PKG_BUILD/src/tinc \
|
||||
$PKG_BUILD/src/tincd \
|
||||
$ADDON_BUILD/$PKG_ADDON_ID/bin
|
||||
}
|
18
packages/addons/service/tinc/source/bin/subnet-up
Executable file
18
packages/addons/service/tinc/source/bin/subnet-up
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
. /etc/profile
|
||||
oe_setup_addon service.system.tinc
|
||||
|
||||
case "$SUBNET" in
|
||||
??:??:??:??:??:??)
|
||||
:
|
||||
;;
|
||||
*)
|
||||
if [ "$NAME" == "$NODE" ]
|
||||
then
|
||||
ip addr replace "$SUBNET/$tinc_mask" dev "$INTERFACE"
|
||||
elif [ "$tinc_mask" == "32" ]
|
||||
then
|
||||
ip route replace "$SUBNET" dev "$INTERFACE"
|
||||
fi
|
||||
;;
|
||||
esac
|
81
packages/addons/service/tinc/source/bin/tinc-service
Normal file
81
packages/addons/service/tinc/source/bin/tinc-service
Normal file
@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
################################################################################
|
||||
# This file is part of LibreELEC - https://libreelec.tv
|
||||
# Copyright (C) 2016 Team LibreELEC
|
||||
#
|
||||
# LibreELEC is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LibreELEC is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
|
||||
################################################################################
|
||||
|
||||
. /etc/profile
|
||||
oe_setup_addon service.system.tinc
|
||||
|
||||
config="$ADDON_HOME/.config"
|
||||
dev="vmnetz"
|
||||
host="$ADDON_HOME/Host"
|
||||
hosts="$ADDON_HOME/Hosts"
|
||||
|
||||
rm -rf "$host"
|
||||
rm -f "$hosts"
|
||||
|
||||
if [ -z "$tinc_name" ]
|
||||
then
|
||||
rm -rf "$config"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
read_name="$(tinc -c $config get name)"
|
||||
|
||||
if [ "$read_name" != "$tinc_name" ]
|
||||
then
|
||||
rm -rf "$config"
|
||||
tinc -c "$config" init "$tinc_name"
|
||||
fi
|
||||
|
||||
mkdir -p "$host"
|
||||
ln -s "$config/hosts/$tinc_name" "$host/$tinc_name"
|
||||
ln -nsf "$config/hosts" "$hosts"
|
||||
|
||||
for var in address port subnet
|
||||
do
|
||||
eval "tinc_var=\$tinc_$var"
|
||||
if [ -z "$tinc_var" ]
|
||||
then
|
||||
tinc -c "$config" del "$var"
|
||||
else
|
||||
tinc -c "$config" set "$var" "$tinc_var"
|
||||
fi
|
||||
done
|
||||
|
||||
cp "$ADDON_DIR/bin/subnet-up" \
|
||||
"$ADDON_DIR/bin/tinc-up" \
|
||||
"$config"
|
||||
|
||||
case "$tinc_subnets" in
|
||||
"default")
|
||||
subnets=""
|
||||
;;
|
||||
"strict subnets")
|
||||
subnets="-o StrictSubnets=yes"
|
||||
;;
|
||||
"tunnel server")
|
||||
subnets="-o TunnelServer=yes"
|
||||
;;
|
||||
esac
|
||||
|
||||
tincd -c "$config" \
|
||||
-n "$dev" \
|
||||
-o AutoConnect=yes \
|
||||
-o LocalDiscovery=yes \
|
||||
-o mode="$tinc_mode" \
|
||||
$subnets
|
2
packages/addons/service/tinc/source/bin/tinc-up
Executable file
2
packages/addons/service/tinc/source/bin/tinc-up
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
ip link set up dev "$INTERFACE"
|
88
packages/addons/service/tinc/source/default.py
Normal file
88
packages/addons/service/tinc/source/default.py
Normal file
@ -0,0 +1,88 @@
|
||||
################################################################################
|
||||
# This file is part of LibreELEC - https://libreelec.tv
|
||||
# Copyright (C) 2016 Team LibreELEC
|
||||
#
|
||||
# LibreELEC is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LibreELEC is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
|
||||
################################################################################
|
||||
import os.path
|
||||
import random
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import urllib2
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
|
||||
|
||||
ADDON = xbmcaddon.Addon()
|
||||
ID = ADDON.getAddonInfo('id')
|
||||
PATH = ADDON.getAddonInfo('path')
|
||||
TINC = os.path.join(PATH, 'bin', 'tinc')
|
||||
|
||||
def run_code(cmd, *argv):
|
||||
return subprocess.call(cmd.format(*argv).split())
|
||||
|
||||
def run_lines(cmd, *argv):
|
||||
try:
|
||||
return subprocess.check_output(cmd.format(*argv).split()).splitlines()
|
||||
except subprocess.CalledProcessError:
|
||||
return []
|
||||
|
||||
|
||||
class Monitor(xbmc.Monitor):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
xbmc.Monitor.__init__(self)
|
||||
|
||||
def onSettingsChanged(self):
|
||||
run_code('systemctl restart {}'.format(ID))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for network in run_lines('{} network', TINC):
|
||||
run_code('{} -n {} start', TINC, network)
|
||||
|
||||
if ADDON.getSetting('tinc_wizard') == 'true':
|
||||
try:
|
||||
ip = urllib2.urlopen('http://ip.42.pl/raw').read()
|
||||
address = socket.gethostbyaddr(ip)[0]
|
||||
ADDON.setSetting('tinc_address', address)
|
||||
except:
|
||||
pass
|
||||
|
||||
network, mask = '10.0.0.0/8'.split('/')
|
||||
mask = 2 ** (32 - int(mask)) - 1
|
||||
network = struct.unpack('!L', socket.inet_aton(network))[0] & -mask
|
||||
ip = network + random.randint(1, mask - 1)
|
||||
name = format(ip, '08x')
|
||||
subnet = socket.inet_ntoa(struct.pack('!L', ip))
|
||||
ADDON.setSetting('tinc_name', name)
|
||||
ADDON.setSetting('tinc_subnet', subnet)
|
||||
|
||||
port = int(ADDON.getSetting('tinc_port'))
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.bind(('', port))
|
||||
s.close()
|
||||
except socket.error:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind(('', 0))
|
||||
a, port = s.getsockname()
|
||||
s.close()
|
||||
ADDON.setSetting('tinc_port', str(port))
|
||||
|
||||
ADDON.setSetting('tinc_wizard', 'false')
|
||||
run_code('systemctl restart {}'.format(ID))
|
||||
|
||||
Monitor().waitForAbort()
|
@ -0,0 +1,70 @@
|
||||
# Kodi Media Center language file
|
||||
# Addon Name: tinc
|
||||
# Addon id: service.system.tinc
|
||||
# Addon Provider: awiouy at gmail dot com
|
||||
msgid ""
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30000"
|
||||
msgid "Configuration"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30001"
|
||||
msgid "Virtual Private Network"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30002"
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30003"
|
||||
msgid "Subnet"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30004"
|
||||
msgid "Mask"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30005"
|
||||
msgid "Mode"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30006"
|
||||
msgid "Subnet Discovery"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30007"
|
||||
msgid "Public Network"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30008"
|
||||
msgid "Address"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30009"
|
||||
msgid "Port"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30010"
|
||||
msgid "Instructions"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30011"
|
||||
msgid "1. Configure local node (see tinc-vpn.org/documentation-1.1)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30012"
|
||||
msgid "2. Enable port forwarding on your router (see e.g. portforward.com)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30013"
|
||||
msgid "3. Distribute local host file from userdata/addon_data/service.system.tinc/Host"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30014"
|
||||
msgid "4. Collect remote host files in userdata/addon_data/service.system.tinc/Hosts"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30015"
|
||||
msgid "5. Restart tinc to load remote host files"
|
||||
msgstr ""
|
24
packages/addons/service/tinc/source/resources/settings.xml
Normal file
24
packages/addons/service/tinc/source/resources/settings.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<settings>
|
||||
<category label="30000">
|
||||
<setting label="30001" type="lsep" />
|
||||
<setting id="tinc_name" label="30002" type="text" />
|
||||
<setting id="tinc_subnet" label="30003" type="ipaddress" />
|
||||
<setting id="tinc_mask" label="30004" type="labelenum"
|
||||
values="32|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31" />
|
||||
<setting id="tinc_mode" label="30005" type="labelenum"
|
||||
values="router|hub|switch" />
|
||||
<setting id="tinc_subnets" label="30006" type="labelenum"
|
||||
values="default|strict subnets|tunnel server" />
|
||||
<setting label="30007" type="lsep" />
|
||||
<setting id="tinc_address" label="30008" type="text" />
|
||||
<setting id="tinc_port" label="30009" type="number" default="6555" />
|
||||
</category>
|
||||
<category label="30010">
|
||||
<setting label="30011" type="lsep" />
|
||||
<setting label="30012" type="lsep" />
|
||||
<setting label="30013" type="lsep" />
|
||||
<setting label="30014" type="lsep" />
|
||||
<setting label="30015" type="lsep" />
|
||||
</category>
|
||||
</settings>
|
11
packages/addons/service/tinc/source/settings-default.xml
Normal file
11
packages/addons/service/tinc/source/settings-default.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<settings>
|
||||
<setting id="tinc_address" value="" />
|
||||
<setting id="tinc_mask" value="32" />
|
||||
<setting id="tinc_mode" value="router" />
|
||||
<setting id="tinc_name" value="" />
|
||||
<setting id="tinc_port" value="6555" />
|
||||
<setting id="tinc_subnet" value="" />
|
||||
<setting id="tinc_subnets" value="default" />
|
||||
<setting id="tinc_wizard" value="true" />
|
||||
</settings>
|
||||
|
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=tinc for LibreELEC
|
||||
Documentation=http://tinc-vpn.org/docs/
|
||||
After=network-online.target
|
||||
Requires=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/bin/sh /storage/.kodi/addons/service.system.tinc/bin/tinc-service
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=kodi.target
|
Loading…
x
Reference in New Issue
Block a user