Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2421 - (hide annotations) (download)
Wed Sep 2 09:25:10 2015 UTC (8 years, 8 months ago) by niro
File size: 3062 byte(s)
-added prompt
1 niro 2051 #!/bin/sh
2    
3 niro 2304 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 niro 2051 # globals
12 niro 2304 # 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/hwdetection.global.class
18 niro 2051
19 niro 2304 # load control classes plugins
20     load_classes control
21 niro 2051
22     SQL_USER=alx
23     SQL_PASS=@lx
24     SQL_HOST=localhost
25     SQL_DB=alx_web
26    
27     import_resource()
28     {
29     local table="$1"
30     local serial="$2"
31     local resource="$3"
32     local value="$4"
33    
34     if [[ ${DEBUG} = 1 ]]
35     then
36     echo "${table}->${resource}=${value}" >> /root/lala.log
37     echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log
38     fi
39    
40     mysql_insert "${table}",serial="${serial}","${resource}"="${value}"
41     }
42    
43     nsslsay()
44     {
45     nssl "${IP}" "${PORT}" << EOF
46     auth ${SSLSAY_USER} ${SSLSAY_PASS}
47     $@
48     quit
49     EOF
50     }
51    
52     control_client()
53     {
54     local serial="$1"
55     local command="${@/$1/}"
56     local IP
57    
58     IP=$(mysqldo "select ip from state_connected where serial='${serial}'")
59     if [[ -z ${IP} ]]
60     then
61     echo "no ip found for client '${serial}'"
62     return 1
63     fi
64    
65     nsslsay "${command}"
66     }
67    
68     #IP="192.168.0.6"
69     PORT="6666"
70     SSLSAY_USER="foo"
71     SSLSAY_PASS="bar"
72    
73 niro 2304 DEBUG=1
74     NOCOLORS="false"
75     WEBCRLF="false"
76     QUIET="false"
77    
78     # argvs are global variables - this fixes issues with whitespaces
79     # global argvs, the whole command line
80     export GLOBAL_ARGV
81     # class specific argvs which are given to the class as parameters
82     export CLASS_ARGV
83    
84 niro 2051 run=run
85     valid_session=no
86    
87 niro 2304 # tell what we are
88     echo "Connected to $(print_version)"
89    
90 niro 2051 while [[ ${run} = run ]]
91     do
92 niro 2421 # use an echo here not read -p '>' because sslsvd ignores the prompt pattern
93     echo -n '> '
94 niro 2051 read line
95 niro 2304 eval "GLOBAL_ARGV=( ${line} )"
96 niro 2051
97 niro 2304 case ${GLOBAL_ARGV[0]} in
98 niro 2051 quit) run=quit ;;
99 niro 2304
100     # only react on the globals -> import|get|set|auth
101     import) run_class ;;
102     control) run_class ;;
103     get) run_class ;;
104     set) run_class ;;
105     auth) validate_auth ${GLOBAL_ARGV[*]:1} ;;
106     provide) valid_session && print_provide ;;
107     require) valid_session && verify_requirements ;;
108     reload) valid_session && mecho "reloading client classes ..." && load_classes client ;;
109     restart) valid_session && restart_service ;;
110     stop) valid_session && stop_service ;;
111     nocolors) export NOCOLORS="true" ;;
112     colors) export NOCOLORS="false" ;;
113     webcrlf) export WEBCRLF="true" ;;
114     quiet) export QUIET="true" ;;
115     # version does not need auth
116     version) print_version ;;
117     help)
118     if valid_session
119     then
120     if [[ ${line} = help ]]
121     then
122     help_topics
123     else
124     run_class ${line}
125     fi
126     else
127     mecho "You must authenticate yourself first!"
128     mecho " auth [username] [password]"
129     fi
130     ;;
131    
132     *)
133     mecho "Unknown command '${line}'"
134     mecho "Type 'help' for more information."
135     #echo "$line" >> /root/lala.log
136     ;;
137 niro 2051 esac
138 niro 2304
139     # unset argvs to be safe
140     unset GLOBAL_ARGS
141     unset CLASS_ARGS
142 niro 2051 done

Properties

Name Value
svn:executable *