query( $sql );
// delete the request fields (which are inserted when requested)
$sql = "DELETE FROM addresses WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1";
$loc_db->query( $sql );
// if the allocation is a block of addresses
if ($type == "block") {
// the node id and email is found by just selecting the info
// from the nodes table
$sql = "SELECT id as node_id, email FROM nodes WHERE id='$node_interface'";
// if its a router allocation
} else {
// the node id and email are found by joining the interface table
// with nodes table, and then searching
$sql = "SELECT nodes.id as node_id, nodes.email FROM nodes, interfaces WHERE ((interfaces.node = nodes.id) AND (interfaces.int_id='$node_interface'))";
}
$loc_db->query( $sql );
$loc_db->next_record();
// allocate some of the valeus used in the email
$email = $loc_db->f("email");
$owner = $loc_db->f("owner");
$node_id = $loc_db->f("node_id");
// the final details for email
$sql = "SELECT subnet, area FROM addresses WHERE address = '" . $address . "'";
$loc_db->query( $sql );
$loc_db->next_record();
// assign these last details to variables, for neatness' sake
$subnet = $loc_db->f("subnet");
$area = $loc_db->f("area");
// send an email to the requestor to let them know they have been
// allocated an address
email_assign_ip($email, $owner, $node_id, $address, $subnet, $area);
return true;
} // end allocate_ip()
/*
* delete_request()
*
* takes 2 varibles containing the node/interface and type values,
* of the requests that are to be deleted.
*
* Usage: $node_interface - the node or interface ID the request
* belongs to
* $type - whether the allocation is a block or
* router allocation
*
* Returns: true or false
*
*/
function delete_request($node_interface, $type) {
// create a DB class
$loc_db = new locDatabase;
// delete a single request where the node/interface and type match
// its possible that there will be more than one match, but the
// LIMIT 1 makes it stop after 1
$sql = "DELETE FROM addresses WHERE ((node_interface='$node_interface') AND (address IS NULL) AND (type='$type')) LIMIT 1";
$loc_db->query( $sql );
// function successful
return true;
} // end delete_request()
/*
* delete_assignment()
*
* takes the address that is to be cleared of its allocation, and
* changes its node/interface value to NULL, freeing the address up
*
* Usage: $address - the address that is to be cleared
*
* Returns: true or false
*
*/
function delete_assignment($address) {
// new DB class
$loc_db = new locDatabase;
// Change node/interface to null for the designated address
$sql = "UPDATE addresses SET node_interface=NULL WHERE (address='$address')";
$loc_db->query( $sql );
// function successful
return true;
} // end delete-assignment()
/*
* flush_assignments()
*
* takes 4 variables and depending on the values, deletes a nodes
* block and/or router and/or backbone allocations
*
* Usage: $node_id - the ID of the node to have its allocations cleared
* $flush_blocks - (true/false) delete the block allocations?
* $flush_router - (true/false) delete the router allocations?
* $flush_backbone - (true/false) delete the backbone allocations?
*
* Returns: true or false
*
*/
function flush_assignments($node_id, $flush_blocks, $flush_router) {
// create the DB classes
$loc_db = new locDatabase;
$loc_db_2 = new locDatabase;
// if the block allocations are to be cleared
if ($flush_blocks) {
// remove the allocations already made
$sql = "UPDATE addresses SET node_interface=NULL WHERE (node_interface='$node_id') AND (address IS NOT NULL)";
$loc_db->query( $sql );
// remove the requests that havent been fullfilled yet
$sql = "DELETE FROM addresses WHERE node_interface='" . $node_id. "'";
$loc_db->query( $sql );
}
// if the router allocations are to be deleted
if ($flush_router) {
// 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 addresses SET node_interface=NULL WHERE ((node_interface='" . $loc_db_2->f("int_id") . "') AND (address IS NOT NULL) AND (type='router'))";
$loc_db_2->query( $sql );
// delete the unfulfilled requests
$sql = "DELETE FROM addresses WHERE ((node_interface='" . $loc_db->f("int_id") . "') AND (type='router'))";
$loc_db_2->query( $sql );
} // end while
} // end if
} // end flush_assignments()
function request_ip_block($node_id) {
GLOBAL $opt_maintainer_email;
GLOBAL $opt_ip_allocater;
GLOBAL $err_message;
GLOBAL $success_message;
$loc_db = new locDatabase;
$sql = "SELECT area from nodes WHERE id='$node_id'";
$loc_db->query( $sql );
$loc_db->next_record();
$area = $loc_db->f("area");
// Setup the SQL Statement
$sql = "INSERT INTO addresses(node_interface, type, area) VALUES('$node_id','block', $area)";
// Run the query
$loc_db->query( $sql );
email_request_ip($opt_ip_allocater, $node_id, "block", $area);
$_SESSION["msg"] = "ip block successfully requested";
$_SESSION["msg_type"] = 0;
return true;
}
function request_ip_router($int_id) {
GLOBAL $opt_maintainer_email;
GLOBAL $opt_ip_allocater;
GLOBAL $err_message;
GLOBAL $success_message;
$loc_db = new locDatabase;
$sql = "SELECT id, area, 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 (get_ip_router($int_id) != "") {
//error
$err_message = "error. Interfaces may only have one IP address";
return false;
} else {
// Setup the SQL Statement
$sql = "INSERT INTO addresses(node_interface, type, area) VALUES('$int_id', 'router', $area)";
// 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"), "router", $area);
$success_message = "routing ip successfully requested";
return true;
}
}
function get_ip_block($node_id) {
$loc_db = new locDatabase;
$sql = "SELECT * from addresses WHERE ((node_interface='$node_id') AND (type='block'))";
$loc_db->query( $sql );
$ip_block = "";
while ($loc_db->next_record()) {
if ($loc_db->f("address") == "") {
$ip_block .= "Request Recorded - awaiting authorisation
";
} else {
$ip_block .= $loc_db->f("address") . "/" . $loc_db->f("subnet") . "
";
}
}
if ($ip_block == "") {
$ip_block = "none";
}
return $ip_block;
}
function get_ip_router($int_id) {
$loc_db = new locDatabase;
$sql = "SELECT * from addresses WHERE ((node_interface='$int_id') AND (type='router'))";
$loc_db->query( $sql );
$loc_db->next_record();
if ($loc_db->num_rows() == 0) {
$ip_router = "";
} elseif ($loc_db->f("address") == "") {
$ip_router = "Request Recorded - awaiting authorisation";
} else {
$ip_router = $loc_db->f("address") . "/" . $loc_db->f("subnet");
}
return $ip_router;
}
function area_exist($area_id) {
GLOBAL $opt_area;
return array_key_exists($area_id, $opt_area);
}
function get_area_name($area_id) {
GLOBAL $opt_area;
return $opt_area[$area_id]["name"];
}
function get_area_list_url($area_id) {
GLOBAL $opt_area;
return $opt_area[$area_id]["mailing_list"];
}
function get_area_description($area_id) {
GLOBAL $opt_area;
return $opt_area[$area_id]["description"];
}
}
?>