Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion jvpn.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ mode=ncsvc
# If you want to use external program to provide the password use
# password=helper:scripts/password.sh
# format
# If there is a secondary password neccessary for login use, i.e. a secure token
# password=interactive-secondary
# format
password=interactive

# enable host checker support. This will require JRE to run tncc.jar process.
Expand All @@ -52,4 +55,3 @@ hostchecker=0

# debug - set to 1 to enable
debug=0

50 changes: 40 additions & 10 deletions jvpn.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@
my $script=$Config{"script"};
my $cfgpass=$Config{"password"};
my $workdir=$Config{"workdir"};
my $password="";
my $password=$ARGV[0];
my $password2=$ARGV[1];
my $hostchecker=$Config{"hostchecker"};
my $tncc_pid = 0;
my $with_passwords=(defined($password)) && (defined($password2));

my $supportdir = $ENV{"HOME"}."/.juniper_networks";
my $narport_file = $supportdir."/narport.txt";
Expand All @@ -79,7 +81,7 @@

# check password method
if(defined $cfgpass){
if($cfgpass !~ /^(interactive|helper:|plaintext:)/) {
if($cfgpass !~ /^(interactive|interactive-secondary|helper:|plaintext:)/) {
print "Configuration error: password is set incorrectly ($cfgpass), check jvpn.ini\n";
exit 1;
}
Expand Down Expand Up @@ -138,26 +140,37 @@
print "\n";
}

if ($cfgpass eq "interactive") {
if (!$with_passwords) {
if ($cfgpass eq "interactive") {
print "Enter PIN+password: ";
$password=read_input("password");
print "\n";
}
elsif ($cfgpass =~ /^plaintext:(.+)/) {
}
elsif ($cfgpass eq "interactive-secondary") {
print "Enter password: ";
$password=read_input("password");
print "\n";
print "Enter password#2: ";
$password2=read_input("password");
print "\n";
}
elsif ($cfgpass =~ /^plaintext:(.+)/) {
print "Using user-defined password\n";
$password=$1;
chomp($password);
}
elsif ($cfgpass =~ /^helper:(.+)/) {
}
elsif ($cfgpass =~ /^helper:(.+)/) {
print "Using user-defined script to get the password\n";
$password=run_pw_helper($1);
}
}

my $response_body = '';

my $res = $ua->post("https://$dhost:$dport/dana-na/auth/$durl/login.cgi",
[ btnSubmit => 'Sign In',
password => $password,
'password#2' => $password2,
realm => $realm,
tz => '60',
username => $username,
Expand Down Expand Up @@ -499,7 +512,7 @@
$ENV{'INTERFACE'}=$vpnint;
system($script);
}

write_pid($pid);
for (;;) {
$exists = kill SIGCHLD, $pid;
$debug && printf("\nChecking child: exists=$exists, $pid\n");
Expand All @@ -509,9 +522,11 @@
while (<STAT>) {
if ($_ =~ m/^\s*${vpnint}:\s*(\d+)(?:\s+\d+){7}\s*(\d+)/) {
print "\r \r";
printf("Duration: %02d:%02d:%02d Sent: %s\tReceived: %s",
my $status = sprintf("Duration: %02d:%02d:%02d Sent: %s\tReceived: %s",
int($now / 3600), int(($now % 3600) / 60), int($now % 60),
format_bytes($2), format_bytes($1));
print $status;
write_status($status);
}
}
close(STAT);
Expand Down Expand Up @@ -562,9 +577,11 @@
my $now = time - $start_t;
# printing RX/TX. This packet also contains encription type,
# compression and transport info, but length seems to be variable
printf("Duration: %02d:%02d:%02d Sent: %s\tReceived: %s",
my $status = sprintf("Duration: %02d:%02d:%02d Sent: %s\tReceived: %s",
int($now / 3600), int(($now % 3600) / 60), int($now % 60),
format_bytes(unpack('x[78]N',$data)), format_bytes(unpack('x[68]N',$data)));
print $status;
write_status($status);
sleep(1);
}

Expand Down Expand Up @@ -642,6 +659,10 @@ sub INT_handler {
$ENV{'MODE'}=$mode;
system($script);
}
if(-f "/tmp/jvpn.state"){
print "delete jvpn.state file\n";
remove("/tmp/jvpn.state");
}
print "Exiting\n";
exit(0);
}
Expand Down Expand Up @@ -858,3 +879,12 @@ sub get_new_tap_interface
}
return '';
}

sub write_status
{
my ($status) = @_;
my $filename = '/tmp/jvpn.state';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh $status;
close $fh;
}