1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
# import_resource $table $serial $resource $value |
# loads client classes from $MCLIBDIR |
4 |
import_resource() |
load_client_classes() |
5 |
{ |
{ |
6 |
local table="$1" |
# client specific |
7 |
local serial="$2" |
for i in ${MCLIBDIR}/include/*.client.class |
8 |
local resource="$3" |
do |
9 |
local value="$4" |
source ${i} || eecho "error loading ${i}" |
10 |
|
done |
11 |
|
} |
12 |
|
|
13 |
if [[ ${DEBUG} = 1 ]] |
# restarts the whole service via remote cmd |
14 |
then |
restart_service() |
15 |
echo "${table}->${resource}=${value}" >> /root/lala.log |
{ |
16 |
echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log |
local pid |
17 |
fi |
for pid in $(pidof sslsvd) |
18 |
|
do |
19 |
|
kill -SIGHUP ${pid} |
20 |
|
done |
21 |
|
} |
22 |
|
|
23 |
mysql_insert "${table}",serial="${serial}","${resource}"="${value}" |
# stops the whole service via remote cmd |
24 |
|
stop_service() |
25 |
|
{ |
26 |
|
local pid |
27 |
|
for pid in $(pidof sslsvd) |
28 |
|
do |
29 |
|
kill -15 ${pid} |
30 |
|
sleep 1 |
31 |
|
kill -9 ${pid} |
32 |
|
done |
33 |
} |
} |
34 |
|
|
35 |
|
# # import_resource $table $serial $resource $value |
36 |
|
# import_resource() |
37 |
|
# { |
38 |
|
# local table="$1" |
39 |
|
# local serial="$2" |
40 |
|
# local resource="$3" |
41 |
|
# local value="$4" |
42 |
|
# |
43 |
|
# if [[ ${DEBUG} = 1 ]] |
44 |
|
# then |
45 |
|
# echo "${table}->${resource}=${value}" >> /root/lala.log |
46 |
|
# echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log |
47 |
|
# fi |
48 |
|
# |
49 |
|
# mysql_insert "${table}",serial="${serial}","${resource}"="${value}" |
50 |
|
# } |
51 |
|
|
52 |
# run_class $method $caller $argv1 $argv2 ... $argvN |
# run_class $method $caller $argv1 $argv2 ... $argvN |
53 |
run_class() |
run_class() |
54 |
{ |
{ |
58 |
local cmd |
local cmd |
59 |
local argv |
local argv |
60 |
|
|
61 |
if validate_session |
if valid_session |
62 |
then |
then |
63 |
class="${caller%.*}" |
class="${caller%.*}" |
64 |
cmd="${caller#*.}" |
cmd="${caller#*.}" |
76 |
then |
then |
77 |
"${method}"_"${class}"_"${cmd}" ${argv} |
"${method}"_"${class}"_"${cmd}" ${argv} |
78 |
else |
else |
79 |
echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
80 |
fi |
fi |
81 |
else |
else |
82 |
invalid_session |
invalid_session |
90 |
|
|
91 |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
92 |
mecho "Global commands:" |
mecho "Global commands:" |
93 |
mecho "\timport - import settings to database" |
mecho "\timport - import settings to database" |
94 |
mecho "\tget - shows current value for a settings" |
mecho "\tget - shows current value for a settings" |
95 |
mecho "\tset - sets value for a setting" |
mecho "\tset - sets value for a setting" |
96 |
mecho "\tauth - authenticate to the daemon" |
mecho "\tauth - authenticate to the daemon" |
97 |
mecho "\tprovide - shows provides of a system" |
mecho "\tprovide - shows provides of a system" |
98 |
mecho "\thelp - shows help" |
mecho "\trequire - verify plugin requirements" |
99 |
|
mecho "\treload - reloads all client classes plugins" |
100 |
|
mecho "\trestart - restarts the daemon" |
101 |
|
mecho "\tstop - stops the daemon" |
102 |
|
mecho "\tnocolors - disable colors, useful for the webclient" |
103 |
|
mecho "\tcolors - enable colors" |
104 |
|
mecho "\tquiet - do not print any unecessary messages" |
105 |
|
mecho "\thelp - shows help" |
106 |
|
mecho "\tquit - quits the connection to the server" |
107 |
mecho |
mecho |
108 |
mecho "Help topics:" |
mecho "Help topics:" |
109 |
for i in ${topics} |
for i in ${topics} |
115 |
|
|
116 |
mecho "\t${i}" |
mecho "\t${i}" |
117 |
done |
done |
118 |
|
mecho |
119 |
|
mecho "Type 'help [topic]' for more information about every topic." |
120 |
} |
} |
121 |
|
|
122 |
# on newer xorg-servers root is not allowed to run progs in a user session |
# on newer xorg-servers root is not allowed to run progs in a user session |
123 |
x11runas() |
x11runas() |
124 |
{ |
{ |
125 |
su - "${MCORE_UNPRIV_USER}" -c "$@" |
if [[ -n $(pidof X) ]] |
126 |
|
then |
127 |
|
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
128 |
|
fi |
129 |
} |
} |
130 |
|
|
131 |
addconfig() |
addconfig() |
132 |
{ |
{ |
133 |
|
local opts |
134 |
|
|
135 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
136 |
then |
then |
137 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
138 |
return 1 |
return 1 |
139 |
fi |
fi |
140 |
|
|
142 |
then |
then |
143 |
install -d $(dirname ${CONFIG}) |
install -d $(dirname ${CONFIG}) |
144 |
fi |
fi |
145 |
echo "$@" >> ${CONFIG} |
|
146 |
|
# check for opts |
147 |
|
case $1 in |
148 |
|
-n) shift; opts=" -n" ;; |
149 |
|
-e) shift; opts=" -e" ;; |
150 |
|
esac |
151 |
|
|
152 |
|
echo ${opts} "$@" >> ${CONFIG} |
153 |
} |
} |
154 |
|
|
155 |
clearconfig() |
clearconfig() |
156 |
{ |
{ |
157 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
158 |
then |
then |
159 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
160 |
return 1 |
return 1 |
161 |
fi |
fi |
162 |
|
|
163 |
|
if [[ ! -d $(dirname ${CONFIG}) ]] |
164 |
|
then |
165 |
|
install -d $(dirname ${CONFIG}) |
166 |
|
fi |
167 |
: > ${CONFIG} |
: > ${CONFIG} |
168 |
} |
} |
169 |
|
|
170 |
|
# no_duplicate $list $item |
171 |
|
no_duplicate() |
172 |
|
{ |
173 |
|
local i |
174 |
|
local list="$1" |
175 |
|
local item="$2" |
176 |
|
|
177 |
|
for i in ${list} |
178 |
|
do |
179 |
|
[[ ${i} = ${item} ]] && return 1 |
180 |
|
done |
181 |
|
|
182 |
|
return 0 |
183 |
|
} |
184 |
|
|
185 |
require() |
require() |
186 |
{ |
{ |
187 |
local requires="$@" |
local requires="$@" |
189 |
|
|
190 |
for i in ${requires} |
for i in ${requires} |
191 |
do |
do |
192 |
export REQUIRE="${REQUIRE} ${i}" |
# check for duplicate provides |
193 |
|
if no_duplicate "${PROVIDE}" "${i}" |
194 |
|
then |
195 |
|
export REQUIRE="${REQUIRE} ${i}" |
196 |
|
else |
197 |
|
decho "duplicate provide '${i}' detected!" |
198 |
|
fi |
199 |
done |
done |
200 |
} |
} |
201 |
|
|
202 |
not_provided() |
verify_requirements() |
203 |
{ |
{ |
204 |
local i |
local req |
205 |
local item="$1" |
local prov |
206 |
|
local missing |
207 |
|
local sorted |
208 |
|
|
209 |
for i in ${PROVIDE} |
for req in ${REQUIRE} |
210 |
do |
do |
211 |
[[ ${i} = ${item} ]] && return 1 |
# scan PROVIDE for dupes |
212 |
|
# if a dupe is found, then requirement is fullfilled |
213 |
|
# else add to missing |
214 |
|
if no_duplicate "${PROVIDE}" "${req}" |
215 |
|
then |
216 |
|
missing="${missing} ${req}" |
217 |
|
fi |
218 |
done |
done |
219 |
|
|
220 |
return 0 |
# sort them alpabetically |
221 |
|
sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) |
222 |
|
|
223 |
|
# show missing and set the right retval |
224 |
|
if [[ -z ${missing} ]] |
225 |
|
then |
226 |
|
rvecho "${sorted}" |
227 |
|
return 0 |
228 |
|
else |
229 |
|
for req in ${sorted} |
230 |
|
do |
231 |
|
if no_duplicate "${missing}" "$req" |
232 |
|
then |
233 |
|
# print normal |
234 |
|
rvecho -n " ${req}" |
235 |
|
else |
236 |
|
# print missing |
237 |
|
eecho -n " ${req}" |
238 |
|
fi |
239 |
|
done |
240 |
|
return 1 |
241 |
|
fi |
242 |
} |
} |
243 |
|
|
244 |
provide() |
provide() |
249 |
for i in ${provides} |
for i in ${provides} |
250 |
do |
do |
251 |
# check for duplicate provides |
# check for duplicate provides |
252 |
if not_provided "${i}" |
if no_duplicate "${PROVIDE}" "${i}" |
253 |
then |
then |
254 |
export PROVIDE="${PROVIDE} ${i}" |
export PROVIDE="${PROVIDE} ${i}" |
255 |
else |
else |
256 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
257 |
fi |
fi |
258 |
done |
done |
259 |
} |
} |
265 |
# sort them alpabetically |
# sort them alpabetically |
266 |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
267 |
# do not escape, or CRLFS get printed to screen too |
# do not escape, or CRLFS get printed to screen too |
268 |
mecho ${sorted} |
rvecho ${sorted} |
269 |
} |
} |
270 |
|
|
271 |
|
# message only echo | disabled in quiet mode |
272 |
mecho() |
mecho() |
273 |
{ |
{ |
274 |
local COLCYAN="\033[1;36m" |
local COLCYAN="\033[1;36m" |
275 |
local COLDEFAULT="\033[0m" |
local COLDEFAULT="\033[0m" |
276 |
|
local opts |
277 |
|
local webcrlf |
278 |
|
|
279 |
|
# print nothing if quiet mode was requested |
280 |
|
[[ ${QUIET} = true ]] && return |
281 |
|
|
282 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = true ]] |
283 |
then |
then |
284 |
COLCYAN="" |
COLCYAN="" |
285 |
COLDEFAULT="" |
COLDEFAULT="" |
286 |
fi |
fi |
287 |
|
|
288 |
echo -e "${COLCYAN}$@${COLDEFAULT}" |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
289 |
|
|
290 |
|
# respect -n |
291 |
|
case $1 in |
292 |
|
-n) shift; opts="n" ;; |
293 |
|
esac |
294 |
|
|
295 |
|
echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" |
296 |
|
} |
297 |
|
|
298 |
|
# prints error messages | enabled even in quiet mode |
299 |
|
eecho() |
300 |
|
{ |
301 |
|
local COLRED="\033[1;31m" |
302 |
|
local COLDEFAULT="\033[0m" |
303 |
|
local opts |
304 |
|
local webcrlf |
305 |
|
|
306 |
|
if [[ ${NOCOLORS} = true ]] |
307 |
|
then |
308 |
|
COLRED="" |
309 |
|
COLDEFAULT="" |
310 |
|
fi |
311 |
|
|
312 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
313 |
|
|
314 |
|
# respect -n |
315 |
|
case $1 in |
316 |
|
-n) shift; opts="n" ;; |
317 |
|
esac |
318 |
|
|
319 |
|
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
320 |
|
} |
321 |
|
|
322 |
|
# prints return values of get | enabled even in quiet mode |
323 |
|
rvecho() |
324 |
|
{ |
325 |
|
local COLPURPLE="\033[1;35m" |
326 |
|
local COLDEFAULT="\033[0m" |
327 |
|
local opts |
328 |
|
local webcrlf |
329 |
|
|
330 |
|
if [[ ${NOCOLORS} = true ]] |
331 |
|
then |
332 |
|
COLPURPLE="" |
333 |
|
COLDEFAULT="" |
334 |
|
fi |
335 |
|
|
336 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
337 |
|
|
338 |
|
# respect -n |
339 |
|
case $1 in |
340 |
|
-n) shift; opts="n" ;; |
341 |
|
esac |
342 |
|
|
343 |
|
echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" |
344 |
|
} |
345 |
|
|
346 |
|
# prints debug messages if requested | enabled even in quiet mode |
347 |
|
decho() |
348 |
|
{ |
349 |
|
# print nothing if debug mode was *not* requested |
350 |
|
[[ ${DEBUG} != 1 ]] && return |
351 |
|
|
352 |
|
eecho "DEBUG: ${@}" |
353 |
|
} |
354 |
|
|
355 |
|
path_not_empty() |
356 |
|
{ |
357 |
|
local path="$1" |
358 |
|
[[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 |
359 |
|
|
360 |
|
# return ERR if path does not exist |
361 |
|
[[ ! -d ${path} ]] && return 1 |
362 |
|
# return ERR if path empty |
363 |
|
[[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1 |
364 |
|
|
365 |
|
# every thing went ok, directory not empty |
366 |
|
return 0 |
367 |
|
} |
368 |
|
|
369 |
|
help_daemon_mroot() |
370 |
|
{ |
371 |
|
mecho "get daemon.mroot" |
372 |
|
mecho " Prints current MROOT variable." |
373 |
|
mecho |
374 |
|
mecho "set daemon.mroot [path]" |
375 |
|
mecho " set MROOT variable to given path." |
376 |
|
} |
377 |
|
|
378 |
|
get_daemon_mroot() |
379 |
|
{ |
380 |
|
rvecho "${MROOT}" |
381 |
|
} |
382 |
|
|
383 |
|
set_daemon_mroot() |
384 |
|
{ |
385 |
|
local path=$1 |
386 |
|
|
387 |
|
if [[ -d ${path} ]] |
388 |
|
then |
389 |
|
export MROOT="${path}" |
390 |
|
decho "MROOT='${MROOT}' is set." |
391 |
|
else |
392 |
|
eecho "Path '${path}' does not exist. MROOT not set." |
393 |
|
fi |
394 |
|
} |
395 |
|
|
396 |
|
list_files_in_directory() |
397 |
|
{ |
398 |
|
local i |
399 |
|
local retval |
400 |
|
local path |
401 |
|
local opts |
402 |
|
local type |
403 |
|
|
404 |
|
# basic getops |
405 |
|
for i in $* |
406 |
|
do |
407 |
|
case $1 in |
408 |
|
-mindepth) shift; opts+=" -mindepth $1" ;; |
409 |
|
-maxdepth) shift; opts+=" -maxdepth $1" ;; |
410 |
|
-type) shift; type="$1" ;; |
411 |
|
'') continue ;; |
412 |
|
*) path="$1" ;; |
413 |
|
esac |
414 |
|
shift |
415 |
|
done |
416 |
|
|
417 |
|
if [[ -z ${path} ]] |
418 |
|
then |
419 |
|
eecho "No path given." |
420 |
|
return 1 |
421 |
|
fi |
422 |
|
|
423 |
|
if [[ ! -d ${path} ]] |
424 |
|
then |
425 |
|
eecho "Directory '${path}' does not exist." |
426 |
|
return 1 |
427 |
|
fi |
428 |
|
|
429 |
|
# default to files |
430 |
|
[[ -z ${type} ]] && type=f |
431 |
|
|
432 |
|
for i in $(find ${path} ${opts} -type ${type} | sort) |
433 |
|
do |
434 |
|
if [[ -z ${retval} ]] |
435 |
|
then |
436 |
|
retval="$(basename ${i})" |
437 |
|
else |
438 |
|
retval="${retval} $(basename ${i})" |
439 |
|
fi |
440 |
|
done |
441 |
|
|
442 |
|
rvecho "${retval}" |
443 |
} |
} |