Changeset 375
- Timestamp:
- 08/08/12 18:04:47 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r372 r375 47 47 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 48 48 &getUserCount &getUserList &getUserDropdown 49 &addLoc &updateLoc &delLoc 49 &addLoc &updateLoc &delLoc &getLoc 50 50 &getLocCount &getLocList &getLocDropdown 51 51 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount … … 74 74 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 75 75 &getUserCount &getUserList &getUserDropdown 76 &addLoc &updateLoc &delLoc 76 &addLoc &updateLoc &delLoc &getLoc 77 77 &getLocCount &getLocList &getLocDropdown 78 78 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount … … 2895 2895 $sth->execute($uid); 2896 2896 return $sth->fetchrow_hashref(); 2897 2898 2897 } # end getUserData() 2899 2898 2900 2899 2901 2900 ## DNSDB::addLoc() 2902 sub addLoc {} 2901 # Add a new location. 2902 # Takes a database handle, group ID, short and long description, and a comma-separated 2903 # list of IP addresses. 2904 # Returns ('OK',<location>) on success, ('FAIL',<failmsg>) on failure 2905 sub addLoc { 2906 my $dbh = shift; 2907 my $grp = shift; 2908 my $shdesc = shift; 2909 my $comments = shift; 2910 my $iplist = shift; 2911 2912 # $shdesc gets set to the generated location ID if possible, but these can be de-undefined here. 2913 $comments = '' if !$comments; 2914 $iplist = '' if !$iplist; 2915 2916 my $loc; 2917 2918 # Generate a location ID. This is, by spec, a two-character widget. We'll use [a-z][a-z] 2919 # for now; 676 locations should satisfy all but the largest of the huge networks. 2920 # Not sure whether these are case-sensitive, or what other rules might apply - in any case 2921 # the absolute maximum is 16K (256*256) since it's parsed by tinydns as a two-character field. 2922 2923 # add just after "my $origloc = $loc;": 2924 # # These expand the possible space from 26^2 to 52^2 [* note in testing only 2052 were achieved], 2925 # # and wrap it around. 2926 # # Yes, they skip a couple of possibles. No, I don't care. 2927 # $loc = 'aA' if $loc eq 'zz'; 2928 # $loc = 'Aa' if $loc eq 'zZ'; 2929 # $loc = 'ZA' if $loc eq 'Zz'; 2930 # $loc = 'aa' if $loc eq 'ZZ'; 2931 2932 # Allow transactions, and raise an exception on errors so we can catch it later. 2933 # Use local to make sure these get "reset" properly on exiting this block 2934 local $dbh->{AutoCommit} = 0; 2935 local $dbh->{RaiseError} = 1; 2936 2937 ##fixme: There is probably a far better way to do this. Sequential increments 2938 # are marginally less stupid that pure random generation though, and the existence 2939 # check makes sure we don't stomp on an imported one. 2940 2941 eval { 2942 # Get the "last" location. Note this is the only use for loc_id, because selecting on location Does Funky Things 2943 ($loc) = $dbh->selectrow_array("SELECT location FROM locations ORDER BY loc_id DESC LIMIT 1"); 2944 ($loc) = ($loc =~ /^(..)/); 2945 my $origloc = $loc; 2946 # Make a change... 2947 $loc++; 2948 # ... and keep changing if it exists 2949 while ($dbh->selectrow_array("SELECT count(*) FROM locations WHERE location LIKE ?", undef, ($loc.'%'))) { 2950 $loc++; 2951 ($loc) = ($loc =~ /^(..)/); 2952 die "too many locations in use, can't add another one\n" if $loc eq $origloc; 2953 ##fixme: really need to handle this case faster somehow 2954 #if $loc eq $origloc die "<thwap> bad admin: all locations used, your network is too fragmented"; 2955 } 2956 # And now we should have a unique location. tinydns fundamentally limits the 2957 # number of these but there's no doc on what characters are valid. 2958 $shdesc = $loc if !$shdesc; 2959 $dbh->do("INSERT INTO locations (location, group_id, iplist, description, comments) VALUES (?,?,?,?,?)", 2960 undef, ($loc, $grp, $iplist, $shdesc, $comments) ); 2961 }; 2962 if ($@) { 2963 my $msg = $@; 2964 eval { $dbh->rollback; }; 2965 if ($config{log_failures}) { 2966 $shdesc = $loc if !$shdesc; 2967 _log($dbh, (entry => "Failed adding location ($shdesc, '$iplist'): $msg")); 2968 $dbh->commit; 2969 } 2970 return ('FAIL',$msg); 2971 } 2972 2973 return ('OK',$loc); 2974 } 2975 2903 2976 2904 2977 ## DNSDB::updateLoc() … … 2907 2980 ## DNSDB::delLoc() 2908 2981 sub delLoc {} 2982 2983 2984 ## DNSDB::getLoc() 2985 sub getLoc { 2986 my $dbh = shift; 2987 my $loc = shift; 2988 2989 my $sth = $dbh->prepare("SELECT group_id,iplist,description,comments FROM locations WHERE location=?"); 2990 $sth->execute($loc); 2991 return $sth->fetchrow_hashref(); 2992 } # end getLoc() 2909 2993 2910 2994 … … 4296 4380 my $lochash = $dbh->selectall_hashref("SELECT location,iplist FROM locations", 'location'); 4297 4381 foreach my $location (keys %$lochash) { 4298 foreach my $ipprefix (split /,/, $lochash->{$location}{iplist}) { 4382 foreach my $ipprefix (split /[,\s]+/, $lochash->{$location}{iplist}) { 4383 $ipprefix =~ s/\s+//g; 4299 4384 print $datafile "%$location:$ipprefix\n"; 4300 4385 } -
trunk/dns-1.0-1.2.sql
r372 r375 4 4 CREATE TABLE locations ( 5 5 location character varying (4) PRIMARY KEY, 6 loc_id serial UNIQUE, 6 7 group_id integer NOT NULL DEFAULT 1, 7 8 iplist text NOT NULL DEFAULT '', 8 description text NOT NULL DEFAULT '' 9 description character varying(40) NOT NULL DEFAULT '', 10 comments text NOT NULL DEFAULT '' 9 11 ); 10 12 -
trunk/dns.cgi
r374 r375 1368 1368 1369 1369 if ($webvar{locact} eq 'new') { 1370 1370 # uuhhmm.... 1371 1371 } elsif ($webvar{locact} eq 'add') { 1372 1372 changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid}) 1373 1373 unless ($permissions{admin} || $permissions{location_create}); 1374 1374 1375 ##work 1376 my ($code,$msg) = addLocation($dbh, $webvar{parentid}, $webvar{locname}, $webvar{iplist}); 1375 my ($code,$msg) = addLoc($dbh, $curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist}); 1377 1376 1378 1377 if ($code eq 'OK' || $code eq 'WARN') { … … 1388 1387 $page->param(todo => "Add location/view"); 1389 1388 $page->param(locact => "add"); 1390 $page->param(parentid => $webvar{parentid});1391 1389 $page->param(id => $webvar{id}); 1392 fill_recdata(); # populate the form... er, mostly. 1390 $page->param(locname => $webvar{locname}); 1391 $page->param(comments => $webvar{comments}); 1392 $page->param(iplist => $webvar{iplist}); 1393 1393 } 1394 1394 … … 1396 1396 changepage(page => "loclist", errmsg => "You are not permitted to edit locations/views", id => $webvar{parentid}) 1397 1397 unless ($permissions{admin} || $permissions{location_edit}); 1398 1399 my $loc = getLoc($dbh, $webvar{loc}); 1400 $page->param(wastrying => "adding"); 1401 $page->param(todo => "Edit location/view"); 1402 $page->param(locact => "update"); 1403 $page->param(id => $webvar{loc}); 1404 $page->param(locname => $loc->{description}); 1405 $page->param(comments => $loc->{comments}); 1406 $page->param(iplist => $loc->{iplist}); 1407 1398 1408 } elsif ($webvar{locact} eq 'update') { 1399 1409 changepage(page => "loclist", errmsg => "You are not permitted to edit locations/views", id => $webvar{parentid}) 1400 1410 unless ($permissions{admin} || $permissions{location_edit}); 1411 ##work 1401 1412 } else { 1402 1413 changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid}) … … 1405 1416 $page->param(todo => "Add location/view"); 1406 1417 $page->param(locact => "add"); 1407 $page->param(parentid => $webvar{parentid});1408 1409 1418 $page->param(locname => ($webvar{locname} ? $webvar{locname} : '')); 1410 1419 $page->param(iplist => ($webvar{iplist} ? $webvar{iplist} : '')); -
trunk/dns.sql
r370 r375 19 19 CREATE TABLE locations ( 20 20 location character varying (4) PRIMARY KEY, 21 loc_id serial UNIQUE, 21 22 group_id integer NOT NULL DEFAULT 1, 22 23 iplist text NOT NULL DEFAULT '', 23 description text NOT NULL DEFAULT '' 24 description character varying(40) NOT NULL DEFAULT '', 25 comments text NOT NULL DEFAULT '' 24 26 ); 25 27 -
trunk/templates/location.tmpl
r374 r375 14 14 <input type="hidden" name="page" value="location" /> 15 15 <input type="hidden" name="sid" value="<TMPL_VAR NAME=sid>" /> 16 <input type="hidden" name="parentid" value="<TMPL_VAR NAME=parentid>" /> 17 <input type="hidden" name="id" value="<TMPL_VAR NAME=id>" /> 16 <TMPL_IF id><input type="hidden" name="id" value="<TMPL_VAR NAME=id>" /></TMPL_IF> 18 17 <input type="hidden" name="locact" value="<TMPL_VAR NAME=locact>" /> 19 18 … … 26 25 <tr class="datalinelight"> 27 26 <td>Location name/description</td> 28 <td><input type="text" name="locname" value="<TMPL_VAR ESCAPE=HTML NAME=locname>" size="30" /></td>27 <td><input type="text" name="locname" value="<TMPL_VAR ESCAPE=HTML NAME=locname>" size="30" maxlength="40" /></td> 29 28 </tr> 30 29 <tr class="datalinelight"> 31 30 <td>IP list</td> 32 31 <td><input type="text" name="iplist" value="<TMPL_VAR ESCAPE=HTML NAME=iplist>" size="30" /></td> 32 </tr> 33 <tr class="datalinelight"> 34 <td>Comments</td> 35 <td><textarea name="comments" cols="50" rows="5"><TMPL_VAR ESCAPE=HTML NAME=comments></textarea></td> 33 36 </tr> 34 37 <tr class="datalinelight"> -
trunk/tiny-import.pl
r373 r375 525 525 if (my ($iplist) = $dbh->selectrow_array("SELECT iplist FROM locations WHERE location = ?", undef, ($loc))) { 526 526 if ($cnet) { 527 $iplist .= ", $cnet";527 $iplist .= ", $cnet"; 528 528 $dbh->do("UPDATE locations SET iplist = ? WHERE location = ?", undef, ($iplist, $loc)); 529 529 } else {
Note:
See TracChangeset
for help on using the changeset viewer.