1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
|
# loads client classes from $MCORE_LIBDIR |
4 |
|
load_client_classes() |
5 |
|
{ |
6 |
|
local i |
7 |
|
|
8 |
|
# client specific |
9 |
|
for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class) |
10 |
|
do |
11 |
|
include ${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 |
# { |
# { |
54 |
# run_class $method $caller $argv1 $argv2 ... $argvN |
# run_class $method $caller $argv1 $argv2 ... $argvN |
55 |
run_class() |
run_class() |
56 |
{ |
{ |
57 |
local method="$1" |
local method="${GLOBAL_ARGV[0]" |
58 |
local caller="$2" |
local caller="${GLOBAL_ARGV[1]" |
59 |
local class |
local class |
60 |
local cmd |
local cmd |
61 |
local argv |
local i |
62 |
|
local count |
63 |
|
|
64 |
if validate_session |
if valid_session |
65 |
then |
then |
66 |
class="${caller%.*}" |
class="${caller%.*}" |
67 |
cmd="${caller#*.}" |
cmd="${caller#*.}" |
|
argv="${@/${caller}/}" # remove caller |
|
|
argv="${argv/${method}/}" # remove method |
|
68 |
|
|
69 |
# echo "method=${method}" |
# copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class |
70 |
# echo "caller=${caller}" |
unset CLASS_ARGV |
71 |
# echo "class=${class}" |
count="${#GLOBAL_ARGV[*]}" |
72 |
# echo "cmd=${cmd}" |
for (( i=2; i<count; i++ )) |
73 |
# echo "argv=${argv}" |
do |
74 |
|
CLASS_ARGV[${i}-2]="${GLOBAL_ARGV[${i}]}" |
75 |
|
done |
76 |
|
|
77 |
|
# decho "method=${method}" |
78 |
|
# decho "caller=${caller}" |
79 |
|
# decho "class=${class}" |
80 |
|
# decho "cmd=${cmd}" |
81 |
|
# decho "class argv=$(printf '\"%s\" ' ${CLASS_ARGV[*]}; printf '\n')" |
82 |
|
|
83 |
# check if class.cmd exist |
# check if class.cmd exist |
84 |
if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] |
if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] |
85 |
then |
then |
86 |
"${method}"_"${class}"_"${cmd}" ${argv} |
"${method}"_"${class}"_"${cmd}" |
87 |
else |
else |
88 |
echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'" |
89 |
fi |
fi |
90 |
else |
else |
91 |
invalid_session |
invalid_session |
99 |
|
|
100 |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
101 |
mecho "Global commands:" |
mecho "Global commands:" |
102 |
mecho "\timport - import settings to database" |
mecho "\timport - import settings to database" |
103 |
mecho "\tget - shows current value for a settings" |
mecho "\tget - shows current value for a settings" |
104 |
mecho "\tset - sets value for a setting" |
mecho "\tset - sets value for a setting" |
105 |
mecho "\tauth - authenticate to the daemon" |
mecho "\tauth - authenticate to the daemon" |
106 |
mecho "\tprovide - shows provides of a system" |
mecho "\tprovide - shows provides of a system" |
107 |
mecho "\thelp - shows help" |
mecho "\trequire - verify plugin requirements" |
108 |
|
mecho "\treload - reloads all client classes plugins" |
109 |
|
mecho "\trestart - restarts the daemon" |
110 |
|
mecho "\tstop - stops the daemon" |
111 |
|
mecho "\tnocolors - disable colors, useful for the webclient" |
112 |
|
mecho "\tcolors - enable colors" |
113 |
|
mecho "\tquiet - do not print any unecessary messages" |
114 |
|
mecho "\thelp - shows help" |
115 |
|
mecho "\tversion - prints version of the daemon" |
116 |
|
mecho "\tquit - quits the connection to the server" |
117 |
mecho |
mecho |
118 |
mecho "Help topics:" |
mecho "Help topics:" |
119 |
for i in ${topics} |
for i in ${topics} |
125 |
|
|
126 |
mecho "\t${i}" |
mecho "\t${i}" |
127 |
done |
done |
128 |
} |
mecho |
129 |
|
mecho "Type 'help [topic]' for more information about every topic." |
|
# on newer xorg-servers root is not allowed to run progs in a user session |
|
|
x11runas() |
|
|
{ |
|
|
su - "${MCORE_UNPRIV_USER}" -c "$@" |
|
|
} |
|
|
|
|
|
addconfig() |
|
|
{ |
|
|
if [[ -z ${CONFIG} ]] |
|
|
then |
|
|
echo "You must define \$CONFIG varibale first!" |
|
|
return 1 |
|
|
fi |
|
|
|
|
|
if [[ ! -d $(dirname ${CONFIG}) ]] |
|
|
then |
|
|
install -d $(dirname ${CONFIG}) |
|
|
fi |
|
|
echo "$@" >> ${CONFIG} |
|
|
} |
|
|
|
|
|
clearconfig() |
|
|
{ |
|
|
if [[ -z ${CONFIG} ]] |
|
|
then |
|
|
echo "You must define \$CONFIG varibale first!" |
|
|
return 1 |
|
|
fi |
|
|
|
|
|
if [[ ! -d $(dirname ${CONFIG}) ]] |
|
|
then |
|
|
install -d $(dirname ${CONFIG}) |
|
|
fi |
|
|
: > ${CONFIG} |
|
130 |
} |
} |
131 |
|
|
132 |
require() |
require() |
136 |
|
|
137 |
for i in ${requires} |
for i in ${requires} |
138 |
do |
do |
139 |
export REQUIRE="${REQUIRE} ${i}" |
# check for duplicate provides |
140 |
|
if no_duplicate "${PROVIDE}" "${i}" |
141 |
|
then |
142 |
|
export REQUIRE="${REQUIRE} ${i}" |
143 |
|
else |
144 |
|
decho "duplicate provide '${i}' detected!" |
145 |
|
fi |
146 |
done |
done |
147 |
} |
} |
148 |
|
|
149 |
not_provided() |
verify_requirements() |
150 |
{ |
{ |
151 |
local i |
local req |
152 |
local item="$1" |
local prov |
153 |
|
local missing |
154 |
|
local sorted |
155 |
|
|
156 |
for i in ${PROVIDE} |
for req in ${REQUIRE} |
157 |
do |
do |
158 |
[[ ${i} = ${item} ]] && return 1 |
# scan PROVIDE for dupes |
159 |
|
# if a dupe is found, then requirement is fullfilled |
160 |
|
# else add to missing |
161 |
|
if no_duplicate "${PROVIDE}" "${req}" |
162 |
|
then |
163 |
|
missing="${missing} ${req}" |
164 |
|
fi |
165 |
done |
done |
166 |
|
|
167 |
return 0 |
# sort them alpabetically |
168 |
|
sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) |
169 |
|
|
170 |
|
# show missing and set the right retval |
171 |
|
if [[ -z ${missing} ]] |
172 |
|
then |
173 |
|
# do not escape, or CRLFS get printed to screen too |
174 |
|
rvecho ${sorted} |
175 |
|
return 0 |
176 |
|
else |
177 |
|
for req in ${sorted} |
178 |
|
do |
179 |
|
if no_duplicate "${missing}" "$req" |
180 |
|
then |
181 |
|
# print normal |
182 |
|
rvecho -n "${req} " |
183 |
|
else |
184 |
|
# print missing |
185 |
|
eecho -n "${req} " |
186 |
|
fi |
187 |
|
done |
188 |
|
# print CRLF |
189 |
|
echo |
190 |
|
return 1 |
191 |
|
fi |
192 |
} |
} |
193 |
|
|
194 |
provide() |
provide() |
199 |
for i in ${provides} |
for i in ${provides} |
200 |
do |
do |
201 |
# check for duplicate provides |
# check for duplicate provides |
202 |
if not_provided "${i}" |
if no_duplicate "${PROVIDE}" "${i}" |
203 |
then |
then |
204 |
export PROVIDE="${PROVIDE} ${i}" |
export PROVIDE="${PROVIDE} ${i}" |
205 |
else |
else |
206 |
[[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
decho "duplicate provide '${i}' detected!" |
207 |
fi |
fi |
208 |
done |
done |
209 |
} |
} |
215 |
# sort them alpabetically |
# sort them alpabetically |
216 |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
217 |
# do not escape, or CRLFS get printed to screen too |
# do not escape, or CRLFS get printed to screen too |
218 |
mecho ${sorted} |
rvecho ${sorted} |
219 |
|
} |
220 |
|
|
221 |
|
help_daemon_mroot() |
222 |
|
{ |
223 |
|
mecho "get daemon.mroot" |
224 |
|
mecho " Prints current MROOT variable." |
225 |
|
mecho |
226 |
|
mecho "set daemon.mroot [path]" |
227 |
|
mecho " set MROOT variable to given path." |
228 |
|
} |
229 |
|
|
230 |
|
get_daemon_mroot() |
231 |
|
{ |
232 |
|
rvecho "${MROOT}" |
233 |
} |
} |
234 |
|
|
235 |
mecho() |
set_daemon_mroot() |
236 |
{ |
{ |
237 |
local COLCYAN="\033[1;36m" |
local path=$1 |
238 |
local COLDEFAULT="\033[0m" |
|
239 |
if [[ ${NOCOLORS} = true ]] |
if [[ -d ${path} ]] |
240 |
then |
then |
241 |
COLCYAN="" |
export MROOT="${path}" |
242 |
COLDEFAULT="" |
decho "MROOT='${MROOT}' is set." |
243 |
|
else |
244 |
|
eecho "Path '${path}' does not exist. MROOT not set." |
245 |
fi |
fi |
246 |
|
} |
247 |
|
|
248 |
echo -e "${COLCYAN}$@${COLDEFAULT}" |
print_version() |
249 |
|
{ |
250 |
|
echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" |
251 |
} |
} |