1
0

pptpdconfig.pl 1.5 KB

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