Re: NetReg: Limiting machines on NetReg

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

From: Allie M Tate (allie@lsu.edu)
Date: Thu Aug 08 2002 - 09:20:21 CDT


I did the same thing for our dorms, expect they are limited to three. This
is probably very specific to my environment because we have separate
subnets for the students. I added an array for containing the student
subnets and an array containing any user id excluded from this rule that
may be in that subnet (used for labs who use a generic id - they must be
allowed more than three registrations). I hope this helps. This is the
entire uniqueHostname routine. I marked my entries with **.

sub uniqueHostname {
# first (only) argument is the specified hostname
    my ($y,$ip) = @_;
    @ip = split(/\./,$ip);

    my $found = 0;
    my @theNames;

    my $thisHost = "";
    my $thisName = "";
    my $temp = "";

**# find out if this is coming from a student subnet - only allow 3
ip's/student
** foreach $exception (@LABIDS){
** $skip = 1 if $y =~ /$exception/;
** }
** if ($skip != 1) {
** foreach $subnet (@STUDENTS){
** $student = 1 if @ip[2] eq $subnet;
** }
** }

# extract all host names from dhcpd.common.new
   open (DHCPDCONFNEW, "$DHCPDCONFPATH/dhcpd.common.new");
   while (<DHCPDCONFNEW>) {
        if ($_ =~ /^host\s+([\w\-]+)\s+{/)
        {
          $temp = $1;
          # grab any hostname that begins with the hostname $y
          if ($temp =~/^$y.*/) {
            push (@theNames, $temp);
          }
        }
    }
    close DHCPDCONFNEW;

# @theNames now contains hostnames from dhcpd.common.new that contain the
specified hostnames
# or it is empty
    if ($#theNames == -1)
        {
        # if the array is empty, then no names were found, $y is unique,
return it
        return $y;
        }
** elsif ($#theNames >= 2 && $student == 1)
** {
** error("You are already registered for three MAC addresses. You
have reached your limit. You must call the Helpdesk
** (8-3375) to have one removed before you are allowed to register this
machine.<br>"); }
    else
        {
        # search the names for an exact match
        my $found = 0;
        foreach $thisName (@theNames) {
           if ($thisName eq $y) {
             $found = 1;
           }
        }
        if (!$found) {
           # this exact hostname wasn't found, so it must be unique
           return $y;
        }
        else{
          $found =1;
          my $j = 1;
          SEARCH: while ($found) {
          # this is the numerical extension to append to a hostname to make
it unique
           $j++;
           $theUniqueName = $y . "-" . $j;
           $found = 0;
           # check to see if our newly constructed hostname is unique
           foreach $thisName (@theNames){
                if ($thisName eq $theUniqueName) {
                   $found = 1;
                   next SEARCH;
                }
          }
      }
        # if we made it here, we got a unique name, return it
        return $theUniqueName;
    }
  }
} # uniqueHostname

                                                                                                                                   
                    Rebecca Irvin
                    <rirvin@mail.lesley To: netreg@southwestern.edu
                    .edu> cc: (bcc: Allie M Tate/allie/LSU)
                    Sent by: Subject: NetReg: Limiting machines on NetReg
                    owner-netreg@southw
                    estern.edu
                                                                                                                                   
                                                                                                                                   
                    08/07/2002 12:06 PM
                    Please respond to
                    netreg
                                                                                                                                   
                                                                                                                                   

we're getting ready to roll NetReg out to the student populace next month,
and have so far found that it works great!

However, we'd really like to limit our students to one computer per student
registered. I was wondering if anyone had already come up with an elegant
(or just plain workable) script to do this yet?

I prefer not to have to reinvent the wheel when I can avoid it.

Thanks!
Rebecca Irvin
Residence Networking
Lesley University

**********************************************************************
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
**********************************************************************

**********************************************************************
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:37 CDT