diff options
author | Dexter Morgan <dmorgan@mageia.org> | 2011-06-02 20:51:50 +0000 |
---|---|---|
committer | Dexter Morgan <dmorgan@mageia.org> | 2011-06-02 20:51:50 +0000 |
commit | f1d6b8a9d3c06f74e904959887cf043d09aff687 (patch) | |
tree | 969cb9fdc3becc19b1f2a21c3a9e3cc2e15f39e6 /common | |
download | drakwizard-f1d6b8a9d3c06f74e904959887cf043d09aff687.tar drakwizard-f1d6b8a9d3c06f74e904959887cf043d09aff687.tar.gz drakwizard-f1d6b8a9d3c06f74e904959887cf043d09aff687.tar.bz2 drakwizard-f1d6b8a9d3c06f74e904959887cf043d09aff687.tar.xz drakwizard-f1d6b8a9d3c06f74e904959887cf043d09aff687.zip |
Branch for updates
Diffstat (limited to 'common')
-rw-r--r-- | common/.perl_checker | 1 | ||||
-rw-r--r-- | common/IFCFG.pm | 85 | ||||
-rw-r--r-- | common/Makefile | 13 | ||||
-rw-r--r-- | common/Varspaceval.pm | 87 | ||||
-rw-r--r-- | common/Wizcommon.pm | 75 | ||||
-rw-r--r-- | common/Wizcommon_gtk2.pm | 104 |
6 files changed, 365 insertions, 0 deletions
diff --git a/common/.perl_checker b/common/.perl_checker new file mode 100644 index 00000000..725f44b4 --- /dev/null +++ b/common/.perl_checker @@ -0,0 +1 @@ +Basedir ..
\ No newline at end of file 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 <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 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; diff --git a/common/Makefile b/common/Makefile new file mode 100644 index 00000000..77e68dfd --- /dev/null +++ b/common/Makefile @@ -0,0 +1,13 @@ + +install2: + su -c 'make install' + +install: + mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards + mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/common + mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/common/images + mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/common/scripts + install --mode=u=rwx,g=rx,o=rx -p scripts/*.sh ${prefix}/share/wizards/common/scripts + install --mode=u=rw,g=r,o=r -p scripts/*.pm ${prefix}/share/wizards/common/scripts + + diff --git a/common/Varspaceval.pm b/common/Varspaceval.pm new file mode 100644 index 00000000..9e996368 --- /dev/null +++ b/common/Varspaceval.pm @@ -0,0 +1,87 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2002,2003 Mandrakesoft +# +# Author: Philippe Hetroy, phetroy@mandrakesoft.com +# +# $Id: Varspaceval.pm,v 1.5 2004-01-22 20:24:48 tvignaud Exp $ +# Module for loding and committing informations in a VAR = value file type + +package MDK::Wizard::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, $file) = @_; + 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, $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..7e58107a --- /dev/null +++ b/common/Wizcommon.pm @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +# Copyright (C) 2003 Mandrakesoft +# +# Author: Florent Villard <warly@mandrakesoft.com> +# A Ginies +# +# 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::Wizcommon; +use strict; +use standalone; +use common; +use MDK::Common; +use MDK::Wizard::IFCFG; + +our @ISA = qw(Exporter); +our @EXPORT = qw(check_started check_starts_on_boot test_host_domain); + +my $net; + +sub check_dhcp { + $net->is_dhcp and return 'dhcp_warning'; +} + +sub new { + my ($class) = @_; + $net = new MDK::Wizard::IFCFG; + bless { + net => $net, + }, $class; +} + +sub check_started { + my ($service) = @_; + my ($isrunning) = chomp_(`pidof $service`) =~ /(\d+)/m; + if (!$isrunning) { + return 'error_end'; + } +} + +sub check_starts_on_boot($$) { + my ($in, $servicename) = @_; + if (!services::starts_on_boot($servicename)) { + my $start_service = $in->ask_yesorno(N("Start %s server on boot", $servicename), N("Would you like to start the %s service automatically on every boot?", $servicename), 1); + if ($start_service) { + services::start_service_on_boot($servicename); + } + } +} + +sub test_host_domain { + my ($SHORTHOSTNAME, $DOMAINNAME) = @_; + if ($SHORTHOSTNAME =~ /localhost/) { + return 0, N("You need to readjust your hostname. 'localhost' is not a correct hostname for a DNS server. Hostname must be a FQDN: Fully Qualified Domain Name"); + } + if (member($DOMAINNAME, qw(localdomain (none))) && -z $DOMAINNAME) { + return 0, N("You need to readjust your domainname. For a DNS server you need a correct domainname, not equal to localdomain or none. Hostname must be a FQDN: Fully Qualified Domain Name. Launch drakconnect to adjust it."); + } + return 1; +} + +1; diff --git a/common/Wizcommon_gtk2.pm b/common/Wizcommon_gtk2.pm new file mode 100644 index 00000000..56d18a0a --- /dev/null +++ b/common/Wizcommon_gtk2.pm @@ -0,0 +1,104 @@ +#!/usr/bin/perl + +# Copyright (C) 2003 Mandrakesoft +# +# Author: Florent Villard <warly@mandrakesoft.com> +# A Ginies +# +# 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::Wizcommon_gtk2; +use strict; +#use common; + +sub wizard_progress_bar { + use lib qw(/usr/lib/libDrakX); + use ugtk2 qw(:wrappers); + my ($command, $descr) = @_; + my ($value, $timer); + my $my_win = ugtk2->new(""); + my $window1 = $my_win->{window}; + gtkadd($window1, + gtkpack(Gtk2::VBox->new(0,0), + gtkpack_(Gtk2::VBox->new(0, 3), + 0, my $text = Gtk2::Label->new($descr), + 0, my $text2 = Gtk2::Label->new, + 0, Gtk2::HSeparator->new, + 0, my $pbar = Gtk2::ProgressBar->new, + ), + ), + ); + $window1->realize; + $pbar->set_pulse_step(0.1); + + local *TMP; + open(TMP, "GP_LANG=UTF-8 $command 2>&1 |"); + while (<TMP>) { + $timer = Glib::Timeout->add(10, sub {}); + $pbar->pulse; + s/\033\[[^mG]*[mG]//g; + $text2->set_text($_); + gtkflush(); + next; + $my_win->main; + $window1->show_all; + #undef $value; + } + close TMP; + $my_win->destroy; + return 0; +} + +sub gtk_log { + use lib qw(/usr/lib/libDrakX); + use ugtk2 qw(:wrappers); + use mygtk2 qw(gtknew); + my ($command, $text) = @_; + my $log_text = gtknew('TextView'); + my $my_win = ugtk2->new(""); + my $window1 = $my_win->{window}; + #my $pid; + gtkadd($window1, + gtknew('VBox', spacing => 3, children => [ + 0, Gtk2::Label->new($text), + 1, gtknew('ScrolledWindow', to_bottom => 1, child => $log_text), +# 0, gtksignal_connect(gtknew('Button', text => N("cancel")), clicked => sub { + # if ($pid) { +# $::in->ask_yesorno('', N("The command is still running. Do you want to kill it and quit the Wizard?")) or return; +# kill 9, $pid and system("touch /tmp/wiz_error"); +# } +# } +# ), + ], + ), + ); + + my $TMP; + open($TMP, "GP_LANG=UTF-8 $command 2>&1 |"); + gtktext_append($log_text, "$command\n\n"); + while (<$TMP>) { + s/\033\[[^mG]*[mG]//g; + c::set_tagged_utf8($_); + gtktext_append($log_text, $_); + gtkflush(); + next; + $my_win->main; + } + $window1->show_all; + close $TMP; + $my_win->destroy; +} + +1; |