#!/usr/local/bin/perl

# Domainedit v2.0
#
# 10/12/95 - Kevin Clark  kclark@usa.net
#
#
# Define your default settings below:
#
# defaultNS1name is the hostname of your primary nameserver,
# defaultNS1ip is the IP address of your primary nameserver,
# defaultNS2name is the hostname of your secondary nameserver,
# defaultNS2ip is the IP address of your secondary nameserver,
# defaultdelivery is the default on billing invoices (E)mail or (P)ostal,
# defaultcountry is self-explanatory,
# mailer is your preferred unix mail agent, must support subject lines
#
### DEFAULTS ### USER DEFINED ###############################################
$defaultNS1name = "NS1.USA.NET";
$defaultNS1ip = "192.156.196.3";
$defaultNS2name = "NS2.USA.NET";
$defaultNS2ip = "192.156.196.1";
$defaultdelivery = "E";
$defaultcountry = "USA";
$mailer = "mailx";
##############################################################################

### Set defaults
$ns1name = $defaultNS1name;
$ns1ip = $defaultNS1ip;
$ns2name = $defaultNS2name;
$ns2ip = $defaultNS2ip;
$delivery = $defaultdelivery;
$country = $defaultcountry;

$numdomains = @ARGV;
&processargs(@ARGV);

sub processargs {
  if($numdomains == 0) {
    print "domainedit v2.0\n";
    print "Usage:  domainedit -[mdn]\n";
    print "        domainedit -[mdn] domain1 domain2 domain3 ...\n";
    print "        domainedit -h for help\n";
    exit(1);
  }

  if(@ARGV[0] eq "-h") {
    print "Domainedit v2.0 by Kevin Clark\n";
    print "------------------------------------------\n";
    print "Options:\n";
    print "-h   : Displays this help screen\n";
    print "-n   : Create a new domain and register it\n";
    print "-m   : Modify existing domain\n";
    print "-d   : Delete existing domain\n\n";
    exit(1);
  }

  if(@ARGV[0] eq "-d") {
    if($numdomains == 1) {
      print "Enter name of domain to delete: ";
      $domainname = <STDIN>; chop($domainname);
      &deletedomain();
      $flag = 1;
    }
    else {
      $numdomains = $numdomains - 1;
      shift(@ARGV);
      $domainname = @ARGV[0];
      &deletedomain();
      $flag = 1;
    }
  }

  if(@ARGV[0] eq "-m") {
    if($numdomains == 1) {
      print "Enter name of domain to edit: ";
      $domainname = <STDIN>; chop($domainname);
      &modifydomain();
      $flag = 1;
    }
    else {
      $numdomains = $numdomains - 1;
      shift(@ARGV);
      $domainname = @ARGV[0];
      &modifydomain();
      $flag = 1;
    }
  }
    
  if(@ARGV[0] eq "-n") {
    if($numdomains == 1) {
      print "Enter name of domain to create: ";
      $domainname = <STDIN>; chop($domainname);
    }
    else {
      $numdomains = $numdomains - 1;
      shift(@ARGV);
      $domainname = @ARGV[0];
    }
    &newdomain();
    $flag = 1;
  }

  if((@ARGV[0] ne "-m") && (@ARGV[0] ne "-n") && (@ARGV[0] ne "-d") && ($flag != 1)) {
    print "Usage:  domainedit -[mdn]\n";
    print "        domainedit -[mdn] domain1 domain2 domain3 ...\n";
    print "        domainedit -h for help\n";
    exit(1);
  }
}

sub deletedomain {
  for($i=0; $i < $numdomains; $i++) {
    system 'clear';
    open(WHOIS, "whois $domainname|");
    @whoisinfo = <WHOIS>;
    close(WHOIS);
    print @whoisinfo;
    print "Do you wish to DELETE [$domainname] (y,n): ";
    $choice = <STDIN>; chop($choice);
    if($choice eq "y") {
      $PURPOSE = "Delete Domain $domainname";
      $type = "D";
      &assignfields(@whoisinfo);
      &modifymenu();
      shift @ARGV;
      $domainname = @ARGV[0];
    }
    else {
      shift @ARGV;
      $domainname = @ARGV[0];
    }
  }
}

sub modifydomain {
  for($i=0; $i < $numdomains; $i++) {
    system 'clear';
    open(WHOIS, "whois $domainname|");
    @whoisinfo = <WHOIS>;
    close(WHOIS);
    print @whoisinfo; 
    print "\nDo you wish to modify domain [$domainname]? [y,n]: ";
    $choice = <STDIN>; chop($choice);
    if($choice eq "y") {
      $PURPOSE = "Modify Domain $domainname";
      $type = "M";
      &assignfields(@whoisinfo);
      &modifymenu();
      shift @ARGV;
      $domainname = @ARGV[0];
    }
    else {
      shift @ARGV;
      $domainname = @ARGV[0];
    }
  }
}

sub resetfields {
  $orgname = ""; $address1 = ""; $address2 = ""; $adminNIC = "";
  $adminlastname = ""; $adminfirstname = ""; $adminphone = "";
  $adminemail = ""; $techNIC = ""; $techlastname = ""; $techfirstname = "";
  $techphone = ""; $techemail = "";
}

sub newdomain {
  for($i=0; $i < $numdomains; $i++) {
    $PURPOSE = "New Domain $domainname";
    $type = "N";
    &modifymenu();
  }
}

sub assignfields {
  ($orgname, $dummy) = split(/\(/,@_[0]);
  $nextline = 1;
  $address1 = @_[$nextline]; chop($address1); $nextline++;
  $street = $address1;
  $address2 = @_[$nextline]; chop($address2); $nextline++;
  substr($street,0,3) = ''; substr($address2,0,3) = '';
  ($city, $remainder) = split(/\,/,$address2);
  substr($remainder,0,1) = '';
  ($state, $zipcode) = split(" ",$remainder);
  if(length(@_[$nextline]) != 1) {
    $country = @_[$nextline];
    substr($country,0,3) = '';
    chop($country);
    $nextline++;
  }
  $nextline = $nextline + 4;
  ($adminlastname, $remainder) = split(/\,/,@_[$nextline]);
  substr($adminlastname,0,6) = ''; $adminlastname = $adminlastname.",";
  ($adminfirstname, $remainder) = split(/\(/,$remainder);
  ($adminNIC, $adminemail) = split(/\)/,$remainder);
  substr($adminemail,0,2) = '';
  chop($adminemail);
  $nextline++;
  $adminphone = @_[$nextline]; substr($adminphone,0,6) = '';
  chop($adminphone); 
  $nextline++;

  $_ = @_[$nextline];
  if(/Technical/) {
    $nextline++;
    ($techlastname, $remainder) = split(/\,/,@_[$nextline]);
    substr($techlastname,0,6) = ''; $techlastname = $techlastname.",";
    ($techfirstname, $remainder) = split(/\(/,$remainder);
    ($techNIC, $techemail) = split(/\)/,$remainder);
    substr($techemail,0,2) = '';
    chop($techemail);
    $nextline++;
    $techphone = @_[$nextline]; substr($techphone,0,6) = '';
    chop($techphone);
    $nextline++;
  }
  else {
    $techlastname = $adminlastname; $techfirstname = $adminfirstname;
    $techNIC = $adminNIC; $techemail = $adminemail; $techphone = $adminphone;
  }
  $nextline = $nextline + 6;
  ($ns1name, $ns1ip) = split(' ',@_[$nextline]);
  $nextline++;
  ($ns2name, $ns2ip) = split(' ',@_[$nextline]);
}

sub showdomain {
  if($delivery eq "E") {
    $deliverydesc = "Email";
  }
  else {
    $deliverydesc = "Postal";
  }
  system 'clear';
  print "Purpose: $PURPOSE\n\n\n";
  print "1.  Complete Domain Name........: $domainname\n";
  print "2.  Organization Name...........: $orgname\n";
  print "3.  Organization Address........: $street\n";
  print "4.  City........................: $city\n";
  print "5.  State.......................: $state\n";
  print "6.  Zipcode.....................: $zipcode\n";
  print "7.  Country.....................: $country\n\n";
  print "8.  Invoice Delivery Type.......: $deliverydesc\n\n";
  print "[N]  Change Name Server Information\n";
  print "[A]  Change Administrative Contact Information\n";
  print "[T]  Change Technical Contact Information\n";
  print "[B]  Change Billing Contact Information\n\n";
  print "[S]  Save changes\n";
  print "[Q]  Quit without saving\n\n\n";
}

sub shownameservers {
  system 'clear';
  print "Nameservers Menu\n\n";
  print "1.  Primary Server Hostname......: $ns1name\n";
  print "2.  Primary Server IP............: $ns1ip\n\n";
  print "3.  Secondary Server Hostname....: $ns2name\n";
  print "4.  Secondary Server IP..........: $ns2ip\n\n";
  print "[X] Return to Main Menu\n\n\n";
}

sub showadmin {
  system 'clear';
  print "Administrative Contact\n\n";
  print "1.  NIC Handle (if known)......: $adminNIC\n";
  print "2.  Name (Last, First).........: $adminlastname $adminfirstname\n";
  print "3.  Organization Name..........: $adminorgname\n";
  print "4.  Street Address.............: $adminstreet\n";
  print "5.  City.......................: $admincity\n";
  print "6.  State......................: $adminstate\n";
  print "7.  Zipcode....................: $adminzipcode\n";
  print "8.  Country....................: $admincountry\n";
  print "9.  Phone Number...............: $adminphone\n";
  print "10. E-Mailbox..................: $adminemail\n\n";
  print "[D] Set information to domain's information\n";
  print "[T] Set information to Technical Contact's information\n";
  print "[B] Set information to Billing Contact's information\n\n";
  print "[X] Return to Main Menu\n\n";
}

sub showtech {
  system 'clear';
  print "Technical Contact\n\n";
  print "1.  NIC Handle (if known)......: $techNIC\n";
  print "2.  Name (Last, First).........: $techlastname $techfirstname\n";
  print "3.  Organization Name..........: $techorgname\n";
  print "4.  Street Address.............: $techstreet\n";
  print "5.  City.......................: $techcity\n";
  print "6.  State......................: $techstate\n";
  print "7.  Zipcode....................: $techzipcode\n";
  print "8.  Country....................: $techcountry\n";
  print "9.  Phone Number...............: $techphone\n";
  print "10. E-Mailbox..................: $techemail\n\n";
  print "[D] Set information to domain's information\n";
  print "[A] Set information to Administrative Contact's information\n";
  print "[B] Set information to Billing Contact's information\n\n";
  print "[X] Return to Main Menu\n\n";
}

sub showbilling {
  system 'clear';
  print "Billing Contact\n\n";
  print "1.  NIC Handle (if known)......: $billingNIC\n";
  print "2.  Name (Last, First).........: $billinglastname $billingfirstname\n";
  print "3.  Organization Name..........: $billingorgname\n";
  print "4.  Street Address.............: $billingstreet\n";
  print "5.  City.......................: $billingcity\n";
  print "6.  State......................: $billingstate\n";
  print "7.  Zipcode....................: $billingzipcode\n";
  print "8.  Country....................: $billingcountry\n";
  print "9.  Phone Number...............: $billingphone\n";
  print "10. E-Mailbox..................: $billingemail\n\n";
  print "[D] Set information to domain's information\n";
  print "[A] Set information to Administrative Contact's information\n";
  print "[T] Set information to Technical Contact's information\n\n";
  print "[X] Return to Main Menu\n\n";
}

sub modifymenu {
  $selection = "99";
  while($selection ne "done") {
    &showdomain();
    print "Enter choice: ";
    $selection = <STDIN>; chop($selection);

    if(($selection eq 'S') || ($selection eq 's')) {
      if(&check_fields() == 2) {
        $selection = "incomplete";
      }
    else {
      $selection = "done";
    }
    }

    if(($selection eq 'Q') || ($selection eq 'q')) {
      print "Quitting...\n";
      exit(0);
    }

    if($selection == 1) {
      print "\nEnter domain name: ";
      $domainname = <STDIN>; chop($domainname); 
    }
    
    if($selection == 2) {
      print "\nEnter organization name: ";
      $orgname = <STDIN>; chop($orgname);
    }

    if($selection == 3) {
      print "\nEnter street address: ";
      $street = <STDIN>; chop($street);
    }

    if($selection == 4) {
      print "Enter city: ";
      $city = <STDIN>; chop($city);
    }

    if($selection == 5) {
      print "Enter state: ";
      $state = <STDIN>; chop($state);
    }

    if($selection == 6) {
      print "Enter zipcode: ";
      $zipcode = <STDIN>; chop($zipcode);
    }

    if($selection == 7) {
      print "Enter country: ";
      $country = <STDIN>; chop($country);
    }

    if($selection == 8) {
      $delivery = 0;
      while(($delivery ne "E") && ($delivery ne "P") && ($delivery ne "p") && ($delivery ne "e")) {
        print "Would you like you bill delivered via Email or Postal Mail [E,P]: ";
        $delivery = <STDIN>; chop($delivery);
        if($delivery eq "e") {
          $delivery = "E";
        }
        if($delivery eq "p") {
          $delivery = "P";
        }
      } 
    } 

    if(($selection eq 'N') || ($selection eq 'n')) {
      while(($selection ne "X") && ($selection ne "x")) {
        &shownameservers();
        print "Enter choice: ";
        $selection = <STDIN>; chop($selection);
       
        if($selection == 1) {
          print "Enter primary server hostname [$defaultNS1name]: ";
          $ns1name = <STDIN>; chop($ns1name);
          if(length($ns1name) < 1) {
            $ns1name = $defaultNS1name;
          }
        }
	
	if($selection == 2) {
	  print "Enter primary server's IP address [$defaultNS1ip]: ";
	  $ns1ip = <STDIN>; chop($ns1ip);
 	  if(length($ns1ip) < 1) {
	    $ns1ip = $defaultNS1ip;
	  }
	}

	if($selection == 3) {
	  print "Enter secondary server hostname [$defaultNS2name]: ";
	  $ns2name = <STDIN>; chop($ns2name);
	  if(length($ns2name) < 1) {
	    $ns2name = $defaultNS2name;
	  }
	}

	if($selection == 4) {
	  print "Enter secondary server's IP address [$defaultNS2ip]: ";
	  $ns2ip = <STDIN>; chop($ns2ip);
	  if(length($ns2ip) < 1) {
	    $ns2ip = $defaultNS2ip;
	  }
	}
      } 
    $selection = 99;
    }

    if(($selection eq 'A') || ($selection eq 'a')) {
      while(($selection ne "X") && ($selection ne "x")) {
        &showadmin();
        print "Enter choice: ";
        $selection = <STDIN>; chop($selection);
        
	if($selection == 1) {
	  print "Enter NIC Handle: ";
	  $adminNIC = <STDIN>; chop($adminNIC);
	}

	if($selection == 2) {
	  print "Enter last name: ";
	  $adminlastname = <STDIN>; chop($adminlastname);
	  $adminlastname = $adminlastname.",";
	  print "Enter first name: ";
	  $adminfirstname = <STDIN>; chop($adminfirstname);
	}

	if($selection == 3) {
	  print "Enter organization name: ";
	  $adminorgname = <STDIN>; chop($adminorgname);
	}

	if($selection == 4) {
	  print "Enter street address: ";
	  $adminstreet = <STDIN>; chop($adminstreet);
	}

	if($selection == 5) {
	  print "Enter city: ";
	  $admincity = <STDIN>; chop($admincity);
	}

	if($selection == 6) {
	  print "Enter state: ";
	  $adminstate = <STDIN>; chop($adminstate);
	}

	if($selection == 7) {
	  print "Enter zipcode: ";
	  $adminzipcode = <STDIN>; chop($adminzipcode);
	}

	if($selection == 8) {
	  print "Enter country: ";
	  $admincountry = <STDIN>; chop($admincountry);
	}

	if($selection == 9) {
	  print "Enter phone number: ";
	  $adminphone = <STDIN>; chop($adminphone);
	}

	if($selection == 10) {
	  print "Enter E-Mailbox: ";
	  $adminemail = <STDIN>; chop($adminemail);
	}

	if(($selection eq 'D') || ($selection eq 'd')) {
	  $adminstreet = $street;
	  $admincity = $city;
	  $adminstate = $state;
	  $adminzipcode = $zipcode;
	  $admincountry = $country;
	  $adminorgname = $orgname;
	}

	if(($selection eq 'T') || ($selection eq 't')) {
	  $adminorgname = $techorgname; 
	  $adminstreet = $techstreet;
	  $admincity = $techcity;
	  $adminstate = $techstate;
	  $adminzipcode = $techzipcode;
	  $admincountry = $techcountry;
	  $adminNIC = $techNIC;
	  $adminlastname = $techlastname;
	  $adminfirstname = $techfirstname;
	  $adminphone = $techphone;
	  $adminemail = $techemail;
	}

	if(($selection eq 'B') || ($selection eq 'b')) {
	  $adminorgname = $billingorgname; 
	  $adminstreet = $billingstreet;
	  $admincity = $billingcity;
	  $adminstate = $billingstate;
	  $adminzipcode = $billingzipcode;
	  $admincountry = $billingcountry;
	  $adminNIC = $billingNIC;
	  $adminlastname = $billinglastname;
	  $adminfirstname = $billingfirstname;
	  $adminphone = $billingphone;
	  $adminemail = $billingemail;
	}

      }
    $selection = 99; 
    }
      
    if(($selection eq 'B') || ($selection eq 'b')) {
      while(($selection ne "X") && ($selection ne "x")) {
        &showbilling();
        print "Enter choice: ";
        $selection = <STDIN>; chop($selection);
        
	if($selection == 1) {
	  print "Enter NIC Handle: ";
	  $billingNIC = <STDIN>; chop($billingNIC);
	}

	if($selection == 2) {
	  print "Enter last name: ";
	  $billinglastname = <STDIN>; chop($billinglastname);
	  $billinglastname = $billinglastname.",";
	  print "Enter first name: ";
	  $billingfirstname = <STDIN>; chop($billingfirstname);
	}

	if($selection == 3) {
	  print "Enter organization name: ";
	  $billingorgname = <STDIN>; chop($billingorgname);
	}

	if($selection == 4) {
	  print "Enter street address: ";
	  $billingstreet = <STDIN>; chop($billingstreet);
	}

	if($selection == 5) {
	  print "Enter city: ";
	  $billingcity = <STDIN>; chop($billingcity);
	}

	if($selection == 6) {
	  print "Enter state: ";
	  $billingstate = <STDIN>; chop($billingstate);
	}

	if($selection == 7) {
	  print "Enter zipcode: ";
	  $billingzipcode = <STDIN>; chop($billingzipcode);
	}

	if($selection == 8) {
	  print "Enter country: ";
	  $billingcountry = <STDIN>; chop($billingcountry);
	}

	if($selection == 9) {
	  print "Enter phone number: ";
	  $billingphone = <STDIN>; chop($billingphone);
	}

	if($selection == 10) {
	  print "Enter E-Mailbox: ";
	  $billingemail = <STDIN>; chop($billingemail);
	}

	if(($selection eq 'D') || ($selection eq 'd')) {
	  $billingstreet = $street;
	  $billingcity = $city;
	  $billingstate = $state;
	  $billingzipcode = $zipcode;
	  $billingcountry = $country;
	  $billingorgname = $orgname;
	}

	if(($selection eq 'T') || ($selection eq 't')) {
	  $billingorgname = $techorgname; 
	  $billingstreet = $techstreet;
	  $billingcity = $techcity;
	  $billingstate = $techstate;
	  $billingzipcode = $techzipcode;
	  $billingcountry = $techcountry;
	  $billingNIC = $techNIC;
	  $billinglastname = $techlastname;
	  $billingfirstname = $techfirstname;
	  $billingphone = $techphone;
	  $billingemail = $techemail;
	}

	if(($selection eq 'A') || ($selection eq 'a')) {
	  $billingorgname = $adminorgname; 
	  $billingstreet = $adminstreet;
	  $billingcity = $admincity;
	  $billingstate = $adminstate;
	  $billingzipcode = $adminzipcode;
	  $billingcountry = $admincountry;
	  $billingNIC = $adminNIC;
	  $billinglastname = $adminlastname;
	  $billingfirstname = $adminfirstname;
	  $billingphone = $adminphone;
	  $billingemail = $adminemail;
	}
      }
    $selection = 99; 
    }
      
    if(($selection eq 'T') || ($selection eq 't')) {
      while(($selection ne "X") && ($selection ne "x")) {
        &showtech();
        print "Enter choice: ";
        $selection = <STDIN>; chop($selection);
        
	if($selection == 1) {
	  print "Enter NIC Handle: ";
	  $techNIC = <STDIN>; chop($techNIC);
	}

	if($selection == 2) {
	  print "Enter last name: ";
	  $techlastname = <STDIN>; chop($techlastname);
	  $techlastname = $techlastname.",";
	  print "Enter first name: ";
	  $techfirstname = <STDIN>; chop($techfirstname);
	}

	if($selection == 3) {
	  print "Enter organization name: ";
	  $techorgname = <STDIN>; chop($techorgname);
	}

	if($selection == 4) {
	  print "Enter street address: ";
	  $techstreet = <STDIN>; chop($techstreet);
	}

	if($selection == 5) {
	  print "Enter city: ";
	  $techcity = <STDIN>; chop($techcity);
	}

	if($selection == 6) {
	  print "Enter state: ";
	  $techstate = <STDIN>; chop($techstate);
	}

	if($selection == 7) {
	  print "Enter zipcode: ";
	  $techzipcode = <STDIN>; chop($techzipcode);
	}

	if($selection == 8) {
	  print "Enter country: ";
	  $techcountry = <STDIN>; chop($techcountry);
	}

	if($selection == 9) {
	  print "Enter phone number: ";
	  $techphone = <STDIN>; chop($techphone);
	}

	if($selection == 10) {
	  print "Enter E-Mailbox: ";
	  $techemail = <STDIN>; chop($techemail);
	}

	if(($selection eq 'D') || ($selection eq 'd')) {
	  $techstreet = $street;
	  $techcity = $city;
	  $techstate = $state;
	  $techzipcode = $zipcode;
	  $techcountry = $country;
	  $techorgname = $orgname;
	}

	if(($selection eq 'A') || ($selection eq 'a')) {
	  $techorgname = $adminorgname; 
	  $techstreet = $adminstreet;
	  $techcity = $admincity;
	  $techstate = $adminstate;
	  $techzipcode = $adminzipcode;
	  $techcountry = $admincountry;
	  $techNIC = $adminNIC;
	  $techlastname = $adminlastname;
	  $techfirstname = $adminfirstname;
	  $techphone = $adminphone;
	  $techemail = $adminemail;
	}

	if(($selection eq 'B') || ($selection eq 'b')) {
	  $techorgname = $billingorgname; 
	  $techstreet = $billingstreet;
	  $techcity = $billingcity;
	  $techstate = $billingstate;
	  $techzipcode = $billingzipcode;
	  $techcountry = $billingcountry;
	  $techNIC = $billingNIC;
	  $techlastname = $billinglastname;
	  $techfirstname = $billingfirstname;
	  $techphone = $billingphone;
	  $techemail = $billingemail;
	}
      }
    $selection = 99; 
    }
      
  }
 
  while(($selection ne "y") && ($selection ne "n")) {
    print "Do you wish to save these changes and mail to Internic? [y,n]: ";
    $selection = <STDIN>; chop($selection);
    if(($type eq "M") && ($selection eq "y")) {
      print "Please enter a one line or less description of change: ";
      $PURPOSE = <STDIN>;
      chop($PURPOSE);
      &sendform("modify");
    }
    if (($type eq "N") && ($selection eq "y")) {
      $PURPOSE = "New Domain Registration";
      &sendform("new");
      $ns1name = $defaultNS1name; $ns1ip = $defaultNS1ip;
      $ns2name = $defaultNS2name; $ns2ip = $defaultNS2ip;
      &resetfields();
    }
    if (($type eq "D") && ($selection eq "y")) {
      $PURPOSE = "DELETE $domainname";
      print "\nAre you SURE you want to do this? [y,n]: ";
      $choice = <STDIN>; chop($choice);
      if($choice eq "y") {
        &sendform("delete");
      }
      else {
        print "whew...aborting.\n";
      }
    }
    if($selection eq "n") {
      print "Changes ignored...\n";
      if ($type eq "N") {
        $ns1name = $defaultNS1name; $ns1ip = $defaultNS1ip;
        $ns2name = $defaultNS2name; $ns2ip = $defaultNS2ip;
        &resetfields();
      }
    }
  }
}

sub sendform {
  open(FORM,">/tmp/.form.$$");
  select(FORM);
  print "Domain Version Number 2.0\n\n";
  print "**************** Please see attached detailed instructions *****************\n\n";
  print "******** Only for registrations under ROOT, EDU, GOV, COM, NET, ORG ********\n\n";
  if(@_[0] eq "modify") {
    print "0.   (N)ew (M)odify (D)elete..: M\n\n";
  }
  if(@_[0] eq "new") {
    print "0.   (N)ew (M)odify (D)elete..: N\n\n";
  }
  if(@_[0] eq "delete") {
    print "0.   (N)ew (M)odify (D)elete..: D\n\n";
  }
  print "1.   Purpose/Description........: $PURPOSE\n\n";
  print "2.   Complete Domain Name.......: $domainname\n\n";
  print "Organization Using Domain Name\n";
  print "3a.  Organization name..........: $orgname\n";
  print "3b.  Street address.............: $street\n";
  print "3c.  City.......................: $city\n";
  print "3d.  State......................: $state\n";
  print "3e.  Postal Code................: $zipcode\n";
  print "3f.  Country....................: $country\n\n";
  print "Administrative Contact\n";
  print "4a.  NIC Handle (if known)......: $adminNIC\n";
  print "4b.  Name (Last, First).........: $adminlastname $adminfirstname\n";
  print "4c.  Organization Name..........: $adminorgname\n";
  print "4d.  Street Address.............: $adminstreet\n";
  print "4e.  City.......................: $admincity\n";
  print "4f.  State......................: $adminstate\n";
  print "4g.  Postal Code................: $adminzipcode\n";
  print "4h.  Country....................: $admincountry\n";
  print "4i.  Phone Number...............: $adminphone\n";
  print "4j.  E-Mailbox..................: $adminemail\n\n";
  print "Technical Contact\n";
  print "5a.  NIC Handle (if known)......: $techNIC\n";
  print "5b.  Name (Last, First).........: $techlastname $techfirstname\n";
  print "5c.  Organization Name..........: $techorgname\n";
  print "5d.  Street Address.............: $techstreet\n";
  print "5e.  City.......................: $techcity\n";
  print "5f.  State......................: $techstate\n";
  print "5g.  Postal Code................: $techzipcode\n";
  print "5h.  Country....................: $techcountry\n";
  print "5i.  Phone Number...............: $techphone\n";
  print "5j.  E-Mailbox..................: $techemail\n\n";
  print "Billing Contact\n";
  print "6a.  NIC Handle (if known)......: $billingNIC\n";
  print "6b.  Name (Last, First).........: $billinglastname $billingfirstname\n";
  print "6c.  Organization Name..........: $billingorgname\n";
  print "6d.  Street Address.............: $billingstreet\n";
  print "6e.  City.......................: $billingcity\n";
  print "6f.  State......................: $billingstate\n";
  print "6g.  Postal Code................: $billingzipcode\n";
  print "6h.  Country....................: $billingcountry\n";
  print "6i.  Phone Number...............: $billingphone\n";
  print "6j.  E-Mailbox..................: $billingemail\n\n";
  print "Primary Name Server\n";
  print "7a.  Primary Server Hostname....: $ns1name\n";
  print "7b.  Primary Server Netaddress..: $ns1ip\n\n";
  print "Secondary Name Server(s)\n";
  print "8a.  Secondary Server Hostname..: $ns2name\n";
  print "8b.  Secondary Server Netaddress: $ns2ip\n\n";
  print "Invoice Delivery\n";
  print "9.   (E)mail (P)ostal...........: $delivery\n";
  close(FORM);
  select(STDOUT);
  print "\nMailing form to Internic, please wait...\n";
  if($type eq "M") {
    system("$mailer -s \"MODIFY DOMAIN $domainname\" hostmaster@internic.net < /tmp/.form.$$");
  }
  if($type eq "N") {
    system("$mailer -s \"NEW DOMAIN $domainname\" hostmaster@internic.net < /tmp/.form.$$");
  }
  if($type eq "D") {
    system("$mailer -s \"DELETE DOMAIN $domainname\" hostmaster@internic.net < /tmp/.form.$$");
  }
  system("rm /tmp/.form.$$");
  print "Form sent...done.\n";
}

sub check_fields {
  if($domainname eq "")  {
    print "Domain Name is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($orgname eq "")  {
    print "Organization Name is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($street eq "")  {
    print "Organization address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($city eq "")  {
    print "City information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($state eq "")  {
    print "State information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($zipcode eq "")  {
    print "Zipcode is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($country eq "")  {
    print "Country is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($ns1name eq "")  {
    print "Primary nameserver hostname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($ns1ip eq "")  {
    print "Primary nameserver IP address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($ns2name eq "")  {
    print "Secondary nameserver hostname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($ns2ip eq "")  {
    print "Secondary nameserver IP address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminNIC eq "")  {
    print "Administrative contact's NIC handle is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminlastname eq "")  {
    print "Administrative contact's lastname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminfirstname eq "")  {
    print "Administrative contact's firstname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminorgname eq "")  {
    print "Administrative contact's Organization name is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminstreet eq "")  {
    print "Administrative contact's street address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($admincity eq "")  {
    print "Administrative contact's city information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminstate eq "")  {
    print "Administrative contact's state information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminzipcode eq "")  {
    print "Administrative contact's zipcode is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($admincountry eq "")  {
    print "Administrative contact's country is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminphone eq "")  {
    print "Administrative contact's NIC phone number is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($adminemail eq "")  {
    print "Administrative contact's E-Mailbox is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techNIC eq "")  {
    print "Technical contact's NIC handle is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techlastname eq "")  {
    print "Technical contact's lastname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techfirstname eq "")  {
    print "Technical contact's firstname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techorgname eq "")  {
    print "Technical contact's Organization name is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techstreet eq "")  {
    print "Technical contact's street address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techcity eq "")  {
    print "Technical contact's city information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techstate eq "")  {
    print "Technical contact's state information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techzipcode eq "")  {
    print "Technical contact's zipcode is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techcountry eq "")  {
    print "Technical contact's country is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techphone eq "")  {
    print "Technical contact's NIC phone number is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($techemail eq "")  {
    print "Technical contact's E-Mailbox is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingNIC eq "")  {
    print "Billing contact's NIC handle is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billinglastname eq "")  {
    print "Billing contact's lastname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingfirstname eq "")  {
    print "Billing contact's firstname is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingorgname eq "")  {
    print "Billing contact's Organization name is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingstreet eq "")  {
    print "Billing contact's street address is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingcity eq "")  {
    print "Billing contact's city information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingstate eq "")  {
    print "Billing contact's state information is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingzipcode eq "")  {
    print "Billing contact's zipcode is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingcountry eq "")  {
    print "Billing contact's country is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingphone eq "")  {
    print "Billing contact's NIC phone number is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }

  if($billingemail eq "")  {
    print "Billing contact's E-Mailbox is empty! [hit enter]\n";
    $temp = <STDIN>; 
    return(2);
  }
}
