function bgp_peer($id, $ipv4, $disabled)
 {
     $peername = guifi_get_hostname($id);
     _outln('/ routing bgp peer');
     _outln(sprintf(':foreach i in [find name=%s] do={/routing bgp peer remove $i;}', $peername));
     _outln(sprintf('add name="%s" instance=default remote-address=%s remote-as=%s \\ ', $peername, $ipv4, $id));
     _outln(sprintf('multihop=no route-reflect=no ttl=default in-filter=ebgp-in out-filter=ebgp-out disabled=%s', $disabled));
 }
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
/**
 * 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;
    }
}
Exemplo n.º 4
0
function guifi_links_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $remote_did = array_pop($values);
    $remote_nid = array_pop($values);
    $link_id = array_pop($values);
    $dummy = array_pop($values);
    $ipv4_id = array_pop($values);
    $dummy = array_pop($values);
    $interface_id = array_pop($values);
    $dummy = array_pop($values);
    if ($values['0'] == 'radios') {
        $radio_id = array_pop($values);
        $fbase =& $form_state['values']['radios'][$radio_id];
        $fbase['unfold'] = TRUE;
    } else {
        $fbase =& $form_state['values'];
    }
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_radio_interface_link_delete_submit(radio: %d-%s, interface: %d, ipv4: %d, lid: %d, rnid: %d rdid: %d)', $radio_id, $form_state['values']['radios'][$radio_id]['mode'], $interface_id, $ipv4_id, $link_id, $remote_nid, $remote_did), $values);
    $fbase['interfaces'][$interface_id]['unfold'] = TRUE;
    $fipv4 =& $fbase['interfaces'][$interface_id]['ipv4'][$ipv4_id];
    $fipv4['unfold'] = TRUE;
    $flink =& $fipv4['links'][$link_id];
    $flink['unfold'] = TRUE;
    $flink['deleted'] = TRUE;
    $flink['ipv4']['unfold'] = TRUE;
    // if P2P link or AP/Client link and radio is the client
    // delete also the local IP
    if ($flink['ipv4']['netmask'] == '255.255.255.252' or $ipv4['netmask'] == '255.255.255.248' or $ipv4['netmask'] == '255.255.255.240' or $form_state['values']['radios'][$radio_id]['mode'] == 'client') {
        $fipv4['deleted'] = TRUE;
    }
    $form_state['rebuild'] = TRUE;
    drupal_set_message(t('%type link with %node/%device deleted.', array('%type' => $fbase['interfaces'][$interface_id]['interface_type'], '%node' => guifi_get_nodename($remote_nid), '%device' => guifi_get_hostname($remote_did))));
    return TRUE;
}
Exemplo n.º 5
0
function guifi_device_links_print($device, $ltype = '%')
{
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_links_print(%s)', $ltype), $device);
    $oGC = new GeoCalc();
    $dtotal = 0;
    $ltotal = 0;
    if ($ltype == '%') {
        $title = t('network information');
    } else {
        $title = t('network information') . ' (' . $ltype . ')';
    }
    $rows_wds = array();
    $rows_ap_client = array();
    $rows_cable = array();
    $loc1 = db_fetch_object(db_query('SELECT lat, lon, nick ' . 'FROM {guifi_location} WHERE id=%d', $device['nid']));
    $curr_radio = 0;
    switch ($ltype) {
        case '%':
        case 'wds':
        case 'ap/client':
            $dname_curr = '';
            if ($device['radios']) {
                foreach ($device['radios'] as $radio_id => $radio) {
                    if ($radio['interfaces']) {
                        foreach ($radio['interfaces'] as $interface_id => $interface) {
                            if ($interface['ipv4']) {
                                foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                                    if ($ipv4['links']) {
                                        foreach ($ipv4['links'] as $link_id => $link) {
                                            guifi_log(GUIFILOG_TRACE, 'going to list link', $link);
                                            $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid']));
                                            $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3);
                                            $dAz = round($oGC->GCAzimuth($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon));
                                            // Calculo orientacio
                                            if ($dAz < 23) {
                                                $dOr = t("N");
                                            } else {
                                                if ($dAz < 68) {
                                                    $dOr = t("NE");
                                                } else {
                                                    if ($dAz < 113) {
                                                        $dOr = t("E");
                                                    } else {
                                                        if ($dAz < 158) {
                                                            $dOr = t("SE");
                                                        } else {
                                                            if ($dAz < 203) {
                                                                $dOr = t("S");
                                                            } else {
                                                                if ($dAz < 248) {
                                                                    $dOr = t("SW");
                                                                } else {
                                                                    if ($dAz < 293) {
                                                                        $dOr = t("W");
                                                                    } else {
                                                                        if ($dAz < 338) {
                                                                            $dOr = t("NW");
                                                                        } else {
                                                                            $dOr = t("N");
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                            $ipdest = explode('.', $link['interface']['ipv4']['ipv4']);
                                            $status_url = guifi_cnml_availability(array('device' => $link['device_id'], 'format' => 'short'));
                                            $cr = db_fetch_object(db_query("SELECT count(*) count FROM {guifi_radios} r WHERE id=%d", $link['device_id']));
                                            if ($cr->count > 1) {
                                                $rn = db_fetch_object(db_query("SELECT ssid FROM {guifi_radios} r WHERE r.id=%d AND r.radiodev_counter=%d", $link['device_id'], $link['interface']['radiodev_counter']));
                                                $dname = guifi_get_hostname($link['device_id']) . '<br />' . $rn->ssid;
                                            } else {
                                                $dname = guifi_get_hostname($link['device_id']);
                                            }
                                            $wrow = array($dname_curr != $radio['ssid'] ? array('data' => '<strong>' . $radio['ssid'] . '</strong>', 'header') : '<small>' . $radio['ssid'] . '</small>', array('data' => $link_id, 'align' => 'right'), '<a href="' . base_path() . 'guifi/device/' . $link['device_id'] . '">' . $dname . '</a>', '<a href="' . base_path() . 'node/' . $link['nid'] . '">' . $loc2->nick . '</a>', $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $status_url, 'class' => $link['flag']), $link[routing], $gDist, $dAz . '-' . $dOr);
                                            $dname_curr = $radio['ssid'];
                                            if ($interface['interface_type'] == 'wds/p2p' or $interface['interface_class'] == 'wds/p2p') {
                                                $rows_wds[] = $wrow;
                                            }
                                            if ($link['link_type'] == 'ap/client') {
                                                $rows_ap_client[] = $wrow;
                                            }
                                            $dtotal = $dtotal + $gDist;
                                            $ltotal++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($ltype != '%') {
                break;
            }
        case 'cable':
            $iname_curr = '';
            if ($device['interfaces']) {
                foreach ($device['interfaces'] as $interface_id => $interface) {
                    if ($interface['ipv4']) {
                        foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                            if ($ipv4['links']) {
                                foreach ($ipv4['links'] as $link_id => $link) {
                                    $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid']));
                                    $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3);
                                    $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                    $ipdest = explode('.', $link['interface']['ipv4']['ipv4']);
                                    if ($gs->var['url'] != NULL) {
                                        $img_url = ' <img src=' . $gs->var['url'] . '?device=' . $link['device_id'] . '&type=availability&format=short>';
                                    } else {
                                        $img_url = NULL;
                                    }
                                    $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, array('data' => $link_id, 'align' => 'right'), l(guifi_get_hostname($link['device_id']), 'guifi/device/' . $link['device_id']), $link['interface']['interface_type'], $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $img_url, 'class' => $link['flag']), $link[routing]);
                                    $ltotal++;
                                    $iname_curr = $interface['interface_type'];
                                }
                            } else {
                                $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, null, null, null, $ipv4['ipv4'] . '/' . $item['maskbits']);
                                $ltotal++;
                                $iname_curr = $interface['interface_type'];
                            }
                        }
                    }
                    // foreach link
                    $iname_curr = $interface['interface_type'];
                }
            }
            // foreach ipv4
            if ($ltype == 'cable') {
                break;
            }
    }
    $header_cable = array(t('interface'), array('data' => t('id'), 'align' => 'right'), t('device'), t('remote<br>interface'), t('ip address'), '&nbsp;', t('status'), t('routing'));
    $header_wireless = array_merge($header_cable, array(t('kms.'), t('az.')));
    $header_wireless[3] = t('node');
    $output = '';
    $attr = array('class' => 'list-links');
    if ($rows_ap_client) {
        $output .= theme_box('<hr>' . t('ap/client'), theme_table($header_wireless, $rows_ap_client, $attr));
    }
    if ($rows_wds) {
        $output .= theme_box('<hr>' . t('wds/p2p'), theme_table($header_wireless, $rows_wds, $attr));
    }
    if ($rows_cable) {
        $output .= theme_box('<hr>' . t('cable'), theme_table($header_cable, $rows_cable, $attr));
    }
    if ($output) {
        return '<h2>' . $title . '</h2>' . '<h3>' . t('Totals') . ': ' . $ltotal . ' ' . t('links') . ', ' . $dtotal . ' ' . t('kms.') . '</h3><br>' . $output;
    } else {
        return;
    }
}
Exemplo n.º 6
0
 function merge_static($link, &$dhcp_statics, &$max, &$curr)
 {
     if (empty($link['interface'][mac])) {
         $link['interface'][mac] = 'FF:FF:FF:FF:FF:FF';
     }
     $dhcp_statics[] = array($link['interface'][ipv4][ipv4], $link['interface'][mac], guifi_get_hostname($link['interface'][device_id]));
     $curr = explode(".", $link['interface'][ipv4][ipv4]);
     if ($curr[3] > $max[3]) {
         $max[3] = $curr[3];
     }
 }
Exemplo n.º 7
0
function guifi_list_services_query($param, $typestr = 'by zone', $service = '%')
{
    $rows = array();
    $sqlprefix = "SELECT s.*,z.title zonename " . "FROM {guifi_services} s " . "  LEFT JOIN {guifi_devices} d ON s.device_id=d.id " . "  LEFT JOIN {guifi_zone} z ON s.zone_id=z.id " . "  LEFT JOIN {guifi_location} l ON d.nid=l.id " . "WHERE ";
    switch ($typestr) {
        case t('by zone'):
            $childs = guifi_zone_childs($param->id);
            $sqlwhere = sprintf('s.zone_id IN (%s) ', implode(',', $childs));
            break;
        case t('by node'):
            $sqlwhere = sprintf('d.nid = %d ', $param->nid);
            break;
        case t('by device'):
            $sqlwhere = sprintf('d.id = %d ', $param);
            break;
    }
    $query = db_query($sqlprefix . $sqlwhere . ' ORDER BY s.service_type, s.zone_id, s.nick');
    $current_service = '';
    while ($service = db_fetch_object($query)) {
        $node = node_load(array('nid' => $service->id));
        if ($current_service != $service->service_type) {
            $typedescr = db_fetch_object(db_query("SELECT * FROM {guifi_types} WHERE type='service' AND text = '%s'", $service->service_type));
            $rows[] = array('<strong>' . t($typedescr->description) . '</strong>', NULL, NULL, NULL, NULL);
            $current_service = $service->service_type;
        }
        $status_url = guifi_cnml_availability(array('device' => $service->device_id, 'format' => 'short'));
        $rows[] = array('<a href="' . base_path() . 'node/' . $service->id . '">' . $node->title . '</a>', '<a href="' . base_path() . 'node/' . $service->zone_id . '">' . $service->zonename . '</a>', '<a href="' . base_path() . 'guifi/device/' . $service->device_id . '">' . guifi_get_hostname($service->device_id) . '</a>', array('data' => t($node->status_flag), 'class' => $node->status_flag), $status_url);
    }
    return array_merge($rows);
}
Exemplo n.º 8
0
 function guifi_unsolclic_wds_vars($dev)
 {
     global $rc_startup;
     $wds_links = array();
     $wds_str = '';
     if (!empty($dev->radios)) {
         foreach ($dev->radios as $radio_id => $radio) {
             if (!empty($radio[interfaces])) {
                 foreach ($radio[interfaces] as $interface_id => $interface) {
                     if ($interface['interface_type'] == 'wds/p2p') {
                         if (!empty($interface[ipv4])) {
                             foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                                 if (!empty($ipv4[links])) {
                                     foreach ($ipv4[links] as $key => $link) {
                                         if ($link['link_type'] == 'wds') {
                                             $wds_links[] = $link;
                                         }
                                         $iplocal[] = $ipv4;
                                         $iflocal[] = $interface;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($wds_links) == 0) {
         return;
     }
     _outln_comment('');
     _outln_comment(t('WDS Links for') . ' ' . $dev->nick);
     if ($dev->variable['firmware'] == 'DD-WRTv23' or $dev->variable['firmware'] == 'DD-guifi') {
         $ifcount = 2;
     } else {
         $ifcount = 1;
     }
     foreach ($wds_links as $key => $wds) {
         $hostname = guifi_get_hostname($wds['device_id']);
         _outln_comment($wds['device_id'] . '-' . $hostname);
         _outln_nvram('wl_wds' . ($key + 1) . '_desc', $hostname);
         if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
             $ifcount++;
             _outln_nvram('wl_wds' . ($key + 1) . '_enable', '1');
             if ($dev->variable['firmware'] == 'DD-WRTv23' or $dev->variable['firmware'] == 'DD-guifi') {
                 _outln_nvram('wl_wds' . ($key + 1) . '_if', 'wds0.4915' . $ifcount);
             } else {
                 _outln_nvram('wl_wds' . ($key + 1) . '_if', 'wds0.' . $ifcount);
             }
             $wds_str .= ' ' . $wds['interface']['mac'];
             // Bug del Talisman 1.0.5
             if ($dev->variable['firmware'] == 'Talisman') {
                 $rc_startup .= "ifconfig wds0." . $ifcount . " up\n<br />";
             }
         } else {
             _outln_nvram('wl_wds' . ($key + 1) . '_enable', '0');
         }
         _outln_nvram('wl_wds' . ($key + 1) . '_ipaddr', $iplocal[$key][ipv4]);
         _outln_nvram('wl_wds' . ($key + 1) . '_hwaddr', $wds['interface'][mac]);
         _outln_nvram('wl_wds' . ($key + 1) . '_netmask', $iplocal[$key][netmask]);
     }
     if (count($wds_links) >= 11) {
         return;
     }
     _outln_comment();
     _outln_comment(t('Free WDS slots'));
     for ($key = count($wds_links) + 1; $key <= 10; $key++) {
         _outln_nvram('wl_wds' . $key . '_desc', t('free'));
         _outln_nvram('wl_wds' . $key . '_enable', '0');
         _outln_nvram('wl_wds' . $key . '_ipaddr', '172.0.0.0');
         _outln_nvram('wl_wds' . $key . '_hwaddr', '00:13:00:00:00:00');
         _outln_nvram('wl_wds' . $key . '_netmask', '255.255.255.252');
     }
     _out_nvram('wl0_wds', $wds_str . '"');
     _outln_nvram('wl0_lazywds', '0');
     _outln_nvram('wl_lazywds', '0');
 }