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

Legend:
Removed from v.2243  
changed lines
  Added in v.2480