Guest User!

You are not Sophos Staff.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Astaro StrongSWAN ipsec wrapper script

Uploaded in this post is a script file  vpn.sh.txt.
(.txt extension so uploader would let me upload.)

The file has instructions on even how to put it onto your Astaro device through the Terminal.

This script makes it a bit more human friendly to manage and monitor the IPSec VPN connections. But the BEST thing is this: I've had problems with 1 or 2 (out of 30) VPN connections that would go down and stay down until I manually reset them. So one thing this script can do is "monitor" a specific connection and automatically reset it if it detects that it is down.

Quite annoying and may or may not be related to Astaro.. threads seem to try to point fingers at certain types of Cisco routers.

Anyway, because the Astaro router is so brilliantly deployed on a Linux system, that allows Linux folks to fix things and make improvements without having to wait for or get denied by Support. 

In order to do this, you have to SSH into the router and then log into the 'root' account. Doing this will certainly not be supported by their support, however I have had very little that is actually supported from them so doing it by utilizing Linux itself is much more supportable on the Internet. I feel it is almost a crime to provide this router on Linux and start closing down those doors if they choose to do it. Instead of providing means for Linux experts to customize their Astaro functionality, they create roadblocks to prevent it.

So give this script a shot. I'm using it. I may post updates to any fixes if I find them.


This thread was automatically locked due to age.
  • Hi, this could be useful... what Astaro versions have you tested this on?

    Thanks!
    Barry
  • Hi,

    looks great, will try it.
    Any ideas of a easy way to find the right name for a VPN connection?
    The script needs the internal name (like "S_REF_QxRsxiopNQ_1") but I see no way to find this name except deeply looking into the IPSec Log file.

    Thanks & Ciao,
    Alfred
  • I thought of that. It's the "list" command. It will show you all the active connection names. And if you run the script without any command it will show you what commands it has with explanations.

    There is another way to list the connections which is not easy to script at all:
    Run command: cc
    Then run command: ipsec      which actually is like a sub-command in the cc program.
    Then run command: connections@   yeah, you need the "@" symbol.
    You can then copy with mouse, and then type quit to exit this program.

    This will show you a proper list, but I don't know how to get that from a script. Further, if I use this cc program then the script becomes more Astaro than StrongSwan ipsec based. I'd prefer wherever practical to focus on the StrongSwan side, with Astaro specific logic to be added carefully or via another script.
    So the way my script works is that it scans the  'ipsec status' output and just filters for some of the lines and then uses other UNIX commands to sort and pretty up the output. These names are slightly different in that they have an extra "S_" at beginning but with or without that seems to work fine for the ipsec commands.

    So, let's say you save the script filename as just "vpn", I would do this:
    vpn list
    Then with mouse, double-click on the name I want which should highlight it (depending on terminal software and emulation you're using), and then right-click to copy it.
    Then I type:
    vpn status 
    and then I right-click to paste what was copied, to make it appear like:
    vpn status S_REF_whatever
  • Interesting...

    I used simply the way of deactivating a connection and comparing "vpn.sh status" before and after.

    Of course, the way of simply copy/paste from that "cc" thing doesn't work as the connections are missing the leading "S_" and trailing "_0" (or higher number).

    But, at least, it's something :-)

    I am now using your script to monitor 4 connections (or 3 connections, one has to connections _0 and _1) where we always have problems and it seems to work like a charm!

    Thanks for the script.

    Oh, btw, isn't the recommended way to look for an empty string "-z STRING" instead of "STRING == ''"?
    (just nipicking [;)] )

    Thanks & Ciao,
    Alfred

  • I used simply the way of deactivating a connection and comparing "vpn.sh status" before and after.

    One note...  it takes a bit of time before ipsec status determines a connection is down before it actually is down, so there could be a delay in that status output.

    Of course, the way of simply copy/paste from that "cc" thing doesn't work as the connections are missing the leading "S_" and trailing "_0" (or higher number).

    But, at least, it's something :-)

    I'm trying to tell you that you don't need to worry about the "S_" thing. It will work with or without it. And all the time the output does show the "_0" at the end because those are specific tunnels. If one of your VPN connections has multiple tunnels in it, you'll see "_1", etc. You do not need to remove those. Copying that whole thing does work. Unless maybe you're trying on a new Astaro version and they changed something? What version are you using this with? And please verify that you really do need to manipulate those names before they actually work.

    I am now using your script to monitor 4 connections (or 3 connections, one has to connections _0 and _1) where we always have problems and it seems to work like a charm!

    Thanks for the script.

    Awesome. Makes me very happy to help make someone's life easier.


    Oh, btw, isn't the recommended way to look for an empty string "-z STRING" instead of "STRING == ''"?
    (just nipicking [;)] )

    Yes it is. However the == ""  does function correctly, so whenever possible I prefer to write code that is most easily read, rather than using some special code or option that someone would have to look up to remember what it means. While the == "" is clearly obvious to anyone who may not even know the scripting language.
  • Hi everyone. I made an update to the script. It now allows you to include pinging for IP's or testing for IP and ports as part of the VPN monitoring. If they fail it will reset the VPN. So you can put in the protected IP's on the other side to watch for.

    Now why would I need that? Well, because it has happened more than once where the VPN indicates it's running fine but traffic does not get through. And after resetting the VPN suddenly it works. BEATS ME!! but I figured it wasn't much more effort to add it.

    Just for fun, here is the "help" from the script that shows what it can do:


    Commands for this script:

    list        Lists the VPN connection names to use for other commands.

    status      Shows if it detects the named connections listed as parameters
                as UP or DOWN. Shows status for all connections if none listed.

    reset       Resets named connections listed as parameters.

    log         Tails the encrypted TCP dump of the named connection.

    monitor     Watches the status of a named connection and automatically resets
                if it goes down. Also has ability to use ping or an IP[[:P]]ort to
                check while monitoring. If any of the pings or tests or an IP[[:P]]ort
                fail, the VPN will be reset. This is in result of sometimes having
                the VPN indicate it's up while traffic stops working.

    Examples:   (assuming you name this script just 'vpn')
    vpn monitor S_REF_IpsSitVpn***_0 ping 192.168.0.1 ping 192.168.0.2
                This will check the VPN tunnel and also ping those IP's.

    vpn monitor S_REF_IpsSitVpn***_0 ping 192.168.0.1 ipport 192.168.0.2:80
                This will ping 192.168.0.1 and check port 80 on 192.168.0.2
                in the very possible case the ICMP ping is not allowed on a 
                firewall.

    If you specify  --debug  as the first parameter, more verbose output will 
    be created.
  • Hey coewar,

    Liking the looks of this script however some things that I saw in the code that irks the programmer in me. [[:)]]

    # In command shells like DOS or UNIX, a command returning error level of 0 means it is successful.
    
    TRUE=0
    FALSE=1


    1) The reversing of TRUE/FALSE will cause confusion amongst programmers. I pretty much have to stop every time there's a $TRUE or $FALSE in the code and mentally negate the result, then use the negated result in the logical operators. Using say, $SUCCESS OR $FAILURE instead would make the code easier to read.

    2) I used logical TRUE's for the debug statements as it makes sense in that context.

    Practicing what I preach, I've submitted my revision back to you for your review. Quite an elegant little piece nevertheless. [[:)]]

    EDIT: Minor update to the script. Forgot that bash doesn't have true/false predefined, you have to do so yourself.
  • Hi everyone. I made an update to the script. It now allows you to include pinging for IP's or testing for IP and ports as part of the VPN monitoring. If they fail it will reset the VPN. So you can put in the protected IP's on the other side to watch for.


    Nice, we also have that kind of connections.
    But sadly, that ping and monitor doesn't work (at least for us).
    For example, the tunnel is configured from one IP address in our LAN to another IP address in the remote LAN.
    Ping from the Astaro doesn't work as it has - of course - another IP, it only works from the local IP that's configured in the tunnel.
    So, monitoring from Astaro this way always fails for all connections.

    Which brings me to another idea. Maybe it's possible to have that monitoring run on a local (Windows) client and if ping fails (for a spezified time) a script on the Astaro is executed to reconnet the tunnel (rsh or something like that, maybe?).

    Ciao, Alfred

  • # In command shells like DOS or UNIX, a command returning error level of 0 means it is successful.
    
    TRUE=0
    FALSE=1


    1) The reversing of TRUE/FALSE will cause confusion amongst programmers. I pretty much have to stop every time there's a $TRUE or $FALSE in the code and mentally negate the result, then use the negated result in the logical operators. Using say, $SUCCESS OR $FAILURE instead would make the code easier to read.

    2) I used logical TRUE's for the debug statements as it makes sense in that context.

    Practicing what I preach, I've submitted my revision back to you for your review. Quite an elegant little piece nevertheless. [:)]



    I agree with you. I don't do much BASH programming so didn't know what to name those values as testing just for 0 or 1 confuses me even more than an obvious alias like TRUE/FALSE.  But SUCCESS/FAILURE seems like a fine compromise to that. Thanks.