Exemplo n.º 1
0
function guifi_radio_add_wlan_submit($form, &$form_state)
{
    $radio = $form_state['clicked_button']['#parents'][1];
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_radio_add_wlan(%d)', $radio));
    $interface = _guifi_radio_add_wlan($radio, $form_state['values']['nid'], $form_state['values']);
    $form_state['values']['radios'][$radio]['unfold'] = TRUE;
    $form_state['values']['radios'][$radio]['interfaces'][] = $interface;
    $form_state['rebuild'] = TRUE;
    drupal_set_message(t('wLan with %net/%mask added at radio#%radio', array('%net' => $net, '%mask' => '255.255.255.224', '%radio' => $radio)));
    return TRUE;
}
Exemplo n.º 2
0
/**
 *
 * @param GuifiAPI $gapi GuifiAPI object
 *
 * @param mixed[] $parameters
 *
 * @return
 */
function guifi_api_interface_add($gapi, $parameters)
{
    if (!guifi_api_check_fields($gapi, array('device_id', 'radiodev_counter'), $parameters)) {
        return FALSE;
    }
    $device = guifi_device_load($parameters['device_id']);
    if (!guifi_device_access('update', $device)) {
        $gapi->addError(501);
        return FALSE;
    }
    if (!$device['id']) {
        $gapi->addError(500, "device not found: {$parameters['device_id']}");
        return FALSE;
    }
    $radiodev_counter = intval($parameters['radiodev_counter']);
    if (!isset($device['radios'][$radiodev_counter])) {
        $gapi->addError(500, "radio not found: {$radiodev_counter}");
        return FALSE;
    }
    $interface = _guifi_radio_add_wlan($radiodev_counter, $device['nid']);
    $old_interfaces = array_keys($device['radios'][$radiodev_counter]['interfaces']);
    $device['radios'][$radiodev_counter]['interfaces'][] = $interface;
    $device_id = guifi_device_save($device);
    $device = guifi_device_load($device_id);
    $new_interfaces = array_keys($device['radios'][$radiodev_counter]['interfaces']);
    $interface_id = array_shift(array_diff($new_interfaces, $old_interfaces));
    $interface = $device['radios'][$radiodev_counter]['interfaces'][$interface_id];
    if (!empty($interface['ipv4'])) {
        $ipv4 = array();
        foreach ($interface['ipv4'] as $if_ipv4) {
            $new_ipv4 = array();
            $new_ipv4['ipv4_type'] = $if_ipv4['ipv4_type'];
            $new_ipv4['ipv4'] = $if_ipv4['ipv4'];
            $new_ipv4['netmask'] = $if_ipv4['netmask'];
            $ipv4[] = $new_ipv4;
        }
        $gapi->addResponseField('ipv4', $ipv4);
    }
    $gapi->addResponseField('interface_id', $interface_id);
    return TRUE;
}