Changeset 470


Ignore:
Timestamp:
08/17/10 15:32:16 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlfrom

Block edit page should be complete and even valid.
Still has some slight fishyness with column edges not aligned due
to stupid "can't start a form in between table rows" validation spec
idiocy. (<table><form><tr>...</tr></form><form><tr>...</tr></form></table>
is not valid for strict HTML 4.01.)
See #3.

Location:
branches/htmlform
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/main.cgi

    r469 r470  
    959959  # Two cases:  block is a netblock, or block is a static IP from a pool
    960960  # 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
    961962  if ($webvar{block} =~ /\/32$/) {
    962963    $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";
     
    972973  # Clean up extra whitespace on alloc type
    973974  $data[2] =~ s/\s//;
    974 
    975   open (HTML, "../editDisplay.html")
    976         or croak "Could not open editDisplay.html :$!";
    977   my $html = join('', <HTML>);
    978975
    979976  # We can't let the city be changed here;  this block is a part of
     
    983980# Needs thinking.  Have to allow changes to city to correct errors, no?
    984981# 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
    999993##fixme The check here should be built from the database
    1000994# 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 => [
    1004998                { selme => ($data[2] eq 'me'), type => "me", disptype => "Dialup netblock" },
    1005999                { selme => ($data[2] eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
     
    10111005                ]
    10121006        );
    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
    10281012## 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
    10291023##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/) {
    10541028      $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;
    10571031      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);
    10591038      }
    1060       $nodes .= "</select>\n";
    1061       $html =~ s/\$\$NODE\$\$/$nodes/;
    1062     } else {
    1063       $html =~ s|\$\$NODE\$\$|N/A|;
     1039      $page->param(nodelist => \@nodelist);
    10641040    }
    10651041  }
    10661042## 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
    10901044  my ($lastmod,undef) = split /\s+/, $data[7];
    10911045  $page->param(lastmod => $lastmod);
    10921046
    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');
    11041050
    11051051  # 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/);
    11451058
    11461059} # edit()
  • branches/htmlform/templates/edit.tmpl

    r469 r470  
    22<div class="heading">Edit the information below</div>
    33
    4 <!-- table class="indent" size="33%" cellspacing=1 bgcolor="black" -->
    5 
    6 <table>
     4<table cellpadding="0" cellspacing="0">
    75<tr>
    86<td>
     
    1513</TMPL_IF>
    1614
    17 <table cellspacing=1>
     15<table cellspacing="1">
    1816
    1917<tr class="row0">
     
    4341<TMPL_ELSE>
    4442<TMPL_VAR NAME=disptype>
     43<input type="hidden" name="alloctype" value="<TMPL_VAR NAME=type>">
    4544</TMPL_IF>
    4645</td>
     
    5857</select>
    5958<TMPL_ELSE>
    60 <TMPL_VAR NAME=nodename>
     59<TMPL_IF nodename><TMPL_VAR NAME=nodename><TMPL_ELSE>N/A</TMPL_IF>
    6160</TMPL_IF>
    6261<TMPL_ELSE>
     
    8079<td class=heading>SWIPed?:</td>
    8180<td class=regular>
     81<TMPL_IF swipable>
    8282<TMPL_IF maychange>
    83 <input type=checkbox name=swip <TMPL_IF swip>checked=yes</TMPL_IF>>
     83<input type="checkbox" name="swip" <TMPL_IF swip>checked="checked"</TMPL_IF>>
    8484<TMPL_ELSE>
    8585<TMPL_IF swip>Yes<TMPL_ELSE>No</TMPL_IF>
     86</TMPL_IF>
     87<TMPL_ELSE>
     88N/A
    8689</TMPL_IF>
    8790</td>
     
    127130<TMPL_IF nocling>
    128131<tr class="row0">
    129 <td class=heading>Restricted data:</td>
    130 <td class=regular>
     132<td class="heading" valign="top">Restricted data:</td>
     133<td class="regular">
    131134<TMPL_IF maychange>
    132135<textarea rows="3" cols="64" name="privdata" class="regular"><TMPL_VAR NAME=privdata></textarea>
     
    137140</tr>
    138141</TMPL_IF>
    139 </table>
    140142
    141143<TMPL_IF maychange>
    142 <div class="row0"><input type="submit" value=" Update this block " class="regular"></div>
     144<tr class="row<TMPL_IF nocling>1<TMPL_ELSE>0</TMPL_IF>">
     145<td colspan="2" class="center">
     146<input type="submit" value=" Update this block " class="regular">
     147</td>
     148</tr>
     149</TMPL_IF>
     150</table>
     151<TMPL_IF maychange>
    143152</fieldset>
    144153</form>
     
    146155
    147156<TMPL_IF maydel>
     157</td></tr>
     158<tr><td class="center">
    148159<form method="POST" action="main.cgi">
    149 <div class="row1">
     160<fieldset><legend></legend>
     161<div class="row<TMPL_IF nocling><TMPL_IF maychange>0<TMPL_ELSE>1</TMPL_IF><TMPL_ELSE><TMPL_IF maychange>1<TMPL_ELSE>0</TMPL_IF></TMPL_IF>">
    150162<input type="hidden" name="action" value="delete">
    151 <input type="hidden" name="block" value="1.2.14.24/29">
    152 <input type="hidden" name="alloctype" value="me">
     163<input type="hidden" name="block" value="<TMPL_VAR NAME=block>">
     164<input type="hidden" name="alloctype" value="<TMPL_VAR NAME=type>">
    153165<input type=submit value=" Delete this block ">
    154166</div>
     167</fieldset>
    155168</form>
    156169</TMPL_IF>
     170
    157171</td>
    158172</tr>
Note: See TracChangeset for help on using the changeset viewer.