#!/bin/sh
# &fullscreen=
if [ "${QUERY_STRING}" != "" ] && [ "$FULLSCREEN" = "" ]; then
FULLSCREEN=`echo ${QUERY_STRING} | sed -n 's/.*fullscreen=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
head_begin
PAGE=""
HELPPAGE=""
RESET=""
WEBIFPASS=""
NEWPATH=""
START=""
DELETE=""
RUN_CMD=""
CLOSE_CMD=""
FILE_SEL=""
# read get variables
if [ "${QUERY_STRING}" != "" ]; then
# &page=
if [ "$PAGE" = "" ]; then
PAGE=`echo ${QUERY_STRING} | sed -n 's/.*page=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
# &help=
if [ "$HELPPAGE" = "" ]; then
HELPPAGE=`echo ${QUERY_STRING} | sed -n 's/.*help=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
# &direct_edit=
_DIRECT_EDIT=`echo ${QUERY_STRING} | sed -n 's/.*direct_edit=\(.*\)/\1/p' | sed -e 's/&.*//g'`
if [ ! -z "$_DIRECT_EDIT" ]; then DIRECT_EDIT="$_DIRECT_EDIT"; fi
# &new_patht=
if [ "$NEWPATH" = "" ]; then
NEWPATH=$($HTTPD -d "`echo ${QUERY_STRING} | sed -n 's/.*new_path=\(.*\)/\1/p' | sed -e 's/&.*//g'`")
fi
# &webifpass=
if [ "$WEBIFPASS" = "" ]; then
WEBIFPASS=$($HTTPD -d "`echo ${QUERY_STRING} | sed -n 's/.*webifpass=\(.*\)/\1/p' | sed -e 's/&.*//g'`")
fi
# &new_path=
if [ "$NEWPATH" = "" ]; then
NEWPATH=$($HTTPD -d "`echo ${QUERY_STRING} | sed -n 's/.*new_path=\(.*\)/\1/p' | sed -e 's/&.*//g'`")
fi
# &reset=
if [ "$RESET" = "" ]; then
RESET=`echo ${QUERY_STRING} | sed -n 's/.*reset_type=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
if [ "$RESET" != "" ]; then
if [ "$RESET" = "path" ];
then
show_title "Pfad ändern"
# stop dtmfbox
/var/dtmfbox/rc.dtmfbox stop
# No path? Then install to /var/dtmfbox-bin
if [ "$NEWPATH" = "" ] || [ "$NEWPATH" = "/var/dtmfbox" ]; then
NEWPATH="/var/dtmfbox-bin"
fi
echo "
"
echo "Pfad wird auf \"$NEWPATH\" geändert.
"
echo "Bitte warten, bis alle Dateien kopiert wurden...
"
if [ "$DTMFBOX_PATH" = "$NEWPATH" ]; then
echo "Hinweis: Alter und neuer Pfad nicht unterschiedlich!
"
echo "
Abgebrochen!"
head_end
return 1;
fi
echo -n "
"
# Copy required files to new path
mkdir -p $NEWPATH
if [ "$FREETZ" = "0" ];
then
# Copy the current files (minimum)
cp -Rf /var/dtmfbox/rc.dtmfbox $NEWPATH
cp -Rf /var/dtmfbox/dtmfbox $NEWPATH
cp -Rf /var/dtmfbox/busybox-tools $NEWPATH
cp -Rf /var/dtmfbox/script $NEWPATH
cp -Rf /var/dtmfbox/httpd $NEWPATH
cp -Rf /var/dtmfbox/default $NEWPATH
cp -Rf /var/dtmfbox/*.so $NEWPATH
cp -Rf /var/dtmfbox/*.cfg $NEWPATH
# USB? Then copy all files (including recordings)...
if [ "$NEWPATH" != "/var/dtmfbox-bin" ]; then
cp -Rf /var/dtmfbox/* $NEWPATH
fi
fi
# Save config
export DTMFBOX_PATH="$NEWPATH" # Export new pathname
rm /var/dtmfbox # Remove link dir
if [ "$FREETZ" = "0" ]; then
$DTMFBOX_PATH/rc.dtmfbox check_busybox # Relink busybox
$DTMFBOX_PATH/rc.dtmfbox install bypath # Reinstall dtmfbox (USB/RAM)
else
/etc/init.d/rc.dtmfbox install bypath # Reinstall dtmfbox (FREETZ)
fi
echo -n "
"
show_page "dtmfbox_scriptedit.cgi" "SAVE" # Save config (change debug.cfg)
# Finished!
echo "
Fertig!"
head_end
return 1;
fi
if [ "$RESET" = "reset" ];
then
show_title "Die Konfiguration wird zurückgesetzt..."
echo -n ""
/var/dtmfbox/rc.dtmfbox defaults
echo -n "
Fertig!"
head_end
return 1;
fi
if [ "$RESET" = "uninstall" ];
then
show_page "dtmfbox_scriptedit.cgi" "UNINSTALL"
show_title "dtmfbox deinstallieren..."
# stop dtmfbox
/var/dtmfbox/rc.dtmfbox stop >/dev/null
# remove entry from /var/flash/debug.cfg
/var/dtmfbox/rc.dtmfbox uninstall
rm /var/dtmfbox
echo "
Fertig!"
head_end
return 1;
fi
if [ "$RESET" = "password" ];
then
if [ ! -z "$WEBIFPASS" ];
then
# save pass to httpd.conf
WEBIFPASS_ENC="/:admin:`$HTTPD -m $WEBIFPASS`"
echo "$WEBIFPASS_ENC" > /var/dtmfbox/httpd/httpd.conf
else
rm /var/dtmfbox/httpd/httpd.conf
fi
show_page "dtmfbox_scriptedit.cgi" "SAVE"
echo "<< zurück zur Statusseite..."
# reload httpd configuration
kill -1 0
sleep 1
return 1;
fi
fi
# &delete=true
if [ "$DELETE" = "" ]; then
DELETE=`echo ${QUERY_STRING} | sed -n 's/.*delete=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
if [ "$DELETE" = "true" ]; then
# read security PID for runcmd!
if [ -f /var/dtmfbox/tmp/webinterface.pid ];
then
SEC_PID1=`echo ${QUERY_STRING} | sed -n 's/.*pid=\(.*\)/\1/p' | sed -e 's/&.*//g'`
SEC_PID2=`cat /var/dtmfbox/tmp/webinterface.pid`
# both PIDs equal? Then run!
if [ "$SEC_PID1" = "$SEC_PID2" ];
then
if [ "$CMD_LOCAL" = "" ]; then
CMD_LOCAL=`echo ${QUERY_STRING} | sed -n 's/.*cmd_local=\(.*\)/\1/p' | sed -e 's/&.*//g'`
CMD_LOCAL=$($HTTPD -d "$CMD_LOCAL")
echo "$CMD_LOCAL" > /var/dtmfbox/tmp/dtmfbox_delete_local.sh
chmod +x /var/dtmfbox/tmp/dtmfbox_delete_local.sh
. /var/dtmfbox/tmp/dtmfbox_delete_local.sh
rm /var/dtmfbox/tmp/dtmfbox_delete_local.sh
fi
if [ "$CMD_REMOTE" = "" ]; then
CMD_REMOTE=`echo ${QUERY_STRING} | sed -n 's/.*cmd_remote=\(.*\)/\1/p' | sed -e 's/&.*//g'`
CMD_REMOTE=$($HTTPD -d "$CMD_REMOTE")
echo "$CMD_REMOTE" > /var/dtmfbox/tmp/dtmfbox_delete_ftp.sh
chmod +x /var/dtmfbox/tmp/dtmfbox_delete_ftp.sh
echo ""
. /var/dtmfbox/tmp/dtmfbox_delete_ftp.sh
echo "
"
rm /var/dtmfbox/tmp/dtmfbox_delete_ftp.sh
fi
fi
fi
fi
# &start=
if [ "$START" = "" ]; then
START=`echo ${QUERY_STRING} | sed -n 's/.*start=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
if [ "$START" != "" ];
then
# Daemon starten
if [ "$START" = "daemon" ];
then
/var/dtmfbox/rc.dtmfbox restart > /dev/null
fi
# Daemon geloggt starten
if [ "$START" = "logged" ];
then
/var/dtmfbox/rc.dtmfbox stop >/dev/null
rm /var/dtmfbox/tmp/dtmfbox.log 2>/dev/null
/var/dtmfbox/rc.dtmfbox log >/dev/null
touch /var/dtmfbox/tmp/dtmfbox.log
fi
# Daemon stoppen
if [ "$START" = "stop" ];
then
/var/dtmfbox/rc.dtmfbox stop >/dev/null
fi
# Fritzbox rebooten
if [ "$START" = "reboot" ];
then
echo "Reboot wird durchgeführt...
"
echo ""
reboot
return 1;
fi
fi
# &close=
if [ "$CLOSE_CMD" = "" ]; then
CLOSE_CMD=`echo ${QUERY_STRING} | sed -n 's/.*close=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
# &run_cmd=
if [ "$RUN_CMD" = "" ]; then
RUN_CMD=`echo ${QUERY_STRING} | sed -n 's/.*run_cmd=\(.*\)/\1/p' | sed -e 's/&.*//g'`
fi
if [ "$RUN_CMD" != "" ];
then
# read security PID for runcmd!
if [ -f /var/dtmfbox/tmp/webinterface.pid ];
then
SEC_PID1=`echo ${QUERY_STRING} | sed -n 's/.*pid=\(.*\)/\1/p' | sed -e 's/&.*//g'`
SEC_PID2=`cat /var/dtmfbox/tmp/webinterface.pid`
# both PIDs equal? Then run!
if [ "$SEC_PID1" = "$SEC_PID2" ];
then
RUN_CMD=$($HTTPD -d "$RUN_CMD")
$RUN_CMD >/dev/null 2>/dev/null
if [ "$CLOSE_CMD" = "1" ];
then
echo "Fenster wird geschlossen! Bitte warten..."
echo ""
exit 1;
fi
fi
fi
fi
fi
if [ "$PAGE" = "" ]; then PAGE="status"; fi
# returns am-messages to $status_recordings (as links)
get_am_messages() {
. /var/dtmfbox/script/funcs.sh
status_recordings=""
let tmp_acc_no=$DTMFBOX_MAX_ACCOUNTS;
while [ $tmp_acc_no -ge 1 ];
do
let msg_cnt=0;
for file in `find $DTMFBOX_PATH/record/${tmp_acc_no}/* 2>/dev/null`
do
if [ ! -d $file ]; then
let msg_cnt=msg_cnt+1
fi
done
if [ "$msg_cnt" != "0" ];
then
get_cfg_value "/var/dtmfbox/dtmfbox.cfg" "acc${tmp_acc_no}" "name"
status_recordings="
Account #${tmp_acc_no} ($CFG_VALUE) - $msg_cnt Nachricht(en)$status_recordings"
fi
let tmp_acc_no=$tmp_acc_no-1
done
}
# Security PID for run_cmd= and dtmfbox_cmd.cgi!
echo "$$" > /var/dtmfbox/tmp/webinterface.pid
####################################################################################
## STATUS
####################################################################################
if [ "$PAGE" = "status" ];
then
show_title "Status"
# Get am messages to $status_recordings
get_am_messages
if [ "$status_recordings" != "" ]; then
echo "
$status_recordings
"
fi
cat << EOF
EOF
fi
####################################################################################
## Basiseinstellungen
####################################################################################
if [ "$PAGE" = "dtmfbox_cfg" ];
then
FILE_EDIT="/var/dtmfbox/dtmfbox.cfg";
SHOW_FILE_SELECTION="0"
CHECK_REBOOT="1"
COMMENT_PREFIX="//"
if [ -z "$DIRECT_EDIT" ]; then DIRECT_EDIT="0"; fi
show_page "dtmfbox_scriptedit.cgi"
fi
####################################################################################
## Skripteinstellungen
####################################################################################
if [ "$PAGE" = "script_cfg" ];
then
FILE_EDIT="/var/dtmfbox/script.cfg";
SHOW_FILE_SELECTION="0"
CHECK_REBOOT="0"
COMMENT_PREFIX="#"
if [ -z "$DIRECT_EDIT" ]; then DIRECT_EDIT="0"; fi
show_page "dtmfbox_scriptedit.cgi"
fi
####################################################################################
## Menü bearbeiten
####################################################################################
if [ "$PAGE" = "menu_cfg" ];
then
FILE_EDIT="/var/dtmfbox/menu.cfg";
SHOW_FILE_SELECTION="0"
CHECK_REBOOT="1"
COMMENT_PREFIX="//"
SHOW_ADD_REMOVE="1"
if [ -z "$DIRECT_EDIT" ]; then DIRECT_EDIT="0"; fi
show_page "dtmfbox_scriptedit.cgi"
fi
####################################################################################
## Skripte bearbeiten
####################################################################################
if [ "$PAGE" = "scripts" ];
then
SHOW_CONFIG_FILES="0"
CHECK_REBOOT="0"
DIRECT_EDIT="1"
show_page "dtmfbox_scriptedit.cgi"
fi
####################################################################################
## Webphone
####################################################################################
if [ "$PAGE" = "webphone" ];
then
show_title "Java Webphone"
echo '
'
echo '
'
fi
####################################################################################
## dtmfbox zurücksetzen
####################################################################################
if [ "$PAGE" = "reset" ] || [ "$PAGE" = "reset_path_only" ];
then
if [ "$PAGE" != "reset_path_only" ]; then
show_title "Pfad, Reset, Deinstallieren, WebIf-Passwort ..."
else
show_title "Pfad ändern ..."
fi
echo "
"
if [ "$FREETZ" = "1" ] && [ -z "$DTMFBOX_PATH" ];
then
head_end
return
fi
fi
####################################################################################
## Nachrichten
####################################################################################
if [ "$PAGE" = "am_messages" ];
then
let ITEMS_PER_PAGE=10
acc_no_str=`echo ${QUERY_STRING} | sed -n 's/.*acc=\(.*\)/\1/p' | sed -e 's/&.*//g'`
page_str=`echo ${QUERY_STRING} | sed -n 's/.*page_msg=\(.*\)/\1/p' | sed -e 's/&.*//g'`
if [ -z "$page_str" ]; then page_str="1"; fi
if [ -z "$acc_no_str" ]; then acc_no_str="1"; fi
let acc_no=$acc_no_str
let page=$page_str
let page=page-1;
if [ $page -le 0 ] || [ "$page" = "" ]; then let page=0; fi
if [ $acc_no -le 0 ] || [ "$acc_no" = "" ]; then acc_no="1"; fi
# load ftp account settings from funcs.sh script
if [ -f /var/dtmfbox/script/funcs.sh ];
then
. /var/dtmfbox/script/am_funcs.sh
load_am_settings "${acc_no}"
fi
delimiter="\n"
ftp_user="$AM_FTP_USERNAME"
ftp_pass="$AM_FTP_PASSWORD"
ftp_path="$AM_FTP_PATH"
ftp_server="$AM_FTP_SERVER"
ftp_port="$AM_FTP_PORT"
ftp_login=`eval echo "USER \\$ftp_user\"$delimiter\"PASS \\$ftp_pass\"$delimiter\"CWD \\$ftp_path\"$delimiter\""`
cat << EOF
EOF
echo '
'
echo '