1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
|
# loads client classes from $MCLIBDIR |
4 |
|
load_client_classes() |
5 |
|
{ |
6 |
|
local i |
7 |
|
|
8 |
|
# client specific |
9 |
|
for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class) |
10 |
|
do |
11 |
|
source ${i} || eecho "error loading ${i}" |
12 |
|
done |
13 |
|
} |
14 |
|
|
15 |
|
# restarts the whole service via remote cmd |
16 |
|
restart_service() |
17 |
|
{ |
18 |
|
local pid |
19 |
|
for pid in $(pidof sslsvd) |
20 |
|
do |
21 |
|
kill -SIGHUP ${pid} |
22 |
|
done |
23 |
|
} |
24 |
|
|
25 |
|
# stops the whole service via remote cmd |
26 |
|
stop_service() |
27 |
|
{ |
28 |
|
local pid |
29 |
|
for pid in $(pidof sslsvd) |
30 |
|
do |
31 |
|
kill -15 ${pid} |
32 |
|
sleep 1 |
33 |
|
kill -9 ${pid} |
34 |
|
done |
35 |
|
} |
36 |
|
|
37 |
# # import_resource $table $serial $resource $value |
# # import_resource $table $serial $resource $value |
38 |
# import_resource() |
# import_resource() |
39 |
# { |
# { |
60 |
local cmd |
local cmd |
61 |
local argv |
local argv |
62 |
|
|
63 |
if validate_session |
if valid_session |
64 |
then |
then |
65 |
class="${caller%.*}" |
class="${caller%.*}" |
66 |
cmd="${caller#*.}" |
cmd="${caller#*.}" |
78 |
then |
then |
79 |
"${method}"_"${class}"_"${cmd}" ${argv} |
"${method}"_"${class}"_"${cmd}" ${argv} |
80 |
else |
else |
81 |
echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
82 |
fi |
fi |
83 |
else |
else |
84 |
invalid_session |
invalid_session |
92 |
|
|
93 |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
94 |
mecho "Global commands:" |
mecho "Global commands:" |
95 |
mecho "\timport - import settings to database" |
mecho "\timport - import settings to database" |
96 |
mecho "\tget - shows current value for a settings" |
mecho "\tget - shows current value for a settings" |
97 |
mecho "\tset - sets value for a setting" |
mecho "\tset - sets value for a setting" |
98 |
mecho "\tauth - authenticate to the daemon" |
mecho "\tauth - authenticate to the daemon" |
99 |
mecho "\tprovide - shows provides of a system" |
mecho "\tprovide - shows provides of a system" |
100 |
mecho "\thelp - shows help" |
mecho "\trequire - verify plugin requirements" |
101 |
mecho "\tquit - quits the connection to the server" |
mecho "\treload - reloads all client classes plugins" |
102 |
|
mecho "\trestart - restarts the daemon" |
103 |
|
mecho "\tstop - stops the daemon" |
104 |
|
mecho "\tnocolors - disable colors, useful for the webclient" |
105 |
|
mecho "\tcolors - enable colors" |
106 |
|
mecho "\tquiet - do not print any unecessary messages" |
107 |
|
mecho "\thelp - shows help" |
108 |
|
mecho "\tversion - prints version of the daemon" |
109 |
|
mecho "\tquit - quits the connection to the server" |
110 |
mecho |
mecho |
111 |
mecho "Help topics:" |
mecho "Help topics:" |
112 |
for i in ${topics} |
for i in ${topics} |
125 |
# 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 |
126 |
x11runas() |
x11runas() |
127 |
{ |
{ |
128 |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
if [[ -n $(pidof X) ]] |
129 |
|
then |
130 |
|
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
131 |
|
fi |
132 |
} |
} |
133 |
|
|
134 |
addconfig() |
addconfig() |
135 |
{ |
{ |
136 |
|
local opts |
137 |
|
|
138 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
139 |
then |
then |
140 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
141 |
return 1 |
return 1 |
142 |
fi |
fi |
143 |
|
|
145 |
then |
then |
146 |
install -d $(dirname ${CONFIG}) |
install -d $(dirname ${CONFIG}) |
147 |
fi |
fi |
148 |
echo "$@" >> ${CONFIG} |
|
149 |
|
# check for opts |
150 |
|
case $1 in |
151 |
|
-n) shift; opts=" -n" ;; |
152 |
|
-e) shift; opts=" -e" ;; |
153 |
|
esac |
154 |
|
|
155 |
|
echo ${opts} "$@" >> ${CONFIG} |
156 |
} |
} |
157 |
|
|
158 |
clearconfig() |
clearconfig() |
159 |
{ |
{ |
160 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
161 |
then |
then |
162 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
163 |
return 1 |
return 1 |
164 |
fi |
fi |
165 |
|
|
197 |
then |
then |
198 |
export REQUIRE="${REQUIRE} ${i}" |
export REQUIRE="${REQUIRE} ${i}" |
199 |
else |
else |
200 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
201 |
fi |
fi |
202 |
done |
done |
203 |
} |
} |
226 |
# show missing and set the right retval |
# show missing and set the right retval |
227 |
if [[ -z ${missing} ]] |
if [[ -z ${missing} ]] |
228 |
then |
then |
229 |
mecho "${sorted}" |
rvecho "${sorted}" |
230 |
return 0 |
return 0 |
231 |
else |
else |
232 |
for req in ${sorted} |
for req in ${sorted} |
234 |
if no_duplicate "${missing}" "$req" |
if no_duplicate "${missing}" "$req" |
235 |
then |
then |
236 |
# print normal |
# print normal |
237 |
mecho -n " ${req}" |
rvecho -n " ${req}" |
238 |
else |
else |
239 |
# print missing |
# print missing |
240 |
eecho -n " ${req}" |
eecho -n " ${req}" |
256 |
then |
then |
257 |
export PROVIDE="${PROVIDE} ${i}" |
export PROVIDE="${PROVIDE} ${i}" |
258 |
else |
else |
259 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
260 |
fi |
fi |
261 |
done |
done |
262 |
} |
} |
268 |
# sort them alpabetically |
# sort them alpabetically |
269 |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
270 |
# do not escape, or CRLFS get printed to screen too |
# do not escape, or CRLFS get printed to screen too |
271 |
mecho ${sorted} |
rvecho ${sorted} |
272 |
} |
} |
273 |
|
|
274 |
|
# message only echo | disabled in quiet mode |
275 |
mecho() |
mecho() |
276 |
{ |
{ |
277 |
local COLCYAN="\033[1;36m" |
local COLCYAN="\033[1;36m" |
278 |
local COLDEFAULT="\033[0m" |
local COLDEFAULT="\033[0m" |
279 |
local opts |
local opts |
280 |
|
local webcrlf |
281 |
|
|
282 |
|
# print nothing if quiet mode was requested |
283 |
|
[[ ${QUIET} = true ]] && return |
284 |
|
|
285 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = true ]] |
286 |
then |
then |
288 |
COLDEFAULT="" |
COLDEFAULT="" |
289 |
fi |
fi |
290 |
|
|
291 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
292 |
|
|
293 |
# respect -n |
# respect -n |
294 |
case $1 in |
case $1 in |
295 |
-n) shift; opts="n" ;; |
-n) shift; opts="n" ;; |
296 |
esac |
esac |
297 |
|
|
298 |
echo -e${opts} "${COLCYAN}$@${COLDEFAULT}" |
echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" |
299 |
} |
} |
300 |
|
|
301 |
|
# prints error messages | enabled even in quiet mode |
302 |
eecho() |
eecho() |
303 |
{ |
{ |
304 |
local COLRED="\033[1;31m" |
local COLRED="\033[1;31m" |
305 |
local COLDEFAULT="\033[0m" |
local COLDEFAULT="\033[0m" |
306 |
local opts |
local opts |
307 |
|
local webcrlf |
308 |
|
|
309 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = true ]] |
310 |
then |
then |
312 |
COLDEFAULT="" |
COLDEFAULT="" |
313 |
fi |
fi |
314 |
|
|
315 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
316 |
|
|
317 |
# respect -n |
# respect -n |
318 |
case $1 in |
case $1 in |
319 |
-n) shift; opts="n" ;; |
-n) shift; opts="n" ;; |
320 |
esac |
esac |
321 |
|
|
322 |
echo -e${opts} "${COLRED}$@${COLDEFAULT}" |
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
323 |
|
} |
324 |
|
|
325 |
|
# prints return values of get | enabled even in quiet mode |
326 |
|
rvecho() |
327 |
|
{ |
328 |
|
local COLPURPLE="\033[1;35m" |
329 |
|
local COLDEFAULT="\033[0m" |
330 |
|
local opts |
331 |
|
local webcrlf |
332 |
|
|
333 |
|
if [[ ${NOCOLORS} = true ]] |
334 |
|
then |
335 |
|
COLPURPLE="" |
336 |
|
COLDEFAULT="" |
337 |
|
fi |
338 |
|
|
339 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
340 |
|
|
341 |
|
# respect -n |
342 |
|
case $1 in |
343 |
|
-n) shift; opts="n" ;; |
344 |
|
esac |
345 |
|
|
346 |
|
echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" |
347 |
|
} |
348 |
|
|
349 |
|
# prints debug messages if requested | enabled even in quiet mode |
350 |
|
decho() |
351 |
|
{ |
352 |
|
# print nothing if debug mode was *not* requested |
353 |
|
[[ ${DEBUG} != 1 ]] && return |
354 |
|
|
355 |
|
eecho "DEBUG: ${@}" |
356 |
} |
} |
357 |
|
|
358 |
path_not_empty() |
path_not_empty() |
359 |
{ |
{ |
360 |
local path="$1" |
local path="$1" |
361 |
[[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1 |
[[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 |
362 |
|
|
363 |
# return ERR if path does not exist |
# return ERR if path does not exist |
364 |
[[ ! -d ${path} ]] && return 1 |
[[ ! -d ${path} ]] && return 1 |
368 |
# every thing went ok, directory not empty |
# every thing went ok, directory not empty |
369 |
return 0 |
return 0 |
370 |
} |
} |
371 |
|
|
372 |
|
help_daemon_mroot() |
373 |
|
{ |
374 |
|
mecho "get daemon.mroot" |
375 |
|
mecho " Prints current MROOT variable." |
376 |
|
mecho |
377 |
|
mecho "set daemon.mroot [path]" |
378 |
|
mecho " set MROOT variable to given path." |
379 |
|
} |
380 |
|
|
381 |
|
get_daemon_mroot() |
382 |
|
{ |
383 |
|
rvecho "${MROOT}" |
384 |
|
} |
385 |
|
|
386 |
|
set_daemon_mroot() |
387 |
|
{ |
388 |
|
local path=$1 |
389 |
|
|
390 |
|
if [[ -d ${path} ]] |
391 |
|
then |
392 |
|
export MROOT="${path}" |
393 |
|
decho "MROOT='${MROOT}' is set." |
394 |
|
else |
395 |
|
eecho "Path '${path}' does not exist. MROOT not set." |
396 |
|
fi |
397 |
|
} |
398 |
|
|
399 |
|
list_files_in_directory() |
400 |
|
{ |
401 |
|
local i |
402 |
|
local retval |
403 |
|
local path |
404 |
|
local opts |
405 |
|
local type |
406 |
|
|
407 |
|
# basic getops |
408 |
|
for i in $* |
409 |
|
do |
410 |
|
case $1 in |
411 |
|
-mindepth) shift; opts+=" -mindepth $1" ;; |
412 |
|
-maxdepth) shift; opts+=" -maxdepth $1" ;; |
413 |
|
-type) shift; type="$1" ;; |
414 |
|
-name) shift; opts+="-name $1" ;; |
415 |
|
'') continue ;; |
416 |
|
*) path="$1" ;; |
417 |
|
esac |
418 |
|
shift |
419 |
|
done |
420 |
|
|
421 |
|
if [[ -z ${path} ]] |
422 |
|
then |
423 |
|
eecho "No path given." |
424 |
|
return 1 |
425 |
|
fi |
426 |
|
|
427 |
|
if [[ ! -d ${path} ]] |
428 |
|
then |
429 |
|
eecho "Directory '${path}' does not exist." |
430 |
|
return 1 |
431 |
|
fi |
432 |
|
|
433 |
|
# default to files |
434 |
|
[[ -z ${type} ]] && type=f |
435 |
|
|
436 |
|
for i in $(find ${path} ${opts} -type ${type} | sort) |
437 |
|
do |
438 |
|
if [[ -z ${retval} ]] |
439 |
|
then |
440 |
|
retval="$(basename ${i})" |
441 |
|
else |
442 |
|
retval="${retval} $(basename ${i})" |
443 |
|
fi |
444 |
|
done |
445 |
|
|
446 |
|
rvecho "${retval}" |
447 |
|
} |
448 |
|
|
449 |
|
print_version() |
450 |
|
{ |
451 |
|
echo "mcored-$(<${MCLIBDIR}/VERSION)" |
452 |
|
} |
453 |
|
|