pax_global_header00006660000000000000000000000064133776002400014514gustar00rootroot0000000000000052 comment=c5f98432e5af8b59eaabb1df50468536bed57f80 bosixnet-2.0/000077500000000000000000000000001337760024000132105ustar00rootroot00000000000000bosixnet-2.0/.gitignore000066400000000000000000000000221337760024000151720ustar00rootroot00000000000000*.user* builddir* bosixnet-2.0/CMakeLists.txt000066400000000000000000000024351337760024000157540ustar00rootroot00000000000000project (bosixnet) cmake_minimum_required (VERSION 2.8) set (PROJECT_NAME "BOSixNet") set (VERSION "1.7") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror") option (WITH_SYSVINIT_SUPPORT "Install sysvinit scripts" OFF) option (WITH_SYSTEMD_SUPPORT "Install systemd unit configuration files" ON) if (WITH_SYSVINIT_SUPPORT) if (NOT SYSVINIT_SCRIPTS_DIR) set (SYSVINIT_SCRIPTS_DIR "/etc/init.d/") endif (NOT SYSVINIT_SCRIPTS_DIR) message (STATUS "SysVinit scripts will be installed to: ${SYSVINIT_SCRIPTS_DIR}") endif (WITH_SYSVINIT_SUPPORT) if (WITH_SYSTEMD_SUPPORT) if (NOT SYSTEMD_UNIT_FILES_DIR) set (SYSTEMD_UNIT_FILES_DIR "/lib/systemd/system/") endif (NOT SYSTEMD_UNIT_FILES_DIR) message (STATUS "Systemd unit configuration files will be installed to: ${SYSTEMD_UNIT_FILES_DIR}") endif (WITH_SYSTEMD_SUPPORT) add_subdirectory (src/bosixnet-daemon) add_subdirectory (src/bosixnet-webui) configure_file (${PROJECT_SOURCE_DIR}/Version.h.in ${PROJECT_BINARY_DIR}/Version.h) add_custom_target (uninstall COMMAND xargs -a "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt" rm COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/bosixnet-daemon/bosixnet-daemon remove COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/bosixnet-webui/bosixnet-webui remove) bosixnet-2.0/INSTALL000066400000000000000000000044021337760024000142410ustar00rootroot00000000000000*** Build dependencies *** gcc (>= 4.8) or clang (>= 3.2) libfcgi-dev (>= 2.4) cmake (>= 2.8) gzip *** Runtime dependencies *** libfcgi -- Shared library of FastCGI spawn-fcgi -- A fastcgi process spawner curl -- Сommand line tool for transferring data with URL syntax sed -- The GNU sed stream editor *** Recommended programs *** miredo -- Teredo IPv6 tunneling through NATs gogoc -- Client to connect to IPv6 tunnel brokers You do not need any of these programs if your Internet provider gives you direct access to IPv6 network. Unfortunately this is too rare situation now. *** Build *** mkdir -p builddir cd builddir cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr .. make sudo make install *** Extra build options *** -DCMAKE_BUILD_TYPE={Release, RelWithDebInfo, Debug, MinRelSize} -DWITH_SYSVINIT_SUPPORT={ON, OFF} (default: OFF) -DSYSVINIT_SCRIPTS_DIR={...} (default: /etc/init.d/) -DWITH_SYSTEMD_SUPPORT={ON, OFF} (default: ON) -DSYSTEMD_UNIT_FILES_DIR={...} (default: /lib/systemd/system/) *** Configuration files *** /etc/bosixnet/bosixnet-daemon.conf /etc/bosixnet/bosixnet-webui.conf *** Example of FastCGI settings in Nginx *** Edit file /etc/nginx/sites-available/default and paste something like this: location /bosixnet/ { fastcgi_pass localhost:33169; include /etc/nginx/fastcgi_params; } *** Example of FastCGI settings in lighttpd *** Edit file /etc/lighttpd/lighttpd.conf and paste something like this: fastcgi.server = ( "/bosixnet/" => (( "host" => "127.0.0.1", "port" => 33169, "check-local" => "disable", "docroot" => "/var/tmp/bosixnet", )) ) *** Examples of Web UI usage with default settings *** Main usage: http://ipv6.example.com/bosixnet/main-laptop?update=2001:0:53aa:64c:2f53:5e65:9258:72de http://ipv6.example.com/bosixnet/main-laptop http://ipv6.example.com/bosixnet/home-pc?update=2001:0:53aa:64c:3574:128e:9291:a021 http://ipv6.example.com/bosixnet/home-pc http://ipv6.example.com/bosixnet/wife-netbook?update=2001:0:53aa:64c:26e0:3bf2:9258:72de http://ipv6.example.com/bosixnet/wife-netbook Service links: http://ipv6.example.com/bosixnet/ http://ipv6.example.com/bosixnet/hosts http://ipv6.example.com/bosixnet/timestamps http://ipv6.example.com/bosixnet/counter bosixnet-2.0/LICENSE000066400000000000000000000020701337760024000142140ustar00rootroot00000000000000Copyright (c) 2013-2017 Boris Pek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. bosixnet-2.0/README000066400000000000000000000057321337760024000140770ustar00rootroot00000000000000BOSixNet – Build Own IPv6 Network Copyright: 2013-2017 Boris Pek License: MIT (Expat) Homepage: https://github.com/tehnick/bosixnet Deb packages: https://github.com/tehnick/bosixnet-debian https://launchpad.net/~tehnick/+archive/bosixnet Description: Project should be useful when you have to administer many computers distributed through different networks and connected via NAT. In most of cases you may just install miredo, gogoc or any other tunnel broker's software and these computers will be available via IPv6 addresses. BOSixNet includes the collection of tools for automatic updating the list of such hosts. Project consist of two parts: 1) bosixnet-webui – FastCGI program which passively listens for incoming connections and generates list of hosts in your IPv6 network. This daemon prepares data which may be put directly into /etc/hosts. 2) bosixnet-daemon – shell script which periodically sends information about current IPv6 address to remote servers and updates local /etc/hosts file based on data received from these remote servers. It is expected that bosixnet-webui is launched on these remote servers, but it is not mandatory. For building own IPv6 network you need to install miredo, gogoc or any other tunnel broker software on all hosts where bosixnet-daemon will be launched. Of course you do not need any of these programs if your Internet provider gives you direct access to IPv6 network. Unfortunately this is too rare situation now. There are few possible solutions for remote server with bosixnet-webui: 1) Fixed IPv4 or IPv6 address. But if you have static IP you may use other solutions (like VPN) and this project is not very useful in such case. 2) Dynamic IPv4 address + fixed domain name. For example, you may use any DDNS provider. 3) Dynamic IPv6 address + fixed domain name. Some tunnel brokers give special domain names for their clients. For example, if you are registered on Freenet6 and use gogoc, you will have domain name like: .broker.freenet6.net 4) etc. bosixnet-webui is a tiny program with a very few dependencies. It may be easily launched on embedded devices. And since this is a microservice then there are no plans to make it more complicated in the future. Important notes: 1) In almost all cases the speed of access via teredo is much better than via tunnel brokers. Also miredo is very easy in use. 2) If two computers are in the same LAN, direct connection via teredo is not possible between them. So for IPv6 connection at least one of them should use tunnel broker or native IPv6 address. For information how to install and to use BOSixNet see file INSTALL. Screenshots: https://tehnick.github.io/bosixnet/screenshots/00.png https://tehnick.github.io/bosixnet/screenshots/01.png Some useful links: https://en.wikipedia.org/wiki/IPv6 https://en.wikipedia.org/wiki/Miredo https://github.com/evi1c/gogoc bosixnet-2.0/TODO000066400000000000000000000002551337760024000137020ustar00rootroot00000000000000--- TODO --- ? Rewrite daemon using c++ and libcurl. ? Add FreeBSD support. ? Add Android support. ? Add Ubuntu Touch support. ? Add MS Windows support. ? Add OS X support. bosixnet-2.0/Version.h.in000066400000000000000000000000631337760024000154120ustar00rootroot00000000000000#pragma once #define VERSION string("@VERSION@") bosixnet-2.0/changelog000066400000000000000000000105631337760024000150670ustar00rootroot00000000000000--- 2.0 2018-11-28 --- *** bosixnet-daemon *** * Fix update_hosts script after changing of behaviuor of `pidof` command line tool. * Add check of ADDRESS_SUB_STRING environment variable in update_address script (see config file for usage details). This variable may be useful when your network device has few registered IPv6 addresses. For example, see: https://en.wikipedia.org/wiki/Unique_local_address *** bosixnet-webui *** * Fix cross-compilation for MS Windows using MinGW and MXE (https://mxe.cc/). This is just for fun. MS Windows is still not supported in this project. --- 1.9 2017-02-08 --- *** common *** * Disable WITH_SYSVINIT_SUPPORT configuration option by default. *** bosixnet-daemon *** * Add "-L" option to `curl` command line tool in update_address and update_hosts scripts for simplifying migration from HTTP to HTTPS and/or between servers. *** bosixnet-webui *** * Tiny improvement in a counter of visits. --- 1.8 2016-10-22 --- *** common *** * Add basic systemd support. * Add WITH_SYSVINIT_SUPPORT, WITH_SYSTEMD_SUPPORT, SYSVINIT_SCRIPTS_DIR and SYSTEMD_UNIT_FILES_DIR cmake configuration options. *** bosixnet-daemon *** * Provide unique default value of HOST_NAME variable. But manual setup is more preferable in any case. *** bosixnet-webui *** * Update launcher script. * Update hosts map only when host address is really changed. * Rename BASIC_STR variable to PREFIX_STR. * Add check that PREFIX_STR is always terminated by '/' character. * Add special page "/timestamps": it shows list of hosts and timestamps of their last activity. * Use show_map() instead of show_file() for "/hosts" and "/timestamps" pages. This allows to decrease the number of disk I/O operations and works faster (even with comparing with reading from modern SSD drive connected via SATA 3). [TODO: add link to tests results] * Code refactoring. --- 1.7 2015-09-30 --- *** common *** * Relicense from GPLv2 or later to Expat. *** bosixnet-daemon *** * Use `ip` tool instead of `ifconfig` for getting local IPv6 address. * Added ability to select specific network device for getting local IPv6 address. By default script searches IPv6 addresses for all network devices of the system and chooses the last of them. * Protect file with list of hosts from simultaneous editing. * Additional check if current IPv6 address is valid. --- 1.6 2014-02-11 --- *** bosixnet-daemon *** * Improved simple check for validity of IPv6 addresses received from server: - strings should be longer than 6 characters - strings should have at least three ":" characters - fifth character from strings should be equal to ":" (Affects only script update_hosts.) * Added support of multiple servers: - IPv6 address is sent to all available servers - data about hosts is got from the first server which replies to request See file bosixnet-daemon.conf for examples of configuring. *** bosixnet-webui *** * Removed support of POST requests. * Added simple check for valid IPv6 address received in GET request: - string should be longer than 7 characters - string should be shorter than 40 characters - string should have at least three ":" characters - fifth character from string should be equal to ":" - string should contain only allowed characters (:0123456789abcdefABCDEF) The same check is used during loading the list of hosts from file. --- 1.5 2014-02-05 --- * Changed default user in webui_launcher from "user" to "bosixnet". * Added man pages, updated README and fixed few typos in help. * Renamed BASIC_URL variable to BASIC_STR. --- 1.4 2014-02-04 --- * Improved update_hosts: only strings with IPv6 addresses is copied into /etc/hosts, all rest data is ignored now. * Small code refactoring in scripts: bosixnet_daemon, update_address, update_hosts, webui_launcher. --- 1.3 2014-02-04 --- * Small fix in bosixnet_daemon: send some useless warnings to /dev/null. * Tiny fix in LOG_DIR variable. --- 1.2 2014-02-04 --- * Rewritten init scripts. * Added script daemon_launcher. * Updated script webui_launcher. --- 1.1 2014-02-04 --- * Update init scripts. --- 1.0 2014-02-03 --- * Changed version numbering scheme. * Project was rewritten from qmake to cmake. * Program bosixnet-webui was rewritten from QtCore 4.x to pure STL. * Added support of config files into scripts: bosixnet_daemon, update_address, update_hosts and webui_launcher. * Updated README. --- 0.0.1 2013-10-17 --- * Initial release. bosixnet-2.0/src/000077500000000000000000000000001337760024000137775ustar00rootroot00000000000000bosixnet-2.0/src/bosixnet-daemon/000077500000000000000000000000001337760024000170735ustar00rootroot00000000000000bosixnet-2.0/src/bosixnet-daemon/CMakeLists.txt000066400000000000000000000025421337760024000216360ustar00rootroot00000000000000project (bosixnet_daemon) cmake_minimum_required (VERSION 2.8) execute_process (COMMAND gzip -9 INPUT_FILE ${PROJECT_NAME}.1 OUTPUT_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.1.gz WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/) install (FILES ${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install (FILES daemon_launcher update_address update_hosts DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/bosixnet/" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install (FILES bosixnet-daemon.conf DESTINATION "/etc/bosixnet/") install (FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.1.gz DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1") if (WITH_SYSVINIT_SUPPORT) install (FILES bosixnet-daemon DESTINATION "${SYSVINIT_SCRIPTS_DIR}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif (WITH_SYSVINIT_SUPPORT) if (WITH_SYSTEMD_SUPPORT) install (FILES bosixnet-daemon.service DESTINATION "${SYSTEMD_UNIT_FILES_DIR}" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) endif (WITH_SYSTEMD_SUPPORT) bosixnet-2.0/src/bosixnet-daemon/bosixnet-daemon000077500000000000000000000041041337760024000221140ustar00rootroot00000000000000#!/bin/bash ### BEGIN INIT INFO # Provides: bosixnet-daemon # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts bosixnet_daemon # Description: starts script which check ipv6 address each N minutes ### END INIT INFO # Author: Boris Pek # Last updated: 2016-10-21 NAME=bosixnet_daemon DESC="BOSixNet client" DAEMON=/usr/lib/bosixnet/daemon_launcher DAEMON_OPTS= SCRIPT=bosixnet-daemon PIDFILE=/var/run/${NAME}.pid [ -x ${DAEMON} ] || exit 0 . /lib/lsb/init-functions set -e check_start() { set +e DAEMON_PID="$(pidof -x ${NAME})" if [ ! -z "${DAEMON_PID}" ]; then log_end_msg $? exit 0 fi set -e } check_stop() { set +e DAEMON_PID="$(pidof -x ${NAME})" if [ ! -z "${DAEMON_PID}" ]; then killall -9 "${NAME}" &>/dev/null sleep 1 fi set -e } start() { check_start start-stop-daemon --start --quiet --pidfile "${PIDFILE}" \ --exec "${DAEMON}" --oknodo -- ${DAEMON_OPTS} } stop() { start-stop-daemon --stop --quiet --pidfile "${PIDFILE}" \ --exec "${DAEMON}" --oknodo --retry 5 sleep 1 check_stop } case "$1" in start) log_daemon_msg "Starting ${DESC}" "${NAME}" start log_end_msg $? ;; stop) log_daemon_msg "Stopping ${DESC}" "${NAME}" stop log_end_msg $? ;; restart|force-reload) log_daemon_msg "Restarting ${DESC}" "${NAME}" stop sleep 1 start log_end_msg $? ;; status) status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" && exit 0 || exit $? ;; install) cp -f ${0} /etc/init.d/${SCRIPT} insserv bosixnet-webui ;; remove) rm -f /etc/rc*.d/*${SCRIPT}* rm -f /etc/init.d/${SCRIPT} ;; *) echo "Usage: /etc/init.d/${SCRIPT} {start|stop|restart|force-reload|status|install|remove}" >&2 exit 1 ;; esac exit 0 bosixnet-2.0/src/bosixnet-daemon/bosixnet-daemon.conf000066400000000000000000000016671337760024000230500ustar00rootroot00000000000000# Host name: # HOST_NAME=my-laptop # Period of updating IPv6 address and /etc/hosts [seconds]: # UPD_PERIOD=300 # Directory with auxiliary scripts: # DIR_UTIL="/usr/lib/bosixnet" # Directory where generated host file is stored: # LOG_DIR=/var/tmp/bosixnet # This may be useful when you use daemon on the same server as web ui. # Network device: # NETWORK_DEVICE=teredo # Address sub-string: # ADDRESS_SUB_STRING=2a02 # This may be useful when your network device has few registered IPv6 addresses. # For example, see: https://en.wikipedia.org/wiki/Unique_local_address # Website URL: # URL="http://ipv6.example.com/bosixnet" # # You may use multiple servers. For example: # URL="http://home-server/bosixnet # http://remote-server:8098/bosixnet # https://common-backup-server/secret-prefix-string" # # In this case: # - IPv6 address is sent to all available servers # - hosts list is got from the first server which replied to request bosixnet-2.0/src/bosixnet-daemon/bosixnet-daemon.service000066400000000000000000000003071337760024000235510ustar00rootroot00000000000000[Unit] Description=BOSixNet client Documentation=man:bosixnet_daemon(1) After=network.target [Service] Type=forking ExecStart=/usr/lib/bosixnet/daemon_launcher [Install] WantedBy=multi-user.target bosixnet-2.0/src/bosixnet-daemon/bosixnet_daemon000077500000000000000000000021561337760024000222030ustar00rootroot00000000000000#!/bin/sh # Config file CONF_FILE="/etc/bosixnet/bosixnet-daemon.conf" # Period of updating IPv6 address and /etc/hosts file [seconds]: UPD_PERIOD=300 # Directory with auxiliary scripts: DIR_UTIL="/usr/lib/bosixnet" # Read settings from config file if it exists [ -e "${CONF_FILE}" ] && . "${CONF_FILE}" # Check command line options if [ "${1}" = "-h" -o "${1}" = "--help" ]; then echo "Usage: bosixnet_daemon [options] This shell script periodically sends information about current IPv6 address to remote servers and updates local /etc/hosts file based on data received from these remote servers. It is expected that bosixnet-webui is launched on these remote servers, but it is not mandatory. Generic options: -h, --help show help and exit -v, --version show version and exit Settings are in config file: ${CONF_FILE}" exit 0 elif [ "${1}" = "-v" -o "${1}" = "--version" ]; then echo "Last updated: 2016-10-19" exit 0 fi # Infinite cycle for periodical updates while [ 1 ]; do "${DIR_UTIL}/update_address" &>/dev/null "${DIR_UTIL}/update_hosts" &>/dev/null sleep ${UPD_PERIOD} done bosixnet-2.0/src/bosixnet-daemon/bosixnet_daemon.1000066400000000000000000000023161337760024000223350ustar00rootroot00000000000000.TH "bosixnet_daemon" 1 "19 Oct 2016" .SH "NAME" bosixnet_daemon \- shell script which periodically sends information about current IPv6 address to remote servers and updates local /etc/hosts file based on data received from these remote servers. It is expected that bosixnet-webui is launched on these remote servers, but it is not mandatory. .SH "SYNOPSIS" .PP .B bosixnet_daemon [options] .SH "DESCRIPTION" .PP \fBBOSixNet\fP \-\- Build Own IPv6 Network. .TP Project should be useful when you have to administer many computers distributed through different networks and connected via NAT. In most of cases you may just install miredo, gogoc or any other tunnel broker's software and these computers will be available via IPv6 addresses. BOSixNet includes the collection of tools for automatic updating the list of such hosts. .SH "OPTIONS" .RB "Generic options:" .TP .BR "\-h, \-\-help" Show help and exit. .TP .BR "\-v, \-\-version" Show version and exit. .SH "FILES" .TP .B "/etc/bosixnet/" Directory with configuration files. .SH "DOCUMENTATION" .TP Basic information: \fBhttps://github.com/tehnick/bosixnet/blob/master/README\fR .SH "BUG REPORTS" Please report bugs here: \fBhttps://github.com/tehnick/bosixnet/issues\fR bosixnet-2.0/src/bosixnet-daemon/daemon_launcher000077500000000000000000000000651337760024000221460ustar00rootroot00000000000000#!/bin/bash /usr/bin/bosixnet_daemon &>/dev/null & bosixnet-2.0/src/bosixnet-daemon/update_address000077500000000000000000000025401337760024000220110ustar00rootroot00000000000000#!/bin/bash # Config file CONF_FILE="/etc/bosixnet/bosixnet-daemon.conf" # Default host name TMP_STR="$(/*/ifconfig 2> /dev/null | grep ether | sort | sha256sum)" HOST_NAME="$(uname -n)-${TMP_STR:3:8}" # Default website URL URL="http://ipv6.example.com/bosixnet" # Read settings from config file if it exists [ -e "${CONF_FILE}" ] && . "${CONF_FILE}" PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin if [ ! -z "${NETWORK_DEVICE}" ]; then IPv6_INFO="$(ip -6 addr show "${NETWORK_DEVICE}" | grep -i global)" else IPv6_INFO="$(ip -6 addr | grep -i global)" fi if [ ! -z "${IPv6_INFO}" ]; then # Get list of IPv6 addresses using simple regexp IPv6_CUR=$(echo "${IPv6_INFO}" | sed -ne "s|^.*inet6\ \(.*\)/[0-9]*\ .*$|\1|p") # Get current IPv6 address if [ ! -z "${ADDRESS_SUB_STRING}" ]; then IPv6_CUR=$(echo "${IPv6_CUR}" | grep "${ADDRESS_SUB_STRING}" | head -n1) else IPv6_CUR=$(echo "${IPv6_CUR}" | head -n1) fi # Check if this IPv6 address is valid IPv6_CUR="$(echo "${IPv6_CUR}" | grep '^....:.*:.*:.*')" fi if [ ! -z "${IPv6_CUR}" ]; then for DEST in ${URL} ; do LINK="${DEST}/${HOST_NAME}" IPv6_OLD="$(curl -L ${LINK} 2> /dev/null)" if [ "${IPv6_OLD}" != "${IPv6_CUR}" ]; then curl -L "${LINK}?update=${IPv6_CUR}" &> /dev/null fi done fi bosixnet-2.0/src/bosixnet-daemon/update_hosts000077500000000000000000000031001337760024000215150ustar00rootroot00000000000000#!/bin/sh # Config file CONF_FILE="/etc/bosixnet/bosixnet-daemon.conf" # Directory where generated host file is stored LOG_DIR="/var/tmp/bosixnet" # Default web-site URL URL="http://ipv6.example.com/bosixnet" # Read settings from config file if it exists [ -e "${CONF_FILE}" ] && . "${CONF_FILE}" # Protect file with list of hosts from simultaneous editing SCRIPT_NAME="$(basename ${0})" PROCESS_ID="$(pidof -x ${SCRIPT_NAME})" if [ "$(echo ${PROCESS_ID} | tr ' ' '\n' | wc -l)" != "1" ]; then echo "Another instance of ${SCRIPT_NAME} script is already running." echo "Please wait until it is finished and try again." exit 1 fi HOSTS="/etc/hosts" FILE="${LOG_DIR}/hosts" [ -e "${FILE}" ] && CUR_INFO="$(cat ${FILE} | grep '^....:.*:.*:.*')" if [ -z "${CUR_INFO}" ]; then echo "File ${FILE} does not exist or does not contain correct data." for DEST in ${URL} ; do LINK="${DEST}/hosts" echo "Trying to get data from ${LINK}..." CUR_INFO="$(curl -L ${LINK} 2>/dev/null | sed 's/
//' | grep '^....:.*:.*:.*')" if [ -z "${CUR_INFO}" ]; then echo "Attempt to get data from ${LINK} failed." else echo "Data from ${LINK} have been received successfully." break fi done fi if [ -z "${CUR_INFO}" ]; then echo "Data failed to be received from specified resources." exit 1 fi cp -f "${HOSTS}" "${HOSTS}.backup" cat "${HOSTS}.backup" | grep -v '^....:.*:.*:.*' | tee "${HOSTS}.new" > /dev/null echo "${CUR_INFO}" | tee -a "${HOSTS}.new" > /dev/null cp -f "${HOSTS}.new" "${HOSTS}" bosixnet-2.0/src/bosixnet-webui/000077500000000000000000000000001337760024000167435ustar00rootroot00000000000000bosixnet-2.0/src/bosixnet-webui/CMakeLists.txt000066400000000000000000000025541337760024000215110ustar00rootroot00000000000000project (bosixnet_webui) cmake_minimum_required (VERSION 2.8) include_directories(${CMAKE_BINARY_DIR}) add_executable (${PROJECT_NAME} bosixnet-webui.cpp) target_link_libraries (${PROJECT_NAME} fcgi) execute_process (COMMAND gzip -9 INPUT_FILE ${PROJECT_NAME}.1 OUTPUT_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.1.gz WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/) install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/") install (FILES webui_launcher DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/bosixnet/" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install (FILES bosixnet-webui.conf DESTINATION "/etc/bosixnet/") install (FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.1.gz DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1") if (WITH_SYSVINIT_SUPPORT) install (FILES bosixnet-webui DESTINATION "${SYSVINIT_SCRIPTS_DIR}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif (WITH_SYSVINIT_SUPPORT) if (WITH_SYSTEMD_SUPPORT) install (FILES bosixnet-webui.service DESTINATION "${SYSTEMD_UNIT_FILES_DIR}" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) endif (WITH_SYSTEMD_SUPPORT) bosixnet-2.0/src/bosixnet-webui/bosixnet-webui000077500000000000000000000040721337760024000216400ustar00rootroot00000000000000#!/bin/bash ### BEGIN INIT INFO # Provides: bosixnet-webui # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts bosixnet_webui # Description: starts FastCGI program for generating /etc/hosts ### END INIT INFO # Author: Boris Pek # Last updated: 2016-10-21 NAME=bosixnet_webui DESC="BOSixNet server" DAEMON=/usr/lib/bosixnet/webui_launcher DAEMON_OPTS= SCRIPT=bosixnet-webui PIDFILE=/var/run/${NAME}.pid [ -x ${DAEMON} ] || exit 0 . /lib/lsb/init-functions set -e check_start() { set +e DAEMON_PID="$(pidof -x ${NAME})" if [ ! -z "${DAEMON_PID}" ]; then log_end_msg $? exit 0 fi set -e } check_stop() { set +e DAEMON_PID="$(pidof -x ${NAME})" if [ ! -z "${DAEMON_PID}" ]; then killall -9 "${NAME}" &>/dev/null sleep 1 fi set -e } start() { check_start start-stop-daemon --start --quiet --pidfile "${PIDFILE}" \ --exec "${DAEMON}" --oknodo -- ${DAEMON_OPTS} } stop() { start-stop-daemon --stop --quiet --pidfile "${PIDFILE}" \ --exec "${DAEMON}" --oknodo --retry 5 sleep 1 check_stop } case "$1" in start) log_daemon_msg "Starting ${DESC}" "${NAME}" start log_end_msg $? ;; stop) log_daemon_msg "Stopping ${DESC}" "${NAME}" stop log_end_msg $? ;; restart|force-reload) log_daemon_msg "Restarting ${DESC}" "${NAME}" stop sleep 1 start log_end_msg $? ;; status) status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" && exit 0 || exit $? ;; install) cp -f ${0} /etc/init.d/${SCRIPT} insserv bosixnet-webui ;; remove) rm -f /etc/rc*.d/*${SCRIPT}* rm -f /etc/init.d/${SCRIPT} ;; *) echo "Usage: /etc/init.d/${SCRIPT} {start|stop|restart|force-reload|status|install|remove}" >&2 exit 1 ;; esac exit 0 bosixnet-2.0/src/bosixnet-webui/bosixnet-webui.conf000066400000000000000000000011141337760024000225530ustar00rootroot00000000000000# Prefix string from fastcgi SCRIPT_NAME variable. For example: # if full URL looks like http://ipv6.example.com/our-ipv6-network/ then it should be: # PREFIX_STR=/our-ipv6-network/ # if full URL looks like http://ipv6.example.com/bosixnet/ then it should be: # PREFIX_STR=/bosixnet/ # if full URL looks like http://ipv6.example.com/ then it should be: # PREFIX_STR=/ # Directory where auxiliary files will be stored # LOG_DIR=/var/tmp/bosixnet # Launch bosixnet-webui from specific user: # USERID=bosixnet # GROUPID=bosixnet # TCP port to which to bind on localhost # FCGIPORT=33169 bosixnet-2.0/src/bosixnet-webui/bosixnet-webui.cpp000066400000000000000000000346041337760024000224220ustar00rootroot00000000000000/***************************************************************************** * * * Copyright (c) 2013-2017 Boris Pek * * * * Permission is hereby granted, free of charge, to any person obtaining * * a copy of this software and associated documentation files (the * * "Software"), to deal in the Software without restriction, including * * without limitation the rights to use, copy, modify, merge, publish, * * distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to * * the following conditions: * * * * The above copyright notice and this permission notice shall be included * * in all copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * * *****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include "Version.h" using std::map; using std::string; using std::stringstream; using std::ifstream; using std::ofstream; using std::ios; using std::cout; string prefix_str = "/bosixnet/"; string log_dir = "/var/tmp/bosixnet"; string conf_file = "/etc/bosixnet/bosixnet-webui.conf"; map hosts_map; map timestamps_map; bool check_options(int, char **); void read_options(int, char **); void read_config(); void show_help(); void show_version(); void show_html(const string &); void show_map(const map &); void show_hosts_map(); void show_timestamps_map(); void update_prefix_str(const string &); void update_timestamp(const string &); void read_file(const string &, map &, bool (*is_valid)(const string &)); void read_hosts(); void read_timestamps(); void write_file(const string &, const map &); void write_hosts(); void write_timestamps(); bool ends_with(const string &, const string &); bool starts_with(const string &, const string &); bool is_valid_ipv6_address(const string &); bool is_valid_timestamp(const string &); string get_env_var(const string &); string get_param(const string &, const string &); string get_conf_var(const string &, const string &); string remove_extra_symbols(const string &, const string &); int main(int argc, char **argv) { if (check_options(argc, argv)) return 0; // Settings in config file have lower priority than command line options. const string conf_file_default = conf_file; read_config(); read_options(argc, argv); if (conf_file != conf_file_default) { read_config(); read_options(argc, argv); } read_hosts(); read_timestamps(); unsigned long counter = 0; while (FCGI_Accept() >= 0) { ++counter; string content; const string request_method = get_env_var("REQUEST_METHOD"); if (request_method.empty()) { continue; } if (request_method == "GET") { content = get_env_var("QUERY_STRING"); } else { show_html("

Only GET request method is allowed!

\n"); continue; }; const string full_path = get_env_var("SCRIPT_NAME"); if (ends_with(full_path, prefix_str)) { show_hosts_map(); } else if (ends_with(full_path, prefix_str + "hosts")) { show_hosts_map(); } else if (ends_with(full_path, prefix_str + "timestamps")) { show_timestamps_map(); } else if (ends_with(full_path, prefix_str + "counter")) { stringstream counter_str; counter_str << counter; show_html("Counter: " + counter_str.str()); } else { const string host_name = full_path.substr(full_path.rfind("/") + 1); const string new_address = get_param(content, "update="); if (new_address.empty()) { const auto it = hosts_map.find(host_name); if (it != hosts_map.end()) { update_timestamp(host_name); show_html(it->second); } else { show_html(""); } } else if (is_valid_ipv6_address(new_address)) { update_timestamp(host_name); if (hosts_map[host_name] != new_address) { hosts_map[host_name] = new_address; write_hosts(); write_timestamps(); } show_html(new_address); } else { show_html(new_address + " is not a valid IPv6 address!"); } } } return 0; } bool check_options(int argc, char **argv) { string arg; for (int idx = 1 ; idx < argc ; ++idx) { arg = argv[idx]; if (arg == "-h" || arg == "--help") { show_help(); return true; } else if (arg == "-v" || arg == "--version") { show_version(); return true; } } return false; } void read_options(int argc, char **argv) { if (argc > 2) { string arg; string arg_next; for (int idx = 1 ; idx < argc - 1 ; ++idx) { arg = argv[idx]; arg_next = argv[idx + 1]; if (arg == "-b" || arg == "--prefix-str") { update_prefix_str(arg_next); } else if (arg == "-l" || arg == "--log-dir") { log_dir = arg_next; } else if (arg == "-c" || arg == "--conf-file") { conf_file = arg_next; } } } } void read_config() { ifstream file; file.open(conf_file.c_str(), ios::in); if (file.is_open()) { string buff, var, tmp; while (!file.eof()) { getline(file, buff); buff = remove_extra_symbols(buff, " \t"); if (buff.size() >= 3 && buff.at(0) != '#') { // This block is added for back compatibility: { // TODO: delete later var = "BASIC_STR"; tmp = get_conf_var(buff, var); if (!tmp.empty()) { update_prefix_str(tmp); } } var = "PREFIX_STR"; tmp = get_conf_var(buff, var); if (!tmp.empty()) { update_prefix_str(tmp); } var = "LOG_DIR"; tmp = get_conf_var(buff, var); if (!tmp.empty()) { log_dir = tmp; } } } file.close(); } } void show_help() { cout << "Usage: bosixnet_webui [options]\n" "\n" "FastCGI program which passively listens for incoming connections and\n" "generates list of hosts in your IPv6 network. This daemon prepares data\n" "which may be put directly into /etc/hosts.\n" "\n" "Generic options:\n" " -h, --help show help and exit\n" " -v, --version show version and exit\n" "\n" "Options:\n" " -b , --prefix-str set url prefix (default: " + prefix_str + ")\n" " -l , --log-dir set directory for auxiliary files (default: " + log_dir + ")\n" " -c , --conf-file set config file (default: " + conf_file + ")\n" "\n" "Settings in config file have lower priority than command line options.\n"; } void show_version() { cout << "Version: " << VERSION << "\n"; } void show_html(const string &str) { printf("Content-type: text/html\n\n"); printf("%s", str.c_str()); } void show_map(const map &map_name) { string out; for (const auto &it : map_name) { out += it.second + " " + it.first + "
\n"; } show_html(out); } void show_hosts_map() { show_map(hosts_map); } void show_timestamps_map() { show_map(timestamps_map); } void update_prefix_str(const string &new_prefix_str) { prefix_str = new_prefix_str; if (prefix_str.at(prefix_str.size()-1) != '/') { prefix_str.push_back('/'); } } void update_timestamp(const string &host_name) { const time_t current_time = time(0); const struct tm *time_info = localtime(¤t_time); char new_timestamp[26]; strftime(new_timestamp, 26, "%F_%H:%M:%S_%z", time_info); timestamps_map[host_name] = string(new_timestamp); } void read_file(const string &file_name, map &map_name, bool (*is_valid)(const string &)) { const string log_file = log_dir + file_name; ifstream file; file.open(log_file.c_str(), ios::in); if (file.is_open()) { string buff, key, value; stringstream str; while (!file.eof()) { getline(file, buff); str.clear(); str << buff; str >> value; str >> key; if (!value.empty() && !key.empty()) { if (is_valid(value)) { map_name[key] = value; } } } file.close(); } } void read_hosts() { read_file("/hosts", hosts_map, is_valid_ipv6_address); } void read_timestamps() { read_file("/timestamps", timestamps_map, is_valid_timestamp); } void write_file(const string &file_name, const map &map_name) { struct stat info; if (stat(log_dir.c_str(), &info)) { #if defined(_WIN32) if (mkdir(log_dir.c_str())) { #else if (mkdir(log_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { #endif cout << "Directory " << log_dir << " was not created!\n"; return; } } const string log_file = log_dir + file_name; ofstream file; file.open(log_file.c_str(), ios::out); if (file.is_open()) { for (const auto &it : map_name) { file << it.second << " " << it.first << "\n"; } file.close(); } } void write_hosts() { write_file("/hosts", hosts_map); } void write_timestamps() { write_file("/timestamps", timestamps_map); } bool ends_with(const string &str, const string &sfx) { if (sfx.size() > str.size()) return false; return equal(str.begin() + str.size() - sfx.size(), str.end(), sfx.begin()); } bool starts_with(const string &str, const string &pfx) { if (pfx.size() > str.size()) return false; return equal(str.begin(), str.begin() + pfx.size(), pfx.begin()); } bool is_valid_ipv6_address(const string &str) { const size_t len = str.size(); if (len < 8) return false; else if (len > 39) return false; unsigned int counter = 0; const char *p = str.c_str(); while (strstr(p,":")) { ++counter; ++p; } if (counter < 3) return false; else if (str.at(4) != ':') return false; if (str.find_first_not_of(":0123456789abcdefABCDEF") != string::npos) return false; return true; } bool is_valid_timestamp(const string &str) { if (str.size() != 25) return false; if (str.at(4) != '-') return false; else if (str.at(7) != '-') return false; else if (str.at(10) != '_') return false; else if (str.at(13) != ':') return false; else if (str.at(16) != ':') return false; else if (str.at(19) != '_') return false; else if (str.at(20) != '+') return false; if (str.find_first_not_of("_+-:0123456789") != string::npos) return false; return true; } string get_env_var(const string &var) { const char *ptr = getenv(var.c_str()); return (ptr ? string(ptr) : ""); } string get_param(const string &buff, const string &name) { if (buff.empty() || name.empty()) return ""; size_t param_begin = buff.find(name); if (param_begin == string::npos) return ""; param_begin += name.size(); if (param_begin >= buff.size()) return ""; size_t param_end = buff.find("&", param_begin); if (param_end == string::npos) param_end = buff.size(); const string out = buff.substr(param_begin, param_end - param_begin); return out; } string get_conf_var(const string &buff, const string &var) { if (!starts_with(buff, var)) return ""; string out = buff.substr(var.size()); out = remove_extra_symbols(out, "= \t\""); return out; } string remove_extra_symbols(const string &str, const string &symbols) { string out = str; size_t pos = out.find_first_not_of(symbols); if (pos != string::npos) { out = out.substr(pos); } pos = out.find_last_not_of(symbols); if (pos != string::npos && pos != out.size() - 1) { out = out.substr(0, pos + 1); } return out; } bosixnet-2.0/src/bosixnet-webui/bosixnet-webui.service000066400000000000000000000003051337760024000232670ustar00rootroot00000000000000[Unit] Description=BOSixNet server Documentation=man:bosixnet_webui(1) After=network.target [Service] Type=forking ExecStart=/usr/lib/bosixnet/webui_launcher [Install] WantedBy=multi-user.target bosixnet-2.0/src/bosixnet-webui/bosixnet_webui.1000066400000000000000000000027731337760024000220640ustar00rootroot00000000000000.TH "bosixnet_webui" 1 "19 Oct 2016" .SH "NAME" bosixnet_webui \- FastCGI program which passively listens for incoming connections and generates list of hosts in your IPv6 network. This daemon prepares data which may be put directly into /etc/hosts. .SH "SYNOPSIS" .PP .B bosixnet_webui [options] .SH "DESCRIPTION" .PP \fBBOSixNet\fP \-\- Build Own IPv6 Network. .TP Project should be useful when you have to administer many computers distributed through different networks and connected via NAT. In most of cases you may just install miredo, gogoc or any other tunnel broker's software and these computers will be available via IPv6 addresses. BOSixNet includes the collection of tools for automatic updating the list of such hosts. .SH "OPTIONS" .RB "Generic options:" .TP .BR "\-h, \-\-help" Show help and exit. .TP .BR "\-v, \-\-version" Show version and exit. .TP .RB "Special options:" .TP .BR "\-b , \-\-prefix-str " Set url prefix (default: /bosixnet/). .TP .BR "\-l , \-\-log-dir " Set directory for auxiliary files (default: /var/tmp/bosixnet). .TP .BR "\-c , \-\-confdir " Set config file (default: /etc/bosixnet/bosixnet-webui.conf). .br Settings in config file have lower priority than command line options. .SH "FILES" .TP .B "/etc/bosixnet/" Directory with configuration files. .SH "DOCUMENTATION" .TP Basic information: \fBhttps://github.com/tehnick/bosixnet/blob/master/README\fR .SH "BUG REPORTS" Please report bugs here: \fBhttps://github.com/tehnick/bosixnet/issues\fR bosixnet-2.0/src/bosixnet-webui/webui_launcher000077500000000000000000000017671337760024000217000ustar00rootroot00000000000000#!/bin/bash # Config file CONF_FILE="/etc/bosixnet/bosixnet-webui.conf" # If this script is run as root, switch to the specific user USERID=bosixnet GROUPID=bosixnet # TCP port for binding on localhost FCGIPORT=33169 # ABSOLUTE path to the spawn-fcgi binary SPAWNFCGI="/usr/bin/spawn-fcgi" # ABSOLUTE path to the program binary FCGIPROGRAM="/usr/bin/bosixnet_webui" # Read settings from config file if it exists [ -e "${CONF_FILE}" ] && . "${CONF_FILE}" # Check user existence if ! id -u ${USERID} &> /dev/null; then echo ; echo "User ${USERID} does not exist! Check what you use the correct USERID." exit 1 fi # Check group existence if ! id -g ${GROUPID} &> /dev/null; then echo ; echo "Group ${GROUPID} does not exist! Check what you use the correct GROUPID." exit 1 fi # spawn-fcgi command-line options EX="${SPAWNFCGI} -p ${FCGIPORT} -f ${FCGIPROGRAM} -u ${USERID} -g ${GROUPID}" # Clean the environment, set up a new one and launch the program env - ${E} ${EX} &> /dev/null