function block_display($options = "") { global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => block_display({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[verbose] (default is yes) $options['verbose'] = sanitize_YN($options['verbose'], 'Y'); // Return the usage summary if we need to if ($options['help'] or !$options['block']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM block_display-v{$version} Displays a block record from the database Synopsis: block_display [KEY=VALUE] ... Required: block=NAME or ID Block name or ID of the block display Optional: verbose=[yes|no] Display additional info (DEFAULT: yes) EOM ); } // The formatting rule on block names is all upper and trim it $options['block'] = trim($options['block']); $options['block'] = preg_replace('/\\s+/', '-', $options['block']); $options['block'] = strtoupper($options['block']); // If the block provided is numeric, check to see if it's an block if (is_numeric($options['block'])) { // See if it's an block_id list($status, $rows, $block) = ona_get_block_record(array('id' => $options['block'])); if (!$block['id']) { printmsg("DEBUG => Unable to find block using the ID {$options['block']}!", 3); $self['error'] = "ERROR => Unable to find block using the ID {$options['block']}!"; return array(2, $self['error'] . "\n"); } } else { list($status, $rows, $block) = ona_get_block_record(array('name' => $options['block'])); if (!$block['id']) { $self['error'] = "ERROR => Unable to find block using the name {$options['block']}!"; printmsg("DEBUG => Unable to find block using the name {$options['block']}!", 3); return array(2, $self['error'] . "\n"); } } printmsg("DEBUG => Found block: {$block['name']}", 3); // Build text to return $text = "BLOCK RECORD\n"; $text .= format_array($block); // If 'verbose' is enabled, grab some additional info to display if ($options['verbose'] == 'Y') { $where .= " ip_addr >= " . $block['ip_addr_start'] . " AND ip_addr <= " . $block['ip_addr_end']; list($status, $netrows, $nets) = db_get_records($onadb, 'subnets', $where, "ip_addr"); // subnet record(s) $i = 0; foreach ($nets as $record) { list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $record['id'])); if ($rows == 0) { break; } $i++; $text .= "\nASSOCIATED SUBNET RECORD ({$i} of {$netrows})\n"; $text .= format_array($subnet); } } // Return the success notice return array(0, $text); }
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 host record list($status, $rows, $record) = ona_get_block_record(array('id' => $form['block_id'])); if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Block 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['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}');"; $record['ip_addr_start'] = ip_mangle($record['ip_addr_start'], 'dotted'); $record['ip_addr_end'] = ip_mangle($record['ip_addr_end'], 'dotted'); $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; // BLOCK INFORMATION $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']}"> <!-- LABEL --> <form id="form_block_{$record['id']}" ><input type="hidden" name="block_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('advanced', $debug_val)) { $html .= <<<EOL <a title="Edit block" class="act" onClick="xajax_window_submit('edit_block', xajax.getFormValues('form_block_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> <a title="Delete block" class="act" onClick="var doit=confirm('Are you sure you want to delete this block?'); if (doit == true) xajax_window_submit('edit_block', xajax.getFormValues('form_block_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL {$record['name']} <a href="?work_space={$window_name}&block_id={$record['id']}"><img title="Direct link to {$record['name']}" src="{$images}/silk/application_link.png" border="0"></a> </td> </tr> <tr> <td align="right" nowrap="true"><b>Name</b> </td> <td class="padding" align="left">{$record['name']} </td> </tr> <tr> <td align="right" nowrap="true"><b>IP start</b> </td> <td class="padding" align="left"> {$record['ip_addr_start']} </td> </tr> <tr> <td align="right" nowrap="true"><b>IP end</b> </td> <td class="padding" align="left"> {$record['ip_addr_end']} </td> </tr> <tr> <td align="right" nowrap="true"><b>Notes</b> </td> <td class="padding" align="left"> {$record['notes']} </td> </tr> </table> EOL; // END BLOCK 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; // SMALL SUBNET MAP // Get the numeric IP address of our subnet (we replace the last quad with a .0) $ip_subnet = ip_mangle($record['ip_addr_start'], 'numeric'); if (is_ipv4($ip_subnet)) { $end = '\\.\\d+$'; $replace_end_by = '.0'; $version = 4; } else { $end = ':[0-9A-F]{0,4}$'; // $replace_end_by = ':0000'; $replace_end_by = ':'; $version = 6; } $ip = ip_mangle(preg_replace("/{$end}/", $replace_end_by, $record['ip_addr_start']), 'numeric'); $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <tr><td colspan="99" nowrap="true"> <!-- LABEL --> <div style="{$style['label_box']}"> <a title="Display full sized subnet map" class="act" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr_start']},ip_block_end=>{$record['ip_addr_end']},id=>{$record['id']}\\', \\'display\\');');" ><img src="{$images}/silk/shape_align_left.png" border="0"></a> <a title="Highlight start of block" class="act" onClick=" var _el = el('{$ip_subnet}_row_label'); if (_el) { if (_el.style.isHighlighted) { _el.style.backgroundColor = '#000000'; _el.style.isHighlighted = false; } else { _el.style.backgroundColor = '{$color['bgcolor_map_selected']}'; _el.style.isHighlighted = true; } } " ><img src="{$images}/silk/paintbrush.png" border="0"></a> <b>Block Map</b> </div> </td></tr> <tr><td colspan="99" nowrap="true"> <input type="hidden" id="{$window_name}_zoom" name="zoom" value="7"> <div id="{$window_name}_portal" style="position: relative; height: 150px; width: 355px;"> <span id="{$window_name}_substrate"></span> </div> </td></tr> </table> EOL; // Get javascript to setup the map portal mouse handlers // Force ip end to be less than ip start to prevent Block highlighting $portal_js .= get_portal_js($window_name, $ip, $version); //*** Send a fake mouseup event to draw the initial map view *** $portal_js .= "el('{$window_name}_portal').myonmouseup('fake event');"; // END SMALL SUBNET MAP $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THIRD COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <!-- END OF TOP SECTION --> EOL; // SUBNET LIST $tab = 'subnets'; $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"> 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="ip_subnet" value="{$record['ip_addr_start']}" type="hidden"> <input name="ip_subnet_thru" value="{$record['ip_addr_end']}" 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> </div> EOL; $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(); // GDO need to use Big Int JS $response->addIncludeScript('include/js/bignumber.js'); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js . $portal_js); } return $response->getXML(); }
function ws_display_list($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Find the "tab" we're on $tab = $_SESSION['ona'][$form['form_id']]['tab']; // Build js to refresh this list $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');"; // If it's not a new query, load the previous query from the session // into $form and save the current page and filter in the session. // Also find/set the "page" we're viewing $page = 1; if ($form['page'] and is_numeric($form['page'])) { $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']); $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page']; $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter']; } // Calculate the SQL query offset (based on the page being displayed) $offset = $conf['search_results_per_page'] * ($page - 1); if ($offset == 0) { $offset = -1; } // Search results go in here $results = array(); $count = 0; // Start building the "where" clause for the sql query to find the blocks to display $where = ""; $and = ""; // DISPLAY ALL BLOCKS if ($form['all_flag']) { $where .= $and . "id > 0"; $and = " AND "; } // BLOCK ID if ($form['id']) { $where .= $and . "id = " . $onadb->qstr($form['id']); $and = " AND "; } // BLOCK , assume a block descripton if ($form['blockname']) { $where .= $and . "name LIKE " . $onadb->qstr('%' . strtoupper($form['blockname']) . '%'); $and = " AND "; } // display a nice message when we dont find all the records if ($where == '' and $form['content_id'] == 'search_results_list') { $js .= "el('search_results_msg').innerHTML = 'Unable to find blocks matching your query, showing all records';"; } // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything. if ($where == '') { $where = 'id > 0'; } // Do the SQL Query $filter = ''; if ($form['filter']) { $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%'); } list($status, $rows, $results) = db_get_records($onadb, 'blocks', $where . $filter, "ip_addr_start ASC", $conf['search_results_per_page'], $offset); // If we got less than search_results_per_page, add the current offset to it // so that if we're on the last page $rows still has the right number in it. if ($rows > 0 and $rows < $conf['search_results_per_page']) { $rows += $conf['search_results_per_page'] * ($page - 1); } else { if ($rows >= $conf['search_results_per_page']) { list($status, $rows, $records) = db_get_records($onadb, 'blocks', $where . $filter, "", 0); } } $count = $rows; $html .= <<<EOL <!-- Block List --> <table id="{$form['form_id']}_block_list" class="list-box" cellspacing="0" border="0" cellpadding="0"> <!-- Table Header --> <tr> <td class="list-header" align="center" style="{$style['borderR']};">Block Name</td> <td class="list-header" align="center" style="{$style['borderR']};">Starting IP</td> <td class="list-header" align="center" style="{$style['borderR']};">Ending IP</td> <td class="list-header" align="center"> </td> </tr> EOL; // Loop and display each record foreach ($results as $record) { // Grab some info from the associated block record list($status, $rows, $block) = ona_get_block_record(array('id' => $record['id'])); $num_hosts = 0xffffffff - $block['ip_addr_end']; $block['ip_block_end'] = $block['ip_addr'] + $num_hosts; $record['name'] = $block['name']; // Convert IP and Netmask to a presentable format $record['ip_addr_start'] = ip_mangle($record['ip_addr_start'], 'dotted'); $record['ip_addr_end'] = ip_mangle($block['ip_addr_end'], 'dotted'); // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block\\', \\'block_id=>{$record['id']}\\', \\'display\\')');"; $html .= <<<EOL <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'"> <td class="list-row" align="left"> <a title="View block. ID: {$record['id']}" class="nav" onClick="{$primary_object_js}" >{$record['name']}</a> </td> <td class="list-row" align="left"> {$record['ip_addr_start']} </td> <td class="list-row" align="left"> {$record['ip_addr_end']} </td> <td class="list-row" align="right"> <form id="{$form['form_id']}_list_block_{$record['id']}" ><input type="hidden" name="block_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('advanced')) { $html .= <<<EOL <a title="Edit block. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'editor');" ><img src="{$images}/silk/brick_edit.png" border="0"></a> EOL; } $html .= <<<EOL <a title="Display subnet map" class="act" onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr_start']},ip_block_end=>{$record['ip_addr_end']},id=>{$record['id']}\\', \\'display\\');');" ><img src="{$images}/silk/shape_align_left.png" border="0"></a> EOL; if (auth('advanced')) { $html .= <<<EOL <a title="Delete block" class="act" onClick="var doit=confirm('Are you sure you want to delete this block?'); if (doit == true) xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> EOL; } $html .= <<<EOL </td> </tr> EOL; } $html .= <<<EOL </table> EOL; // Build page links if there are any $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']); // If there was only 1 result, and we're about to display results in the "Search Results" window, display it. if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '') { $js .= $primary_object_js; } // Insert the new html into the content div specified // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})"); $response->addAssign($form['content_id'], "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function 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(); } // Load an existing host record (and associated info) if $form is a host_id if (is_numeric($form['block_id'])) { list($status, $rows, $block) = ona_get_block_record(array('id' => $form['block_id'])); $block['ip_addr_start'] = ip_mangle($block['ip_addr_start'], 'dotted'); $block['ip_addr_end'] = ip_mangle($block['ip_addr_end'], 'dotted'); } // Escape data for display in html foreach (array_keys((array) $block) as $key) { $block[$key] = htmlentities($block[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Add Block"; if ($block['id']) { $window['title'] = "Edit Block"; } // 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('name').focus(); EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- Block Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="block_id" value="{$block['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;"> <!-- BLOCK RECORD --> <tr> <td align="left" nowrap="true"><b><u>Block Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Block Name </td> <td class="padding" align="left" width="100%"> <input id="name" name="name" alt="Block name" value="{$block['name']}" class="edit" type="text" size="27" maxlength="255" > </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> IP Block Start </td> <td class="padding" align="left" width="100%"> <input name="start" alt="IP block start" value="{$block['ip_addr_start']}" class="edit" type="text" size="20" maxlength="40" > </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> IP Block End </td> <td class="padding" align="left" width="100%"> <input name="end" alt="IP block end" value="{$block['ip_addr_end']}" class="edit" type="text" size="20" maxlength="40" > </td> </tr> <tr> <td align="right" nowrap="true"> Notes </td> <td class="padding" align="left" width="100%"> <input name="notes" alt="Notes" value="{$block['notes']}" class="edit" type="text" size="17" 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}_edit_form'), 'save');" > </td> </tr> </table> </form> EOL; return window_open($window_name, $window); }