summaryrefslogtreecommitdiffstats
path: root/net/frp/files/frpc.uci-defaults
blob: 4887acc90617bf3ebb771b9ffd19ff4c64a3742f (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh

. /lib/functions.sh

changed=0
init_section=
package=frpc

find_init_section() {
	[ -z "$init_section" ] && init_section="$1"
	return 0
}

set_if_empty() {
	local section="$1"
	local option="$2"
	local value="$3"
	local cur

	config_get cur "$section" "$option"

	if [ -z "$cur" ]; then
		uci_set "$package" "$section" "$option" "$value"
		changed=1
	fi
}

copy_if_empty() {
	local section="$1"
	local old_option="$2"
	local new_option="$3"
	local value

	config_get value "$section" "$old_option"
	[ -n "$value" ] || return 0

	set_if_empty "$section" "$new_option" "$value"
}

upgrade_common() {
	local section="$1"
	local dashboard_tls_mode

	[ "$section" = "common" ] || return 0

	set_if_empty "$section" server_addr 127.0.0.1
	set_if_empty "$section" server_port 7000
	set_if_empty "$section" authentication_method token
	set_if_empty "$section" login_fail_exit true
	set_if_empty "$section" protocol tcp
	set_if_empty "$section" wire_protocol v1
	set_if_empty "$section" tcp_mux true
	set_if_empty "$section" tls_enable true
	set_if_empty "$section" disable_custom_tls_first_byte true

	config_get dashboard_tls_mode "$section" dashboard_tls_mode
	if [ -n "$dashboard_tls_mode" ]; then
		set_if_empty "$section" admin_tls_enable "$dashboard_tls_mode"
	else
		set_if_empty "$section" admin_tls_enable false
	fi

	copy_if_empty "$section" dashboard_addr admin_addr
	copy_if_empty "$section" dashboard_port admin_port
	copy_if_empty "$section" dashboard_user admin_user
	copy_if_empty "$section" dashboard_pwd admin_pwd
	copy_if_empty "$section" dashboard_tls_cert_file admin_tls_cert_file
	copy_if_empty "$section" dashboard_tls_key_file admin_tls_key_file

	set_if_empty "$section" pprof_enable false
	set_if_empty "$section" log_file console
	set_if_empty "$section" log_level info
	set_if_empty "$section" log_max_days 3
}

upgrade_init() {
	if [ -z "$init_section" ]; then
		init_section="$(uci add "$package" init)" || return 0
		changed=1
	fi

	set_if_empty "$init_section" stdout 1
	set_if_empty "$init_section" stderr 1
	set_if_empty "$init_section" respawn 1
}

upgrade_proxy_name() {
	local section="$1"
	local name

	[ "$section" != "common" ] || return 0

	config_get name "$section" name

	if [ -z "$name" ]; then
		uci_set "$package" "$section" name "$section"
		changed=1
	fi
}

config_load "$package"
config_foreach find_init_section init
upgrade_init
config_foreach upgrade_common conf
config_foreach upgrade_proxy_name conf

[ "$changed" -eq 1 ] && uci_commit "$package"

exit 0