Example #1
0
function ona_find_device_type($search = "")
{
    global $self;
    // Validate input
    if ($search == "") {
        return array(1, 0, array());
    }
    // If it's numeric
    if (preg_match('/^\\d+$/', $search)) {
        // It's a number - do several sql queries and see if we can get a unique match
        list($status, $rows, $record) = ona_get_device_type_record(array('id' => $search));
        // If we got it, return it
        if ($status == 0 and $rows == 1) {
            printmsg("DEBUG => ona_find_device_type() found device_type record by id", 2);
            return array(0, $rows, $record);
        }
        /* PK: this was the original code...
           foreach (array('id', 'DEVICE_TYPE_ID', 'MANUFACTURER_ID') as $field) {
               list($status, $rows, $record) = ona_get_model_record(array($field => $search));
               // If we got it, return it
               if ($status == 0 and $rows == 1) {
                   printmsg("DEBUG => ona_find_device() found device record by $field", 2);
                   return(array(0, $rows, $record));
               }
           }*/
    }
    // It's a string - do several sql queries and see if we can get a unique match
    list($manufmodel, $role) = split("\\(", $search);
    list($manuf, $model) = split(", ", $manufmodel);
    $role = preg_replace(array('/\\(/', '/\\)/'), '', "{$role}");
    list($status, $rows, $manu) = ona_get_manufacturer_record(array('name' => $manuf));
    list($status, $rows, $rol) = ona_get_role_record(array('name' => $role));
    list($status, $rows, $record) = ona_get_model_record(array('name' => $model, 'manufacturer_id' => $manu['id']));
    if ($status == 0 and $rows == 1) {
        list($status, $rows, $record) = ona_get_device_type_record(array('model_id' => $record['id'], 'role_id' => $rol['id']));
    }
    // If we got it, return it
    if ($status == 0 and $rows == 1) {
        printmsg("DEBUG => ona_find_device_type() found device_type record by model name", 2);
        return array(0, $rows, $record);
    }
    // We didn't find it - return and error code, 0 matches, and an empty record.
    $self['error'] = "NOTICE => couldn't find a unique device_type record with specified search criteria";
    printmsg($self['error'], 2);
    return array(2, 0, array());
}
Example #2
0
function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $window = array();
    // Check permissions
    if (!(auth('host_modify') or auth('host_add'))) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    // Load an existing host record (and associated info) if $form is a host_id
    $host = array('fqdn' => '.', 'domain_fqdn' => $conf['dns_defaultdomain']);
    $interface = array();
    if (is_numeric($form['host_id'])) {
        list($status, $rows, $host) = ona_get_host_record(array('id' => $form['host_id']));
        if ($rows) {
            // Load associated INTERFACE record(s)
            list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $host['id']));
            list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id']));
            $interface['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted');
            if ($interface['mac_addr']) {
                $interface['mac_addr'] = mac_mangle($interface['mac_addr'], 2);
            }
            //FIXME: (PK) should not use numeric format specifier here!
        }
    } else {
        if (strlen($form['ip_addr']) > 1) {
            $interface['ip_addr'] = $form['ip_addr'];
        }
        if (strlen($form['hostname']) > 1) {
            $host['name'] = $form['hostname'];
        }
    }
    // Set the default security level if there isn't one
    if (!array_key_exists('lvl', $host)) {
        $host['lvl'] = $conf['ona_lvl'];
    }
    // Load a subnet record if we got passed a subnet_id
    if ($form['subnet_id']) {
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id']));
    }
    // Load a domain record if we got passed a domain_id
    if ($form['domain_id']) {
        list($status, $rows, $domain) = ona_get_domain_record(array('id' => $form['domain_id']));
        $host['domain_fqdn'] = $domain['fqdn'];
    }
    // If we dont have a domain_fqdn yet.. lets use the system default domain
    if (!$host['domain_fqdn']) {
        $host['domain_fqdn'] = $conf['dns_defaultdomain'];
    }
    // Build a device_types list
    list($status, $rows, $records) = db_get_records($onadb, 'device_types', 'id >= 1');
    $device_types = array();
    foreach ($records as $type) {
        list($status, $rows, $model) = ona_get_model_record(array('id' => $type['model_id']));
        list($status, $rows, $role) = ona_get_role_record(array('id' => $type['role_id']));
        list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
        $device_types[$type['id']] = "{$manufacturer['name']} {$model['name']} ({$role['name']})";
    }
    asort($device_types);
    list($status, $rows, $device) = ona_get_device_record(array('id' => $host['device_id']));
    list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_id']));
    $host['location'] = $location['reference'];
    $device_model_list = "<option value=\"\"></option>\n";
    foreach (array_keys((array) $device_types) as $id) {
        $device_types[$id] = htmlentities($device_types[$id]);
        $selected = '';
        if ($id == $device['device_type_id']) {
            $selected = 'SELECTED';
        }
        $device_model_list .= "<option value=\"{$id}\" {$selected}>{$device_types[$id]}</option>\n";
    }
    unset($device_types, $device, $manufacturer, $role, $model, $records);
    //Get the list of DNS views
    if ($conf['dns_views']) {
        list($status, $rows, $dnsviews) = db_get_records($onadb, 'dns_views', 'id >= 0', 'name');
        foreach ($dnsviews as $entry) {
            $selected = '';
            //$dnsviews['name'] = htmlentities($dnsviews['name']);
            // If this entry matches the record you are editing, set it to selected
            if ($host['id'] and $entry['id'] == $host['dns_view_id']) {
                $selected = "SELECTED=\"selected\"";
                $dns_view_name = $entry['name'] . '/';
            } elseif (!$host['id'] and $entry['id'] == 0) {
                // Otherwise use the default record if we are adding a new entry
                $selected = "SELECTED=\"selected\"";
                $dns_view_name = $entry['name'] . '/';
            }
            $dns_view_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['name']}</option>\n";
        }
    }
    // Escape data for display in html
    foreach (array_keys((array) $host) as $key) {
        $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $subnet) as $key) {
        $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $interface) as $key) {
        $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Set the window title:
    $window['title'] = "Add Host";
    if ($host['id']) {
        $window['title'] = "Edit Host";
    } else {
        unset($dns_view_name);
    }
    // Javascript to run after the window is built
    $window['js'] = <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&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;

        suggest_setup('set_domain_{$window_name}',    'suggest_set_domain_{$window_name}');
        suggest_setup('set_location_{$window_name}',  'suggest_set_location_{$window_name}');

        /* Setup the Quick Find location icon */

        var _button = el('qf_location_{$window_name}');
        _button.style.cursor = 'pointer';
        _button.onclick =
            function(ev) {
                if (!ev) ev = event;
                /* Create the popup div */
                wwTT(this, ev,
                     'id', 'tt_qf_location_{$window_name}',
                     'type', 'static',
                     'direction', 'south',
                     'delay', 0,
                     'styleClass', 'wwTT_qf',
                     'javascript',
                     "xajax_window_submit('tooltips', '" +
                         "tooltip=>qf_location," +
                         "id=>tt_qf_location_{$window_name}," +
                         "input_id=>set_location_{$window_name}');"
                );
            };

    el('set_host').focus();
EOL;
    // If we are modifying do not allow them to edit/change dns names.  this should only be done when creating a new host
    $hideit = '';
    if ($host['id']) {
        $hideit = 'style="display: none;"';
    }
    // Define the window's inner html
    $window['html'] = <<<EOL

    <!-- Host Edit Form -->
    <form id="{$window_name}_edit_form" onSubmit="return false;">
    <input type="hidden" name="host" value="{$dns_view_name}{$host['fqdn']}">
    <input type="hidden" name="interface" value="{$interface['id']}">
    <input type="hidden" name="js" value="{$form['js']}">
    <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">

        <!-- HOST RECORD -->
        <tr>
            <td align="left" nowrap="true">
                <b><u>Host Record</u></b>&nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                &nbsp;
            </td>
        </tr>
EOL;
    // Print a dns view selector
    if ($conf['dns_views']) {
        $window['html'] .= <<<EOL
        <tr {$hideit}>
            <td align="right" nowrap="true">
                DNS View
            </td>
            <td class="padding" align="left" width="100%">
                <select
                    id="dns_view_select"
                    name="set_view"
                    alt="DNS View"
                    class="edit"
                >{$dns_view_list}</select>
            </td>
        </tr>

EOL;
    }
    $window['html'] .= <<<EOL
        <tr {$hideit}>
            <td class="input_required" align="right" nowrap="true">
                DNS Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="set_host"
                    name="set_host"
                    alt="Hostname"
                    value="{$host['name']}"
                    class="edit"
                    type="text"
                    size="20" maxlength="64"
                >
            </td>
        </tr>

        <tr {$hideit}>
            <td class="input_required" align="right" nowrap="true">
                Domain
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="set_domain_{$window_name}"
                    name="set_domain"
                    alt="Domain name"
                    value="{$host['domain_fqdn']}"
                    class="edit"
                    type="text"
                    size="25" maxlength="64"
                >
                <div id="suggest_set_domain_{$window_name}" class="suggest"></div>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Device type
            </td>
            <td class="padding" align="left" width="100%">
                <select
                    name="set_type"
                    alt="Device type"
                    class="edit"
                >{$device_model_list}</select>
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Notes
            </td>
            <td class="padding" align="left" width="100%">
                <textarea name="set_notes" class="edit" cols="40" rows="1">{$host['notes']}</textarea>
            </td>
        </tr>
        <tr>
            <td align="right" nowrap="true">
                Location
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="set_location_{$window_name}"
                    name="set_location"
                    alt="Location"
                    value="{$host['location']}"
                    class="edit"
                    type="text"
                    size="7" maxlength="10"
                >
                <div id="suggest_set_location_{$window_name}" class="suggest"></div>
                <span id="qf_location_{$window_name}" title="Location Quick Search"><img src="{$images}/silk/find.png" border="0"/></span>
            </td>
        </tr>
EOL;
    // Display an interface edit section if it's a new host or there were exactly one interface.
    if (!$interfaces) {
        $window['js'] .= <<<EOL

        /* Setup the Quick Find for available IPs */
        var _button = el('qf_free_ip_{$window_name}');
        _button.style.cursor = 'pointer';
        _button.onclick =
            function(ev) {
                if (!ev) ev = event;
                /* Create the popup div */
                wwTT(this, ev,
                     'id', 'tt_qf_free_ip_{$window_name}',
                     'type', 'static',
                     'direction', 'south',
                     'delay', 0,
                     'styleClass', 'wwTT_qf',
                     'javascript',
                     "xajax_window_submit('tooltips', '" +
                         "tooltip=>qf_free_ip," +
                         "id=>tt_qf_free_ip_{$window_name}," +
                         "text_id=>associated_subnet_{$window_name}," +
                         "text_value=>" + el('associated_subnet_{$window_name}').innerHTML + "," +
                         "input_id=>set_ip_{$window_name}');"
                );
            };

EOL;
        $window['html'] .= <<<EOL

        <!-- FIRST INTERFACE -->
        <tr>
            <td align="left" nowrap="true">
                <b><u>Interface</u></b>&nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                &nbsp;
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Subnet
            </td>
            <td class="padding" align="left" width="100%" nowrap="true">
                <span id="associated_subnet_{$window_name}"
                >{$subnet['name']}</span>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                IP Address
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="set_ip_{$window_name}"
                    name="set_ip"
                    alt="IP Address"
                    value="{$interface['ip_addr']}"
                    class="edit"
                    type="text"
                    size="25" maxlength="64"
                >
                <span id="qf_free_ip_{$window_name}" title="Available IP Quick Search"><img src="{$images}/silk/find.png" border="0"/></span>
                <div id="suggest_set_ip_{$window_name}" class="suggest"></div>
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                MAC Address
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="set_mac"
                    alt="MAC Address"
                    value="{$interface['mac_addr']}"
                    class="edit"
                    type="text"
                    size="17" maxlength="17"
                >
                <a class="nav" onClick="this.style.display = 'none'; el('force_{$window_name}').style.display = browser.isIE ? 'block' : 'table-row';">More >></a>
            </td>
        </tr>

        <tr id="force_{$window_name}" style="display: none;">
            <td align="right" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="force"
                    alt="Allow duplicate MAC addresses"
                    type="checkbox"
                > Allow duplicate MAC addresses
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Interface name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="set_name"
                    alt="Interface name"
                    value="{$interface['name']}"
                    class="edit"
                    type="text"
                    size="17" maxlength="255"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Interface description
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="set_description"
                    alt="Interface description"
                    value="{$interface['description']}"
                    class="edit"
                    type="text"
                    size="25" maxlength="255"
                >
            </td>
        </tr>
EOL;
    }
    if (!$host['id']) {
        $window['html'] .= <<<EOL
        <td align="right" nowrap="true">
            Auto create PTR
        </td>
        <td class="padding" align="left" width="100%" nowrap>
            <input
                id="set_addptr"
                name="set_addptr"
                alt="Automaticaly create PTR record"
                type="checkbox"
                checked="1"
            />
        </td>
        <tr>
            <td align="right" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="keepadding"
                    alt="Keep adding more hosts"
                    type="checkbox"
                > Keep adding more hosts
            </td>
        </tr>

        <tr>
            <td colspan="2" class="padding" align="center" width="100%">
            <span id="statusinfo_{$window_name}" style="color: green;" ></span>
            </td>
        </tr>

EOL;
    }
    $window['html'] .= <<<EOL

        <tr>
            <td align="right" valign="top" nowrap="true">
                &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('{$window_name}_edit_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>
EOL;
    return window_open($window_name, $window);
}
Example #3
0
function ws_more_host_options($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    // Build custom attribute list
    list($status, $rows, $records) = db_get_records($onadb, 'custom_attribute_types', 'id >= 1', '');
    $custom_attribute_type_list = '<option value="">&nbsp;</option>\\n';
    foreach ($records as $record) {
        $custom_attribute_type_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n";
        unset($records, $ca);
    }
    // Build device model list
    list($status, $rows, $records) = db_get_records($onadb, 'models', 'id >= 1');
    $models = array();
    foreach ($records as $record) {
        list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $record['manufacturer_id']));
        $models[$record['id']] = "{$manufacturer['name']}, {$record['name']}";
    }
    asort($models);
    $device_model_list = '<option value="">&nbsp;</option>\\n';
    foreach (array_keys($models) as $id) {
        $models[$id] = htmlentities($models[$id]);
        $device_model_list .= "<option value=\"{$id}\">{$models[$id]}</option>\n";
    }
    unset($models, $model);
    // Build device type list
    list($status, $rows, $records) = db_get_records($onadb, 'roles', 'id >= 1', 'name');
    $device_role_list = '<option value="">&nbsp;</option>\\n';
    $record['name'] = htmlentities($record['name']);
    foreach ($records as $record) {
        $device_role_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n";
    }
    // Build device manufacturer list
    list($status, $rows, $records) = db_get_records($onadb, 'manufacturers', 'ID >= 1', 'name');
    $device_manufacturer_list = '<option value="">&nbsp;</option>\\n';
    $record['name'] = htmlentities($record['name']);
    foreach ($records as $record) {
        $device_manufacturer_list .= "<option value=\"{$record['id']}\">{$record['name']}</option>\n";
    }
    // Build the new HTML
    $html = <<<EOL
    <table cellspacing="0" border="0" cellpadding="0">
    <tr>
        <td align="right" class="asearch-line">
            <u>C</u>ustom attribute
        </td>
        <td align="left" class="asearch-line">
            <select id="custom_attribute_type" name="custom_attribute_type" class="edit" accesskey="c">
                {$custom_attribute_type_list}
            </select>
            <u>V</u>alue
            <input id="ca_value" name="ca_value" type="text" class="edit" size="15" accesskey="v" />
        </td>
    </tr>

    <tr>
        <td align="right" class="asearch-line">
            Device mode<u>l</u>
        </td>
        <td align="left" class="asearch-line">
            <select id="model" name="model" class="edit" accesskey="l">
                {$device_model_list}
            </select>
        </td>
    </tr>

    <tr>
        <td align="right" class="asearch-line">
            Device <u>t</u>ype Role
        </td>
        <td align="left" class="asearch-line">
            <select id="role" name="role" class="edit" accesskey="t">
                {$device_role_list}
            </select>
        </td>
    </tr>

    <tr>
        <td align="right" class="asearch-line">
            Device man<u>u</u>facturer
        </td>
        <td align="left" class="asearch-line">
            <select id="manufacturer" name="manufacturer" class="edit" accesskey="u">
                {$device_manufacturer_list}
            </select>
        </td>
    </tr>
    </table>
EOL;
    $js = "el('more_options_link').style.display = 'none';";
    // Insert the new html
    $response = new xajaxResponse();
    $response->addAssign("more_host_options", "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
Example #4
0
function host_display($options = "")
{
    global $conf, $self, $onadb;
    $text_array = array();
    // Version - UPDATE on every edit!
    $version = '1.04';
    printmsg("DEBUG => host_display({$options}) called", 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize options[verbose] (default is yes)
    $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
    // Return the usage summary if we need to
    if ($options['help'] or !$options['host']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

host_display-v{$version}
Displays a host record from the database

  Synopsis: host_display [KEY=VALUE] ...

  Required:
    host=NAME[.DOMAIN] or ID      hostname or ID of the host display

  Optional:
    verbose=[yes|no]              display additional info (yes)



EOM
);
    }
    // Find the host (and domain) record from $options['host']
    list($status, $rows, $host) = ona_find_host($options['host']);
    printmsg("DEBUG => Host: {$host['fqdn']}", 3);
    if (!$host['id']) {
        printmsg("DEBUG => Unknown host: {$options['host']}", 3);
        $self['error'] = "ERROR => Unknown host: {$options['host']}";
        return array(2, $self['error'] . "\n");
    }
    $text_array = $host;
    // Build text to return
    $text = "HOST RECORD ({$host['fqdn']})\n";
    $text .= format_array($host);
    // If 'verbose' is enabled, grab some additional info to display
    if ($options['verbose'] == 'Y') {
        // TODO: if it is a nat interface, maybe process that IP and make it visible?
        // Interface record(s)
        $i = 0;
        do {
            list($status, $rows, $interface) = ona_get_interface_record(array('host_id' => $host['id']));
            if ($rows == 0) {
                break;
            }
            $i++;
            $text .= "\nASSOCIATED INTERFACE RECORD ({$i} of {$rows})\n";
            $text .= format_array($interface);
            $text_array['interfaces'][$i] = $interface;
            unset($text_array['interfaces'][$i]['host_id']);
        } while ($i < $rows);
        $text_array['interface_count'] = $rows;
        // Device record
        list($status, $rows, $device) = ona_get_device_record(array('id' => $host['device_id']));
        if ($rows >= 1) {
            // Fill out some other device info
            list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id']));
            list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id']));
            list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id']));
            list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
            $device['device_type'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})";
            list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_id']));
            $text_array['location'] = $location;
            $text_array['device'] = $device;
            $text .= "\nASSOCIATED DEVICE RECORD\n";
            $text .= format_array($device);
        }
        // Tag records
        list($status, $rows, $tags) = db_get_records($onadb, 'tags', array('type' => 'host', 'reference' => $host['id']));
        if ($rows) {
            $text .= "\nASSOCIATED TAG RECORDS\n";
            foreach ($tags as $tag) {
                $text_array['tags'][] = $tag['name'];
                $text .= "  {$tag['name']}\n";
            }
        }
    }
    // Cleanup unused info
    unset($text_array['device_id']);
    unset($text_array['device']['asset_tag']);
    unset($text_array['device']['location_id']);
    unset($text_array['device']['serial_number']);
    // change the output format if other than default
    if ($options['format'] == 'json') {
        $text = $text_array;
    }
    if ($options['format'] == 'yaml') {
        $text = $text_array;
    }
    // Return the success notice
    return array(0, $text);
}
Example #5
0
function format_array($array = array())
{
    $text = '';
    foreach (array_keys($array) as $key) {
        // Make some data look pretty
        if ($key == 'ip_addr') {
            $array[$key] = ip_mangle($array[$key], 'dotted');
        } else {
            if ($key == 'ip_addr_start') {
                $array[$key] = ip_mangle($array[$key], 'dotted');
            } else {
                if ($key == 'ip_addr_end') {
                    $array[$key] = ip_mangle($array[$key], 'dotted');
                } else {
                    if ($key == 'ip_mask') {
                        $array[$key] = ip_mangle($array[$key]) . '  (/' . ip_mangle($array[$key], 'cidr') . ')';
                    } else {
                        if ($key == 'mac_addr') {
                            $array[$key] = mac_mangle($array[$key]);
                            if ($array[$key] == -1) {
                                $array[$key] = '';
                            }
                        } else {
                            if ($key == 'host_id') {
                                list($status, $rows, $host) = ona_find_host($array[$key]);
                                if ($host['id']) {
                                    $array[$key] = str_pad($array[$key], 20) . strtolower("({$host['fqdn']})");
                                }
                            } else {
                                if ($key == 'server_id') {
                                    list($status, $rows, $server) = ona_get_server_record(array('id' => $array[$key]));
                                    list($status, $rows, $host) = ona_find_host($server['host_id']);
                                    if ($host['id']) {
                                        $array[$key] = str_pad($array[$key], 20) . strtolower("({$host['fqdn']})");
                                    }
                                } else {
                                    if ($key == 'subnet_id') {
                                        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $array[$key]));
                                        if ($subnet['id']) {
                                            $array[$key] = str_pad($array[$key], 20) . strtoupper("({$subnet['name']})");
                                        }
                                    } else {
                                        if ($key == 'domain_id' or $key == 'primary_dns_domain_id') {
                                            list($status, $rows, $domain) = ona_get_domain_record(array('id' => $array[$key]));
                                            $array[$key] = str_pad($array[$key], 20) . strtolower("({$domain['fqdn']})");
                                        } else {
                                            if ($key == 'interface_id') {
                                                list($status, $rows, $interface) = ona_get_interface_record(array('id' => $array[$key]));
                                                $array[$key] = str_pad($array[$key], 20) . '(' . ip_mangle($interface['ip_addr'], 'dotted') . ')';
                                            } else {
                                                if ($key == 'device_type_id') {
                                                    list($status, $rows, $devtype) = ona_get_device_type_record(array('id' => $array[$key]));
                                                    if ($devtype['id']) {
                                                        list($status, $rows, $model) = ona_get_model_record(array('id' => $devtype['model_id']));
                                                        list($status, $rows, $role) = ona_get_role_record(array('id' => $devtype['role_id']));
                                                        list($status, $rows, $manu) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
                                                        $array[$key] = str_pad($array[$key], 20) . "({$manu['name']}, {$model['name']} ({$role['name']}))";
                                                    }
                                                } else {
                                                    if ($key == 'custom_attribute_type_id') {
                                                        list($status, $rows, $ca) = ona_get_custom_attribute_type_record(array('id' => $array[$key]));
                                                        if ($ca['id']) {
                                                            $array[$key] = str_pad($array[$key], 20) . "({$ca['name']})";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // Align columns
        if ($array[$key]) {
            $text .= str_pad("  {$key}", 30) . $array[$key] . "\n";
        }
    }
    // Return a nice string :)
    return $text;
}
Example #6
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();
}
Example #7
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();
}
Example #8
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 hosts list page: {$page}", 1);
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    //
    // *** ADVANCED HOST SEARCH ***
    //       FIND RESULT SET
    //
    // Start building the "where" clause for the sql query to find the hosts to display
    $where = "";
    $and = "";
    $orderby = "";
    $from = 'hosts h';
    // enable or disable wildcards
    $wildcard = '%';
    if ($form['nowildcard']) {
        $wildcard = '';
    }
    // DISPLAY ALL
    // MP: I dont think this is used.. remove it if you can
    if ($form['all_flag']) {
        $where .= $and . "h.id > 0";
        $and = " AND ";
    }
    // HOST ID
    if ($form['host_id']) {
        $where .= $and . "h.id = " . $onadb->qstr($form['host_id']);
        $and = " AND ";
    }
    // DEVICE ID
    if ($form['device_id']) {
        $where .= $and . "h.device_id = " . $onadb->qstr($form['device_id']);
        $and = " AND ";
    }
    // HOSTNAME
    if ($form['hostname']) {
        // Find the domain name piece of the hostname assuming it was passed in as an fqdn.
        // FIXME: MP this was taken from the ona_find_domain function. make that function have the option
        // to NOT return a default domain.
        // lets test out if it has a / in it to strip the view name portion
        $view['id'] = 0;
        if (strstr($form['hostname'], '/')) {
            list($dnsview, $form['hostname']) = explode('/', $form['hostname']);
            list($status, $viewrows, $view) = db_get_record($onadb, 'dns_views', array('name' => strtoupper($dnsview)));
            if (!$viewrows) {
                $view['id'] = 0;
            }
        }
        // Split it up on '.' and put it in an array backwards
        $parts = array_reverse(explode('.', $form['hostname']));
        // Find the domain name that best matches
        $name = '';
        $domain = array();
        foreach ($parts as $part) {
            if (!$rows) {
                if (!$name) {
                    $name = $part;
                } else {
                    $name = "{$part}.{$name}";
                }
                list($status, $rows, $record) = ona_get_domain_record(array('name' => $name));
                if ($rows) {
                    $domain = $record;
                }
            } else {
                list($status, $rows, $record) = ona_get_domain_record(array('name' => $part, 'parent_id' => $domain['id']));
                if ($rows) {
                    $domain = $record;
                }
            }
        }
        $withdomain = '';
        $hostname = $form['hostname'];
        // If you found a domain in the query, add it to the search, and strip the domain from the host portion.
        if (array_key_exists('id', $domain) and !$form['domain']) {
            $withdomain = "AND b.domain_id = {$domain['id']}";
            // Now find what the host part of $search is
            $hostname = str_replace(".{$domain['fqdn']}", '', $form['hostname']);
        }
        // If we have a hostname and a domain name then use them both
        if ($form['domain']) {
            list($status, $rows, $record) = ona_find_domain($form['domain']);
            if ($record['id']) {
                $withdomain = "AND b.domain_id = {$record['id']}";
            }
            // Now find what the host part of $search is
            $hostname = trim($form['hostname']);
        }
        // MP: Doing the many select IN statements was too slow.. I did this kludge:
        //  1. get a list of all the interfaces
        //  2. loop through the array and build a list of comma delimited host_ids to use in the final select
        list($status, $rows, $tmp) = db_get_records($onadb, 'interfaces a, dns b', "a.id = b.interface_id and b.name LIKE '{$wildcard}{$hostname}{$wildcard}' {$withdomain}");
        $commait = '';
        $hostids = '';
        foreach ($tmp as $item) {
            $hostids .= $commait . $item['host_id'];
            $commait = ',';
        }
        // Just look for the host itself
        list($status, $rows, $r) = ona_find_host($form['hostname']);
        if ($rows) {
            $hostids .= ',' . $r['id'];
        }
        // MP: this is the old, slow query for reference.
        //
        // TODO: MP this seems to be kinda slow (gee I wonder why).. look into speeding things up somehow.
        //       This also does not search for CNAME records etc.  only things with interface_id.. how to fix that issue.......?
        //        $where .= $and . "id IN (select host_id from interfaces where id in (SELECT interface_id " .
        //                                "  FROM dns " .
        //                                "  WHERE name LIKE '%{$hostname}%' {$withdomain} ))";
        // Trim off extra commas
        $hostids = trim($hostids, ",");
        // If we got a list of hostids from interfaces then use them
        if ($hostids) {
            $idqry = "h.id IN ({$hostids})";
        } else {
            $idqry = "";
        }
        $where .= $and . $idqry;
        $and = " AND ";
    }
    // DOMAIN
    if ($form['domain'] and !$form['hostname']) {
        // FIXME: does this clause work correctly?
        printmsg("FIXME: => Does \$form['domain'] work correctly in list_hosts.inc.php?", 2);
        // Find the domain name piece of the hostname.
        // FIXME: MP this was taken from the ona_find_domain function. make that function have the option
        // to NOT return a default domain.
        // Split it up on '.' and put it in an array backwards
        $parts = array_reverse(explode('.', $form['domain']));
        // Find the domain name that best matches
        $name = '';
        $domain = array();
        foreach ($parts as $part) {
            if (!$rows) {
                if (!$name) {
                    $name = $part;
                } else {
                    $name = "{$part}.{$name}";
                }
                list($status, $rows, $record) = ona_get_domain_record(array('name' => $name));
                if ($rows) {
                    $domain = $record;
                }
            } else {
                list($status, $rows, $record) = ona_get_domain_record(array('name' => $part, 'parent_id' => $domain['id']));
                if ($rows) {
                    $domain = $record;
                }
            }
        }
        if (array_key_exists('id', $domain)) {
            // Crappy way of writing the query but it makes it fast.
            $from = "(\nSELECT distinct a.*\nfrom hosts as a, interfaces as i, dns as d\nwhere a.id = i.host_id\nand i.id = d.interface_id\nand d.domain_id = " . $onadb->qstr($domain['id']) . "\n) h";
            $and = " AND ";
        }
    }
    // DOMAIN ID
    if ($form['domain_id'] and !$form['hostname']) {
        $where .= $and . "h.primary_dns_id IN ( SELECT id " . "  FROM dns " . "  WHERE domain_id = " . $onadb->qstr($form['domain_id']) . " )  ";
        $and = " AND ";
    }
    // MAC
    if ($form['mac']) {
        // Clean up the mac address
        $form['mac'] = strtoupper($form['mac']);
        $form['mac'] = preg_replace('/[^%0-9A-F]/', '', $form['mac']);
        // We do a sub-select to find interface id's that match
        $where .= $and . "h.id IN ( SELECT host_id " . "        FROM interfaces " . "        WHERE mac_addr LIKE " . $onadb->qstr($wildcard . $form['mac'] . $wildcard) . " ) ";
        $and = " AND ";
    }
    // IP ADDRESS
    $ip = $ip_end = '';
    if ($form['ip']) {
        // Build $ip and $ip_end from $form['ip'] and $form['ip_thru']
        $ip = ip_complete($form['ip'], '0');
        if ($form['ip_thru']) {
            $ip_end = ip_complete($form['ip_thru'], '255');
        } else {
            $ip_end = ip_complete($form['ip'], '255');
        }
        // Find out if $ip and $ip_end are valid
        $ip = ip_mangle($ip, 'numeric');
        $ip_end = ip_mangle($ip_end, 'numeric');
        if ($ip != -1 and $ip_end != -1) {
            // We do a sub-select to find interface id's between the specified ranges
            $where .= $and . "h.id IN ( SELECT host_id " . "        FROM interfaces " . "        WHERE ip_addr >= " . $onadb->qstr($ip) . " AND ip_addr <= " . $onadb->qstr($ip_end) . " )";
            $and = " AND ";
        }
    }
    // NOTES
    if ($form['notes']) {
        $where .= $and . "h.notes LIKE " . $onadb->qstr($wildcard . $form['notes'] . $wildcard);
        $and = " AND ";
    }
    // DEVICE MODEL
    if ($form['model_id']) {
        $where .= $and . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id = {$form['model_id']}))";
        $and = " AND ";
    }
    if ($form['model']) {
        $where .= $and . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id in (select id from models where name like '{$form['model']}')))";
        $and = " AND ";
    }
    // DEVICE TYPE
    if ($form['role']) {
        // Find model_id's that have a device_type_id of $form['role']
        list($status, $rows, $records) = db_get_records($onadb, 'roles', array('name' => $form['role']));
        // If there were results, add each one to the $where clause
        if ($rows > 0) {
            $where .= $and . " ( ";
            $and = " AND ";
            $or = "";
            foreach ($records as $record) {
                // Yes this is one freakin nasty query but it works.
                $where .= $or . "h.device_id in (select id from devices where device_type_id in (select id from device_types where role_id = " . $onadb->qstr($record['id']) . "))";
                $or = " OR ";
            }
            $where .= " ) ";
        }
    }
    // DEVICE MANUFACTURER
    if ($form['manufacturer']) {
        // Find model_id's that have a device_type_id of $form['manufacturer']
        if (is_numeric($form['manufacturer'])) {
            list($status, $rows, $records) = db_get_records($onadb, 'models', array('manufacturer_id' => $form['manufacturer']));
        } else {
            list($status, $rows, $manu) = db_get_record($onadb, 'manufacturers', array('name' => $form['manufacturer']));
            list($status, $rows, $records) = db_get_records($onadb, 'models', array('manufacturer_id' => $manu['id']));
        }
        // If there were results, add each one to the $where clause
        if ($rows > 0) {
            $where .= $and . " ( ";
            $and = " AND ";
            $or = "";
            foreach ($records as $record) {
                // Yes this is one freakin nasty query but it works.
                $where .= $or . "h.device_id in (select id from devices where device_type_id in (select id from device_types where model_id = " . $onadb->qstr($record['id']) . "))";
                $or = " OR ";
            }
            $where .= " ) ";
        }
    }
    // tag
    if ($form['tag_host']) {
        $where .= $and . "h.id in (select reference from tags where type like 'host' and name like " . $onadb->qstr($form['tag_host']) . ")";
        $and = " AND ";
    }
    // custom attribute type
    if ($form['custom_attribute_type']) {
        $where .= $and . "h.id in (select table_id_ref from custom_attributes where table_name_ref like 'hosts' and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type']) . "))";
        $and = " AND ";
        $cavaluetype = "and custom_attribute_type_id = (SELECT id FROM custom_attribute_types WHERE name = " . $onadb->qstr($form['custom_attribute_type']) . ")";
    }
    // custom attribute value
    if ($form['ca_value']) {
        $where .= $and . "h.id in (select table_id_ref from custom_attributes where table_name_ref like 'hosts' {$cavaluetype} and value like " . $onadb->qstr($wildcard . $form['ca_value'] . $wildcard) . ")";
        $and = " AND ";
    }
    // LOCATION No.
    if ($form['location']) {
        list($status, $rows, $loc) = ona_find_location($form['location']);
        $where .= $and . "h.device_id in (select id from devices where location_id = " . $onadb->qstr($loc['id']) . ")";
        $and = " AND ";
    }
    // subnet ID
    if (is_numeric($form['subnet_id'])) {
        // We do a sub-select to find interface id's that match
        $from = "(\nSELECT distinct a.*\nfrom hosts as a, interfaces as b\nwhere a.id = b.host_id\nand b.subnet_id = " . $onadb->qstr($form['subnet_id']) . "\norder by b.ip_addr) h";
        $and = " AND ";
    }
    // display a nice message when we dont find all the records
    if ($where == '' and $form['content_id'] == 'search_results_list') {
        $js .= "el('search_results_msg').innerHTML = 'Unable to find hosts matching your query, showing all records';";
    }
    // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything.
    if ($where == '') {
        $where = 'h.id > 0';
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        // Host names should always be lower case
        $form['filter'] = strtolower($form['filter']);
        // FIXME (MP) for now this uses primary_dns_id, this will NOT find multiple A records or other record types. Find a better way some day
        $filter = " AND h.primary_dns_id IN  (SELECT id " . " FROM dns " . " WHERE name LIKE " . $onadb->qstr('%' . $form['filter'] . '%') . " )  ";
    }
    list($status, $rows, $results) = db_get_records($onadb, $from, $where . $filter, $orderby, $conf['search_results_per_page'], $offset);
    // If we got less than serach_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $records) = db_get_records($onadb, $from, $where . $filter, "", 0);
        }
    }
    $count = $rows;
    //
    // *** BUILD HTML LIST ***
    //
    $html .= <<<EOL
        <!-- Host Results -->
        <table id="{$form['form_id']}_host_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Subnet</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Interface</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Device Type</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Location</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Notes</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Get additional info about eash host record
        // If a subnet_id was passed use it as part of the search.  Used to display the IP of the subnet you searched
        if (is_numeric($form['subnet_id'])) {
            list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id'], 'subnet_id' => $form['subnet_id']), '');
            // Count how many rows and assign it back to the interfaces variable
            list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']), "ip_addr", 0);
            $interfaces = $rows;
        } else {
            if (is_numeric($ip)) {
                list($status, $interfaces, $interface) = db_get_record($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']) . ' AND ip_addr >= ' . $onadb->qstr($ip) . ' AND ip_addr <= ' . $onadb->qstr($ip_end), "ip_addr", 0);
                // Count how many rows and assign it back to the interfaces variable
                list($status, $rows, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($record['id']), "ip_addr", 0);
                $interfaces = $rows;
            } else {
                // Interface (and find out how many there are)
                list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id']), '');
            }
        }
        // bz: why did someone add this??  You especially want to show hosts with no interfaces so you can fix them!
        // if (!$interfaces) {$count -1; continue;}
        // get interface cluster info
        $clusterhtml = '';
        list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$interface['id']}");
        if ($intclusterrows > 0) {
            $clusterscript = "onMouseOver=\"wwTT(this, event,\n                    'id', 'tt_interface_cluster_list_{$record['id']}',\n                    'type', 'velcro',\n                    'styleClass', 'wwTT_niceTitle',\n                    'direction', 'south',\n                    'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$record['id']},interface_id=>{$interface['id']}\\');'\n                    );\"";
            $clusterhtml .= <<<EOL
                <img src="{$images}/silk/sitemap.png" {$clusterscript} />
EOL;
        }
        $record['ip_addr'] = ip_mangle($interface['ip_addr'], 'dotted');
        $interface_style = '';
        if ($interfaces > 1) {
            $interface_style = 'font-weight: bold;';
        }
        // DNS A record
        list($status, $rows, $dns) = ona_get_dns_record(array('id' => $record['primary_dns_id']));
        $record['name'] = $dns['name'];
        // Domain Name
        list($status, $rows, $domain) = ona_get_domain_record(array('id' => $dns['domain_id']));
        $record['domain'] = $domain['fqdn'];
        // Subnet description
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id']));
        $record['subnet'] = $subnet['name'];
        $record['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
        $record['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
        // Device Description
        list($status, $rows, $device) = ona_get_device_record(array('id' => $record['device_id']));
        list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id']));
        list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id']));
        list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id']));
        list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
        $record['devicefull'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})";
        $record['device'] = str_replace('Unknown', '?', $record['devicefull']);
        $record['notes_short'] = truncate($record['notes'], 40);
        // Get location_number from the location_id
        list($status, $rows, $location) = ona_get_location_record(array('id' => $device['location_id']));
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$record['id']}\\', \\'display\\')');";
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';">

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

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

                <td class="list-row" align="left">
                    <span style="{$interface_style}"
EOL;
        if ($interfaces > 1) {
            $html .= <<<EOL
                          onMouseOver="wwTT(this, event,
                                            'id', 'tt_host_interface_list_{$record['id']}',
                                            'type', 'velcro',
                                            'styleClass', 'wwTT_niceTitle',
                                            'direction', 'south',
                                            'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>host_interface_list,id=>tt_host_interface_list_{$record['id']},host_id=>{$record['id']}\\');'
                                           );"
EOL;
        }
        $html .= <<<EOL
                    >{$record['ip_addr']}</span>&nbsp;
                    <span title="{$record['ip_mask']}">/{$record['ip_mask_cidr']}</span>
                    <span>{$clusterhtml}</span>
                </td>

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

                <td class="list-row" align="right">
                    <span onMouseOver="wwTT(this, event,
                                            'id', 'tt_location_{$device['location_id']}',
                                            'type', 'velcro',
                                            'styleClass', 'wwTT_niceTitle',
                                            'direction', 'south',
                                            'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>location,id=>tt_location_{$device['location_id']},location_id=>{$device['location_id']}\\');'
                                           );"
                    >{$location['reference']}</span>&nbsp;
                </td>

                <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_host_{$record['id']}"
                        ><input type="hidden" name="host_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>&nbsp;
EOL;
        if (auth('host_modify')) {
            $html .= <<<EOL

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

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

            </tr>
EOL;
    }
    if ($count == 0 and $form['subnet_id'] and !$form['filter']) {
        $html .= <<<EOL
     <tr><td colspan="99" align="center" style="color: red;">Please add the gateway host (router) to this subnet</td></tr>
EOL;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // If there was only 1 result, and we're about to display results in the "Search Results" window, display it.
    if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '') {
        $js .= $primary_object_js;
    }
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
Example #9
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']};">Manufacturer</td>
            <td class="list-header" align="center" style="{$style['borderR']};">Device model</td>
            <td class="list-header" align="center" style="{$style['borderR']};">SNMP sysobjectid</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, 'models', $where, 'manufacturer_id', $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, 'models', $where, '', 0);
        }
    }
    $count = $rows;
    // Loop through and display the device models
    foreach ($records as $record) {
        list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $record['manufacturer_id']));
        $record['manufacturer_name'] = $manufacturer['name'];
        // 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">
                {$record['manufacturer_name']}&nbsp;
            </td>

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

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

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

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

        <a title="New device model"
            class="act"
            onClick="xajax_window_submit('app_device_model_edit', ' ', 'editor');"
        >Add device model</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']}_device_model_count", "innerHTML", "({$count})");
    $response->addAssign("{$form['content_id']}", "innerHTML", $html);
    // $response->addScript($js);
    return $response->getXML();
}
Example #10
0
function ws_save($window_name, $form = '')
{
    global $conf, $self, $onadb;
    // Check permissions
    if (!auth('advanced')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Strip whitespace
    // FIXME: (PK) What about SQL injection attacks?  This is a user-entered string...
    $form['manufacturer_name'] = trim($form['manufacturer_name']);
    // Don't insert a string of all white space!
    if (trim($form['manufacturer_name']) == "") {
        $self['error'] = "ERROR => Blank names not allowed.";
        printmsg($self['error'], 0);
        $response->addScript("alert('{$self['error']}');");
        return $response->getXML();
    }
    // If you get a numeric in $form, update the record
    if (is_numeric($form['id'])) {
        // Get the manufacturer record before updating (logging)
        list($status, $rows, $original_manufacturer) = ona_get_manufacturer_record(array('id' => $form['id']));
        if ($form['manufacturer_name'] !== $original_manufacturer['name']) {
            list($status, $rows) = db_update_record($onadb, 'manufacturers', array('id' => $form['id']), array('name' => $form['manufacturer_name']));
            if ($status or !$rows) {
                $self['error'] = "ERROR => manufacturer_edit update ws_save() failed: " . $self['error'];
                printmsg($self['error'], 0);
                $response->addScript("alert('{$self['error']}');");
            } else {
                // Get the manufacturer record after updating (logging)
                list($status, $rows, $new_manufacturer) = ona_get_manufacturer_record(array('id' => $form['id']));
                // Return the success notice
                $self['error'] = "INFO => Manufacturer UPDATED:{$new_manufacturer['id']}: {$new_manufacturer['name']}";
                printmsg($self['error'], 0);
                $log_msg = "INFO => Manufacturer UPDATED:{$new_manufacturer['id']}: name[{$original_manufacturer['name']}=>{$new_manufacturer['name']}]";
                printmsg($log_msg, 0);
            }
        }
    } else {
        $id = ona_get_next_id('manufacturers');
        if (!$id) {
            $self['error'] = "ERROR => The ona_get_next_id() call failed!";
            printmsg($self['error'], 0);
        } else {
            printmsg("DEBUG => id for new manufacturer record: {$id}", 3);
            list($status, $rows) = db_insert_record($onadb, "manufacturers", array('id' => $id, 'name' => trim($form['manufacturer_name'])));
            if ($status or !$rows) {
                $self['error'] = "ERROR => manufacturer_edit add ws_save() failed: " . $self['error'];
                printmsg($self['error'], 0);
            } else {
                $self['error'] = "INFO => Manufacturer ADDED: {$form['manufacturer_name']} ";
                printmsg($self['error'], 0);
            }
        }
    }
    // If the module returned an error code display a popup warning
    if ($status or !$rows) {
        $js .= "alert(\"Save failed. " . trim($self['error']) . " (Hint: Does the name you're trying to insert already exist?)\");";
    } else {
        $js .= "removeElement('{$window_name}');";
        $js .= "xajax_window_submit('app_manufacturer_list', xajax.getFormValues('app_manufacturer_list_filter_form'), 'display_list');";
    }
    // Return some javascript to the browser
    $response->addScript($js);
    return $response->getXML();
}
Example #11
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' => 'Device Type 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 we got a device type, load it for display
    $overwrite = 'no';
    if (is_numeric($form)) {
        list($status, $rows, $record) = db_get_record($onadb, 'device_types', array('id' => $form));
        if (!$status and $rows) {
            $overwrite = 'yes';
        }
    }
    // Build model list
    // TODO: this needs to be made more efficent
    list($status, $rows, $model) = db_get_records($onadb, 'manufacturers b, models a', 'a.manufacturer_id = b.id and a.id >= 1', 'b.name, a.name');
    $model['name'] = htmlentities($model['name']);
    foreach ($model as $entry) {
        $selected = "";
        list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $entry['manufacturer_id']));
        $entry['manufacturer_name'] = $manufacturer['name'];
        // If this entry matches the record you are editing, set it to selected
        if ($entry['id'] == $record['model_id']) {
            $selected = "SELECTED=\"selected\"";
        }
        if ($entry['id']) {
            $model_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['manufacturer_name']}, {$entry['name']}</option>\n";
        }
    }
    // Build role list
    // TODO: this needs to be made more efficent
    list($status, $rows, $role) = db_get_records($onadb, 'roles', 'id >= 1', 'name');
    $role['name'] = htmlentities($role['name']);
    foreach ($role as $entry) {
        $selected = "";
        // If this entry matches the record you are editing, set it to selected
        if ($entry['id'] == $record['role_id']) {
            $selected = "SELECTED=\"selected\"";
        }
        if ($entry['id']) {
            $role_list .= "<option {$selected} value=\"{$entry['id']}\">{$entry['name']}</option>\n";
        }
    }
    // 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 device types Edit Form -->
    <form id="device_type_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 nowrap="yes" align="right">
                Device model
            </td>
            <td class="padding" align="left" width="100%">
                <select id="model_id" name="model_id" class="edit" accesskey="m">
                    {$model_list}
                </select>
            </td>
        </tr>

        <tr>
            <td nowrap="yes" align="right">
                Device role
            </td>
            <td class="padding" align="left" width="100%">
                <select id="role_id" name="role_id" class="edit" accesskey="r">
                    {$role_list}
                </select>
            </td>
        </tr>

        <tr>
            <td align="right" valign="top">
                &nbsp;
            </td>
            <td class="padding" align="right" width="100%">
                <input type="hidden" name="overwrite" value="{$overwrite}">
                <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
                <input class="edit" type="button"
                    name="submit"
                    value="Save"
                    accesskey=" "
                    onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('device_type_edit_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>

EOL;
    // Lets build a window and display the results
    return window_open($window_name, $window);
}
Example #12
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');";
    // Search results go in here
    $results = array();
    $count = 0;
    // NETWORK ID
    if (is_numeric($form['subnet_id'])) {
    }
    // Do the SQL Query
    list($status, $count, $results) = db_get_records($onadb, 'interfaces', "subnet_id = " . $onadb->qstr($form['subnet_id']), 'ip_addr', -1, -1);
    // make an array of ips from our results
    $iplist = array();
    foreach ($results as $record) {
        $iplist["{$record['ip_addr']}"] = 'used';
    }
    list($status, $rows, $subnet) = ona_find_subnet($form['subnet_id']);
    // Create a few variables that will be handy later
    $num_ips = 0xffffffff - $subnet['ip_mask'];
    $last_ip = $subnet['ip_addr'] + $num_ips - 1;
    $currip = $subnet['ip_addr'] + 1;
    // Get a list of blocks that touches this subnet
    list($status, $blockrows, $blocks) = db_get_records($onadb, 'blocks', "{$subnet['ip_addr']} BETWEEN ip_addr_start AND ip_addr_end OR {$last_ip} BETWEEN ip_addr_start AND ip_addr_end OR ip_addr_start BETWEEN {$subnet['ip_addr']} and {$last_ip}");
    // Get a list of dhcp pools on the selected subnet
    list($status, $rows, $pools) = db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id']));
    // Add DHCP pool addresses into the list of used ips
    foreach ($pools as $pool) {
        for ($ip = $pool['ip_addr_start']; $ip <= $pool['ip_addr_end']; $ip++) {
            $iplist["{$ip}"] = 'pool-' . $pool['id'];
        }
    }
    //
    // *** BUILD HTML LIST ***
    //
    $html .= <<<EOL
        <!-- Host Results -->
        <table id="{$form['form_id']}_full_host_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
            
            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};" title="IP Block Association">B</td>
                <td class="list-header" align="center" style="{$style['borderR']};">IP Address</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Last Response</td>
                <td class="list-header" align="center" style="{$style['borderR']};">[Name] Desc</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Host Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Device Type</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Host Notes</td>
            </tr>
EOL;
    // Loop and display each ip on the subnet
    while ($currip <= $last_ip) {
        $loc = array();
        $host = array();
        $interface = array();
        $interfaces = 0;
        $record = array();
        $interface_style = '';
        $clusterhtml = '';
        $rowstyle = 'background-color: #E9FFE1';
        $rowid = 'byip_available';
        $currip_txt = ip_mangle($currip, 'dotted');
        $interface['desc'] = '<span style="color: #aaaaaa;">AVAILABLE</span>';
        $nameval = <<<EOL
            <a title="Add host"
               class="act"
               onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');"
            ></a>&nbsp;

            <a title="Add host"
               class="act"
               onClick="xajax_window_submit('edit_host', 'ip_addr=>{$currip_txt}', 'editor');"
            >Add a new host</a>&nbsp;

             <a title="Add interface"
               class="act"
               onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');"
            ></a>&nbsp;

            <a title="Add interface"
               class="act"
               onClick="xajax_window_submit('edit_interface', 'ip_addr=>{$currip_txt}', 'editor');"
            >Add interface to an existing host</a>&nbsp;
                 
EOL;
        // If the current ip is one allocated on this subnet lets do some stuff
        if (array_key_exists($currip, $iplist)) {
            $rowid = 'byip_allocated';
            $rowstyle = '';
            // check if it is a pool range
            list($pooltype, $poolid) = explode('-', $iplist[$currip]);
            if ($pooltype == 'pool') {
                $interface['desc'] = '<span style="color: #aaaaaa;">DHCP Pool</span>';
                $rowstyle = 'background-color: #FFFBD6';
                $nameval = <<<EOL
                    <a title="Edit Pool"
                       class="act"
                       onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');"
                    ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
        
                    <a title="Edit Pool"
                       class="act"
                       onClick="xajax_window_submit('edit_dhcp_pool', 'subnet=>{$subnet['id']},id=>{$poolid}', 'editor');"
                    >Edit DHCP Pool</a>&nbsp;
EOL;
            } else {
                // Get host record
                list($status, $rows, $host) = ona_find_host($currip);
                // Get the interface info
                list($status, $rows, $interface) = ona_find_interface($currip);
                // Count how many interface rows this host hasand assign it back to the interfaces variable
                list($status, $interfaces, $records) = db_get_records($onadb, 'interfaces', 'host_id = ' . $onadb->qstr($host['id']), "", 0);
                // get interface cluster info
                list($status, $intclusterrows, $intcluster) = db_get_records($onadb, 'interface_clusters', "interface_id = {$interface['id']}");
                if ($intclusterrows > 0) {
                    $clusterscript = "onMouseOver=\"wwTT(this, event,\n                        'id', 'tt_interface_cluster_list_{$interface['id']}',\n                        'type', 'velcro',\n                        'styleClass', 'wwTT_niceTitle',\n                        'direction', 'south',\n                        'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>interface_cluster_list,id=>tt_interface_cluster_list_{$interface['id']},interface_id=>{$interface['id']}\\');'\n                        );\"";
                    $clusterhtml .= <<<EOL
                    <img src="{$images}/silk/sitemap.png" {$clusterscript} />
EOL;
                }
                // set the name value for an allocated host
                $nameval = <<<EOL
                    <a title="View host. ID: {$host['id']}"
                       class="nav"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$host['id']}\\', \\'display\\')');"
                    >{$host['name']}</a
                    >.<a title="View domain. ID: {$host['domain_id']}"
                         class="domain"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_domain\\', \\'domain_id=>{$host['domain_id']}\\', \\'display\\')');"
                    >{$host['domain_fqdn']}</a>
EOL;
                // Make it bold if we have more than one interface on this host
                if ($interfaces > 1) {
                    $interface_style = 'font-weight: bold;';
                }
                // Device Description
                list($status, $rows, $device) = ona_find_device($host['device_id']);
                list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $device['device_type_id']));
                list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id']));
                list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id']));
                list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
                $record['device'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})";
                $record['device'] = str_replace('Unknown', '?', $record['device']);
                $record['notes_short'] = truncate($host['notes'], 40);
                $interface['description_short'] = truncate($interface['description'], 40);
                if ($interface['name']) {
                    $interface['name'] = "[{$interface['name']}]";
                }
                $interface['desc'] = "{$interface['name']} {$interface['description_short']}";
                // Format the date and colorize if its older than 2 months
                if ($interface['last_response']) {
                    $interface['last_response'] = date($conf['date_format'], strtotime($interface['last_response']));
                    if (strtotime($interface['last_response']) < strtotime('-2 month')) {
                        $interface['last_response_fmt'] = 'style=color:red;';
                    }
                }
                // Get location info
                list($status, $rows, $loc) = ona_get_location_record(array('id' => $device['location_id']));
            }
            // end real host ifblock
        }
        // end while loop
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
            <tr {$rowid}=true style="{$rowstyle}" onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
                
EOL;
        // Print color info for any matching blocks
        $c = 0;
        $blockcolors = array('#CD5C5C', '#588C7E', '#8C4646', '#FFD700', '#1E90F0', '#8A2BE2', '#32CD32', '#D96459');
        if ($blockrows) {
            $html .= "<td class='list-row' nowrap style='padding:0'>";
            foreach ($blocks as $block) {
                if ($currip >= $block['ip_addr_start'] && $currip <= $block['ip_addr_end']) {
                    $html .= "<span title='{$block['name']}' style='background-color:{$blockcolors[$c]};padding-bottom:4px;float:left;'>&nbsp;&nbsp</span> ";
                }
                $c++;
            }
        } else {
            // print an empty table cell
            $html .= "<td class='list-row'>";
        }
        $html .= <<<EOL
                </td>
                <td class="list-row" align="left">
EOL;
        // if it is used, show an edit interface link
        if ($rowid == 'byip_allocated') {
            $html .= <<<EOL
                    <a class="nav" style="{$interface_style}" title="Edit interface ID: {$interface['id']}"
                          onClick="xajax_window_submit('edit_interface', 'interface_id=>{$interface['id']}', 'editor');"
EOL;
            if ($interfaces > 1) {
                $html .= <<<EOL
                          onMouseOver="wwTT(this, event,
                                            'id', 'tt_host_interface_list_{$host['id']}',
                                            'type', 'velcro',
                                            'styleClass', 'wwTT_niceTitle',
                                            'direction', 'south',
                                            'javascript', 'xajax_window_submit(\\'tooltips\\', \\'tooltip=>host_interface_list,id=>tt_host_interface_list_{$host['id']},host_id=>{$host['id']}\\');'
                                           );"
EOL;
            }
            $html .= '>';
        }
        //print out the IP address
        $html .= $currip_txt;
        // close the A tag if used above
        if ($rowid == 'byip_allocated') {
            $html .= '</a>';
        }
        // Keep on goin with the rest of the line
        $html .= <<<EOL

                    &nbsp;<span>{$clusterhtml}</span>
                </td>

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

                <td class="list-row">
                    <span title="{$interface['description']}">{$interface['desc']}</span>&nbsp;
                </td>

                <td class="list-row" style="border-left: 1px solid; border-left-color: #aaaaaa;">
                   {$nameval}
                </td>

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

                <td class="list-row">
                    <span title="{$host['notes']}">{$record['notes_short']}</span>&nbsp;
                </td>

            </tr>
EOL;
        // increment the currip
        $currip++;
    }
    $html .= <<<EOL
    </table>
EOL;
    $js .= <<<EOL
            /* Make sure this table is 100% wide */
            el('{$form['form_id']}_full_host_list').style.width = el('{$form['form_id']}_table').offsetWidth + 'px';

function togglebyip(name) {
    tr=document.getElementsByTagName('tr')
    for (i=0;i<tr.length;i++){
      if (tr[i].getAttribute(name)){
        if (tr[i].style.display=='none'){tr[i].style.display = '';}
        else {tr[i].style.display = 'none';}
      }
    }
}
EOL;
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}