1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/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 (<OLD>) {
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;
|