function _ipcalc($ip, $mask)
{
    # Modified by Ramon Roca (http://guifi.net)
    # based on code created by Daniel Lafraia
    # www.lafraia.com
    # Please do not remove this header
    $return = array();
    $return['netmask'] = $mask;
    if ($ip == '0.0.0.0' && ($mask == '0.0.0.0' || $mask == 0)) {
        $return['netid'] = '0.0.0.0';
        $return['netmask'] = '0.0.0.0';
        $return['broadcast'] = '255.255.255.255';
        $return['netstart'] = '0.0.0.1';
        $return['netend'] = '255.255.255.254';
        $return['maskbits'] = '0';
        $return['wildcard'] = '255.255.255.255';
        $return['hosts'] = ip2long($return['netend']) - ip2long($return['netstart']) + 1;
        return $return;
    }
    $octets = array("ip" => preg_split('/\\./', $ip), "mask" => preg_split('/\\./', $mask));
    foreach ($octets as $obj => $split) {
        foreach ($split as $val) {
            if ($val >= 0 && $val <= 255) {
                $octets[$obj]['binary'] .= str_repeat("0", 8 - strlen(decbin($val))) . decbin($val);
            } else {
                guifi_log(GUIFILOG_NONE, '_ipcalc ' . $ip . ' mask ' . $mask . ' invalid(' . $obj . ')', NULL);
                print "Error: Item '{$obj}' invàlid";
                return -1;
            }
        }
    }
    if ($mask == '255.255.255.255') {
        $return['maskbits'] = 32;
    } else {
        if (!preg_match("/^(1+)0+\$/", $octets['mask']['binary'], $matches)) {
            guifi_log(GUIFILOG_NONE, '_ipcalc ' . $ip . ' mask ' . $mask . ' invalid (' . $obj . ')', $matches);
            //    print "Error: Item 'mask' ".$mask." invàlid ";
            return -1;
        } else {
            $return["maskbits"] = strlen($matches[1]);
        }
    }
    $return['netid'] = bintoIP(substr($octets['ip']['binary'], 0, $return["maskbits"]) . str_repeat("0", 32 - $return["maskbits"]));
    $return['broadcast'] = bintoIP(substr($octets['ip']['binary'], 0, $return["maskbits"]) . str_repeat("1", 32 - $return["maskbits"]));
    $positivemask = 32 - $return["maskbits"] - 1 >= 0 ? 32 - $return["maskbits"] - 1 : 0;
    $return['netstart'] = bintoIP(substr($octets['ip']['binary'], 0, $return["maskbits"]) . str_repeat("0", $positivemask) . "1");
    $return['netend'] = bintoIP(substr($octets['ip']['binary'], 0, $return["maskbits"]) . str_repeat("1", $positivemask) . "0");
    $return['wildcard'] = preg_replace(array("/1/", "/0/"), array("a", "b"), $octets['mask']['binary']);
    $return['wildcard'] = bintoIP(preg_replace(array("/a/", "/b/"), array("0", "1"), $return['wildcard']));
    $return['hosts'] = ip2long($return['netend']) - ip2long($return['netstart']) + 1;
    return $return;
}
/**
 * It delivers all the notification messages and empties the queue
 *
 * @param $send
 *   If FALSE, the messages won't be sent nor removed from the queue
 *
 * @return
 *   Message sent or to be sent, HTML formatted
 */
function guifi_notify_send($send = TRUE)
{
    global $user;
    $destinations = array();
    $messages = array();
    // Get all the queue to be processesed, grouping to every single destination
    $qt = db_query("\n    SELECT *\n    FROM {guifi_notify}");
    while ($message = db_fetch_array($qt)) {
        $messages[$message['id']] = $message;
        foreach (unserialize($message['to_array']) as $dest) {
            $destinations[$dest][] = $message['id'];
        }
    }
    // For every destination, construct a single mail with all messages
    $errors = FALSE;
    $output = '';
    foreach ($destinations as $to => $msgs) {
        $body = str_repeat('-', 72) . "\n\n" . t('Complete trace messages (for trace purposes, to be used by developers)') . "\n" . str_repeat('-', 72) . "\n";
        $subjects = t('Summary of changes:') . "\n" . str_repeat('-', 72) . "\n";
        foreach ($msgs as $msg_id) {
            $subjects .= format_date($messages[$msg_id]['timestamp'], 'small') . ' ** ' . $messages[$msg_id]['who_name'] . ' ' . $messages[$msg_id]['subject'] . "\n";
            $body .= format_date($messages[$msg_id]['timestamp'], 'small') . ' ** ' . $messages[$msg_id]['who_name'] . ' ' . $messages[$msg_id]['subject'] . "\n" . $messages[$msg_id]['body'] . "\n" . str_repeat('-', 72) . "\n";
        }
        $subject = t('[guifi.net notify] Report of changes at !date', array('!date' => format_date(time(), 'small')));
        $output .= '<h2>' . t('Sending a mail to: %to', array('%to' => $to)) . '</h2>';
        $output .= '<h3>' . $subject . '</h3>';
        $output .= '<pre><small>' . $subjects . $body . '</small></pre>';
        $params['mail']['subject'] = $subject;
        $params['mail']['body'] = $subjects . $body;
        $return = FALSE;
        if ($send) {
            $return = drupal_mail('guifi_notify', 'notify', $to, user_preferred_language($user), $params, variable_get('guifi_contact', $user->mail));
            guifi_log(GUIFILOG_TRACE, 'return code for email sent:', $return);
        }
        if ($return['result']) {
            watchdog('guifi', 'Report of changes sent to %name', array('%name' => $to));
        } else {
            watchdog('guifi', 'Unable to notify %name', array('%name' => $to), WATCHDOG_ERROR);
            $errors = TRUE;
        }
    }
    // delete messages
    if (!$errors and $send) {
        db_query("DELETE FROM {guifi_notify}\n       WHERE id in (" . implode(',', array_keys($messages)) . ")");
    }
    return $output;
}
function guifi_traceroute_search($params = NULL)
{
    if (count($params)) {
        $to = explode(',', $params);
        $from = array_shift($to);
    }
    $output = drupal_get_form('guifi_traceroute_search_form', $from, $to);
    if (!count($to)) {
        return $output;
    }
    if (is_numeric($to[0])) {
        $dto = guifi_get_devicename($to[0], 'nick');
    } else {
        $dto = $to[0];
        $qry = db_query('SELECT device_id FROM {guifi_services} WHERE service_type="%s"', $to[0]);
        $nto = array();
        while ($service = db_fetch_object($qry)) {
            $nto[] = $service->device_id;
        }
        $to = $nto;
    }
    $routes = array();
    $btime = microtime(TRUE);
    $explored = guifi_traceroute(array($from => array()), $to, $routes);
    $tracetit = t('%results routes found. %explored routes analyzed in %secs seconds', array('%results' => count($routes), '%explored' => number_format($explored), '%secs' => number_format(microtime(TRUE) - $btime, 4)));
    $tracetit .= '<br /><small>' . t('Note that this is a software traceroute generated by the information currently available at the database, it might be distinct than the real routes at the network, however this information could be helpful in cleaning the data and network planning.') . '</small><hr>';
    sort($routes);
    $linkslist = array();
    $nodeslist = array();
    $nroute = 0;
    $trace = '';
    $collapsed = FALSE;
    foreach ($routes as $route) {
        end($route[1]);
        $target = key($route[1]);
        $trace .= theme('fieldset', array('#title' => t('Route from !oname to !dname, !hops hops, cost !cost', array('!cost' => $route[0], '!oname' => guifi_get_devicename($from, 'nick'), '!hops' => count($route[1]) - 1, '!dname' => guifi_get_devicename($target, 'nick'))), '#value' => theme_guifi_traceroute($route[1]), '#collapsible' => TRUE, '#collapsed' => $collapsed));
        $collapsed = TRUE;
        guifi_traceroute_dataexport($route[1], ++$nroute, $linkslist, $nodeslist);
    }
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_traceroute.js', 'module');
        $datalinks = guifi_export_arraytojs($linkslist);
        $datanodes = guifi_export_arraytojs($nodeslist);
        $lat1 = 99;
        $lon1 = 190;
        $lat2 = -99;
        $lon2 = -190;
        foreach ($nodeslist as $value) {
            if ($value[lat] < $lat1) {
                $lat1 = $value[lat];
            }
            if ($value[lon] < $lon1) {
                $lon1 = $value[lon];
            }
            if ($value[lat] > $lat2) {
                $lat2 = $value[lat];
            }
            if ($value[lon] > $lon2) {
                $lon2 = $value[lon];
            }
        }
        if ($lat1 == 99) {
            $lat1 = 'NA';
            $lon1 = 'NA';
            $lat2 = 'NA';
            $lon2 = 'NA';
        }
        $tracetit .= '<form>' . '<input type=hidden value=' . $lat1 . ' id=lat />' . '<input type=hidden value=' . $lon1 . ' id=lon />' . '<input type=hidden value=' . $lat2 . ' id=lat2 />' . '<input type=hidden value=' . $lon2 . ' id=lon2 />' . '<input type=hidden value="' . $datalinks . '" id=datalinks />' . '<input type=hidden value="' . $datanodes . '" id=datanodes />' . '<input type=hidden value=' . base_path() . drupal_get_path('module', 'guifi') . '/js/' . ' id=edit-jspath />' . '<input type=hidden value=' . variable_get('guifi_wms_service', '') . ' id=guifi-wms />' . '</form>';
        $tracetit .= drupal_get_form('guifi_traceroute_map_form');
        $tracetit .= '<div id="map" style="width: 100%; height: 600px; margin:5px;"></div>';
    }
    $output .= theme('box', t('Software traceroute result from %from to %to', array('%from' => guifi_get_devicename($from, 'nick'), '%to' => $dto)), $tracetit . $trace);
    guifi_log(GUIFILOG_TRACE, 'Routes', $routes);
    return $output;
}
function guifi_interfaces_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $radio_id = $values[count($values) - 4];
    $interface_id = $values[count($values) - 2];
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_interface_delete_submit(radio: %d, interface: %d)', $radio_id, $interface_id), $form_state['clicked_button']['#parents']);
    if ($values[0] == 'interfaces') {
        $interface =& $form_state['values']['interfaces'][$interface_id];
    } else {
        $form_state['values']['radios'][$radio_id]['unfold'] = TRUE;
        $interface =& $form_state['values']['radios'][$radio_id]['interfaces'][$interface_id];
    }
    $interface['unfold'] = TRUE;
    $interface['deleted'] = TRUE;
    //  $form_state['deleteInterface']=($radio_id).','.($interface_id);
    $form_state['rebuild'] = TRUE;
    //  $form_state['action'] = 'guifi_interface_delete';
    return TRUE;
}
function guifi_devicename_validate($devicestr, &$form_state)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_devicename_validate()', $form_state['values']['form_id']);
    if ($form_state['clicked_button']['#value'] == t('Reset') or empty($devicestr['#value'])) {
        return;
    }
    $dev = explode('-', $devicestr['#value']);
    $qry = db_query('SELECT id FROM {guifi_devices} WHERE id="%s"', $dev[0]);
    while ($device = db_fetch_array($qry)) {
        if ($form_state['values']['form_id'] != 'guifi_device_form') {
            $form_state['values']['nid'] = $device['id'];
        }
        return $devicestr;
    }
    form_error($devicestr, t('Device name %name not valid.', array('%name' => $devicestr['#value'])), 'error');
    return $devicestr;
}
function guifi_links_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $remote_did = array_pop($values);
    $remote_nid = array_pop($values);
    $link_id = array_pop($values);
    $dummy = array_pop($values);
    $ipv4_id = array_pop($values);
    $dummy = array_pop($values);
    $interface_id = array_pop($values);
    $dummy = array_pop($values);
    if ($values['0'] == 'radios') {
        $radio_id = array_pop($values);
        $fbase =& $form_state['values']['radios'][$radio_id];
        $fbase['unfold'] = TRUE;
    } else {
        $fbase =& $form_state['values'];
    }
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_radio_interface_link_delete_submit(radio: %d-%s, interface: %d, ipv4: %d, lid: %d, rnid: %d rdid: %d)', $radio_id, $form_state['values']['radios'][$radio_id]['mode'], $interface_id, $ipv4_id, $link_id, $remote_nid, $remote_did), $values);
    $fbase['interfaces'][$interface_id]['unfold'] = TRUE;
    $fipv4 =& $fbase['interfaces'][$interface_id]['ipv4'][$ipv4_id];
    $fipv4['unfold'] = TRUE;
    $flink =& $fipv4['links'][$link_id];
    $flink['unfold'] = TRUE;
    $flink['deleted'] = TRUE;
    $flink['ipv4']['unfold'] = TRUE;
    // if P2P link or AP/Client link and radio is the client
    // delete also the local IP
    if ($flink['ipv4']['netmask'] == '255.255.255.252' or $ipv4['netmask'] == '255.255.255.248' or $ipv4['netmask'] == '255.255.255.240' or $form_state['values']['radios'][$radio_id]['mode'] == 'client') {
        $fipv4['deleted'] = TRUE;
    }
    $form_state['rebuild'] = TRUE;
    drupal_set_message(t('%type link with %node/%device deleted.', array('%type' => $fbase['interfaces'][$interface_id]['interface_type'], '%node' => guifi_get_nodename($remote_nid), '%device' => guifi_get_hostname($remote_did))));
    return TRUE;
}
function guifi_stats_nodes()
{
    drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_stats_nodes.js', 'module');
    $output = "";
    if (isset($_GET['id'])) {
        $vid = $_GET['id'];
        if (isset($_GET['zone'])) {
            $zone_id = $_GET['zone'];
            if ($zone_id == "3671") {
                $zone_id = "0";
            }
        } else {
            $zone_id = "0";
        }
        if ($zone_id != "0") {
            $vz = "?zone=" . $zone_id;
        } else {
            $vz = "?zone=0";
        }
        if (isset($_GET['width'])) {
            $vz .= "&width=" . $_GET['width'];
        }
        if (isset($_GET['height'])) {
            $vz .= "&height=" . $_GET['height'];
        }
        if (isset($_GET['title'])) {
            $vz .= "&title=" . $_GET['title'];
        }
        switch ($vid) {
            case $vid == '5':
                if (isset($_GET['sid'])) {
                    $v = $_GET['sid'];
                } else {
                    $v = '12';
                }
                $output .= '<div id="plot" style="width: 500px; border-style:none; margin:5px;"><img src="/guifi/stats/chart0' . $vid . '/' . $v . $vz . '"></div>';
                break;
            case $vid >= 1 && $vid <= 9:
                $output .= '<div id="plot" style="width: 500px; border-style:none; margin:5px;"><img src="/guifi/stats/chart0' . $vid . '/0' . $vz . '"></div>';
                break;
            default:
                $vid = '0';
                break;
        }
    } else {
        $vid = '0';
        if (isset($_GET['zone'])) {
            $zone_id = $_GET['zone'];
            if ($zone_id == "3671") {
                $zone_id = "0";
            }
        } else {
            $zone_id = "0";
        }
    }
    if ($vid == '0') {
        $output .= drupal_get_form('guifi_stats_nodes_form', $zone_id);
        $output .= '<div id="sep" style="height: 5px; border-style:none; float:none; margin:5px;"></div>';
        $output .= '<div id="plot" style="width: 500px; border-style:none; float:right; margin:5px;"></div>';
        $output .= '<div id="menu" style="width: 230px; margin:5px;">';
        $output .= '<a href="javascript:guifi_stats_chart01()">' . t("1 Growth chart") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart02()">' . t("2 Annual increment") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart03()">' . t("3 Monthly average") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart04()">' . t("4 Last year") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart05(3)">' . t("5.3 Nodes per month, avr. 3m.") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart05(6)">' . t("5.6 Nodes per month, avr. 6m.") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart05(12)">' . t("5.12 Nodes per month, avr. 12m.") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart06()">' . t("6 Zones") . '</a>';
        $output .= '<br /><a href="javascript:guifi_stats_chart07()">' . t("7 Largest annual increase") . '</a>';
        $output .= '</div>';
        $output .= '<div style="height:300px">&nbsp;</div>';
        $output .= '<div style="width:700px;">';
        $output .= t('link:') . ' http://guifi.net/guifi/menu/stats/nodes?id=N';
        $output .= '<br />' . t('link:') . ' http://guifi.net/guifi/menu/stats/nodes?id=N&sid=M';
        $output .= '<br />' . t('image:') . ' &lt;img src="http://guifi.net/guifi/stats/chart?id=N"&gt;';
        $output .= '<br />' . t('image:') . ' &lt;img src="http://guifi.net/guifi/stats/chart?id=N&sid=M"&gt;';
        $output .= '<br />' . t('options:') . ' &zone=nnnn&width=nnn&height=nnn&title=';
        $output .= '</div>';
    }
    guifi_log(GUIFILOG_TRACE, 'stats_nodes', 1);
    return $output;
}
function guifi_funders_form($node, &$form_weight)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_funders_form(funders 1)', $node->funders);
    foreach ($node->funders as $km => $vm) {
        if ($vm['new'] and (empty($vm['user']) and empty($vm['supplier']) and empty($vm['comment']))) {
            unset($node->funders[$km]);
            guifi_log(GUIFILOG_TRACE, 'function guifi_funders_form(funders -)', $km);
        }
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_funders_form(funders 2)', $node->funders);
    $form['funders'] = array('#type' => 'fieldset', '#title' => t('Funder(s)'), '#description' => t('Funders for this infrastructure. Used to recognize the ownership.<br>' . 'A funder is who contribute to this infrastructure. When a funder claims for refunds, new funder contributors become co-owners.<br>' . 'Use web username, supplier or a free text description, whatever is more suitable.<br>' . 'Use "Preview" button if you need more rows to fill.<br>' . 'Leave all fields in blank for delete a row.'), '#collapsible' => TRUE, '#collapsed' => $node->funders[0] != '' ? TRUE : FALSE, '#attributes' => array('class' => 'funders'), '#weight' => $form_weight++, '#tree' => TRUE);
    $funder_id = 0;
    $nfunders = count($node->funders);
    guifi_log(GUIFILOG_TRACE, 'function guifi_funders_form(funders)', $nfunders);
    do {
        $disabled = !guifi_funders_access('update', $node->funders[$funder_id]);
        $form['funders'][$funder_id]['user'] = array('#title' => t('User'), '#type' => 'textfield', '#size' => 40, '#default_value' => $node->funders[$funder_id]['user'] != '' ? $node->funders[$funder_id]['user'] : NULL, '#maxsize' => 256, '#disabled' => $disabled, '#autocomplete_path' => 'guifi/js/select-user', '#prefix' => '<div class="funder-item">', '#weight' => $form_weight++);
        $form['funders'][$funder_id]['supplier'] = array('#title' => t('Supplier'), '#type' => 'textfield', '#disabled' => $disabled, '#size' => 30, '#default_value' => $node->funders[$funder_id]['supplier'] != '' ? $node->funders[$funder_id]['supplier'] : NULL, '#maxsize' => 256, '#autocomplete_path' => 'budgets/js/select-supplier', '#weight' => $form_weight++);
        $form['funders'][$funder_id]['id'] = array('#type' => 'hidden', '#value' => $node->funders[$funder_id]['id'], '#weight' => $form_weight++);
        $form['funders'][$funder_id]['user_created'] = array('#type' => 'hidden', '#value' => $node->funders[$funder_id]['user_created'], '#weight' => $form_weight++);
        $form['funders'][$funder_id]['comment'] = array('#title' => t('Comment'), '#disabled' => $disabled, '#description' => t('Funder description or not registered funder name'), '#type' => 'textfield', '#size' => 50, '#maxsize' => 256, '#required' => FALSE, '#default_value' => $node->funders[$funder_id]['comment'], '#weight' => $form_weight++);
        if ($node->funders[$funder_id]) {
            $u = user_load($node->funders[$funder_id]['user_created']);
            $form['funders'][$funder_id]['created'] = array('#title' => t('Created'), '#disabled' => yes, '#type' => 'item', '#value' => l($u->name, 'user/' . $u->uid) . ', ' . format_date($node->funders[$funder_id]['timestamp_created'], 'small'), '#weight' => $form_weight++);
        }
        if ($funder_id == $nfunders) {
            $form['funders'][$funder_id]['new'] = array('#type' => 'hidden', '#value' => true);
        }
        $funder_id++;
    } while ($funder_id < $nfunders + 1);
    return $form['funders'];
}
/**
 * Save changes to the database.
 */
function guifi_user_save($edit)
{
    global $user;
    $n = node_load($edit['nid']);
    $to_mail = $n->notification;
    $log = '';
    if (isset($edit['services'])) {
        if (isset($edit['services']['proxystr'])) {
            unset($edit['services']['proxystr']);
        }
        $edit['services'] = serialize($edit['services']);
    }
    if (isset($edit['var'])) {
        $edit['extra'] = serialize($edit['var']);
    }
    if (isset($edit['content_filters'])) {
        $edit['content_filters'] = serialize($edit['content_filters']);
    }
    if (isset($edit['username_created'])) {
        $cuser = user_load(array('name' => $edit['username_created']));
        $edit['user_created'] = $cuser->uid;
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_user_save()', $edit);
    _guifi_db_sql('guifi_users', array('id' => $edit['id']), $edit, $log, $to_mail);
    drupal_set_message(t('%user saved. Note that in some cases the change will not take effect until after some time.', array('%user' => $edit['username'])));
    guifi_notify($to_mail, t('The user !username has been UPDATED by !user.', array('!username' => $edit['username'], '!user' => $user->name)), $log);
}
/**
 * guifi_device_graph_overview
 * outputs an overiew graph of the device
**/
function guifi_device_graph_overview($radio)
{
    guifi_log(GUIFILOG_TRACE, 'guifi_device_graph_overview()', $radio);
    if (isset($radio['mode'])) {
        $radio['type'] = 'radio';
    }
    if ($radio['graph_server'] == -1) {
        $rows[] = array(t('This device has the graphs disabled.'));
        return array_merge($rows);
    }
    if (empty($radio['graph_server'])) {
        $gs = guifi_service_load(guifi_graphs_get_server($radio['id'], 'device'));
    } else {
        $gs = guifi_service_load($radio['graph_server']);
    }
    if (substr($server_mrtg, 0, 3) == "fot") {
        $ssid = get_SSID_radio($radio['id']);
        $ssid = strtolower($ssid);
        $mrtg_url = substr($server_mrtg, 3);
        $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg" target="_blank" > <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_6&cfg=mrtg.cfg&png=weekly"></a>');
        $rows[] = array('<a href="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg" target="_blank" > <img src="' . $mrtg_url . '/14all.cgi?log=' . $ssid . '_ping&cfg=mrtg.cfg&png=weekly"></a>');
        return array_merge($rows);
    } else {
        $clients = db_fetch_object(db_query("SELECT count(c.id) count " . "FROM {guifi_links} c " . "WHERE c.device_id=%d " . "  AND c.link_type IN ('wds','ap/client','bridge')", $radio['id']));
        $args = array('type' => 'clients', 'node' => $radio['nid'], 'device' => $radio['id']);
        if ($clients->count > 1) {
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=in') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=in') . '"></a>', 'align' => 'center'));
            $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args, 'direction=out') . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args, 'direction=out') . '"></a>', 'align' => 'center'));
        } else {
            if ($radio['type'] == 'radio' or $radio['variable']['mrtg_index'] != '') {
                $args['type'] = 'device';
                $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args) . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args) . '"></a>', 'align' => 'center'));
            }
        }
        $args['type'] = 'pings';
        $rows[] = array(array('data' => '<a href=' . base_path() . 'guifi/graph_detail?' . guifi_cnml_args($args) . '><img src="' . guifi_cnml_call_service($gs->var['url'], 'graph', $args) . '"></a>', 'align' => 'center'));
        return array_merge($rows);
    }
}
function guifi_vinterfaces_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $interface_id = $values[1];
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_vinterface_delete_submit(radio: %d, interface: %d)', $radio_id, $interface_id), $form_state['clicked_button']['#parents']);
    $vinterface =& $form_state['values'][$values[0]][$interface_id];
    $vinterface['deleted'] = TRUE;
    //  $form_state['deleteInterface']=($radio_id).','.($interface_id);
    $form_state['rebuild'] = TRUE;
    //  $form_state['action'] = 'guifi_interface_delete';
    return TRUE;
}
Beispiel #12
0
/**
 * Add virtual interface
 *
 * URL: http://guifi.net/guifi/js/add-vinterface
 */
function guifi_ahah_add_vinterface($iClass)
{
    $iClass = arg(3);
    $edit = $_POST;
    $vinterfaces =& $_POST[arg(3)];
    guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_vinterface(iClass)', arg(3));
    guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_vinterface(vinterfaces)', $vinterfaces);
    // Build our new form element.
    $newI['new'] = TRUE;
    // $newI['interface_type'] = $iClass.$delta;
    $delta = count($vinterfaces);
    $newI['id'] = $delta;
    $newI['interface_id'] = $delta;
    $edit[$iClass][] = $newI;
    foreach ($edit[$iClass] as $k => $value) {
        guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_vinterface(iname)', $value);
        if (!empty($value[iname])) {
            $edit[$iClass][$k][interface_type] = $value[iname];
        }
    }
    guifi_log(GUIFILOG_TRACE, 'guifi_ahah_add_vinterface(newI)', $newI);
    $form_element = guifi_vinterfaces_form($iClass, $edit);
    //    guifi_vinterface_form($iClass,$newI,!$delta,guifi_get_currentInterfaces($_POST));
    //  drupal_alter('form', $form_element, array(), 'guifi_ahah_add_interface');
    // Build the new form.
    $form_state = array('submitted' => FALSE);
    $form_build_id = $_POST['form_build_id'];
    // Add the new element to the stored form. Without adding the element to the
    // form, Drupal is not aware of this new elements existence and will not
    // process it. We retreive the cached form, add the element, and resave.
    $form = form_get_cache($form_build_id, $form_state);
    $choice_form = $form[$iClass];
    $form_element['#weight'] = $choice_form['#weight'];
    $form_element['#collapsed'] = false;
    $form[$iClass] = $form_element;
    form_set_cache($form_build_id, $form, $form_state);
    $form += array('#post' => $_POST, '#programmed' => FALSE);
    // Rebuild the old form.
    $form = form_builder('guifi_device_form', $form, $form_state);
    // Render the new output.
    $choice_form = $form[$iClass];
    unset($choice_form['#prefix'], $choice_form['#suffix']);
    // Prevent duplicate wrappers.
    // unset($choice_form[$delta]);
    // build new form
    //  $fs = array();
    //  $form_element['#post'] = array();
    //  $form_element = form_builder($form_element['form_id']['#value'] , $form_element, $fs);
    //  $newfield = drupal_render($form_element);
    //  guifi_log(GUIFILOG_BASIC,sprintf('choice_form %d',$delta),htmlspecialchars($newfield));
    //  guifi_log(GUIFILOG_BASIC,'guifi_ahah_add_vinterface(choice_form)',$choice_form);
    $output = theme('status_messages') . drupal_render($choice_form) . $newfield;
    drupal_json(array('status' => TRUE, 'data' => $output));
    exit;
}
/**
 * outputs the zone information data
**/
function theme_guifi_service_data($node, $links = TRUE)
{
    if (!isset($node->nid)) {
        $node = node_load(array('nid' => $node->id));
    }
    guifi_log(GUIFILOG_TRACE, 'guifi_service_print_data()', $node);
    $zone = db_fetch_object(db_query('SELECT title FROM {guifi_zone} WHERE id = %d', $node->zone_id));
    $type = db_fetch_object(db_query('SELECT description FROM {guifi_types} WHERE type="service" AND text = "%s"', $node->service_type));
    $rows[] = array(t('service'), $node->nid . '-' . $node->nick, '<b>' . $node->title . '</b>');
    $rows[] = array(t('type'), $node->service_type, t($type->description));
    if ($node->device_id > 0) {
        $device = db_fetch_object(db_query('SELECT nick FROM {guifi_devices} WHERE id = %d', $node->device_id));
        $url = url('guifi/device/' . $node->device_id);
        $rows[] = array(t('device & status'), '<a href=' . $url . '>' . $device->nick . '</a>', array('data' => t($node->status_flag), 'class' => $node->status_flag));
    }
    $node->var = unserialize($node->extra);
    switch ($node->service_type) {
        case 'mail':
            $rows[] = array(t('inbound and outbound servers'), $node->var['in'], $node->var['out']);
            $rows[] = array(t('webmail and admin url'), guifi_url($node->var['webmail']), guifi_url($node->var['admin']));
            break;
        case 'Proxy':
        case 'ADSL':
            $rows[] = array(t('bandwidth (Down/Up)'), $node->var['down'], $node->var['up']);
            $rows[] = array(t('proxy name &#038; port'), $node->var['proxy'], $node->var['port']);
            $rows[] = array(t('type'), $node->var['type'], NULL);
            if (is_array($node->var['fed'])) {
                $rows[] = array(t('federation'), implode(", ", $node->var['fed']), NULL);
            } else {
                $rows[] = array(t('federation'), t('This proxy is not federated yet'), NULL);
            }
            break;
        case 'ftp':
            $rows[] = array(t('ftphost'), $node->var['ftphost'], NULL);
            $rows[] = array(t('supported protocols'), implode(", ", $node->var['protocols']), NULL);
            break;
        case 'ntp':
            $rows[] = array(t('IP address or hostname'), $node->var['ntp'], NULL);
            break;
        case 'asterisk':
            $rows[] = array(t('dial prefix and incoming calls'), $node->var['prefix'], $node->var['incoming']);
            if (isset($node->var['protocols'])) {
                $rows[] = array(t('supported protocols'), implode(", ", $node->var['protocols']), NULL);
            }
            break;
        default:
            if (!empty($node->var['url'])) {
                if (preg_match('/^http:\\/\\//', $node->var[url])) {
                    $url = $node->var[url];
                } else {
                    $url = 'http://' . $node->var[url];
                }
                $rows[] = array(t('url'), '<a href="' . $url . '">' . $node->var['url'] . '</a>', NULL);
            }
            break;
    }
    if (isset($node->var['homepages'])) {
        if (count($node->var['homepages'] > 0)) {
            $rows[] = array(t('homepages'), NULL, NULL);
            foreach ($node->var['homepages'] as $homepage) {
                if (preg_match('/^http:\\/\\//', $homepage)) {
                    $url = $homepage;
                } else {
                    $url = 'http://' . $homepage;
                }
                $rows[] = array(NULL, '<a href=' . $url . '>' . $homepage . '</a>', NULL);
            }
        }
    }
    if (isset($node->var['ircs'])) {
        if (count($node->var['ircs'] > 0)) {
            $rows[] = array(t('ircs'), NULL, NULL);
            foreach ($node->var['ircs'] as $irc) {
                $rows[] = array(NULL, $irc, NULL);
            }
        }
    }
    if (isset($node->var['domains'])) {
        if (count($node->var['domains'] > 0)) {
            $rows[] = array(t('domains'), NULL, NULL);
            foreach ($node->var['domains'] as $domain) {
                $rows[] = array(NULL, $domain, NULL);
            }
        }
    }
    $output = theme('table', NULL, $rows);
    $output .= theme_guifi_contacts($node);
    if ($links) {
        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;
}
Beispiel #14
0
function guifi_ipv4_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $k = count($values);
    $ka = $values[$k - 2];
    // ipv4#
    $ki = $values[$k - 4];
    // interface#
    if ($k == 7) {
        $rk = $values[$k - 6];
        // radio#
        $form_state['values']['radios'][$rk]['unfold'] = TRUE;
        $interface =& $form_state['values']['radios'][$rk]['interfaces'][$ki];
    } else {
        $rk = -1;
    }
    $interface =& $form_state['values']['interfaces'][$ki];
    guifi_log(GUIFILOG_TRACE, sprintf('function _guifi_delete_ipv4_submit(radio %d, interface %d, address: %d)', $rk, $ki, $ka), $form_state['clicked_button']['#parents']);
    $form_state['rebuild'] = TRUE;
    $interface['unfold'] = TRUE;
    $interface['ipv4'][$ka]['unfold'] = TRUE;
    $interface['ipv4'][$ka]['deleted'] = TRUE;
    if ($interface['ipv4'][$ka]['new']) {
        unset($interface['ipv4'][$ka]);
    }
    return;
}
function guifi_domain_add()
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_domain_add()');
    if (arg(8) == 'external') {
        $ipv4 = '';
    } else {
        $ipv4 = arg(6);
    }
    $output = drupal_get_form('guifi_domain_form', array('add' => arg(3), 'dname' => arg(4), 'type' => arg(5), 'ipv4' => $ipv4, 'mname' => arg(7), 'scope' => arg(8), 'management' => arg(9)));
    // To gain space, save bandwith and CPU, omit blocks
    print theme('page', $output, FALSE);
}
function guifi_devel_paramusc_delete_confirm($form_state, $id)
{
    guifi_log(GUIFILOG_TRACE, 'guifi_devel_parameter_delete_confirm()', $id);
    $form['id'] = array('#type' => 'hidden', '#value' => $id);
    $qry = db_fetch_object(db_query("SELECT\n                                      p.nom, pusc.uscid as uscid\n                                  FROM\n                                      guifi_parametresConfiguracioUnsolclic pusc\n                                      inner join guifi_parametres p on p.id = pusc.pid\n                                  WHERE\n                                      pusc.id = %d", $id));
    return confirm_form($form, t('Are you sure you want to delete the USC Configuration parameter " %parameter "?', array('%parameter' => $qry->nom)), "guifi/menu/devel/configuraciousc/{$qry->uscid}/edit", t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}
function guifi_routingmap_all_init()
{
    $output = "";
    if (guifi_gmap_key()) {
        drupal_add_js(drupal_get_path('module', 'guifi') . '/js/guifi_gmap_routingmapall.js', 'module');
        $output .= '<form>' . '<input type=hidden value=' . base_path() . drupal_get_path('module', 'guifi') . '/js/' . ' id=edit-jspath />' . '<input type=hidden value=' . variable_get('guifi_wms_service', '') . ' id=guifi-wms />' . '</form>';
        $output .= '<div id="topmap" style="margin:5px;text-align:center;font-size:14px"></div>';
        $output .= '<div id="map" style="width: 100%; height: 600px; margin:5px;"></div>';
        $output .= '<div id="bottommap" style="margin:5px;"></div>';
    }
    guifi_log(GUIFILOG_TRACE, 'routingmap', 1);
    return $output;
}
Beispiel #18
0
function guifi_cnml_home($cnmlid)
{
    if ($cnmlid == 0) {
        $vid = 1;
    } else {
        $vid = $cnmlid;
    }
    $CNML = new SimpleXMLElement('<cnml></cnml>');
    $CNML->addAttribute('version', '0.1');
    $CNML->addAttribute('server_id', '1');
    $CNML->addAttribute('server_url', 'http://guifi.net');
    $CNML->addAttribute('generated', date('Ymd hi', time()));
    switch ($vid) {
        case 1:
            //Home Avui
            $oGC = new GeoCalc();
            $btime = microtime(TRUE);
            $result = db_query("select COUNT(*) as num from {guifi_location} where status_flag='Working'");
            $classXML = $CNML->addChild('total_working_nodes');
            if ($record = db_fetch_object($result)) {
                $classXML->addAttribute('nodes', number_format($record->num, 0, ',', '.'));
            }
            // link statistics
            $dTotals = array();
            $dTotals['dTotal'] = 0;
            $dTotals['count'] = 0;
            $qlinks = db_query('
      SELECT
      l1.id, n1.id nid1, n2.id nid2, l1.link_type, n1.lat lat1,
      n1.lon lon1, n2.lat lat2, n2.lon lon2
      FROM guifi_links l1
      LEFT JOIN guifi_links l2 ON l1.id=l2.id
      LEFT JOIN guifi_location n1 ON l1.nid=n1.id
      LEFT JOIN guifi_location n2 ON l2.nid=n2.id
    WHERE l1.nid != l2.nid AND l1.device_id != l2.device_id');
            unset($listed);
            while ($link = db_fetch_object($qlinks)) {
                if (!isset($listed[$link->id])) {
                    $listed[$link->id] = $link;
                } else {
                    continue;
                }
                $d = round($oGC->EllipsoidDistance($link->lat1, $link->lon1, $link->lat2, $link->lon2), 1);
                if ($d < 100) {
                    $dTotals['dTotal'] += $d;
                    $dTotals['count']++;
                } else {
                    guifi_log(GUIFILOG_TRACE, sprintf('Probable DISTANCE error between nodes (%d and %d) %d kms.', $link->nid1, $link->nid2, $d));
                }
            }
            $classXML = $CNML->addChild('total_links');
            $classXML->addAttribute('num', number_format($dTotals['count'], 0, ',', '.'));
            $classXML->addAttribute('kms', number_format($dTotals['dTotal'], 1, ',', '.'));
            //add nodes last week
            $afecha = getdate();
            $tiempomax = mktime($afecha[hours], $afecha[minutes], $afecha[seconds], $afecha[mon], $afecha[mday], $afecha[year]);
            $tiempomin = $tiempomax - 604800;
            $qnodes = "select COUNT(*) as num from {guifi_location}\n      where status_flag!='Dropped'\n      and timestamp_created>" . $tiempomin . " and timestamp_created<=" . $tiempomax;
            $result = db_query($qnodes);
            $classXML = $CNML->addChild('nodes_last_week');
            if ($record = db_fetch_object($result)) {
                $classXML->addAttribute('total_nodes', number_format($record->num, 0, ',', '.'));
            }
            $qnodes = "select COUNT(*) as num from {guifi_location}\n      where status_flag='Working'\n      and timestamp_created>" . $tiempomin . " and timestamp_created<=" . $tiempomax;
            $result = db_query($qnodes);
            if ($record = db_fetch_object($result)) {
                $classXML->addAttribute('working_nodes', number_format($record->num, 0, ',', '.'));
            }
            $etime = microtime(TRUE);
            $classXML = $CNML->addChild('control');
            $classXML->addAttribute('in_seconds', number_format($etime - $btime, 4));
            break;
        case 2:
            //Home services
            //$result=db_query("select service_type as service,COUNT(*) as num from guifi_services where status_flag='Working' group by service_type");
            $result = db_query("select service_type as service,description as description,COUNT(*) as num from guifi_services as t1\n    inner join guifi_types as t2 on t2.type = 'service' and t1.service_type = t2.text\n    where status_flag='Working'\n    group by service_type");
            $classXML = $CNML->addChild('working_services');
            $num_type_services = 0;
            $total_services = 0;
            while ($record = db_fetch_object($result)) {
                $num_type_services++;
                $total_services += $record->num;
                $classXML2 = $classXML->addChild('service');
                $classXML2->addAttribute("type", $record->service);
                $classXML2->addAttribute("description", t($record->description));
                $classXML2->addAttribute("total", $record->num);
            }
            $classXML->addAttribute("types", $num_type_services);
            $classXML->addAttribute("total", $total_services);
            break;
        case 3:
            //Home budgets
            $classXML = $CNML->addChild('general_open_budgets');
            if (module_exists('budgets')) {
                $today = getdate();
                $qbudgets = db_query("SELECT b.id, b.expires " . "FROM {budgets} b " . "WHERE b.budget_status = 'Open' and b.zone_id = 3671 and b.expires >= " . $today[0] . " " . "ORDER BY b.id DESC");
                while ($budget = db_fetch_object($qbudgets)) {
                    $b = node_load(array('nid' => $budget->id));
                    $classXML2 = $classXML->addChild('budget');
                    $classXML2->addAttribute("id", $budget->id);
                    $classXML2->addAttribute("title", $b->title);
                    $classXML2->addAttribute("amount", $b->total);
                    $classXML2->addAttribute("funded", $b->covered);
                    $classXML2->addAttribute("currency_symbol", $b->currency_symbol);
                }
            }
    }
    return $CNML;
}
Beispiel #19
0
/** _guifi_db_delete(): Delete SQL statements for node, devices, radios, users, services, interfaces, ipv4, links, zones...
***/
function _guifi_db_delete($table, $key, &$to_mail = array(), $depth = 0, $cascade = TRUE)
{
    global $user;
    $log = str_repeat('- ', $depth);
    $depth++;
    $to_mail = array();
    guifi_log(GUIFILOG_TRACE, sprintf('function _guifi_db_delete(%s,%s)', $table, var_export($key, TRUE)));
    if (!in_array($user->mail, $to_mail)) {
        $to_mail[] = $user->mail;
    }
    switch ($table) {
        // Node (location)
        case 'guifi_location':
            // cascade to node devices
            $qc = db_query("SELECT id FROM {guifi_devices} where nid = '%s'", $key['id']);
            while ($device = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_devices', $device, $to_mail, $depth);
            }
            // cascade to node users
            $qc = db_query("SELECT id FROM {guifi_users} where nid = '%s'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_users', $quser, $to_mail, $depth);
            }
            // delete Device
            // cascade to node maintainers
            $qc = db_query("SELECT id FROM {guifi_maintainers} where subject_id = '%s' and subject_type='location'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_maintainers', $quser, $to_mail, $depth);
            }
            break;
        case 'guifi_dns_domains':
            $item = db_fetch_object(db_query('SELECT d.id did, d.name dname, d.notification, d.sid,
        l.nick nname, l.notification ncontact
       FROM {guifi_dns_domains} d LEFT JOIN {guifi_services} l ON d.sid=l.id
       WHERE d.id = %d', $key['id']));
            $log .= t('Domain %id-%name at node %nname deleted.', array('%id' => $key['id'], '%name' => $item->dname, '%nname' => $item->nname));
            // cascade to dns_hosts
            $qc = db_query('SELECT id, counter FROM {guifi_dns_hosts} WHERE id=%d', $key['id']);
            while ($host = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_dns_hosts', $host, $to_mail, $depth);
            }
            break;
        case 'guifi_devices':
            $item = db_fetch_object(db_query('SELECT d.nick dname, d.notification, d.nid, d.type, d.comment,
        l.nick nname, l.notification ncontact
       FROM {guifi_devices} d LEFT JOIN {guifi_location} l ON d.nid=l.id
       WHERE d.id = %d', $key['id']));
            $log .= t('Device (%type) %id-%name at node %nname deleted.', array('%type' => $item->type, '%id' => $key['id'], '%name' => $item->dname, '%nname' => $item->nname));
            // cascade to device radios
            $qc = db_query('SELECT id, radiodev_counter FROM {guifi_radios} WHERE id=%d', $key['id']);
            while ($radio = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_radios', $radio, $to_mail, $depth);
            }
            // cascade to device interfaces
            $qc = db_query('SELECT id FROM {guifi_interfaces} WHERE device_id=%d', $key['id']);
            while ($interface = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_interfaces', $interface, $to_mail, $depth);
            }
            // cascade to node maintainers
            $qc = db_query("SELECT id FROM {guifi_maintainers} where subject_id = '%s' and subject_type='device'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_maintainers', $quser, $to_mail, $depth);
            }
            break;
            // delete Radio
        // delete Radio
        case 'guifi_radios':
            $item = db_fetch_object(db_query('SELECT
          r.protocol, r.ssid sid, r.mode, r.radiodev_counter,
          d.nick dname, d.notification, d.nid, l.nick nname
        FROM {guifi_radios} r, {guifi_devices} d, {guifi_location} l
        WHERE  r.id = %d AND r.radiodev_counter = %d AND
          r.id=d.id AND d.nid=l.id', $key['id']), $key['radiodev_counter']);
            $log .= t('Radio (%mode-%protocol) %id-%rc %ssid at device %dname deleted.', array('%mode' => $item->mode, '%protocol' => $item->protocol, '%id' => $key['id'], '%rc' => $key['radiodev_counter'], '%ssid' => $item->sid, '%dname' => $item->dname));
            // cascade to radio interfaces
            $qc = db_query('SELECT id, radiodev_counter FROM {guifi_interfaces} WHERE device_id=%d AND radiodev_counter=%d', $key['id'], $key['radiodev_counter']);
            while ($interface = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_interfaces', $interface, $to_mail, $depth);
            }
            break;
            // delete Interfaces
        // delete Interfaces
        case 'guifi_interfaces':
            $item = db_fetch_object(db_query('SELECT i.interface_type, i.radiodev_counter, i.connto_did, i.connto_iid,
               d.nick dname,
               d.notification, d.nid, l.nick nname
        FROM {guifi_interfaces} i LEFT JOIN {guifi_devices} d ON i.device_id=d.id
             LEFT JOIN {guifi_location} l ON d.nid=l.id
        WHERE i.id = %d', $key['id']));
            $log .= t('interface (%type) %id - %rc at device %dname deleted.', array('%type' => $item->interface_type, '%id' => $key['id'], '%rc' => $item->radiodev_counter, '%dname' => $item->dname));
            // cascade ipv4
            $qc = db_query('SELECT id, interface_id FROM {guifi_ipv4} WHERE interface_id=%d', $key['id']);
            while ($ipv4 = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_ipv4', $ipv4, $to_mail, $depth);
            }
            // cascade remote interface plug
            if ($item->connto_did and $item->connto_iid) {
                $if_remote = array('device_id' => $item->connto_did, 'id' => $item->connto_iid, 'connto_did' => '', 'connto_iid' => '');
                _guifi_db_sql('guifi_interfaces', array('device_id' => $item->connto_did, 'id' => $item->connto_iid), $if_remote, $log, $to_mail);
            }
            break;
            // delete ipv4
        // delete ipv4
        case 'guifi_ipv4':
            $item = db_fetch_object(db_query('SELECT a.id, a.interface_id, a.ipv4, i.interface_type, d.nick dname, d.notification, d.nid, l.nick nname
        FROM {guifi_ipv4} a LEFT JOIN {guifi_interfaces} i ON a.interface_id=i.id LEFT JOIN {guifi_devices} d ON i.device_id=d.id LEFT JOIN {guifi_location} l ON d.nid=l.id
        WHERE a.id = %d AND a.interface_id=%d', $key['id'], $key['interface_id']));
            $log .= t('address (%addr) at device %dname deleted.', array('%addr' => $item->ipv4, '%dname' => $item->dname));
            if (!$cascade) {
                break;
            }
            // cascade links
            $qc = db_query('SELECT id, device_id FROM {guifi_links} WHERE ipv4_id=%d AND interface_id=%d', $key['id'], $key['interface_id']);
            while ($link = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_links', $link, $to_mail, $depth);
            }
            break;
            // delete links
        // delete links
        case 'guifi_links':
            $item = db_fetch_object(db_query('SELECT l.id, l.link_type, l.ipv4_id, i.id interface_id, ' . '       d.nick dname, d.id device_id, d.notification, d.nid, n.nick nname
        FROM {guifi_links} l ' . '    LEFT JOIN {guifi_interfaces} i ON l.interface_id=i.id ' . '    LEFT JOIN {guifi_devices} d ON l.device_id=d.id ' . '    LEFT JOIN {guifi_location} n ON l.nid=n.id
        WHERE l.id = %d' . '    AND l.device_id=%d', $key['id'], $key['device_id']));
            $log .= t('link %id-%did (%type) at %nname-%dname deleted.', array('%id' => $key['id'], '%did' => $key['device_id'], '%type' => $item->link_type, '%nname' => $item->nname, '%dname' => $item->dname));
            if (!$cascade) {
                break;
            }
            // cascade to remote link
            $qc = db_query('SELECT id, ipv4_id, interface_id, device_id ' . 'FROM {guifi_links} ' . 'WHERE id=%d ' . '  AND device_id !=%d', $key['id'], $key['device_id']);
            while ($link = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_links', $link, $to_mail, $depth, FALSE);
                // cleanup of remote ipv4 addresses when appropriate
                $qar = db_query('SELECT * ' . 'FROM {guifi_ipv4} ' . 'WHERE id=%d AND interface_id=%d', $link['ipv4_id'], $link['interface_id']);
                while ($ripv4 = db_fetch_array($qar)) {
                    $aitem = _ipcalc($ripv4['ipv4'], $ripv4['netmask']);
                    if ($ripv4['ipv4_type'] == '2') {
                        // type 2: link is backbone
                        // if the addres is a:
                        // /30 (single p2p link)
                        // or /29 and /28 ( Multilink )
                        if ($ripv4['netmask'] == '255.255.255.252' or $ripv4['netmask'] == '255.255.255.248' or $ripv4['netmask'] == '255.255.255.240') {
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $link['ipv4_id'], 'interface_id' => $link['interface_id']), $to_mail, $depth, FALSE);
                            // cascade to local ipv4
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $item->ipv4_id, 'interface_id' => $item->interface_id), $to_mail, $depth, FALSE);
                        }
                    } else {
                        $mlinks = db_fetch_array(db_query('SELECT count(id) AS links ' . 'FROM {guifi_links} ' . 'WHERE ipv4_id=%d AND interface_id=%d', $link['ipv4_id'], $link['interface_id']));
                        if ($ripv4['ipv4'] != $aitem['netstart'] and $mlinks['links'] < 1) {
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $link['ipv4_id'], 'interface_id' => $link['interface_id']), $to_mail, $depth, FALSE);
                        }
                    }
                    // guifi_log(GUIFILOG_BASIC,'function delete cascade remote address()',$link);
                    // cleanup remote interface when appropriate
                    $qir = db_query('SELECT i.id id, i.interface_type, count(a.id) na ' . 'FROM {guifi_interfaces} i ' . '  LEFT OUTER JOIN {guifi_ipv4} a ' . '  ON i.id=a.interface_id ' . 'WHERE i.id=%d ' . 'GROUP BY i.id, i.interface_type', $link['interface_id']);
                    while ($na = db_fetch_array($qir)) {
                        //          guifi_log(GUIFILOG_BASIC,'function delete cascade remote interface()',$na);
                        // delete the interface, if has no other ipv4 address and is not
                        // in the list Wan, wLan/Lan, Lan/Lan, Lan or wds/p2p
                        if (in_array($na['interface_type'], array('Wan', 'wLan/Lan', 'Lan/Lan', 'Lan', 'wds/p2p')) or $na['na'] != 0) {
                            continue;
                        }
                        $log .= '<br />' . _guifi_db_delete('guifi_interfaces', array('id' => $na['id']), $to_mail, $depth, FALSE);
                    }
                }
            }
            // delete services
        // delete services
        case 'guifi_services':
            // cascade interfaces
            break;
            // delete users
        // delete users
        case 'guifi_users':
            $item = db_fetch_object(db_query('SELECT * ' . 'FROM {guifi_users} u ' . 'WHERE id = %d', $key['id']));
            $log .= t('User %id-%name deleted.', array('%id' => $key['id'], '%name' => $item->username));
            break;
        case 'guifi_zone':
            break;
        case 'budgets':
            if (!$cascade) {
                break;
            }
            $qc = db_query('SELECT id, budget_id ' . 'FROM {budget_items} ' . 'WHERE budget_id=%d', $key['id']);
            while ($item = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('budget_items', $item, $to_mail, $depth);
            }
            $qc = db_query('SELECT id, budget_id ' . 'FROM {budget_funds} ' . 'WHERE budget_id=%d', $key['id']);
            while ($fund = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('budget_funds', $fund, $to_mail, $depth);
            }
            break;
    }
    $where_str = '';
    foreach ($key as $k => $value) {
        if ($where_str != '') {
            $where_str .= ' AND ';
        }
        if ($table == 'guifi_types') {
            $where_str .= $k . ' = \'' . $value . '\'';
        } else {
            $where_str .= $k . ' = ' . $value;
        }
    }
    $count = db_fetch_array(db_query("\n    SELECT count(*) c\n    FROM {" . $table . "}\n    WHERE " . $where_str));
    if ($count['c'] != 1) {
        return $log . '<br />' . t('There was nothing to delete at %table with (%where)', array('%table' => $table, '%where' => $where_str));
    }
    if (!in_array($item->notification, $to_mail)) {
        $to_mail[] = $item->notification;
    }
    if (!in_array($item->ncontact, $to_mail)) {
        $to_mail[] = $item->ncontact;
    }
    $where_str = '';
    foreach ($key as $k => $value) {
        if ($where_str != '') {
            $where_str .= ' AND ';
        }
        if ($table == 'guifi_types') {
            $where_str .= $k . ' = \'' . $value . '\'';
        } else {
            $where_str .= $k . ' = ' . $value;
        }
    }
    $delete_str = 'DELETE FROM {' . $table . '} WHERE ' . $where_str;
    $log .= '<br />' . $delete_str;
    guifi_log(GUIFILOG_TRACE, $delete_str);
    db_query($delete_str);
    return $log;
}
/**
 * E-mail address update form submit
 */
function guifi_tools_mail_update_form_submit($form, &$form_state)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'guifi_tools_mail_update_submit()', $form_state['values']);
    // perform the massive update to the granted rows, using guifi db api
    // instead of straight SQL to create the notificaton messages.
    $tables = array('guifi_zone', 'guifi_location', 'guifi_devices', 'guifi_services', 'guifi_users');
    foreach ($tables as $table) {
        $sqlm = db_query('SELECT * FROM {%s} WHERE notification LIKE "%s"', $table, $form_state['values']['mail_search']);
        while ($amails = db_fetch_object($sqlm)) {
            // Check that the user has update access and creates the link
            $continue = FALSE;
            if (!user_access('administer guifi networks')) {
                switch ($table) {
                    case 'guifi_users':
                        $title = $amails->username;
                        $type = t('User');
                        if (guifi_user_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_devices':
                        $title = $amails->nick;
                        $type = t('Device');
                        if (guifi_device_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_zone':
                        $title = $amails->nick;
                        $type = t('Zone');
                        if (guifi_zone_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_location':
                        $title = $amails->nick;
                        $type = t('Node');
                        if (guifi_node_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_service':
                        $title = $amails->nick;
                        $type = t('Service');
                        if (guifi_service_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                }
            } else {
                $continue = TRUE;
            }
            if (!$continue) {
                continue;
            }
            // here we have update access, so perform the update
            // Notify prevuious mail id, just in case...
            $to_mail = $amails->notification;
            $amails->notification = str_ireplace($form_state['values']['mail_search'], strtolower($form_state['values']['mail_replacewith']), $amails->notification);
            if ($to_mail == $amails->notification) {
                //no changes, so next
                continue;
            }
            $n = _guifi_db_sql($table, array('id' => $amails->id), (array) $amails, $log, $to_mail);
            guifi_notify($to_mail, t('The notification %notify for %type %title has been CHANGED to %new by %user.', array('%notify' => $form_state['values']['mail_search'], '%new' => $form_state['values']['mail_replacewith'], '%type' => $type, '%title' => $title, '%user' => $user->name)), $log);
        }
        // foreach row with the email found
    }
    // foreach table
    drupal_goto('guifi/menu/ip/mailsearch/' . $form_state['values']['mail_replacewith']);
}
Beispiel #21
0
/**
 * Remove a device from guifi.net
 *
 * @param GuifiAPI $gapi
 * @param mixed[] $parameters Parameters to remove the device (device_id, basically)
 * @return boolean Whether the device was removed or not
 */
function guifi_api_device_remove($gapi, $parameters)
{
    if (!guifi_api_check_fields($gapi, array('device_id'), $parameters)) {
        return FALSE;
    }
    global $user;
    $device = guifi_device_load($parameters['device_id']);
    if (!$device['id']) {
        $gapi->addError(500, "device_id = {$parameters['device_id']}");
        return FALSE;
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_delete()');
    $to_mail = explode(',', $device['notification']);
    $log = _guifi_db_delete('guifi_devices', array('id' => $device['id']), $to_mail);
    drupal_set_message($log);
    $subject = t('The device %name has been DELETED by %user.', array('%name' => $device['nick'], '%user' => $user->name));
    guifi_notify($to_mail, $subject, $log, $verbose, $notify);
    guifi_node_set_flag($device['nid']);
    return TRUE;
}
function guifi_device_links_print($device, $ltype = '%')
{
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_links_print(%s)', $ltype), $device);
    $oGC = new GeoCalc();
    $dtotal = 0;
    $ltotal = 0;
    if ($ltype == '%') {
        $title = t('network information');
    } else {
        $title = t('network information') . ' (' . $ltype . ')';
    }
    $rows_wds = array();
    $rows_ap_client = array();
    $rows_cable = array();
    $loc1 = db_fetch_object(db_query('SELECT lat, lon, nick ' . 'FROM {guifi_location} WHERE id=%d', $device['nid']));
    $curr_radio = 0;
    switch ($ltype) {
        case '%':
        case 'wds':
        case 'ap/client':
            $dname_curr = '';
            if ($device['radios']) {
                foreach ($device['radios'] as $radio_id => $radio) {
                    if ($radio['interfaces']) {
                        foreach ($radio['interfaces'] as $interface_id => $interface) {
                            if ($interface['ipv4']) {
                                foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                                    if ($ipv4['links']) {
                                        foreach ($ipv4['links'] as $link_id => $link) {
                                            guifi_log(GUIFILOG_TRACE, 'going to list link', $link);
                                            $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid']));
                                            $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3);
                                            $dAz = round($oGC->GCAzimuth($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon));
                                            // Calculo orientacio
                                            if ($dAz < 23) {
                                                $dOr = t("N");
                                            } else {
                                                if ($dAz < 68) {
                                                    $dOr = t("NE");
                                                } else {
                                                    if ($dAz < 113) {
                                                        $dOr = t("E");
                                                    } else {
                                                        if ($dAz < 158) {
                                                            $dOr = t("SE");
                                                        } else {
                                                            if ($dAz < 203) {
                                                                $dOr = t("S");
                                                            } else {
                                                                if ($dAz < 248) {
                                                                    $dOr = t("SW");
                                                                } else {
                                                                    if ($dAz < 293) {
                                                                        $dOr = t("W");
                                                                    } else {
                                                                        if ($dAz < 338) {
                                                                            $dOr = t("NW");
                                                                        } else {
                                                                            $dOr = t("N");
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                            $ipdest = explode('.', $link['interface']['ipv4']['ipv4']);
                                            $status_url = guifi_cnml_availability(array('device' => $link['device_id'], 'format' => 'short'));
                                            $cr = db_fetch_object(db_query("SELECT count(*) count FROM {guifi_radios} r WHERE id=%d", $link['device_id']));
                                            if ($cr->count > 1) {
                                                $rn = db_fetch_object(db_query("SELECT ssid FROM {guifi_radios} r WHERE r.id=%d AND r.radiodev_counter=%d", $link['device_id'], $link['interface']['radiodev_counter']));
                                                $dname = guifi_get_hostname($link['device_id']) . '<br />' . $rn->ssid;
                                            } else {
                                                $dname = guifi_get_hostname($link['device_id']);
                                            }
                                            $wrow = array($dname_curr != $radio['ssid'] ? array('data' => '<strong>' . $radio['ssid'] . '</strong>', 'header') : '<small>' . $radio['ssid'] . '</small>', array('data' => $link_id, 'align' => 'right'), '<a href="' . base_path() . 'guifi/device/' . $link['device_id'] . '">' . $dname . '</a>', '<a href="' . base_path() . 'node/' . $link['nid'] . '">' . $loc2->nick . '</a>', $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $status_url, 'class' => $link['flag']), $link[routing], $gDist, $dAz . '-' . $dOr);
                                            $dname_curr = $radio['ssid'];
                                            if ($interface['interface_type'] == 'wds/p2p' or $interface['interface_class'] == 'wds/p2p') {
                                                $rows_wds[] = $wrow;
                                            }
                                            if ($link['link_type'] == 'ap/client') {
                                                $rows_ap_client[] = $wrow;
                                            }
                                            $dtotal = $dtotal + $gDist;
                                            $ltotal++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($ltype != '%') {
                break;
            }
        case 'cable':
            $iname_curr = '';
            if ($device['interfaces']) {
                foreach ($device['interfaces'] as $interface_id => $interface) {
                    if ($interface['ipv4']) {
                        foreach ($interface['ipv4'] as $ipv4_id => $ipv4) {
                            if ($ipv4['links']) {
                                foreach ($ipv4['links'] as $link_id => $link) {
                                    $loc2 = db_fetch_object(db_query('SELECT lat, lon, nick FROM {guifi_location} WHERE id=%d', $link['nid']));
                                    $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3);
                                    $item = _ipcalc($ipv4['ipv4'], $ipv4['netmask']);
                                    $ipdest = explode('.', $link['interface']['ipv4']['ipv4']);
                                    if ($gs->var['url'] != NULL) {
                                        $img_url = ' <img src=' . $gs->var['url'] . '?device=' . $link['device_id'] . '&type=availability&format=short>';
                                    } else {
                                        $img_url = NULL;
                                    }
                                    $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, array('data' => $link_id, 'align' => 'right'), l(guifi_get_hostname($link['device_id']), 'guifi/device/' . $link['device_id']), $link['interface']['interface_type'], $ipv4['ipv4'] . '/' . $item['maskbits'], '.' . $ipdest[3], array('data' => t($link['flag']) . $img_url, 'class' => $link['flag']), $link[routing]);
                                    $ltotal++;
                                    $iname_curr = $interface['interface_type'];
                                }
                            } else {
                                $rows_cable[] = array($iname_curr != $interface['interface_type'] ? $interface['interface_type'] : null, null, null, null, $ipv4['ipv4'] . '/' . $item['maskbits']);
                                $ltotal++;
                                $iname_curr = $interface['interface_type'];
                            }
                        }
                    }
                    // foreach link
                    $iname_curr = $interface['interface_type'];
                }
            }
            // foreach ipv4
            if ($ltype == 'cable') {
                break;
            }
    }
    $header_cable = array(t('interface'), array('data' => t('id'), 'align' => 'right'), t('device'), t('remote<br>interface'), t('ip address'), '&nbsp;', t('status'), t('routing'));
    $header_wireless = array_merge($header_cable, array(t('kms.'), t('az.')));
    $header_wireless[3] = t('node');
    $output = '';
    $attr = array('class' => 'list-links');
    if ($rows_ap_client) {
        $output .= theme_box('<hr>' . t('ap/client'), theme_table($header_wireless, $rows_ap_client, $attr));
    }
    if ($rows_wds) {
        $output .= theme_box('<hr>' . t('wds/p2p'), theme_table($header_wireless, $rows_wds, $attr));
    }
    if ($rows_cable) {
        $output .= theme_box('<hr>' . t('cable'), theme_table($header_cable, $rows_cable, $attr));
    }
    if ($output) {
        return '<h2>' . $title . '</h2>' . '<h3>' . t('Totals') . ': ' . $ltotal . ' ' . t('links') . ', ' . $dtotal . ' ' . t('kms.') . '</h3><br>' . $output;
    } else {
        return;
    }
}
Beispiel #23
0
function theme_guifi_node_data($node, $links = FALSE)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_node_data(node)', $node);
    /*  $zone = db_fetch_object(db_query('SELECT id, title, master, zone_mode FROM {guifi_zone} WHERE id = %d',
        $node->zone_id));*/
    $zone = db_fetch_object(db_query('SELECT id, title, master FROM {guifi_zone} WHERE id = %d', $node->zone_id));
    $rows[] = array(t('node'), $node->nid . ' ' . $node->nick, '<b>' . $node->title . '</b>');
    //  $rows[] = array(t('zone (mode)'),l($zone->title,'node/'.$zone->id).' ('.t($zone->zone_mode).')',$node->zone_description);
    $rows[] = array(t('zone'), l($zone->title, 'node/' . $zone->id), $node->zone_description);
    $rows[] = array(t('position (lat/lon)'), sprintf('<a href="http://maps.guifi.net/world.phtml?Lat=%f&Lon=%f&Layers=all" target="_blank">Lat:%f<br />Lon:%f</a>', $node->lat, $node->lon, $node->lat, $node->lon), $node->elevation . '&nbsp;' . t('meters above the ground'));
    $rows[] = array(t('available for mesh &#038; status'), $node->stable, array('data' => t($node->status_flag), 'class' => $node->status_flag));
    if (count($node->funders)) {
        $rows[] = array(count($node->funders) == 1 ? t('Funder') : t('Funders'), array('data' => implode(', ', guifi_funders_links($node->funders)), 'colspan' => 2));
    }
    if (count($node->maintainers)) {
        $rows[] = array(t('Maintenance & SLAs'), array('data' => implode(', ', guifi_maintainers_links($node->maintainers)), 'colspan' => 2));
    } else {
        $radios = db_fetch_object(db_query('SELECT count(id) c FROM {guifi_radios} WHERE nid=%d', $node->id));
        if ($radios->c > 1) {
            $pmaintainers = guifi_maintainers_parents($node->zone_id);
            if (!empty($pmaintainers)) {
                $rows[] = array(t('Maintenance & SLAs') . ' ' . t('(from parents)'), implode(', ', guifi_maintainers_links($pmaintainers)));
            }
        }
    }
    if ($node->graph_server > 0) {
        $gs = node_load(array('nid' => $node->graph_server));
    } else {
        $gs = node_load(array('nid' => guifi_graphs_get_server($node->id, 'node')));
    }
    $rows[] = array(t('graphs provided from'), array('data' => l(guifi_service_str($node->graph_server), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2));
    $output = theme('table', NULL, array_merge($rows));
    $output .= theme_guifi_contacts($node);
    if ($links) {
        $node = node_load(array('nid' => $node->id));
        drupal_set_title(t('%node data', 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 theme('box', NULL, $output);
}
Beispiel #24
0
function budgets_quote_list($params = NULL)
{
    guifi_log(GUIFILOG_TRACE, 'quote_list (params)', $params);
    $output = drupal_get_form('budgets_quote_list_filter', $params);
    if (!empty($params)) {
        $vs = explode('-', $params);
        if (count($vs) > 1 and is_numeric($vs[0])) {
            $where = ' q.id = ' . $vs[0];
        } else {
            $strings = str_word_count(strtoupper(arg(4)), 1, '0123456789ÀÁÈÉÍÓÒÚÑÇÏÄËÜ');
            foreach ($strings as $k => $v) {
                $strings[$k] = '(CONCAT(upper(s.title), " ",q.id, "-", q.partno, ", ", upper(q.title)) LIKE "%' . $v . '%") ';
            }
            $where = implode(' AND ', $strings);
        }
    } else {
        $where = ' 1=1 ';
    }
    $qsql = 'SELECT q.id ' . 'FROM {supplier} s, {supplier_quote} q ' . 'WHERE q.supplier_id=s.id AND ' . $where . ' ORDER BY q.title, q.partno, q.id';
    guifi_log(GUIFILOG_TRACE, 'quote_list (query)', $qsql);
    $qquotes = pager_query($qsql, variable_get('default_nodes_main', 10));
    if (!$teaser) {
        $output .= '<br<br><hr><h2>' . t('Quotes from') . ': <em>' . $supplier->title . '</em></h2>';
        $q = 0;
        while ($quote = db_fetch_object($qquotes)) {
            guifi_log(GUIFILOG_TRACE, 'quote_list (supplier)', $quote);
            $output .= node_view(node_load(array('nid' => $quote->id)), TRUE, FALSE);
            $q++;
        }
        $q == 0 ? $output .= t('No quotes available') : NULL;
        $node->content['quotes'] = array('#value' => $output . theme('pager', NULL, variable_get('default_nodes_main', 10)), '#weight' => 1);
    }
    $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
    //drupal_set_breadcrumb(guifi_zone_ariadna($zone->id,'node/%d/view/suppliers'));
    print theme('page', $output, FALSE);
    return;
}
function guifi_host_delete_submit($form, &$form_state)
{
    guifi_log(GUIFILOG_TRACE, "function guifi_host_delete_submit()", $form_state['clicked_button]']);
    $host_id = $form_state['clicked_button']['#parents'][1];
    $form_state['values']['hosts'][$host_id]['deleted'] = TRUE;
    $form_state['values']['hosts'][$host_id]['unfold'] = TRUE;
    drupal_set_message(t('Hostname <strong>%hostname</strong> has been deleted.', array('%hostname' => $form_state['values']['hosts'][$host_id]['host'])));
    $form_state['rebuild'] = TRUE;
    return;
}
function guifi_maintainers_parents($zid, $ret = 'maintainer')
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers(parent maintainers)', $pmaintainers);
    $m = array();
    $parent = $zid;
    while ($parent > 0 and empty($m)) {
        $result = db_query('
      SELECT z.master master
      FROM {guifi_zone} z
      WHERE z.id = %d', $parent);
        $row = db_fetch_object($result);
        $parent = $row->master;
        if ($parent) {
            $m = guifi_maintainers_load($parent, 'zone', $ret);
        }
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_maintainers(loaded parent maintainers)', $m);
    return $m;
}
Beispiel #27
0
function budgets_supplier_sla($supplier, $type, $pager = 50)
{
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (supplier)', $type);
    if ($type != 'all') {
        $swt = ' AND subject_type = "' . $type . '" ';
    }
    $qquery = 'SELECT * ' . 'FROM {guifi_maintainers} ' . 'WHERE supplier_id=' . $supplier->id . ' ' . $swt . 'ORDER BY timestamp_created desc ';
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (budgets query)', $qquery);
    $pager = pager_query($qquery, variable_get('default_nodes_main', $pager));
    $output = '';
    $rows = array();
    while ($s = db_fetch_object($pager)) {
        guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (row)', $s);
        switch ($s->subject_type) {
            case 'location':
                $n = guifi_get_nodename($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'zone':
                $n = guifi_get_zone_name($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'device':
                $n = guifi_get_devicename($s->subject_id);
                $l = 'guifi/device/' . $s->subject_id . '/view';
                break;
        }
        if ($type == 'all') {
            $n .= ' (' . t($s->subject_type) . ')';
        }
        $u = user_load($s->user_created);
        $rows[] = array(l($s->subject_id . '-' . $n, $l), $s->commitment, $s->sla, $s->sla_resp, $s->sla_fix, l(t('by') . ' ' . $u->name, 'user/' . $s->user_created), format_date($s->timestamp_created));
    }
    if (count($rows) == 0) {
        $rows[] = array(array('data' => t('none'), 'colspan' => 8));
    }
    $header = array(t($type), t('type'), t('SLA'), t('resp.'), t('fix.'), t('created'), null);
    $output = theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager);
    print theme('page', $output, FALSE);
    return;
}
function guifi_radio_add_wds_submit(&$form, &$form_state)
{
    $radio_id = $form_state['clicked_button']['#parents'][1];
    $interface_id = $form_state['clicked_button']['#parents'][3];
    guifi_log(GUIFILOG_TRACE, sprintf("function guifi_radio_add_wds(Radio: %d, Interface: %d)", $radio_id, $interface_id), $form_state['clicked_button']['#parents']);
    $form_state['rebuild'] = TRUE;
    $form_state['action'] = 'guifi_radio_add_wds_form';
    // get list of the current used ips
    $ips_allocated = guifi_ipcalc_get_ips('0.0.0.0', '0.0.0.0', $form_state['values'], 2);
    $newif = _guifi_radio_add_wds_get_new_interface($form_state['values']['nid'], $ips_allocated);
    if ($newif == -1) {
        drupal_set_message(t('Unable to create link, no networks available'), 'warning');
        return FALSE;
    }
    // Initialize filters
    $form_state['filters'] = array('dmin' => 0, 'dmax' => 15, 'search' => NULL, 'type' => 'wds', 'mode' => $form_state['values']['radios'][$radio_id]['mode'], 'from_node' => $form_state['values']['nid'], 'from_device' => $form_state['values']['id'], 'from_radio' => $radio_id, 'azimuth' => "0,360");
    $form_state['newInterface'][$interface_id]['ipv4'][] = $newif;
    return TRUE;
}
Beispiel #29
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;
 }