function get_interface_cluster_list_html($form) { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $html = $js = ''; // Interface Record list($status, $introws, $interfaces) = db_get_records($onadb, 'interface_clusters', "interface_id = {$form['interface_id']}"); if ($introws == 0 or $status) { return array('', ''); } // Get primary host info list($status, $rows, $priint) = ona_get_interface_record(array('id' => $form['interface_id'])); list($status, $rows, $prihost) = ona_get_host_record(array('id' => $priint['host_id'])); $priip = ip_mangle($priint['ip_addr'], dotted); // add one for primary host $introws = $introws + 1; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; text-align: center; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; $html .= <<<EOL <!-- INTERFACE CLUSTER INFORMATION --> <table cellspacing="0" border="0" cellpadding="0"> <!-- LABEL --> <tr> <td colspan=3 style="{$style['label_box']}">{$introws} hosts share IP:<br>{$priip}</td> </tr> <tr> <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true"> <a title="View host. ID: {$prihost['id']}" style="color: #6CB3FF;" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$prihost['id']}\\', \\'display\\')'); removeElement('{$form['id']}');" >{$prihost['fqdn']}</a> </td> <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$priint['name']}</td> </tr> EOL; $i = 0; foreach ($interfaces as $interface) { list($status, $rows, $host) = ona_get_host_record(array('id' => $interface['host_id'])); foreach (array_keys((array) $interface) as $key) { $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); } // If there is no cluster name then use the name from the primary interface if (!$interface['name']) { $interface['name'] = $priint['name']; } $html .= <<<EOL <tr> <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true"> <form id="quick_interface_share_del_form" onSubmit="return(false);"> <input type="hidden" name="ip" value="{$interface['interface_id']}"> <input type="hidden" name="host" value="{$host['id']}"> </form> <a title="View host. ID: {$host['id']}" style="color: #6CB3FF;" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$host['id']}\\', \\'display\\')'); removeElement('{$form['id']}');" >{$host['fqdn']}</a> </td> <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$interface['name']}</td> <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true"> <img src="{$images}/silk/delete.png" title="Remove interface share with {$host['fqdn']}" border="0" onClick="xajax_window_submit('tooltips', xajax.getFormValues('quick_interface_share_del_form'), 'interface_share_del');removeElement('{$form['id']}');" /> </td> </tr> EOL; // increment counter $i++; if ($i == 15) { $html .= <<<EOL <tr> <td align="center" class="padding" style="color: #FFFFFF;" nowrap="true" colspan=2> Only displaying first 15 hosts in cluster. <a title="View host. ID: {$interface['host_id']}" style="color: #6CB3FF;" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$interface['host_id']}\\', \\'display\\')'); removeElement('{$form['id']}');" >View Primary Host</a> </td> </tr> EOL; break; } } $html .= <<<EOL </table> EOL; return array($html, $js); }
function ona_find_host($search = "") { global $conf, $self, $onadb; printmsg("DEBUG => ona_find_host({$search}) called", 3); // By record ID? if (is_numeric($search)) { list($status, $rows, $host) = ona_get_host_record(array('id' => $search)); if ($rows) { printmsg("DEBUG => ona_find_host({$search}) called, found: {$host['fqdn']}", 3); return array($status, $rows, $host); } } // By Interface ID or IP address? list($status, $rows, $interface) = ona_find_interface($search); if (!$status and $rows) { // Load and return associated info list($status, $rows, $host) = ona_get_host_record(array('id' => $interface['host_id'])); return array($status, $rows, $host); } // MP: NEEDS MORE VALIDATION ON THIS PART!! // If it does not have a dot in it. append the default domain if (!strstr($search, '.')) { $search = $search . '.' . $conf['dns_defaultdomain']; } // // It's an FQDN, do a bunch of stuff! // // lets test out if it has a / in it to strip the view name portion $view['id'] = 0; if (strstr($search, '/')) { list($dnsview, $search) = explode('/', $search); list($status, $rows, $view) = db_get_record($onadb, 'dns_views', array('name' => strtoupper($dnsview))); printmsg("DEBUG => ona_find_host: DNS view [{$dnsview}] was not found, using default", 2); if (!$rows) { $view['id'] = 0; } } // FIXME: MP this will currently "fail" if the fqdn of the server // is the same as a valid domain name. not sure why anyone would have this but // never say never. I'll leave this issue unfixed for now // Find the 'first', domain name piece of $search list($status, $rows, $domain) = ona_find_domain($search, 0); if (!isset($domain['id'])) { printmsg("ERROR => Unable to determine domain name portion of ({$search})!", 3); $self['error'] = "ERROR => Unable to determine domain name portion of ({$search})!"; return array(3, $self['error'] . "\n"); } printmsg("DEBUG => ona_find_domain({$search}) returned: {$domain['fqdn']}", 3); // Now find what the host part of $search is $hostname = str_replace(".{$domain['fqdn']}", '', $search); // Let's see if that hostname is valid or not in $domain['id'] $domain_parts = explode('.', $domain['fqdn']); foreach ($domain_parts as $part) { // Loop through the parts of the domain to find host.sub domain.com type entries.. list($status, $dnsrows, $dnsrecs) = db_get_records($onadb, 'dns', array('domain_id' => $domain['id'], 'name' => $hostname, 'dns_view_id' => $view['id'])); // If we didnt just find a dns record.. lets move the period over and try a deeper domain/host pair. if (!$dnsrows) { $hostname = $hostname . '.' . $part; $name = str_replace("{$part}.", '', $domain['fqdn']); list($status, $rows, $domain) = ona_get_domain_record(array('name' => $name)); } else { break; } } // If we found one or more dns records, lets loop through them all and find the first primary host using that name if ($dnsrows) { foreach ($dnsrecs as $entry) { list($status, $rows, $host) = ona_get_host_record(array('primary_dns_id' => $entry['id'])); if ($host['id']) { return array($status, $rows, $host); } } } // Otherwise, build a fake host record with only a few entries in it and return that $host = array('id' => 0, 'name' => $hostname, 'fqdn' => "{$hostname}.{$domain['fqdn']}", 'domain_id' => $domain['id'], 'domain_fqdn' => $domain['fqdn']); return array(0, 0, $host); }
function ws_editor($window_name, $form = '') { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $window = array(); // Check permissions if (!(auth('host_modify') or auth('host_add'))) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // If an array in a string was provided, build the array and store it in $form $form = parse_options_string($form); // Load an existing host record (and associated info) if $form is a host_id $host = array('fqdn' => '.', 'domain_fqdn' => $conf['dns_defaultdomain']); $interface = array(); if (is_numeric($form['host_id'])) { list($status, $rows, $host) = ona_get_host_record(array('id' => $form['host_id'])); if ($rows) { // Load associated INTERFACE record(s) list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $host['id'])); list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); $interface['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted'); if ($interface['mac_addr']) { $interface['mac_addr'] = mac_mangle($interface['mac_addr'], 2); } //FIXME: (PK) should not use numeric format specifier here! } } else { if (strlen($form['ip_addr']) > 1) { $interface['ip_addr'] = $form['ip_addr']; } if (strlen($form['hostname']) > 1) { $host['name'] = $form['hostname']; } } // Set the default security level if there isn't one if (!array_key_exists('lvl', $host)) { $host['lvl'] = $conf['ona_lvl']; } // Load a subnet record if we got passed a subnet_id if ($form['subnet_id']) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id'])); } // Load a domain record if we got passed a domain_id if ($form['domain_id']) { list($status, $rows, $domain) = ona_get_domain_record(array('id' => $form['domain_id'])); $host['domain_fqdn'] = $domain['fqdn']; } // If we dont have a domain_fqdn yet.. lets use the system default domain if (!$host['domain_fqdn']) { $host['domain_fqdn'] = $conf['dns_defaultdomain']; } // Build a device_types list list($status, $rows, $records) = db_get_records($onadb, 'device_types', 'id >= 1'); $device_types = array(); foreach ($records as $type) { list($status, $rows, $model) = ona_get_model_record(array('id' => $type['model_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $type['role_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $device_types[$type['id']] = "{$manufacturer['name']} {$model['name']} ({$role['name']})"; } asort($device_types); list($status, $rows, $device) = ona_get_device_record(array('id' => $host['device_id'])); list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_id'])); $host['location'] = $location['reference']; $device_model_list = "<option value=\"\"></option>\n"; foreach (array_keys((array) $device_types) as $id) { $device_types[$id] = htmlentities($device_types[$id]); $selected = ''; if ($id == $device['device_type_id']) { $selected = 'SELECTED'; } $device_model_list .= "<option value=\"{$id}\" {$selected}>{$device_types[$id]}</option>\n"; } unset($device_types, $device, $manufacturer, $role, $model, $records); //Get the list of DNS views if ($conf['dns_views']) { list($status, $rows, $dnsviews) = db_get_records($onadb, 'dns_views', 'id >= 0', 'name'); foreach ($dnsviews as $entry) { $selected = ''; //$dnsviews['name'] = htmlentities($dnsviews['name']); // If this entry matches the record you are editing, set it to selected if ($host['id'] and $entry['id'] == $host['dns_view_id']) { $selected = "SELECTED=\"selected\""; $dns_view_name = $entry['name'] . '/'; } elseif (!$host['id'] and $entry['id'] == 0) { // Otherwise use the default record if we are adding a new entry $selected = "SELECTED=\"selected\""; $dns_view_name = $entry['name'] . '/'; } $dns_view_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['name']}</option>\n"; } } // Escape data for display in html foreach (array_keys((array) $host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $interface) as $key) { $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Add Host"; if ($host['id']) { $window['title'] = "Edit Host"; } else { unset($dns_view_name); } // Javascript to run after the window is built $window['js'] = <<<EOL /* Put a minimize icon in the title bar */ el('{$window_name}_title_r').innerHTML = ' <a onClick="toggle_window(\\'{$window_name}\\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' + el('{$window_name}_title_r').innerHTML; /* Put a help icon in the title bar */ el('{$window_name}_title_r').innerHTML = ' <a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' + el('{$window_name}_title_r').innerHTML; suggest_setup('set_domain_{$window_name}', 'suggest_set_domain_{$window_name}'); suggest_setup('set_location_{$window_name}', 'suggest_set_location_{$window_name}'); /* Setup the Quick Find location icon */ var _button = el('qf_location_{$window_name}'); _button.style.cursor = 'pointer'; _button.onclick = function(ev) { if (!ev) ev = event; /* Create the popup div */ wwTT(this, ev, 'id', 'tt_qf_location_{$window_name}', 'type', 'static', 'direction', 'south', 'delay', 0, 'styleClass', 'wwTT_qf', 'javascript', "xajax_window_submit('tooltips', '" + "tooltip=>qf_location," + "id=>tt_qf_location_{$window_name}," + "input_id=>set_location_{$window_name}');" ); }; el('set_host').focus(); EOL; // If we are modifying do not allow them to edit/change dns names. this should only be done when creating a new host $hideit = ''; if ($host['id']) { $hideit = 'style="display: none;"'; } // Define the window's inner html $window['html'] = <<<EOL <!-- Host Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="host" value="{$dns_view_name}{$host['fqdn']}"> <input type="hidden" name="interface" value="{$interface['id']}"> <input type="hidden" name="js" value="{$form['js']}"> <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;"> <!-- HOST RECORD --> <tr> <td align="left" nowrap="true"> <b><u>Host Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> EOL; // Print a dns view selector if ($conf['dns_views']) { $window['html'] .= <<<EOL <tr {$hideit}> <td align="right" nowrap="true"> DNS View </td> <td class="padding" align="left" width="100%"> <select id="dns_view_select" name="set_view" alt="DNS View" class="edit" >{$dns_view_list}</select> </td> </tr> EOL; } $window['html'] .= <<<EOL <tr {$hideit}> <td class="input_required" align="right" nowrap="true"> DNS Name </td> <td class="padding" align="left" width="100%"> <input id="set_host" name="set_host" alt="Hostname" value="{$host['name']}" class="edit" type="text" size="20" maxlength="64" > </td> </tr> <tr {$hideit}> <td class="input_required" align="right" nowrap="true"> Domain </td> <td class="padding" align="left" width="100%"> <input id="set_domain_{$window_name}" name="set_domain" alt="Domain name" value="{$host['domain_fqdn']}" class="edit" type="text" size="25" maxlength="64" > <div id="suggest_set_domain_{$window_name}" class="suggest"></div> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Device type </td> <td class="padding" align="left" width="100%"> <select name="set_type" alt="Device type" class="edit" >{$device_model_list}</select> </td> </tr> <tr> <td align="right" nowrap="true"> Notes </td> <td class="padding" align="left" width="100%"> <textarea name="set_notes" class="edit" cols="40" rows="1">{$host['notes']}</textarea> </td> </tr> <tr> <td align="right" nowrap="true"> Location </td> <td class="padding" align="left" width="100%"> <input id="set_location_{$window_name}" name="set_location" alt="Location" value="{$host['location']}" class="edit" type="text" size="7" maxlength="10" > <div id="suggest_set_location_{$window_name}" class="suggest"></div> <span id="qf_location_{$window_name}" title="Location Quick Search"><img src="{$images}/silk/find.png" border="0"/></span> </td> </tr> EOL; // Display an interface edit section if it's a new host or there were exactly one interface. if (!$interfaces) { $window['js'] .= <<<EOL /* Setup the Quick Find for available IPs */ var _button = el('qf_free_ip_{$window_name}'); _button.style.cursor = 'pointer'; _button.onclick = function(ev) { if (!ev) ev = event; /* Create the popup div */ wwTT(this, ev, 'id', 'tt_qf_free_ip_{$window_name}', 'type', 'static', 'direction', 'south', 'delay', 0, 'styleClass', 'wwTT_qf', 'javascript', "xajax_window_submit('tooltips', '" + "tooltip=>qf_free_ip," + "id=>tt_qf_free_ip_{$window_name}," + "text_id=>associated_subnet_{$window_name}," + "text_value=>" + el('associated_subnet_{$window_name}').innerHTML + "," + "input_id=>set_ip_{$window_name}');" ); }; EOL; $window['html'] .= <<<EOL <!-- FIRST INTERFACE --> <tr> <td align="left" nowrap="true"> <b><u>Interface</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td align="right" nowrap="true"> Subnet </td> <td class="padding" align="left" width="100%" nowrap="true"> <span id="associated_subnet_{$window_name}" >{$subnet['name']}</span> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> IP Address </td> <td class="padding" align="left" width="100%"> <input id="set_ip_{$window_name}" name="set_ip" alt="IP Address" value="{$interface['ip_addr']}" class="edit" type="text" size="25" maxlength="64" > <span id="qf_free_ip_{$window_name}" title="Available IP Quick Search"><img src="{$images}/silk/find.png" border="0"/></span> <div id="suggest_set_ip_{$window_name}" class="suggest"></div> </td> </tr> <tr> <td align="right" nowrap="true"> MAC Address </td> <td class="padding" align="left" width="100%"> <input name="set_mac" alt="MAC Address" value="{$interface['mac_addr']}" class="edit" type="text" size="17" maxlength="17" > <a class="nav" onClick="this.style.display = 'none'; el('force_{$window_name}').style.display = browser.isIE ? 'block' : 'table-row';">More >></a> </td> </tr> <tr id="force_{$window_name}" style="display: none;"> <td align="right" nowrap="true"> </td> <td class="padding" align="left" width="100%"> <input name="force" alt="Allow duplicate MAC addresses" type="checkbox" > Allow duplicate MAC addresses </td> </tr> <tr> <td align="right" nowrap="true"> Interface name </td> <td class="padding" align="left" width="100%"> <input name="set_name" alt="Interface name" value="{$interface['name']}" class="edit" type="text" size="17" maxlength="255" > </td> </tr> <tr> <td align="right" nowrap="true"> Interface description </td> <td class="padding" align="left" width="100%"> <input name="set_description" alt="Interface description" value="{$interface['description']}" class="edit" type="text" size="25" maxlength="255" > </td> </tr> EOL; } if (!$host['id']) { $window['html'] .= <<<EOL <td align="right" nowrap="true"> Auto create PTR </td> <td class="padding" align="left" width="100%" nowrap> <input id="set_addptr" name="set_addptr" alt="Automaticaly create PTR record" type="checkbox" checked="1" /> </td> <tr> <td align="right" nowrap="true"> </td> <td class="padding" align="left" width="100%"> <input name="keepadding" alt="Keep adding more hosts" type="checkbox" > Keep adding more hosts </td> </tr> <tr> <td colspan="2" class="padding" align="center" width="100%"> <span id="statusinfo_{$window_name}" style="color: green;" ></span> </td> </tr> EOL; } $window['html'] .= <<<EOL <tr> <td align="right" valign="top" nowrap="true"> </td> <td class="padding" align="right" width="100%"> <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');"> <input class="edit" type="button" name="submit" value="Save" accesskey=" " onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_edit_form'), 'save');" > </td> </tr> </table> </form> EOL; return window_open($window_name, $window); }
function get_server_name_ip($server_id) { printmsg("DEBUG => get_server_name_ip(\$server_id = {$server_id}) called", 5); list($status, $rows, $host) = ona_get_host_record(array('id' => $server_id)); list($status, $rows, $interface) = ona_get_interface_record(array('host_id' => $server_id)); return array($host['fqdn'], $interface['ip_addr']); }
function ws_display($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style, $msgtype; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the host record if ($form['interface_id']) { list($status, $rows, $record) = ona_get_interface_record(array('id' => $form['interface_id'])); } $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted'); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Interface doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Update History Title (and tell the browser to re-draw the history div) $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = $record['ip_addr']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; // Associated Host info list($status, $rows, $host) = ona_get_host_record(array('id' => $record['host_id']), ''); // Subnet description list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); $record['subnet_name'] = $subnet['name']; $record['ip_subnet_mask'] = ip_mangle($subnet['ip_mask'], 'dotted'); $record['ip_subnet_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr'); $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; vertical-align: top; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <!-- FORMATTING TABLE --> <div style="{$style['content_box']}"> <table cellspacing="0" border="0" cellpadding="0"><tr> <!-- START OF FIRST COLUMN OF SMALL BOXES --> <td nowrap="true" valign="top" style="padding-right: 15px;"> <!-- HOST INFORMATION --> <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <tr><td colspan="99" nowrap="true" style="{$style['label_box']}"> <!-- LABEL --> <form id="form_interface_{$record['id']}" ><input type="hidden" name="interface_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('host_modify', $debug_val)) { $html .= <<<EOL <a title="Edit interface. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> EOL; } if (auth('host_del', $debug_val)) { $html .= <<<EOL <a title="Delete interface. ID: {$record['id']}" class="act" onClick="var doit=confirm('Are you sure you want to delete this interface?'); if (doit == true) xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL {$record['ip_addr']} </td></tr> <tr> <td align="right" nowrap="true"><b>MAC Address</b> </td> <td class="padding" align="left">{$record['mac_addr']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Name</b> </td> <td class="padding" align="left">{$record['name']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Description</b> </td> <td class="padding" align="left">{$record['description']} </td> </tr> </table> EOL; $html .= <<<EOL <!-- END OF FIRST COLUMN OF SMALL BOXES --> </td> <!-- START OF SECOND COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THIRD COLUMN OF SMALL BOXES --> <td valign="top"> EOL; $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <!-- END OF TOP SECTION --> EOL; // record LIST $tab = 'records'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- RECORD LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated DNS {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="interface_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Filter</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('record_add', $debug_val)) { $html .= <<<EOL <!-- ADD DNS RECORD LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_record_{$record['id']}" ><input type="hidden" name="interface_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Add record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Add record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" >Add record</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function ws_display_list($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; // If the user supplied an array in a string, transform it into an array $form = parse_options_string($form); // Find the "tab" we're on $tab = $_SESSION['ona'][$form['form_id']]['tab']; // Build js to refresh this list $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');"; // If it's not a new query, load the previous query from the session // into $form and save the current page and filter in the session. // Also find/set the "page" we're viewing $page = 1; if ($form['page'] and is_numeric($form['page'])) { $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']); $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page']; $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter']; } printmsg("DEBUG => Displaying records list page: {$page}", 1); // Calculate the SQL query offset (based on the page being displayed) $offset = $conf['search_results_per_page'] * ($page - 1); if ($offset == 0) { $offset = -1; } // Search results go in here $results = array(); $count = 0; // // *** ADVANCED RECORD SEARCH *** // FIND RESULT SET // // Start building the "where" clause for the sql query to find the records to display $where = ""; $and = ""; $orderby = ""; // enable or disable wildcards $wildcard = '%'; if ($form['nowildcard']) { $wildcard = ''; } // RECORD ID if ($form['record_id']) { $where .= $and . "id = " . $onadb->qstr($form['record_id']); $and = " AND "; } // DNS VIEW ID if ($form['dns_view']) { if (is_string($form['dns_view'])) { list($status, $rows, $dnsview) = ona_get_dns_view_record(array('name' => $form['dns_view'])); } if (is_numeric($form['dns_view'])) { list($status, $rows, $dnsview) = ona_get_dns_view_record(array('id' => $form['dns_view'])); } $where .= $and . "dns_view_id = " . $onadb->qstr($dnsview['id']); $and = " AND "; } // INTERFACE ID if ($form['interface_id']) { $where .= $and . "interface_id = " . $onadb->qstr($form['interface_id']); $and = " AND "; } // DNS RECORD note if ($form['notes']) { $where .= $and . "notes LIKE " . $onadb->qstr($wildcard . $form['notes'] . $wildcard); $and = " AND "; } // DNS RECORD TYPE if ($form['dnstype']) { $where .= $and . "type = " . $onadb->qstr($form['dnstype']); $and = " AND "; } // HOSTNAME if ($form['hostname']) { $where .= $and . "id IN (SELECT id " . " FROM dns " . " WHERE name LIKE " . $onadb->qstr($wildcard . $form['hostname'] . $wildcard) . " )"; $and = " AND "; } // DOMAIN if ($form['domain']) { // FIXME: MP test if this clause works correctly? Not sure that anything even uses this? list($status, $rows, $tmpdomain) = ona_find_domain($form['domain']); $where .= $and . "domain_id = " . $onadb->qstr($tmpdomain['id']); $orderby .= "name, domain_id"; $and = " AND "; } // DOMAIN ID if ($form['domain_id']) { //$where .= $and . "primary_dns_id IN ( SELECT id " . // " FROM dns " . // " WHERE domain_id = " . $onadb->qstr($form['domain_id']) . " ) "; $where .= $and . "domain_id = " . $onadb->qstr($form['domain_id']); $orderby .= "name, domain_id"; $and = " AND "; } // IP ADDRESS $ip = $ip_end = ''; if ($form['ip']) { // Build $ip and $ip_end from $form['ip'] and $form['ip_thru'] $ip = ip_complete($form['ip'], '0'); if ($form['ip_thru']) { $ip_end = ip_complete($form['ip_thru'], '255'); } else { $ip_end = ip_complete($form['ip'], '255'); } // Find out if $ip and $ip_end are valid $ip = ip_mangle($ip, 'numeric'); $ip_end = ip_mangle($ip_end, 'numeric'); if ($ip != -1 and $ip_end != -1) { // We do a sub-select to find interface id's between the specified ranges $where .= $and . "interface_id IN ( SELECT id " . " FROM interfaces " . " WHERE ip_addr >= " . $onadb->qstr($ip) . " AND ip_addr <= " . $onadb->qstr($ip_end) . " )"; $and = " AND "; } } // display a nice message when we dont find all the records if ($where == '' and $form['content_id'] == 'search_results_list') { $js .= "el('search_results_msg').innerHTML = 'Unable to find DNS records matching your query, showing all records';"; } // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything. if ($where == '') { $where = 'id > 0'; } // If we dont have DNS views turned on, limit data to just the default view. // Even if there is data associated with other views, ignore it if (!$conf['dns_views']) { $where .= ' AND dns_view_id = 0'; } // Do the SQL Query $filter = ''; if ($form['filter']) { // Host names should always be lower case $form['filter'] = strtolower($form['filter']); $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } // If we get a specific host to look for we must do the following // 1. get (A) records that match any interface_id associated with the host // 2. get CNAMES that point to dns records that are using an interface_id associated with the host if ($form['host_id']) { // If we dont have DNS views turned on, limit data to just the default view. // Even if there is data associated with other views, ignore it // MP: something strange with this, it should only limit to default view.. sometimes it does not??? if (!$conf['dns_views']) { $hwhere .= 'dns_view_id = 0 AND '; } // Get the host record so we know what the primary interface is list($status, $rows, $host) = ona_get_host_record(array('id' => $form['host_id']), ''); list($status, $rows, $results) = db_get_records($onadb, 'dns', $hwhere . 'interface_id in (select id from interfaces where host_id = ' . $onadb->qstr($form['host_id']) . ') OR interface_id in (select interface_id from interface_clusters where host_id = ' . $onadb->qstr($form['host_id']) . ')', "type", $conf['search_results_per_page'], $offset); // If we got less than search_results_per_page, add the current offset to it // so that if we're on the last page $rows still has the right number in it. if ($rows > 0 and $rows < $conf['search_results_per_page']) { $rows += $conf['search_results_per_page'] * ($page - 1); } else { if ($rows >= $conf['search_results_per_page']) { list($status, $rows, $records) = db_get_records($onadb, 'dns', $hwhere . 'interface_id in (select id from interfaces where host_id = ' . $onadb->qstr($form['host_id']) . ') OR interface_id in (select interface_id from interface_clusters where host_id = ' . $onadb->qstr($form['host_id']) . ')' . $filter, "", 0); } } } else { list($status, $rows, $results) = db_get_records($onadb, 'dns', $where . $filter, $orderby, $conf['search_results_per_page'], $offset); // If we got less than search_results_per_page, add the current offset to it // so that if we're on the last page $rows still has the right number in it. if ($rows > 0 and $rows < $conf['search_results_per_page']) { $rows += $conf['search_results_per_page'] * ($page - 1); } else { if ($rows >= $conf['search_results_per_page']) { list($status, $rows, $records) = db_get_records($onadb, 'dns', $where . $filter, "", 0); } } } $count = $rows; // // *** BUILD HTML LIST *** // $html .= <<<EOL <!-- dns record Results --> <table id="{$form['form_id']}_dns_record_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td colspan="2" class="list-header" align="center" style="{$style['borderR']};">Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Time to Live</td> <td class="list-header" align="center" style="{$style['borderR']};">Type</td> <td class="list-header" align="center" style="{$style['borderR']};">Data</td> <td class="list-header" align="center" style="{$style['borderR']};">Effective</td> EOL; if ($conf['dns_views']) { $html .= "<td class=\"list-header\" align=\"center\" style=\"{$style['borderR']};\">DNS View</td>"; } $html .= <<<EOL <td class="list-header" align="center" style="{$style['borderR']};">Notes</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record // $last_record = array('name' => $results[0]['name'], 'domain_id' => $results[0]['domain_id']); // $last_record_count = 0; for ($i = 1; $i <= count($results); $i++) { $record = $results[$i]; // Get additional info about each host record $record = $results[$i - 1]; // if the interface is the primary_dns_id for the host then mark it $primary_record = ' '; if ($host['primary_dns_id'] == $record['id']) { $primary_record = '<img title="Primary DNS record" src="' . $images . '/silk/font_go.png" border="0">'; } // Check for interface records (and find out how many there are) list($status, $interfaces, $interface) = ona_get_interface_record(array('id' => $record['interface_id']), ''); if ($interfaces) { // Get the host record so we know what the primary interface is //list($status, $rows, $inthost) = ona_get_host_record(array('id' => $interface['host_id']), ''); // Make the type correct based on the IP passed in if (strlen($interface['ip_addr']) > 11 and $record['type'] == 'A') { $record['type'] = 'AAAA'; } $record['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted'); // Subnet description list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); $record['subnet'] = $subnet['name']; $record['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted'); $record['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr'); // Create string to be embedded in HTML for display $data = <<<EOL {$record['ip_addr']} EOL; } else { // Get other DNS records which name this record as parent list($status, $rows, $dns_other) = ona_get_host_record(array('id' => $record['dns_id'])); // Create string to be embedded in HTML for display if ($rows) { $data = <<<EOL <a title="View host. ID: {$dns_other['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$dns_other['id']}\\', \\'display\\')');" >{$dns_other['name']}</a >.<a title="View domain. ID: {$dns_other['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$dns_other['domain_id']}\\', \\'display\\')');" >{$dns_other['domain_fqdn']}</a> EOL; } } $record['notes_short'] = truncate($record['notes'], 30); // Add a dot to the end of record name for display purposes $record['name'] = $record['name'] . '.'; // Process PTR record if ($record['type'] == 'PTR') { list($status, $rows, $pointsto) = ona_get_dns_record(array('id' => $record['dns_id']), ''); list($status, $rows, $pdomain) = ona_get_domain_record(array('id' => $record['domain_id']), ''); // Flip the IP address $record['name'] = ip_mangle($record['ip_addr'], 'flip'); $record['domain'] = $pdomain['name']; if ($pdomain['parent_id']) { list($status, $rows, $parent) = ona_get_domain_record(array('id' => $pdomain['parent_id'])); $parent['name'] = ona_build_domain_name($parent['id']); $record['domain'] = $pdomain['name'] . '.' . $parent['name']; unset($parent['name']); } // strip down the IP to just the "host" part as it relates to the domain its in if (strstr($record['domain'], 'in-addr.arpa')) { $domain_part = preg_replace("/.in-addr.arpa\$/", '', $record['domain']); } else { $domain_part = preg_replace("/.ip6.arpa\$/", '', $record['domain']); } $record['name'] = preg_replace("/{$domain_part}\$/", '', $record['name']); $data = <<<EOL <a title="Edit DNS A record" class="act" onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');" >{$pointsto['name']}</a>.<a title="View domain. ID: {$pointsto['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$pointsto['domain_id']}\\', \\'display\\')');" >{$pointsto['domain_fqdn']}</a>. EOL; } // Process CNAME record if ($record['type'] == 'CNAME') { list($status, $rows, $cname) = ona_get_dns_record(array('id' => $record['dns_id']), ''); $data = <<<EOL <a title="Edit DNS A record" class="act" onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');" >{$cname['name']}</a>.<a title="View domain. ID: {$cname['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$cname['domain_id']}\\', \\'display\\')');" >{$cname['domain_fqdn']}</a>. EOL; } // Process NS record if ($record['type'] == 'NS') { // clear out the $record['domain'] value so it shows properly in the list $record['name'] = ''; list($status, $rows, $ns) = ona_get_dns_record(array('id' => $record['dns_id']), ''); $data = <<<EOL <a title="Edit DNS A record" class="act" onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');" >{$ns['name']}</a>.<a title="View domain. ID: {$ns['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$ns['domain_id']}\\', \\'display\\')');" >{$ns['domain_fqdn']}</a>. EOL; } // Process MX record if ($record['type'] == 'MX') { // show the preference value next to the type $record['type'] = "{$record['type']} ({$record['mx_preference']})"; list($status, $rows, $mx) = ona_get_dns_record(array('id' => $record['dns_id']), ''); $data = <<<EOL <a title="Edit DNS A record" class="act" onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');" >{$mx['name']}</a>.<a title="View domain. ID: {$mx['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$mx['domain_id']}\\', \\'display\\')');" >{$mx['domain_fqdn']}</a>. EOL; } // Process SRV record if ($record['type'] == 'SRV') { // show the preference value next to the type $record['type'] = "{$record['type']} ({$record['srv_port']})"; list($status, $rows, $srv) = ona_get_dns_record(array('id' => $record['dns_id']), ''); $data = <<<EOL <a title="Edit DNS A record" class="act" onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');" >{$srv['name']}</a>.<a title="View domain. ID: {$srv['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$srv['domain_id']}\\', \\'display\\')');" >{$srv['domain_fqdn']}</a>. EOL; } // Process TXT record if ($record['type'] == 'TXT') { // some records will have an interfaceid and dnsid when associated to another dns name // some will just be un associated txt records or domain only records. Determine that here and // display appropriately. This is to ensure associated DNS records match up if the name changes if ($record['interface_id'] and $record['dns_id']) { list($status, $rows, $txtmain) = ona_get_dns_record(array('id' => $record['dns_id']), ''); $record['name'] = $txtmain['name'] . '.'; } $data = truncate($record['txt'], 70); } // Get the domain name and domain ttl $ttl_style = 'title="Time-to-Live"'; list($status, $rows, $domain) = ona_get_domain_record(array('id' => $record['domain_id'])); // Make record['domain'] have the right name in it if ($record['type'] != 'PTR') { $record['domain'] = $domain['fqdn']; } // clear out the $record['domain'] value so it shows properly in the list for NS records if ($record['type'] == 'NS') { $record['domain'] = $domain['fqdn']; } // if the ttl is blank, use the one in the domain (minimum) if ($record['ttl'] == 0) { $record['ttl'] = $domain['default_ttl']; $ttl_style = 'style="font-style: italic;" title="Using TTL from domain"'; } // format the ebegin using the configured date format $ebegin = ''; // If it is in the future, print the time if (strtotime($record['ebegin']) > time()) { $ebegin = '<span title="Active in DNS on: ' . $record['ebegin'] . '">' . date($conf['date_format'], strtotime($record['ebegin'])) . '</span>'; } // If it is 0 then show as disabled if (strtotime($record['ebegin']) < 0) { $ebegin = <<<EOL <span style="background-color:#FFFF99;" title="Disabled: Won't build in DNS" onClick="var doit=confirm('Are you sure you want to enable this DNS record?'); if (doit == true) xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'enablerecord');" >Disabled</span> EOL; } // If we get this far and the name we have built has a leading . in it then remove the dot. $record['name'] = preg_replace("/^\\./", '', $record['name']); // Get the name of the view and the description if ($conf['dns_views']) { list($status, $rows, $dnsview) = ona_get_dns_view_record(array('id' => $record['dns_view_id'])); $record['view_name'] = $dnsview['name']; $record['view_desc'] = $dnsview['description']; } // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } //$primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$record['id']}\', \'display\')');"; $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td class="list-row" style="padding-right: 2px; padding-left: 4px;" width="16px"> {$primary_record} </td> <td class="list-row"> <span title="Record. ID: {$record['id']}" onClick="" >{$record['name']}</span ><a title="View domain. ID: {$domain['id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$domain['id']}\\', \\'display\\')');" >{$record['domain']}.</a> </td> <td class="list-row"> <span onClick="" {$ttl_style} >{$record['ttl']} seconds</span> </td> <td class="list-row"> <span title="Record Type" onClick="" >{$record['type']}</span> </td> <td class="list-row" align="left"> EOL; // Put the data in! $html .= $data; $html .= <<<EOL </td> <td class="list-row" align="center"> {$ebegin} </td> EOL; // Display the view we are part of if ($conf['dns_views']) { $html .= <<<EOL <td class="list-row" align="center" title="{$record['view_desc']}"> {$record['view_name']} </td> EOL; } $html .= <<<EOL <td class="list-row"> <span title="{$record['notes']}">{$record['notes_short']}</span> </td> <!-- ACTION ICONS --> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_record_{$record['id']}" ><input type="hidden" name="dns_record_id" value="{$record['id']}" ><input type="hidden" name="host_id" value="{$host['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('dns_record_modify')) { // If it is an A record but not the primary, display an option to make it primary. and only if we are dealing with a specific host if (($record['type'] == 'A' or $record['type'] == 'AAAA') and $host['primary_dns_id'] != $record['id'] and $form['host_id']) { $html .= <<<EOL <a title="Make this the primary DNS record" class="act" onClick="var doit=confirm('Are you sure you want to make this the primary DNS record for this host?'); if (doit == true) xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'makeprimary');" ><img src="{$images}/silk/font_go.png" border="0"></a> EOL; } } // display a view host button on the dns record search form list if ($form['search_form_id'] == 'dns_record_search_form') { $html .= <<<EOL <a title="View associated host record: {$interface['host_id']}" class="act" onClick="xajax_window_submit('display_host', 'host_id=>{$interface['host_id']}', 'display');" ><img src="{$images}/silk/computer_go.png" border="0"></a> EOL; } if (auth('dns_record_modify')) { $html .= <<<EOL <a title="Edit DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> EOL; } if (auth('dns_record_del')) { $html .= <<<EOL <a title="Delete DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; // reset the record counter before we go back for the next iteration $last_record = array('name' => $record['name'], 'domain_id' => $record['domain_id']); $last_record_count = 1; } $html .= <<<EOL </table> EOL; // Build page links if there are any $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']); // Insert the new html into the content div specified // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})"); $response->addAssign($form['content_id'], "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function ws_display($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the server record list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id'])); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Server doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Pick up host information //list($status, $rows, $host) = ona_find_host($form['host_id']); // Update History Title $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = "DNS server - " . $record['fqdn']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; vertical-align: top; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys((array) $record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <!-- FORMATTING TABLE --> <div style="{$style['content_box']}"> <table cellspacing="0" border="0" cellpadding="0"><tr> <!-- START OF FIRST COLUMN OF SMALL BOXES --> <td nowrap="true" valign="top" style="padding-right: 15px;"> EOL; // DNS SERVER INFO $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <tr><td colspan="99" nowrap="true" style="{$style['label_box']}"> DNS server <a title="View host. ID: {$record['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$record['id']}\\', \\'display\\')');" >{$record['name']}.{$record['domain_fqdn']}</a> </td></tr> </table> EOL; // END DNS SERVER INFO $html .= <<<EOL <!-- END OF FIRST COLUMN OF SMALL BOXES --> </td> <!-- START OF SECOND COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THIRD COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <!-- END OF TOP SECTION --> EOL; // DOMAIN SERVERS LIST $tab = 'domain_server'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- Domain Servers LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Assigned domains on {$record['name']}.{$record['domain_fqdn']} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="server_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Filter</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="{$form['form_id']}_domain_server_{$record['id']}" ><input type="hidden" name="server" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <!-- ADD DOMAIN LINK --> <a title="Assign domain" class="act" onClick="xajax_window_submit('edit_domain_server', xajax.getFormValues('{$form['form_id']}_domain_server_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Assign domain" class="act" onClick="xajax_window_submit('edit_domain_server', xajax.getFormValues('{$form['form_id']}_domain_server_{$record['id']}'), 'editor');" >Assign existing domain</a> <!-- ADD DOMAIN LINK --> <a title="New DNS domain" class="act" onClick="xajax_window_submit('edit_domain', xajax.getFormValues('{$form['form_id']}_domain_server_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="New DNS domain" class="act" onClick="xajax_window_submit('edit_domain', xajax.getFormValues('{$form['form_id']}_domain_server_{$record['id']}'), 'editor');" >Add DNS domain</a> </div> EOL; } $html .= <<<EOL </div> EOL; // If we have a build type set, then display the output div if ($conf['build_dns_type'] && auth('dns_record_add', $debug_val)) { // Get a list of the views so we can build a select option if ($conf['dns_views']) { list($status, $rows, $recs) = db_get_records($onadb, 'dns_views', 'id >= 0', 'name'); $dns_view_list = ''; foreach ($recs as $rec) { $rec['name'] = htmlentities($rec['name']); $dns_view_list .= "<option value=\"{$rec['id']}\">{$rec['name']}</option>\n"; } $html .= <<<EOL <div style="margin: 10px 20px;padding-left: 8px;"> <form> Show config for DNS view: <select name="build_dns_view" id="build_dns_view" class="edit" onchange="xajax_window_submit('{$window_name}', 'fqdn=>{$record['fqdn']},view=>'+el('build_dns_view').value , 'display_config');" > {$dns_view_list} </select> </form> </div> EOL; } $html .= <<<EOL <div id="confoutputdiv" style="border: 1px solid rgb(26, 26, 26); margin: 10px 20px;padding-left: 8px;overflow:hidden;width: 100px;"><pre style='font-family: monospace;overflow-y:auto;' id="confoutput"><center>Generating configuration...</center><br>{$conf['loading_icon']}</pre></div> EOL; $js .= "xajax_window_submit('{$window_name}', 'fqdn=>{$record['fqdn']}', 'display_config');"; } $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); setTimeout('el(\\'confoutputdiv\\').style.width = el(\\'{$form_id}_table\\').offsetWidth-8+\\'px\\';',900); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function rpt_get_data($form) { global $base, $onadb; // If they want to perform a scan on an existing file if ($form['subnet']) { $rptdata['scansource'] = "Based on an existing scan file for '{$form['subnet']}'"; //$xml = shell_exec("{$nmapcommand} -sP -R -oX - {$form['subnet']}"); list($status, $rows, $subnet) = ona_find_subnet($form['subnet']); if ($rows) { $netip = ip_mangle($subnet['ip_addr'], 'dotted'); $netcidr = ip_mangle($subnet['ip_mask'], 'cidr'); $nmapxmlfile = "{$base}/local/nmap_scans/subnets/{$netip}-{$netcidr}.xml"; if (file_exists($nmapxmlfile)) { $xml[0] = xml2ary(file_get_contents($nmapxmlfile)); } else { $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not have an nmap scan XML file on this server. {$nmapxmlfile}"; return array(2, $self['error'] . "\n"); } } else { $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not exist."; return array(2, $self['error'] . "\n"); } } // If they want to build a report on ALL the nmap data if ($form['all']) { $rptdata['scansource'] = "Showing all scan data"; $nmapdir = "{$base}/local/nmap_scans/subnets"; $dh = @opendir($nmapdir); $c = 0; while (false !== ($filename = @readdir($dh))) { if (strpos($filename, 'xml')) { $xml[$c] = xml2ary(file_get_contents($nmapdir . '/' . $filename)); } $c++; } } // If they pass a file from the remote host via CLI if ($form['file']) { $rptdata['scansource'] = "Based on an uploaded XML file"; $nmapxmlfile = $form['file']; // clean up escaped characters $nmapxmlfile = preg_replace('/\\\\"/', '"', $nmapxmlfile); $nmapxmlfile = preg_replace('/\\\\=/', '=', $nmapxmlfile); $nmapxmlfile = preg_replace('/\\\\&/', '&', $nmapxmlfile); $xml[0] = xml2ary($nmapxmlfile); } // loop through all the xml arrays that have been built. for ($z = 0; $z < count($xml); $z++) { // Find out how many total hosts we have in the array $rptdata['totalhosts'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['hosts']['_a']['total']; $rptdata['runtime'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['finished']['_a']['timestr']; // pull args to find subnet/cidr $rptdata['args'] = $xml[$z]['nmaprun']['_a']['args']; // process args list($subnetaddr, $netcidr) = explode('/', preg_replace("/.* (.*)\\/(\\d+)\$/", "\\1/\\2", $rptdata['args'])); $netip = ip_mangle($subnetaddr, 'dotted'); $netcidr = ip_mangle($netcidr, 'cidr'); // Process the array for the total amount of hosts reported for ($i = 0; $i < $rptdata['totalhosts']; $i++) { // Clear MAC each itteration of the loop $macaddr = ''; // Gather some info from the nmap XML file $netstatus = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['status']['_a']['state']; $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr']; //$macaddr = $xml['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr']; $dnsname = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['hostnames']['_c']['hostname']['_a']['name']; $dnsrows = 0; $dns = array(); // Try the older nmap format if no IP found.. not sure of what differences there are in the XSL used? if (!$ipaddr) { $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['0']['_a']['addr']; $macaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['1']['_a']['addr']; } // Lookup the IP address in the database if ($ipaddr) { list($status, $introws, $interface) = ona_find_interface($ipaddr); if (!$introws) { $interface['ip_addr_text'] = 'NOT FOUND'; list($status, $introws, $tmp) = ona_find_subnet($ipaddr); $interface['subnet_id'] = $tmp['id']; } else { // Lookup the DNS name in the database list($status, $dnsrows, $dnscount) = db_get_records($onadb, 'dns', "interface_id = {$interface['id']}", "", 0); list($status, $dnsptrrows, $dnsptr) = ona_get_dns_record(array('interface_id' => $interface['id'], 'type' => 'PTR')); list($status, $dnsprows, $dns) = ona_get_dns_record(array('id' => $dnsptr['dns_id'])); } } // Find out if this IP falls inside of a pool $inpool = 0; $ip = ip_mangle($ipaddr, 'numeric'); if ($ip > 0) { list($status, $poolrows, $pool) = ona_get_dhcp_pool_record("ip_addr_start <= '{$ip}' AND ip_addr_end >= '{$ip}'"); } if ($poolrows) { $inpool = 1; } // some base logic // if host is up in nmap but no db ip then put in $nodb // if host is up and is in db then put in $noissue // if host is down and not in db then skip // if host is down and in db then put in $nonet // if host is up an in db, does DNS match? // in DNS but not DB // in DB but not DNS // DNS and DB dont match // Setup the base array element for the IP $rptdata['ip'][$ipaddr] = array(); $rptdata['ip'][$ipaddr]['netstatus'] = $netstatus; $rptdata['ip'][$ipaddr]['netip'] = $ipaddr; $rptdata['ip'][$ipaddr]['netdnsname'] = strtolower($dnsname); if ($macaddr != -1) { $rptdata['ip'][$ipaddr]['netmacaddr'] = $macaddr; } $rptdata['ip'][$ipaddr]['inpool'] = $inpool; $rptdata['ip'][$ipaddr]['dbip'] = $interface['ip_addr_text']; $rptdata['ip'][$ipaddr]['dbsubnetid'] = $interface['subnet_id']; $rptdata['ip'][$ipaddr]['dbdnsrows'] = $dnsrows; if (!$dns['fqdn']) { // lets see if its a PTR record if ($dnsptrrows) { // If we have a PTR for this interface, use it (never if built from ona?) $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn']; $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn']; } else { // find the hosts primary DNS record list($status, $hostrows, $host) = ona_get_host_record(array('id' => $interface['host_id'])); if ($host['fqdn']) { $host['fqdn'] = "({$host['fqdn']})"; } if ($dnsrows) { list($status, $dnstmprows, $dnstmp) = ona_get_dns_record(array('interface_id' => $interface['id'])); $rptdata['ip'][$ipaddr]['dbdnsname'] = $dnstmp['fqdn']; } else { $rptdata['ip'][$ipaddr]['dbdnsname'] = 'NO PTR'; } $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $host['fqdn']; } } else { if ($dnsptrrows > 1) { $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn']; $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn']; } else { $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn']; $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn']; } } $rptdata['ip'][$ipaddr]['dbmacaddr'] = $interface['mac_addr']; $rptdata['netip'] = $netip; $rptdata['netcidr'] = $netcidr; if ($form['all']) { $rptdata['all'] = 1; } if ($form['update_response']) { $rptdata['update_response'] = 1; } } } return array(0, $rptdata); }
function host_modify($options = "") { global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.07'; printmsg("DEBUG => host_modify({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['interface'] and !$options['host'] or !$options['set_host'] and !$options['set_type'] and !$options['set_location'] and !$options['set_notes']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM host_modify-v{$version} Modify a host record Synopsis: host_modify [KEY=VALUE] ... Where: host=NAME[.DOMAIN] or ID Select host by hostname or ID or interface=[ID|IP|MAC] Select host by IP or MAC Update: set_type=TYPE or ID Change device/model type or ID set_notes=NOTES Change the textual notes set_location=REF Reference for location set_device=NAME|ID Name or ID of the device this host is associated with EOM ); } // clean up what is passed in $options['interface'] = trim($options['interface']); $options['host'] = trim($options['host']); // // Find the host record we're modifying // // If they provided a hostname / ID let's look it up if ($options['host']) { list($status, $rows, $host) = ona_find_host($options['host']); } else { if ($options['interface']) { // Find an interface record by something in that interface's record list($status, $rows, $interface) = ona_find_interface($options['interface']); if ($status or !$rows) { printmsg("DEBUG => Interface not found ({$options['interface']})!", 3); $self['error'] = "ERROR => Interface not found ({$options['interface']})!"; return array(4, $self['error'] . "\n"); } // Load the associated host record list($status, $rows, $host) = ona_get_host_record(array('id' => $interface['host_id'])); } } // If we didn't get a record then exit if (!$host['id']) { printmsg("DEBUG => Host not found ({$options['host']})!", 3); $self['error'] = "ERROR => Host not found ({$options['host']})!"; return array(4, $self['error'] . "\n"); } // Get related Device record info list($status, $rows, $device) = ona_get_device_record(array('id' => $host['device_id'])); // // Define the records we're updating // // This variable will contain the updated info we'll insert into the DB $SET = array(); // Set options['set_type']? if ($options['set_type']) { // Find the Device Type ID (i.e. Type) to use list($status, $rows, $device_type) = ona_find_device_type($options['set_type']); if ($status or $rows != 1 or !$device_type['id']) { printmsg("DEBUG => The device type specified, {$options['set_type']}, does not exist!", 3); $self['error'] = "ERROR => The device type specified, {$options['set_type']}, does not exist!"; return array(6, $self['error'] . "\n"); } printmsg("DEBUG => Device type ID: {$device_type['id']}", 3); // Everything looks ok, add it to $SET if it changed... if ($device['device_type_id'] != $device_type['id']) { $SET_DEV['device_type_id'] = $device_type['id']; } } // Set options['set_notes'] (it can be a null string!) if (array_key_exists('set_notes', $options)) { // There is an issue with escaping '=' and '&'. We need to avoid adding escape characters $options['set_notes'] = str_replace('\\=', '=', $options['set_notes']); $options['set_notes'] = str_replace('\\&', '&', $options['set_notes']); // If it changed... if ($host['notes'] != $options['set_notes']) { $SET['notes'] = $options['set_notes']; } } if (array_key_exists('set_device', $options)) { list($status, $rows, $devid) = ona_find_device($options['set_device']); if (!$rows) { printmsg("DEBUG => The device specified, {$options['set_device']}, does not exist!", 3); $self['error'] = "ERROR => The device specified, {$options['set_device']}, does not exist!"; return array(7, $self['error'] . "\n"); } // set the device id if ($host['device_id'] != $devid['id']) { $SET['device_id'] = $devid['id']; } } if (array_key_exists('set_location', $options)) { if (!$options['set_location']) { unset($SET_DEV['location_id']); } else { list($status, $rows, $loc) = ona_find_location($options['set_location']); if (!$rows) { printmsg("DEBUG => The location specified, {$options['set_location']}, does not exist!", 3); $self['error'] = "ERROR => The location specified, {$options['set_location']}, does not exist!"; return array(7, $self['error'] . "\n"); } // If location is changing, then set the variable if ($device['location_id'] != $loc['id']) { $SET_DEV['location_id'] = $loc['id']; } } } // Check permissions if (!auth('host_modify')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // Get the host record before updating (logging) $original_host = $host; // Update the host record if necessary if (count($SET) > 0) { list($status, $rows) = db_update_record($onadb, 'hosts', array('id' => $host['id']), $SET); if ($status or !$rows) { $self['error'] = "ERROR => host_modify() SQL Query failed for host: " . $self['error']; printmsg($self['error'], 0); return array(8, $self['error'] . "\n"); } } // Update device table if necessary if (count($SET_DEV) > 0) { list($status, $rows) = db_update_record($onadb, 'devices', array('id' => $host['device_id']), $SET_DEV); if ($status or !$rows) { $self['error'] = "ERROR => host_modify() SQL Query failed for device type: " . $self['error']; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } } // Get the host record after updating (logging) list($status, $rows, $new_host) = ona_get_host_record(array('id' => $host['id'])); // Return the success notice $self['error'] = "INFO => Host UPDATED:{$host['id']}: {$new_host['fqdn']}"; $log_msg = "INFO => Host UPDATED:{$host['id']}: "; $more = ""; foreach (array_keys($host) as $key) { if ($host[$key] != $new_host[$key]) { $log_msg .= "{$more}{$key}: {$host[$key]} => {$new_host[$key]}"; $more = "; "; } } // only print to logfile if a change has been made to the record if ($more != '') { printmsg($self['error'], 0); printmsg($log_msg, 0); } return array(0, $self['error'] . "\n"); }
$hasserver = "<img src='{$images}/silk/error.png' border='0'>"; $rowstyle = 'style="background-color: #FFDDDD;" title="There is no DHCP server defined for this pool!"'; } $pool['ip_addr_start'] = ip_mangle($pool['ip_addr_start'], 'dotted'); $pool['ip_addr_end'] = ip_mangle($pool['ip_addr_end'], 'dotted'); $modbodyhtml .= <<<EOL <tr {$rowstyle}> <td align="left" nowrap="true"> {$hasserver} {$pool['ip_addr_start']} Thru {$pool['ip_addr_end']} EOL; // Display information about what pool group this pool is assigned to // TODO: make this more efficient. seems like there would be a better way to do this if ($pool['dhcp_failover_group_id']) { list($status, $rows, $failover_group) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'])); list($status, $rows, $server_host1) = ona_get_host_record(array('id' => $failover_group['primary_server_id'])); list($status, $rows, $server_host2) = ona_get_host_record(array('id' => $failover_group['secondary_server_id'])); $modbodyhtml .= <<<EOL <a title="View DHCP server (Primary failover) - {$server_host1['fqdn']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_dhcp_server\\', \\'host_id=>{$server_host1['id']}\\', \\'display\\')');" >{$server_host1['name']}</a>/ <a title="View DHCP server (Secondary failover) - {$server_host2['fqdn']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_dhcp_server\\', \\'host_id=>{$server_host2['id']}\\', \\'display\\')');" >{$server_host2['name']}</a> EOL; } $modbodyhtml .= <<<EOL </td> <td align="right" nowrap="true"> <form id="form_dhcp_pool_{$pool['id']}"
function ws_display($window_name, $form = '') { global $conf, $self, $onadb, $base; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the host record if ($form['host_id']) { list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id'])); } else { if ($form['host']) { list($status, $rows, $record) = ona_find_host($form['host']); } } if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Host doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Update History Title (and tell the browser to re-draw the history div) $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = $record['name']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; // FIXME: umm.. put this somewhere else if (!$record['name']) { $record['name'] = "NONE SET"; } // Interface (and find out how many there are) list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id']), ''); $record['ip_address'] = ip_mangle($interface['ip_addr'], 'dotted'); $interface_style = ''; if ($interfaces > 1) { $interface_style = 'font-weight: bold;'; } // Subnet description list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); $record['subnet'] = $subnet['name']; $record['subnet_id'] = $subnet['id']; $record['ip_subnet_mask'] = ip_mangle($subnet['ip_mask'], 'dotted'); $record['ip_subnet_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr'); // Device Description list($status, $rows, $device) = ona_get_device_record(array('id' => $record['device_id'])); $record['device_type_id'] = $device['device_type_id']; list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id'])); list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $record['devicefull'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})"; $record['device'] = str_replace('Unknown', '?', $record['devicefull']); $record['location_id'] = $device['location_id']; // Device serial number and/or asset tag $record['serial_number'] = $device['serial_number']; $record['asset_tag'] = $device['asset_tag']; // Get location_number from the location_id list($status, $rows, $location) = ona_get_location_record(array('id' => $record['location_id'])); // extra stuff to pass to ws_plugins $extravars['refresh'] = $refresh; $extravars['window_name'] = $window_name; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } // Create a div for workspace plugins to live $html .= "<div id='wsplugins' style='margin: 10px;'>"; // Start displaying all the ws plugins $wspl = workspace_plugin_loader('host_detail', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('host_services', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('custom_attributes', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('config_archives', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Display the host_action workspace_plugin $wspl = workspace_plugin_loader('host_actions', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Display messages $wspl = workspace_plugin_loader('messages', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('reports', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Get all the plugin based worspace items $wspl_list = plugin_list('wspl_item'); // Load all the dynamic plugins foreach ($wspl_list as $p) { $wspl = workspace_plugin_loader($p['path'], $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; } // Gather our menuitems and build the HTML $wsmenuhtml = build_workspace_menu($wsmenu); $html .= <<<EOL </div> <br style="clear:both;"> <form id="form_host_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div> EOL; // RECORD LIST $tab = 'records'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- INTERFACE LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated DNS {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="host_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" title="Filter" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Name</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('host_add', $debug_val)) { $html .= <<<EOL <!-- ADD RECORD LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_record_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Add DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" ><img src="{$images}/silk/font_add.png" border="0"></a> <a title="Add DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" >Add DNS record</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // INTERFACE LIST $tab = 'interfaces'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- INTERFACE LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="host_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" title="Filter" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Full IP</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('host_add', $debug_val)) { $html .= <<<EOL <!-- ADD INTERFACE LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_interface_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');" >Add interface</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function build_bind_conf($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.51'; printmsg("DEBUG => build_bind_conf({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['server'] and $options['path'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOF build_bind_conf-v{$version} Builds a named.conf for a dns server from the database (bind 8+) Synopsis: build_bind_conf [KEY=VALUE] ... Required: server=NAME[.DOMAIN] or ID Build conf by server name or ID path=STRING Absolute prefix path for local zone files Notes: * Specified host must be a valid DNS server * Paths are absolute but MUST NOT contain a leading /, this will be added. EOF ); } // NOTE: the whole path absolute thing with no leading slash is confusing I know // the problem here is that DCM.pl tries to load the contents of the path you pass in // as a file and will always return blank for path. this is a work around for now // until dcm gets fixed. Maybe fix it by checking if it is a DIR or a FILE. // Determine the hostname and domain to be used -- // i.e. add the default domain, or find the part of the host provided // that will be used as the "zone" or "domain". This means testing many // zone name's against the DB to see what's valid. list($status, $rows, $shost) = ona_find_host($options['server']); printmsg("DEBUG => build_bind_conf() server record: {$domain['server']}", 3); if (!$shost['id']) { printmsg("DEBUG => Unknown server record: {$options['server']}", 3); $self['error'] = "ERROR => Unknown server record: {$options['server']}"; return array(3, $self['error'] . "\n"); } // For the given server id. find all domains for that server list($status, $rows, $records) = db_get_records($onadb, 'dns_server_domains', array('host_id' => $shost['id']), ''); // Start building the named.conf - save it in $text $text = "# Named.conf file for {$shost['fqdn']} built on " . date($conf['date_format']) . "\n"; $text .= "# TOTAL DOMAINS (count={$rows})\n\n"; ////////////// Header stuff ////////////////// // Allow for a local header include.. I expect this to rarely be used // MP: it is probably best to let the user set up all their own stuff and just include the resulting config // file in whatever their own config is. SOOO no need for this // $text .= "; Allow for a local header include.. I expect this to rarely be used.\n"; // $text .= "include \"/etc/named.conf-header\";\n\n"; ////////////// End Header stuff ////////////////// foreach ($records as $sdomain) { list($status, $rows, $domain) = ona_get_domain_record(array('id' => $sdomain['domain_id'])); // what is the role for this server. switch (strtolower($sdomain['role'])) { case "forward": //TODO: fixme.. this needs IPs like slaves do.. no file $text .= "zone \"{$domain['fqdn']}\" in {\n type forward;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";}\n"; break; case "master": $text .= "zone \"{$domain['fqdn']}\" in {\n type master;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";\n};\n\n"; break; case "slave": // get the IP addresses for the master domain servers for this domain list($status, $rows, $records) = db_get_records($onadb, 'dns_server_domains', array('domain_id' => $domain['id'], 'role' => 'master'), ''); // TODO: if there are no rows then bail // TODO: look for static master list stored in DB and append it to the list. $text .= "zone \"{$domain['fqdn']}\" in {\n type slave;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";\n masterfile-format text;\n"; // Print the master statement $text .= " masters { "; foreach ($records as $master) { // Lookup a bunch of crap.. this should be done better. list($status, $rows, $rec) = ona_get_host_record(array('id' => $master['host_id'])); list($status, $rows, $rec) = ona_get_dns_record(array('id' => $rec['primary_dns_id'])); list($status, $rows, $rec) = ona_get_interface_record(array('id' => $rec['interface_id'])); $text .= $rec['ip_addr_text'] . "; "; } $text .= "};\n"; $text .= "};\n\n"; break; default: $text .= "# {$domain['name']} has an invalid value for the column ROLE.\n"; break; } } // Return the config file return array(0, $text); }
// Redirecting you to: <a href="{$https}{$baseURL}/login.php">{$https}{$baseURL}/login.php</a> // <script type="text/javascript"><!-- // setTimeout("window.location = \"{$https}{$baseURL}/login.php\";", 1000); // --></script> // </body></html> // EOL; // exit; // } // This code is to provide a proper file attachment download for configuration archives // If they have a session go for it if ($_SESSION['ona']['auth']['user']['username']) { if (auth('host_config_admin', $debug_val)) { if ($_REQUEST['config_id'] and $_REQUEST['download']) { // Generate a SQL query to get the config to display list($status, $rows, $config) = ona_get_config_record(array('id' => $_REQUEST['config_id'])); if (!$config['id']) { print "<html><body>Configuration record doesn't exist!</body></html>"; } list($status, $rows, $host) = ona_get_host_record(array('id' => $config['host_id'])); // Print the config file and exit $size = strlen($config['config_body']); header("Content-Disposition: attachment; filename=\"{$host['fqdn']}-{$config['config_type_name']}.txt\"; size=\"{$size}\""); print $config['config_body']; exit; } } else { print "<html><body>ERROR: You are unauthorized for this page!</body></html>"; } } else { print "<html><body>ERROR: You are unauthorized for this page!</body></html>"; }
function ws_display($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the server record list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id'])); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Server doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Pick up host information list($status, $rows, $host) = ona_find_host($form['host_id']); $record['fqdn'] = $host['fqdn']; // Update History Title $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = "DHCP server - " . $record['name']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; // extra stuff to pass to ws_plugins $extravars['refresh'] = $refresh; $extravars['window_name'] = $window_name; $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; vertical-align: top; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <!-- FORMATTING TABLE --> <div style="{$style['content_box']}"> <table cellspacing="0" border="0" cellpadding="0"><tr> <!-- START OF FIRST COLUMN OF SMALL BOXES --> <td nowrap="true" valign="top" style="padding-right: 15px;"> EOL; // SERVER INFORMATION $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <!-- LABEL --> <tr><td colspan="99" nowrap="true" style="{$style['label_box']}"> DHCP server <a title="View host" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$record['id']}\\', \\'display\\')');" >{$record['name']}</a>.<a title="View domain. ID: {$record['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$record['domain_id']}\\', \\'display\\')');" >{$record['domain_fqdn']}</a> </td></tr> </table> EOL; // END SERVER INFORMATION $html .= <<<EOL <!-- END OF FIRST COLUMN OF SMALL BOXES --> </td> <!-- START OF SECOND COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; // FAILOVER GROUP INFO BOX // get failover group information list($status, $rows, $failover_groups) = db_get_records($onadb, 'dhcp_failover_groups', "primary_server_id = {$record['id']} or secondary_server_id = {$record['id']}"); if ($rows) { $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <!-- LABEL --> <tr><td colspan="2" nowrap="true" style="{$style['label_box']}">Failover groups</td></tr> EOL; foreach ($failover_groups as $failover) { // Get DNS name for primary and secondary servers list($status, $rows, $fail_pri_host) = ona_get_host_record(array('id' => $failover['primary_server_id'])); list($status, $rows, $fail_sec_host) = ona_get_host_record(array('id' => $failover['secondary_server_id'])); $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td align="left">GROUP_ID-{$failover['id']}: {$fail_pri_host['name']}<img src="{$images}/silk/link.png" border="0">{$fail_sec_host['name']} </td> <td align="right"> <a title="Edit failover group. ID: {$failover['id']}" class="act" onClick="xajax_window_submit('edit_dhcp_failover_group', '{$failover['id']}', 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> </td> </tr> </table> EOL; } } // END FAILOVER GROUP INFO BOX $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THRID COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; // Start displaying all the ws plugins $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; //DONT add the, not needed $wsmenu{}=$wspl[2]; // This will display the server level, not global level $extravars['dhcpserver_id'] = $host['id']; $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wsmenuhtml = build_workspace_menu($wsmenu); $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <form id="form_server_{$record['id']}" ><input type="hidden" name="server_id" value="{$host['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <form id="form_global_{$record['id']}" ><input type="hidden" name="global_id" value="0" ><input type="hidden" name="js" value="{$refresh}" ></form> <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div> <!-- END OF TOP SECTION --> EOL; // SUBNET LIST $tab = 'dhcp_server'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- SUBNET LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_subnets_tab" class="table-tab-active"> Assigned Subnets <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="server_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Filter</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_dhcp_server_{$record['id']}" ><input type="hidden" name="server" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <!-- ADD SUBNET LINK --> <a title="Assign subnet to DHCP server" class="act" onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Assign subnet to DHCP server" class="act" onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');" >Assign subnet</a> </div> EOL; } $html .= <<<EOL </div> EOL; // If we have a build type set, then display the output div if ($conf['build_dhcp_type'] && auth('advanced', $debug_val)) { $html .= <<<EOL <div id="confoutputdiv" style="border: 1px solid rgb(26, 26, 26); margin: 10px 20px;padding-left: 8px;overflow:hidden;width: 100px;"><pre style='font-family: monospace;overflow-y:auto;' id="confoutput"><center>Generating configuration...</center><br>{$conf['loading_icon']}</pre></div> EOL; $js .= "xajax_window_submit('{$window_name}', 'fqdn=>{$record['fqdn']}', 'display_config');"; } $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); setTimeout('el(\\'confoutputdiv\\').style.width = el(\\'{$form_id}_table\\').offsetWidth-8+\\'px\\';',900); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function interface_move_host($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => interface_move_host({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.00'; // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['host'] and $options['ip'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM interface_move_host-v{$version} Move an interface to a new host Synopsis: interface_move_host [KEY=VALUE] ... Required: ip=[address|ID] the IP address or ID of the interface host=[fqdn|ID] the fqdn or ID of the new host EOM ); } // Find the Host they are looking for list($status, $rows, $host) = ona_find_host($options['host']); if (!$host['id']) { printmsg("DEBUG => The host specified, {$options['host']}, does not exist!", 3); $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!"; return array(2, $self['error'] . "\n"); } printmsg("DEBUG => Host selected: {$options['host']}", 3); // Find the interface that is moving list($status, $rows, $interface) = ona_find_interface($options['ip']); if (!$interface['id']) { printmsg("DEBUG => The interface specified, {$options['ip']}, does not exist!", 3); $self['error'] = "ERROR => The interface specified, {$options['ip']}, does not exist!"; return array(3, $self['error'] . "\n"); } // check if this interface is the primary DNS interface address. list($status, $rows, $primaryhost) = ona_get_host_record(array('id' => $interface['host_id'])); list($status, $rows, $primarydns) = ona_get_dns_record(array('id' => $primaryhost['primary_dns_id'])); if ($primarydns['interface_id'] == $interface['id']) { printmsg("DEBUG => This interface is part of the primary DNS name for {$primaryhost['fqdn']}, please assign a new primary DNS.", 3); $self['error'] = "ERROR => This interface is part of the primary DNS name for {$primaryhost['fqdn']}, please assign a new primary DNS."; return array(4, $self['error'] . "\n"); } // if this is the last interface on the host display a message // TODO: MP is this best? I would think a lot of people WANT to move the last IP before removing the host // it would cut some steps of having to delete/re-add when moving an IP. maybe allow this?!? // ------ Since most hosts use the last interface as a primary dns id then they cant move the last interface.-------- // list($status, $rows, $int) = db_get_records($onadb, 'interfaces', array('host_id' => $interface['host_id'], '', 0); // if ($rows == 1) { // printmsg("DEBUG => You cannot delete the last interface on a host, you must delete the host itself ({$host['fqdn']}).",3); // $self['error'] = "ERROR => You can not delete the last interface on a host, you must delete the host itself ({$host['fqdn']})."; // return(array(5, $self['error'] . "\n")); // } printmsg("DEBUG => Interface selected: {$options['ip']}", 3); // Check that this interface is not associated with this host via an interface_cluster list($status, $rows, $int_cluster) = db_get_records($onadb, 'interface_clusters', array('host_id' => $host['id'], 'interface_id' => $interface['id']), '', 0); printmsg("DEBUG => interface_move_host() New host is clustered with this IP, Deleting cluster record", 3); if ($rows == 1) { // Delete the interface_cluster if there is one list($status, $rows) = db_delete_records($onadb, 'interface_clusters', array('interface_id' => $interface['id'], 'host_id' => $host['id'])); if ($status or !$rows) { $self['error'] = "ERROR => interface_move_host() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(14, $self['error'] . "\n"); } } // If the interface being moved has a NAT IP then the ext interface needs the host_id updated as well if ($interface['nat_interface_id'] > 0) { printmsg("DEBUG => interface_move_host() Moving interface with NAT IP.", 3); list($status, $rows) = db_update_record($onadb, 'interfaces', array('id' => $interface['nat_interface_id']), array('host_id' => $host['id'])); if ($status or !$rows) { $self['error'] = "ERROR => interface_move_host() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(15, $self['error'] . "\n"); } } // Update the interface record list($status, $rows) = db_update_record($onadb, 'interfaces', array('id' => $interface['id']), array('host_id' => $host['id'])); if ($status or !$rows) { $self['error'] = "ERROR => interface_move_host() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(16, $self['error'] . "\n"); } $text = "INFO => Interface " . ip_mangle($interface['ip_addr'], 'dotted') . " moved to {$host['fqdn']}"; printmsg($text, 0); // Return the success notice return array(0, $text . "\n"); }