55 |
|
|
56 |
// find the record that contains the specified addess and set the |
// find the record that contains the specified addess and set the |
57 |
// node_interface field to an appropriate value |
// node_interface field to an appropriate value |
58 |
$sql = "UPDATE ip_assignments SET node_interface='$node_interface' WHERE ((address='$address'))"; |
$sql = "UPDATE addresses SET node_interface='$node_interface' WHERE ((address='$address'))"; |
59 |
|
|
60 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
61 |
|
|
62 |
// delete the request fields (which are inserted when requested) |
// delete the request fields (which are inserted when requested) |
63 |
$sql = "DELETE FROM ip_assignments WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1"; |
$sql = "DELETE FROM addresses WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1"; |
64 |
|
|
65 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
66 |
|
|
90 |
$node_id = $loc_db->f("node_id"); |
$node_id = $loc_db->f("node_id"); |
91 |
|
|
92 |
// the final details for email |
// the final details for email |
93 |
$sql = "SELECT subnet, area FROM ip_assignments WHERE address = '" . $address . "'"; |
$sql = "SELECT subnet, area FROM addresses WHERE address = '" . $address . "'"; |
94 |
|
|
95 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
96 |
|
|
131 |
// delete a single request where the node/interface and type match |
// delete a single request where the node/interface and type match |
132 |
// its possible that there will be more than one match, but the |
// its possible that there will be more than one match, but the |
133 |
// LIMIT 1 makes it stop after 1 |
// LIMIT 1 makes it stop after 1 |
134 |
$sql = "DELETE FROM ip_assignments WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1"; |
$sql = "DELETE FROM addresses WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1"; |
135 |
|
|
136 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
137 |
|
|
158 |
$loc_db = new locDatabase; |
$loc_db = new locDatabase; |
159 |
|
|
160 |
// Change node/interface to null for the designated address |
// Change node/interface to null for the designated address |
161 |
$sql = "UPDATE ip_assignments SET node_interface=NULL WHERE (address='$address')"; |
$sql = "UPDATE addresses SET node_interface=NULL WHERE (address='$address')"; |
162 |
|
|
163 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
164 |
|
|
182 |
* |
* |
183 |
*/ |
*/ |
184 |
|
|
185 |
function flush_assignments($node_id, $flush_blocks, $flush_router, $flush_backbone) { |
function flush_assignments($node_id, $flush_blocks, $flush_router) { |
186 |
|
|
187 |
// create the DB classes |
// create the DB classes |
188 |
$loc_db = new locDatabase; |
$loc_db = new locDatabase; |
192 |
if ($flush_blocks) { |
if ($flush_blocks) { |
193 |
|
|
194 |
// remove the allocations already made |
// remove the allocations already made |
195 |
$sql = "UPDATE ip_assignments SET node_interface=NULL WHERE (node_interface='$node_id') AND (address IS NOT NULL)"; |
$sql = "UPDATE addresses SET node_interface=NULL WHERE (node_interface='$node_id') AND (address IS NOT NULL)"; |
196 |
|
|
197 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
198 |
|
|
199 |
// remove the requests that havent been fullfilled yet |
// remove the requests that havent been fullfilled yet |
200 |
$sql = "DELETE FROM ip_assignments WHERE node_interface='" . $node_id. "'"; |
$sql = "DELETE FROM addresses WHERE node_interface='" . $node_id. "'"; |
201 |
|
|
202 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
203 |
|
|
216 |
while ($loc_db->next_record()) { |
while ($loc_db->next_record()) { |
217 |
|
|
218 |
// delete the allocations already made |
// delete the allocations already made |
219 |
$sql = "UPDATE ip_assignments SET node_interface=NULL WHERE ((node_interface='" . $loc_db_2->f("int_id") . "') AND (address IS NOT NULL) AND (type='router'))"; |
$sql = "UPDATE addresses SET node_interface=NULL WHERE ((node_interface='" . $loc_db_2->f("int_id") . "') AND (address IS NOT NULL) AND (type='router'))"; |
220 |
|
|
221 |
$loc_db_2->query( $sql ); |
$loc_db_2->query( $sql ); |
222 |
|
|
223 |
// delete the unfulfilled requests |
// delete the unfulfilled requests |
224 |
$sql = "DELETE FROM ip_assignments WHERE ((node_interface='" . $loc_db->f("int_id") . "') AND (type='router'))"; |
$sql = "DELETE FROM addresses WHERE ((node_interface='" . $loc_db->f("int_id") . "') AND (type='router'))"; |
|
|
|
|
$loc_db_2->query( $sql ); |
|
|
|
|
|
} // end while |
|
|
|
|
|
} // end if |
|
|
|
|
|
// if the router allocations are to be deleted |
|
|
if ($flush_backbone) { |
|
|
|
|
|
// select all the interfaces from the node, since router |
|
|
// allocations are stored by interface, not node |
|
|
$sql = "SELECT * FROM interfaces WHERE (node='" . $node_id . "')"; |
|
|
|
|
|
$loc_db->query( $sql ); |
|
|
|
|
|
// for each interface |
|
|
while ($loc_db->next_record()) { |
|
|
|
|
|
// delete the allocations already made |
|
|
$sql = "UPDATE ip_assignments SET node_interface=NULL WHERE ((node_interface='" . $loc_db_2->f("int_id") . "') AND (address IS NOT NULL) AND (type='backbone'))"; |
|
|
|
|
|
$loc_db_2->query( $sql ); |
|
|
|
|
|
// delete the unfulfilled requests |
|
|
$sql = "DELETE FROM ip_assignments WHERE ((node_interface='" . $loc_db->f("int_id") . "') AND (type='backbone'))"; |
|
225 |
|
|
226 |
$loc_db_2->query( $sql ); |
$loc_db_2->query( $sql ); |
227 |
|
|
249 |
$area = $loc_db->f("area"); |
$area = $loc_db->f("area"); |
250 |
|
|
251 |
// Setup the SQL Statement |
// Setup the SQL Statement |
252 |
$sql = "INSERT INTO ip_assignments(node_interface, type, area) VALUES('$node_id','block', $area)"; |
$sql = "INSERT INTO addresses(node_interface, type, area) VALUES('$node_id','block', $area)"; |
253 |
|
|
254 |
// Run the query |
// Run the query |
255 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
256 |
|
|
257 |
email_request_ip($opt_ip_allocater, $node_id, "block", $area); |
email_request_ip($opt_ip_allocater, $node_id, "block", $area); |
258 |
|
|
259 |
$success_message = "ip block successfully requested"; |
$_SESSION["msg"] = "ip block successfully requested"; |
260 |
|
$_SESSION["msg_type"] = 0; |
261 |
return true; |
return true; |
262 |
|
|
263 |
} |
} |
271 |
|
|
272 |
$loc_db = new locDatabase; |
$loc_db = new locDatabase; |
273 |
|
|
274 |
$sql = "SELECT id, area, ospf_mode from nodes, interfaces WHERE ((nodes.id = interfaces.node) AND (interfaces.int_id='$int_id'))"; |
$sql = "SELECT id, area, from nodes, interfaces WHERE ((nodes.id = interfaces.node) AND (interfaces.int_id='$int_id'))"; |
275 |
|
|
276 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
277 |
|
|
281 |
$mode = $loc_db->f("ospf_mode"); |
$mode = $loc_db->f("ospf_mode"); |
282 |
$node_id = $loc_db->f("id"); |
$node_id = $loc_db->f("id"); |
283 |
|
|
|
//if ($mode == "none") { |
|
|
|
|
|
//error |
|
|
//$err_message = "error. only routing nodes running OSPF may request routing addresses"; |
|
|
//return false; |
|
|
|
|
284 |
if (get_ip_router($int_id) != "") { |
if (get_ip_router($int_id) != "") { |
285 |
|
|
286 |
//error |
//error |
291 |
} else { |
} else { |
292 |
|
|
293 |
// Setup the SQL Statement |
// Setup the SQL Statement |
294 |
$sql = "INSERT INTO ip_assignments(node_interface, type, area) VALUES('$int_id', 'router', $area)"; |
$sql = "INSERT INTO addresses(node_interface, type, area) VALUES('$int_id', 'router', $area)"; |
295 |
|
|
296 |
// Run the query |
// Run the query |
297 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
310 |
} |
} |
311 |
} |
} |
312 |
|
|
|
function request_ip_backbone($int_id) { |
|
|
|
|
|
GLOBAL $opt_maintainer_email; |
|
|
GLOBAL $opt_ip_allocater; |
|
|
GLOBAL $err_message; |
|
|
GLOBAL $success_message; |
|
|
|
|
|
$loc_db = new locDatabase; |
|
|
|
|
|
$sql = "SELECT id, area, ospf_mode from nodes, interfaces WHERE ((nodes.id = interfaces.node) AND (interfaces.int_id='$int_id'))"; |
|
|
|
|
|
$loc_db->query( $sql ); |
|
|
|
|
|
$loc_db->next_record(); |
|
|
|
|
|
$area = $loc_db->f("area"); |
|
|
$mode = $loc_db->f("ospf_mode"); |
|
|
$node_id = $loc_db->f("id"); |
|
|
|
|
|
if ($mode == "none") { |
|
|
|
|
|
//error |
|
|
$err_message = "error. only routing nodes running OSPF may request backbone addresses"; |
|
|
|
|
|
return false; |
|
|
|
|
|
} elseif (get_ip_backbone($int_id) != "") { |
|
|
|
|
|
//error |
|
|
$err_message = "error. Interfaces may only have one IP address"; |
|
|
|
|
|
return false; |
|
|
|
|
|
} else { |
|
|
|
|
|
// Setup the SQL Statement |
|
|
$sql = "INSERT INTO ip_assignments(node_interface, type, area) VALUES('$int_id', 'backbone', 0)"; |
|
|
|
|
|
// Run the query |
|
|
$loc_db->query( $sql ); |
|
|
|
|
|
$sql = "SELECT node FROM interfaces WHERE int_id=" . $int_id; |
|
|
|
|
|
$loc_db->query( $sql ); |
|
|
|
|
|
$loc_db->next_record(); |
|
|
|
|
|
email_request_ip($opt_ip_allocater, $loc_db->f("node"), "backbone", 0); |
|
|
|
|
|
$success_message = "backbone ip successfully requested"; |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
313 |
function get_ip_block($node_id) { |
function get_ip_block($node_id) { |
314 |
|
|
315 |
$loc_db = new locDatabase; |
$loc_db = new locDatabase; |
316 |
|
|
317 |
$sql = "SELECT * from ip_assignments WHERE ((node_interface='$node_id') AND (type='block'))"; |
$sql = "SELECT * from addresses WHERE ((node_interface='$node_id') AND (type='block'))"; |
318 |
|
|
319 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
320 |
|
|
347 |
|
|
348 |
$loc_db = new locDatabase; |
$loc_db = new locDatabase; |
349 |
|
|
350 |
$sql = "SELECT * from ip_assignments WHERE ((node_interface='$int_id') AND (type='router'))"; |
$sql = "SELECT * from addresses WHERE ((node_interface='$int_id') AND (type='router'))"; |
351 |
|
|
352 |
$loc_db->query( $sql ); |
$loc_db->query( $sql ); |
353 |
|
|
369 |
|
|
370 |
return $ip_router; |
return $ip_router; |
371 |
} |
} |
|
|
|
|
function get_ip_backbone($int_id) { |
|
|
|
|
|
$loc_db = new locDatabase; |
|
|
|
|
|
$sql = "SELECT * from ip_assignments WHERE ((node_interface='$int_id') AND (type='backbone'))"; |
|
|
|
|
|
$loc_db->query( $sql ); |
|
|
|
|
|
$loc_db->next_record(); |
|
|
|
|
|
if ($loc_db->num_rows() == 0) { |
|
|
|
|
|
$ip_backbone = ""; |
|
|
|
|
|
} elseif ($loc_db->f("address") == "") { |
|
|
|
|
|
$ip_backbone = "Request Recorded - awaiting authorisation"; |
|
|
|
|
|
} else { |
|
|
|
|
|
$ip_backbone = $loc_db->f("address") . "/" . $loc_db->f("subnet"); |
|
|
|
|
|
} |
|
|
|
|
|
return $ip_backbone; |
|
|
} |
|
372 |
|
|
373 |
function area_exist($area_id) { |
function area_exist($area_id) { |
374 |
|
|
403 |
} |
} |
404 |
|
|
405 |
} |
} |
|
?> |
|
406 |
|
?> |