mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-10 18:34:18 +08:00
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2018 Dengfeng Liu
|
||||||
|
#
|
||||||
|
# This is free software, licensed under the GNU General Public License v3.
|
||||||
|
# See /LICENSE for more information.
|
||||||
|
#
|
||||||
|
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=apfree-wifidog
|
||||||
|
PKG_VERSION:=9.09.2938
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||||
|
PKG_SOURCE_URL:=https://codeload.github.com/liudf0716/$(PKG_NAME)/tar.gz/$(PKG_VERSION)?
|
||||||
|
PKG_HASH:=skip
|
||||||
|
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||||
|
|
||||||
|
PKG_MAINTAINER:=Dengfeng Liu <liudf0716@gmail.com>
|
||||||
|
PKG_LICENSE:=GPL-3.0-or-later
|
||||||
|
PKG_LICENSE_FILES:=COPYING
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
include $(INCLUDE_DIR)/cmake.mk
|
||||||
|
|
||||||
|
define Package/apfree-wifidog
|
||||||
|
SUBMENU:=Captive Portals
|
||||||
|
SECTION:=net
|
||||||
|
CATEGORY:=Network
|
||||||
|
DEPENDS:=+zlib +libjson-c +libevent2 +libevent2-openssl +libuci \
|
||||||
|
+openssl-util +libnetfilter-queue +conntrack +libmosquitto \
|
||||||
|
+libnftnl +libmnl +libbpf +aw-bpf
|
||||||
|
TITLE:=Apfree's wireless captive portal solution
|
||||||
|
URL:=https://github.com/liudf0716/apfree_wifidog
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/apfree-wifidog/description
|
||||||
|
The ApFree Wifidog project is a complete and embeddable captive portal
|
||||||
|
solution for wireless community groups or individuals who wish to open a free
|
||||||
|
Hotspot while still preventing abuse of their Internet connection.
|
||||||
|
It's enhanced wifidog
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/apfree-wifidog/conffiles
|
||||||
|
/etc/config/wifidogx
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/apfree-wifidog/install
|
||||||
|
$(INSTALL_DIR) $(1)/usr/bin
|
||||||
|
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifidogx $(1)/usr/bin/wifidogx
|
||||||
|
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wdctlx $(1)/usr/bin/wdctlx
|
||||||
|
$(INSTALL_DIR) $(1)/usr/sbin
|
||||||
|
$(INSTALL_DIR) $(1)/etc
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/wifidog-msg.html $(1)/etc/
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/wifidog-redir.html $(1)/etc/
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/wifidog-redir.html.front $(1)/etc/
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/wifidog-redir.html.rear $(1)/etc/
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/authserver-offline.html $(1)/etc/
|
||||||
|
$(INSTALL_DATA) $(PKG_BUILD_DIR)/internet-offline.html $(1)/etc/
|
||||||
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
|
$(INSTALL_BIN) ./files/wifidogx.init $(1)/etc/init.d/wifidogx
|
||||||
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
|
$(CP) ./files/wifidogx.conf $(1)/etc/config/wifidogx
|
||||||
|
$(INSTALL_DIR) $(1)/etc/wifidogx
|
||||||
|
$(INSTALL_DIR) $(1)/www/cgi-bin
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifi-config $(1)/www/cgi-bin/
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifi-diag $(1)/www/cgi-bin/
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,apfree-wifidog))
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
[![license][1]][2]
|
||||||
|
[![PRs Welcome][3]][4]
|
||||||
|
[![Issues Welcome][5]][6]
|
||||||
|
[![Release Version][7]][8]
|
||||||
|
[![OpenWrt][11]][12]
|
||||||
|
[![Join the QQ Group][15]][16]
|
||||||
|
|
||||||
|
|
||||||
|
[1]: https://img.shields.io/badge/license-GPLV3-brightgreen.svg?style=plastic
|
||||||
|
[2]: https://github.com/liudf0716/apfree_wifidog/blob/master/COPYING
|
||||||
|
[3]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=plastic
|
||||||
|
[4]: https://github.com/liudf0716/apfree_wifidog/pulls
|
||||||
|
[5]: https://img.shields.io/badge/Issues-welcome-brightgreen.svg?style=plastic
|
||||||
|
[6]: https://github.com/liudf0716/apfree_wifidog/issues/new
|
||||||
|
[7]: https://img.shields.io/badge/release-3.11.1716-red.svg?style=plastic
|
||||||
|
[8]: https://github.com/liudf0716/apfree_wifidog/releases
|
||||||
|
[11]: https://img.shields.io/badge/Platform-%20OpenWrt%7C%20LEDE%20-brightgreen.svg?style=plastic
|
||||||
|
[12]: https://github.com/KunTengRom/kunteng-lede-17.01.4
|
||||||
|
[13]: https://img.shields.io/badge/KunTeng-Inside-blue.svg?style=plastic
|
||||||
|
[14]: https://www.kunteng.org.cn
|
||||||
|
[15]: https://img.shields.io/badge/chat-qq%20group-brightgreen.svg
|
||||||
|
[16]: https://jq.qq.com/?_wv=1027&k=4ADDSev
|
||||||
|
|
||||||
|
## ApFree WiFiDog: A high performance captive portal solution for HTTP(s)
|
||||||
|
|
||||||
|
ApFree WiFiDog is a high performance captive portal solution for HTTP(s), which mainly used in ([LEDE](https://github.com/lede-project/source) & [OpenWrt](https://github.com/openwrt/openwrt)) platform.
|
||||||
|
|
||||||
|
|
||||||
|
**[中文介绍](https://github.com/liudf0716/apfree_wifidog/blob/master/README_ZH.md)**
|
||||||
|
|
||||||
|
## Enhancement of apfree-wifidog
|
||||||
|
|
||||||
|
In fact, the title should be why we choose apfree-wifidog, the reason was the following:
|
||||||
|
|
||||||
|
> Stable
|
||||||
|
|
||||||
|
apfree-wifidog was widely used in tens of thousands device, which were running in business scene. In order to improve its stable, we rewrite all iptables rule by api instead of fork call, which will easily cause deadlock in multithread-fork running environment. we also re-write the code and replace libhttpd (which is unmaintained for years) with libevent
|
||||||
|
|
||||||
|
> Performance
|
||||||
|
|
||||||
|
apfree-wifidog's http request-response is more quick, u can find statistic data in our test document
|
||||||
|
|
||||||
|
> HTTPs redirect
|
||||||
|
|
||||||
|
apfree-wifidog support https redirect, in current internet environment, captive portal solution without supporting https redirect will become unsuitable gradually
|
||||||
|
|
||||||
|
|
||||||
|
> More features
|
||||||
|
|
||||||
|
apfree-wifidog support mac temporary-pass, ip,domain,pan-domain,white-mac,black-mac rule and etc. all these rules can be applied without restarting wifidog
|
||||||
|
|
||||||
|
> MQTT support
|
||||||
|
|
||||||
|
by enable mqtt support, u can remotely deliver such as trusted ip, domain and pan-domain rules to apfree wifidog
|
||||||
|
|
||||||
|
> Compilable with wifidog protocol
|
||||||
|
|
||||||
|
u don't need to modify your wifidog authentication server to adapt apfree-wifidog; if u have pression on server-side, apfree wifidog's improved protocol can greatly relieve it, which disabled by default
|
||||||
|
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
before starting apfree-wifidog, we must know how to configure it. apfree-wifidog use OpenWrt standard uci config system, all your apfree-wifidog configure information stored in `/etc/confg/wifidogx`, which will be parsed by `/etc/init.d/wifidogx` to /tmp/wifidog.conf, apfree-wifidog's real configure file is `/tmp/wifidog.conf`
|
||||||
|
|
||||||
|
The default apfree-wifidog UCI configuration file like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
config wifidog
|
||||||
|
option gateway_interface 'br-lan'
|
||||||
|
option auth_server_hostname 'wifidog.kunteng.org.cn'
|
||||||
|
option auth_server_port 443
|
||||||
|
option auth_server_path '/wifidog/'
|
||||||
|
option check_interval 60
|
||||||
|
option client_timeout 5
|
||||||
|
option apple_cna 1
|
||||||
|
option thread_number 5
|
||||||
|
option wired_passed 0
|
||||||
|
option enable 0
|
||||||
|
```
|
||||||
|
|
||||||
|
> auth_server_hostname was apfree-wifidog auth server, it can be domain or ip; wifidog.kunteng.org.cn is a free auth server we provided, it was also [open source](https://github.com/wificoin-project/wwas)
|
||||||
|
|
||||||
|
> apple_cna 1 apple captive detect deceive; 2 apple captive detect deceive to disallow portal page appear
|
||||||
|
|
||||||
|
> wired_passed means whether LAN access devices need to auth or not, value 1 means no need to auth
|
||||||
|
|
||||||
|
> enable means whether start apfree-wifidog when we executed `/etc/init.d/wifidogx start`, if u wanted to start apfree-wifidog, you must set enable to 1 before executing `/etc/init.d/wifidogx start`
|
||||||
|
|
||||||
|
### How to support https redirect
|
||||||
|
|
||||||
|
In order to support https redirect, apfree-wifidog need x509 pem cert and private key, u can generate yourself like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
PX5G_BIN="/usr/sbin/px5g"
|
||||||
|
OPENSSL_BIN="/usr/bin/openssl"
|
||||||
|
APFREE_CERT="/etc/apfree.crt"
|
||||||
|
APFREE_KEY="/etc/apfree.key"
|
||||||
|
|
||||||
|
generate_keys() {
|
||||||
|
local days bits country state location commonname
|
||||||
|
|
||||||
|
# Prefer px5g for certificate generation (existence evaluated last)
|
||||||
|
local GENKEY_CMD=""
|
||||||
|
local UNIQUEID=$(dd if=/dev/urandom bs=1 count=4 | hexdump -e '1/1 "%02x"')
|
||||||
|
[ -x "$OPENSSL_BIN" ] && GENKEY_CMD="$OPENSSL_BIN req -x509 -sha256 -outform pem -nodes"
|
||||||
|
[ -x "$PX5G_BIN" ] && GENKEY_CMD="$PX5G_BIN selfsigned -pem"
|
||||||
|
[ -n "$GENKEY_CMD" ] && {
|
||||||
|
$GENKEY_CMD \
|
||||||
|
-days ${days:-730} -newkey rsa:${bits:-2048} -keyout "${APFREE_KEY}.new" -out "${APFREE_CERT}.new" \
|
||||||
|
-subj /C="${country:-CN}"/ST="${state:-localhost}"/L="${location:-Unknown}"/O="${commonname:-ApFreeWiFidog}$UNIQUEID"/CN="${commonname:-ApFreeWiFidog}"
|
||||||
|
sync
|
||||||
|
mv "${APFREE_KEY}.new" "${APFREE_KEY}"
|
||||||
|
mv "${APFREE_CERT}.new" "${APFREE_CERT}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
or when u start `/etc/init.d/wifidogx start`, it will generate it automatically
|
||||||
|
|
||||||
|
|
||||||
|
For more information, please refer to the upstream [project page](https://github.com/liudf0716/apfree_wifidog)
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
config wifidogx 'common'
|
||||||
|
option external_interface 'wan'
|
||||||
|
option check_interval '60'
|
||||||
|
option client_timeout '60'
|
||||||
|
option wired_passed '1'
|
||||||
|
option enabled '1'
|
||||||
|
option log_level '0'
|
||||||
|
option js_filter '1'
|
||||||
|
option apple_cna '1'
|
||||||
|
option auth_server_mode 'local'
|
||||||
|
option enable_anti_nat '0'
|
||||||
|
option ttl_values '64,128,255'
|
||||||
|
option ap_device_id 'AW85844955CC7D742A339'
|
||||||
|
option ap_mac_address '5C-C7-D7-42-A3-39'
|
||||||
|
option ap_longitude '116.395000'
|
||||||
|
option ap_latitude '039.911000'
|
||||||
|
option disable_portal_auth '0'
|
||||||
|
option enable_privileged_ops '0'
|
||||||
|
option privileged_ops_secret 'chawrt@2026'
|
||||||
|
option device_id 'AW58534605CC7D742A339'
|
||||||
|
option local_portal 'https://qq.com'
|
||||||
|
|
||||||
|
config gateway 'apfree'
|
||||||
|
option gateway_name 'br-lan'
|
||||||
|
option gateway_channel 'apfree'
|
||||||
|
option gateway_auth_enabled '1'
|
||||||
|
option gateway_id '5CC7D742A336'
|
||||||
|
option gateway_subnetv4 '192.168.8.1/24'
|
||||||
|
|
||||||
|
config auth 'local'
|
||||||
|
option auth_server_hostname '192.168.8.109'
|
||||||
|
option auth_server_port '8001'
|
||||||
|
option auth_server_path '/wifidog/'
|
||||||
|
|
||||||
|
config longconn 'openclaw'
|
||||||
|
option long_conn_mode 'ws'
|
||||||
|
option ws_server_hostname '192.168.8.109'
|
||||||
|
option ws_server_port '8001'
|
||||||
|
option ws_server_path '/ws/wifidogx'
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
# Copyright (C) 2018 Dengfeng Liu
|
||||||
|
|
||||||
|
# After aw-bpf (START=98) so dns_ringbuf_portal is pinned for wildcard trust.
|
||||||
|
START=99
|
||||||
|
USE_PROCD=1
|
||||||
|
NAME=wifidogx
|
||||||
|
PROG="/usr/bin/${NAME}"
|
||||||
|
CONFIGFILE="/tmp/wifidogx.conf"
|
||||||
|
|
||||||
|
handle_gateway() {
|
||||||
|
local section="$1"
|
||||||
|
local gateway_name gateway_channel gateway_id
|
||||||
|
local gateway_subnetv4
|
||||||
|
local gateway_auth_enabled
|
||||||
|
|
||||||
|
config_get gateway_name "$section" gateway_name
|
||||||
|
config_get gateway_channel "$section" gateway_channel
|
||||||
|
config_get gateway_id "$section" gateway_id
|
||||||
|
config_get gateway_auth_enabled "$section" gateway_auth_enabled 1
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z "$gateway_name" ] || [ -z "$gateway_channel" ] ; then
|
||||||
|
echo "gateway_name and gateway_channel are required for $section" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get gateway_id from gateway_name if not set
|
||||||
|
if [ -z "$gateway_id" ]; then
|
||||||
|
gateway_id=$(ifconfig "$gateway_name" | awk '/HWaddr/ {print toupper($5)}' | tr -d ':')
|
||||||
|
if [ -z "$gateway_id" ]; then
|
||||||
|
echo "Failed to get gateway_id for $gateway_name" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
uci set wifidogx."$section".gateway_id="$gateway_id"
|
||||||
|
uci commit wifidogx
|
||||||
|
fi
|
||||||
|
# according to the gateway_name to get the subnetv4
|
||||||
|
local gateway_ipv4=$(ifconfig "$gateway_name" | awk '/inet addr:/ {print $2}' | cut -d: -f2)
|
||||||
|
local gateway_maskv4=$(ifconfig "$gateway_name" | awk '/Mask:/ {print $4}' | cut -d: -f2)
|
||||||
|
[ -z "$gateway_ipv4" ] && echo "Failed to get gateway_ipv4 for $gateway_name" >&2 && return
|
||||||
|
[ -z "$gateway_maskv4" ] && echo "Failed to get gateway_maskv4 for $gateway_name" >&2 && return
|
||||||
|
|
||||||
|
# change the gateway_ip4/gateway_maskv4 to CIDR format
|
||||||
|
local mask_bits=0
|
||||||
|
local mask_value=$(printf '%d' "0x$(echo $gateway_maskv4 | tr '.' ' ' | awk '{printf "%02x%02x%02x%02x",$1,$2,$3,$4}')")
|
||||||
|
while [ $mask_value -ne 0 ]; do
|
||||||
|
mask_bits=$((mask_bits + (mask_value & 1)))
|
||||||
|
mask_value=$((mask_value >> 1))
|
||||||
|
done
|
||||||
|
gateway_subnetv4="$gateway_ipv4/$mask_bits"
|
||||||
|
|
||||||
|
uci set wifidogx."$section".gateway_subnetv4="$gateway_subnetv4"
|
||||||
|
uci commit wifidogx
|
||||||
|
|
||||||
|
printf "GatewaySetting {\n\tGatewayAuthEnabled %s\n\tGatewayInterface %s\n\tGatewayChannel %s\n\tGatewayID %s\n\tGatewaySubnetV4 %s\n}\n" \
|
||||||
|
"${gateway_auth_enabled}" "${gateway_name}" "${gateway_channel}" "${gateway_id}" "${gateway_subnetv4}" >> "$CONFIGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
add_white_list_entries() {
|
||||||
|
local list_type="$1"
|
||||||
|
local uci_field="$2"
|
||||||
|
local target_variable="$3"
|
||||||
|
|
||||||
|
list_type=$(uci get wifidogx.common."$list_type")
|
||||||
|
for group in $list_type; do
|
||||||
|
group_list=$(uci get wifidogx."$group"."$uci_field")
|
||||||
|
if [ -n "$group_list" ]; then
|
||||||
|
eval "$target_variable=\"\${$target_variable} \$group_list\""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_common_settings() {
|
||||||
|
printf "CheckInterval %s\nClientTimeout %s\nJsFilter %s\nWiredPassed %s\nBypassAppleCNA %s\n" \
|
||||||
|
"$check_interval" "$client_timeout" "$js_filter" "$wired_passed" "$apple_cna" >> "$CONFIGFILE"
|
||||||
|
|
||||||
|
printf "EnableAntiNat %s\n" "$enable_anti_nat" >> "$CONFIGFILE"
|
||||||
|
printf "TTLValues %s\n" "$ttl_values" >> "$CONFIGFILE"
|
||||||
|
printf "DisablePortalAuth %s\n" "$disable_portal_auth" >> "$CONFIGFILE"
|
||||||
|
printf "EnablePrivilegedOps %s\n" "$enable_privileged_ops" >> "$CONFIGFILE"
|
||||||
|
[ -n "$privileged_ops_secret" ] && printf "PrivilegedOpsSecret %s\n" "$privileged_ops_secret" >> "$CONFIGFILE"
|
||||||
|
|
||||||
|
[ -n "$anti_nat_permit_macs" ] && printf "AntiNatPermitMACs %s\n" "$anti_nat_permit_macs" >> "$CONFIGFILE"
|
||||||
|
|
||||||
|
process_trusted_list() {
|
||||||
|
local list="$1"
|
||||||
|
local config_name="$2"
|
||||||
|
|
||||||
|
if [ -n "$list" ]; then
|
||||||
|
# Clean up whitespace and remove duplicates
|
||||||
|
list=$(echo "$list" | sed -e 's/^[[:space:]]*//;s/[[:space:]]*$//;s/[[:space:]]\+/ /g' \
|
||||||
|
| tr ' ' '\n' | sort -u | tr '\n' ',' | sed 's/,$//')
|
||||||
|
printf "%s %s\n" "$config_name" "$list" >> "$CONFIGFILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
process_trusted_list "$trusted_domains" "TrustedDomains"
|
||||||
|
process_trusted_list "$trusted_macs" "TrustedMACList"
|
||||||
|
process_trusted_list "$trusted_wildcard_domains" "TrustedWildcardDomains"
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_device_info() {
|
||||||
|
# Check if any device info fields are set
|
||||||
|
if [ -n "$ap_device_id" ] || [ -n "$ap_mac_address" ] || [ -n "$ap_longitude" ] || [ -n "$ap_latitude" ] || [ -n "$location_id" ]; then
|
||||||
|
printf "DeviceInfo {\n" >> "$CONFIGFILE"
|
||||||
|
|
||||||
|
[ -n "$ap_device_id" ] && printf "\tApDeviceId %s\n" "$ap_device_id" >> "$CONFIGFILE"
|
||||||
|
[ -n "$ap_mac_address" ] && printf "\tApMacAddress %s\n" "$ap_mac_address" >> "$CONFIGFILE"
|
||||||
|
[ -n "$ap_longitude" ] && printf "\tApLongitude %s\n" "$ap_longitude" >> "$CONFIGFILE"
|
||||||
|
[ -n "$ap_latitude" ] && printf "\tApLatitude %s\n" "$ap_latitude" >> "$CONFIGFILE"
|
||||||
|
[ -n "$location_id" ] && printf "\tLocationId %s\n" "$location_id" >> "$CONFIGFILE"
|
||||||
|
|
||||||
|
printf "}\n" >> "$CONFIGFILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_auth_server_settings() {
|
||||||
|
# 获取选中的认证服务器配置
|
||||||
|
local selected_auth_server
|
||||||
|
selected_auth_server=$(uci get wifidogx.common.selected_auth_server 2>/dev/null)
|
||||||
|
|
||||||
|
# 如果是云认证或旁路模式,需要验证选中的认证服务器
|
||||||
|
if [ "$auth_server_mode" = "cloud" ] || [ "$auth_server_mode" = "bypass" ]; then
|
||||||
|
if [ -z "$selected_auth_server" ]; then
|
||||||
|
echo "Error: selected_auth_server is required for $auth_server_mode mode" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local auth_server_hostname auth_server_port auth_server_path
|
||||||
|
|
||||||
|
uci_validate_section "$NAME" "auth" "$selected_auth_server" \
|
||||||
|
'auth_server_hostname:string:192.168.1.1' \
|
||||||
|
'auth_server_port:port:80' \
|
||||||
|
'auth_server_path:string:/wifidog/'
|
||||||
|
|
||||||
|
export auth_server_hostname
|
||||||
|
export auth_server_port
|
||||||
|
export auth_server_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$auth_server_mode" in
|
||||||
|
cloud|bypass)
|
||||||
|
printf "AuthServerMode 0\n" >> "$CONFIGFILE"
|
||||||
|
printf "DeviceID %s\nAuthServer {\n\tHostname %s\n\tHTTPPort %s\n\tPath %s\n}\n" \
|
||||||
|
"$device_id" "$auth_server_hostname" "$auth_server_port" "$auth_server_path" >> "$CONFIGFILE"
|
||||||
|
;;
|
||||||
|
local)
|
||||||
|
printf "AuthServerMode 2\n" >> "$CONFIGFILE"
|
||||||
|
[ -n "$device_id" ] && printf "DeviceID %s\n" "$device_id" >> "$CONFIGFILE"
|
||||||
|
[ -n "$auth_server_offline_file" ] && printf "AuthServerOfflineFile %s\n" "$auth_server_offline_file" >> "$CONFIGFILE"
|
||||||
|
[ -n "$local_portal" ] && printf "LocalPortal %s\n" "$local_portal" >> "$CONFIGFILE"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ -n "$internet_offline_file" ] && printf "InternetOfflineFile %s\n" "$internet_offline_file" >> "$CONFIGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_longconn_settings() {
|
||||||
|
local long_conn_mode ws_server_hostname ws_server_port ws_server_path
|
||||||
|
local mqtt_server_hostname mqtt_server_port mqtt_username mqtt_password
|
||||||
|
local selected_long_conn
|
||||||
|
|
||||||
|
selected_long_conn=$(uci get wifidogx.common.selected_long_conn 2>/dev/null)
|
||||||
|
[ -z "$selected_long_conn" ] && return
|
||||||
|
|
||||||
|
if ! uci -q get wifidogx."$selected_long_conn" >/dev/null; then
|
||||||
|
echo "Long connection: selected section $selected_long_conn does not exist" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
uci_validate_section "$NAME" "longconn" "$selected_long_conn" \
|
||||||
|
'long_conn_mode:or("ws","wss","mqtt","mqtts"):ws' \
|
||||||
|
'ws_server_hostname:string' \
|
||||||
|
'ws_server_port:port:443' \
|
||||||
|
'ws_server_path:string:/ws/wifidogx' \
|
||||||
|
'mqtt_server_hostname:string' \
|
||||||
|
'mqtt_server_port:port:1883' \
|
||||||
|
'mqtt_username:string' \
|
||||||
|
'mqtt_password:string'
|
||||||
|
|
||||||
|
case "$long_conn_mode" in
|
||||||
|
ws|wss)
|
||||||
|
if [ -z "$ws_server_hostname" ]; then
|
||||||
|
echo "Long connection: ws_server_hostname is required" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local ws_ssl
|
||||||
|
ws_ssl=$([ "$long_conn_mode" = "wss" ] && echo 1 || echo 0)
|
||||||
|
printf "WebSocket {\n\tWSServer %s\n\tWSServerPort %s\n\tWSServerPath %s\n\tWSServerSSL %s\n}\n" \
|
||||||
|
"$ws_server_hostname" "$ws_server_port" "$ws_server_path" "$ws_ssl" >> "$CONFIGFILE"
|
||||||
|
;;
|
||||||
|
mqtt|mqtts)
|
||||||
|
if [ -z "$mqtt_server_hostname" ]; then
|
||||||
|
echo "Long connection: mqtt_server_hostname is required" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local mqtt_ssl
|
||||||
|
mqtt_ssl=$([ "$long_conn_mode" = "mqtts" ] && echo 1 || echo 0)
|
||||||
|
printf "mqtt {\n\tserveraddr %s\n\tserverport %s\n\tmqttUseSSL %s\n\tmqttUsername %s\n\tmqttPassword %s\n}\n" \
|
||||||
|
"$mqtt_server_hostname" "$mqtt_server_port" "$mqtt_ssl" "${mqtt_username:-}" "${mqtt_password:-}" >> "$CONFIGFILE"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_external_interface() {
|
||||||
|
[ -z "$external_interface" ] && echo "No ExternalInterface " >&2 && return
|
||||||
|
local external_interface_name
|
||||||
|
|
||||||
|
if [ "$external_interface" = "wwan" ]; then
|
||||||
|
external_interface_name=$(ubus call network.interface."$external_interface" status | jsonfilter -e '@.device')
|
||||||
|
else
|
||||||
|
external_interface_name=$(uci get network."$external_interface".device)
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$external_interface_name" ] && echo "Failed to get device name for $external_interface" >&2 && return
|
||||||
|
|
||||||
|
printf "ExternalInterface %s\n" "$external_interface_name" >> "$CONFIGFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_wifidog_conf() {
|
||||||
|
[ -f "$CONFIGFILE" ] && rm -f "$CONFIGFILE"
|
||||||
|
local auth_server_mode_value='"cloud", "bypass", "local"'
|
||||||
|
|
||||||
|
# 获取选中的认证服务器
|
||||||
|
local selected_auth_server
|
||||||
|
selected_auth_server=$(uci get wifidogx.common.selected_auth_server 2>/dev/null)
|
||||||
|
|
||||||
|
|
||||||
|
uci_validate_section "$NAME" "$NAME" common \
|
||||||
|
'enabled:bool:0' \
|
||||||
|
"auth_server_mode:or($auth_server_mode_value)" \
|
||||||
|
'selected_auth_server:string' \
|
||||||
|
'selected_long_conn:string' \
|
||||||
|
'log_level:integer:7' \
|
||||||
|
'device_id:string' \
|
||||||
|
'check_interval:integer:60' \
|
||||||
|
'client_timeout:integer:5' \
|
||||||
|
'wired_passed:bool:1' \
|
||||||
|
'apple_cna:bool:0' \
|
||||||
|
'trusted_domains:list(host)' \
|
||||||
|
'trusted_wildcard_domains:list(string)' \
|
||||||
|
'trusted_macs:list(string)' \
|
||||||
|
'app_white_list:list(string)' \
|
||||||
|
'mac_white_list:list(string)' \
|
||||||
|
'wildcard_white_list:list(string)' \
|
||||||
|
'js_filter:bool:1' \
|
||||||
|
'auth_server_offline_file:string' \
|
||||||
|
'internet_offline_file:string' \
|
||||||
|
'local_portal:string' \
|
||||||
|
'external_interface:string' \
|
||||||
|
'enable_anti_nat:bool:0' \
|
||||||
|
'enable_privileged_ops:bool:0' \
|
||||||
|
'privileged_ops_secret:string:chawrt@2026' \
|
||||||
|
'ttl_values:string:64,128' \
|
||||||
|
'anti_nat_permit_macs:string' \
|
||||||
|
'disable_portal_auth:bool:1' \
|
||||||
|
'ap_device_id:string' \
|
||||||
|
'ap_mac_address:string' \
|
||||||
|
'ap_longitude:string' \
|
||||||
|
'ap_latitude:string' \
|
||||||
|
'location_id:string'
|
||||||
|
|
||||||
|
[ -n "$app_white_list" ] && add_white_list_entries "app_white_list" "domain_name" "trusted_domains"
|
||||||
|
[ -n "$mac_white_list" ] && add_white_list_entries "mac_white_list" "mac_address" "trusted_macs"
|
||||||
|
[ -n "$wildcard_white_list" ] && add_white_list_entries "wildcard_white_list" "wildcard_domain" "trusted_wildcard_domains"
|
||||||
|
|
||||||
|
prepare_external_interface
|
||||||
|
prepare_auth_server_settings
|
||||||
|
prepare_longconn_settings
|
||||||
|
prepare_device_info
|
||||||
|
config_foreach handle_gateway gateway
|
||||||
|
prepare_common_settings
|
||||||
|
}
|
||||||
|
|
||||||
|
service_triggers() {
|
||||||
|
procd_add_reload_trigger "wifidogx"
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
config_load "$NAME"
|
||||||
|
|
||||||
|
prepare_wifidog_conf
|
||||||
|
|
||||||
|
if [ "$enabled" -eq 0 ]; then
|
||||||
|
echo "wifidogx is disabled, exit..." >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
procd_open_instance
|
||||||
|
procd_set_param command "$PROG" -c "$CONFIGFILE" -s -f -d "$log_level"
|
||||||
|
procd_set_param respawn
|
||||||
|
procd_set_param file /etc/config/wifidogx
|
||||||
|
procd_close_instance
|
||||||
|
}
|
||||||
|
|
||||||
|
status_service() {
|
||||||
|
/usr/bin/wdctlx status
|
||||||
|
}
|
||||||
|
|
||||||
|
reload_service() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user