mirror of
https://github.com/openwrt/packages.git
synced 2025-12-21 21:24:31 +04:00
tor-hs: reformat and cleanup
Remove unused description. Quote variables. Use hostname_file variable. Remove unnecessary quotes around "common". Use echo -n to truncate a TORRC_FILE. Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
This commit is contained in:
committed by
Josef Schlehofer
parent
783b92d5b3
commit
a97989f0c2
@@ -6,23 +6,21 @@ STOP=52
|
|||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
TORRC_FILE=/etc/tor/torrc_generated # file with torrc config
|
TORRC_FILE=/etc/tor/torrc_generated # file with torrc config
|
||||||
HS_DIR_PATH=/etc/tor/hidden_service #hidden service directory path
|
HS_DIR_PATH=/etc/tor/hidden_service # onion services directory
|
||||||
TOR_USER=tor
|
TOR_USER=tor
|
||||||
|
|
||||||
config_tor() {
|
config_tor() {
|
||||||
local restart_tor update_config
|
local restart_tor update_config
|
||||||
config_get_bool restart_tor "common" RestartTor
|
config_get_bool restart_tor common RestartTor
|
||||||
config_get_bool update_config "common" UpdateTorConf
|
config_get_bool update_config common UpdateTorConf
|
||||||
|
|
||||||
tail_conf=$(uci show tor.conf.tail_include 2>/dev/null)
|
tail_conf=$(uci show tor.conf.tail_include 2>/dev/null)
|
||||||
head_conf=$(uci show tor.conf.head_include 2>/dev/null)
|
head_conf=$(uci show tor.conf.head_include 2>/dev/null)
|
||||||
echo "tail_conf $tail_conf"
|
|
||||||
|
|
||||||
if [ "$update_config" = "1" ]; then
|
if [ "$update_config" = "1" ]; then
|
||||||
if [ -n "$(echo $tail_conf | grep $TORRC_FILE)" ] || [ -n "$(echo $head_conf | grep $TORRC_FILE)" ]; then
|
if [ -n "$(echo $tail_conf | grep $TORRC_FILE)" ] || [ -n "$(echo $head_conf | grep $TORRC_FILE)" ]; then
|
||||||
echo "Info. Not updating tor configuration"
|
echo "Info. Not updating tor configuration"
|
||||||
else
|
else
|
||||||
#uci add_list
|
|
||||||
echo "Info. Updating tor configuration"
|
echo "Info. Updating tor configuration"
|
||||||
uci add_list tor.conf.tail_include="$TORRC_FILE"
|
uci add_list tor.conf.tail_include="$TORRC_FILE"
|
||||||
uci commit tor
|
uci commit tor
|
||||||
@@ -41,7 +39,7 @@ handle_hs_ports_conf() {
|
|||||||
|
|
||||||
public_port="${value#*;}"
|
public_port="${value#*;}"
|
||||||
local_port="${value%;*}"
|
local_port="${value%;*}"
|
||||||
echo "HiddenServicePort $public_port $ipv4:$local_port">>$TORRC_FILE
|
echo "HiddenServicePort $public_port $ipv4:$local_port" >> "$TORRC_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_hs_conf() {
|
parse_hs_conf() {
|
||||||
@@ -50,7 +48,6 @@ parse_hs_conf() {
|
|||||||
|
|
||||||
config_get name "$config" Name
|
config_get name "$config" Name
|
||||||
[ -z "$name" ] && return 0
|
[ -z "$name" ] && return 0
|
||||||
config_get description "$config" Description
|
|
||||||
config_get_bool enable_hs "$config" Enabled 0
|
config_get_bool enable_hs "$config" Enabled 0
|
||||||
config_get ipv4 "$config" IPv4
|
config_get ipv4 "$config" IPv4
|
||||||
|
|
||||||
@@ -61,7 +58,7 @@ parse_hs_conf() {
|
|||||||
chmod 700 "$HS_DIR_PATH/"
|
chmod 700 "$HS_DIR_PATH/"
|
||||||
chmod 700 "$HS_DIR_PATH/$name/"
|
chmod 700 "$HS_DIR_PATH/$name/"
|
||||||
|
|
||||||
echo "HiddenServiceDir $HS_DIR_PATH/$name" >>$TORRC_FILE
|
echo "HiddenServiceDir $HS_DIR_PATH/$name" >> "$TORRC_FILE"
|
||||||
config_list_foreach "$config" PublicLocalPort handle_hs_ports_conf "$ipv4"
|
config_list_foreach "$config" PublicLocalPort handle_hs_ports_conf "$ipv4"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -75,11 +72,11 @@ parse_hs_conf_hooks() {
|
|||||||
config_get enable_hs "$config" Enabled 0
|
config_get enable_hs "$config" Enabled 0
|
||||||
config_get hook_script "$config" HookScript
|
config_get hook_script "$config" HookScript
|
||||||
|
|
||||||
hostname="$HS_DIR_PATH/$name/hostname"
|
hostname_file="$HS_DIR_PATH/$name/hostname"
|
||||||
|
|
||||||
# check if we should run hook_script
|
# check if we should run hook_script
|
||||||
if [ "$enable_hs" = "true" ] && [ -x "$hook_script" ] && [ -f "$hostname" ] ; then
|
if [ "$enable_hs" = "true" ] && [ -x "$hook_script" ] && [ -f "$hostname_file" ]; then
|
||||||
hostname_uri=$(cat "$hostname")
|
hostname_uri=$(cat "$hostname_file")
|
||||||
# call hook script
|
# call hook script
|
||||||
$hook_script "--update-onion" "$hostname_uri"
|
$hook_script "--update-onion" "$hostname_uri"
|
||||||
fi
|
fi
|
||||||
@@ -87,8 +84,8 @@ parse_hs_conf_hooks() {
|
|||||||
|
|
||||||
parse_common_conf() {
|
parse_common_conf() {
|
||||||
local hs_dir generated_config
|
local hs_dir generated_config
|
||||||
config_get generated_config "common" GenConf
|
config_get generated_config common GenConf
|
||||||
config_get hs_dir "common" HSDir
|
config_get hs_dir common HSDir
|
||||||
[ -n "$hs_dir" ] && HS_DIR_PATH="$hs_dir"
|
[ -n "$hs_dir" ] && HS_DIR_PATH="$hs_dir"
|
||||||
[ -n "$generated_config" ] && TORRC_FILE="$generated_config"
|
[ -n "$generated_config" ] && TORRC_FILE="$generated_config"
|
||||||
}
|
}
|
||||||
@@ -96,17 +93,13 @@ parse_common_conf() {
|
|||||||
start_service() {
|
start_service() {
|
||||||
config_load tor-hs
|
config_load tor-hs
|
||||||
# clean config
|
# clean config
|
||||||
echo "" > $TORRC_FILE # clean config
|
echo -n "" > "$TORRC_FILE"
|
||||||
|
|
||||||
# load common config
|
# load common config
|
||||||
parse_common_conf
|
parse_common_conf
|
||||||
|
|
||||||
# load hs service
|
# load hs service
|
||||||
config_foreach parse_hs_conf hidden-service
|
config_foreach parse_hs_conf hidden-service
|
||||||
|
|
||||||
# update tor config
|
# update tor config
|
||||||
config_tor
|
config_tor
|
||||||
|
|
||||||
# load and run tor-hs hooks
|
# load and run tor-hs hooks
|
||||||
config_foreach parse_hs_conf_hooks hidden-service
|
config_foreach parse_hs_conf_hooks hidden-service
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user