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

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