From f1d6b8a9d3c06f74e904959887cf043d09aff687 Mon Sep 17 00:00:00 2001 From: Dexter Morgan Date: Thu, 2 Jun 2011 20:51:50 +0000 Subject: Branch for updates --- common/IFCFG.pm | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 common/IFCFG.pm (limited to 'common/IFCFG.pm') diff --git a/common/IFCFG.pm b/common/IFCFG.pm new file mode 100644 index 00000000..38eed528 --- /dev/null +++ b/common/IFCFG.pm @@ -0,0 +1,85 @@ +#!/usr/bin/perl + +# Interfaces Conf Parser + +# Copyright (C) 2002,2003 Mandrakesoft +# +# Author: Arnaud Desmons +# +# 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 MDK::Wizard::IFCFG; +use strict; +use lib qw(/usr/lib/libDrakX); +use Data::Dumper; +use MDK::Common; +use network::network; + +#my $file = "/etc/sysconfig/network-scripts/drakconnect_conf"; +#!-f $file and die "no such $file"; +sub new { + my $self = {}; + + my $ifconfig = `LC_ALL=C /sbin/ifconfig -a`; + my $device = 'NONE'; + 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"); + my $r = network::network::read_resolv_conf(); + foreach my $k (keys %$r) { + $self->{network}{$k} ||= $r->{$k}; + } + $self->{network}{HOSTNAME} ||= `/bin/hostname` and chomp $self->{network}{HOSTNAME}; + ($self->{network}{DOMAINNAME}) = $self->{network}{HOSTNAME} =~ /\.(.*)/; + $self->{network}{DOMAINNAME} ||= `/bin/dnsdomainname` and chomp $self->{network}{DOMAINNAME}; + bless $self; +} + +sub is_dhcp { + my ($self, $itf) = @_; + + $itf ||= default_itf(); + $self->{itf}{$itf}{BOOTPROTO} eq 'dhcp'; +} + +#- TODO : return the main interface +sub default_itf { + "eth0"; +} + +sub itf_get { + my ($self, $key, $itf) = @_; + + $itf ||= default_itf(); + exists $self->{itf}{$itf}{$key} or print "ERROR: no $key field in $itf hash\n"; + $self->{itf}{$itf}{$key}; +} + +sub network_get { + my ($self, $key) = @_; + + exists $self->{network}{$key} or print "ERROR: no $key field in network hash\n"; + $self->{network}{$key}; +} + +10; -- cgit v1.2.1