2 # Common functions for parsing the rp-pppoe config file
4 BEGIN { push(@INC, ".."); };
10 # Parse the PPPOE configuration file
15 open(FILE, $config{'pppoe_conf'}) || return undef;
19 if (/^\s*(\S+)\s*=\s*"([^"]*)"/ ||
20 /^\s*(\S+)\s*=\s*'([^']*)'/ ||
21 /^\s*(\S+)\s*=\s*(\S+)/) {
22 push(@rv, { 'name' => $1,
33 # Looks up an entry in the config file
37 foreach $c (@{$_[1]}) {
38 if (lc($c->{'name'}) eq lc($_[0])) {
45 # save_directive(&config, name, value)
48 local ($old) = grep { lc($_->{'name'}) eq lc($_[1]) } @{$_[0]};
49 local $lref = &read_file_lines($config{'pppoe_conf'});
50 local $nl = "$_[1]=".($_[2] =~ /^\S+$/ ? $_[2] : "\"$_[2]\"");
52 $lref->[$old->{'line'}] = $nl;
60 # Returns the device name and IP address of the ADSL connection (if up),
64 local $out = `$config{'status_cmd'} 2>&1`;
65 if ($out =~ /link is up/i &&
66 $out =~ /on\s+interface\s+ppp(\d+)[\000-\377]+inet addr:\s*(\S+)/i) {
69 elsif ($out =~ /attached\s+to\s+(ppp\d+)/i) {
72 elsif ($out =~ /could\s+not\s+find\s+interface\s+corresponding\s+to/i) {
73 return ("unknown", undef)
75 elsif ($out =~ /demand-connection/) {
76 return ("demand", undef);
83 # get_pppoe_version(&out)
86 local $out = `$config{'pppoe_cmd'} -V 2>&1`;
88 return $out =~ /version\s+(\S+)/i ? $1 : undef;