Albert Siersema wrote:
I will write a simple perl script that does it for you soon...

If I come up with a non-perl but GUI-y like solution i'll post it to the
list as well.

Well... I don't work with Windows...
So attached is a simple perl script that helps me interact with OpenVPN.

I hope some will find it useful!

-----------------------------------------------------------

This script provides a simple interface for OpenVPN management.
It allows a KDE user to handle the following commands:
- hold
- need-ok
- password

In order to use this script specify the following options at
OpenVPN configuration file:
    management-hold
    management 127.0.0.1 2222
    management-query-passwords

The best place to run this script is at .kde/Autostart, put
the following script at this location:
    #!/bin/sh
    exec openvpn-kde-dialogs.pl 2222

The script will signal openvpn into hold state when the
user logoffs.

Best Regards,
Alon Bar-Lev.
#!/usr/bin/perl
#
# This script provides a simple interface for OpenVPN management.
# It allows a KDE user to handle the following commands:
# - hold
# - need-ok
# - password
#
# In order to use this script specify the following options at
# OpenVPN configuration file:
#     management-hold
#     management 127.0.0.1 2222
#     management-query-passwords
#
# The best place to run this script is at .kde/Autostart, put
# the following script at this location:
#     #!/bin/sh
#     exec openvpn-kde-dialogs.pl 2222
#
# The script will signal openvpn into hold state when the
# user logoffs.
#
# History:
# 2005-11-03, Alon Bar-Lev (alon.bar...@gmail.com)
#     Written.
#

use strict;
use Net::Telnet;

my $FALSE = 0;
my $TRUE = (!$FALSE);

my $t = new Net::Telnet;

$SIG{'INT'} = $SIG{'STOP'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = sub {
        $t->print ("signal SIGUSR1");
        exit (1);
};

main (@ARGV);

sub main {
        my (
                $port
        ) = @_;

        my $fShouldConnect = $TRUE;

        if ($port eq undef) {
                printf STDERR ("usage: $0 port\n");
                exit (1);
        }

        while ($TRUE) {
                while ($fShouldConnect) {
                        my $r = $t->open (
                                host => "localhost",
                                port => $port,
                                errmode => "return"
                        );

                        if ($r == undef) {
                                sleep (5);
                        }
                        else {
                                $fShouldConnect = $FALSE;
                        }
                }

                my ($pre, $match) = $t->waitfor (
                        string => ">HOLD:",
                        string => ">PASSWORD:",
                        string => ">NEED-OK:",
                        errmode => "return",
                        timeout => 2
                );
                if ($match eq undef) {
                        my $msg = $t->errmsg;
                        if ($msg =~ /eof/) {
                                $fShouldConnect = $TRUE;
                        }
                }
                elsif ($match eq ">HOLD:") {
                        do {
                                `kdialog --title \"OpenVPN\" --yesno \"Release 
hold\"`;
                        } while ($? != 0);
                        $t->print ("hold release");
                }
                elsif ($match eq ">NEED-OK:") {
                        my $line = $t->getline ();
                        $line =~ /.*'(.*)'.* MSG:(.*)/;
                        my $req = $1;
                        my $msg = $2;

                        `kdialog --title \"OpenVPN\" --yesno \"$msg\"`;
                        if ($? == 0) {
                                $t->print ("needok \"$req\" ok");
                        }
                        else {
                                $t->print ("needok \"$req\" cancel");
                        }
                }
                elsif ($match eq ">PASSWORD:") {
                        my $line = $t->getline ();
                        $line =~ /.*'(.*)'.*/;
                        my $req = $1;
                        my $pass = `kdialog --title \"OpenVPN\" --password 
\"$req password:\"`;
                        if ($? == 0) {
                                $pass =~ s/[\r\n]//g;
                        }
                        else {
                                $pass = "";
                        }
                        $t->print ("password \"$req\" \"$pass\"");
                }
        }
}

Reply via email to