Browse Source

make torrc file generic for multissid

Émile Morel 10 years ago
parent
commit
128aa45566
3 changed files with 9 additions and 6 deletions
  1. 4 1
      conf/init_ynh-torclient
  2. 3 3
      conf/torrc
  3. 2 2
      scripts/install

+ 4 - 1
conf/init_ynh-torclient

@@ -36,7 +36,6 @@ is_running() {
 }
 
 set_nat() {
-
   iptables -t nat -A PREROUTING -i ${torclient_wifi_device} -p udp --dport 53 -j REDIRECT --to-ports 9053
   iptables -t nat -A PREROUTING -i ${torclient_wifi_device} -p tcp ! --dport 53 --syn -j REDIRECT --to-ports 9040
 }
@@ -58,6 +57,8 @@ stop_tor() {
 }
 
 start_tor() {
+  cp /etc/tor/torrc.tpl /etc/tor/torrc
+  sed "s|<TPL:TOR_NETWORK>|${torclient_wifi_prefix}|g" -i /etc/tor/torrc
   service tor start
 }
 
@@ -187,6 +188,7 @@ if [ "$torclient_wifi_device_old" == "notset" ] && [ "$1" == "stop" ] ; then
   exit 1
 fi
 IFS='|' read -a ynh_wifi_ssid <<< "$(moulinette_get wifi_ssid)"
+IFS='|' read -a ynh_wifi_prefix <<< "$(moulinette_get ip4_nat_prefix)"
 ynh_multissid=$(moulinette_get multissid)
 for i in $(seq 0 $((${ynh_multissid} - 1))); do
   if [ ${ynh_wifi_ssid[$i]} == ${torclient_wifi_ssid} ] ; then
@@ -195,6 +197,7 @@ for i in $(seq 0 $((${ynh_multissid} - 1))); do
     else
       torclient_wifi_device="hotspot${i}"
     fi
+    torclient_wifi_prefix=${ynh_wifi_prefix[$i]}
 
     echo "Torclient will be active on $torclient_wifi_device device and $torclient_wifi_ssid SSID"
     break

+ 3 - 3
conf/torrc

@@ -23,7 +23,7 @@
 ## all (and only) requests that reach a SocksPort. Untrusted users who
 ## can access your SocksPort may be able to learn about the connections
 ## you make.
-SocksPolicy accept 10.0.242.0/24
+SocksPolicy accept <TPL:TOR_NETWORK>.0/24
 SocksPolicy reject *
 
 ## Logs go to stdout at level "notice" unless redirected by something
@@ -93,11 +93,11 @@ SocksPolicy reject *
 VirtualAddrNetwork 10.192.0.0/10
 Address ns0.ldn-fai.net
 DNSPort 9053
-DNSListenAddress 10.0.242.1
+DNSListenAddress <TPL:TOR_NETWORK>.1
 AutomapHostsOnResolve 1
 AutomapHostsSuffixes .exit,.onion
 TransPort 9040
-TransListenAddress 10.0.242.1
+TransListenAddress <TPL:TOR_NETWORK>.1
 
 ## If you have multiple network interfaces, you can specify one for
 ## outgoing traffic to use.

+ 2 - 2
scripts/install

@@ -46,7 +46,7 @@ DEBIAN_FRONTEND=noninteractive sudo apt-get --assume-yes --force-yes install ${p
 # Save arguments
 #sudo yunohost app setting torclient server_name -v "${server_name}"
 
-sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc
+sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
 sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
 sudo install -b -o root -g root -m 0644 ../conf/phpfpm_torclient.conf /etc/php5/fpm/pool.d/torclient.conf
 
@@ -92,7 +92,7 @@ sudo yunohost app ssowatconf
 
 # Stop tor client
 sudo service tor stop
-sudo insserv -d tor
+sudo insserv -r tor
 #sudo service ynh-torclient start
 sudo yunohost app setting torclient wifi_ssid -v notset
 sudo yunohost app setting torclient wifi_device_old -v notset