pax_global_header00006660000000000000000000000064126026026440014514gustar00rootroot0000000000000052 comment=2cdf52b3692d199b450db4b5b0c53150803b4137 bosixnet-1.7/000077500000000000000000000000001260260264400132165ustar00rootroot00000000000000bosixnet-1.7/.gitignore000066400000000000000000000000121260260264400151770ustar00rootroot00000000000000builddir* bosixnet-1.7/CMakeLists.txt000066400000000000000000000010351260260264400157550ustar00rootroot00000000000000project (bosixnet) cmake_minimum_required (VERSION 2.8) set (PROJECT_NAME "BOSixNet") set (VERSION "1.7") 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-1.7/INSTALL000066400000000000000000000014421260260264400142500ustar00rootroot00000000000000*** 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 *** Build options *** -DCMAKE_BUILD_TYPE={Release, RelWithDebInfo, Debug, MinRelSize} bosixnet-1.7/LICENSE000066400000000000000000000020661260260264400142270ustar00rootroot00000000000000Copyright (c) 2013-2015 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-1.7/README000066400000000000000000000072561260260264400141100ustar00rootroot00000000000000BOSixNet -- Build Own IPv6 Network Copyright: 2013-2015 Boris Pek License: 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 server and updates local /etc/hosts based on data received from that remote server. It is expected that bosixnet-webui is launched on that remote server. 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 statical 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 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 small program with very few dependencies. It may be easily launched on embedded devices. 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 at least one of them should use tunnel broker. Some useful links: https://en.wikipedia.org/wiki/IPv6 https://en.wikipedia.org/wiki/Teredo_tunneling https://en.wikipedia.org/wiki/Miredo https://github.com/jorti/gogoc Examples of using Web UI: 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 http://ipv6.example.com/bosixnet/counter http://ipv6.example.com/bosixnet/hosts http://ipv6.example.com/bosixnet/ Example of configuring 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 configuring 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", )) ) bosixnet-1.7/Version.h.in000066400000000000000000000000531260260264400154170ustar00rootroot00000000000000#pragma once #define VERSION "@VERSION@" bosixnet-1.7/changelog000066400000000000000000000050301260260264400150660ustar00rootroot00000000000000--- 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-1.7/src/000077500000000000000000000000001260260264400140055ustar00rootroot00000000000000bosixnet-1.7/src/bosixnet-daemon/000077500000000000000000000000001260260264400171015ustar00rootroot00000000000000bosixnet-1.7/src/bosixnet-daemon/CMakeLists.txt000066400000000000000000000020621260260264400216410ustar00rootroot00000000000000project (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 bosixnet-daemon DESTINATION "/etc/init.d/" 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") bosixnet-1.7/src/bosixnet-daemon/bosixnet-daemon000077500000000000000000000041171260260264400221260ustar00rootroot00000000000000#!/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: 2014-02-04 NAME=bosixnet_daemon DESC="BOSixNet daemon" 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 2>/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-1.7/src/bosixnet-daemon/bosixnet-daemon.conf000066400000000000000000000013231260260264400230430ustar00rootroot00000000000000# 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 # Network device: #NETWORK_DEVICE=teredo # Host name #HOST_NAME=my-laptop # Web-site URL #URL="http://ipv6.example.com/bosixnet" # # You may use multiple servers. For setting them use something like this: #URL="http://my-personal-server/bosixnet # http://my-friend's-server/bosixnet # http://common-backup-server/bosixnet" # # In the case of using multiple servers: # - IPv6 address is sent to all available servers # - data about hosts is got from the first server which replies to request bosixnet-1.7/src/bosixnet-daemon/bosixnet_daemon000077500000000000000000000021031260260264400222010ustar00rootroot00000000000000#!/bin/sh # Config file CONF_FILE="/etc/bosixnet/bosixnet-daemon.conf" # Period of updating IPv6 address and /etc/hosts [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 server and updates local /etc/hosts based on data received from that remote server. It is expected that bosixnet-webui is launched on remote server. Generic options: -h, --help show help -v, --version show version Settings are in config file: ${CONF_FILE}" exit 0 elif [ "${1}" = "-v" -o "${1}" = "--version" ]; then echo "Last updated: 2014-02-05" exit 0 fi # Infinite cycle for periodical updates while [ 1 ]; do "${DIR_UTIL}/update_address" >/dev/null 2>/dev/null "${DIR_UTIL}/update_hosts" >/dev/null 2>/dev/null sleep ${UPD_PERIOD} done bosixnet-1.7/src/bosixnet-daemon/bosixnet_daemon.1000066400000000000000000000022531260260264400223430ustar00rootroot00000000000000.TH "bosixnet_daemon" 1 "05 Feb 2014" .SH "NAME" bosixnet_daemon \- shell script which periodically sends information about current IPv6 address to remote server and updates local /etc/hosts based on data received from that remote server. It is expected that bosixnet-webui is launched on that remote server. .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-1.7/src/bosixnet-daemon/daemon_launcher000077500000000000000000000000641260260264400221530ustar00rootroot00000000000000#!/bin/bash /usr/bin/bosixnet_daemon >/dev/null & bosixnet-1.7/src/bosixnet-daemon/update_address000077500000000000000000000020661260260264400220220ustar00rootroot00000000000000#!/bin/sh # Config file CONF_FILE="/etc/bosixnet/bosixnet-daemon.conf" # Default host name HOST_NAME="$(uname -n)" # Default web-site 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 current IPv6 address using simple regexp IPv6_CUR=$(echo "${IPv6_INFO}" | sed -ne "s|^.*inet6\ \(.*\)/[0-9]*\ .*$|\1|p" | tail -n1) # 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 ${LINK} 2>/dev/null)" if [ "${IPv6_OLD}" != "${IPv6_CUR}" ]; then curl "${LINK}?update=${IPv6_CUR}" 2>/dev/null >/dev/null fi done fi bosixnet-1.7/src/bosixnet-daemon/update_hosts000077500000000000000000000030371260260264400215340ustar00rootroot00000000000000#!/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})" if [ ! -z "$(pidof -o %PPID -x ${SCRIPT_NAME})" ]; 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 ${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}" > /dev/null echo "${CUR_INFO}" | tee -a "${HOSTS}" > /dev/null echo "There are such data in ${HOSTS} now:" cat "${HOSTS}" bosixnet-1.7/src/bosixnet-webui/000077500000000000000000000000001260260264400167515ustar00rootroot00000000000000bosixnet-1.7/src/bosixnet-webui/CMakeLists.txt000066400000000000000000000020751260260264400215150ustar00rootroot00000000000000project (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 bosixnet-webui DESTINATION "/etc/init.d/" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) 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") bosixnet-1.7/src/bosixnet-webui/bosixnet-webui000077500000000000000000000041051260260264400216430ustar00rootroot00000000000000#!/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: 2014-02-04 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 2>/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-1.7/src/bosixnet-webui/bosixnet-webui.conf000066400000000000000000000007321260260264400225660ustar00rootroot00000000000000# Basic part of full URL on server. For example: # if full URL looks like http://ipv6.example.com/bosixnet/ # then BASIC_STR should be "/bosixnet/" or "/". #BASIC_STR=/bosixnet/ BASIC_STR=/ # Directory where generated host file 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 # Number of bosixnet-webui children to spawn #FCGI_CHILDREN=1 bosixnet-1.7/src/bosixnet-webui/bosixnet-webui.cpp000066400000000000000000000271241260260264400224270ustar00rootroot00000000000000/***************************************************************************** * * * Copyright (c) 2013-2015 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 "Version.h" using namespace std; string basic_str = "/bosixnet/"; string log_dir = "/var/tmp/bosixnet"; string conf_file = "/etc/bosixnet/bosixnet-webui.conf"; map hosts_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_hosts(); void read_hosts(); void write_hosts(); bool ends_with(const string &, const string &); bool starts_with(const string &, const string &); bool is_valid_ipv6_address(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. 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(); int counter = 0; while (FCGI_Accept() >= 0) { ++counter; string content; 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; }; string full_path = get_env_var("SCRIPT_NAME"); string path = get_env_var("SCRIPT_FULL_PATHNAME"); if (ends_with(full_path, basic_str)) { show_hosts(); } else if(ends_with(full_path, basic_str + "hosts")) { show_hosts(); } else if(ends_with(full_path, basic_str + "counter")) { stringstream counter_str; counter_str << counter; show_html("Counter: " + counter_str.str()); } else { string host_name = full_path.substr(full_path.rfind("/") + 1); string new_address = get_param(content, "update="); if (new_address.empty()) { map::iterator it = hosts_map.find(host_name); if (it != hosts_map.end()) { show_html(it->second); } else { show_html(""); } } else if(is_valid_ipv6_address(new_address)) { hosts_map[host_name] = new_address; show_html(new_address); write_hosts(); } 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 == "--basic-str") { basic_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) != '#') { var = "BASIC_STR"; tmp = get_conf_var(buff, var); if (!tmp.empty()) { basic_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\n" " -v, --version show version\n" "\n" "Options:\n" " -b , --basic-str set basic url (default: " + basic_str + ")\n" " -l , --log-dir set log directory (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: " << string(VERSION) << "\n"; } void show_html(const string &str) { printf("Content-type: text/html\n\n"); printf("%s", str.c_str()); } void show_hosts() { string log_file = log_dir + "/hosts"; string out = "File " + log_file + " is empty!"; ifstream file; file.open(log_file.c_str(), ios::in); if (file.is_open()) { out.clear(); string buff; while (!file.eof()) { getline(file, buff); out += buff + "
\n"; } file.close(); } show_html(out); } void read_hosts() { string log_file = log_dir + "/hosts"; ifstream file; file.open(log_file.c_str(), ios::in); if (file.is_open()) { string buff, host, addr; stringstream str; while (!file.eof()) { getline(file, buff); str.clear(); str << buff; str >> addr; str >> host; if (!addr.empty() && !host.empty()){ if (is_valid_ipv6_address(addr)){ hosts_map[host] = addr; } } } file.close(); } } void write_hosts() { struct stat info; if (stat(log_dir.c_str(), &info)) { if (mkdir(log_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { cout << "Directory " << log_dir << " was not created!\n"; return; } } string log_file = log_dir + "/hosts"; ofstream file; file.open(log_file.c_str(), ios::out); if (file.is_open()) { for (map::iterator it = hosts_map.begin(); it != hosts_map.end(); ++it) { file << it->second << " " << it->first << "\n"; } file.close(); } } 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) { 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; } string get_env_var(const string &var) { 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(); 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-1.7/src/bosixnet-webui/bosixnet_webui.1000066400000000000000000000027511260260264400220660ustar00rootroot00000000000000.TH "bosixnet_webui" 1 "05 Feb 2014" .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 , \-\-basic-str " Set basic url (default: /bosixnet/). .TP .BR "\-l , \-\-log-dir " Set log directory (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-1.7/src/bosixnet-webui/webui_launcher000077500000000000000000000023521260260264400216750ustar00rootroot00000000000000#!/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 to which to bind on localhost FCGIPORT=33169 # Number of children to spawn FCGI_CHILDREN=1 # 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 if user exists if ! id -u ${USERID} >/dev/null 2>&1; then echo ; echo "User ${USERID} does not exist! Check what you use the correct USERID." exit 1 fi # Check if gruop exists if ! id -g ${GROUPID} >/dev/null 2>&1; then echo ; echo "Group ${GROUPID} does not exist! Check what you use the correct GROUPID." exit 1 fi # Check the number of children for spawning [ x${FCGI_CHILDREN} = x ] && FCGI_CHILDREN=5 # Launch program if [ x${UID} = x0 ]; then EX="${SPAWNFCGI} -p ${FCGIPORT} -f ${FCGIPROGRAM} -u ${USERID} -g ${GROUPID} -C ${FCGI_CHILDREN}" else EX="${SPAWNFCGI} -p ${FCGIPORT} -f ${FCGIPROGRAM} -C ${FCGI_CHILDREN}" fi # Clean the environment and set up a new one env - ${E} ${EX} >/dev/null 2>&1