#!/bin/sh #------------------------------------------------------------------------------ # /usr/local/htdocs/wolsol/wolsol.cgi - wake/shutdown on LAN # # Copyright (c) 2004-2010 Andreas Pohl, apohl(at)ibp-consult(dot)com # Copyright (c) 2011-2019 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2004-07-30 ap # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version.. #------------------------------------------------------------------------------ #exec 2>/tmp/wolsol-cgi-trace-$$.log #set -x #eval `echo "${QUERY_STRING}" |tr '&' '\n'` query_str="${QUERY_STRING}" myname=`basename $0` sol_env_file=/usr/local/htdocs/wolsol/action-env # HTML header echo "Content-Type: text/html; charset=iso-8859-1" echo "Cache-control: no-store" # HTTP/1.1 (or no-cache?) echo "Pragma: no-cache" # HTTP/1.0 echo echo "" echo "wolsol" echo '' echo "" echo "" echo "

WOLSOL - Wake and Shutdown on LAN

" echo "
" . /etc/config.d/mini_httpd_wolsol # print pc selection idx=1 if [ ${WOLSOL_N} -ge ${idx} ] then echo '' idx=1 while [ ${idx} -le ${WOLSOL_N} ] do eval active='$WOLSOL_'${idx}'_ACTIVE' if [ "${active}" = "yes" ] then eval name='$WOLSOL_'${idx}'_NAME' eval device='$WOLSOL_'${idx}'_DEVICE' eval ipaddr='$WOLSOL_'${idx}'_IPADDR' eval wolmac='$WOLSOL_'${idx}'_WOL_MAC' if [ -z "${device}" ] then device='eth0' fi # sol command file lowname=`echo ${name} | sed 's#%20# #g' | tr 'A-Z ' 'a-z_'` sol_cmd_file=/usr/local/htdocs/wolsol/${lowname}-off echo "" fi idx=`expr ${idx} + 1` done echo "
${name}" if [ -n "${ipaddr}" ] then /usr/bin/arping -f -c 1 -I ${device} -w 1 -q ${ipaddr} if [ $? -eq 0 ] then echo 'up' else echo 'down' fi echo '' fi echo " " echo " " if [ -f ${sol_cmd_file} ] then echo " " else echo " " fi echo "" echo "
" # echo "
" else echo "No pc configurations found, check configuration." fi # print link selection echo '

' echo "" idx=1 while [ ${idx} -le ${WOLSOL_LINK_N} ] do eval l_active='$WOLSOL_LINK_'${idx}'_ACTIVE' if [ "${l_active}" = "yes" ] then eval l_name='$WOLSOL_LINK_'${idx}'_NAME' eval l_href='$WOLSOL_LINK_'${idx}'_HREF' eval l_target='$WOLSOL_LINK_'${idx}'_TARGET' echo " | ${l_name}" fi idx=`expr ${idx} + 1` done echo "


" # process parameters exec_flag=0 case "${QUERY_STRING}" in (name=*) # save variables to file eval `echo "${QUERY_STRING}" |tr '&' '\n'` { echo "name='${name}'" echo "device='${dev}'" echo "action='${action}'" echo "ipaddr='${ip}'" echo "wolmac='${mac}'" } > ${sol_env_file} chmod 600 ${sol_env_file} 2>/dev/null # sol command file lowname=`echo ${name} | sed 's#%20# #g' | tr 'A-Z ' 'a-z_'` sol_cmd_file=/usr/local/htdocs/wolsol/${lowname}-off if [ "${action}" = 'off' -a -f ${sol_cmd_file} ] then # off - check if password is required grep -q '{solpass}' ${sol_cmd_file} if [ $? -eq 0 ] then # off - ask for password echo '
' echo '

Kennwort: ' echo '' echo '

' echo '
' echo "
" else # off - no password required exec_flag=1 fi else # on / status exec_flag=1 fi ;; (pass=*) # save variable to file eval `echo "${QUERY_STRING}" |tr '&' '\n'` { echo "solpass=\"${pass}\"" } >> ${sol_env_file} chmod 600 ${sol_env_file} 2>/dev/null # check if environment file contains required data grep -q "^name=" ${sol_env_file} if [ $? -eq 0 -a "${action}" = 'off' ] then exec_flag=1 else # incomplete file, delete it rm -f ${sol_env_file} fi ;; esac # execute script if [ ${exec_flag} -eq 1 ] then echo "

Start: " date +"%a, %d.%m.%Y %H:%M:%S" echo "

" echo "
"
    ./action.sh --html
    echo "
" echo "

Ende: " date +"%a, %d.%m.%Y %H:%M:%S" echo "

" echo "
" fi echo "" exit 0