Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/src/mcore-controld.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

mcore-src/trunk/mcore-tools/daemon/control/control-daemon.sh revision 2051 by niro, Wed May 8 11:09:38 2013 UTC mcore-src/trunk/mcore-tools/src/mcore-controld.in revision 2484 by niro, Thu Sep 10 11:46:04 2015 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/sh
2    
3  # globals  MCORE_LIBDIR="@@MCORE_LIBDIR@@"
 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 "unkown 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  
4    
5   nsslsay "${command}"  # respect system env (proxy settings etc)
6  }  if [ -e @@SYSCONFDIR@@/profile ]
7    then
8     source @@SYSCONFDIR@@/profile
9    fi
10    
11    # globals
12    # include function comes with common.global class
13    source ${MCORE_LIBDIR}/include/common.global.class
14    include ${MCORE_LIBDIR}/include/daemon.global.class
15    include ${MCORE_LIBDIR}/include/sessionauth.global.class
16    include ${MCORE_LIBDIR}/include/mysqlfunctions.global.class
17    include ${MCORE_LIBDIR}/include/register.global.class
18    include ${MCORE_LIBDIR}/include/control.global.class
19    #include ${MCORE_LIBDIR}/include/hwdetection.global.class
20    
21    # load control classes plugins
22    load_classes control
23    
24    # config settings
25    include @@SYSCONFDIR@@/mcore/mcore.conf
26    include @@SYSCONFDIR@@/mcore/control.conf
27    
28    # 0=false, 1=true
29  DEBUG=1  DEBUG=1
30  #IP="192.168.0.6"  NOCOLORS=0
31  PORT="6666"  WEBCRLF=0
32  SSLSAY_USER="foo"  QUIET=0
33  SSLSAY_PASS="bar"  # daemon silent mode, read from env
34    : ${SILENT=0}
35    
36    # argvs are global variables - this fixes issues with whitespaces
37    # global argvs, the whole command line
38    export GLOBAL_ARGV
39    # class specific argvs which are given to the class as parameters
40    export CLASS_ARGV
41    
42  run=run  run=run
43  valid_session=no  valid_session=no
44    
45    # tell what we are
46    [[ ${SILENT} = 1 ]] || echo "Connected to $(print_version)"
47    
48  while [[ ${run} = run ]]  while [[ ${run} = run ]]
49  do  do
50     # use an echo here not read -p '>' because sslsvd ignores the prompt pattern
51     [[ ${SILENT} = 1 ]] || echo -n '> '
52   read line   read line
53     eval "GLOBAL_ARGV=( ${line} )"
54    
55   case ${line} in   case ${GLOBAL_ARGV[0]} in
56   quit) run=quit ;;   quit) run=quit ;;
57   # only react on the globals -> import|get|set|auth|control  
58   import*) run_class ${line} ;;   # only react on the globals -> import|get|set|auth
59   get*) run_class ${line} ;;   import) run_class ;;
60   set*) run_class ${line} ;;   control) run_class ;;
61   auth*) validate_auth ${line/auth /} ;;   get) run_class ;;
62   # control client daemons   set) run_class ;;
63   #control*) control_client ${line/control /} ;;   auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
64   control*) run_class ${line} ;;   certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;;
65   *) echo "$line" >> /root/lala.log ;;   register) valid_session && validate_client ${GLOBAL_ARGV[*]:1} ;;
66     provide) valid_session && print_provide ;;
67     require) valid_session && verify_requirements ;;
68     reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
69     restart) valid_session && restart_service ;;
70     stop) valid_session && stop_service ;;
71     nocolors) export NOCOLORS=1 ;;
72     colors) export NOCOLORS=0 ;;
73     webcrlf) export WEBCRLF=1 ;;
74     quiet) export QUIET=1 ;;
75     # version does not need auth
76     version) print_version ;;
77     help)
78     if valid_session
79     then
80     if [[ ${line} = help ]]
81     then
82     help_topics
83     else
84     run_class ${line}
85     fi
86     else
87     mecho "You must authenticate yourself first!"
88     mecho "  auth [username] [password]"
89     mecho "or"
90     mecho "  certauth [certificate fingerprint]"
91     fi
92     ;;
93    
94     *)
95     mecho "Unknown command '${line}'"
96     mecho "Type 'help' for more information."
97     #echo "$line" >> /root/lala.log
98     ;;
99   esac   esac
 done  
100    
101     # unset argvs to be safe
102     unset GLOBAL_ARGS
103     unset CLASS_ARGS
104    done

Legend:
Removed from v.2051  
changed lines
  Added in v.2484