Last active
October 23, 2023 19:22
-
-
Save zhujunsan/8a329d07ad7ebcbbac0aba6e93954100 to your computer and use it in GitHub Desktop.
Openwrt sockd init scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config sockd | |
option external 'wg0' | |
option internal '127.0.0.1' | |
option clientmethod 'none' | |
option socksmethod 'none' | |
option user_privileged 'root' | |
option user_notprivileged 'nobody' | |
option logoutput 'syslog' | |
option port '10080' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
[ "$ACTION" = ifup ] || exit 0 | |
/etc/init.d/sockd enabled && /etc/init.d/sockd start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
START=90 | |
USE_PROCD=1 | |
PROG=/usr/sbin/sockd | |
CONFIGFILE="/var/etc/sockd.conf" | |
xappend() { | |
local value="$1" | |
echo "${value#--}" >> $CONFIGFILE | |
} | |
append_parm() { | |
local section="$1" | |
local option="$2" | |
local switch="$3" | |
local defval="$4" | |
local _loctmp | |
config_get _loctmp "$section" "$option" | |
if [ -z "$_loctmp" ]; then | |
[ -z "$defval" ] && return 0 | |
xappend "$switch: $defval" | |
else | |
xappend "$switch: $_loctmp" | |
fi | |
} | |
sockd(){ | |
local cfg="$1" | |
append_parm "$cfg" "socksmethod" "--socksmethod" | |
append_parm "$cfg" "clientmethod" "--clientmethod" | |
append_parm "$cfg" "user_privileged" "--user.privileged" "root" | |
append_parm "$cfg" "user_notprivileged" "--user.notprivileged" "nobody" | |
append_parm "$cfg" "logoutput" "--logoutput" "syslog" | |
local _extif _intif _extip _intip | |
config_get _extif "$cfg" "external" | |
[ -z "$_extif" ] && _extif="wan" | |
config_get _intif "$cfg" "internal" | |
[ -z "$_intif" ] && _intif="lan" | |
network_flush_cache | |
network_get_ipaddr _extip $_extif | |
xappend "--external: $_extif" | |
network_get_ipaddr _intip $_intif | |
local _port | |
config_get _port "$cfg" "port" "1080" | |
xappend "--internal: $_intif port = $_port" | |
echo >> $CONFIGFILE | |
} | |
service_triggers() { | |
procd_add_reload_trigger "sockd" | |
# procd_add_network_trigger "wan"|"pppoe-wan" | |
} | |
boot() { | |
# Will be launched through hotplug | |
return 0 | |
} | |
start_service() { | |
include /lib/functions | |
config_load sockd | |
procd_open_instance | |
procd_set_param command $PROG -f $CONFIGFILE | |
procd_set_param file $CONFIGFILE | |
procd_set_param netdev wan | |
procd_set_param respawn | |
procd_close_instance | |
echo "# auto-generated config file from /etc/config/sockd" > $CONFIGFILE | |
config_foreach sockd sockd | |
[ -f /etc/sockd.conf ] && { | |
cat /etc/sockd.conf >> $CONFIGFILE | |
} | |
} | |
reload_service() { | |
return 0 | |
} | |
stop_service() { | |
return 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client pass { | |
from: 0.0.0.0/0 to: 0.0.0.0/0 | |
log: error | |
# log: connect disconnect error | |
} | |
socks pass { | |
from: 0.0.0.0/0 to: 0.0.0.0/0 | |
protocol: tcp udp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment