#!/bin/sh #------------------------------------------------------------------------------ # dyndns.cgi - display the answers from the dyndns services # part of Package DYNDNS __FLI4LVER__, see documentation for licence # # (c) copyright 2001-2002 Thomas Mueller # (c) copyright 2002-2003 Tobias Gruetzmacher # # Creation: 27.08.2001 Thomas Mueller # Last update: $Id$ #------------------------------------------------------------------------------ # set_debug=yes sanitize_log () { local sed_lang=/srv/www/lang/status_dyndns.sed.$lang if [ -f $sed_lang ]; then sed -f /srv/www/admin/status_dyndns.sed $1 | sed -f $sed_lang else sed -f /srv/www/admin/status_dyndns.sed $1 fi } show_history () { host=$1 show_html_header "DynDNS-Status $host" show_tab_header "$_DYNDNS_tab_header" no sanitize_log $dyn_histdir/$host } show_status () { hist=$1 show_html_header "DynDNS-Status" show_tab_header "$_DYNDNS_tab_header" no cat < EOF while read host provider foo; do dyn_runfile="$dyn_rundir/$host" dyn_disabled="${dyn_runfile}.disabled" dyn_logfile="$dyn_logdir/$host" dyn_histfile="$dyn_histdir/$host" if [ "$hist" ]; then [ "$hist" != "$host" ] && continue dyn_logfile="$dyn_histfile" fi if [ -f $dyn_runfile ]; then . $dyn_runfile last="`date -d $registered_date -D '%s' '+%d.%m.%Y %H:%M'`" state="Up to date" else last=unknown state=unknown fi if [ -f $dyn_disabled ]; then action=enable text="$_DYNDNS_action_enable" state="Update disabled" else if [ -f $dyn_runfile.pid ]; then action=cancel text="$_DYNDNS_action_cancel" state="Update running" else action=update text="$_DYNDNS_action_update" img="\"$text\"/" fi fi # # header # cat < $host, Current state: $state, Last succesful update: $last \n ' # # right column # echo ' ' [ -f $dyn_logfile ] && sanitize_log $dyn_logfile echo ' ' # # close row # echo '' done < /etc/dyndns/dyndns.conf echo "" show_tab_footer } update_host () { local host=$1 local ip= local interface= local pid= local tmp=/tmp/dyncgi.$$ local res= conf_line="`grep \"^$host[[:space:]]\" /etc/dyndns/dyndns.conf`" if [ ! "$conf_line" ]; then show_error "error" "Missing config line for host '$host,$circuit' in config file" return 1 fi set -- $conf_line if [ $# -lt 6 -o $# -gt 7 ]; then show_error "error" "Invalid config line for host '$host' in config file" return 1 fi dyndns-update.sh $deb_flag -f $host > $tmp 2>&1 & pid=$! for i in 1 2 3 4 5; do kill -0 $pid 2> /dev/null || break sleep 1 done if [ -s $tmp ]; then if grep "Update successful" $tmp; then res=0 else cat $tmp res=1 fi else msg="$_DYNDNS_update_triggered" res=0 fi rm -f $tmp return $res } dyndns_debug () { val=$1 if [ "$val" ]; then file=$dyn_rundir/inv_$val if [ -f $file ]; then rm -f $file else > $file fi fi show_html_header "DynDNS - Debug Provider" echo "" } debug_trace () { show_html_header "DynDNS - Debug Trace $1" { echo "
"
        cat /var/tmp/$1
        echo "
" } | show_error "$1" } # get main helper functions . /srv/www/include/cgi-helper : ${FORM_action:=status} # Security check_rights "dyndns" "view" dyn_logdir="/var/log/dyndns" dyn_histdir="${dyn_logdir}/history" dyn_rundir="/var/run/dyndns" _rurl=$myname # reload-url _rshort=5 # short reload (5) [ "$set_debug" = yes ] && _rshort=1800 # use a longer reload for the debug case action=$FORM_action host=$FORM_host method=$FORM_method msg= if [ $action = status -o $action = history ]; then show_status $host elif [ $action = debug_provider ]; then dyndns_debug $host elif [ $action = debug_trace ]; then debug_trace $host else if [ -f $dyn_rundir/inv_verb_debug ]; then deb_flag=-vx else [ -f $dyn_rundir/inv_debug ] && deb_flag=-x fi case $action in update) update_host $host ;; enable_method) dyndns-update.sh $deb_flag enable_method $host $method ;; enable) dyndns-update.sh $deb_flag enable $host ;; cancel) dyndns-update.sh $deb_flag cancel $host ;; *) echo "$_DYNDNS_unknown_action_msg: '$action'" action=unknown_action false ;; esac > /tmp/status_dyndns.cgi.$$ 2>&1 res=$? eval header="\"\$_DYNDNS_${action}_header $host\"" if [ $res -eq 0 ]; then if true; then show_status else show_html_header "$header" "refresh=$_rshort;url=$_rurl" [ "$msg" ] || eval msg="\"\$_DYNDNS_${action}_done_info\"" { if [ -s /tmp/status_dyndns.cgi.$$ ]; then echo '
'
                cat /tmp/status_dyndns.cgi.$$
                echo '
' fi echo "$_DYNDNS_done_message$_DYNDNS_done_url." } | show_info "$msg" fi else show_html_header "$header" # "refresh=$_rshort;url=$_rurl" { echo '
'
            cat /tmp/status_dyndns.cgi.$$
            echo -e "
\n$_DYNDNS_err_head $_DYNDNS_done_url$_DYNDNS_err_tail" } | show_error "Error" fi fi # # one closing html footer for all # show_html_footer