You are here

function drd_server_settings_keys in Drupal Remote Dashboard Server 6.2

Same name and namespace in other branches
  1. 7.2 drd_server.admin.inc \drd_server_settings_keys()

AES key settings form for an IP of an accepted DRD instance.

Parameters

array $form_state: Form_state array.

string $ip: The IP address for which the settings should be edited

Return value

array Array containing the form.

1 string reference to 'drd_server_settings_keys'
drd_server_menu in ./drd_server.module
Implements hook_menu().

File

./drd_server.admin.inc, line 154

Code

function drd_server_settings_keys($form_state, $ip) {
  $allowed = drd_get_allowed_referers();
  if (!in_array($ip, $allowed)) {
    drupal_not_found();
    exit;
  }
  drupal_set_title(t('Set AES keys for !ip', array(
    '!ip' => $ip,
  )));
  $keys = variable_get('drd_aes_keys', array());
  if (!isset($keys[$ip])) {
    $keys[$ip] = array();
  }
  $keys[$ip] += array(
    'key' => '',
    'cipher' => '',
    'iv' => '',
    'impl' => '',
    'cluster_mode' => FALSE,
    'cluster_ips' => '',
  );
  $form = array();
  $form['#ip'] = $ip;

  // AES settings
  $phpsec_load_result = _drd_server_aes_load_phpsec();
  $phpsec_loaded = $phpsec_load_result > 0;
  $encryption_implementations = array();
  if ($phpsec_loaded) {
    $encryption_implementations['phpseclib'] = t('PHP Secure Communications Library (phpseclib)');
  }
  if (extension_loaded('mcrypt')) {
    $encryption_implementations['mcrypt'] = t('Mcrypt extension');
  }
  if (empty($encryption_implementations)) {
    $encryption_implementations = array(
      t('None!'),
    );
  }
  $form['aes_implementation'] = array(
    '#type' => 'select',
    '#title' => t('AES implementation'),
    '#options' => $encryption_implementations,
    '#default_value' => $keys[$ip]['impl'],
  );
  $form['aes_cipher'] = array(
    '#type' => 'select',
    '#title' => t('Cipher'),
    '#options' => array(
      'rijndael-128' => 'Rijndael 128',
      'rijndael-192' => 'Rijndael 192',
      'rijndael-256' => 'Rijndael 256',
    ),
    '#default_value' => $keys[$ip]['cipher'],
    '#states' => array(
      'invisible' => array(
        ':input[name="aes_implementation"]' => array(
          'value' => 'phpseclib',
        ),
      ),
    ),
  );
  $form['aes_iv'] = array(
    '#type' => 'textfield',
    '#title' => 'IV',
    '#default_value' => $keys[$ip]['iv'],
  );
  $form['aes_key'] = array(
    '#type' => 'textfield',
    '#title' => 'Key',
    '#default_value' => $keys[$ip]['key'],
  );
  $form['aes']['cluster_mode'] = array(
    '#type' => 'checkbox',
    '#title' => 'Operate on a cluster behind load balancer',
    '#default_value' => $keys[$ip]['cluster_mode'],
  );
  $form['aes']['cluster_ips'] = array(
    '#type' => 'textarea',
    '#title' => 'IP addresses in cluster mode',
    '#default_value' => $keys[$ip]['cluster_ips'],
    '#description' => t('One IP address per line'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  return $form;
}