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 |
59 |
local opts |
local opts |
60 |
local webcrlf |
local webcrlf |
61 |
|
|
62 |
if [[ ${NOCOLORS} = true ]] |
if [[ ${NOCOLORS} = 1 ]] |
63 |
then |
then |
64 |
COLPURPLE="" |
COLPURPLE="" |
65 |
COLDEFAULT="" |
COLDEFAULT="" |
66 |
fi |
fi |
67 |
|
|
68 |
[[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
[[ ${WEBCRLF} = 1 ]] && webcrlf="<br>" |
69 |
|
|
70 |
# respect -n |
# respect -n |
71 |
case $1 in |
case $1 in |
149 |
# this wrapper runs a command in the xsession of the unpriv_user |
# this wrapper runs a command in the xsession of the unpriv_user |
150 |
x11runas() |
x11runas() |
151 |
{ |
{ |
152 |
if [[ -n $(pidof X) ]] |
if [[ -n $(pidof X) ]] || [[ -n $(pidof Xorg) ]] || [[ -n $(pidof Xorg.bin) ]] |
153 |
then |
then |
154 |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
155 |
|
else |
156 |
|
decho "x11runas(): No running X, Xorg or Xorg.bin process found" |
157 |
fi |
fi |
158 |
} |
} |
159 |
|
|
255 |
|
|
256 |
chroot ${MROOT} ${cmd} |
chroot ${MROOT} ${cmd} |
257 |
} |
} |
258 |
|
|
259 |
|
# gets interface used to reach given ip |
260 |
|
iface_for_remote_addr() |
261 |
|
{ |
262 |
|
set -- $(ip -o route get to $1) |
263 |
|
echo $5 |
264 |
|
} |
265 |
|
|
266 |
|
# get ip from dns name |
267 |
|
dns_to_ip() |
268 |
|
{ |
269 |
|
set -- $(getent hosts $1) |
270 |
|
echo $1 |
271 |
|
} |
272 |
|
|
273 |
|
iface_for_ip() |
274 |
|
{ |
275 |
|
set -- $(ip -o addr show to $1) |
276 |
|
echo $2 |
277 |
|
} |
278 |
|
|
279 |
|
iface_for_mac() |
280 |
|
{ |
281 |
|
local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')" |
282 |
|
for interface in /sys/class/net/*; do |
283 |
|
if [ $(cat $interface/address) = "$mac" ]; then |
284 |
|
echo ${interface##*/} |
285 |
|
fi |
286 |
|
done |
287 |
|
} |
288 |
|
|
289 |
|
mac_for_iface() |
290 |
|
{ |
291 |
|
local iface="$1" |
292 |
|
if [ -f /sys/class/net/${iface}/address ] |
293 |
|
then |
294 |
|
cat /sys/class/net/${iface}/address |
295 |
|
fi |
296 |
|
} |
297 |
|
|
298 |
|
certificate_fingerprint() |
299 |
|
{ |
300 |
|
local cert_fingerprint |
301 |
|
local retval |
302 |
|
|
303 |
|
if [[ ! -f ${MCORE_CERT_FILE} ]] |
304 |
|
then |
305 |
|
eecho "MCORE_CERT_FILE '${MCORE_CERT_FILE}' does not exist." |
306 |
|
return 1 |
307 |
|
fi |
308 |
|
|
309 |
|
cert_fingerprint=$(openssl x509 -noout -modulus -in "${MCORE_CERT_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
310 |
|
retval="$?" |
311 |
|
|
312 |
|
if [[ ${retval} != 0 ]] |
313 |
|
then |
314 |
|
eecho "Error '${retval}' while generating cert_fingerprint." |
315 |
|
return 1 |
316 |
|
fi |
317 |
|
|
318 |
|
if [[ -z ${cert_fingerprint} ]] |
319 |
|
then |
320 |
|
eecho "Error: cert_fingerprint is empty" |
321 |
|
return 1 |
322 |
|
else |
323 |
|
echo "${cert_fingerprint}" |
324 |
|
fi |
325 |
|
} |
326 |
|
|
327 |
|
key_fingerprint() |
328 |
|
{ |
329 |
|
local key_fingerprint |
330 |
|
local retval |
331 |
|
|
332 |
|
if [[ ! -f ${MCORE_KEY_FILE} ]] |
333 |
|
then |
334 |
|
eecho "MCORE_KEY_FILE '${MCORE_KEY_FILE}' does not exist." |
335 |
|
return 1 |
336 |
|
fi |
337 |
|
|
338 |
|
key_fingerprint=$(openssl rsa -noout -modulus -in "${MCORE_KEY_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
339 |
|
retval="$?" |
340 |
|
|
341 |
|
if [[ ${retval} != 0 ]] |
342 |
|
then |
343 |
|
eecho "Error '${retval}' while generating key_fingerprint." |
344 |
|
return 1 |
345 |
|
fi |
346 |
|
|
347 |
|
if [[ -z ${key_fingerprint} ]] |
348 |
|
then |
349 |
|
eecho "Error: key_fingerprint is empty" |
350 |
|
return 1 |
351 |
|
else |
352 |
|
echo "${key_fingerprint}" |
353 |
|
fi |
354 |
|
} |
355 |
|
|
356 |
|
nsslsay() |
357 |
|
{ |
358 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
359 |
|
auth ${SSLSAY_USER} ${SSLSAY_PASS} |
360 |
|
$@ |
361 |
|
quit |
362 |
|
EOF |
363 |
|
} |
364 |
|
|
365 |
|
nsslsay_fingerprint() |
366 |
|
{ |
367 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
368 |
|
certauth $(certificate_fingerprint) |
369 |
|
$@ |
370 |
|
quit |
371 |
|
EOF |
372 |
|
} |
373 |
|
|
374 |
|
nsslsay_queue_init() |
375 |
|
{ |
376 |
|
SSLSAY_QUEUE=() |
377 |
|
} |
378 |
|
|
379 |
|
nsslsay_queue_add() |
380 |
|
{ |
381 |
|
SSLSAY_QUEUE+=( "$@" ) |
382 |
|
} |
383 |
|
|
384 |
|
nsslsay_queue_print() |
385 |
|
{ |
386 |
|
local count |
387 |
|
local i |
388 |
|
|
389 |
|
count="${#SSLSAY_QUEUE[*]}" |
390 |
|
for ((i=0; i < count; i++)) |
391 |
|
do |
392 |
|
echo "${SSLSAY_QUEUE[${i}]}" |
393 |
|
done |
394 |
|
} |
395 |
|
|
396 |
|
nsslsay_queue_run() |
397 |
|
{ |
398 |
|
nsslsay "$(nsslsay_queue_print)" |
399 |
|
} |
400 |
|
|
401 |
|
nsslsay_queue_run_fingerprint() |
402 |
|
{ |
403 |
|
nsslsay_fingerprint "$(nsslsay_queue_print)" |
404 |
|
} |