Changeset 320 for trunk/cgi-bin/main.cgi
- Timestamp:
- 04/04/06 18:25:28 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/main.cgi
r314 r320 103 103 104 104 if ($@) { 105 carp "Transaction aborted because $@"; 105 my $msg = $@; 106 carp "Transaction aborted because $msg"; 106 107 eval { $ip_dbh->rollback; }; 107 syslog "err", "Could not add master block '$webvar{cidr}' to database: '$ @'";108 printError("Could not add master block $webvar{cidr} to database: $ @");108 syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'"; 109 printError("Could not add master block $webvar{cidr} to database: $msg"); 109 110 } else { 110 111 print "<div type=heading align=center>Success!</div>\n"; … … 414 415 qq($master ($data[0]):</div></center><br>\n); 415 416 416 startTable('CIDR allocation','Customer Location','Type','CustID',' Description/Name');417 startTable('CIDR allocation','Customer Location','Type','CustID','SWIPed?','Description/Name'); 417 418 418 419 # Snag the allocations for this block 419 $sth = $ip_dbh->prepare("select cidr,city,type,custid, description".420 $sth = $ip_dbh->prepare("select cidr,city,type,custid,swip,description". 420 421 " from allocations where cidr <<= '$master' order by cidr"); 421 422 $sth->execute(); … … 423 424 my $count=0; 424 425 while (my @data = $sth->fetchrow_array()) { 425 # cidr,city,type,custid, description, as per the SELECT426 # cidr,city,type,custid,swip,description, as per the SELECT 426 427 my $cidr = new NetAddr::IP $data[0]; 427 428 … … 432 433 my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : ''). 433 434 qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>), 434 $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]); 435 $data[1], $disp_alloctypes{$data[2]}, $data[3], 436 ($data[4] eq 'y' ? 'Yes' : 'No'), $data[5]); 435 437 # If the allocation is a pool, allow listing of the IPs in the pool. 436 438 if ($data[2] =~ /^.[pd]$/) { … … 710 712 my $city; 711 713 my $failmsg; 714 my $extracond = ''; 715 if ($webvar{allocfrom} eq '-') { 716 $extracond = ($webvar{allowpriv} eq 'on' ? '' : 717 " and not (cidr <<= '192.168.0.0/16'". 718 " or cidr <<= '10.0.0.0/8'". 719 " or cidr <<= '172.16.0.0/12')"); 720 } 721 my $sortorder; 712 722 if ($webvar{alloctype} eq 'rm') { 713 723 if ($webvar{allocfrom} ne '-') { 714 724 $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'". 715 " and cidr <<= '$webvar{allocfrom}' order by maskbits desc"; 725 " and cidr <<= '$webvar{allocfrom}'"; 726 $sortorder = "maskbits desc"; 716 727 } else { 717 $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'" .718 " order bymaskbits desc";728 $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'"; 729 $sortorder = "maskbits desc"; 719 730 } 720 731 $failmsg = "No suitable free block found.<br>\nWe do not have a free". … … 745 756 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}". 746 757 " and cidr <<= '$webvar{allocfrom}' and routed='". 747 (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."' order by maskbits desc,cidr"; 758 (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'"; 759 $sortorder = "maskbits desc,cidr"; 748 760 } else { 749 761 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}". 750 " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y'). 751 "' order bymaskbits desc,cidr";762 " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'"; 763 $sortorder = "maskbits desc,cidr"; 752 764 } 753 765 } 766 $sql = $sql.$extracond." order by ".$sortorder; 754 767 $sth = $ip_dbh->prepare($sql); 755 768 $sth->execute; … … 914 927 } else { 915 928 # New! Improved! And now Loaded From The Database!! 916 $webvar{custid} = $def_custids{$webvar{alloctype}}; 929 if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) { 930 $webvar{custid} = $def_custids{$webvar{alloctype}}; 931 } 917 932 } 918 933 … … 929 944 } else { 930 945 $flag = 'n'; 931 if ($webvar{alloctype} =~ /[wp][cr]| [ds][pi]/) {946 if ($webvar{alloctype} =~ /[wp][cr]|d[pi]/) { 932 947 # Set this forcibly rather than messing around elsewhere. Yes, this *is* a hack. PTHBTT!! 933 $webvar{pop} = 'Sudbury';934 }935 if ($webvar{pop} =~ /^-$/) {948 # Match CORE/WAN types (wc, wr, pc, pr), DSL pool and IP (dp, di). 949 $webvar{pop} = "Sudbury"; 950 } elsif ($webvar{pop} =~ /^-$/) { 936 951 $flag = 'to route the block from/through'; 937 952 } … … 957 972 # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data 958 973 if ($webvar{block} =~ /\/32$/) { 959 $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";974 $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid from poolips where ip='$webvar{block}'"; 960 975 } else { 961 $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata from allocations where cidr='$webvar{block}'"976 $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,oldcustid,swip from allocations where cidr='$webvar{block}'" 962 977 } 963 978 … … 1006 1021 $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}<input type=hidden name=alloctype value="$data[2]">/g; 1007 1022 } 1023 $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g; 1008 1024 $html =~ s/\$\$CITY\$\$/<input type=text name=city value="$data[3]">/g; 1009 1025 $html =~ s/\$\$CIRCID\$\$/<input type="text" name="circid" value="$data[4]" maxlength=64 size=64 class="regular">/g; … … 1012 1028 } else { 1013 1029 $html =~ s/\$\$CUSTID\$\$/$data[1]/g; 1030 $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g; 1014 1031 $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}/g; 1015 1032 $html =~ s/\$\$CITY\$\$/$data[3]/g; … … 1020 1037 my ($lastmod,undef) = split /\s+/, $data[7]; 1021 1038 $html =~ s/\$\$LASTMOD\$\$/$lastmod/g; 1039 1040 ## Hack time! SWIP isn't going to stay, so I'm not going to integrate it with ACLs. 1041 if ($data[2] =~ /.i/) { 1042 $html =~ s/\$\$SWIP\$\$/N\/A/; 1043 } else { 1044 my $tmp = (($data[10] eq 'n') ? '<input type=checkbox name=swip>' : 1045 '<input type=checkbox name=swip checked=yes>'); 1046 $html =~ s/\$\$SWIP\$\$/$tmp/; 1047 } 1022 1048 1023 1049 # Allows us to "correctly" colour backgrounds in table … … 1091 1117 $sql = "update allocations set custid='$webvar{custid}',". 1092 1118 "description='$webvar{desc}',notes='$webvar{notes}',city='$webvar{city}',". 1093 "type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata ". 1119 "type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata,". 1120 "swip='".($webvar{swip} eq 'on' ? 'y' : 'n')."' ". 1094 1121 "where cidr='$webvar{block}'"; 1095 1122 } … … 1115 1142 my $html = join('', <HTML>); 1116 1143 1144 my $swiptmp = ($webvar{swip} eq 'on' ? 'Yes' : 'No'); 1117 1145 $html =~ s/\$\$BLOCK\$\$/$webvar{block}/g; 1118 1146 $webvar{city} = desanitize($webvar{city}); … … 1121 1149 $html =~ s/\$\$TYPEFULL\$\$/$disp_alloctypes{$webvar{alloctype}}/g; 1122 1150 $html =~ s/\$\$CUSTID\$\$/$webvar{custid}/g; 1151 $html =~ s/\$\$SWIP\$\$/$swiptmp/g; 1123 1152 $webvar{circid} = desanitize($webvar{circid}); 1124 1153 $html =~ s/\$\$CIRCID\$\$/$webvar{circid}/g;
Note:
See TracChangeset
for help on using the changeset viewer.