blob: 2f615168eb53cae6d22ba1e735d40d0904435bdf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env bash
set -euo pipefail
bundle="${1:-/usr/share/cockpit/anaconda-webui/index.js.gz}"
broken='n===0?r(new Error(X2("Password is too weak"))):o('
fixed='n===0&&!e?r(new Error(X2("Password is too weak"))):o('
fixed_sed='n===0\&\&!e?r(new Error(X2("Password is too weak"))):o('
if [[ ! -f "${bundle}" ]]; then
echo "Anaconda WebUI bundle not found: ${bundle}" >&2
exit 1
fi
webui_js="$(mktemp)"
patched_js="$(mktemp)"
patched_bundle="$(mktemp)"
trap 'rm -f "${webui_js}" "${patched_js}" "${patched_bundle}"' EXIT
gzip -dc "${bundle}" > "${webui_js}"
fixed_count="$( (grep -oF "${fixed}" "${webui_js}" || true) | wc -l | tr -d ' ')"
if [[ "${fixed_count}" == "1" ]]; then
echo "Anaconda WebUI weak-password handling is already fixed"
exit 0
fi
broken_count="$( (grep -oF "${broken}" "${webui_js}" || true) | wc -l | tr -d ' ')"
if [[ "${broken_count}" != "1" ]]; then
echo "Unexpected Anaconda WebUI password helper; refusing an unsafe patch" >&2
echo "Expected one weak-password rejection, found ${broken_count}" >&2
exit 1
fi
sed "s|${broken}|${fixed_sed}|" "${webui_js}" > "${patched_js}"
fixed_count="$( (grep -oF "${fixed}" "${patched_js}" || true) | wc -l | tr -d ' ')"
if [[ "${fixed_count}" != "1" ]] || grep -Fq "${broken}" "${patched_js}"; then
echo "Failed to patch Anaconda WebUI weak-password handling" >&2
exit 1
fi
gzip -n -9 -c "${patched_js}" > "${patched_bundle}"
chmod 0644 "${patched_bundle}"
mv -f "${patched_bundle}" "${bundle}"
echo "Patched Anaconda WebUI weak-password handling"
|