예제 #1
0
function guifi_device_print_data($device)
{
    $radios = db_query('SELECT *
       FROM {guifi_radios}
       WHERE id=%d
       ORDER BY id', $device['id']);
    $rows[] = array(t($device[type]), '<b>' . $device[nick] . '</b>');
    if (count($device['funders'])) {
        $rows[] = array(count($device['funders']) == 1 ? t('Funder') : t('Funders'), implode(', ', guifi_funders_links($device['funders'])));
    }
    if (count($device['maintainers'])) {
        $rows[] = array(t('Maintenance & SLAs'), implode(', ', guifi_maintainers_links($device['maintainers'])));
    }
    // If radio, print model & firmware
    if ($device['type'] == 'radio') {
        $rows[] = array($device[manufacturer] . '-' . $device[model], $device[variable][firmware]);
        // going to list all device radios
        if (count($device['radios'])) {
            foreach ($device['radios'] as $radio_id => $radio) {
                if ($radio['fund_required'] == '') {
                    $policy = t('n/d, ask to node contacts');
                } else {
                    if ($radio['fund_required'] == 'yes') {
                        $policy = t('Fund: :fund :curr', array(':fund' => $radio['fund_amount'], ':curr' => $radio['fund_currency']));
                    } else {
                        $policy = t($radio['fund_required']);
                    }
                }
                $rowsr[] = array($radio['ssid'], $radio['mode'], $radio['protocol'], $radio['channel'], $radio['mac'], t($radio['clients_accepted']), $policy);
            }
            $rows[] = array(array('data' => theme('table', array(t('ssid'), t('mode'), t('protocol'), t('ch'), t('wireless mac'), t('clients'), t('connection policy')), $rowsr), 'colspan' => 2));
        }
    }
    // If ADSL, print characteristics
    if ($device['type'] == 'ADSL' and $device['variable'] != '') {
        $bandwidth = guifi_bandwidth_types();
        $rows[] = array(t('bandwidth'), $bandwidth[$device['variable']['download']] . '/' . $bandwidth[$device['variable']['upload']]);
        $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']);
    }
    // Others with modelDescr set
    if (isset($device['variable']['modelDescr'])) {
        switch ($device['type']) {
            case 'ups':
                $vDescr = t('Power: %power', array('%power' => $device['variable']['specs']));
                break;
            case 'generator':
                $vDescr = t('Max Power: %power Watts', array('%power' => $device['variable']['specs']));
                break;
            case 'battery':
                $vDescr = t('Power: %power/Ah, Quantity: %quantity', array('%power' => $device['variable']['specs'], '%quantity' => $device['variable']['units']));
                break;
            case 'rack':
                $vDescr = t('Height: %height Us, Width: %width inches, Depth: %depth mm', array('%height' => $device['variable']['height'], '%width' => $device['variable']['width'], '%depth' => $device['variable']['depth']));
                break;
            case 'breaker':
                $vDescr = t('Protection: %cbtype, Auto-reclose: %recloser', array('%cbtype' => $device['variable']['cbtype'], '%recloser' => $device['variable']['recloser'] ? t('Yes') : t('No')));
                break;
        }
        $rows[] = array($device['variable']['modelDescr'], $vDescr);
    }
    // generic
    if ($device['type'] == 'generic' || 'confine' and !empty($device['variable']['mrtg_index'])) {
        $rows[] = array(t('SNMP index to graph'), $device['variable']['mrtg_index']);
    }
    if ($device['graph_server'] > 0) {
        $gs = node_load(array('nid' => $device['graph_server']));
    } else {
        $gs = node_load(array('nid' => guifi_graphs_get_server($device['id'], 'device')));
    }
    $rows[] = array(t('graphs provided from'), array('data' => l(guifi_service_str($device['graph_server']), $gs->l, array('attributes' => array('title' => $gs->nick . ' - ' . $gs->title))), 'colspan' => 2));
    $ip = guifi_main_ip($device[id]);
    $rows[] = array(t('IP address & MAC'), $ip[ipv4] . '/' . $ip[maskbits] . ' ' . $device[mac]);
    $status_url = guifi_cnml_availability(array('device' => $device['id'], 'format' => 'long'), $gs);
    if (!empty($ip[ipv4])) {
        $rows[] = array(t('status &#038; availability'), array('data' => t($device[flag]) . $status_url, 'class' => $device['flag']));
    }
    $rows[] = array(array('data' => theme_guifi_contacts($device), 'colspan' => 2));
    return array_merge($rows);
}
예제 #2
0
/**
 * Present the guifi zone editing form.
 */
function guifi_service_form($node, $param)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'guifi_service_form()', $node);
    drupal_set_breadcrumb(guifi_zone_ariadna($node->zone_id, 'node/%d/view/services'));
    // $f = guifi_form_hidden_var($node,array('id'));
    if (empty($node->nid) and is_numeric($node->title)) {
        $zone = guifi_zone_load($node->title);
        $node->zone_id = $node->title;
        $node->contact = $user->mail;
        $default = t('<service>');
        $node->title = NULL;
        $node->nick = $zone->nick . $default;
        $node->status_flag = 'Planned';
    }
    if (isset($node->id)) {
        $f['id'] = array('#type' => 'hidden', '#value' => $node->id);
    }
    $type = db_fetch_object(db_query("SELECT description FROM {guifi_types} WHERE type='service' AND text='%s'", $node->service_type));
    if ($node->nid > 0) {
        $f['service_type'] = array('#type' => 'item', '#value' => t('Service type'), '#description' => t($type->description));
    }
    //$output = form_item(t('Service type'),$node->service_type,t($type->description));
    $type = node_get_types('type', $node);
    if ($type->has_title) {
        $f['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title);
    }
    $f['nick'] = array('#type' => 'textfield', '#title' => t('Nick'), '#required' => FALSE, '#size' => 20, '#maxlength' => 20, '#default_value' => $node->nick, '#element_validate' => array('guifi_service_nick_validate'), '#collapsible' => FALSE, '#tree' => TRUE, '#description' => t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only."));
    //$output .= form_textfield(t("Nick"), "nick", $node->nick, 20, 20, t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only.") . ($error['nick'] ? $error["nick"] : ''), NULL, TRUE);
    $f['notification'] = array('#type' => 'textfield', '#title' => t('Contact'), '#required' => FALSE, '#size' => 60, '#maxlength' => 128, '#default_value' => $node->notification, '#element_validate' => array('guifi_emails_validate'), '#description' => t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page."));
    //$output .= form_textfield(t("Contact"), "contact", $node->contact, 60, 128, t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page.") . ($error['contact'] ? $error["contact"] : ''));
    ////  $output .= form_select(t('Zone'), 'zone_id', $node->zone_id, guifi_zones_listbox(), t('The zone where this node where this node belongs to.'));
    $f['server'] = array('#type' => 'textfield', '#title' => t("Device"), '#size' => 60, '#maxlength' => 128, '#default_value' => guifi_server_descr($node->device_id), '#element_validate' => array('guifi_servername_validate'), '#autocomplete_path' => 'guifi/js/select-server', '#description' => t('Where it runs.'));
    //$params .= guifi_form_column(form_select(t('Device'), "device_id", $node->device_id, guifi_servers_select(),t('Where it runs.')));
    if (!$node->nid) {
        $f['service_type'] = array('#type' => 'select', '#title' => t("Service"), '#default_value' => $node->service_type, '#options' => guifi_types('service'), '#description' => t('Type of service'));
        //$types = guifi_types('service');
        //array_shift($types);
        //$params.= guifi_form_column(form_select(t('Service'), "service_type", $node->service_type, $types,t('Type of service')));
    } else {
        $f['protocol'] = array('#type' => 'hidden', '#title' => t("service_type"), '#value' => $node->service_type);
    }
    //$output .= form_hidden("service_type",$node->service_type);
    $f['status_flag'] = array('#type' => 'select', '#title' => t("Status"), '#default_value' => $node->status_flag, '#options' => guifi_types('status'), '#description' => t('Current status'));
    //$params .= guifi_form_column(form_select(t('Status'), 'status_flag', $node->status_flag, guifi_types('status'), t('Current status')));
    //$output .= guifi_form_column_group(t('General parameters'),$params, NULL);
    // $node->var = unserialize($node->extra);
    if ($node->nid > 0) {
        $f['var'] = array('#type' => 'fieldset', '#title' => $node->service_type . ' ' . t("settings"), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE);
    }
    if ($node->nid > 0) {
        switch ($node->service_type) {
            case 'mail':
                $f['var']['in'] = array('#type' => 'textfield', '#title' => t('Inbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['in'], '#description' => t('Where email clients have to be configured for getting email messages'));
                $f['var']['out'] = array('#type' => 'textfield', '#title' => t('Outbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['out'], '#description' => t('Where email clients have to be configured for sending email messages'));
                $f['var']['webmail'] = array('#type' => 'textfield', '#title' => t('Webmail url'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['webmail'], '#description' => t('URL for accessing to this mail server, if there is'));
                $f['var']['admin'] = array('#type' => 'textfield', '#title' => t('Admin web interface'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['admin'], '#description' => t('Where to create/edit/delete users, change passwords, etc...'));
                break;
            case 'asterisk':
                $f['var']['prefix'] = array('#type' => 'textfield', '#title' => t('Dial prefix'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['prefix'], '#description' => t('Dial prefix for calling this server extensions'));
                $f['var']['incoming'] = array('#type' => 'textfield', '#title' => t('Incoming calls'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['incoming'], '#description' => t('Server or IP address where the calls have to be sent'));
                $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('IAX' => 'IAX', 'SIP' => 'SIP'));
                break;
            case 'NTP':
                $f['var']['ntp'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ntp']);
                break;
            case 'ftp':
                $f['var']['ftphost'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ftphost']);
                $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('SMB' => 'SMB (Samba)', 'ftp' => 'FTP', 'nfs' => 'NFS'));
                break;
            case 'Proxy':
            case 'ADSL':
                $f['var']['down'] = array('#type' => 'select', '#title' => t('Download'), '#default_value' => $node->var['down'], '#options' => guifi_bandwidth_types(), '#description' => t('Download bandwidth'));
                $f['var']['up'] = array('#type' => 'select', '#title' => t('Upload'), '#options' => guifi_bandwidth_types(), '#default_value' => $node->var['up'], '#description' => t('Upload bandwidth'));
                if ($node->service_type == 'ADSL') {
                    break;
                }
                if (empty($node->var['fed'])) {
                    $node->var['fed'] = array('IN' => '0', 'OUT' => '0');
                }
                $f['var']['fed'] = array('#type' => 'checkboxes', '#title' => t('Proxy federation'), '#default_value' => $node->var['fed'], '#options' => array('IN' => t('Allow login of users from OUT federated proxys'), 'OUT' => t('Allow proxy users to use other IN federated proxys')));
                $f['var']['proxy'] = array('#type' => 'textfield', '#title' => t("Name"), '#default_value' => $node->var['proxy'], '#size' => 60, '#maxlength' => 60);
                $f['var']['port'] = array('#type' => 'textfield', '#title' => t("Port"), '#default_value' => $node->var['port'], '#size' => 60, '#maxlength' => 60);
                $f['var']['type'] = array('#type' => 'select', '#title' => t("Type"), '#default_value' => $node->var['type'], '#options' => array('HTTP' => 'HTTP', 'Socks4' => 'SOCKS4', 'Socks5' => 'SOCKS5', 'arp' => 'ARP', 'ftp' => 'FTP'));
                break;
            case 'SNPgraphs':
                $f['var']['version'] = array('#type' => 'select', '#title' => t('version'), '#default_value' => $node->var['version'], '#options' => drupal_map_assoc(array('1.0', '2.0')), '#description' => t('version of the CNML services'));
                $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url'], '#description' => t('Base url to call CNML services'));
                break;
            default:
                $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url']);
                break;
        }
    }
    // multiple fields
    $delta = 0;
    if ($node->nid > 0) {
        switch ($node->service_type) {
            case 'mail':
                $f['var']['domains'] = guifi_service_multiplefield($node->var['domains'], 'domains', t('Managed domains'));
                break;
            case 'web':
                $f['var']['homepages'] = guifi_service_multiplefield($node->var['homepages'], 'homepages', t('URL pointing to the website homepage'));
                break;
            case 'irc':
                $f['var']['irc'] = guifi_service_multiplefield($node->var['irc'], 'irc', t('IRC server hostname'));
                break;
        }
    }
    if ($type->has_body) {
        $f['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
    }
    return $f;
}