1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
|
# loads client classes from $MCLIBDIR |
4 |
|
load_client_classes() |
5 |
|
{ |
6 |
|
# client specific |
7 |
|
for i in ${MCLIBDIR}/include/*.client.class |
8 |
|
do |
9 |
|
source ${i} || eecho "error loading ${i}" |
10 |
|
done |
11 |
|
} |
12 |
|
|
13 |
|
# restarts the whole service via remote cmd |
14 |
|
restart_service() |
15 |
|
{ |
16 |
|
local pid |
17 |
|
for pid in $(pidof sslsvd) |
18 |
|
do |
19 |
|
kill -SIGHUP ${pid} |
20 |
|
done |
21 |
|
} |
22 |
|
|
23 |
|
# 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 |
# # import_resource $table $serial $resource $value |
36 |
# import_resource() |
# import_resource() |
37 |
# { |
# { |
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 "\tquiet - do not print any unecessary messages" |
104 |
|
mecho "\thelp - shows help" |
105 |
|
mecho "\tquit - quits the connection to the server" |
106 |
mecho |
mecho |
107 |
mecho "Help topics:" |
mecho "Help topics:" |
108 |
for i in ${topics} |
for i in ${topics} |
114 |
|
|
115 |
mecho "\t${i}" |
mecho "\t${i}" |
116 |
done |
done |
117 |
|
mecho |
118 |
|
mecho "Type 'help [topic]' for more information about every topic." |
119 |
} |
} |
120 |
|
|
121 |
# 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 |
122 |
x11runas() |
x11runas() |
123 |
{ |
{ |
124 |
su - "${MCORE_UNPRIV_USER}" -c "$@" |
if [[ -n $(pidof X) ]] |
125 |
|
then |
126 |
|
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
127 |
|
fi |
128 |
} |
} |
129 |
|
|
130 |
addconfig() |
addconfig() |
131 |
{ |
{ |
132 |
|
local opts |
133 |
|
|
134 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
135 |
then |
then |
136 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
137 |
return 1 |
return 1 |
138 |
fi |
fi |
139 |
|
|
141 |
then |
then |
142 |
install -d $(dirname ${CONFIG}) |
install -d $(dirname ${CONFIG}) |
143 |
fi |
fi |
144 |
echo "$@" >> ${CONFIG} |
|
145 |
|
# check for opts |
146 |
|
case $1 in |
147 |
|
-n) shift; opts=" -n" ;; |
148 |
|
-e) shift; opts=" -e" ;; |
149 |
|
esac |
150 |
|
|
151 |
|
echo ${opts} "$@" >> ${CONFIG} |
152 |
} |
} |
153 |
|
|
154 |
clearconfig() |
clearconfig() |
155 |
{ |
{ |
156 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
157 |
then |
then |
158 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
159 |
return 1 |
return 1 |
160 |
fi |
fi |
161 |
|
|
166 |
: > ${CONFIG} |
: > ${CONFIG} |
167 |
} |
} |
168 |
|
|
169 |
|
# no_duplicate $list $item |
170 |
|
no_duplicate() |
171 |
|
{ |
172 |
|
local i |
173 |
|
local list="$1" |
174 |
|
local item="$2" |
175 |
|
|
176 |
|
for i in ${list} |
177 |
|
do |
178 |
|
[[ ${i} = ${item} ]] && return 1 |
179 |
|
done |
180 |
|
|
181 |
|
return 0 |
182 |
|
} |
183 |
|
|
184 |
require() |
require() |
185 |
{ |
{ |
186 |
local requires="$@" |
local requires="$@" |
188 |
|
|
189 |
for i in ${requires} |
for i in ${requires} |
190 |
do |
do |
191 |
export REQUIRE="${REQUIRE} ${i}" |
# check for duplicate provides |
192 |
|
if no_duplicate "${PROVIDE}" "${i}" |
193 |
|
then |
194 |
|
export REQUIRE="${REQUIRE} ${i}" |
195 |
|
else |
196 |
|
decho "duplicate provide '${i}' detected!" |
197 |
|
fi |
198 |
done |
done |
199 |
} |
} |
200 |
|
|
201 |
not_provided() |
verify_requirements() |
202 |
{ |
{ |
203 |
local i |
local req |
204 |
local item="$1" |
local prov |
205 |
|
local missing |
206 |
|
local sorted |
207 |
|
|
208 |
for i in ${PROVIDE} |
for req in ${REQUIRE} |
209 |
do |
do |
210 |
[[ ${i} = ${item} ]] && return 1 |
# scan PROVIDE for dupes |
211 |
|
# if a dupe is found, then requirement is fullfilled |
212 |
|
# else add to missing |
213 |
|
if no_duplicate "${PROVIDE}" "${req}" |
214 |
|
then |
215 |
|
missing="${missing} ${req}" |
216 |
|
fi |
217 |
done |
done |
218 |
|
|
219 |
return 0 |
# sort them alpabetically |
220 |
|
sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) |
221 |
|
|
222 |
|
# show missing and set the right retval |
223 |
|
if [[ -z ${missing} ]] |
224 |
|
then |
225 |
|
rvecho "${sorted}" |
226 |
|
return 0 |
227 |
|
else |
228 |
|
for req in ${sorted} |
229 |
|
do |
230 |
|
if no_duplicate "${missing}" "$req" |
231 |
|
then |
232 |
|
# print normal |
233 |
|
rvecho -n " ${req}" |
234 |
|
else |
235 |
|
# print missing |
236 |
|
eecho -n " ${req}" |
237 |
|
fi |
238 |
|
done |
239 |
|
return 1 |
240 |
|
fi |
241 |
} |
} |
242 |
|
|
243 |
provide() |
provide() |
248 |
for i in ${provides} |
for i in ${provides} |
249 |
do |
do |
250 |
# check for duplicate provides |
# check for duplicate provides |
251 |
if not_provided "${i}" |
if no_duplicate "${PROVIDE}" "${i}" |
252 |
then |
then |
253 |
export PROVIDE="${PROVIDE} ${i}" |
export PROVIDE="${PROVIDE} ${i}" |
254 |
else |
else |
255 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
256 |
fi |
fi |
257 |
done |
done |
258 |
} |
} |
264 |
# sort them alpabetically |
# sort them alpabetically |
265 |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
266 |
# do not escape, or CRLFS get printed to screen too |
# do not escape, or CRLFS get printed to screen too |
267 |
mecho ${sorted} |
rvecho ${sorted} |
268 |
} |
} |
269 |
|
|
270 |
|
# message only echo | disabled in quiet mode |
271 |
mecho() |
mecho() |
272 |
{ |
{ |
273 |
local COLCYAN="\033[1;36m" |
local COLCYAN="\033[1;36m" |
274 |
local COLDEFAULT="\033[0m" |
local COLDEFAULT="\033[0m" |
275 |
|
local opts |
276 |
|
local webcrlf |
277 |
|
|
278 |
|
# print nothing if quiet mode was requested |
279 |
|
[[ ${QUIET} = true ]] && return |
280 |
|
|
281 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = true ]] |
282 |
then |
then |
283 |
COLCYAN="" |
COLCYAN="" |
284 |
COLDEFAULT="" |
COLDEFAULT="" |
285 |
fi |
fi |
286 |
|
|
287 |
echo -e "${COLCYAN}$@${COLDEFAULT}" |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
288 |
|
|
289 |
|
# respect -n |
290 |
|
case $1 in |
291 |
|
-n) shift; opts="n" ;; |
292 |
|
esac |
293 |
|
|
294 |
|
echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" |
295 |
|
} |
296 |
|
|
297 |
|
# prints error messages | enabled even in quiet mode |
298 |
|
eecho() |
299 |
|
{ |
300 |
|
local COLRED="\033[1;31m" |
301 |
|
local COLDEFAULT="\033[0m" |
302 |
|
local opts |
303 |
|
local webcrlf |
304 |
|
|
305 |
|
if [[ ${NOCOLORS} = true ]] |
306 |
|
then |
307 |
|
COLRED="" |
308 |
|
COLDEFAULT="" |
309 |
|
fi |
310 |
|
|
311 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
312 |
|
|
313 |
|
# respect -n |
314 |
|
case $1 in |
315 |
|
-n) shift; opts="n" ;; |
316 |
|
esac |
317 |
|
|
318 |
|
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
319 |
|
} |
320 |
|
|
321 |
|
# prints return values of get | enabled even in quiet mode |
322 |
|
rvecho() |
323 |
|
{ |
324 |
|
local COLPURPLE="\033[1;35m" |
325 |
|
local COLDEFAULT="\033[0m" |
326 |
|
local opts |
327 |
|
local webcrlf |
328 |
|
|
329 |
|
if [[ ${NOCOLORS} = true ]] |
330 |
|
then |
331 |
|
COLPURPLE="" |
332 |
|
COLDEFAULT="" |
333 |
|
fi |
334 |
|
|
335 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
336 |
|
|
337 |
|
# respect -n |
338 |
|
case $1 in |
339 |
|
-n) shift; opts="n" ;; |
340 |
|
esac |
341 |
|
|
342 |
|
echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" |
343 |
|
} |
344 |
|
|
345 |
|
# prints debug messages if requested | enabled even in quiet mode |
346 |
|
decho() |
347 |
|
{ |
348 |
|
# print nothing if debug mode was *not* requested |
349 |
|
[[ ${DEBUG} != 1 ]] && return |
350 |
|
|
351 |
|
eecho "DEBUG: ${@}" |
352 |
|
} |
353 |
|
|
354 |
|
path_not_empty() |
355 |
|
{ |
356 |
|
local path="$1" |
357 |
|
[[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 |
358 |
|
|
359 |
|
# return ERR if path does not exist |
360 |
|
[[ ! -d ${path} ]] && return 1 |
361 |
|
# return ERR if path empty |
362 |
|
[[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1 |
363 |
|
|
364 |
|
# every thing went ok, directory not empty |
365 |
|
return 0 |
366 |
} |
} |