Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
function guifi_kamikaze_files($dev, $zone)
{
    //SOME VARIABLES
    $dns = guifi_get_dns($zone, 2);
    $lan = guifi_unsolclic_if($dev->id, 'wLan/Lan');
    $lan_network = _ipcalc($lan->ipv4, $lan->netmask);
    switch ($dev->variable['model_id']) {
        case "38":
            // RouterStation
            $wireless_model = 'atheros';
            $lan_iface = 'eth0';
            $lan2_iface = 'eth1';
            $packages = 'ar71xx/packages';
            break;
        default:
            _outln_comment('model id not supported');
            exit;
    }
    // SECTION FILES
    _outln_comment();
    _outln_comment();
    _outln_comment(t('Wireless Settings'));
    print '<pre>';
    function wds_add($dev, $radio, $radio_id)
    {
        $wds_links = array();
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links[] = $link;
                        }
                    }
                }
                $ifcount = 0;
                foreach ($wds_links as $key => $wds) {
                    if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                        $status = 'active';
                        print 'uci set wireless.@wifi-iface[' . $radio_id . '].bssid' . $ifcount . '=' . $wds['interface']['mac'] . '<br />';
                        $ifcount++;
                    } else {
                        $status = 'disabled';
                        print '# uci set wireless.@wifi-iface[' . $radio_id . '].bssidX=' . $wds['interface']['mac'] . ' # ' . t($wds['flag']) . '<br />';
                    }
                }
            }
        }
    }
    function wds_network($dev, $radio)
    {
        $ifcount = '0';
        foreach ($radio[interfaces] as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    if ($link['link_type'] == 'wds') {
                        $wds_links = array();
                        $wds_links[] = $link;
                        foreach ($wds_links as $key => $wds) {
                            $hostname = guifi_get_hostname($wds['device_id']);
                            if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                                $status = 'active';
                                print '
## wds_' . $hostname . '
uci delete network.wds_' . $hostname . '
uci set network.wds_' . $hostname . '=interface
uci set network.wds_' . $hostname . '.ifname=ath' . $radio[radiodev_counter] . '.wds' . $ifcount . '
uci set network.wds_' . $hostname . '.proto=static
';
                                $ifcount++;
                            } else {
                                $status = 'disabled';
                                print '
##### ' . t($wds['flag']) . ' ####
## wds_' . $hostname . '
# uci set network.wds_' . $hostname . '.ifname=ath' . $radio[radiodev_counter] . '.wdsX
# uci set network.wds_' . $hostname . '.proto=none
';
                            }
                        }
                        if ($status == 'active') {
                            print 'uci set network.wds_' . $hostname . '.ipaddr=' . $ipv4[ipv4] . '
uci set network.wds_' . $hostname . '.netmask=' . $ipv4['netmask'] . '
';
                        } else {
                            print '# uci set network.wds_' . $hostname . '.ipaddr=' . $ipv4[ipv4] . '
# uci set network.wds_' . $hostname . '.netmask=' . $ipv4['netmask'] . '
';
                        }
                    }
                }
            }
        }
    }
    if (isset($dev->radios)) {
        foreach ($dev->radios as $radio_id => $radio) {
            $mode = 'apwds';
            $ssid = $radio[ssid];
            $channel = atheros_channel($radio);
            if ($channel <= 14) {
                $band = '11b';
            } else {
                $band = '11a';
            }
            if (empty($radio[antenna_mode])) {
                $radio[antenna_mode] = '1';
            } else {
                if ($radio[antenna_mode] != 'Main') {
                    $radio[antenna_mode] = '2';
                } else {
                    $radio[antenna_mode] = '1';
                }
            }
            if ($radio_id == '0') {
                $wireless_iface = 'wifi0';
                $network = 'wlanLan';
            } else {
                $wireless_iface = 'wifi' . $radio_id;
                $network = 'wlan' . ($radio_id + 1);
            }
            $wireless_model = 'atheros';
            $txant = $radio[antenna_mode];
            $rxant = $radio[antenna_mode];
            print '
## Radio: ' . $radio[ssid] . '
uci delete wireless.' . $wireless_iface . '
uci set wireless.' . $wireless_iface . '=wifi-device
uci set wireless.' . $wireless_iface . '.type=' . $wireless_model . '
uci set wireless.' . $wireless_iface . '.channel=' . $channel . '
uci set wireless.' . $wireless_iface . '.disabled=0
uci set wireless.' . $wireless_iface . '.hwmode=' . $band . '
uci set wireless.' . $wireless_iface . '.diversity=0
uci set wireless.' . $wireless_iface . '.txantenna=' . $txant . '
uci set wireless.' . $wireless_iface . '.rxantenna=' . $rxant . '
uci set wireless.' . $wireless_iface . '.txpower=16
uci set wireless.' . $wireless_iface . '.regdomain=31
uci set wireless.' . $wireless_iface . '.country=724
uci set wireless.' . $wireless_iface . '.distance=2000
uci delete wireless.@wifi-iface[' . $radio_id . ']
uci add wireless wifi-iface
uci set wireless.@wifi-iface[' . $radio_id . ']=wifi-iface
uci set wireless.@wifi-iface[' . $radio_id . '].device=' . $wireless_iface . '
uci set wireless.@wifi-iface[' . $radio_id . '].network=' . $network . '
uci set wireless.@wifi-iface[' . $radio_id . '].mode=' . $mode . '
uci set wireless.@wifi-iface[' . $radio_id . '].ssid=guifi.net-' . $radio[ssid] . '
uci set wireless.@wifi-iface[' . $radio_id . '].encryption=none
';
            wds_add($dev, $radio, $radio_id);
        }
    }
    print 'sleep 1</pre>';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('Network Settings'));
    print '<pre>';
    function cable_network($dev)
    {
        foreach ($dev->interfaces as $interface_id => $interface) {
            switch ($interface[interface_type]) {
                case 'vlan1':
                    $iname = 'eth0:1';
                    break;
                case 'vlan2':
                    $iname = 'eth1';
                    break;
                case 'vlan3':
                    $iname = 'eth1:1';
                    break;
                default:
                    $iname = $interface[interface_type];
                    break;
            }
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $network = guifi_get_hostname($link[device_id]);
                    if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                        $status = 'active';
                        if ($interface[interface_type] != 'wLan/Lan') {
                            print '
## cable_' . $network . '
uci delete network.' . $network . '
uci set network.' . $network . '=interface
uci set network.' . $network . '.ifname=' . $iname . '
uci set network.' . $network . '.proto=static
uci set network.' . $network . '.ipaddr=' . $ipv4[ipv4] . '
uci set network.' . $network . '.netmask=' . $ipv4[netmask] . '
';
                        }
                    } else {
                        $status = 'disabled';
                        print '
##### ' . t($link['flag']) . ' ####
## cable_' . $network . '
# uci set network.' . $network . '=interface
# uci set network.' . $network . '.ifname=' . $iname . '
# uci set network.' . $network . '.proto=static
# uci set network.' . $network . '.ipaddr=' . $ipv4[ipv4] . '
# uci set network.' . $network . '.netmask=' . $ipv4[netmask] . '
';
                    }
                }
            }
        }
    }
    print '
uci set network.loopback=interface
uci set network.loopback.ifname=lo
uci set network.loopback.proto=static
uci set network.loopback.ipaddr=127.0.0.1
uci set network.loopback.netmask=255.0.0.0

uci delete network.lan
uci delete network.wan
';
    if (isset($dev->radios)) {
        foreach ($dev->radios as $radio_id => $radio) {
            if (isset($radio[interfaces])) {
                foreach ($radio[interfaces] as $interface_id => $interface) {
                    if ($interface[interface_type] != 'wds/p2p') {
                        if (isset($interface[ipv4])) {
                            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                                if ($interface[interface_type] == 'wLan/Lan') {
                                    $iface = '"ath0 eth0"';
                                    $network = 'wlanLan';
                                } else {
                                    $iface = 'wifi' . $radio_id;
                                    $network = 'wlan' . ($radio_id + 1);
                                }
                                $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                                // FILE NETWORK
                                print '
uci delete network.' . $network . '
uci set network.' . $network . '=interface
';
                                if ($interface[interface_type] == 'wLan/Lan') {
                                    print 'uci set network.' . $network . '.type=bridge
';
                                }
                                print 'uci set network.' . $network . '.ifname=' . $iface . '
uci set network.' . $network . '.proto=static
uci set network.' . $network . '.ipaddr=' . $ipv4[ipv4] . '
uci set network.' . $network . '.netmask=' . $ipv4[netmask] . '
uci set network.' . $network . '.dns="' . $dns . '"
';
                            }
                        }
                    }
                }
            }
            wds_network($dev, $radio);
        }
    }
    cable_network($dev);
    print 'sleep 1</pre>';
    //FILE FIREWALL
    _outln_comment();
    _outln_comment();
    _outln_comment(t('Firewall Settings'));
    print '<pre>';
    print 'uci set firewall.@defaults[0]=defaults
uci set firewall.@defaults[0].syn_flood=1
uci set firewall.@defaults[0].input=ACCEPT
uci set firewall.@defaults[0].output=ACCEPT
uci set firewall.@defaults[0].forward=ACCEPT
';
    print 'COUNTER=0
while [  $COUNTER -lt 64 ]; do
  uci delete firewall.@zone[0] > /dev/null 2>&1
  let COUNTER=COUNTER+1 
done
uci delete firewall.@forwarding[0]
';
    $icount = '0';
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    if ($interface[interface_type] == 'wLan/Lan') {
                        $network = 'wlanLan';
                    } else {
                        $network = 'wlan' . ($radio_id + 1);
                    }
                    print 'uci add firewall zone
uci set firewall.@zone[' . $icount . ']=zone
uci set firewall.@zone[' . $icount . '].name=' . $network . '
uci set firewall.@zone[' . $icount . '].input=ACCEPT
uci set firewall.@zone[' . $icount . '].output=ACCEPT
uci set firewall.@zone[' . $icount . '].forward=ACCEPT
';
                    $icount++;
                }
            }
        }
    }
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links = array();
                            $wds_links[] = $link;
                            foreach ($wds_links as $key => $wds) {
                                $hostname = guifi_get_hostname($wds['device_id']);
                                if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                                    print 'uci add firewall zone
uci set firewall.@zone[' . $icount . ']=zone
uci set firewall.@zone[' . $icount . '].name=wds_' . $hostname . '
uci set firewall.@zone[' . $icount . '].input=ACCEPT
uci set firewall.@zone[' . $icount . '].output=ACCEPT
uci set firewall.@zone[' . $icount . '].forward=ACCEPT
';
                                    $icount++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    foreach ($dev->interfaces as $interface_id => $interface) {
        foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
            foreach ($ipv4[links] as $link_id => $link) {
                $hostname = guifi_get_hostname($link['device_id']);
                if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                    print 'uci add firewall zone
uci set firewall.@zone[' . $icount . ']=zone
uci set firewall.@zone[' . $icount . '].name=' . $hostname . '
uci set firewall.@zone[' . $icount . '].input=ACCEPT
uci set firewall.@zone[' . $icount . '].output=ACCEPT
uci set firewall.@zone[' . $icount . '].forward=ACCEPT
';
                    $icount++;
                }
            }
        }
    }
    print 'sleep 1</pre>';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('DHCP Static Leases'));
    print '<pre>';
    $dhcp_statics = array();
    $max = explode(".", $dev->ipv4);
    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];
        }
    }
    $main_ip = guifi_main_ip($dev->id);
    $item = _ipcalc_by_netbits($main_ip[ipv4], $main_ip[maskbits]);
    $max = explode(".", $main_ip[ipv4]);
    // cable links
    foreach ($dev->interfaces as $interface) {
        foreach ($interface[ipv4] as $ipv4) {
            foreach ($ipv4[links] as $link) {
                if ($link['interface'][ipv4][ipv4] != '') {
                    $item2 = _ipcalc($link['interface'][ipv4][ipv4], $link['interface'][ipv4][netmask]);
                    if ($item[netid] == $item2[netid]) {
                        merge_static($link, $dhcp_statics, $max, $cur);
                    }
                }
            }
        }
    }
    // ap/client links
    foreach ($dev->radios as $radio) {
        foreach ($radio[interfaces] as $interface) {
            foreach ($interface[ipv4] as $ipv4) {
                foreach ($ipv4[links] as $link) {
                    if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                        merge_static($link, $dhcp_statics, $max, $cur);
                    }
                }
            }
        }
    }
    $statics = count($dhcp_statics) - 1;
    $totalstatics = count($dhcp_statics);
    $first = explode(".", $item[netid]);
    $last = explode(".", $item[broadcast]);
    $limit = $last[3] - 1 - ($first[3] + 3) - $totalstatics;
    $counter = '0';
    print 'COUNTER=0
while [  $COUNTER -lt 64 ]; do
  uci delete luci_ethers.@static_lease[0] > /dev/null 2>&1
  let COUNTER=COUNTER+1 
done
';
    foreach ($dhcp_statics as $static) {
        print '
## Device: ' . $static[2] . '
uci add luci_ethers static_lease
uci set luci_ethers.@static_lease[' . $counter . ']=static_lease
uci set luci_ethers.@static_lease[' . $counter . '].macaddr=' . $static[1] . '
uci set luci_ethers.@static_lease[' . $counter . '].ipaddr=' . $static[0] . '
';
        $counter++;
    }
    print 'sleep 1</pre>';
    // FILE DHCP
    _outln_comment();
    _outln_comment();
    _outln_comment(t('DHCP Settings'));
    print '<pre>';
    print 'uci set dhcp.@dnsmasq[0]=dnsmasq                                                                                                               
uci set dhcp.@dnsmasq[0].domainneeded=1
uci set dhcp.@dnsmasq[0].boguspriv=1
uci set dhcp.@dnsmasq[0].filterwin2k=0
uci set dhcp.@dnsmasq[0].localise_queries=1
uci set dhcp.@dnsmasq[0].local=/lan/
uci set dhcp.@dnsmasq[0].domain=lan
uci set dhcp.@dnsmasq[0].expandhosts=1
uci set dhcp.@dnsmasq[0].nonegcache=0
uci set dhcp.@dnsmasq[0].authoritative=1
uci set dhcp.@dnsmasq[0].readethers=1
uci set dhcp.@dnsmasq[0].leasefile=/tmp/dhcp.leases
uci set dhcp.@dnsmasq[0].resolvfile=/tmp/resolv.conf.auto
';
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    if ($interface[interface_type] == 'wLan/Lan') {
                        $iface = 'wlanLan';
                        $network = 'wlanLan';
                    } else {
                        $network = 'wlan' . ($radio_id + 1);
                    }
                    $max = explode(".", $ipv4[ipv4]);
                    foreach ($ipv4[links] as $link) {
                        if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                            $totalstaticss = count($ipv4[links]);
                        }
                    }
                    $first = explode(".", $item[netid]);
                    $last = explode(".", $item[broadcast]);
                    $limit = $last[3] - 1 - ($first[3] + 3) - $totalstaticss;
                    $totalstaticss = '0';
                    print '
uci delete dhcp.lan
uci delete dhcp.wan
uci set dhcp.' . $network . '=dhcp
uci set dhcp.' . $network . '.interface=' . $network . '
uci set dhcp.' . $network . '.leasetime=12h
uci set dhcp.' . $network . '.start=' . ($max[3] + 2) . '
uci set dhcp.' . $network . '.limit=' . $limit . '
uci set dhcp.' . $network . '.netmask=' . $ipv4[netmask] . '
';
                }
            }
        }
    }
    print 'sleep 1</pre>';
    $wds_links = array();
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links[] = $link;
                        }
                    }
                }
            }
        }
    }
    foreach ($wds_links as $key => $wds) {
        if ($wds['routing'] == 'BGP') {
            $wds_bgpd = '1';
        }
        if ($wds['routing'] == 'OSPF') {
            $wds_ospfd = '1';
        }
    }
    $cable_links = array();
    foreach ($dev->interfaces as $interface_id => $interface) {
        foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
            foreach ($ipv4[links] as $link_id => $link) {
                if ($link['link_type'] == 'cable') {
                    $cable_links[] = $link;
                }
            }
        }
    }
    foreach ($cable_links as $key => $cable) {
        if ($cable['routing'] == 'BGP') {
            $cable_bgpd = '1';
        }
        if ($cable['routing'] == 'OSPF') {
            $cable_ospfd = '1';
        }
    }
    // QUAGGA CONFIG FILES
    $file_zebra = '';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/quagga/zebra.conf'));
    print '<pre>';
    print 'true > /etc/quagga/zebra.conf';
    print '</pre>';
    // FILE OSPFD
    if ($wds_ospfd == '1' || $cable_ospfd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/ospfd.conf'));
        print '<pre>';
        print 'cat > /etc/quagga/ospfd.conf << EOF
!
interface br-lan
!
router ospf
 ospf router-id ' . $lan->ipv4 . '
 redistribute bgp
';
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                    foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                        $network = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    }
                    if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                        print ' network ' . $network[netid] . '/' . $network[maskbits] . ' area 0<br />';
                    }
                }
            }
        }
        foreach ($wds_links as $key => $wds) {
            $iplocal[] = $wds['interface']['ipv4'];
            if ($wds['routing'] == 'OSPF') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                    print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . ' area 0<br />';
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    if ($link['routing'] == 'OSPF') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' network ' . $item[netid] . '/' . $item[maskbits] . ' area 0<br />';
                        }
                    }
                }
            }
        }
        print 'default-information originate
!
EOF

';
        print 'sleep 1</pre>';
    }
    // FILE BGPD
    if ($wds_bgpd == '1' || $cable_bgpd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/bgpd.conf'));
        print '<pre>';
        print 'cat > /etc/quagga/bgpd.conf << EOF
!
interface br-lan
!
router bgp ' . $dev->id . '
bgp router-id ' . $lan->ipv4 . '
';
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                    foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                        $network = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    }
                    print ' network ' . $network[netid] . '/' . $network[maskbits] . '<br />';
                }
            }
        }
        print 'redistribute ospf
';
        foreach ($wds_links as $key => $wds) {
            $iplocal[] = $wds['interface']['ipv4'];
            if ($wds['routing'] == 'BGP') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                    print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . '<br />';
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    if ($link['routing'] == 'BGP') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' network ' . $item[netid] . '/' . $item[maskbits] . '<br />';
                        }
                    }
                }
            }
        }
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['routing'] == 'BGP') {
                            if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                                print ' neighbor ' . $link['interface']['ipv4']['ipv4'] . ' remote-as ' . $link['device_id'] . '
';
                            }
                        }
                    }
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    if ($link['routing'] == 'BGP') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' neighbor ' . $link['interface']['ipv4']['ipv4'] . ' remote-as ' . $link['device_id'] . '
';
                        }
                    }
                }
            }
        }
        print 'EOF

';
        print 'sleep 1</pre>';
    }
    //FILE OPKG
    $opkg_conf = '
src/gz snapshots http://downloads.openwrt.org/snapshots/' . $packages . '
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /jffs
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/opkg.conf'));
    openwrt_out_file($opkg_conf, '/etc/opkg.conf');
}
Ejemplo n.º 4
0
 function _add_cnml_node(&$CNML, $node, &$summary, $action)
 {
     global $devices;
     global $radios;
     global $interfaces;
     global $links;
     global $services;
     global $models;
     $nodesummary->ap = 0;
     $nodesummary->client = 0;
     $nodesummary->devices = 0;
     $nodesummary->services = 0;
     $nodesummary->links = 0;
     if ($action != 'zones') {
         //      $nodeXML = $CNML->addChild('node',htmlspecialchars($node->body,ENT_QUOTES));
         $nodeXML = $CNML->addChild('node');
         foreach ($node as $key => $value) {
             if ($value) {
                 switch ($key) {
                     case 'body':
                         break;
                     case 'id':
                         $nodeXML->addAttribute('id', $value);
                         break;
                     case 'nick':
                         $nodeXML->addAttribute('title', $value);
                         break;
                     case 'lat':
                         $nodeXML->addAttribute('lat', $value);
                         break;
                     case 'lon':
                         $nodeXML->addAttribute('lon', $value);
                         break;
                     case 'elevation':
                         if ($value) {
                             $nodeXML->addAttribute('antenna_elevation', $value);
                         }
                         break;
                     case 'status_flag':
                         $nodeXML->addAttribute('status', $value);
                         break;
                     case 'graph_server':
                         $nodeXML->addAttribute('graph_server', $value);
                         break;
                     case 'timestamp_created':
                         $nodeXML->addAttribute('created', date('Ymd hi', $value));
                         break;
                     case 'timestamp_changed':
                         $nodeXML->addAttribute('updated', date('Ymd hi', $value));
                         break;
                 }
             }
         }
     }
     $summary->nodes++;
     if ($node->lon < $summary->minx) {
         $summary->minx = $node->lon;
     }
     if ($node->lat < $summary->miny) {
         $summary->miny = $node->lat;
     }
     if ($node->lon > $summary->maxx) {
         $summary->maxx = $node->lon;
     }
     if ($node->lat > $summary->maxy) {
         $summary->maxy = $node->lat;
     }
     // if report type = 'detail', going to list all node content
     // devices
     if (is_array($devices[$node->id])) {
         if (count($devices[$node->id])) {
             foreach ($devices[$node->id] as $id => $device) {
                 if ($action == 'detail') {
                     $deviceXML = $nodeXML->addChild('device', htmlspecialchars($device->comment, ENT_QUOTES));
                     foreach ($device as $key => $value) {
                         if ($value) {
                             switch ($key) {
                                 case 'body':
                                     comment;
                                 case 'id':
                                     $main_ip = guifi_main_ip($value);
                                     $deviceXML->addAttribute('id', $value);
                                     $deviceXML->addAttribute('mainipv4', $main_ip[ipv4]);
                                     break;
                                 case 'nick':
                                     $deviceXML->addAttribute('title', $value);
                                     break;
                                 case 'type':
                                     $deviceXML->addAttribute('type', $value);
                                     break;
                                 case 'flag':
                                     $deviceXML->addAttribute('status', $value);
                                     break;
                                 case 'graph_server':
                                     $deviceXML->addAttribute('graph_server', $value);
                                     break;
                                 case 'timestamp_created':
                                     $deviceXML->addAttribute('created', date('Ymd hi', $value));
                                     break;
                                 case 'timestamp_changed':
                                     $deviceXML->addAttribute('updated', date('Ymd hi', $value));
                                     break;
                                     // case 'mainipv4': $deviceXML->addAttribute('mainipv4',guifi_main_ip(id)); break;
                             }
                         }
                     }
                     // TODO obtenir model_id i firmware del device o no de extra
                     if (!empty($device->extra)) {
                         $device->variable = unserialize($device->extra);
                         if ($device->type == 'radio') {
                             if (isset($device->variable['firmware'])) {
                                 $deviceXML->addAttribute('firmware', $device->variable['firmware']);
                             }
                         }
                         if (isset($device->variable['model_id'])) {
                             $model_name = $models[(int) $device->variable['model_id']];
                             $deviceXML->addAttribute('name', $model_name);
                         }
                         if (!empty($device->variable['mrtg_index'])) {
                             $deviceXML->addAttribute('snmp_index', $device->variable['mrtg_index']);
                         }
                     }
                 }
                 $nodesummary->devices++;
                 // device radios
                 if (is_array($radios[$node->id][$device->id])) {
                     if (count($radios[$node->id][$device->id])) {
                         foreach ($radios[$node->id][$device->id] as $id => $radio) {
                             if ($action == 'detail') {
                                 $radioXML = $deviceXML->addChild('radio', htmlspecialchars($radio->comment, ENT_QUOTES));
                                 $radioXML->addAttribute('id', $radio->radiodev_counter);
                                 $radioXML->addAttribute('device_id', $device->id);
                                 foreach ($radio as $key => $value) {
                                     if ($value) {
                                         switch ($key) {
                                             case 'radiodev_counter':
                                             case 'comment':
                                                 break;
                                             case 'ssid':
                                                 $radioXML->addAttribute('ssid', $value);
                                                 break;
                                             case 'mode':
                                                 $radioXML->addAttribute('mode', $value);
                                                 break;
                                             case 'protocol':
                                                 $radioXML->addAttribute('protocol', $value);
                                                 break;
                                             case 'channel':
                                                 $radioXML->addAttribute('channel', $value);
                                                 break;
                                             case 'antenna_angle':
                                                 $radioXML->addAttribute('antenna_angle', $value);
                                                 break;
                                             case 'antenna_gain':
                                                 $radioXML->addAttribute('antenna_gain', $value);
                                                 break;
                                             case 'antenna_azimuth':
                                                 $radioXML->addAttribute('antenna_azimuth', $value);
                                                 break;
                                             case 'clients_accepted':
                                                 $radioXML->addAttribute('clients_accepted', $value);
                                                 break;
                                         }
                                     }
                                 }
                                 if (isset($device->variable['model_id'])) {
                                     // TODO resolve issue  wlanX ( 1,2,3,4, etc.. ) incremental.
                                     if (in_array($model_name, array('Routerboard 112', 'Routerboard 133', 'Routerboard 133C', 'Routerboard 153', 'Routerboard 333', 'Routerboard 411', 'Routerboard 433', 'Routerboard 532', 'Routerboard 600', 'Routerboard 800', 'Supertrasto guifiBUS guifi.net', 'Routerboard SXT 5HnD', 'Routerboard 493/G', 'OmniTIK Uxx-5HnD', 'Routerboard SXT Lite2', 'Routerboard SXT Lite5', 'Routerboard 2011', 'Routerboard Sextant'))) {
                                         switch ($device->variable['firmware']) {
                                             case 'RouterOSv2.9':
                                             case 'RouterOSv3.x':
                                             case 'RouterOSv4.0+':
                                             case 'RouterOSv4.7+':
                                             case 'RouterOSv5.x':
                                             case 'RouterOSv6.x':
                                                 $radioXML->addAttribute('snmp_name', 'wlan' . (string) ($id + 1));
                                                 break;
                                         }
                                     } else {
                                         $snmp = db_fetch_object(db_query('SELECT snmp_id FROM guifi_configuracioUnSolclic WHERE id=%d', $device->usc_id));
                                         list($modeap, $modesta) = explode("|", $snmp->snmp_id);
                                         if (empty($modesta)) {
                                             $modesta = $modeap;
                                         }
                                         if (eregi("^[0-9]+\$", $modeap)) {
                                             $snmp_iname = 'snmp_index';
                                         } else {
                                             $snmp_iname = 'snmp_name';
                                         }
                                         if (eregi("^[0-9]+\$", $modesta)) {
                                             $snmp_ciname = 'snmp_index';
                                         } else {
                                             $snmp_ciname = 'snmp_name';
                                         }
                                         if ($radio->mode == 'client') {
                                             $radioXML->addAttribute($snmp_ciname, $modesta);
                                         } else {
                                             $radioXML->addAttribute($snmp_iname, $modeap);
                                         }
                                     }
                                 }
                                 switch ($radio->mode) {
                                     case 'ap':
                                         $nodesummary->ap++;
                                         break;
                                     case 'client':
                                         $nodesummary->client++;
                                         break;
                                 }
                             }
                             // device radio interfaces
                             if (is_array($interfaces[$device->id][$radio->radiodev_counter])) {
                                 if (count($interfaces[$device->id][$radio->radiodev_counter])) {
                                     foreach ($interfaces[$device->id][$radio->radiodev_counter] as $radio_interfaces) {
                                         foreach ($radio_interfaces as $interface) {
                                             if (!array_search($interface->interface_type, array('a' => 'wds/p2p', 'b' => 'wLan', 'c' => 'wLan/Lan', 'd' => 'Wan')) and !array_search($interface->interface_class, array('a' => 'wds/p2p'))) {
                                                 continue;
                                             }
                                             if ($interface->interface_type == 'Wan' and $radio->mode != 'client') {
                                                 continue;
                                             }
                                             if ($action == 'detail') {
                                                 $interfaceXML = $radioXML->addChild('interface');
                                                 foreach ($interface as $key => $value) {
                                                     if ($value) {
                                                         switch ($key) {
                                                             case 'id':
                                                                 $interfaceXML->addAttribute('id', $interface->id);
                                                                 break;
                                                             case 'mac':
                                                                 $interfaceXML->addAttribute('mac', $interface->mac);
                                                                 break;
                                                             case 'ipv4':
                                                                 $interfaceXML->addAttribute('ipv4', $interface->ipv4);
                                                                 break;
                                                             case 'netmask':
                                                                 $interfaceXML->addAttribute('mask', $interface->netmask);
                                                                 break;
                                                             case 'interface_type':
                                                                 $interfaceXML->addAttribute('type', $interface->interface_type);
                                                                 break;
                                                         }
                                                     }
                                                 }
                                             }
                                             // linked interfaces
                                             if (is_array($links[$device->id][$interface->id])) {
                                                 if (count($links[$device->id][$interface->id])) {
                                                     foreach ($links[$device->id][$interface->id] as $id => $link) {
                                                         if (!array_search($link->link_type, array('a' => 'ap/client', 'b' => 'wds'))) {
                                                             continue;
                                                         }
                                                         if ($link->ipv4_id != $interface->ipv4_id) {
                                                             continue;
                                                         }
                                                         $nodesummary->links++;
                                                         if ($action == 'detail') {
                                                             $linkXML = $interfaceXML->addChild('link');
                                                             foreach ($link as $key => $value) {
                                                                 if ($value) {
                                                                     switch ($key) {
                                                                         case 'id':
                                                                             $linkXML->addAttribute('id', $link->id);
                                                                             break;
                                                                         case 'linked_node_id':
                                                                             $linkXML->addAttribute('linked_node_id', $link->linked_node_id);
                                                                             break;
                                                                         case 'linked_device_id':
                                                                             $linkXML->addAttribute('linked_device_id', $link->linked_device_id);
                                                                             break;
                                                                         case 'linked_interface_id':
                                                                             $linkXML->addAttribute('linked_interface_id', $link->linked_interface_id);
                                                                             break;
                                                                         case 'link_type':
                                                                             $linkXML->addAttribute('link_type', $link->link_type);
                                                                             break;
                                                                         case 'status':
                                                                             $linkXML->addAttribute('link_status', $link->status);
                                                                             break;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     // foreach link
                                                 }
                                             }
                                             //interface links
                                         }
                                     }
                                     // foreach radio interface
                                 }
                             }
                             // radio interfaces
                         }
                         // foreach radios
                     }
                 }
                 // device radios
                 // device interfaces
                 if (is_array($interfaces[$device->id])) {
                     if (count($interfaces[$device->id])) {
                         foreach ($interfaces[$device->id] as $device_interfaces) {
                             foreach ($device_interfaces as $counter_interfaces) {
                                 foreach ($counter_interfaces as $interface) {
                                     if (array_search($interface->interface_type, array('a' => 'wds/p2p', 'b' => 'wLan', 'c' => 'wlan/Lan')) and array_search($interface->interface_class, array('a' => 'wds/p2p'))) {
                                         continue;
                                     }
                                     if ($action == 'detail') {
                                         $interfaceXML = $deviceXML->addChild('interface');
                                         foreach ($interface as $key => $value) {
                                             if ($value) {
                                                 switch ($key) {
                                                     case 'id':
                                                         $interfaceXML->addAttribute('id', $interface->id);
                                                         break;
                                                     case 'mac':
                                                         $interfaceXML->addAttribute('mac', $interface->mac);
                                                         break;
                                                     case 'ipv4':
                                                         $interfaceXML->addAttribute('ipv4', $interface->ipv4);
                                                         break;
                                                     case 'netmask':
                                                         $interfaceXML->addAttribute('mask', $interface->netmask);
                                                         break;
                                                     case 'interface_type':
                                                         $interfaceXML->addAttribute('type', $interface->interface_type);
                                                         break;
                                                 }
                                             }
                                         }
                                     }
                                     // linked interfaces
                                     if (is_array($links[$device->id][$interface->id])) {
                                         if (count($links[$device->id][$interface->id])) {
                                             foreach ($links[$device->id][$interface->id] as $id => $link) {
                                                 if (array_search($link->link_type, array('a' => 'ap/client', 'b' => 'wds'))) {
                                                     continue;
                                                 }
                                                 if ($link->ipv4_id != $interface->ipv4_id) {
                                                     continue;
                                                 }
                                                 if ($action == 'detail') {
                                                     $linkXML = $interfaceXML->addChild('link');
                                                     foreach ($link as $key => $value) {
                                                         if ($value) {
                                                             switch ($key) {
                                                                 case 'id':
                                                                     $linkXML->addAttribute('id', $link->id);
                                                                     break;
                                                                 case 'linked_node_id':
                                                                     $linkXML->addAttribute('linked_node_id', $link->linked_node_id);
                                                                     break;
                                                                 case 'linked_device_id':
                                                                     $linkXML->addAttribute('linked_device_id', $link->linked_device_id);
                                                                     break;
                                                                 case 'linked_interface_id':
                                                                     $linkXML->addAttribute('linked_interface_id', $link->linked_interface_id);
                                                                     break;
                                                                 case 'link_type':
                                                                     $linkXML->addAttribute('link_type', $link->link_type);
                                                                     break;
                                                                 case 'status':
                                                                     $linkXML->addAttribute('link_status', $link->status);
                                                                     break;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             // foreach link
                                         }
                                     }
                                     //interface links
                                 }
                             }
                         }
                         // foreach interface
                     }
                 }
                 //interface
                 // services
                 if (is_array($services[$device->id])) {
                     if (count($services[$device->id])) {
                         foreach ($services[$device->id] as $id => $service) {
                             if ($action == 'detail') {
                                 $serviceXML = $deviceXML->addChild('service', htmlspecialchars($service->body, ENT_QUOTES));
                                 foreach ($service as $key => $value) {
                                     if ($value) {
                                         switch ($key) {
                                             case 'body':
                                                 break;
                                             case 'id':
                                                 $serviceXML->addAttribute('id', $value);
                                                 break;
                                             case 'nick':
                                                 $serviceXML->addAttribute('title', $value);
                                                 break;
                                             case 'service_type':
                                                 $serviceXML->addAttribute('type', $value);
                                                 break;
                                             case 'status_flag':
                                                 $serviceXML->addAttribute('status', $value);
                                                 break;
                                             case 'timestamp_created':
                                                 $serviceXML->addAttribute('created', date('Ymd hi', $value));
                                                 break;
                                             case 'timestamp_changed':
                                                 $serviceXML->addAttribute('updated', date('Ymd hi', $value));
                                                 break;
                                         }
                                     }
                                 }
                             }
                             $nodesummary->services++;
                         }
                         // foreach service
                     }
                 }
                 // service
             }
             // foreach device
         }
     }
     // devices
     $summary->ap += $nodesummary->ap;
     $summary->client += $nodesummary->client;
     $summary->devices += $nodesummary->devices;
     $summary->links += $nodesummary->links;
     $summary->services += $nodesummary->services;
     if ($action != 'zones') {
         if ($nodesummary->ap) {
             $nodeXML->addAttribute('access_points', $nodesummary->ap);
         }
         if ($nodesummary->client) {
             $nodeXML->addAttribute('clients', $nodesummary->client);
         }
         if ($nodesummary->devices) {
             $nodeXML->addAttribute('devices', $nodesummary->devices);
         }
         if ($nodesummary->links) {
             $nodeXML->addAttribute('links', $nodesummary->links);
         }
         if ($nodesummary->services) {
             $nodeXML->addAttribute('services', $nodesummary->services);
         }
     }
     return;
 }
Ejemplo n.º 5
0
function guifi_domain_create_form($form_state, $node)
{
    $ip = guifi_main_ip($node->device_id);
    if (guifi_domain_access('create', $node->sid)) {
        $form['text_add'] = array('#type' => 'item', '#value' => t('You are not allowed to create a domain on this service.'), '#weight' => 0);
        return $form;
    }
    if (empty($ip['ipv4'])) {
        $device = db_fetch_object(db_query('SELECT nick FROM {guifi_devices} WHERE id = %d', $node->device_id));
        $url = url('guifi/device/' . $node->device_id);
        $form['text'] = array('#type' => 'item', '#value' => t('The server <a href=' . $url . '>' . $device->nick . '</a> does not have an IPv4 address, can not create a domain.'));
        return $form;
    }
    $form['domain_type'] = array('#type' => 'select', '#title' => t('Select new domain type'), '#default_value' => 'none', '#options' => array('NULL' => 'none', 'master' => 'Master, ex: newdomain.net', 'delegation' => 'Delegation, ex: newdomain.guifi.net'), '#ahah' => array('path' => 'guifi/js/add-domain', 'wrapper' => 'select_type', 'effect' => 'fade'));
    $form['domain_type_form'] = array('#prefix' => '<div id="select_type">', '#suffix' => '</div>', '#type' => 'fieldset');
    if ($form_state['values']['domain_type'] == 'master') {
        $form['domain_type_form']['sid'] = array('#type' => 'hidden', '#value' => $node->id);
        $form['domain_type_form']['name'] = array('#type' => 'textfield', '#size' => 64, '#maxlength' => 32, '#title' => t('Add a new domain'), '#description' => t('Insert domain name'), '#prefix' => '<table style="width: 0px"><tr><td>', '#suffix' => '</td>');
        $form['domain_type_form']['type'] = array('#type' => 'hidden', '#value' => 'master');
        $form['domain_type_form']['ipv4'] = array('#type' => 'hidden', '#value' => $ip[ipv4]);
        $form['domain_type_form']['scope'] = array('#type' => 'select', '#title' => t('Scope'), '#options' => array('internal' => 'internal', 'external' => 'external'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['management'] = array('#type' => 'select', '#title' => t('Management'), '#options' => array('automatic' => 'automatic', 'manual' => 'manual'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['mname'] = array('#type' => 'hidden', '#value' => '0');
        $form['domain_type_form']['submit'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/add.png', '#attributes' => array('title' => t('add')), '#executes_submit_callback' => TRUE, '#submit' => array(guifi_domain_create_form_submit), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
    }
    if ($form_state['values']['domain_type'] == 'delegation') {
        $ip = guifi_main_ip($node->device_id);
        $form['domain_type_form']['sid'] = array('#type' => 'hidden', '#value' => $node->id);
        $form['domain_type_form']['name'] = array('#type' => 'textfield', '#title' => t('Add a new delegated Domain Name'), '#description' => t('Just the hostname (HOSTNAME.domain.com) will be added before master domain.'), '#prefix' => '<table style="width: 0px"><tr><td>', '#suffix' => '</td>');
        $domqry = db_query("\n      SELECT *\n      FROM {guifi_dns_domains}\n      WHERE type = 'master'\n      AND public = 'yes'\n      ORDER BY name");
        $values = array();
        while ($type = db_fetch_object($domqry)) {
            $values[$type->name] = $type->name;
        }
        $form['domain_type_form']['mname'] = array('#type' => 'select', '#options' => $values, '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['scope'] = array('#type' => 'select', '#title' => t('Scope'), '#options' => array('internal' => 'internal', 'external' => 'external'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['management'] = array('#type' => 'select', '#title' => t('Management'), '#options' => array('automatic' => 'automatic', 'manual' => 'manual'), '#prefix' => '<td>', '#suffix' => '</td>');
        $form['domain_type_form']['type'] = array('#type' => 'hidden', '#value' => 'delegation');
        $form['domain_type_form']['ipv4'] = array('#type' => 'hidden', '#value' => $ip[ipv4]);
        $form['domain_type_form']['submit'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/add.png', '#attributes' => array('title' => t('add')), '#executes_submit_callback' => TRUE, '#submit' => array(guifi_domain_create_form_submit), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
    }
    return $form;
}
Ejemplo n.º 6
0
function guifi_kamikaze_files($dev, $zone)
{
    //SOME VARIABLES
    $dns = guifi_get_dns($zone, 2);
    $lan = guifi_unsolclic_if($dev->id, 'wLan/Lan');
    $lan_network = _ipcalc($lan->ipv4, $lan->netmask);
    switch ($dev->variable['model_id']) {
        case "39":
            // Avila GW2348-4
            $wireless_model = 'atheros';
            $lan_iface = 'eth0';
            $lan2_iface = 'eth1';
            $packages = 'ixp4xx/packages';
            break;
        default:
            _outln_comment('model id not supported');
            exit;
    }
    // SECTION FILES
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/wireless'));
    function wds_add($dev, $radio)
    {
        $wds_links = array();
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links[] = $link;
                        }
                    }
                }
                $ifcount = 0;
                foreach ($wds_links as $key => $wds) {
                    if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                        $status = 'active';
                        print '        option \'wds_add' . $ifcount . '\' \'' . $wds['interface']['mac'] . '\'<br />';
                        $ifcount++;
                    } else {
                        $status = 'disabled';
                        print '# option \'wds_addX\' \'' . $wds['interface']['mac'] . '\'# ' . t($wds['flag']) . '<br />';
                    }
                }
            }
        }
    }
    function wds_network($dev, $radio)
    {
        $ifcount = '0';
        foreach ($radio[interfaces] as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    if ($link['link_type'] == 'wds') {
                        $wds_links = array();
                        $wds_links[] = $link;
                        foreach ($wds_links as $key => $wds) {
                            $hostname = guifi_get_hostname($wds['device_id']);
                            if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                                $status = 'active';
                                print '
## wds_' . $hostname . '
config \'interface\' \'wds_' . $hostname . '\'
        option \'ifname\' \'ath' . $radio[radiodev_counter] . '.wds' . $ifcount . '\'
        option \'proto\' \'static\'
';
                                $ifcount++;
                            } else {
                                $status = 'disabled';
                                print '
##### ' . t($wds['flag']) . ' ####
## wds_' . $hostname . '
# config \'interface\' \'ath' . $radio[radiodev_counter] . '.wdsX\'
#       option \'proto\' \'none\'
';
                            }
                        }
                        if ($status == 'active') {
                            print '        option \'ipaddr\' \'' . $ipv4[ipv4] . '\'
        option \'netmask\' \'' . $ipv4['netmask'] . '\'
';
                        } else {
                            print '#       option \'ipaddr\' \'' . $ipv4[ipv4] . '\'
#       option \'netmask\' \'' . $ipv4['netmask'] . '\'
';
                        }
                    }
                }
            }
        }
    }
    function cable_network($dev)
    {
        foreach ($dev->interfaces as $interface_id => $interface) {
            switch ($interface[interface_type]) {
                case 'vlan1':
                    $iname = 'eth0:1';
                    break;
                case 'vlan2':
                    $iname = 'eth1';
                    break;
                case 'vlan3':
                    $iname = 'eth2';
                    break;
                default:
                    $iname = $interface[interface_type];
                    break;
            }
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $network = guifi_get_hostname($link[device_id]);
                    if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                        $status = 'active';
                        if ($interface[interface_type] != 'wLan/Lan') {
                            print '
## cable_' . $network . '
config \'interface\' \'' . $network . '\'
        option \'ifname\'   \'' . $iname . '\'
';
                            print '        option \'proto\'    \'static\'
        option \'ipaddr\'   \'' . $ipv4[ipv4] . '\'
        option \'netmask\'  \'' . $ipv4[netmask] . '\'

';
                        }
                    } else {
                        $status = 'disabled';
                        print '
##### ' . t($link['flag']) . ' ####
## cable_' . $network . '
# config \'interface\' \'' . $network . '\'
#        option \'ifname\'   \'' . $iname . '\'
';
                        print '#        option \'proto\'    \'static\'
#        option \'ipaddr\'   \'' . $ipv4[ipv4] . '\'
#        option \'netmask\'  \'' . $ipv4[netmask] . '\'

';
                    }
                }
            }
        }
    }
    print '<pre>
echo "
';
    if (isset($dev->radios)) {
        foreach ($dev->radios as $radio_id => $radio) {
            $mode = 'ap';
            $ssid = $radio[ssid];
            $channel = atheros_channel($radio);
            if ($channel < 14) {
                $band = '11b';
            } else {
                $band = '11a';
            }
            if (empty($radio[antenna_mode])) {
                $radio[antenna_mode] = '1';
            } else {
                if ($radio[antenna_mode] != 'Main') {
                    $radio[antenna_mode] = '2';
                } else {
                    $radio[antenna_mode] = '1';
                }
            }
            if ($radio_id == '0') {
                $wireless_iface = 'wifi0';
                $network = 'lan';
            } else {
                $wireless_iface = 'wifi' . $radio_id;
                $network = 'wlan' . ($radio_id + 1);
            }
            $wireless_model = 'atheros';
            $txant = 'txantenna';
            $rxant = 'rxantenna';
            print '
## Radio: ' . $radio[ssid] . '
config \'wifi-device\' \'' . $wireless_iface . '\'
        option \'type\' \'' . $wireless_model . '\'
        option \'channel\' \'' . $channel . '\'
        option \'disabled\' \'0\'
        option \'hwmode\' \'' . $band . '\'
        option \'diversity\' \'0\'
        option \'' . $txant . '\' \'' . $radio[antenna_mode] . '\'
        option \'' . $rxant . '\' \'' . $radio[antenna_mode] . '\'
        option \'txpower\' \'16\'

config wifi-iface
        option \'device\' \'' . $wireless_iface . '\'
        option \'network\' \'' . $network . '\'
        option \'agmode\' \'' . $mode . '\'
        option \'ssid\' \'guifi.net-' . $radio[ssid] . '\'
        option \'encryption\' \'none\'
';
            wds_add($dev, $radio);
        }
    }
    print '
" > /etc/config/wireless </pre>
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/network'));
    print '<pre>
echo "
config interface loopback
        option \'ifname\'  \'lo\'
        option \'proto\'    \'static\'
        option \'ipaddr\'   \'127.0.0.1\'
        option \'netmask\'  \'255.0.0.0\'

';
    if (isset($dev->radios)) {
        foreach ($dev->radios as $radio_id => $radio) {
            if (isset($radio[interfaces])) {
                foreach ($radio[interfaces] as $interface_id => $interface) {
                    if ($interface[interface_type] != 'wds/p2p') {
                        if (isset($interface[ipv4])) {
                            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                                if ($interface[interface_type] == 'wLan/Lan') {
                                    $iface = 'ath0 eth0';
                                    $network = 'lan';
                                } else {
                                    $iface = 'wifi' . $radio_id;
                                    $network = 'wlan' . ($radio_id + 1);
                                }
                                $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                                // FILE NETWORK
                                print '
config interface ' . $network . '
        option \'ifname\'   \'' . $iface . '\'
';
                                if ($interface[interface_type] == 'wLan/Lan') {
                                    print '        option \'type\'     \'bridge\'
';
                                }
                                print '        option \'proto\'    \'static\'
        option \'ipaddr\'   \'' . $ipv4[ipv4] . '\'
        option \'netmask\'  \'' . $ipv4[netmask] . '\'
        option \'dns\'      \'' . $dns . '\'

';
                            }
                        }
                    }
                }
            }
            wds_network($dev, $radio);
        }
    }
    cable_network($dev);
    print '
" > /etc/config/network </pre>
';
    $wds_links = array();
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links[] = $link;
                        }
                    }
                }
            }
        }
    }
    foreach ($wds_links as $key => $wds) {
        if ($wds['routing'] == 'BGP') {
            $wds_bgpd = '1';
        }
        if ($wds['routing'] == 'OSPF') {
            $wds_ospfd = '1';
        }
    }
    $cable_links = array();
    foreach ($dev->interfaces as $interface_id => $interface) {
        foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
            foreach ($ipv4[links] as $link_id => $link) {
                if ($link['link_type'] == 'cable') {
                    $cable_links[] = $link;
                }
            }
        }
    }
    foreach ($cable_links as $key => $cable) {
        if ($cable['routing'] == 'BGP') {
            $cable_bgpd = '1';
        }
        if ($cable['routing'] == 'OSPF') {
            $cable_ospfd = '1';
        }
    }
    // QUAGGA CONFIG FILES
    $file_zebra = '';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/quagga/zebra.conf'));
    _out_file($file_zebra, '/etc/quagga/zebra.conf');
    // FILE OSPFD
    if ($wds_ospfd == '1' || $cable_ospfd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/ospfd.conf'));
        print '<pre>mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.conf.bak
echo "
!
interface br-lan
!
router ospf
 ospf router-id ' . $lan->ipv4 . '
 redistribute bgp
';
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                    foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                        $network = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    }
                    if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                        print ' network ' . $network[netid] . '/' . $network[maskbits] . ' area 0<br />';
                    }
                }
            }
        }
        foreach ($wds_links as $key => $wds) {
            $iplocal[] = $wds['interface']['ipv4'];
            if ($wds['routing'] == 'OSPF') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                    print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . ' area 0<br />';
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    if ($link['routing'] == 'OSPF') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' network ' . $item[netid] . '/' . $item[maskbits] . ' area 0<br />';
                        }
                    }
                }
            }
        }
        print 'default-information originate
!
" > /etc/quagga/ospfd.conf</pre>';
    }
    // FILE BGPD
    if ($wds_bgpd == '1' || $cable_bgpd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/bgpd.conf'));
        print '<pre>mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bak
echo "
!
interface br-lan
!
router bgp ' . $dev->id . '
bgp router-id ' . $lan->ipv4 . '
';
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                    foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                        $network = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    }
                    print ' network ' . $network[netid] . '/' . $network[maskbits] . '<br />';
                }
            }
        }
        print 'redistribute ospf
';
        foreach ($wds_links as $key => $wds) {
            $iplocal[] = $wds['interface']['ipv4'];
            if ($wds['routing'] == 'BGP') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
                    print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . '<br />';
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    $item = _ipcalc($ipv4[ipv4], $ipv4[netmask]);
                    if ($link['routing'] == 'BGP') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' network ' . $item[netid] . '/' . $item[maskbits] . '<br />';
                        }
                    }
                }
            }
        }
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['routing'] == 'BGP') {
                            if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                                print ' neighbor ' . $link['interface']['ipv4']['ipv4'] . ' remote-as ' . $link['device_id'] . '
';
                            }
                        }
                    }
                }
            }
        }
        foreach ($dev->interfaces as $interface_id => $interface) {
            foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                foreach ($ipv4[links] as $link_id => $link) {
                    if ($link['routing'] == 'BGP') {
                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                            print ' neighbor ' . $link['interface']['ipv4']['ipv4'] . ' remote-as ' . $link['device_id'] . '
';
                        }
                    }
                }
            }
        }
        print '" > /etc/quagga/bgpd.conf</pre>';
    }
    //FILE FIREWALL
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/firewall'));
    print '<pre>
echo "
config defaults
        option \'syn_flood\' \'1\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'
';
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    if ($interface[interface_type] == 'wLan/Lan') {
                        $network = 'lan';
                    } else {
                        $network = 'wlan' . ($radio_id + 1);
                    }
                    print '        
config zone
        option \'name\' \'' . $network . '\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'

';
                }
            }
        }
    }
    if ($interface[interface_type] == 'wds/p2p') {
        foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
            foreach ($ipv4[links] as $link_id => $link) {
                if ($link['link_type'] == 'wds') {
                    $ifcount = 0;
                }
            }
        }
    }
    foreach ($wds_links as $key => $wds) {
        $hostname = guifi_get_hostname($wds['device_id']);
        if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
            print '        
config zone
        option \'name\' \'wds_' . $hostname . '\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'

';
        }
    }
    foreach ($dev->interfaces as $interface_id => $interface) {
        foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
            foreach ($ipv4[links] as $link_id => $link) {
                $hostname = guifi_get_hostname($link['device_id']);
                if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                    print '        
config zone
        option \'name\' \'' . $hostname . '\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'

';
                }
            }
        }
    }
    print '" > /etc/config/firewall</pre>';
    //FILE OPKG
    $opkg_conf = '
src/gz snapshots http://downloads.openwrt.org/snapshots/' . $packages . '
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /jffs
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/opkg.conf'));
    _out_file($opkg_conf, '/etc/opkg.conf');
    $dhcp_statics = array();
    $max = explode(".", $dev->ipv4);
    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];
        }
    }
    $main_ip = guifi_main_ip($dev->id);
    $item = _ipcalc_by_netbits($main_ip[ipv4], $main_ip[maskbits]);
    $max = explode(".", $main_ip[ipv4]);
    // cable links
    foreach ($dev->interfaces as $interface) {
        foreach ($interface[ipv4] as $ipv4) {
            foreach ($ipv4[links] as $link) {
                if ($link['interface'][ipv4][ipv4] != '') {
                    $item2 = _ipcalc($link['interface'][ipv4][ipv4], $link['interface'][ipv4][netmask]);
                    if ($item[netid] == $item2[netid]) {
                        merge_static($link, $dhcp_statics, $max, $cur);
                    }
                }
            }
        }
    }
    // ap/client links
    foreach ($dev->radios as $radio) {
        foreach ($radio[interfaces] as $interface) {
            foreach ($interface[ipv4] as $ipv4) {
                foreach ($ipv4[links] as $link) {
                    if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                        merge_static($link, $dhcp_statics, $max, $cur);
                    }
                }
            }
        }
    }
    $statics = count($dhcp_statics) - 1;
    $totalstatics = count($dhcp_statics);
    $first = explode(".", $item[netid]);
    $last = explode(".", $item[broadcast]);
    $limit = $last[3] - 1 - ($first[3] + 3) - $totalstatics;
    _outln_comment();
    _outln_comment(t('File /etc/config/luci_ethers'));
    print 'echo "';
    foreach ($dhcp_statics as $static) {
        print '<pre>
## Device: ' . $static[2] . '
config \'static_lease\'
        option \'macaddr\' \'' . $static[1] . '\'
        option \'ipaddr\' \'' . $static[0] . '\'
</pre>';
    }
    print '" > /etc/config/luci_ethers<br />';
    // FILE DHCP
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/dhcp'));
    print '<pre>
echo "
config \'dnsmasq\'
        option \'domainneeded\' \'1\'
        option \'boguspriv\' \'1\'
        option \'filterwin2k\' \'0\'
        option \'localise_queries\' \'1\'
        option \'local\' \'/lan/\'
        option \'domain\' \'lan\'
        option \'expandhosts\' \'1\'
        option \'nonegcache\' \'0\'
        option \'authoritative\' \'1\'
        option \'readethers\' \'1\'
        option \'leasefile\' \'/tmp/dhcp.leases\'
        option \'resolvfile\' \'/tmp/resolv.conf.auto\'
';
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface[interface_type] == 'wLan' || $interface[interface_type] == 'wLan/Lan') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    if ($interface[interface_type] == 'wLan/Lan') {
                        $iface = 'lan';
                        $network = 'lan';
                    } else {
                        $network = 'wlan' . ($radio_id + 1);
                    }
                    $max = explode(".", $ipv4[ipv4]);
                    foreach ($ipv4[links] as $link) {
                        if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                            $totalstaticss = count($ipv4[links]);
                        }
                    }
                    $first = explode(".", $item[netid]);
                    $last = explode(".", $item[broadcast]);
                    $limit = $last[3] - 1 - ($first[3] + 3) - $totalstaticss;
                    $totalstaticss = '0';
                    print '
 config \'dhcp\' \'' . $network . '\'
        option \'interface\' \'' . $network . '\'
        option \'leasetime\' \'12h\'
        option \'start\' \'' . ($max[3] + 2) . '\'
        option \'limit\' \'' . $limit . '\'
';
                }
            }
        }
    }
    print '" > /etc/config/dhcp<br /></pre>';
}
Ejemplo n.º 7
0
function theme_guifi_node_devices_list($node, $links = FALSE)
{
    $id = $node->id;
    $rows = array();
    $header = array('<h2>' . t('device') . '</h2>', t('type'), t('ip'), t('status'), array('data' => t('last available'), 'style' => 'text-align: right;'), t('unsolclic'));
    // Form for adding a new device
    $form = drupal_get_form('guifi_device_create_form', $node);
    $query = db_query("SELECT d.id FROM {guifi_devices} d WHERE nid=%d", $id);
    while ($d = db_fetch_object($query)) {
        $device = guifi_device_load($d->id);
        // Edit and delete buttons
        if (guifi_device_access('update', $device['id'])) {
            $edit_device = l(guifi_img_icon('edit.png'), 'guifi/device/' . $device['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('edit device'))));
            $delete_device = l(guifi_img_icon('drop.png'), 'guifi/device/' . $device['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('delete device'))));
        } else {
            $edit_device = '';
            $delete_device = '';
        }
        // Traceroute button
        if (user_access('create guifi nodes')) {
            $traceroute = l(guifi_img_icon('discover-routes.png'), 'guifi/menu/ip/traceroute/' . $device['id'], array('html' => TRUE, 'attributes' => array('target' => '_blank', 'title' => t('trace routes, discover services from this device'))));
        } else {
            $traceroute = '';
        }
        // Firmware text which links to unsolclic feature
        if ($device->variable['firmware'] != "n/d") {
            $unsolclic = l($device[variable]['firmware'], 'guifi/device/' . $device['id'] . '/view/unsolclic', array('attributes' => array('title' => t("Get radio configuration with singleclick"))));
        }
        // Get IP assigned to the device
        $ip = guifi_main_ip($device[id]);
        // Availability image
        $status_url = guifi_cnml_availability(array('device' => $device['id'], 'format' => 'short'));
        // Device main attributes
        if (!empty($device['manufacturer'])) {
            $mDescr = $device['manufacturer'] . '-' . $device['model'];
        } else {
            $mDescr = '';
        }
        $uCreated = db_fetch_object(db_query('SELECT u.name FROM {users} u WHERE u.uid = %d', $device[user_created]));
        $deviceAttr = $device[id] . ' ' . $mDescr . '
         ' . t('created by') . ': ' . $uCreated->name . ' ' . t('at') . ' ' . format_date($device[timestamp_created], 'small');
        if (!empty($device[timestamp_changed])) {
            $uChanged = db_fetch_object(db_query('SELECT u.name FROM {users} u WHERE u.uid = %d', $device[user_changed]));
            $deviceAttr .= '
           ' . t('updated by') . ': ' . $uChanged->name . ' ' . t('at') . ' ' . format_date($device[timestamp_changed], 'small');
        }
        // Groups all this data in an array for the theme() function
        $rows[] = array(l($device[nick], 'guifi/device/' . $device[id], array('attributes' => array('title' => $deviceAttr))), $device[type], array('data' => $ip[ipv4] . '/' . $ip[maskbits], 'align' => 'left'), empty($ip[ipv4]) ? '&nbsp;' : array('data' => t($device[flag]), 'class' => $device['flag']), empty($ip[ipv4]) ? '&nbsp;' : array('data' => $status_url, 'class' => $device['flag']), $unsolclic, $edit_device, $delete_device, empty($ip[ipv4]) ? '&nbsp;' : $traceroute);
    }
    // Creates the table with devices if any, otherwise just outputs the node has not devices
    if (count($rows)) {
        $output = '<h4>' . t('devices') . '</h4>' . theme('table', $header, $rows, array('class' => 'device-data')) . $form;
    } else {
        $output = theme('box', t('This node does not have any device'), $form);
    }
    // Again, it creates a table with the links, if they exist
    if ($links) {
        $node = node_load(array('nid' => $node->id));
        drupal_set_title(t('devices @ %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;
}
Ejemplo n.º 8
0
function unsolclic_routeros($dev)
{
    //Fixed testing mode
    $ospf_id = '0.0.0.0';
    $ospf_name = 'backbone';
    //
    $ipd = guifi_main_ip($dev->id);
    $ospf_routerid = $ipd['ipv4'];
    $defined_ips = array();
    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));
    }
    function ospf_interface($iname, $netid, $maskbits, $ospf_name, $ospf_zone, $ospf_id, $disabled)
    {
        _outln('/ routing ospf interface');
        _outln(sprintf(':foreach i in [/routing ospf interface find interface=%s] do={/routing ospf interface remove $i;}', $iname));
        _outln(sprintf('add interface=%s', $iname));
        _outln('/ routing ospf network');
        _outln(sprintf(':foreach i in [/routing ospf network find network=%s/%d] do={/routing ospf network remove $i;}', $netid, $maskbits));
        _outln(sprintf('add network=%s/%d area=%s disabled=%s', $netid, $maskbits, $ospf_name, $disabled));
    }
    //  Check if there's any wLan/Lan interface defined on the device
    $wlanlan = false;
    foreach ($dev->radios as $ri) {
        $ii = $ri['interfaces'];
        foreach ($ii as $iii) {
            if ($iii['interface_type'] == 'wLan/Lan') {
                $wlanlan = true;
            }
        }
    }
    $node = node_load(array('nid' => $dev->nid));
    $zone = node_load(array('nid' => $node->zone_id));
    _outln(sprintf(':log info "Unsolclic for %d-%s going to be executed."', $dev->id, $dev->nick));
    _outln_comment();
    if ($dev->variable['firmware'] == 'RouterOSv4.7+') {
        _outln_comment(t('Configuration for RouterOS 4.7 and newer 4.x'));
    } else {
        _outln_comment(t('Configuration for ' . $dev->variable['firmware']));
    }
    _outln_comment(t('Device') . ': ' . $dev->id . '-' . $dev->nick);
    _outln_comment();
    _outln_comment(t('Methods to upload/execute this script:'));
    _outln_comment(t('1.-As a script. Upload this output as a script either with:'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('a.Winbox (with Linux, wine required)'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('b.Terminal (telnet, ssh...)'));
    _outln_comment('&nbsp;&nbsp;&nbsp;' . t('Then execute the script with:'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . t('>&nbsp;/system script run script_name'));
    _outln_comment(t('2.-Imported file:'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('Save this output to a file, then upload it to the router'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('using ftp using a name like "script_name.rsc".'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('(note that extension ".rsc" is required)'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('Run the import file using the command:'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . t('>&nbsp;/import script_name'));
    _outln_comment(t('3.-Telnet cut&paste:'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('Open a terminal session, and cut&paste this output'));
    _outln_comment('&nbsp;&nbsp;&nbsp;&nbsp;' . t('directly on the terminal input.'));
    _outln_comment();
    _outln_comment(t('Notes:'));
    _outln_comment(t('-routing-test package is required if you use RouterOSv2.9 , be sure you have it enabled at system packages'));
    _outln_comment(t('-wlans should be enabled manually, be sure to set the correct antenna (a or b)'));
    _outln_comment(t('&nbsp;&nbsp;according in how did you connect the cable to the miniPCI. Keep the'));
    _outln_comment(t('&nbsp;&nbsp;power at the minimum possible and check the channel.'));
    _outln_comment(t('-The script doesn\'t reset the router, you might have to do it manually'));
    _outln_comment(t('-You must have write access to the router'));
    _outln_comment(t('-MAC access (winbox, MAC telnet...) method is recommended'));
    _outln_comment(t('&nbsp;&nbsp;(the script reconfigures some IP addresses, so communication can be lost)'));
    _outln_comment(t('-No changes are done in user passwords on the device'));
    _outln_comment(t('-A Read Only guest account with no password will be created to allow guest access'));
    _outln_comment(t('&nbsp;&nbsp;to the router with no danger of damage but able to see the config.'));
    _outln_comment(t('-Be sure that all packages are activated.'));
    _outln_comment(t('-Don\'t run the script from telnet and being connected through an IP connection at'));
    _outln_comment(t('&nbsp;&nbsp;the wLan/Lan interface: This interface will be destroyed during the script.'));
    _outln_comment();
    _outln('/ system identity set name=' . $dev->nick);
    // DNS
    _outln_comment();
    _outln_comment('DNS (client &#038; server cache) zone: ' . $node->zone_id);
    list($primary_dns, $secondary_dns) = explode(' ', guifi_get_dns($zone, 2));
    $dns[] .= $primary_dns;
    $dns[] .= $secondary_dns;
    if ($secondary_dns != null) {
        if ($dev->variable['firmware'] == 'RouterOSv4.7+' or $dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
            _outln(sprintf('/ip dns set servers=%s,%s allow-remote-requests=yes', $primary_dns, $secondary_dns));
        } else {
            _outln(sprintf('/ip dns set primary-dns=%s secondary-dns=%s allow-remote-requests=yes', $primary_dns, $secondary_dns));
        }
    } else {
        if ($primary_dns != null) {
            if ($dev->variable['firmware'] == 'RouterOSv4.7+' or $dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
                _outln(sprintf('/ip dns set servers=%s allow-remote-requests=yes', $primary_dns));
            } else {
                _outln(sprintf('/ip dns set primary-dns=%s allow-remote-requests=yes', $primary_dns));
            }
        }
    }
    _outln(':delay 1');
    // NTP
    _outln_comment();
    _outln_comment('NTP (client &#038; server cache) zone: ' . $node->zone_id);
    list($primary_ntp, $secondary_ntp) = explode(' ', guifi_get_ntp($zone));
    if ($secondary_ntp != null) {
        _outln(sprintf('/system ntp client set enabled=yes mode=unicast primary-ntp=%s secondary-ntp=%s', $primary_ntp, $secondary_ntp));
    } else {
        if ($primary_ntp != null) {
            _outln(sprintf('/system ntp client set enabled=yes mode=unicast primary-ntp=%s', $primary_ntp));
        }
    }
    if ($dev->variable['firmware'] == 'RouterOSv2.9') {
        _outln(sprintf('/system ntp server set manycast=no enabled=yes'));
    }
    _outln(':delay 1');
    // Bandwidth-server
    _outln_comment();
    _outln_comment(t('Bandwidth-server'));
    _outln('/ tool bandwidth-server set enabled=yes authenticate=no allocate-udp-ports-from=2000');
    // SNMP
    _outln_comment();
    _outln_comment('SNMP');
    if ($dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
        $community = 'trap-community=public';
        _outln(sprintf('/snmp community set public addresses=0.0.0.0/0'));
    } else {
        $community = '';
    }
    _outln(sprintf('/snmp set contact="*****@*****.**" enabled=yes location="%s" %s', $node->nick, $community));
    // User guest
    _outln_comment();
    _outln_comment('Guest user');
    _outln('/user');
    _outln(':foreach i in [find group=read] do={/user remove $i;}');
    _outln('add name="guest" group=read address=0.0.0.0/0 comment="" disabled=no');
    // Graphing
    _outln_comment();
    _outln_comment(t('Graphing'));
    _outln(sprintf('/tool graphing interface add'));
    // LogServer
    if (!empty($dev->logserver)) {
        $ipd = array();
        $ipd = guifi_main_ip($dev->id);
        _outln_comment(t('Ip for ServerLogs'));
        _outln('/system logging');
        _outln(':foreach i in [/system logging find action=remote]');
        _outln('do={/system logging remove $i }');
        _outln(':foreach i in [/system logging action find name=guifi]');
        _outln('do=[/system logging action remove $i]');
        _outln('/system logging action add name=' . $dev->nick . ' target=remote remote=' . $dev->logserver . ':514 src-address=' . $ipd['ipv4']);
        _outln('/system logging add action=guifi_remot topics=critical');
        _outln('/system logging add action=guifi_remot topics=account');
    }
    if ($radio[mode] != 'client') {
        // Define wLan/Lan bridge (main interface)
        _outln_comment(t('Remove current wLan/Lan bridge if exists'));
        _outln(':foreach i in [/interface bridge find name=wLan/Lan] \\ ');
        _outln('do={:foreach i in [/interface bridge port find bridge=wLan/Lan] \\ ');
        _outln('do={/interface bridge port remove $i; \\ ');
        _outln(':foreach i in [/ip address find interface=wLan/Lan] \\ ');
        _outln('do={/ip address remove $i;};};');
        _outln('/interface bridge remove $i;}');
        // Construct bridge only if exists wlan/lan interface
        if ($wlanlan) {
            _outln_comment(t('Construct main bridge on wlan1 &#038; ether1'));
            _outln('/ interface bridge');
            _outln('add name="wLan/Lan"');
            _outln('/ interface bridge port');
            _outln('add interface=ether1 bridge=wLan/Lan');
            _outln('add interface=wlan1 bridge=wLan/Lan');
        }
        _outln(':delay 1');
    }
    $firewall = false;
    // Going to setup wireless interfaces
    if (isset($dev->radios)) {
        foreach ($dev->radios as $radio_id => $radio) {
            switch ($radio[mode]) {
                case 'ap':
                    $mode = 'ap-bridge';
                    $ssid = $radio['ssid'];
                    $gain = $radio['antenna_gain'];
                    if ($radio[channel] < 5000) {
                        if ($dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
                            $band = '2ghz-b';
                            $chwidth = 'channel-width=20mhz';
                        } else {
                            $band = '2.4ghz-b';
                            $chwidth = '';
                        }
                    } else {
                        if ($dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
                            $band = '5ghz-a';
                            $chwidth = 'channel-width=20mhz';
                        } else {
                            $band = '5ghz';
                            $chwidth = '';
                        }
                    }
                    break;
                case 'client':
                case 'clientrouted':
                    $mode = 'station';
                    $gain = $radio['antenna_gain'];
                    foreach ($radio['interfaces'] as $interface) {
                        foreach ($interface['ipv4'] as $ipv4) {
                            foreach ($ipv4['links'] as $link) {
                                $ssid = guifi_get_ap_ssid($link['interface']['device_id'], $link['interface']['radiodev_counter']);
                                $protocol = guifi_get_ap_protocol($link['interface']['device_id'], $link['interface']['radiodev_counter']);
                                $channel = guifi_get_ap_channel($link['interface']['device_id'], $link['interface']['radiodev_counter']);
                                if ($protocol == '802.11b') {
                                    if ($dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
                                        $band = '2ghz-b';
                                    } else {
                                        $band = '2.4ghz-b';
                                    }
                                }
                                if ($protocol == '802.11a') {
                                    if ($dev->variable['firmware'] == 'RouterOSv5.x' or $dev->variable['firmware'] == 'RouterOSv6.x') {
                                        $band = '5ghz-a';
                                    } else {
                                        $band = '5ghz';
                                    }
                                }
                                if ($protocol == '802.11n' and $channel > 5000) {
                                    $band = '5ghz-a/n';
                                }
                            }
                        }
                    }
                    $firewall = true;
                    break;
            }
            _outln_comment();
            _outln_comment('Radio#: ' . $radio_id . ' ' . $radio[ssid]);
            _outln(sprintf('/interface wireless set wlan%d name="wlan%d" \\ ', $radio_id + 1, $radio_id + 1));
            _outln(sprintf('    radio-name="%s" mode=%s ssid="guifi.net-%s" \\ ', $radio[ssid], $mode, $ssid));
            _outln(sprintf('    band="%s" ' . $chwidth . ' \\ ', $band));
            _outln(sprintf('    frequency-mode=regulatory-domain country=spain antenna-gain=%s \\ ', $gain));
            if ($radio['channel'] != 0 and $radio['channel'] != 5000) {
                // if not auto.. set channel
                if ($radio['channel'] < 20) {
                    $incr = $radio['channel'] * 5;
                    $radio['channel'] = 2407 + $incr;
                }
                _outln(sprintf('    frequency=%d \\ ', $radio['channel']));
            }
            if ($band == '5ghz' || '5ghz-a' and $radio['channel'] == 5000 or $band == '2.4ghz-b' || '2ghz-b' and $radio['channel'] == 0) {
                _outln('    dfs-mode=radar-detect \\ ');
            } else {
                _outln('    dfs-mode=none \\ ');
            }
            if (empty($radio['antenna_mode'])) {
                _outln(sprintf('    wds-mode=static wds-default-bridge=none wds-default-cost=100 \\ '));
            } else {
                if ($radio['antenna_mode'] != 'Main') {
                    $radio['antenna_mode'] = 'ant-b';
                } else {
                    $radio['antenna_mode'] = 'ant-a';
                }
                _outln(sprintf('    antenna-mode=%s wds-mode=static wds-default-bridge=none wds-default-cost=100 \\ ', $radio['antenna_mode']));
            }
            _outln('    wds-cost-range=50-150 wds-ignore-ssid=yes hide-ssid=no');
            if (isset($radio['interfaces'])) {
                foreach ($radio['interfaces'] as $interface_id => $interface) {
                    _outln(':delay 1');
                    _outln_comment('Type: ' . $interface['interface_type']);
                    if ($interface['interface_class'] == 'wds/p2p' || $interface['interface_type'] == 'wds/p2p') {
                        _outln_comment(t('Remove all existing wds interfaces'));
                        _outln(sprintf(':foreach i in [/interface wireless wds find master-interface=wlan%s] \\ ', $radio_id + 1));
                        _outln('do={:foreach n in [/interface wireless wds get $i name] \\ ');
                        _outln('do={:foreach inum in [/ip address find interface=$n] \\ ');
                        _outln('do={/ip address remove $inum;};}; \\ ');
                        _outln('/interface wireless wds remove $i;}');
                        if (isset($interface['ipv4'])) {
                            foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                                if (isset($ipv4['links'])) {
                                    foreach ($ipv4['links'] as $link_id => $link) {
                                        if (preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                                            $disabled = 'no';
                                        } else {
                                            $disabled = 'yes';
                                        }
                                        $wdsname = 'wds_' . guifi_get_hostname($link['device_id']);
                                        if ($link['interface']['mac'] == null) {
                                            $link['interface']['mac'] = 'FF:FF:FF:FF:FF:FF';
                                        }
                                        _outln('/ interface wireless wds');
                                        _outln(sprintf('add name="%s" master-interface=wlan%d wds-address=%s disabled=%s', $wdsname, $radio_id + 1, $link['interface']['mac'], $disabled));
                                        $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                        $ospf_zone = guifi_get_ospf_zone($zone);
                                        _outln(sprintf('/ ip address add address=%s/%d network=%s broadcast=%s interface=%s disabled=%s comment="%s"', $ipv4['ipv4'], $item['maskbits'], $item['netid'], $item['broadcast'], $wdsname, $disabled, $wdsname));
                                        if ($link['routing'] == 'OSPF') {
                                            ospf_interface($wdsname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'no');
                                            bgp_peer($link['device_id'], $link['interface']['ipv4']['ipv4'], 'yes');
                                        } else {
                                            ospf_interface($wdsname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'yes');
                                            bgp_peer($link['device_id'], $link['interface']['ipv4']['ipv4'], 'no');
                                        }
                                    }
                                }
                            }
                        }
                        // each wds link (ipv4)
                    } else {
                        // wds
                        // wLan, wLan/Lan, Hotspot or client
                        // Defining all networks and IP addresses at the interface
                        if (isset($interface['ipv4'])) {
                            foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                                if ($interface['interface_type'] == 'wLan/Lan') {
                                    $iname = $interface['interface_type'];
                                    $ospf_routerid = $ipv4['ipv4'];
                                } else {
                                    $iname = 'wlan' . ($radio_id + 1);
                                }
                                $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                _outln('/ip address');
                                if ($interface['interface_type'] == 'Wan') {
                                    _outln(sprintf(':foreach i in [find interface=%s] do={remove $i}', $iname));
                                }
                                _outln(sprintf(':foreach i in [find address="%s/%d"] do={remove $i}', $ipv4['ipv4'], $item['maskbits']));
                                _outln(sprintf('/ ip address add address=%s/%d network=%s broadcast=%s interface=%s disabled=no', $ipv4['ipv4'], $item['maskbits'], $item['netid'], $item['broadcast'], $iname));
                                $defined_ips[$ipv4['ipv4']] = $item;
                                $ospf_zone = guifi_get_ospf_zone($zone);
                                _outln('/ routing bgp network');
                                _outln(sprintf(':foreach i in [/routing bgp network find network=%s/%d] do={/routing bgp network remove $i;}', $item['netid'], $item['maskbits']));
                                _outln(sprintf('add network=%s/%d synchronize=no disabled=no', $item['netid'], $item['maskbits']));
                                if ($radio['mode'] != 'client') {
                                    ospf_interface($iname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'no');
                                } else {
                                    ospf_interface($iname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'yes');
                                }
                            }
                        }
                        // HotSpot
                        if ($interface['interface_type'] == 'HotSpot') {
                            _outln_comment();
                            _outln_comment('HotSpot');
                            _outln('/interface wireless');
                            _outln(sprintf(':foreach i in [find name=hotspot%d] do={remove $i}', $radio_id + 1));
                            _outln(sprintf('add name="hotspot%d" arp=enabled master-interface=wlan%d ssid="guifi.net-%s" disabled="no"', $radio_id + 1, $radio_id + 1, variable_get("hotspot_ssid", "HotSpot")));
                            _outln('/ip address');
                            _outln(sprintf(':foreach i in [find address="192.168.%d.1/24"] do={remove $i}', $radio_id + 100));
                            _outln(sprintf('/ip address add address=192.168.%d.1/24 interface=hotspot%d disabled=no', $radio_id + 100, $radio_id + 1));
                            _outln('/ip pool');
                            _outln(sprintf(':foreach i in [find name=hs-pool-%d] do={remove $i}', $radio_id + 100));
                            _outln(sprintf('add name="hs-pool-%d" ranges=192.168.%d.2-192.168.%d.254', $radio_id + 100, $radio_id + 100, $radio_id + 100));
                            _outln('/ip dhcp-server');
                            _outln(sprintf(':foreach i in [find name=hs-dhcp-%d] do={remove $i}', $radio_id + 100));
                            _outln(sprintf('add name="hs-dhcp-%d" interface=hotspot%d lease-time=1h address-pool=hs-pool-%d bootp-support=static authoritative=after-2sec-delay disabled=no', $radio_id + 100, $radio_id + 1, $radio_id + 100));
                            _outln('/ip dhcp-server network');
                            _outln(sprintf(':foreach i in [find address="192.168.%d.0/24"] do={remove $i}', $radio_id + 100));
                            _outln(sprintf('add address=192.168.%d.0/24 gateway=192.168.%d.1 domain=guifi.net comment=dhcp-%s', $radio_id + 100, $radio_id + 100, $radio_id));
                            _outln('/ip hotspot profile');
                            _outln(sprintf(':foreach i in [find name=hsprof%d] do={remove $i}', $radio_id + 1));
                            _outln(sprintf('add name="hsprof%d" hotspot-address=192.168.%d.1 dns-name="guests.guifi.net" html-directory=hotspot smtp-server=0.0.0.0 login-by=http-pap,trial split-user-domain=no trial-uptime=30m/1d trial-user-profile=default use-radius=no', $radio_id + 1, $radio_id + 100));
                            _outln('/ip hotspot user profile');
                            _outln('set default name="default" advertise-url=http://guifi.net/trespassos/');
                            _outln('/ip hotspot');
                            _outln(sprintf(':foreach i in [find name=hotspot%d] do={remove $i}', $radio_id + 1));
                            _outln(sprintf('add name="hotspot%d" interface=hotspot%d address-pool=hs-pool-%d profile=hsprof%d idle-timeout=5m keepalive-timeout=none addresses-per-mac=2 disabled=no', $radio_id + 1, $radio_id + 1, $radio_id + 100, $radio_id + 1));
                            _outln_comment('end of HotSpot');
                        }
                        // HotSpot
                        _outln(':delay 1');
                        if (!preg_match("/(HotSpot|Wan)/", $interface['interface_type'])) {
                            // Not link only (AP), setting DHCP
                            if ($mode == 'ap-bridge') {
                                $maxip = ip2long($item['netstart']) + 1;
                                if ($maxip + 5 > ip2long($item['netend']) - 5) {
                                    $maxip = ip2long($item['netend']);
                                    $dhcp_disabled = 'yes';
                                } else {
                                    $maxip = $maxip + 5;
                                    $dhcp_disabled = 'no';
                                }
                                _outln_comment();
                                _outln_comment('DHCP');
                                _outln(sprintf(':foreach i in [/ip pool find name=dhcp-%s] do={/ip pool remove $i;}', $iname));
                                _outln(sprintf('/ip pool add name=dhcp-%s ranges=%s-%s', $iname, long2ip($maxip), $item['netend']));
                                _outln(sprintf(':foreach i in [/ip dhcp-server find name=dhcp-%s] do={/ip dhcp-server remove $i;}', $iname));
                                _outln(sprintf('/ip dhcp-server add name=dhcp-%s interface=%s address-pool=dhcp-%s disabled=%s', $iname, $iname, $iname, $dhcp_disabled));
                                _outln(sprintf(':foreach i in [/ip dhcp-server network find address="%s/%d"] do={/ip dhcp-server network remove $i;}', $item['netid'], $item['maskbits']));
                                _outln(sprintf('/ip dhcp-server network add address=%s/%d gateway=%s domain=guifi.net comment=dhcp-%s', $item['netid'], $item['maskbits'], $item['netstart'], $iname));
                                $dhcp = array();
                                $dhcp[] = '/ip dhcp-server lease';
                                $dhcp[] = ':foreach i in [find comment=""] do={remove $i;}';
                                $dhcp[] = ':delay 1';
                                if (isset($ipv4['links'])) {
                                    foreach ($ipv4['links'] as $link_id => $link) {
                                        if (isset($link['interface']['ipv4']['ipv4'])) {
                                            if (ip2long($link['interface']['ipv4']['ipv4']) >= $maxip) {
                                                $maxip = ip2long($link['interface']['ipv4']['ipv4']) + 1;
                                            }
                                        }
                                        if ($link['interface']['mac'] == null) {
                                            $rmac = 'ff:ff:ff:ff:ff:ff';
                                        } else {
                                            $rmac = $link['interface']['mac'];
                                        }
                                        $dhcp[] = sprintf('add address=%s mac-address=%s client-id=%s server=dhcp-%s', $link['interface']['ipv4']['ipv4'], $rmac, guifi_get_hostname($link['device_id']), $iname);
                                    }
                                }
                                foreach ($dhcp as $outln) {
                                    _outln($outln);
                                }
                            }
                        }
                    }
                    // wLan, wLan/Lan or client
                    _outln_comment();
                }
            }
            // foreach radio->interface
            _outln(':delay 1');
        }
    }
    // foreach radio
    if ($firewall) {
        _outln_comment();
        _outln_comment('Device has firewall (setting up as CPE)');
        // Setting gateway
        _outln(sprintf('/ip route add gateway=%s', $link['interface']['ipv4']['ipv4']));
        // Setting private network and DHCP
        _outln(':foreach i in [find address="192.168.1.1/24"] do={remove $i}');
        _outln('/ip address add address=192.168.1.1/24 network=192.168.1.0 broadcast=192.168.1.255 interface=ether1 comment="" disabled=no');
        _outln(':delay 1');
        _outln('/ip pool');
        _outln(':foreach i in [find name=private] do={remove $i}');
        _outln('add name="private" ranges=192.168.1.100-192.168.1.200');
        _outln(':delay 1');
        _outln('/ip dhcp-server');
        _outln(':foreach i in [find name=private] do={remove $i}');
        _outln('add name="private" interface=ether1 lease-time=3d address-pool=private bootp-support=static authoritative=after-2sec-delay disabled=no');
        _outln(':delay 1');
        _outln('/ip dhcp-server network');
        _outln(':foreach i in [find] do={remove $i}');
        if ($secondary_dns != null) {
            _outln(sprintf('add address=192.168.1.0/24 gateway=192.168.1.1 netmask=24 dns-server=%s,%s domain="guifi.net" comment=""', $primary_dns, $secondary_dns));
        } else {
            if ($primary_dns != null) {
                _outln(sprintf('add address=192.168.1.0/24 gateway=192.168.1.1 netmask=24 dns-server=%s domain="guifi.net" comment=""', $primary_dns));
            }
        }
        _outln(':delay 1');
        // be sure that there is no dhcp client requests since having a static ip
        _outln('/ip dhcp-client');
        _outln(':foreach i in [find] do={remove $i}');
        _outln(':delay 1');
        // NAT private network
        _outln('/ip firewall nat');
        _outln(':foreach i in [find] do={remove $i}');
        _outln(':delay 1');
        _outln('add chain=srcnat out-interface=wlan1 action=masquerade comment="" disabled=no');
        // Firewall enabled, allowing winbox, ssh and snmp
        _outln('/ip firewall filter');
        _outln(':foreach i in [find] do={remove $i}');
        _outln('add chain=input connection-state=established action=accept comment="Allow Established connections" disabled=no');
        _outln('add chain=input protocol=udp action=accept comment="Allow UDP" disabled=no');
        _outln('add chain=input src-address="192.168.1.0/24" action=accept comment="Allow access to router from known network" disabled=no');
        _outln('add chain=input protocol=tcp dst-port=22 action=accept comment="Allow remote ssh" disabled=no');
        _outln('add chain=input protocol=udp dst-port=161 action=accept comment="Allow snmp" disabled=no');
        _outln('add chain=input protocol=tcp dst-port=8291 action=accept comment="Allow remote winbox" disabled=no');
        _outln('add chain=input protocol=icmp action=accept comment="Allow ping" disabled=no');
        _outln('add chain=forward connection-state=established action=accept comment="Allow already established connections" disabled=no');
        _outln('add chain=forward connection-state=related action=accept comment="Allow related connections" disabled=no');
        _outln('add chain=forward src-address="192.168.1.0/24" action=accept comment="Allow access to router from known network" disabled=no');
        _outln('add chain=input protocol=tcp connection-state=invalid action=drop comment="" disabled=no');
        _outln('add chain=forward protocol=tcp connection-state=invalid action=drop comment="Drop invalid connections" disabled=no');
        _outln('add chain=forward action=drop comment="Drop anything else" disabled=no');
        _outln('add chain=input action=drop comment="Drop anything else" disabled=no');
        _outln(':delay 1');
        // End of Unsolclic
        _outln_comment();
        _outln(sprintf(':log info "Unsolclic for %d-%s executed."', $dev->id, $dev->nick));
        _outln('/');
        return;
    }
    _outln_comment();
    _outln_comment('Routed device');
    // Now, defining other interfaces (if they aren't yet)
    _outln_comment();
    _outln_comment(t('Other cable connections'));
    if (isset($dev->interfaces)) {
        foreach ($dev->interfaces as $interface_id => $interface) {
            switch ($interface[interface_type]) {
                case 'vlan':
                    $iname = 'wLan/Lan';
                    break;
                case 'vlan2':
                    $iname = 'ether2';
                    break;
                case 'vlan3':
                    $iname = 'ether3';
                    break;
                case 'vlan4':
                    $iname = 'wLan/Lan';
                    break;
                case 'Wan':
                    $iname = 'wLan/Lan';
                    break;
                default:
                    $iname = $interface['interface_type'];
                    break;
            }
            $ospf_intrefaces[] = $iname;
            if (isset($interface['ipv4'])) {
                foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                    if (!isset($defined_ips[$ipv4['ipv4']])) {
                        $disabled = 'yes';
                        if (isset($ipv4['links'])) {
                            unset($comments);
                            foreach ($ipv4['links'] as $link_id => $link) {
                                if ($disabled = 'yes' and preg_match("/(Working|Testing|Building)/", $link['flag'])) {
                                    $disabled = 'no';
                                }
                                $comments[] = guifi_get_hostname($link['device_id']);
                                $ospf_zone = guifi_get_ospf_zone($zone);
                                $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                if ($link['routing'] == 'OSPF') {
                                    ospf_interface($iname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'no');
                                    bgp_peer($link['device_id'], $link['interface']['ipv4']['ipv4'], 'yes');
                                } else {
                                    ospf_interface($iname, $item['netid'], $item['maskbits'], $ospf_name, $ospf_zone, $ospf_id, 'yes');
                                    bgp_peer($link['device_id'], $link['interface']['ipv4']['ipv4'], 'no');
                                }
                            }
                        } else {
                            $disabled = 'no';
                        }
                        $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                        _outln(sprintf(':foreach i in [/ip address find address="%s/%d"] do={/ip address remove $i;}', $ipv4['ipv4'], $item['maskbits']));
                        _outln(':delay 1');
                        _outln(sprintf('/ ip address add address=%s/%d network=%s broadcast=%s interface=%s disabled=%s comment="%s"', $ipv4['ipv4'], $item['maskbits'], $item['netid'], $item['broadcast'], $iname, $disabled, implode(',', $comments)));
                        $defined_ips[$ipv4['ipv4']] = $item;
                    }
                }
            }
        }
    }
    // NAT for internal addresses while being used inside the router
    _outln_comment();
    _outln_comment(t('Internal addresses NAT'));
    _outln(':foreach i in [/ip firewall nat find src-address="172.16.0.0/12"] do={/ip firewall nat remove $i;}');
    _outln(':foreach i in [/ip firewall nat find src-address="192.168.0.0/16"] do={/ip firewall nat remove $i;}');
    _outln('/ip firewall nat');
    switch ($dev->variable['firmware']) {
        case 'RouterOSv2.9':
            _outln(sprintf('add chain=srcnat src-address="192.168.0.0/16" dst-address=!192.168.0.0/16 action=src-nat to-addresses=%s to-ports=0-65535 comment="" disabled=no', $ospf_routerid));
            break;
        case 'RouterOSv3.x':
        case 'RouterOSv4.0+':
        case 'RouterOSv4.7+':
        case 'RouterOSv5.x':
        case 'RouterOSv6.x':
            _outln(sprintf('add chain=srcnat src-address="192.168.0.0/16" dst-address=!192.168.0.0/16 action=src-nat to-addresses=%s comment="" disabled=no', $ospf_routerid));
            break;
    }
    // BGP
    _outln_comment();
    _outln_comment(t('BGP Routing'));
    _outln_comment(t('BGP & OSPF Filters'));
    _outln(':foreach i in [/routing filter find chain=ospf-in] do={/routing filter remove $i;}');
    _outln(':foreach i in [/routing filter find chain=ospf-out] do={/routing filter remove $i;}');
    _outln(':foreach i in [/routing filter find chain=ebgp-in] do={/routing filter remove $i;}');
    _outln(':foreach i in [/routing filter find chain=ebgp-out] do={/routing filter remove $i;}');
    _outln("/ routing filter");
    _outln(sprintf('add chain=ebgp-in comment="0. Set ebgp-in preferred source." set-pref-src="%s" disabled=no', $ospf_routerid));
    _outln('add action=discard chain=ebgp-in comment="1. Discard insert non 10.x routes from BGP peer" disabled=no invert-match=no prefix=!10.0.0.0/8 prefix-length=8-32');
    _outln('add action=discard chain=ebgp-out comment="2. Discard send non 10.x routes to BGP peer" disabled=no invert-match=no prefix=!10.0.0.0/8 prefix-length=8-32');
    _outln(sprintf('add action=accept chain=ospf-in comment="3. Accept insert 10.x routes from OSPF neighbor" disabled=no invert-match=no prefix=10.0.0.0/8 prefix-length=8-32 set-pref-src="%s"', $ospf_routerid));
    _outln('add action=accept chain=ospf-in comment="4. Accept insert 172.x routes from OSPF neighbor" disabled=no invert-match=no prefix=172.16.0.0/12 prefix-length=8-32');
    _outln('add action=discard chain=ospf-in comment="5. Discard insert non 10.x and 172.x from OSPF neighbor" disabled=no invert-match=no');
    _outln('add action=accept chain=ospf-out comment="6. Allow send 10.x routes to OSPF neighbor" disabled=no invert-match=no prefix=10.0.0.0/8 prefix-length=8-32');
    _outln('add action=accept chain=ospf-out comment="7. Allow send 172.x routes to OSPF neighbor" disabled=no invert-match=no prefix=172.16.0.0/12 prefix-length=8-32');
    _outln('add action=discard chain=ospf-out comment="8. Discard send non 10.x and 172.x to OSPF neighbor" disabled=no invert-match=no');
    _outln_comment();
    _outln_comment(t('BGP instance'));
    _outln("/ routing bgp instance");
    _outln(sprintf('set default name="default" as=%d router-id=%s \\ ', $dev->id, $ospf_routerid));
    switch ($dev->variable['firmware']) {
        case 'RouterOSv4.0+':
        case 'RouterOSv4.7+':
        case 'RouterOSv5.x':
        case 'RouterOSv6.x':
            _outln('redistribute-connected=no redistribute-static=no redistribute-rip=no \\ ');
            break;
        default:
            _outln('redistribute-connected=yes redistribute-static=yes redistribute-rip=yes \\ ');
    }
    _outln('redistribute-ospf=yes redistribute-other-bgp=yes out-filter=ebgp-out \\ ');
    _outln('client-to-client-reflection=yes comment="" disabled=no');
    // OSPF
    _outln_comment();
    _outln_comment(t('OSPF Routing'));
    switch ($dev->variable['firmware']) {
        case 'RouterOSv2.9':
        case 'RouterOSv3.x':
            _outln(sprintf('/routing ospf set router-id=%s distribute-default=never redistribute-connected=no \\ ', $ospf_routerid));
            _outln(sprintf('redistribute-static=no redistribute-rip=no redistribute-bgp=as-type-1'));
            break;
        case 'RouterOSv4.0+':
        case 'RouterOSv4.7+':
        case 'RouterOSv5.x':
        case 'RouterOSv6.x':
            _outln(sprintf('/routing ospf instance set default name=default router-id=%s comment="" disabled=no distribute-default=never \\ ', $ospf_routerid));
            _outln(sprintf('redistribute-bgp=as-type-1 redistribute-connected=no redistribute-other-ospf=no redistribute-rip=no redistribute-static=no in-filter=ospf-in out-filter=ospf-out'));
            break;
    }
    // End of Unsolclic
    _outln_comment();
    _outln(sprintf(':log info "Unsolclic for %d-%s executed."', $dev->id, $dev->nick));
    _outln('/');
}
Ejemplo n.º 9
0
 function _guifi_user_queue_devices($u)
 {
     $query = db_query('SELECT d.id ' . 'FROM {guifi_devices} d ' . 'WHERE d.nid=%d' . '  AND type="radio"', $u['nid']);
     $rows = array();
     while ($d = db_fetch_array($query)) {
         $d = guifi_device_load($d['id']);
         $d['uid'] = $u['id'];
         if (guifi_device_access('update', $d['id'])) {
             $edit_device_icon = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank')));
         } else {
             $edit_device_icon = '';
         }
         if (user_access('administer guifi users')) {
             $edit_ok_icon = drupal_get_form('_guifi_user_queue_device_form', $d);
         } else {
             $edit_ok_icon = $d['flag'];
             if (count($d['radios']) == 1 and $d['radios'][0]['mode'] == 'client') {
                 $edit_ok_icon .= ' ' . $d['radios'][0]['mac'];
             }
         }
         $ip = guifi_main_ip($d['id']);
         $status_url = guifi_cnml_availability(array('device' => $d['id'], 'format' => 'short'));
         $rows[] = array($edit_device_icon . l($d['nick'], 'guifi/device/' . $d['id'], array('attributes' => array('target' => '_blank'))), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d, $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $edit_ok_icon, 'class' => $d['flag']), array('data' => $status_url, 'class' => $d['flag']));
     }
     return $rows;
 }
Ejemplo n.º 10
0
function guifi_kamikaze_files($dev, $zone)
{
    //SOME VARIABLES
    $lan = guifi_unsolclic_if($dev->id, 'wLan/Lan');
    $wan = guifi_unsolclic_if($dev->id, 'Wan');
    $dns = guifi_get_dns($zone, 2);
    $wireless_model = 0;
    $wireless_iface = 0;
    switch ($dev->variable['model_id']) {
        case "1":
        case "15":
        case "16":
        case "17":
        case "18":
            // WRT54Gv1-4, WHR-HP-G54, WHR-G54S (BUFFALO), WRT54GL, WRT54GSv1-2, WRT54GSv4
            $wireless_model = 'broadcom';
            $wireless_iface = 'wl0';
            $vlans = 'config switch eth0
        option vlan0    \\"1 2 3 4 5*\\"
        option vlan1    \\"0 5\\"
      ';
            $lan_iface = 'eth0.0';
            $wan_iface = 'eth0.1';
            $txant = 'txant';
            $rxant = 'rxant';
            $packages = 'broadcom/packages';
            break;
        default:
            _outln_comment('model id not supported');
            exit;
    }
    if (empty($dev->radios[0][antenna_mode])) {
        $dev->radios[0][antenna_mode] = 'Main';
    }
    if ($dev->radios[0][antenna_mode] != 'Main') {
        $dev->radios[0][antenna_mode] = '1';
    } else {
        $dev->radios[0][antenna_mode] = '0';
    }
    $wds_links = array();
    $wds_str = '';
    foreach ($dev->radios as $radio_id => $radio) {
        foreach ($radio[interfaces] as $interface_id => $interface) {
            if ($interface['interface_type'] == 'wds/p2p') {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $key => $link) {
                        if ($link['link_type'] == 'wds') {
                            $wds_links[] = $link;
                        }
                        $iplocal[] = $ipv4;
                        $iflocal[] = $interface;
                    }
                }
            }
        }
    }
    if (count($wds_links) == 0) {
        return;
    }
    // SECTION FILES
    // FILE NETWORK
    $lan_network = _ipcalc($lan->ipv4, $lan->netmask);
    $file_network = '
' . $vlans . '
config interface loopback
        option \'ifname\'  \'lo\'
        option \'proto\'    \'static\'
        option \'ipaddr\'   \'127.0.0.1\'
        option \'netmask\'  \'255.0.0.0\'

config interface lan
        option \'ifname\'   \'' . $lan_iface . '\'
        option \'type\'     \'bridge\'
        option \'proto\'    \'static\'
        option \'ipaddr\'   \'' . $lan->ipv4 . '\'
        option \'netmask\'  \'' . $lan->netmask . '\'
        option \'gateway\'  \'0.0.0.0\'
        option \'dns\'      \'' . $dns . '\'

config interface wan
        option \'ifname\'   \'' . $wan_iface . '\'
        option \'proto\'    \'none\'
        
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/network'));
    _out_file($file_network, '/etc/config/network');
    // FILE WIRELESS
    $file_wireless = '
config \'wifi-device\' \'' . $wireless_iface . '\'
        option \'type\' \'' . $wireless_model . '\'
        option \'channel\' \'' . $dev->radios[0][channel] . '\'
        option \'disabled\' \'0\'
        option \'' . $txant . '\' \'' . $dev->radios[0][antenna_mode] . '\'
        option \'' . $rxant . '\' \'' . $dev->radios[0][antenna_mode] . '\'

config wifi-iface
        option \'device\' \'' . $wireless_iface . '\'
        option \'network\' \'lan\'
        option \'mode\' \'ap\'
        option \'ssid\' \'guifi.net-' . guifi_to_7bits($dev->radios[0][ssid]) . '\'
        option \'encryption \'none\'
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/wireless'));
    _out_file($file_wireless, '/etc/config/wireless');
    // WDS Links
    $ifcount = 1;
    foreach ($wds_links as $key => $wds) {
        $hostname = guifi_get_hostname($wds['device_id']);
        if (preg_match("/(Working|Testing|Building)/", $wds['flag'])) {
            $status = 'active';
            if ($wds['routing'] == 'BGP') {
                $bgpd = '1';
            }
            if ($wds['routing'] == 'OSPF') {
                $ospfd = '1';
            }
            $ifcount++;
            $wds_won = 'option \'bssid\' \'' . $wds['interface']['mac'] . '\'';
            $wds_non = 'option \'proto\' \'static\'
        option \'ifname\' \'wds0.' . ($key + 1) . '\'
        option \'ipaddr\' \'' . $iplocal[$key][ipv4] . '\'
        option \'netmask\' \'' . $iplocal[$key][netmask] . '\'';
        } else {
            $status = 'disabled';
            $wds_won = 'option \'bssid\' \'00:00:00:00:00:00\'';
            $wds_non = 'option \'proto\' \'none\'';
        }
        $wds_network = 'config \'interface\' \'wds_' . $hostname . '\'
        ' . $wds_non . '
        ';
        $wds_wireless = 'config \'wifi-iface\'
        option \'device\' \'wl0\'
        option \'network\' \'wds_' . $hostname . '\'
        option \'mode\' \'wds\'
        option \'encryption\' \'none\'
        ' . $wds_won . '
        ';
        _outln_comment();
        _outln_comment('WDS ' . $hostname . '');
        _outln_comment('Routing: ' . $wds['routing'] . '');
        _outln_comment('Status: ' . $status . '');
        print '<pre>echo "' . $wds_network . '
" >> /etc/config/network
          </pre>';
        print '<pre>echo "' . $wds_wireless . '
" >> /etc/config/wireless
          </pre>';
    }
    if (count($wds_links) >= 5) {
        return;
    }
    // QUAGGA CONFIG FILES
    $file_zebra = '';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/quagga/zebra.conf'));
    _out_file($file_zebra, '/etc/quagga/zebra.conf');
    // FILE OSPFD
    if ($ospfd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/ospfd.conf'));
        print '<pre>mv /etc/quagga/ospfd.conf /etc/quagga/ospfd.conf.bak
echo "
!
interface br-lan
!
router ospf
 ospf router-id ' . $lan->ipv4 . '
 redistribute bgp
 network ' . $lan_network[netid] . '/' . $lan_network[maskbits] . ' area 0<br />';
        foreach ($wds_links as $key => $wds) {
            if ($wds['routing'] == 'OSPF') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . ' area 0<br />';
            }
        }
        print 'default-information originate
!
" > /etc/quagga/ospfd.conf</pre>';
    }
    // FILE BGPD
    if ($bgpd == '1') {
        _outln_comment();
        _outln_comment();
        _outln_comment(t('File /etc/quagga/bgpd.conf'));
        print '<pre>mv /etc/quagga/bgpd.conf /etc/quagga/bgpd.conf.bak
echo "
!
interface br-lan
!
router bgp ' . $dev->id . '
bgp router-id ' . $lan->ipv4 . '
 network ' . $lan_network[netid] . '/' . $lan_network[maskbits] . '<br />';
        foreach ($wds_links as $key => $wds) {
            if ($wds['routing'] == 'BGP') {
                $wds_network = _ipcalc($iplocal[$key][ipv4], $iplocal[$key][netmask]);
                print ' network ' . $wds_network[netid] . '/' . $wds_network[maskbits] . '<br />';
            }
        }
        print 'redistribute ospf
';
        foreach ($dev->radios as $radio_id => $radio) {
            foreach ($radio[interfaces] as $interface_id => $interface) {
                foreach ($interface[ipv4] as $ipv4_id => $ipv4) {
                    foreach ($ipv4[links] as $link_id => $link) {
                        if ($link['routing'] == 'BGP') {
                            print 'neighbor ' . $link['interface']['ipv4']['ipv4'] . ' remote-as ' . $link['device_id'] . '
';
                        }
                    }
                }
            }
        }
        print '" > /etc/quagga/bgpd.conf</pre>';
    }
    //FILE FIREWALL
    $firewall = '
config defaults
        option \'syn_flood\' \'1\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'
        
config zone
        option \'name\' \'lan\'
        option \'input\' \'ACCEPT\'
        option \'output\' \'ACCEPT\'
        option \'forward\' \'ACCEPT\'

';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/firewall'));
    _out_file($firewall, '/etc/config/firewall');
    //FILE OPKG
    $opkg_conf = '
src/gz guifi http://ausa.guifi.net/drupal/files/openwrt/ap/' . $packages . '
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/opkg.conf'));
    _out_file($opkg_conf, '/etc/opkg.conf');
    $dhcp_statics = array();
    $max = explode(".", $dev->ipv4);
    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];
        }
    }
    $main_ip = guifi_main_ip($dev->id);
    $item = _ipcalc_by_netbits($main_ip[ipv4], $main_ip[maskbits]);
    $max = explode(".", $main_ip[ipv4]);
    // cable links
    if (!empty($dev->interfaces)) {
        foreach ($dev->interfaces as $interface) {
            if (!empty($interface[ipv4])) {
                foreach ($interface[ipv4] as $ipv4) {
                    if (!empty($ipv4[links])) {
                        foreach ($ipv4[links] as $link) {
                            if ($link['interface'][ipv4][ipv4] != '') {
                                $item2 = _ipcalc($link['interface'][ipv4][ipv4], $link['interface'][ipv4][netmask]);
                                if ($item[netid] == $item2[netid]) {
                                    merge_static($link, $dhcp_statics, $max, $cur);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // ap/client links
    if (!empty($dev->radios)) {
        foreach ($dev->radios as $radio) {
            if (!empty($radio[interfaces])) {
                foreach ($radio[interfaces] as $interface) {
                    if (!empty($interface[ipv4])) {
                        foreach ($interface[ipv4] as $ipv4) {
                            if (!empty($ipv4[links])) {
                                foreach ($ipv4[links] as $link) {
                                    if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                                        merge_static($link, $dhcp_statics, $max, $cur);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $statics = count($dhcp_statics) - 1;
    $totalstatics = count($dhcp_statics);
    $first = explode(".", $item[netid]);
    $last = explode(".", $item[broadcast]);
    $limit = $last[3] - 1 - ($first[3] + 3) - $totalstatics;
    if ($statics == -1) {
        _outln_comment();
        _outln_comment(t('File /etc/config/luci_ethers'));
        _outln_nvram('dhcp_start', $max[3] + 2);
    }
    _outln_comment();
    _outln_comment(t('File /etc/config/luci_ethers'));
    print 'echo "';
    foreach ($dhcp_statics as $static) {
        print '<pre>
## Device: ' . $static[2] . '
config \'static_lease\'
        option \'macaddr\' \'' . $static[1] . '\'
        option \'ipaddr\' \'' . $static[0] . '\'
</pre>';
    }
    print '" > /etc/config/luci_ethers<br />';
    // FILE DHCP
    $file_dhcp = '
config \'dnsmasq\'
        option \'domainneeded\' \'1\'
        option \'boguspriv\' \'1\'
        option \'filterwin2k\' \'0\'
        option \'localise_queries\' \'1\'
        option \'local\' \'/lan/\'
        option \'domain\' \'lan\'
        option \'expandhosts\' \'1\'
        option \'nonegcache\' \'0\'
        option \'authoritative\' \'1\'
        option \'readethers\' \'1\'
        option \'leasefile\' \'/tmp/dhcp.leases\'
        option \'resolvfile\' \'/tmp/resolv.conf.auto\'

config \'dhcp\' \'lan\'
        option \'interface\' \'lan\'
        option \'leasetime\' \'12h\'
        option \'start\' \'' . ($max[3] + 2) . '\'
        option \'limit\' \'' . $limit . '\'
';
    _outln_comment();
    _outln_comment();
    _outln_comment(t('File /etc/config/dhcp'));
    _out_file($file_dhcp, '/etc/config/dhcp');
}
Ejemplo n.º 11
0
 function guifi_unsolclic_dhcp($dev)
 {
     $dhcp_statics = array();
     $max = explode(".", $dev->ipv4);
     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];
         }
     }
     $main_ip = guifi_main_ip($dev->id);
     $item = _ipcalc_by_netbits($main_ip[ipv4], $main_ip[maskbits]);
     $max = explode(".", $main_ip[ipv4]);
     // cable links
     if (!empty($dev->interfaces)) {
         foreach ($dev->interfaces as $interface) {
             if (!empty($interface[ipv4])) {
                 foreach ($interface[ipv4] as $ipv4) {
                     if (!empty($ipv4[links])) {
                         foreach ($ipv4[links] as $link) {
                             if ($link['interface'][ipv4][ipv4] != '') {
                                 $item2 = _ipcalc($link['interface'][ipv4][ipv4], $link['interface'][ipv4][netmask]);
                                 if ($item[netid] == $item2[netid]) {
                                     merge_static($link, $dhcp_statics, $max, $cur);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // ap/client links
     if (!empty($dev->radios)) {
         foreach ($dev->radios as $radio) {
             if (!empty($radio[interfaces])) {
                 foreach ($radio[interfaces] as $interface) {
                     if (!empty($interface[ipv4])) {
                         foreach ($interface[ipv4] as $ipv4) {
                             if (!empty($ipv4[links])) {
                                 foreach ($ipv4[links] as $link) {
                                     if ($link['link_type'] == 'ap/client' and !empty($link['interface'][ipv4][ipv4])) {
                                         merge_static($link, $dhcp_statics, $max, $cur);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $statics = count($dhcp_statics) - 1;
     $totalstatics = count($dhcp_statics);
     if ($statics == -1) {
         _outln_comment();
         _outln_comment('DHCP');
         _outln_nvram('dhcp_start', $max[3] + 5);
         return;
     }
     _outln_comment();
     _outln_comment('DHCP');
     if ($dev->variable['firmware'] == 'Alchemy') {
         _out_nvram('dhcpd_statics');
         for ($i = 0; $i < $statics; $i++) {
             _out(implode(" ", $dhcp_statics[$i]));
         }
         _out(implode(" ", $dhcp_statics[$statics]), '"');
     }
     if ($dev->variable['firmware'] == 'DD-WRTv23' or $dev->variable['firmware'] == 'DD-guifi') {
         $staticText = "";
         foreach ($dhcp_statics as $static) {
             $staticText .= $static[1] . "=" . $static[2] . "=" . $static[0] . " ";
         }
         _out('nvram set static_leases="' . $staticText, ' "');
         _outln_nvram('static_leasenum', $totalstatics);
     }
     if ($dev->variable['firmware'] == 'Talisman') {
         _out_nvram('dhcp_statics');
         foreach ($dhcp_statics as $static) {
             _out($static[1] . "-" . $static[0] . "-" . $static[2] . " ");
         }
         _out(null, '"');
     }
     _outln_nvram('dhcp_start', $max[3] + 5);
     return;
 }
Ejemplo n.º 12
0
function unsolclic_qmp($dev)
{
    $version = "v1.0.3";
    //  sed 's/<br \/>//g'
    //  echo "<pre>";
    //  _outln_comment("<pre>");
    _outln_comment("<style type=\"text/css\"> x {font-family:courier;} </style> <x>");
    _outln_comment("qMp Guifi-oneclick " . $version);
    _outln_comment("&nbsp;&nbsp;__&nbsp;_&nbsp;&nbsp;/\\/\\&nbsp;&nbsp;_&nbsp;__");
    _outln_comment("&nbsp;/&nbsp;_`&nbsp;|/&nbsp;&nbsp;&nbsp;&nbsp;\\|&nbsp;'_&nbsp;\\ ");
    _outln_comment("|&nbsp;(_|&nbsp;/&nbsp;/\\/\\&nbsp;\\&nbsp;|_)&nbsp;| ");
    _outln_comment("&nbsp;\\__,&nbsp;\\/&nbsp;&nbsp;&nbsp;&nbsp;\\/&nbsp;.__/ ");
    _outln_comment("&nbsp;&nbsp;&nbsp;&nbsp;|_|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|_| ");
    _outln_comment("&nbsp;quick MESH project </x> ");
    _outln_comment("");
    _outln_comment("<b>Important:</b> You should have <b>'qmp-guifi'</b> package installed in your node.");
    _outln_comment("");
    _outln_comment("To apply this configuration in your node, you can follow this instructions: ");
    _outln_comment("<a href='http://dev.qmp.cat/projects/qmp/wiki/Guifi_oneclick' target='_blank'>http://dev.qmp.cat/projects/qmp/wiki/Guifi_oneclick</a> ");
    _outln_comment("");
    // ONLY THE FIRST MESH IP FOUND IS GET
    // TO DO: Check if there are more than one MESH radios and/or interfaces
    //
    $mesh = "no";
    $ipv4 = "-";
    $netmask = "-";
    $devmodel = "-";
    foreach ($dev->radios as $radio) {
        if ($radio['mode'] == 'mesh') {
            $mesh = "yes";
            $ipd = guifi_main_ip($dev->id);
            if ($ipd != '') {
                $ipv4 = $ipd['ipv4'];
                $netmask = $ipd['netmask'];
                $maskbits = $ipd['maskbits'];
            } else {
                $ipv4 = "-";
                $netmask = "-";
                $maskbits = "-";
            }
        }
    }
    // GET ZONE NICK (MAYBE ID?)
    //
    $node = node_load(array('nid' => $dev->nid));
    $zone = node_load(array('nid' => $node->zone_id));
    $zonename = $zone->nick;
    _outln();
    _outln("meshradio='" . $mesh . "'");
    if ($mesh == 'yes') {
        _outln("nodename='" . $node->nick . "'");
        // This is the node name
        _outln("latitude='" . $node->lat . "'");
        _outln("longitude='" . $node->lon . "'");
        _outln("devname='" . $dev->nick . "'");
        // This is the device name with mesh radio
        _outln("devmodel='" . $dev->model . "'");
        _outln("ipv4='" . $ipv4 . "'");
        _outln("netmask='" . $netmask . "'");
        _outln("zoneid='" . $zonename . "'");
    } else {
        _outln();
        _outln_comment(" <b>You don't have any Mesh radio!</b>");
        _outln_comment(" If you want to use Guifi-oneclick, make sure you configure it properly.");
        _outln_comment(" You can follow the instructions in the wiki: <a href='./unsolclic' target='_self'>EN (not yet)</a>, <a href='http://es.wiki.guifi.net/wiki/Mesh#Conectarse_a_una_red_Mesh' target='_blank'>ES</a>, <a href='http://ca.wiki.guifi.net/wiki/Mesh#Connectar-se_a_una_xarxa_Mesh' target='_blank'>CA</a>");
    }
    //  var_dump($node->nid['zone_id']);
}
Ejemplo n.º 13
0
 function _guifi_zone_availability_devices($nid)
 {
     $oneyearfromnow = time() - '31622400';
     $qry = db_query('SELECT d.id did, d.nick dnick, d.flag dflag, d.timestamp_changed changed ' . 'FROM {guifi_devices} d ' . 'WHERE d.type = "radio" ' . '  AND d.nid=%d ' . 'ORDER BY d.nick', $nid);
     $rows = array();
     while ($d = db_fetch_array($qry)) {
         $dev = guifi_device_load($d['did']);
         if (guifi_device_access('update', $dev)) {
             $edit = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['did'] . '/edit', array('html' => TRUE, 'attributes' => array('title' => t('edit device'), 'target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['did'] . '/delete', array('html' => TRUE, 'attributes' => array('title' => t('delete device'), 'target' => '_blank')));
         } else {
             $edit = NULL;
         }
         $ip = guifi_main_ip($d['did']);
         $status_url = guifi_cnml_availability(array('device' => $d['did'], 'format' => 'long'));
         if (!empty($d['changed'])) {
             if ($d['changed'] < $oneyearfromnow) {
                 $dchanged = array('data' => '<b><font color="#AA0000">' . format_date($d['changed'], 'custom', t('d/m/Y')) . '</font></b>');
             } else {
                 $dchanged = array('data' => format_date($d['changed'], 'custom', t('d/m/Y')));
             }
         } else {
             $dchanged = array('data' => t('never changed'));
         }
         $rows[] = array(array('data' => $edit . l($d['dnick'], 'guifi/device/' . $d['did'])), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d['did'], $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $d['dflag'] . $status_url, 'class' => $d['dflag']), $dchanged);
     }
     guifi_log(GUIFILOG_TRACE, 'function guifi_zone_availability_device()', $rows);
     return $rows;
 }