Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r708 r709 3707 3707 my $self = shift; 3708 3708 my $dbh = $self->{dbh}; 3709 my $grp = shift; 3710 my $shdesc = shift; 3711 my $comments = shift; 3712 my $iplist = shift; 3709 my %args = @_; 3710 3711 my $grp = $args{group}; 3712 my $shdesc = $args{desc}; 3713 my $comments = $args{comments}; 3714 my $iplist = $args{iplist}; 3713 3715 3714 3716 # $shdesc gets set to the generated location ID if possible, but these can be de-undefined here. … … 3716 3718 $iplist = '' if !$iplist; 3717 3719 3718 my $loc; 3720 # allow requesting a specific location entry. 3721 my $loc = $args{loc}; 3719 3722 3720 3723 # Generate a location ID. This is, by spec, a two-character widget. We'll use [a-z][a-z] 3721 3724 # for now; 676 locations should satisfy all but the largest of the huge networks. 3722 # Not sure whether these are case-sensitive, or what other rules might apply - in any case 3723 # the absolute maximum is 16K (256*256) since it's parsed by tinydns as a two-character field. 3724 3725 # and just to be as clear as possible; as per http://cr.yp.to/djbdns/tinydns-data.html: 3725 3726 # just to be as clear as possible; as per http://cr.yp.to/djbdns/tinydns-data.html: 3726 3727 3727 3728 #For versions 1.04 and above: You may include a client location on each line. The line is ignored for clients … … 3732 3733 #means that IP addresses starting with ipprefix are in location lo. lo is a sequence of one or two ASCII letters. 3733 3734 3734 # so locations could probably include both upper and lower case.3735 # this has been confirmed by experiment; locations "lo", "Lo", and "lO" are all distinct. 3735 3736 3736 3737 # add just after "my $origloc = $loc;": … … 3754 3755 eval { 3755 3756 # Get the "last" location. Note this is the only use for loc_id, because selecting on location Does Funky Things 3756 ($loc) = $dbh->selectrow_array("SELECT location FROM locations ORDER BY loc_id DESC LIMIT 1"); 3757 ($loc) = ($loc =~ /^(..)/) if $loc; 3758 my $origloc = $loc; 3759 $loc = 'aa' if !$loc; 3757 my ($newloc) = $dbh->selectrow_array("SELECT location FROM locations ORDER BY loc_id DESC LIMIT 1"); 3758 3759 no warnings qw(uninitialized); 3760 3761 my $ecnt = $dbh->prepare("SELECT count(*) FROM locations WHERE location LIKE ?"); 3762 3763 if ($loc) { 3764 $ecnt->execute($loc); 3765 if (($ecnt->fetchrow_array())[0]) { 3766 # too bad, so sad, requested location is unavailable. 3767 ##fixme: known failure case: caller requests a location ID that is not two characters. 3768 die "Requested location is already defined\n" if $args{reqonly}; 3769 # fall back to autoincrement 3770 } 3771 $newloc = $loc; 3772 } 3773 3774 # Either the requested location ID is unavailable and the caller isn't too attached 3775 # to it, OR, the caller hasn't specified a location ID. (The second case should be 3776 # far more common.) Find the "next available" location identifier. 3777 3778 ($newloc) = ($newloc =~ /^(..)/) if $newloc; 3779 my $origloc = $newloc; 3780 $newloc = 'aa' if !$newloc; 3760 3781 # Make a change... 3761 $loc++;3762 3782 # ... and keep changing if it exists 3763 while ($dbh->selectrow_array("SELECT count(*) FROM locations WHERE location LIKE ?", undef, ($ loc.'%'))) {3764 $ loc++;3765 ($ loc) = ($loc =~ /^(..)/);3766 die "too many locations in use, can't add another one\n" if $ loc eq $origloc;3783 while ($dbh->selectrow_array("SELECT count(*) FROM locations WHERE location LIKE ?", undef, ($newloc.'%'))) { 3784 $newloc++; 3785 ($newloc) = ($newloc =~ /^(..)/); 3786 die "too many locations in use, can't add another one\n" if $newloc eq $origloc; 3767 3787 ##fixme: really need to handle this case faster somehow 3768 3788 #if $loc eq $origloc die "<thwap> bad admin: all locations used, your network is too fragmented"; 3769 3789 } 3770 # And now we should have a unique location. tinydns fundamentally limits the 3771 # number of these but there's no doc on what characters are valid. 3772 $shdesc = $loc if !$shdesc; 3790 # And now we should have a unique location. 3791 $shdesc = $newloc if !$shdesc; 3773 3792 $dbh->do("INSERT INTO locations (location, group_id, iplist, description, comments) VALUES (?,?,?,?,?)", 3774 undef, ($ loc, $grp, $iplist, $shdesc, $comments) );3793 undef, ($newloc, $grp, $iplist, $shdesc, $comments) ); 3775 3794 $self->_log(entry => "Added location ($shdesc, '$iplist')"); 3795 $loc = $newloc; 3776 3796 $dbh->commit; 3777 3797 }; -
trunk/dns.cgi
r706 r709 1525 1525 unless ($permissions{admin} || $permissions{location_create}); 1526 1526 1527 my ($code,$msg) = $dnsdb->addLoc($curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist}); 1527 my ($code,$msg) = $dnsdb->addLoc(group => $curgroup, desc => $webvar{locname}, 1528 comments => $webvar{comments}, iplist => $webvar{iplist}); 1528 1529 1529 1530 if ($code eq 'OK' || $code eq 'WARN') {
Note:
See TracChangeset
for help on using the changeset viewer.