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) ]] |
153 |
then |
then |
154 |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} '$@'" |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
155 |
fi |
fi |
156 |
} |
} |
157 |
|
|
253 |
|
|
254 |
chroot ${MROOT} ${cmd} |
chroot ${MROOT} ${cmd} |
255 |
} |
} |
256 |
|
|
257 |
|
# gets interface used to reach given ip |
258 |
|
iface_for_remote_addr() |
259 |
|
{ |
260 |
|
set -- $(ip -o route get to $1) |
261 |
|
echo $5 |
262 |
|
} |
263 |
|
|
264 |
|
# get ip from dns name |
265 |
|
dns_to_ip() |
266 |
|
{ |
267 |
|
set -- $(getent hosts $1) |
268 |
|
echo $1 |
269 |
|
} |
270 |
|
|
271 |
|
iface_for_ip() |
272 |
|
{ |
273 |
|
set -- $(ip -o addr show to $1) |
274 |
|
echo $2 |
275 |
|
} |
276 |
|
|
277 |
|
iface_for_mac() |
278 |
|
{ |
279 |
|
local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')" |
280 |
|
for interface in /sys/class/net/*; do |
281 |
|
if [ $(cat $interface/address) = "$mac" ]; then |
282 |
|
echo ${interface##*/} |
283 |
|
fi |
284 |
|
done |
285 |
|
} |
286 |
|
|
287 |
|
mac_for_iface() |
288 |
|
{ |
289 |
|
local iface="$1" |
290 |
|
if [ -f /sys/class/net/${iface}/address ] |
291 |
|
then |
292 |
|
cat /sys/class/net/${iface}/address |
293 |
|
fi |
294 |
|
} |
295 |
|
|
296 |
|
certificate_fingerprint() |
297 |
|
{ |
298 |
|
local cert_fingerprint |
299 |
|
local retval |
300 |
|
|
301 |
|
if [[ ! -f ${MCORE_CERT_FILE} ]] |
302 |
|
then |
303 |
|
eecho "MCORE_CERT_FILE '${MCORE_CERT_FILE}' does not exist." |
304 |
|
return 1 |
305 |
|
fi |
306 |
|
|
307 |
|
cert_fingerprint=$(openssl x509 -noout -modulus -in "${MCORE_CERT_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
308 |
|
retval="$?" |
309 |
|
|
310 |
|
if [[ ${retval} != 0 ]] |
311 |
|
then |
312 |
|
eecho "Error '${retval}' while generating cert_fingerprint." |
313 |
|
return 1 |
314 |
|
fi |
315 |
|
|
316 |
|
if [[ -z ${cert_fingerprint} ]] |
317 |
|
then |
318 |
|
eecho "Error: cert_fingerprint is empty" |
319 |
|
return 1 |
320 |
|
else |
321 |
|
echo "${cert_fingerprint}" |
322 |
|
fi |
323 |
|
} |
324 |
|
|
325 |
|
key_fingerprint() |
326 |
|
{ |
327 |
|
local key_fingerprint |
328 |
|
local retval |
329 |
|
|
330 |
|
if [[ ! -f ${MCORE_KEY_FILE} ]] |
331 |
|
then |
332 |
|
eecho "MCORE_KEY_FILE '${MCORE_KEY_FILE}' does not exist." |
333 |
|
return 1 |
334 |
|
fi |
335 |
|
|
336 |
|
key_fingerprint=$(openssl rsa -noout -modulus -in "${MCORE_KEY_FILE}" | openssl sha1 | sed 's:(stdin)=\ ::') |
337 |
|
retval="$?" |
338 |
|
|
339 |
|
if [[ ${retval} != 0 ]] |
340 |
|
then |
341 |
|
eecho "Error '${retval}' while generating key_fingerprint." |
342 |
|
return 1 |
343 |
|
fi |
344 |
|
|
345 |
|
if [[ -z ${key_fingerprint} ]] |
346 |
|
then |
347 |
|
eecho "Error: key_fingerprint is empty" |
348 |
|
return 1 |
349 |
|
else |
350 |
|
echo "${key_fingerprint}" |
351 |
|
fi |
352 |
|
} |
353 |
|
|
354 |
|
nsslsay() |
355 |
|
{ |
356 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
357 |
|
auth ${SSLSAY_USER} ${SSLSAY_PASS} |
358 |
|
$@ |
359 |
|
quit |
360 |
|
EOF |
361 |
|
} |
362 |
|
|
363 |
|
nsslsay_fingerprint() |
364 |
|
{ |
365 |
|
nssl "${SSLSAY_IP}" "${SSLSAY_PORT}" << EOF |
366 |
|
certauth $(certificate_fingerprint) |
367 |
|
$@ |
368 |
|
quit |
369 |
|
EOF |
370 |
|
} |