Exemplo n.º 1
0
function guifi_links_delete_submit(&$form, &$form_state)
{
    $values = $form_state['clicked_button']['#parents'];
    $remote_did = array_pop($values);
    $remote_nid = array_pop($values);
    $link_id = array_pop($values);
    $dummy = array_pop($values);
    $ipv4_id = array_pop($values);
    $dummy = array_pop($values);
    $interface_id = array_pop($values);
    $dummy = array_pop($values);
    if ($values['0'] == 'radios') {
        $radio_id = array_pop($values);
        $fbase =& $form_state['values']['radios'][$radio_id];
        $fbase['unfold'] = TRUE;
    } else {
        $fbase =& $form_state['values'];
    }
    guifi_log(GUIFILOG_TRACE, sprintf('function guifi_radio_interface_link_delete_submit(radio: %d-%s, interface: %d, ipv4: %d, lid: %d, rnid: %d rdid: %d)', $radio_id, $form_state['values']['radios'][$radio_id]['mode'], $interface_id, $ipv4_id, $link_id, $remote_nid, $remote_did), $values);
    $fbase['interfaces'][$interface_id]['unfold'] = TRUE;
    $fipv4 =& $fbase['interfaces'][$interface_id]['ipv4'][$ipv4_id];
    $fipv4['unfold'] = TRUE;
    $flink =& $fipv4['links'][$link_id];
    $flink['unfold'] = TRUE;
    $flink['deleted'] = TRUE;
    $flink['ipv4']['unfold'] = TRUE;
    // if P2P link or AP/Client link and radio is the client
    // delete also the local IP
    if ($flink['ipv4']['netmask'] == '255.255.255.252' or $ipv4['netmask'] == '255.255.255.248' or $ipv4['netmask'] == '255.255.255.240' or $form_state['values']['radios'][$radio_id]['mode'] == 'client') {
        $fipv4['deleted'] = TRUE;
    }
    $form_state['rebuild'] = TRUE;
    drupal_set_message(t('%type link with %node/%device deleted.', array('%type' => $fbase['interfaces'][$interface_id]['interface_type'], '%node' => guifi_get_nodename($remote_nid), '%device' => guifi_get_hostname($remote_did))));
    return TRUE;
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
function guifi_user_form_validate($form, &$form_state)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_user_form_validate()', $form_state);
    $edit =& $form_state['values'];
    if (isset($edit['username_created'])) {
        if (user_load(array('name' => $edit['username_created'])) == FALSE) {
            form_set_error('username_created', t('Invalid user name.'));
        }
    }
    if (isset($edit['id']) and isset($edit['previous_pwd'])) {
        if ($form_state['clicked_button']['#value'] != t('Reset password')) {
            if (empty($edit['previous_pwd'])) {
                form_set_error('previous_pwd', t('You need to specify the current password to submit any change'));
            }
            $prevUser = guifi_user_load($edit['id']);
            if (crypt($edit['previous_pwd'], $prevUser['password']) != $prevUser['password']) {
                form_set_error('previous_pwd', t('Unable to submit changes: Password failure.'));
            }
        }
    }
    if (empty($edit['firstname'])) {
        form_set_error('firstname', t('Firstname field cannot be blank .'));
    }
    if (empty($edit['lastname'])) {
        form_set_error('lastname', t('Lastname field cannot be blank .'));
    }
    $edit['firstname'] = trim($edit['firstname']);
    $edit['lastname'] = trim($edit['lastname']);
    $edit['username'] = str_replace(" ", ".", strtolower(guifi_to_7bits($edit['firstname']) . '.' . guifi_to_7bits($edit['lastname'])));
    //  $edit['username'] = str_replace(" ",".",strtolower(guifi_to_7bits($edit['firstname'].'.'.$edit['lastname'])));
    if (!empty($edit['username'])) {
        if (isset($edit['id'])) {
            $query = db_query("SELECT username, services " . "FROM {guifi_users} " . "WHERE username ='******' " . " AND id <> %d", $edit['username'], $edit['id']);
        } else {
            $query = db_query("SELECT username, nid, services " . "FROM {guifi_users} " . "WHERE username ='******'", $edit['username']);
        }
        while ($proxy_id = db_fetch_object($query)) {
            $services = unserialize($proxy_id->services);
            $qry2 = db_query("SELECT nick " . "FROM {guifi_services} " . "WHERE id = %d", $services['proxy']);
            $proxy_name = db_fetch_object($qry2);
            form_set_error('username', t('The user %username is already defined ' . 'at the node %nodename ' . 'for service %servicename. Use middle initial, 2nd lastname or a prefix ' . 'with the proxy to get a unique username.', array('%username' => $edit['username'], '%nodename' => guifi_get_nodename($proxy_id->nid), '%servicename' => $proxy_name->nick)));
        }
    }
    if (!empty($edit['pass'])) {
        $edit['password'] = crypt($edit['pass']);
    }
    if (!empty($edit['notification'])) {
        if (isset($edit['id'])) {
            $query = db_query("SELECT username, notification, nid, services " . "FROM {guifi_users} " . "WHERE notification ='%s' " . " AND id <> %d", $edit['notification'], $edit['id']);
        } else {
            $query = db_query("SELECT username, notification, nid, services " . "FROM {guifi_users} " . "WHERE notification ='%s'", $edit['notification']);
        }
        while ($guifi_users = db_fetch_object($query)) {
            form_set_error('notification', t('The e-mail address: %notification is already defined ' . 'for the user: %username on node %nodename ' . '<p>Each user must use a real e-mail and this must not be repeated in others.', array('%notification' => $edit['notification'], '%username' => $guifi_users->username, '%nodename' => guifi_get_nodename($guifi_users->nid))));
        }
    }
}
Exemplo n.º 4
0
function budgets_supplier_sla($supplier, $type, $pager = 50)
{
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (supplier)', $type);
    if ($type != 'all') {
        $swt = ' AND subject_type = "' . $type . '" ';
    }
    $qquery = 'SELECT * ' . 'FROM {guifi_maintainers} ' . 'WHERE supplier_id=' . $supplier->id . ' ' . $swt . 'ORDER BY timestamp_created desc ';
    guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (budgets query)', $qquery);
    $pager = pager_query($qquery, variable_get('default_nodes_main', $pager));
    $output = '';
    $rows = array();
    while ($s = db_fetch_object($pager)) {
        guifi_log(GUIFILOG_TRACE, 'budgets_supplier_sla (row)', $s);
        switch ($s->subject_type) {
            case 'location':
                $n = guifi_get_nodename($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'zone':
                $n = guifi_get_zone_name($s->subject_id);
                $l = 'node/' . $s->subject_id;
                break;
            case 'device':
                $n = guifi_get_devicename($s->subject_id);
                $l = 'guifi/device/' . $s->subject_id . '/view';
                break;
        }
        if ($type == 'all') {
            $n .= ' (' . t($s->subject_type) . ')';
        }
        $u = user_load($s->user_created);
        $rows[] = array(l($s->subject_id . '-' . $n, $l), $s->commitment, $s->sla, $s->sla_resp, $s->sla_fix, l(t('by') . ' ' . $u->name, 'user/' . $s->user_created), format_date($s->timestamp_created));
    }
    if (count($rows) == 0) {
        $rows[] = array(array('data' => t('none'), 'colspan' => 8));
    }
    $header = array(t($type), t('type'), t('SLA'), t('resp.'), t('fix.'), t('created'), null);
    $output = theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager);
    print theme('page', $output, FALSE);
    return;
}
Exemplo n.º 5
0
function guifi_traceroute_dataexport($route, $nRoute, &$linkslist, &$nodeslist)
{
    $oGC = new GeoCalc();
    $tDist = 0;
    $nLink = 0;
    $nReg = 0;
    $output = '';
    foreach ($route as $did => $hop) {
        if (isset($hop['to'])) {
            $linkslist[$nReg]['todevicename'] = guifi_get_devicename($did, 'nick');
            $linkslist[$nReg]['todevicelink'] = 'guifi/device/' . $did;
            $linkslist[$nReg]['tonode'] = $hop['to'][0];
            $ip = db_fetch_object(db_query('SELECT ipv4, netmask FROM {guifi_ipv4} WHERE id=%d AND interface_id=%d', $hop['to'][2], $hop['to'][1]));
            $linkslist[$nReg]['toipv4'] = $ip->ipv4 . '/' . guifi_ipcalc_get_maskbits($ip->netmask);
            if (!isset($nodeslist[$hop['to'][0]])) {
                $nodeslist[$hop["to"][0]] = guifi_get_location($hop["to"][0]);
                $nodeslist[$hop["to"][0]][nodename] = guifi_get_nodename($hop['to'][0]);
                $nodeslist[$hop["to"][0]][nodelink] = $hop['to'][0];
            }
        }
        if (isset($hop['from'])) {
            $nLink++;
            $nReg = $nRoute * 100 + $nLink;
            $linkslist[$nReg]['route'] = $nRoute;
            $linkslist[$nReg]['nlink'] = $nLink;
            $linkslist[$nReg]['idlink'] = $hop['from'][0];
            $linkslist[$nReg]['fromdevicename'] = guifi_get_devicename($did, 'nick');
            $linkslist[$nReg]['fromdevicelink'] = 'guifi/device/' . $did;
            $linkslist[$nReg]['fromnode'] = $hop['from'][5];
            $ip = db_fetch_object(db_query('SELECT ipv4, netmask FROM {guifi_ipv4} WHERE id=%d AND interface_id=%d', $hop['from'][4], $hop['from'][3]));
            $linkslist[$nReg]['fromipv4'] = $ip->ipv4 . '/' . guifi_ipcalc_get_maskbits($ip->netmask);
            $linkslist[$nReg]['type'] = $hop['from'][1];
            $linkslist[$nReg]['status'] = $hop['from'][2];
            if (!isset($nodeslist[$hop['from'][5]])) {
                $nodeslist[$hop["from"][5]] = guifi_get_location($hop["from"][5]);
                $nodeslist[$hop["from"][5]][nodename] = guifi_get_nodename($hop['from'][5]);
                $nodeslist[$hop["from"][5]][nodelink] = $hop['from'][5];
            }
        }
        // if not same location, give the distance
        if ($hop['from'][1] != 'cable') {
            $qry = db_query('SELECT n.id nid, lat, lon
         FROM {guifi_location} n, {guifi_links} l
         WHERE l.id=%d
           AND l.nid=n.id', $hop['from'][0]);
            $loc1 = db_fetch_object($qry);
            $loc2 = db_fetch_object($qry);
            $gDist = round($oGC->EllipsoidDistance($loc1->lat, $loc1->lon, $loc2->lat, $loc2->lon), 3);
            if ($gDist) {
                $linkslist[$nReg]['distance'] = $gDist;
            }
        }
    }
    return $output;
}