Hey guys,

I currently have a cgi application that has to talk to a remote mysql server.
I would very much like to encrypt these transactions since some of the information is fairly important. I haven't been able to see any perl modules ( such as Net::SSH and Net::SSH::Perl ) which provide methods for building and tearing down ssh tunnels.
I can fork a process to build the tunnel myself but this is messy and despite my best efforts to tear it down often leaves the tunnel standing. This forked process ( for tunnel building ) also means that I am currently sleeping the cgi process for a set interval to allow time for the tunnel to build and I am also concerned that if there is high traffic everything could fail ( though I try to handle that gracefully ).

simplistically the code looks like this
my $childPid = fork(); if ($childPid) { sleep 2; ## then open the database ## do stuff kill 'HUP', $childPid; } else { exec("ssh $user\@$host -L 3306:$host:3306 -N"); }
With this background my question is do you guys know of a module that I haven't found that deals with ssh tunneling so that the tunnel becomes an object to be used or something??

or alternatively can you suggest a way to get the code to recognise when the tunnel is up and inform the other process so that I am not dependant on a fixed sleep interval??

Thanks in Advance

In reply to ssh tunneling by live_in_hades

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.