Пример #1
0
function guifi_node_distances($node)
{
    drupal_set_title(t('distances from') . ' ' . guifi_get_zone_nick($node->zone_id) . '-' . $node->nick);
    $output .= drupal_get_form('guifi_node_distances_form', $node);
    $node = node_load(array('nid' => $node->id));
    drupal_set_breadcrumb(guifi_node_ariadna($node));
    $output .= theme_links(module_invoke_all('link', 'node', $node, FALSE));
    print theme('page', $output, FALSE);
    return;
}
Пример #2
0
function guifi_device_form($form_state, $params = array())
{
    global $user;
    $form = array();
    //$form['#suffix'] = '<script type="text/javascript">'
    //               . 'jQuery(\'input#edit-funders-0-user\').focus();'
    //               . '</script>';
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form()', $params);
    // Local javascript validations not actve because of bug in Firefox
    // Errors are not displayed when fieldset folder is collapsed
    // guifi_validate_js("#guifi-device-form");
    // $form['#attributes'] = array('onsubmit' => 'kk');
    if (empty($form_state['values'])) {
        $form_state['values'] = $params;
    }
    $form_state['#redirect'] = FALSE;
    // if new device, initializing variables
    if ($form_state['values']['nid'] == NULL && $params['add'] != NULL) {
        $form_state['values']['nid'] = $params['add'];
        $form_state['values']['new'] = TRUE;
        $form_state['values']['type'] = $params['type'];
        $form_state['values']['links'] = array();
        $form_state['values']['netmask'] = '255.255.255.224';
        if ($form_state['values']['type'] == 'radio') {
            $form_state['values']['variable']['firmware_id'] = '23';
            $form_state['values']['variable']['model_id'] = '70';
        }
    }
    drupal_set_breadcrumb(guifi_node_ariadna($form_state['values']['nid']));
    // Check permissions
    if ($params['edit']) {
        if (!guifi_device_access('update', $params['edit'])) {
            drupal_set_message(t('You are not authorized to edit this device', 'error'));
            return;
        }
    }
    // Loading node & zone where the device belongs to (some information will be used)
    $node = node_load(array('nid' => $form_state['values']['nid']));
    $zone = node_load($node->zone_id);
    // Setting the breadcrumb
    drupal_set_breadcrumb(guifi_node_ariadna($form_state['values']['nid']));
    // if contact is NULL, then get it from the node or the user logged in drupal
    if (is_null($form_state['values']['notification'])) {
        if (guifi_notification_validate($node->notification)) {
            $form_state['values']['notification'] = $node->notification;
        } else {
            drupal_set_message(t('The node has not a valid email address as a contact. Using your email as a default. Change the contact mail address if necessary.'));
            $form_state['values']['notification'] = $user->mail;
        }
    }
    // if nick is NULL, get a default name
    if ($form_state['values']['nick'] == "") {
        $form_state['values']['nick'] = guifi_device_get_default_nick($node, $form_state['values']['type'], $form_state['values']['nid']);
    }
    if (isset($form_state['action'])) {
        guifi_log(GUIFILOG_TRACE, 'action', $form_state['action']);
        if (function_exists($form_state['action'])) {
            if (!call_user_func_array($form_state['action'], array(&$form, &$form_state))) {
                return $form;
            }
        }
    }
    $form_weight = 0;
    if ($form_state['values']['id']) {
        $form['id'] = array('#type' => 'hidden', '#name' => 'id', '#value' => $form_state['values']['id'], '#weight' => $form_weight++);
    } else {
        $form['new'] = array('#type' => 'hidden', '#name' => 'new', '#weight' => $form_weight++, '#value' => TRUE);
    }
    $form['type'] = array('#type' => 'hidden', '#name' => 'type', '#weight' => $form_weight++, '#value' => $form_state['values']['type']);
    if ($params['add'] != NULL) {
        drupal_set_title(t('adding a new %device at %node', array('%node' => $node->nick, '%device' => $form_state['values']['type'])));
    } else {
        drupal_set_title(t('edit device %dname', array('%dname' => $form_state['values']['nick'])));
    }
    // All preprocess is complete, now going to create the form
    $form['main'] = array('#type' => 'fieldset', '#title' => t('Device name, status and main settings') . ' (' . $form_state['values']['nick'] . ') - ' . $form_state['values']['flag'], '#weight' => $form_weight++, '#collapsible' => TRUE, '#attributes' => array('class' => 'fieldset-device-main'), '#collapsed' => is_null($params['edit']));
    $form['main']['movenode'] = array('#type' => 'textfield', '#title' => t('Node'), '#maxlength' => 60, '#weight' => $form_weight++, '#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 device 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.'), '#prefix' => '<div class"form-newline">', '#suffix' => '</div>');
    $form['main']['nid'] = array('#type' => 'hidden', '#weight' => $form_weight++, '#value' => $form_state['values']['nid']);
    $form['main']['nick'] = array('#type' => 'textfield', '#size' => 20, '#maxlength' => 128, '#title' => t('nick'), '#required' => TRUE, '#attributes' => array('class' => 'required'), '#default_value' => $form_state['values']['nick'], '#weight' => $form_weight++, '#description' => t('The name of the device.<br />Used as a hostname, SSID, etc...'));
    $form['main']['flag'] = array('#type' => 'select', '#title' => t("Status"), '#required' => TRUE, '#default_value' => $form_state['values']['flag'], '#options' => guifi_types('status'), '#weight' => $form_weight++, '#description' => t("Current status of this device."));
    $form['main']['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'], '#weight' => $form_weight++, '#description' => t('Mailid where changes on the device will be notified, ' . 'if many, separated by \',\'<br />' . 'used for network administration.'));
    if (!empty($form_state['values']['ipv4'])) {
        $form['main']['mainipv4'] = array('#type' => 'select', '#title' => t('Main IPv4'), '#options' => guifi_get_currentDeviceIpv4s($form_state['values']), '#default_value' => $form_state['values']['mainipv4'], '#weight' => $form_weight++, '#description' => t('Used for monitoring.<br>Save and continue to refresh available addresses'));
    }
    $form['main']['logserver'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 60, '#title' => t('Log Server'), '#default_value' => $form_state['values']['logserver'], '#weight' => $form_weight++, '#description' => t('If you have a log server for mikrotik (dude), add your ip.'));
    $form['main']['graph_server'] = array('#type' => 'select', '#title' => t("Server which collects traffic and availability data"), '#required' => FALSE, '#default_value' => $node->graph_server ? $node->graph_server : 0, '#options' => array('0' => t('Default'), '-1' => t('None')) + guifi_services_select('SNPgraphs'), '#weight' => $form_weight++, '#description' => t("If not specified, inherits zone properties."));
    if (!user_access('administer guifi zones') || $device['user_created'] == $user->uid and $form_state['values']['type'] == 'radio') {
        $form['main']['graph_server']['#disabled'] = true;
        $form['main']['graph_server']['#description'] .= '<br>' . t('To change the value, you are required for maintainer privilege.');
    }
    /*
     * maintainers fieldset
     */
    $form['maintainers'] = guifi_maintainers_form(array2object($form_state['values']), $form_weight);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form(maintainers)', $form_state['values']['maintainers']);
    /*
     * funders fieldset
     */
    $form['funders'] = guifi_funders_form(array2object($form_state['values']), $form_weight);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form(funders)', $form_state['values']['funders']);
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans type)'), $form_weight);
    // create the device-type depenedent form
    // looking for a "guifi_"<device_type>"_form()" function
    if (function_exists('guifi_' . $form_state['values']['type'] . '_form')) {
        $form = array_merge($form, call_user_func_array('guifi_' . $form_state['values']['type'] . '_form', array($form_state['values'], &$form_weight)));
    }
    // Cable interfaces/networking
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if cable links)'), $form_weight);
    $form['if'] = guifi_interfaces_cable_form($form_state['values'], $form_weight);
    $form['if']['#weight'] = $form_weight++;
    // Cable interfaces/ports
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if ports)'), $form_weight);
    if (isset($form_state['values']['interfaces'])) {
        foreach ($form_state['values']['interfaces'] as $k => $v) {
            unset($form_state['values']['interfaces'][$k]['ipv4']);
        }
        guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if ports)'), $form_state['values']['interfaces']);
        $form['interfaces'] = guifi_ports_form($form_state['values'], $form_weight);
        $form['interfaces']['#weight'] = $form_weight++;
    }
    // VLANs (VLans, VRRPs, WDS...)
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if vLANs)'), $form_weight);
    $form['vlans'] = guifi_vinterfaces_form('vlans', $form_state['values'], $form_weight);
    $form['vlans']['#weight'] = $form_weight++;
    // Aggregations (Bridges & Bondings)
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if Aggregations)'), $form_weight);
    $form['aggregations'] = guifi_vinterfaces_form('aggregations', $form_state['values'], $form_weight);
    $form['aggregations']['#weight'] = $form_weight++;
    // ipv4
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans if ipv4)'), $form_weight);
    $form['ipv4'] = guifi_ipv4s_form($form_state['values'], $form_weight);
    $form['ipv4']['#weight'] = $form_weight++;
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans comments)'), $form_weight);
    // Comments
    $form['comment'] = array('#type' => 'textarea', '#title' => t('Comments'), '#default_value' => $form_state['values']['comment'], '#description' => t('This text will be displayed as an information of the device.'), '#cols' => 60, '#rows' => 5, '#weight' => $form_weight++);
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(abans buttons)'), $form_weight);
    //  save/validate/reset buttons
    $form['dbuttons'] = guifi_device_buttons(FALSE, '', 0, $form_weight);
    $form['dbuttons']['#weight'] = $form_weight++;
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_device_form(form_final)'), $form);
    return $form;
}
Пример #3
0
function guifi_users_queue($zone)
{
    function _guifi_user_queue_device_form($form_state, $d = array())
    {
        guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_device_form()', $d);
        if (count($d['radios']) != 1) {
            return;
        }
        if ($d['radios'][0]['mode'] != 'client') {
            return;
        }
        if (!isset($d['radios'][0]['interfaces'])) {
            return;
        }
        $iid = key($d['radios'][0]['interfaces']);
        if (!isset($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links'])) {
            return;
        }
        $lid = key($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links']);
        if (empty($iid) or empty($lid)) {
            return;
        }
        if (empty($form_state['values'])) {
            $form_state['values'] = $d;
        }
        $f['flag'] = array('#type' => 'item', '#value' => $form_state['values']['flag'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>');
        $f['mac'] = array('#type' => 'textfield', '#required' => TRUE, '#size' => 17, '#maxlength' => 17, '#default_value' => $form_state['values']['radios'][0]['mac'], '#element_validate' => array('guifi_mac_validate'), '#prefix' => '<td>', '#suffix' => '</td>');
        $f['did'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']);
        $f['nid'] = array('#type' => 'hidden', '#value' => $form_state['values']['nid']);
        $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['uid']);
        $f['iid'] = array('#type' => 'hidden', '#value' => $iid);
        $f['lid'] = array('#type' => 'hidden', '#value' => $lid);
        $f['approve'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/ok.png', '#attributes' => array('title' => t('Set the device and link Online, confirm MAC & approve user.')), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
        return $f;
    }
    function _guifi_user_queue_form($form_state, $params = array())
    {
        guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_form()', $params);
        if (empty($form_state['values'])) {
            $form_state['values'] = $params;
        }
        $f['status'] = array('#type' => 'select', '#options' => guifi_types('user_status'), '#default_value' => $form_state['values']['status'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>');
        $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']);
        $f['saveUser'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/save.png', '#attributes' => array('title' => t('Change & Save users Status.')), '#submit' => array('_guifi_user_queue_device_form_submit'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>');
        return $f;
    }
    function _guifi_user_queue_devices($u)
    {
        $query = db_query('SELECT d.id ' . 'FROM {guifi_devices} d ' . 'WHERE d.nid=%d' . '  AND type="radio"', $u['nid']);
        $rows = array();
        while ($d = db_fetch_array($query)) {
            $d = guifi_device_load($d['id']);
            $d['uid'] = $u['id'];
            if (guifi_device_access('update', $d['id'])) {
                $edit_device_icon = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank')));
            } else {
                $edit_device_icon = '';
            }
            if (user_access('administer guifi users')) {
                $edit_ok_icon = drupal_get_form('_guifi_user_queue_device_form', $d);
            } else {
                $edit_ok_icon = $d['flag'];
                if (count($d['radios']) == 1 and $d['radios'][0]['mode'] == 'client') {
                    $edit_ok_icon .= ' ' . $d['radios'][0]['mac'];
                }
            }
            $ip = guifi_main_ip($d['id']);
            $status_url = guifi_cnml_availability(array('device' => $d['id'], 'format' => 'short'));
            $rows[] = array($edit_device_icon . l($d['nick'], 'guifi/device/' . $d['id'], array('attributes' => array('target' => '_blank'))), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d, $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $edit_ok_icon, 'class' => $d['flag']), array('data' => $status_url, 'class' => $d['flag']));
        }
        return $rows;
    }
    global $user;
    $owner = $user->uid;
    guifi_log(GUIFILOG_TRACE, 'function guifi_users_node_list()', $zone);
    drupal_set_breadcrumb(guifi_zone_ariadna($zone->id, 'node/%d/view/userqueue'));
    $title = t('Queue of pending users @') . ' ' . $zone->title;
    drupal_set_title($title);
    $childs = guifi_zone_childs($zone->id);
    $childs[] = $zone->id;
    $sql = 'SELECT ' . '  u.*, l.id nid, l.nick nnick, l.status_flag nflag, l.zone_id ' . 'FROM {guifi_users} u, {guifi_location} l ' . 'WHERE u.nid=l.id' . '  AND (l.status_flag != "Working" OR u.status != "Approved") ' . '  AND l.zone_id IN (' . implode(',', $childs) . ') ' . 'ORDER BY FIND_IN_SET(u.status,"New,Pending,Approved,Rejected"),' . '  u.timestamp_created';
    $query = pager_query($sql, variable_get("guifi_pagelimit", 50));
    $rows = array();
    $nrow = 0;
    if (user_access('administer guifi networks') || user_access('administer guifi zones') || user_access('administer guifi users')) {
        $administer = TRUE;
    } else {
        $administer = FALSE;
    }
    while ($u = db_fetch_array($query)) {
        $pUser = (object) guifi_user_load($u['id']);
        $proxy = node_load(array('nid' => $pUser->services['proxy']));
        $srows = _guifi_user_queue_devices($u);
        $nsr = count($srows);
        if (empty($nsr)) {
            $nsr = 1;
        }
        $node = node_load(array('nid' => $u['nid']));
        if (guifi_node_access('update', $node)) {
            $edit_node_icon = l(guifi_img_icon('edit.png'), 'node/' . $u['nid'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'node/' . $u['nid'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank')));
        } else {
            $edit_node_icon = '';
        }
        if (guifi_user_access('update', $u)) {
            $edit_user_icon = l(guifi_img_icon('edit.png'), 'guifi/user/' . $u['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/user/' . $u['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank')));
        } else {
            $edit_user_icon = '';
        }
        if ($administer) {
            $edit_user_form = drupal_get_form('_guifi_user_queue_form', $u);
        } else {
            $edit_user_form = $u['status'];
        }
        if (user_access('administer guifi users') or $node->uid == $owner) {
            $rn3 = $u['lastname'] . ", " . $u['firstname'];
            $u3 = $u['username'];
        } else {
            $rn3 = ereg_replace("_", " ", $u['lastname'] . ", " . $u['firstname']);
            if (strlen($rn3) > 3) {
                $rn3 = substr($u['lastname'] . ", " . $u['firstname'], 0, 3);
                $rn3 .= "..";
            }
            $u3 = $u['username'];
            if (strlen($u3) > 3) {
                $u3 = substr($u['username'], 0, 5);
                $u3 .= "..";
            }
        }
        $rows[] = array(array('data' => $edit_user_icon . l($u3, 'node/' . $u['nid'] . '/view/users', array('attributes' => array('title' => $rn3, 'target' => '_blank'))) . "\n<br />" . '<small>' . format_date($u['timestamp_created']) . '<br />' . l($proxy->nick, "node/" . $proxy->id, array('attributes' => array('title' => $proxy->title))), 'rowspan' => $nsr), array('data' => guifi_get_zone_nick($u['zone_id']) . "<br /><strong>" . $edit_node_icon . l($u['nnick'], 'node/' . $u['nid'], array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . '</strong><br /><small>' . l(t('add a comment'), 'comment/reply/' . $u['nid'], array('fragment' => 'comment-form', 'html' => TRUE, 'attributes' => array('title' => t('Add a comment to the page of this node'), 'target' => '_blank'))) . '</small>', 'class' => $u['nflag'], 'rowspan' => $nsr), array('data' => $edit_user_form, 'rowspan' => $nsr));
        end($rows);
        $krow = key($rows);
        if (count($srows)) {
            // merge current row with first element
            $rows[$krow] = array_merge($rows[$krow], array_shift($srows));
            // adding rest og the elements
            foreach ($srows as $k => $v) {
                $rows[] = $v;
            }
        }
    }
    $header = array(t('Username'), t('Node'), t('User status'), t('Device'), t('IP v4 address'), t('Status & MAC'), t('Current status'));
    $output .= theme('table', $header, $rows);
    $output .= theme_pager(NULL, variable_get("guifi_pagelimit", 50));
    // Full screen (no lateral bars, etc...)
    print theme('page', $output, FALSE);
    // If normal output, retrurn $output...
}