Contents of /mcore-src/trunk/mcore-tools/src/mcore-controld.in
Parent Directory | Revision Log
Revision 2432 -
(show annotations)
(download)
Thu Sep 3 12:29:10 2015 UTC (8 years, 9 months ago) by niro
File size: 3255 byte(s)
Thu Sep 3 12:29:10 2015 UTC (8 years, 9 months ago) by niro
File size: 3255 byte(s)
-accept the register param
1 | #!/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 |
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/hwdetection.global.class |
18 | |
19 | # load control classes plugins |
20 | load_classes control |
21 | |
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 | 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 | run=run |
85 | valid_session=no |
86 | |
87 | # tell what we are |
88 | echo "Connected to $(print_version)" |
89 | |
90 | while [[ ${run} = run ]] |
91 | do |
92 | # use an echo here not read -p '>' because sslsvd ignores the prompt pattern |
93 | echo -n '> ' |
94 | read line |
95 | eval "GLOBAL_ARGV=( ${line} )" |
96 | |
97 | case ${GLOBAL_ARGV[0]} in |
98 | quit) run=quit ;; |
99 | |
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 | certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;; |
107 | register) valid_session && validate_client ${GLOBAL_ARGV[*]:1} ;; |
108 | provide) valid_session && print_provide ;; |
109 | require) valid_session && verify_requirements ;; |
110 | reload) valid_session && mecho "reloading client classes ..." && load_classes client ;; |
111 | restart) valid_session && restart_service ;; |
112 | stop) valid_session && stop_service ;; |
113 | nocolors) export NOCOLORS="true" ;; |
114 | colors) export NOCOLORS="false" ;; |
115 | webcrlf) export WEBCRLF="true" ;; |
116 | quiet) export QUIET="true" ;; |
117 | # version does not need auth |
118 | version) print_version ;; |
119 | help) |
120 | if valid_session |
121 | then |
122 | if [[ ${line} = help ]] |
123 | then |
124 | help_topics |
125 | else |
126 | run_class ${line} |
127 | fi |
128 | else |
129 | mecho "You must authenticate yourself first!" |
130 | mecho " auth [username] [password]" |
131 | mecho "or" |
132 | mecho " certauth [certificate fingerprint]" |
133 | fi |
134 | ;; |
135 | |
136 | *) |
137 | mecho "Unknown command '${line}'" |
138 | mecho "Type 'help' for more information." |
139 | #echo "$line" >> /root/lala.log |
140 | ;; |
141 | esac |
142 | |
143 | # unset argvs to be safe |
144 | unset GLOBAL_ARGS |
145 | unset CLASS_ARGS |
146 | done |
Properties
Name | Value |
---|---|
svn:executable | * |