#!/bin/sh MCORE_LIBDIR="@@MCORE_LIBDIR@@" # respect system env (proxy settings etc) if [ -e @@SYSCONFDIR@@/profile ] then source @@SYSCONFDIR@@/profile fi # globals # 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/register.global.class #include ${MCORE_LIBDIR}/include/hwdetection.global.class # load control classes plugins load_classes control # config settings include @@SYSCONFDIR@@/mcore/mcore.conf 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}" } 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}" } #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 # use an echo here not read -p '>' because sslsvd ignores the prompt pattern echo -n '> ' read line eval "GLOBAL_ARGV=( ${line} )" case ${GLOBAL_ARGV[0]} in quit) run=quit ;; # 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} ;; certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;; register) valid_session && validate_client ${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]" mecho "or" mecho " certauth [certificate fingerprint]" fi ;; *) mecho "Unknown command '${line}'" mecho "Type 'help' for more information." #echo "$line" >> /root/lala.log ;; esac # unset argvs to be safe unset GLOBAL_ARGS unset CLASS_ARGS done