Changeset 463


Ignore:
Timestamp:
08/05/10 17:34:29 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Validation nitpick fix in assign.tmpl - also fixes missing field
name on alloctype list. <headdesk>
Convert new assignment result page to template.
Add missing error handling, missing IP pool selection on confirm.tmpl
Create footer template object earlier to allow pushing bits into
it during processing
Prepare to move initial output further down execution to prepare for
proper error handling in subs
Fix probable bug introduced with r456 where the "Routing" type isn't
available when it should be. Maybe. Probably.
Error messages for sub insertAssign() and confirmAssign could arguably
be further moved into the templates, but the complexity of the template
would go *way* up with little or no benefit.
See #3.

Location:
branches/htmlform
Files:
1 added
4 edited

Legend:

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

    r461 r463  
    5656
    5757my $header = HTML::Template->new(filename => "header.tmpl");
     58my $footer = HTML::Template->new(filename => "footer.tmpl");
     59
    5860$header->param(version => $IPDB::VERSION);
    5961$header->param(addperm => $IPDBacl{$authuser} =~ /a/);
     
    183185#       if $IPDBacl{$authuser} =~ /A/;
    184186
     187## Do all our printing here so we can generate errors and stick them into the slots in the templates.
     188
     189# can't do this yet, too many blowups
     190#print "Content-type: text/html\n\n", $header->output;
     191
    185192print $page->output;
    186193
    187 # We print the footer here, so we don't have to do it elsewhere.
    188 my $footer = HTML::Template->new(filename => "footer.tmpl");
    189194# include the admin tools link in the output?
    190195$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
     
    639644    # could arguably include routing (500) in the list, but ATM it doesn't
    640645    # make sense, and in any case that shouldn't be structurally possible here.
    641     $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 order by listorder");
     646    $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder <= 500 order by listorder");
    642647    $sth->execute;
    643648    my @typelist;
     
    706711    $sth->execute;
    707712    my $optionlist;
    708     while (my @data = $sth->fetchrow_array) {
     713
     714    my @poollist;
     715    while (my ($poolcit,$poolblock,$poolfree) = $sth->fetchrow_array) {
    709716      # city,pool cidr,free IP count
    710       if ($data[2] > 0) {
    711         $optionlist .= "<option value='$data[1]'>$data[1] [$data[2] free IP(s)] in $data[0]</option>\n";
     717      if ($poolfree > 0) {
     718        my %row = (poolcit => $poolcit, poolblock => $poolblock, poolfree => $poolfree);
     719        push (@poollist, \%row);
    712720      }
    713721    }
     722    $page->param(staticip => 1);
     723    $page->param(poollist => \@poollist);
    714724    $cidr = "Single static IP";
    715     $alloc_from = "<select name=alloc_from>".$optionlist."</select>\n";
     725##fixme:  need to handle "no available pools"
    716726
    717727  } else { # end show pool options
     
    723733
    724734      if (!$webvar{maskbits}) {
    725         printError("Please specify a CIDR mask length.");
     735        $page->param(err => "Please specify a CIDR mask length.");
    726736        return;
    727737      }
     
    782792      my @data = $sth->fetchrow_array();
    783793      if ($data[0] eq "") {
    784         printError($failmsg);
     794        $page->param(err => $failmsg);
    785795        return;
    786796      }
     
    788798    } # check for freeblocks assignment or IPDB-controlled assignment
    789799
    790 ##fixme:  HTML must be removed from script!
    791     $alloc_from = qq($cidr<input type=hidden name=alloc_from value="$cidr">);
     800    $alloc_from = "$cidr";
    792801
    793802    # If the block to be allocated is smaller than the one we found,
     
    860869  # successful netblock allocation, the IP allocated for static
    861870  # IP, or the error message if an error occurred.
     871
    862872  my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
    863873        $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
     
    867877    if ($webvar{alloctype} =~ /^.i$/) {
    868878      $msg =~ s|/32||;
    869       print qq(<div class="center"><div class="heading">The IP $msg has been allocated to customer $webvar{custid}</div>).
    870         ( ($webvar{alloctype} eq 'di' && $webvar{billinguser}) ?
    871                 qq(<div><a href="https://billing.example.com/radius.pl?).
    872                 "action=new_radius_user&custid=$webvar{custid}&userid=$webvar{billinguser}".
    873                 qq(&ipdb=1&ip=$msg">Add this IP to RADIUS user table</a></div>)
    874         : "</div>");
     879      $page->param(staticip => $msg);
     880      $page->param(custid => $webvar{custid});
     881      $page->param(billinguser => $webvar{billinguser});
    875882      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
    876883        "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
     
    878885    } else {
    879886      my $netblock = new NetAddr::IP $webvar{fullcidr};
    880       print qq(<div class="center"><div class="heading">The block $webvar{fullcidr} was ).
    881         "sucessfully added as: $disp_alloctypes{$webvar{alloctype}}</div>".
    882         ( ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) ?
    883                 qq(<div><a href="https://billing.example.com/radius.pl?).
    884                 "action=new_radius_user&custid=$webvar{custid}&userid=$webvar{billinguser}".
    885                 "&route_subnet=".$netblock->addr."&subnet_slash=".$netblock->masklen.
    886                 "&include_routed_subnet=1&ipdb=1".
    887                 qq(">Add this netblock to RADIUS user table</a></div>)
    888         : "</div>");
     887      $page->param(fullcidr => $webvar{fullcidr});
     888      $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
     889      $page->param(custid => $webvar{custid});
     890      if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
     891        $page->param(billinguser => $webvar{billinguser});
     892        $page->param(custid => $webvar{custid});
     893        $page->param(netaddr => $netblock->addr);
     894        $page->param(masklen => $netblock->masklen);
     895      }
    889896      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
    890897        "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
     
    896903    syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
    897904        "'$webvar{alloctype}' by $authuser failed: '$msg'";
    898     printError("Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
     905    $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
    899906        " failed:<br>\n$msg\n");
    900907  }
     
    14071414
    14081415  # We print the footer here, so we don't have to do it elsewhere.
    1409   my $footer = HTML::Template->new(filename => "footer.tmpl");
    14101416  # include the admin tools link in the output?
    14111417  $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
  • branches/htmlform/ipdb.css

    r461 r463  
    44        padding: 0px;
    55        margin: 0px;
     6}
     7
     8#debug {
     9        background-color: #990066;
     10        padding: 2px;
    611}
    712
     
    176181}
    177182
     183.err {
     184        text-align: center;
     185        font-size: 100%;
     186}
     187
    178188.red {
    179189        font-weight: bold;
  • branches/htmlform/templates/assign.tmpl

    r460 r463  
    3737<TMPL_VAR NAME=fbdisptype><input type="hidden" name="alloctype" value="<TMPL_VAR NAME=type>">
    3838<TMPL_ELSE>
    39 <select>
     39<select name="alloctype">
    4040<TMPL_LOOP name=typelist>
    4141        <option value="<TMPL_VAR NAME=tval>"<TMPL_VAR NAME=sel>><TMPL_VAR NAME=type></option></TMPL_LOOP>
  • branches/htmlform/templates/confirm.tmpl

    r461 r463  
     1<TMPL_IF err>
     2<div class="err">
     3<p><TMPL_VAR NAME=err></p>
     4<input type="button" value="Back" onclick="history.go(-1)">
     5</div>
     6<TMPL_ELSE>
    17<div class="heading">Please confirm</div>
    28<div class="indent">
     9
     10<form method="POST" action="main.cgi" class="regular">
     11<fieldset><legend></legend>
    312<table class="regular" cellspacing="1" cellpadding="1">
    413
     
    1019<tr class="row1">
    1120<td>Block allocation is taken from:</td>
     21<TMPL_IF staticip>
     22<td>
     23<select name="alloc_from">
     24<TMPL_LOOP name=poollist>       <option value="<TMPL_VAR NAME=poolblock>"><TMPL_VAR NAME=poolblock> [<TMPL_VAR NAME=poolfree>] free IP(s) in <TMPL_VAR NAME=poolcit></option>
     25</TMPL_LOOP></select>
     26</td>
     27<TMPL_ELSE>
    1228<td><TMPL_VAR NAME=alloc_from></td>
     29</TMPL_IF>
    1330</tr>
    1431
     
    5875<tr class="<TMPL_IF privdata>row0<TMPL_ELSE>row1</TMPL_IF>">
    5976<td class="center" colspan="2">
    60 <form method="POST" action="main.cgi" class="regular">
    61 <fieldset><legend></legend>
     77<TMPL_UNLESS poollist><input type="hidden" name="alloc_from" value="<TMPL_VAR NAME=alloc_from>"></TMPL_UNLESS>
    6278<input type="hidden" name="fullcidr" value="<TMPL_VAR NAME=cidr>">
    6379<input type="hidden" name="city" value="<TMPL_VAR NAME=city>">
     
    7692<input type="hidden" name="action" value="<TMPL_VAR NAME=action>">
    7793<input type="button" value="Back" onclick="history.go(-1)"><input type="submit" value="Confirm">
     94</td></tr>
     95</table>
    7896</fieldset>
    7997</form>
    80 </td></tr>
    81 </table>
    8298</div>
     99</TMPL_IF>
Note: See TracChangeset for help on using the changeset viewer.