home *** CD-ROM | disk | FTP | other *** search
- ## 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- Networking is not yet configured.
- >
- EOM
- , 60);
- return 0;
- }
-
- $ret = &_init_net;
-
- if ($net_up) {
- &rhs_msgbox("Notice",
- <<EOM
- >
- The network has been initialized.
- >
- EOM
- , 40);
- } else {
- &rhs_msgbox("Error",
- <<EOM
- >
- 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",
- <<EOM
- >
- The network was NOT brought down.
- >
- EOM
- , 40);
- } else {
- &rhs_msgbox("Notice",
- <<EOM
- >
- Networking has been brought down.
- >
- EOM
- , 40);
- }
-
- return $ret;
- }
-
- # This sub is used for the auto install
- sub configure_network {
-
- &mount_bootdisk();
-
- if ( -f "/bootdisk/defaults/network" ) {
- require "/bootdisk/defaults/network";
- $config_net_first_time = 0;
- }
-
- if ($net_configed) {
- if (&rhs_yesno("Choose",
- <<EOM
- >
- 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 && !($installsource eq "ftp" ||
- $installsource eq "nfs")) {
- if (! &rhs_yesno("Choose",
- <<EOM
- >
- Do you want to configure networking for your installed Linux system?
- >
- EOM
- , 70)) {
- $net_configed = 0;
-
- if (! &rhs_inputbox ( "Hostname",
- <<EOM
- >
- Please enter a hostname for this machine (Example: torgo.redhat.com)
- >
- EOM
- , 70, $tmp)) {
- return 0;
- }
- $fqdn = $dialog_result;
- 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",
- <<EOM
- >
- 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 =
- <<EOM
- >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 .=
- <<EOM
- >Nameserver: none
- EOM
- ;
- } else {
- for ($i = 0; $i < @nslist; $i++) {
- $msg .=
- <<EOM
- >Nameserver: $nslist[$i]
- EOM
- ;
- }
- }
- $msg .=
- <<EOM
- >
- Is this correct?
- EOM
- ;
-
- if (&rhs_yesno("Net Config", $msg, 50)) {
- $net_configed = 1;
- return 1;
- }
-
- if (! &rhs_menu("Choose",
- <<EOM
- >
- 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",
- <<EOM
- Edit network parameters.
- EOM
- , 60, 12,
- "Interface", $interface,
- "Hostname", $hostname,
- "Domain name", $domainname,
- "FQDN", $fqdn,
- "IP Address", $ipaddr,
- "Network", $network,
- "Network mask", $netmask,
- "Broadcast addr", $broadcast,
- "Gateway", $gateway,
- "Nameservers", $ns,
- "--------------", "",
- "Done", "" );
-
- return 0 if (! $ret);
- return 1 if ($dialog_result eq "Done");
-
- &net_interface if ($dialog_result eq "Interface");
- &net_hostname if ($dialog_result eq "Hostname");
- &net_domainname if ($dialog_result eq "Domain name");
- &net_fqdn if ($dialog_result eq "FQDN");
- &net_ipaddr if ($dialog_result eq "IP Address");
- &net_network if ($dialog_result eq "Network");
- &net_netmask if ($dialog_result eq "Network mask");
- &net_broadcast if ($dialog_result eq "Broadcast addr");
- &net_gateway if ($dialog_result eq "Gateway");
- &net_nameservers if ($dialog_result eq "Nameservers");
- }
- }
-
- sub _uninit_net {
- if ($net_up) {
- &invoke("ifconfig $iface down");
- $net_up = 0;
- }
- return 1;
- }
-
- sub _init_net {
- local ( $ret, $domain_bit, $string );
-
- open (FD, ">/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",
- <<EOM
- >
- 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",
- <<EOM
- Which type of Ethernet adapter does this computer have?
- EOM
- , 70, 2,
- "internal", "Internal Ethernet card",
- "external", "D-Link external adapter")) {
- return 0;
- }
- }
-
- $interface = $dialog_result;
- if ($interface eq "internal") {
- $iface = "eth0";
- } else {
- $iface = "dl0";
- }
- return 1;
- }
-
- sub net_hostname {
-
- if (! &rhs_inputbox ( "Network Configuration",
- <<EOM
- What hostname have you selected for this computer? (Example: torgo)
- EOM
- , 70, $hostname)) {
- return 0;
- }
-
- $hostname = $dialog_result;
- return 1;
- }
-
- sub net_domainname {
-
- if (! &rhs_inputbox ( "Network Configuration",
- <<EOM
- What domain name is this computer part of? (Example: redhat.com)
- EOM
- , 70, $domainname)) {
- return 0;
- }
-
- $domainname = $dialog_result;
- return 1;
- }
-
- sub net_fqdn {
- local ( $tmp, $ex );
-
- if ($hostname ne "" && $domainname ne "") {
- $tmp = $hostname . "." . $domainname;
- }
- if ($fqdn ne "") {
- $tmp = $fqdn;
- }
-
- if (! &rhs_inputbox ( "Network Configuration",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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",
- <<EOM
- >
- Does this computer use a nameserver?
- >
- EOM
- , 70)) {
- return 0;
- }
-
- do {
- if (! &rhs_inputbox ( "Network Configuration",
- <<EOM
- >
- What is the IP address of the nameserver?
- >
- EOM
- , 70, "")) {
- return 0;
- }
-
- $nslist[@nslist] = $dialog_result;
- } while (&rhs_yesno ( "Network Configuration",
- <<EOM
- >
- 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
- <<EOM
- #!/bin/sh
-
- #>>>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",
- <<EOM
- >
- 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",
- <<EOM
- >
- 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;
-