init II
This commit is contained in:
66
CISCO Config Template Konverter/convert.pl
Normal file
66
CISCO Config Template Konverter/convert.pl
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/perl
|
||||
|
||||
$i=@ARGV;
|
||||
die "Zu wenige Parameter!\nconvert.pl <Eingabedatei> <Ausgabedatei>" if $i<2;
|
||||
|
||||
print "\n";
|
||||
print "Eingabedatei $ARGV[0]\n";
|
||||
print "Ausgabedatei $ARGV[1]\n";
|
||||
|
||||
|
||||
open IN, "<$ARGV[0]";
|
||||
open OUT, ">$ARGV[1]";
|
||||
|
||||
|
||||
@INF=<IN>;
|
||||
foreach (@INF) {
|
||||
chomp;
|
||||
router() if ($_ =~ /^!!ROUTER/);
|
||||
router() if ($_ =~ /^!!SWITCH/);
|
||||
router() if ($_ =~ /^!!FIREWALL/);
|
||||
}
|
||||
|
||||
close IN;
|
||||
close OUT;
|
||||
|
||||
sub router {
|
||||
$read_v=0;
|
||||
|
||||
# Variablen lesen
|
||||
foreach (@INF) {
|
||||
$read_v=1 if ($_ =~ /^!!VARIABLEN/);
|
||||
last if ($_ =~ /^!!CONFIG/);
|
||||
next if ($_ =~ /^!/);
|
||||
read_var($_) if ($read_v);
|
||||
}
|
||||
|
||||
# Konfig lesen
|
||||
$read_c=0;
|
||||
foreach (@INF) {
|
||||
chomp;
|
||||
$read_c=1 if ($_ =~ /^!!CONFIG/);
|
||||
if ($read_c) {
|
||||
if($_ =~ /<.*>/) {
|
||||
($vn)=$_=~/(<.*>)/;
|
||||
$_ =~ s/$vn/$VARS{$vn}/;
|
||||
next if ($VARS{$vn} eq "");
|
||||
}
|
||||
# und schreiben
|
||||
printf OUT "$_\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub switch {
|
||||
}
|
||||
|
||||
sub firewall {
|
||||
}
|
||||
|
||||
sub read_var {
|
||||
$l=$_[0];
|
||||
if ($l=~ /<.*>.*=.*/) {
|
||||
($vn, $vv) = $l =~/(<.*>).*=[\s]*(.*)/;
|
||||
$VARS{$vn}=$vv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user