#!/usr/bin/haserl <%in p/common.cgi %> <% page_title="Настройки Majestic" mj=$(echo "$mj" | sed "s/ /_/g") only="$GET_tab"; [ -z "$only" ] && only="system" eval title="\$tT_mj_${only}" # hide certain domains if not supported if [ -n "$(eval echo "\$mj_hide_${only}" | sed -n "/\b${soc_family}\b/p")" ]; then redirect_to "majestic-settings.cgi" "danger" "$title не поддерживается в вашей системе." fi if [ "POST" = "$REQUEST_METHOD" ]; then mj_conf=/etc/majestic.yaml temp_yaml=/tmp/majestic.yaml # make a copy of the actual config into memory cp -f $mj_conf $temp_yaml OIFS=$IFS IFS=$'\n' # make newlines the only separator for yaml_param_name in $(printenv|grep POST_); do form_field_name=$(echo $yaml_param_name | sed 's/^POST_mj_//') key=".$(echo $form_field_name | cut -d= -f1 | sed 's/_/./g')" # do not include helping fields into config if [ "$key" = ".netip.password.plain" ] || [ "$key" = ".osd.corner" ]; then continue fi value="$(echo $form_field_name | cut -d= -f2)" # normalization # (that's why we can't have nice things) case "$key" in .image.rotate) [ "0" = "$value" ] && value="none" ;; .isp.antiFlicker) [ "50Hz" = "$value" ] && value="50" [ "60Hz" = "$value" ] && value="60" ;; .motionDetect.visualize) [ "true" = "$value" ] && yaml-cli -s ".osd.enabled" "true" -i $temp_yaml ;; .osd.enabled) [ "false" = "$value" ] && yaml-cli -s ".motionDetect.visualize" "false" -i $temp_yaml ;; .system.webAdmin) [ "true" = "$value" ] && value="enabled" [ "false" = "$value" ] && value="disabled" ;; esac # read existing value oldvalue=$(yaml-cli -g "$key" -i $temp_yaml) if [ -z "$value" ]; then # if no new value submitted but there is an existing value, delete the yaml_param_name [ -n "$oldvalue" ] && yaml-cli -d $key -i "$temp_yaml" -o "$temp_yaml" else # if new value is submitted and it differs from the existing one, update the yaml_param_name [ "$oldvalue" != "$value" ] && yaml-cli -s $key "$value" -i "$temp_yaml" -o "$temp_yaml" fi done IFS=$OIFS # update config if differs [ -n "$(diff -q $temp_yaml $mj_conf)" ] && cp -f $temp_yaml $mj_conf # clean up rm $temp_yaml # reload majestic killall -1 majestic redirect_to "$HTTP_REFERER" fi %> <%in p/header.cgi %>