/** * Load statistics form */ function guifi_admin_loadstats_form($form_state, $params = array()) { $form['zone_services']['graph_serverstr'] = array('#type' => 'textfield', '#title' => t('CNML Graph server'), '#maxlength' => 60, '#required' => FALSE, '#default_value' => guifi_service_str($params), '#autocomplete_path' => 'guifi/js/select-service/SNPgraphs', '#element_validate' => array('guifi_service_name_validate', 'guifi_zone_service_validate'), '#description' => t('CNML graph server to load statistics from. Should support remote calls in v2 syntax.')); $form['submit'] = array('#type' => 'submit', '#value' => t('Load statistics')); return $form; }
function guifi_device_print_data($device) { $radios = db_query('SELECT * FROM {guifi_radios} WHERE id=%d ORDER BY id', $device['id']); $rows[] = array(t($device[type]), '<b>' . $device[nick] . '</b>'); if (count($device['funders'])) { $rows[] = array(count($device['funders']) == 1 ? t('Funder') : t('Funders'), implode(', ', guifi_funders_links($device['funders']))); } if (count($device['maintainers'])) { $rows[] = array(t('Maintenance & SLAs'), implode(', ', guifi_maintainers_links($device['maintainers']))); } // If radio, print model & firmware if ($device['type'] == 'radio') { $rows[] = array($device[manufacturer] . '-' . $device[model], $device[variable][firmware]); // going to list all device radios if (count($device['radios'])) { foreach ($device['radios'] as $radio_id => $radio) { if ($radio['fund_required'] == '') { $policy = t('n/d, ask to node contacts'); } else { if ($radio['fund_required'] == 'yes') { $policy = t('Fund: :fund :curr', array(':fund' => $radio['fund_amount'], ':curr' => $radio['fund_currency'])); } else { $policy = t($radio['fund_required']); } } $rowsr[] = array($radio['ssid'], $radio['mode'], $radio['protocol'], $radio['channel'], $radio['mac'], t($radio['clients_accepted']), $policy); } $rows[] = array(array('data' => theme('table', array(t('ssid'), t('mode'), t('protocol'), t('ch'), t('wireless mac'), t('clients'), t('connection policy')), $rowsr), 'colspan' => 2)); } } // If ADSL, print characteristics if ($device['type'] == 'ADSL' and $device['variable'] != '') { $bandwidth = guifi_bandwidth_types(); $rows[] = array(t('bandwidth'), $bandwidth[$device['variable']['download']] . '/' . $bandwidth[$device['variable']['upload']]); $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']); } // Others with modelDescr set if (isset($device['variable']['modelDescr'])) { switch ($device['type']) { case 'ups': $vDescr = t('Power: %power', array('%power' => $device['variable']['specs'])); break; case 'generator': $vDescr = t('Max Power: %power Watts', array('%power' => $device['variable']['specs'])); break; case 'battery': $vDescr = t('Power: %power/Ah, Quantity: %quantity', array('%power' => $device['variable']['specs'], '%quantity' => $device['variable']['units'])); break; case 'rack': $vDescr = t('Height: %height Us, Width: %width inches, Depth: %depth mm', array('%height' => $device['variable']['height'], '%width' => $device['variable']['width'], '%depth' => $device['variable']['depth'])); break; case 'breaker': $vDescr = t('Protection: %cbtype, Auto-reclose: %recloser', array('%cbtype' => $device['variable']['cbtype'], '%recloser' => $device['variable']['recloser'] ? t('Yes') : t('No'))); break; } $rows[] = array($device['variable']['modelDescr'], $vDescr); } // generic if ($device['type'] == 'generic' || 'confine' and !empty($device['variable']['mrtg_index'])) { $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']); } if ($device['graph_server'] > 0) { $gs = node_load(array('nid' => $device['graph_server'])); } else { $gs = node_load(array('nid' => guifi_graphs_get_server($device['id'], 'device'))); } $rows[] = array(t('graphs provided from'), array('data' => l(guifi_service_str($device['graph_server']), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2)); $ip = guifi_main_ip($device[id]); $rows[] = array(t('IP address & MAC'), $ip[ipv4] . '/' . $ip[maskbits] . ' ' . $device[mac]); $status_url = guifi_cnml_availability(array('device' => $device['id'], 'format' => 'long'), $gs); if (!empty($ip[ipv4])) { $rows[] = array(t('status & availability'), array('data' => t($device[flag]) . $status_url, 'class' => $device['flag'])); } $rows[] = array(array('data' => theme_guifi_contacts($device), 'colspan' => 2)); return array_merge($rows); }
/** * Load statistics from remote CNML graph servers into the database * * @param $graph_server * Graph server ID. * * @param $verbose * If TRUE, it will return theme() * * @return * theme() if $verbose==TRUE */ function guifi_cron_loadCNMLstats($graph_server, $verbose = FALSE) { if (is_null($gs)) { $gs = guifi_service_load($graph_server); } if ($gs->var['version'] >= 2.0) { $handle = fopen(guifi_cnml_call_service($gs, 'stats', array()), "r"); } else { $output .= t("This graph server doesn't support v2.0 CNML calls syntax.\n"); } if ($handle) { $c = 0; $u = 0; while (!feof($handle)) { $c++; $updatestr = array(); $stat = stream_get_line($handle, 4096, "\n"); $vstats = explode('|', $stat); $device_id = array_shift($vstats); $availability_stats = array_shift($vstats); list($latmax, $latavg, $availability, $lastonline, $laststatdate, $laststattime, $lastavailability) = explode(',', $availability_stats); $tlaststat = to_date($laststatdate . $laststattime); if (!$tlaststat) { continue; } $dev = db_fetch_object(db_query('SELECT last_stats,last_online,last_flag,ly_availability ' . 'FROM {guifi_devices} ' . 'WHERE id=%d', $device_id)); if ($tlaststat <= $dev->last_stats) { continue; } $u++; $tlastonline = to_date($lastonline); if ($tlastonline > $dev->last_online) { $updatestr[] = 'last_online=' . $tlastonline; } if ($lastavailability <= 100 and $lastavailability >= 0) { if ($lastavailability == 0) { $updatestr[] = 'last_flag="Down"'; } else { $updatestr[] = 'last_flag="Up"'; } } $updatestr[] = 'last_stats=' . $tlaststat; if ($availability <= 100 and $availability >= 0) { $updatestr[] = 'ly_availability=' . $availability; } if ($latavg) { $updatestr[] = 'latency_avg=' . $latavg; } if ($latmax) { $updatestr[] = 'latency_max=' . $latmax; } // Update availability statistics db_query('UPDATE {guifi_devices} SET ' . implode(', ', $updatestr) . ' WHERE id=%d', $device_id); // Now going to update traffic statistics $nradios = db_fetch_object(db_query('SELECT count(*) count ' . 'FROM {guifi_radios} ' . 'WHERE id=%d', $device_id)); if ($nradios->count == 1) { // if just one radio, sum all values $in = 0; $out = 0; foreach ($vstats as $value) { $traffic = explode(',', $value); $in += $traffic[1]; $out += $traffic[2]; } if ($in or $out) { db_query('UPDATE {guifi_radios} ' . 'SET ly_mb_in=%d, ly_mb_out=%d ' . 'WHERE id=%d', $in, $out, $device_id); } } else { // more than one radio, give the value to each radio foreach ($vstats as $value) { db_query('UPDATE {guifi_radios} ' . 'SET ly_mb_in=%d, ly_mb_out=%d ' . 'WHERE id=%d AND radiodev_counter=%d', $traffic[1], $traffic[2], $device_id, $traffic[0]); } } $stats .= $c . ' ' . $stat . "\n"; } watchdog('guifi', 'Loaded statistics from %name, %ndevices updated', array('%name' => guifi_service_str($graph_server), '%ndevices' => $u), WATCHDOG_NOTICE); // $stats = stream_get_contents($handle); fclose($handle); $output .= '<pre>' . $stats . '</pre>'; } else { $output .= t('Get stats failed.'); } if ($verbose) { return theme('box', t("Load statistics from '%server'", array('%server' => guifi_service_str($graph_server))), $output); } }
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 . ' ' . t('meters above the ground')); $rows[] = array(t('available for mesh & 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); }
function guifi_user_form($form_state, $params = array()) { _user_password_dynamic_validation(); guifi_log(GUIFILOG_TRACE, 'function guifi_user_form()', $form_state); guifi_validate_js("#guifi-user-form"); if (empty($form_state['values'])) { if (is_numeric($params)) { $form_state['values'] = guifi_user_load($params); } else { $form_state['values'] = $params; } } if (isset($form_state['values']['id'])) { $f['id'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']); drupal_set_title(t('edit user') . ' ' . $form_state['values']['username']); } else { $f['new'] = array('#type' => 'hidden', '#value' => TRUE); drupal_set_title(t('add user') . ' @ ' . guifi_get_nodename($form_state['values']['nid'])); } $f['firstname'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 128, '#title' => t('Firstname'), '#required' => TRUE, '#attributes' => array('class' => 'required'), '#default_value' => $form_state['values']['firstname'], '#description' => t('The real user name (Firstname), ' . 'will be used while building the username.<br />' . 'If username results duplicated, add more words ' . '(i.e. middle initial).<br />' . 'Please enter real data, if fake information is entered, ' . 'administrators might <strong>remove</strong> this user.')); $f['lastname'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 128, '#title' => t('Lastname'), '#required' => TRUE, '#attributes' => array('class' => 'required'), '#default_value' => $form_state['values']['lastname'], '#description' => t('The real user name (Lastname).')); if (!empty($form_state['values']['username'])) { $f['username'] = array('#type' => 'item', '#value' => $form_state['values']['username'], '#description' => t('The resulting username.')); } if (user_access('administer guifi users')) { $f['status'] = array('#type' => 'select', '#title' => t('Status'), '#options' => guifi_types('user_status'), '#default_value' => $form_state['values']['status']); $f['node'] = array('#type' => 'textfield', '#title' => t('Node'), '#maxlength' => 60, '#default_value' => $form_state['values']['nid'] . '-' . guifi_get_zone_nick(guifi_get_zone_of_node($form_state['values']['nid'])) . ', ' . guifi_get_nodename($form_state['values']['nid']), '#autocomplete_path' => 'guifi/js/select-node', '#element_validate' => array('guifi_nodename_validate'), '#description' => t('Select the node where the user is.<br />' . 'You can find the node by introducing part of the node id number, ' . 'zone name or node name. A list with all matching values ' . 'with a maximum of 50 values will be created.<br />' . 'You can refine the text to find your choice.')); } else { $f['status'] = array('#type' => 'item', '#title' => t('Status'), '#value' => $form_state['values']['status']); $f['node'] = array('#type' => 'item', '#title' => t('Node'), '#value' => $form_state['values']['nid'] . '-' . guifi_get_zone_nick(guifi_get_zone_of_node($form_state['values']['nid'])) . ', ' . guifi_get_nodename($form_state['values']['nid'])); if (!isset($f['new'])) { $f['previous_pwd'] = array('#type' => 'password', '#title' => t('Current password'), '#description' => t('To proceed for any change, you have to ' . 'know the current password.')); } if (!isset($f['new'])) { $f['resetPwd'] = array('#type' => 'submit', '#value' => t('Reset password')); } } $f['nid'] = array('#type' => 'hidden', '#value' => $form_state['values']['nid']); $f['pass'] = array('#type' => 'password_confirm', '#required' => isset($f['new']), '#title' => t('Set a new password'), '#description' => t('To change/set the current user password, enter the new password in both fields.'), '#size' => 25); $f['notification'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 1024, '#title' => t('contact'), '#required' => TRUE, '#element_validate' => array('guifi_emails_validate'), '#default_value' => $form_state['values']['notification'], '#description' => t('Mailid where changes on this user will be notified, ' . 'if many, separated by \',\'<br />' . 'Also where the user can be contacted.')); // services $f['services'] = array('#type' => 'fieldset', '#title' => t('services'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE); if (user_access('administer guifi users')) { $f['services']['proxystr'] = array('#type' => 'textfield', '#title' => t('proxy'), '#maxlength' => 60, '#default_value' => guifi_service_str($form_state['values']['services']['proxy']), '#autocomplete_path' => 'guifi/js/select-service/proxy', '#element_validate' => array('guifi_service_name_validate', 'guifi_user_proxy_validate')); } else { $f['services']['proxystr'] = array('#type' => 'item', '#title' => t('proxy'), '#value' => guifi_service_str($form_state['values']['services']['proxy'])); } $f['services']['proxy'] = array('#type' => 'hidden', '#value' => $form_state['values']['services']['proxy']); $f['services']['filters'] = array('#type' => 'checkboxes', '#parents' => array('content_filters'), '#title' => t('content filters'), '#options' => guifi_types('filter'), '#multiple' => TRUE, '#description' => t('Content to be filtered.<br />Check the type of content ' . 'which will be filtered to this user. ' . 'Note that this filters will work only on those sites ' . 'which have enabled this feature, ' . 'so don\'t think that is safe to rely on this.')); if (!empty($form_state['values']['content_filters'])) { $f['services']['filters']['#default_value'] = $form_state['values']['content_filters']; } $f['author'] = array('#type' => 'fieldset', '#access' => user_access('administer guifi users'), '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE); $f['author']['username_created'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $form_state['values']['username_created'], '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous'))))); $f['submit'] = array('#type' => 'submit', '#value' => t('Save')); if (!isset($f['new'])) { $f['delete'] = array('#type' => 'submit', '#value' => t('Delete')); } return $f; }
function guifi_service_url($id) { if (empty($id)) { // get from parents return l(guifi_service_str($id), 'node/' . $id); } }
/** guifi_zone_data(): outputs the zone information data **/ function guifi_zone_data($zone) { $rows[] = array(t('zone name'), $zone->nick . ' - <b>' . $zone->title . '</b>'); if (count($zone->maintainers)) { $rows[] = array(t('Maintenance & SLAs'), implode(', ', guifi_maintainers_links($zone->maintainers))); } else { $pmaintainers = guifi_maintainers_parents($zone->id); if (!empty($pmaintainers)) { $rows[] = array(t('Maintenance & SLAs') . ' ' . t('(from parents)'), implode(', ', guifi_maintainers_links($pmaintainers))); } } if ($zone->homepage) { $rows[] = array(t('homepage'), l($zone->homepage, $zone->homepage)); } $rows[] = array(t('default proxy'), l(guifi_service_str($zone->proxy_id), guifi_zone_get_service($zone, 'proxy_id', TRUE))); if ($zone->graph_server > 0) { $gs = node_load(array('nid' => $zone->graph_server)); } else { $gs = node_load(array('nid' => guifi_graphs_get_server($zone->id, 'zone'))); } $rows[] = array(t('default graph server'), array('data' => l(guifi_service_str($zone->graph_server), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2)); $rows[] = array(t('network global information') . ':', NULL); // $rows[] = array(t('Mode'),t($zone->zone_mode)); $rows[] = array(t('DNS Servers'), $zone->dns_servers); $rows[] = array(t('NTP Servers'), $zone->ntp_servers); $rows[] = array(t('OSPF zone'), $zone->ospf_zone); $tz = db_fetch_object(db_query("SELECT description FROM {guifi_types} WHERE type = 'tz' AND text = '%s'", $zone->time_zone)); $rows[] = array(t('Time zone'), $tz->description); return array_merge($rows); }