function get_module_list($options = "type=string") { global $conf, $self, $onadb; printmsg('DEBUG => get_module_list(' . $options . ') called', 3); // Version - UPDATE on every edit! $version = '1.01'; // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['type']) { $self['error'] = 'ERROR => Insufficient parameters'; // NOTE: Help message lines should not exceed 80 characters for proper display on a console return array(1, <<<EOM get_module_list-v{$version} Returns a list of available DCM modules Synopsis: get_module_list(OPTIONS) Options: type=<string|perl|array> format module list in the specified format string = human readable for console perl = hash for perl parsing array = php array EOM ); } // $pad_length is the amount of padding to put after each NAME. $pad_length = 25; $modules_string = str_pad('NAME', $pad_length) . " :: DESCRIPTION\n"; $modules_perl = ""; $modules_array = array(); // Get a list of the valid "modules" and their descriptions. // FIXME: move this to the db later! list($status, $rows, $modules) = db_get_records($onadb, 'dcm_module_list', '1', 'name'); printmsg("DEBUG => get_module_list() found {$rows} modules in db", 4); foreach ($modules as $module) { if ($module['name'] != 'get_module_list') { $modules_string .= str_pad($module['name'], $pad_length) . " :: {$module['description']}\n"; } $modules_array[$module['name']] = $module['description']; $modules_perl .= "\$modules{'{$module['name']}'} = \"{$module['description']}\";\n"; } // Return the list of modules as a string or array. if ($options['type'] == 'string') { return array(0, "\n" . $modules_string . "\n"); } else { if ($options['type'] == 'array') { return array(0, $modules_array); } else { if ($options['type'] == 'perl') { return array(0, $modules_perl); } else { return array(3, "ERROR => get_module_list() Invalid \"type\" specified!"); } } } }
function ws_display_list($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); // Override system default for lists.. we want logs to show more $conf['search_results_per_page'] = 20; // 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']; } // 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; // Start building the "where" clause for the sql query to find the vlans to display $where = ""; $and = ""; // DISPLAY ALL VLAN CAMPUSES if ($form['all_flag']) { $where .= $and . "id > 0"; $and = " AND "; } // CAMPUS ID if ($form['id']) { $where .= $and . "id = " . $onadb->qstr($form['id']); $and = " AND "; } // CAMPUS NAME if ($form['username']) { $where .= $and . " username LIKE " . $onadb->qstr('%' . $form['username'] . '%'); $and = " AND "; } // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything. if ($where == '') { $where = 'id > 0'; } // Do the SQL Query $filter = ''; if ($form['filter']) { $filter = ' AND username LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } list($status, $rows, $results) = db_get_records($onadb, 'ona_logs', $where . $filter, "timestamp DESC", $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, 'ona_logs', $where . $filter, "", 0); } } $count = $rows; $html .= <<<EOL <!-- List --> <table id="{$form['form_id']}_ona_db_logs_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">Timestamp</td> <td class="list-header" align="center" style="{$style['borderR']};">Username</td> <td class="list-header" align="center" style="{$style['borderR']};">Remote location</td> <td class="list-header" align="center" style="{$style['borderR']};">Context</td> <td class="list-header" align="center">Message</td> </tr> EOL; // Loop and display each record foreach ($results as $record) { // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td class="list-row"> {$record['timestamp']} </td> <td class="list-row" align="left"> {$record['username']} </td> <td class="list-row"> {$record['remote_addr']} </td> <td class="list-row"> {$record['context_name']} </td> <td class="list-row"> {$record['message']} </td> </tr> EOL; } $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']); // If there was only 1 result, and we're about to display results in the "Search Results" window, display it. if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '') { $js .= $primary_object_js; } // 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(); }
<td colspan="5" align="left" valign="middle" nowrap="true" class="act-box"> <form id="form_dhcp_entry_add_{$kind}_{$record['id']}" ><input type="hidden" name="{$kind}_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$extravars['refresh']}" ></form> <a title="Add DHCP Entry" class="act" onClick="xajax_window_submit('edit_dhcp_option_entry', xajax.getFormValues('form_dhcp_entry_add_{$kind}_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Add DHCP Entry" class="act" onClick="xajax_window_submit('edit_dhcp_option_entry', xajax.getFormValues('form_dhcp_entry_add_{$kind}_{$record['id']}'), 'editor');" >Add DHCP Entry</a> </td> </tr> EOL; } $modbodyhtml .= "</table>"; } // Show a menu warning about gateway missing if ($kind == 'subnet' and $hasgateway == 0) { list($status, $rows, $dhcp_servers) = db_get_records($onadb, 'dhcp_server_subnets', array('subnet_id' => $record['id'])); if ($rows or $poolrows) { $modwsmenu[0]['menutitle'] = "Add DHCP Entry <span style='background-color: #FFDDDD;'>(<img src='{$images}/silk/error.png' border='0'>Gateway)</span>"; } } // END DHCP ENTRIES LIST unset($rec_content);
<?php $title_left_html = 'Custom Attributes'; // Determine if this is a host, a subnet or a vlan we are dealing with if (is_numeric($record['subnet_type_id'])) { $kind = 'subnet'; } elseif (is_numeric($record['device_id'])) { $kind = 'host'; } else { $kind = 'vlan'; } // This adds an "s" at the end of the table name. assumes all tables are plural list($status, $rows, $attributes) = db_get_records($onadb, 'custom_attributes', array('table_id_ref' => $record['id'], 'table_name_ref' => $kind . 's'), ''); // create workspace menu items // This is where you list an array of menu items to display for this workspace $modwsmenu[0]['menutitle'] = 'Add Custom Attribute'; $modwsmenu[0]['tooltip'] = "Add Custom Attribute to this {$kind}"; $modwsmenu[0]['authname'] = 'custom_attribute_add'; $modwsmenu[0]['commandjs'] = "xajax_window_submit('edit_custom_attribute', xajax.getFormValues('form_{$kind}_{$record['id']}'), 'editor');"; $modwsmenu[0]['image'] = '/images/silk/tag_blue.png'; // CUSTOM ATTRIBUTES LIST if ($rows) { $modbodyhtml .= <<<EOL <!-- CUSTOM ATTRIBUTES --> <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px; margin-top: 0px;"> EOL; foreach ($attributes as $entry) { list($status, $rows, $ca_type) = ona_get_custom_attribute_record(array('id' => $entry['id'])); $modbodyhtml .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';">
function config_diff($options = "") { // The important globals global $conf; global $self; global $onadb; // Version - UPDATE on every edit! $version = '1.03'; printmsg('DEBUG => config_diff(' . $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['host'] or !$options['type']) and (!$options['ida'] or !$options['idb'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console return array(1, <<<EOM config_diff-v{$version} Displays the difference between selected archive entries Synopsis: config_diff [KEY=VALUE] ... Required: host=ID or NAME[.DOMAIN] display most recent config for specified host type=TYPE type of config to display - usually "IOS_VERSION" or "IOS_CONFIG" OR ida=ID First config ID to compare against idb idb=ID Second config ID to compare against ida Note: If you don't pass any IDs you will get the two most recent configs related to the host/type you provide. EOM ); } $text = ""; // Compare arbitrary configs based on config IDs // If we have ids, lets use those instead if ($options['ida'] and $options['idb']) { // get the two configs from the db list($status, $rows, $configs) = db_get_records($onadb, 'configurations', "id in ({$options['ida']},{$options['idb']})", 'ctime DESC', '2', ''); } else { // Get a config record if there is one $self['error'] = ""; list($status, $rows, $config) = ona_find_config($options); list($status, $rows, $configs) = db_get_records($onadb, 'configurations', array('host_id' => $config['host_id'], 'configuration_type_id' => $config['configuration_type_id']), 'ctime DESC', '2', ''); } // Error if an error was returned if ($status or $rows != 2) { if ($self['error']) { $text = $self['error'] . "\n"; } $text .= "ERROR => One or more config text entries not found!\n"; return array(2, $text); } // Get a unified text diff output $text .= text_diff($configs[1]['config_body'], $configs[0]['config_body']); // Return the success notice return array(0, $text); }
function ws_interface_move_save($window_name, $form = '') { global $base, $include, $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; $refresh = "xajax_window_submit('list_interfaces', xajax.getFormValues('list_interfaces_filter_form'), 'display_list');"; // Validate input if (!$form['host'] and !$form['ip']) { $response->addScript("alert('Please complete all fields to continue!');"); return $response->getXML(); } list($status, $total_interfaces, $ints) = db_get_records($onadb, 'interfaces', array('host_id' => $form['orig_host']), '', 0); // Decide if we're editing or adding $module = 'interface_move_host'; // Run the module list($status, $output) = run_module($module, $form); // If the module returned an error code display a popup warning if ($status) { $js .= "alert('Save failed. " . preg_replace('/[\\s\']+/', ' ', $self['error']) . "');"; } else { // Check if this is the last interface, if it is, delete the host too. if ($total_interfaces == 0) { // Run the host del module list($status, $output) = run_module('host_del', array('host' => $form['orig_host'], 'commit' => 'y')); if ($status) { // If the host del failed, move the interface back to the original host to clean things up list($status, $output) = run_module('interface_move_host', array('host' => $form['orig_host'], 'ip' => $form['ip'])); $js .= "alert('Host delete failed. " . preg_replace('/[\\s\']+/', ' ', $self['error']) . "');"; } else { $js .= "removeElement('{$window_name}');{$refresh}"; if ($form['js']) { $js .= $form['js']; } } } else { $js .= "removeElement('{$window_name}');{$refresh}"; if ($form['js']) { $js .= $form['js']; } } } // Insert the new table into the window $response->addScript($js); return $response->getXML(); }
function dns_record_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => dns_record_del({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.03'; // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['name']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dns_record_del-v{$version} Deletes a DNS record from the database Synopsis: dns_record_del [KEY=VALUE] ... Required: name=NAME[.DOMAIN] or ID hostname or ID of the record to delete type=TYPE record type (A,CNAME,PTR...) Optional: ip=ADDRESS ip address (numeric or dotted) commit=[yes|no] commit db transaction (no) EOM ); } /* thoughts on the flow of things: A records: remove any CNAMES using this A record remove any PTR records using this A record test that it is not a primary_dns_id, if it is, it must be reassigned should make a find_dns_record(s) function. a find by host option would be good. need to do a better delete of DNS records when deleting a host.. currently its a problem. MP: TODO: this delete will not handle DNS views unless you use the ID of the record to delete. add a view option at some point. */ // If the name we were passed has a leading . in it then remove the dot. $options['name'] = preg_replace("/^\\./", '', $options['name']); // FIXME: MP Fix this to use a find_dns_record function ID only for now // Find the DNS record from $options['name'] list($status, $rows, $dns) = ona_find_dns_record($options['name'], $options['type']); printmsg("DEBUG => dns_record_del() DNS record: {$options['name']}", 3); if (!$dns['id']) { printmsg("DEBUG => Unknown DNS record: {$options['name']} ({$options['type']})", 3); $self['error'] = "ERROR => Unknown DNS record: {$options['name']} ({$options['type']})"; return array(2, $self['error'] . "\n"); } // Check permissions if (!auth('host_del') or !authlvl($host['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // If "commit" is yes, delete the host if ($options['commit'] == 'Y') { $text = ""; $add_to_error = ""; // SUMMARY: // Display any associated PTR records for an A record // Display any associated CNAMEs for an A record // Test if it is used as a primary_dns_id unless it is the host_del module calling if (!isset($options['delete_by_module'])) { list($status, $rows, $srecord) = db_get_record($onadb, 'hosts', array('primary_dns_id' => $dns['id'])); if ($rows) { $self['error'] = "ERROR => dns_record_del() The DNS record, {$dns['name']}.{$dns['domain_fqdn']}[{$dns['id']}], is a primary A record for a host! You can not delete it until you associate a new primary record, or delete the host."; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } } // Delete related Points to records // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'dns', array('dns_id' => $dns['id'])); // do the delete list($status, $rows) = db_delete_records($onadb, 'dns', array('dns_id' => $dns['id'])); if ($status) { $self['error'] = "ERROR => dns_record_del() Child record delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } if ($rows) { // log deletions // FIXME: do better logging here printmsg("INFO => {$rows} child DNS record(s) DELETED from {$dns['fqdn']}", 0); $add_to_error .= "INFO => {$rows} child record(s) DELETED from {$dns['fqdn']}\n"; } // TRIGGER: flag the domains for rebuild foreach ($records as $record) { list($status, $rows) = db_update_record($onadb, 'dns_server_domains', array('domain_id' => $record['domain_id']), array('rebuild_flag' => 1)); if ($status) { $self['error'] = "ERROR => dns_record_del() Unable to update rebuild flags for domain.: {$self['error']}"; printmsg($self['error'], 0); return array(7, $self['error'] . "\n"); } } // Delete the DNS record list($status, $rows) = db_delete_records($onadb, 'dns', array('id' => $dns['id'])); if ($status) { $self['error'] = "ERROR => dns_record_del() DNS record delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } // TRIGGER: flag the current dnsrecords domain for rebuild list($status, $rows) = db_update_record($onadb, 'dns_server_domains', array('domain_id' => $dns['domain_id']), array('rebuild_flag' => 1)); if ($status) { $self['error'] = "ERROR => dns_record_del() Unable to update rebuild flags for domain.: {$self['error']}"; printmsg($self['error'], 0); return array(7, $self['error'] . "\n"); } // FIXME: if it is a NS or something display a proper FQDN message here // Display proper PTR information if ($dns['type'] == 'PTR') { list($status, $rows, $pointsto) = ona_get_dns_record(array('id' => $dns['dns_id']), ''); list($status, $rows, $ptrint) = ona_get_interface_record(array('id' => $dns['interface_id']), ''); $ipflip = ip_mangle($ptrint['ip_addr'], 'flip'); $octets = explode(".", $ipflip); if (count($octets) > 4) { $arpa = '.ip6.arpa'; $octcount = 31; } else { $arpa = '.in-addr.arpa'; $octcount = 3; } $dns['fqdn'] = "{$ipflip}{$arpa} -> {$pointsto['fqdn']}"; } // Return the success notice $self['error'] = "INFO => DNS {$dns['type']} record DELETED: {$dns['fqdn']}"; printmsg($self['error'], 0); return array(0, $add_to_error . $self['error'] . "\n"); } // // We are just displaying records that would have been deleted // // SUMMARY: // Display any associated PTR records for an A record // Display any associated CNAMEs for an A record // Otherwise just display the host record for the host we would have deleted $text = "Record(s) NOT DELETED (see \"commit\" option)\n" . "Displaying record(s) that would have been deleted:\n"; // Test if it is used as a primary_dns_id list($status, $rows, $srecord) = db_get_record($onadb, 'hosts', array('primary_dns_id' => $dns['id'])); if ($rows) { $text .= "\nWARNING! This DNS record is a primary A record for a host\n"; } // Display the complete dns record list($status, $tmp) = dns_record_display("name={$dns['id']}&verbose=N"); $text .= "\n" . $tmp; // Display associated Child records list($status, $rows, $records) = db_get_records($onadb, 'dns', array('dns_id' => $dns['id'])); if ($rows) { $text .= "\nASSOCIATED POINTS-TO RECORDS ({$rows}):\n"; } foreach ($records as $record) { if ($record['type'] == 'NS') { $record['name'] = ''; } // FIXME:I could fix this but I'm lazy if ($record['type'] == 'PTR') { $record['name'] = '??'; } list($status, $rows, $domain) = ona_get_domain_record(array('id' => $record['domain_id']), ''); $text .= " {$record['type']}: {$record['name']}.{$domain['fqdn']} -> {$dns['fqdn']}\n"; } return array(7, $text); }
function build_dhcpd_conf($options = "") { global $self; global $conf; global $onadb; // Version - UPDATE on every edit! $version = '1.10'; // Exit status of the function $exit = 0; printmsg('DEBUG => build_dhcpd_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']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console return array(1, <<<EOM build_dhcpd_conf-v{$version} Builds configuration for dhcpcd from the database Synopsis: build_dhcpd_conf [KEY=VALUE] ... Required: server=NAME[.DOMAIN] or ID Build conf by hostname or HOST_ID Optional: header_path=PATH Path to the server local header to include Notes: * Specified host must be a valid DHCP server * header_path is a file on the DHCP server. It will be defined at the very top of your configuration using the DHCP "include" directive. EOM ); } // TODO: ipv6 need to pass in if we want v4 or v6.. default to v4 for now. // looks like you cant have a mixed config // Debugging printmsg("DEBUG => Building DHCP config for: {$options['server']}", 3); // Validate that there is already a host named $options['server']. list($status, $rows, $host) = ona_find_host($options['server']); if (!$host['id']) { return array(2, "ERROR => No such host: {$options['server']}\n"); } // Now determine if that host is a valid server list($status, $dhcp_rows, $dhcp_server) = db_get_records($onadb, 'dhcp_server_subnets', array('host_id' => $host['id']), ''); list($status, $dhcpf_rows, $dhcpf_server) = db_get_records($onadb, 'dhcp_failover_groups', "primary_server_id = {$host['id']} or secondary_server_id = {$host['id']}", ''); if ($dhcp_rows == 0 and $dhcpf_rows == 0) { return array(3, "ERROR => Specified host is not a DHCP server: {$options['server']}\n"); } // Throw the host id into a self variable for later use $self['serverid'] = $host['id']; // Start an output variable with build timestamp $text .= "###### DO NOT EDIT THIS FILE ###### \n"; $text .= "# dhcpd.conf file for {$host['fqdn']} built on " . date($conf['date_format']) . "\n#\n"; $text .= "# This file is built by an automated script. Any change to this \n"; $text .= "# file will be lost at the next build.\n\n"; // setup standard include path // TODO: MP possibly put this into a configuration option like header so the user can easily change where this is. if (isset($options['header_path'])) { $text .= "include \"{$options['header_path']}\";\n"; } /////////////////////////////// Build global options ////////////////////////////////////////// list($status, $globals) = build_global($host['id']); $text .= $globals; /////////////////////////////// Failover groups ////////////////////////////////////////// // build list of failover group statements for provided server list($status, $failovergroup) = ona_dhcp_build_failover_group($host['id']); $text .= $failovergroup; /////////////////////////////// shared subnets ////////////////////////////////////////// // setup a variable to keep track of which vlan we are on $vlananchor = ''; // Loop through all of the vlan subnets and print them printmsg("DEBUG => Processing all Shared (VLAN) Subnets", 1); $i = 0; do { list($status, $rows, $vlan_subnet) = ona_get_record('vlan_id != 0 AND id IN (SELECT subnet_id FROM dhcp_server_subnets WHERE host_id = ' . $host['id'] . ' UNION SELECT subnet_id FROM dhcp_pools WHERE dhcp_failover_group_id IN (SELECT id FROM dhcp_failover_groups WHERE primary_server_id = ' . $host['id'] . ' OR secondary_server_id = ' . $host['id'] . '))', 'subnets', 'vlan_id ASC'); if ($status) { printmsg($self['error'], 0); $exit += $status; } if ($rows == 0) { printmsg("DEBUG => build_dhcpd_conf(): Found no shared subnets.", 3); break; } else { if ($i == 0) { $text .= "# --------SHARED SUBNETS (count={$rows})--------\n\n"; } } printmsg("DEBUG => Processing vlan subnet " . ($i + 1) . " of {$rows}", 3); // pull info about the vlan itself list($status, $vlanrows, $vlan) = ona_get_vlan_record(array('id' => $vlan_subnet['vlan_id'])); if ($status) { printmsg($self['error'], 0); $exit += $status; } // check to see if we have switched to a new vlan if ($vlananchor != $vlan_subnet['vlan_id']) { // if this is NOT the first loop through, close the previous shared network block if ($i >= 1) { $text .= "}\n\n"; } // print the opening statement for the shared network block and strip characters that may cause errors $text .= "shared-network " . preg_replace('/[^A-Za-z0-9_-]/', '', "{$vlan['vlan_campus_name']}-{$vlan['number']}-{$vlan['name']}") . " {\n"; } // print the subnet block for the current subnet in the loop list($status, $subnetblock) = subnet_conf($vlan_subnet, 1); if ($status) { printmsg("ERROR => subnet_conf() returned an error: vlan subnet: {$vlan_subnet['name']}", 0); $exit += $status; } else { $text .= $subnetblock; } $i++; // If the loop is at the end,and this isnt the first time we've come through the loop, print a close statement // if ($i == $rows && $vlananchor != '') {$text .= "}\n\n";} if ($i == $rows) { $text .= "}\n\n"; } // continue to update the vlan anchor $vlananchor = $vlan_subnet['vlan_id']; } while ($i < $rows); /////////////////////////////// standard subnets ////////////////////////////////////////// // Loop through all of the NON vlan subnets and print them printmsg("DEBUG => Processing all Non-Shared (Standard) Subnets", 1); // We do our own sql query here because it makes more sense than calling ona_get_record() a zillion times ;) $q = "SELECT *\n FROM subnets\n WHERE vlan_id = 0 AND\n id IN (SELECT subnet_id\n FROM dhcp_server_subnets\n WHERE host_id = {$host['id']}\n UNION\n SELECT subnet_id\n FROM dhcp_pools\n WHERE dhcp_failover_group_id IN (SELECT id\n FROM dhcp_failover_groups\n WHERE primary_server_id = {$host['id']}\n OR secondary_server_id = {$host['id']}))\n\n ORDER BY name ASC"; $rs = $onadb->Execute($q); if ($rs === false) { $self['error'] = 'ERROR => build_dhcpd_conf(): standard_subnets: SQL query failed: ' . $onadb->ErrorMsg(); printmsg($self['error'], 0); $exit += 1; } $rows = $rs->RecordCount(); if ($rows > 0) { $text .= "# --------STANDARD SUBNETS (count={$rows})--------\n"; } $i = 0; // Loop through the record set while ($std_subnet = $rs->FetchRow()) { printmsg("DEBUG => build_dhcpd_conf() Processing standard subnet " . ($i + 1) . " of {$rows}", 3); // print the subnet info for the current subnet in the loop list($status, $subnetblock) = subnet_conf($std_subnet, 0); if ($status) { printmsg("ERROR => subnet_conf() returned an error: non-vlan subnet: {$std_subnet['description']}", 0); $exit += $status; } else { $text .= $subnetblock; } $i++; } $rs->Close(); /////////////////////////////// build static hosts ////////////////////////////////////////// list($status, $hostconf) = build_hosts($host['id']); $text .= $hostconf; /////////////////////////////// Yer done, go home ////////////////////////////////////////// // Return the config file return array($exit, $text); }
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 dhcp_server_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.03'; printmsg("DEBUG => dhcp_server_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !($options['subnet'] and $options['server'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dhcp_server_del-v{$version} Removes a subnet record from a DHCP server Synopsis: dhcp_server_del [KEY=VALUE] ... Required: subnet=NAME or ID subnet name or ID server=NAME[.DOMAIN] or ID server name or ID Optional: commit=[Y|N] commit db transaction (no) Notes: DOMAIN will default to {$conf['dns_defaultdomain']} if not specified EOM ); } // Determine the entry itself exists list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); // Test to see that we were able to find the specified record if (!$subnet['id']) { printmsg("DEBUG => Unable to find the subnet record using {$options['subnet']}!", 3); $self['error'] = "ERROR => Unable to find the subnet record using {$options['subnet']}!"; return array(4, $self['error'] . "\n"); } printmsg("DEBUG => dhcp_server_del(): Found subnet, {$subnet['name']}", 3); if ($options['server']) { // Determine the server is valid list($status, $rows, $host) = ona_find_host($options['server']); if (!$host['id']) { printmsg("DEBUG => The server ({$options['server']}) does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!"; return array(2, $self['error'] . "\n"); } } //printmsg("DEBUG => dhcp_server_del(): Found server, {$host['FQDN']}", 3); // Test that this subnet is even assigned to the server list($status, $rows, $dhcpserver) = ona_get_dhcp_server_subnet_record(array('host_id' => $host['id'], 'subnet_id' => $subnet['id'])); if (!$rows) { printmsg("DEBUG => Unable to find {$subnet['name']} on server {$host['fqdn']}", 3); $self['error'] = "ERROR => Unable to find {$subnet['name']} on server {$host['fqdn']}"; return array(11, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($host['LVL']) or !authlvl($subnet['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // check if allowed to remove subnet from server // check for pool assigned to the server itself list($status, $rows, $pools) = db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id'])); foreach ($pools as $pool) { if ($pool['dhcp_failover_group_id']) { $foundfg = 0; list($status, $rows, $primary) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'], 'primary_server_id' => $host['id'])); if ($rows) { $foundfg++; } list($status, $rows, $secondary) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'], 'secondary_server_id' => $host['id'])); if ($rows) { $foundfg++; } // if a subnet/server pair is found in dhcp pools, don't allow removal if ($foundfg > 0) { printmsg("DEBUG => Subnet ({$subnet['name']}) has a pool assigned to this Server ({$host['fqdn']}), which is part of a failover group. The server must be removed from the failover group first.", 3); $self['error'] = "ERROR => Subnet ({$subnet['name']}) has a pool assigned to this Server ({$host['fqdn']}), which is part of a failover group. The server must be removed from the failover group first."; return array(12, $self['error'] . "\n"); } } } // MP: remove this after testing. dhcp options should not stop us from dis-associating a subnet from a server // Not really sure why I have this.. probably left over cruft from old thoughts // // check if there are any DHCP parameters assigned to the subnet // list($status, $rows, $tmp) = ona_get_dhcp_option_entry_record(array('subnet_id' => $subnet['id'])); // // // if so, check that this is not the last DHCP server that services this subnet // if ($rows > 0) { // list($status, $rows, $tmp) = ona_get_dhcp_server_subnet_record(array('subnet_id' => $subnet['id'])); // // // If this is the last DHCP server that services this subnet, don't allow removal until DHCP parameters are removed // if($rows <= 1){ // printmsg("DEBUG => Subnet ({$subnet['name']}) has DHCP parameters assigned which need to be removed first",3); // $self['error'] = "ERROR => Subnet ({$subnet['name']}) has DHCP parameters assigned which need to be removed first"; // return(array(12, $self['error'] . "\n")); // } // } // delete record from dhcp_server_subnets list($status, $rows) = db_delete_records($onadb, 'dhcp_server_subnets', array('id' => $dhcpserver['id'])); if ($status) { $self['error'] = "ERROR => dhcp_server_del() SQL Query failed:" . $self['error']; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => DHCP Subnet/Server Pair DELETED: {$subnet['name']}/{$host['fqdn']} "; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been removed: {$subnet['name']} from: {$host['fqdn']} EOL; return array(6, $text); }
function ws_editor($window_name, $form = '') { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $window = array(); // Check permissions if (!auth('advanced')) { $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); // If $form is a number, it's an dhcp entry record id- so we transform $form into an array if ($form['id']) { list($status, $rows, $dhcp_entry) = ona_get_dhcp_option_entry_record(array('id' => $form['id'])); $window['title'] = "Edit DHCP Entry"; } else { $window['title'] = "Add DHCP Entry"; } // If they are adding a global option $global_id = 'N'; if (is_numeric($form['global_id'])) { // Setup a title description for this edit type $window['edit_type'] = "Global"; $window['edit_type_value'] = 'This will be a Global DHCP option'; $global_id = 'Y'; } // Load the subnet record and associated info. if (is_numeric($form['subnet_id'])) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id'])); // Setup a title description for this edit type $window['edit_type'] = "Subnet"; $window['edit_type_value'] = "{$subnet['name']}"; } // If they are adding a new DHCP entry they will usually pass a host_id in if (is_numeric($form['host_id'])) { list($status, $rows, $host) = ona_find_host($form['host_id']); // Setup a title description for this edit type $window['edit_type'] = "Host"; $window['edit_type_value'] = $host['fqdn']; } // If they are adding a new server level DHCP entry they will usually pass a server_id in if (is_numeric($form['server_id'])) { list($status, $rows, $server) = ona_find_host($form['server_id']); // Setup a title description for this edit type $window['edit_type'] = "Server"; $window['edit_type_value'] = $server['fqdn']; } // Escape data for display in html foreach (array_keys((array) $subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $zone) as $key) { $zone[$key] = htmlentities($zone[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $server) as $key) { $server[$key] = htmlentities($server[$key], ENT_QUOTES, $conf['php_charset']); } // Build dhcp option list list($status, $rows, $dhcpoptions) = db_get_records($onadb, 'dhcp_options', 'id >= 1', 'display_name'); $dhcp_option_list = '<option value=""> </option>\\n'; $dhcpoptions['dhcp_options'] = htmlentities($dhcpoptions['display_name']); foreach ($dhcpoptions as $record) { $selected = ""; if ($record['id'] == $dhcp_entry['dhcp_option_id']) { $selected = "SELECTED=\"selected\""; } if ($record['id']) { $dhcp_option_list .= "<option {$selected} value=\"{$record['id']}\">{$record['display_name']} ({$record['number']})</option>\n"; } } // 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; el('{$window_name}_form').onsubmit = function() { return false; }; EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- DHCP entry Edit Form --> <form id="{$window_name}_form" onSubmit="return false;"> <input type="hidden" name="host" value="{$host['id']}"> <input type="hidden" name="subnet" value="{$subnet['id']}"> <input type="hidden" name="server" value="{$server['id']}"> <input type="hidden" name="global" value="{$global_id}"> <input type="hidden" name="id" value="{$dhcp_entry['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;"> <!-- DHCP ENTRY RECORD --> <tr> <td align="left" nowrap="true"><b><u>DHCP Entry Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td align="right" nowrap="true"> {$window['edit_type']}: </td> <td class="padding" align="left" width="100%"> {$window['edit_type_value']} </td> </tr> <tr> <td class="input_required" align="right" nowrap="true" > DHCP Option </td> <td class="padding" align="left" width="100%"> <select id="option" name="option" class="edit" accesskey="l"> {$dhcp_option_list} </select> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Value </td> <td class="padding" align="left" width="100%"> <input name="value" alt="Value" value="{$dhcp_entry['value']}" class="edit" type="text" size="31" maxlength="255" > </td> </tr> <tr> <td align="right" valign="top" nowrap="true"> </td> <td class="padding" align="right" width="100%"> <input type="hidden" name="overwrite" value="{$overwrite}"> <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}_form'), 'save');" > </td> </tr> </table> </form> EOL; return window_open($window_name, $window); }
function custom_attribute_display($options = "") { // The important globals global $conf, $self, $onadb; $text_array = array(); // Version - UPDATE on every edit! $version = '1.02'; printmsg("DEBUG => custom_attribute_display({$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['host'] and !$options['id'] and !$options['subnet'] and !$options['vlan']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM custom_attribute_display-v{$version} Display the custom attribute specified or attributes for a host Synopsis: custom_attribute_display Where: id=ID custom attribute ID OR host=ID or NAME[.DOMAIN] display custom attributes for specified host OR subnet=ID or NAME display custom attributes for specified subnet OR vlan=NAME display custom attributes for specified VLAN Optional: type=ID or NAME If you specify a type and a host or subnet you will only get back a 1 or a 0 indicating that that type is set or not set for the host or subnet EOM ); } // if a type was set, check if it is associated with the host or subnet and return 1 or 0 if ($options['type']) { $field = is_numeric($options['type']) ? 'id' : 'name'; list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array($field => $options['type'])); // error if we cant find the type specified if (!$catype['id']) { $self['error'] = "ERROR => The custom attribute type specified, {$options['type']}, does not exist!"; return array(5, $self['error']); } $where['custom_attribute_type_id'] = $catype['id']; } // Search for the host first if ($options['host']) { list($status, $rows, $host) = ona_find_host($options['host']); // Error if the host doesn't exist if (!$host['id']) { $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!"; return array(2, $self['error']); } else { $where['table_id_ref'] = $host['id']; $where['table_name_ref'] = 'hosts'; list($status, $rows, $cas) = db_get_records($onadb, 'custom_attributes', $where); } $anchor = 'host'; $desc = $host['fqdn']; } // Search for subnet if ($options['subnet']) { list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); // Error if the record doesn't exist if (!$subnet['id']) { $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!"; return array(3, $self['error']); } else { $where['table_id_ref'] = $subnet['id']; $where['table_name_ref'] = 'subnets'; list($status, $rows, $cas) = db_get_records($onadb, 'custom_attributes', $where); } $anchor = 'subnet'; $desc = $subnet['description']; } // Search for vlan if ($options['vlan']) { list($status, $rows, $vlan) = ona_find_vlan($options['vlan']); // Error if the record doesn't exist if (!$vlan['id']) { $self['error'] = "ERROR => The VLAN specified, {$options['vlan']}, does not exist!"; return array(3, $self['error']); } else { $where['table_id_ref'] = $vlan['id']; $where['table_name_ref'] = 'vlans'; list($status, $rows, $cas) = db_get_records($onadb, 'custom_attributes', $where); } $anchor = 'vlan'; $desc = $vlan['description']; } // Now find the ID of the record, returns a specific record only if ($options['id']) { list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $options['id'])); if (!$ca['id']) { $self['error'] = "ERROR => The custom attribute specified, {$options['id']}, is invalid!"; return array(4, $self['error']); } $text_array = $ca; $text .= "CUSTOM ATTRIBUTE ENTRY RECORD ({$ca['id']})\n"; $text .= format_array($ca); } elseif ($options['type']) { // If we requested type, now is the time to return a response if it is found associated. if ($cas[0]) { $text .= '1'; $text_array['has_attribute'] = 'Y'; } else { $text .= '0'; $text_array['has_attribute'] = 'N'; } } else { // Build text to return $text .= strtoupper($anchor) . " CUSTOM ATTRIBUTE RECORDS ({$desc})\n"; // Display the record(s) $i = 0; do { $text .= "\nASSOCIATED CUSTOM ATTRIBUTE ENTRY RECORD ({$i} of {$rows})\n"; $text .= format_array($cas[$i]); list($status, $carows, $ca) = ona_get_custom_attribute_type_record(array('id' => $cas[$i]['custom_attribute_type_id'])); $text_array[$ca['name']] = $cas[$i]['value']; $i++; } while ($i < $rows); } // change the output format if other than default if ($options['format'] == 'json') { $text = $text_array; } if ($options['format'] == 'yaml') { $text = $text_array; } // Return the success notice return array(0, $text); }
function ws_editor($window_name, $form = '') { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $window = array(); // Check permissions if (!(auth('subnet_modify') and auth('subnet_add'))) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // If $form is a number, it's an record ID- so we transform $form into an array if (is_numeric($form)) { $form = array('subnet_id' => $form); } $subnet = array(); // Load an existing record (and associated info) if $form is an id if (is_numeric($form['subnet_id'])) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id'])); if ($rows) { if (strlen($subnet['ip_addr']) > 11) { $subnet['ip_mask'] = '/' . ip_mangle($subnet['ip_mask'], 'cidr'); } else { $subnet['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted'); } $subnet['ip_addr'] = ip_mangle($subnet['ip_addr'], 'dotted'); // Vlan Record list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $subnet['vlan_id'])); $subnet['vlan_desc'] = $vlan['vlan_campus_name'] . ' / ' . $vlan['name']; } } else { if (strlen($form['ip_addr']) > 1) { $subnet['ip_addr'] = ip_mangle($form['ip_addr'], 'dotted'); } if (strlen($form['ip_mask']) > 1) { $subnet['ip_mask'] = ip_mangle($form['ip_mask'], 'dotted'); } if (strlen($form['name']) > 1) { $subnet['name'] = $form['name']; } } if (!$subnet['vlan_id']) { $subnet['vlan_desc'] = 'None'; } // Escape data for display in html foreach (array_keys((array) $subnet) as $key) { $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Add Subnet"; if ($subnet['id']) { $window['title'] = "Edit Subnet"; } // Build subnet type list list($status, $rows, $subnettypes) = db_get_records($onadb, 'subnet_types', 'id > 0', 'display_name'); $subnet_type_list = '<option value=""> </option>\\n'; $subnettypes['subnet_type_name'] = htmlentities($subnettypes['display_name']); foreach ($subnettypes as $record) { $selected = ""; if ($record['id'] == $subnet['subnet_type_id']) { $selected = "SELECTED=\"selected\""; } if ($record['id']) { $subnet_type_list .= "<option {$selected} value=\"{$record['id']}\">{$record['display_name']}</option>\n"; } } // 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; el('{$window_name}_edit_form').onsubmit = function() { return false; }; /* Setup the Quick Find VLAN icon */ var _button = el('qf_vlan_{$window_name}'); _button.style.cursor = 'pointer'; _button.onclick = function(ev) { if (!ev) ev = event; /* Create the popup div */ wwTT(this, ev, 'id', 'tt_qf_vlan_{$window_name}', 'type', 'static', 'direction', 'south', 'delay', 0, 'styleClass', 'wwTT_qf', 'javascript', "xajax_window_submit('tooltips', '" + "tooltip=>qf_vlan," + "id=>tt_qf_vlan_{$window_name}," + "text_id=>vlan_text_{$window_name}," + "input_id=>set_vlan_{$window_name}');" ); }; suggest_setup('masks_{$window_name}', 'suggest_masks_{$window_name}'); el('set_name').focus(); EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- Subnet Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="subnet" value="{$subnet['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;"> <!-- SUBNET RECORD --> <tr> <td align="left" nowrap="true"><b><u>Subnet Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td align="right" nowrap="true"> VLAN </td> <td class="padding" align="left" width="100%" nowrap="true"> <input type="hidden" id="set_vlan_{$window_name}" name="set_vlan" value="{$subnet['vlan_id']}"> <span id="qf_vlan_{$window_name}"> <a id="vlan_text_{$window_name}" class="nav" >{$subnet['vlan_desc']}</a> <img src="{$images}/silk/find.png" border="0" /></span> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Name </td> <td class="padding" align="left" width="100%"> <input id="set_name" name="set_name" alt="Subnet name" value="{$subnet['name']}" class="edit" type="text" size="35" maxlength="100" > </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Subnet type </td> <td class="padding" align="left" width="100%"> <select name="set_type" class="edit" accesskey="t"> {$subnet_type_list} </select> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> IP Address </td> <td class="padding" align="left" width="100%"> <input name="set_ip" alt="IP Address" value="{$subnet['ip_addr']}" class="edit" type="text" size="35" maxlength="40" > </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Netmask </td> <td class="padding" align="left" width="100%"> <input id="masks_{$window_name}" name="set_netmask" alt="Netmask (i.e. 255.255.255.0 or /24)" value="{$subnet['ip_mask']}" class="edit" type="text" size="35" maxlength="17" > <div id="suggest_masks_{$window_name}" class="suggest"></div> </td> </tr> EOL; // Show a "keep adding" checkbox if they are adding records if (!isset($subnet['id'])) { $window['html'] .= <<<EOL <tr> <td align="right" nowrap="true"> </td> <td class="padding" align="left" width="100%"> <input name="keepadding" alt="Keep adding more subnets" type="checkbox" > Keep adding more subnets </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 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 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, build the array and store it in $form $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 subnets 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 SUBNET SEARCH *** // FIND RESULT SET // // Start building the "where" clause for the sql query to find the subnets to display $where = ""; $and = ""; // enable or disable wildcards $wildcard = '%'; if ($form['nowildcard']) { $wildcard = ''; } // DISPLAY ALL if ($form['all_flag']) { $where .= $and . "id > 0"; $and = " AND "; } // SUBNET ID if ($form['subnet_id']) { $where .= $and . "id = " . $form['subnet_id']; $and = " AND "; } // VLAN ID if ($form['vlan_id']) { $where .= $and . "vlan_id = " . $onadb->qstr($form['vlan_id']); $and = " AND "; } // SUBNET TYPE if ($form['nettype']) { $where .= $and . "subnet_type_id = " . $onadb->qstr($form['nettype']); $and = " AND "; } // find subnets that are associated with dhcp server if ($form['server_id']) { $where .= $and . "id IN (SELECT subnet_id FROM dhcp_server_subnets WHERE host_id = " . $onadb->qstr($form['server_id']) . ')'; $and = " AND "; } // SUBNET NAME if ($form['subnetname']) { // This field is always upper case $form['subnetname'] = strtoupper($form['subnetname']); $where .= $and . "name LIKE " . $onadb->qstr($wildcard . $form['subnetname'] . $wildcard); $and = " AND "; } // IP ADDRESS if ($form['ip_subnet']) { // Build $ip and $ip_end from $form['ip_subnet'] and $form['ip_subnet_thru'] $ip = ip_complete($form['ip_subnet'], '0'); if ($form['ip_subnet_thru']) { $ip = ip_complete($form['ip_subnet'], '0'); $ip_end = ip_complete($form['ip_subnet_thru'], '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) { // Find subnets between the specified ranges $where .= $and . " ip_addr >= " . $ip . " AND ip_addr <= " . $ip_end; $and = " AND "; } } else { list($status, $rows, $record) = ona_find_subnet($ip); if ($rows) { $where .= $and . " id = " . $record['id']; $and = " AND "; } } } // tag if ($form['tag_net']) { $where .= $and . "id in (select reference from tags where type like 'subnet' and name like " . $onadb->qstr($form['tag_net']) . ")"; $and = " AND "; } // custom attribute type if ($form['custom_attribute_type_net']) { $where .= $and . "id in (select table_id_ref from custom_attributes where table_name_ref like 'subnets' and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type_net']) . "))"; $and = " AND "; $cavaluetype = "and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type_net']) . ")"; } // custom attribute value if ($form['ca_value_net']) { $where .= $and . "id in (select table_id_ref from custom_attributes where table_name_ref like 'subnets' {$cavaluetype} and value like " . $onadb->qstr($wildcard . $form['ca_value_net'] . $wildcard) . ")"; $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 subnets matching your query, showing all records';"; } // Wild card .. if $where is still empty, add a 'ID > 0' to it so you see everything. if ($where == '') { $where = 'id > 0'; } // Do the SQL Query $filter = ''; if ($form['filter']) { // Subnet namess are always upper case $form['filter'] = strtoupper($form['filter']); $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } list($status, $rows, $results) = db_get_records($onadb, 'subnets', $where . $filter, "ip_addr", $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, 'subnets', $where . $filter, "", 0); } } $count = $rows; // // *** BUILD HTML LIST *** // $html .= <<<EOL <!-- Subnet Results --> <table id="{$form['form_id']}_subnet_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td> <td class="list-header" align="center" style="{$style['borderR']};">Usage</td> <td class="list-header" align="center" style="{$style['borderR']};">Type</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record foreach ($results as $record) { // Get additional info about eash subnet record // // Convert IP and Netmask to a presentable format $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted'); $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted'); $record['IP_SUBNET_MASK_CIDR'] = ip_mangle($record['ip_mask'], 'cidr'); list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id'])); $record['type'] = $type['display_name']; // Calculate the percentage of the subnet that's used (total size - allocated hosts - dhcp pool size) $usage_html = get_subnet_usage_html($record['id']); // 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_subnet\\', \\'subnet_id=>{$record['id']}\\', \\'display\\')');"; $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td class="list-row"> <a title="View subnet. ID: {$record['id']}" class="nav" onClick="{$primary_object_js}" >{$record['name']}</a> </td> <td class="list-row" align="left"> {$record['ip_addr']} <span title="{$record['ip_mask']}">/{$record['IP_SUBNET_MASK_CIDR']}</span> </td> <td class="list-row" align="center" style="vertical-align: middle;"> {$usage_html} </td> <td class="list-row" align="left"> {$record['type']} </td> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_subnet_{$record['id']}" ><input type="hidden" name="subnet_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Display subnet map" class="act" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr']}\\', \\'display\\');');" ><img src="{$images}/silk/shape_align_left.png" border="0"></a> EOL; if (auth('subnet_modify')) { $html .= <<<EOL <a title="Edit subnet" class="act" onClick="xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_subnet_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> EOL; } if (auth('subnet_del')) { $html .= <<<EOL <a title="Delete subnet" class="act" onClick="var doit=confirm('Are you sure you want to delete this subnet?'); if (doit == true) xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_subnet_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } $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']); // If there was only 1 result, and we're about to display results in the "Search Results" window, display it. if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '') { $js .= $primary_object_js; } // 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_more_host_options($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; // Build custom attribute list list($status, $rows, $records) = db_get_records($onadb, 'custom_attribute_types', 'id >= 1', ''); $custom_attribute_type_list = '<option value=""> </option>\\n'; foreach ($records as $record) { $custom_attribute_type_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n"; unset($records, $ca); } // Build device model list list($status, $rows, $records) = db_get_records($onadb, 'models', 'id >= 1'); $models = array(); foreach ($records as $record) { list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $record['manufacturer_id'])); $models[$record['id']] = "{$manufacturer['name']}, {$record['name']}"; } asort($models); $device_model_list = '<option value=""> </option>\\n'; foreach (array_keys($models) as $id) { $models[$id] = htmlentities($models[$id]); $device_model_list .= "<option value=\"{$id}\">{$models[$id]}</option>\n"; } unset($models, $model); // Build device type list list($status, $rows, $records) = db_get_records($onadb, 'roles', 'id >= 1', 'name'); $device_role_list = '<option value=""> </option>\\n'; $record['name'] = htmlentities($record['name']); foreach ($records as $record) { $device_role_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n"; } // Build device manufacturer list list($status, $rows, $records) = db_get_records($onadb, 'manufacturers', 'ID >= 1', 'name'); $device_manufacturer_list = '<option value=""> </option>\\n'; $record['name'] = htmlentities($record['name']); foreach ($records as $record) { $device_manufacturer_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n"; } // Build the new HTML $html = <<<EOL <table cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>C</u>ustom attribute </td> <td align="left" class="asearch-line"> <select id="custom_attribute_type" name="custom_attribute_type" class="edit" accesskey="c"> {$custom_attribute_type_list} </select> <u>V</u>alue <input id="ca_value" name="ca_value" type="text" class="edit" size="15" accesskey="v" /> </td> </tr> <tr> <td align="right" class="asearch-line"> Device mode<u>l</u> </td> <td align="left" class="asearch-line"> <select id="model" name="model" class="edit" accesskey="l"> {$device_model_list} </select> </td> </tr> <tr> <td align="right" class="asearch-line"> Device <u>t</u>ype Role </td> <td align="left" class="asearch-line"> <select id="role" name="role" class="edit" accesskey="t"> {$device_role_list} </select> </td> </tr> <tr> <td align="right" class="asearch-line"> Device man<u>u</u>facturer </td> <td align="left" class="asearch-line"> <select id="manufacturer" name="manufacturer" class="edit" accesskey="u"> {$device_manufacturer_list} </select> </td> </tr> </table> EOL; $js = "el('more_options_link').style.display = 'none';"; // Insert the new html $response = new xajaxResponse(); $response->addAssign("more_host_options", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function get_class_c_html($ip = 0, $zoom = 2, $row_height) { global $conf, $self, $onadb, $color, $style, $images; $html = ''; if ($ip == 0) { return $html; } $ip_end = $ip + 255; $x_px_per_ip = $zoom; // Select all subnet records in this class C //$where = "ip_addr >= {$ip} AND ip_addr <= " . $ona->qstr($ip_end); $where = "ip_addr >= {$ip} AND ip_addr <= {$ip_end}"; list($status, $num_subnets, $subnets) = db_get_records($onadb, 'subnets', $where, "ip_addr ASC"); // If the first record isn't a subnet, see if the first IP is in another subnet if ($subnets[0]['ip_addr'] != $ip) { $where = "ip_addr < {$ip} AND ((4294967295 - ip_mask) + ip_addr) >= {$ip}"; list($status, $rows, $subnet) = db_get_record($onadb, 'subnets', $where); if ($rows) { $num_subnets++; array_unshift($subnets, $subnet); } } $block_start = $ip; // Find the next block of addresses while ($block_start < $ip_end) { if (!is_array($subnet) or $block_start > $subnet['ip_addr']) { $subnet = array_shift($subnets); if (is_array($subnet)) { $subnet['SIZE'] = 0xffffffff - $subnet['ip_mask'] + 1; $subnet['ip_addr_end'] = $subnet['ip_addr'] + $subnet['SIZE'] - 1; } else { // pretend like the next subnet record is the next class C $subnet['SIZE'] = $ip_end - $block_start + 1; $subnet['ip_addr'] = $ip_end + 1; } } // If it's unallocated space if ($block_start < $subnet['ip_addr']) { $block_end = $subnet['ip_addr'] - 1; $block_color = $color['bgcolor_map_empty']; } else { $block_end = $subnet['ip_addr_end']; if ($block_end > $ip_end) { $block_end = $ip_end; } $block_color = $color['bgcolor_map_subnet']; } $block_size = $block_end - $block_start + 1; $block_size_total += $block_size; // $block_title = htmlentities($subnet['DESCRIPTION'] . " :: Size={$block_size}", ENT_QUOTES) . ' :: ' . ip_mangle($block_start, 'dotted') . " -> " . ip_mangle($block_end, 'dotted'); // Display the current block (-1 for px border unless it's IE) $x = $block_size * $x_px_per_ip - 1; if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') != false) { $x++; } $html .= <<<EOL <div id="{$block_start}_block" style=" clear: none; float: left; border-right: 1px solid #000000; background-color: {$block_color}; width: {$x}px; height: {$row_height}px;" onMouseOver=" wwTT(this, event, 'id', 'tt_subnet_{$block_start}', 'type', 'velcro', 'styleClass', 'wwTT_niceTitle', 'direction', 'south', 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>subnet,id=>tt_subnet_{$block_start},subnet_ip=>{$block_start}\\');' );" ></div> EOL; $block_start = $block_end + 1; } return $html; }
function ws_display_list($window_name, $form = '') { global $conf, $self, $onadb, $baseURL; 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); // 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']; } // 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; // Start building the "where" clause for the sql query to find the records to display $where = ''; $and = ''; // DISPLAY ALL CONFIGS if ($form['all_flag']) { $where .= $and . "id > 0"; $and = " AND "; } if ($form['host_id']) { $where .= 'host_id = ' . $form['host_id']; $and = " AND "; } // Do the SQL Query $filter = ''; if ($form['filter']) { $filter = $and . ' configuration_type_id in (select id from configuration_types where name like "%' . $form['filter'] . '%")'; } list($status, $rows, $results) = db_get_records($onadb, 'configurations', $where . $filter, 'configuration_type_id ASC, ctime DESC', $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, 'configurations', $where . $filter, "", 0); } } $count = $rows; $html .= <<<EOL <!-- Config List --> <table id="{$form['form_id']}_config_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">A</td> <td class="list-header" align="center" style="{$style['borderR']};">B</td> <td class="list-header" align="center" style="{$style['borderR']};">Date</td> <td class="list-header" align="center" style="{$style['borderR']};">Type</td> <td class="list-header" align="center" style="{$style['borderR']};">MD5 Checksum</td> <td class="list-header" align="center" style="{$style['borderR']};">Size (chars)</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record foreach ($results as $record) { $id++; // Counter used for comparison seleciton // Grab some info from the associated record list($status, $rows, $ctype) = ona_get_config_type_record(array('id' => $record['configuration_type_id'])); $record['config_type_name'] = $ctype['name']; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } // MP: FIXME still not working right for encoded stings.. always returns 0 $confsize = mb_strlen(html_entity_decode($record['config_body'], ENT_QUOTES, $conf['php_charset']), $conf['php_charset']); $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td align="center" class="list-row" style="padding-right: 4px; width: 20px;" ><input id="old{$id}" name="old" type="radio" value="{$record['id']}" onClick=" var tmp = 1; var obj = el('new' + tmp); while (obj) { obj.style.visibility = (tmp <= {$id}) ? 'visible' : 'hidden'; if (tmp > {$id}) obj.checked = false; obj = el('new' + tmp++); }" > </td> <td class="list-row" align="center" style="width: 20px;"> <input id="new{$id}" style="visibility: hidden;" name="new" type="radio" value="{$record['id']}"> </td> <td class="list-row" align="center"> {$record['ctime']} </td> <td class="list-row" align="center"> {$record['config_type_name']} </td> <td class="list-row" align="center"> {$record['md5_checksum']} </td> <td class="list-row" align="center"> {$confsize} </td> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_configs_{$record['id']}" ><input type="hidden" name="config_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('host_config_admin', $debug_val)) { $html .= <<<EOL <a title="View config. ID: {$record['id']}" class="act" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_config_text\\', \\'host_id=>{$record['host_id']},type_id=>{$record['configuration_type_id']},displayconf=>{$record['id']}\\', \\'display\\')');" ><img src="{$images}/silk/zoom.png" border="0"></a> <a title="Download config" class="act" target="null" href="{$baseURL}/config_dnld.php?config_id={$record['id']}&download=1" ><img src="{$images}/silk/disk.png" alt="Download config" border="0"></a> <a title="Delete config" class="nav" onClick="var doit=confirm('Are you sure you want to delete this config record?'); if (doit == true) xajax_window_submit('display_config_text', xajax.getFormValues('{$form['form_id']}_list_configs_{$record['id']}'), 'delete_config');" ><img src="{$images}/silk/delete.png" alt="Delete config" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } $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(); }
$title_left_html = ''; $modbodyhtml = ''; // if this is a display host screen then go ahead and make a puppet facts window if ($extravars['window_name'] == 'html_desktop') { // Set up a generic where clause $where = 'id > 0'; // Start getting various record counts list($status, $host_count, $records) = db_get_records($onadb, 'hosts', $where, "", 0); list($status, $dns_count, $records) = db_get_records($onadb, 'dns', $where, "", 0); list($status, $interface_count, $records) = db_get_records($onadb, 'interfaces', $where, "", 0); list($status, $domain_count, $records) = db_get_records($onadb, 'domains', $where, "", 0); list($status, $subnet_count, $records) = db_get_records($onadb, 'subnets', $where, "", 0); list($status, $pool_count, $records) = db_get_records($onadb, 'dhcp_pools', $where, "", 0); list($status, $block_count, $records) = db_get_records($onadb, 'blocks', $where, "", 0); list($status, $vlan_campus_count, $records) = db_get_records($onadb, 'vlan_campuses', $where, "", 0); list($status, $config_archive_count, $records) = db_get_records($onadb, 'configurations', $where, "", 0); $title_left_html .= " Record Counts"; $modbodyhtml .= <<<EOL <script type="text/javascript"> function record_counts_pie(rownum) { // Function modified from code posted on http://www.phpied.com/canvas-pie/ // // source data table and canvas tag var data_table = document.getElementById('record_counts'); var td_index = 1; // which TD contains the data var canvas = document.getElementById('record_counts_pie'); // exit if canvas is not supported if (typeof canvas.getContext === 'undefined') { return;
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the record to make sure it exists list($status, $rows, $subnet_type) = db_get_record($onadb, 'subnet_types', array('id' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: Subnet type ID {$form} doesnt exist');"); return $response->getXML(); } // Get a list of subnets that use this subnet type list($status, $rows, $subnet) = db_get_records($onadb, 'subnets', array('subnet_type_id' => $form), '', 0); // Check that there are no parent records using this type if ($rows > 0) { $js .= "alert('Delete failed: There are {$rows} subnets using this subnet type.');"; } else { // Delete the record list($status, $rows) = db_delete_records($onadb, 'subnet_types', array('id' => $subnet_type['id'])); // If the module returned an error code display a popup warning if ($status != 0) { $js .= "alert('Delete failed: " . trim($self['error']) . "');"; } } // Refresh the current list.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; // Send an XML response $response->addScript($js); return $response->getXML(); }
function get_ip_suggestions($q, $max_results = 10) { global $onadb; $formatted = $results = array(); // Complete the (potentially incomplete) ip address $ip = ip_complete($q, '0'); $ip_end = ip_complete($q, '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 or $ip_end == -1) { return array(); } // It's not valid ip addresses // Now use SQL to look for subnet ip records that match $table = 'subnets'; $field = 'ip_addr'; $where = "{$field} >= " . $onadb->qstr($ip) . " AND {$field} <= " . $onadb->qstr($ip_end); $order = "{$field} ASC"; // Search the db for results and put results into $results list($status, $rows, $records) = db_get_records($onadb, $table, $where, $order, $max_results); foreach ($records as $record) { $results[] = $record[$field]; } // If we need more suggestions, look in the host_subnets table $max_results -= count($results); if ($max_results) { $table = 'interfaces'; list($status, $rows, $records) = db_get_records($onadb, $table, $where, $order, $max_results); foreach ($records as $record) { $results[] = $record[$field]; } } // Format the ip's in dotted format sort($results); foreach ($results as $result) { // format ipv6 or regular $format = is_ipv4($result) ? 'dotted' : 'ipv6'; $formatted[] = ip_mangle($result, $format); } unset($results, $result, $records, $record); return $formatted; }
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the record to make sure it exists list($status, $rows, $role) = db_get_record($onadb, 'roles', array('id' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: Role id {$form} does not exist');"); return $response->getXML(); } // Get a list of device models that use this role list($status, $rows, $devicemodels) = db_get_records($onadb, 'models', array('role_id' => $form), '', 0); // Check that there are no parent records using this type if ($rows > 0) { $js .= "alert('Delete failed: There are {$rows} device models using this role.');"; } else { // Delete the record list($status, $rows) = db_delete_records($onadb, 'roles', array('id' => $role['id'])); if ($status or !$rows) { // If the module returned an error code display a popup warning $js .= "alert('Delete failed: " . trim($self['error']) . "');"; $self['error'] = "ERROR => role_list ws_delete() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { $self['error'] = "INFO => Role DELETED: {$role['name']} "; printmsg($self['error'], 0); } } // Refresh the current list.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; // Send an XML response $response->addScript($js); return $response->getXML(); }
function ws_search_results_submit($window_name, $form = '') { global $conf, $self, $onadb; global $font_family, $color, $style, $images; // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // We're building the window in $window and will use window_open() to create the window $window = array('title' => "Search Results", 'html' => "", 'js' => ""); $max_img = "{$images}/silk/bullet_arrow_down.png"; $min_img = "{$images}/silk/bullet_arrow_up.png"; // Build subnet type list list($status, $rows, $records) = db_get_records($onadb, 'subnet_types', 'id >= 1', 'display_name'); $subnet_type_list = '<option value=""> </option>\\n'; foreach ($records as $record) { $record['display_name'] = htmlentities($record['display_name']); $subnet_type_list .= "<option value=\"{$record['id']}\">{$record['display_name']}</option>\n"; } // Build subnet type list if ($conf['dns_views']) { list($status, $rows, $records) = db_get_records($onadb, 'dns_views', 'id >= 0', 'name'); $dns_view_list = '<option value=""> </option>\\n'; foreach ($records as $record) { $record['name'] = htmlentities($record['name']); $dns_view_list .= "<option value=\"{$record['name']}\">{$record['name']}</option>\n"; } } // keep wildcard checkbox value if ($form['nowildcard']) { $wildchecked = 'checked="yes"'; } // Load some html into $window['html'] $form_id = "{$window_name}_filter_form"; $content_id = $_SESSION['ona'][$form_id]['content_id'] = "{$window_name}_list"; $window['html'] .= <<<EOL <!-- Tabs & Quick Filter --> <table id="{$form_id}_table" width="100%" cellspacing="0" border="0" cellpadding="0" style="{$style['borderT']} {$style['borderB']}"> <tr> <td id="{$form_id}_blocks_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>blocks', 'change_tab');"> Blocks <span id="{$form_id}_blocks_count"></span> </td> <td id="{$form_id}_vlan_campus_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>vlan_campus', 'change_tab');"> Vlan campuses <span id="{$form_id}_vlan_campus_count"></span> </td> <td id="{$form_id}_subnets_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>subnets', 'change_tab');"> Subnets <span id="{$form_id}_subnets_count"></span> </td> <td id="{$form_id}_hosts_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>hosts', 'change_tab');"> Hosts <span id="{$form_id}_hosts_count"></span> </td> <td id="{$form_id}_records_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>records', 'change_tab');"> DNS records <span id="{$form_id}_records_count"></span> </td> <td style="vertical-align: middle;" class="padding" nowrap="true"> <img id="adv_search_img" src="{$min_img}" /> <span id="adv_search_div_toggle" style="text-align: right;" title="Min/Max" onclick="if (el('adv_search_div').style.display=='none') { el('adv_search_div').style.display=''; el('toggle_text').innerHTML='Hide search form'; el('adv_search_img').src='{$min_img}'; } else { el('adv_search_div').style.display='none'; el('toggle_text').innerHTML='Show search form'; el('adv_search_img').src='{$max_img}';}" > <span id="toggle_text" style="font-size: xx-small;">Hide search form</span> </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 id="{$form_id}_tab" name="tab" value="" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_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;' + ' el(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'list_\\' + el(\\'{$form_id}_tab\\').value, xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id="adv_search_div" style="background-color: {$color['window_content_bg']};padding-top: 5px;"> <!-- Block Search Tab --> <form id="block_search_form"> <input type="hidden" name="search_form_id" value="block_search_form"> <table id="blocks_search" style="display: none;" cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>B</u>lock name </td> <td align="left" class="asearch-line"> <input id="blocks_field1" name="blockname" type="text" class="edit" size="35" accesskey="b" value="{$form['blockname']}" /> <div id="suggest_hostname" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> </td> <td align="right" class="asearch-line"> <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('block_search_form');"> <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('block_search_form'));"> </td> </tr> </table> </form> <!-- Vlan Campus Search Tab --> <form id="vlan_campus_search_form"> <input type="hidden" name="search_form_id" value="vlan_campus_search_form"> <table id="vlan_campus_search" style="display: none;" cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>C</u>ampus name </td> <td align="left" class="asearch-line"> <input id="vlan_campus_field1" name="campusname" type="text" class="edit" size="35" accesskey="c" value="{$form['campusname']}" /> <div id="suggest_hostname" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> </td> <td align="right" class="asearch-line"> <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('vlan_campus_search_form');"> <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('vlan_campus_search_form'));"> </td> </tr> </table> </form> <!-- Host Search Tab --> <form id="host_search_form"> <input type="hidden" name="search_form_id" value="host_search_form"> <table id="hosts_search" style="display: none;" cellspacing="0" border="0" cellpadding="0"> <tr> <td> <table cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>H</u>ostname </td> <td align="left" class="asearch-line"> <input id="hosts_field1" name="hostname" type="text" class="edit" size="35" accesskey="h" value="{$form['hostname']}" /> <div id="suggest_hostname" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> Subdomain (<u>z</u>one) </td> <td align="left" class="asearch-line"> <input id="domain" name="domain" type="text" class="edit" size="35" accesskey="z" value="{$form['domain']}" /> <div id="suggest_domain" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>M</u>AC </td> <td align="left" class="asearch-line"> <input id="mac" name="mac" type="text" class="edit" size="17" accesskey="m" value="{$form['mac']}" /> <div id="suggest_mac" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>I</u>P Address </td> <td align="left" class="asearch-line" nowrap="true"> <input id="ip" name="ip" type="text" class="edit" size="15" accesskey="i" value="{$form['ip']}" /> <div id="suggest_ip" class="suggest"></div> thru <input id="ip_thru" name="ip_thru" class="edit" type="text" size="15" value="{$form['ip_thru']}"> <div id="suggest_ip_thru" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>N</u>otes </td> <td align="left" class="asearch-line"> <input id="notes" name="notes" type="text" class="edit" size="17" accesskey="n" value="{$form['notes']}" /> <div id="suggest_notes" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>L</u>ocation Ref </td> <td align="left" class="asearch-line"> <input id="location" class="edit" type="text" name="location" size="8" accesskey="l" value="{$form['location']}" /> <span id="qf_location_{$window_name}"><img src="{$images}/silk/find.png" border="0"/></span> <div id="suggest_location" class="suggest"></div> </td> </tr> </table> </td> <td> <table cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>C</u>ustom attribute </td> <td align="left" class="asearch-line"> <input id="custom_attribute_type" type="text" name="custom_attribute_type" size="20" class="edit" accesskey="c" value="{$form['custom_attribute_type']}"> <div id="suggest_custom_attribute_type" class="suggest"></div> <u>V</u>alue <input id="ca_value" name="ca_value" type="text" class="edit" size="15" accesskey="v" value="{$form['ca_value']}"/> </td> </tr> <tr> <td align="right" class="asearch-line"> Device mode<u>l</u> </td> <td align="left" class="asearch-line"> <input id="model" type="text" name="model" class="edit" size="20" accesskey="l" value="{$form['model']}"> <div id="suggest_model" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> Device <u>t</u>ype Role </td> <td align="left" class="asearch-line"> <input id="role" type="text" name="role" class="edit" size="20" accesskey="t" value="{$form['role']}"> <div id="suggest_role" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> Device man<u>u</u>facturer </td> <td align="left" class="asearch-line"> <input id="manufacturer" type="text" name="manufacturer" class="edit" size="20" accesskey="u" value="{$form['manufacturer']}"> <div id="suggest_manufacturer" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>T</u>ag </td> <td align="left" class="asearch-line"> <input id="tag_host" type="text" name="tag_host" size="20" class="edit" accesskey="t" value="{$form['tag_host']}"> <div id="suggest_tag_host" class="suggest"></div> </td> </tr> </table> </td> </tr> <tr> <td colspan=4 align="right" class="asearch-line"> Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed."> <input class="button" type="button" name="reset" value="Clear" onClick="clearElements('host_search_form');"> <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('host_search_form'));"> </td> </tr> </table> </form> <!-- DNS record Search Tab --> <form id="dns_record_search_form"> <input type="hidden" name="search_form_id" value="dns_record_search_form"> <table id="records_search" style="display: none;" cellspacing="0" border="0" cellpadding="0"> EOL; // Display view dropdown if ($conf['dns_views']) { $window['html'] .= <<<EOL <tr> <td align="right" class="asearch-line"> DNS <u>V</u>iew </td> <td align="left" class="asearch-line"> <select id="dns_view" name="dns_view" class="edit" accesskey="v" > {$dns_view_list} </select> </td> </tr> EOL; } $window['html'] .= <<<EOL <tr> <td align="right" class="asearch-line"> <u>H</u>ostname </td> <td align="left" class="asearch-line"> <input id="records_field1" name="hostname" type="text" class="edit" size="35" accesskey="h" value="{$form['hostname']}" /> <div id="suggest_hostname" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> Subdomain (<u>z</u>one) </td> <td align="left" class="asearch-line"> <input id="dns_domain" name="domain" type="text" class="edit" size="35" accesskey="z" value="{$form['domain']}" /> <div id="suggest_dns_domain" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> Type </td> <td align="left" class="asearch-line"> <select id="dnstype" name="dnstype" class="edit" accesskey="u" > <option></option> <option>A</option> <option>CNAME</option> <option>NS</option> <option>PTR</option> <option>MX</option> <option>SRV</option> <option>TXT</option> </select> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>I</u>P Address </td> <td align="left" class="asearch-line" nowrap="true"> <input id="dns_ip" name="ip" type="text" class="edit" size="15" accesskey="i" value="{$form['ip']}" /> <div id="suggest_dns_ip" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>N</u>otes </td> <td align="left" class="asearch-line"> <input id="notes" name="notes" type="text" class="edit" size="17" accesskey="n" value="{$form['notes']}" /> <div id="suggest_notes" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> </td> <td align="right" class="asearch-line"> Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed."> <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('dns_record_search_form');"> <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('dns_record_search_form'));"> </td> </tr> </table> </form> <!-- END DNS record Search Tab --> <!-- subnet Search Tab --> <form id="subnet_search_form"> <input type="hidden" name="search_form_id" value="subnet_search_form"> <table id="subnets_search" style="display: none;" cellspacing="0" border="0" cellpadding="0"> <tr> <td align="right" class="asearch-line"> <u>V</u>lan </td> <td align="left" class="asearch-line"> <input id="subnets_field1" name="vlandesc" type="text" class="edit" size="32" accesskey="v" value="{$form['vlandesc']}" /> </td> </tr> <tr> <td align="right" class="asearch-line"> Subnet <u>T</u>ype </td> <td align="left" class="asearch-line"> <select id="nettype" name="nettype" class="edit" accesskey="u" accesskey="t" > {$subnet_type_list} </select> </td> </tr> <tr> <td align="right" class="asearch-line"> Subnet <u>N</u>ame </td> <td align="left" class="asearch-line"> <input id="subnet" name="subnetname" type="text" class="edit" size="32" accesskey="n" value="{$form['subnetname']}" /> <div id="suggest_subnet" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>I</u>P Address </td> <td align="left" class="asearch-line" nowrap="true"> <input id="ip_subnet" name="ip_subnet" class="edit" type="text" size="15" accesskey="i" value="{$form['ip_subnet']}" /> <div id="suggest_ip_subnet" class="suggest"></div> thru <input id="ip_subnet_thru" name="ip_subnet_thru" class="edit" type="text" size="15" value="{$form['ip_subnet_thru']}" /> <div id="suggest_ip_subnet_thru" class="suggest"></div> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>C</u>ustom attribute </td> <td align="left" class="asearch-line"> <input id="custom_attribute_type_net" type="text" name="custom_attribute_type_net" size="20" class="edit" value="{$form['custom_attribute_type_net']}"> <div id="suggest_custom_attribute_type_net" class="suggest"></div> <u>V</u>alue <input id="ca_value_net" name="ca_value_net" type="text" class="edit" size="15" value="{$form['ca_value_net']}"/> </td> </tr> <tr> <td align="right" class="asearch-line"> <u>T</u>ag </td> <td align="left" class="asearch-line"> <input id="tag_net" type="text" name="tag_net" size="20" class="edit" accesskey="t" value="{$form['tag_net']}"> <div id="suggest_tag_net" class="suggest"></div> </td> <tr> <tr> <td align="right" class="asearch-line"> </td> <td align="right" class="asearch-line"> Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed."> <input class="button" type="button" name="reset" value="Clear" onClick="clearElements('subnet_search_form');"> <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('subnet_search_form'));"> </td> </tr> </table> </form> <center><span style="font-weight: bold;color: green; font-size: small;" id="search_results_msg"></span></center> </div> <!-- Item List --> <div id="{$content_id}">{$conf['loading_icon']}</div> EOL; //TODO: this is a test I did on having a click focus bring up the full list of entries.. kinda like a dropdown dialog.. //onfocus="suggest_display('role', 'suggest_role');searchKeyDown('37', el('role'), 'suggest_role');" // Before we can let the browser call "display_list" // we need to make sure we know what type of list we'll be displaying switch ($form['search_form_id']) { case 'host_search_form': $tab = 'hosts'; break; case 'subnet_search_form': $tab = 'subnets'; break; case 'block_search_form': $tab = 'blocks'; break; case 'vlan_campus_search_form': $tab = 'vlan_campus'; break; case 'dns_record_search_form': $tab = 'records'; break; case 'qsearch_form': // If the quick search begins with a "/" it's a command if (strpos($form['q'], '/') === 0) { $form['q'] = substr($form['q'], 1); return qsearch_command($form['q']); } // We (unfortunately) have to do a few sql queries to see what kind of // search this is and what "tab" we'll be displaying data on. list($tab, $form) = quick_search($form['q']); break; } // Save a few things in the session (the search query, page, and tab) $_SESSION['ona'][$form_id]['tab'] = $tab; $_SESSION['ona'][$form_id][$tab]['q'] = $form; // A little javascript for the browser to run once we've created the window $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; /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Save the new tab and make it look active */ el('{$form_id}_tab').value = '{$tab}'; el('{$form_id}_{$tab}_tab').className = 'table-tab-active'; el('{$tab}_search').style.display = 'block'; /* make the first field have focus */ el('{$tab}_field1').focus(); suggest_setup('hosts_field1', 'suggest_hostname'); suggest_setup('domain', 'suggest_domain'); suggest_setup('dns_domain', 'suggest_dns_domain'); suggest_setup('mac', 'suggest_mac'); suggest_setup('ip', 'suggest_ip'); suggest_setup('dns_ip', 'suggest_dns_ip'); suggest_setup('ip_thru', 'suggest_ip_thru'); suggest_setup('notes', 'suggest_notes'); suggest_setup('ip_subnet', 'suggest_ip_subnet'); suggest_setup('ip_subnet_thru', 'suggest_ip_subnet_thru'); suggest_setup('subnet', 'suggest_subnet'); suggest_setup('location', 'suggest_location'); suggest_setup('custom_attribute_type', 'suggest_custom_attribute_type'); suggest_setup('custom_attribute_type_net', 'suggest_custom_attribute_type_net'); suggest_setup('role', 'suggest_role'); suggest_setup('model', 'suggest_model'); suggest_setup('manufacturer', 'suggest_manufacturer'); suggest_setup('tag_host', 'suggest_tag_host'); suggest_setup('tag_net', 'suggest_tag_net'); el('host_search_form').onsubmit = function() { return false; }; el('subnet_search_form').onsubmit = function() { return false; }; /* 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=>qf_location_{$window_name}');" ); }; /* Display the list of results */ xajax_window_submit('list_' + el('{$form_id}_tab').value, xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // Lets build a window and display the results return window_open($window_name, $window); }
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, build the array and store it in $form $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']; } // 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; // Start building the "where" clause for the sql query to find the blocks to display $where = ""; $and = ""; // DISPLAY ALL BLOCKS if ($form['all_flag']) { $where .= $and . "id > 0"; $and = " AND "; } // BLOCK ID if ($form['id']) { $where .= $and . "id = " . $onadb->qstr($form['id']); $and = " AND "; } // BLOCK , assume a block descripton if ($form['blockname']) { $where .= $and . "name LIKE " . $onadb->qstr('%' . strtoupper($form['blockname']) . '%'); $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 blocks 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'; } // Do the SQL Query $filter = ''; if ($form['filter']) { $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } list($status, $rows, $results) = db_get_records($onadb, 'blocks', $where . $filter, "ip_addr_start ASC", $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, 'blocks', $where . $filter, "", 0); } } $count = $rows; $html .= <<<EOL <!-- Block List --> <table id="{$form['form_id']}_block_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">Block Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Starting IP</td> <td class="list-header" align="center" style="{$style['borderR']};">Ending IP</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record foreach ($results as $record) { // Grab some info from the associated block record list($status, $rows, $block) = ona_get_block_record(array('id' => $record['id'])); $num_hosts = 0xffffffff - $block['ip_addr_end']; $block['ip_block_end'] = $block['ip_addr'] + $num_hosts; $record['name'] = $block['name']; // Convert IP and Netmask to a presentable format $record['ip_addr_start'] = ip_mangle($record['ip_addr_start'], 'dotted'); $record['ip_addr_end'] = ip_mangle($block['ip_addr_end'], 'dotted'); // 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_block\\', \\'block_id=>{$record['id']}\\', \\'display\\')');"; $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td class="list-row" align="left"> <a title="View block. ID: {$record['id']}" class="nav" onClick="{$primary_object_js}" >{$record['name']}</a> </td> <td class="list-row" align="left"> {$record['ip_addr_start']} </td> <td class="list-row" align="left"> {$record['ip_addr_end']} </td> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_block_{$record['id']}" ><input type="hidden" name="block_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('advanced')) { $html .= <<<EOL <a title="Edit block. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'editor');" ><img src="{$images}/silk/brick_edit.png" border="0"></a> EOL; } $html .= <<<EOL <a title="Display subnet map" class="act" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr_start']},ip_block_end=>{$record['ip_addr_end']},id=>{$record['id']}\\', \\'display\\');');" ><img src="{$images}/silk/shape_align_left.png" border="0"></a> EOL; if (auth('advanced')) { $html .= <<<EOL <a title="Delete block" class="act" onClick="var doit=confirm('Are you sure you want to delete this block?'); if (doit == true) xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } $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']); // If there was only 1 result, and we're about to display results in the "Search Results" window, display it. if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '') { $js .= $primary_object_js; } // 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 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_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 block_display($options = "") { global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => block_display({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[verbose] (default is yes) $options['verbose'] = sanitize_YN($options['verbose'], 'Y'); // Return the usage summary if we need to if ($options['help'] or !$options['block']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM block_display-v{$version} Displays a block record from the database Synopsis: block_display [KEY=VALUE] ... Required: block=NAME or ID Block name or ID of the block display Optional: verbose=[yes|no] Display additional info (DEFAULT: yes) EOM ); } // The formatting rule on block names is all upper and trim it $options['block'] = trim($options['block']); $options['block'] = preg_replace('/\\s+/', '-', $options['block']); $options['block'] = strtoupper($options['block']); // If the block provided is numeric, check to see if it's an block if (is_numeric($options['block'])) { // See if it's an block_id list($status, $rows, $block) = ona_get_block_record(array('id' => $options['block'])); if (!$block['id']) { printmsg("DEBUG => Unable to find block using the ID {$options['block']}!", 3); $self['error'] = "ERROR => Unable to find block using the ID {$options['block']}!"; return array(2, $self['error'] . "\n"); } } else { list($status, $rows, $block) = ona_get_block_record(array('name' => $options['block'])); if (!$block['id']) { $self['error'] = "ERROR => Unable to find block using the name {$options['block']}!"; printmsg("DEBUG => Unable to find block using the name {$options['block']}!", 3); return array(2, $self['error'] . "\n"); } } printmsg("DEBUG => Found block: {$block['name']}", 3); // Build text to return $text = "BLOCK RECORD\n"; $text .= format_array($block); // If 'verbose' is enabled, grab some additional info to display if ($options['verbose'] == 'Y') { $where .= " ip_addr >= " . $block['ip_addr_start'] . " AND ip_addr <= " . $block['ip_addr_end']; list($status, $netrows, $nets) = db_get_records($onadb, 'subnets', $where, "ip_addr"); // subnet record(s) $i = 0; foreach ($nets as $record) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $record['id'])); if ($rows == 0) { break; } $i++; $text .= "\nASSOCIATED SUBNET RECORD ({$i} of {$netrows})\n"; $text .= format_array($subnet); } } // Return the success notice return array(0, $text); }
<?php /* * This finds the disctrict number in the request and match the district senator's name and display On behalf of Senator (firstname + lastname) */ $dbh = open_db(); if (isset($_GET['fm_requestid'])) { $fm_requestid = $_GET['fm_requestid']; } else { $fm_requestid = $_POST['fm_requestid']; } $table_name = 'request'; $key_field = 'uuid'; $key_value = $fm_requestid; $result = db_get_records($dbh, $table_name, $key_field, $key_value, $sortby = null); if ($result != null) { $table_name = 'senator'; $key_field = 'district'; $key_value = $result[0]['district']; $result = db_get_records($dbh, $table_name, $key_field, $key_value, $sortby = null); if ($result != null) { print 'On behalf of Senator '; print $result[0]['firstname'] . " " . $result[0]['lastname']; } } print '<br /><br />';
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, build the array and store it in $form $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 this is the display_host screen that called, add refresh for DNS records too if ($form['content_id'] == 'display_host_list_interfaces') { $refresh .= "xajax_window_submit('list_records', xajax.getFormValues('list_records_filter_form'), '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']; } // 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; // Start building the "where" clause for the sql query to find the interfaces to display $where = ""; $and = ""; // HOST ID if ($form['host_id']) { $where .= $and . "host_id = " . $onadb->qstr($form['host_id']) . " OR id in (select interface_id from interface_clusters where host_id = " . $onadb->qstr($form['host_id']) . ")"; $and = " AND "; } // Do the SQL Query $filter = ''; if ($form['filter']) { $form['filter'] = ip_mangle($form['filter']); $filter = $and . ' ip_addr LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } list($status, $rows, $results) = db_get_records($onadb, 'interfaces', $where . $filter, "ip_addr ASC", $conf['search_results_per_page'], $offset); // If we got less than serach_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); } // Re-Count only "internal" interfaces, not nat interfaces list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'nat_interface_id = \'0\' and ' . $where . $filter, "", 0); $count = $rows; $html .= <<<EOL <!-- Interface List --> <table id="{$form['form_id']}_interface_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td colspan="2" class="list-header" align="center" style="{$style['borderR']};">Interface</td> <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td> <td class="list-header" align="center" style="{$style['borderR']};">MAC</td> <td class="list-header" align="center" style="{$style['borderR']};">Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Description</td> <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record foreach ($results as $record) { // Get additional info about each host record // // Check if this interface has an external NAT unset($extnatint, $extnatdisplay, $extnatdisplay, $extnatsubdisplay); if ($record['nat_interface_id'] > 0) { list($status, $rows, $extnatint) = ona_get_interface_record(array('id' => $record['nat_interface_id'])); // GDO: get the subnet object of the NATing interface, display it in both Interface and Subnet columns list($status, $rows, $extnatintsub) = ona_get_subnet_record(array('id' => $extnatint['subnet_id'])); $extnatint['ip_addr'] = ip_mangle($extnatint['ip_addr'], 'dotted'); //$extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']}'> => {$extnatint['ip_addr']}</span>"; $extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']} (on {$extnatintsub['name']})'> => {$extnatint['ip_addr']}</span>"; $extnatsubdisplay = " => <a title=\"View NATed subnet. ID: {$extnatintsub['id']}\"\n class=\"nav\"\n onClick=\"xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$extnatintsub['id']}\\', \\'display\\')');\"\n >{$extnatintsub['name']}</a>"; } // Check if this interface is an external NAT for another interface list($isnatstatus, $isnatrows, $isnat) = db_get_records($onadb, 'interfaces', "nat_interface_id = {$record['id']}", '', 0); // If the current interface is external NAT for another, dont display it in the list. if ($isnatrows > 0) { continue; } list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$record['id']}"); // Grab some info from the associated subnet record list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $record['subnet_id'])); $record['ip_mask'] = $subnet['ip_mask']; $record['subnet_id'] = $subnet['id']; $record['subnet_description'] = $subnet['name']; // Convert IP and Netmask to a presentable format $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted'); $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted'); $record['ip_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr'); if ($record['mac_addr']) { $record['mac_addr'] = mac_mangle($record['mac_addr']); } $record['description_short'] = truncate($record['description'], 40); // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } // Format the date and colorize if its older than 2 months if ($record['last_response']) { $record['last_response_fmt'] = date($conf['date_format'], strtotime($record['last_response'])); if (strtotime($record['last_response']) < strtotime('-2 month')) { $record['last_response_fmt'] = "<span style=\"color: red;\">" . $record['last_response_fmt'] . "</style>"; } } $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td nowrap="true" class="list-row" style="padding: 0px;" width="16px"> EOL; // Display cluster related information $clusterhtml = ' '; $clusterstyle = ''; $clusterscript = ''; if ($intclusterrows > 0) { $clusterstyle = 'font-weight: bold'; $clusterscript = "onMouseOver=\"wwTT(this, event,\n 'id', 'tt_interface_cluster_list_{$record['id']}',\n 'type', 'velcro',\n 'styleClass', 'wwTT_niceTitle',\n 'direction', 'south',\n 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$record['id']},interface_id=>{$record['id']}\\');'\n );\""; $clusterhtml .= <<<EOL <img src="{$images}/silk/sitemap.png" border="0" {$clusterscript} /> EOL; } $html .= $clusterhtml; $html .= <<<EOL </td> <td class="list-row"> EOL; // MP: Disabling the display_interface link. I dont think this will be needed if (1 < 0) { $html .= <<<EOL <a title="View interface. ID: {$record['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_interface\\',\\'interface_id=>{$record['id']}\\', \\'display\\')');"> {$record['ip_addr']} </a> EOL; } else { $html .= "<span style='{$clusterstyle}' {$clusterscript}>{$record['ip_addr']}</span>"; } $html .= <<<EOL <span style="{$clusterstyle}" title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span> {$extnatdisplay} </td> <td class="list-row" align="left"> <a title="View subnet. ID: {$subnet['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$subnet['id']}\\', \\'display\\')');" >{$record['subnet_description']}</a> {$extnatsubdisplay} </td> <td class="list-row" align="right"> {$record['mac_addr']} </td> <td class="list-row" align="left"> {$record['name']} </td> <td class="list-row" align="left" title="{$record['description']}"> {$record['description_short']} </td> <td class="list-row" align="left" title="{$record['last_response']}"> {$record['last_response_fmt']} </td> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_interface_{$record['id']}" ><input type="hidden" name="interface_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('interface_modify')) { $html .= <<<EOL <a title="Interface Menu" id="int_menu_button_{$record['id']}" class="act" onmouseover="wwTT(this, event, 'id', 'tt_quick_interface_menu_{$record['id']}', 'type', 'velcro', 'delay', 0, 'styleClass', 'wwTT_int_menu', 'lifetime', 1000, 'direction', 'west', 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>quick_interface_menu,id=>tt_quick_interface_menu_{$record['id']},interface_id=>{$record['id']},ip_addr=>{$record['ip_addr']},orig_host=>{$record['host_id']},form_id=>{$form['form_id']}_list_interface_{$record['id']},subnet_id=>{$subnet['id']},natip=>{$record['nat_interface_id']}\\');' );" ><img src="{$images}/silk/add.png" border="0"></a> EOL; } if (auth('interface_modify')) { $html .= <<<EOL <a title="Edit interface. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> EOL; } if (auth('interface_del')) { $html .= <<<EOL <a title="Delete interface" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } if ($count == 0 and $form['host_id'] and !$form['filter']) { $html .= <<<EOL <tr><td colspan="99" align="center" style="color: red;">Please add an interface to this host, or delete the host</td></tr> EOL; } $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_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); }