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 |
# # import_resource $table $serial $resource $value |
# # import_resource $table $serial $resource $value |
24 |
# import_resource() |
# import_resource() |
25 |
# { |
# { |
46 |
local cmd |
local cmd |
47 |
local argv |
local argv |
48 |
|
|
49 |
if validate_session |
if valid_session |
50 |
then |
then |
51 |
class="${caller%.*}" |
class="${caller%.*}" |
52 |
cmd="${caller#*.}" |
cmd="${caller#*.}" |
64 |
then |
then |
65 |
"${method}"_"${class}"_"${cmd}" ${argv} |
"${method}"_"${class}"_"${cmd}" ${argv} |
66 |
else |
else |
67 |
echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
68 |
fi |
fi |
69 |
else |
else |
70 |
invalid_session |
invalid_session |
78 |
|
|
79 |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
80 |
mecho "Global commands:" |
mecho "Global commands:" |
81 |
mecho "\timport - import settings to database" |
mecho "\timport - import settings to database" |
82 |
mecho "\tget - shows current value for a settings" |
mecho "\tget - shows current value for a settings" |
83 |
mecho "\tset - sets value for a setting" |
mecho "\tset - sets value for a setting" |
84 |
mecho "\tauth - authenticate to the daemon" |
mecho "\tauth - authenticate to the daemon" |
85 |
mecho "\tprovide - shows provides of a system" |
mecho "\tprovide - shows provides of a system" |
86 |
mecho "\thelp - shows help" |
mecho "\trequire - verify plugin requirements" |
87 |
|
mecho "\treload - reloads all client classes plugins" |
88 |
|
mecho "\trestart - restarts the daemon" |
89 |
|
mecho "\tnocolors - disable colors, useful for the webclient" |
90 |
|
mecho "\tquiet - do not print any unecessary messages" |
91 |
|
mecho "\thelp - shows help" |
92 |
|
mecho "\tquit - quits the connection to the server" |
93 |
mecho |
mecho |
94 |
mecho "Help topics:" |
mecho "Help topics:" |
95 |
for i in ${topics} |
for i in ${topics} |
101 |
|
|
102 |
mecho "\t${i}" |
mecho "\t${i}" |
103 |
done |
done |
104 |
|
mecho |
105 |
|
mecho "Type 'help [topic]' for more information about every topic." |
106 |
} |
} |
107 |
|
|
108 |
# 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 |
109 |
x11runas() |
x11runas() |
110 |
{ |
{ |
111 |
su - "${MCORE_UNPRIV_USER}" -c "$@" |
if [[ -n $(pidof X) ]] |
112 |
|
then |
113 |
|
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
114 |
|
fi |
115 |
} |
} |
116 |
|
|
117 |
addconfig() |
addconfig() |
118 |
{ |
{ |
119 |
|
local opts |
120 |
|
|
121 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
122 |
then |
then |
123 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
124 |
return 1 |
return 1 |
125 |
fi |
fi |
126 |
|
|
128 |
then |
then |
129 |
install -d $(dirname ${CONFIG}) |
install -d $(dirname ${CONFIG}) |
130 |
fi |
fi |
131 |
echo "$@" >> ${CONFIG} |
|
132 |
|
# check for opts |
133 |
|
case $1 in |
134 |
|
-n) shift; opts=" -n" ;; |
135 |
|
-e) shift; opts=" -e" ;; |
136 |
|
esac |
137 |
|
|
138 |
|
echo ${opts} "$@" >> ${CONFIG} |
139 |
} |
} |
140 |
|
|
141 |
clearconfig() |
clearconfig() |
142 |
{ |
{ |
143 |
if [[ -z ${CONFIG} ]] |
if [[ -z ${CONFIG} ]] |
144 |
then |
then |
145 |
echo "You must define \$CONFIG varibale first!" |
eecho "You must define \$CONFIG varibale first!" |
146 |
return 1 |
return 1 |
147 |
fi |
fi |
148 |
|
|
153 |
: > ${CONFIG} |
: > ${CONFIG} |
154 |
} |
} |
155 |
|
|
156 |
|
# no_duplicate $list $item |
157 |
|
no_duplicate() |
158 |
|
{ |
159 |
|
local i |
160 |
|
local list="$1" |
161 |
|
local item="$2" |
162 |
|
|
163 |
|
for i in ${list} |
164 |
|
do |
165 |
|
[[ ${i} = ${item} ]] && return 1 |
166 |
|
done |
167 |
|
|
168 |
|
return 0 |
169 |
|
} |
170 |
|
|
171 |
require() |
require() |
172 |
{ |
{ |
173 |
local requires="$@" |
local requires="$@" |
175 |
|
|
176 |
for i in ${requires} |
for i in ${requires} |
177 |
do |
do |
178 |
export REQUIRE="${REQUIRE} ${i}" |
# check for duplicate provides |
179 |
|
if no_duplicate "${PROVIDE}" "${i}" |
180 |
|
then |
181 |
|
export REQUIRE="${REQUIRE} ${i}" |
182 |
|
else |
183 |
|
decho "duplicate provide '${i}' detected!" |
184 |
|
fi |
185 |
done |
done |
186 |
} |
} |
187 |
|
|
188 |
not_provided() |
verify_requirements() |
189 |
{ |
{ |
190 |
local i |
local req |
191 |
local item="$1" |
local prov |
192 |
|
local missing |
193 |
|
local sorted |
194 |
|
|
195 |
for i in ${PROVIDE} |
for req in ${REQUIRE} |
196 |
do |
do |
197 |
[[ ${i} = ${item} ]] && return 1 |
# scan PROVIDE for dupes |
198 |
|
# if a dupe is found, then requirement is fullfilled |
199 |
|
# else add to missing |
200 |
|
if no_duplicate "${PROVIDE}" "${req}" |
201 |
|
then |
202 |
|
missing="${missing} ${req}" |
203 |
|
fi |
204 |
done |
done |
205 |
|
|
206 |
return 0 |
# sort them alpabetically |
207 |
|
sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) |
208 |
|
|
209 |
|
# show missing and set the right retval |
210 |
|
if [[ -z ${missing} ]] |
211 |
|
then |
212 |
|
rvecho "${sorted}" |
213 |
|
return 0 |
214 |
|
else |
215 |
|
for req in ${sorted} |
216 |
|
do |
217 |
|
if no_duplicate "${missing}" "$req" |
218 |
|
then |
219 |
|
# print normal |
220 |
|
rvecho -n " ${req}" |
221 |
|
else |
222 |
|
# print missing |
223 |
|
eecho -n " ${req}" |
224 |
|
fi |
225 |
|
done |
226 |
|
return 1 |
227 |
|
fi |
228 |
} |
} |
229 |
|
|
230 |
provide() |
provide() |
235 |
for i in ${provides} |
for i in ${provides} |
236 |
do |
do |
237 |
# check for duplicate provides |
# check for duplicate provides |
238 |
if not_provided "${i}" |
if no_duplicate "${PROVIDE}" "${i}" |
239 |
then |
then |
240 |
export PROVIDE="${PROVIDE} ${i}" |
export PROVIDE="${PROVIDE} ${i}" |
241 |
else |
else |
242 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
243 |
fi |
fi |
244 |
done |
done |
245 |
} |
} |
251 |
# sort them alpabetically |
# sort them alpabetically |
252 |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
253 |
# do not escape, or CRLFS get printed to screen too |
# do not escape, or CRLFS get printed to screen too |
254 |
mecho ${sorted} |
rvecho ${sorted} |
255 |
} |
} |
256 |
|
|
257 |
|
# message only echo | disabled in quiet mode |
258 |
mecho() |
mecho() |
259 |
{ |
{ |
260 |
local COLCYAN="\033[1;36m" |
local COLCYAN="\033[1;36m" |
261 |
local COLDEFAULT="\033[0m" |
local COLDEFAULT="\033[0m" |
262 |
|
local opts |
263 |
|
local webcrlf |
264 |
|
|
265 |
|
# print nothing if quiet mode was requested |
266 |
|
[[ ${QUIET} = true ]] && return |
267 |
|
|
268 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = true ]] |
269 |
then |
then |
270 |
COLCYAN="" |
COLCYAN="" |
271 |
COLDEFAULT="" |
COLDEFAULT="" |
272 |
fi |
fi |
273 |
|
|
274 |
echo -e "${COLCYAN}$@${COLDEFAULT}" |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
275 |
|
|
276 |
|
# respect -n |
277 |
|
case $1 in |
278 |
|
-n) shift; opts="n" ;; |
279 |
|
esac |
280 |
|
|
281 |
|
echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" |
282 |
|
} |
283 |
|
|
284 |
|
# prints error messages | enabled even in quiet mode |
285 |
|
eecho() |
286 |
|
{ |
287 |
|
local COLRED="\033[1;31m" |
288 |
|
local COLDEFAULT="\033[0m" |
289 |
|
local opts |
290 |
|
local webcrlf |
291 |
|
|
292 |
|
if [[ ${NOCOLORS} = true ]] |
293 |
|
then |
294 |
|
COLRED="" |
295 |
|
COLDEFAULT="" |
296 |
|
fi |
297 |
|
|
298 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
299 |
|
|
300 |
|
# respect -n |
301 |
|
case $1 in |
302 |
|
-n) shift; opts="n" ;; |
303 |
|
esac |
304 |
|
|
305 |
|
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
306 |
|
} |
307 |
|
|
308 |
|
# prints return values of get | enabled even in quiet mode |
309 |
|
rvecho() |
310 |
|
{ |
311 |
|
local COLPURPLE="\033[1;35m" |
312 |
|
local COLDEFAULT="\033[0m" |
313 |
|
local opts |
314 |
|
local webcrlf |
315 |
|
|
316 |
|
if [[ ${NOCOLORS} = true ]] |
317 |
|
then |
318 |
|
COLPURPLE="" |
319 |
|
COLDEFAULT="" |
320 |
|
fi |
321 |
|
|
322 |
|
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
323 |
|
|
324 |
|
# respect -n |
325 |
|
case $1 in |
326 |
|
-n) shift; opts="n" ;; |
327 |
|
esac |
328 |
|
|
329 |
|
echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" |
330 |
|
} |
331 |
|
|
332 |
|
# prints debug messages if requested | enabled even in quiet mode |
333 |
|
decho() |
334 |
|
{ |
335 |
|
# print nothing if debug mode was *not* requested |
336 |
|
[[ ${DEBUG} != 1 ]] && return |
337 |
|
|
338 |
|
eecho "DEBUG: ${@}" |
339 |
|
} |
340 |
|
|
341 |
|
path_not_empty() |
342 |
|
{ |
343 |
|
local path="$1" |
344 |
|
[[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 |
345 |
|
|
346 |
|
# return ERR if path does not exist |
347 |
|
[[ ! -d ${path} ]] && return 1 |
348 |
|
# return ERR if path empty |
349 |
|
[[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1 |
350 |
|
|
351 |
|
# every thing went ok, directory not empty |
352 |
|
return 0 |
353 |
} |
} |