Changeset 470 for branches/htmlform/cgi-bin
- Timestamp:
- 08/17/10 15:32:16 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/htmlform/cgi-bin/main.cgi
r469 r470 959 959 # Two cases: block is a netblock, or block is a static IP from a pool 960 960 # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data 961 ##fixme: allow "SWIP" (publication to rWHOIS) of static IP data 961 962 if ($webvar{block} =~ /\/32$/) { 962 963 $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'"; … … 972 973 # Clean up extra whitespace on alloc type 973 974 $data[2] =~ s/\s//; 974 975 open (HTML, "../editDisplay.html")976 or croak "Could not open editDisplay.html :$!";977 my $html = join('', <HTML>);978 975 979 976 # We can't let the city be changed here; this block is a part of … … 983 980 # Needs thinking. Have to allow changes to city to correct errors, no? 984 981 # Also have areas where a routed block at a POP serves "many" cities/towns/named crossroads 985 $html =~ s/\$\$BLOCK\$\$/$webvar{block}/g; 986 987 # cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip 988 989 $page->param(block => $webvar{block}); 990 991 $page->param(custid => $data[1]); 992 $page->param(city => $data[3]); 993 $page->param(circid => $data[4]); 994 $page->param(desc => $data[5]); 995 $page->param(notes => $data[6]); 996 997 if ($IPDBacl{$authuser} =~ /c/) { 998 $html =~ s/\$\$CUSTID\$\$/<input type=text name=custid value="$data[1]" maxlength=15 class="regular">/; 982 983 # @data: cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip 984 985 $page->param(block => $webvar{block}); 986 987 $page->param(custid => $data[1]); 988 $page->param(city => $data[3]); 989 $page->param(circid => $data[4]); 990 $page->param(desc => $data[5]); 991 $page->param(notes => $data[6]); 992 999 993 ##fixme The check here should be built from the database 1000 994 # Need to expand to support pool types too 1001 if ($data[2] =~ /^.[ne]$/) {1002 $page->param(changetype => $IPDBacl{$authuser} =~ /c/);1003 $page->param(alloctype => [995 if ($data[2] =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) { 996 $page->param(changetype => 1); 997 $page->param(alloctype => [ 1004 998 { selme => ($data[2] eq 'me'), type => "me", disptype => "Dialup netblock" }, 1005 999 { selme => ($data[2] eq 'de'), type => "de", disptype => "Dynamic DSL netblock" }, … … 1011 1005 ] 1012 1006 ); 1013 1014 # Block that can be changed 1015 my $blockoptions = "<select name=alloctype><option". 1016 (($data[2] eq 'me') ? ' selected' : '') ." value='me'>Dialup netblock</option>\n<option". 1017 (($data[2] eq 'de') ? ' selected' : '') ." value='de'>Dynamic DSL netblock</option>\n<option". 1018 (($data[2] eq 'ce') ? ' selected' : '') ." value='ce'>Dynamic cable netblock</option>\n<option". 1019 (($data[2] eq 'we') ? ' selected' : '') ." value='we'>Dynamic wireless netblock</option>\n<option". 1020 (($data[2] eq 'cn') ? ' selected' : '') ." value='cn'>Customer netblock</option>\n<option". 1021 (($data[2] eq 'en') ? ' selected' : '') ." value='en'>End-use netblock</option>\n<option". 1022 (($data[2] eq 'in') ? ' selected' : '') ." value='in'>Internal netblock</option>\n". 1023 "</select>\n"; 1024 $html =~ s/\$\$TYPESELECT\$\$/$blockoptions/g; 1025 } else { 1026 $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}<input type=hidden name=alloctype value="$data[2]">/g; 1027 } 1007 } else { 1008 $page->param(disptype => $disp_alloctypes{$data[2]}); 1009 $page->param(type => $data[2]); 1010 } 1011 1028 1012 ## node hack 1013 $sth = $ip_dbh->prepare("SELECT nodes.node_id,node_name FROM nodes INNER JOIN noderef". 1014 " ON nodes.node_id=noderef.node_id WHERE noderef.block='$webvar{block}'"); 1015 $sth->execute; 1016 my ($nodeid,$nodename) = $sth->fetchrow_array(); 1017 $page->param(havenodeid => $nodeid); 1018 1019 if ($data[2] eq 'fr' || $data[2] eq 'bi') { 1020 $page->param(typesupportsnodes => 1); 1021 $page->param(nodename => $nodename); 1022 1029 1023 ##fixme: this whole hack needs cleanup and generalization for all alloctypes 1030 $sth = $ip_dbh->prepare("SELECT node_id FROM noderef WHERE block='$webvar{block}'"); 1031 $sth->execute; 1032 my ($nodeid) = $sth->fetchrow_array(); 1033 $page->param(havenodeid => $nodeid); 1034 $page->param(typesupportsnodes => ($data[2] eq 'fr' || $data[2] eq 'bi')); 1035 if ($nodeid) { 1036 $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id"); 1037 $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n"; 1038 my $nodes = "<select name=node>\n"; 1039 my @nodelist; 1040 while (my ($nid,$nname) = $sth->fetchrow_array()) { 1041 $nodes .= "<option".($nodeid == $nid ? ' selected' : '')." value='$nid'>$nname</option>\n"; 1042 my %row = ( 1043 selme => ($nodeid == $nid), 1044 nodeid => $nid, 1045 nodename => $nname, 1046 ); 1047 push (@nodelist, \%row); 1048 } 1049 $page->param(nodelist => \@nodelist); 1050 $nodes .= "</select>\n"; 1051 $html =~ s/\$\$NODE\$\$/$nodes/; 1052 } else { 1053 if ($data[2] eq 'fr' || $data[2] eq 'bi') { 1024 ##fixme: arguably a bug that presence of a nodeid implies it can be changed.. 1025 # but except for manual database changes, only the two types fr and bi can 1026 # (currently) have a nodeid set in the first place. 1027 if ($IPDBacl{$authuser} =~ /c/) { 1054 1028 $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id"); 1055 $sth->execute () or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";1056 my $nodes = "<select name=node>\n<option value=>--</option>\n";1029 $sth->execute; 1030 my @nodelist; 1057 1031 while (my ($nid,$nname) = $sth->fetchrow_array()) { 1058 $nodes .= "<option value='$nid'>$nname</option>\n"; 1032 my %row = ( 1033 selme => ($nodeid == $nid), 1034 nodeid => $nid, 1035 nodename => $nname, 1036 ); 1037 push (@nodelist, \%row); 1059 1038 } 1060 $nodes .= "</select>\n"; 1061 $html =~ s/\$\$NODE\$\$/$nodes/; 1062 } else { 1063 $html =~ s|\$\$NODE\$\$|N/A|; 1039 $page->param(nodelist => \@nodelist); 1064 1040 } 1065 1041 } 1066 1042 ## end node hack 1067 $html =~ s/\$\$CITY\$\$/<input type=text name=city value="$data[3]">/g; 1068 $html =~ s/\$\$CIRCID\$\$/<input type="text" name="circid" value="$data[4]" maxlength=64 size=64 class="regular">/g; 1069 $html =~ s/\$\$DESC\$\$/<input type="text" name="desc" value="$data[5]" maxlength=64 size=64 class="regular">/g; 1070 $html =~ s|\$\$NOTES\$\$|<textarea rows="8" cols="64" name="notes" class="regular">$data[6]</textarea>|g; 1071 } else { 1072 ## node hack 1073 if ($data[2] eq 'fr' || $data[2] eq 'bi') { 1074 $sth = $ip_dbh->prepare("SELECT node_name FROM nodes INNER JOIN noderef". 1075 " ON nodes.node_id=noderef.node_id WHERE noderef.block='$webvar{block}'"); 1076 $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n"; 1077 my ($node) = $sth->fetchrow_array; 1078 $html =~ s/\$\$NODE\$\$/$node/; 1079 } else { 1080 $html =~ s|\$\$NODE\$\$|N/A|; 1081 } 1082 ## end node hack 1083 $html =~ s/\$\$CUSTID\$\$/$data[1]/g; 1084 $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}/g; 1085 $html =~ s/\$\$CITY\$\$/$data[3]/g; 1086 $html =~ s/\$\$CIRCID\$\$/$data[4]/g; 1087 $html =~ s/\$\$DESC\$\$/$data[5]/g; 1088 $html =~ s/\$\$NOTES\$\$/$data[6]/g; 1089 } 1043 1090 1044 my ($lastmod,undef) = split /\s+/, $data[7]; 1091 1045 $page->param(lastmod => $lastmod); 1092 1046 1093 ## Hack time! SWIP isn't going to stay, so I'm not going to integrate it with ACLs. 1094 if ($data[2] =~ /.i/) { 1095 $html =~ s/\$\$SWIP\$\$/N\/A/; 1096 } else { 1097 my $tmp = (($data[10] eq 'n') ? '<input type=checkbox name=swip>' : 1098 '<input type=checkbox name=swip checked=yes>'); 1099 $html =~ s/\$\$SWIP\$\$/$tmp/; 1100 } 1101 1102 # Allows us to "correctly" colour backgrounds in table 1103 my $i=1; 1047 # not happy with the upside-down logic, but... 1048 $page->param(swipable => $data[2] !~ /.i/); 1049 $page->param(swip => $data[10] ne 'n'); 1104 1050 1105 1051 # Check to see if we can display sensitive data 1106 my $privdata = ''; 1107 $page->param(nocling => $IPDBacl{$authuser} =~ /s/); 1108 $page->param(privdata => $data[8]); 1109 1110 if ($IPDBacl{$authuser} =~ /s/) { 1111 $privdata = qq(<tr class="color).($i%2).qq("><td class=heading>Restricted data:</td>). 1112 qq(<td class=regular><textarea rows="3" cols="64" name="privdata" class="regular">). 1113 qq($data[8]</textarea></td></tr>\n); 1114 $i++; 1115 } 1116 $html =~ s/\$\$PRIVDATA\$\$/$privdata/g; 1117 1118 # More ACL trickery - we can live with forms that don't submit, 1119 # but we can't leave the extra table rows there, and we *really* 1120 # can't leave the submit buttons there. 1121 my $updok = ''; 1122 $page->param(maychange => $IPDBacl{$authuser} =~ /c/); 1123 if ($IPDBacl{$authuser} =~ /c/) { 1124 $updok = qq(<tr class="color).($i%2).qq("><td colspan=2><div class="center">). 1125 qq(<input type="submit" value=" Update this block " class="regular">). 1126 "</div></td></tr></form>\n"; 1127 $i++; 1128 } 1129 $html =~ s/\$\$UPDOK\$\$/$updok/g; 1130 1131 my $delok = ''; 1132 $page->param(maydel => $IPDBacl{$authuser} =~ /d/); 1133 if ($IPDBacl{$authuser} =~ /d/) { 1134 $delok = qq(<form method="POST" action="main.cgi"> 1135 <tr class="color).($i%2).qq("><td colspan=2 class="regular"><div class=center> 1136 <input type="hidden" name="action" value="delete"> 1137 <input type="hidden" name="block" value="$webvar{block}"> 1138 <input type="hidden" name="alloctype" value="$data[2]"> 1139 <input type=submit value=" Delete this block "> 1140 </div></td></tr>); 1141 } 1142 $html =~ s/\$\$DELOK\$\$/$delok/; 1143 1144 # print $html; 1052 $page->param(nocling => $IPDBacl{$authuser} =~ /s/); 1053 $page->param(privdata => $data[8]); 1054 1055 # ACL trickery - these two template booleans control the presence of all form/input tags 1056 $page->param(maychange => $IPDBacl{$authuser} =~ /c/); 1057 $page->param(maydel => $IPDBacl{$authuser} =~ /d/); 1145 1058 1146 1059 } # edit()
Note:
See TracChangeset
for help on using the changeset viewer.