blob: f80ed34a1b534626c22cd156994aff40e0e5c7f0 (
plain) (
blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/bin/bash
format_urls() {
local url scheme host path count chost
for url in $@; do
# first remove '*://' scheme, none means the same
url="${url#*\*://}"
# extract scheme and remove it from url if needed
scheme="${url%%://*}"
if [ "$scheme" != "$url" ]; then
url="${url#*://}"
else
scheme=
fi
# extract host, skip entry if empty
host="${url%%/*}"
[ -z "$host" ] && continue
# transform into chromium syntax
if [ "$host" != "${host//\*/}" ]; then
# host contains wildcard '*'
# look for the longest subdomain until the wildcard
chost="$(echo "$host" | grep -oE '[^*]+$')"
# remove dot left over
if [ -n "$chost" ]; then
chost="${chost#?}"
else
chost='*'
fi
else
# chromium: exact host match must be prefixed with '.'
chost=".${host}"
fi
path="${url#*/}"
[ "$path" = "${host}" ] && path=
cpath=
if [ -n "$path" ]; then
cpath="$(echo "$path" | grep -oE '^[^*]*')"
fi
echo -e "\t\t\"${scheme:+${scheme}://}${chost}${cpath:+/${cpath}}\","
done | sed '$ s/.$//'
}
main() {
[ -e "/opt/openslx/config" ] || exit 0
. /opt/openslx/config
local url_policy_file="/etc/chromium-browser/policies/managed/url-filter.json"
echo -e "{\n" > "$url_policy_file"
local ttype
if [ "$SLX_BROWSER_IS_WHITELIST" -eq 1 ]; then
ttype="White"
echo -e '\t"URLBlacklist": [ "*" ],' >> "$url_policy_file"
else
ttype="Black"
fi
if [ -n "$SLX_BROWSER_URLLIST" ]; then
echo -e '\t"URL'"$ttype"'list": [' >> "$url_policy_file"
format_urls $SLX_BROWSER_URLLIST >> "$url_policy_file"
echo -e '\t]' >> "$url_policy_file"
fi
echo -e '}' >> "$url_policy_file"
}
if [ "${PAM_SERVICE//autologin/}" != "$PAM_SERVICE" -a "$PAM_TTY" = ":0" ]; then
# autologin of some sort
main
fi
true
|