function guifi_live_traceroute($device_id)
{
    if (empty($device_id)) {
        $output = t('Target device not specified.');
    } else {
        $gs = guifi_service_load(guifi_graphs_get_server($device_id, 'device'));
        $ipd = guifi_main_ip($device_id);
        $ipf = guifi_main_ip($gs->device_id);
    }
    $title = t('Live traceroute from %from (%ipf) to %dest (%ipd)', array('%ipd' => $ipd['ipv4'], '%dest' => guifi_get_hostname($device_id), '%ipf' => $ipf['ipv4'], '%from' => guifi_get_hostname($gs->device_id)));
    drupal_set_title($title);
    print theme('page', guifi_cnml_live('livetraceroute', $device_id, $ipd['ipv4'], $gs), FALSE);
    exit;
}
/**
 * Returns image url to CNML
 */
function guifi_cnml_availability($args, $gs = NULL)
{
    if (is_null($gs)) {
        $gs = guifi_service_load(guifi_graphs_get_server($args['device'], 'device'));
    }
    $img_url = '<img src="' . guifi_cnml_call_service($gs, 'availability', $args) . '">';
    if ($gs->var['version'] >= 2.0) {
        return l($img_url, 'guifi/menu/ip/liveping/' . $args['device'], array('html' => TRUE, 'attributes' => array('title' => t('live ping/traceroute to %device', array('%device' => guifi_get_hostname($args['device']))), 'target' => '_blank')));
    } else {
        // old v1.0 format for backward compatibility
        return $img_url;
    }
}
function guifi_device_print_data($device)
{
    $radios = db_query('SELECT *
       FROM {guifi_radios}
       WHERE id=%d
       ORDER BY id', $device['id']);
    $rows[] = array(t($device[type]), '<b>' . $device[nick] . '</b>');
    if (count($device['funders'])) {
        $rows[] = array(count($device['funders']) == 1 ? t('Funder') : t('Funders'), implode(', ', guifi_funders_links($device['funders'])));
    }
    if (count($device['maintainers'])) {
        $rows[] = array(t('Maintenance & SLAs'), implode(', ', guifi_maintainers_links($device['maintainers'])));
    }
    // If radio, print model & firmware
    if ($device['type'] == 'radio') {
        $rows[] = array($device[manufacturer] . '-' . $device[model], $device[variable][firmware]);
        // going to list all device radios
        if (count($device['radios'])) {
            foreach ($device['radios'] as $radio_id => $radio) {
                if ($radio['fund_required'] == '') {
                    $policy = t('n/d, ask to node contacts');
                } else {
                    if ($radio['fund_required'] == 'yes') {
                        $policy = t('Fund: :fund :curr', array(':fund' => $radio['fund_amount'], ':curr' => $radio['fund_currency']));
                    } else {
                        $policy = t($radio['fund_required']);
                    }
                }
                $rowsr[] = array($radio['ssid'], $radio['mode'], $radio['protocol'], $radio['channel'], $radio['mac'], t($radio['clients_accepted']), $policy);
            }
            $rows[] = array(array('data' => theme('table', array(t('ssid'), t('mode'), t('protocol'), t('ch'), t('wireless mac'), t('clients'), t('connection policy')), $rowsr), 'colspan' => 2));
        }
    }
    // If ADSL, print characteristics
    if ($device['type'] == 'ADSL' and $device['variable'] != '') {
        $bandwidth = guifi_bandwidth_types();
        $rows[] = array(t('bandwidth'), $bandwidth[$device['variable']['download']] . '/' . $bandwidth[$device['variable']['upload']]);
        $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']);
    }
    // Others with modelDescr set
    if (isset($device['variable']['modelDescr'])) {
        switch ($device['type']) {
            case 'ups':
                $vDescr = t('Power: %power', array('%power' => $device['variable']['specs']));
                break;
            case 'generator':
                $vDescr = t('Max Power: %power Watts', array('%power' => $device['variable']['specs']));
                break;
            case 'battery':
                $vDescr = t('Power: %power/Ah, Quantity: %quantity', array('%power' => $device['variable']['specs'], '%quantity' => $device['variable']['units']));
                break;
            case 'rack':
                $vDescr = t('Height: %height Us, Width: %width inches, Depth: %depth mm', array('%height' => $device['variable']['height'], '%width' => $device['variable']['width'], '%depth' => $device['variable']['depth']));
                break;
            case 'breaker':
                $vDescr = t('Protection: %cbtype, Auto-reclose: %recloser', array('%cbtype' => $device['variable']['cbtype'], '%recloser' => $device['variable']['recloser'] ? t('Yes') : t('No')));
                break;
        }
        $rows[] = array($device['variable']['modelDescr'], $vDescr);
    }
    // generic
    if ($device['type'] == 'generic' || 'confine' and !empty($device['variable']['mrtg_index'])) {
        $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']);
    }
    if ($device['graph_server'] > 0) {
        $gs = node_load(array('nid' => $device['graph_server']));
    } else {
        $gs = node_load(array('nid' => guifi_graphs_get_server($device['id'], 'device')));
    }
    $rows[] = array(t('graphs provided from'), array('data' => l(guifi_service_str($device['graph_server']), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2));
    $ip = guifi_main_ip($device[id]);
    $rows[] = array(t('IP address & MAC'), $ip[ipv4] . '/' . $ip[maskbits] . ' ' . $device[mac]);
    $status_url = guifi_cnml_availability(array('device' => $device['id'], 'format' => 'long'), $gs);
    if (!empty($ip[ipv4])) {
        $rows[] = array(t('status &#038; availability'), array('data' => t($device[flag]) . $status_url, 'class' => $device['flag']));
    }
    $rows[] = array(array('data' => theme_guifi_contacts($device), 'colspan' => 2));
    return array_merge($rows);
}
Example #4
0
/**
 * guifi_node_graph_overview
 * outputs an overiew graph of the node
**/
function theme_guifi_node_graphs_overview($node, $links = FALSE)
{
    $gs = guifi_service_load(guifi_graphs_get_server($node->id, 'node'));
    $radios = array();
    $query = db_query("SELECT * FROM {guifi_radios} WHERE nid=%d", $node->id);
    while ($radio = db_fetch_array($query)) {
        $radios[] = $radio;
    }
    // print "Count radios: ".count($radios)."\n<br />";
    if (count($radios) > 1) {
        if (substr($gs->var['url'], 0, 3) == "fot") {
            //  graph all devices.about a node. Ferran Ot
            while ($radio = db_fetch_object($query)) {
                $ssid = get_SSID_radio($radio->id);
                $ssid = strtolower($ssid);
                $mrtg_url = substr($gs->var['url'], 3);
                $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg" target="_blank"> <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg&png=weekly"></a>');
                $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg" target="_blank"> <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg&png=weekly"></a>');
            }
            $ret = array_merge($rows);
        } else {
            $args = array('type' => 'supernode', 'node' => $node->id);
            //      $args = sprintf('type=supernode&node=%d&direction=',$node->id);
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=in') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=in') . '"></a>', 'align' => 'center'));
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=out') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=out') . '"></a>', 'align' => 'center'));
            //      $rows[] = array(
            //      guifi_cnml_call_service($gs->var['url'],'graph',$args,'direction=in'sprintf('<a href="'.base_path().'guifi/graph_detail?'.$args.'in"><img src="'.$gs->var['url'].'?'.$args.'in"></a>',$node->id));
            //      $rows[] = array(sprintf('<a href="'.base_path().'guifi/graph_detail?'.$args.'out"><img src="'.$gs->var['url'].'?'.$args.'out"></a>',$node->id));
            $ret = array_merge($rows);
        }
    } else {
        if (count($radios) == 1) {
            $ret = guifi_device_graph_overview($radios[0]);
        }
    }
    $output = theme('table', NULL, $ret);
    if ($links) {
        $node = node_load(array('nid' => $node->id));
        drupal_set_title(t('graph overview @ %node', array('%node' => $node->title)));
        drupal_set_breadcrumb(guifi_node_ariadna($node));
        $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE));
        print theme('page', $output, FALSE);
        return;
    }
    return $output;
}
/**
 * guifi_device_graph_overview
 * outputs an overiew graph of the device
**/
function guifi_device_graph_overview($radio)
{
    guifi_log(GUIFILOG_TRACE, 'guifi_device_graph_overview()', $radio);
    if (isset($radio['mode'])) {
        $radio['type'] = 'radio';
    }
    if ($radio['graph_server'] == -1) {
        $rows[] = array(t('This device has the graphs disabled.'));
        return array_merge($rows);
    }
    if (empty($radio['graph_server'])) {
        $gs = guifi_service_load(guifi_graphs_get_server($radio['id'], 'device'));
    } else {
        $gs = guifi_service_load($radio['graph_server']);
    }
    if (substr($server_mrtg, 0, 3) == "fot") {
        $ssid = get_SSID_radio($radio['id']);
        $ssid = strtolower($ssid);
        $mrtg_url = substr($server_mrtg, 3);
        $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg" target="_blank" > <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg&png=weekly"></a>');
        $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg" target="_blank" > <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg&png=weekly"></a>');
        return array_merge($rows);
    } else {
        $clients = db_fetch_object(db_query("SELECT count(c.id) count " . "FROM {guifi_links} c " . "WHERE c.device_id=%d " . "  AND c.link_type IN ('wds','ap/client','bridge')", $radio['id']));
        $args = array('type' => 'clients', 'node' => $radio['nid'], 'device' => $radio['id']);
        if ($clients->count > 1) {
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=in') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=in') . '"></a>', 'align' => 'center'));
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=out') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=out') . '"></a>', 'align' => 'center'));
        } else {
            if ($radio['type'] == 'radio' or $radio['variable']['mrtg_index'] != '') {
                $args['type'] = 'device';
                $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args) . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args) . '"></a>', 'align' => 'center'));
            }
        }
        $args['type'] = 'pings';
        $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args) . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args) . '"></a>', 'align' => 'center'));
        return array_merge($rows);
    }
}
Example #6
0
/** guifi_zone_data(): outputs the zone information data
**/
function guifi_zone_data($zone)
{
    $rows[] = array(t('zone name'), $zone->nick . ' - <b>' . $zone->title . '</b>');
    if (count($zone->maintainers)) {
        $rows[] = array(t('Maintenance & SLAs'), implode(', ', guifi_maintainers_links($zone->maintainers)));
    } else {
        $pmaintainers = guifi_maintainers_parents($zone->id);
        if (!empty($pmaintainers)) {
            $rows[] = array(t('Maintenance & SLAs') . ' ' . t('(from parents)'), implode(', ', guifi_maintainers_links($pmaintainers)));
        }
    }
    if ($zone->homepage) {
        $rows[] = array(t('homepage'), l($zone->homepage, $zone->homepage));
    }
    $rows[] = array(t('default proxy'), l(guifi_service_str($zone->proxy_id), guifi_zone_get_service($zone, 'proxy_id', TRUE)));
    if ($zone->graph_server > 0) {
        $gs = node_load(array('nid' => $zone->graph_server));
    } else {
        $gs = node_load(array('nid' => guifi_graphs_get_server($zone->id, 'zone')));
    }
    $rows[] = array(t('default graph server'), array('data' => l(guifi_service_str($zone->graph_server), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2));
    $rows[] = array(t('network global information') . ':', NULL);
    //  $rows[] = array(t('Mode'),t($zone->zone_mode));
    $rows[] = array(t('DNS Servers'), $zone->dns_servers);
    $rows[] = array(t('NTP Servers'), $zone->ntp_servers);
    $rows[] = array(t('OSPF zone'), $zone->ospf_zone);
    $tz = db_fetch_object(db_query("SELECT description FROM {guifi_types} WHERE type = 'tz' AND text = '%s'", $zone->time_zone));
    $rows[] = array(t('Time zone'), $tz->description);
    return array_merge($rows);
}