diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-03-28 08:44:26 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-03-28 08:44:26 -0700 |
commit | c957b47e639779cb862ff7752d1ff1f95544a061 (patch) | |
tree | b8cd06fe8f319396474e1447b8915bec6c256c45 /lib | |
parent | 3a887bd8e0098b128e741362d8d34c8b086999c4 (diff) | |
download | vyatta-cfg-vpn-c957b47e639779cb862ff7752d1ff1f95544a061.tar.gz vyatta-cfg-vpn-c957b47e639779cb862ff7752d1ff1f95544a061.zip |
Fix perl critic warnings
Get rid of things deemed undesirable by Perl Best Practices:
* Convert to 3 argument open.
* Use local file handles
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Vyatta/VPN/Util.pm | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/lib/Vyatta/VPN/Util.pm b/lib/Vyatta/VPN/Util.pm index 0c16049..e57d5f9 100755 --- a/lib/Vyatta/VPN/Util.pm +++ b/lib/Vyatta/VPN/Util.pm @@ -23,14 +23,15 @@ # package Vyatta::VPN::Util; +use strict; +use warnings; + our @EXPORT = qw(rsa_get_local_key_file LOCAL_KEY_FILE_DEFAULT rsa_get_local_pubkey is_vpn_running vpn_debug enableICMP); use base qw(Exporter); -use strict; -use warnings; - use Vyatta::Config; +use POSIX qw(strftime); use constant LOCAL_KEY_FILE_DEFAULT => '/opt/vyatta/etc/config/ipsec.d/rsa-keys/localhost.key'; @@ -61,13 +62,10 @@ sub rsa_get_local_key_file { sub rsa_get_local_pubkey { my ($file) = @_; - unless ( -r $file) { - return 0; - } - - open(DAT, $file) || die("Could not open file $file!"); - my @raw_data=<DAT>; - close(DAT); + open(my $dat, '<', $file) + or return 0; + my @raw_data=<$dat>; + close($dat); foreach my $line (@raw_data) { my $file_pubkey; @@ -79,23 +77,24 @@ sub rsa_get_local_pubkey { } sub vpn_debug { - use POSIX; my $timestamp = strftime("%Y%m%d-%H:%M.%S", localtime); - open LOG, ">>", "/var/log/vpn-debug.log"; - print LOG "$timestamp: ", @_ , "\n"; - close LOG; + + open my $log, '>>', "/var/log/vpn-debug.log" + or return; + print {$log} "$timestamp: ", @_ , "\n"; + close $log; } sub vpn_log { my ($msg) = @_; - open LOG, ">> /tmp/ipsec.log"; + open my $log, '>>', "/tmp/ipsec.log" + or return; - use POSIX; my $timestamp = strftime("%Y-%m-%d %H:%M.%S", localtime); - print LOG "$timestamp\nLog: $msg\n"; - close LOG; + print {$log} "$timestamp\nLog: $msg\n"; + close $log; } sub vpn_system { @@ -112,18 +111,20 @@ sub vpn_system { sub enableICMP { my ($enable) = @_; - opendir DIR, '/proc/sys/net/ipv4/conf/' or return undef; - my @nodes = grep !/^\./, readdir DIR; - closedir DIR; + opendir my $dir, '/proc/sys/net/ipv4/conf/' + or return; + my @nodes = grep !/^\./, readdir $dir; + closedir $dir; foreach my $node (@nodes) { - my $OUT; - open OUT, ">/proc/sys/net/ipv4/conf/$node/accept_redirects" or return undef; - print OUT $enable; - close OUT; - open OUT, ">/proc/sys/net/ipv4/conf/$node/send_redirects" or return undef; - print OUT $enable; - close OUT; + open my $out, '>', "/proc/sys/net/ipv4/conf/$node/accept_redirects" + or return; + print {$out} $enable; + close $out; + open $out, '>', "/proc/sys/net/ipv4/conf/$node/send_redirects" + or return; + print {$out} $enable; + close $out; } return 1; } |