예제 #1
0
파일: edit_tag.inc.php 프로젝트: edt82/ona
function ws_delete($window_name, $form = '')
{
    global $base, $include, $conf, $self, $onadb;
    // Check permissions
    if (!(auth('host_del') or auth('subnet_del'))) {
        $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);
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Run the module
    list($status, $output) = run_module('tag_del', array('tag' => $form['id'], 'commit' => 'Y'));
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Delete failed. " . preg_replace('/[\\s\']+/', ' ', $self['error']) . "');";
    } else {
        // If there's (refresh) js, send it to the browser
        if ($form['js']) {
            $js .= $form['js'];
        }
    }
    // Return an XML response
    $response->addScript($js);
    return $response->getXML();
}
예제 #2
0
function ws_menu($window_name, $form = '')
{
    global $conf, $images;
    $html = $js = '';
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    printmsg("DEBUG => Displaying tooltip: {$form['tooltip']}", 4);
    $menuname = 'get_html_' . $form['menu_name'];
    list($html, $js) = $menuname($form);
    // Okay here's what we do:
    //   1. Hide the tool-tip
    //   2. Update it's content
    //   3. Reposition it
    //   4. Unhide it
    $response = new xajaxResponse();
    if ($html) {
        $response->addScript("el('{$form['id']}').style.visibility = 'hidden';");
        $response->addAssign($form['id'], "innerHTML", $html);
        $response->addScript("wwTT_position('{$form['id']}'); el('{$form['id']}').style.visibility = 'visible';");
    }
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #3
0
파일: ipcalcgui.inc.php 프로젝트: edt82/ona
function ws_ipcalcgui_submit($window_name, $form = '')
{
    global $conf, $self, $onadb, $tip_style;
    global $font_family, $color, $style, $images;
    $html = $js = '';
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    $text = '';
    $ipinfo = ipcalc_info($form['ip'], $form['mask']);
    // MP: I removed the following as they are tooooo large
    //bin128:  {$ipinfo['ip_bin128']}
    //bin128:      {$ipinfo['mask_bin128']}
    // NOTE: yes it is annoying but I had to do the <br> thing due to windows
    // not being able to handle the new lines via a standard <pre> statement.
    // I went with this as it keeps things consistant between platforms.  The pre is now a span
    $text .= <<<EOL
<br />
<br />
Input: IP={$ipinfo['in_ip']}    MASK={$ipinfo['in_mask']}<br />
<br />
IP={$ipinfo['in_ip']}<br />
  Dotted:  {$ipinfo['ip_dotted']}<br />
  Numeric: {$ipinfo['ip_numeric']}<br />
  binary:  {$ipinfo['ip_binary']}<br />
  ipv6:    {$ipinfo['ip_ipv6']}<br />
  ipv6gz:  {$ipinfo['ip_ipv6gz']}<br />
  flip:    {$ipinfo['ip_flip']}<br />
<br />
MASK={$ipinfo['mask_dotted']}<br />
  Dotted:      {$ipinfo['mask_dotted']}<br />
  Numeric:     {$ipinfo['mask_numeric']}<br />
  Cidr:        /{$ipinfo['mask_cidr']}<br />
  binary:      {$ipinfo['mask_binary']}<br />
  bin invert:  {$ipinfo['mask_bin_invert']}<br />
  ipv6:        {$ipinfo['mask_ipv6']}<br />
  ipv6gz:      {$ipinfo['mask_ipv6gz']}<br />
  flip:        {$ipinfo['mask_flip']}<br />
  IP invert:   {$ipinfo['mask_dotted_invert']}<br />
<br />
The subnet your IP falls in is:   {$ipinfo['truenet']}/{$ipinfo['mask_cidr']} ({$ipinfo['mask_dotted']})<br />
<br />
Total addresses using this mask:  {$ipinfo['ip_total']}<br />
Usable addresses using this mask: {$ipinfo['ip_usable']}<br />
Last address using this mask:     {$ipinfo['ip_last']}<br />
<br />

EOL;
    $response = new xajaxResponse();
    $response->addAssign('ipcalc_data', "innerHTML", $text);
    return $response->getXML();
}
예제 #4
0
function ws_process_alerts_submit($window_name, $form = '')
{
    global $conf, $self, $onadb, $tip_style;
    global $font_family, $color, $style, $images;
    $html = $js = '';
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    printmsg("DEBUG => Processing Alerts:", 5);
    // FIXME: this code is called from html_desktop.inc.php.. however it is failing to process for some reason
    // The intent of this code is to be called to display a "message waiting" type icon in the top menu bar.
    // Check for messages that begin with SYS_ in the table_name_ref column
    list($status, $rows, $msg) = db_get_record($onadb, 'messages', "table_name_ref LIKE 'SYS_%'");
    if ($rows) {
        $js .= "if (el('sys_alert')) {el('sys_alert').style.visibility = 'visible';}";
    } else {
        $js .= "if (el('sys_alert')) {el('sys_alert').style.visibility = 'hidden';}";
    }
    $response = new xajaxResponse();
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #5
0
function ws_change_tab($window_name, $form, $display_list = 1, $return_text = 0)
{
    global $conf, $self;
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    $form_id = $form['form_id'];
    $tab = $form['tab'];
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Save the new tab in the session
    $old_tab = $_SESSION['ona'][$form_id]['tab'];
    $_SESSION['ona'][$form_id]['tab'] = $tab;
    // remove any messages
    $js .= "el('search_results_msg').innerHTML = '';";
    // Make the old tab look inactive
    $js .= "_el = el('{$form_id}_{$old_tab}_tab'); if (_el) _el.className = 'table-tab-inactive'; el('{$old_tab}_search').style.display = 'none';";
    // Make the new tab look active
    $js .= "el('{$form_id}_{$tab}_tab').className = 'table-tab-active'; el('{$tab}_search').style.display = 'block';";
    // Set the "filter" to the correct value
    $js .= "el('{$form_id}_filter').value = '{$_SESSION['ona'][$form_id][$tab]['filter']}';";
    // Set the "page" and "tab" to the correct value
    $js .= "el('{$form_id}_page').value = '{$_SESSION['ona'][$form_id][$tab]['page']}';";
    $js .= "el('{$form_id}_tab').value = '{$tab}';";
    // Put the cursor in the first field
    $js .= "_el = el('{$tab}_field1'); if (_el) el('{$tab}_field1').focus();";
    // Hide/show the filter overlay
    $js .= "el('{$form_id}_filter_overlay').style.display = (el('{$form_id}_filter').value == '') ? 'inline' : 'none';";
    // Tell the browser to ask for a new list of data
    if ($display_list) {
        $js .= "xajax_window_submit('list_{$tab}', xajax.getFormValues('{$form_id}'), 'display_list');";
    }
    // If they asked us to return text, we return the javascript text..
    if ($return_text) {
        return $js;
    }
    // Send an XML response to the window
    $response->addAssign($_SESSION['ona'][$form_id]['content_id'], 'innerHTML', $conf['loading_icon']);
    $response->addScript($js);
    return $response->getXML();
}
예제 #6
0
파일: tooltips.inc.php 프로젝트: edt82/ona
function ws_window_progressbar($window_name, $form = '')
{
    global $images;
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    $window_name = $form['name'];
    $output = "<center>Working on the results, please wait<br><img src={$images}/loading.gif></center>";
    $window['title'] = 'Processing...';
    $window['js'] = "el('{$window_name}_extras').innerHTML='<br>';";
    $build_commit_html = 0;
    $commit_function = '';
    include window_find_include('module_results');
    return window_open("{$window_name}_results", $window);
}
예제 #7
0
function ws_display($window_name, $form = '')
{
    global $conf, $self, $ona;
    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);
    // Build $ip from $form['ip_block_start']
    $form['ip_block_start'] = ip_complete($form['ip_block_start'], '0');
    // Since we currently only display /24 (C) class networks, the
    //GD Need to call ip_mangle() so we can use is_ipv4()
    // last quad needs to be a .0.
    $ip = ip_mangle($form['ip_block_start'], 'numeric');
    if (is_ipv4($ip)) {
        $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 = $form['ip_block_start'] = preg_replace("/{$end}/", $replace_end_by, $form['ip_block_start']);
    // Find out if $ip is valid
    $ip = ip_mangle($ip, 'numeric');
    if ($ip == -1) {
        $js .= "alert('The IP address specified is invalid!');";
    }
    // 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'] = 'Map: ' . ip_mangle($ip, 'dotted');
        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}');";
    // Define the window's inner html
    $html .= <<<EOL
    <div id="{$window_name}_content" style="padding: 2px 4px;">
        <form id="block_search_form" onsubmit="el('zoom_block_button').onclick(); return false;">
        <div id="{$window_name}_tools">
            <b>IP Address</b>
            <input type="hidden" id="{$window_name}_zoom" name="zoom" value="8">
            <input id="{$window_name}_ip_block_start" name="{$window_name}_ip_block_start" value="{$form['ip_block_start']}" class="edit" type="text" size="15" />
            <a id="zoom_block_button" title="Zoom block"
                       class="act"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'{$window_name}\\', \\'ip_block_start=>' + el('{$window_name}_ip_block_start').value + ',zoom=>' + el('{$window_name}_zoom').value + '\\', \\'display\\');');"
            ><img src="{$images}/silk/bullet_go.png" border="0"></a>&nbsp;
        <br><br>
        </div>
        </form>

        <div id="{$window_name}_portal">
            <span id="{$window_name}_substrate"></span>
        </div>

    </div>
EOL;
    // Position/size the portal ourselves
    $js .= <<<EOL
        var _el = el('{$window_name}_portal');

        /* Now calculate where we will sit */
        var my_height = el('work_space_content').offsetHeight - el('{$window_name}_tools').offsetHeight - 40;
        var my_width  = el('{$window_name}_tools').offsetWidth - 10;

        /* Finally reposition/resize the window */
        _el.style.position = 'relative';
        _el.style.height   = my_height + 'px';

EOL;
    // Get javascript to setup the map portal
    $js .= get_portal_js($window_name, $ip, $version);
    //*** Send a fake mouseup event to draw the initial map view ***
    $js .= "el('{$window_name}_portal').myonmouseup('fake event');";
    // 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);
    }
    return $response->getXML();
}
예제 #8
0
파일: edit_host.inc.php 프로젝트: edt82/ona
function ws_delete($window_name, $form = '')
{
    global $include, $conf, $self, $onadb;
    // Check permissions
    if (!auth('host_del')) {
        $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);
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Run the module
    list($status, $output) = run_module('host_del', array('host' => $form['host_id'], 'commit' => $form['commit']));
    // If commit was N, display the confirmation dialog box
    if (!$form['commit']) {
        $build_commit_html = 1;
        $commit_function = 'delete';
        include window_find_include('module_results');
        return window_open("{$window_name}_results", $window);
    }
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Delete failed. " . preg_replace('/[\\s\']+/', ' ', $output) . "');";
    } else {
        if ($form['js']) {
            $js .= $form['js'];
        }
    }
    // usually js will refresh the window we got called from
    // Return an XML response
    $response->addScript($js);
    return $response->getXML();
}
예제 #9
0
function ws_display($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style, $msgtype;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Load the host record
    if ($form['interface_id']) {
        list($status, $rows, $record) = ona_get_interface_record(array('id' => $form['interface_id']));
    }
    $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
    if ($status or !$rows) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>Interface doesn't exist!</b></font></center>";
        $response = new xajaxResponse();
        $response->addAssign("work_space_content", "innerHTML", $html);
        return $response->getXML();
    }
    // Update History Title (and tell the browser to re-draw the history div)
    $history = array_pop($_SESSION['ona']['work_space']['history']);
    $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');";
    if ($history['title'] == $window_name) {
        $history['title'] = $record['ip_addr'];
        array_push($_SESSION['ona']['work_space']['history'], $history);
    }
    // Create some javascript to refresh the current page
    $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
    $refresh = "xajax_window_submit('work_space', '{$refresh}');";
    // Associated Host info
    list($status, $rows, $host) = ona_get_host_record(array('id' => $record['host_id']), '');
    // Subnet description
    list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id']));
    $record['subnet_name'] = $subnet['name'];
    $record['ip_subnet_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
    $record['ip_subnet_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
    $style['content_box'] = <<<EOL
        margin: 10px 20px;
        padding: 2px 4px;
        background-color: #FFFFFF;
        vertical-align: top;
EOL;
    $style['label_box'] = <<<EOL
        font-weight: bold;
        padding: 2px 4px;
        border: solid 1px {$color['border']};
        background-color: {$color['window_content_bg']};
EOL;
    // Escape data for display in html
    foreach (array_keys($record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    $html .= <<<EOL

    <!-- FORMATTING TABLE -->
    <div style="{$style['content_box']}">
    <table cellspacing="0" border="0" cellpadding="0"><tr>

        <!-- START OF FIRST COLUMN OF SMALL BOXES -->
        <td nowrap="true" valign="top" style="padding-right: 15px;">

            <!-- HOST INFORMATION -->
            <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">

                <tr><td colspan="99" nowrap="true" style="{$style['label_box']}">
                    <!-- LABEL -->
                    <form id="form_interface_{$record['id']}"
                        ><input type="hidden" name="interface_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>
EOL;
    if (auth('host_modify', $debug_val)) {
        $html .= <<<EOL
                    <a title="Edit interface. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>
EOL;
    }
    if (auth('host_del', $debug_val)) {
        $html .= <<<EOL
                    <a title="Delete interface. ID: {$record['id']}"
                       class="act"
                       onClick="var doit=confirm('Are you sure you want to delete this interface?');
                                if (doit == true)
                                    xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/delete.png" border="0"></a>
EOL;
    }
    $html .= <<<EOL
                     &nbsp;{$record['ip_addr']}
                </td></tr>

                <tr>
                    <td align="right" nowrap="true"><b>MAC Address</b>&nbsp;</td>
                    <td class="padding" align="left">{$record['mac_addr']}&nbsp;</td>
                </tr>

                <tr>
                    <td align="right" nowrap="true"><b>Name</b>&nbsp;</td>
                    <td class="padding" align="left">{$record['name']}&nbsp;</td>
                </tr>

                <tr>
                    <td align="right" nowrap="true"><b>Description</b>&nbsp;</td>
                    <td class="padding" align="left">{$record['description']}&nbsp;</td>
                </tr>

            </table>
EOL;
    $html .= <<<EOL
        <!-- END OF FIRST COLUMN OF SMALL BOXES -->
        </td>

        <!-- START OF SECOND COLUMN OF SMALL BOXES -->
        <td valign="top" style="padding-right: 15px;">
EOL;
    $html .= <<<EOL
        <!-- END OF SECOND COLUMN OF SMALL BOXES -->
        </td>


        <!-- START OF THIRD COLUMN OF SMALL BOXES -->
        <td valign="top">
EOL;
    $html .= <<<EOL
        </td>
        <!-- END OF THIRD COLUMN OF SMALL BOXES -->
    </tr></table>
    </div>
    <!-- END OF TOP SECTION -->

EOL;
    // record LIST
    $tab = 'records';
    $submit_window = "list_{$tab}";
    $form_id = "{$submit_window}_filter_form";
    $_SESSION['ona'][$form_id]['tab'] = $tab;
    $content_id = "{$window_name}_{$submit_window}";
    $html .= <<<EOL
    <!-- RECORD LIST -->
    <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">

        <!-- Tab & Quick Filter -->
        <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
            <tr>
                <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
                    Associated DNS {$tab} <span id="{$form_id}_{$tab}_count"></span>
                </td>

                <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
                    <form id="{$form_id}" onSubmit="return false;">
                    <input id="{$form_id}_page" name="page" value="1" type="hidden">
                    <input name="content_id" value="{$content_id}" type="hidden">
                    <input name="form_id" value="{$form_id}" type="hidden">
                    <input name="interface_id" value="{$record['id']}" type="hidden">
                    <div id="{$form_id}_filter_overlay"
                         style="position: relative;
                                display: inline;
                                color: #CACACA;
                                cursor: text;"
                         onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
                    >Filter</div>
                    <input
                        id="{$form_id}_filter"
                        name="filter"
                        class="filter"
                        type="text"
                        value=""
                        size="10"
                        maxlength="20"
                        alt="Quick Filter"
                        onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
                        onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
                        onKeyUp="
                            if (typeof(timer) != 'undefined') clearTimeout(timer);
                            code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' +
                                   '    {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' +
                                   '    document.getElementById(\\'{$form_id}_page\\').value = 1;' +
                                   '    xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' +
                                   '}';
                            timer = setTimeout(code, 700);"
                    >
                    </form>
                </td>

            </tr>
        </table>

        <div id='{$content_id}'>
            {$conf['loading_icon']}
        </div>
EOL;
    if (auth('record_add', $debug_val)) {
        $html .= <<<EOL

        <!-- ADD DNS RECORD LINK -->
        <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}">
            <form id="form_record_{$record['id']}"
                ><input type="hidden" name="interface_id" value="{$record['id']}"
                ><input type="hidden" name="js" value="{$refresh}"
            ></form>

            <a title="Add record"
               class="act"
               onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
            ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

            <a title="Add record"
               class="act"
               onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
            >Add record</a>&nbsp;
        </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();
}
예제 #10
0
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);
    // 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']};">Role</td>
            <td class="list-header" align="center">&nbsp;</td>
        </tr>

EOL;
    $where = 'id > 0';
    if (is_array($form) and $form['filter']) {
        $where = 'name 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, 'roles', $where, 'name', $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, 'roles', $where, '', 0);
        }
    }
    $count = $rows;
    // Loop through and display the users
    foreach ($records as $record) {
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
        <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

            <td class="list-row">
                <a title="Edit role. id: {$record['id']}"
                   class="act"
                   onClick="xajax_window_submit('app_device_role_edit', '{$record['id']}', 'editor');"
                >{$record['name']}</a>&nbsp;
            </td>

            <td align="right" class="list-row" nowrap="true">
                <a title="Edit role. id: {$record['id']}"
                    class="act"
                    onClick="xajax_window_submit('app_device_role_edit', '{$record['id']}', 'editor');"
                ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;

                <a title="Delete role. id: {$record['id']}"
                    class="act"
                    onClick="var doit=confirm('Are you sure you want to delete this role?');
                            if (doit == true)
                                xajax_window_submit('{$window_name}', '{$record['id']}', 'delete');"
                ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
            </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']};">
        <!-- ADD role LINK -->
        <a title="New role"
            class="act"
            onClick="xajax_window_submit('app_device_role_edit', ' ', 'editor');"
        ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

        <a title="New role"
            class="act"
            onClick="xajax_window_submit('app_device_role_edit', ' ', 'editor');"
        >Add role</a>&nbsp;
    </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']}_role_count", "innerHTML", "({$count})");
    $response->addAssign("{$form['content_id']}", "innerHTML", $html);
    // $response->addScript($js);
    return $response->getXML();
}
예제 #11
0
function ws_delete($window_name, $form = '')
{
    global $include, $conf, $self, $mysql, $onadb;
    // 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);
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Run the module
    list($status, $output) = run_module('domain_del', array('domain' => $form['id'], 'commit' => 'Y'));
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Delete failed. " . preg_replace('/[\\s\']+/', ' ', $self['error']) . "');";
    } else {
        if ($form['js']) {
            $js .= $form['js'];
        }
    }
    // usually js will refresh the window we got called from
    // Return an XML response
    $response->addScript($js);
    return $response->getXML();
}
예제 #12
0
function ws_display($window_name, $form = '')
{
    global $conf, $self, $onadb, $base;
    global $images, $color, $style, $msgtype;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Load the host record
    if ($form['device_id']) {
        list($status, $rows, $record) = ona_get_device_record(array('id' => $form['device_id']));
    } else {
        if ($form['device']) {
            // FIXME.. no find_device yet
            list($status, $rows, $record) = ona_find_device($form['device']);
        }
    }
    if ($status or !$rows) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>Device 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}');";
    // 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['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_type) = ona_get_device_type_record(array('id' => $record['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']);
    // 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;
    $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']);
    }
    // force 300px width to Notes field if the length is longer than 50 characters and put Notes at the top of the td
    $notes_width = "";
    $notes_valign = "";
    if (strlen($record['notes']) > 50) {
        $notes_width = ' style="width: 300px" ';
        $notes_valign = ' valign="top" ';
    }
    $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;">

            <form id="form_device_{$record['id']}"
                ><input type="hidden" name="device_id" value="{$record['id']}"
                ><input type="hidden" name="js" value="{$refresh}"
            ></form>

EOL;
    $wspl = workspace_plugin_loader('host_detail', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wspl = workspace_plugin_loader('location_detail', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $html .= <<<EOL
        <!-- END OF FIRST COLUMN OF SMALL BOXES -->
        </td>

        <!-- START OF SECOND COLUMN OF SMALL BOXES -->
        <td valign="top" style="padding-right: 15px;">
EOL;
    $html .= <<<EOL
        <!-- END OF SECOND COLUMN OF SMALL BOXES -->
        </td>


        <!-- START OF THIRD COLUMN OF SMALL BOXES -->
        <td valign="top">
EOL;
    // START MESSAGES BOX
    // $tablename is a reference directly to the table that contains the item
    // we are displaying to the user.
    // It is possible that you can have the same ID in multiple tables, currently.
    $tablename = 'devices';
    require_once 'winc/tooltips.inc.php';
    list($lineshtml, $linesjs) = get_message_lines_html("table_id_ref = {$record['id']} AND table_name_ref LIKE '{$tablename}'");
    if ($lineshtml) {
        $html .= <<<EOL
            <!-- MESSAGES LIST -->
            <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">
                <tr><td colspan="99" nowrap="true" style="{$style['label_box']}">
                    Messages
                </td></tr>
                <tr><td>
EOL;
        $html .= $lineshtml;
        $js .= $linesjs;
        $html .= "</td></tr></table>";
    }
    // END MESSAGES LIST
    $html .= <<<EOL
        </td>
        <!-- END OF THIRD COLUMN OF SMALL BOXES -->
    </tr></table>
    </div>
    <!-- END OF TOP SECTION -->

EOL;
    // RECORD LIST
    $tab = 'hosts';
    $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 Hosts {$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="device_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 host"
               class="act"
               onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
            ><img src="{$images}/silk/font_add.png" border="0"></a>&nbsp;

            <a title="Add host"
               class="act"
               onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
            >Add host</a>&nbsp;
        </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();
}
예제 #13
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // 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;
    //
    //       FIND RESULT SET
    //
    // Start building the "where" clause for the sql query to find the subnets to display
    $where = "";
    $and = "";
    // SERVER ID
    if ($form['server_id']) {
        $where .= $and . 'id IN (SELECT subnet_id
                                FROM   dhcp_server_subnets
                                WHERE  host_id = ' . $onadb->qstr($form['server_id']) . '
                                UNION
                                SELECT subnet_id
                                FROM dhcp_pools
                                WHERE dhcp_failover_group_id IN (SELECT id
                                                                FROM dhcp_failover_groups
                                                                WHERE primary_server_id = ' . $onadb->qstr($form['server_id']) . '
                                                                OR secondary_server_id = ' . $onadb->qstr($form['server_id']) . '))';
        $and = " AND ";
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        // Subnet descriptions are always upper case
        $form['filter'] = strtoupper($form['filter']);
        $filter = $and . ' name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'subnets', $where . $filter, 'ip_addr', $conf['search_results_per_page'], $offset);
    // If we got less than 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, 'subnets', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    //
    // *** BUILD HTML LIST ***
    //
    $html .= <<<EOL
    <!-- Subnet Results -->
    <table id="{$form['form_id']}_dhcp_server_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

        <!-- Table Header -->
        <tr>
            <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
            <td class="list-header" align="center">&nbsp;</td>
        </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Get additional info about eash subnet record //
        // Convert IP and Netmask to a presentable format
        $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
        $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
        $record['ip_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr');
        list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id']));
        $record['type'] = $type['display_name'];
        // Calculate the percentage of the subnet that's used (total size - allocated hosts - dhcp pool size)
        $usage_html = get_subnet_usage_html($record['id']);
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$record['id']}\\', \\'display\\')');";
        $html .= <<<EOL
        <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

            <td class="list-row">
                <a title="View subnet. ID: {$record['id']}"
                   class="nav"
                   onClick="{$primary_object_js}"
                >{$record['name']}</a>
            </td>

            <td class="list-row" align="left">
                {$record['ip_addr']} <span title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span>&nbsp;
            </td>

            <td class="list-row" align="center" style="vertical-align: middle;">
                {$usage_html}
            </td>

            <td class="list-row" align="right">
                {$record['type']}&nbsp;
            </td>

            <td class="list-row" align="right">
                <form id="{$form['form_id']}_list_dhcp_server_{$record['id']}"
                    ><input type="hidden" name="subnet_id" value="{$record['id']}"
                    ><input type="hidden" name="server_id" value="{$form['server_id']}"
                    ><input type="hidden" name="js" value="{$refresh}"
                ></form>

                <a title="Display subnet map"
                   class="act"
                   onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr']}\\', \\'display\\');');"
                ><img src="{$images}/silk/shape_align_left.png" border="0"></a>&nbsp;
EOL;
        if (auth('subnet_modify', $debug_val)) {
            $html .= <<<EOL

                <a title="Edit subnet"
                   class="act"
                   onClick="xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_dhcp_server_{$record['id']}'), 'editor');"
                ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
EOL;
        }
        // check if the subnet listed is from a failover group or an actual dhcp server subnet assignment
        list($dhcpsubnetstatus, $dhcpsubnetrows, $dhcpserver) = ona_get_dhcp_server_subnet_record(array('subnet_id' => $record['id'], 'host_id' => $form['server_id']));
        if (auth('subnet_del', $debug_val) && $dhcpsubnetrows == 1) {
            $html .= <<<EOL

                <a title="Remove subnet association with server."
                   class="act"
                   onClick="var doit=confirm('Are you sure you want to remove this subnet from this DHCP server?');
                        if (doit == true)
                            xajax_window_submit('edit_dhcp_server', xajax.getFormValues('{$form['form_id']}_list_dhcp_server_{$record['id']}'), 'delete');"
                ><img src="{$images}/silk/page_delete.png" border="0"></a>&nbsp;
EOL;
        } else {
            $html .= <<<EOL
                <span title="You must change the failover group assignment on the pool to remove this entry."><img src="{$images}/silk/comment.png" border="0"></span>&nbsp;
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();
}
예제 #14
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // 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 DOMAINS
    if ($form['server_id']) {
        $where .= $and . 'id IN (SELECT domain_id FROM dns_server_domains WHERE host_id = ' . $onadb->qstr($form['server_id']) . ')';
        $and = " AND ";
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        $filter = $and . 'name LIKE ' . $oracle->qstr('%' . $form['filter'] . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'domains', $where . $filter, "name 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, 'domains', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    $html .= <<<EOL
        <!-- Domain List -->
        <table id="{$form['form_id']}_domain_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};">Domain Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Parent Domain</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Role</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Grab some info from the associated domain server record
        list($status, $rows, $domain_server) = ona_get_dns_server_domain_record(array('domain_id' => $record['id'], 'host_id' => $form['server_id']));
        list($status, $rows, $parent_zone) = ona_get_domain_record(array('id' => $record['parent_id']));
        $record['role'] = strtoupper($domain_server['role']);
        $record['parent_dns_zone_id'] = $parent_zone['id'];
        $record['parent_dns_zone'] = $parent_zone['fqdn'];
        if ($parent_zone['fqdn']) {
            $parent_zone['fqdn'] = '.' . $parent_zone['fqdn'];
        }
        // Escape data for display in html
        foreach (array_keys((array) $record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

                <td class="list-row" align="left">
                    <a title="View domain. ID: {$record['id']}"
                       class="domain"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$record['id']}\\', \\'display\\')');"
                    >{$record['name']}{$parent_zone['fqdn']}</a>
                </td>

                <td class="list-row" align="left">
                    <a title="View domain. ID: {$record['parent_dns_zone_id']}"
                       class="domain"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_zone\\', \\'zone_id=>{$record['parent_dns_zone_id']}\\', \\'display\\')');"
                    >{$record['parent_dns_zone']}</a>&nbsp;
                </td>

                <td class="list-row" align="left">
                    {$record['role']}&nbsp;
                </td>

                <td class="list-row" align="right">
                    <form id="{$form['form_id']}_list_domain_server_{$record['id']}"
                        ><input type="hidden" name="id" value="{$record['id']}"
                        ><input type="hidden" name="domain" value="{$record['id']}"
                        ><input type="hidden" name="server" value="{$form['server_id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>
EOL;
        if (auth('advanced', $debug_val)) {
            $html .= <<<EOL

                    <a title="Edit domain. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('edit_domain', xajax.getFormValues('{$form['form_id']}_list_domain_server_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;

                    <a title="Remove domain assosiation. ID: {$domain_server['id']}"
                       class="act"
                       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']}_list_domain_server_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/page_delete.png" border="0"></a>
EOL;
        }
        $html .= <<<EOL
                &nbsp;
                </td>

            </tr>

EOL;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #15
0
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>&nbsp;

                    <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>&nbsp;
EOL;
    }
    $html .= <<<EOL
                    {$record['name']}

                    &nbsp;&nbsp;<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>&nbsp;</td>
                    <td class="padding" align="left">{$record['name']}&nbsp;</td>
                </tr>

                <tr>
                    <td align="right" nowrap="true"><b>IP start</b>&nbsp;</td>
                    <td class="padding" align="left">
                        {$record['ip_addr_start']}
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" nowrap="true"><b>IP end</b>&nbsp;</td>
                    <td class="padding" align="left">
                        {$record['ip_addr_end']}
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" nowrap="true"><b>Notes</b>&nbsp;</td>
                    <td class="padding" align="left">
                        {$record['notes']}
                        &nbsp;
                    </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>&nbsp;
                        <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>&nbsp;
                        <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();
}
예제 #16
0
function ws_display_config($window_name, $form = '')
{
    global $conf;
    $html = '';
    $js = '';
    // If the user supplied an array in a string, transform it into an array
    $form = parse_options_string($form);
    // MP: This could be slow depending on the size of the database.  maybe make it a button.. having no build_dns_type turns it off
    // It expects to be passed the domain name as domain= to the module
    if ($conf['build_dns_type'] && auth('dns_record_add', $debug_val)) {
        switch (strtolower($conf['build_dns_type'])) {
            case "bind":
                $dns_module_name = 'build_bind_conf';
                break;
            case "tinydns":
                $dns_module_name = 'build_tinydns_conf';
                break;
        }
        list($status, $output) = run_module("{$dns_module_name}", array('server' => $form['fqdn'], 'view' => $form['view'], 'path' => 'GUI-only-path'));
        // Display the config if it ran ok
        if (!$status) {
            $html .= $output;
        } else {
            $html .= "There was a problem generating the configuration.<br>{$output}";
        }
    }
    // Insert the new html into the window
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("confoutput", "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #17
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb, $baseURL;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    // Start building the "where" clause for the sql query to find the records to display
    $where = '';
    $and = '';
    // DISPLAY ALL CONFIGS
    if ($form['all_flag']) {
        $where .= $and . "id > 0";
        $and = " AND ";
    }
    if ($form['host_id']) {
        $where .= 'host_id = ' . $form['host_id'];
        $and = " AND ";
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        $filter = $and . ' configuration_type_id in (select id from configuration_types where name like "%' . $form['filter'] . '%")';
    }
    list($status, $rows, $results) = db_get_records($onadb, 'configurations', $where . $filter, 'configuration_type_id ASC, ctime DESC', $conf['search_results_per_page'], $offset);
    // If we got less than search_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $records) = db_get_records($onadb, 'configurations', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    $html .= <<<EOL
        <!-- Config List -->
        <table id="{$form['form_id']}_config_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};">A</td>
                <td class="list-header" align="center" style="{$style['borderR']};">B</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Date</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
                <td class="list-header" align="center" style="{$style['borderR']};">MD5 Checksum</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Size (chars)</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        $id++;
        // Counter used for comparison seleciton
        // Grab some info from the associated record
        list($status, $rows, $ctype) = ona_get_config_type_record(array('id' => $record['configuration_type_id']));
        $record['config_type_name'] = $ctype['name'];
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        // MP: FIXME still not working right for encoded stings.. always returns 0
        $confsize = mb_strlen(html_entity_decode($record['config_body'], ENT_QUOTES, $conf['php_charset']), $conf['php_charset']);
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

                <td align="center" class="list-row" style="padding-right: 4px; width: 20px;"
                  ><input id="old{$id}" name="old" type="radio" value="{$record['id']}"
                    onClick="
                        var tmp = 1; var obj = el('new' + tmp);
                        while (obj) {
                            obj.style.visibility = (tmp <= {$id}) ? 'visible' : 'hidden';
                            if (tmp > {$id}) obj.checked = false;
                            obj = el('new' + tmp++);
                        }"
                  >
                </td>

                <td class="list-row" align="center" style="width: 20px;">
                    <input id="new{$id}" style="visibility: hidden;" name="new" type="radio" value="{$record['id']}">
                </td>

                <td class="list-row" align="center">
                    {$record['ctime']}&nbsp;
                </td>

                <td class="list-row" align="center">
                    {$record['config_type_name']}&nbsp;
                </td>

                <td class="list-row" align="center">
                    {$record['md5_checksum']}&nbsp;
                </td>

                <td class="list-row" align="center">
                    {$confsize}
                </td>
                <td class="list-row" align="right">
                    <form id="{$form['form_id']}_list_configs_{$record['id']}"
                        ><input type="hidden" name="config_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>
EOL;
        if (auth('host_config_admin', $debug_val)) {
            $html .= <<<EOL

                    <a title="View config. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_config_text\\', \\'host_id=>{$record['host_id']},type_id=>{$record['configuration_type_id']},displayconf=>{$record['id']}\\', \\'display\\')');"
                    ><img src="{$images}/silk/zoom.png" border="0"></a>&nbsp;

                    <a title="Download config"
                       class="act"
                       target="null"
                       href="{$baseURL}/config_dnld.php?config_id={$record['id']}&download=1"
                    ><img src="{$images}/silk/disk.png" alt="Download config" border="0"></a>&nbsp;

                    <a title="Delete config"
                       class="nav"
                       onClick="var doit=confirm('Are you sure you want to delete this config record?');
                                if (doit == true)
                                    xajax_window_submit('display_config_text', xajax.getFormValues('{$form['form_id']}_list_configs_{$record['id']}'), 'delete_config');"
                    ><img src="{$images}/silk/delete.png" alt="Delete config" border="0"></a>&nbsp;

EOL;
        }
        $html .= <<<EOL
                    &nbsp;
                </td>

            </tr>

EOL;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #18
0
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>&nbsp;

            <a title="Add DNS record"
               class="act"
               onClick="xajax_window_submit('edit_record', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
            >Add DNS record</a>&nbsp;
        </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>&nbsp;

            <a title="Add interface"
               class="act"
               onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_interface_{$record['id']}'), 'editor');"
            >Add interface</a>&nbsp;
        </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();
}
예제 #19
0
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">&nbsp;</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']}&nbsp;
                </td>

                <td class="list-row" align="left">
                    {$record['ip_addr_end']}&nbsp;
                </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>&nbsp;
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>&nbsp;
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
                    &nbsp;
                </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();
}
예제 #20
0
function ws_toggleenable($window_name, $form = '')
{
    global $include, $conf, $self, $onadb;
    // 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);
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = "xajax_window_submit('app_plugin_list', xajax.getFormValues('app_plugin_list_filter_form'), 'display_list');";
    if (is_writable($form['path'])) {
        if ($form['state'] == 'disable') {
            touch($form['path'] . '/plugin_disabled');
        }
        if ($form['state'] == 'enable') {
            unlink($form['path'] . '/plugin_disabled');
        }
    } else {
        $js .= "alert('Plugin path {$form['path']} is not writeable by the web server!');";
    }
    if ($form['task'] == 'install') {
        return window_open('', $window);
    }
    if ($form['js']) {
        $js .= $form['js'];
    }
    // usually js will refresh the window we got called from
    // Return an XML response
    $response->addScript($js);
    return $response->getXML();
}
예제 #21
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    // If the user supplied an array in a string, transform it into an array
    $form = parse_options_string($form);
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    printmsg("DEBUG => Displaying records list page: {$page}", 1);
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    //
    // *** ADVANCED RECORD SEARCH ***
    //       FIND RESULT SET
    //
    // Start building the "where" clause for the sql query to find the records to display
    $where = "";
    $and = "";
    $orderby = "";
    // enable or disable wildcards
    $wildcard = '%';
    if ($form['nowildcard']) {
        $wildcard = '';
    }
    // RECORD ID
    if ($form['record_id']) {
        $where .= $and . "id = " . $onadb->qstr($form['record_id']);
        $and = " AND ";
    }
    // DNS VIEW ID
    if ($form['dns_view']) {
        if (is_string($form['dns_view'])) {
            list($status, $rows, $dnsview) = ona_get_dns_view_record(array('name' => $form['dns_view']));
        }
        if (is_numeric($form['dns_view'])) {
            list($status, $rows, $dnsview) = ona_get_dns_view_record(array('id' => $form['dns_view']));
        }
        $where .= $and . "dns_view_id = " . $onadb->qstr($dnsview['id']);
        $and = " AND ";
    }
    // INTERFACE ID
    if ($form['interface_id']) {
        $where .= $and . "interface_id = " . $onadb->qstr($form['interface_id']);
        $and = " AND ";
    }
    // DNS RECORD note
    if ($form['notes']) {
        $where .= $and . "notes LIKE " . $onadb->qstr($wildcard . $form['notes'] . $wildcard);
        $and = " AND ";
    }
    // DNS RECORD TYPE
    if ($form['dnstype']) {
        $where .= $and . "type = " . $onadb->qstr($form['dnstype']);
        $and = " AND ";
    }
    // HOSTNAME
    if ($form['hostname']) {
        $where .= $and . "id IN (SELECT id " . "  FROM dns " . "  WHERE name LIKE " . $onadb->qstr($wildcard . $form['hostname'] . $wildcard) . " )";
        $and = " AND ";
    }
    // DOMAIN
    if ($form['domain']) {
        // FIXME: MP test if this clause works correctly?  Not sure that anything even uses this?
        list($status, $rows, $tmpdomain) = ona_find_domain($form['domain']);
        $where .= $and . "domain_id = " . $onadb->qstr($tmpdomain['id']);
        $orderby .= "name, domain_id";
        $and = " AND ";
    }
    // DOMAIN ID
    if ($form['domain_id']) {
        //$where .= $and . "primary_dns_id IN ( SELECT id " .
        //                                    "  FROM dns " .
        //                                    "  WHERE domain_id = " . $onadb->qstr($form['domain_id']) . " )  ";
        $where .= $and . "domain_id = " . $onadb->qstr($form['domain_id']);
        $orderby .= "name, domain_id";
        $and = " AND ";
    }
    // IP ADDRESS
    $ip = $ip_end = '';
    if ($form['ip']) {
        // Build $ip and $ip_end from $form['ip'] and $form['ip_thru']
        $ip = ip_complete($form['ip'], '0');
        if ($form['ip_thru']) {
            $ip_end = ip_complete($form['ip_thru'], '255');
        } else {
            $ip_end = ip_complete($form['ip'], '255');
        }
        // Find out if $ip and $ip_end are valid
        $ip = ip_mangle($ip, 'numeric');
        $ip_end = ip_mangle($ip_end, 'numeric');
        if ($ip != -1 and $ip_end != -1) {
            // We do a sub-select to find interface id's between the specified ranges
            $where .= $and . "interface_id IN ( SELECT id " . "        FROM interfaces " . "        WHERE ip_addr >= " . $onadb->qstr($ip) . " AND ip_addr <= " . $onadb->qstr($ip_end) . " )";
            $and = " AND ";
        }
    }
    // display a nice message when we dont find all the records
    if ($where == '' and $form['content_id'] == 'search_results_list') {
        $js .= "el('search_results_msg').innerHTML = 'Unable to find DNS records matching your query, showing all records';";
    }
    // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything.
    if ($where == '') {
        $where = 'id > 0';
    }
    // If we dont have DNS views turned on, limit data to just the default view.
    // Even if there is data associated with other views, ignore it
    if (!$conf['dns_views']) {
        $where .= ' AND dns_view_id = 0';
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        // Host names should always be lower case
        $form['filter'] = strtolower($form['filter']);
        $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%');
    }
    // If we get a specific host to look for we must do the following
    // 1. get (A) records that match any interface_id associated with the host
    // 2. get CNAMES that point to dns records that are using an interface_id associated with the host
    if ($form['host_id']) {
        // If we dont have DNS views turned on, limit data to just the default view.
        // Even if there is data associated with other views, ignore it
        // MP: something strange with this, it should only limit to default view.. sometimes it does not???
        if (!$conf['dns_views']) {
            $hwhere .= 'dns_view_id = 0 AND ';
        }
        // Get the host record so we know what the primary interface is
        list($status, $rows, $host) = ona_get_host_record(array('id' => $form['host_id']), '');
        list($status, $rows, $results) = db_get_records($onadb, 'dns', $hwhere . 'interface_id in (select id from interfaces where host_id = ' . $onadb->qstr($form['host_id']) . ') OR interface_id in (select interface_id from interface_clusters where host_id = ' . $onadb->qstr($form['host_id']) . ')', "type", $conf['search_results_per_page'], $offset);
        // If we got less than search_results_per_page, add the current offset to it
        // so that if we're on the last page $rows still has the right number in it.
        if ($rows > 0 and $rows < $conf['search_results_per_page']) {
            $rows += $conf['search_results_per_page'] * ($page - 1);
        } else {
            if ($rows >= $conf['search_results_per_page']) {
                list($status, $rows, $records) = db_get_records($onadb, 'dns', $hwhere . 'interface_id in (select id from interfaces where host_id = ' . $onadb->qstr($form['host_id']) . ') OR interface_id in (select interface_id from interface_clusters where host_id = ' . $onadb->qstr($form['host_id']) . ')' . $filter, "", 0);
            }
        }
    } else {
        list($status, $rows, $results) = db_get_records($onadb, 'dns', $where . $filter, $orderby, $conf['search_results_per_page'], $offset);
        // If we got less than search_results_per_page, add the current offset to it
        // so that if we're on the last page $rows still has the right number in it.
        if ($rows > 0 and $rows < $conf['search_results_per_page']) {
            $rows += $conf['search_results_per_page'] * ($page - 1);
        } else {
            if ($rows >= $conf['search_results_per_page']) {
                list($status, $rows, $records) = db_get_records($onadb, 'dns', $where . $filter, "", 0);
            }
        }
    }
    $count = $rows;
    //
    // *** BUILD HTML LIST ***
    //
    $html .= <<<EOL
        <!-- dns record Results -->
        <table id="{$form['form_id']}_dns_record_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>

                <td colspan="2" class="list-header" align="center" style="{$style['borderR']};">Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Time to Live</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Data</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Effective</td>
EOL;
    if ($conf['dns_views']) {
        $html .= "<td class=\"list-header\" align=\"center\" style=\"{$style['borderR']};\">DNS View</td>";
    }
    $html .= <<<EOL
                <td class="list-header" align="center" style="{$style['borderR']};">Notes</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    //  $last_record = array('name' => $results[0]['name'], 'domain_id' => $results[0]['domain_id']);
    //  $last_record_count = 0;
    for ($i = 1; $i <= count($results); $i++) {
        $record = $results[$i];
        // Get additional info about each host record
        $record = $results[$i - 1];
        // if the interface is the primary_dns_id for the host then mark it
        $primary_record = '&nbsp;';
        if ($host['primary_dns_id'] == $record['id']) {
            $primary_record = '<img title="Primary DNS record" src="' . $images . '/silk/font_go.png" border="0">';
        }
        // Check for interface records (and find out how many there are)
        list($status, $interfaces, $interface) = ona_get_interface_record(array('id' => $record['interface_id']), '');
        if ($interfaces) {
            // Get the host record so we know what the primary interface is
            //list($status, $rows, $inthost) = ona_get_host_record(array('id' => $interface['host_id']), '');
            // Make the type correct based on the IP passed in
            if (strlen($interface['ip_addr']) > 11 and $record['type'] == 'A') {
                $record['type'] = 'AAAA';
            }
            $record['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted');
            // Subnet description
            list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id']));
            $record['subnet'] = $subnet['name'];
            $record['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
            $record['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
            // Create string to be embedded in HTML for display
            $data = <<<EOL
                        {$record['ip_addr']}&nbsp;

EOL;
        } else {
            // Get other DNS records which name this record as parent
            list($status, $rows, $dns_other) = ona_get_host_record(array('id' => $record['dns_id']));
            // Create string to be embedded in HTML for display
            if ($rows) {
                $data = <<<EOL
                <a title="View host. ID: {$dns_other['id']}"
                    class="nav"
                    onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$dns_other['id']}\\', \\'display\\')');"
                >{$dns_other['name']}</a
                >.<a title="View domain. ID: {$dns_other['domain_id']}"
                        class="domain"
                        onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$dns_other['domain_id']}\\', \\'display\\')');"
                >{$dns_other['domain_fqdn']}</a>&nbsp;
EOL;
            }
        }
        $record['notes_short'] = truncate($record['notes'], 30);
        // Add a dot to the end of record name for display purposes
        $record['name'] = $record['name'] . '.';
        // Process PTR record
        if ($record['type'] == 'PTR') {
            list($status, $rows, $pointsto) = ona_get_dns_record(array('id' => $record['dns_id']), '');
            list($status, $rows, $pdomain) = ona_get_domain_record(array('id' => $record['domain_id']), '');
            // Flip the IP address
            $record['name'] = ip_mangle($record['ip_addr'], 'flip');
            $record['domain'] = $pdomain['name'];
            if ($pdomain['parent_id']) {
                list($status, $rows, $parent) = ona_get_domain_record(array('id' => $pdomain['parent_id']));
                $parent['name'] = ona_build_domain_name($parent['id']);
                $record['domain'] = $pdomain['name'] . '.' . $parent['name'];
                unset($parent['name']);
            }
            // strip down the IP to just the "host" part as it relates to the domain its in
            if (strstr($record['domain'], 'in-addr.arpa')) {
                $domain_part = preg_replace("/.in-addr.arpa\$/", '', $record['domain']);
            } else {
                $domain_part = preg_replace("/.ip6.arpa\$/", '', $record['domain']);
            }
            $record['name'] = preg_replace("/{$domain_part}\$/", '', $record['name']);
            $data = <<<EOL
                    <a title="Edit DNS A record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');"
                    >{$pointsto['name']}</a>.<a title="View domain. ID: {$pointsto['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$pointsto['domain_id']}\\', \\'display\\')');"
                    >{$pointsto['domain_fqdn']}</a>.&nbsp;
EOL;
        }
        // Process CNAME record
        if ($record['type'] == 'CNAME') {
            list($status, $rows, $cname) = ona_get_dns_record(array('id' => $record['dns_id']), '');
            $data = <<<EOL
                    <a title="Edit DNS A record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');"
                    >{$cname['name']}</a>.<a title="View domain. ID: {$cname['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$cname['domain_id']}\\', \\'display\\')');"
                    >{$cname['domain_fqdn']}</a>.&nbsp;
EOL;
        }
        // Process NS record
        if ($record['type'] == 'NS') {
            // clear out the $record['domain'] value so it shows properly in the list
            $record['name'] = '';
            list($status, $rows, $ns) = ona_get_dns_record(array('id' => $record['dns_id']), '');
            $data = <<<EOL
                    <a title="Edit DNS A record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');"
                    >{$ns['name']}</a>.<a title="View domain. ID: {$ns['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$ns['domain_id']}\\', \\'display\\')');"
                    >{$ns['domain_fqdn']}</a>.&nbsp;
EOL;
        }
        // Process MX record
        if ($record['type'] == 'MX') {
            // show the preference value next to the type
            $record['type'] = "{$record['type']} ({$record['mx_preference']})";
            list($status, $rows, $mx) = ona_get_dns_record(array('id' => $record['dns_id']), '');
            $data = <<<EOL
                    <a title="Edit DNS A record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');"
                    >{$mx['name']}</a>.<a title="View domain. ID: {$mx['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$mx['domain_id']}\\', \\'display\\')');"
                    >{$mx['domain_fqdn']}</a>.&nbsp;
EOL;
        }
        // Process SRV record
        if ($record['type'] == 'SRV') {
            // show the preference value next to the type
            $record['type'] = "{$record['type']} ({$record['srv_port']})";
            list($status, $rows, $srv) = ona_get_dns_record(array('id' => $record['dns_id']), '');
            $data = <<<EOL
                    <a title="Edit DNS A record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', 'dns_record_id=>{$record['dns_id']}', 'editor');"
                    >{$srv['name']}</a>.<a title="View domain. ID: {$srv['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$srv['domain_id']}\\', \\'display\\')');"
                    >{$srv['domain_fqdn']}</a>.&nbsp;
EOL;
        }
        // Process TXT record
        if ($record['type'] == 'TXT') {
            // some records will have an interfaceid and dnsid when associated to another dns name
            // some will just be un associated txt records or domain only records.  Determine that here and
            // display appropriately.  This is to ensure associated DNS records match up if the name changes
            if ($record['interface_id'] and $record['dns_id']) {
                list($status, $rows, $txtmain) = ona_get_dns_record(array('id' => $record['dns_id']), '');
                $record['name'] = $txtmain['name'] . '.';
            }
            $data = truncate($record['txt'], 70);
        }
        // Get the domain name and domain ttl
        $ttl_style = 'title="Time-to-Live"';
        list($status, $rows, $domain) = ona_get_domain_record(array('id' => $record['domain_id']));
        // Make record['domain'] have the right name in it
        if ($record['type'] != 'PTR') {
            $record['domain'] = $domain['fqdn'];
        }
        // clear out the $record['domain'] value so it shows properly in the list for NS records
        if ($record['type'] == 'NS') {
            $record['domain'] = $domain['fqdn'];
        }
        // if the ttl is blank, use the one in the domain (minimum)
        if ($record['ttl'] == 0) {
            $record['ttl'] = $domain['default_ttl'];
            $ttl_style = 'style="font-style: italic;" title="Using TTL from domain"';
        }
        // format the ebegin using the configured date format
        $ebegin = '';
        // If it is in the future, print the time
        if (strtotime($record['ebegin']) > time()) {
            $ebegin = '<span title="Active in DNS on: ' . $record['ebegin'] . '">' . date($conf['date_format'], strtotime($record['ebegin'])) . '</span>';
        }
        // If it is 0 then show as disabled
        if (strtotime($record['ebegin']) < 0) {
            $ebegin = <<<EOL
                <span
                    style="background-color:#FFFF99;"
                    title="Disabled: Won't build in DNS"
                    onClick="var doit=confirm('Are you sure you want to enable this DNS record?');
                                if (doit == true)
                                    xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'enablerecord');"
                >Disabled</span>
EOL;
        }
        // If we get this far and the name we have built has a leading . in it then remove the dot.
        $record['name'] = preg_replace("/^\\./", '', $record['name']);
        // Get the name of the view and the description
        if ($conf['dns_views']) {
            list($status, $rows, $dnsview) = ona_get_dns_view_record(array('id' => $record['dns_view_id']));
            $record['view_name'] = $dnsview['name'];
            $record['view_desc'] = $dnsview['description'];
        }
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        //$primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_host\', \'host_id=>{$record['id']}\', \'display\')');";
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';">
                <td class="list-row" style="padding-right: 2px; padding-left: 4px;" width="16px">
                {$primary_record}
                </td>

                <td class="list-row">
                    <span title="Record. ID: {$record['id']}"
                       onClick=""
                    >{$record['name']}</span
                    ><a title="View domain. ID: {$domain['id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$domain['id']}\\', \\'display\\')');"
                    >{$record['domain']}.</a>
                </td>

                <td class="list-row">
                    <span
                       onClick=""
                       {$ttl_style}
                    >{$record['ttl']} seconds</span>&nbsp;
                </td>

                <td class="list-row">
                    <span title="Record Type"
                       onClick=""
                    >{$record['type']}</span>&nbsp;
                </td>

                <td class="list-row" align="left">
EOL;
        // Put the data in!
        $html .= $data;
        $html .= <<<EOL
                </td>

                <td class="list-row" align="center">
                    {$ebegin}&nbsp;
                </td>
EOL;
        // Display the view we are part of
        if ($conf['dns_views']) {
            $html .= <<<EOL
                <td class="list-row" align="center" title="{$record['view_desc']}">
                    {$record['view_name']}&nbsp;
                </td>
EOL;
        }
        $html .= <<<EOL
                <td class="list-row">
                    <span title="{$record['notes']}">{$record['notes_short']}</span>&nbsp;
                </td>

                <!-- ACTION ICONS -->
                <td class="list-row" align="right">
                    <form id="{$form['form_id']}_list_record_{$record['id']}"
                        ><input type="hidden" name="dns_record_id" value="{$record['id']}"
                        ><input type="hidden" name="host_id" value="{$host['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>&nbsp;
EOL;
        if (auth('dns_record_modify')) {
            // If it is an A record but not the primary, display an option to make it primary. and only if we are dealing with a specific host
            if (($record['type'] == 'A' or $record['type'] == 'AAAA') and $host['primary_dns_id'] != $record['id'] and $form['host_id']) {
                $html .= <<<EOL

                    <a title="Make this the primary DNS record"
                       class="act"
                       onClick="var doit=confirm('Are you sure you want to make this the primary DNS record for this host?');
                                if (doit == true)
                                    xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'makeprimary');"
                    ><img src="{$images}/silk/font_go.png" border="0"></a>
EOL;
            }
        }
        // display a view host button on the dns record search form list
        if ($form['search_form_id'] == 'dns_record_search_form') {
            $html .= <<<EOL

                    <a title="View associated host record: {$interface['host_id']}"
                       class="act"
                       onClick="xajax_window_submit('display_host', 'host_id=>{$interface['host_id']}', 'display');"
                    ><img src="{$images}/silk/computer_go.png" border="0"></a>&nbsp;
EOL;
        }
        if (auth('dns_record_modify')) {
            $html .= <<<EOL

                    <a title="Edit DNS record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
EOL;
        }
        if (auth('dns_record_del')) {
            $html .= <<<EOL

                    <a title="Delete DNS record"
                       class="act"
                       onClick="xajax_window_submit('edit_record', xajax.getFormValues('{$form['form_id']}_list_record_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/delete.png" border="0"></a>
EOL;
        }
        $html .= <<<EOL
                    &nbsp;
                </td>

            </tr>
EOL;
        // reset the record counter before we go back for the next iteration
        $last_record = array('name' => $record['name'], 'domain_id' => $record['domain_id']);
        $last_record_count = 1;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #22
0
function ws_display_list($window_name, $form)
{
    global $conf, $self, $mysql, $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']};">Server name</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Domain count</td>
            <td class="list-header" align="center">&nbsp;</td>
        </tr>
        
EOL;
    $where = 'id in (select host_id from dns_server_domains group by host_id)';
    if (is_array($form) and $form['filter']) {
        //$where = 'name 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, 'hosts', $where, '', $conf['search_results_per_page'], $offset);
    //$records = array_unique(array_slice($dnsservers,1,1));
    // 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, $tmp) = db_get_records($onadb, 'hosts', $where, '', 0);
        }
    }
    $count = $rows;
    // Loop through and display
    foreach ($records as $record) {
        list($status, $rows, $dns) = ona_get_dns_record(array('id' => $record['primary_dns_id']));
        $record['fqdn'] = $dns['fqdn'];
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        list($status, $usage_rows, $tmp) = db_get_records($onadb, 'dns_server_domains', "host_id = {$record['id']}", '', 0);
        $html .= <<<EOL
        <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
            <form id="{$form['form_id']}_list_domain_{$record['id']}"
                    ><input type="hidden" name="id" value="{$record['id']}"
                    ><input type="hidden" name="js" value="{$refresh}"
            ></form>

            <td class="list-row">
                <a title="View DNS server. ID: {$record['id']}"
                   class="act"
                   onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain_server\\', \\'host_id=>{$record['id']}\\', \\'display\\')');"
                >{$record['fqdn']}</a>&nbsp;
            </td>

            <td class="list-row">
                {$usage_rows}
            </td>
            
            <td align="right" class="list-row" nowrap="true">
                <a title="View DNS server. ID: {$record['id']}"
                    class="act"
                    onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain_server\\', \\'host_id=>{$record['id']}\\', \\'display\\')');"
                ><img src="{$images}/silk/zoom.png" border="0"></a>&nbsp;

            </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_domain_{$record['id']}"
                ><input type="hidden" name="js" value="{$refresh}"
        ></form>
        <!-- ADD domain LINK -->
        <a title="New DNS domain"
            class="act"
            onClick="xajax_window_submit('edit_domain', xajax.getFormValues('{$form['form_id']}_add_domain_{$record['id']}'), 'editor');"
        ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

        <a title="New DNS domain"
            class="act"
            onClick="xajax_window_submit('edit_domain', xajax.getFormValues('{$form['form_id']}_add_domain_{$record['id']}'), 'editor');"
        >Add DNS domain</a>&nbsp;

        <!-- ADD server LINK -->
        <a title="New DNS server"
            class="act"
            onClick="xajax_window_submit('edit_domain_server', xajax.getFormValues('{$form['form_id']}_add_domain_{$record['id']}'), 'editor');"
        ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

        <a title="New DNS server"
            class="act"
            onClick="xajax_window_submit('edit_domain_server', xajax.getFormValues('{$form['form_id']}_add_domain_{$record['id']}'), 'editor');"
        >Add DNS server</a>&nbsp;
    </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']}_domain_count", "innerHTML", "({$count})");
    $response->addAssign("{$form['content_id']}", "innerHTML", $html);
    // $response->addScript($js);
    return $response->getXML();
}
예제 #23
0
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);
    // 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'] = 'ONA DB logs';
        array_push($_SESSION['ona']['work_space']['history'], $history);
    }
    // Create some javascript to refresh the current page
    $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
    $refresh = "xajax_window_submit('work_space', '{$refresh}');";
    $style['content_box'] = <<<EOL
        margin: 10px 20px;
        padding: 2px 4px;
        background-color: #FFFFFF;
        vertical-align: top;
EOL;
    $style['label_box'] = <<<EOL
        font-weight: bold;
        padding: 2px 4px;
        border: solid 1px {$color['border']};
        background-color: {$color['window_content_bg']};
EOL;
    // Escape data for display in html
    foreach (array_keys((array) $record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    $html .= <<<EOL
    <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;
    // LOG INFORMATION
    $logstat = $conf['log_to_db'] ? "<img src=\"{$images}/silk/accept.png\" border=\"0\"> Enabled" : "<img src=\"{$images}/silk/stop.png\" border=\"0\"> Disabled";
    $html .= <<<EOL
            <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">

                <tr>
                    <td align="right" nowrap="true"><b>System DB logging status:</b>&nbsp;</td>
                    <td>
                        <div style="border: 1px solid #555555;cursor: pointer;padding: 2px;"
                             onmouseover="this.style.backgroundColor='#EBEBEB';"
                             onmouseout="this.style.backgroundColor='#FFFFFF';"
                             title="Click to change"
                             onClick="xajax_window_submit('app_sysconf_edit', 'log_to_db', 'editor');">
                             {$logstat}&nbsp;
                        </div>
                    </td>
                </tr>


            </table>
EOL;
    // END LOG INFORMATION
    $html .= <<<EOL
        <!-- END OF FIRST COLUMN OF SMALL BOXES -->
        </td>
      </tr></table>
    </div>
EOL;
    // LIST
    $tab = 'ona_db_logs';
    $submit_window = "list_{$tab}";
    $form_id = "{$submit_window}_filter_form";
    $_SESSION['ona'][$form_id]['tab'] = $tab;
    $content_id = "{$window_name}_{$submit_window}";
    $html .= <<<EOL
    <!-- VLAN 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">
                    Log entries <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="vlan_campus_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();"
                    >Username</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;
    $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();
}
예제 #24
0
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();
}
예제 #25
0
function ws_draw_block($window_name, $form = '')
{
    global $conf, $self, $ona;
    global $images, $color, $style;
    $html = '';
    $js = '';
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Find out if $ip is valid
    $ip = ip_mangle($form['ip'], 'numeric');
    if ($ip == -1) {
        $js .= "alert('Invalid IP address!');";
        $response->addScript($js);
        return $response->getXML();
    }
    // Build a few variables
    $label = ip_mangle($ip, 'dotted');
    if (is_ipv4($ip)) {
        $string_size = 15;
    } else {
        $string_size = 20;
    }
    $function = "get_{$form['row_type']}_html";
    $row_zoom = $form['row_zoom'];
    $row_height = $form['row_height'];
    $row_offset = $form['row_offset'];
    // This is the number of pixels to leave for the label on the left (.45 * row height, * $string_size possible characters)
    $label_width = round($form['row_height'] * 0.45 * $string_size);
    $font_height = $form['row_height'] - 2;
    // Label font-size
    if ($font_height < 8) {
        $font_height = 8;
    }
    $row_left = $label_width + 10;
    // Left offset for the block row
    // Get some html (the html that goes inside the div)
    $html = $function($ip, $row_zoom, $row_height);
    $el_name = $ip . '_row';
    // Add a row label
    $response->addCreate("{$window_name}_substrate", "div", $el_name . '_label');
    $response->addScript(<<<EOL
        var _el = el('{$el_name}_label');
        _el.style.visibility = 'hidden';
        _el.style.position = 'absolute';
        _el.style.textAlign = 'right';
        _el.style.color = '#000000';
        _el.style.fontSize = '{$font_height}px';
        _el.style.top  = '{$row_offset}px';
        _el.style.left = '2px';
        _el.style.width = '{$label_width}px';
        _el.style.overflow = 'visible';
        _el.style.whiteSpace = 'nowrap';
EOL
);
    // Add the row
    $response->addCreate("{$window_name}_substrate", "div", $el_name);
    $response->addScript(<<<EOL
        var _el = el('{$el_name}');
        _el.style.visibility = 'hidden';
        _el.style.position = 'absolute';
        _el.style.top  = '{$row_offset}px';
        _el.style.left = '{$row_left}px';
        _el.style.borderTop    = '1px solid #000000';
        _el.style.borderBottom = '1px solid #000000';
        _el.style.borderLeft   = '1px solid #000000';
        if (browser.isIE)
            _el.style.fontSize = ({$font_height} - 2) + 'px';
EOL
);
    // Fill the label and row
    $response->addAssign($el_name, "innerHTML", $html);
    $response->addAssign($el_name . '_label', "innerHTML", $label);
    // Javascript to make sure the container (row) div is the exact length to hold it's contents in one row
    $response->addScript(<<<EOL
        var nodes = _el.childNodes;
        var width = 0;
        for (var counter=0; counter < nodes.length; counter++)
            if (nodes[counter].nodeType == 1)
                width += parseInt(nodes[counter].offsetWidth);
        if (browser.isIE) width += 1; /* for the left border */
        _el.style.width = width + 'px';
EOL
);
    // Display the label and block
    $response->addScript(<<<EOL
        el('{$el_name}_label').style.visibility = 'visible';
        el('{$el_name}').style.visibility = 'visible';
        /* Tell the browser we've sent it this block so it knows it can re-request it if it needs to */
        _map_requests_['{$el_name}'] = undefined;
EOL
);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #26
0
function ws_vlan($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $color, $style, $images;
    $html = $js = '';
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Set max_results and max_usage_bars if we need to
    if (!is_numeric($form['max_results'])) {
        $form['max_results'] = 250;
    }
    //
    // *** QF VLAN SEARCH ***
    //
    // Get the specified VLAN Campus record by name
    // If it isn't exact, don't accept it.
    list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $form['campus']));
    if ($status or !$rows) {
        // Send a javascript popup error
        $response = new xajaxResponse();
        $response->addScript("alert('ERROR => Invalid VLAN campus!');");
        return $response->getXML();
    }
    // Get a list of vlan's in the selected campus
    list($status, $count, $results) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), 'number', $form['max_results']);
    // If there were more than $form['max_results'] find out how many records there really are
    if ($count >= $form['max_results']) {
        list($status, $count, $tmp) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), '', 0);
    }
    //
    // *** BUILD RESULTS HTML ***
    //
    $html .= <<<EOL
<table style="cursor: pointer;" width="100%" cellspacing="0" border="0" cellpadding="0">
    <!-- The "None" option.. they need to be able to de-select a vlan -->
    <tr onMouseOver="this.className='row-highlight';"
        onMouseOut="this.className='row-normal';"
        onClick="el('{$form['input_id']}').value = ''; el('{$form['text_id']}').innerHTML = 'None'; removeElement('{$form['id']}');">
        <td style="font-size: 10px; padding: 0px 2px;">None (i.e. no vlan)</td>
    </tr>
EOL;
    if ($count > $form['max_results']) {
        $html .= <<<EOL
<tr><td style="cursor: default; font-size: 12px; background-color: #FFCCCC; color: 000;" colspan="5" align="center">Displaying {$form['max_results']} of {$count} results</td></tr>
EOL;
    }
    $campus['name'] = htmlentities($campus['name'], ENT_QUOTES, $conf['php_charset']);
    foreach ($results as $record) {
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
<tr onMouseOver="this.className='row-highlight';"
    onMouseOut="this.className='row-normal';"
    onClick="el('{$form['input_id']}').value = '{$record['id']}'; el('{$form['text_id']}').innerHTML = '{$campus['name']} / {$record['name']}'; removeElement('{$form['id']}');">
    <td style="font-size: 10px; padding: 0px 2px;">{$campus['name']} / [{$record['number']}] {$record['name']}</td>
</tr>
EOL;
    }
    $html .= <<<EOL
</table>
EOL;
    $js .= <<<EOL
        el('{$form['content_id']}').style.display = 'block';
        /* Reposition the popup if the new content is displayed off the screen */
        wwTT_position('{$form['id']}');
EOL;
    // Insert the new html into the window
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #27
0
function ws_editor($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();
    }
    // Set a few parameters for the "results" window we're about to create
    $window = array('title' => 'DNS View Editor', 'html' => '', 'js' => '');
    $window['js'] .= <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<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 =
            '&nbsp;<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;
EOL;
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    // If we got a view, load it for display
    if (is_numeric($form['id'])) {
        list($status, $rows, $record) = db_get_record($onadb, 'dns_views', array('id' => $form['id']));
    }
    // Escape data for display in html
    foreach (array_keys((array) $record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Load some html into $window['html']
    $window['html'] .= <<<EOL

    <!-- Simple class types Edit Form -->
    <form id="dns_view_edit_form" onSubmit="return false;">
    <input name="id" type="hidden" value="{$record['id']}">
    <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 class="input_required" align="right">
                Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="dns_view_name"
                    alt="DNS View Name"
                    value="{$record['name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="64"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right">
                Description
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="dns_view_description"
                    alt="DNS View Description"
                    value="{$record['description']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="64"
                >
            </td>
        </tr>

        <tr>
            <td align="right" valign="top">
                &nbsp;
            </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('dns_view_edit_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>

EOL;
    // Lets build a window and display the results
    return window_open($window_name, $window);
}
예제 #28
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Override system default for lists.. we want logs to show more
    $conf['search_results_per_page'] = 20;
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    // Start building the "where" clause for the sql query to find the vlans to display
    $where = "";
    $and = "";
    // DISPLAY ALL VLAN CAMPUSES
    if ($form['all_flag']) {
        $where .= $and . "id > 0";
        $and = " AND ";
    }
    // CAMPUS ID
    if ($form['id']) {
        $where .= $and . "id = " . $onadb->qstr($form['id']);
        $and = " AND ";
    }
    // CAMPUS NAME
    if ($form['username']) {
        $where .= $and . " username LIKE " . $onadb->qstr('%' . $form['username'] . '%');
        $and = " AND ";
    }
    // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything.
    if ($where == '') {
        $where = 'id > 0';
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        $filter = ' AND username LIKE ' . $onadb->qstr('%' . $form['filter'] . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'ona_logs', $where . $filter, "timestamp DESC", $conf['search_results_per_page'], $offset);
    // If we got less than search_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $records) = db_get_records($onadb, 'ona_logs', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    $html .= <<<EOL
        <!-- List -->
        <table id="{$form['form_id']}_ona_db_logs_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};">Timestamp</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Username</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Remote location</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Context</td>
                <td class="list-header" align="center">Message</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

                <td class="list-row">
                    {$record['timestamp']}&nbsp;
                </td>

                <td class="list-row" align="left">
                    {$record['username']}
                </td>

                <td class="list-row">
                    {$record['remote_addr']}&nbsp;
                </td>

                <td class="list-row">
                    {$record['context_name']}&nbsp;
                </td>

                <td class="list-row">
                    {$record['message']}&nbsp;
                </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();
}
예제 #29
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If this is the display_host screen that called, add refresh for DNS records too
    if ($form['content_id'] == 'display_host_list_interfaces') {
        $refresh .= "xajax_window_submit('list_records', xajax.getFormValues('list_records_filter_form'), 'display_list');";
    }
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    // Start building the "where" clause for the sql query to find the interfaces to display
    $where = "";
    $and = "";
    // HOST ID
    if ($form['host_id']) {
        $where .= $and . "host_id = " . $onadb->qstr($form['host_id']) . " OR id in (select interface_id from interface_clusters where host_id = " . $onadb->qstr($form['host_id']) . ")";
        $and = " AND ";
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        $form['filter'] = ip_mangle($form['filter']);
        $filter = $and . ' ip_addr LIKE ' . $onadb->qstr('%' . $form['filter'] . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'interfaces', $where . $filter, "ip_addr ASC", $conf['search_results_per_page'], $offset);
    // If we got less than serach_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    }
    // Re-Count only "internal" interfaces, not nat interfaces
    list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'nat_interface_id = \'0\' and ' . $where . $filter, "", 0);
    $count = $rows;
    $html .= <<<EOL
        <!-- Interface List -->
        <table id="{$form['form_id']}_interface_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>

                <td colspan="2" class="list-header" align="center" style="{$style['borderR']};">Interface</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
                <td class="list-header" align="center" style="{$style['borderR']};">MAC</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Description</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Get additional info about each host record //
        // Check if this interface has an external NAT
        unset($extnatint, $extnatdisplay, $extnatdisplay, $extnatsubdisplay);
        if ($record['nat_interface_id'] > 0) {
            list($status, $rows, $extnatint) = ona_get_interface_record(array('id' => $record['nat_interface_id']));
            // GDO: get the subnet object of the NATing interface, display it in both Interface and Subnet columns
            list($status, $rows, $extnatintsub) = ona_get_subnet_record(array('id' => $extnatint['subnet_id']));
            $extnatint['ip_addr'] = ip_mangle($extnatint['ip_addr'], 'dotted');
            //$extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']}'> &nbsp;&nbsp;=> &nbsp;{$extnatint['ip_addr']}</span>";
            $extnatdisplay = "<span title='Interface is NATed to {$extnatint['ip_addr']} (on {$extnatintsub['name']})'> &nbsp;&nbsp;=> &nbsp;{$extnatint['ip_addr']}</span>";
            $extnatsubdisplay = " => <a title=\"View NATed subnet. ID: {$extnatintsub['id']}\"\n                                            class=\"nav\"\n                                            onClick=\"xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$extnatintsub['id']}\\', \\'display\\')');\"\n                                         >{$extnatintsub['name']}</a>";
        }
        // Check if this interface is an external NAT for another interface
        list($isnatstatus, $isnatrows, $isnat) = db_get_records($onadb, 'interfaces', "nat_interface_id = {$record['id']}", '', 0);
        // If the current interface is external NAT for another, dont display it in the list.
        if ($isnatrows > 0) {
            continue;
        }
        list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$record['id']}");
        // Grab some info from the associated subnet record
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $record['subnet_id']));
        $record['ip_mask'] = $subnet['ip_mask'];
        $record['subnet_id'] = $subnet['id'];
        $record['subnet_description'] = $subnet['name'];
        // Convert IP and Netmask to a presentable format
        $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
        $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
        $record['ip_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr');
        if ($record['mac_addr']) {
            $record['mac_addr'] = mac_mangle($record['mac_addr']);
        }
        $record['description_short'] = truncate($record['description'], 40);
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        // Format the date and colorize if its older than 2 months
        if ($record['last_response']) {
            $record['last_response_fmt'] = date($conf['date_format'], strtotime($record['last_response']));
            if (strtotime($record['last_response']) < strtotime('-2 month')) {
                $record['last_response_fmt'] = "<span style=\"color: red;\">" . $record['last_response_fmt'] . "</style>";
            }
        }
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

                <td nowrap="true" class="list-row" style="padding: 0px;" width="16px">
EOL;
        // Display cluster related information
        $clusterhtml = '&nbsp;';
        $clusterstyle = '';
        $clusterscript = '';
        if ($intclusterrows > 0) {
            $clusterstyle = 'font-weight: bold';
            $clusterscript = "onMouseOver=\"wwTT(this, event,\n                        'id', 'tt_interface_cluster_list_{$record['id']}',\n                        'type', 'velcro',\n                        'styleClass', 'wwTT_niceTitle',\n                        'direction', 'south',\n                        'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$record['id']},interface_id=>{$record['id']}\\');'\n                        );\"";
            $clusterhtml .= <<<EOL
                    <img src="{$images}/silk/sitemap.png" border="0" {$clusterscript} />
EOL;
        }
        $html .= $clusterhtml;
        $html .= <<<EOL
                </td>

                <td class="list-row">
EOL;
        // MP: Disabling the display_interface link. I dont think this will be needed
        if (1 < 0) {
            $html .= <<<EOL
                    <a title="View interface. ID: {$record['id']}"
                       class="nav"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_interface\\',\\'interface_id=>{$record['id']}\\', \\'display\\')');">
                        {$record['ip_addr']}
                        </a>
EOL;
        } else {
            $html .= "<span style='{$clusterstyle}' {$clusterscript}>{$record['ip_addr']}</span>";
        }
        $html .= <<<EOL
                    <span style="{$clusterstyle}" title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span> {$extnatdisplay}
                </td>

                <td class="list-row" align="left">
                    <a title="View subnet. ID: {$subnet['id']}"
                       class="nav"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$subnet['id']}\\', \\'display\\')');"
                    >{$record['subnet_description']}</a> {$extnatsubdisplay}
                </td>

                <td class="list-row" align="right">
                    {$record['mac_addr']}&nbsp;
                </td>

                <td class="list-row" align="left">
                    {$record['name']}&nbsp;
                </td>

                <td class="list-row" align="left" title="{$record['description']}">
                    {$record['description_short']}&nbsp;
                </td>

                <td class="list-row" align="left" title="{$record['last_response']}">
                    {$record['last_response_fmt']}&nbsp;
                </td>

                <td class="list-row" align="right">
                    <form id="{$form['form_id']}_list_interface_{$record['id']}"
                        ><input type="hidden" name="interface_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>&nbsp;
EOL;
        if (auth('interface_modify')) {
            $html .= <<<EOL

                    <a title="Interface Menu"
                       id="int_menu_button_{$record['id']}"
                       class="act"
                       onmouseover="wwTT(this, event,
                                            'id', 'tt_quick_interface_menu_{$record['id']}',
                                            'type', 'velcro',
                                            'delay', 0,
                                            'styleClass', 'wwTT_int_menu',
                                            'lifetime', 1000,
                                            'direction', 'west',
                                            'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>quick_interface_menu,id=>tt_quick_interface_menu_{$record['id']},interface_id=>{$record['id']},ip_addr=>{$record['ip_addr']},orig_host=>{$record['host_id']},form_id=>{$form['form_id']}_list_interface_{$record['id']},subnet_id=>{$subnet['id']},natip=>{$record['nat_interface_id']}\\');'
                                           );"
                    ><img src="{$images}/silk/add.png" border="0"></a>&nbsp;
EOL;
        }
        if (auth('interface_modify')) {
            $html .= <<<EOL

                    <a title="Edit interface. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
EOL;
        }
        if (auth('interface_del')) {
            $html .= <<<EOL

                    <a title="Delete interface"
                       class="act"
                       onClick="xajax_window_submit('edit_interface', xajax.getFormValues('{$form['form_id']}_list_interface_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
EOL;
        }
        $html .= <<<EOL
                </td>

            </tr>
EOL;
    }
    if ($count == 0 and $form['host_id'] and !$form['filter']) {
        $html .= <<<EOL
     <tr><td colspan="99" align="center" style="color: red;">Please add an interface to this host, or delete the host</td></tr>
EOL;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
예제 #30
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    printmsg("DEBUG => Displaying subnets list page: {$page}", 1);
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    //
    // *** ADVANCED SUBNET SEARCH ***
    //       FIND RESULT SET
    //
    // Start building the "where" clause for the sql query to find the subnets to display
    $where = "";
    $and = "";
    // enable or disable wildcards
    $wildcard = '%';
    if ($form['nowildcard']) {
        $wildcard = '';
    }
    // DISPLAY ALL
    if ($form['all_flag']) {
        $where .= $and . "id > 0";
        $and = " AND ";
    }
    // SUBNET ID
    if ($form['subnet_id']) {
        $where .= $and . "id = " . $form['subnet_id'];
        $and = " AND ";
    }
    // VLAN ID
    if ($form['vlan_id']) {
        $where .= $and . "vlan_id = " . $onadb->qstr($form['vlan_id']);
        $and = " AND ";
    }
    // SUBNET TYPE
    if ($form['nettype']) {
        $where .= $and . "subnet_type_id = " . $onadb->qstr($form['nettype']);
        $and = " AND ";
    }
    // find subnets that are associated with dhcp server
    if ($form['server_id']) {
        $where .= $and . "id IN (SELECT subnet_id FROM dhcp_server_subnets WHERE host_id = " . $onadb->qstr($form['server_id']) . ')';
        $and = " AND ";
    }
    // SUBNET NAME
    if ($form['subnetname']) {
        // This field is always upper case
        $form['subnetname'] = strtoupper($form['subnetname']);
        $where .= $and . "name LIKE " . $onadb->qstr($wildcard . $form['subnetname'] . $wildcard);
        $and = " AND ";
    }
    // IP ADDRESS
    if ($form['ip_subnet']) {
        // Build $ip and $ip_end from $form['ip_subnet'] and $form['ip_subnet_thru']
        $ip = ip_complete($form['ip_subnet'], '0');
        if ($form['ip_subnet_thru']) {
            $ip = ip_complete($form['ip_subnet'], '0');
            $ip_end = ip_complete($form['ip_subnet_thru'], '255');
            // Find out if $ip and $ip_end are valid
            $ip = ip_mangle($ip, 'numeric');
            $ip_end = ip_mangle($ip_end, 'numeric');
            if ($ip != -1 and $ip_end != -1) {
                // Find subnets between the specified ranges
                $where .= $and . " ip_addr >= " . $ip . " AND ip_addr <= " . $ip_end;
                $and = " AND ";
            }
        } else {
            list($status, $rows, $record) = ona_find_subnet($ip);
            if ($rows) {
                $where .= $and . " id = " . $record['id'];
                $and = " AND ";
            }
        }
    }
    // tag
    if ($form['tag_net']) {
        $where .= $and . "id in (select reference from tags where type like 'subnet' and name like " . $onadb->qstr($form['tag_net']) . ")";
        $and = " AND ";
    }
    // custom attribute type
    if ($form['custom_attribute_type_net']) {
        $where .= $and . "id in (select table_id_ref from custom_attributes where table_name_ref like 'subnets' and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type_net']) . "))";
        $and = " AND ";
        $cavaluetype = "and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type_net']) . ")";
    }
    // custom attribute value
    if ($form['ca_value_net']) {
        $where .= $and . "id in (select table_id_ref from custom_attributes where table_name_ref like 'subnets' {$cavaluetype} and value like " . $onadb->qstr($wildcard . $form['ca_value_net'] . $wildcard) . ")";
        $and = " AND ";
    }
    // display a nice message when we dont find all the records
    if ($where == '' and $form['content_id'] == 'search_results_list') {
        $js .= "el('search_results_msg').innerHTML = 'Unable to find subnets matching your query, showing all records';";
    }
    // Wild card .. if $where is still empty, add a 'ID > 0' to it so you see everything.
    if ($where == '') {
        $where = 'id > 0';
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        // Subnet namess are always upper case
        $form['filter'] = strtoupper($form['filter']);
        $filter = ' AND name LIKE ' . $onadb->qstr('%' . $form['filter'] . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'subnets', $where . $filter, "ip_addr", $conf['search_results_per_page'], $offset);
    // If we got less than search_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $records) = db_get_records($onadb, 'subnets', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    //
    // *** BUILD HTML LIST ***
    //
    $html .= <<<EOL
    <!-- Subnet Results -->
    <table id="{$form['form_id']}_subnet_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

        <!-- Table Header -->
        <tr>
            <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
            <td class="list-header" align="center">&nbsp;</td>
        </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Get additional info about eash subnet record //
        // Convert IP and Netmask to a presentable format
        $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
        $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
        $record['IP_SUBNET_MASK_CIDR'] = ip_mangle($record['ip_mask'], 'cidr');
        list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id']));
        $record['type'] = $type['display_name'];
        // Calculate the percentage of the subnet that's used (total size - allocated hosts - dhcp pool size)
        $usage_html = get_subnet_usage_html($record['id']);
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$record['id']}\\', \\'display\\')');";
        $html .= <<<EOL
        <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

            <td class="list-row">
                <a title="View subnet. ID: {$record['id']}"
                   class="nav"
                   onClick="{$primary_object_js}"
                >{$record['name']}</a>
            </td>

            <td class="list-row" align="left">
                {$record['ip_addr']} <span title="{$record['ip_mask']}">/{$record['IP_SUBNET_MASK_CIDR']}</span>&nbsp;
            </td>

            <td class="list-row" align="center" style="vertical-align: middle;">
                {$usage_html}
            </td>

            <td class="list-row" align="left">
                {$record['type']}&nbsp;
            </td>

            <td class="list-row" align="right">
                <form id="{$form['form_id']}_list_subnet_{$record['id']}"
                    ><input type="hidden" name="subnet_id" value="{$record['id']}"
                    ><input type="hidden" name="js" value="{$refresh}"
                ></form>

                <a title="Display subnet map"
                   class="act"
                   onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_block_map\\', \\'ip_block_start=>{$record['ip_addr']}\\', \\'display\\');');"
                ><img src="{$images}/silk/shape_align_left.png" border="0"></a>&nbsp;
EOL;
        if (auth('subnet_modify')) {
            $html .= <<<EOL

                <a title="Edit subnet"
                   class="act"
                   onClick="xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_subnet_{$record['id']}'), 'editor');"
                ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
EOL;
        }
        if (auth('subnet_del')) {
            $html .= <<<EOL

                <a title="Delete subnet"
                   class="act"
                   onClick="var doit=confirm('Are you sure you want to delete this subnet?');
                            if (doit == true)
                                xajax_window_submit('edit_subnet', xajax.getFormValues('{$form['form_id']}_list_subnet_{$record['id']}'), 'delete');"
                ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
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();
}