Id Name Address OS Serial Type Manage '; $class = 'row1'; $sql = "select * from hosts order by $order $sort"; $result = execsql($sql); while ($row = mysql_fetch_row($result)) { echo ' '.$row[0].' '.$row[1].' '.$row[2].' '.$row[3].' '.$row[4].' '.$row[5].' Services / Interfaces Edit Delete '; if ($class == 'row1') $class = 'row2'; else $class = 'row1'; } echo ' '; } function add() { global $submit, $name, $address, $os, $serial, $type; if ($submit == 'Cancel') { show(); } else if ($name != '' && $address != '') { $sql = "insert into hosts values(NULL, '$name', '$address', '$os', '$serial', '$type')"; if (execsql($sql)) { formSuccess('Host '.$name.' added.'); } } else { $action = "hosts/index.php"; $title = 'Add Host'; $rows = array(); $row = array('hidden', 'pagedest', '/hosts'); array_push($rows, $row); $row = array('hidden', 'task', 'add'); array_push($rows, $row); $row = array('text', "* Name", 'name', $name); array_push($rows, $row); $row = array('text', "* IP Address", 'address', $address); array_push($rows, $row); $row = array('text', "Operating Sys", 'os', $os); array_push($rows, $row); $row = array('text', "Serial No.", 'serial', $serial); array_push($rows, $row); $row = array('text', "Type", 'type', $type); array_push($rows, $row); $buttons = array(); $button = array('submit', 'Add Host', 'submit'); array_push($buttons, $button); $button = array('submit', 'Cancel', 'submit'); array_push($buttons, $button); formInput($action, $title, $rows, $buttons); } } function edit() { global $submit, $id, $name, $address, $os, $serial, $type; if ($submit == 'Cancel') { show(); } else if ($name != '' && $address != '') { $sql = "update hosts set name = '$name', address = '$address', os = '$os', serial = '$serial', type = '$type' where id = '$id'"; if (execsql($sql)) { formSuccess('Host '.$name.' updated.'); } } else { $info = getHostInfo($id); $action = "hosts/index.php"; $title = 'Modify Host'; $rows = array(); $row = array('hidden', 'id', $id); array_push($rows, $row); $row = array('hidden', 'pagedest', '/hosts'); array_push($rows, $row); $row = array('hidden', 'task', 'edit'); array_push($rows, $row); $row = array('text', "* Name", 'name', $info[0]); array_push($rows, $row); $row = array('text', "* IP Address", 'address', $info[1]); array_push($rows, $row); $row = array('text', "Operating Sys", 'os', $info[2]); array_push($rows, $row); $row = array('text', "Serial No.", 'serial', $info[3]); array_push($rows, $row); $row = array('text', "Type", 'type', $info[4]); array_push($rows, $row); $buttons = array(); $button = array('submit', 'Update Host', 'submit'); array_push($buttons, $button); $button = array('submit', 'Cancel', 'submit'); array_push($buttons, $button); formInput($action, $title, $rows, $buttons); } } function delete($id) { global $page, $submit; $info = getHostInfo($id); $error = 1; if ($submit == 'Cancel') { show(); } else if ($submit == 'Confirm Delete') { $sql = "delete from host_interface where host_id = '$id'"; if (execsql($sql)) { $error = 0; $sql = "delete from host_service where host_id = '$id'"; if (execsql($sql)) { $error = 0; $sql = "delete from hosts where id = '$id'"; if (execsql($sql)) { $error = 0; } } } if ($error == 0) { formSuccess("Host $info[0] removed."); } else { formError("Failed to remove host $info[0]"); } } else { $message = "You are about to delete host $info[0].
Are you sure?"; formDelete($message, $page, $id); } } function detail($id) { $info = getHostInfo($id); echo '
Host '.$info[0].' Detail
IP address: '.$info[1].'
Operating System: '.$info[2].'
Serial Number: '.$info[3].'
Type: '.$info[4].'
Services
'; $services = array(); $services = gethostservices($id); $class = 'row1'; if (! is_null($services)) { $colspan = 'colspan=3'; while ($row = array_pop($services)) { echo ' '; if ($class == 'row1') $class = 'row2'; else $class = 'row1'; } } else { echo ' '; } echo '
'.$row[0].' '.$row['name'].'
No services defined for this host
Interfaces
'; $interfaces = array(); $interfaces = getHostInterfaces($id); $class = 'row1'; if (! is_null($interfaces)) { $colspan = 'colspan=3'; while ($row = array_pop($interfaces)) { echo ' '; if ($class == 'row1') $class = 'row2'; else $class = 'row1'; } } else { echo ' '; } echo '
'.$row[0].' '.$row['name'].'
No interfaces defined for this host
'; } function services($id) { global $submit; $info = getHostInfo($id); $title = "Add/Remove Services for Host $info[0]"; if ($submit == "add_members") { if (array_key_exists('nonmembers', $_GET)) { $alist = $_GET['nonmembers']; while(!is_null($row = array_pop($alist))) { $service_id = $row; $result = mysql_query("select count(*) from host_service where host_id = $id and service_id = '$service_id'"); $count = mysql_fetch_row($result); if ($count[0] == 0) { $sql = "insert into host_service values(NULL, $id, $service_id)"; execsql($sql); } } } viewServices($id, $title); } else if ($submit == "remove_members") { if (array_key_exists('members', $_GET)) { $dlist = $_GET['members']; while(!is_null($row = array_pop($dlist))) { $service_id = $row; $sql = "delete from host_service where host_id = '$id' and service_id = '$service_id'"; execsql($sql); } } viewServices($id, $title); } else { viewServices($id, $title); } } function viewServices($id, $title) { global $page, $task; $sql = "select services.id, services.name from services left join host_service on services.id=host_service.service_id where host_service.host_id = $id order by services.name"; $memlist = array(); $row = array(); $nonmembers = array(); $result = execsql($sql); while($row = mysql_fetch_array($result)) { $service_id = $row['id']; $name = $row['name']; $memlist[] = $service_id; $members[] = array($service_id, $name); } $sql = "select id, name from services order by 'name' desc"; $result = execsql($sql); while($row = mysql_fetch_array($result)) { $service_id = $row['id']; $name = $row['name']; if (!in_array($service_id, $memlist)) $nonmembers[] = array($service_id, $name); } formMembers($id, $title, $page, $task, $members, $nonmembers, 'Available', 'Assigned'); } function interfaces($id) { global $submit; $info = getHostInfo($id); $title = "Add/Remove Interfaces for Host $info[0]"; if ($submit == "add_members") { if (array_key_exists('nonmembers', $_GET)) { $alist = $_GET['nonmembers']; while(!is_null($row = array_pop($alist))) { $interface_id = $row; $result = mysql_query("select count(*) from host_interface where host_id = $id and interface_id = '$interface_id'"); $count = mysql_fetch_row($result); if ($count[0] == 0) { $sql = "insert into host_interface values(NULL, $id, $interface_id)"; execsql($sql); } } } viewInterfaces($id, $title); } else if ($submit == "remove_members") { if (array_key_exists('members', $_GET)) { $dlist = $_GET['members']; while(!is_null($row = array_pop($dlist))) { $interface_id = $row; $sql = "delete from host_interface where host_id = '$id' and interface_id = '$interface_id'"; execsql($sql); } } viewInterfaces($id, $title); } else { viewInterfaces($id, $title); } } function viewInterfaces($id, $title) { global $page, $task; $sql = "select interfaces.id, interfaces.name from interfaces left join host_interface on interfaces.id=host_interface.interface_id where host_interface.host_id = $id order by interfaces.name"; $memlist = array(); $row = array(); $nonmembers = array(); $result = execsql($sql); while($row = mysql_fetch_array($result)) { $interface_id = $row['id']; $name = $row['name']; $memlist[] = $interface_id; $members[] = array($interface_id, $name); } $sql = "select id, name from interfaces order by 'name' desc"; $result = execsql($sql); while($row = mysql_fetch_array($result)) { $interface_id = $row['id']; $name = $row['name']; if (!in_array($interface_id, $memlist)) $nonmembers[] = array($interface_id, $name); } formMembers($id, $title, $page, $task, $members, $nonmembers, 'Available', 'Assigned'); } ?>