Changeset 397 for trunk/cgi-bin


Ignore:
Timestamp:
05/10/10 17:33:13 (14 years ago)
Author:
Kris Deugau
Message:

/trunk

Merge basic node-tracking from r393:396 into trunk. See #13.

Location:
trunk/cgi-bin
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r371 r397  
    292292# Returns a success code and optional error message.
    293293sub allocateBlock {
    294   my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata) = @_;
     294  my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata,$nodeid) = @_;
    295295
    296296  my $cidr = new NetAddr::IP $_[1];
     
    333333        " where ip='$cidr'");
    334334      $sth->execute;
     335# node hack
     336      if ($nodeid && $nodeid ne '') {
     337        $sth = $dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
     338        $sth->execute("$cidr",$nodeid);
     339      }
     340# end node hack
    335341      $dbh->commit;
    336342    };
     
    393399        } # routing vs non-routing netblock
    394400
     401# node hack
     402      if ($nodeid && $nodeid ne '') {
     403        $sth = $dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
     404        $sth->execute("$cidr",$nodeid);
     405      }
     406# end node hack
    395407        $dbh->commit;
    396408      }; # end of eval
     
    497509        } # done with netblock alloctype != rm
    498510
     511# node hack
     512      if ($nodeid && $nodeid ne '') {
     513        $sth = $dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
     514        $sth->execute("$cidr",$nodeid);
     515      }
     516# end node hack
    499517        $dbh->commit;
    500518      }; # end eval
  • trunk/cgi-bin/ipdb.psql

    r388 r397  
    213213        "auto" character(1) DEFAULT 'y'
    214214);
     215
     216-- Network nodes - allows finding customers affected by a broken <x> quickly
     217CREATE TABLE noderef (
     218    block inet NOT NULL PRIMARY KEY,
     219    node_id integer
     220);
     221
     222CREATE TABLE nodes (
     223    node_id serial NOT NULL PRIMARY KEY,
     224    node_type character varying(2),
     225    node_name character varying(40),
     226    node_ip inet
     227);
  • trunk/cgi-bin/main.cgi

    r380 r397  
    126126elsif($webvar{action} eq 'finaldelete') {
    127127  finalDelete();
     128}
     129elsif ($webvar{action} eq 'nodesearch') {
     130  open HTML, "<../nodesearch.html";
     131  my $html = join('',<HTML>);
     132  close HTML;
     133
     134  $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
     135  $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
     136  my $nodes = '';
     137  while (my ($nid,$nname) = $sth->fetchrow_array()) {
     138    $nodes .= "<option value='$nid'>$nname</option>\n";
     139  }
     140  $html =~ s/\$\$NODELIST\$\$/$nodes/;
     141
     142  print $html;
    128143}
    129144
     
    613628  }
    614629  $html =~ s|\$\$ALLCITIES\$\$|$cities|g;
     630
     631## node hack
     632  $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
     633  $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
     634  my $nodes = '';
     635  while (my ($nid,$nname) = $sth->fetchrow_array()) {
     636    $nodes .= "<option value='$nid'>$nname</option>\n";
     637  }
     638  $html =~ s/\$\$NODELIST\$\$/$nodes/;
     639## end node hack
    615640
    616641  my $i = 0;
     
    779804  close HTML;
    780805
     806## node hack
     807  if ($webvar{node} && $webvar{node} ne '-') {
     808    $sth = $ip_dbh->prepare("SELECT node_name FROM nodes WHERE node_id=?");
     809    $sth->execute($webvar{node});
     810    my ($nodename) = $sth->fetchrow_array();
     811    $html =~ s/\$\$NODENAME\$\$/$nodename/;
     812    $html =~ s/\$\$NODEID\$\$/$webvar{node}/;
     813  } else {
     814    $html =~ s/\$\$NODENAME\$\$//;
     815    $html =~ s/\$\$NODEID\$\$//;
     816  }
     817## end node hack
     818
    781819### gotta fix this in final
    782820  # Stick in customer info as necessary - if it's blank, it just ends
     
    841879  my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
    842880        $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
    843         $webvar{circid}, $webvar{privdata});
     881        $webvar{circid}, $webvar{privdata}, $webvar{node});
    844882
    845883  if ($code eq 'OK') {
     
    10061044      $html =~ s/\$\$TYPESELECT\$\$/$disp_alloctypes{$data[2]}<input type=hidden name=alloctype value="$data[2]">/g;
    10071045    }
     1046## node hack
     1047  $sth = $ip_dbh->prepare("SELECT node_id FROM noderef WHERE block='$webvar{block}'");
     1048  $sth->execute;
     1049  my ($nodeid) = $sth->fetchrow_array();
     1050  if ($nodeid) {
     1051    $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
     1052    $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
     1053    my $nodes = "<select name=node>\n";
     1054    while (my ($nid,$nname) = $sth->fetchrow_array()) {
     1055      $nodes .= "<option".($nodeid == $nid ? ' selected' : '')." value='$nid'>$nname</option>\n";
     1056    }
     1057    $nodes .= "</select>\n";
     1058    $html =~ s/\$\$NODE\$\$/$nodes/;
     1059  } else {
     1060    if ($data[2] eq 'fr' || $data[2] eq 'bi') {
     1061      $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
     1062      $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
     1063      my $nodes = "<select name=node>\n<option value=>--</option>\n";
     1064      while (my ($nid,$nname) = $sth->fetchrow_array()) {
     1065        $nodes .= "<option value='$nid'>$nname</option>\n";
     1066      }
     1067      $nodes .= "</select>\n";
     1068      $html =~ s/\$\$NODE\$\$/$nodes/;
     1069    } else {
     1070      $html =~ s|\$\$NODE\$\$|N/A|;
     1071    }
     1072  }
     1073## end node hack
    10081074    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
    10091075    $html =~ s/\$\$CITY\$\$/<input type=text name=city value="$data[3]">/g;
     
    10121078    $html =~ s|\$\$NOTES\$\$|<textarea rows="8" cols="64" name="notes" class="regular">$data[6]</textarea>|g;
    10131079  } else {
     1080## node hack
     1081    if ($data[2] eq 'fr' || $data[2] eq 'bi') {
     1082      $sth = $ip_dbh->prepare("SELECT node_name FROM nodes INNER JOIN noderef".
     1083        " ON nodes.node_id=noderef.node_id WHERE noderef.block='$webvar{block}'");
     1084      $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
     1085      my ($node) = $sth->fetchrow_array;
     1086      $html =~ s/\$\$NODE\$\$/$node/;
     1087    } else {
     1088      $html =~ s|\$\$NODE\$\$|N/A|;
     1089    }
     1090## end node hack
    10141091    $html =~ s/\$\$CUSTID\$\$/$data[1]/g;
    10151092    $html =~ s/\$\$OLDCUSTID\$\$/$data[9]/g;
     
    11101187    $sth = $ip_dbh->prepare($sql);
    11111188    $sth->execute;
     1189## node hack
     1190    if ($webvar{node}) {
     1191      $ip_dbh->do("DELETE FROM noderef WHERE block='$webvar{block}'");
     1192      $sth = $ip_dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
     1193      $sth->execute($webvar{block},$webvar{node});
     1194    }
     1195## end node hack
    11121196    $ip_dbh->commit;
    11131197  };
  • trunk/cgi-bin/search.cgi

    r382 r397  
    187187    printError "No matches found.  Try eliminating one of the criteria,".
    188188        " or making one or more criteria more general.";
     189  } else {
     190    # Add the limit/offset clauses
     191    $sql .= " order by cidr";
     192    $sql .= " limit $RESULTS_PER_PAGE offset $offset" if $RESULTS_PER_PAGE != 0;
     193    # And tell the user.
     194    print "<div class=heading>Searching...............</div>\n";
     195    queryResults($sql, $webvar{page}, $count);
     196  }
     197
     198} elsif ($webvar{stype} eq 'n') {
     199  # Node search.
     200
     201  my $sql = "SELECT cidr,custid,type,city,description FROM searchme".
     202        " WHERE cidr IN (SELECT block FROM noderef WHERE node_id=$webvar{node})";
     203
     204  # Find the offset for multipage results
     205  my $offset = ($webvar{page}-1)*$RESULTS_PER_PAGE;
     206
     207  # Find out how many rows the "core" query will return.
     208  my $count = countRows($sql);
     209
     210  if ($count == 0) {
     211    printError "No customers currently listed as connected through this node.";
    189212  } else {
    190213    # Add the limit/offset clauses
Note: See TracChangeset for help on using the changeset viewer.