summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2003-08-22 19:59:48 +0000
committerFlorent Villard <warly@mandriva.com>2003-08-22 19:59:48 +0000
commit150bc87396011253a541ca0ad32250e926ab0ecc (patch)
tree1b90808250fc42a37248dfeb726b55f8203e8ba2 /common
parent817bcd2c3a985552620cece5905d5b5982ae14c4 (diff)
downloaddrakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.gz
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.bz2
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.xz
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.zip
switch to perl only
Diffstat (limited to 'common')
-rw-r--r--common/IFCFG.pm88
-rw-r--r--common/Varspaceval.pm88
-rw-r--r--common/Wizcommon.pm39
3 files changed, 215 insertions, 0 deletions
diff --git a/common/IFCFG.pm b/common/IFCFG.pm
new file mode 100644
index 00000000..e86128d1
--- /dev/null
+++ b/common/IFCFG.pm
@@ -0,0 +1,88 @@
+#!/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 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 = {};
+
+ $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");
+ my $r = 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 = shift;
+ my ($itf) = @_;
+
+ $itf ||= default_itf();
+ $self->{itf}{$itf}{BOOTPROTO} eq 'dhcp';
+}
+
+#- 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 $itf hash";
+ $self->{itf}{$itf}{$key}
+}
+
+sub network_get {
+ my $self = shift;
+ my ($key) = @_;
+
+ exists $self->{network}{$key} or die "no $key field in network hash";
+ $self->{network}{$key};
+}
+
+10;
diff --git a/common/Varspaceval.pm b/common/Varspaceval.pm
new file mode 100644
index 00000000..61a31cff
--- /dev/null
+++ b/common/Varspaceval.pm
@@ -0,0 +1,88 @@
+#!/usr/bin/perl -w
+
+# Author Philippe Hétroy, phetroy@mandrakesoft.com
+# $Id: Varspaceval.pm,v 1.1 2003-08-22 19:59:47 warly Exp $
+
+# Module for loding and committing informations in a VAR = value file type
+
+package Varspaceval;
+use lib('./');
+use strict;
+use Data::Dumper;
+
+
+# Get all useful content of the config file
+# Return a hash containg the key and the value
+# ATTENTION : in the conf file, an empty value is returnes as a spaced value (mandatory because of XML compatibility)
+sub get {
+ my $self = shift;
+ my $file = shift;
+ my %l;
+ local *F; open F, $file or return;
+ local $_;
+
+ while (<F>) {
+
+ my ($v, $val, $val2) =
+ /^\s* # leading space
+ (\w+)\s* # variable
+ (
+ "(.*)" # double-quoted text
+ | '(.*)' # single-quoted text
+ | [^'"\s]* # normal text
+ )
+ \s*$ # end of line
+ /x;
+ no warnings;
+ $l{$v} = defined $val2 ? $val2 : $val;
+ }
+
+ %l;
+}
+
+# Commits changes in conf files and ifconfig
+sub commit {
+ my $self = shift;
+ my ($file, $hash) = @_;
+ local *F;
+
+ my $output = "";
+ if (open(F, $file)) {
+ local $_;
+
+ while (<F>) {
+ my ($pre, $key, $eq, $val, $rest) = /(^\s*)(\w+)(\s*"*'*)([^'"\s]*)(.*)/x;
+
+ if (!defined $key) {
+ $output .= $_;
+ next;
+ };
+ next if (!exists $hash->{$key}); #Elt has been removed
+ no warnings;
+ $val = $hash->{$key};
+ delete $hash->{$key};
+ $output .= defined $val ? $pre . $key . $eq . $val . $rest . "\n" : $pre . $key . $eq . $val . $rest;
+# $output .= $pre . $key . $eq . $val . $rest . "\n";
+ }
+ #appending added parameters
+ foreach (keys %$hash) {
+ $output .= $_ . " " . $hash->{$_} . "\n";
+ }
+
+ } else { #the file does not exist
+ print STDERR "File $file will be created\n";
+ foreach (keys %$hash) {
+ $output .= defined $hash->{$_} ? $_ . "=" . $hash->{$_} . "\n" : $_ . "=\n";
+ }
+ }
+
+#print $output;
+#print "\n------------------\n";
+
+ # outputing the new conf
+ open(F, "> $file") or return;
+ print F $output;
+ close(F);
+}
+
+1;
diff --git a/common/Wizcommon.pm b/common/Wizcommon.pm
new file mode 100644
index 00000000..847f41f9
--- /dev/null
+++ b/common/Wizcommon.pm
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# Interfaces Conf Parser
+
+# Copyright (C) 2003 Florent Villard <warly@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 Wizcommon;
+use strict;
+use MDK::Wizard::IFCFG;
+
+my $net;
+
+sub check_dhcp {
+ $net->is_dhcp() and return 'dhcp_warning';
+}
+
+sub new {
+ my ($class, $conf) = @_;
+ $net = new IFCFG;
+ bless {
+ net => $net,
+ }, $class;
+}
+
+1