Example #1
0
/**
 * IP subrange search form.
 */
function guifi_tools_ip_rangesearch_form($form_state, $params = array())
{
    if (empty($params)) {
        $mask = '255.255.255.224';
        $network_type = 'public';
        $zone_id = guifi_zone_root();
    } else {
        list($mask, $network_type, $zone_id, $allocate) = explode(',', $params);
    }
    $form['mask'] = array('#type' => 'select', '#title' => t("Mask"), '#required' => TRUE, '#default_value' => $mask, '#options' => guifi_types('netmask', 30, 0), '#description' => t('The mask of the network to search for. The number of the available hosts of each masks is displayed in the list box.'));
    $form['network_type'] = array('#type' => 'select', '#title' => t("Type"), '#required' => TRUE, '#default_value' => $network_type, '#options' => drupal_map_assoc(array('public', 'backbone')), '#description' => t('The type of network addresses you are looking for. <ul><li><em>public:</em> is for addresses which will allow the users connect to the services, therefore must be unique across all the network and assigned with care for not being wasted.</li><li><em>backbone:</em> internal addresses for network operation, could be shared across distinct network segments, do not neet to be known as a service address to the users</li></ul>'));
    $form['zone_id'] = guifi_zone_select_field($zone_id, 'zone_id');
    $form['allocate'] = array('#type' => 'select', '#title' => t("Allocate"), '#required' => TRUE, '#access' => user_access('administer guifi networks'), '#default_value' => 'No', '#options' => drupal_map_assoc(array('Yes', 'No')), '#description' => t('If yes, the network found will be allocated at the database being assigned to the zone'));
    $form['submit'] = array('#type' => 'submit', '#value' => t('Find space for the subnetwork'));
    return $form;
}
Example #2
0
/**
 * Present the guifi zone editing form.
 */
function guifi_ipv4_form($form_state, $params = array())
{
    guifi_log(GUIFILOG_TRACE, 'guifi_ipv4_form()', $params);
    $network_types = array('public' => t('public - for any device available to everyone'), 'backbone' => t("backbone - used for internal management, links..."), 'mesh' => t('mesh - for any device in Mesh'), 'reserved' => t('reserved - used for reserved addressing'));
    // $network_types = array_merge($network_types,guifi_types('adhoc'));
    if (empty($form_state['values'])) {
        // first execution, initializing the form
        // if new network, initialize the zone
        if ($params['add']) {
            $zone_id = $params['add'];
            $zone = guifi_zone_load($zone_id);
            // if is root zone, don't find next value'
            if ($zone_id != guifi_zone_root()) {
                // not root zone, fill default values looking to next available range
                $zone = guifi_zone_load($zone_id);
                $ndefined = db_fetch_object(db_query('SELECT count(*) c FROM guifi_networks WHERE zone=%d', $zone_id));
                switch ($ndefined->c) {
                    case 0:
                        $mask = '255.255.255.0';
                        break;
                    case 1:
                        $mask = '255.255.254.0';
                        break;
                    case 2:
                        $mask = '255.255.252.0';
                        break;
                    case 3:
                        $mask = '255.255.248.0';
                        break;
                    default:
                        $mask = '255.255.240.0';
                }
                $form_state['values']['zone'] = $zone_id;
                $ips_allocated = guifi_ipcalc_get_ips('0.0.0.0', '0.0.0.0', NULL, 1);
                $network_type = 'public';
                $allocate = 'No';
                $net = guifi_ipcalc_get_subnet_by_nid($zone->master, $mask, $network_type, $ips_allocated, $allocate, TRUE);
                // verbose output
                if ($net) {
                    $item = _ipcalc($net, $mask);
                    $form_state['values']['base'] = $net;
                    $form_state['values']['mask'] = $mask;
                } else {
                    drupal_set_message(t('It was not possible to find %type space for %mask', array('%type' => $network_type, '%mask' => $mask)), 'error');
                }
            }
            // if is not the root zone
        }
        // if existent network, get the network and edit
        if ($params['edit']) {
            $form_state['values'] = db_fetch_array(db_query('SELECT *
                                                       FROM {guifi_networks}
                                                       WHERE id = %d', $params['edit']));
        }
    }
    $form['base'] = array('#type' => 'textfield', '#title' => t('Network base IPv4 address'), '#required' => TRUE, '#default_value' => $form_state['values']['base'], '#size' => 16, '#maxlength' => 16, '#description' => t('A valid base ipv4 network address.'), '#weight' => 0);
    $form['mask'] = array('#type' => 'select', '#title' => t("Mask"), '#required' => TRUE, '#default_value' => $form_state['values']['mask'], '#options' => guifi_types('netmask', 24, 0), '#description' => t('The mask of the network. The number of valid hosts of each masks is displayed in the list box.'), '#weight' => 1);
    $form['zone'] = guifi_zone_select_field($form_state['values']['zone'], 'zone');
    $form['zone']['#weight'] = 2;
    $form['network_type'] = array('#type' => 'select', '#title' => t("Network type"), '#required' => TRUE, '#default_value' => $form_state['values']['network_type'], '#options' => $network_types, '#description' => t('The type of usage that this network will be used for.'), '#weight' => 3);
    $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 4);
    $form['id'] = array('#type' => 'hidden', '#value' => $form_state['values']['id'], '#weight' => 5);
    $form['valid'] = array('#type' => 'hidden', '#value' => $form_state['values']['valid'], '#weight' => 6);
    return $form;
}
Example #3
0
/** guifi_node_validate(): Confirm that an edited guifi item has fields properly filled in.
 */
function guifi_node_validate($node, $form)
{
    guifi_validate_nick($node->nick);
    // not at root zone
    if ($node->zone_id == 0 or $node->zone_id == guifi_zone_root()) {
        form_set_error('zone_id', t('Can\'t be assigned to root zone, please assign the node to an appropiate zone.'));
    } else {
        $nz = 0;
        guifi_zone_childs_tree_depth($node->zone_id, 3, $nz);
        if ($nz > 2) {
            form_set_error('zone_id', t('Can\'t be assigned to parent zone, please assign the node to an final zone.'));
        }
    }
    if ($node->elevation == 0) {
        $node->elevation = NULL;
    }
    if ($node->elevation < -1 && $node->elevation != NULL) {
        form_set_error('elevation', t('Elevation must be above the floor! :)'));
    }
    if ($node->elevation > 261 && $node->elevation != NULL) {
        form_set_error('elevation', t('Do you mean that you are flying over the earth??? :)'));
    }
    /*
     * Validate maintainer(s)
     */
    guifi_maintainers_validate($node);
    /*
     * Validate funder(s)
     */
    guifi_funders_validate($node);
}
Example #4
0
/** guifi_zone_l(): Creates a link to the zone
**/
function guifi_zone_l($id, $title = NULL, $linkto = 'node/')
{
    if ($id == 0) {
        $id = guifi_zone_root();
    }
    if (empty($title)) {
        $title = guifi_get_zone_name($id);
    }
    return l($title, $linkto . $id);
}