9 |
local webcrlf |
local webcrlf |
10 |
|
|
11 |
# print nothing if quiet mode was requested |
# print nothing if quiet mode was requested |
12 |
[[ ${QUIET} = true ]] && return |
[[ ${QUIET} = 1 ]] && return |
13 |
|
|
14 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = 1 ]] |
15 |
then |
then |
16 |
COLCYAN="" |
COLCYAN="" |
17 |
COLDEFAULT="" |
COLDEFAULT="" |
18 |
fi |
fi |
19 |
|
|
20 |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
[[ ${WEBCRLF} = 1 ]] && webcrlf="<br>" |
21 |
|
|
22 |
# respect -n |
# respect -n |
23 |
case $1 in |
case $1 in |
35 |
local opts |
local opts |
36 |
local webcrlf |
local webcrlf |
37 |
|
|
38 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = 1 ]] |
39 |
then |
then |
40 |
COLRED="" |
COLRED="" |
41 |
COLDEFAULT="" |
COLDEFAULT="" |
42 |
fi |
fi |
43 |
|
|
44 |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
[[ ${WEBCRLF} = 1 ]] && webcrlf="<br>" |
45 |
|
|
46 |
# respect -n |
# respect -n |
47 |
case $1 in |
case $1 in |
48 |
-n) shift; opts="n" ;; |
-n) shift; opts="n" ;; |
49 |
esac |
esac |
50 |
|
|
51 |
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
# echo to stderr |
52 |
|
echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" 1>&2 |
53 |
} |
} |
54 |
|
|
55 |
# prints return values of get | enabled even in quiet mode |
# prints return values of get | enabled even in quiet mode |
60 |
local opts |
local opts |
61 |
local webcrlf |
local webcrlf |
62 |
|
|
63 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = 1 ]] |
64 |
then |
then |
65 |
COLPURPLE="" |
COLPURPLE="" |
66 |
COLDEFAULT="" |
COLDEFAULT="" |
67 |
fi |
fi |
68 |
|
|
69 |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
[[ ${WEBCRLF} = 1 ]] && webcrlf="<br>" |
70 |
|
|
71 |
# respect -n |
# respect -n |
72 |
case $1 in |
case $1 in |
85 |
eecho "DEBUG: ${@}" |
eecho "DEBUG: ${@}" |
86 |
} |
} |
87 |
|
|
88 |
|
# source a file with debug information |
89 |
|
include() |
90 |
|
{ |
91 |
|
local retval |
92 |
|
|
93 |
|
if [ -f $@ ] |
94 |
|
then |
95 |
|
decho "including '$@'" |
96 |
|
source $@ |
97 |
|
retval=$? |
98 |
|
else |
99 |
|
decho "include: '$@' not found" |
100 |
|
retval=1 |
101 |
|
fi |
102 |
|
|
103 |
|
return ${retval} |
104 |
|
} |
105 |
|
|
106 |
# adds a line to a configuration file defined by the $CONFIG variable |
# adds a line to a configuration file defined by the $CONFIG variable |
107 |
# $CONFIG="/etc/conf.d/mcore" addconfig 'LIBDIR="/usr/lib"' |
# $CONFIG="/etc/conf.d/mcore" addconfig 'LIBDIR="/usr/lib"' |
108 |
addconfig() |
addconfig() |
150 |
# this wrapper runs a command in the xsession of the unpriv_user |
# this wrapper runs a command in the xsession of the unpriv_user |
151 |
x11runas() |
x11runas() |
152 |
{ |
{ |
153 |
if [[ -n $(pidof X) ]] |
if [[ -n $(pidof X) ]] || [[ -n $(pidof Xorg) ]] || [[ -n $(pidof Xorg.bin) ]] |
154 |
then |
then |
155 |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
156 |
fi |
fi |
254 |
|
|
255 |
chroot ${MROOT} ${cmd} |
chroot ${MROOT} ${cmd} |
256 |
} |
} |
257 |
|
|
258 |
|
# gets interface used to reach given ip |
259 |
|
iface_for_remote_addr() |
260 |
|
{ |
261 |
|
set -- $(ip -o route get to $1) |
262 |
|
echo $5 |
263 |
|
} |
264 |
|
|
265 |
|
# get ip from dns name |
266 |
|
dns_to_ip() |
267 |
|
{ |
268 |
|
set -- $(getent hosts $1) |
269 |
|
echo $1 |
270 |
|
} |
271 |
|
|
272 |
|
iface_for_ip() |
273 |
|
{ |
274 |
|
set -- $(ip -o addr show to $1) |
275 |
|
echo $2 |
276 |
|
} |
277 |
|
|
278 |
|
iface_for_mac() |
279 |
|
{ |
280 |
|
local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')" |
281 |
|
for interface in /sys/class/net/*; do |
282 |
|
if [ $(cat $interface/address) = "$mac" ]; then |
283 |
|
echo ${interface##*/} |
284 |
|
fi |
285 |
|
done |
286 |
|
} |
287 |
|
|
288 |
|
mac_for_iface() |
289 |
|
{ |
290 |
|
local iface="$1" |
291 |
|
if [ -f /sys/class/net/${iface}/address ] |
292 |
|
then |
293 |
|
cat /sys/class/net/${iface}/address |
294 |
|
fi |
295 |
|
} |
296 |
|
|
297 |
|
certificate_fingerprint() |
298 |
|
{ |
299 |
|
local cert_fingerprint |
300 |
|
local retval |
301 |
|
|
302 |
|
if [[ ! -f ${MCORE_CERT_FILE} ]] |
303 |
|
then |
304 |
|
eecho "MCORE_CERT_FILE '${MCORE_CERT_FILE}' does not exist." |
305 |
|
return 1 |
306 |
|
fi |
307 |
|
|
308 |
|
cert_fingerprint=$(openssl x509 -noout -modulus -in "${MCORE_CERT_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
309 |
|
retval="$?" |
310 |
|
|
311 |
|
if [[ ${retval} != 0 ]] |
312 |
|
then |
313 |
|
eecho "Error '${retval}' while generating cert_fingerprint." |
314 |
|
return 1 |
315 |
|
fi |
316 |
|
|
317 |
|
if [[ -z ${cert_fingerprint} ]] |
318 |
|
then |
319 |
|
eecho "Error: cert_fingerprint is empty" |
320 |
|
return 1 |
321 |
|
else |
322 |
|
echo "${cert_fingerprint}" |
323 |
|
fi |
324 |
|
} |
325 |
|
|
326 |
|
key_fingerprint() |
327 |
|
{ |
328 |
|
local key_fingerprint |
329 |
|
local retval |
330 |
|
|
331 |
|
if [[ ! -f ${MCORE_KEY_FILE} ]] |
332 |
|
then |
333 |
|
eecho "MCORE_KEY_FILE '${MCORE_KEY_FILE}' does not exist." |
334 |
|
return 1 |
335 |
|
fi |
336 |
|
|
337 |
|
key_fingerprint=$(openssl rsa -noout -modulus -in "${MCORE_KEY_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
338 |
|
retval="$?" |
339 |
|
|
340 |
|
if [[ ${retval} != 0 ]] |
341 |
|
then |
342 |
|
eecho "Error '${retval}' while generating key_fingerprint." |
343 |
|
return 1 |
344 |
|
fi |
345 |
|
|
346 |
|
if [[ -z ${key_fingerprint} ]] |
347 |
|
then |
348 |
|
eecho "Error: key_fingerprint is empty" |
349 |
|
return 1 |
350 |
|
else |
351 |
|
echo "${key_fingerprint}" |
352 |
|
fi |
353 |
|
} |
354 |
|
|
355 |
|
nsslsay() |
356 |
|
{ |
357 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
358 |
|
auth ${SSLSAY_USER} ${SSLSAY_PASS} |
359 |
|
$@ |
360 |
|
quit |
361 |
|
EOF |
362 |
|
} |
363 |
|
|
364 |
|
nsslsay_fingerprint() |
365 |
|
{ |
366 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
367 |
|
certauth $(certificate_fingerprint) |
368 |
|
$@ |
369 |
|
quit |
370 |
|
EOF |
371 |
|
} |
372 |
|
|
373 |
|
nsslsay_queue_init() |
374 |
|
{ |
375 |
|
SSLSAY_QUEUE=() |
376 |
|
} |
377 |
|
|
378 |
|
nsslsay_queue_add() |
379 |
|
{ |
380 |
|
SSLSAY_QUEUE+=( "$@" ) |
381 |
|
} |
382 |
|
|
383 |
|
nsslsay_queue_print() |
384 |
|
{ |
385 |
|
local count |
386 |
|
local i |
387 |
|
|
388 |
|
count="${#SSLSAY_QUEUE[*]}" |
389 |
|
for ((i=0; i < count; i++)) |
390 |
|
do |
391 |
|
echo "${SSLSAY_QUEUE[${i}]}" |
392 |
|
done |
393 |
|
} |
394 |
|
|
395 |
|
nsslsay_queue_run() |
396 |
|
{ |
397 |
|
nsslsay "$(nsslsay_queue_print)" |
398 |
|
} |
399 |
|
|
400 |
|
nsslsay_queue_run_fingerprint() |
401 |
|
{ |
402 |
|
nsslsay_fingerprint "$(nsslsay_queue_print)" |
403 |
|
} |