diff options
-rw-r--r-- | common/scripts/IFCFG.pm | 87 | ||||
-rw-r--r-- | common/scripts/test.pl | 12 |
2 files changed, 99 insertions, 0 deletions
diff --git a/common/scripts/IFCFG.pm b/common/scripts/IFCFG.pm new file mode 100644 index 00000000..00a98845 --- /dev/null +++ b/common/scripts/IFCFG.pm @@ -0,0 +1,87 @@ +#!/usr/bin/perl + +# Interfaces Conf Parser + +# Copyright (C) 2002 MandrakeSoft Arnaud Desmons <adesmons@mandrakesoft.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +package IFCFG; +use strict; +use Data::Dumper; +use MDK::Common; + +my $file = "/etc/sysconfig/network-scripts/drakconnect_conf"; +!-f $file and die "no such $file"; +sub new { + my $self = {}; + + $ENV{PATH} = ""; + my $ifconfig = `LC_ALL=C /sbin/ifconfig -a`; + my $device = 'NONE'; + my @interfaces; + foreach (split('\n', $ifconfig)) { + my ($temp) = /(^eth[0-9]*:?[0-9]*).*/; + $device = $temp if defined $temp; + my ($ip, $bcast, $netmask) = /\s*inet addr:([0-9\.]*)\s*Bcast:([0-9\.]*)\s*Mask:([0-9\.]*).*/; + if (defined $ip && defined $bcast && defined $netmask) { + $self->{itf}{$device} = {IPADDR => $ip, BROADCAST => $bcast, NETMASK => $netmask}; + my %conf = getVarsFromSh("/etc/sysconfig/network-scripts/ifcfg-$device"); + $self->{itf}{$device}{$_} = $conf{$_} foreach ('BOOTPROTO'); + } + } + $self->{network} = getVarsFromSh("/etc/sysconfig/network"); + bless $self; +} + +sub is_dhcp { + my $self = shift; + my ($itf) = @_; + + $itf ||= default_itf(); + $self->{itf}{$itf}{BOOTPROTO} eq 'dhcp'; +} + + +sub get { + my $self = shift; + my ($key1, $key2) = @_; + + exists $self->{$key1}{$key2} or die "no $key1 $key2 field in $file"; + $self->{$key1}{$key2}; +} + +#- TODO : return the main interface +sub default_itf { + "eth0"; +} + +sub itf_get { + my $self = shift; + my ($key, $itf) = @_; + + $itf ||= default_itf; + exists $self->{itf}{$itf}{$key} or die "no $key field in $file"; + $self->{itf}{$itf}{$key} +} + +sub network_get { + my $self = shift; + my ($key) = @_; + + get("network", $key); +} + +10; diff --git a/common/scripts/test.pl b/common/scripts/test.pl new file mode 100644 index 00000000..5fbba3cb --- /dev/null +++ b/common/scripts/test.pl @@ -0,0 +1,12 @@ +use lib qw(/usr/lib/libDrakX); +package Dhcpconf; +require "IFCFG.pm"; +#require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm"; +use MDK::Common; +use strict; +use standalone; + +my $o = IFCFG->new(); +print $o->is_dhcp() ? "toto\n" : "tata\n"; +print $o->itf_get("IPADDR"); +print $o->network_get("DOMAINNAME"); |