diff -c ./freeipdb-0_1_3/CHANGES.TXT ./FreeIPdb-0_1_4/CHANGES.TXT *** ./freeipdb-0_1_3/CHANGES.TXT Sun Dec 16 22:16:48 2001 --- ./FreeIPdb-0_1_4/CHANGES.TXT Sat Mar 30 01:54:28 2002 *************** *** 4,10 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### --- 4,10 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # CHANGES.TXT-$Name: $-$Revision: 1.7 $ $Date: 2002/03/28 05:24:49 $ <$Author: bapril $@freeipdb.org> ###################################################################### *************** *** 32,34 **** --- 32,46 ---- -The Search function can now look for addresses that are not on bit-boundaries. -The Admin page is more verbose. -Fixed some bugs in search.cgi + 0_1_4 + -Piles of bug-fixes. + -Added report.pl + -Display DNS in search. + -Add option to toggle DNS zones on and off. + -Reclaim stops at region boundies. + -Change "= NULL" to "IS NULL" [ Martin Richard ] + -Patch from Stojan Rancic + -Dave Burke \H fix. + -Montgomery Newcom DBI::err fix + -Added import tool. + -Hostnames are now searchable. Only in ./freeipdb-0_1_3: Data_Types.txt diff -c ./freeipdb-0_1_3/INSTALL.TXT ./FreeIPdb-0_1_4/INSTALL.TXT *** ./freeipdb-0_1_3/INSTALL.TXT Sun Dec 16 22:17:20 2001 --- ./FreeIPdb-0_1_4/INSTALL.TXT Sat Mar 30 01:54:09 2002 *************** *** 4,10 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### FreeIPdb Install --- 4,10 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # INSTALL.TXT-$Name: $-$Revision: 1.11 $ $Date: 2002/03/28 05:24:50 $ <$Author: bapril $@freeipdb.org> ###################################################################### FreeIPdb Install *************** *** 13,28 **** It's best to do this in cgi-bin area you want the cgi portion to run from (e.g. /usr/local/httpd/cgi-bin/) ! tar -zxvf freeipdb-0_1_2.tar.gz ! cd freeipdb-0_1_2 or ! gzip -d freeipdb-0_1_2.tar.gz ! tar -xvf freeipdb-0_1_2.tar ! cd freeipdb-0_1_2 ! You may want to consider at this point a sym-link from freeipdb- to freeipdb so in the future you can just re-point the sym-link once testing on the new version is finished. --- 13,28 ---- It's best to do this in cgi-bin area you want the cgi portion to run from (e.g. /usr/local/httpd/cgi-bin/) ! tar -zxvf FreeIPdb-0_1_4.tar.gz ! cd FreeIPdb-0_1_4 or ! gzip -d FreeIPdb-0_1_4.tar.gz ! tar -xvf FreeIPdb-0_1_4.tar ! cd FreeIPdb-0_1_4 ! You may want to consider at this point a sym-link from FreeIPdb- to freeipdb so in the future you can just re-point the sym-link once testing on the new version is finished. *************** *** 32,38 **** (here is one of them) /usr/local/pgsql/bin/createdb freeipdb ! cat Data_Types.txt | /usr/local/pgsql/bin/psql freeipdb -Set-up the config file. --- 32,48 ---- (here is one of them) /usr/local/pgsql/bin/createdb freeipdb ! /usr/local/pgsql/bin/createuser freeipdb ! (I answer no and no) ! cat SQL/Data_Types.txt | /usr/local/pgsql/bin/psql freeipdb ! ! If you would like to use the DNS features of FreeIPdb do: ! ! cat SQL/DNS.sql | /usr/local/pgsql/bin/psql freeipdb ! ! If you would like to use the Rwhois features of FreeIPdb do: ! ! cat SQL/Rwhois.sql | /usr/local/pgsql/bin/psql freeipdb -Set-up the config file. *************** *** 53,55 **** --- 63,101 ---- -Setup a cron job to run the ipdb_ck.pl script every so often. (Mine is once a day) + ---==== Notes about upgrades ====--- + From 0.1.4 or before: + I don't think there are any real changes. + + From 0.1.3 or before: + the zone_record_table needs to be dropped an rebuilt. + It was never really used before so it should have no data. + + The data in reverse_serial_table needs to move into zone_record_table + + + --- END CONVERT SCRIPT --- + #!/usr/local/bin/perl + use Pg; + use config; + use DBI; + %config = config::config(); + my $conn = DBI->connect("DBI:Pg:dbname=$config{dbname}; + host=$config{dbhost};port=$config{dbport}", + "$config{dbuser}", "$config{dbpass}",); + my $str = $conn->prepare("SELECT TEXT,BLOCK,ZONE,INDEX FROM REVERSE_SERIAL_TABLE"); + $str->execute; + if($str->err){my $err = $str->errstr;&IPDBError(-1,"Something went wrong.: $err"); } + while(@out = $str->fetchrow){ + $str2 = $conn->prepare("INSERT INTO ZONE_RECORD_TABLE + (HOSTNAME,ZONE,BLOCK,INDEX,TYPE) + VALUES ('$out[0]',$out[2],$out[1],$out[3],3)"); + $str2->execute; + if($str2->err){my $err = $str2->errstr;&IPDBError(-1,"Something went wrong.: $err");} + } + --- END CONVERT SCRIPT --- + + The REVERSE_SERIAL_TABLE and it's sequence can now be destroyed. + + From 0.1.2 or before: + Perl::DBI is now required. at this point PG:DBD is also required. diff -c ./freeipdb-0_1_3/README.TXT ./FreeIPdb-0_1_4/README.TXT *** ./freeipdb-0_1_3/README.TXT Sun Dec 16 22:17:27 2001 --- ./FreeIPdb-0_1_4/README.TXT Sat Mar 30 01:52:31 2002 *************** *** 4,10 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### 1 What is FreeIPdb? --- 4,10 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # README.TXT-$Name: $-$Revision: 1.8 $ $Date: 2002/02/04 05:27:22 $ <$Author: bapril $@freeipdb.org> ###################################################################### 1 What is FreeIPdb? *************** *** 177,183 **** [Submit Request]. You should get something like this: Your New BlockID is : 327 ! 10.0.23.208/28 from NorthAmerica Swipped=No To: 12333 IPv4 [Confirm Allocation] [Cancel Allocation] --- 177,183 ---- [Submit Request]. You should get something like this: Your New BlockID is : 327 ! 10.0.23.208/28 from NorthAmerica To: 12333 IPv4 [Confirm Allocation] [Cancel Allocation] *************** *** 203,208 **** --- 203,209 ---- is a flag set on that entry so that it will not be reused until the 10-days have elapsed. (You can use the admin.cgi page to manually assign that block if the customer wants it back.) + BTW the holdtime is an option in the config.pm file Thats is for now. Only in ./FreeIPdb-0_1_4: SQL diff -c ./freeipdb-0_1_3/TODO.TXT ./FreeIPdb-0_1_4/TODO.TXT *** ./freeipdb-0_1_3/TODO.TXT Sun Dec 16 22:17:36 2001 --- ./FreeIPdb-0_1_4/TODO.TXT Fri Mar 29 19:07:18 2002 *************** *** 4,29 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### 0.1-5- Write an API to get blocks for scripts. (serial IP's) 0.1-6- Reporting. 0.1-11- Rwhoisd... - 0.1-14- Add Forward DNS Functionality. 0.1-15- Add Sorts to the The Search Function 0.1-32- Oracle port. 0.1-33- Mysql port. - 0.1.2-37- Get report.pl ported over. 0.1.2-38- Check for correct BigNum-Int version. 0.1.2-41- Make admin functions report something useful. 0.1.2-44- in SearchResult if the result is free give option to assign it. - 0.1.2-53- add a dns-admin page to admin.cgi turn-zones on and off. 0.1.2-54- DNS needs to understnd regions. 0.1.2-56- CheckBlockFree Unint Value error. ! 0.1.2-58- under admin.cgi putting a block in a region is not recurssive. ---======== 0.1.3 ========--- [12-16-01] 0.1-7- Be sure we can have 2 regions with the same block. (e.g. 10.) 0.1.2-51- Error trying to reclaim a block. (seems to work but errors.) --- 4,96 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # TODO.TXT-$Name: $-$Revision: 1.32 $ $Date: 2002/03/30 02:07:18 $ <$Author: bapril $@freeipdb.org> ###################################################################### 0.1-5- Write an API to get blocks for scripts. (serial IP's) 0.1-6- Reporting. 0.1-11- Rwhoisd... 0.1-15- Add Sorts to the The Search Function 0.1-32- Oracle port. 0.1-33- Mysql port. 0.1.2-38- Check for correct BigNum-Int version. 0.1.2-41- Make admin functions report something useful. 0.1.2-44- in SearchResult if the result is free give option to assign it. 0.1.2-54- DNS needs to understnd regions. 0.1.2-56- CheckBlockFree Unint Value error. ! 0.1.2-58- under admin.cgi putting a block in a region is not recurssive.(Should be) ! 0.1.3-61- Make a more pretty error when there is no free-space in region. ! 0.1.3-66- Create an config(optional) limit on searches. ! 0.1.3-68- PostgreSQL triggers to prevent incorrect data in ipdb tables. ! 0.1.3-70- Build an interface to edit the records of a dns zone. ! 0.1.3-71- Add the MX type of DNS record. ! 0.1.3-72- Add the NS type of DNS record. ! 0.1.3-73- Add the HINFO type of DNS record. ! 0.1.3-74- Add the LOC type of DNS record. ! 0.1.3-75- Add the AAAA type of DNS record. ! 0.1.3-76- Add the CNAME type of DNS record. ! 0.1.3-77- Add secondarys to the dns config options. ! 0.1.3-78- Build a form for editing a Zone file. ! 0.1.3-89- Clean-up HTML formatting (View source should look nice.) ! 0.1.3-100- Allow for delete of RA ! 0.1.3-101- Allow for delete of Region ! ! ---======== 0.1.4 ========--- ! ! [03-29-02] ! 0.1.3-87- Make hostname a vaid search on the search page. ! 0.1.3-60- add hostname to search. ! 0.1.3-86- Add hostname search to the public search form. ! 0.1.3-103- Make config options work on search.cgi. ! 0.1.3-102- SQL tables need to "GRANT" on the ID_SEQ ! [03-27-02] ! 0.1.3-95- Fix bug in display of DNSTable ! 0.1.3-96- Fix Reverse DNS updating. ! 0.1.3-97- Add Import Tool. ! 0.1.3-98- Made the example IPv6 address more vauge ! 0.1.3-99- Montgomery Newcom err fix. ! [03-09-02] ! 0.1.3-94- Change "= NULL" to "IS NULL" [ Martin Richard ] ! http://www.postgresql.org/idocs/index.php?functions-comparison.html ! 0.1.3-93- Add Error checking to data-dump. ! 0.1.3-92- Add Some form of text output format. ! [02-20-02] ! 0.1.3-91- Added String check/clean-up for DNS addition. ! [02-19-02] ! 0.1.3-90- Patch from Stojan Rancic ! [02-03-02] ! 0.1.3-64- Allow delete of DNS Records. ! 0.1.3-88- Fixed &UtilRegion() in report.pl ! [02-01-02] ! 0.1.3-84- provide an option to require Customer Name ! 0.1.3-85- provide an option to require Customer Number ! 0.1.3-82- Fix bug in reclaim (anti region-traverse) ! [01-17-02] ! 0.1.3-83- Fix headder errors in Data_Types.txt ! 0.1.3-82- Dave Burke \H fix. ! [01-16-02] ! 0.1.3-79- Reclaim Needs to stop at region boundries. ! 0.1.3-81- Fix Search on cust and custdesc. ! [01-11-01] ! 0.1.3-80- Fix field naming in customer search. ! [01-08-02] ! 0.1.3-78- Fix Search.cgi bug. ! [01-01-02] ! 0.1.3-69- Make the calling of $str->errstr consistant. ! 0.1.2-53- add a dns-admin page to admin.cgi turn-zones on and off. ! [12-30-01] ! 0.1-14- Add Forward DNS Functionality. ! 0.1.3-67- Move All DNS records to the zone_record_table. (Anyone using the old table?) ! 0.1.3-65- Make DNS an option on config.pm. ! 0.1.3-63- Remove old SWIP code. ! [12-29-01] ! 0.1.3-59- List reverse DNS with blocks in search. ! [12-28-01] ! 0.1.2-37- Get report.pl ported over. ! 0.1.3-62- Fix big in &UtilDisplay() & &Addresses() ---======== 0.1.3 ========--- + [12-16-01] 0.1-7- Be sure we can have 2 regions with the same block. (e.g. 10.) 0.1.2-51- Error trying to reclaim a block. (seems to work but errors.) diff -c ./freeipdb-0_1_3/admin.cgi ./FreeIPdb-0_1_4/admin.cgi *** ./freeipdb-0_1_3/admin.cgi Sun Dec 16 22:17:39 2001 --- ./FreeIPdb-0_1_4/admin.cgi Fri Mar 29 19:44:50 2002 *************** *** 5,11 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### require 'ipdb_httpcgi.pl'; --- 5,11 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # admin.cgi-$Name: $-$Revision: 1.13 $ $Date: 2002/03/28 04:21:12 $ <$Author: bapril $@freeipdb.org> ###################################################################### require 'ipdb_httpcgi.pl'; *************** *** 50,56 **** } $FORM{NULL} = "NULL"; ! if($FORM{'FORM'} =~ /RECLAIM/){ #procede to reclaim &ReclaimBlock($conn,$FORM{'RECLAIM'}); --- 50,72 ---- } $FORM{NULL} = "NULL"; ! if($FORM{'FORM'} =~ /IMPORT/){ ! print "Importing IP Blocks
\n"; ! my @lines = split('\n',$FORM{'DATA'}); ! my $i = 0; ! while($lines[$i]){ ! my @line = split(':',$lines[$i]); ! my $ver = &VersionFromRegion($conn,$FORM{'REGION'}); ! my $added = &SetBlockP($conn,$line[0],$FORM{'REGION'},$line[1],$line[2],$line[3],$ver); ! if($added){ ! print "Line successfully added Block: $added\n
\n"; ! } else { ! print "Line Failed: $lines[$i]
\n"; ! } ! $i++; ! } ! } ! if($FORM{'FORM'} =~ /RECLAIM/){ #procede to reclaim &ReclaimBlock($conn,$FORM{'RECLAIM'}); *************** *** 98,109 **** } # Bail Missing some info. print ""; $ver = &VersionFromRegion($conn,$FORM{'REGION'}); ! my $id = SetBlockP($conn,$FORM{'BLOCK'},$FORM{'REGION'},$FORM{'BITS'},$FORM{'CUSTDESC'},1,$FORM{'CUSTOMER'},$ver); &SetRegion($conn,$id,$FORM{'REGION'}); if($id){ ! print "

Success Your block id $id<\H1>\n"; } else { ! print "

For some reason this request failed<\H1>\n"; } print ""; --- 114,125 ---- } # Bail Missing some info. print ""; $ver = &VersionFromRegion($conn,$FORM{'REGION'}); ! my $id = SetBlockP($conn,$FORM{'BLOCK'},$FORM{'REGION'},$FORM{'BITS'},$FORM{'CUSTDESC'},$FORM{'CUSTOMER'},$ver); &SetRegion($conn,$id,$FORM{'REGION'}); if($id){ ! print "

Success Your block id $id

\n"; } else { ! print "

For some reason this request failed

\n"; } print ""; *************** *** 162,168 **** exit(); } $ver = &Version($conn,$id); ! my $added = &SetBlockP($conn,$FORM{'BLOCK'},$FORM{'REGION_END'},$FORM{'BITS'},1,1,1,$ver); if($added){ print "A parent of that block exists.
\n"; &reclaim($conn,$added); --- 178,184 ---- exit(); } $ver = &Version($conn,$id); ! my $added = &SetBlockP($conn,$FORM{'BLOCK'},$FORM{'REGION_END'},$FORM{'BITS'},1,1,$ver); if($added){ print "A parent of that block exists.
\n"; &reclaim($conn,$added); *************** *** 226,232 ****
! Block(10.0.0.0 or 2001:0450:0000:0000:0000:0000:0000:0000)
Bits(0-32 or 0-128)
Region ! Block(10.0.0.0 or 0000:0000:0000:0000:0000:0000:0000:0000)
Bits(0-32 or 0-128)
Region + + Region:
+ Format:
+ ip address:netmask + EOF + if($config{custname}){ + print ":$config{custname_f}"; + } + if($config{custnum}){ + print ":$config{custnum_f}"; + } + + + print <
+ Parent is required to exist and be availiable. + + + EOF diff -c ./freeipdb-0_1_3/auto.cgi ./FreeIPdb-0_1_4/auto.cgi *** ./freeipdb-0_1_3/auto.cgi Sun Dec 16 22:17:43 2001 --- ./FreeIPdb-0_1_4/auto.cgi Fri Mar 29 19:44:50 2002 *************** *** 5,11 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### require 'ipdb_httpcgi.pl'; --- 5,11 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # auto.cgi-$Name: $-$Revision: 1.8 $ $Date: 2001/12/30 17:54:46 $ <$Author: bapril $@freeipdb.org> ###################################################################### require 'ipdb_httpcgi.pl'; *************** *** 38,44 **** if($FORM{'TYPE'} eq "SERIALREQ"){ #Get /30 from a serial region ! my $id = &GetNewBlock($conn,$FORM{'REGION'},30,'SERIAL-REQ',0,1); IncReverseSerial($conn1,$id); &SetSerialDNS($conn1,$id,$FORM{'CUST'},$FORM{'PORT'},$FORM{'ROUTER'}); } --- 38,44 ---- if($FORM{'TYPE'} eq "SERIALREQ"){ #Get /30 from a serial region ! my $id = &GetNewBlock($conn,$FORM{'REGION'},30,'SERIAL-REQ',1); IncReverseSerial($conn1,$id); &SetSerialDNS($conn1,$id,$FORM{'CUST'},$FORM{'PORT'},$FORM{'ROUTER'}); } diff -c ./freeipdb-0_1_3/config.pm.sample ./FreeIPdb-0_1_4/config.pm.sample *** ./freeipdb-0_1_3/config.pm.sample Sun Dec 16 22:17:50 2001 --- ./FreeIPdb-0_1_4/config.pm.sample Fri Mar 29 19:44:50 2002 *************** *** 4,10 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### --- 4,10 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # config.pm.sample-$Name: $-$Revision: 1.13 $ $Date: 2002/03/28 05:24:50 $ <$Author: bapril $@freeipdb.org> ###################################################################### *************** *** 29,42 **** $config{dnsinclude} = "config.file"; # Use Customer Name $config{custname} = 1; # Name of Customer Name filed $config{custname_f} = "Customer Name"; # Use Customer Num $config{custnum} = 1; # Name of Customer Number Field $config{custnum_f} = "Customer Number"; # Color of Header ! $config{headcolor} = "#33FFFF"; # Header Text color $config{headtextcolor} = "#000000"; # List alternating colors. --- 29,55 ---- $config{dnsinclude} = "config.file"; # Use Customer Name $config{custname} = 1; + # require value in Customer Name filed + $config{custname_r} = 1; # Name of Customer Name filed $config{custname_f} = "Customer Name"; # Use Customer Num $config{custnum} = 1; + # require value in Customer Number Field + $config{custnum_r} = 1; # Name of Customer Number Field $config{custnum_f} = "Customer Number"; + #Display DNS options + $config{allowDNS} = 1; + #Display Rwhois options + $config{allowRwhois} = 0; #Under development. + #require Rwhois on new blocks + $config{requireRwhois} = 0; #Under development. + #Allow Text Dump format tool + $config{allowDump} = 1; + # Color of Header ! $config{headcolor} = "#FF44AA"; # Header Text color $config{headtextcolor} = "#000000"; # List alternating colors. *************** *** 45,51 **** # Hold-time for reclaims $config{holdtime} = 864000; #10 days. ! $config{ver} = "FreeIPdb 0.1.3"; return(%config); } 1; --- 58,64 ---- # Hold-time for reclaims $config{holdtime} = 864000; #10 days. ! $config{ver} = "FreeIPdb 0.1.4"; return(%config); } 1; diff -c ./freeipdb-0_1_3/index.cgi ./FreeIPdb-0_1_4/index.cgi *** ./freeipdb-0_1_3/index.cgi Sun Dec 16 22:17:56 2001 --- ./FreeIPdb-0_1_4/index.cgi Fri Mar 29 19:44:50 2002 *************** *** 5,11 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### require 'ipdb_httpcgi.pl'; --- 5,11 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # index.cgi-$Name: $-$Revision: 1.20 $ $Date: 2002/03/10 03:11:04 $ <$Author: bapril $@freeipdb.org> ###################################################################### require 'ipdb_httpcgi.pl'; *************** *** 17,23 **** printHead("$config{ver}"); my $conn = DBI->connect("DBI:Pg:dbname=$config{dbname};host=$config{dbhost};port=$config{dbport}", "$config{dbuser}", "$config{dbpass}",); - my $script = get_cgi($0); my $buffer; my @pairs; --- 17,22 ---- *************** *** 35,40 **** --- 34,40 ---- $name =~ tr/+/ /; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; + $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $FORM{NULL} = "NULL"; *************** *** 44,52 **** if($FORM{'ACTION'} =~ m/RECLAIM/){ #procede to reclaim ! &ClearRevDNS($conn,$FORM{'RECLAIM'}); ! &ReclaimBlock($conn,$FORM{'RECLAIM'}); ! print "Reclaim Block $FORM{'RECLAIM'}\n
"; } if($FORM{'ACTION'} =~ /EDIT/){ &EditForm($conn,$FORM{'EDIT'},$script); --- 44,54 ---- if($FORM{'ACTION'} =~ m/RECLAIM/){ #procede to reclaim ! unless(&ClearRevDNS($conn,$FORM{'RECLAIM'})){ ! unless(&ReclaimBlock($conn,$FORM{'RECLAIM'})){ ! print "Reclaim Block $FORM{'RECLAIM'}\n
"; ! } ! } } if($FORM{'ACTION'} =~ /EDIT/){ &EditForm($conn,$FORM{'EDIT'},$script); *************** *** 70,83 **** } } if($FORM{'ACTION'} =~ /REQ/){ print < - -
Confirm New IP Block - Assignment
- EOF my $exit = ""; if($FORM{'REGION'} =~ /---/){ print "

Please go back and choose a REGION\n"; --- 72,128 ---- } } + if($FORM{'ACTION'} =~ /ZONEED/){ + foreach $form (keys(%FORM)){ + if($form =~ /ZONE\[(.*)\]/){ + &ToggleZone($conn,$1); + } + } + if($FORM{ZONEEDIT}){ + print "Edit Zone $FORM{ZONEEDIT}\n"; + } + $FORM{'ACTION'} = "ZONELIST"; + } + + if($FORM{'ACTION'} =~ /ZONELIST/){ + print "\n"; + &ZoneTable($conn,$script); + print "
\n"; + printTail(); + $conn->disconnect; + exit(); + } + + if($FORM{'ACTION'} =~ /DELETEDNS/){ + &DeleteDNSRecord($conn,$FORM{'ID'}); + print "DNS Record Deleted."; + } + + if($FORM{'ACTION'} =~ /DATADUMP/){ + $exit = 0; + if($FORM{BLOCK} =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\/([0-9]{1,2})/){ + $FORM{BLOCK} = $1; + $FORM{BITS} = $2; + } elsif ($FORM{BLOCK} =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/ && $FORM{BITS}){ + $FORM{BLOCK} = $1; + } else { + print "

Bad IP block format.\n"; + #exit = 1; + } + if($FORM{'REGION'} =~ /---/){ + print "

Must Select Region \n"; + $exit = 1; + } + if($exit){ print "";&printTail();$conn->disconnect;exit();} # Bail Missing some info. + &DataDump($conn,$FORM{BLOCK},$FORM{BITS},$FORM{'REGION'}); + exit(); + } + if($FORM{'ACTION'} =~ /REQ/){ print < EOF + my $exit = ""; if($FORM{'REGION'} =~ /---/){ print "

Please go back and choose a REGION\n"; *************** *** 91,105 **** print "

Can't Sethostname and request a block at the same time \n"; $exit = 1; } if($exit){ print "";&printTail();$conn->disconnect;exit();} # Bail Missing some info. print ""; ! my $ra = &GetRAFromRegion($conn,$FORM{'REGION'}); ! my $newblock = &GetNewBlock($conn,$FORM{'REGION'},$FORM{'BITS'},$FORM{'CUSTDESC'},$FORM{'SWIP'},$FORM{'CUSTOMER'}); ! my $ev = sprintf("&RA_%s_SUBMIT1(%d,%d,%d);",$ra,$FORM{'CUSTOMER'},$newblock,$FORM{'REGION'}); ! eval $ev; ! if($FORM{'REVERSE'}){ ! #Create Reverse Zone. ! } print "\n"; print "
"; print ""; --- 136,172 ---- print "

Can't Sethostname and request a block at the same time \n"; $exit = 1; } + if($config{custname_r} && $config{custname}){ + if(!$FORM{'CUSTDESC'}){ + print "

No $config{custname_f}\n"; + $exit = 1; + } + } + if($config{custnum_r} && $config{custnum}){ + if(!$FORM{'CUSTOMER'}){ + print "

No $config{custnum_f}\n"; + $exit = 1; + } + } + if($config{allowRwhois}){ + if($config{requireRwhois}){ + if(!$FORM{'NETNAME'}){ + print "

No NetName\n"; + $exit = 1; + } elsif (!$FORM{'ORG'}) { + print "Rwhois Form"; + #&RwhoisForm($conn,,$FORM{'NETNAME'}); + $exit = 1; + } + } + } if($exit){ print "";&printTail();$conn->disconnect;exit();} # Bail Missing some info. + print "\n"; + print ""; + print "
Confirm New IP Block Assignment
\n"; + print "\n"; print ""; ! my $newblock = &GetNewBlock($conn,$FORM{'REGION'},$FORM{'BITS'},$FORM{'CUSTDESC'},$FORM{'CUSTOMER'}); print "\n"; print ""; print ""; *************** *** 122,131 **** my $bits = $FORM{'BITS'}; my $cust = $FORM{'CUSTOMER'}; my $custdesc = $FORM{'CUSTDESC'}; my $id = ""; ! print "\n"; &AllocatedSearch_Head(); ! &AllocatedSearch($conn,$script,1,$id,$block,$bits,$region,$cust,$custdesc,1); print ""; printTail(); $conn->disconnect; --- 189,199 ---- my $bits = $FORM{'BITS'}; my $cust = $FORM{'CUSTOMER'}; my $custdesc = $FORM{'CUSTDESC'}; + my $hostname = $FORM{'HOSTNAME'}; my $id = ""; ! print "\n"; &AllocatedSearch_Head(); ! &AllocatedSearch($conn,$script,1,$id,$block,$bits,$region,$cust,$custdesc,$hostname,1); print ""; printTail(); $conn->disconnect; *************** *** 154,187 **** if($FORM{'ACTION'} =~ /SETDNS/){ # Check for hostname and an IP address. if($FORM{'BLOCK'} && $FORM{'HOSTNAME'} && ($FORM{'REGION'} !~ m/---/)){ print ""; - #@ip = split(/\./,$FORM{'BLOCK'}); - #$RevZoneName = "$ip[2].$ip[1].$ip[0].in-addr.arpa"; - #Get/Create the reverse ZONE ID: - #$RevZone = &GetZone($conn,$RevZoneName); $fqdn = $FORM{'HOSTNAME'}; $fqdn =~ m/^([0-9A-Za-z-]*)\.(.*)$/; $hostname = $1; $zone = $2; $ForZone = &GetZone($conn,$zone); #Get Block ID and Offset. $BLK = ip2deci($FORM{'BLOCK'}); @blk = &GetBlockIdNM($conn,$BLK,$FORM{'REGION'}); $block = $blk[0]; $index = $blk[1]; unless($block){ print "Block not allocated.(Can't assign DNS)"; } - #Set the reverse enrty. - if($FORM{DNSTYPE} eq "REV" || $FORM{DNSTYPE} eq "BOTH"){ - print "Set Reverse DNS for $FORM{'BLOCK'} to $hostname.$fqdn\n"; - &SetRevDNS($conn,$block,$ForZone,$index,$hostname); - &SetRevZone($conn,$FORM{'BLOCK'},$FORM{'REGION'}); - } - #Get/Create the Forward Block ID - #Set the forward entry. - print "
"; } else { print "

No IP address ,region or hostname set

\n"; --- 222,274 ---- if($FORM{'ACTION'} =~ /SETDNS/){ # Check for hostname and an IP address. + $exit = 0; + if($FORM{'HOSTNAME'} =~ m/[^A-Za-z0-9\.-]/){ + print "

Hostname contains invalid symbols.\n"; + $exit = 1; + } + if($exit){ print "";&printTail();$conn->disconnect;exit();} # Bail Missing some info. if($FORM{'BLOCK'} && $FORM{'HOSTNAME'} && ($FORM{'REGION'} !~ m/---/)){ print ""; $fqdn = $FORM{'HOSTNAME'}; $fqdn =~ m/^([0-9A-Za-z-]*)\.(.*)$/; $hostname = $1; + $hostname =~ s/[\/:_]/-/g; + $hostname =~ s/[ ]//g; + $hostname =~ s/--//g; + $hostname =~ s/^-//g; + $hostname =~ s/\.\././g; + $hostname =~ s/-\././g; $zone = $2; + $zone =~ s/[\/:_]/-/g; + $zone =~ s/[ ]//g; + $zone =~ s/--//g; + $zone =~ s/^-//g; + $zone =~ s/\.\././g; + $zone =~ s/-\././g; $ForZone = &GetZone($conn,$zone); #Get Block ID and Offset. $BLK = ip2deci($FORM{'BLOCK'}); @blk = &GetBlockIdNM($conn,$BLK,$FORM{'REGION'}); $block = $blk[0]; $index = $blk[1]; + unless($block){ print "Block not allocated.(Can't assign DNS)"; + } else { + #Set the reverse enrty. + if($FORM{DNSTYPE} eq "REV" || $FORM{DNSTYPE} eq "BOTH"){ + print "Set Reverse DNS for $FORM{'BLOCK'} to $fqdn
\n"; + &SetRevDNS($conn,$block,$ForZone,$index,$hostname); + &SetRevZone($conn,$FORM{'BLOCK'},$FORM{'REGION'}); + } + #Get/Create the Forward Block ID + #Set the forward entry. + if($FORM{DNSTYPE} eq "FWD" || $FORM{DNSTYPE} eq "BOTH"){ + print "Set Forward DNS for $FORM{'BLOCK'} to $fqdn
\n"; + &SetFwdDNS($conn,$block,$ForZone,$index,$hostname); + } } print "
"; } else { print "

No IP address ,region or hostname set

\n"; *************** *** 192,322 **** } print < ! ! !

! ! $config{ver} !

! ! ! ! ! !
!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! EOF if($config{custname}){ print < ! ! ! ! EOF } if($config{custnum}){ print < ! ! ! EOF } print < ! ! ! ! ! ! ! ! ! ! ! ! !
Block:
Subnet Mask: ! !
Region: !
$config{custname_f}:
$config{custnum_f}:
Hostname: Set :
Action:
!
!
!
! ! ! ! ! EOF &printTail; $conn->disconnect; --- 279,468 ---- } print < ! ! !

! ! $config{ver} !

! ! ! ! ! !
!
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! EOF if($config{custname}){ print < ! ! ! ! EOF } if($config{custnum}){ print < ! ! ! ! EOF ! } ! if($config{allowDNS}){ ! print < ! ! ! ! EOF ! } ! if($config{allowRwhois}){ ! print < ! ! ! ! EOF ! } ! print < ! ! ! ! ! ! !
! Block: ! ! !
! Subnet Mask: ! ! !
! Region: ! !
! $config{custname_f}: ! ! !
! $config{custnum_f}: ! ! !
! Hostname: ! ! ! Set : ! !
! Rhowis: ! ! Net-Name: !
! Action: ! !
!
!
!
! ! ! EOF &printTail; $conn->disconnect; diff -c ./freeipdb-0_1_3/ipdb_ck.pl ./FreeIPdb-0_1_4/ipdb_ck.pl *** ./freeipdb-0_1_3/ipdb_ck.pl Sun Dec 16 22:17:59 2001 --- ./FreeIPdb-0_1_4/ipdb_ck.pl Fri Mar 29 19:44:51 2002 *************** *** 5,11 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### --- 5,11 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # ipdb_ck.pl-$Name: $-$Revision: 1.10 $ $Date: 2002/03/10 03:53:58 $ <$Author: bapril $@freeipdb.org> ###################################################################### *************** *** 25,34 **** $now = time; $query = "SELECT ID,PARENT,REGION,BITS FROM IPDB ! WHERE ( HOLDTIME < $now OR HOLDTIME = NULL) ! AND ALLOCATED = NULL ! AND CHILDL = NULL ! AND (RECLAIM != 1 OR RECLAIM = NULL)"; my $str = $conn->prepare($query); my $num = $str->execute; $first = 0; --- 25,34 ---- $now = time; $query = "SELECT ID,PARENT,REGION,BITS FROM IPDB ! WHERE ( HOLDTIME < $now OR HOLDTIME IS NULL) ! AND ALLOCATED IS NULL ! AND CHILDL IS NULL ! AND (RECLAIM != 1 OR RECLAIM IS NULL)"; my $str = $conn->prepare($query); my $num = $str->execute; $first = 0; *************** *** 46,52 **** $PRTNS[$parent]++; if($PRTNS[$parent] == 2){ unless($first){print "reclaimed pairs that need to be cleared.\n";$first = 1;} ! print "ID $id - $FIRST[$parent] Cleared.\n"; demoblock($conn,$id) || &IPDBError(-1,"Could not demoblock"); demoblock($conn,$FIRST[$parent]) || &IPDBError(-1,"Could not demoblock #2"); clearblock($conn,$parent,1) || &IPDBError(-1,"Could not clearblock #3"); --- 46,52 ---- $PRTNS[$parent]++; if($PRTNS[$parent] == 2){ unless($first){print "reclaimed pairs that need to be cleared.\n";$first = 1;} ! print "ID $id - $FIRST[$parent] Cleared. $parent\n"; demoblock($conn,$id) || &IPDBError(-1,"Could not demoblock"); demoblock($conn,$FIRST[$parent]) || &IPDBError(-1,"Could not demoblock #2"); clearblock($conn,$parent,1) || &IPDBError(-1,"Could not clearblock #3"); *************** *** 61,68 **** $str = $conn->prepare("SELECT BLOCK,BITS,HOLDTIME FROM IPDB WHERE HOLDTIME > $now ! AND ALLOCATED = NULL ! AND CHILDL = NULL ORDER BY HOLDTIME"); $num = $str->execute; $first = 0; $i = 0; --- 61,68 ---- $str = $conn->prepare("SELECT BLOCK,BITS,HOLDTIME FROM IPDB WHERE HOLDTIME > $now ! AND ALLOCATED IS NULL ! AND CHILDL IS NULL ORDER BY HOLDTIME"); $num = $str->execute; $first = 0; $i = 0; *************** *** 90,96 **** } # Check for parents with only one child defined. ! $str = $conn->prepare("SELECT ID FROM IPDB WHERE (CHILDL = NULL AND CHILDR NOTNULL) OR (CHILDR = NULL AND CHILDL NOTNULL)"); $num = $str->execute; $i = 0; if($num){print "Blocks that have only one child:\n";} --- 90,96 ---- } # Check for parents with only one child defined. ! $str = $conn->prepare("SELECT ID FROM IPDB WHERE (CHILDL IS NULL AND CHILDR NOTNULL) OR (CHILDR IS NULL AND CHILDL NOTNULL)"); $num = $str->execute; $i = 0; if($num){print "Blocks that have only one child:\n";} *************** *** 99,104 **** --- 99,117 ---- print "\t$id\n"; $i++; } + + #Starting with the smallest block(s) + #Gen list of block and thei parrents. + #walk the list + #Query parent + #confirm children are truly related. + #confirm any siblings. + #Remove any ok siblings + #Add parents to the list of bits-- + # + # + #Incrament blocksize. + $str->finish; undef $str; $conn->disconnect; diff -c ./freeipdb-0_1_3/ipdb_httpcgi.pl ./FreeIPdb-0_1_4/ipdb_httpcgi.pl *** ./freeipdb-0_1_3/ipdb_httpcgi.pl Mon Dec 17 07:46:43 2001 --- ./FreeIPdb-0_1_4/ipdb_httpcgi.pl Sat Mar 30 01:50:09 2002 *************** *** 4,10 **** # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # FreeIPdb-0.1.3 12-16-2001 ###################################################################### require 'ipdb_lib.pl'; --- 4,10 ---- # | _|| | | __/ __/| || __/ (_| | |_) | # |_| |_| \___|\___|___|_| \__,_|_.__/ # ! # ipdb_httpcgi.pl-$Name: $-$Revision: 1.27 $ $Date: 2002/03/30 02:07:18 $ <$Author: bapril $@freeipdb.org> ###################################################################### require 'ipdb_lib.pl'; *************** *** 21,30 **** print < ! ! $title ! ! EOM } --- 21,30 ---- print < ! ! $title ! ! EOM } *************** *** 35,45 **** ###################################################################### sub printTail { print <<'EOF'; !
! FreeIPdb ! Copyright Benjamin D. April & Paul J. Benjes 2001 !
! EOF } --- 35,46 ---- ###################################################################### sub printTail { print <<'EOF'; !
! FreeIPdb ! Copyright Benjamin D. April & Paul J. Benjes 2001 !
! ! EOF } *************** *** 56,74 **** my $region = shift; my $bits = shift; my $CUSTDESC = shift; - my $SWIP = shift; my $CUST = shift; ! my $newblock = &NewBlock($conn,$region,$bits,$CUSTDESC,$SWIP,$CUST) || &IPDBError(-1,"Could not create Block"); ! print "Your New BlockID is : $newblock\n"; my $string = &ReadBlock($conn,$newblock); ! print "
$string
"; return($newblock); } sub ReclaimBlock(){ my $conn = shift; my $block = shift; ! &reclaim($conn,$block); } sub IP2Deci(){ --- 57,74 ---- my $region = shift; my $bits = shift; my $CUSTDESC = shift; my $CUST = shift; ! my $newblock = &NewBlock($conn,$region,$bits,$CUSTDESC,$CUST) || &IPDBError(-1,"Could not create Block"); ! print " Your New BlockID is : $newblock\n"; my $string = &ReadBlock($conn,$newblock); ! print "
$string
"; return($newblock); } sub ReclaimBlock(){ my $conn = shift; my $block = shift; ! return(&reclaim($conn,$block)); } sub IP2Deci(){ *************** *** 82,90 **** $query = "SELECT i.ID,i.BLOCK,i.BITS,r.name,r.v6,i.reclaim FROM IPDB i,REGIONTABLE r WHERE r.ID = i.REGION ! AND i.CHILDL = NULL ! AND CHILDR = NULL ! AND ALLOCATED = NULL ORDER BY r.name,bits"; my $str = $conn->prepare($query); my $num = $str->execute;; my $in = 0; --- 82,90 ---- $query = "SELECT i.ID,i.BLOCK,i.BITS,r.name,r.v6,i.reclaim FROM IPDB i,REGIONTABLE r WHERE r.ID = i.REGION ! AND i.CHILDL IS NULL ! AND CHILDR IS NULL ! AND ALLOCATED IS NULL ORDER BY r.name,bits"; my $str = $conn->prepare($query); my $num = $str->execute;; my $in = 0; *************** *** 142,147 **** --- 142,150 ---- my $block = shift; my $bits = shift; my $region = shift; + my $cust = shift; + my $custdesc = shift; + my $hostname = shift; my $toggle = shift; my $query = "SELECT ID FROM IPDB WHERE ID NOTNULL"; if($id){ *************** *** 152,157 **** --- 155,161 ---- if($region !~ m/---/){$query = $query." AND REGION = $region";} if($bits =~ m/^[0-9]+$/){$query = $query." AND BITS = $bits";} if($block){ $query = $query." AND BLOCK = ".$block."::NUMERIC(40,0) "; } + if($hostname){$query = $query." AND ZONE_RECORD_TABLE.hostname ~* '$hostname' AND ZONE_RECORD_TABLE.block = ID";} } $query = $query." ORDER BY BITS ASC"; print "\n"; *************** *** 185,192 **** my $childr = $out[6]; if(($block >= $start) && ($block <= $end)){ if($childl){ ! &RecBlockSearch($conn,$childl,$block,$bits,$class); ! &RecBlockSearch($conn,$childr,$block,$bits,$class); } else { $toggle = &SearchResult($conn,$id,$toggle,$script,$class); } --- 189,196 ---- my $childr = $out[6]; if(($block >= $start) && ($block <= $end)){ if($childl){ ! &RecBlockSearch($conn,$childl,$block,$bits,$script,$class); ! &RecBlockSearch($conn,$childr,$block,$bits,$script,$class); } else { $toggle = &SearchResult($conn,$id,$toggle,$script,$class); } *************** *** 200,205 **** --- 204,210 ---- my $id = shift; my $block = shift; my $bits = shift; + my $script = shift; my $class = shift; $query = "SELECT ID,BLOCK,BITS,REGION,ALLOCATED,CHILDL,CHILDR FROM IPDB WHERE ID = $id"; print "\n"; *************** *** 216,223 **** my $childr = $out[6]; if(($block >= $start) && ($block <= $end)){ if($childl){ ! &RecBlockSearch($conn,$childl,$block,$bits,$class); ! &RecBlockSearch($conn,$childr,$block,$bits,$class); } else { $toggle = &SearchResult($conn,$id,$toggle,$script,$class); } --- 221,228 ---- my $childr = $out[6]; if(($block >= $start) && ($block <= $end)){ if($childl){ ! &RecBlockSearch($conn,$childl,$block,$bits,$script,$class); ! &RecBlockSearch($conn,$childr,$block,$bits,$script,$class); } else { $toggle = &SearchResult($conn,$id,$toggle,$script,$class); } *************** *** 231,237 **** my $toggle = shift; my $script = shift; my $class = shift; ! $query = "SELECT BLOCK,BITS,REGION,ALLOCATED,CUSTNUM,CUSTDESC,CHILDL,CHILDR FROM IPDB WHERE ID = $id"; print "\n"; my $str = $conn->prepare($query); my $num = $str->execute; --- 236,242 ---- my $toggle = shift; my $script = shift; my $class = shift; ! $query = "SELECT BLOCK,BITS,REGION,ALLOCATED,CUSTDESC,CUSTNUM,CHILDL,CHILDR FROM IPDB WHERE ID = $id"; print "\n"; my $str = $conn->prepare($query); my $num = $str->execute; *************** *** 283,288 **** --- 288,296 ---- print " "; } print ""; + if($config{allowDNS} && &CheckDNS($conn,$id)){ + &DNSTable($conn,$id,$script); + } return($toggle); } *************** *** 345,351 **** my $ver = &Version($conn,$id); print "1"; $ip = deci2ip($block[0],$ver); ! my $added = &SetBlockP($conn,$ip,$region,$block[1],1,1,1,$ver); print "2"; if($added){ print "A parent of that block exists.
\n"; --- 353,359 ---- my $ver = &Version($conn,$id); print "1"; $ip = deci2ip($block[0],$ver); ! my $added = &SetBlockP($conn,$ip,$region,$block[1],1,1,$ver); print "2"; if($added){ print "A parent of that block exists.
\n"; *************** *** 368,381 **** $str = $conn->prepare("UPDATE IPDB SET CUSTDESC = '$custdesc' WHERE ID = $id"); $num = $str->execute(); if($str->err){ ! &IPDBError(-1,"Could not update block info in IPDB $str->errstr"); } } if($customer){ $str = $conn->prepare("UPDATE IPDB SET CUSTNUM = $customer WHERE ID = $id"); $num = $str->execute(); if($str->err){ ! &IPDBError(-1,"Could not update block info in IPDB $str->errstr"); } } } --- 376,391 ---- $str = $conn->prepare("UPDATE IPDB SET CUSTDESC = '$custdesc' WHERE ID = $id"); $num = $str->execute(); if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update block info in IPDB $err"); } } if($customer){ $str = $conn->prepare("UPDATE IPDB SET CUSTNUM = $customer WHERE ID = $id"); $num = $str->execute(); if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update block info in IPDB $err"); } } } *************** *** 392,431 **** print "Functions\n"; } - #----------------------------------------------------------------------------- - # UsedSpace() - # Takes: - # Database ID - # Customer ID - # Region ID - # Returns: - # Total number of allocated IP addresses - # - sub UsedSpace(){ - my $conn = shift; - my $cust = shift; - my $region = shift; - my $str = $conn->prepare("SELECT BITS FROM IPDB WHERE CUSTNUM = $cust AND REGION = $region"); - my $num = $str->execute; - my $i = 0; - my $long = 0; - my $bits; - my $total; - while(@out = $str->fetchrow){ - $bits = $out[0]; - #//TODO// This will need to be v6ified soon. - $ver = &VersionFromRegion($conn,$region); - $total += Addresses($bits,$ver); - $i++; - } - $str->finish; - undef $str; - return($total); - } - #-------------------------------------------------------------------------------------- - - - #-------------------------------------------------------------------------------------- sub SetRegion(){ $conn = shift; --- 402,407 ---- *************** *** 434,443 **** $str = $conn->prepare("UPDATE IPDB SET REGION = $region WHERE ID = $id"); $str->execute; if($str->err){ $str->finish; undef $str; ! &IPDBError(-1,"Could not set reason: $str->errstr"); } return(1); } #-------------------------------------------------------------------------------------- --- 410,422 ---- $str = $conn->prepare("UPDATE IPDB SET REGION = $region WHERE ID = $id"); $str->execute; if($str->err){ + my $err = $DBI::errstr; $str->finish; undef $str; ! &IPDBError(-1,"Could not set reason: $err"); } + $str->finish; + undef $str; return(1); } #-------------------------------------------------------------------------------------- *************** *** 450,462 **** my $str = $conn->prepare("UPDATE IPDB SET RECLAIM = $level WHERE ID = $id"); $str->execute; if($str->err){ ! &IPDBError(-1,"Could not set reason: $str->errstr"); } if($level){print "Setting reclaim on blockID: $id
\n";} $str = $conn->prepare("SELECT CHILDL,CHILDR FROM IPDB WHERE ID = $id"); my $num = $str->execute; ! if($str->err){ ! &IPDBError(-1,"Could not set reclaim $str->errstr"); } $num =~ s/E.*//g; if($num){ --- 429,443 ---- my $str = $conn->prepare("UPDATE IPDB SET RECLAIM = $level WHERE ID = $id"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set reason: $err"); } if($level){print "Setting reclaim on blockID: $id
\n";} $str = $conn->prepare("SELECT CHILDL,CHILDR FROM IPDB WHERE ID = $id"); my $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set reclaim $err"); } $num =~ s/E.*//g; if($num){ *************** *** 477,486 **** sub ReclaimSerial(){ my $conn = shift; my $block = shift; ! my $str = $conn->prepare("DELETE FROM reverse_serial_table WHERE BLOCK = $block"); $str->execute; if($str->err){ ! &IPDBError(-1,"Could not delete reverse entry $str->errstr"); } } --- 458,468 ---- sub ReclaimSerial(){ my $conn = shift; my $block = shift; ! my $str = $conn->prepare("DELETE FROM ZONE_RECORD_TABLE WHERE BLOCK = $block AND TYPE = 2"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not delete reverse entry $err"); } } *************** *** 493,508 **** # Walk the list and gen the last IP. #Find the one that ends after this block. - #TODO make V6 compliant. - sub GetBlockIdNM(){ my $conn = shift; my $block = shift; my $region = shift; ! my $query = "SELECT ID,BLOCK,BITS FROM IPDB WHERE BLOCK <= ".$block."::NUMERIC(40,0) AND REGION = $region AND ALLOCATED NOTNULL ORDER BY BLOCK DESC"; my $str = $conn->prepare($query); my $num = $str->execute; ! if($str->err){ my $err = $str->errstr;&IPDBError(-1,"Could not GetBlock List $err"); } $i = 0; while(@out = $str->fetchrow){ my $id = $out[0]; --- 475,495 ---- # Walk the list and gen the last IP. #Find the one that ends after this block. sub GetBlockIdNM(){ my $conn = shift; my $block = shift; my $region = shift; ! my $query = "SELECT ID,BLOCK,BITS FROM IPDB WHERE ! BLOCK <= ".$block."::NUMERIC(40,0) ! AND REGION = $region AND ALLOCATED NOTNULL ! ORDER BY BLOCK DESC"; my $str = $conn->prepare($query); my $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! ! &IPDBError(-1,"Could not GetBlock List $err"); ! } $i = 0; while(@out = $str->fetchrow){ my $id = $out[0]; *************** *** 543,562 **** my $index = shift; my $string = shift; &IncSerial($conn,$zone); ! my $str = $conn->prepare("SELECT TEXT FROM reverse_serial_table WHERE BLOCK = $block AND INDEX = $index"); my $num = $str->execute; ! if($str->err){ &IPDBError(-1,"Could not GetBlockIdNM $str->errstr"); } $num =~ s/E.*//g; if($num){ print "
Updating existing entry"; ! $str = $conn->prepare("UPDATE reverse_serial_table SET TEXT = '$string' WHERE BLOCK = $block AND ZONE = $zone AND INDEX = $index"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not GetBlockIdNM $str->errstr"); } } else { print "
Adding new entry"; ! $str = $conn->prepare("INSERT INTO reverse_serial_table (BLOCK,ZONE,INDEX,TEXT) VALUES ($block,$zone,$index,'$string')"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not GetBlockIdNM $str->errstr"); } } } --- 530,577 ---- my $index = shift; my $string = shift; &IncSerial($conn,$zone); ! my $str = $conn->prepare("SELECT HOSTNAME FROM ZONE_RECORD_TABLE WHERE BLOCK = $block AND INDEX = $index AND TYPE = 2"); my $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not query for existing records: $err"); ! } $num =~ s/E.*//g; if($num){ print "
Updating existing entry"; ! $str = $conn->prepare("UPDATE ZONE_RECORD_TABLE SET HOSTNAME = '$string' WHERE BLOCK = $block AND INDEX = $index AND TYPE = 2"); $str->execute; ! $str = $conn->prepare("UPDATE ZONE_RECORD_TABLE SET ZONE = $zone WHERE BLOCK = $block AND INDEX = $index AND TYPE = 2"); ! $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not Update DNS record. $err"); ! } } else { print "
Adding new entry"; ! $str = $conn->prepare("INSERT INTO ZONE_RECORD_TABLE (BLOCK,ZONE,INDEX,HOSTNAME,TYPE) VALUES ($block,$zone,$index,'$string',2)"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not add new DNS record. $err"); ! } ! } ! } ! ! sub SetFwdDNS(){ ! my $conn = shift; ! my $block = shift; ! my $zone = shift; ! my $index = shift; ! my $string = shift; ! &IncSerial($conn,$zone); ! print "
Adding new entry"; ! my $query = "INSERT INTO zone_record_table (ZONE,TYPE,BLOCK,INDEX,HOSTNAME) VALUES ($zone,1,$block,$index,'$string')"; ! $str = $conn->prepare($query); ! $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not Add DNS record. $err ($zone,1,$block,$index,$string)"); } } *************** *** 565,571 **** my $block = shift; my $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE REVERSE_BLOCK = $block"); my $num = $str->execute; ! if($str->err){ &IPDBError(-1,"Could not get used zone list. $str->errstr"); } while(@out = $str->fetchrow){ $zone = $out[0]; IncSerial($conn,$zone); --- 580,589 ---- my $block = shift; my $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE REVERSE_BLOCK = $block"); my $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not get used zone list. $err"); ! } while(@out = $str->fetchrow){ $zone = $out[0]; IncSerial($conn,$zone); *************** *** 573,585 **** } $str = $conn->prepare("UPDATE ZONE_TABLE SET own = 'f' WHERE REVERSE_BLOCK = $block"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not update table $str->errstr"); } $str = $conn->prepare("UPDATE ZONE_TABLE SET REVERSE_BLOCK = NULL WHERE REVERSE_BLOCK = $block"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not update table $str->errstr"); } ! $str = $conn->prepare("DELETE FROM reverse_serial_table WHERE BLOCK = $block"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not update table $str->errstr"); } } sub SetRevZone(){ --- 591,613 ---- } $str = $conn->prepare("UPDATE ZONE_TABLE SET own = 'f' WHERE REVERSE_BLOCK = $block"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update table $err"); ! } $str = $conn->prepare("UPDATE ZONE_TABLE SET REVERSE_BLOCK = NULL WHERE REVERSE_BLOCK = $block"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update table $err"); ! } ! $str = $conn->prepare("DELETE FROM ZONE_RECORD_TABLE WHERE BLOCK = $block AND TYPE = 2"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update table $err"); ! } ! return(0); } sub SetRevZone(){ *************** *** 594,612 **** my $query = "SELECT ID FROM IPDB WHERE BLOCK <= ".$block."::NUMERIC(40,0) AND REGION = $region AND BITS = 24 ORDER BY BLOCK DESC"; my $str = $conn->prepare($query); my $num = $str->execute; ! if($str->err){ &IPDBError(-1,"Could not query Block from database. $str->errstr"); } $num =~ s/E.*//g; if($num){ @out = $str->fetchrow; $id = $out[0]; $str = $conn->prepare("SELECT REVERSE_BLOCK FROM ZONE_TABLE WHERE ID = $RevZone"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not pull from zone database. $str->errstr"); } @out = $str->fetchrow; ! unless($$out[0]){ $str = $conn->prepare("UPDATE ZONE_TABLE SET REVERSE_BLOCK = $id WHERE ID = $RevZone"); $str->execute; ! if($str->err){ &IPDBError(-1,"Could not update zone database. $str->errstr"); } } } else { &IPDBError(-1,"Can't find matching block"); --- 622,649 ---- my $query = "SELECT ID FROM IPDB WHERE BLOCK <= ".$block."::NUMERIC(40,0) AND REGION = $region AND BITS = 24 ORDER BY BLOCK DESC"; my $str = $conn->prepare($query); my $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not query Block from database. $err"); ! } $num =~ s/E.*//g; if($num){ @out = $str->fetchrow; $id = $out[0]; $str = $conn->prepare("SELECT REVERSE_BLOCK FROM ZONE_TABLE WHERE ID = $RevZone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not pull from zone database. $err"); ! } @out = $str->fetchrow; ! unless($out[0]){ $str = $conn->prepare("UPDATE ZONE_TABLE SET REVERSE_BLOCK = $id WHERE ID = $RevZone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not update zone database. $err"); ! } } } else { &IPDBError(-1,"Can't find matching block"); *************** *** 623,639 **** my @Array = split(/\./,$zone); @array = reverse(@Array); while($array[$i] ne "" ){ ! $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE NAME = '$array[$i]' AND PARENT = $out[0]"); $num = $str->execute; ! if($str->err){&IPDBError(-1,"Can't query Zone ID $str->errstr");} $num =~ s/E.*//g; unless($num){ $str = $conn->prepare("INSERT INTO ZONE_TABLE (NAME,PARENT,own) VALUES ('$array[$i]',$out[0],'f')"); $str->execute; ! if($str->err){&IPDBError(-1,"Can't Insert ZONE $str->errstr");} $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE NAME = '$array[$i]' AND PARENT = $out[0]"); $str->execute; ! if($str->err){&IPDBError(-1,"Can't query new Zone ID $str->errstr");} $insert = 1; } else { } --- 660,685 ---- my @Array = split(/\./,$zone); @array = reverse(@Array); while($array[$i] ne "" ){ ! $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE NAME ~* '$array[$i]' AND PARENT = $out[0]"); $num = $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Can't query Zone ID $err"); ! } $num =~ s/E.*//g; unless($num){ $str = $conn->prepare("INSERT INTO ZONE_TABLE (NAME,PARENT,own) VALUES ('$array[$i]',$out[0],'f')"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Can't Insert ZONE $err"); ! } $str = $conn->prepare("SELECT ID FROM ZONE_TABLE WHERE NAME = '$array[$i]' AND PARENT = $out[0]"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Can't query new Zone ID $err"); ! } $insert = 1; } else { } *************** *** 659,692 **** $serial++; $str = $conn->prepare("UPDATE ZONE_TABLE SET SERIAL = $serial WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Can't set serial $str->errstr");} } else { $str = $conn->prepare("UPDATE ZONE_TABLE SET SERIAL = 1 WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Could not set serial $str->errstr");} $str = $conn->prepare("UPDATE ZONE_TABLE SET REFRESH = 7200 WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Could not set refresh $str->errstr");} $str = $conn->prepare("UPDATE ZONE_TABLE SET RETRY = 1800 WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Could not set retry $str->errstr");} $str = $conn->prepare("UPDATE ZONE_TABLE SET EXPIRE = 604800 WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Could not set expire $str->errstr");} $str = $conn->prepare("UPDATE ZONE_TABLE SET TTL = 3600 WHERE ID = $zone"); $str->execute; ! if($str->err){&IPDBError(-1,"Could not set TTL $str->errstr");} } } else { &IPDBError(-1,"Could not incrament Serial #"); } } ! sub ReverseHead(){ my $conn = shift; my $zone = shift; ! my $str = $conn->prepare("SELECT SERIAL,REFRESH,RETRY,EXPIRE,TTL,ID FROM ZONE_TABLE WHERE REVERSE_BLOCK = $zone"); my $num = $str->execute; my @out = $str->fetchrow; my $serial = $out[0]; my $refresh = $out[1]; --- 705,764 ---- $serial++; $str = $conn->prepare("UPDATE ZONE_TABLE SET SERIAL = $serial WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Can't set serial $err"); ! } } else { $str = $conn->prepare("UPDATE ZONE_TABLE SET SERIAL = 1 WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set serial $err"); ! } $str = $conn->prepare("UPDATE ZONE_TABLE SET REFRESH = 7200 WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set refresh $err"); ! } $str = $conn->prepare("UPDATE ZONE_TABLE SET RETRY = 1800 WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set retry $err"); ! } $str = $conn->prepare("UPDATE ZONE_TABLE SET EXPIRE = 604800 WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set expire $err"); ! } $str = $conn->prepare("UPDATE ZONE_TABLE SET TTL = 3600 WHERE ID = $zone"); $str->execute; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not set TTL $err"); ! } } } else { &IPDBError(-1,"Could not incrament Serial #"); } } ! ! sub DNSHead(){ my $conn = shift; my $zone = shift; ! my $rev = shift; ! my $str; ! if($rev){ ! $str = $conn->prepare("SELECT SERIAL,REFRESH,RETRY,EXPIRE,TTL,ID FROM ZONE_TABLE WHERE REVERSE_BLOCK = $zone"); ! } else { ! $str = $conn->prepare("SELECT SERIAL,REFRESH,RETRY,EXPIRE,TTL,ID FROM ZONE_TABLE WHERE ID = $zone"); ! } my $num = $str->execute; + if(my $err = $str->err){&IPDBError(-1,"Could not get Zone info $err"); } my @out = $str->fetchrow; my $serial = $out[0]; my $refresh = $out[1]; *************** *** 695,709 **** my $ttl = $out[4]; my $id = $out[5]; ! print "@ IN SOA gblx.net. dns.gblx.net. (\n"; ! print " $serial ;Serial\n"; ! print " $refresh ;Refresh\n"; ! print " $retry ;Retry\n"; ! print " $expire ;Expire\n"; ! print " $ttl ) ;TTL\n"; print "\$INCLUDE ns\n"; my $ORIG = GetZoneString($conn,$id); ! print "\$ORIGIN $ORIG.\n"; print <prepare($query); + my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not get Zone list $err"); + } + my @out; + while(@out = $str->fetchrow){ + $type = $out[0]; + $block = $out[1]; + $index = $out[2]; + $hostname = $out[3]; + $text = $out[4]; + $ip = $out[5]; + @Block = &GetBlockFromID($conn,$block); + $address = deci2ip(($Block[0] + $index),&Version($conn,$Block[2])); + if($type == 1){ + print "$hostname IN A $address\n"; + } elsif ($type == 2) { + + + } + } + } + sub WalkReverseBlocks(){ my $conn = shift; my $zone = shift; my $str = $conn->prepare("SELECT BLOCK,CHILDL,CHILDR FROM IPDB WHERE ID = $zone"); my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not query IPDB $err"); + } $num =~ s/E.*//g; if($num){ my @out = $str->fetchrow; *************** *** 731,737 **** &WalkReverseBlocks($conn,$childr); } else { my $block = $out[0]; ! my $str2 = $conn->prepare("SELECT TEXT,INDEX,ZONE FROM REVERSE_SERIAL_TABLE WHERE BLOCK = $zone ORDER BY INDEX ASC"); my $num = $str2->execute; while(@out = $str2->fetchrow){ my $text = $out[0]; --- 836,842 ---- &WalkReverseBlocks($conn,$childr); } else { my $block = $out[0]; ! my $str2 = $conn->prepare("SELECT HOSTNAME,INDEX,ZONE FROM ZONE_RECORD_TABLE WHERE BLOCK = $zone AND TYPE = 2 ORDER BY INDEX ASC"); my $num = $str2->execute; while(@out = $str2->fetchrow){ my $text = $out[0]; *************** *** 740,746 **** my $ip = deci2ip($block + $index,4); $zone = &GetZoneString($conn,$zone); $ip = LastOctet($ip); ! print "$ip IN PTR $text.$zone.\n"; $i++; } } --- 845,851 ---- my $ip = deci2ip($block + $index,4); $zone = &GetZoneString($conn,$zone); $ip = LastOctet($ip); ! print "$ip IN PTR $text.\n"; $i++; } } *************** *** 756,778 **** sub GetZoneString(){ $conn = shift; $block = shift; ! my $out = 0; my $str = $conn->prepare("SELECT NAME,PARENT FROM ZONE_TABLE WHERE ID = $block"); my $num = $str->execute; $num =~ s/E.*//g; if($num){ my @out = $str->fetchrow; my $name = $out[0]; my $parent = $out[1]; if($parent){ ! my $zn = &GetZoneString($conn,$parent); $foo = $name.".".$zn; } else { $foo = $name; } ! $foo =~ s/\.\.//g; return($foo); } } sub Toggle(){ --- 861,892 ---- sub GetZoneString(){ $conn = shift; $block = shift; ! my @out; ! my $zn = ""; ! my $foo = ""; my $str = $conn->prepare("SELECT NAME,PARENT FROM ZONE_TABLE WHERE ID = $block"); my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not query Zone table $err"); + } $num =~ s/E.*//g; if($num){ my @out = $str->fetchrow; my $name = $out[0]; my $parent = $out[1]; if($parent){ ! $zn = &GetZoneString($conn,$parent); $foo = $name.".".$zn; } else { $foo = $name; } ! $foo =~ s/^0$/./g; ! $foo =~ s/\.\././g; ! $str->finish; return($foo); } + return(""); } sub Toggle(){ *************** *** 786,790 **** --- 900,1087 ---- } } + sub DNSTable(){ + my $conn = shift; + my $block = shift; + my $script = shift; + print "\n"; + print "\n"; + my $query = "SELECT ID,HOSTNAME,INDEX,ZONE,TYPE FROM ZONE_RECORD_TABLE WHERE BLOCK = $block"; + my $str = $conn->prepare($query); + my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not query dns records $err"); + } + while(@out = $str->fetchrow){ + my $id = $out[0]; + my $hostname = $out[1].".".&GetZoneString($conn,$out[3]); + my @info = &GetBlockFromID($conn,$block); + my $ver = &VersionFromRegion($conn,$info[2]); + my $ip = deci2ip($info[0] + $out[2],$ver); + if($out[4]){ + if($out[4] == 1){ + $type = "Forward"; + } elsif($out[4] == 2){ + $type = "Reverse"; + } + } + print "\n"; + } + print "
HostnameIPType
$hostname$ip$type"; + print "
\n"; + print "\n"; + print "\n"; + print "\n"; + print "
\n"; + print "
\n"; + $str->finish; + } + + sub ZoneTable(){ + my $conn = shift; + my $script = shift; + print "ZoneTypeSerialRetry/Refresh/"; + print "Expire/TTLStatusState-change/
Edit\n"; + print "
\n"; + print "\n"; + my $query = "SELECT ID,OWN,SERIAL,RETRY,REFRESH,EXPIRE,TTL,REVERSE_BLOCK FROM ZONE_TABLE"; + my $str = $conn->prepare($query); + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not query zone $err"); + } + my $num = $str->execute; + my @out; + while(@out = $str->fetchrow){ + my $id = $out[0]; + my $zone = &GetZoneString($conn,$id); + my $serial = $out[2]; + if($out[7]){ + $type = "Reverse"; + } else { + $type = "Forward"; + } + if(&CheckZone($conn,$id) && $out[3] ){ + my $times = $out[3]." / ".$out[4]." / ".$out[5]." / ".$out[6]; + print "$zone$type$serial$times\n"; + if($out[1]){ + $status = "Active"; + print "$status"; + } else { + $status = "Disabled"; + print "$status"; + } + print ""; + print " /\n"; + print "\n"; + print ""; + } + } + $str->finish; + print ""; + print ""; + print ""; + print "
"; + } + + sub ToggleZone(){ + my $conn = shift; + my $zone = shift; + #Get current state + my $query = "SELECT OWN FROM ZONE_TABLE WHERE ID = $zone"; + my $str = $conn->prepare($query); + my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not query block's current state $err"); + } + @out = $str->fetchrow; + #Set new state. + if($out[0]){ + $query = "UPDATE ZONE_TABLE SET OWN = 'f' WHERE ID = $zone"; + } else { + $query = "UPDATE ZONE_TABLE SET OWN = 't' WHERE ID = $zone"; + } + $str = $conn->prepare($query); + $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not change block's current state $err"); + } + } + + sub DeleteDNSRecord(){ + my $conn = shift; + my $id = shift; + if($id){ + my $query = "DELETE FROM ZONE_RECORD_TABLE WHERE ID = $id"; + my $str = $conn->prepare($query); + my $num = $str->execute; + if($str->err){ + my $err = $DBI::errstr; + &IPDBError(-1,"Could not Delete record $err"); + } + return(0); + } else { + &IPDBError(-1,"No Zone_Record ID to delete"); + } + } + + sub RwhoisForm(){ + my $conn = shift; + my $block = shift; + my $netname = shift; + # Choose known org || Create New one. + } + + + sub DataDump(){ + my $conn = shift; + my $block = shift; + my $bits = shift; + my $region = shift; + $ip = ip2deci($block); + my $id = &GetBlockId($conn,$ip,$bits,$region); + if($id){ + &DumpHead(); + &BlockDump($conn,$id); + } else { + &IPDBError(-1,"Could not get Block ID"); + } + } + + sub DumpHead(){ + print "
\n";
+ 	print "IP Address:Netmask(bits):Region:$config{custnum_f}:$config{custname_f}:Allocated Timestamp\n";
+ 	print "==========================================================\n";
+ }
+ 
+ sub BlockDump(){
+ 	my $conn = shift;
+ 	my $block = shift;
+ 	# Check if block is child or parent
+ 	my $query = "SELECT BLOCK,BITS,REGION,CHILDL,CHILDR,custnum,custdesc,ALLOCATED FROM IPDB WHERE ID = $block";
+ 	my $str = $conn->prepare($query);
+ 	my $num = $str->execute;
+ 	if($str->err){
+ 		my $err = $DBI::errstr;
+ 		&IPDBError(-1,"Could not get Block record $err"); 
+ 	}
+ 	my @out;
+ 	if(@out = $str->fetchrow){
+ 		if($out[3]){
+ 			&BlockDump($conn,$out[3]);
+ 			&BlockDump($conn,$out[4]);
+ 		} else {
+ 			my $ip = &deci2ip($out[0],4);
+ 			my $region = &LookupRegion($conn,$out[2]);
+ 			print "$ip:$out[1]:$region:$out[5]:$out[6]:$out[7]\n";
+ 		}
+ 	
+ 	} else {	
+ 		&IPDBError(-1,"No result for block");
+ 	}
+ }
  
  1;
diff -c ./freeipdb-0_1_3/ipdb_lib.pl ./FreeIPdb-0_1_4/ipdb_lib.pl
*** ./freeipdb-0_1_3/ipdb_lib.pl	Sun Dec 16 22:18:04 2001
--- ./FreeIPdb-0_1_4/ipdb_lib.pl	Sat Mar 30 01:11:04 2002
***************
*** 4,10 ****
  #               |  _|| | |  __/  __/| ||  __/ (_| | |_) |
  #               |_|  |_|  \___|\___|___|_|   \__,_|_.__/
  #
! #       FreeIPdb-0.1.3 12-16-2001 
  ######################################################################
  
  
--- 4,10 ----
  #               |  _|| | |  __/  __/| ||  __/ (_| | |_) |
  #               |_|  |_|  \___|\___|___|_|   \__,_|_.__/
  #
! #	ipdb_lib.pl-$Revision: 1.20 $ $Date: 2002/03/28 05:24:50 $ <$Author: bapril $@freeipdb.org>
  ######################################################################
  
  
***************
*** 26,32 ****
  		$str = $conn->prepare("INSERT INTO RATABLE (NAME) VALUES ('$ra')");
  		$str->execute;
  		if($str->err){
! 			&IPDBError(-1,"Could not lookup RA:  $str->errstr");
  		}
  		$str->finish;
  		undef $str;
--- 26,33 ----
  		$str = $conn->prepare("INSERT INTO RATABLE (NAME) VALUES ('$ra')");
  		$str->execute;
  		if($str->err){
! 			my $err = $DBI::errstr;
! 			&IPDBError(-1,"Could not lookup RA:  $err");
  		}
  		$str->finish;
  		undef $str;
***************
*** 75,81 ****
  		}
  		$str->execute;
  		if($str->err){
! 			&IPDBError(-1,"Could not add Region:  $str->errstr");
  		} else {
  			$str->finish;
  			undef $str;
--- 76,83 ----
  		}
  		$str->execute;
  		if($str->err){
! 			my $err = $DBI::errstr;
! 			&IPDBError(-1,"Could not add Region:  $err");
  		} else {
  			$str->finish;
  			undef $str;
***************
*** 111,117 ****
  	}
  	$num = $str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not lookup Region:  $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
--- 113,120 ----
  	}
  	$num = $str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not lookup Region:  $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
***************
*** 151,157 ****
  	$str = $conn->prepare($query);
  	$num = $str->execute();
  	if($str->err){
! 		&IPDBError(-1,"Could not lookup RA:  $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
--- 154,161 ----
  	$str = $conn->prepare($query);
  	$num = $str->execute();
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not lookup RA:  $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
***************
*** 186,192 ****
  	}
  	$str = $conn->prepare("SELECT RA FROM REGIONTABLE WHERE ID = $region");
  	$num = $str->execute();
! 	if($str->err){ &IPDBError(-1,"Could not lookup RA: $str->errstr"); }
  	$num =~ s/E.*//g;
  	$num || &IPDBError(-1,"No result from database");
  	my @out = $str->fetchrow;
--- 190,199 ----
  	}
  	$str = $conn->prepare("SELECT RA FROM REGIONTABLE WHERE ID = $region");
  	$num = $str->execute();
! 	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not lookup RA: $err"); 
! 	}
  	$num =~ s/E.*//g;
  	$num || &IPDBError(-1,"No result from database");
  	my @out = $str->fetchrow;
***************
*** 214,256 ****
  	my $childr;
  	my $parent;
  	my $sibling;
! 	my $str = $conn->prepare("SELECT PARENT,CHILDL,CHILDR FROM IPDB WHERE ID = $id");
  	my $num = $str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not get parent/child info $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
  		@out = $str->fetchrow;
  		$parent = $out[0];
  		$childl = $out[1];
  		$childr = $out[2];
  	} else {
  		&IPDBError(-1,"Can't find block in database");
  	}
  	$str->finish;
  	undef $str;
! 	if($parent != 0 && !$childl && !$childr){
  		&clearblock($conn,$id) ||&IPDBError(-1,"Could not clearblock");
  		$sibling = &getsibling($conn,$id) || &IPDBError(-1,"Can't get sibling");
  		if(&checksibling($conn,$sibling) == 1 && !&CheckReclaim($conn,$id)){
  			&demoblock($conn,$id) || &IPDBError(-1,"Could not demoblock");
  			&demoblock($conn,$sibling) || &IPDBError(-1,"Could not demoblock #2");
! 			&clearblock($conn,$parent) || &IPDBError(-1,"Could not clearblock #3");
  			my $oktoreclaim = &CheckReclaim($conn,$parent);
  			if($oktoreclaim){
! 				return(3);
  			} else {
  				&reclaim($conn,$parent);
  			}
! 			return(2);
  		}
  	} else {
  		unless(!$childl || !$childr){
! 			&clearblock($conn,$id)|| &IPDBError(-1,"Could not clearblock #2");
! 			return(1);
  		} else {
! 			&IPDBError(-1,"Could not clearblock has children");
  		}
  	}
  }
--- 221,276 ----
  	my $childr;
  	my $parent;
  	my $sibling;
! 	my $str = $conn->prepare("SELECT PARENT,CHILDL,CHILDR,REGION FROM IPDB WHERE ID = $id");
  	my $num = $str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not get parent/child info $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
  		@out = $str->fetchrow;
  		$parent = $out[0];
+ 		my $str = $conn->prepare("SELECT PARENT,CHILDL,CHILDR,REGION FROM IPDB WHERE ID = $id");
  		$childl = $out[1];
  		$childr = $out[2];
+ 		$region = $out[3];
+ 		my $num = $str->execute;
+ 		if($num){
+ 			@out = $str->fetchrow;
+ 			$parentregion = $out[3];
+ 		}
  	} else {
  		&IPDBError(-1,"Can't find block in database");
  	}
  	$str->finish;
  	undef $str;
! 	if(($parent != 0 && !$childl && !$childr) && ($region == $parentregion)){ 
  		&clearblock($conn,$id) ||&IPDBError(-1,"Could not clearblock");
  		$sibling = &getsibling($conn,$id) || &IPDBError(-1,"Can't get sibling");
  		if(&checksibling($conn,$sibling) == 1 && !&CheckReclaim($conn,$id)){
  			&demoblock($conn,$id) || &IPDBError(-1,"Could not demoblock");
  			&demoblock($conn,$sibling) || &IPDBError(-1,"Could not demoblock #2");
! 			&clearblock($conn,$parent) || &IPDBError(-1,"Error clearing block #1");
  			my $oktoreclaim = &CheckReclaim($conn,$parent);
  			if($oktoreclaim){
! 				return(0);
  			} else {
  				&reclaim($conn,$parent);
  			}
! 			return(0);
  		}
  	} else {
+ 		if($region != $parentregion){
+ 			&clearblock($conn,$id)|| &IPDBError(-1,"Error clearing block #2");
+ 			print "Did not traverse region boundry\n";
+ 			return(0);
+ 		}
  		unless(!$childl || !$childr){
! 			&clearblock($conn,$id)|| &IPDBError(-1,"Error clearing block #3");
! 			return(0);
  		} else {
! 			&IPDBError(-1,"Could not clearblock it has children");
  		}
  	}
  }
***************
*** 266,283 ****
  #	0 on OK to reclaim
  #	1 on DO NOT RECLAIM
  sub CheckReclaim(){
! 	my $conn = shift || &IPDBError(-1,"No Database connection");
  	my $blockid = shift || &IPDBError(-1,"No block supplied");
  	my $str = $conn->prepare("SELECT RECLAIM FROM IPDB WHERE ID = $blockid");
  	my $num = $str->execute;
  	if($str->err){ 
! 		&IPDBError(-1,"There was an error quering the database: $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
  		my @out = $str->fetchrow;
  		my $reclaim = $out[0];
! 		print "RECLAIM: $reclaim\n";
  		$str->finish;
  		undef $str;
  		return($reclaim);
--- 286,308 ----
  #	0 on OK to reclaim
  #	1 on DO NOT RECLAIM
  sub CheckReclaim(){
! 	my $conn = shift || &IPDBError(-1,"No Database connection") ;
  	my $blockid = shift || &IPDBError(-1,"No block supplied");
  	my $str = $conn->prepare("SELECT RECLAIM FROM IPDB WHERE ID = $blockid");
  	my $num = $str->execute;
  	if($str->err){ 
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"There was an error quering the database: $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
  		my @out = $str->fetchrow;
  		my $reclaim = $out[0];
! 		if($reclaim) {
! 			print "RECLAIM: $reclaim\n";
! 		} else {
! 			print "RECLAIM\n";
! 		}
  		$str->finish;
  		undef $str;
  		return($reclaim);
***************
*** 299,312 ****
  sub ReadBlock(){
  	my $conn = shift || &IPDBError(-1,"No Database connection");
  	my $block = shift || &IPDBError(-1,"No Block supplied");
! 	my $query = "SELECT i.BLOCK,i.BITS,r.name,i.ALLOCATED,i.SWIPPED,i.CUSTNUM,i.CUSTDESC
  		FROM IPDB i,REGIONTABLE r
  		WHERE i.ID = $block
  			AND i.REGION = r.ID";
  	my $str = $conn->prepare($query);
  	my $num = $str->execute();
  	if($str->err){ 
! 		&IPDBError(-1,"There was an error quering the database: $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
--- 324,338 ----
  sub ReadBlock(){
  	my $conn = shift || &IPDBError(-1,"No Database connection");
  	my $block = shift || &IPDBError(-1,"No Block supplied");
! 	my $query = "SELECT i.BLOCK,i.BITS,r.name,i.ALLOCATED,i.CUSTNUM,i.CUSTDESC
  		FROM IPDB i,REGIONTABLE r
  		WHERE i.ID = $block
  			AND i.REGION = r.ID";
  	my $str = $conn->prepare($query);
  	my $num = $str->execute();
  	if($str->err){ 
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"There was an error quering the database: $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
***************
*** 315,329 ****
  		my $bits = $out[1];
  		my $region = $out[2];
  		my $allocated = $out[3];
! 		my $swip = $out[4];
! 		my $customer = $out[5];
! 		my $CUSTDESC = $out[6];
  		my $city;
  		my $v;
  		$ipblock = &deci2ip($dblock,&Version($conn,$block)) || &IPDBError(-1,"Invalid Deci2IP");
- 		if($swip){$swip = "Yes";} else {$swip = "No";}
  		$v = &Version($conn,$block)|| &IPDBError(-1,"determine version");
! 		$string = "$ipblock/$bits from $region Swipped=$swip To: $customer IPv$v\n";
  		$str->finish;
  		undef $str;
  		return($string);
--- 341,353 ----
  		my $bits = $out[1];
  		my $region = $out[2];
  		my $allocated = $out[3];
! 		my $customer = $out[4];
! 		my $CUSTDESC = $out[5];
  		my $city;
  		my $v;
  		$ipblock = &deci2ip($dblock,&Version($conn,$block)) || &IPDBError(-1,"Invalid Deci2IP");
  		$v = &Version($conn,$block)|| &IPDBError(-1,"determine version");
! 		$string = "$ipblock/$bits from $region To: $customer IPv$v\n";
  		$str->finish;
  		undef $str;
  		return($string);
***************
*** 347,359 ****
  	my $id = shift || &IPDBError(-1,"No Block id supplied");
  	my $str = $conn->prepare("SELECT ID 
  		FROM IPDB 
! 		WHERE CHILDL = NULL 
! 			AND CHILDR = NULL 
! 			AND ALLOCATED = NULL 
  			AND ID = $id");
  	my $num = $str->execute();
  	if($str->err){
! 		&IPDBError(-1,"There was an error quering the database: $str->errstr");
          } 
  	$str->finish;
  	undef $str;
--- 371,384 ----
  	my $id = shift || &IPDBError(-1,"No Block id supplied");
  	my $str = $conn->prepare("SELECT ID 
  		FROM IPDB 
! 		WHERE CHILDL IS NULL 
! 			AND CHILDR IS NULL 
! 			AND ALLOCATED IS NULL 
  			AND ID = $id");
  	my $num = $str->execute();
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"There was an error quering the database: $err");
          } 
  	$str->finish;
  	undef $str;
***************
*** 382,420 ****
  	my $str = $conn->prepare("UPDATE IPDB SET CHILDR = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not set childr null on block $str->errstr");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CHILDL = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not set childl null on block $str->errstr");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CUSTDESC = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not set Customer Name null on block $str->errstr");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET ALLOCATED = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not set allocated null on block $str->errstr");
! 	}
! 	$str = $conn->prepare("UPDATE IPDB SET SWIPPED = NULL WHERE ID = $id");
! 	$str->execute;
! 	if($str->err){
! 		&IPDBError(-1,"Could not set swipped null on block-$id $str->errstr");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CUSTNUM = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not set customer null on block $str->errstr");
  	}
  	my $now = time();
  	my $hold = $now + $config{holdtime};
  	$str = $conn->prepare("UPDATE IPDB SET HOLDTIME = $hold WHERE ID = $id");
  	$str->execute();
  	if($str->err){
! 		&IPDBError(-1,"Could not set holdtime on block $str->errstr");
  	}
  	$str->finish;
  	undef $str;
--- 407,446 ----
  	my $str = $conn->prepare("UPDATE IPDB SET CHILDR = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set childr null on block $err");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CHILDL = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set childl null on block $err");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CUSTDESC = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set Customer Name null on block $err");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET ALLOCATED = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set allocated null on block $err");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET CUSTNUM = NULL WHERE ID = $id");
  	$str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set customer null on block $err");
  	}
  	my $now = time();
  	my $hold = $now + $config{holdtime};
  	$str = $conn->prepare("UPDATE IPDB SET HOLDTIME = $hold WHERE ID = $id");
  	$str->execute();
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not set holdtime on block $err");
  	}
  	$str->finish;
  	undef $str;
***************
*** 437,445 ****
  	my $str = $conn->prepare("DELETE FROM IPDB WHERE ID = $id");
  	$str->execute();
  	if($str->err){
  		$str->finish;
  		undef $str;
! 		&IPDBError(-1,"There was an error deleting the block $str->errstr");
  	} else {
  		$str->finish;
  		undef $str;
--- 463,472 ----
  	my $str = $conn->prepare("DELETE FROM IPDB WHERE ID = $id");
  	$str->execute();
  	if($str->err){
+ 		my $err = $DBI::errstr;
  		$str->finish;
  		undef $str;
! 		&IPDBError(-1,"There was an error deleting the block $err");
  	} else {
  		$str->finish;
  		undef $str;
***************
*** 466,472 ****
  	my $str = $conn->prepare("SELECT PARENT FROM IPDB WHERE ID = $id");
  	my $num = $str->execute;
  	if($str->err){
! 		&IPDBError(-1,"Could not get parent from database $str->errstr");
  	}
  	$num =~ s/E.*//g;
  	if($num){
--- 493,500 ----
  	my $str = $conn->prepare("SELECT PARENT FROM IPDB WHERE ID = $id");
  	my $num = $str->execute;
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not get parent from database $err");
  	}
  	$num =~ s/E.*//g;
  	if($num){
***************
*** 480,486 ****
  	my $str2 = $conn->prepare("SELECT CHILDL,CHILDR FROM IPDB WHERE ID = $parent");
  	my $num2 = $str2->execute;
  	if($str2->err){
! 		&IPDBError(-1,"Could not get child info from database $str2->errstr\n");
          }
  	$num2 =~ s/E.*//g;
  	if($num2){
--- 508,515 ----
  	my $str2 = $conn->prepare("SELECT CHILDL,CHILDR FROM IPDB WHERE ID = $parent");
  	my $num2 = $str2->execute;
  	if($str2->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not get child info from database $err\n");
          }
  	$num2 =~ s/E.*//g;
  	if($num2){
***************
*** 508,514 ****
  #	A region ID
  #	The size of the new block (in bits)
  #	A req #
- #	Is the block swipped?
  #	A customer code.
  # Returns:
  #	-1 on error
--- 537,542 ----
***************
*** 520,526 ****
  	my $region = shift || &IPDBError(-1,"No region supplied");
  	my $bits = shift || &IPDBError(-1,"No bits supplied");
  	my $CUSTDESC = shift;
- 	my $SWIPPED = shift;
  	my $CUST = shift ;
  	my $id = "";
  	my $newblock = "";
--- 548,553 ----
***************
*** 529,559 ****
  	# Any blocks the exact Size?
  	my $str = $conn->prepare("SELECT ID,BITS
  					FROM IPDB 
! 					WHERE CHILDL = NULL 
! 						AND CHILDR = NULL 
! 						AND ALLOCATED = NULL  
  						AND REGION = $region 	
  						AND BITS <= $bits 
! 						AND RECLAIM = NULL 
! 						AND (HOLDTIME < $now OR HOLDTIME = NULL)
  					ORDER BY priority ASC,BITS DESC");
  	my $num = $str->execute;
  	if($str->err){ 
! 		&IPDBError(-1,"Could not pull free-blocks from the database $str->errstr");
  	}
  	while(@out = $str->fetchrow){
  		my $size = $out[1];
  		$id = $out[0];
  		if($size == $bits){
  			#We have exact blocks
! 			&setblock($conn,$id,$CUSTDESC,$SWIPPED,$CUST,$region) || &IPDBError(-1,"Unable to setblock");
  			$str->finish;
  			undef $str;
  			return($id);
  		} else {
  			# There are larger blocks in region.
  			$newblock = &makeblock($conn,$id,$bits) || &IPDBError(-1,"Unable to makeblock");
! 			&setblock($conn,$newblock,$CUSTDESC,$SWIPPED,$CUST,$region) || &IPDBError(-1,"Unable to setblock #2");
  			$str->finish;
  			undef $str;
  			return($newblock);
--- 556,587 ----
  	# Any blocks the exact Size?
  	my $str = $conn->prepare("SELECT ID,BITS
  					FROM IPDB 
! 					WHERE CHILDL IS NULL 
! 						AND CHILDR IS NULL 
! 						AND ALLOCATED IS NULL  
  						AND REGION = $region 	
  						AND BITS <= $bits 
! 						AND RECLAIM IS NULL 
! 						AND (HOLDTIME < $now OR HOLDTIME IS NULL)
  					ORDER BY priority ASC,BITS DESC");
  	my $num = $str->execute;
  	if($str->err){ 
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Could not pull free-blocks from the database $err");
  	}
  	while(@out = $str->fetchrow){
  		my $size = $out[1];
  		$id = $out[0];
  		if($size == $bits){
  			#We have exact blocks
! 			&setblock($conn,$id,$CUSTDESC,$CUST,$region) || &IPDBError(-1,"Unable to setblock");
  			$str->finish;
  			undef $str;
  			return($id);
  		} else {
  			# There are larger blocks in region.
  			$newblock = &makeblock($conn,$id,$bits) || &IPDBError(-1,"Unable to makeblock");
! 			&setblock($conn,$newblock,$CUSTDESC,$CUST,$region) || &IPDBError(-1,"Unable to setblock #2");
  			$str->finish;
  			undef $str;
  			return($newblock);
***************
*** 587,593 ****
  #       Database Connection (from pg) to ipdb
  #       The block id of the block to set.
  #       The Customer name to assign this allocation to.
- #       't' or NULL for is the block swipped.
  #       Customer code/number
  #       Optional Region
  # Returns:
--- 615,620 ----
***************
*** 598,604 ****
          my $conn = shift || &IPDBError(-1,"No Database connection");
          my $block = shift || &IPDBError(-1,"No Block ID");
          my $CUSTDESC = shift;
-         my $SWIPPED = shift;
          my $CUST = shift;
          my $region = shift;
          my $time = time();
--- 625,630 ----
***************
*** 606,612 ****
          my $str = $conn->prepare("SELECT ALLOCATED,CHILDL,CHILDR,RECLAIM FROM IPDB WHERE ID = $block");
  	my $num = $str->execute;
          if($str->err){
!                 &IPDBError(-1,"could not check database for block: $str->errstr");
          }
          my $allocated;
          my $childl;
--- 632,639 ----
          my $str = $conn->prepare("SELECT ALLOCATED,CHILDL,CHILDR,RECLAIM FROM IPDB WHERE ID = $block");
  	my $num = $str->execute;
          if($str->err){
! 		my $err = $DBI::errstr;
!                 &IPDBError(-1,"could not check database for block: $err");
          }
          my $allocated;
          my $childl;
***************
*** 619,671 ****
                  $childl = $out[1];
                  $childr = $out[2];
                  $reclaim = $out[3];
!                 if($allocated =~ /\d+/){
!                         &IPDBError(-1,"Block in use  or allocated set to $allocated");
!                 }
!                 if($childl =~ /\d+/ || $childr =~ /\d+/){
!                         &IPDBError(-1,"Block $block has children");
!                 }
          } else {
                  &IPDBError(-1,"Block not in database");
          }
!         if($reclaim =~ /[01]/){
!                 &IPDBError(0,"Unable to set block In reclaim mode");
!         }
          $str = $conn->prepare("UPDATE IPDB SET ALLOCATED = $time WHERE ID = $block");
  	$str->execute();
  	if($str->err){
! 		&IPDBError(-1,"Unable to set Allocated time. $str->errstr");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET HOLDTIME = NULL WHERE ID = $block");
          if($str->err){
!                 &IPDBError(-1,"Unable to set allocated $str->errstr");
          }
  	if($CUSTDESC){
          	$str = $conn->prepare("UPDATE IPDB SET CUSTDESC = '$CUSTDESC' WHERE ID = $block");
  		$str->execute;
          	if($str->err){
! 			&IPDBError(-1,"Unable to set  CUSTDESC($CUSTDESC) $block $str->errstr");
          	}
  	}
-         if($SWIPPED){
-                 $str = $conn->prepare("UPDATE IPDB SET SWIPPED = '1' WHERE ID = $block");
- 		$str->execute;
-                 if($str->err){
-                         &IPDBError(-1,"Unable to set swipped($SWIPPED) on block $block $str->errstr");
-                 }
-         }
          if($CUST){
                  $str = $conn->prepare("UPDATE IPDB SET CUSTNUM = $CUST WHERE ID = $block");
  		$str->execute;
                  if($str->err){
!                         &IPDBError(-1,"unable to set customer code $str->errstr");
                  }
          }
          if($region){
                  $str = $conn->prepare("UPDATE IPDB SET REGION = $region WHERE ID = $block");
  		$str->execute;
                  if($str->err){
!                         &IPDBError(-1,"unable to set Region $str->errstr");
                  }
          }
  	$str->finish;
--- 646,702 ----
                  $childl = $out[1];
                  $childr = $out[2];
                  $reclaim = $out[3];
! 		if ($allocated) {
! 			if($allocated =~ /\d+/){
! 				&IPDBError(-1,"Block in use  or allocated set to $allocated");
! 			}
! 		}
! 		if ($childl || $childr) {
! 			if($childl =~ /\d+/ || $childr =~ /\d+/){
! 				&IPDBError(-1,"Block $block has children");
! 			}
! 		}
          } else {
                  &IPDBError(-1,"Block not in database");
          }
! 	if($reclaim){
!         	if($reclaim =~ /[01]/){
! 			&IPDBError(0,"Unable to set block In reclaim mode");
!         	}
! 	}
          $str = $conn->prepare("UPDATE IPDB SET ALLOCATED = $time WHERE ID = $block");
  	$str->execute();
  	if($str->err){
! 		my $err = $DBI::errstr;
! 		&IPDBError(-1,"Unable to set Allocated time. $err");
  	}
  	$str = $conn->prepare("UPDATE IPDB SET HOLDTIME = NULL WHERE ID = $block");
          if($str->err){
! 		my $err = $DBI::errstr;
!                 &IPDBError(-1,"Unable to set allocated $err");
          }
  	if($CUSTDESC){
          	$str = $conn->prepare("UPDATE IPDB SET CUSTDESC = '$CUSTDESC' WHERE ID = $block");
  		$str->execute;
          	if($str->err){
! 			my $err = $DBI::errstr;
! 			&IPDBError(-1,"Unable to set  CUSTDESC($CUSTDESC) $block $err");
          	}
  	}
          if($CUST){
                  $str = $conn->prepare("UPDATE IPDB SET CUSTNUM = $CUST WHERE ID = $block");
  		$str->execute;
                  if($str->err){
! 			my $err = $DBI::errstr;
!                         &IPDBError(-1,"unable to set customer code $err");
                  }
          }
          if($region){
                  $str = $conn->prepare("UPDATE IPDB SET REGION = $region WHERE ID = $block");
  		$str->execute;
                  if($str->err){
! 			my $err = $DBI::errstr;
!                         &IPDBError(-1,"unable to set Region $err");
                  }
          }
  	$str->finish;
***************
*** 697,703 ****
                  return(0);
          } else {
  		$ver = &VersionFromRegion($conn,$region);
!                 my $added = &SetBlockP($conn,$block,$region,$bits,1,1,1,$ver);
                  if($added){
                          print "A parent of that block exists.
\n"; &reclaim($conn,$added); --- 728,734 ---- return(0); } else { $ver = &VersionFromRegion($conn,$region); ! my $added = &SetBlockP($conn,$block,$region,$bits,1,1,$ver); if($added){ print "A parent of that block exists.
\n"; &reclaim($conn,$added); *************** *** 706,718 **** my $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,PRIORITY) VALUES ($binblock,$bits,$region,0,$priority)"); $str->execute; if($str->err){ ! &IPDBError(-1,"Could not insert block into database| $str->errstr"); } my $query = "SELECT ID FROM IPDB WHERE BLOCK = ".$binblock."::NUMERIC(40,0) AND BITS = $bits AND REGION = $region"; $str = $conn->prepare($query); my $num = $str->execute; if($str->err){ ! &IPDBError(-1,"Could not query block from database| $str->errstr"); } $num =~ s/E.*//g; if($num){ --- 737,751 ---- my $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,PRIORITY) VALUES ($binblock,$bits,$region,0,$priority)"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not insert block into database| $err"); } my $query = "SELECT ID FROM IPDB WHERE BLOCK = ".$binblock."::NUMERIC(40,0) AND BITS = $bits AND REGION = $region"; $str = $conn->prepare($query); my $num = $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Could not query block from database| $err"); } $num =~ s/E.*//g; if($num){ *************** *** 750,756 **** my $str = $conn->prepare("SELECT BLOCK,BITS,REGION,RECLAIM,priority FROM IPDB WHERE ID = $id"); my $num = $str->execute; if($str->err){ ! &IPDBError(-1,"Couldn't query block from database| $str->errstr"); } $num =~ s/E.*//g; unless($num){ --- 783,790 ---- my $str = $conn->prepare("SELECT BLOCK,BITS,REGION,RECLAIM,priority FROM IPDB WHERE ID = $id"); my $num = $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Couldn't query block from database| $err"); } $num =~ s/E.*//g; unless($num){ *************** *** 787,810 **** $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,priority) VALUES ($block1,$bits,$region,$id,$alloc_prio)"); $str->execute(); if($str->err){ ! &IPDBError(-1,"Error creating block1 Sent Block |$block1| BITS |$bits| REGION |$region| ID |$id| PRIO |$alloc_prio| $str->errstr"); } $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,priority) VALUES ($block2,$bits,$region,$id,$alloc_prio)"); $str->execute; if($str->err){ ! &IPDBError(-1,"Error creating block2 $str->errstr"); } my $query1 = "SELECT ID FROM IPDB WHERE BLOCK = ".$block1."::numeric(40,0) AND BITS = $bits AND REGION = $region"; my $query2 = "SELECT ID FROM IPDB WHERE BLOCK = ".$block2."::numeric(40,0) AND BITS = $bits AND REGION = $region"; my $str1 = $conn->prepare($query1); my $num1 = $str1->execute; if($str1->err){ ! &IPDBError(-1,"Error quering for block1 $str1->errstr"); } my $str2 = $conn->prepare($query2); my $num2 = $str2->execute; if($str2->err){ ! &IPDBError(-1,"Error quering for block2 $str2->errstr"); } my $childr; my $childl; --- 821,848 ---- $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,priority) VALUES ($block1,$bits,$region,$id,$alloc_prio)"); $str->execute(); if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Error creating block1 Sent Block |$block1| BITS |$bits| REGION |$region| ID |$id| PRIO |$alloc_prio| $err"); } $str = $conn->prepare("INSERT INTO IPDB (BLOCK,BITS,REGION,PARENT,priority) VALUES ($block2,$bits,$region,$id,$alloc_prio)"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Error creating block2 $err"); } my $query1 = "SELECT ID FROM IPDB WHERE BLOCK = ".$block1."::numeric(40,0) AND BITS = $bits AND REGION = $region"; my $query2 = "SELECT ID FROM IPDB WHERE BLOCK = ".$block2."::numeric(40,0) AND BITS = $bits AND REGION = $region"; my $str1 = $conn->prepare($query1); my $num1 = $str1->execute; if($str1->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Error quering for block1 $err"); } my $str2 = $conn->prepare($query2); my $num2 = $str2->execute; if($str2->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Error quering for block2 $err"); } my $childr; my $childl; *************** *** 825,836 **** $str = $conn->prepare("UPDATE IPDB SET CHILDR = $childr WHERE ID = $id"); $str->execute; if($str->err){ ! &IPDBError(-1,"Setting ChildR($childr) filed in parent($id) $str->errstr"); } $str = $conn->prepare("UPDATE IPDB SET CHILDL = $childl WHERE ID = $id"); $str->execute; if($str->err){ ! &IPDBError(-1,"Setting ChildL filed in parent $str->errstr"); } my $a; $a = &makemask($bits,$v) || &IPDBError(0,"Makemask failed"); --- 863,876 ---- $str = $conn->prepare("UPDATE IPDB SET CHILDR = $childr WHERE ID = $id"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Setting ChildR($childr) filed in parent($id) $err"); } $str = $conn->prepare("UPDATE IPDB SET CHILDL = $childl WHERE ID = $id"); $str->execute; if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"Setting ChildL filed in parent $err"); } my $a; $a = &makemask($bits,$v) || &IPDBError(0,"Makemask failed"); *************** *** 920,926 **** my $str = $conn->prepare("SELECT BITS,REGION,BLOCK FROM IPDB WHERE ID = $id"); my $num = $str->execute; if($str->err) { ! &IPDBError(-1,"There was an error iuering parent block $str->errstr"); } $num =~ s/E.*//g; $num|| &IPDBError(-1,"Parent block does not exist."); --- 960,967 ---- my $str = $conn->prepare("SELECT BITS,REGION,BLOCK FROM IPDB WHERE ID = $id"); my $num = $str->execute; if($str->err) { ! my $err = $DBI::errstr; ! &IPDBError(-1,"There was an error iuering parent block $err"); } $num =~ s/E.*//g; $num|| &IPDBError(-1,"Parent block does not exist."); *************** *** 999,1005 **** # Region to put block in. # Size of block in bits. # CUSTDESC Number - # SWIPPED 't' or null # CUST number # Returns: # -1 on error --- 1040,1045 ---- *************** *** 1012,1020 **** my $region = shift || &IPDBError(-1,"Region nit supplied"); my $bits = shift || &IPDBError(-1,"Bits not supplied"); my $CUSTDESC = shift; - my $SWIPPED = shift || &IPDBError(-1,"SWIPPED Not supplied"); my $CUST = shift; ! my $ver = shift || &IPDBError(-1,"No IP version supplied"); my $bblock = &ip2deci($block); my $newblock = &CheckBlockFree($conn,$bblock,$bits,$region); if($newblock == -1){ --- 1052,1059 ---- my $region = shift || &IPDBError(-1,"Region nit supplied"); my $bits = shift || &IPDBError(-1,"Bits not supplied"); my $CUSTDESC = shift; my $CUST = shift; ! my $ver = shift || &IPDBError(-1,"No IP version supplied 1"); my $bblock = &ip2deci($block); my $newblock = &CheckBlockFree($conn,$bblock,$bits,$region); if($newblock == -1){ *************** *** 1025,1031 **** if($newblock == 0){ $newblock = &MakeParent($conn,$bblock,$bits,$region,$bblock,$ver) || return(0); } ! &setblock($conn,$newblock,$CUSTDESC,$SWIPPED,$CUST,$region); return($newblock); } #-------------------------------------------------------------------------------------- --- 1064,1070 ---- if($newblock == 0){ $newblock = &MakeParent($conn,$bblock,$bits,$region,$bblock,$ver) || return(0); } ! &setblock($conn,$newblock,$CUSTDESC,$CUST,$region); return($newblock); } #-------------------------------------------------------------------------------------- *************** *** 1050,1056 **** my $str = $conn->prepare($query); my $num = $str->execute; $num =~ s/E.*//g; ! if($str->err){ &IPDBError(-1,"There was an error with the database query $str->errstr"); } unless($num){ return(0); } else { --- 1089,1098 ---- my $str = $conn->prepare($query); my $num = $str->execute; $num =~ s/E.*//g; ! if($str->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"There was an error with the database query $err"); ! } unless($num){ return(0); } else { *************** *** 1059,1065 **** my $str2 = $conn->prepare("SELECT ALLOCATED,CHILDR,CHILDL FROM IPDB WHERE ID = $id"); $str2->execute; if($str2->err){ ! &IPDBError(-1,"There was an error with the database query $id $str2->errstr"); } else { my @out1 = $str2->fetchrow; my $allo = $out1[0]; --- 1101,1108 ---- my $str2 = $conn->prepare("SELECT ALLOCATED,CHILDR,CHILDL FROM IPDB WHERE ID = $id"); $str2->execute; if($str2->err){ ! my $err = $DBI::errstr; ! &IPDBError(-1,"There was an error with the database query $id $err"); } else { my @out1 = $str2->fetchrow; my $allo = $out1[0]; *************** *** 1166,1172 **** my $str = $conn->prepare("SELECT ID,NAME FROM REGIONTABLE ORDER BY NAME"); my @out; $str->execute; ! if($str->err){&IPDBError(-1,"Could not query Database $str->errstr");} while (@out = $str->fetchrow) { print "