RE: NetReg: Possible NetReg 1.3rc2 bug + suggestions..

New Message Reply Date view Thread view Subject view Author view Attachment view

From: Patrick Jaques (pjaques@attbi.com)
Date: Mon May 19 2003 - 14:11:35 CDT


Hi Nathan,

Interesting code. I have wanted for some time to be able to add fixed
addresses through the NetReg system. I found a problem in your code that
checks for a duplicate fixed address in dhcpd.conf.new. The below code from
subroutine "add_reserv()" does not correctly match fixed addresses in
dhcpdconf.new. For example, when a fixed address of 192.168.0.2 is entered
in the form, it will also match 192.168.0.20 and 192.168.0.200 in the
dhcpd.conf.new file.

        if (($FORM{'ip_addy'} ne "") && ($_ =~ $FORM{'ip_addy'})) {
                printf "$FORM{'ip_addy'} Already Exists in DHCPD.CONF.NEW!";
              exit;
        }

This can be fixed by adding a "fixed-address" statement in the patern match.
For example:

        if (($FORM{'ip_addy'} ne "") && ($_ =~ /fixed-address
$FORM{'ip_addy'}/)) {
                printf "$FORM{'ip_addy'} Already Exists in DHCPD.CONF.NEW!";
              exit;
        }

The original code (NetReg 1.3rc2) in admin.cgi will need additional code
modifications to display fixed addresses added by add_reserv(). While you
can find fixed addresses by the "Find MAC" or the "Find User" routines, it
only display the User, MAC Address, Platform and Registration Timestamp. It
doesn't display the IP Address associated with the fixed address.
Additionally, entering a MAC address should be validated. By mistake, I
entered an invalid MAC address in the Static IP Reservation/Registration
form. This prevented any additional changes to dhcpd.conf from being
activated until the entry with the invalid hardware address (MAC) was
removed from the dhcpd.conf.new file. I am wondering why the
refresh-dhcpdconf script does not restore the dhcpd.conf.new file back to
its original state when an error occurrs like it does with the dhcpd.conf
file?

If anyone has a solution to make this work, it would add a cool feature to
NetReg 1.3rc2.

-- Patrick

----- File: admin.cgi -----

#---------------------------------------------------------------------------
-\
# Main Function
#---------------------------------------------------------------------------
-\
  get_input();
  print_header();
  if ($FORM{'action'} eq "SM") { server_manager(); }
  elsif ($FORM{'action'} eq "FC") { find_conf(); }
  elsif ($FORM{'action'} eq "FL") { find_lease(); }
  elsif ($FORM{'action'} eq "SO") { subnet_overview(); }
  elsif ($FORM{'action'} eq "VS") { view_subnet(); }
#---- added form action AR to call our add reserv function
  elsif ($FORM{'action'} eq "AR") { add_reserv(); }
#---- there also has to be a link somewhere with action set to AR
  elsif (!$FORM{'action'}) { subnet_overview(); }
  print_footer();
#---------------------------------------------------------------------------
-/

also, somewhere in your page you need to make a link that will call the
admin script with action=AR, so yo might add a line like this printf "<A
HREF=$ADMINPATH/admin.cgi?action=AR><b> Add Reservation(s)</A><P>"; to one
of your subroutines.. perhapse print_header or print_footer.. it all depends
on where you want the link to show up..

#-------------SMU-----------------------------------------------------------
\
# inserts a "reservation" record (originally written for 1.2)
#-------------SMU-----------------------------------------------------------
\
  sub add_reserv {
    if (($FORM{'host_name'}) && ($FORM{'mac_addy'}) && ($FORM{'platform'}))
{
    #User entered host name, mac address, and platform note, check info and
    #add the record (modified from register.cgi::append_host_entry())
      ($SEC,$MIN,$HOUR,$DAY,$MO,$YR) = localtime;
      $YR+=1900; $MO++;
      if ($DAY<10) { $DAY="0$DAY"; }
      if ($MO<10) { $MO="0$MO"; }
      if ($HOUR<10) { $HOUR="0$HOUR"; }
      if ($MIN<10) { $MIN="0$MIN"; }
      if ($SEC<10) { $SEC="0$SEC"; }
      $TIME="$HOUR:$MIN:$SEC";
      #check if MAC_ADDY is already registered
      open (DHCPDCONFNEW, "$DHCPDCONFPATH/dhcpd.conf.new");
      while (<DHCPDCONFNEW>) {
             if ($_ =~ /$FORM{'mac_addy'}/) {
                printf "$FORM{'mac_addy'} Already Exists in
DHCPD.CONF.NEW!";
                exit;
             }
             if ($_ =~ /$FORM{'host_name'}/) {
                printf "$FORM{'host_name'} Already Exists in
DHCPD.CONF.NEW!";
                exit;
             }
             if (($FORM{'ip_addy'} ne "") && ($_ =~ $FORM{'ip_addy'})) {
                printf "$FORM{'ip_addy'} Already Exists in DHCPD.CONF.NEW!";
                exit;
             }
      }
      close(DHCPDCONFNEW);
      open(LEASES, "$LEASESPATH/dhcpd.leases");
      while (<LEASES>) {
              if (($FORM{'ip_addy'} ne "") && ($_ =~ $FORM{'ip_addy'})) {
                 printf "$FORM{'ip_addy'} Already Exists in DHCPD.LEASES!";
                 exit;
              }
      }
      close(LEASES);
      $_ = $FORM{'host_name'} ;
      tr/'//d;
      $GOODHOSTNAME = $_;
      open (DHCPDCONFNEW, ">>$DHCPDCONFPATH/dhcpd.conf.new");
      print DHCPDCONFNEW "host $GOODHOSTNAME { hardware ethernet ";
      print DHCPDCONFNEW "$FORM{'mac_addy'} \; ";
      if ($FORM{'ip_addy'} ne "") {
             print DHCPDCONFNEW "fixed-address $FORM{'ip_addy'} \; ";
      }
      print DHCPDCONFNEW "}\#$FORM{'platform'}";
      print DHCPDCONFNEW "\#$YR$MO$DAY $TIME\n";
      close(DHCPDCONFNEW);
      printf "$FORM{'host_name'} $FORM{'mac_addy'} $FORM{'ip_addy'}";
    }
    else {
    #no form data entered, print the entry form
      printf "<form method=get action=$ADMINPATH/admin.cgi>";
      printf "<input type=hidden name=action value=AR>";
      printf "<ul><b> Enter information for Static IP
Reservation/Registration without an IP Address</b><p>";
      printf "<pre>";
      printf " Hostname: <input type=text name=host_name><P>";
      printf "Mac Address: <input type=text name=mac_addy><P>";
      printf " IP Address: <input type=text name=ip_addy><P>";
      printf "Description: <input type=text name=platform><P>";
      printf "</pre></ul>";
      printf "<input type=submit>";
    }
  }
#-------------SMU-----------------------------------------------------------
/

**********************************************************************
To unsubscribe from this list, send an e-mail message to
majordomo@southwestern.edu containing a single line with the words:
unsubscribe netreg
Send requests for assistance to: owner-netreg@southwestern.edu
**********************************************************************


New Message Reply Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.4 : Thu Aug 12 2004 - 12:01:39 CDT