## Takes care of configuring the network -*-perl-*- $net_up = 0; $interface = "internal"; $hostname = ""; $domainname = ""; $fqdn = ""; $ipaddr = ""; $network = ""; $netmask = ""; $broadcast = ""; $gateway = ""; @nslist = (); $config_net_first_time = 1; $net_configed = 0; sub make_net_up { while (! $net_up) { if (! &config_net) { return 0; } &_uninit_net; &_init_net; } return 1; } sub reconfig_net_up { if ($net_up) { &_uninit_net; } return &make_net_up; } sub bring_net_up { local ( $ret ); if ($net_up) { if (! &rhs_yesno("Notice", < Networking appears to be active already. > Bring it down and then back up? > EOM , 60)) { return 1; } &_uninit_net; } if (! $net_configed) { &rhs_msgbox("Error", < Networking is not yet configured. > EOM , 60); return 0; } $ret = &_init_net; if ($net_up) { &rhs_msgbox("Notice", < The network has been initialized. > EOM , 40); } else { &rhs_msgbox("Error", < The network has NOT been initialized. > EOM , 40); } return $ret; } sub bring_net_down { local ( $ret ); $ret = &_uninit_net; if ($net_up) { &rhs_msgbox("Error", < The network was NOT brought down. > EOM , 40); } else { &rhs_msgbox("Notice", < Networking has been brought down. > EOM , 40); } return $ret; } # This sub is used for the auto install sub configure_network { if ( -f "/bootdisk/defaults/network" ) { require "/bootdisk/defaults/network"; $config_net_first_time = 0; } if ($net_configed) { if (&rhs_yesno("Choose", < Networking has already been configured (probably for an NFS install). Do you wish to use this configuration for your installed Linux system? > EOM , 70)) { return 1; } } if ($config_net_first_time) { if (! &rhs_yesno("Choose", < Do you want to configure networking for your installed Linux system? > EOM , 70)) { $net_configed = 0; return 1; } } return &reconfig_net_up; print "Reached end of configure_network() !!\n"; exit 1; } sub config_net { local ( $msg, $i, $first_time ); if ($net_up) { if (! &rhs_yesno("Notice", < Networking appears to be up. If you continue and change any network parameters, you should bring networking down and back up again. > Continue? > EOM , 60)) { return 1; } } while (1) { if ($config_net_first_time) { $config_net_first_time = 0; next if (! &config_net_sequence); } # Are these parameters correct? $msg = <You have entered the following parameters: >Interface: $interface >Hostname: $hostname >Domain name: $domainname >IP address: $ipaddr >Network address: $network >Network mask: $netmask >Broadcast address: $broadcast >Gateway: $gateway EOM ; if (@nslist == 0) { $msg .= <Nameserver: none EOM ; } else { for ($i = 0; $i < @nslist; $i++) { $msg .= <Nameserver: $nslist[$i] EOM ; } } $msg .= < Is this correct? EOM ; if (&rhs_yesno("Net Config", $msg, 50)) { $net_configed = 1; return 1; } if (! &rhs_menu("Choose", < What do you wish to do? > EOM , 60, 3, "Sequence", "Configure network information in sequence", "Individual", "Configure individual network parameters", "Cancel", "Cancel all network configuration")) { return 0; } if ($dialog_result eq "Sequence") { next if (! &config_net_sequence); } elsif ($dialog_result eq "Individual") { next if (! &config_net_individual); } elsif ($dialog_result eq "Cancel") { # Cancel $net_configed = 0; return 0; } } } sub config_net_sequence { return 0 if (! &net_interface); return 0 if (! &net_hostname); return 0 if (! &net_domainname); return 0 if (! &net_fqdn); return 0 if (! &net_ipaddr); return 0 if (! &net_network); return 0 if (! &net_netmask); return 0 if (! &net_broadcast); return 0 if (! &net_gateway); return 0 if (! &net_nameservers); return 1; } sub config_net_individual { local ( $ret, $i, $ns ); while (1) { $ns = $nslist[0]; for ($i = 1; $i < @nslist; $i++) { $ns .= ", $nslist[$i]"; } $ns = sprintf("%.25s", $ns); $ret = &rhs_menu ( "Network Configuration", </etc/resolv.conf"); $string = &gen_resolv_conf; print FD $string; close FD; # We write this stuff so the X install can get at it open (FD, ">/tmp/resolv.conf"); print FD $string; close FD; open (FD, ">/tmp/network"); $string = &gen_network; print FD $string; close FD; open(FD, ">/tmp/ifcfg-$iface"); $string = &gen_ifcfg_eth; print FD $string; close FD; open(FD, ">/tmp/HOSTNAME"); $string = &gen_HOSTNAME; print FD $string; close FD; open(FD, ">/tmp/hosts"); $string = &gen_hosts; print FD $string; close FD; open(FD, ">/tmp/networks"); $string = &gen_networks; print FD $string; close FD; # Done writing temp stuff &invoke("hostname $fqdn"); $ret = &invoke("ifconfig $iface $ipaddr netmask $netmask broadcast $broadcast"); $ret = &invoke("route add -net $network netmask $netmask") unless ($ret != 0); $ret = &invoke("route add default gw $gateway metric 1") if (($gateway ne "none") && ($ret == 0)); if ($ret != 0) { $net_up = 0; &rhs_msgbox ( "Error", < An error occurred while setting up the network. Please check to see that it is configured properly. > EOM , 70); return 0; } $net_up = 1; return 1; } ########## Individual Network config dialogs #################### sub net_interface { if ($express_install) { # just assume internal # I dont even know if it will work with an "external" $dialog_result = "internal"; } else { if (! &rhs_menu ( "Network Configuration", < What is the fully qualified domain name (FQDN) of this computer? (Example: torgo.redhat.com) > EOM , 70, $tmp)) { return 0; } $fqdn = $dialog_result; return 1; } sub net_ipaddr { if (! &rhs_inputbox ( "Network Configuration", < What is the IP address of this computer? (Example: 199.183.24.2) > EOM , 70, $ipaddr)) { return 0; } if ($dialog_result =~ /^(.*)\.(.*)\.(.*)\.(.*)$/) { if ($1 > 223) { if (! &rhs_yesno ( "Network Configuration", < You have indicated a reserved network address. Please confirm this choice. > EOM , 70 )) { return 0; } } } $ipaddr = $dialog_result; return 1; } sub net_network { local ( $tmp ); if ($ipaddr =~ /^(.*)\.(.*)\.(.*)\.(.*)$/) { $tmp = $ipaddr; $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.0.0.0/ if ($1 <= 26); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2.0.0/ if ($1 > 26 && $1 <= 128); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2.$3.0/ if ($1 > 128); } $tmp = $network if ($network ne ""); if (! &rhs_inputbox ( "Network Configuration", < What is the network address of this computer? (Example: 199.183.24.0) > EOM , 70, $tmp)) { return 0; } $network = $dialog_result; return 1; } sub net_netmask { local ( $tmp ); if ($ipaddr =~ /^(.*)\.(.*)\.(.*)\.(.*)$/) { $tmp = $ipaddr; $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/255.0.0.0/ if ($1 <= 26); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/255.255.0.0/ if ($1 > 26 && $1 <= 128); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/255.255.255.0/ if ($1 > 128); } $tmp = $netmask if ($netmask ne ""); if (! &rhs_inputbox ( "Network Configuration", < What is the netmask used by this computer? (Example: 255.255.255.0) > EOM , 70, $tmp)) { return 0; } $netmask = $dialog_result; return 1; } sub net_broadcast { local ( $tmp ); if ($ipaddr =~ /^(.*)\.(.*)\.(.*)\.(.*)$/) { $tmp = $ipaddr; $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.255.255.255/ if ($1 <= 26); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2.255.255/ if ($1 > 26 && $1 <= 128); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2.$3.255/ if ($1 > 128); } $tmp = $broadcast if ($broadcast ne ""); if (! &rhs_inputbox ( "Network Configuration", < What is the broadcast address used by this computer? (Example: 199.183.24.255) > EOM , 70, $tmp)) { return 0; } $broadcast = $dialog_result; return 1; } sub net_gateway { local ( $tmp ); if (! &rhs_yesno ( "Network Configuration", < Does this computer use a gateway? > EOM , 70 )) { $gateway = "none"; return 1; } if ($ipaddr =~ /^(.*)\.(.*)\.(.*)\.(.*)$/) { $tmp = $ipaddr; $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1./ if ($1 <= 26); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2./ if ($1 > 26 && $1 <= 128); $tmp =~ s/^(.*)\.(.*)\.(.*)\.(.*)$/$1.$2.$3./ if ($1 > 128); } $tmp = $gateway if ($gateway ne "" && $gateway ne "none"); if (! &rhs_inputbox ( "Network Configuration", < What is the IP address of the gateway used by this computer? > EOM , 70, $tmp)) { return 0; } $gateway = $dialog_result; return 1; } sub net_nameservers { @nslist = (); if (! &rhs_yesno ( "Network Configuration", < Does this computer use a nameserver? > EOM , 70)) { return 0; } do { if (! &rhs_inputbox ( "Network Configuration", < What is the IP address of the nameserver? > EOM , 70, "")) { return 0; } $nslist[@nslist] = $dialog_result; } while (&rhs_yesno ( "Network Configuration", < Does this computer use another nameserver? > EOM , 70)); return 1; } sub gen_network { local ( $res ); $res = "NETWORKING=yes\n"; $res .= "HOSTNAME=$fqdn\n"; return $res; } sub gen_ifcfg_eth { return <>>Device type: ethernet #>>>Variable declarations: DEVICE=$iface IPADDR=$ipaddr NETMASK=$netmask NETWORK=$network BROADCAST=$broadcast GATEWAY=$gateway ONBOOT=yes #>>>End variable declarations EOM ; } sub gen_HOSTNAME { return "$fqdn\n"; } sub gen_hosts { local ( $res ); if ($net_configed == 1) { $res = sprintf("%-18s %-25s\n", "127.0.0.1", "localhost"); $res .= sprintf("%-18s %-25s %s\n", $ipaddr, $fqdn, $hostname); } else { $res = sprintf("%-18s %-25s %s\n", "127.0.0.1", "localhost", $fqdn); } return $res; } sub gen_resolv_conf { local ( $res, $tmp, $domain_bit, $i ); $res = "domain $domainname\n"; # There needs to be a "search" line in here $res .= "search"; $tmp = $domainname; for (;;) { last if (! ($tmp =~ /\./)); $domain_bit = $tmp; $res .= " $domain_bit"; $tmp =~ s/^\w*\.//; last if ($tmp eq $domain_bit); } $res .= "\n"; for ($i = 0; $i < @nslist; $i++) { $res .= "nameserver $nslist[$i]\n"; } return $res; } sub gen_networks { local ( $res ); $res = "loopback 127.0.0.0\n"; if ($net_configed == 1) { $res .= "localnet $network\n"; } return $res; } sub finish_net { local ( $tmp, $domain_bit, $i, $string ); # Indicate networking - we always have a loopback device open(FD, ">$fsmount/etc/sysconfig/network"); $string = &gen_network; print FD $string; close FD; # Configure ethernet device if ($net_configed != 0) { open(FD, ">$fsmount/etc/sysconfig/network-scripts/ifcfg-$iface"); $string = &gen_ifcfg_eth; print FD $string; close FD; } # /etc/HOSTNAME open(FD, ">$fsmount/etc/HOSTNAME"); $string = &gen_HOSTNAME; print FD $string; close FD; # /etc/hosts open(FD, ">$fsmount/etc/hosts"); $string = &gen_hosts; print FD $string; close FD; # /etc/networks open(FD, ">$fsmount/etc/networks"); $string = &gen_networks; print FD $string; close FD; # /etc/resolv.conf open (FD, ">$fsmount/etc/resolv.conf"); $string = &gen_resolv_conf; print FD $string; close FD; return 1; } sub config_hostname { if ($net_configed) { if (! $express_install) { &rhs_msgbox("Notice", < You have already configured your hostname to be $fqdn (during network configuration). This will be used unless you re-configure networking. > EOM , 60); } return 1; } if (! &rhs_inputbox("Hostname", < Please enter the hostname that you wish to use for your machine. > EOM , 60, "")) { return 0; } $hostname = $dialog_result; $fqdn = $dialog_result; &invoke("hostname $fqdn"); return 1; } sub net_reset { &_uninit_net; $net_configed = 0; } ########################## 1;