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 2438 by niro, Thu Sep 3 12:50:25 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/hwdetection.global.class
18  #source include/input.control.class  
19  for i in include/*.control.class  # load control classes plugins
20  do  load_classes control
  source ${i} || echo "error loading ${i}"  
 done  
21    
22    # config settings
23    include @@SYSCONFDIR@@/mcore/mcore.conf
24    
25  SQL_USER=alx  SQL_USER=alx
26  SQL_PASS=@lx  SQL_PASS=@lx
# Line 35  import_resource() Line 43  import_resource()
43   mysql_insert "${table}",serial="${serial}","${resource}"="${value}"   mysql_insert "${table}",serial="${serial}","${resource}"="${value}"
44  }  }
45    
 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  
 }  
   
46  nsslsay()  nsslsay()
47  {  {
48   nssl "${IP}" "${PORT}" << EOF   nssl "${IP}" "${PORT}" << EOF
# Line 93  control_client() Line 68  control_client()
68   nsslsay "${command}"   nsslsay "${command}"
69  }  }
70    
   
 DEBUG=1  
71  #IP="192.168.0.6"  #IP="192.168.0.6"
72  PORT="6666"  PORT="6666"
73  SSLSAY_USER="foo"  SSLSAY_USER="foo"
74  SSLSAY_PASS="bar"  SSLSAY_PASS="bar"
75    
76    DEBUG=1
77    NOCOLORS="false"
78    WEBCRLF="false"
79    QUIET="false"
80    
81    # argvs are global variables - this fixes issues with whitespaces
82    # global argvs, the whole command line
83    export GLOBAL_ARGV
84    # class specific argvs which are given to the class as parameters
85    export CLASS_ARGV
86    
87  run=run  run=run
88  valid_session=no  valid_session=no
89    
90    # tell what we are
91    echo "Connected to $(print_version)"
92    
93  while [[ ${run} = run ]]  while [[ ${run} = run ]]
94  do  do
95     # use an echo here not read -p '>' because sslsvd ignores the prompt pattern
96     echo -n '> '
97   read line   read line
98     eval "GLOBAL_ARGV=( ${line} )"
99    
100   case ${line} in   case ${GLOBAL_ARGV[0]} in
101   quit) run=quit ;;   quit) run=quit ;;
102   # only react on the globals -> import|get|set|auth|control  
103   import*) run_class ${line} ;;   # only react on the globals -> import|get|set|auth
104   get*) run_class ${line} ;;   import) run_class ;;
105   set*) run_class ${line} ;;   control) run_class ;;
106   auth*) validate_auth ${line/auth /} ;;   get) run_class ;;
107   # control client daemons   set) run_class ;;
108   #control*) control_client ${line/control /} ;;   auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
109   control*) run_class ${line} ;;   certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;;
110   *) echo "$line" >> /root/lala.log ;;   register) valid_session && validate_client ${GLOBAL_ARGV[*]:1} ;;
111     provide) valid_session && print_provide ;;
112     require) valid_session && verify_requirements ;;
113     reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
114     restart) valid_session && restart_service ;;
115     stop) valid_session && stop_service ;;
116     nocolors) export NOCOLORS="true" ;;
117     colors) export NOCOLORS="false" ;;
118     webcrlf) export WEBCRLF="true" ;;
119     quiet) export QUIET="true" ;;
120     # version does not need auth
121     version) print_version ;;
122     help)
123     if valid_session
124     then
125     if [[ ${line} = help ]]
126     then
127     help_topics
128     else
129     run_class ${line}
130     fi
131     else
132     mecho "You must authenticate yourself first!"
133     mecho "  auth [username] [password]"
134     mecho "or"
135     mecho "  certauth [certificate fingerprint]"
136     fi
137     ;;
138    
139     *)
140     mecho "Unknown command '${line}'"
141     mecho "Type 'help' for more information."
142     #echo "$line" >> /root/lala.log
143     ;;
144   esac   esac
 done  
145    
146     # unset argvs to be safe
147     unset GLOBAL_ARGS
148     unset CLASS_ARGS
149    done

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