#!/usr/bin/perl package Serverconf; use lib qw(/usr/lib/perl5/vendor_perl/5.8.1/MDK/Wizard/ /usr/share/wizards/common/scripts/); require Vareqval; require IFCFG; use MDK::Common; use strict; my $o = IFCFG->new; sub get_hostname { my $host = $o->network_get("HOSTNAME"); return $host if $host; "host.domain" } sub check_domain { $ENV{wiz_host_name} =~ /\S+\.\S+/ and return 10; 1 } sub check_network { print "$ENV{wiz_ip_net}\n"; foreach (split '\.', $ENV{wiz_ip_net}) { $_ >= 0 && $_ < 256 or return 1 } return 10 } sub get_net { $o->itf_get('NET_ADDR') or "192.168.1.0"; } sub compute_server_ip { $o->itf_get('ADDR') or "192.168.1.1" } sub set_ip { } sub check_server_ip { my @net = split '\.', $ENV{wiz_ip_net}; my @ip = split '\.', $ENV{wiz_ip_server}; mapn { $_[0] == $_[1] || $_[0] == 0 or return 0 } \@net, \@ip; return 10 } sub do_it_last { my $file = "/etc/sysconfig/mdk_serv"; MDK::Common::cp_af($file, $file.".orig"); my $date = `date`; open(NEW, "> $file"); print NEW "#mdk server basic info $date mdk_serv_version=1.0 wiz_device=$ENV{wiz_device} wiz_host_name=$ENV{wiz_host_name} wiz_domain_name=$ENV{wiz_domain_name}"; } sub get_gateway_dev { $o->network_get('GATEWAYDEV') or "eth0" } sub get_device { "eth0" } sub get_gateway { $o->network_get('GATEWAY') } sub do_it { my $old_ip; my $date = `date`; my $file = "/etc/sysconfig/network"; MDK::Common::cp_af($file, $file . ".orig"); my %mdk = Vareqval->get($file); my $wiz_ip_netmask = "255.255.255.0"; $mdk{FORWARD_IPV4} = "yes"; $mdk{HOSTNAME} = $ENV{wiz_host_name} if defined $ENV{wiz_host_name} or die "wiz_host_name not in env"; my $hostname = $mdk{HOSTNAME}; $mdk{DOMAINNAME} = $ENV{wiz_domain_name} if defined $ENV{wiz_host_name} or die "wiz_domain_name not in env"; $mdk{NETWORKING} = "yes"; $mdk{GATEWAYDEV} = $ENV{wiz_extn_device} if defined $ENV{wiz_extn_device} or die "wiz_extn_device not in env"; $mdk{GATEWAY} = $ENV{wiz_extn_gateway} if defined $ENV{wiz_extn_gateway} or die "wiz_extn_gateway not in env"; Vareqval->commit($file, \%mdk); $file = "/etc/sysconfig/network-scripts/ifcfg-$ENV{wiz_device}" if defined $ENV{wiz_device} or die "wiz_device not in env"; if (-f $file) { MDK::Common::cp_af($file, "mdk_$file.orig"); %mdk = Vareqval->get($file); $old_ip = $mdk{IPADDR} || $o->network_get('IPADDR') } else { system("touch $file"); %mdk = Vareqval->get($file); } # starting chg_val sequence $mdk{DEVICE} = $ENV{wiz_device}; $mdk{BOOTPROTO} = "none"; $mdk{IPADDR} = $ENV{wiz_ip_server} if defined $ENV{wiz_ip_server} or die "IPADDR not found in $file"; my $new_ip = $mdk{IPADDR}; $mdk{NETMASK} = $wiz_ip_netmask; $mdk{NETWORK} = $ENV{wiz_ip_net} if defined $ENV{wiz_ip_net} or die "NETWORK not found in $file"; $mdk{ONBOOT} = "yes"; $mdk{IPXNETNUM_802_2} = ""; $mdk{IPXPRIMARY_802_2} = "no"; $mdk{IPXACTIVE_802_2} = "no"; $mdk{IPXNETNUM_802_3} = ""; $mdk{IPXPRIMARY_802_3} = "no"; $mdk{IPXACTIVE_802_3} = "no"; $mdk{IPXNETNUM_ETHERII} = ""; $mdk{IPXPRIMARY_ETHERII} = "no"; $mdk{IPXACTIVE_ETHERII} = "no"; $mdk{IPXNETNUM_SNAP} = ""; $mdk{IPXPRIMARY_SNAP} = "no"; $mdk{IPXACTIVE_SNAP} = "no"; # chg_val sequence ended Vareqval->commit($file, \%mdk); $file = "/etc/hosts"; MDK::Common::cp_af($file, $file . ".orig"); if (defined $old_ip && $old_ip ne $new_ip) { my $tmp = `mktemp /tmp/Serverconf.XXXXXX`; chomp($tmp); open(OLD, "< $file") or die "can not open $file"; open(NEW, "> $tmp") or die "can not open $tmp"; while () { if (/^\s*(?!#)*\s*$old_ip/) { print NEW "# removed by mdk_serv script on $date #$_ $new_ip\t$hostname\n"; next; } print NEW $_; } close OLD; close NEW; system("mv $tmp $file"); } else { open(NEW, ">> $file"); print NEW "$new_ip\t$hostname\n"; close NEW; } do_it_last(); system("/etc/rc.d/init.d/network stop"); system("/etc/rc.d/init.d/network start"); 10; } 1;