Esempio n. 1
0
/**
 * Display neighbours.
 *
 * Display pages with device neighbours in some formats.
 * Examples:
 * print_neighbours() - display all neighbours from all devices
 * print_neighbours(array('pagesize' => 99)) - display 99 neighbours from all device
 * print_neighbours(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 neighbours from page 3 with pagination header
 * print_neighbours(array('pagesize' => 10, 'device' = 4)) - display 10 neighbours for device_id 4
 *
 * @param array $vars
 * @return none
 *
 */
function print_neighbours($vars)
{
    // Get neighbours array
    $neighbours = get_neighbours_array($vars);
    if (!$neighbours['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No neighbours found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if ($vars['page'] != 'device') {
            $list['device'] = TRUE;
        }
        if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) {
            $graph_types = array($vars['graph']);
        } else {
            $graph_types = array('bits', 'upkts', 'errors');
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port', 'protocol' => 'Protocol');
        if (!$list['device']) {
            unset($cols[0], $cols['device_a']);
        }
        $string .= get_table_header($cols, $vars);
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($neighbours['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['row_class'] . '">' . PHP_EOL;
            if ($list['device']) {
                $string .= '   <td class="state-marker"></td>';
                $string .= '    <td class="entity">' . generate_device_link($entry, NULL, array('tab' => 'ports', 'view' => 'neighbours')) . '</td>' . PHP_EOL;
            }
            $string .= '    <td><span class="entity">' . generate_port_link($entry) . '</span><br />' . $entry['ifAlias'] . '</td>' . PHP_EOL;
            $string .= '    <td><i class="icon-resize-horizontal text-success"></i></td>' . PHP_EOL;
            if (is_numeric($entry['remote_port_id']) && $entry['remote_port_id']) {
                $remote_port = get_port_by_id_cache($entry['remote_port_id']);
                $remote_device = device_by_id_cache($remote_port['device_id']);
                $string .= '    <td><span class="entity">' . generate_device_link($remote_device) . '</span><br />' . $remote_device['hardware'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . generate_port_link($remote_port) . '</span><br />' . $remote_port['ifAlias'] . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td><span class="entity">' . $entry['remote_hostname'] . '</span><br />' . $entry['remote_platform'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . $entry['remote_port'] . '</span></td>' . PHP_EOL;
            }
            $string .= '    <td>' . strtoupper($entry['protocol']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($neighbours['pagination_html']) {
            $string = $neighbours['pagination_html'] . $string . $neighbours['pagination_html'];
        }
        // Print
        echo $string;
    }
}
Esempio n. 2
0
/**
 * Display authentication log.
 *
 * @param array $vars
 * @return none
 *
 */
function print_authlog($vars)
{
    $authlog = get_authlog_array($vars);
    if (!$authlog['count']) {
        // There have been no entries returned. Print the warning. Shouldn't happen, how did you get here without auth?!
        print_warning('<h4>No authentication entries found!</h4>');
    } else {
        $string = generate_box_open($vars['header']);
        // Entries have been returned. Print the table.
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        $cols = array('date' => array('Date', 'style="width: 150px;"'), 'user' => 'User', 'from' => 'From', 'ua' => array('User-Agent', 'style="width: 200px;"'), 'NONE' => 'Action');
        if ($vars['page'] == 'preferences') {
            unset($cols['user']);
        }
        $string .= get_table_header($cols);
        //, $vars); // Currently sorting is not available
        $string .= '<tbody>' . PHP_EOL;
        foreach ($authlog['entries'] as $entry) {
            if (strlen($entry['user_agent']) > 1) {
                $entry['detect_browser'] = detect_browser($entry['user_agent']);
                //r($entry['detect_browser']);
                $entry['user_agent'] = '<i class="' . $entry['detect_browser']['icon'] . '"></i>&nbsp;' . $entry['detect_browser']['browser_full'];
                if ($entry['detect_browser']['platform']) {
                    $entry['user_agent'] .= ' (' . $entry['detect_browser']['platform'] . ')';
                }
            }
            if (strstr(strtolower($entry['result']), 'fail', true)) {
                $class = " class=\"error\"";
            } else {
                $class = "";
            }
            $string .= '
      <tr' . $class . '>
        <td>' . $entry['datetime'] . '</td>';
            if (isset($cols['user'])) {
                $string .= '
        <td>' . escape_html($entry['user']) . '</td>';
            }
            $string .= '
        <td>' . ($_SESSION['userlevel'] > 5 ? generate_popup_link('ip', $entry['address']) : preg_replace('/^\\d+/', '*', $entry['address'])) . '</td>
        <td>' . $entry['user_agent'] . '</td>
        <td>' . $entry['result'] . '</td>
      </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Add pagination header
        if ($authlog['pagination_html']) {
            $string = $authlog['pagination_html'] . $string . $authlog['pagination_html'];
        }
        // Print authlog
        echo $string;
    }
}
Esempio n. 3
0
function print_processor_table($vars)
{
    global $cache;
    $sql = generate_processor_query($vars);
    $processors = array();
    foreach (dbFetchRows($sql) as $proc) {
        if (isset($cache['devices']['id'][$proc['device_id']])) {
            $proc['hostname'] = $cache['devices']['id'][$proc['device_id']]['hostname'];
            $proc['html_row_class'] = $cache['devices']['id'][$proc['device_id']]['html_row_class'];
            $processors[] = $proc;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'usage':
            $processors = array_sort_by($processors, 'processor_usage', $sort_neg, SORT_NUMERIC);
            break;
        default:
            $processors = array_sort_by($processors, 'hostname', $sort_order, SORT_STRING, 'processor_descr', $sort_order, SORT_STRING);
            break;
    }
    $processors_count = count($processors);
    // Pagination
    $pagination_html = pagination($vars, $processors_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $processors = array_chunk($processors, $vars['pagesize']);
        $processors = $processors[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_processor_table_header($vars);
    foreach ($processors as $processor) {
        print_processor_row($processor, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 4
0
function print_p2pradio_table($vars)
{
    if ($vars['view'] == "graphs" || isset($vars['graph'])) {
        $stripe_class = "table-striped-two";
    } else {
        $stripe_class = "table-striped";
    }
    echo generate_box_open();
    echo '<table class="table table-hover ' . $stripe_class . '  table-condensed">';
    print_p2pradio_table_header($vars);
    $sql = generate_p2pradio_query($vars);
    $radios = dbFetchRows($sql);
    foreach ($radios as $radio) {
        print_p2pradio_row($radio, $vars);
    }
    echo '</table>';
    echo generate_box_close();
}
Esempio n. 5
0
/**
 * Returns a string containing an HTML table to be used in popups for the port entity type
 *
 * @param array $port array
 *
 * @return string Table containing port header for popups
 */
function generate_port_popup_header($port)
{
    // Push through processing function to set attributes
    humanize_port($port);
    $contents .= generate_box_open();
    $contents .= '<table class="' . OBS_CLASS_TABLE . '">
        <tr class="' . $port['row_class'] . '" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td style="width: 250px;"><a href="#" class="' . $port['html_class'] . '" style="font-size: 15px; font-weight: bold;">' . $port['port_label'] . '</a><br />' . escape_html($port['ifAlias']) . '</td>
          <td style="width: 100px;">' . $port['human_speed'] . '<br />' . $port['ifMtu'] . '</td>
          <td>' . $port['human_type'] . '<br />' . $port['human_mac'] . '</td>
        </tr>
          </table>';
    $contents .= generate_box_close();
    return $contents;
}
Esempio n. 6
0
                $navbar['options'][$app_section]['class'] = "active";
            }
            $navbar['options'][$app_section]['url'] = generate_url($vars, array('app_section' => $app_section));
            $navbar['options'][$app_section]['text'] = $text;
        }
        print_navbar($navbar);
        unset($navbar);
    } else {
        // It appears this app doesn't have multiple sections. We set app_section to default here.
        $vars['app_section'] = 'default';
    }
    // If a matching app_section array exists within app_graphs, print the graphs.
    if (isset($app_graphs[$vars['app_section']]) && is_array($app_graphs[$vars['app_section']])) {
        echo generate_box_open();
        echo '<table class="table table-striped table-hover  table-condensed">';
        foreach ($app_graphs[$vars['app_section']] as $key => $text) {
            $graph_type = $key;
            $graph_array['to'] = $config['time']['now'];
            $graph_array['id'] = $app['app_id'];
            $graph_array['type'] = "application_" . $key;
            echo '<tr><td>';
            echo '<h3>', $text, '</h4>';
            print_graph_row($graph_array);
            echo '</td></tr>';
        }
        echo '</table>';
        generate_box_close();
    }
}
register_html_title("Apps");
// EOF
Esempio n. 7
0
/**
 * Pretty print for xml string
 *
 * @param string $xml An xml string
 * @param boolean $formatted Convert or not output to human formatted xml
 */
function print_xml($xml, $formatted = TRUE)
{
    if ($formatted) {
        $xml = format_xml($xml);
    }
    if (is_cli()) {
        echo $xml;
    } else {
        echo generate_box_open(array('title' => 'Output', 'padding' => TRUE));
        echo '
    <pre class="prettyprint lang-xml small">' . escape_html($xml) . '</pre>
    <span><em>NOTE: XML values are always escaped, that\'s why you can see this <mark>' . escape_html(escape_html('< > & " \'')) . '</mark> instead of this <mark>' . escape_html('< > & " \'') . '</mark>. <u>Leave them as is</u>.</em></span>
    <script type="text/javascript">window.prettyPrint && prettyPrint();</script>' . PHP_EOL;
        echo generate_box_close();
    }
}
Esempio n. 8
0
/**
 * Display bgp peers.
 *
 * Display pages with BGP Peers.
 * Examples:
 * print_bgp() - display all bgp peers from all devices
 * print_bgp(array('pagesize' => 99)) - display 99 bgp peers from all device
 * print_bgp(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 bgp peers from page 3 with pagination header
 * print_bgp(array('pagesize' => 10, 'device' = 4)) - display 10 bgp peers for device_id 4
 *
 * @param array $vars
 * @return none
 *
 */
function print_bgp_table($vars)
{
    // Get bgp peers array
    $entries = get_bgp_array($vars);
    //r($entries);
    if (!$entries['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No BGP peers found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if ($vars['page'] != 'device') {
            $list['device'] = TRUE;
        }
        switch ($vars['graph']) {
            case 'prefixes_ipv4unicast':
            case 'prefixes_ipv4multicast':
            case 'prefixes_ipv4vpn':
            case 'prefixes_ipv6unicast':
            case 'prefixes_ipv6multicast':
            case 'macaccounting_bits':
            case 'macaccounting_pkts':
            case 'updates':
                $table_class = 'table-striped-two';
                $list['graph'] = TRUE;
                break;
            default:
                $table_class = 'table-striped';
                $list['graph'] = FALSE;
        }
        $string = generate_box_open();
        $string .= '<table class="table  ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), array(NULL, 'style="width: 1px;"'), 'device' => array('Local address', 'style="width: 150px;"'), array(NULL, 'style="width: 20px;"'), 'peer_ip' => array('Peer address', 'style="width: 150px;"'), 'type' => array('Type', 'style="width: 50px;"'), array('Family', 'style="width: 50px;"'), 'peer_as' => 'Remote AS', 'state' => 'State', 'Uptime / Updates');
        //if (!$list['device']) { unset($cols['device']); }
        $string .= get_table_header($cols, $vars);
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries['entries'] as $peer) {
            $local_dev = device_by_id_cache($peer['device_id']);
            $local_as = $list['device'] ? ' (AS' . $peer['bgpLocalAs'] . ')' : '';
            $local_name = generate_device_link($local_dev, short_hostname($local_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp'));
            $local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, array('tab' => 'routing', 'proto' => 'bgp'));
            $peer_as = 'AS' . $peer['bgpPeerRemoteAs'];
            if ($peer['peer_device_id']) {
                $peer_dev = device_by_id_cache($peer['peer_device_id']);
                $peer_name = generate_device_link($peer_dev, short_hostname($peer_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp'));
            } else {
                $peer_name = $peer['reverse_dns'];
            }
            $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
            $peer_afis =& $entries['afisafi'][$peer['device_id']][$peer['bgpPeerRemoteAddr']];
            $peer_afis_html = array();
            foreach ($peer_afis as $peer_afi) {
                $peer_afi_html = '<span class="label-group">';
                switch ($peer_afi['afi']) {
                    case 'ipv4':
                    case 'ipv4z':
                        $afi_class = 'success';
                        break;
                    case 'ipv6':
                    case 'ipv6z':
                        $afi_class = 'primary';
                        break;
                    default:
                        $afi_class = 'default';
                }
                switch ($peer_afi['safi']) {
                    case 'unicast':
                        $safi_class = 'delayed';
                        break;
                    case 'multicast':
                        $safi_class = 'warning';
                        break;
                    case 'vpn':
                        $safi_class = 'suppressed';
                        break;
                    default:
                        $safi_class = 'default';
                }
                $peer_afi_html .= '<span class="label label-' . $afi_class . '">' . $peer_afi['afi'] . '</span>';
                $peer_afi_html .= '<span class="label label-' . $safi_class . '">' . $peer_afi['safi'] . '</span>';
                $peer_afi_html .= '</span>';
                $peer_afis_html[] = $peer_afi_html;
            }
            $string .= '  <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
            $string .= '     <td class="state-marker"></td>' . PHP_EOL;
            $string .= '     <td></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL;
            $string .= '     <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL;
            $string .= '     <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL;
            $string .= '     <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL;
            $string .= '     <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL;
            $string .= '     <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL;
            $string .= '     <td style="white-space: nowrap">' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . '<br />
                Updates: <i class="icon-circle-arrow-down text-success"></i> ' . format_si($peer['bgpPeerInUpdates']) . ' <i class="icon-circle-arrow-up text-primary"></i> ' . format_si($peer['bgpPeerOutUpdates']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
            // Graphs
            $peer_graph = FALSE;
            switch ($vars['graph']) {
                case 'prefixes_ipv4unicast':
                case 'prefixes_ipv4multicast':
                case 'prefixes_ipv4vpn':
                case 'prefixes_ipv6unicast':
                case 'prefixes_ipv6multicast':
                    $afisafi = preg_replace('/prefixes_(ipv[46])(\\w+)/', '$1.$2', $vars['graph']);
                    // prefixes_ipv6unicast ->> ipv6.unicast
                    if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id']) {
                        $graph_array['type'] = 'bgp_' . $vars['graph'];
                        $graph_array['id'] = $peer['bgpPeer_id'];
                        $peer_graph = TRUE;
                    }
                    break;
                case 'updates':
                    if ($peer['bgpPeer_id']) {
                        $graph_array['type'] = 'bgp_updates';
                        $graph_array['id'] = $peer['bgpPeer_id'];
                        $peer_graph = TRUE;
                    }
                    break;
                case 'macaccounting_bits':
                case 'macaccounting_pkts':
                    //FIXME. I really still not know it works or not? -- mike
                    // This part copy-pasted from old code as is
                    $acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M\n                            LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address\n                            LEFT JOIN `ports` AS P ON P.port_id = M.port_id\n                            LEFT JOIN `devices` AS D ON D.device_id = P.device_id\n                            WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr']));
                    $database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
                    if (is_array($acc) && is_file($database)) {
                        $peer_graph = TRUE;
                        $graph_array['id'] = $acc['ma_id'];
                        $graph_array['type'] = $vars['graph'];
                    }
                    break;
            }
            if ($peer_graph) {
                $graph_array['to'] = $config['time']['now'];
                $string .= '  <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
                $string .= '    <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL;
                $string .= generate_graph_row($graph_array);
                $string .= '    </td>' . PHP_EOL . '  </tr>' . PHP_EOL;
            } else {
                if ($list['graph']) {
                    // Empty row for correct view class table-striped-two
                    $string .= '  <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></tr>' . PHP_EOL;
                }
            }
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($entries['pagination_html']) {
            $string = $entries['pagination_html'] . $string . $entries['pagination_html'];
        }
        // Print
        echo $string;
    }
}
Esempio n. 9
0
/**
 * Display dot1x sessions
 *
 * @param array $vars
 * @return none
 *
 */
function print_dot1xtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
                    } else {
                        if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
                            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
                        } else {
                            $value = trim($value);
                            $where .= generate_query_values($value, 'username', '%LIKE%');
                        }
                    }
                    break;
            }
        }
    }
    // Check permissions
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M'));
    $query = 'FROM `wifi_sessions` AS M ';
    $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query;
    $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query;
    $query .= ' ORDER BY M.`timestamp` DESC';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query wireless  sessions table
    $entries = dbFetchRows($query, $param);
    // Query wireless  sessions table count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number`  FROM `wifi_accesspoints`");
    foreach ($aps_db as $ap_db) {
        $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db;
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    // A radio is like a port
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>IP Address</th>' . PHP_EOL;
        $string .= '      <th>Username</th>' . PHP_EOL;
        $string .= '      <th>SSID/VLAN</th>' . PHP_EOL;
        $string .= '      <th>Last Seen</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface/AP</th>' . PHP_EOL;
        }
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $ap_id = $entry['accesspoint_id'];
        $interface = $aps_sorted_db[$ap_id]['name'];
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '    <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL;
        }
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print wireless sessions
    echo $string;
}
Esempio n. 10
0
/**
 * Display IPv4/IPv6 addresses.
 *
 * Display pages with IP addresses from device Interfaces.
 *
 * @param array $vars
 * @return none
 *
 */
function print_addresses($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    if (in_array($vars['search'], array('6', 'v6', 'ipv6')) || in_array($vars['view'], array('6', 'v6', 'ipv6'))) {
        $address_type = 'ipv6';
    } else {
        $address_type = 'ipv4';
    }
    $ip_array = array();
    $param = array();
    $where = ' WHERE 1 ';
    $param_netscaler = array();
    $where_netscaler = " WHERE `vsvr_ip` != '0.0.0.0' AND `vsvr_ip` != '' ";
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    $where_netscaler .= generate_query_values($value, 'N.device_id');
                    break;
                case 'interface':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'network':
                    list($net, $mask) = explode('/', $value);
                    if (is_numeric(stripos($net, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    $where .= generate_query_values($value, 'N.ip_network', 'LIKE%');
                    break;
                case 'address':
                    list($addr, $mask) = explode('/', $value);
                    if (is_numeric(stripos($addr, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    switch ($address_type) {
                        case 'ipv6':
                            $ip_valid = Net_IPv6::checkIPv6($addr);
                            break;
                        case 'ipv4':
                            $ip_valid = Net_IPv4::validateIP($addr);
                            break;
                    }
                    if ($ip_valid) {
                        // If address valid -> seek occurrence in network
                        if (!$mask) {
                            $mask = $address_type === 'ipv4' ? '32' : '128';
                        }
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip');
                    } else {
                        // If address not valid -> seek LIKE
                        $where .= generate_query_values($addr, 'A.ip_address', '%LIKE%');
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%');
                    }
                    break;
            }
        }
    }
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Also search netscaler Vserver IPs
    $query_netscaler = 'FROM `netscaler_vservers` AS N ';
    $query_netscaler .= 'LEFT JOIN `devices` AS D ON N.`device_id` = D.`device_id` ';
    $query_netscaler .= $where_netscaler . $query_device_permitted;
    //$query_netscaler_count = 'SELECT COUNT(`vsvr_id`) ' . $query_netscaler;
    $query_netscaler = 'SELECT * ' . $query_netscaler;
    $query_netscaler .= ' ORDER BY N.`vsvr_ip`';
    // Override by address type
    if ($address_type == 'ipv6') {
        $query_netscaler = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler);
        //$query_netscaler_count = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler_count);
    }
    $entries = dbFetchRows($query_netscaler, $param_netscaler);
    // Rewrite netscaler addresses
    foreach ($entries as $entry) {
        $ip_address = $address_type == 'ipv4' ? $entry['vsvr_ip'] : $entry['vsvr_' . $address_type];
        $ip_network = $address_type == 'ipv4' ? $entry['vsvr_ip'] . '/32' : $entry['vsvr_' . $address_type] . '/128';
        $ip_array[] = array('type' => 'netscaler_vsvr', 'device_id' => $entry['device_id'], 'hostname' => $entry['hostname'], 'vsvr_id' => $entry['vsvr_id'], 'vsvr_label' => $entry['vsvr_label'], 'ifAlias' => 'Netscaler: ' . $entry['vsvr_type'] . '/' . $entry['vsvr_entitytype'], $address_type . '_address' => $ip_address, $address_type . '_network' => $ip_network);
    }
    //print_message($query_netscaler_count);
    $query = 'FROM `ip_addresses` AS A ';
    $query .= 'LEFT JOIN `ports`   AS I ON I.`port_id`   = A.`port_id` ';
    $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
    $query .= 'LEFT JOIN `ip_networks` AS N ON N.`ip_network_id` = A.`ip_network_id` ';
    $query .= $where . $query_port_permitted;
    //$query_count = 'SELECT COUNT(`ip_address_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY A.`ip_address`';
    if ($ip_valid) {
        $pagination = FALSE;
    }
    // Override by address type
    $query = str_replace(array('ip_address', 'ip_network'), array($address_type . '_address', $address_type . '_network'), $query);
    //$query_count = str_replace(array('ip_address', 'ip_network'), array($address_type.'_address', $address_type.'_network'), $query_count);
    // Query addresses
    $entries = dbFetchRows($query, $param);
    $ip_array = array_merge($ip_array, $entries);
    $ip_array = array_sort($ip_array, $address_type . '_address');
    // Query address count
    //if ($pagination) { $count = dbFetchCell($query_count, $param); }
    if ($pagination) {
        $count = count($ip_array);
        $ip_array = array_slice($ip_array, $start, $pagesize);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    $string = generate_box_open($vars['header']);
    $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED . '">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>Address</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($ip_array as $entry) {
        $address_show = TRUE;
        if ($ip_valid) {
            // If address not in specified network, don't show entry.
            if ($address_type === 'ipv4') {
                $address_show = Net_IPv4::ipInNetwork($entry[$address_type . '_address'], $addr . '/' . $mask);
            } else {
                $address_show = Net_IPv6::isInNetmask($entry[$address_type . '_address'], $addr, $mask);
            }
        }
        if ($address_show) {
            list($prefix, $length) = explode('/', $entry[$address_type . '_network']);
            if (port_permitted($entry['port_id']) || $entry['type'] == 'netscaler_vsvr') {
                if ($entry['type'] == 'netscaler_vsvr') {
                    $entity_link = generate_entity_link($entry['type'], $entry);
                } else {
                    humanize_port($entry);
                    if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                        $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
                    }
                    $entity_link = generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error;
                }
                $device_link = generate_device_link($entry);
                $string .= '  <tr>' . PHP_EOL;
                if ($list['device']) {
                    $string .= '    <td class="entity" style="white-space: nowrap">' . $device_link . '</td>' . PHP_EOL;
                }
                $string .= '    <td class="entity">' . $entity_link . '</td>' . PHP_EOL;
                if ($address_type === 'ipv6') {
                    $entry[$address_type . '_address'] = Net_IPv6::compress($entry[$address_type . '_address']);
                }
                $string .= '    <td>' . generate_popup_link('ip', $entry[$address_type . '_address'] . '/' . $length) . '</td>' . PHP_EOL;
                $string .= '    <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL;
                $string .= '  </tr>' . PHP_EOL;
            }
        }
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print addresses
    echo $string;
}
Esempio n. 11
0
function print_syslog_rules_table($vars)
{
    if (isset($vars['la_id'])) {
        $las = dbFetchRows("SELECT * FROM `syslog_rules` WHERE `la_id` = ?", array($vars['la_id']));
    } else {
        $las = dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`");
    }
    if (is_array($las) && count($las)) {
        $string = generate_box_open();
        $string .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), 'name' => array('Name', 'style="width: 160px;"'), 'descr' => array('Description', 'style="width: 400px;"'), 'rule' => 'Rule', 'severity' => array('Severity', 'style="width: 60px;"'), 'disabled' => array('Status', 'style="width: 60px;"'), 'controls' => array('', 'style="width: 40px;"'));
        $string .= get_table_header($cols, $vars);
        foreach ($las as $la) {
            if ($la['disable'] == 0) {
                $la['html_row_class'] = "up";
            } else {
                $la['html_row_class'] = "disabled";
            }
            $string .= '<tr class="' . $la['html_row_class'] . '">';
            $string .= '<td class="state-marker"></td>';
            $string .= '    <td><strong><a href="' . generate_url(array('page' => 'syslog_rules', 'la_id' => $la['la_id'])) . '">' . escape_html($la['la_name']) . '</a></strong></td>' . PHP_EOL;
            $string .= '    <td><a href="' . generate_url(array('page' => 'syslog_rules', 'la_id' => $la['la_id'])) . '">' . escape_html($la['la_descr']) . '</a></td>' . PHP_EOL;
            $string .= '    <td><code>' . escape_html($la['la_rule']) . '</code></td>' . PHP_EOL;
            $string .= '    <td>' . escape_html($la['la_severity']) . '</td>' . PHP_EOL;
            $string .= '    <td>' . ($la['la_disable'] ? '<span class="label label-error">disabled</span>' : '<span class="label label-success">enabled</span>') . '</td>' . PHP_EOL;
            $string .= '    <td style="text-align: right;"><a href="#edit_modal_' . $la['la_id'] . '" data-toggle="modal"><i class="icon-cog text-muted"></i></a>&nbsp;';
            $string .= '                                   <a href="#del_modal_' . $la['la_id'] . '" data-toggle="modal"><i class="icon-trash text-danger"></i></a></td>';
            $string .= '  </tr>' . PHP_EOL;
            // Delete Rule Modal
            $modals .= '<div id="del_modal_' . $la['la_id'] . '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="delete_syslog_rule" aria-hidden="true">
 <form id="edit" name="edit" method="post" class="form" action="' . generate_url(array('page' => 'syslog_rules')) . '">
  <input type="hidden" name="la_id" value="' . $la['la_id'] . '">

  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Syslog Rule ' . escape_html($la['la_descr']) . '</h3>
  </div>
  <div class="modal-body">

  <span class="help-block">This will completely delete the rule and all associations and history.</span>
  <fieldset>
    <div class="control-group">
      <label class="control-label" for="confirm">
        <strong>Confirm</strong>
      </label>
      <div class="controls">
        <label class="checkbox">
          <input type="checkbox" name="confirm" value="confirm" onchange="javascript: showWarning(this.checked, ' . $la['la_id'] . ');" />
          Yes, please delete this rule.
        </label>

      <script type="text/javascript">' . "\n        function showWarning(checked, id) {\n          \$('#warning'+id).toggle();\n          if (checked) {\n            \$('#delete_button'+id).removeAttr('disabled');\n          } else {\n            \$('#delete_button'+id).attr('disabled', 'disabled');\n          }\n        } " . '
      </script>

      </div>
    </div>
  </fieldset>

  <div class="alert alert-message alert-danger" id="warning' . $la['la_id'] . '" style="display:none;">
    <h4 class="alert-heading"><i class="icon-warning-sign"></i> Warning!</h4>
    This rule and all history will be completely deleted!
  </div>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button id="delete_button' . $la['la_id'] . '" type="submit" class="btn btn-danger" name="submit" value="delete_syslog_rule" disabled><i class="icon-trash icon-white"></i> Delete Rule</button>
  </div>
 </form>
</div>';
            // Edit Rule Modal
            $modals .= '
<div id="edit_modal_' . $la['la_id'] . '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <form id="edit" name="edit" method="post" class="form form-horizontal" action="">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="edit_modal_label">Edit Syslog Rule</h3>
  </div>
  <div class="modal-body">

  <input type="hidden" name="la_id" value="' . $la['la_id'] . '">

  <fieldset>

    <div class="control-group">
      <label class="control-label" for="la_name">Rule Name</label>
      <div class="controls">
        <input type="text" name="la_name" size="32" value="' . escape_html($la['la_name']) . '"/>
      </div>
    </div>

    <div class="control-group">
      <label class="control-label" for="la_descr">Description</label>
      <div class="controls">
        <textarea class="form-control col-sm-12" name="la_descr" rows="3">' . escape_html($la['la_descr']) . '</textarea>
      </div>
    </div>

    <div class="control-group">
      <label class="control-label" for="la_rule">Regular Expression</label>
      <div class="controls">
        <textarea class="form-control col-sm-12" name="la_rule" rows="3">' . escape_html($la['la_rule']) . '</textarea>
      </div>
    </div>

    <div class="control-group">
      <label class="control-label" for="la_disable">Status</label>
      <div class="controls">
        <input type=checkbox id="la_disable" name="la_disable" ' . ($la['la_disable'] ? 'checked' : '') . ' data-toggle="switch" data-on-text="disabled" data-off-text="enabled" data-on-color="danger" data-off-color="primary">
      </div>
    </div>


  </fieldset>

  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button type="submit" class="btn btn-primary" name="submit" value="edit_syslog_rule"><i class="icon-ok icon-white"></i> Save Changes</button>
  </div>
 </form>
</div>';
        }
        $string .= '</table>';
        $string .= generate_box_close();
        echo $string;
    } else {
        print_warning("There are currently no Syslog alerting filters defined.");
    }
    echo $modals;
}
Esempio n. 12
0
/**
 * Display Interface MACs addresses.
 *
 * Display pages with MAC addresses from device Interfaces.
 *
 * @param array $vars
 * @return none
 *
 */
function print_mac_addresses($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'interface':
                    $where .= generate_query_values($value, 'ifDescr', 'LIKE');
                    break;
                case 'address':
                    $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                    $where .= generate_query_values($value, 'ifPhysAddress', '%LIKE%');
                    break;
            }
        }
    }
    $where .= ' AND `ifPhysAddress` IS NOT NULL';
    //Exclude empty MACs
    // Show MACs only for permitted ports
    $query_permitted = generate_query_permitted(array('port'));
    $query = 'FROM `ports` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `ifPhysAddress`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    $string = generate_box_open($vars['header']);
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        if (port_permitted($entry['port_id'])) {
            humanize_port($entry);
            $string .= '  <tr>' . PHP_EOL;
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
            }
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
            $string .= '    <td style="width: 160px;">' . generate_popup_link('mac', $entry['human_mac']) . '</td>' . PHP_EOL;
            $string .= '    <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print MAC addresses
    echo $string;
}
Esempio n. 13
0
function print_pseudowire_table($vars)
{
    $pws = get_pseudowire_table($vars);
    $pws_count = count($pws);
    // Pagination
    $pagination_html = pagination($vars, $pws_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $pws = array_chunk($pws, $vars['pagesize']);
        $pws = $pws[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_pseudowire_table_header($vars);
    foreach ($pws as $pw) {
        print_pseudowire_row($pw, $vars);
    }
    echo '</tbody></table>';
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 14
0
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    global $config;
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No eventlog entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['entity'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['entity']) {
                $string .= '      <th>Entity</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            switch ($entry['severity']) {
                case "0":
                    // Emergency
                // Emergency
                case "1":
                    // Alert
                // Alert
                case "2":
                    // Critical
                // Critical
                case "3":
                    // Error
                    $entry['html_row_class'] = "error";
                    break;
                case "4":
                    // Warning
                    $entry['html_row_class'] = "warning";
                    break;
                case "5":
                    // Notification
                    $entry['html_row_class'] = "recovery";
                    break;
                case "6":
                    // Informational
                    $entry['html_row_class'] = "up";
                    break;
                case "7":
                    // Debugging
                    $entry['html_row_class'] = "suppressed";
                    break;
                default:
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['entity']) {
                if ($entry['entity_type'] == 'device' && !$entry['entity_id']) {
                    $entry['entity_id'] = $entry['device_id'];
                }
                if ($entry['entity_type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['entity_id']);
                    $entry['link'] = '<span class="entity"><i class="' . $config['entities']['port']['icon'] . '"></i> ' . generate_port_link($this_if, $this_if['port_label_short']) . '</span>';
                } else {
                    if (!empty($config['entities'][$entry['entity_type']]['icon'])) {
                        $entry['link'] = '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> <span class="entity">' . generate_entity_link($entry['entity_type'], $entry['entity_id']) . '</span>';
                    } else {
                        $entry['link'] = nicecase($entry['entity_type']);
                    }
                }
                if (!$events['short']) {
                    $string .= '    <td style="white-space: nowrap">' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">';
                if (strpos($entry['message'], $entry['link']) !== 0) {
                    $string .= $entry['link'] . ' ';
                }
            } else {
                $string .= '    <td>';
            }
            $string .= escape_html($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
Esempio n. 15
0
/**
 * Display FDB table.
 *
 * @param array $vars
 * @return none
 *
 */
function print_fdbtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'interface':
                case 'port_name':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'vlan_id':
                    $where .= generate_query_values($value, 'F.vlan_id');
                    break;
                case 'vlan_name':
                    $where .= generate_query_values($value, 'V.vlan_name');
                    break;
                case 'address':
                    $where .= generate_query_values(str_replace(array(':', ' ', '-', '.', '0x'), '', $value), 'F.mac_address', '%LIKE%');
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "vlan_id":
                $sort = " ORDER BY `V`.`vlan_vlan`";
                break;
            case "vlan_name":
                $sort = " ORDER BY `V`.`vlan_name`";
                break;
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show FDB tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `vlans_fdb` AS F ';
    $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('device' => 'Device', 'mac' => array('MAC Address', 'style="width: 160px;"'), 'status' => array('Status', 'style="width: 100px;"'), 'port' => 'Port', 'vlan_id' => 'VLAN ID', 'vlan_name' => 'VLAN NAME');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $string .= '  <tr>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        $string .= '    <td>' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['fdb_status'] . '</td>' . PHP_EOL;
        if ($list['port']) {
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['vlan_name'] . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print FDB table
    echo $string;
}
Esempio n. 16
0
/**
 * Display syslog messages.
 *
 * Display pages with device syslog messages.
 * Examples:
 * print_syslogs() - display last 10 syslog messages from all devices
 * print_syslogs(array('pagesize' => 99)) - display last 99 syslog messages from all device
 * print_syslogs(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 syslog messages from page 3 with pagination header
 * print_syslogs(array('pagesize' => 10, 'device' = 4)) - display last 10 syslog messages for device_id 4
 * print_syslogs(array('short' => TRUE)) - show small block with last syslog messages
 *
 * @param array $vars
 * @return none
 *
 */
function print_syslogs($vars)
{
    // Short events? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $priorities = $GLOBALS['config']['syslog']['priorities'];
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'priority':
                    if (!is_array($value)) {
                        $value = explode(',', $value);
                    }
                    foreach ($value as $k => $v) {
                        // Rewrite priority strings to numbers
                        $value[$k] = priority_string_to_numeric($v);
                    }
                    // Do not break here, it's true!
                // Do not break here, it's true!
                case 'program':
                    $where .= generate_query_values($value, $var);
                    break;
                case 'message':
                    $where .= generate_query_values($value, 'msg', '%LIKE%');
                    break;
                case 'timestamp_from':
                    $where .= ' AND `timestamp` > ?';
                    $param[] = $value;
                    break;
                case 'timestamp_to':
                    $where .= ' AND `timestamp` < ?';
                    $param[] = $value;
                    break;
            }
        }
    }
    // Show events only for permitted devices
    $query_permitted = generate_query_permitted();
    $query = 'FROM `syslog` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `seq` DESC ';
    $query .= "LIMIT {$start},{$pagesize}";
    // Query syslog messages
    $entries = dbFetchRows($query, $param);
    // Query syslog count
    if ($pagination && !$short) {
        $count = dbFetchCell($query_count, $param);
    } else {
        $count = count($entries);
    }
    if (!$count) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No syslog entries found!</h4>
Check that the syslog daemon and Observium configuration options are set correctly, that your devices are configured to send syslog to Observium and that there are no firewalls blocking the messages.

See <a href="' . OBSERVIUM_URL . '/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="' . OBSERVIUM_URL . '/wiki/Configuration_Options#Syslog_Settings" target="_blank">configuration options</a> for more information.');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'priority' => TRUE);
        // For now (temporarily) priority always displayed
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'syslog') {
            $list['device'] = TRUE;
        }
        if ($short || !isset($vars['priority']) || empty($vars['priority'])) {
            $list['priority'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        if (!$short) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            #    $string .= '      <th></th>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['priority']) {
                $string .= '      <th>Priority</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries as $entry) {
            switch ($entry['priority']) {
                case "0":
                    // Emergency
                // Emergency
                case "1":
                    // Alert
                // Alert
                case "2":
                    // Critical
                // Critical
                case "3":
                    // Error
                    $entry['html_row_class'] = "error";
                    break;
                case "4":
                    // Warning
                    $entry['html_row_class'] = "warning";
                    break;
                case "5":
                    // Notification
                    $entry['html_row_class'] = "recovery";
                    break;
                case "6":
                    // Informational
                    $entry['html_row_class'] = "up";
                    break;
                case "7":
                    // Debugging
                    $entry['html_row_class'] = "suppressed";
                    break;
                default:
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($short) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td width="130">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'syslog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['priority']) {
                if (!$short) {
                    $string .= '    <td style="color: ' . $priorities[$entry['priority']]['color'] . '; white-space: nowrap; width: 95px;"><span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</span></td>' . PHP_EOL;
                }
            }
            $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program'];
            if ($short) {
                $string .= '    <td class="syslog">';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '"><strong>' . $entry['program'] . '</strong></span> ';
            } else {
                $string .= '    <td>';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . $entry['program'] . '</span>';
            }
            $string .= escape_html($entry['msg']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>' . PHP_EOL;
        $string .= generate_box_close();
        // Print pagination header
        if ($pagination && !$short) {
            $string = pagination($vars, $count) . $string . pagination($vars, $count);
        }
        // Print syslog
        echo $string;
    }
}
Esempio n. 17
0
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'ip_version':
                    $where .= generate_query_values($value, 'ip_version');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        if (strpos($value, ':') !== FALSE) {
                            if (Net_IPv6::checkIPv6($value)) {
                                $value = Net_IPv6::uncompress($value, TRUE);
                            } else {
                                // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                            }
                        }
                        $where .= generate_query_values($value, 'ip_address', '%LIKE%');
                    } else {
                        // MAC Addresses
                        $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                        $where .= generate_query_values($value, 'mac_address', '%LIKE%');
                    }
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "ip_version":
                $sort = " ORDER BY `ip_version`";
                break;
            case "ip":
            case "address":
                $sort = " ORDER BY `ip_address`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = 'Self Device';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = 'Self Port';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
Esempio n. 18
0
function print_vm_table($vars)
{
    $sql = generate_vm_query($vars);
    $vms = array();
    foreach (dbFetchRows($sql) as $vm) {
        if (isset($GLOBALS['cache']['devices']['id'][$vm['device_id']])) {
            $vm['hostname'] = $GLOBALS['cache']['devices']['id'][$vm['device_id']]['hostname'];
            $vms[] = $vm;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'name':
            $vms = array_sort_by($vms, 'vm_name', $sort_order, SORT_STRING);
            break;
        case 'os':
            $vms = array_sort_by($vms, 'vm_os', $sort_order, SORT_STRING);
            break;
        case 'state':
            $vms = array_sort_by($vms, 'vm_state', $sort_order, SORT_STRING);
            break;
        case 'memory':
            $vms = array_sort_by($vms, 'vm_memory', $sort_order, SORT_NUMERIC);
            break;
        case 'cpu':
            $vms = array_sort_by($vms, 'vm_cpucount', $sort_order, SORT_NUMERIC);
            break;
        default:
            // Not sorted
    }
    $vms_count = count($vms);
    // Pagination
    $pagination_html = pagination($vars, $vms_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $vms = array_chunk($vms, $vars['pagesize']);
        $vms = $vms[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_vm_table_header($vars);
    foreach ($vms as $vm) {
        print_vm_row($vm, $vars);
    }
    echo '</tbody></table>';
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 19
0
function print_status_table($vars)
{
    $sql = generate_status_query($vars);
    $status_list = array();
    foreach (dbFetchRows($sql) as $status) {
        if (isset($GLOBALS['cache']['devices']['id'][$status['device_id']])) {
            $status['hostname'] = $GLOBALS['cache']['devices']['id'][$status['device_id']]['hostname'];
            $status_list[] = $status;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device':
            $status_list = array_sort_by($status_list, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'descr':
            $status_list = array_sort_by($status_list, 'status_descr', $sort_order, SORT_STRING);
            break;
        case 'class':
            $status_list = array_sort_by($status_list, 'entPhysicalClass', $sort_order, SORT_STRING);
            break;
        case 'event':
            $status_list = array_sort_by($status_list, 'status_event', $sort_order, SORT_STRING);
            break;
        case 'status':
            $status_list = array_sort_by($status_list, 'status_name', $sort_order, SORT_STRING);
            break;
        case 'last_change':
            $status_list = array_sort_by($status_list, 'status_last_change', $sort_neg, SORT_NUMERIC);
            break;
        default:
            $status_list = array_sort_by($status_list, 'hostname', $sort_order, SORT_STRING, 'status_descr', $sort_order, SORT_STRING);
    }
    $status_count = count($status_list);
    // Pagination
    $pagination_html = pagination($vars, $status_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $status_list = array_chunk($status_list, $vars['pagesize']);
        $status_list = $status_list[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_status_table_header($vars);
    foreach ($status_list as $status) {
        print_status_row($status, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 20
0
function generate_device_popup_header($device, $vars = array())
{
    global $config;
    humanize_device($device);
    if ($device['os'] == "ios") {
        formatCiscoHardware($device, TRUE);
    }
    // FIXME or generic function for more than just IOS? [and/or do this at poll time]
    $contents = generate_box_open() . '
<table class="table table-striped table-rounded table-condensed">
  <tr class="' . $device['html_row_class'] . '" style="font-size: 10pt;">
    <td class="state-marker"></td>
    <td class="vertical-align" style="width: 64px; text-align: center;">' . get_device_icon($device) . '</td>
    <td width="200px"><a href="#" class="' . device_link_class($device) . '" style="font-size: 15px; font-weight: bold;">' . escape_html($device['hostname']) . '</a><br />' . escape_html(truncate($device['location'], 64, '')) . '</td>
    <td>' . escape_html($device['hardware']) . ' <br /> ' . $device['os_text'] . ' ' . escape_html($device['version']) . '</td>
    <td>' . deviceUptime($device, 'short') . '<br />' . escape_html($device['sysName']) . '
  </tr>
</table>
' . generate_box_close();
    return $contents;
}
Esempio n. 21
0
function print_sla_table($vars)
{
    $sql = generate_sla_query($vars);
    $slas = array();
    foreach (dbFetchRows($sql) as $sla) {
        if (isset($GLOBALS['cache']['devices']['id'][$sla['device_id']])) {
            $sla['hostname'] = $GLOBALS['cache']['devices']['id'][$sla['device_id']]['hostname'];
            $slas[] = $sla;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device':
            $slas = array_sort_by($slas, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'descr':
            $slas = array_sort_by($slas, 'sla_index', $sort_order, SORT_STRING, 'sla_tag', $sort_order, SORT_STRING);
            break;
        case 'owner':
            $slas = array_sort_by($slas, 'sla_owner', $sort_order, SORT_STRING);
            break;
        case 'type':
            $slas = array_sort_by($slas, 'rtt_type', $sort_order, SORT_STRING);
            break;
        case 'event':
            $slas = array_sort_by($slas, 'rtt_event', $sort_order, SORT_STRING);
            break;
        case 'sense':
            $slas = array_sort_by($slas, 'rtt_sense', $sort_order, SORT_STRING);
            break;
        case 'last_change':
            $slas = array_sort_by($slas, 'rtt_last_change', $sort_neg, SORT_NUMERIC);
            break;
        case 'rtt':
            $slas = array_sort_by($slas, 'rtt_value', $sort_order, SORT_NUMERIC);
            break;
        default:
            // Not sorted
    }
    $slas_count = count($slas);
    // Pagination
    $pagination_html = pagination($vars, $slas_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $slas = array_chunk($slas, $vars['pagesize']);
        $slas = $slas[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_sla_table_header($vars);
    foreach ($slas as $sla) {
        print_sla_row($sla, $vars);
    }
    echo '</tbody></table>';
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 22
0
/**
 * Display alert_table entries.
 *
 * @param array $vars
 * @return none
 *
 */
function print_alert_table($vars)
{
    global $alert_rules;
    global $config;
    // This should be set outside, but do it here if it isn't
    if (!is_array($alert_rules)) {
        $alert_rules = cache_alert_rules();
    }
    /// WARN HERE
    if (isset($vars['device']) && !isset($vars['device_id'])) {
        $vars['device_id'] = $vars['device'];
    }
    if (isset($vars['entity']) && !isset($vars['entity_id'])) {
        $vars['entity_id'] = $vars['entity'];
    }
    // Short? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    list($query, $param, $query_count) = build_alert_table_query($vars);
    // Fetch alerts
    $count = dbFetchCell($query_count, $param);
    $alerts = dbFetchRows($query, $param);
    // Set which columns we're going to show.
    // We hide the columns that have been given as search options via $vars
    $list = array('device_id' => FALSE, 'entity_id' => FALSE, 'entity_type' => FALSE, 'alert_test_id' => FALSE);
    foreach ($list as $argument => $nope) {
        if (!isset($vars[$argument]) || empty($vars[$argument]) || $vars[$argument] == "all") {
            $list[$argument] = TRUE;
        }
    }
    if ($vars['format'] != "condensed") {
        $list['checked'] = TRUE;
        $list['changed'] = TRUE;
        $list['alerted'] = TRUE;
    }
    if ($vars['short'] == TRUE) {
        $list['checked'] = FALSE;
        $list['alerted'] = FALSE;
    }
    // Hide device if we know entity_id
    if (isset($vars['entity_id'])) {
        $list['device_id'] = FALSE;
    }
    // Hide entity_type if we know the alert_test_id
    if (isset($vars['alert_test_id']) || TRUE) {
        $list['entity_type'] = FALSE;
    }
    // Hide entity types in favour of icons to save space
    if ($vars['pagination'] && !$short) {
        $pagination_html = pagination($vars, $count);
        echo $pagination_html;
    }
    echo generate_box_open($vars['header']);
    echo '<table class="table table-condensed  table-striped  table-hover">';
    if ($vars['no_header'] == FALSE) {
        echo '
  <thead>
    <tr>
      <th class="state-marker"></th>
      <th style="width: 1px;"></th>';
        if ($list['device_id']) {
            echo '      <th style="width: 15%">Device</th>';
        }
        if ($list['entity_type']) {
            echo '      <th style="width: 10%">Type</th>';
        }
        if ($list['entity_id']) {
            echo '      <th style="">Entity</th>';
        }
        if ($list['alert_test_id']) {
            echo '      <th style="min-width: 15%;">Alert</th>';
        }
        echo '
      <th style="width: 100px;">Status</th>';
        if ($list['checked']) {
            echo '      <th style="width: 95px;">Checked</th>';
        }
        if ($list['changed']) {
            echo '      <th style="width: 95px;">Changed</th>';
        }
        if ($list['alerted']) {
            echo '      <th style="width: 95px;">Alerted</th>';
        }
        echo '    <th style="width: 45px;"></th>
    </tr>
  </thead>';
    }
    echo '<tbody>' . PHP_EOL;
    foreach ($alerts as $alert) {
        // Process the alert entry, generating colours and classes from the data
        humanize_alert_entry($alert);
        // Get the entity array using the cache
        $entity = get_entity_by_id_cache($alert['entity_type'], $alert['entity_id']);
        // Get the device array using the cache
        $device = device_by_id_cache($alert['device_id']);
        // Get the entity_name.
        ### FIXME - This is probably duplicated effort from above. We should pass it $entity
        $entity_name = entity_name($alert['entity_type'], $entity);
        // Set the alert_rule from the prebuilt cache array
        $alert_rule = $alert_rules[$alert['alert_test_id']];
        echo '<tr class="' . $alert['html_row_class'] . '" style="cursor: pointer;" onclick="openLink(\'' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $alert['alert_table_id'])) . '\')">';
        echo '<td class="state-marker"></td>';
        echo '<td style="width: 1px;"></td>';
        // If we know the device, don't show the device
        if ($list['device_id']) {
            echo '<td><span class="entity-title">' . generate_device_link($device) . '</span></td>';
        }
        // If we're showing all entity types, print the entity type here
        if ($list['entity_type']) {
            echo '<td>' . nicecase($alert['entity_type']) . '</td>';
        }
        // Print a link to the entity
        if ($list['entity_id']) {
            echo '<td><span class="entity-title"><i class="' . $config['entities'][$alert['entity_type']]['icon'] . '"></i> ' . generate_entity_link($alert['entity_type'], $alert['entity_id']) . '</span></td>';
        }
        // Print link to the alert rule page
        if ($list['alert_test_id']) {
            echo '<td class="entity"><a href="', generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])), '">', escape_html($alert_rule['alert_name']), '</a></td>';
        }
        echo '<td>';
        echo '<span class="label label-' . ($alert['html_row_class'] != 'up' ? $alert['html_row_class'] : 'success') . '">' . generate_tooltip_link('', $alert['status'], '<div class="small" style="max-width: 500px;"><strong>' . $alert['last_message'] . '</strong></div>', $alert['alert_class']) . '</span>';
        echo '</td>';
        // echo('<td class="'.$alert['class'].'">'.$alert['last_message'].'</td>');
        if ($list['checked']) {
            echo '<td>' . generate_tooltip_link('', $alert['checked'], format_unixtime($alert['last_checked'], 'r')) . '</td>';
        }
        if ($list['changed']) {
            echo '<td>' . generate_tooltip_link('', $alert['changed'], format_unixtime($alert['last_changed'], 'r')) . '</td>';
        }
        if ($list['alerted']) {
            echo '<td>' . generate_tooltip_link('', $alert['alerted'], format_unixtime($alert['last_alerted'], 'r')) . '</td>';
        }
        echo '<td>';
        // This stuff should go in an external entity popup in the future.
        $state = json_decode($alert['state'], true);
        $alert['state_popup'] = '';
        if (count($state['failed'])) {
            $alert['state_popup'] .= generate_box_open(array('title' => 'Failed Tests'));
            //'<h4>Failed Tests</h4>';
            $alert['state_popup'] .= '<table style="min-width: 400px;" class="table   table-striped table-condensed">';
            $alert['state_popup'] .= '<thead><tr><th>Metric</th><th>Cond</th><th>Value</th><th>Measured</th></tr></thead>';
            foreach ($state['failed'] as $test) {
                $alert['state_popup'] .= '<tr><td><strong>' . $test['metric'] . '</strong></td><td>' . $test['condition'] . '</td><td>' . $test['value'] . '</td><td><i class="red">' . $state['metrics'][$test['metric']] . '</i></td></tr>';
            }
            $alert['state_popup'] .= '</table>';
            $alert['state_popup'] .= generate_box_close();
        }
        $alert['state_popup'] .= generate_entity_popup_graphs($alert, array('entity_type' => 'alert_entry'));
        // Print (i) icon with popup of state.
        echo overlib_link("", '<i class="icon-info-sign text-primary"></i>', $alert['state_popup'], NULL);
        echo '&nbsp;&nbsp;<a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'alert', 'alert_entry' => $alert['alert_table_id'])) . '"><i class="icon-cog text-muted"></i></a>';
        echo '</td>';
        echo '</tr>';
    }
    echo '  </tbody>' . PHP_EOL;
    echo '</table>' . PHP_EOL;
    echo generate_box_close();
    if ($vars['pagination'] && !$short) {
        echo $pagination_html;
    }
}
Esempio n. 23
0
function print_printersupplies_table($vars)
{
    $supplies = array();
    foreach (dbFetchRows(build_printersupplies_query($vars)) as $supply) {
        global $cache;
        if (isset($cache['devices']['id'][$supply['device_id']])) {
            $supply['hostname'] = $cache['devices']['id'][$supply['device_id']]['hostname'];
            $supply['html_row_class'] = $cache['devices']['id'][$supply['device_id']]['html_row_class'];
            $supplies[] = $supply;
        }
    }
    $supplies = array_sort_by($supplies, 'hostname', SORT_ASC, SORT_STRING, 'supply_descr', SORT_ASC, SORT_STRING);
    $supplies_count = count($supplies);
    echo generate_box_open();
    // Pagination
    $pagination_html = pagination($vars, $supplies_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $supplies = array_chunk($supplies, $vars['pagesize']);
        $supplies = $supplies[$vars['pageno'] - 1];
    }
    // End Pagination
    if ($vars['view'] == "graphs") {
        $stripe_class = "table-striped-two";
    } else {
        $stripe_class = "table-striped";
    }
    // Allow the table to be printed headerless for use in some places.
    if ($vars['headerless'] != TRUE) {
        echo '<table class="table ' . $stripe_class . '  table-condensed">';
        echo '  <thead>';
        echo '<tr class="strong">';
        echo '<th class="state-marker"></th>';
        echo '<th></th>';
        if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
            echo '      <th style="width: 250px;">Device</th>';
        }
        echo '<th>Toner</th>';
        if (!isset($vars['supply'])) {
            echo '<th>Type</th>';
        }
        echo '<th></th>';
        echo '<th>Level</th>';
        echo '<th>Remaining</th>';
        echo '</tr>';
        echo '</thead>';
    }
    foreach ($supplies as $supply) {
        print_printersupplies_row($supply, $vars);
    }
    echo "</table>";
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 24
0
/**
 * Display events.
 *
 * Display pages with alert logs in multiple formats.
 * Examples:
 * print_alert_log() - display last 10 events from all devices
 * print_alert_log(array('pagesize' => 99)) - display last 99 events from all device
 * print_alert_log(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_alert_log(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_alert_log(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_alert_log($vars)
{
    global $alert_rules, $config;
    // This should be set outside, but do it here if it isn't
    if (!is_array($alert_rules)) {
        $alert_rules = cache_alert_rules();
    }
    // Get events array
    $events = get_alert_log($vars);
    if (!$events['count']) {
        if (!$vars['no_empty_message']) {
            // There have been no entries returned. Print the warning.
            print_message('<h4>No alert log entries found!</h4>', FALSE);
        }
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'entity' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['entity']) || empty($vars['entity'])) {
            $list['entity'] = TRUE;
        }
        if (!isset($vars['alert_test_id']) || empty($vars['alert_test_id']) || $vars['page'] == 'alert_check' || TRUE) {
            $list['alert_test_id'] = TRUE;
        }
        if (!isset($vars['entity_type']) || empty($vars['entity_type']) || $vars['page'] == 'alert_check' || TRUE) {
            $list['entity_type'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $cols = array();
            $cols[] = array(NULL, 'class="state-marker"');
            $cols['date'] = array('Date', 'style="width: 160px"');
            if ($list['device']) {
                $cols['device'] = 'Device';
            }
            if ($list['alert_test_id']) {
                $cols['alert_test_id'] = 'Alert Check';
            }
            if ($list['entity']) {
                $cols['entity'] = 'Entity';
            }
            $cols[] = 'Message';
            $cols['status'] = 'Status';
            $cols['notified'] = array('Notified', 'style="width: 40px"');
            $string .= get_table_header($cols);
            // , $vars); // Actually sorting is disabled now
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            $alert_rule = $alert_rules[$entry['alert_test_id']];
            // Functionize?
            // Set colours and classes based on the status of the alert
            if ($entry['log_type'] == 'OK') {
                $entry['class'] = "green";
                $entry['html_row_class'] = "success";
            } else {
                if ($entry['log_type'] == 'RECOVER_NOTIFY') {
                    $entry['class'] = "green";
                    $entry['html_row_class'] = "info";
                } else {
                    if ($entry['log_type'] == 'ALERT_NOTIFY') {
                        $entry['class'] = "red";
                        $entry['html_row_class'] = "error";
                    } elseif ($entry['log_type'] == 'FAIL') {
                        $entry['class'] = "red";
                        $entry['html_row_class'] = "error";
                    } elseif ($entry['log_type'] == 'FAIL_DELAYED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "warning";
                    } elseif ($entry['log_type'] == 'FAIL_SUPPRESSED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "suppressed";
                    } elseif ($entry['log_type'] == 'RECOVER_SUPPRESSED') {
                        $entry['class'] = "purple";
                        $entry['html_row_class'] = "suppressed";
                    } else {
                        // Anything else set the colour to grey and the class to disabled.
                        $entry['class'] = "gray";
                        $entry['html_row_class'] = "disabled";
                    }
                }
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td>';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'alertlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['alert_test_id']) {
                $string .= '     <td class="entity"><a href="' . generate_url(array('page' => 'alert_check', 'alert_test_id' => $alert_rule['alert_test_id'])) . '">' . escape_html($alert_rule['alert_name']) . '</a></td>';
            }
            if ($list['entity']) {
                $string .= '    <td class="entity">';
                if ($list['entity_type']) {
                    $string .= '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> ';
                }
                if ($events['short']) {
                    $string .= '    ' . generate_entity_link($entry['entity_type'], $entry['entity_id'], NULL, NULL, NULL, TRUE) . '</td>' . PHP_EOL;
                } else {
                    $string .= '    ' . generate_entity_link($entry['entity_type'], $entry['entity_id']) . '</td>' . PHP_EOL;
                }
            }
            $string .= '<td>' . escape_html($entry['message']) . '</td>' . PHP_EOL;
            if (!$vars['short']) {
                $string .= '<td>' . escape_html($entry['log_type']) . '</td>' . PHP_EOL;
                $string .= '<td style="text-align: right">' . ($entry['notified'] ? '<span class="label label-success">YES</span>' : '<span class="label">NO</span>') . '</td>' . PHP_EOL;
            }
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
Esempio n. 25
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function print_logalert_log($vars)
{
    global $config;
    foreach (dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`") as $la) {
        $syslog_rules[$la['la_id']] = $la;
    }
    $entries = get_logalert_log($vars);
    if (!$entries['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No logging alert entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'alert_log') {
            $list['device'] = TRUE;
        }
        if (!isset($vars['la_id']) || empty($vars['la_id'])) {
            $list['la_id'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$entries['short']) {
            $cols = array();
            $cols[] = array(NULL, 'class="state-marker"');
            $cols['date'] = array('Date', 'style="width: 140px"');
            if ($list['device']) {
                $cols['device'] = array('Device', 'style="width: 150px;"');
            }
            if ($list['la_id']) {
                $cols['la_id'] = array('Alert Rule', 'style="width: 150px;"');
            }
            $cols[] = array('Program', 'style="width: 80px"');
            $cols[] = 'Message';
            $cols[] = array('Notified', 'style="width: 40px"');
            $string .= get_table_header($cols);
            // , $vars); // Actually sorting is disabled now
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($entries['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td>';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'alertlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['la_id']) {
                $string .= '<td><strong><a href="' . generate_url(array('page' => 'syslog_rules', 'la_id' => $entry['la_id'])) . '">' . (is_array($syslog_rules[$entry['la_id']]) ? $syslog_rules[$entry['la_id']]['la_name'] : 'Rule Deleted') . '</td>' . PHP_EOL;
            }
            $string .= '<td>' . (strlen($entry['program']) ? '<span class="label">' . $entry['program'] . '</span> ' : '') . '</td>' . PHP_EOL;
            $string .= '<td>' . escape_html($entry['message']) . '</td>' . PHP_EOL;
            if (!$vars['short']) {
                //$string .= '<td>' . escape_html($entry['log_type']) . '</td>' . PHP_EOL;
                $string .= '<td style="text-align: right">' . ($entry['notified'] == '1' ? '<span class="label label-success">YES</span>' : ($entry['notified'] == '-1' ? '<span class="label label-suppressed">NO</span>' : '<span class="label">NO</span>')) . '</td>' . PHP_EOL;
            }
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
    }
    // Print pagination header
    if ($entries['pagination_html']) {
        $string = $entries['pagination_html'] . $string . $entries['pagination_html'];
    }
    // Print events
    echo $string;
}
Esempio n. 26
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function print_storage_table($vars)
{
    global $cache, $config;
    $graph_type = "storage_usage";
    $sql = "SELECT *, `storage`.`storage_id` AS `storage_id` FROM `storage`";
    $sql .= " LEFT JOIN `storage-state` USING(`storage_id`)";
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    if (!isset($vars['ignored'])) {
        $vars['ignored'] = 0;
    }
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'storage.storage_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'storage.device_id');
                break;
            case 'ignored':
                $sql .= generate_query_values($value, 'storage.storage_ignore');
                break;
        }
    }
    $storages = array();
    foreach (dbFetchRows($sql) as $storage) {
        if (isset($cache['devices']['id'][$storage['device_id']])) {
            $storage['hostname'] = $cache['devices']['id'][$storage['device_id']]['hostname'];
            $storage['html_row_class'] = $cache['devices']['id'][$storage['device_id']]['html_row_class'];
            $storages[] = $storage;
        }
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'usage':
            $storages = array_sort_by($storages, 'storage_perc', $sort_neg, SORT_NUMERIC);
            break;
        case 'mountpoint':
            $storages = array_sort_by($storages, 'storage_descr', $sort_order, SORT_STRING);
            break;
        case 'size':
        case 'free':
        case 'used':
            $storages = array_sort_by($storages, 'storage_' . $vars['sort'], $sort_neg, SORT_NUMERIC);
            break;
        default:
            $storages = array_sort_by($storages, 'hostname', $sort_order, SORT_STRING, 'storage_descr', $sort_order, SORT_STRING);
            break;
    }
    $storages_count = count($storages);
    // Pagination
    $pagination_html = pagination($vars, $storages_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $storages = array_chunk($storages, $vars['pagesize']);
        $storages = $storages[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_storage_table_header($vars);
    foreach ($storages as $storage) {
        print_storage_row($storage, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
Esempio n. 27
0
function print_form_box($data, $return = FALSE)
{
    $form_id = isset($data['id']) ? $data['id'] : 'form-' . strgen();
    $form_class = 'form form-horizontal';
    if (isset($data['style'])) {
        $form_style = ' style="' . $data['style'] . '"';
    } else {
        $form_style = ' style="margin-bottom:0;"';
    }
    $base_class = array_key_exists('class', $data) ? $data['class'] : 'box';
    $base_space = $data['space'] ? $data['space'] : '15px';
    $used_vars = array();
    // Cache permissions to session var
    permissions_cache_session();
    //r($_SESSION['cache']);
    if ($data['submit_by_key']) {
        $action = '';
        if ($data['url']) {
            $action .= 'this.form.prop(\'action\', form_to_path(\'' . $form_id . '\'));';
        }
        register_html_resource('script', '$(function(){$(\'form#' . $form_id . '\').each(function(){$(this).find(\'input\').keypress(function(e){if(e.which==10||e.which==13){' . $action . 'this.form.submit();}});});});');
    }
    $header = '';
    if (isset($data['title'])) {
        $header .= '  <h2>' . $data['title'] . '</h2>' . PHP_EOL;
    }
    // Form elements
    $div_begin = '<div class="row">' . PHP_EOL;
    $div_end = '</div>' . PHP_EOL;
    if ($data['type'] == 'horizontal') {
        $row_style = '';
        $fieldset = array();
        foreach ($data['row'] as $k => $row) {
            $row_group = $k;
            $row_elements = '';
            $row_label = '';
            $row_control_group = FALSE;
            $i = 0;
            foreach ($row as $id => $element) {
                $used_vars[] = $id;
                $element['id'] = $id;
                if ($element['fieldset']) {
                    $row_group = $element['fieldset'];
                    // Add this element to group
                }
                // Additional element options for horizontal specific form
                switch ($element['type']) {
                    case 'hidden':
                        $div_class = '';
                        $div_style = '';
                        break;
                    case 'submit':
                        $div_class = 'form-actions';
                        $div_style = ' style="margin: 0px;"';
                        break;
                    case 'text':
                    case 'input':
                    case 'password':
                    case 'textarea':
                    default:
                        $row_control_group = TRUE;
                        // In horizontal, name always placed at left
                        if (!isset($element['placeholder'])) {
                            $element['placeholder'] = TRUE;
                        }
                        if ($i < 1) {
                            // Add laber for first element in row
                            $row_label = '    <label class="control-label" for="' . $element['id'] . '">' . $element['name'] . '</label>' . PHP_EOL;
                            $row_control_id = $element['id'] . '_div';
                        }
                        $div_class = 'controls';
                        $div_style = '';
                        break;
                }
                if (!isset($element['div_class'])) {
                    $element['div_class'] = $div_class;
                }
                //if ($element['right'])
                //{
                //  $element['div_class'] .= ' pull-right';
                //}
                if ($id == 'search' && $data['url']) {
                    // Add form_id here, for generate onclick action in submit button
                    $element['form_id'] = $form_id;
                }
                $row_elements .= generate_form_element($element);
                $i++;
            }
            if ($element['div_class']) {
                // no additional divs if empty div class (hidden element for example)
                $row_elements = $row_label . PHP_EOL . '    <div class="' . $element['div_class'] . '"' . $div_style . '>' . PHP_EOL . $row_elements . '    </div>' . PHP_EOL;
            } else {
                $row_label = str_replace(' class="control-label"', '', $row_label);
                $row_elements = $row_label . PHP_EOL . $row_elements;
            }
            if ($row_control_group) {
                $fieldset[$row_group] .= '  <div id="' . $row_control_id . '" class="control-group"> <!-- START row-' . $k . ' -->' . PHP_EOL;
                $fieldset[$row_group] .= $row_elements;
                $fieldset[$row_group] .= '  </div> <!-- END row-' . $k . ' -->' . PHP_EOL;
            } else {
                // Do not add control group for submit/hidden
                $fieldset[$row_group] .= $row_elements;
            }
            //$row_style = 'style="margin-top: '.$base_space.';"'; // Add space between rows
        }
        $divs = array();
        $fieldset_tooltip = '';
        foreach ($data['fieldset'] as $group => $entry) {
            if (isset($fieldset[$group])) {
                if (!is_array($entry)) {
                    $entry = array('title' => $entry);
                }
                // Custom style
                if (!isset($entry['style'])) {
                    $entry['style'] = 'padding-bottom: 0px !important;';
                    // Remove last additional padding space
                }
                // Combinate fieldsets into common rows
                if ($entry['div']) {
                    $divs[$entry['div']][] = $group;
                } else {
                    $divs['row'][] = $group;
                }
                $box_args = array('header-border' => TRUE, 'padding' => TRUE, 'id' => $group);
                if (isset($entry['style'])) {
                    $box_args['body-style'] = $entry['style'];
                }
                if (isset($entry['title'])) {
                    $box_args['title'] = $entry['title'];
                    if ($entry['icon']) {
                        // $box_args['icon'] => $entry['icon'];
                    }
                }
                if (isset($entry['tooltip'])) {
                    $box_args['header-controls'] = array('controls' => array('tooltip' => array('icon' => 'icon-info text-primary', 'anchor' => TRUE, 'class' => 'tooltip-from-element', 'data' => 'data-tooltip-id="tooltip-' . $group . '"')));
                    $fieldset_tooltip .= '<div id="tooltip-' . $group . '" style="display: none;">' . PHP_EOL;
                    $fieldset_tooltip .= $entry['tooltip'] . '</div>' . PHP_EOL;
                }
                if (isset($entry['tooltip'])) {
                    $box_args['style'] = $entry['style'];
                }
                $fieldset_begin = generate_box_open($box_args);
                $fieldset_end = generate_box_close();
                // Additional div class if set
                if (isset($entry['class'])) {
                    $fieldset_begin = '<div class="' . $entry['class'] . '">' . PHP_EOL . $fieldset_begin;
                    $fieldset_end .= '</div>' . PHP_EOL;
                }
                $row_elements = $fieldset_begin . '
          <fieldset> <!-- START fieldset-' . $group . ' -->';
                $row_elements .= PHP_EOL . $fieldset[$group] . '
          </fieldset> <!-- END fieldset-' . $group . ' -->' . PHP_EOL;
                $fieldset[$group] = $row_elements . $fieldset_end;
            }
        }
        // Combinate fieldsets into common rows
        foreach ($divs as $entry) {
            $row_elements = $div_begin;
            foreach ($entry as $i => $group) {
                $row_elements .= $fieldset[$group];
                if ($i > 0) {
                    // unset all fieldsets except first one for replace later
                    unset($fieldset[$group]);
                }
            }
            $row_elements .= $div_end;
            // now replace first fieldset in group
            $fieldset[array_shift($entry)] = $row_elements;
        }
        // Final combining elements
        $string_elements = implode('', $fieldset);
    }
    // Remove old vars from url
    if ($data['url']) {
        foreach ($used_vars as $var) {
            $data['url'] = preg_replace('/' . $var . '=[^\\/]+\\/?/', '', $data['url']);
        }
    }
    // Form header
    $string = PHP_EOL . "<!-- START {$form_id} -->" . PHP_EOL;
    $string .= $header;
    $string .= '<form method="POST" id="' . $form_id . '" name="' . $form_id . '" action="' . $data['url'] . '" class="' . $form_class . '"' . $form_style . '>' . PHP_EOL;
    // Form elements
    $string .= $string_elements;
    // Form footer
    $string .= '</form>' . PHP_EOL;
    $string .= $fieldset_tooltip;
    $string .= "<!-- END {$form_id} -->" . PHP_EOL;
    if ($return) {
        // Save generation time for profiling
        $GLOBALS['form_time'] += utime() - $form_start;
        // Return form as string
        return $string;
    } else {
        // Print form
        echo $string;
        // Save generation time for profiling (after echo)
        $GLOBALS['form_time'] += utime() - $form_start;
    }
}
Esempio n. 28
0
function generate_entity_popup_header($entity, $vars)
{
    $translate = entity_type_translate_array($vars['entity_type']);
    $vars['popup'] = TRUE;
    $vars['entity_icon'] = TRUE;
    switch ($vars['entity_type']) {
        case "sensor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sensor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "toner":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_toner_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "bgp_peer":
            if ($entity['peer_device_id']) {
                $peer_dev = device_by_id_cache($entity['peer_device_id']);
                $peer_name = '<br /><a class="entity" style="font-weight: bold;">' . $peer_dev['hostname'] . '</a>';
            } else {
                if ($entity['reverse_dns']) {
                    $peer_name = '<br /><span style="font-weight: bold;">' . $entity['reverse_dns'] . '</span>';
                }
            }
            $astext = '<span>AS' . $entity['bgpPeerRemoteAs'];
            if ($entity['astext']) {
                $astext .= '<br />' . $entity['astext'] . '</span>';
            }
            $astext .= '</span>';
            $contents .= generate_box_open();
            $contents .= '
      <table class="' . OBS_CLASS_TABLE . '">
        <tr class="' . $entity['row_class'] . ' vertical-align" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td style="width: 10px;"><i class="' . $translate['icon'] . '"></i></td>
          <td><a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_shortname'] . '</a>' . $peer_name . '</td>
          <td class="text-nowrap" style="width: 20%;">' . $astext . '</td>
          <td></td>
        </tr>
      </table>';
            $contents .= generate_box_close();
            break;
        case "sla":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_sla_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "processor":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_processor_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "mempool":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_mempool_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "p2pradio":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_p2pradio_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "status":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_status_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "storage":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_storage_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalervsvr":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalervsvr_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvc":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvc_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        case "netscalersvcgrpmem":
            $contents .= generate_box_open();
            $contents .= '<table class="' . OBS_CLASS_TABLE . '">';
            $contents .= generate_netscalersvcmem_row($entity, $vars);
            $contents .= '</table>';
            $contents .= generate_box_close();
            break;
        default:
            entity_rewrite($vars['entity_type'], $entity);
            $contents = generate_box_open() . '
      <table class="' . OBS_CLASS_TABLE_STRIPED . '">
        <tr class="' . $entity['row_class'] . '" style="font-size: 10pt;">
          <td class="state-marker"></td>
          <td style="width: 10px;"></td>
          <td width="400"><i class="' . $translate['icon'] . '" style="margin-right: 10px;"></i> <a class="entity-popup" style="font-size: 15px; font-weight: bold;">' . $entity['entity_name'] . '</a></td>
          <td width="100"></td>
          <td></td>
        </tr>
      </table>' . generate_box_close();
    }
    return $contents;
}
Esempio n. 29
0
function show_portpercent($config)
{
    if ($config['frontpage']['portpercent'] != '') {
        echo generate_box_open(array('title' => 'Port Utilization by Type', 'url' => '/groups/entity_type=port/', 'header-border' => TRUE));
        echo '<img src="portpercent-graph.php">';
        echo generate_box_close();
    }
}
Esempio n. 30
0
        $item = array('id' => 'contact_id', 'live-search' => FALSE, 'width' => '220px', 'readonly' => $readonly);
        foreach ($all_contacts as $contact) {
            if (!isset($c_exist[$contact['contact_id']])) {
                $item['values'][$contact['contact_id']] = array('name' => escape_html($contact['contact_descr']), 'subtext' => escape_html($contact['contact_method']));
            }
        }
        $form .= generate_form_element($item, 'select');
        $item = array('id' => 'submit', 'name' => 'Associate', 'class' => 'btn-primary', 'icon' => 'icon-plus', 'readonly' => $readonly, 'value' => 'associate_alert_check');
        $form .= generate_form_element($item, 'submit');
        $form .= '</form>';
        $box_close['footer_content'] = $form;
        $box_close['footer_nopadding'] = TRUE;
    } else {
        // print_warning('No unassociated alert checkers.');
    }
    echo generate_box_close($box_close);
    echo '
  </div>

</div>';
} elseif ($vars['view'] == 'entries') {
    echo '
<div class="row" style="margin-top: 10px;">
  <div class="col-md-12">';
    if ($vars['view'] == 'alert_log') {
        print_alert_log($vars);
    } else {
        $vars['pagination'] = TRUE;
        print_alert_table($vars);
    }
    echo '