function host_display($options = "") { global $conf, $self, $onadb; $text_array = array(); // Version - UPDATE on every edit! $version = '1.04'; printmsg("DEBUG => host_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['host']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM host_display-v{$version} Displays a host record from the database Synopsis: host_display [KEY=VALUE] ... Required: host=NAME[.DOMAIN] or ID hostname or ID of the host display Optional: verbose=[yes|no] display additional info (yes) EOM ); } // Find the host (and domain) record from $options['host'] list($status, $rows, $host) = ona_find_host($options['host']); printmsg("DEBUG => Host: {$host['fqdn']}", 3); if (!$host['id']) { printmsg("DEBUG => Unknown host: {$options['host']}", 3); $self['error'] = "ERROR => Unknown host: {$options['host']}"; return array(2, $self['error'] . "\n"); } $text_array = $host; // Build text to return $text = "HOST RECORD ({$host['fqdn']})\n"; $text .= format_array($host); // If 'verbose' is enabled, grab some additional info to display if ($options['verbose'] == 'Y') { // TODO: if it is a nat interface, maybe process that IP and make it visible? // Interface record(s) $i = 0; do { list($status, $rows, $interface) = ona_get_interface_record(array('host_id' => $host['id'])); if ($rows == 0) { break; } $i++; $text .= "\nASSOCIATED INTERFACE RECORD ({$i} of {$rows})\n"; $text .= format_array($interface); $text_array['interfaces'][$i] = $interface; unset($text_array['interfaces'][$i]['host_id']); } while ($i < $rows); $text_array['interface_count'] = $rows; // Device record list($status, $rows, $device) = ona_get_device_record(array('id' => $host['device_id'])); if ($rows >= 1) { // Fill out some other device info list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id'])); list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $device['device_type'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})"; list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_id'])); $text_array['location'] = $location; $text_array['device'] = $device; $text .= "\nASSOCIATED DEVICE RECORD\n"; $text .= format_array($device); } // Tag records list($status, $rows, $tags) = db_get_records($onadb, 'tags', array('type' => 'host', 'reference' => $host['id'])); if ($rows) { $text .= "\nASSOCIATED TAG RECORDS\n"; foreach ($tags as $tag) { $text_array['tags'][] = $tag['name']; $text .= " {$tag['name']}\n"; } } } // Cleanup unused info unset($text_array['device_id']); unset($text_array['device']['asset_tag']); unset($text_array['device']['location_id']); unset($text_array['device']['serial_number']); // 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 config_add($options = "") { // The important globals global $conf; global $self; global $onadb; // Version - UPDATE on every edit! $version = '1.00'; // This debug is set very high as it can contain large configs and sensitive data, you gotta mean it! printmsg('DEBUG => config_add(' . $options . ') called', 7); // 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['type'] and $options['config'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console return array(1, <<<EOM config_add-v{$version} Adds a new config text record into the database Synopsis: config_add [KEY=VALUE] ... Required: config=TEXT the actual config text or filename to insert host=ID or NAME[.DOMAIN] host the config text is from type=TYPE type of config text we're inserting - usually "IOS_VERSION" or "IOS_CONFIG" EOM ); } // Search for the host first 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']); } // Now find the ID of the config type they entered list($status, $rows, $config_type) = ona_get_config_type_record(array('name' => $options['type'])); if (!$config_type['id']) { $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!"; return array(3, $self['error']); } $options['config'] = preg_replace('/\\\\"/', '"', $options['config']); $options['config'] = preg_replace('/\\\\=/', '=', $options['config']); // Get the next ID for the new config_text record $id = ona_get_next_id('configurations'); if (!$id) { return array(4, "ERROR => The ona_get_next_id(configurations) call failed!\n"); } printmsg("DEBUG => ID for new config_record: {$id}", 3); // Add the config_text list($status, $rows) = db_insert_record($onadb, 'configurations', array('id' => $id, 'configuration_type_id' => $config_type['id'], 'host_id' => $host['id'], 'md5_checksum' => md5($options['config']), 'config_body' => $options['config'])); if ($status or !$rows) { $self['error'] = "ERROR => message_add() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(6, $self['error'] . "\n"); } list($status, $rows, $record) = ona_get_config_record(array('id' => $id)); if ($status or !$rows) { $self['error'] = 'ERROR => SQL INSERT failed. Database error: ' . $error . "\n"; return array(5, $self['error']); } // Return the success notice $text = "NOTICE => Config text record ADDED, ID: {$id}\n"; return array(0, $text); }
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 suppress 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 domain record list($status, $rows, $record) = ona_get_domain_record(array('id' => $form['domain_id'])); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Domain doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // 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'] = $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}');"; // Get associated info if ($record['parent_id']) { list($status, $rows, $parent_domain) = ona_get_domain_record(array('id' => $record['parent_id'])); $parent_domain['name'] = ona_build_domain_name($parent_domain['id']); } else { $parent_domain = ""; } // Find the primary_master host to see if it is valid list($status, $rows, $primaster_host) = ona_find_dns_record($record['primary_master']); if ($primaster_host['id'] === 0) { $not_a_primaster = 1; } $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } foreach (array_keys((array) $parent_domain) as $key) { $parent_domain[$key] = htmlentities($parent_domain[$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; // DOMAIN INFORMATION BOX $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <tr> <td colspan="99" nowrap="true"> <!-- LABEL --> <form id="form_domain_{$record['id']}" ><input type="hidden" name="id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <div style="{$style['label_box']}"> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <a title="Edit domain. ID: {$record['id']}" onClick="xajax_window_submit('edit_domain', xajax.getFormValues('form_domain_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> <a title="Delete domain. ID: {$record['id']}" class="linkact" onClick="var doit=confirm('Are you sure you want to delete this domain?'); if (doit == true) xajax_window_submit('edit_domain', xajax.getFormValues('form_domain_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png"></a> EOL; } $html .= <<<EOL {$record['fqdn']} </div> </td> </tr> EOL; if ($parent_domain['id']) { $html .= <<<EOL <tr> <td align="right" nowrap="true"><b>Parent Domain</b> </td> <td class="padding" align="left"> <a title="View domain. ID: {$parent_domain['id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$parent_domain['id']}\\', \\'display\\')');" >{$parent_domain['name']}</a> </td> </tr> <tr><td colspan="2" align="left" nowrap="true"> </td></tr> EOL; } $html .= <<<EOL <tr> <td colspan="2" align="left" nowrap="true"><b><u>Domain SOA Parameters</u></b> </td> </tr> EOL; if ($record['primary_master']) { if ($not_a_primaster) { $record['primary_master'] = "<span style='background-color: #FFDDDD;' title='INFO: This FQDN is not defined in the database.'><img src='{$images}/silk/error.png' border='0'> {$record['primary_master']}</span>"; } $html .= <<<EOL <tr> <td align="right" nowrap="true"><b>Primary Master</b> </td> <td class="padding" align="left" onClick="xajax_window_submit('edit_domain', xajax.getFormValues('form_domain_{$record['id']}'), 'editor');"> {$record['primary_master']} </td> </tr> EOL; } else { $html .= <<<EOL <tr style="background-color: #FFDDDD;" title="There is no defined primary master server!"> <td align="right" nowrap="true"><b>Primary Master</b> </td> <td nowrap="true"> <img src='{$images}/silk/error.png' border='0'> Please assign a Primary Master server! </td> </tr> EOL; } $html .= <<<EOL <tr> <td align="right" nowrap="true"><b>Refresh</b> </td> <td class="padding" align="left"> {$record['refresh']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Retry</b> </td> <td class="padding" align="left"> {$record['retry']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Expiry</b> </td> <td class="padding" align="left"> {$record['expiry']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Minimum</b> </td> <td class="padding" align="left"> {$record['minimum']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Default TTL</b> </td> <td class="padding" align="left"> {$record['default_ttl']} </td> </tr> </table> EOL; // END DOMAIN INFORMATION BOX $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; // DNS SERVERS BOX $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 servers </td> </tr> EOL; // Get a list of servers, and loop through them list($status, $rows, $domainservers) = db_get_records($onadb, 'dns_server_domains', array('domain_id' => $record['id']), 'role'); if ($rows) { foreach ($domainservers as $domainserver) { $domainserver['role'] = strtoupper($domainserver['role']); list($status, $rows, $host) = ona_find_host($domainserver['host_id']); $host['fqdn'] = htmlentities($host['fqdn'], ENT_QUOTES, $conf['php_charset']); $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td align="left" nowrap="true"> <a title="View server. ID: {$host['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain_server\\', \\'host_id=>{$host['id']}\\', \\'display\\')');" >{$host['fqdn']}</a> </td> <td align="left" nowrap="true" style="border-left: 1px solid; border-left-color: #aaaaaa;padding-left: 3px;"> {$domainserver['role']} </td> <td align="right" nowrap="true"> <form id="{$form['form_id']}_domain_serv_{$domainserver['id']}" ><input type="hidden" name="server" value="{$domainserver['host_id']}" ><input type="hidden" name="domain" value="{$domainserver['domain_id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <a title="Remove domain assignment" class="linkact" onClick="var doit=confirm('Are you sure you want to remove this domain from this DNS server?'); if (doit == true) xajax_window_submit('edit_domain_server', xajax.getFormValues('{$form['form_id']}_domain_serv_{$domainserver['id']}'), 'delete');" ><img src="{$images}/silk/page_delete.png"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } } else { $html .= <<<EOL <tr style="background-color: #FFDDDD;" title="There are no defined servers for this domain!"> <td colspan=10 nowrap="true"> <img src="{$images}/silk/error.png"> Please add a server for this domain! </td> EOL; } if (auth('advanced', $debug_val)) { $html .= <<<EOL <tr> <td colspan="3" align="left" valign="middle" nowrap="true" class="act-box"> <form id="form_domain_server_{$record['id']}" ><input type="hidden" name="domain" value="{$record['name']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Assign server" class="linkact" onClick="xajax_window_submit('edit_domain_server', xajax.getFormValues('form_domain_server_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png">Assign to server</a> </td> </tr> EOL; } $html .= " </table>"; // END DNS SERVERS BOX $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; // extra stuff to pass to ws_plugins $extravars['refresh'] = $refresh; $extravars['window_name'] = $window_name; // Get all the plugin based worspace items $wspl_list = plugin_list('wspl_item'); // Load all the dynamic plugins foreach ($wspl_list as $p) { $wspl = workspace_plugin_loader($p['path'], $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; } $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <!-- END OF TOP SECTION --> EOL; // HOST LIST $tab = 'records'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- HOST LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> EOL; $html .= <<<EOL <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="domain_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('dns_record_add', $debug_val)) { $html .= <<<EOL <!-- List by IP Address LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_dns_add_{$record['id']}"> <input type="hidden" name="js" value="{$refresh}"> <input type="hidden" name="domain_id" value="{$record['id']}"> </form> <a title="Add DNS Record" class="linkact" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_dns_add_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png">Add a new DNS record</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 domain_server_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.02'; printmsg("DEBUG => domain_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['domain'] 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 domain_server_del-v{$version} Removes a domain record from a DNS server Synopsis: domain_server_del [KEY=VALUE] ... Required: domain=NAME or ID domain name or ID server=NAME[.DOMAIN] or ID server name or ID Optional: commit=[Y|N] commit db transaction (no) EOM ); } if (is_numeric($options['domain'])) { $domainsearch['id'] = $options['domain']; } else { $domainsearch['name'] = strtoupper($options['domain']); } // Determine the entry itself exists list($status, $rows, $domain) = ona_get_domain_record($domainsearch); // Test to see that we were able to find the specified record if (!$domain['id']) { printmsg("DEBUG => Unable to find the domain record using {$options['domain']}!", 3); $self['error'] = "ERROR => Unable to find the domain record using {$options['domain']}!"; return array(4, $self['error'] . "\n"); } printmsg("DEBUG => domain_server_del(): Found domain, {$domain['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"); } } // Test that this domain is even assigned to the server list($status, $rows, $domainserver) = ona_get_dns_server_domain_record(array('host_id' => $host['id'], 'domain_id' => $domain['id'])); if (!$rows) { printmsg("DEBUG => Unable to find {$domain['name']} on server {$host['fqdn']}", 3); $self['error'] = "ERROR => Unable to find {$domain['name']} on server {$host['fqdn']}"; return array(11, $self['error'] . "\n"); } // Test that there are no NS records for this pair // ASSUMPTION: MP this will always be just one record?? // depending on how the user has their NS records set up, we may not find anything. list($status, $dnsrows, $dnsrec) = db_get_record($onadb, 'dns', "domain_id = {$domain['id']} AND type = 'NS' AND interface_id in (select id from interfaces where host_id = {$host['id']})"); // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($host['LVL']) or !authlvl($domain['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // delete record from domain_server_domains list($status, $rows) = db_delete_records($onadb, 'dns_server_domains', array('id' => $domainserver['id'])); if ($status) { $self['error'] = "ERROR => domain_server_del() SQL Query failed:" . $self['error']; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Run the module to delete the associated NS record.. Only if we found a dns record for NS if ($dnsrec['id']) { list($status, $output) = run_module('dns_record_del', array('name' => $dnsrec['id'], 'type' => 'NS', 'commit' => 'Y')); if ($status) { $self['error'] = "ERROR => domain_server_del() NS record delete failed:" . $output; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } else { // add the output to self error for display $add_to_error = $output; } } // Return the success notice $self['error'] = "INFO => DNS Domain/Server Pair DELETED: {$domain['name']}/{$host['fqdn']} "; printmsg($self['error'], 0); return array(0, $add_to_error . $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: {$domain['name']} from: {$host['fqdn']} EOL; if ($dnsrows) { $text .= " Removing related NS record, if any. Please double check your NS records for this domain.\n"; } return array(6, $text); }
function quick_pool_server_search($form) { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $html = $js = ''; $font_color = '#FFFFFF'; // Build failover group list list($status, $rows, $fg) = db_get_records($onadb, 'dhcp_failover_groups', 'id >= 1', 'id'); $fg_list = '<option value="0">None</option>\\n'; foreach ($fg as $record) { list($status, $rows, $fail_host1) = ona_find_host($record['primary_server_id']); list($status, $rows, $fail_host2) = ona_find_host($record['secondary_server_id']); $selected = ""; if ($record['id'] == $form['failover_group_id']) { $selected = "SELECTED=\"selected\""; } if ($record['id']) { $fg_list .= "<option {$selected} value=\"{$record['id']}\">{$fail_host1['fqdn']}/{$fail_host2['fqdn']}</option>\n"; } } $js .= <<<EOL suggest_setup('pool_server_qf', 'suggest_pool_server_qf'); EOL; $style['content_box'] = <<<EOL padding: 2px 4px; vertical-align: top; EOL; // WARNING: this one's different than most of them! $style['label_box'] = <<<EOL font-weight: bold; cursor: move; color: #FFFFFF; EOL; $html .= <<<EOL <!-- POOL SERVER QUICK SEARCH --> <form id="quick_pool_server_search_form" onSubmit="return(false);"> <input type="hidden" name="id" value="{$form['id']}"> <input type="hidden" name="input_id" value="{$form['input_id']}"> <input type="hidden" name="content_id" value="qf_pool_server_results"> <table id="pool_server_search" style="{$style['content_box']}" cellspacing="0" border="0" cellpadding="0"> <tr> <td colspan="2" align="center" class="qf-search-line" style="{$style['label_box']}; padding-top: 0px;" onMouseDown="dragStart(event, '{$form['id']}', 'savePosition', 0);"> DHCP Pool Failover Server Quick Select </td> </tr> <tr> <td align="right" class="qf-search-line" nowrap="true"> Server <u>g</u>roup </td> <td align="left" class="qf-search-line"> <select id="failover_group_qf" name="failover_group" class="edit" accesskey="f" onClick="el('pool_server_qf').value = '';"> {$fg_list} </select> </td> </tr> <tr> <td align="right" class="qf-search-line"> </td> <td align="right" class="qf-search-line"> <input class="button" type="button" name="cancel" value="Cancel" onClick="removeElement('{$form['id']}');"> <input class="button" type="button" name="select" value="Select" accesskey="s" onClick="el('{$form['failover_group']}').value = failover_group_qf.options[failover_group_qf.selectedIndex].value; if (failover_group_qf.options[failover_group_qf.selectedIndex].value) el('{$form['text_id']}').innerHTML = failover_group_qf.options[failover_group_qf.selectedIndex].innerHTML; removeElement('{$form['id']}');"> </td> </tr> </table> </form> EOL; return array($html, $js); }
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 format_array($array = array()) { $text = ''; foreach (array_keys($array) as $key) { // Make some data look pretty if ($key == 'ip_addr') { $array[$key] = ip_mangle($array[$key], 'dotted'); } else { if ($key == 'ip_addr_start') { $array[$key] = ip_mangle($array[$key], 'dotted'); } else { if ($key == 'ip_addr_end') { $array[$key] = ip_mangle($array[$key], 'dotted'); } else { if ($key == 'ip_mask') { $array[$key] = ip_mangle($array[$key]) . ' (/' . ip_mangle($array[$key], 'cidr') . ')'; } else { if ($key == 'mac_addr') { $array[$key] = mac_mangle($array[$key]); if ($array[$key] == -1) { $array[$key] = ''; } } else { if ($key == 'host_id') { list($status, $rows, $host) = ona_find_host($array[$key]); if ($host['id']) { $array[$key] = str_pad($array[$key], 20) . strtolower("({$host['fqdn']})"); } } else { if ($key == 'server_id') { list($status, $rows, $server) = ona_get_server_record(array('id' => $array[$key])); list($status, $rows, $host) = ona_find_host($server['host_id']); if ($host['id']) { $array[$key] = str_pad($array[$key], 20) . strtolower("({$host['fqdn']})"); } } else { if ($key == 'subnet_id') { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $array[$key])); if ($subnet['id']) { $array[$key] = str_pad($array[$key], 20) . strtoupper("({$subnet['name']})"); } } else { if ($key == 'domain_id' or $key == 'primary_dns_domain_id') { list($status, $rows, $domain) = ona_get_domain_record(array('id' => $array[$key])); $array[$key] = str_pad($array[$key], 20) . strtolower("({$domain['fqdn']})"); } else { if ($key == 'interface_id') { list($status, $rows, $interface) = ona_get_interface_record(array('id' => $array[$key])); $array[$key] = str_pad($array[$key], 20) . '(' . ip_mangle($interface['ip_addr'], 'dotted') . ')'; } else { if ($key == 'device_type_id') { list($status, $rows, $devtype) = ona_get_device_type_record(array('id' => $array[$key])); if ($devtype['id']) { list($status, $rows, $model) = ona_get_model_record(array('id' => $devtype['model_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $devtype['role_id'])); list($status, $rows, $manu) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $array[$key] = str_pad($array[$key], 20) . "({$manu['name']}, {$model['name']} ({$role['name']}))"; } } else { if ($key == 'custom_attribute_type_id') { list($status, $rows, $ca) = ona_get_custom_attribute_type_record(array('id' => $array[$key])); if ($ca['id']) { $array[$key] = str_pad($array[$key], 20) . "({$ca['name']})"; } } } } } } } } } } } } } // Align columns if ($array[$key]) { $text .= str_pad(" {$key}", 30) . $array[$key] . "\n"; } } // Return a nice string :) return $text; }
function dhcp_failover_group_display($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => dhcp_failover_group_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['id'] or $options['pri_server'] and $options['sec_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_failover_group_display-v{$version} Displays an DHCP failover group record from the database Synopsis: dhcp_failover_group_display [KEY=VALUE] ... Required: id=id id of the DHCP failover group to display OR pri_server=NAME[.DOMAIN] or id identifier of the primary server sec_server=NAME[.DOMAIN] or id identifier of the secondary server EOM ); } $search = array(); if ($options['pri_server'] and $options['sec_server']) { // Determine the server is valid list($status, $rows, $pri_host) = ona_find_host($options['pri_server']); if (!$pri_host['id']) { printmsg("DEBUG => The server specified, {$options['pri_server']}, does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['pri_server']}, does not exist!"; return array(2, $self['error'] . "\n"); } // Determine the host that was found is actually a server // MP: FIXME: dont think I'm going to pursue doing a seperate server table.. lets remove // list($status, $rows, $pri_server) = ona_get_server_record(array('host_id' => $pri_host['id'])); // // if (!$pri_server['id']) { // printmsg("DEBUG => The host specified, {$pri_host['FQDN']}, is not a server!",3); // $self['error'] = "ERROR => The host specified, {$pri_host['FQDN']}, is not a server!"; // return(array(5, $self['error'] . "\n")); // } // Determine the server is valid list($status, $rows, $sec_host) = ona_find_host($options['sec_server']); if (!$sec_host['id']) { printmsg("DEBUG => The server specified, {$options['sec_server']}, does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['sec_server']}, does not exist!"; return array(2, $self['error'] . "\n"); } // Determine the host that was found is actually a server // MP: FIXME: dont think I'm going to pursue doing a seperate server table.. lets remove // list($status, $rows, $sec_server) = ona_get_server_record(array('HOST_id' => $sec_host['id'])); // // if (!$sec_server['id']) { // printmsg("DEBUG => The host specified, {$sec_host['fqdn']}, is not a server!",3); // $self['error'] = "ERROR => The host specified, {$sec_host['fqdn']}, is not a server!"; // return(array(5, $self['error'] . "\n")); // } $search['primary_server_id'] = $pri_server['id']; $search['secondary_server_id'] = $sec_server['id']; } if ($options['id']) { $search['id'] = $options['id']; } // Determine the entry itself exists list($status, $rows, $failovergroup) = ona_get_dhcp_failover_group_record($search); // Test to see that we were able to find the specified record if (!$failovergroup['id']) { printmsg("DEBUG => Unable to find the DHCP failover group record using {$options['id']}!", 3); $self['error'] = "ERROR => Unable to find the DHCP failover group record using {$options['id']}!"; return array(4, $self['error'] . "\n"); } list($status, $rows, $pri_server) = ona_find_host($failovergroup['primary_server_id']); list($status, $rows, $sec_server) = ona_find_host($failovergroup['secondary_server_id']); $failovergroup['pri_server_name'] = $pri_server['fqdn']; $failovergroup['sec_server_name'] = $sec_server['fqdn']; // Debugging printmsg("DEBUG => dhcp_failover_group_display(): Found id:{$failovergroup['id']}", 3); // Build text to return $text = "DHCP FAILOVER GROUP RECORD:\n"; $text .= format_array($failovergroup); // Return the success notice return array(0, $text); }
function ws_display($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the server record list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id'])); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Server doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Pick up host information list($status, $rows, $host) = ona_find_host($form['host_id']); $record['fqdn'] = $host['fqdn']; // Update History Title $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = "DHCP server - " . $record['name']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; // extra stuff to pass to ws_plugins $extravars['refresh'] = $refresh; $extravars['window_name'] = $window_name; $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; vertical-align: top; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <!-- FORMATTING TABLE --> <div style="{$style['content_box']}"> <table cellspacing="0" border="0" cellpadding="0"><tr> <!-- START OF FIRST COLUMN OF SMALL BOXES --> <td nowrap="true" valign="top" style="padding-right: 15px;"> EOL; // SERVER INFORMATION $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <!-- LABEL --> <tr><td colspan="99" nowrap="true" style="{$style['label_box']}"> DHCP server <a title="View host" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$record['id']}\\', \\'display\\')');" >{$record['name']}</a>.<a title="View domain. ID: {$record['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$record['domain_id']}\\', \\'display\\')');" >{$record['domain_fqdn']}</a> </td></tr> </table> EOL; // END SERVER INFORMATION $html .= <<<EOL <!-- END OF FIRST COLUMN OF SMALL BOXES --> </td> <!-- START OF SECOND COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; // FAILOVER GROUP INFO BOX // get failover group information list($status, $rows, $failover_groups) = db_get_records($onadb, 'dhcp_failover_groups', "primary_server_id = {$record['id']} or secondary_server_id = {$record['id']}"); if ($rows) { $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <!-- LABEL --> <tr><td colspan="2" nowrap="true" style="{$style['label_box']}">Failover groups</td></tr> EOL; foreach ($failover_groups as $failover) { // Get DNS name for primary and secondary servers list($status, $rows, $fail_pri_host) = ona_get_host_record(array('id' => $failover['primary_server_id'])); list($status, $rows, $fail_sec_host) = ona_get_host_record(array('id' => $failover['secondary_server_id'])); $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td align="left">GROUP_ID-{$failover['id']}: {$fail_pri_host['name']}<img src="{$images}/silk/link.png" border="0">{$fail_sec_host['name']} </td> <td align="right"> <a title="Edit failover group. ID: {$failover['id']}" class="act" onClick="xajax_window_submit('edit_dhcp_failover_group', '{$failover['id']}', 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> </td> </tr> </table> EOL; } } // END FAILOVER GROUP INFO BOX $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THRID COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; // Start displaying all the ws plugins $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; //DONT add the, not needed $wsmenu{}=$wspl[2]; // This will display the server level, not global level $extravars['dhcpserver_id'] = $host['id']; $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wsmenuhtml = build_workspace_menu($wsmenu); $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <form id="form_server_{$record['id']}" ><input type="hidden" name="server_id" value="{$host['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <form id="form_global_{$record['id']}" ><input type="hidden" name="global_id" value="0" ><input type="hidden" name="js" value="{$refresh}" ></form> <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div> <!-- END OF TOP SECTION --> EOL; // SUBNET LIST $tab = 'dhcp_server'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- SUBNET LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_subnets_tab" class="table-tab-active"> Assigned Subnets <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="server_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Filter</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_dhcp_server_{$record['id']}" ><input type="hidden" name="server" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <!-- ADD SUBNET LINK --> <a title="Assign subnet to DHCP server" class="act" onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Assign subnet to DHCP server" class="act" onClick="xajax_window_submit('edit_dhcp_server', xajax.getFormValues('form_dhcp_server_{$record['id']}'), 'editor');" >Assign subnet</a> </div> EOL; } $html .= <<<EOL </div> EOL; // If we have a build type set, then display the output div if ($conf['build_dhcp_type'] && auth('advanced', $debug_val)) { $html .= <<<EOL <div id="confoutputdiv" style="border: 1px solid rgb(26, 26, 26); margin: 10px 20px;padding-left: 8px;overflow:hidden;width: 100px;"><pre style='font-family: monospace;overflow-y:auto;' id="confoutput"><center>Generating configuration...</center><br>{$conf['loading_icon']}</pre></div> EOL; $js .= "xajax_window_submit('{$window_name}', 'fqdn=>{$record['fqdn']}', 'display_config');"; } $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); setTimeout('el(\\'confoutputdiv\\').style.width = el(\\'{$form_id}_table\\').offsetWidth-8+\\'px\\';',900); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function 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 hosts 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 HOST SEARCH *** // FIND RESULT SET // // Start building the "where" clause for the sql query to find the hosts to display $where = ""; $and = ""; $orderby = ""; $from = 'hosts h'; // enable or disable wildcards $wildcard = '%'; if ($form['nowildcard']) { $wildcard = ''; } // DISPLAY ALL // MP: I dont think this is used.. remove it if you can if ($form['all_flag']) { $where .= $and . "h.id > 0"; $and = " AND "; } // HOST ID if ($form['host_id']) { $where .= $and . "h.id = " . $onadb->qstr($form['host_id']); $and = " AND "; } // DEVICE ID if ($form['device_id']) { $where .= $and . "h.device_id = " . $onadb->qstr($form['device_id']); $and = " AND "; } // HOSTNAME if ($form['hostname']) { // Find the domain name piece of the hostname assuming it was passed in as an fqdn. // FIXME: MP this was taken from the ona_find_domain function. make that function have the option // to NOT return a default domain. // lets test out if it has a / in it to strip the view name portion $view['id'] = 0; if (strstr($form['hostname'], '/')) { list($dnsview, $form['hostname']) = explode('/', $form['hostname']); list($status, $viewrows, $view) = db_get_record($onadb, 'dns_views', array('name' => strtoupper($dnsview))); if (!$viewrows) { $view['id'] = 0; } } // Split it up on '.' and put it in an array backwards $parts = array_reverse(explode('.', $form['hostname'])); // Find the domain name that best matches $name = ''; $domain = array(); foreach ($parts as $part) { if (!$rows) { if (!$name) { $name = $part; } else { $name = "{$part}.{$name}"; } list($status, $rows, $record) = ona_get_domain_record(array('name' => $name)); if ($rows) { $domain = $record; } } else { list($status, $rows, $record) = ona_get_domain_record(array('name' => $part, 'parent_id' => $domain['id'])); if ($rows) { $domain = $record; } } } $withdomain = ''; $hostname = $form['hostname']; // If you found a domain in the query, add it to the search, and strip the domain from the host portion. if (array_key_exists('id', $domain) and !$form['domain']) { $withdomain = "AND b.domain_id = {$domain['id']}"; // Now find what the host part of $search is $hostname = str_replace(".{$domain['fqdn']}", '', $form['hostname']); } // If we have a hostname and a domain name then use them both if ($form['domain']) { list($status, $rows, $record) = ona_find_domain($form['domain']); if ($record['id']) { $withdomain = "AND b.domain_id = {$record['id']}"; } // Now find what the host part of $search is $hostname = trim($form['hostname']); } // MP: Doing the many select IN statements was too slow.. I did this kludge: // 1. get a list of all the interfaces // 2. loop through the array and build a list of comma delimited host_ids to use in the final select list($status, $rows, $tmp) = db_get_records($onadb, 'interfaces a, dns b', "a.id = b.interface_id and b.name LIKE '{$wildcard}{$hostname}{$wildcard}' {$withdomain}"); $commait = ''; $hostids = ''; foreach ($tmp as $item) { $hostids .= $commait . $item['host_id']; $commait = ','; } // Just look for the host itself list($status, $rows, $r) = ona_find_host($form['hostname']); if ($rows) { $hostids .= ',' . $r['id']; } // MP: this is the old, slow query for reference. // // TODO: MP this seems to be kinda slow (gee I wonder why).. look into speeding things up somehow. // This also does not search for CNAME records etc. only things with interface_id.. how to fix that issue.......? // $where .= $and . "id IN (select host_id from interfaces where id in (SELECT interface_id " . // " FROM dns " . // " WHERE name LIKE '%{$hostname}%' {$withdomain} ))"; // Trim off extra commas $hostids = trim($hostids, ","); // If we got a list of hostids from interfaces then use them if ($hostids) { $idqry = "h.id IN ({$hostids})"; } else { $idqry = ""; } $where .= $and . $idqry; $and = " AND "; } // DOMAIN if ($form['domain'] and !$form['hostname']) { // FIXME: does this clause work correctly? printmsg("FIXME: => Does \$form['domain'] work correctly in list_hosts.inc.php?", 2); // Find the domain name piece of the hostname. // FIXME: MP this was taken from the ona_find_domain function. make that function have the option // to NOT return a default domain. // Split it up on '.' and put it in an array backwards $parts = array_reverse(explode('.', $form['domain'])); // Find the domain name that best matches $name = ''; $domain = array(); foreach ($parts as $part) { if (!$rows) { if (!$name) { $name = $part; } else { $name = "{$part}.{$name}"; } list($status, $rows, $record) = ona_get_domain_record(array('name' => $name)); if ($rows) { $domain = $record; } } else { list($status, $rows, $record) = ona_get_domain_record(array('name' => $part, 'parent_id' => $domain['id'])); if ($rows) { $domain = $record; } } } if (array_key_exists('id', $domain)) { // Crappy way of writing the query but it makes it fast. $from = "(\nSELECT distinct a.*\nfrom hosts as a, interfaces as i, dns as d\nwhere a.id = i.host_id\nand i.id = d.interface_id\nand d.domain_id = " . $onadb->qstr($domain['id']) . "\n) h"; $and = " AND "; } } // DOMAIN ID if ($form['domain_id'] and !$form['hostname']) { $where .= $and . "h.primary_dns_id IN ( SELECT id " . " FROM dns " . " WHERE domain_id = " . $onadb->qstr($form['domain_id']) . " ) "; $and = " AND "; } // MAC if ($form['mac']) { // Clean up the mac address $form['mac'] = strtoupper($form['mac']); $form['mac'] = preg_replace('/[^%0-9A-F]/', '', $form['mac']); // We do a sub-select to find interface id's that match $where .= $and . "h.id IN ( SELECT host_id " . " FROM interfaces " . " WHERE mac_addr LIKE " . $onadb->qstr($wildcard . $form['mac'] . $wildcard) . " ) "; $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 . "h.id IN ( SELECT host_id " . " FROM interfaces " . " WHERE ip_addr >= " . $onadb->qstr($ip) . " AND ip_addr <= " . $onadb->qstr($ip_end) . " )"; $and = " AND "; } } // NOTES if ($form['notes']) { $where .= $and . "h.notes LIKE " . $onadb->qstr($wildcard . $form['notes'] . $wildcard); $and = " AND "; } // DEVICE MODEL if ($form['model_id']) { $where .= $and . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id = {$form['model_id']}))"; $and = " AND "; } if ($form['model']) { $where .= $and . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id in (select id from models where name like '{$form['model']}')))"; $and = " AND "; } // DEVICE TYPE if ($form['role']) { // Find model_id's that have a device_type_id of $form['role'] list($status, $rows, $records) = db_get_records($onadb, 'roles', array('name' => $form['role'])); // If there were results, add each one to the $where clause if ($rows > 0) { $where .= $and . " ( "; $and = " AND "; $or = ""; foreach ($records as $record) { // Yes this is one freakin nasty query but it works. $where .= $or . "h.device_id in (select id from devices where device_type_id in (select id from device_types where role_id = " . $onadb->qstr($record['id']) . "))"; $or = " OR "; } $where .= " ) "; } } // DEVICE MANUFACTURER if ($form['manufacturer']) { // Find model_id's that have a device_type_id of $form['manufacturer'] if (is_numeric($form['manufacturer'])) { list($status, $rows, $records) = db_get_records($onadb, 'models', array('manufacturer_id' => $form['manufacturer'])); } else { list($status, $rows, $manu) = db_get_record($onadb, 'manufacturers', array('name' => $form['manufacturer'])); list($status, $rows, $records) = db_get_records($onadb, 'models', array('manufacturer_id' => $manu['id'])); } // If there were results, add each one to the $where clause if ($rows > 0) { $where .= $and . " ( "; $and = " AND "; $or = ""; foreach ($records as $record) { // Yes this is one freakin nasty query but it works. $where .= $or . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id = " . $onadb->qstr($record['id']) . "))"; $or = " OR "; } $where .= " ) "; } } // tag if ($form['tag_host']) { $where .= $and . "h.id in (select reference from tags where type like 'host' and name like " . $onadb->qstr($form['tag_host']) . ")"; $and = " AND "; } // custom attribute type if ($form['custom_attribute_type']) { $where .= $and . "h.id in (select table_id_ref from custom_attributes where table_name_ref like 'hosts' and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type']) . "))"; $and = " AND "; $cavaluetype = "and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type']) . ")"; } // custom attribute value if ($form['ca_value']) { $where .= $and . "h.id in (select table_id_ref from custom_attributes where table_name_ref like 'hosts' {$cavaluetype} and value like " . $onadb->qstr($wildcard . $form['ca_value'] . $wildcard) . ")"; $and = " AND "; } // LOCATION No. if ($form['location']) { list($status, $rows, $loc) = ona_find_location($form['location']); $where .= $and . "h.device_id in (select id from devices where location_id = " . $onadb->qstr($loc['id']) . ")"; $and = " AND "; } // subnet ID if (is_numeric($form['subnet_id'])) { // We do a sub-select to find interface id's that match $from = "(\nSELECT distinct a.*\nfrom hosts as a, interfaces as b\nwhere a.id = b.host_id\nand b.subnet_id = " . $onadb->qstr($form['subnet_id']) . "\norder by b.ip_addr) h"; $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 hosts 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 = 'h.id > 0'; } // Do the SQL Query $filter = ''; if ($form['filter']) { // Host names should always be lower case $form['filter'] = strtolower($form['filter']); // FIXME (MP) for now this uses primary_dns_id, this will NOT find multiple A records or other record types. Find a better way some day $filter = " AND h.primary_dns_id IN (SELECT id " . " FROM dns " . " WHERE name LIKE " . $onadb->qstr('%' . $form['filter'] . '%') . " ) "; } list($status, $rows, $results) = db_get_records($onadb, $from, $where . $filter, $orderby, $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); } else { if ($rows >= $conf['search_results_per_page']) { list($status, $rows, $records) = db_get_records($onadb, $from, $where . $filter, "", 0); } } $count = $rows; // // *** BUILD HTML LIST *** // $html .= <<<EOL <!-- Host Results --> <table id="{$form['form_id']}_host_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']};">Interface</td> <td class="list-header" align="center" style="{$style['borderR']};">Device Type</td> <td class="list-header" align="center" style="{$style['borderR']};">Location</td> <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 foreach ($results as $record) { // Get additional info about eash host record // If a subnet_id was passed use it as part of the search. Used to display the IP of the subnet you searched if (is_numeric($form['subnet_id'])) { list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id'], 'subnet_id' => $form['subnet_id']), ''); // Count how many rows and assign it back to the interfaces variable list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']), "ip_addr", 0); $interfaces = $rows; } else { if (is_numeric($ip)) { list($status, $interfaces, $interface) = db_get_record($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']) . ' AND ip_addr >= ' . $onadb->qstr($ip) . ' AND ip_addr <= ' . $onadb->qstr($ip_end), "ip_addr", 0); // Count how many rows and assign it back to the interfaces variable list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']), "ip_addr", 0); $interfaces = $rows; } else { // Interface (and find out how many there are) list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id']), ''); } } // bz: why did someone add this?? You especially want to show hosts with no interfaces so you can fix them! // if (!$interfaces) {$count -1; continue;} // get interface cluster info $clusterhtml = ''; list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$interface['id']}"); if ($intclusterrows > 0) { $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=>{$interface['id']}\\');'\n );\""; $clusterhtml .= <<<EOL <img src="{$images}/silk/sitemap.png" {$clusterscript} /> EOL; } $record['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted'); $interface_style = ''; if ($interfaces > 1) { $interface_style = 'font-weight: bold;'; } // DNS A record list($status, $rows, $dns) = ona_get_dns_record(array('id' => $record['primary_dns_id'])); $record['name'] = $dns['name']; // Domain Name list($status, $rows, $domain) = ona_get_domain_record(array('id' => $dns['domain_id'])); $record['domain'] = $domain['fqdn']; // 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'); // Device Description list($status, $rows, $device) = ona_get_device_record(array('id' => $record['device_id'])); list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id'])); list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $record['devicefull'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})"; $record['device'] = str_replace('Unknown', '?', $record['devicefull']); $record['notes_short'] = truncate($record['notes'], 40); // Get location_number from the location_id list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_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_host\\', \\'host_id=>{$record['id']}\\', \\'display\\')');"; $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td class="list-row"> <a title="View host. ID: {$record['id']}" class="nav" onClick="{$primary_object_js}" >{$record['name']}</a >.<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"> <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']}</a> </td> <td class="list-row" align="left"> <span style="{$interface_style}" EOL; if ($interfaces > 1) { $html .= <<<EOL onMouseOver="wwTT(this, event, 'id', 'tt_host_interface_list_{$record['id']}', 'type', 'velcro', 'styleClass', 'wwTT_niceTitle', 'direction', 'south', 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>host_interface_list,id=>tt_host_interface_list_{$record['id']},host_id=>{$record['id']}\\');' );" EOL; } $html .= <<<EOL >{$record['ip_addr']}</span> <span title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span> <span>{$clusterhtml}</span> </td> <td class="list-row" title="{$record['devicefull']}">{$record['device']} </td> <td class="list-row" align="right"> <span onMouseOver="wwTT(this, event, 'id', 'tt_location_{$device['location_id']}', 'type', 'velcro', 'styleClass', 'wwTT_niceTitle', 'direction', 'south', 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>location,id=>tt_location_{$device['location_id']},location_id=>{$device['location_id']}\\');' );" >{$location['reference']}</span> </td> <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_host_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('host_modify')) { $html .= <<<EOL <a title="Edit host" class="act" onClick="xajax_window_submit('edit_host', xajax.getFormValues('{$form['form_id']}_list_host_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> EOL; } if (auth('host_del')) { $html .= <<<EOL <a title="Delete host" class="act" onClick="xajax_window_submit('edit_host', xajax.getFormValues('{$form['form_id']}_list_host_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } if ($count == 0 and $form['subnet_id'] and !$form['filter']) { $html .= <<<EOL <tr><td colspan="99" align="center" style="color: red;">Please add the gateway host (router) to this subnet</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_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); // Load an existing host record (and associated info) if $form is a host_id if ($form['id']) { list($status, $rows, $failovergroup) = ona_get_dhcp_failover_group_record(array('id' => $form['id'])); if (!$rows) { $self['error'] = "ERROR => Unable to find the DHCP failover record using {$form['id']}!"; return array(4, $self['error'] . "\n"); } list($status, $rows, $pri_server) = ona_find_host($failovergroup['primary_server_id']); list($status, $rows, $sec_server) = ona_find_host($failovergroup['secondary_server_id']); $failovergroup['pri_server_name'] = $pri_server['fqdn']; $failovergroup['sec_server_name'] = $sec_server['fqdn']; // Set the window title: $window['title'] = "Edit DHCP Failover Group"; } else { // Set up default failover information $failovergroup['max_response_delay'] = '60'; $failovergroup['max_unacked_updates'] = '10'; $failovergroup['max_load_balance'] = '3'; $failovergroup['primary_port'] = '647'; $failovergroup['peer_port'] = '847'; $failovergroup['mclt'] = '1800'; $failovergroup['split'] = '255'; // Set the window title: $window['title'] = "Add DHCP Failover Group"; } // Escape data for display in html foreach (array_keys((array) $failovergroup) as $key) { $failovergroup[$key] = htmlentities($failovergroup[$key], ENT_QUOTES, $conf['php_charset']); } // 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('failover_pri_hostname', 'suggest_failover_pri_hostname'); suggest_setup('failover_sec_hostname', 'suggest_failover_sec_hostname'); el('{$window_name}_edit_form').onsubmit = function() { return false; }; EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- DHCP Failover Group Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="id" value="{$failovergroup['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 FAILOVER GROUP RECORD --> <tr> <td align="left" nowrap="true"><b><u>DHCP Failover Group Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Primary Server </td> <td class="padding" align="left" width="100%"> <input id="failover_pri_hostname" name="pri_server" alt="Primary Server" value="{$failovergroup['pri_server_name']}" class="edit" type="text" size="30" maxlength="255" > <div id="suggest_failover_pri_hostname" class="suggest"></div> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Secondary Server </td> <td class="padding" align="left" width="100%"> <input id="failover_sec_hostname" name="sec_server" alt="Secondary Server" value="{$failovergroup['sec_server_name']}" class="edit" type="text" size="30" maxlength="255" > <div id="suggest_failover_sec_hostname" class="suggest"></div> </td> </tr> <tr> <td align="right" nowrap="true"> Max Response Delay </td> <td class="padding" align="left" width="100%"> <input name="response_delay" alt="Max Response Delay" value="{$failovergroup['max_response_delay']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Max Unacked Updates </td> <td class="padding" align="left" width="100%"> <input name="unacked_updates" alt="Max Unacked Updates" value="{$failovergroup['max_unacked_updates']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Max Load Balance </td> <td class="padding" align="left" width="100%"> <input name="max_balance" alt="Load Balance" value="{$failovergroup['max_load_balance']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Primary Port Num </td> <td class="padding" align="left" width="100%"> <input name="priport" alt="Primary Port Num" value="{$failovergroup['primary_port']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Peer Port Num </td> <td class="padding" align="left" width="100%"> <input name="peerport" alt="Peer Port Num" value="{$failovergroup['peer_port']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> MCLT </td> <td class="padding" align="left" width="100%"> <input name="mclt" alt="MCLT" value="{$failovergroup['mclt']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Split </td> <td class="padding" align="left" width="100%"> <input name="split" alt="split" value="{$failovergroup['split']}" class="edit" type="text" size="10" maxlength="10" > </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}_edit_form'), 'save');" > </td> </tr> </table> </form> EOL; return window_open($window_name, $window); }
FROM dhcp_failover_groups WHERE id IN (SELECT dhcp_failover_group_id FROM dhcp_pools WHERE subnet_id = ' . $record['id'] . ') UNION SELECT secondary_server_id FROM dhcp_failover_groups WHERE id IN (SELECT dhcp_failover_group_id FROM dhcp_pools WHERE subnet_id = ' . $record['id'] . '))'); if ($rows) { $modbodyhtml .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> EOL; foreach ($dhcpservers as $dhcphost) { list($status, $rows, $host) = ona_find_host($dhcphost['id']); list($dhcpsubnetstatus, $dhcpsubnetrows, $dhcpserver) = ona_get_dhcp_server_subnet_record(array('subnet_id' => $record['id'], 'host_id' => $host['id'])); $host['fqdn'] = htmlentities($host['fqdn'], ENT_QUOTES); $modbodyhtml .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';"> <td align="left" nowrap="true"> <a title="View server. ID: {$host['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_dhcp_server\\', \\'host_id=>{$host['id']}\\', \\'display\\')');" >{$host['fqdn']}</a> </td> <td align="right" nowrap="true"> EOL; if (auth('advanced', $debug_val) && $dhcpsubnetrows == 1) { $modbodyhtml .= <<<EOL
function interface_share_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => interface_share_del({$options['ip']}) called", 3); // Version - UPDATE on every edit! $version = '1.00'; // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['host'] and $options['ip'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM interface_share_del-v{$version} Delete a shareed interface from another host. An IP address only exists once in the database. This allows you to share that IP with several other hosts which are configured to use technologies such as HSRP, CARP, VRRP etc. Synopsis: interface_share_del [KEY=VALUE] ... Required: ip=[address|ID] the IP address or ID of the interface host=[fqdn|ID] the fqdn or ID of the host EOM ); } // Find the Host they are looking for list($status, $rows, $host) = ona_find_host($options['host']); if (!$host['id']) { printmsg("DEBUG => The host specified, {$options['host']}, does not exist!", 3); $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!"; return array(2, $self['error'] . "\n"); } printmsg("DEBUG => Host selected: {$options['host']}", 3); // Find the interface list($status, $rows, $interface) = ona_find_interface($options['ip']); if (!$interface['id']) { printmsg("DEBUG => The interface specified, {$options['ip']}, does not exist!", 3); $self['error'] = "ERROR => The interface specified, {$options['ip']}, does not exist!"; return array(3, $self['error'] . "\n"); } printmsg("DEBUG => Interface selected: {$options['ip']}", 3); // Check that this interface is not associated with this host via an interface_cluster already list($status, $rows, $int_cluster) = db_get_records($onadb, 'interface_clusters', array('host_id' => $host['id'], 'interface_id' => $interface['id']), '', 0); if ($rows == 0) { printmsg("DEBUG => Unable to find share ({$host['fqdn']}-{$interface['ip_addr_text']}).", 3); $self['error'] = "ERROR => Unable to find share ({$host['fqdn']}-{$interface['ip_addr_text']})."; return array(13, $self['error'] . "\n"); } // Drop the record list($status, $rows) = db_delete_records($onadb, 'interface_clusters', array('host_id' => $host['id'], 'interface_id' => $interface['id'])); if ($status or !$rows) { $self['error'] = "ERROR => interface_share_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(5, $self['error']); } // Return the success notice $self['error'] = "INFO => Interface Share deleted: {$interface['ip_addr_text']} from {$host['fqdn']}."; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); }
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['subnet_id']) { $form['subnet'] = $form['subnet_id']; } // if it is a new pool, setup some things if (!$form['id']) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet'])); // set start and end IP to subnet IP $pool['start_ip'] = $pool['end_ip'] = ip_mangle($subnet['ip_addr'], 'dotted'); // setup defaults for form values-- FIXME use $conf['dhcp_pool'] stuff later $pool['lease_length'] = '604800'; $pool['lease_grace_period'] = '0'; $pool['lease_rebind_time'] = '0'; $pool['lease_renewal_time'] = '0'; $pool['server_name_text'] = 'None'; $window['title'] = "Add DHCP Pool"; } else { list($status, $rows, $pool) = ona_get_dhcp_pool_record(array('id' => $form['id'])); $pool['start_ip'] = ip_mangle($pool['ip_addr_start']); $pool['end_ip'] = ip_mangle($pool['ip_addr_end']); $pool['server_name_text'] = 'None'; // Load the subnet record and associated info. if (is_numeric($form['subnet'])) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet'])); } // Load the server record and associated info. if ($pool['dhcp_failover_group_id'] >= 1) { list($status, $rows, $failover) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'])); list($status, $rows, $fail_host1) = ona_find_host($failover['primary_server_id']); list($status, $rows, $fail_host2) = ona_find_host($failover['secondary_server_id']); $pool['server_name_text'] = $fail_host1['fqdn'] . "/" . $fail_host2['fqdn']; } $window['title'] = "Edit DHCP Pool"; } // 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) $failover) as $key) { $failover[$key] = htmlentities($failover[$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']); } // 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; }; /* Setup the Quick Find pool server icon */ var _button = el('qf_pool_server_{$window_name}'); _button.style.cursor = 'pointer'; _button.onclick = function(ev) { if (!ev) ev = event; /* Create the popup div */ wwTT(this, ev, 'id', 'tt_qf_pool_server_{$window_name}', 'type', 'static', 'direction', 'south', 'delay', 0, 'styleClass', 'wwTT_qf', 'javascript', "xajax_window_submit('tooltips', '" + "tooltip=>qf_pool_server," + "id=>tt_qf_pool_server_{$window_name}," + "text_id=>pool_server_text_{$window_name}," + "server=>set_pool_server_{$window_name}," + "server_name=>{$pool['server_name_text']}," + "failover_group_id=>{$pool['dhcp_failover_group_id']}," + "failover_group=>set_failover_group_{$window_name}');" ); }; EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- DHCP pool Edit Form --> <form id="{$window_name}_form" onSubmit="return false;"> <input type="hidden" name="id" value="{$pool['id']}"> <input type="hidden" name="subnet_id" value="{$form['subnet']}"> <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 POOL RECORD --> <tr> <td align="left" nowrap="true"><b><u>DHCP Pool</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%"> {$subnet['name']} </td> </tr> <tr> <td align="right" nowrap="true"> Failover Group </td> <td class="padding" align="left" width="100%" nowrap="true"> <input type="hidden" id="set_failover_group_{$window_name}" name="failover_group" value="{$pool['dhcp_failover_group_id']}"> <span id="qf_pool_server_{$window_name}" title="DHCP Pool Server Quick Select"> <a id="pool_server_text_{$window_name}" class="nav" >{$pool['server_name_text']}</a> <img src="{$images}/silk/find.png" border="0" /></span> </td> </tr> <!-- TODO: add a qf for IP addresses to list avail ips on subnet --> <tr> <td class="input_required" align="right" nowrap="true"> IP Start </td> <td class="padding" align="left" width="100%"> <input name="start" alt="IP Start" value="{$pool['start_ip']}" class="edit" type="text" size="25" maxlength="255" > </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> IP End </td> <td class="padding" align="left" width="100%"> <input name="end" alt="IP End" value="{$pool['end_ip']}" class="edit" type="text" size="25" maxlength="255" > </td> </tr> <tr> <td align="right" nowrap="true"> Lease Length </td> <td class="padding" align="left" width="100%"> <input name="llength" alt="Lease Length" value="{$pool['lease_length']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Lease Grace </td> <td class="padding" align="left" width="100%"> <input name="lgrace" alt="Lease Grace" value="{$pool['lease_grace_period']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Lease Renewal </td> <td class="padding" align="left" width="100%"> <input name="lrenewal" alt="Lease Renewal" value="{$pool['lease_renewal_time']}" class="edit" type="text" size="10" maxlength="10" > </td> </tr> <tr> <td align="right" nowrap="true"> Lease Rebind </td> <td class="padding" align="left" width="100%"> <input name="lrebind" alt="Lease Rebind" value="{$pool['lease_rebind_time']}" class="edit" type="text" size="10" maxlength="10" > </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 ws_delete_configs($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the host record list($status, $rows, $host) = ona_find_host($form['host_id']); if (!$host['id']) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Host doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Check permissions if (!(auth('host_config_admin') and authlvl($host['lvl']))) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Load the config type list($status, $rows, $type) = ona_get_config_type_record(array('id' => $form['type_id'])); if ($status or !$rows) { $response = new xajaxResponse(); $response->addScript("alert('ERROR => Invalid config type!');"); return $response->getXML(); } // Delete the config text records that match // FIXME, this should probably use a module, but there isn't one! list($status, $rows) = db_delete_records($onadb, 'configurations', array('host_id' => $host['id'], 'configuration_type_id' => $type['id'])); if ($status or !$rows) { $response = new xajaxResponse(); $response->addScript("alert('Delete failed!');"); return $response->getXML(); } // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); if ($form['js']) { $response->addScript($form['js']); } return $response->getXML(); }
function dhcp_entry_display($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => dhcp_entry_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['server'] and !$options['subnet']) { // 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_entry_display-v{$version} Displays an dhcp_entry record from the database Synopsis: dhcp_entry_display [KEY=VALUE] ... Required: host=NAME[.DOMAIN] or id hostname or id of the host to display OR subnet=NAME or id description or id of the subnet to display OR server=NAME[.DOMAIN] or id hostname or id of the server to display Notes: * DOMAIN will default to {$conf['dns_defaultdomain']} if not specified EOM ); } if ($options['host']) { // Determine the host is valid list($status, $rows, $host) = ona_find_host($options['host']); if (!$host['id']) { printmsg("DEBUG => The host specified, {$options['host']}, does not exist!", 3); $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!"; return array(2, $self['error'] . "\n"); } $anchor = 'host'; $desc = $host['FQDN']; $where = array('HOST_id' => $host['id']); } elseif ($options['subnet']) { // Determine the subnet is valid list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); if (!$subnet['id']) { printmsg("DEBUG => The subnet specified, {$options['subnet']}, does not exist!", 3); $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!"; return array(3, $self['error'] . "\n"); } $anchor = 'subnet'; $desc = "{$subnet['DESCRIPTION']} (" . ip_mangle($subnet['IP_ADDRESS']) . ")"; $where = array('NETWORK_id' => $subnet['id']); } elseif ($options['server']) { // Determine the server is valid list($status, $rows, $host) = ona_find_host($options['server']); if (!$host['id']) { printmsg("DEBUG => The server specified, {$options['server']}, does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!"; return array(4, $self['error'] . "\n"); } // Determine the host that was found is actually a server list($status, $rows, $server) = ona_get_server_record(array('HOST_id' => $host['id'])); if (!$server['id']) { printmsg("DEBUG => The host specified, {$host['FQDN']}, is not a server!", 3); $self['error'] = "ERROR => The host specified, {$host['FQDN']}, is not a server!"; return array(5, $self['error'] . "\n"); } $anchor = 'server'; $desc = $host['FQDN']; $where = array('SERVER_id' => $server['id']); } // Debugging printmsg("DEBUG => dhcp_entry_display(): Found {$anchor}: {$desc}", 3); // Build text to return $text = strtoupper($anchor) . " RECORD ({$desc})\n"; // Display the record(s) $i = 0; do { list($status, $rows, $entry) = ona_get_dhcp_entry_record($where); if ($rows == 0) { $text .= "\nNO ASSOCIATED DHCP ENTRY RECORDS\n"; break; } $i++; $text .= "\nASSOCIATED DHCP ENTRY RECORD ({$i} of {$rows})\n"; $text .= format_array($entry); } while ($i < $rows); // Return the success notice return array(0, $text); }
function ws_display_list($window_name, $form) { global $conf, $self, $onadb; global $font_family, $color, $style, $images; // Check permissions if (!auth('advanced')) { $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); // Build js to refresh this list $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');"; // Find out what page we're on $page = 1; if ($form['page'] and is_numeric($form['page'])) { $page = $form['page']; } $html = <<<EOL <!-- Results Table --> <table cellspacing="0" border="0" cellpadding="0" width="100%" class="list-box"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">Primary server</td> <td class="list-header" align="center" style="{$style['borderR']};">Secondary server</td> <td class="list-header" align="center"> </td> </tr> EOL; // Filter currently broken.. need host-> server lookup code here $where = 'id > 0'; if (is_array($form) and $form['filter']) { $where = 'primary_server_id LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } // Offset for SQL query $offset = $conf['search_results_per_page'] * ($page - 1); if ($offset == 0) { $offset = -1; } // Get list of elements list($status, $rows, $records) = db_get_records($onadb, 'dhcp_failover_groups', $where, '', $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); } else { if ($rows >= $conf['search_results_per_page']) { list($status, $rows, $tmp) = db_get_records($onadb, 'dhcp_failover_groups', $where, '', 0); } } $count = $rows; // Loop through and display the users foreach ($records as $record) { list($status, $rows, $pri_server) = ona_find_host($record['primary_server_id']); list($status, $rows, $sec_server) = ona_find_host($record['secondary_server_id']); $record['pri_server_name'] = $pri_server['fqdn']; $record['sec_server_name'] = $sec_server['fqdn']; // 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['pri_server_name']} </td> <td class="list-row"> {$record['sec_server_name']} </td> <td align="right" class="list-row" nowrap="true"> <form id="{$form['form_id']}_list_failover_{$record['id']}"> <input type="hidden" name="id" value="{$record['id']}"> <input type="hidden" name="js" value="{$refresh}"> </form> <a title="Edit failover group. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_dhcp_failover_group', xajax.getFormValues('{$form['form_id']}_list_failover_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> <a title="Delete failover group: ID: {$record['id']}" class="act" onClick="var doit=confirm('Are you sure you want to delete this failover group?'); if (doit == true) xajax_window_submit('edit_dhcp_failover_group', xajax.getFormValues('{$form['form_id']}_list_failover_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> </td> </tr> EOL; } $html .= <<<EOL </table> <!-- Add a new record --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}; border-bottom: 1px solid {$color['border']};"> <form id="{$form['form_id']}_add_failover_{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <!-- EDIT LINK --> <a title="New failover group" class="act" onClick="xajax_window_submit('edit_dhcp_failover_group', xajax.getFormValues('{$form['form_id']}_add_failover_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="New failover group" class="act" onClick="xajax_window_submit('edit_dhcp_failover_group', xajax.getFormValues('{$form['form_id']}_add_failover_{$record['id']}'), 'editor');" >Add DHCP failover group</a> </div> 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 table into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("{$form['form_id']}_dhcp_failover_count", "innerHTML", "({$count})"); $response->addAssign("{$form['content_id']}", "innerHTML", $html); // $response->addScript($js); return $response->getXML(); }
function build_bind_conf($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.51'; printmsg("DEBUG => build_bind_conf({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['server'] and $options['path'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOF build_bind_conf-v{$version} Builds a named.conf for a dns server from the database (bind 8+) Synopsis: build_bind_conf [KEY=VALUE] ... Required: server=NAME[.DOMAIN] or ID Build conf by server name or ID path=STRING Absolute prefix path for local zone files Notes: * Specified host must be a valid DNS server * Paths are absolute but MUST NOT contain a leading /, this will be added. EOF ); } // NOTE: the whole path absolute thing with no leading slash is confusing I know // the problem here is that DCM.pl tries to load the contents of the path you pass in // as a file and will always return blank for path. this is a work around for now // until dcm gets fixed. Maybe fix it by checking if it is a DIR or a FILE. // Determine the hostname and domain to be used -- // i.e. add the default domain, or find the part of the host provided // that will be used as the "zone" or "domain". This means testing many // zone name's against the DB to see what's valid. list($status, $rows, $shost) = ona_find_host($options['server']); printmsg("DEBUG => build_bind_conf() server record: {$domain['server']}", 3); if (!$shost['id']) { printmsg("DEBUG => Unknown server record: {$options['server']}", 3); $self['error'] = "ERROR => Unknown server record: {$options['server']}"; return array(3, $self['error'] . "\n"); } // For the given server id. find all domains for that server list($status, $rows, $records) = db_get_records($onadb, 'dns_server_domains', array('host_id' => $shost['id']), ''); // Start building the named.conf - save it in $text $text = "# Named.conf file for {$shost['fqdn']} built on " . date($conf['date_format']) . "\n"; $text .= "# TOTAL DOMAINS (count={$rows})\n\n"; ////////////// Header stuff ////////////////// // Allow for a local header include.. I expect this to rarely be used // MP: it is probably best to let the user set up all their own stuff and just include the resulting config // file in whatever their own config is. SOOO no need for this // $text .= "; Allow for a local header include.. I expect this to rarely be used.\n"; // $text .= "include \"/etc/named.conf-header\";\n\n"; ////////////// End Header stuff ////////////////// foreach ($records as $sdomain) { list($status, $rows, $domain) = ona_get_domain_record(array('id' => $sdomain['domain_id'])); // what is the role for this server. switch (strtolower($sdomain['role'])) { case "forward": //TODO: fixme.. this needs IPs like slaves do.. no file $text .= "zone \"{$domain['fqdn']}\" in {\n type forward;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";}\n"; break; case "master": $text .= "zone \"{$domain['fqdn']}\" in {\n type master;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";\n};\n\n"; break; case "slave": // get the IP addresses for the master domain servers for this domain list($status, $rows, $records) = db_get_records($onadb, 'dns_server_domains', array('domain_id' => $domain['id'], 'role' => 'master'), ''); // TODO: if there are no rows then bail // TODO: look for static master list stored in DB and append it to the list. $text .= "zone \"{$domain['fqdn']}\" in {\n type slave;\n file \"/{$options['path']}/named-{$domain['fqdn']}\";\n masterfile-format text;\n"; // Print the master statement $text .= " masters { "; foreach ($records as $master) { // Lookup a bunch of crap.. this should be done better. list($status, $rows, $rec) = ona_get_host_record(array('id' => $master['host_id'])); list($status, $rows, $rec) = ona_get_dns_record(array('id' => $rec['primary_dns_id'])); list($status, $rows, $rec) = ona_get_interface_record(array('id' => $rec['interface_id'])); $text .= $rec['ip_addr_text'] . "; "; } $text .= "};\n"; $text .= "};\n\n"; break; default: $text .= "# {$domain['name']} has an invalid value for the column ROLE.\n"; break; } } // Return the config file return array(0, $text); }
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 dhcp_pool_modify($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.03'; printmsg("DEBUG => dhcp_pool_modify({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['pool'] and ($options['set_failover_group'] or $options['set_start'] or $options['set_end'] or $options['set_llength'] or $options['set_lgrace'] or $options['set_lrenewal'] or $options['set_lrebind']))) { // 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_pool_modify-v{$version} Updates a dhcp pool in the database pointing to the specified identifier Synopsis: dhcp_pool_modify [KEY=VALUE] ... Where: pool=ID Table ID for the pool Optional: set_failover_group=ID group identifier set_server=NAME[.DOMAIN] or ID server identifier set_start=IP Start ip address of pool set_end=IP End IP of pool set_llength=NUMBER Lease Time. Default ({$conf['dhcp_pool']['llength']}) set_lgrace=NUMBER Lease Grace Period. Default ({$conf['dhcp_pool']['lgrace']}) set_lrenewal=NUMBER Lease Renewal. Default ({$conf['dhcp_pool']['lrenewal']}) set_lrebind=NUMBER Lease Rebind. Default ({$conf['dhcp_pool']['lrebind']}) EOM ); } // get the existing pool to edit list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', array('id' => $options['pool'])); if (!$rows) { printmsg("DEBUG => Unable to find the DHCP pool record using id: {$options['id']}!", 3); $self['error'] = "ERROR => Unable to find a pool using id: {$options['pool']}"; return array(1, $self['error'] . "\n"); } // set the pool id in the set variable $SET['id'] = $pool['id']; // NOTE: currently modify pool does not allow you to change subnets // Get subnet info.. list($status, $rows, $subnet) = ona_find_subnet($pool['subnet_id']); $SET['subnet_id'] = $subnet['id']; // make sure that the start address is actually part of an existing subnet if ($options['set_start']) { list($status, $rows, $subnetstart) = ona_find_subnet(ip_mangle($options['set_start'], 'dotted')); if (!$rows) { printmsg("DEBUG => Unable to find a subnet related to starting address ({$options['set_start']})!", 3); $self['error'] = "ERROR => Unable to find a subnet related to your starting address of {$options['set_start']}."; return array(1, $self['error'] . "\n"); } if ($subnetstart['id'] != $pool['subnet_id']) { printmsg("DEBUG => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3); $self['error'] = "ERROR => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!"; return array(1, $self['error'] . "\n"); } } // make sure that the end address is actually part of an existing subnet if ($options['set_end']) { list($status, $rows, $subnetend) = ona_find_subnet(ip_mangle($options['set_end'], 'dotted')); if (!$rows) { printmsg("DEBUG => Unable to find a subnet related to ending address ({$options['set_end']})!", 3); $self['error'] = "ERROR => Unable to find a subnet related to your ending address of {$options['set_end']}."; return array(1, $self['error'] . "\n"); } if ($subnetend['id'] != $pool['subnet_id']) { printmsg("DEBUG => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3); $self['error'] = "ERROR => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!"; return array(1, $self['error'] . "\n"); } } // Assign which failover group to use if ($options['set_failover_group'] == 0) { $desc = 'Not using a failover group'; $SET['dhcp_failover_group_id'] = 0; } else { list($status, $rows, $fg) = ona_get_dhcp_failover_group_record(array('id' => $options['set_failover_group'])); if (!$fg['id']) { printmsg("DEBUG => The failover_group specified ({$options['set_failover_group']}) does not exist", 3); $self['error'] = "ERROR => The failover_group specified ({$options['set_failover_group']}) does not exist!"; return array(4, $self['error'] . "\n"); } // get the server names for the two servers list($fail_host1, $fail_zone1) = ona_find_host($fg['primary_server_id']); list($fail_host2, $fail_zone2) = ona_find_host($fg['secondary_server_id']); $desc = $fail_host1['fqdn'] . '/' . $fail_host2['fqdn']; $SET['dhcp_failover_group_id'] = $fg['id']; } // check that start and end are not the same //if ($options['set_start'] and $options['set_end'] and $options['set_start'] == $options['set_end']) { // printmsg("DEBUG => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!",3); // $self['error'] = "ERROR => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!"; // return(array(2, $self['error'] . "\n")); //} if ($options['set_start']) { $start_dec = ip_mangle($options['set_start'], 'numeric'); } else { $start_dec = $pool['ip_addr_start']; } if ($options['set_end']) { $end_dec = ip_mangle($options['set_end'], 'numeric'); } else { $end_dec = $pool['ip_addr_end']; } $net_end = 4294967295 - $subnet['ip_mask'] + $subnet['ip_addr']; // Validate that the IP address supplied isn't the base or broadcast of the subnet if ($start_dec == $subnet['ip_addr'] or $end_dec == $subnet['ip_addr']) { printmsg("DEBUG => IP address can't be a subnet's base address (" . ip_mangle($subnet['ip_addr'], 'dotted') . ")!", 3); $self['error'] = "ERROR => IP address can't be a subnet's base address (" . ip_mangle($subnet['ip_addr'], 'dotted') . ")!"; return array(7, $self['error'] . "\n"); } if ($start_dec == $net_end or $end_dec == $net_end) { printmsg("DEBUG => IP address can't be a subnet's broadcast address (" . ip_mangle($net_end, 'dotted') . ")!", 3); $self['error'] = "ERROR => IP address can't be the subnet broadcast address(" . ip_mangle($net_end, 'dotted') . ")!"; return array(8, $self['error'] . "\n"); } // check that start is not after the end if ($start_dec > $end_dec) { printmsg("DEBUG => The start IP addresses (" . ip_mangle($start_dec, 'dotted') . ") falls after the end IP address (" . ip_mangle($end_dec, 'dotted') . ")!", 3); $self['error'] = "ERROR => The start IP addresses (" . ip_mangle($start_dec, 'dotted') . ") falls after the end IP address(" . ip_mangle($end_dec, 'dotted') . ")!"; return array(2, $self['error'] . "\n"); } // check for existing hosts inside the pool range list($status, $rows, $interface) = db_get_records($onadb, 'interfaces', 'subnet_id = ' . $subnet['id'] . ' AND ip_addr BETWEEN ' . $start_dec . ' AND ' . $end_dec, '', 0); if ($rows) { printmsg("DEBUG => IP conflict: Specified range (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") encompasses {$rows} host(s)!", 3); $self['error'] = "ERROR => IP conflict: Specified range (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") encompasses {$rows} host(s)"; return array(4, $self['error'] . "\n"); } // *** Check to see if the new pool overlaps any existing pools *** // // Look for overlaps like this (where new pool address starts inside an existing pool): // [ -- new pool -- ] // [ -- old pool --] list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND ' . $start_dec . ' BETWEEN ip_addr_start AND ip_addr_end'); if ($rows != 0) { printmsg("DEBUG => Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") starts inside an existing pool!", 3); $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") starts inside an existing pool."; return array(5, $self['error'] . "\n" . "INFO => Conflicting pool record ID: {$tmp['id']}\n"); } // Look for overlaps like this (where the new pool ends inside an existing pool): // [ -- new pool -- ] // [ -- old pool --] list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND ' . $end_dec . ' BETWEEN ip_addr_start AND ip_addr_end'); if ($rows != 0) { printmsg("DEBUG => Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") ends inside an existing pool!", 3); $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") ends inside an existing pool."; return array(6, $self['error'] . "\n" . "INFO => Conflicting pool record ID: {$tmp['id']}\n"); } // Look for overlaps like this (where the new pool entirely overlaps an existing pool): // [ -------- new pool --------- ] // [ -- old pool --] list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND (ip_addr_start BETWEEN ' . $start_dec . ' AND ' . $end_dec . ' OR ip_addr_end BETWEEN ' . $start_dec . ' AND ' . $end_dec . ')'); if ($rows != 0) { printmsg("DEBUG => Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") would encompass an existing pool!", 3); $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") would encompass an existing pool."; return array(7, $self['error'] . "\n" . "INFO => Conflicting pool record ID: {$tmp['id']}\n"); } // Check permissions if (!auth('advanced') or !authlvl($subnet['lvl'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(8, $self['error'] . "\n"); } // define the remaining entries if (array_key_exists('set_lgrace', $options)) { $SET['lease_grace_period'] = $options['set_lgrace']; } if (array_key_exists('set_llength', $options)) { $SET['lease_length'] = $options['set_llength']; } if (array_key_exists('set_lrenewal', $options)) { $SET['lease_renewal_time'] = $options['set_lrenewal']; } if (array_key_exists('set_lrebind', $options)) { $SET['lease_rebind_time'] = $options['set_lrebind']; } // Set the IPs if you got this far $SET['ip_addr_start'] = $start_dec; $SET['ip_addr_end'] = $end_dec; // Get the DHCP pool record before updating (logging) list($status, $rows, $original_pool) = ona_get_dhcp_pool_record(array('id' => $SET['id'])); // Update the record list($status, $rows) = db_update_record($onadb, 'dhcp_pools', array('id' => $SET['id']), $SET); if ($status or !$rows) { $self['error'] = "ERROR => dhcp_pool_modify() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(6, $add_to_error . $self['error'] . "\n"); } $success_start = ip_mangle($SET['ip_addr_start'], 'dotted'); $success_end = ip_mangle($SET['ip_addr_end'], 'dotted'); // Get the DHCP pool record after updating (logging) list($status, $rows, $new_pool) = ona_get_dhcp_pool_record(array('id' => $SET['id'])); // Return the success notice $self['error'] = "INFO => DHCP pool UPDATED:{$original_pool['id']}: {$success_start}-{$success_end} on {$subnet['name']}."; $log_msg = "INFO => DHCP pool UPDATED:{$original_pool['id']}: "; $more = ""; foreach (array_keys($original_pool) as $key) { if ($original_pool[$key] != $new_pool[$key]) { $log_msg .= $more . $key . "[" . $original_pool[$key] . "=>" . $new_pool[$key] . "]"; $more = ";"; } } // only print to logfile if a change has been made to the record if ($more != '') { printmsg($self['error'], 0); printmsg($log_msg, 0); } return array(0, $add_to_error . $self['error'] . "\n"); }
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, $interface; $window = array(); // Check permissions if (!auth('interface_modify')) { $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 alias record ID- so we transform $form into an array if (is_numeric($form)) { $form = array('interface_id' => $form); } // Load an existing record (and associated info) if we're editing if (is_numeric($form['interface_id'])) { list($status, $rows, $interface) = ona_get_interface_record(array('id' => $form['interface_id'])); if ($rows) { list($status, $rows, $host) = ona_find_host($interface['host_id']); list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); list($status, $rows_nat, $extnatint) = ona_get_interface_record(array('id' => $record['nat_interface_id'])); $interface['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted'); if ($interface['mac_addr']) { $interface['mac_addr'] = mac_mangle($interface['mac_addr']); } if ($rows_nat > 0) { $interface['natip_addr'] = ip_mangle($extnatint['ip_addr'], 'dotted'); } } } else { // Maybe we didn't get an interface record, but we got a host record (adding an interface) // Set it in $interface so it's available below. if (is_numeric($form['host_id'])) { $interface['host_id'] = $form['host_id']; } if (is_numeric($form['subnet_id'])) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id'])); } // allow various default items to be set during an add that are passed in from the form if (isset($form['ip_addr'])) { $interface['ip_addr'] = $form['ip_addr']; } if (isset($form['name'])) { $interface['name'] = $form['name']; } if (isset($form['description'])) { $interface['description'] = $form['description']; } if (isset($form['mac_addr'])) { $interface['mac_addr'] = $form['mac_addr']; } if (isset($form['natip_addr'])) { $interface['natip_addr'] = $form['natip_addr']; } } // Load the host record for display if ($interface['host_id']) { list($status, $rows, $host) = ona_find_host($interface['host_id']); } //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 ($dns_record['id'] and $entry['id'] == $dns_record['dns_view_id']) { $selected = "SELECTED=\"selected\""; } elseif (!$dns_record['id'] and $entry['id'] == 0) { // Otherwise use the default record if we are adding a new entry $selected = "SELECTED=\"selected\""; } $dns_view_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['name']}</option>\n"; } } // Escape data for display in html foreach (array_keys((array) $interface) as $key) { $interface[$key] = htmlentities($interface[$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) $host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Add Interface"; if ($interface['id']) { $window['title'] = "Edit Interface"; } // 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; /* Setup the Quick Find FREE IP icon */ 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}');" ); }; suggest_setup('hostname', 'suggest_int_hostname'); el('hostname').focus(); EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- Interface Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="interface_id" value="{$interface['id']}"> EOL; if ($host['fqdn']) { $window['html'] .= <<<EOL <input type="hidden" name="host" value="{$interface['host_id']}"> <input type="hidden" name="hostfqdn" value="{$host['fqdn']}"> EOL; } $window['html'] .= <<<EOL <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;"> <!-- INTERFACE RECORD --> <tr> <td align="left" nowrap="true"><b><u>Interface Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> EOL; if ($host['fqdn']) { $window['html'] .= <<<EOL <td align="right" nowrap="true"> Host: </td> <td class="padding" align="left" width="100%"> {$host['fqdn']} </td> EOL; } else { $window['html'] .= <<<EOL <td class="input_required" align="right" nowrap="true"> Existing Host </td> <td class="padding" align="left" width="100%"> <input id="hostname" name="host" alt="Hostname" value="{$host['name']}" class="edit" type="text" size="20" maxlength="64" > <div id="suggest_int_hostname" class="suggest"></div> </td> EOL; } $window['html'] .= <<<EOL </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%" nowrap="true"> <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 id="set_mac" 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 nowrap 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; // Show a "keep adding" checkbox if they are adding records if (!isset($interface['id'])) { // Print a dns view selector if ($conf['dns_views']) { $window['html'] .= <<<EOL <tr> <td align="right" nowrap="true"> DNS View for PTR </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 <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 nowrap class="padding" align="left" width="100%"> <input name="keepadding" alt="Keep adding more interfaces" type="checkbox" > Keep adding more interfaces </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 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 ws_display($window_name, $form = '') { global $conf, $self, $onadb, $base; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the host record if ($form['host_id']) { list($status, $rows, $record) = ona_get_host_record(array('id' => $form['host_id'])); } else { if ($form['host']) { list($status, $rows, $record) = ona_find_host($form['host']); } } if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Host doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Update History Title (and tell the browser to re-draw the history div) $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = $record['name']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; // FIXME: umm.. put this somewhere else if (!$record['name']) { $record['name'] = "NONE SET"; } // Interface (and find out how many there are) list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id']), ''); $record['ip_address'] = ip_mangle($interface['ip_addr'], 'dotted'); $interface_style = ''; if ($interfaces > 1) { $interface_style = 'font-weight: bold;'; } // Subnet description list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id'])); $record['subnet'] = $subnet['name']; $record['subnet_id'] = $subnet['id']; $record['ip_subnet_mask'] = ip_mangle($subnet['ip_mask'], 'dotted'); $record['ip_subnet_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr'); // Device Description list($status, $rows, $device) = ona_get_device_record(array('id' => $record['device_id'])); $record['device_type_id'] = $device['device_type_id']; list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id'])); list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $record['devicefull'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})"; $record['device'] = str_replace('Unknown', '?', $record['devicefull']); $record['location_id'] = $device['location_id']; // Device serial number and/or asset tag $record['serial_number'] = $device['serial_number']; $record['asset_tag'] = $device['asset_tag']; // Get location_number from the location_id list($status, $rows, $location) = ona_get_location_record(array('id' => $record['location_id'])); // extra stuff to pass to ws_plugins $extravars['refresh'] = $refresh; $extravars['window_name'] = $window_name; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } // Create a div for workspace plugins to live $html .= "<div id='wsplugins' style='margin: 10px;'>"; // Start displaying all the ws plugins $wspl = workspace_plugin_loader('host_detail', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('host_services', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('custom_attributes', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('config_archives', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Display the host_action workspace_plugin $wspl = workspace_plugin_loader('host_actions', $record); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Display messages $wspl = workspace_plugin_loader('messages', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; $wspl = workspace_plugin_loader('reports', $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; // Get all the plugin based worspace items $wspl_list = plugin_list('wspl_item'); // Load all the dynamic plugins foreach ($wspl_list as $p) { $wspl = workspace_plugin_loader($p['path'], $record, $extravars); $html .= $wspl[0]; $js .= $wspl[1]; $wsmenu[] = $wspl[2]; } // Gather our menuitems and build the HTML $wsmenuhtml = build_workspace_menu($wsmenu); $html .= <<<EOL </div> <br style="clear:both;"> <form id="form_host_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div> EOL; // RECORD LIST $tab = 'records'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- INTERFACE LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated DNS {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="host_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" title="Filter" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Name</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('host_add', $debug_val)) { $html .= <<<EOL <!-- ADD RECORD LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_record_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Add DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" ><img src="{$images}/silk/font_add.png" border="0"></a> <a title="Add DNS record" class="act" onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');" >Add DNS record</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // INTERFACE LIST $tab = 'interfaces'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- INTERFACE LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="host_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" title="Filter" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Full IP</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('host_add', $debug_val)) { $html .= <<<EOL <!-- ADD INTERFACE LINK --> <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_interface_{$record['id']}" ><input type="hidden" name="host_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');" >Add interface</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function message_add($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; // Default expiration $exp_default = "+6 week"; $pri_default = 3; // Priority is one of the following: // 0 = Informational // 1 = red or high // 2 = yellow or medium // 3 = green or low printmsg("DEBUG => message_add({$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['subnet'] and !$options['host'] or !$options['message'] and (!$options['expiration'] and !$options['priority'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM message_add-v{$version} Adds the provided message to the host or subnet specified Synopsis: message_add Required: host=NAME[.DOMAIN]|IP hostname or IP of the host OR subnet=NAME|IP name or IP of the subnet message="STRING" the content of the message Optional: priority=NUMBER device/model type or ID (default: {$pri_default}) expiration=DATE date to expire message (default: NOW {$exp_default}s) Notes: Priority is one of the following: 0 = blue or Informational 1 = red or high 2 = yellow or medium 3 = green or low EOM ); } // If they provided a hostname / ID let's look it up if ($options['host']) { list($status, $rows, $host) = ona_find_host($options['host']); $table_name_ref = 'hosts'; $table_id_ref = $host['id']; $desc = $host['fqdn']; } else { if ($options['subnet']) { list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); $table_name_ref = 'subnets'; $table_id_ref = $subnet['id']; $desc = $subnet['name']; } } // If we didn't get a record then exit if (!$host['id'] and !$subnet['id']) { printmsg("DEBUG => No host or subnet found!", 3); $self['error'] = "ERROR => No host or subnet found!"; return array(4, $self['error'] . "\n"); } // Set the priority $priority = array_key_exists('priority', $options) ? $options['priority'] : $pri_default; if ($priority > 3 or $priority < 0 or !is_numeric($priority)) { $self['error'] = "ERROR => Priority must be a number between 0 and 3!"; return array(4, $self['error'] . "\n"); } // Get a username or "anonymous" $username = isset($_SESSION['username']) ? $_SESSION['username'] : "******"; // Expiration date format if ($options['expiration']) { $expiration = date("Y-m-d G:i:s", strtotime($options['expiration'])); } else { $expiration = date("Y-m-d G:i:s", strtotime($exp_default)); } // TODO: there should probably be some sort of security checks on the message that is passed in. // I suspect this could be a security issue. SQL injection etc. list($status, $rows) = db_insert_record($onadb, 'messages', array('table_name_ref' => $table_name_ref, 'table_id_ref' => $table_id_ref, 'priority' => $priority, 'username' => $username, 'expiration' => $expiration, 'message_text' => $options['message'])); if ($status or !$rows) { $self['error'] = "ERROR => message_add() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(6, $self['error'] . "\n"); } $text = "INFO => Message ADDED to: {$desc}\n"; // Return the message file 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('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['server']) { list($status, $rows, $host) = ona_find_host($form['server']); } if ($form['host_id']) { list($status, $rows, $host) = ona_find_host($form['host_id']); } if ($form['domain']) { list($status, $rows, $domain) = ona_find_domain($form['domain']); } // Escape data for display in html foreach (array_keys((array) $host) as $key) { $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Assign domain to server"; // 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('domain_server_name', 'suggest_domain_server_name'); suggest_setup('domain_server_edit', 'suggest_domain_server_edit'); EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- DNS server Edit Form --> <form id="{$window_name}_form" onSubmit="return false;"> <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;"> <tr> <td align="left" nowrap="true"><b><u>Assign Domain</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Server </td> <td class="padding" align="left" width="100%"> <input id="domain_server_name" name="server" alt="Server name" value="{$host['fqdn']}" class="edit" type="text" size="34" maxlength="255" > <div id="suggest_domain_server_name" class="suggest"></div> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Domain </td> <td class="padding" align="left" width="100%"> <input id="domain_server_edit" name="domain" alt="Domain name" value="{$domain['fqdn']}" class="edit" type="text" size="34" maxlength="255" > <div id="suggest_domain_server_edit" class="suggest"></div> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Role </td> <td class="padding" align="left" width="100%" nowrap="true"> <select class="edit" name="role" alt="Role"> <option value="forward">Forward</option> <option value="master" selected>Master</option> <option value="slave">Slave</option> </select> </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 ona_find_config($options = array()) { global $self; $status = 1; $rows = 0; $config = array(); // If the user specified a config text ID if ($options['config']) { if (!preg_match('/^\\d+$/', $options['config'])) { $self['error'] = "ERROR => A non-digit config ID was specified!"; return array(2, 0, array()); } list($status, $rows, $config) = ona_get_config_record(array('id' => $options['config'])); } else { if ($options['host'] and $options['type']) { // Search for the host first 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(3, 0, array()); } // Now find the ID of the config type they entered list($status, $rows, $config_type) = ona_get_config_type_record(array('name' => $options['type'])); if (!$config_type['id']) { $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!"; return array(4, 0, array()); } // Select the first config record of the specified type and host list($status, $rows, $config) = ona_get_config_record(array('host_id' => $host['id'], 'configuration_type_id' => $config_type['id'])); if ($status) { $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!"; return array(5, 0, array()); } } } // Return the config record we got return array($status, $rows, $config); }
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');"; // Search results go in here $results = array(); $count = 0; // NETWORK ID if (is_numeric($form['subnet_id'])) { } // Do the SQL Query list($status, $count, $results) = db_get_records($onadb, 'interfaces', "subnet_id = " . $onadb->qstr($form['subnet_id']), 'ip_addr', -1, -1); // make an array of ips from our results $iplist = array(); foreach ($results as $record) { $iplist["{$record['ip_addr']}"] = 'used'; } list($status, $rows, $subnet) = ona_find_subnet($form['subnet_id']); // Create a few variables that will be handy later $num_ips = 0xffffffff - $subnet['ip_mask']; $last_ip = $subnet['ip_addr'] + $num_ips - 1; $currip = $subnet['ip_addr'] + 1; // Get a list of blocks that touches this subnet list($status, $blockrows, $blocks) = db_get_records($onadb, 'blocks', "{$subnet['ip_addr']} BETWEEN ip_addr_start AND ip_addr_end OR {$last_ip} BETWEEN ip_addr_start AND ip_addr_end OR ip_addr_start BETWEEN {$subnet['ip_addr']} and {$last_ip}"); // Get a list of dhcp pools on the selected subnet list($status, $rows, $pools) = db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id'])); // Add DHCP pool addresses into the list of used ips foreach ($pools as $pool) { for ($ip = $pool['ip_addr_start']; $ip <= $pool['ip_addr_end']; $ip++) { $iplist["{$ip}"] = 'pool-' . $pool['id']; } } // // *** BUILD HTML LIST *** // $html .= <<<EOL <!-- Host Results --> <table id="{$form['form_id']}_full_host_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};" title="IP Block Association">B</td> <td class="list-header" align="center" style="{$style['borderR']};">IP Address</td> <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td> <td class="list-header" align="center" style="{$style['borderR']};">[Name] Desc</td> <td class="list-header" align="center" style="{$style['borderR']};">Host Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Device Type</td> <td class="list-header" align="center" style="{$style['borderR']};">Host Notes</td> </tr> EOL; // Loop and display each ip on the subnet while ($currip <= $last_ip) { $loc = array(); $host = array(); $interface = array(); $interfaces = 0; $record = array(); $interface_style = ''; $clusterhtml = ''; $rowstyle = 'background-color: #E9FFE1'; $rowid = 'byip_available'; $currip_txt = ip_mangle($currip, 'dotted'); $interface['desc'] = '<span style="color: #aaaaaa;">AVAILABLE</span>'; $nameval = <<<EOL <a title="Add host" class="act" onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');" ></a> <a title="Add host" class="act" onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');" >Add a new host</a> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');" ></a> <a title="Add interface" class="act" onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');" >Add interface to an existing host</a> EOL; // If the current ip is one allocated on this subnet lets do some stuff if (array_key_exists($currip, $iplist)) { $rowid = 'byip_allocated'; $rowstyle = ''; // check if it is a pool range list($pooltype, $poolid) = explode('-', $iplist[$currip]); if ($pooltype == 'pool') { $interface['desc'] = '<span style="color: #aaaaaa;">DHCP Pool</span>'; $rowstyle = 'background-color: #FFFBD6'; $nameval = <<<EOL <a title="Edit Pool" class="act" onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Edit Pool" class="act" onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');" >Edit DHCP Pool</a> EOL; } else { // Get host record list($status, $rows, $host) = ona_find_host($currip); // Get the interface info list($status, $rows, $interface) = ona_find_interface($currip); // Count how many interface rows this host hasand assign it back to the interfaces variable list($status, $interfaces, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($host['id']), "", 0); // get interface cluster info list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$interface['id']}"); if ($intclusterrows > 0) { $clusterscript = "onMouseOver=\"wwTT(this, event,\n 'id', 'tt_interface_cluster_list_{$interface['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_{$interface['id']},interface_id=>{$interface['id']}\\');'\n );\""; $clusterhtml .= <<<EOL <img src="{$images}/silk/sitemap.png" {$clusterscript} /> EOL; } // set the name value for an allocated host $nameval = <<<EOL <a title="View host. ID: {$host['id']}" class="nav" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$host['id']}\\', \\'display\\')');" >{$host['name']}</a >.<a title="View domain. ID: {$host['domain_id']}" class="domain" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$host['domain_id']}\\', \\'display\\')');" >{$host['domain_fqdn']}</a> EOL; // Make it bold if we have more than one interface on this host if ($interfaces > 1) { $interface_style = 'font-weight: bold;'; } // Device Description list($status, $rows, $device) = ona_find_device($host['device_id']); list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id'])); list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id'])); list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id'])); list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id'])); $record['device'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})"; $record['device'] = str_replace('Unknown', '?', $record['device']); $record['notes_short'] = truncate($host['notes'], 40); $interface['description_short'] = truncate($interface['description'], 40); if ($interface['name']) { $interface['name'] = "[{$interface['name']}]"; } $interface['desc'] = "{$interface['name']} {$interface['description_short']}"; // Format the date and colorize if its older than 2 months if ($interface['last_response']) { $interface['last_response'] = date($conf['date_format'], strtotime($interface['last_response'])); if (strtotime($interface['last_response']) < strtotime('-2 month')) { $interface['last_response_fmt'] = 'style=color:red;'; } } // Get location info list($status, $rows, $loc) = ona_get_location_record(array('id' => $device['location_id'])); } // end real host ifblock } // end while loop // 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 {$rowid}=true style="{$rowstyle}" onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> EOL; // Print color info for any matching blocks $c = 0; $blockcolors = array('#CD5C5C', '#588C7E', '#8C4646', '#FFD700', '#1E90F0', '#8A2BE2', '#32CD32', '#D96459'); if ($blockrows) { $html .= "<td class='list-row' nowrap style='padding:0'>"; foreach ($blocks as $block) { if ($currip >= $block['ip_addr_start'] && $currip <= $block['ip_addr_end']) { $html .= "<span title='{$block['name']}' style='background-color:{$blockcolors[$c]};padding-bottom:4px;float:left;'>  </span> "; } $c++; } } else { // print an empty table cell $html .= "<td class='list-row'>"; } $html .= <<<EOL </td> <td class="list-row" align="left"> EOL; // if it is used, show an edit interface link if ($rowid == 'byip_allocated') { $html .= <<<EOL <a class="nav" style="{$interface_style}" title="Edit interface ID: {$interface['id']}" onClick="xajax_window_submit('edit_interface', 'interface_id=>{$interface['id']}', 'editor');" EOL; if ($interfaces > 1) { $html .= <<<EOL onMouseOver="wwTT(this, event, 'id', 'tt_host_interface_list_{$host['id']}', 'type', 'velcro', 'styleClass', 'wwTT_niceTitle', 'direction', 'south', 'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>host_interface_list,id=>tt_host_interface_list_{$host['id']},host_id=>{$host['id']}\\');' );" EOL; } $html .= '>'; } //print out the IP address $html .= $currip_txt; // close the A tag if used above if ($rowid == 'byip_allocated') { $html .= '</a>'; } // Keep on goin with the rest of the line $html .= <<<EOL <span>{$clusterhtml}</span> </td> <td class="list-row" {$interface['last_response_fmt']}>{$interface['last_response']} </td> <td class="list-row"> <span title="{$interface['description']}">{$interface['desc']}</span> </td> <td class="list-row" style="border-left: 1px solid; border-left-color: #aaaaaa;"> {$nameval} </td> <td class="list-row">{$record['device']} </td> <td class="list-row"> <span title="{$host['notes']}">{$record['notes_short']}</span> </td> </tr> EOL; // increment the currip $currip++; } $html .= <<<EOL </table> EOL; $js .= <<<EOL /* Make sure this table is 100% wide */ el('{$form['form_id']}_full_host_list').style.width = el('{$form['form_id']}_table').offsetWidth + 'px'; function togglebyip(name) { tr=document.getElementsByTagName('tr') for (i=0;i<tr.length;i++){ if (tr[i].getAttribute(name)){ if (tr[i].style.display=='none'){tr[i].style.display = '';} else {tr[i].style.display = 'none';} } } } EOL; // 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(); }