From: Kilian Saffran Date: Fri, 27 Apr 2018 11:15:24 +0000 (+0200) Subject: openvpn changes X-Git-Tag: 3.19.1^0 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=0a4d566952282c5aa5b5096dc058f9fee60eaa61;p=creorga.git openvpn changes --- diff --git a/Tools/openvpn.pl b/Tools/openvpn.pl deleted file mode 100644 index bc85414..0000000 --- a/Tools/openvpn.pl +++ /dev/null @@ -1,153 +0,0 @@ -#!C:\Stawberry\Perl\bin\perl.exe - -use strict; -use Getopt::Long; -use File::Find::Rule; -use File::Basename; -my $connect =0; -my $disconnect=0; -GetOptions("connect" => \$connect,"disconnect" => \$disconnect); -my $conn = ""; -print "Starting vpn!\n"; -if (! -d $ENV{USERPROFILE}.'/OpenVPN/config' ){ - print "no default VPN Configuration found missing: ".$ENV{USERPROFILE}.'/OpenVPN/config'."\n"; - exit(1); -} -if (-e $ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'){ - - open(CFG,$ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'); - while (my $l = ){ - if ($l =~ /^OPENVPNNAME=/){ - ($conn) = $l =~ m/OPENVPNNAME=(.+)$/; - chomp($conn); - } - } - close(CFG); -} -if ($conn eq "" && $disconnect != 1){ - print "No configuration, no disconnect forced!Nothing to do!\n"; - exit(0); -} -if ($connect == $disconnect){ - if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ - my $status = &vpnstatus(); - if (exists($status->{active})){ - &vpndisconnect(); - } else { - &vpnconnect(); - } - } else { - &vpndisconnect(); - } -}else{ - if ($connect == 1){ - &vpnconnect(); - } else { - &vpndisconnect(); - } -} - -sub vpnconnect(){ - - my $uprofile = ""; - #is gui or vpn running - - if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ - my $status = &vpnstatus(); - if (!exists($status->{active}->{$conn})){ - if ($^O eq "MSWin32"){ - if (exists($status->{gui})){ - system('taskkill.exe /F /IM openvpn.exe'); - system('taskkill.exe /F /IM openvpn-gui.exe'); - sleep(1); - } - my $st = system('start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect '.$conn.'.ovpn'); - if ($st == 0){ - - my $bconn = 0; - my $i = 30; - while ($bconn == 0 || $i > 0){ - $status = &vpnstatus(); - if (exists($status->{active}->{$conn})){ - - $bconn = 1; - } - $i--; - sleep(1); - } - } - } - } - } - -} - -sub vpnstatus(){ - my $status = (); - if ($^O eq "MSWin32"){ - - my $tasklist = `tasklist`; - my @task = split("\n",$tasklist); - my @ovpntasks = grep(/openvpn-gui\.exe/,@task); - if (scalar(@ovpntasks) > 0){ - $status->{gui} = "running"; - } - @ovpntasks = grep(/openvpn.exe/,@task); - #$status->{active_connections} = scalar(@ovpntasks); - if (scalar(@ovpntasks) > 0){ - my $ff = File::Find::Rule->new(); - $ff->file; - $ff->name('*.log'); - my @loglist =$ff->in($ENV{USERPROFILE}.'/OpenVPN/log'); - foreach my $c (@loglist){ - open(CLOG,$c); - my @data = ; - close(CLOG); - my $laststate=$data[scalar(@data)-1]; - chomp($laststate); - if ($laststate =~ /CONNECTED/){ - my ($time,$ip,$server,$port) = $laststate =~ /.+MANAGEMENT:\s>STATE:(\d+),CONNECTED,SUCCESS,(.+),(.+),(.+),,$/; - if (!exists($status->{connection}->{$ip})){ - $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4);; - $status->{connection}->{$ip}->{server} = $server; - $status->{connection}->{$ip}->{port} = $port; - $status->{connection}->{$ip}->{connected_since} = $time; - }else { - if ($time >= $status->{connection}->{$ip}->{connected_since}){ - $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4); - $status->{connection}->{$ip}->{server}= $server; - $status->{connection}->{$ip}->{port} = $port; - $status->{connection}->{$ip}->{connected_since} = $time; - } - } - } - } - my @notactive = (); - my $active = (); - foreach my $c (keys(%{$status->{connection}})){ - my $routeslist = `route print -4`; - my @routes = split("\n",$routeslist); - my @activetest = grep(/$c/,@routes); - if (scalar(@activetest) == 0){ - push @notactive,$c; - } else { - $active->{$status->{connection}->{$c}->{config}} = $c; - } - } - foreach my $na (@notactive){ - delete $status->{connection}->{$na}; - } - $status->{active} = $active; - } - } - return $status; -} - -sub vpndisconnect(){ - - if ($^O eq "MSWin32"){ - system('taskkill.exe /F /IM openvpn.exe'); - system('taskkill.exe /F /IM openvpn-gui.exe'); - } - -} \ No newline at end of file diff --git a/Tools/ovpn.pl b/Tools/ovpn.pl index 3c3ea91..bc85414 100644 --- a/Tools/ovpn.pl +++ b/Tools/ovpn.pl @@ -1,153 +1,153 @@ -#!C:\Stawberry\Perl\bin\perl.exe - -use strict; -use Getopt::Long; -use File::Find::Rule; -use File::Basename; -my $connect =0; -my $disconnect=0; -GetOptions("connect" => \$connect,"disconnect" => \$disconnect); -my $conn = ""; -print "Starting vpn!\n"; -if (! -d $ENV{USERPROFILE}.'/OpenVPN/config' ){ - print "no default VPN Configuration found missing: ".$ENV{USERPROFILE}.'/OpenVPN/config'."\n"; - exit(1); -} -if (-e $ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'){ - - open(CFG,$ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'); - while (my $l = ){ - if ($l =~ /^OPENVPNNAME=/){ - ($conn) = $l =~ m/OPENVPNNAME=(.+)$/; - chomp($conn); - } - } - close(CFG); -} -if ($conn eq "" && $disconnect != 1){ - print "No configuration, no disconnect forced!Nothing to do!\n"; - exit(0); -} -if ($connect == $disconnect){ - if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ - my $status = &vpnstatus(); - if (exists($status->{active})){ - &vpndisconnect(); - } else { - &vpnconnect(); - } - } else { - &vpndisconnect(); - } -}else{ - if ($connect == 1){ - &vpnconnect(); - } else { - &vpndisconnect(); - } -} - -sub vpnconnect(){ - - my $uprofile = ""; - #is gui or vpn running - - if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ - my $status = &vpnstatus(); - if (!exists($status->{active}->{$conn})){ - if ($^O eq "MSWin32"){ - if (exists($status->{gui})){ - system('taskkill.exe /F /IM openvpn.exe'); - system('taskkill.exe /F /IM openvpn-gui.exe'); - sleep(1); - } - my $st = system('start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect '.$conn.'.ovpn'); - if ($st == 0){ - - my $bconn = 0; - my $i = 30; - while ($bconn == 0 || $i > 0){ - $status = &vpnstatus(); - if (exists($status->{active}->{$conn})){ - - $bconn = 1; - } - $i--; - sleep(1); - } - } - } - } - } - -} - -sub vpnstatus(){ - my $status = (); - if ($^O eq "MSWin32"){ - - my $tasklist = `tasklist`; - my @task = split("\n",$tasklist); - my @ovpntasks = grep(/openvpn-gui\.exe/,@task); - if (scalar(@ovpntasks) > 0){ - $status->{gui} = "running"; - } - @ovpntasks = grep(/openvpn.exe/,@task); - #$status->{active_connections} = scalar(@ovpntasks); - if (scalar(@ovpntasks) > 0){ - my $ff = File::Find::Rule->new(); - $ff->file; - $ff->name('*.log'); - my @loglist =$ff->in($ENV{USERPROFILE}.'/OpenVPN/log'); - foreach my $c (@loglist){ - open(CLOG,$c); - my @data = ; - close(CLOG); - my $laststate=$data[scalar(@data)-1]; - chomp($laststate); - if ($laststate =~ /CONNECTED/){ - my ($time,$ip,$server,$port) = $laststate =~ /.+MANAGEMENT:\s>STATE:(\d+),CONNECTED,SUCCESS,(.+),(.+),(.+),,$/; - if (!exists($status->{connection}->{$ip})){ - $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4);; - $status->{connection}->{$ip}->{server} = $server; - $status->{connection}->{$ip}->{port} = $port; - $status->{connection}->{$ip}->{connected_since} = $time; - }else { - if ($time >= $status->{connection}->{$ip}->{connected_since}){ - $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4); - $status->{connection}->{$ip}->{server}= $server; - $status->{connection}->{$ip}->{port} = $port; - $status->{connection}->{$ip}->{connected_since} = $time; - } - } - } - } - my @notactive = (); - my $active = (); - foreach my $c (keys(%{$status->{connection}})){ - my $routeslist = `route print -4`; - my @routes = split("\n",$routeslist); - my @activetest = grep(/$c/,@routes); - if (scalar(@activetest) == 0){ - push @notactive,$c; - } else { - $active->{$status->{connection}->{$c}->{config}} = $c; - } - } - foreach my $na (@notactive){ - delete $status->{connection}->{$na}; - } - $status->{active} = $active; - } - } - return $status; -} - -sub vpndisconnect(){ - - if ($^O eq "MSWin32"){ - system('taskkill.exe /F /IM openvpn.exe'); - system('taskkill.exe /F /IM openvpn-gui.exe'); - } - +#!C:\Stawberry\Perl\bin\perl.exe + +use strict; +use Getopt::Long; +use File::Find::Rule; +use File::Basename; +my $connect =0; +my $disconnect=0; +GetOptions("connect" => \$connect,"disconnect" => \$disconnect); +my $conn = ""; +print "Starting vpn!\n"; +if (! -d $ENV{USERPROFILE}.'/OpenVPN/config' ){ + print "no default VPN Configuration found missing: ".$ENV{USERPROFILE}.'/OpenVPN/config'."\n"; + exit(1); +} +if (-e $ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'){ + + open(CFG,$ENV{APPDATA}.'/Creorga/Profiles/vpncfg.txt'); + while (my $l = ){ + if ($l =~ /^OPENVPNNAME=/){ + ($conn) = $l =~ m/OPENVPNNAME=(.+)$/; + chomp($conn); + } + } + close(CFG); +} +if ($conn eq "" && $disconnect != 1){ + print "No configuration, no disconnect forced!Nothing to do!\n"; + exit(0); +} +if ($connect == $disconnect){ + if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ + my $status = &vpnstatus(); + if (exists($status->{active})){ + &vpndisconnect(); + } else { + &vpnconnect(); + } + } else { + &vpndisconnect(); + } +}else{ + if ($connect == 1){ + &vpnconnect(); + } else { + &vpndisconnect(); + } +} + +sub vpnconnect(){ + + my $uprofile = ""; + #is gui or vpn running + + if (-e $ENV{USERPROFILE}.'/OpenVPN/config/'.$conn.'.ovpn'){ + my $status = &vpnstatus(); + if (!exists($status->{active}->{$conn})){ + if ($^O eq "MSWin32"){ + if (exists($status->{gui})){ + system('taskkill.exe /F /IM openvpn.exe'); + system('taskkill.exe /F /IM openvpn-gui.exe'); + sleep(1); + } + my $st = system('start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect '.$conn.'.ovpn'); + if ($st == 0){ + + my $bconn = 0; + my $i = 30; + while ($bconn == 0 || $i > 0){ + $status = &vpnstatus(); + if (exists($status->{active}->{$conn})){ + + $bconn = 1; + } + $i--; + sleep(1); + } + } + } + } + } + +} + +sub vpnstatus(){ + my $status = (); + if ($^O eq "MSWin32"){ + + my $tasklist = `tasklist`; + my @task = split("\n",$tasklist); + my @ovpntasks = grep(/openvpn-gui\.exe/,@task); + if (scalar(@ovpntasks) > 0){ + $status->{gui} = "running"; + } + @ovpntasks = grep(/openvpn.exe/,@task); + #$status->{active_connections} = scalar(@ovpntasks); + if (scalar(@ovpntasks) > 0){ + my $ff = File::Find::Rule->new(); + $ff->file; + $ff->name('*.log'); + my @loglist =$ff->in($ENV{USERPROFILE}.'/OpenVPN/log'); + foreach my $c (@loglist){ + open(CLOG,$c); + my @data = ; + close(CLOG); + my $laststate=$data[scalar(@data)-1]; + chomp($laststate); + if ($laststate =~ /CONNECTED/){ + my ($time,$ip,$server,$port) = $laststate =~ /.+MANAGEMENT:\s>STATE:(\d+),CONNECTED,SUCCESS,(.+),(.+),(.+),,$/; + if (!exists($status->{connection}->{$ip})){ + $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4);; + $status->{connection}->{$ip}->{server} = $server; + $status->{connection}->{$ip}->{port} = $port; + $status->{connection}->{$ip}->{connected_since} = $time; + }else { + if ($time >= $status->{connection}->{$ip}->{connected_since}){ + $status->{connection}->{$ip}->{config} = substr(basename($c),0,-4); + $status->{connection}->{$ip}->{server}= $server; + $status->{connection}->{$ip}->{port} = $port; + $status->{connection}->{$ip}->{connected_since} = $time; + } + } + } + } + my @notactive = (); + my $active = (); + foreach my $c (keys(%{$status->{connection}})){ + my $routeslist = `route print -4`; + my @routes = split("\n",$routeslist); + my @activetest = grep(/$c/,@routes); + if (scalar(@activetest) == 0){ + push @notactive,$c; + } else { + $active->{$status->{connection}->{$c}->{config}} = $c; + } + } + foreach my $na (@notactive){ + delete $status->{connection}->{$na}; + } + $status->{active} = $active; + } + } + return $status; +} + +sub vpndisconnect(){ + + if ($^O eq "MSWin32"){ + system('taskkill.exe /F /IM openvpn.exe'); + system('taskkill.exe /F /IM openvpn-gui.exe'); + } + } \ No newline at end of file diff --git a/app_v3/chrome/content/js/init.js b/app_v3/chrome/content/js/init.js index 17a6e1e..107b6e3 100644 --- a/app_v3/chrome/content/js/init.js +++ b/app_v3/chrome/content/js/init.js @@ -17,7 +17,7 @@ else { //dump("current loadtimeout:" + loadtimeout + "\n"); if (system.os == "WINNT") { - system.runcmdline(system.toolsdir() + system.sep() + "openvpn.exe",["--connect"],function(data){ + system.runcmdline(system.toolsdir() + system.sep() + "ovpn.exe",["--connect"],function(data){ system.popup("Info","démarrage VPN!\n"); }); } diff --git a/app_v3/chrome/content/modules/support/js/multisite.js b/app_v3/chrome/content/modules/support/js/multisite.js index 68bf8c0..013dbfc 100644 --- a/app_v3/chrome/content/modules/support/js/multisite.js +++ b/app_v3/chrome/content/modules/support/js/multisite.js @@ -123,8 +123,15 @@ function getremotefolder() { } function vpnconnection(){ - if (system.os == "Darwin" && system.fileexists(system.profilerootdir() + system.sep() + 'vpncfg.txt')){ + if (system.fileexists(system.profilerootdir() + system.sep() + 'vpncfg.txt')){ + if (system.os == "Darwin"){ system.runcmdline("/bin/bash",[system.toolsdir() + system.sep() + "vpnconnect.sh",system.profilerootdir() + system.sep() + 'vpncfg.txt']); + } else { + system.runcmdline(system.toolsdir() + system.sep() + "ovpn.exe",["--connect"],function(data){ + system.popup("Info","démarrage VPN!\n"); + }); + + } } } diff --git a/app_v3/chrome/content/modules/support/multisite.html b/app_v3/chrome/content/modules/support/multisite.html index 85ff605..bc9a996 100644 --- a/app_v3/chrome/content/modules/support/multisite.html +++ b/app_v3/chrome/content/modules/support/multisite.html @@ -54,7 +54,7 @@
- +
@@ -85,7 +85,7 @@
- +
diff --git a/install/create_setup_windows.pl b/install/create_setup_windows.pl index 5286e53..0ed04f4 100644 --- a/install/create_setup_windows.pl +++ b/install/create_setup_windows.pl @@ -179,7 +179,8 @@ print APP "MaxVersion=38.0.6\n"; close(APP); make_path("C:\\Users\\ksaff\\Release\\dist\\Tools"); -system('"C:\\Strawberry\\perl\\site\\bin\\pp" -o "C:\\Users\\ksaff\\Release\\dist\\Tools\\openvpn.exe" openvpn.pl'); +chdir("C:\\Users\\ksaff\\Release\\tag\\Tools"); +system('"C:\\Strawberry\\perl\\site\\bin\\pp" -o "C:\\Users\\ksaff\\Release\\dist\\Tools\\ovpn.exe" ovpn.pl'); if (($setup eq "director")){ # open(CHKS,">C:\\Users\\ksaff\\Release\\dist\\checkschema.txt"); # close(CHKS); @@ -192,7 +193,7 @@ if (($setup eq "director")){ # unlink("C:\\Users\\ksaff\\Release\\tag\\app_v3\\Tools\\vpncfg.txt"); #compile executeables chdir("C:\\Users\\ksaff\\Release\\tag\\Tools"); - system('"C:\\Strawberry\\perl\\site\\bin\\pp" -o "C:\\Users\\ksaff\\Release\\dist\\Tools\\creorgadb.exe" creorgadb.pl'); +# system('"C:\\Strawberry\\perl\\site\\bin\\pp" -o "C:\\Users\\ksaff\\Release\\dist\\Tools\\creorgadb.exe" creorgadb.pl'); system('"C:\\Strawberry\\perl\\site\\bin\\pp" -o "C:\\Users\\ksaff\\Release\\dist\\Tools\\pdfextract.exe" pdfextract.pl'); } diff --git a/install/windows/pp_ovpn.bat b/install/windows/pp_ovpn.bat index 69f4b42..a81b39b 100644 --- a/install/windows/pp_ovpn.bat +++ b/install/windows/pp_ovpn.bat @@ -1,4 +1,4 @@ @echo off -"C:\Strawberry\perl\site\bin\pp" -o "C:\\Debug\\Creorga\\Tools\\openvpn.exe" -vvv "C:\\Users\\ksaff\\Workspace\\creorga\\Tools\\openvpn.pl" +"C:\Strawberry\perl\site\bin\pp" -o "C:\\Debug\\Creorga\\Tools\\ovpn.exe" -vvv "C:\\Users\\ksaff\\Workspace\\creorga\\Tools\\ovpn.pl" pause