PIWan 0000755 0015532 0015531 00000010674 12155146634 010472 0 ustar paul paul #!/bin/bash # Start/stop the PIWan configuration # ### BEGIN INIT INFO # Provides: PIWan # Required-Start: $network # Required-Stop: $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Configuration script for PIWan tool # Description: PIWan is a simple script to configure latency and bandwidth # limitation between two interfaces. ### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin DESC="PIWan" NAME=PIWan DAEMON="" PIDFILE=/var/run/PIWan.pid SCRIPTNAME=/etc/init.d/"$NAME" if [ "$1" == "stop" ] ; then exit 0 fi # PIWan_script LOCAL_IP=192.168.9.254 LOCAL_NET=192.168.9 LOCAL_MASK=255.255.255.0 DEBUG=1 print_debug() { if [ "${DEBUG}" -eq 1 ] ; then echo [Debug] $* fi } # check wan port configuration and extract information if ! ifconfig eth0 | grep inet > /dev/null &>2 ; then echo "WAN Interface configuration invalid. make sure DHCP is started" exit 1 fi WAN_IP=`ifconfig eth0 | grep inet | tr -s " " | cut -d ":" -f 2 | cut -d " " -f 1` print_debug "Wan IP is : ${WAN_IP}" # configure eth1 as static address if ! ifconfig eth1 >/dev/null &>2 ; then echo "LAN Inteface configuration impossible. make sure USB adapter is connected" exit 1 fi ifconfig eth1 ${LOCAL_IP} netmask ${LOCAL_MASK} up print_debug "Lan IP : `ifconfig eth1 | grep inet` " # configure routing & nating sysctl -w net.ipv4.ip_forward=1 >/dev/null &>2 print_debug "Routing status : `sysctl net.ipv4.ip_forward`" iptables -t nat -A POSTROUTING --out-interface eth0 -j MASQUERADE iptables --append FORWARD --in-interface eth0 -j ACCEPT print_debug "Nating status : done" # configure dhcp and dns masking if [ ! -f /etc/dnsmasq.conf ] ; then apt-get -y install dnsmasq fi if ! cat /etc/dnsmasq.conf | grep ^interface 2>/dev/null &>2 ; then echo "interface=eth1" >> /etc/dnsmasq.conf echo "dhcp-range=eth1,${LOCAL_NET}.1,${LOCAL_NET}.10,255.255.255.0,4h" >> /etc/dnsmasq.conf echo "dhcp-option=option:router,${LOCAL_IP}" >> /etc/dnsmasq.conf print_debug "DNSMASQ configuration added" fi /etc/init.d/dnsmasq restart # configure httpd if [ ! -d /etc/lighttpd ] ; then print_debug "Install Lighttpd server" apt-get -y install lighttpd lighty-enable-mod cgi ln -s /usr/lib/cgi-bin /var/www/ /etc/init.d/lighttpd force-reload else print_debug "Restart lighttpd server" /etc/init.d/lighttpd restart fi if [ ! -f /var/www/index.html ] ; then print_debug "Installing index.html" ( echo '