Hi.
Sorry to bother but I can't get this script to work..
It is supposed to parse the openvpn config,
1) any line starting with a ";" is to be ignored
2) all directives are written to a hash where the key is the directive and
the value is the  value of the  directive .
3) if the directive is present but no value is set then the key must be set
to the directive and the value must be set to "defined" or the same value as
the key..

this is the script so far


#!/usr/bin/perl
#

use strict;

# vars
my @tmp_load_file;
my @tmp_directive;
my %directive;
#
sub get_config_file {
my $line; #used in while for outputing each line.
print "opening config file for processing\n\n";
open(IN, "< /etc/openvpn/client.conf");

while (<IN>){

  if (( $_ =~ /^#/ ) || ( $_ =~ /^\ /) || ( $_ =~ /^\n/) ){
  } else {
  chomp;         push(@tmp_directive , $_ );
          }
}

close (IN);
}

get_config_file;



sub config_hash {
      ##### regex used in the function
      ## /.+\s(.+) used to find the option set for that directive. "dev
tun" will return "tun"
  my $value ;
foreach (@tmp_directive) {
  #print "$_";       if ( $_ != /^\;/) {
  } else {
      /^([\w|-]+)\s(.+)/ ;
      print " $1 => $2 \n";
      $directive{$1} = $2 ;
  }        if ( $_ != /^\;/) {
  } else {
      /^([\w|-]+)\n/ ;
      #print ">> $1 => $1 \n";
      #$value = "1" unless $2;
      $directive{$1} = $1 ;
  }      }
}


config_hash ;

my $key; my $value;#

print ">>>>>>>>>>>>>>>\n\n";
for $key (keys %directive){
 $value = $directive{$key};
 print "$key => $value\n";
}

this it the output..
[EMAIL PROTECTED] openvpn]$ perl passconfig.pl
opening config file for processing

=>
dev => tun0
proto => tcp
remote => 192.168.1.1 1194
resolv-retry => infinite
=>
=>
=>
ca => ca.crt
cert => greg.crt
key => greg.key
cipher => AES-128-CBC
=>
verb => 3


=>
proto => tcp
cert => greg.crt
dev => tun0
ca => ca.crt
key => greg.key
remote => 192.168.1.1 1194
verb => 3
cipher => AES-128-CBC
resolv-retry => infinite



Many Thanks
Greg



--
Gregory Machin
[EMAIL PROTECTED]
www.linuxpro.co.za

Reply via email to