uci_validate_section xfrpc tcp $section \
'enabled:bool:1' \
+ 'service_type:string' \
'local_ip:host' \
'local_port:uinteger' \
- 'remote_port:uinteger'
+ 'remote_port:uinteger' \
+ 'start_time:string' \
+ 'end_time:string'
# if enabled is 0, then return
[ $enabled = 0 ] && return
+ # Validate service_type if provided
+ if [ -n "$service_type" ]; then
+ case "$service_type" in
+ ssh|mstsc|rdp|vnc|telnet)
+ # Valid service type
+ ;;
+ *)
+ echo "Error: Invalid service_type '$service_type'. Must be one of: ssh, mstsc, rdp, vnc, telnet"
+ return 1
+ ;;
+ esac
+ fi
+
# Write the validated settings to the config file
echo "[${section}]" >> "$config"
echo "type = tcp" >> "$config"
+ [ -z "$service_type" ] || echo "service_type = $service_type" >> "$config"
[ -z "$local_ip" ] || echo "local_ip = $local_ip" >> "$config"
[ -z "$local_port" ] || echo "local_port = $local_port" >> "$config"
[ -z "$remote_port" ] || echo "remote_port = $remote_port" >> "$config"
+ [ -z "$start_time" ] || echo "start_time = $start_time" >> "$config"
+ [ -z "$end_time" ] || echo "end_time = $end_time" >> "$config"
}
handle_http() {
'local_port:uinteger' \
'custom_domains:string' \
'subdomain:string' \
+ 'start_time:string' \
+ 'end_time:string'
# if enabled is 0, then return
[ $enabled = 0 ] && return
# Write the validated settings to the config file
echo "[${section}]" >> "$config"
echo "type = http" >> "$config"
+ echo "service_type = http" >> "$config"
[ -z "$local_ip" ] || echo "local_ip = $local_ip" >> "$config"
[ -z "$local_port" ] || echo "local_port = $local_port" >> "$config"
[ -z "$custom_domains" ] || echo "custom_domains = $custom_domains" >> "$config"
[ -z "$subdomain" ] || echo "subdomain = $subdomain" >> "$config"
+ [ -z "$start_time" ] || echo "start_time = $start_time" >> "$config"
+ [ -z "$end_time" ] || echo "end_time = $end_time" >> "$config"
}
handle_https() {
'local_ip:host' \
'local_port:uinteger' \
'custom_domains:string' \
- 'subdomain:string'
+ 'subdomain:string' \
+ 'start_time:string' \
+ 'end_time:string'
# if enabled is 0, then return
[ $enabled = 0 ] && return
# Write the validated settings to the config file
echo "[${section}]" >> "$config"
echo "type = https" >> "$config"
+ echo "service_type = https" >> "$config"
[ -z "$local_ip" ] || echo "local_ip = $local_ip" >> "$config"
[ -z "$local_port" ] || echo "local_port = $local_port" >> "$config"
[ -z "$custom_domains" ] || echo "custom_domains = $custom_domains" >> "$config"
[ -z "$subdomain" ] || echo "subdomain = $subdomain" >> "$config"
+ [ -z "$start_time" ] || echo "start_time = $start_time" >> "$config"
+ [ -z "$end_time" ] || echo "end_time = $end_time" >> "$config"
}
handle_socks5() {
uci_validate_section xfrpc socks5 $section \
'enabled:bool:1' \
- 'remote_port:uinteger'
+ 'remote_port:uinteger' \
+ 'start_time:string' \
+ 'end_time:string'
# if enabled is 0, then return
[ $enabled = 0 ] && return
echo "[${section}]" >> "$config"
echo "type = socks5" >> "$config"
[ -z "$remote_port" ] || echo "remote_port = $remote_port" >> "$config"
+ [ -z "$start_time" ] || echo "start_time = $start_time" >> "$config"
+ [ -z "$end_time" ] || echo "end_time = $end_time" >> "$config"
+}
+
+handle_iod() {
+ local section="$1"
+ local config="$2"
+
+ uci_validate_section xfrpc iod $section \
+ 'enabled:bool:1' \
+ 'local_port:uinteger' \
+ 'remote_port:uinteger'
+
+ # if enabled is 0, then return
+ [ $enabled = 0 ] && return
+
+ # Write the validated settings to the config file
+ echo "[${section}]" >> "$config"
+ echo "type = iod" >> "$config"
+ [ -z "$local_port" ] || echo "local_port = $local_port" >> "$config"
+ [ -z "$remote_port" ] || echo "remote_port = $remote_port" >> "$config"
}
service_triggers() {
procd_add_reload_trigger "$NAME"
+ procd_add_interface_trigger "interface.*.up" wan /etc/init.d/xfrpc restart
}
start_service() {
config_foreach handle_http http "$conf_file"
config_foreach handle_https https "$conf_file"
config_foreach handle_socks5 socks5 "$conf_file"
+ config_foreach handle_iod iod "$conf_file"
procd_open_instance
- procd_set_param command "$PROG" -c "$conf_file" -f -d $loglevel
+ procd_set_param command "$PROG" -c "$conf_file" -s -f -d $loglevel
procd_set_param file "$conf_file"
procd_set_param respawn
procd_close_instance