Annotation of /mcore-src/trunk/mcore-tools/src/mcore-controld.in
Parent Directory | Revision Log
Revision 2423 -
(hide annotations)
(download)
Thu Sep 3 07:29:19 2015 UTC (9 years ago) by niro
File size: 3123 byte(s)
Thu Sep 3 07:29:19 2015 UTC (9 years ago) by niro
File size: 3123 byte(s)
-added certifacte auth method
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 | niro | 2423 | certauth) validate_auth_certificate ${GLOBAL_ARGV[*]:1} ;; |
107 | niro | 2304 | provide) valid_session && print_provide ;; |
108 | require) valid_session && verify_requirements ;; | ||
109 | reload) valid_session && mecho "reloading client classes ..." && load_classes client ;; | ||
110 | restart) valid_session && restart_service ;; | ||
111 | stop) valid_session && stop_service ;; | ||
112 | nocolors) export NOCOLORS="true" ;; | ||
113 | colors) export NOCOLORS="false" ;; | ||
114 | webcrlf) export WEBCRLF="true" ;; | ||
115 | quiet) export QUIET="true" ;; | ||
116 | # version does not need auth | ||
117 | version) print_version ;; | ||
118 | help) | ||
119 | if valid_session | ||
120 | then | ||
121 | if [[ ${line} = help ]] | ||
122 | then | ||
123 | help_topics | ||
124 | else | ||
125 | run_class ${line} | ||
126 | fi | ||
127 | else | ||
128 | mecho "You must authenticate yourself first!" | ||
129 | mecho " auth [username] [password]" | ||
130 | fi | ||
131 | ;; | ||
132 | |||
133 | *) | ||
134 | mecho "Unknown command '${line}'" | ||
135 | mecho "Type 'help' for more information." | ||
136 | #echo "$line" >> /root/lala.log | ||
137 | ;; | ||
138 | niro | 2051 | esac |
139 | niro | 2304 | |
140 | # unset argvs to be safe | ||
141 | unset GLOBAL_ARGS | ||
142 | unset CLASS_ARGS | ||
143 | niro | 2051 | done |
Properties
Name | Value |
---|---|
svn:executable | * |