diff --git a/packages/addons/service/tinc/changelog.txt b/packages/addons/service/tinc/changelog.txt new file mode 100755 index 0000000000..9455e1f3c8 --- /dev/null +++ b/packages/addons/service/tinc/changelog.txt @@ -0,0 +1,2 @@ +8.0.100 +- Initial addon diff --git a/packages/addons/service/tinc/icon/icon.png b/packages/addons/service/tinc/icon/icon.png new file mode 100644 index 0000000000..112b784f83 Binary files /dev/null and b/packages/addons/service/tinc/icon/icon.png differ diff --git a/packages/addons/service/tinc/package.mk b/packages/addons/service/tinc/package.mk new file mode 100644 index 0000000000..c06f39baaa --- /dev/null +++ b/packages/addons/service/tinc/package.mk @@ -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 . +################################################################################ + +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 +} diff --git a/packages/addons/service/tinc/source/bin/subnet-up b/packages/addons/service/tinc/source/bin/subnet-up new file mode 100755 index 0000000000..1a5cbdf504 --- /dev/null +++ b/packages/addons/service/tinc/source/bin/subnet-up @@ -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 diff --git a/packages/addons/service/tinc/source/bin/tinc-service b/packages/addons/service/tinc/source/bin/tinc-service new file mode 100644 index 0000000000..0901a54331 --- /dev/null +++ b/packages/addons/service/tinc/source/bin/tinc-service @@ -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 . +################################################################################ + +. /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 diff --git a/packages/addons/service/tinc/source/bin/tinc-up b/packages/addons/service/tinc/source/bin/tinc-up new file mode 100755 index 0000000000..396cfd071c --- /dev/null +++ b/packages/addons/service/tinc/source/bin/tinc-up @@ -0,0 +1,2 @@ +#!/bin/sh +ip link set up dev "$INTERFACE" diff --git a/packages/addons/service/tinc/source/default.py b/packages/addons/service/tinc/source/default.py new file mode 100644 index 0000000000..c7cb3a4f32 --- /dev/null +++ b/packages/addons/service/tinc/source/default.py @@ -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 . +################################################################################ +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() diff --git a/packages/addons/service/tinc/source/resources/language/English/strings.po b/packages/addons/service/tinc/source/resources/language/English/strings.po new file mode 100644 index 0000000000..82efcf4fdf --- /dev/null +++ b/packages/addons/service/tinc/source/resources/language/English/strings.po @@ -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 "" diff --git a/packages/addons/service/tinc/source/resources/settings.xml b/packages/addons/service/tinc/source/resources/settings.xml new file mode 100644 index 0000000000..c9919ea0ac --- /dev/null +++ b/packages/addons/service/tinc/source/resources/settings.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/addons/service/tinc/source/settings-default.xml b/packages/addons/service/tinc/source/settings-default.xml new file mode 100644 index 0000000000..38d2d1c812 --- /dev/null +++ b/packages/addons/service/tinc/source/settings-default.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/packages/addons/service/tinc/source/system.d/service.system.tinc.service b/packages/addons/service/tinc/source/system.d/service.system.tinc.service new file mode 100644 index 0000000000..59f6f7f125 --- /dev/null +++ b/packages/addons/service/tinc/source/system.d/service.system.tinc.service @@ -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