#!/bin/sh DAEMON=cpmaccfg . /etc/init.d/modlibrc start() { # include environment [ -r /var/env.cache ] && . /var/env.cache BOXTYPE=${CONFIG_PRODUKT#Fritz_Box_} [ -z "$BOXTYPE" ] && echo "Warning: boxtype not recognized" if [ "$BOXTYPE" = "7170" ];then echo 'Setting Ports ...' # Port Mode /sbin/$DAEMON spm 1 $CPMACCFG_MODE1 /sbin/$DAEMON spm 2 $CPMACCFG_MODE2 /sbin/$DAEMON spm 3 $CPMACCFG_MODE3 /sbin/$DAEMON spm 4 $CPMACCFG_MODE4 # Port Settings /sbin/$DAEMON spme 1 $CPMACCFG_SPEED1 $CPMACCFG_FLOW1 /sbin/$DAEMON spme 2 $CPMACCFG_SPEED2 $CPMACCFG_FLOW2 /sbin/$DAEMON spme 3 $CPMACCFG_SPEED3 $CPMACCFG_FLOW3 /sbin/$DAEMON spme 4 $CPMACCFG_SPEED4 $CPMACCFG_FLOW4 fi # VLAN Settings vlan # IP Adressen setzen ethernet # WLAN Settings wlan exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } vlan() { d_eth0=32 d_eth1=32 d_eth2=32 d_eth3=32 if [ $CPMACCFG_VLAN1 = "eth0" ]; then let d_eth0++; fi if [ $CPMACCFG_VLAN1 = "eth1" ]; then let d_eth1++; fi if [ $CPMACCFG_VLAN1 = "eth2" ]; then let d_eth2++; fi if [ $CPMACCFG_VLAN1 = "eth3" ]; then let d_eth3++; fi if [ $CPMACCFG_VLAN2 = "eth0" ]; then let d_eth0+=2; fi if [ $CPMACCFG_VLAN2 = "eth1" ]; then let d_eth1+=2; fi if [ $CPMACCFG_VLAN2 = "eth2" ]; then let d_eth2+=2; fi if [ $CPMACCFG_VLAN2 = "eth3" ]; then let d_eth3+=2; fi if [ $CPMACCFG_VLAN3 = "eth0" ]; then let d_eth0+=4; fi if [ $CPMACCFG_VLAN3 = "eth1" ]; then let d_eth1+=4; fi if [ $CPMACCFG_VLAN3 = "eth2" ]; then let d_eth2+=4; fi if [ $CPMACCFG_VLAN3 = "eth3" ]; then let d_eth3+=4; fi if [ $CPMACCFG_VLAN4 = "eth0" ]; then let d_eth0+=8; fi if [ $CPMACCFG_VLAN4 = "eth1" ]; then let d_eth1+=8; fi if [ $CPMACCFG_VLAN4 = "eth2" ]; then let d_eth2+=8; fi if [ $CPMACCFG_VLAN4 = "eth3" ]; then let d_eth3+=8; fi h_eth0='0x'$(printf "%X" $d_eth0) h_eth1='0x'$(printf "%X" $d_eth1) h_eth2='0x'$(printf "%X" $d_eth2) h_eth3='0x'$(printf "%X" $d_eth3) if [ "$h_eth0" != "0x20" ]; then SpecialMode='eth0 '$h_eth0 fi if [ "$h_eth1" != "0x20" ]; then SpecialMode=$SpecialMode' eth1 '$h_eth1 fi if [ "$h_eth2" != "0x20" ]; then SpecialMode=$SpecialMode' eth2 '$h_eth2 fi if [ "$h_eth3" != "0x20" ]; then SpecialMode=$SpecialMode' eth3 '$h_eth3 fi if [ "$h_eth0" != "0x2F" ]; then ifconfig eth3 down 2>/dev/null ifconfig eth2 down 2>/dev/null ifconfig eth1 down 2>/dev/null sleep 2 echo 'VLAN Settings ...' echo "/sbin/$DAEMON ssms $SpecialMode ..." /sbin/$DAEMON ssms $SpecialMode /sbin/$DAEMON ssm special else /sbin/$DAEMON ssm normal fi } wlan () { ETHERMODE=$(echo 'ar7cfg.ethmode' | ar7cfgctl -s) if [ $ETHERMODE = "ethmode_router" ]; then echo -n 'Setting WLAN to '$CPMACCFG_WLAN echo '' brctl addif wlan $CPMACCFG_WLAN else echo -n 'Skipping WLAN bridge-settings. WLAN is bridged in AVM webinterface' echo '' fi } ipv4bcast () { local IP1=${1%%.*.*.*} local IP2=${1#*.}; IP2=${IP2%%.*.*} local IP3=${1#*.*.}; IP3=${IP3%%.*} local IP4=${1#*.*.*.} local NM1=${2%%.*.*.*} local NM2=${2#*.}; NM2=${NM2%%.*.*} local NM3=${2#*.*.}; NM3=${NM3%%.*} local NM4=${2#*.*.*.} local IIP=$(($IP1 << 24 | $IP2 << 16 | $IP3 << 8 | $IP4)) local INM=$(($NM1 << 24 | $NM2 << 16 | $NM3 << 8 | $NM4)) local IBC=$((${IIP} | ~${INM})) printf "%u.%u.%u.%u" $((${IBC} >> 24 & 0xFF)) $((${IBC} >> 16 & 0xFF)) \ $((${IBC} >> 8 & 0xFF)) $((${IBC} & 0xFF)) } ethernet() { if [ -n "$CPMACCFG_ETH1_IP" ]; then if [ "$h_eth1" != "0x20" ]; then BROADCAST=$(ipv4bcast $CPMACCFG_ETH1_IP $CPMACCFG_ETH1_SUBNET) echo "ifconfig eth1 $CPMACCFG_ETH1_IP netmask $CPMACCFG_ETH1_SUBNET broadcast $BROADCAST up" ifconfig eth1 $CPMACCFG_ETH1_IP netmask $CPMACCFG_ETH1_SUBNET broadcast $BROADCAST up fi fi if [ -n "$CPMACCFG_ETH2_IP" ]; then if [ "$h_eth2" != "0x20" ]; then BROADCAST=$(ipv4bcast $CPMACCFG_ETH2_IP $CPMACCFG_ETH2_SUBNET) echo "ifconfig eth2 $CPMACCFG_ETH2_IP netmask $CPMACCFG_ETH2_SUBNET broadcast $BROADCAST up" ifconfig eth2 $CPMACCFG_ETH2_IP netmask $CPMACCFG_ETH2_SUBNET broadcast $BROADCAST up fi fi if [ -n "$CPMACCFG_ETH3_IP" ]; then if [ "$h_eth3" != "0x20" ]; then BROADCAST=$(ipv4bcast $CPMACCFG_ETH3_IP $CPMACCFG_ETH3_SUBNET) echo "ifconfig eth3 $CPMACCFG_ETH3_IP netmask $CPMACCFG_ETH3_SUBNET broadcast $BROADCAST up" ifconfig eth3 $CPMACCFG_ETH3_IP netmask $CPMACCFG_ETH3_SUBNET broadcast $BROADCAST up fi fi } case $1 in ""|load) modreg cgi 'cpmaccfg' 'Cpmaccfg' modreg daemon --hide cpmaccfg modlib_start $CPMACCFG_ENABLED ;; unload) modunreg cgi 'cpmaccfg' modunreg daemon cpmaccfg ;; start) start ;; stop) ;; restart) start ;; status) ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0