parent
62dd688e0c
commit
fd1d997ec1
@ -0,0 +1,82 @@ |
||||
#!/bin/bash |
||||
|
||||
set -e |
||||
set -u |
||||
set -f |
||||
set -o pipefail |
||||
|
||||
echo_err(){ |
||||
echo "$@" 1>&2 |
||||
} |
||||
|
||||
#readonly dir="${XDG_CONFIG_HOME:-$HOME/.config}" |
||||
readonly dir="/etc" |
||||
mkdir -p "$dir" |
||||
readonly config="$dir/doskastrc" |
||||
|
||||
_zenity(){ |
||||
zenity --width=250 --title="Doskast" "$@" |
||||
} |
||||
|
||||
# $1: path |
||||
_create_config(){ |
||||
if ! echo 'board=' > "$1"; then |
||||
_zenity --error --text="Ошибка при создании пустого конфига" |
||||
return 1 |
||||
fi |
||||
} |
||||
|
||||
# $1: IP |
||||
_write_systemd_config(){ |
||||
mkdir -p /etc/systemd/system/doskast-student.service.d |
||||
cat > /etc/systemd/system/doskast-student.service.d/doskast-student-firewall.conf << EOF |
||||
[Service] |
||||
IPAddressDeny=any |
||||
# IP-адрес доски |
||||
IPAddressAllow=$1 |
||||
EOF |
||||
} |
||||
|
||||
corrupted=0 |
||||
board="" |
||||
if ! test -f "$config"; then |
||||
echo_err "No config $config, creating it" |
||||
_create_config "$config" |
||||
else |
||||
if ! . "$config"; then |
||||
corrupted=1 |
||||
fi |
||||
if test -z "${board:-}"; then |
||||
corrupted=1 |
||||
fi |
||||
if [ "$corrupted" = 1 ]; then |
||||
echo_err "Config file $config is corrupted, recreating it..." |
||||
_create_config "$config" |
||||
fi |
||||
fi |
||||
|
||||
# TODO: validate IP |
||||
if ! answer="$(zenity \ |
||||
--entry \ |
||||
--title="Doskast" \ |
||||
--text="Введите IP-адрес доски:" \ |
||||
--entry-text "$board" |
||||
)"; then |
||||
_zenity --error --text="Произошла неизвестная ошибка." |
||||
exit 1 |
||||
fi |
||||
|
||||
if test -z "$answer" ; then |
||||
zenity --title="Doskast" --error --text="Введено пустое знаничение. Попробуйте заново." |
||||
exit 1 |
||||
fi |
||||
|
||||
if ! _write_systemd_config "$answer"; then |
||||
_zenity --error --text="Ошибка при сохранении настроек eBPF-фаерволирования." |
||||
exit 1 |
||||
fi |
||||
|
||||
if echo board="$answer" > "$config"; then |
||||
# жаба, чтобы был нулевой код возврата при нажатии "Отмена" |
||||
_zenity --info --text="Настройки сохранены" || : |
||||
fi |
@ -0,0 +1,2 @@ |
||||
#!/bin/bash |
||||
|
@ -0,0 +1,21 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" |
||||
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> |
||||
<policyconfig> |
||||
<vendor>KDE</vendor> |
||||
<vendor_url>http://osmesh.ru</vendor_url> |
||||
<icon_name>document-page-setup</icon_name> |
||||
<action id="ru.mos.doskast-student-config"> |
||||
<description>Setup student part of Doskast</description> |
||||
<description xml:lang="ru">Настройка ученичоеской части Doskast</description> |
||||
<message>Enter password to setup Doskast</message> |
||||
<message xml:lang="ru">Введите пароль для настройки Doskast</message> |
||||
<defaults> |
||||
<allow_any>auth_admin</allow_any> |
||||
<allow_inactive>auth_admin</allow_inactive> |
||||
<allow_active>auth_admin</allow_active> |
||||
</defaults> |
||||
<annotate key="org.freedesktop.policykit.exec.path">/usr/sbin/doskast-student-setup</annotate> |
||||
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate> |
||||
</action> |
||||
</policyconfig> |
Loading…
Reference in new issue