#!/bin/sh

echo "Content-Type: application/json"
echo ""

wizard_complete=$(uci -q get wizard.default.wizard_complete)
[ -z "$wizard_complete" ] && wizard_complete="0"

mesh_mode=$(uci -q get wizard.default.mesh_mode)

# Authentication step disabled
# auth_confirmed=$(uci -q get wizard.default.authentication_confirmed)

# Проверка: пароль root установлен?
pass=$(awk -F: '/^root:/ {print $2}' /etc/shadow 2>/dev/null)
if [ -n "$pass" ]; then
    password_set="true"
else
    password_set="false"
fi

# LAN IP
lan_ip=$(uci -q get network.lan.ipaddr || echo "192.168.1.1")
lan_ip="${lan_ip%%/*}"

# Формируем JSON
printf '{"wizard_complete":"%s","password_set":%s,"lan_ip":"%s","wizard_version":"1.4.0"' "$wizard_complete" "$password_set" "$lan_ip"
[ -n "$mesh_mode" ] && printf ',"mesh_mode":"%s"' "$mesh_mode"
# Authentication step disabled
# [ -n "$auth_confirmed" ] && printf ',"authentication_confirmed":"%s"' "$auth_confirmed"
printf '}\n'
