#!/bin/sh # globals source include/daemon.global.class source include/sessionauth.global.class source include/mysqlfunctions.global.class # control specific #source include/graphic.control.class #source include/input.control.class for i in include/*.control.class do source ${i} || echo "error loading ${i}" done SQL_USER=alx SQL_PASS=@lx SQL_HOST=localhost SQL_DB=alx_web import_resource() { local table="$1" local serial="$2" local resource="$3" local value="$4" if [[ ${DEBUG} = 1 ]] then echo "${table}->${resource}=${value}" >> /root/lala.log echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log fi mysql_insert "${table}",serial="${serial}","${resource}"="${value}" } run_class() { local method="$1" local caller="$2" local class local cmd local argv if validate_session then class="${caller%.*}" cmd="${caller#*.}" argv="${@/${caller}/}" # remove caller argv="${argv/${method}/}" # remove method # echo "method=${method}" # echo "caller=${caller}" # echo "class=${class}" # echo "cmd=${cmd}" # echo "argv=${argv}" # check if class.cmd exist if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] then "${method}"_"${class}"_"${cmd}" ${argv} else echo "unknown class.cmd" fi else invalid_session fi } nsslsay() { nssl "${IP}" "${PORT}" << EOF auth ${SSLSAY_USER} ${SSLSAY_PASS} $@ quit EOF } control_client() { local serial="$1" local command="${@/$1/}" local IP IP=$(mysqldo "select ip from state_connected where serial='${serial}'") if [[ -z ${IP} ]] then echo "no ip found for client '${serial}'" return 1 fi nsslsay "${command}" } DEBUG=1 #IP="192.168.0.6" PORT="6666" SSLSAY_USER="foo" SSLSAY_PASS="bar" run=run valid_session=no while [[ ${run} = run ]] do read line case ${line} in quit) run=quit ;; # only react on the globals -> import|get|set|auth|control import*) run_class ${line} ;; get*) run_class ${line} ;; set*) run_class ${line} ;; auth*) validate_auth ${line/auth /} ;; # control client daemons #control*) control_client ${line/control /} ;; control*) run_class ${line} ;; *) echo "$line" >> /root/lala.log ;; esac done