Transmission+OpenVPN - automating vpn-server changes

Status
Not open for further replies.

unca_NAS

Explorer
Joined
Mar 25, 2012
Messages
87
Been using jailed vpn+transmission for some time now, mostly happy with my current setup.

However lately many popular trackers have started blocking certain vpn-servers completely > you cannot connect to the tracker - period. Of course you can still download stuff but with much slower speeds. Disconnecting the vpn and reconnecting to another server sometimes helps, but this is 'dull manual labor'. And when finding a server that is welcome to most of the trackers, you slowly but eventually get banned, usually within 24 hours.

I've been planning to write (with my very limited FreeNAS scripting skills, I must add) a cron-jobbed script that is to do the following:.
- when ran, jexec the jail
- initiate a make a connection to - say - at least three or four popular trackers, one at a time - via the vpn-tube
- successfull connection adds value of check-out variable with 1
- if after the check-cycle the check-value is three or four, assume that everything is hunky-dory, leave openvpn and trasmission running and exit
- if value is two or less, kill transmission-daemon, kill openvpn, start openvpn connection to a different server (start with different config-file)
- verify that both openvpn and transmission are running (vpn-interface and daemon exist)
- initiate a connection etc

Cron is to run the service again in 30 minutes.

I "might" get this done by myself, but some problems I havent been able to solve

> how the current JID (jail ID) can be extracted to be used with 'jexec N bash /to/stuff'
> whats the best way to verify that udp://im.a.tracker:1234 lets your bt-client to connect (pinging and telnetting have I tried, with no success)

I know, way over my head here, but hey, if you dont try, you never learn anything :)
 

unca_NAS

Explorer
Joined
Mar 25, 2012
Messages
87
Not really, but found an alternative - manual script. Simple, but working. Kudos to The Maker :)
(you have to kill/stop the openvpn prior to running the script. Adding kill-stop command to row 2 should do the trick)

Code:
#!/bin/bash
show_menu(){
    NORMAL=`echo "\033[m"`
    MENU=`echo "\033[36m"` #Blue
    NUMBER=`echo "\033[33m"` #yellow
    FGRED=`echo "\033[41m"`
    RED_TEXT=`echo "\033[31m"`
    ENTER_LINE=`echo "\033[33m"`
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${MENU}${NORMAL}"
    echo -e "${MENU}${NORMAL}"
    echo -e "${MENU}******${NUMBER} 1)${MENU} 1st.vpn.server.name ${NORMAL}"
    echo -e ""
    echo -e "${MENU}******${NUMBER} 2)${MENU} 2nd.vpn.server.name ${NORMAL}"
    echo -e ""
    echo -e "${MENU}******${NUMBER} 3)${MENU} 3rd.vpn.server.name ${NORMAL}"
    echo -e ""
    echo -e "${MENU}******${NUMBER} 4)${MENU} 4th.vpn.server.name ${NORMAL}"
    echo -e ""
    echo -e "${MENU}******${NUMBER} 5)${MENU} Disconnect VPN ${NORMAL}"
    echo -e "${MENU}${NORMAL}"
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"
    read opt
}
function option_picked() {
    COLOR='\033[01;31m' # bold red
    RESET='\033[00;00m' # normal white
    MESSAGE=${@:-"${RESET}Error: No message passed"}
    echo -e "${COLOR}${MESSAGE}${RESET}"
}

clear
show_menu
while [ opt != '' ]
    do
    if [[ $opt = "" ]]; then 
            exit;
    else
        case $opt in
        1) clear;
        option_picked "Option 1 Picked";
   /usr/local/etc/rc.d/openvpn start --config /path/to/first.openvpn.conf
           show_menu;
        ;;

        2) clear;
            option_picked "Option 2 Picked";
   /usr/local/etc/rc.d/openvpn start --config /path/to/second.openvpn.conf
            show_menu;
            ;;

        3) clear;
            option_picked "Option 3 Picked";
   /usr/local/etc/rc.d/openvpn start --config /path/to/third.openvpn.conf
            show_menu;
            ;;

        4) clear;
            option_picked "Option 4 Picked";
   /usr/local/etc/rc.d/openvpn start --config /path/to/fourth.openvpn.conf
            show_menu;
            ;;
        5) clear;
   option_picked "Option 5 picked";
   sudo killall -SIGINT openvpn
   show_menu;
            ;;

        x)exit;
        ;;

        \n)exit;
        ;;

        *)clear;
        option_picked "Pick an option from the menu";
        show_menu;
        ;;
    esac
fi
done
 
Status
Not open for further replies.
Top