tsocks.conf

m.
2005-09-16
2016-03-05
  • m.

    m. - 2005-09-16

    Is there any way for tsocks to read user-defined config file instead of /etc/tsocks.conf?
    I have login/password for proxy in this file and don't want it to be readable by anybody else but me.. something like $HOME/.tsocks.conf would be fine..
    Thanks

    m.

     
    • Adam Katz

      Adam Katz - 2007-03-27

      I am also interested in a ~/.tsocks.conf file that would trump the defaults at /etc/tsocks.conf ... this is standard convention and I am surprised that it is not in place, especially when there are issues with root using tsocks to begin with.

      I would also like command-line arguments that can trump the configuration file(s), like
        tsocks --server=127.0.0.1:1080 --type=5 telnet 192.168.0.1
      or the shorter
        tsocks -s 127.0.0.1:1081 -t5 telnet 192.168.0.1

      Hell, I'll even help on the shell scripting side ... I just can't contribute to the library.

      If my code gets mangled here, I may give up.  Nobody is reading this anyway.

      #!/bin/sh

      # read in application defaults here

        # these are dummy defaults so that you can test properly
        local=127.0.0.0/255.0.0.0
        server=default-server
        type=5
        port=1080

      # read in default config (/etc/tsocks.conf) here (overriding app defaults)

      # read in user config (~/.tsocks.conf) here (overriding system defaults)

      # now we read in the command line arguments to override the above

      # display 1st arg when it exists and is unique, otherwise second arg and FALSE
      get_value() {
        if [ -n "$1" ] && [ "$1" != "$2" ]
          then echo "$1"
          else echo "$2"; false # this return value is used below to shift arguments
        fi
      }

      while true; do
        case $1 in
          --server* ) server=`get_value "${1#--server=}" "$2" || shift` ;;
          -s* | -d* ) server=`get_value "${1#-[sd]}"  "$2" || shift` ;;
          --port* )   cport=`get_value "${1#--port=}" "$2" || shift` ;;
          -p* )       cport=`get_value "${1#-p}"      "$2" || shift` ;;
          --type* )   type=`get_value "${1#--type=}"  "$2" || shift` ;;
          -t* )       type=`get_value "${1#-t}"       "$2" || shift` ;;
          --local* )  local=`get_value "${1#--local=}" "$2" || shift` ;;
          -l* )       local=`get_value "${1#-l}"      "$2" || shift` ;;
          * )         break ;;
        esac
        shift
      done

      # if syntax is "server:port" then separate into server and port
      p="${server#*:}"
      server="${server%:*}"
      [ -z "$cport" ] && [ "$server" != "$p" ] && cport="$p"
      [ -n "$cport" ] && port="$cport"

      echo "server: '$server'"
      echo "port: '$port'"
      echo "type: '$type'"
      echo "local net: '$local'"
      echo "execute code: '$@'"
      echo "(note, execute code will actually be passed with correct quoting)"

       
    • Adam Katz

      Adam Katz - 2007-03-27

      that cool logic with shift doesn't work in a subshell (back-ticked command substitution). 
      also note that indentation was removed and spacing truncated (likely anti-ascii porn) :-(

      fix:

      #!/bin/sh

      # read in application defaults here

        # these are dummy defaults so that you can test properly
        local=127.0.0.0/255.0.0.0
        server=default-server
        type=5
        port=1080

      # read in default config (/etc/tsocks.conf) here (overriding app defaults)

      # read in user config (~/.tsocks.conf) here (overriding system defaults)

      # now we read in the command line arguments to override the above

      # display 1st arg when it exists and is unique, otherwise second arg and FALSE
      get() {
        [ -n "$1" ] && [ "$1" != "$2" ] && echo "$1" || echo "$2"
      }

      while true; do
      unset r
      case $1 in
      --server* ) server=`get "${1#--server=}" "$2"`; [ "$server" = "$2" ] && r=2 ;;
      -s* | -d* ) server=`get "${1#-[sd]}"     "$2"`; [ "$server" = "$2" ] && r=2 ;;
      --port* ) cport=`get "${1#--port=}"      "$2"`; [ "$cport"  = "$2" ] && r=2 ;;
      -p* )           cport=`get "${1#-p}"     "$2"`; [ "$cport"  = "$2" ] && r=2 ;;
      --type* ) type=`get "${1#--type=}"       "$2"`; [ "$type"   = "$2" ] && r=2 ;;
      -t* )           type=`get "${1#-t}"      "$2"`; [ "$type"   = "$2" ] && r=2 ;;
      --local* ) local=`get "${1#--local=}"    "$2"`; [ "$local"  = "$2" ] && r=2 ;;
      -l* )           local=`get "${1#-l}"     "$2"`; [ "$local"  = "$2" ] && r=2 ;;
      * )  break ;;
      esac
      shift $r
      done

      # if syntax is "server:port" then separate into server and port
      p="${server#*:}"
      server="${server%:*}"
      [ -z "$cport" ] && [ "$server" != "$p" ] && cport="$p"
      [ -n "$cport" ] && port="$cport"

      echo "server: '$server'"
      echo "port: '$port'"
      echo "type: '$type'"
      echo "local net: '$local'"
      echo "execute code: '$@'"
      echo "(note, execute code will actually be passed with correct quoting)"

       
    • Adam Katz

      Adam Katz - 2009-05-29

      Four years after the initial query, two years after my pondering, I discover that the actual tsocks program is itself a posix script, and that libtsocks works fully via shell environment variables, including on that sets the tsocks configuration file.  I'm also a far better scripter these days.

      I have fully implemented ALL configuration options on the command line, plus several various configuration file manipulators (alternate config file, save command line in config file, etc), help, descriptions, and more.

      http://khopesh.com/scripts/tsocks

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks