function guifi_device_print_interfaces($device) { if (empty($device['interfaces'])) { return NULL; } $rows = array(); $inamestr = ''; $fo_connectors = guifi_types('fo_port'); foreach ($device['interfaces'] as $inum => $if) { $ipstr = ''; $rows_if = array(); guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_print_interfaces(interface %s)', $if['id']), $if); $connto_dev = array('data' => ''); if ($if['connto_did']) { $connto_dev['data'] = guifi_get_devicename($if['connto_did']); if ($if['connto_did']) { $rdev = db_fetch_object(db_query('SELECT interface_type FROM {guifi_interfaces} WHERE device_id=%d AND id=%d', $if['connto_did'], $if['connto_iid'])); $connto_dev['data'] .= ' / ' . $rdev->interface_type; } } if (!empty($connto_dev['data'])) { $connto_dev['data'] = l($connto_dev['data'], 'guifi/device/' . $if['connto_did']); } else { $connto_dev['class'] = 'available'; } if ($if['ipv4']) { foreach ($if['ipv4'] as $ipnum => $ipv4) { guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_print_interfaces(ip %s)', $ipv4['ipv4']), $ipv4); if ($ipv4['ipv4']) { $ip = _ipcalc($ipv4['ipv4'], $ipv4['netmask']); $ipstr = $ipv4['ipv4'] . '/' . $ip['maskbits']; } else { $ipstr = t('n/a'); } $rows_if[] = array($ipstr, $ipv4['netmask']); } } else { $rows_if[] = array(null, null); } $rspan = count($rows_if); if (empty($if['connector_type'])) { $if['connector_type'] = t('RJ45'); } if ($if['connector_type'] != t('RJ45')) { $if['connector_type'] = $fo_connectors[$if['connector_type']]; } $begin = array(array('data' => $if['interface_type']), array('data' => $connto_dev['data'], 'class' => $connto_dev['class']), array('data' => $if['connector_type']), array('data' => $if['comments']), array('data' => $if['mac'])); foreach ($begin as $i => $r) { $begin[$i] = array_merge($r, array('rowspan' => $rspan, 'valign' => 'top')); } foreach ($rows_if as $i => $row) { if ($i == 0) { $rows[] = array_merge($begin, $row); } else { $rows[] = $row; } } } return $rows; }
/** * @file guifi_interfaces.inc.php */ function guifi_interfaces_form(&$interface, $ptree) { global $hotspot; $cable = FALSE; guifi_log(GUIFILOG_TRACE, 'function guifi_interfaces_form()', $interface); $key = $ptree[count($ptree) - 1]; // Interface type shoudn't be NULL if ($interface['interface_type'] == NULL) { return; } $it = $interface['interface_type']; if ($it == 'Wan') { $interface['unfold'] = TRUE; $msg = t('Connection to AP'); } else { $msg = $it; } $f = array('#type' => 'fieldset', '#title' => $msg, '#collapsible' => TRUE, '#collapsed' => !isset($interface['unfold']), '#description' => t('Go to Port connections section to rename interfaces or edit physical links'), '#attributes' => array('class' => 'fieldset-interface-port')); $f['interface'] = guifi_form_hidden_var($interface, array('id', 'interface_type', 'radiodev_counter'), $ptree); // Cable interface buttons if ($ptree[0] == 'interfaces' and !$interface['deleted']) { $cable = TRUE; $f['interface']['niid'] = array('#type' => 'textfield', '#title' => t('Name'), '#parents' => array_merge($ptree, array('interface_type')), '#disabled' => true, '#size' => 10, '#maxlength' => 60, '#value' => $interface['interface_type'], '#attributes' => array('class' => 'interface-item')); if (!empty($interface['connto_did'])) { $dname = guifi_get_devicename($interface['connto_did']); $dinterfaces = guifi_get_device_interfaces($interface['connto_did'], $interface['connto_iid']); $f['interface']['dname'] = array('#type' => 'textfield', '#title' => t('Connects to'), '#disabled' => true, '#size' => 40, '#maxsize' => 256, '#value' => $interface['connto_iid'] ? $dname . ' / ' . $dinterfaces[$interface['connto_iid']] : $dname, '#attributes' => array('class' => 'interface-item')); } if (!$interface['new']) { $f['interface']['AddPublicSubnetMask'] = array('#type' => 'hidden', '#value' => '255.255.255.224', '#parents' => array_merge($ptree, array('AddPublicSubnetMask')), '#prefix' => '<div> </div><div id="editInterface-' . $key . '">', '#suffix' => '</div>'); $f['interface']['AddCableLink'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/addprivatecablelink.png', '#parents' => array_merge($ptree, array('AddCableLink')), '#attributes' => array('title' => t('Link to another device at the node using a private network')), '#ahah' => array('path' => 'guifi/js/add-cable-link/' . $key, 'wrapper' => 'editInterface-' . $key, 'method' => 'replace', 'effect' => 'fade')); $f['interface']['AddPublicSubnet'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/insertwlan.png', '#parents' => array_merge($ptree, array('AddPublicSubnet')), '#attributes' => array('title' => t('Allocate a Public Subnetwork to the interface')), '#ahah' => array('path' => 'guifi/js/add-subnet-mask/' . $key, 'wrapper' => 'editInterface-' . $key, 'method' => 'replace', 'effect' => 'fade')); } else { $f['interface']['msg'] = array('#type' => 'item', '#title' => t('New interface'), '#description' => t('Save to database to add links or allocate subnetworks')); $f['interface']['itype']['#disabled'] = false; } } // wds/p2p link, allow to create new links if ($it == 'wds/p2p' || $interface['interface_class'] == 'wds/p2p') { $f['interface']['AddWDS'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/wdsp2p.png', '#parents' => array_merge($ptree, array('AddWDS', $ptree[1], $ptree[2])), '#attributes' => array('title' => t('Add WDS/P2P link to extend the backbone')), '#submit' => array('guifi_radio_add_wds_submit')); } if ($interface['deleted']) { $f['interface']['deleteMsg'] = array('#type' => 'item', '#value' => t('Deleted'), '#description' => guifi_device_item_delete_msg('This interface has been deleted, ' . 'related addresses and links will be also deleted')); } else { if ($it != 'wds/p2p' and $interface['interface_class'] != 'wds/p2p' and $it != 'wLan/Lan' and $it != 'Wan') { $f['interface']['deleteInterface'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#parents' => array_merge($ptree, array('deleteInterface')), '#attributes' => array('title' => t('Delete interface')), '#submit' => array('guifi_interfaces_delete_submit')); } } $ipv4Count = 0; if (count($interface['ipv4']) > 0) { foreach ($interface['ipv4'] as $ka => $ipv4) { if (!$ipv4['deleted']) { $ipv4Count++; } $f['ipv4'][$ka] = guifi_device_ipv4_link_form($ipv4, array_merge($ptree, array('ipv4', $ka)), $cable); } } // foreach ipv4 // Mode Client or client-routed, allow to link to AP if ($it == 'Wan' and $ipv4Count == 0) { $f['interface']['Link2AP'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/link2ap.png', '#parents' => array('Link2AP', $ptree[1], $interface['id']), '#attributes' => array('title' => t('Create a simple (ap/client) link to an Access Point')), '#submit' => array('guifi_radio_add_link2ap_submit')); } if ($it != 'HotSpot') { $f['#title'] .= ' - ' . $ipv4Count . ' ' . t('address(es)'); } else { $hotspot = TRUE; } return $f; }
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; }
/** * @param array containing editing device information $edit * @param weight form ewlements $form_weight */ function guifi_ports_form($edit, &$form_weight) { global $user; guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form()', $edit); // Select device model from model_specs if (!empty($edit['mid'])) { $querymid = db_query("\n SELECT mid, model, etherdev_max, optoports_max, m.opto_interfaces, f.name manufacturer\n FROM guifi_model_specs m, guifi_manufacturer f\n WHERE f.fid = m.fid\n AND m.mid = " . $edit['mid']); $swmodel = db_fetch_object($querymid); } switch ($edit['type']) { case 'switch': $fs_title = t('Switch ports & connections'); $swtype = true; break; default: $fs_title = t('Physical ports & connections'); $swtype = false; } // Build port fieldset $form = array('#type' => 'fieldset', '#title' => t('Ports'), '#collapsible' => TRUE, '#tree' => TRUE, '#collapsed' => FALSE, '#weight' => $form_weight++, '#prefix' => '<br><img src="/' . drupal_get_path('module', 'guifi') . '/icons/ports-16.png"> ' . t('%title section', array('%title' => $fs_title))); guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form()', $swmodel); $opto_interfaces = explode('|', $swmodel->opto_interfaces); guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form(opto_interfaces)', $opto_interfaces); // if no switch model selected / unknown number of ports, ask for save if (empty($swmodel->etherdev_max) and empty($edit['mid'])) { $form['msg'] = array('#type' => 'item', '#value' => t('Number of ports is still unknown. Select a model above and save & continue edit to populate ports.'), '#weight' => $form_weight++); } $connector_types = array('RJ45' => str_pad(t('RJ45 Cooper'), $type_length, '-')); if ($swmodel->opto_interfaces) { $connector_types = array_merge($connector_types, guifi_types('fo_port')); } // Loop across all existing interfaces $port_count = 0; $total_ports = count($edit['interfaces']); $first_port = true; $eCountOpts = array(); for ($i = 0; $i < $total_ports; $i++) { $eCountOpts[$i] = $i; } $m = guifi_get_model_specs($edit[variable][model_id]); guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form(m)', $m); foreach ($edit['interfaces'] as $port => $interface) { guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form(interface)', $interface); // Skip ports: // -with no interface type // -with related interfaces // -no interface_class but 'wLan/Lan' (v1 schema) if (empty($interface['interface_type']) or !empty($interface[related_interfaces]) or empty($interface[interface_class]) and $interface[interface_type] == 'wLan/Lan') { guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form(interface)', $interface); continue; } $prefix = ''; $suffix = ''; $port_count++; $form[$port] = array('#type' => 'fieldset', '#attributes' => array('class' => 'fieldset-interface-port'), '#prefix' => '<div id="fieldset-port-' . $port . '">', '#suffix' => '</div>', '#tree' => TRUE); $form[$port]['etherdev_counter'] = array('#tree' => TRUE, '#type' => 'select', '#title' => $first_port ? t('#') : false, '#options' => $eCountOpts, '#default_value' => $port_count - 1, '#attributes' => array('class' => 'interface-item'), '#weight' => $form_weight++); $form[$port]['interface_type'] = array('#tree' => TRUE, '#type' => 'textfield', '#title' => $first_port ? t('name') : false, '#default_value' => $interface['deleted'] ? t('deleted') . ' - ' . $interface['interface_type'] : $interface['interface_type'], '#size' => in_array($edit['type'], array('switch')) ? 10 : 20, '#size' => 10, '#maxlength' => 40, '#disabled' => $interface['deleted'] or in_array($edit['type'], array('switch')) ? TRUE : FALSE, '#attributes' => array('class' => 'interface-item'), '#weight' => $form_weight++); if ($form[$port]['interface_type']['#disabled'] == true) { $form[$port]['interface_type']['#value'] = $interface['interface_type']; $form[$port]['interface_type']['#attributes'] = array('class' => 'interface-item-disabled'); if (empty($interface['deleted'])) { $form[$port]['iname'] = array('#tree' => true, '#type' => 'hidden', '#value' => $interface['interface_type']); } } guifi_log(GUIFILOG_TRACE, 'function guifi_ports_form(type)', $interface); $form[$port]['connector_type'] = array('#tree' => TRUE, '#type' => 'select', '#title' => $first_port ? t('connector') : false, '#options' => $connector_types, '#disabled' => in_array($interface['interface_type'], $opto_interfaces) ? false : true, '#default_value' => $interface['connector_type'], '#attributes' => in_array($interface['interface_type'], $opto_interfaces) ? array('class' => 'interface-item') : array('class' => 'interface-item-disabled'), '#weight' => $form_weight++); if (!empty($interface['connto_did'])) { $dname = guifi_get_devicename($interface['connto_did']); $dinterfaces = guifi_get_device_interfaces($interface['connto_did'], $interface['connto_iid']); } else { $dname = ''; } $form[$port]['dname'] = array('#type' => 'textfield', '#tree' => TRUE, '#title' => $first_port ? t('connects to') : false, '#disabled' => true, '#size' => 30, '#maxsize' => 256, '#value' => $interface['connto_iid'] ? $dname . ' / ' . $dinterfaces[$interface['connto_iid']] : $dname, '#attributes' => empty($dname) ? array('class' => 'interface-item-available') : array('class' => 'interface-item-disabled'), '#weight' => $form_weight++); if (!$interface[deleted]) { $form[$port]['addLink'] = array('#type' => 'image_button', '#src' => $interface['deleted'] ? drupal_get_path('module', 'guifi') . '/icons/drop.png' : drupal_get_path('module', 'guifi') . '/icons/edit.png', '#attributes' => array('title' => t('Edit dialog for connecting to another device'), 'class' => 'interface-item.form-button'), '#ahah' => array('path' => 'guifi/js/edit_cableconn/' . $port, 'wrapper' => 'interface-cableconn-' . $port, 'method' => 'replace', 'effect' => 'fade'), '#prefix' => $first_port ? '<div class="form-item"><div> </div>' : '<div class="form-item">', '#suffix' => '</div>', '#weight' => $form_weight++); /* If onclick is wanted to edit, uncomment this $form[$port]['dname']['#disabled'] = false; $form[$port]['dname']['#ahah'] = array( 'event' => 'mousedown', 'path' => 'guifi/js/edit_cableconn/'.$port, 'wrapper' => 'interface-cableconn-'.$port, 'method' => 'replace', 'effect' => 'fade', ); */ } $form[$port]['vlan'] = array('#tree' => TRUE, '#type' => 'textfield', '#type' => in_array($edit['type'], array('switch')) ? 'hidden' : 'textfield', '#type' => 'hidden', '#title' => $first_port ? t('vlan') : false, '#size' => 6, '#maxlength' => 10, '#default_value' => $interface['vlan'], '#attributes' => array('class' => 'interface-item'), '#weight' => $form_weight++); $form[$port]['comments'] = array('#tree' => TRUE, '#type' => 'textfield', '#title' => $first_port ? t('comments') : false, '#size' => 40, '#maxlength' => 60, '#default_value' => $interface['comments'], '#attributes' => array('class' => 'interface-item'), '#weight' => $form_weight++); if ($interface[deleted]) { $form[$port]['comments']['#value'] = t('will be deleted. press "reset" to cancel'); $form[$port]['comments']['#disabled'] = true; } if (!$interface[deleted]) { $form[$port]['mac'] = array('#type' => 'textfield', '#title' => $first_port ? t('mac') : false, '#required' => FALSE, '#size' => 20, '#maxlength' => 17, '#default_value' => $interface['mac'], '#element_validate' => array('guifi_mac_validate'), '#weight' => $form_weight++); } if (!$interface[deleted] and !($port_count <= $m->ethermax)) { $form[$port]['delete'] = array('#type' => 'image_button', '#title' => $first_port ? t('delete') : false, '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#attributes' => array('title' => t('Delete interface' . $m->ethermax . '-' . $port_count)), '#submit' => array('guifi_vinterfaces_delete_submit'), '#prefix' => $first_port ? '<div class="form-item"><label> </label>' : false, '#suffix' => $first_port ? '</div>' : false); } $form[$port]['conn'] = array('#type' => 'hidden', '#prefix' => '<div id="interface-cableconn-' . $port . '">', '#suffix' => '</div>', '#weight' => $form_weight++); $form[$port]['conn']['did'] = array('#type' => 'textfield', '#parents' => array('interfaces', $port, 'did'), '#value' => guifi_get_devicename($interface['connto_did'], 'large'), '#autocomplete_path' => 'guifi/js/select-node-device', '#size' => 60, '#maxlength' => 128, '#element_validate' => array('guifi_devicename_validate'), '#attributes' => array('class' => 'interface-item'), '#ahah' => array('path' => 'guifi/js/select-device-interface/' . $port, 'wrapper' => 'fieldset-port-' . $port, 'method' => 'replace', 'effect' => 'fade')); $form[$port]['conn']['if'] = array('#parents' => array('interfaces', $port, 'if'), '#type' => 'select', '#value' => $interface['connto_iid'], '#attributes' => array('class' => 'interface-item'), '#options' => $dinterfaces, '#ahah' => array('path' => 'guifi/js/select-device-interface/' . $port, 'wrapper' => 'fieldset-port-' . $port, 'method' => 'replace', 'effect' => 'fade')); // Hidden fields $form[$port]['id'] = array('#type' => 'hidden', '#value' => $interface['id'], '#weight' => $form_weight++); $form[$port]['device_id'] = array('#type' => 'hidden', '#value' => $interface['device_id'], '#weight' => $form_weight++); $form[$port]['connto_did'] = array('#type' => 'hidden', '#value' => $interface['connto_did'], '#weight' => $form_weight++); $form[$port]['connto_iid'] = array('#type' => 'hidden', '#value' => $interface['connto_iid'], '#weight' => $form_weight++); if ($interface['deleted']) { $form[$port]['deleted'] = array('#type' => 'hidden', '#value' => $interface['deleted'], '#weight' => $form_weight++); } if ($interface['new']) { $form[$port]['new'] = array('#type' => 'hidden', '#value' => $interface['new'], '#weight' => $form_weight++); } $first_port = false; } return $form; }
/** * Edit cable connection * * URL: http://guifi.net/guifi/js/edit-cableconn/% */ function guifi_ahah_edit_cableconn() { $cid = 'form_' . $_POST['form_build_id']; $cache = cache_get($cid, 'cache_form'); $port = arg(3); $interface = $_POST['interfaces'][$port]; $tree = array('interfaces', $port); $dname = guifi_get_devicename($interface['connto_did'], 'large'); guifi_log(GUIFILOG_TRACE, sprintf('guifi_ahah_edit_cableconn (port=%d did) interface:', $port), $interface); $device_interfaces = guifi_get_device_interfaces($interface['connto_did'], $interface['connto_iid']); // guifi_log(GUIFILOG_FILE,sprintf('guifi_ahah_edit_cableconn (port=%d did) device interfaces:',$port),$device_interfaces); $form_weight = -10000; if ($cache) { $form = $cache->data; $form['interfaces'][$port]['conn']['#type'] = 'fieldset'; $form['interfaces'][$port]['conn']['#attributes'] = array('class' => 'fieldset-interface-connection'); $form['interfaces'][$port]['conn']['#description'] = t('Links to device & interface'); $form['interfaces'][$port]['conn']['#collapsible'] = FALSE; $form['interfaces'][$port]['conn']['#tree'] = FALSE; $form['interfaces'][$port]['conn']['#collapsed'] = FALSE; unset($form['interfaces'][$port]['conn']['did']['#value']); $form['interfaces'][$port]['conn']['did']['#value'] = $interface['deleted'] ? '' : $dname; $form['interfaces'][$port]['conn']['did']['#type'] = 'textfield'; $form['interfaces'][$port]['conn']['if']['#options'] = $device_interfaces; $form['interfaces'][$port]['conn']['if']['#value'] = $interface['connto_iid']; guifi_log(GUIFILOG_TRACE, sprintf('guifi_ahah_edit_cableconn (port=%d did) FORM:', $conn), $form['interfaces'][$port]['conn']); cache_set($cid, $form, 'cache_form', $cache->expire); // Build and render the new select element, then return it in JSON format. $form_state = array(); // $form['#post'] = array(); $form['#post'] = $_POST; $form = form_builder($form['form_id']['#value'], $form, $form_state); $output = drupal_render($form['interfaces'][$port]['conn']); drupal_json(array('status' => TRUE, 'data' => $output)); } else { drupal_json(array('status' => FALSE, 'data' => '')); } exit; }
function guifi_ipv4subnet_form($ipv4, $k, $view = false) { define('MAXNIPS', 12); guifi_log(GUIFILOG_TRACE, sprintf('guifi_ipv4subnet_form (id=%d)', $k), $ipv4); $ipc = _ipcalc($ipv4[ipv4], $ipv4[netmask]); if (!empty($ipv4[subnet])) { $subnet = $ipv4[subnet]; } else { $subnet = $ipv4[snet]; } guifi_log(GUIFILOG_FULL, sprintf('guifi_ipv4subnet_form (id=%d)', $k), $subnet); $ips = array(ip2long($ipv4[ipv4])); foreach ($subnet as $ki => $ip) { if (empty($ip[ipv4]) and !empty($ip[ipv4value])) { $subnet[$ki][ipv4] = $ip[ipv4value]; } if (ip2long($ip[ipv4])) { $ips[] = ip2long($ip[ipv4]); } } sort($ips); $form = array('#type' => !$view ? 'hidden' : 'fieldset', '#type' => 'fieldset', '#title' => t('Subnet') . ' ' . $ipc['netid'] . '/' . $ipc['maskbits'] . ' - ' . count($ips) . ' address(es)', '#prefix' => '<div class="ipv4-subnet" id="fieldset-ipv4subnet-' . $k . '">', '#suffix' => '</div>', '#collapsible' => true, '#collapsed' => $view ? false : true); // foreach ($subnet as $ks => $snet) { $nIps = 0; $newIps = 0; for ($ks = 0; $ks < $ipc['hosts']; $ks++) { $snet = $subnet[$ks]; $form[$ks] = array('#type' => !empty($snet[ipv4]) ? 'fieldset' : 'hidden', '#attributes' => array('class' => 'fieldset-interface-port'), '#prefix' => '<div id="fieldset-ipv4subnet-' . $k . '-' . $ks . '">', '#suffix' => '</div>'); $form[$ks][ipv4value] = array('#type' => 'hidden', '#value' => $snet[ipv4]); if (isset($snet['id'])) { $form[$ks]['id'] = array('#type' => 'hidden', '#value' => $snet['id']); } if (isset($snet[interface_id])) { $form[$ks][interface_id] = array('#type' => 'hidden', '#value' => $snet[interface_id]); } $form[$ks][ipv4] = array('#type' => 'textfield', '#default_value' => $snet[ipv4], '#size' => 24, '#maxlength' => 16); if ($snet['new']) { $form[$ks][ipv4]['#type'] = 'hidden'; $form[$ks][ipv4]['#value'] = $snet[ipv4]; $form[$ks][ipv4txt] = array('#type' => 'textfield', '#value' => $snet[ipv4], '#disabled' => true, '#size' => 24); $newIps++; $form[$ks]['new'] = array('#type' => 'hidden', '#value' => true); } $form[$ks][did] = array('#type' => ($view and !empty($snet[ipv4])) ? 'textfield' : 'hidden', '#type' => 'textfield', '#default_value' => guifi_get_devicename($snet['did'], 'large'), '#autocomplete_path' => 'guifi/js/select-node-device', '#size' => 60, '#maxlength' => 128, '#element_validate' => array('guifi_devicename_validate'), '#ahah' => array('event' => 'blur', 'path' => 'guifi/js/select-device-interfacename/' . $k . '-' . $ks, 'wrapper' => 'fieldset-ipv4subnet-' . $k . '-' . $ks, 'method' => 'replace', 'effect' => 'fade')); // if (!empty($snet['ipv4'])) { $dinterfaces = guifi_get_device_allinterfaces($snet['did']); $form[$ks]['iid'] = array('#type' => 'select', '#value' => $snet['iid'], '#required' => true, '#options' => $dinterfaces); // } if (!($snet['deleted'] == true)) { $form[$ks]['deleted'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/drop.png', '#attributes' => array('title' => t('Delete address')), '#ahah' => array('path' => 'guifi/js/delete-ipv4/' . $k . '-' . $ks, 'wrapper' => 'fieldset-ipv4subnet-' . $k . '-' . $ks, 'method' => 'replace', 'effect' => 'fade')); } else { $form[$ks][deleted] = array('#type' => 'hidden', '#value' => true); $form[$ks][ipv4]['#type'] = 'hidden'; $form[$ks][ipv4]['#value'] = $snet[ipv4]; $form[$ks][did]['#type'] = 'hidden'; $form[$ks][iid]['#type'] = 'hidden'; $form[$ks][deletedmsg] = array('#type' => 'item', '#value' => t('Address %addr will be DELETED', array('%addr' => $snet[ipv4]))); } // force save if new addresses at the in-memory form is too high if (empty($snet['ipv4'])) { $nIps++; } if ($nIps >= MAXNIPS) { break; } } if (count($ips) < $ipc['hosts']) { if ($newIps < MAXNIPS) { $form['add-ipv4'] = array('#type' => 'image_button', '#title' => $first_port ? t('Add') : false, '#src' => drupal_get_path('module', 'guifi') . '/icons/ipv4-new.png', '#attributes' => array('title' => t('Add new ipv4 address to the subnetwork')), '#weight' => 100, '#ahah' => array('path' => 'guifi/js/add-remoteipv4/' . $k, 'wrapper' => 'fieldset-ipv4subnet-' . $k, 'method' => 'replace', 'effect' => 'fade')); } else { $form['add-ipv4'] = array('#type' => 'item', '#title' => $first_port ? t('Add') : false, '#value' => t('To many new addresses added. Is not safe to add more values, please confirm or discard changes'), '#weight' => 100); } } return $form; }
function guifi_traceroute_dataexport($route, $nRoute, &$linkslist, &$nodeslist) { $oGC = new GeoCalc(); $tDist = 0; $nLink = 0; $nReg = 0; $output = ''; foreach ($route as $did => $hop) { if (isset($hop['to'])) { $linkslist[$nReg]['todevicename'] = guifi_get_devicename($did, 'nick'); $linkslist[$nReg]['todevicelink'] = 'guifi/device/' . $did; $linkslist[$nReg]['tonode'] = $hop['to'][0]; $ip = db_fetch_object(db_query('SELECT ipv4, netmask FROM {guifi_ipv4} WHERE id=%d AND interface_id=%d', $hop['to'][2], $hop['to'][1])); $linkslist[$nReg]['toipv4'] = $ip->ipv4 . '/' . guifi_ipcalc_get_maskbits($ip->netmask); if (!isset($nodeslist[$hop['to'][0]])) { $nodeslist[$hop["to"][0]] = guifi_get_location($hop["to"][0]); $nodeslist[$hop["to"][0]][nodename] = guifi_get_nodename($hop['to'][0]); $nodeslist[$hop["to"][0]][nodelink] = $hop['to'][0]; } } if (isset($hop['from'])) { $nLink++; $nReg = $nRoute * 100 + $nLink; $linkslist[$nReg]['route'] = $nRoute; $linkslist[$nReg]['nlink'] = $nLink; $linkslist[$nReg]['idlink'] = $hop['from'][0]; $linkslist[$nReg]['fromdevicename'] = guifi_get_devicename($did, 'nick'); $linkslist[$nReg]['fromdevicelink'] = 'guifi/device/' . $did; $linkslist[$nReg]['fromnode'] = $hop['from'][5]; $ip = db_fetch_object(db_query('SELECT ipv4, netmask FROM {guifi_ipv4} WHERE id=%d AND interface_id=%d', $hop['from'][4], $hop['from'][3])); $linkslist[$nReg]['fromipv4'] = $ip->ipv4 . '/' . guifi_ipcalc_get_maskbits($ip->netmask); $linkslist[$nReg]['type'] = $hop['from'][1]; $linkslist[$nReg]['status'] = $hop['from'][2]; if (!isset($nodeslist[$hop['from'][5]])) { $nodeslist[$hop["from"][5]] = guifi_get_location($hop["from"][5]); $nodeslist[$hop["from"][5]][nodename] = guifi_get_nodename($hop['from'][5]); $nodeslist[$hop["from"][5]][nodelink] = $hop['from'][5]; } } // if not same location, give the distance if ($hop['from'][1] != 'cable') { $qry = db_query('SELECT n.id nid, lat, lon FROM {guifi_location} n, {guifi_links} l WHERE l.id=%d AND l.nid=n.id', $hop['from'][0]); $loc1 = db_fetch_object($qry); $loc2 = db_fetch_object($qry); $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3); if ($gDist) { $linkslist[$nReg]['distance'] = $gDist; } } } return $output; }