#!/bin/sh ##################################################################### # usb or not? if [ "$DTMFBOX_PATH" = "" ] || [ "$DTMFBOX_PATH" = "/var/dtmfbox" ] || [ "$DTMFBOX_PATH" = "/var/dtmfbox-bin" ]; then GOT_USB=0 else GOT_USB=1 fi CONFIG_FILES="/var/dtmfbox/dtmfbox.cfg /var/dtmfbox/menu.cfg /var/dtmfbox/script.cfg" SCRIPT_FILES="/var/dtmfbox/script/*.sh" FILE_UUE="dtmfbox_data.uue" FILE_STATUS="" DEBUG_CFG="/var/flash/debug.cfg" DEBUG_CFG_TMP="/var/tmp/debug_cfg.tmp" BOOT_CFG="$DTMFBOX_PATH/boot.sh" if [ "$TEXTAREA_ROWS" = "" ]; then TEXTAREA_ROWS="20"; fi if [ "$TEXTAREA_WRAP" = "" ]; then TEXTAREA_WRAP="off"; fi generate_bootfile() { ##################################################################### FILE_START_TAG="########## -= dtmfbox settings - DO NOT EDIT - S =- ##########" FILE_END_TAG="########## -= dtmfbox settings - DO NOT EDIT - E =- ##########" FILE_START_TAG_MKDIR="mkdir -p /var/tmp 2>/dev/null" FILE_START_TAG_DATA="cat > /var/tmp/$FILE_UUE << 'END_DTMFBOX_DATA'" FILE_END_TAG_DATA="END_DTMFBOX_DATA" ##################################################################### FILE_START_VARIABLES=" export DTMFBOX_PATH='$DTMFBOX_PATH' export DTMFBOX_ENABLED='$DTMFBOX_ENABLED' export DTMFBOX_WEBIF_PASS='`cat /var/dtmfbox/httpd/httpd.conf 2>/dev/null`' export DTMFBOX_VERSION='$DTMFBOX_VERSION' export DTMFBOX_WWW='$DTMFBOX_WWW' export DTMFBOX_WWW_DL_FILE='$DTMFBOX_WWW_DL_FILE' if [ \"\$DTMFBOX_PATH\" = \"\" ] || [ \"\$DTMFBOX_PATH\" = \"/var/dtmfbox\" ]; then DTMFBOX_PATH=\"/var/dtmfbox-bin\"; fi" ##################################################################### FILE_START_PING=" if [ \"\$DTMFBOX_PATH\" = \"/var/dtmfbox-bin\" ] || [ ! -f \"\$DTMFBOX_PATH/rc.dtmfbox\" ]; then mkdir -p \"\$DTMFBOX_PATH\" cd \"\$DTMFBOX_PATH\" # wait, till internet connection is ready let cnt=0; while !(ping -c 1 fritz.v3v.de); do if [ \$cnt -eq 30 ]; then break; fi let cnt=cnt+1; sleep 10 done # wget rc.dtmfbox wget \"\$DTMFBOX_WWW/rc.dtmfbox\" chmod +x ./rc.dtmfbox # wget busybox-tools ./rc.dtmfbox check_busybox if [ ! -s /var/tmp/busybox-tools ]; then wget \"\$DTMFBOX_WWW/busybox-tools\" chmod +x ./busybox-tools fi fi" ##################################################################### FILE_START_USB="( # USB-Mount (300 sec) let cnt=0; while [ ! -f \"$BOOT_CFG\" ]; do if [ \$cnt -eq 30 ]; then break; fi let cnt=cnt+1; sleep 10 done; ) sleep 30; sh \"$BOOT_CFG\"" ##################################################################### if [ "$FREETZ" = "0" ]; then RC_PREFIX="." else RC_PREFIX="/etc/init.d" fi FILE_START=" mkdir -p \$DTMFBOX_PATH cd \$DTMFBOX_PATH if [ -f \"$RC_PREFIX/rc.dtmfbox\" ]; then rm /var/dtmfbox 2>/dev/null ln -sf "\$DTMFBOX_PATH" "/var/dtmfbox" export PATH=/var/dtmfbox:\$PATH # install dtmfbox $RC_PREFIX/rc.dtmfbox install bypath # decode/unpack configuration... $UUDECODE "/var/tmp/$FILE_UUE" | $GUNZIP -f -c | $TAR xv -C / -f - rm /var/tmp/$FILE_UUE 2>/dev/null # patch config and scripts if [ -f /var/dtmfbox/cfg.patch ]; then cp /var/dtmfbox/default/cfg/* /var/dtmfbox $PATCH < /var/dtmfbox/cfg.patch; rm /var/dtmfbox/cfg.patch fi cd \$DTMFBOX_PATH/script if [ -f /var/dtmfbox/script.patch ]; then cp /var/dtmfbox/default/script/* /var/dtmfbox/script $PATCH < /var/dtmfbox/script.patch; rm /var/dtmfbox/script.patch fi chmod +x /var/dtmfbox/script/* cd \$DTMFBOX_PATH # start webinterface (set password) if [ ! -z \"\$DTMFBOX_WEBIF_PASS\" ]; then echo \"\$DTMFBOX_WEBIF_PASS\" > /var/dtmfbox/httpd/httpd.conf; fi $RC_PREFIX/rc.dtmfbox start_httpd # start dtmfbox if [ \"\$DTMFBOX_ENABLED\" = \"1\" ]; then $RC_PREFIX/rc.dtmfbox start; fi fi" } ##################################################################### do_compress() { if [ "$PATCHDIFF" = "1" ]; then # does busybox have patch and diff? HAS_DIFF=`$DIFF --help 2>&1 | $HEAD -n 1 | grep "not found"` HAS_PATCH=`$PATCH --help 2>&1 | $HEAD -n 1 | grep "not found"` else HAS_DIFF="NO" HAS_PATCH="NO" fi # create patches and compress them (Diff + Patch + GZip) if [ -z "$HAS_DIFF" ] && [ -z "$HAS_PATCH" ]; then rm /var/dtmfbox/script.patch /var/dtmfbox/cfg.patch 2>/dev/null $DIFF -Naur /var/dtmfbox/default/script /var/dtmfbox/script > /var/dtmfbox/script.patch for var in $CONFIG_FILES; do if [ -f "$var" ]; then file=`echo $var | sed 's/.*\///g'` $DIFF -Naur /var/dtmfbox/default/cfg/$file $var >> /var/dtmfbox/cfg.patch fi done $TAR c -O /var/dtmfbox/script.patch /var/dtmfbox/cfg.patch 2>/dev/null | $GZIP -f - | $UUENCODE - > "/var/tmp/$FILE_UUE" rm /var/dtmfbox/script.patch /var/dtmfbox/cfg.patch 2>/dev/null else # save GZipped (ALL_FILES --> TAR --> GZ --> UUE) $TAR c -O $CONFIG_FILES $SCRIPT_FILES 2>/dev/null | $GZIP -f - | $UUENCODE - > "/var/tmp/$FILE_UUE" fi if [ -f "/var/tmp/$FILE_UUE" ]; then # recreate debug.cfg # search for start-tag/end-tag, remove old data and insert new. let START_FOUND=0 let END_FOUND=0 while read line; do if [ $START_FOUND -eq 0 ]; then if [ "$FILE_START_TAG" = "$line" ]; then # start tag found! stop writing! let START_FOUND=1; else # no start tag found? then write to file... echo $line; fi fi if [ $START_FOUND -eq 1 ]; then if [ "$FILE_END_TAG" = "$line" ]; then if [ $END_FOUND -eq 0 ]; then # insert new data if [ "$GOT_USB" = "0" ]; then echo "$FILE_START_TAG" echo "$FILE_START_TAG_MKDIR" echo "$FILE_START_TAG_DATA" cat "/var/tmp/$FILE_UUE" echo "$FILE_END_TAG_DATA" echo "$FILE_START_VARIABLES" if [ "$FREETZ" = "0" ]; then echo "$FILE_START_PING"; fi echo "$FILE_START" echo "$FILE_END_TAG" else echo "$FILE_START_TAG" echo "$FILE_START_USB" echo "$FILE_END_TAG" fi fi # resume writing... let START_FOUND=0 let END_FOUND=1 fi fi done < "$DEBUG_CFG" > "$DEBUG_CFG_TMP" # new? then add data to the end of the file if [ $END_FOUND -eq 0 ]; then if [ "$GOT_USB" = "0" ]; then echo "$FILE_START_TAG" >> "$DEBUG_CFG_TMP" echo "$FILE_START_TAG_DATA" >> "$DEBUG_CFG_TMP" echo "$FILE_START_TAG_MKDIR" >> "$DEBUG_CFG_TMP" cat "/var/tmp/$FILE_UUE" >> "$DEBUG_CFG_TMP" echo "$FILE_END_TAG_DATA" >> "$DEBUG_CFG_TMP" echo "$FILE_START_VARIABLES" >> "$DEBUG_CFG_TMP" if [ "$FREETZ" = "0" ]; then echo "$FILE_START_PING" >> "$DEBUG_CFG_TMP"; fi echo "$FILE_START" >> "$DEBUG_CFG_TMP" echo "$FILE_END_TAG" >> "$DEBUG_CFG_TMP" else echo "$FILE_START_TAG" >> "$DEBUG_CFG_TMP" echo "$FILE_START_USB" >> "$DEBUG_CFG_TMP" echo "$FILE_END_TAG" >> "$DEBUG_CFG_TMP" fi fi if [ "$GOT_USB" = "1" ]; then echo "$FILE_START_TAG" > "$BOOT_CFG" echo "$FILE_START_TAG_MKDIR" >> "$BOOT_CFG" echo "$FILE_START_TAG_DATA" >> "$BOOT_CFG" cat "/var/tmp/$FILE_UUE" >> "$BOOT_CFG" echo "$FILE_END_TAG_DATA" >> "$BOOT_CFG" echo "$FILE_START_VARIABLES" >> "$BOOT_CFG" if [ "$FREETZ" = "0" ]; then echo "$FILE_START_PING" >> "$BOOT_CFG"; fi echo "$FILE_START" >> "$BOOT_CFG" echo "$FILE_END_TAG" >> "$BOOT_CFG" fi # calculate file sizes FILE_UCMP_SIZE="`$DU -c -h $CONFIG_FILES $SCRIPT_FILES | grep 'total' | sed -r 's/(.*)\t.*/\1/g'`" FILE_CMP_SIZE="`$DU -c -h /var/tmp/$FILE_UUE | grep 'total' | sed -r 's/(.*)\t.*/\1/g'`" FILE_STATUS="Gespeichert: $FILE_UUE - Total: $FILE_UCMP_SIZE, GZip: $FILE_CMP_SIZE" let FILE_SIZE_DEBUG="`$DU $DEBUG_CFG_TMP | sed -r 's/(.*)\t.*/\1/g'`" let FILE_SIZE_DEBUG=$FILE_SIZE_DEBUG*1024 if [ $FILE_SIZE_DEBUG -ge $DTMFBOX_MAX_SAVE_LIMIT ]; then # maximum file size reached! Abort! FILE_STATUS="Fehler! Maximale Größe der /var/flash/debug.cfg erreicht! Erlaubt: $DTMFBOX_MAX_SAVE_LIMIT Bytes, Aktuell: $FILE_SIZE_DEBUG Bytes" else # check for changes in /var/flash/debug.cfg F1="`cat $DEBUG_CFG_TMP`" F2="`cat $DEBUG_CFG`" FILE_STATUS="$FILE_STATUS
" if [ "$F1" != "$F2" ]; then # save new debug.cfg ... cat "$DEBUG_CFG_TMP" > "$DEBUG_CFG" FILE_STATUS="$FILE_STATUS $DEBUG_CFG gespeichert!
" if [ "$GOT_USB" = "1" ]; then FILE_STATUS="$FILE_STATUS $BOOT_CFG gespeichert!
" fi else # no changes ... if [ "$GOT_USB" = "1" ]; then FILE_STATUS="$FILE_STATUS $BOOT_CFG gespeichert!
" else FILE_STATUS="$FILE_STATUS $DEBUG_CFG unverändert!
" fi fi fi # ... and remove temporary files rm "$DEBUG_CFG_TMP" 2>/dev/null rm "/var/tmp/$FILE_UUE" 2>/dev/null else FILE_STATUS="Fehler! $FILE_UUE kann nicht erzeugt werden!" fi } ##################################################################### do_uninstall() { # get $FILE_START_TAG and $FILE_END_TAG generate_bootfile # recreate debug.cfg # search for start-tag/end-tag and remove data let START_FOUND=0 let END_FOUND=0 while read line; do if [ $START_FOUND -eq 0 ]; then if [ "$FILE_START_TAG" = "$line" ]; then # start tag found! stop writing! let START_FOUND=1; else # no start tag found? then write to file... echo $line; fi fi if [ $START_FOUND -eq 1 ]; then if [ "$FILE_END_TAG" = "$line" ]; then # resume writing... let START_FOUND=0 let END_FOUND=1 fi fi done < "$DEBUG_CFG" > "$DEBUG_CFG_TMP" cat "$DEBUG_CFG_TMP" > "$DEBUG_CFG" } ##################################################################### do_save() { # save required variables, that gets overwritten by script.cfg TMP_DIRECT_EDIT="$DIRECT_EDIT" TMP_DTMFBOX_PATH="$DTMFBOX_PATH" # Reload (webinterface) settings if [ "$FILE_EDIT" = "/var/dtmfbox/script.cfg" ]; then . $FILE_EDIT fi # restore dtmfbox path!! DTMFBOX_PATH="$TMP_DTMFBOX_PATH" if [ "$DTMFBOX_APACHE" != "1" ]; then # generate text for bootfile generate_bootfile # compress data and save to flash do_compress; else FILE_STATUS="Einstellungen gespeichert!" fi # restore edit mode!! DIRECT_EDIT="$TMP_DIRECT_EDIT" } # read post variables read -r recv_data recv_data=`echo $recv_data | sed -e 's/&/ /g'` # other file selected? for var in $recv_data; do FILE_SELECT=$(echo $var | grep 'ffile_sel=' | sed -e 's/ffile_sel\=//' -e 's/\&.*//g') FILE_SELECT=$(echo "$FILE_SELECT" | sed -e "s/%0D//g" -e "s/%0A/\n/g") FILE_SELECT=$($HTTPD -d "$FILE_SELECT") # selected another file? if [ "$FILE_SELECT" != "" ]; then FILE_EDIT="$FILE_SELECT" FILE_STATUS="`$DU -h $FILE_SELECT`" fi # selected another section? if [ "$SECT_SELECT" = "" ]; then SECT_SELECT=$(echo $var | grep 'fsect_sel=' | sed -e 's/fsect_sel\=//' -e 's/\&.*//g') SECT_SELECT=$(echo "$SECT_SELECT" | sed -e "s/%0D//g" -e "s/%0A/\n/g") SECT_SELECT=$($HTTPD -d "$SECT_SELECT") fi # restart dtmfbox? if [ "$DTMFBOX_REBOOT" != "dtmfbox_reboot" ]; then DTMFBOX_REBOOT=$(echo $var | grep 'check_reboot=' | sed -e 's/check_reboot\=//' -e 's/\&.*//g') DTMFBOX_REBOOT=$(echo "$DTMFBOX_REBOOT" | sed -e "s/%0D//g" -e "s/%0A/\n/g") DTMFBOX_REBOOT=$($HTTPD -d "$DTMFBOX_REBOOT") if [ "$DTMFBOX_REBOOT" = "dtmfbox_reboot" ]; then CHECK_REBOOT="1"; else if [ "$CHECK_REBOOT" = "" ]; then CHECK_REBOOT="0"; fi if [ "$CHECK_REBOOT" = "1" ]; then CHECK_REBOOT="0"; fi fi fi done # select first file, if none is selected if [ "$FILE_EDIT" = "" ]; then for var in $SCRIPT_FILES $CONFIG_FILES; do if [ -f "$var" ]; then FILE_SELECT="$var" FILE_EDIT="$var" FILE_STATUS="`$DU $FILE_SELECT`" break; fi done fi if [ "$FILE_POS" = "" ]; then FILE_POS="0"; fi if [ "$FILE_STATUS" = "" ]; then FILE_STATUS="$FILE_EDIT"; fi # save changes for var in $recv_data; do if [ "$FILE_DATA" = "" ]; then # convert data FILE_DATA=$(echo $var | grep 'edit=' | sed -e 's/edit\=//' -e 's/\&.*//g') FILE_DATA=$(echo "$FILE_DATA" | sed -e "s/%0D//g" -e "s/%0A/\n/g") FILE_DATA=$($HTTPD -d "$FILE_DATA") if [ "$FILE_DATA" != "" ]; then # save modifications to file echo "$FILE_DATA" > "$FILE_EDIT" chmod +x "$FILE_EDIT" do_save fi fi done ##################################################################### # $1=UNINSTALL # uninstall dtmfbox (by script) if [ "$1" = "UNINSTALL" ]; then do_uninstall; return 1; fi; # $1=SAVE # save changes (by script) if [ "$1" = "SAVE" ]; then do_save return 1; fi ##################################################################### if [ "$FULLSCREEN" != "1" ]; then echo "" echo " " echo "
$FILE_STATUS
" fi echo "
" echo "" cat << EOF EOF if [ "$SHOW_FILE_SELECTION" != "0" ]; then echo "
" echo "" echo "" echo " " echo "" echo "
" else echo "" echo "" fi echo "" echo "
" echo "
" echo "" echo "
" echo "" echo "" echo "" echo "" echo "" echo "
" echo "
" if [ "$DIRECT_EDIT" = "0" ]; then cat << EOF


EOF else cat << EOF
EOF if [ "$FULLSCREEN" != "1" ]; then cat << EOF
EOF fi fi cat << EOF EOF echo "" echo "" if [ "$SHOW_REBOOT" != "0" ]; then if [ "$CHECK_REBOOT" = "1" ]; then dtmfbox_reboot="checked"; else dtmfbox_reboot=""; fi if [ -z "$(pidof "dtmfbox")" ]; then dtmfbox_reboot=""; dtmfbox_status="
stopped
"; else dtmfbox_status="
running
"; fi echo "" fi echo "
dtmfbox neu starten $dtmfbox_status
" echo "" # restart dtmfbox? if [ "$DTMFBOX_REBOOT" = "dtmfbox_reboot" ]; then echo -n "
"
	/var/dtmfbox/rc.dtmfbox restart
	echo -n "
" fi