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; }
function _guifi_api_node_check_parameters($gapi, $parameters) { extract($parameters); if (isset($status)) { if (guifi_validate_types('status', $status)) { $parameters['status_flag'] = $status; unset($parameters['status']); } else { $gapi->addError(403, "status: {$status}"); return FALSE; } } if (isset($lat) || isset($lon)) { if (isset($lat) && isset($lon)) { if (!is_numeric($lat)) { $gapi->addError(403, "lat: {$lat}"); } if (!is_numeric($lon)) { $gapi->addError(403, "lon: {$lon}"); } } else { $gapi->addError(403, "all coordinates should be specified"); } } if (isset($notification)) { if (!guifi_notification_validate($notification)) { $gapi->addError(403, "notification: {$notification}"); return FALSE; } } if (isset($graph_server)) { $server = db_fetch_object(db_query("SELECT id FROM {guifi_services} WHERE id = '%d' AND service_type = 'SNPgraphs'", $graph_server)); if (!$server->id) { $gapi->addError(403, "graph_server: {$graph_server}"); return FALSE; } } return TRUE; }
function guifi_domain_form($form_state, $params = array()) { global $user; guifi_log(GUIFILOG_TRACE, 'function guifi_domain_form()', $params); if (empty($form_state['values'])) { $form_state['values'] = $params; } $form_state['#redirect'] = FALSE; // if new domain, initializing variables if ($form_state['values']['sid'] == NULL && $params['add'] != NULL) { $form_state['values']['sid'] = $params['add']; $form_state['values']['new'] = TRUE; if ($params['mname']) { $masteridqry = db_query("SELECT name FROM {guifi_dns_domains} WHERE name = '%s'", $params['mname']); $mname = db_fetch_object($masteridqry); $form_state['values']['mname'] = $mname->name; $form_state['values']['name'] = $params['dname'] . '.' . $params['mname']; } else { $form_state['values']['name'] = $params['dname']; } $form_state['values']['type'] = $params['type']; if ($params['scope'] == 'external') { $form_state['values']['ipv4'] = ''; } else { $form_state['values']['ipv4'] = $params['ipv4']; } $form_state['values']['scope'] = $params['scope']; $form_state['values']['management'] = $params['management']; $form_state['values']['allow'] = 'disabled'; $form_state['values']['hosts']['0']['new'] = TRUE; $form_state['values']['hosts']['0']['counter'] = '0'; $form_state['values']['hosts']['0']['host'] = 'ns1'; $form_state['values']['hosts']['0']['ipv4'] = $params['ipv4']; $form_state['values']['hosts']['0']['ipv6'] = $params['ipv6']; $form_state['values']['hosts']['0']['opt']['options'] = array('NS' => 'NS', 'MX' => '0'); } drupal_set_breadcrumb(guifi_node_ariadna($form_state['values']['sid'])); // Check permissions if ($params['edit']) { if (!guifi_domain_access('update', $params['edit'])) { drupal_set_message(t('You are not authorized to edit this domain', 'error')); return; } } // Loading node & zone where the domain belongs to (some information will be used) $node = node_load(array('nid' => $form_state['values']['sid'])); // Setting the breadcrumb drupal_set_breadcrumb(guifi_node_ariadna($form_state['values']['sid'])); // 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 service 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 (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 = -20; if ($form_state['values']['id']) { $form['id'] = array('#type' => 'hidden', '#name' => 'id', '#value' => $form_state['values']['id']); } else { $form['new'] = array('#type' => 'hidden', '#name' => 'new', '#value' => TRUE); } if ($params['add'] != NULL) { drupal_set_title(t('adding a new type %domain at %node', array('%node' => $node->nick, '%domain' => $form_state['values']['type']))); } else { drupal_set_title(t('edit domain %dname', array('%dname' => $form_state['values']['name']))); } // All preprocess is complete, now going to create the form $form['main'] = array('#type' => 'fieldset', '#title' => t('Domain name main settings') . ' (' . $form_state['values']['name'] . ')', '#weight' => $form_weight++, '#collapsible' => TRUE, '#collapsed' => FALSE); $form['main']['sid'] = array('#type' => 'hidden', '#value' => $form_state['values']['sid']); $form['main']['type'] = array('#type' => 'hidden', '#value' => $form_state['values']['type']); $form['main']['mname'] = array('#type' => 'hidden', '#value' => $form_state['values']['mname']); $form['main']['scope'] = array('#type' => 'hidden', '#value' => $form_state['values']['scope']); $form['main']['name'] = array('#type' => 'textfield', '#size' => 32, '#maxlength' => 32, '#title' => t('Domain Name'), '#required' => TRUE, '#default_value' => $form_state['values']['name'], '#description' => t('The Domain Name'), '#weight' => $form_weight++); $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'], '#description' => t('Mails where changes on the domain will be notified, if many, separated by \',\'') . '<br />' . t('used for network administration.'), '#weight' => $form_weight++); if ($form_state['values']['scope'] == 'external') { $form['main']['ipv4'] = array('#type' => 'textfield', '#title' => t('Set the Nameserver IP Address'), '#size' => 16, '#maxlength' => 16, '#required' => TRUE, '#default_value' => $form_state['values']['ipv4'], '#element_validate' => array('guifi_ipv4_validate'), '#description' => t('External scope: Put the Internet IP Address of NameServer.'), '#weight' => $form_weight++); } else { $form['main']['ipv4'] = array('#type' => 'hidden', '#default_value' => $form_state['values']['ipv4']); } $form['main']['settings'] = array('#type' => 'fieldset', '#title' => t('Advanced domain name settings'), '#weight' => $form_weight++, '#collapsible' => TRUE, '#collapsed' => TRUE); $form['main']['settings']['management'] = array('#type' => 'select', '#title' => t('Management'), '#default_value' => $form_state['values']['management'], '#options' => array('automatic' => 'automatic', 'manual' => 'manual'), '#description' => t('Choose <strong>Automatic</strong> if you want to use your domain management with the utility for servers "DNSServices"') . '<br \\>' . t('Choose <strong>Manual</strong>, if you just want to keep track of your domain/hosts here but want to do the management in your server manually.')); $form['main']['settings']['public'] = array('#type' => 'select', '#title' => t('Public domain'), '#default_value' => $form_state['values']['public'], '#options' => array('yes' => 'Yes', 'no' => 'No'), '#description' => t('Choose <strong>Yes</strong> if you want your domain/subdomain can be delegated subdomains from other users. (Ex: DELEGATED.yourdomain.net.') . '<br/>' . t('Choose <strong>No</strong> if your domain/subdomain is private and you do not want to allow delegates subdomains.')); $form['main']['settings']['allow'] = array('#type' => 'radios', '#required' => TRUE, '#title' => t('Transfer Options'), '#default_value' => $form_state['values']['allow'], '#options' => array('slave' => t('Allow to be enslaved (Recommended)'), 'forward' => t('Allow Forward'), 'disabled' => t('Disabled')), '#description' => t('<strong>Enslaved</strong>, Allow other DNS servers on the network have an exact copy of the domain, so, if the original DNS does not work, can access to the hosts.') . '<br \\>' . t('<strong>Forward</strong>, Allow other DNS servers on the network to forward the request to the master server transparently saving bandwidth.') . '<br \\>' . t('<strong>Disabled</strong>, If you select this option, the management of your domain may not be transferred in any way, your domain will not be visible to other network servers.')); $form['main']['settings']['defipv4'] = array('#type' => 'textfield', '#title' => t("Default Domain IPv4 Address"), '#default_value' => $form_state['values']['defipv4'], '#element_validate' => array('guifi_ipv4_validate'), '#description' => t("Ex: domain.net without hostname resolve this IPv4 Address, tends to be the same address as hostname: www.") . "<br />" . t("leave it blank if not needed."), '#required' => FALSE); $form['main']['settings']['defipv6'] = array('#type' => 'textfield', '#title' => t("Default Domain IPv6 Address"), '#default_value' => $form_state['values']['defipv6'], '#element_validate' => array('guifi_ipv6_validate'), '#description' => t("Ex: domain.net without hostname resolve this IPv6 Address, tends to be the same address as hostname: www.") . "<br />" . t("leave it blank if not needed."), '#required' => FALSE); $form['main']['settings']['externalmx'] = array('#type' => 'textfield', '#title' => t("External Mailservers MX "), '#default_value' => $form_state['values']['externalmx'], '#description' => t("Separated by ','. Put them here only if the mail servers are external, if they are not, leave it blank.") . "<br />" . t("Internal MailServers should be configured in the advanced options of the hosts."), '#required' => FALSE); $form['main']['settings']['externalns'] = array('#type' => 'textfield', '#title' => t("External Namservers "), '#default_value' => $form_state['values']['externalns'], '#description' => t("Separated by ','. Put external nameserver IP address if you need it, if they are not, leave it blank.") . "<br />" . t("Internal domain Nameservers should be configured in the advanced options of the hosts."), '#required' => FALSE); if ($form_state['values']['management'] == 'automatic') { if (function_exists('guifi_host_form')) { $form = array_merge($form, call_user_func('guifi_host_form', $form_state['values'], $form_weight)); } } // Comments $form_weight = 200; $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 domain.'), '#cols' => 60, '#rows' => 5, '#weight' => $form_weight++); // save/validate/reset buttons $form['dbuttons'] = guifi_domain_buttons(FALSE, '', $form_weight); return $form; }
function guifi_emails_validate($element, &$form_state) { if (empty($element['#value'])) { form_error($element, t('You have to specify at least one notification email address.')); } $emails = guifi_notification_validate($element['#value']); if (!$emails) { form_error($element, t('Error while validating email address')); } else { form_set_value($element, $emails, $form_state); } }