--- mcore-src/trunk/mcore-tools/src/mcore-controld.in 2014/01/14 16:11:53 2285 +++ mcore-src/trunk/mcore-tools/src/mcore-controld.in 2014/01/20 14:07:32 2304 @@ -1,18 +1,23 @@ #!/bin/sh +MCORE_LIBDIR="@@MCORE_LIBDIR@@" + +# respect system env (proxy settings etc) +if [ -e @@SYSCONFDIR@@/profile ] +then + source @@SYSCONFDIR@@/profile +fi + # 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 +# include function comes with common.global class +source ${MCORE_LIBDIR}/include/common.global.class +include ${MCORE_LIBDIR}/include/daemon.global.class +include ${MCORE_LIBDIR}/include/sessionauth.global.class +include ${MCORE_LIBDIR}/include/mysqlfunctions.global.class +#include ${MCORE_LIBDIR}/include/hwdetection.global.class +# load control classes plugins +load_classes control SQL_USER=alx SQL_PASS=@lx @@ -35,39 +40,6 @@ 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 @@ -93,31 +65,76 @@ nsslsay "${command}" } - -DEBUG=1 #IP="192.168.0.6" PORT="6666" SSLSAY_USER="foo" SSLSAY_PASS="bar" +DEBUG=1 +NOCOLORS="false" +WEBCRLF="false" +QUIET="false" + +# argvs are global variables - this fixes issues with whitespaces +# global argvs, the whole command line +export GLOBAL_ARGV +# class specific argvs which are given to the class as parameters +export CLASS_ARGV + run=run valid_session=no +# tell what we are +echo "Connected to $(print_version)" + while [[ ${run} = run ]] do read line + eval "GLOBAL_ARGV=( ${line} )" - case ${line} in + case ${GLOBAL_ARGV[0]} 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 ;; + + # only react on the globals -> import|get|set|auth + import) run_class ;; + control) run_class ;; + get) run_class ;; + set) run_class ;; + auth) validate_auth ${GLOBAL_ARGV[*]:1} ;; + provide) valid_session && print_provide ;; + require) valid_session && verify_requirements ;; + reload) valid_session && mecho "reloading client classes ..." && load_classes client ;; + restart) valid_session && restart_service ;; + stop) valid_session && stop_service ;; + nocolors) export NOCOLORS="true" ;; + colors) export NOCOLORS="false" ;; + webcrlf) export WEBCRLF="true" ;; + quiet) export QUIET="true" ;; + # version does not need auth + version) print_version ;; + help) + if valid_session + then + if [[ ${line} = help ]] + then + help_topics + else + run_class ${line} + fi + else + mecho "You must authenticate yourself first!" + mecho " auth [username] [password]" + fi + ;; + + *) + mecho "Unknown command '${line}'" + mecho "Type 'help' for more information." + #echo "$line" >> /root/lala.log + ;; esac -done + # unset argvs to be safe + unset GLOBAL_ARGS + unset CLASS_ARGS +done