1#!/usr/bin/perl -w 2use strict; 3 4use Debian::DebConf::Client::ConfModule ':all'; 5 6&pptpd("/etc/pptpd.conf", get("pptpd/localip"), get("pptpd/remoteip")); 7exit 0; 8 9sub pptpd ($$$) { 10 11 my $line; # eine Zeile von IN 12 my $xxx; 13 my @lines; 14 my $count; 15 my $filename; 16 my $localIp; 17 my $remoteIp; 18 my $spaces; 19 my $foundlocal=0; 20 my $foundremote=0; 21 my $IDString="# generated by pptpdconfig"; 22 23 $filename=shift; 24 $localIp=shift; 25 $remoteIp=shift; 26 print("Configuring pptpd to use localip(s) $localIp and remoteip(s) "); 27 print("$remoteIp ...\n"); 28 29 open(IN, "<$filename") || die("$filename not found.\n"); 30 @lines=<IN>; 31 32 open(OUT, ">${filename}.old"); 33 print OUT @lines; 34 close OUT; 35 36 $count=0; 37 while ($count<=$#lines) 38 { 39 $line=$lines[$count]; 40 if ($line=~/^\s*localip/) { 41 if ($line=~/$IDString/) 42 { 43 ($spaces)=($line=~/^(\s*)\S*.*/); 44 $lines[$count]="${spaces}localip $localIp $IDString\n"; 45 $foundlocal=1; 46 } 47 else 48 { 49 $lines[$count]="# removed by pptpdconfig --- ".$lines[$count]."\n"; 50 } 51 } 52 53 if ($line=~/^\s*remoteip/) { 54 if ($line=~/$IDString/) 55 { 56 ($spaces)=($line=~/^(\s*)\S*.*/); 57 $lines[$count]="${spaces}remoteip $remoteIp $IDString\n"; 58 $foundremote=1; 59 } 60 else 61 { 62 $lines[$count]="# removed by pptpdconfig --- ".$lines[$count]."\n"; 63 } 64 } 65 $count++; 66 } 67 if ($foundlocal==0) 68 { 69 push(@lines, "localip $localIp $IDString\n"); 70 } 71 if ($foundremote==0) 72 { 73 push(@lines, "remoteip $remoteIp $IDString\n"); 74 } 75 close IN; 76 print("done\n"); 77 78 open(OUT, ">$filename"); 79 print OUT @lines; 80 close OUT; 81} 82