#!/usr/bin/perl # # author Florin Grad (florin@mandrakesoft.com) # # Copyright 2006 Mandriva # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # i18n: IMPORTANT: to get correct namespace (drakx-net instead of libDrakX) BEGIN { unshift @::textdomains, 'drakx-net' } use lib qw(/usr/lib/libDrakX); use standalone; #- warning, standalone must be loaded very first, for 'explanations' use common; use detect_devices; use interactive; use network::network; use log; use c; use network::netconnect; use network::shorewall; use network::ipsec; use Data::Dumper; $::isInstall and die "Not supported during install.\n"; require_root_capability(); local $_ = join '', @ARGV; $::Wizard_pix_up = "drakvpn"; $ugtk3::wm_icon = "drakvpn"; my $direct = /-direct/; my $tunnels_file = "/etc/shorewall/tunnels"; my $ipsec_conf = ""; my $racoon_conf = "/etc/racoon/racoon.conf"; my $ipsec_package = ""; my $in = interactive->vnew; my $shorewall = network::shorewall::read($in); my @section_names; $ipsec_conf = "/etc/ipsec.conf"; my $ipsec = network::ipsec::read_ipsec_conf($ipsec_conf); my $racoon = network::ipsec::read_racoon_conf($racoon_conf); #print network::ipsec::display_ipsec_conf($ipsec_conf,$ipsec); $::Wizard_title = N("DrakVPN"); $in->isa('interactive::gtk') and $::isWizard = 1; my $wait_configuring; sub fatal_quit ($) { log::l("[drakvpn] FATAL: $_[0]"); undef $wait_configuring; $in->ask_warn('', $_[0]); quit_global($in, -1); } begin: #- ********************************** #- * 0th step: verify if we are already set up if ($shorewall && any { !/^\s*(?:#|\n)/ } cat_($tunnels_file)) { $::Wizard_no_previous = 1; if (!$shorewall->{disabled}) { my $r = $in->ask_from_list_(N("The VPN connection is enabled."), N("The setup of a VPN connection has already been done. It's currently enabled. What would you like to do?"), [ N_("disable"), N_("reconfigure"), N_("dismiss") ]) or quit_global($in, 0); # FIXME: reconfigure is not handled if ($r eq "disable") { if (!$::testing) { my $_wait_disabl = $in->wait_message(N("Please wait"), N("Disabling VPN...")); network::ipsec::stop_daemons(); } foreach ($ipsec_conf, $tunnels_file) { if (-f $_) { rename($_, "$_.drakvpndisable") or die "Could not rename $_ to $_.drakvpndisable" } } network::ipsec::sys("/etc/init.d/shorewall restart >/dev/null"); log::l("[drakvpn] Disabled"); $::Wizard_finished = 1; $in->ask_okcancel('', N("The VPN connection is now disabled.")); quit_global($in, 0); } if ($r eq "dismiss") { quit_global($in, 0); } } else { my $r = $in->ask_from_list_(N("VPN connection currently disabled"), N("The setup of a VPN connection has already been done. It's currently disabled. What would you like to do?"), [ N_("enable"), N_("reconfigure"), N_("dismiss") ]); # FIXME: reconfigure is not handled if ($r eq "enable") { foreach ($ipsec_conf, $tunnels_file) { rename($_, "$_.old") if -f $_; rename("$_.drakvpndisable", $_) or die "Could not find configuration. Please reconfigure."; } { my $_wait_enabl = $in->wait_message(N("Please wait"), N("Enabling VPN...")); network::ipsec::start_daemons(); } log::l("[drakvpn] Enabled"); } $::Wizard_finished = 1; $in->ask_okcancel('', N("The VPN connection is now enabled.")); quit_global($in, 0); if ($r eq "dismiss") { quit_global($in, 0); } } } #- ********************************** #- * 1st step: detect/setup step_ask_confirm: $::Wizard_no_previous = 1; $direct or $in->ask_okcancel(N("Simple VPN setup."), N("You are about to configure your computer to use a VPN connection. With this feature, computers on your local private network and computers on some other remote private networks, can share resources, through their respective firewalls, over the Internet, in a secure manner. The communication over the Internet is encrypted. The local and remote computers look as if they were on the same network. Make sure you have configured your Network/Internet access using drakconnect before going any further."), 1) or goto begin; undef $::Wizard_no_previous; $ipsec_package = "ipsec-tools"; $direct or $in->ask_okcancel(N("Simple VPN setup."), N("VPN connection. This program is based on the following projects: - FreeSwan: \t\t\thttp://www.freeswan.org/ - Super-FreeSwan: \t\thttp://www.freeswan.ca/ - ipsec-tools: \t\t\thttp://ipsec-tools.sourceforge.net/ - ipsec-howto: \t\thttp://www.ipsec-howto.org - the docs and man pages coming with the %s package Please read AT LEAST the ipsec-howto docs before going any further.",$ipsec_package)) or goto begin; step_detectsetup: #my @configured_devices = map { /ifcfg-(\S+)/ } glob('/etc/sysconfig/network-scripts/ifcfg*'); my %aliased_devices; /^\s*alias\s+(eth[0-9])\s+(\S+)/ and $aliased_devices{$1} = $2 foreach cat_("/etc/modules.conf"); #- ********************************** #- * 2nd step: configure #$wait_configuring = $in->wait_message(N("Configuring..."), # N("Configuring scripts, installing software, starting servers...")); #- install and setup the RPM packages, if needed my %rpm2file; log::l("[drakvpn] install the $ipsec_package and the shorewall rpm packages"); %rpm2file = ($ipsec_package => '/sbin/setkey', shorewall => '/sbin/shorewall'); #- first: try to install all in one step, if needed if (!-e "/sbin/setkey") { my @needed_to_install = grep { !-e $rpm2file{$_} } keys %rpm2file; @needed_to_install and $in->do_pkgs->install(@needed_to_install) if !$::testing; #- second: try one by one if failure detected if (!$::testing && any { !-e $rpm2file{$_} } keys %rpm2file) { foreach (keys %rpm2file) { -e $rpm2file{$_} or $in->do_pkgs->install($_); -PHPBB3-10946