You are here

function uc_credit_settings_form_submit in Ubercart 7.3

Same name and namespace in other branches
  1. 5 payment/uc_credit/uc_credit.module \uc_credit_settings_form_submit()
  2. 6.2 payment/uc_credit/uc_credit.module \uc_credit_settings_form_submit()

Creates the encryption key file if it doesn't already exist.

See also

uc_credit_settings_form()

uc_credit_settings_form_validate()

1 string reference to 'uc_credit_settings_form_submit'
uc_credit_settings_form in payment/uc_credit/uc_credit.admin.inc
Credit card settings form.

File

payment/uc_credit/uc_credit.admin.inc, line 322
Credit administration menu items.

Code

function uc_credit_settings_form_submit($form, &$form_state) {

  // Check to see if we need to create a key file.
  if (isset($form_state['uc_credit']['update_cc_encrypt_dir']) && $form_state['uc_credit']['update_cc_encrypt_dir'] === TRUE) {
    $key_path = $form_state['values']['uc_credit_encryption_path'];
    $key_file = $key_path . '/' . UC_CREDIT_KEYFILE_NAME;
    if (!file_exists($key_file)) {
      if (!($file = fopen($key_file, 'wb'))) {
        drupal_set_message(t('Credit card encryption key file creation failed for file @file. Check your filepath settings and directory permissions.', array(
          '@file' => $key_file,
        )), 'error');
        watchdog('uc_credit', 'Credit card encryption key file creation failed for file @file. Check your filepath settings and directory permissions.', array(
          '@file' => $key_file,
        ), WATCHDOG_ERROR);
      }
      else {

        // Replacement key generation suggested by Barry Jaspan
        // for increased security.
        fwrite($file, md5(drupal_get_token(serialize($_REQUEST) . serialize($_SERVER) . REQUEST_TIME)));
        fclose($file);
        drupal_set_message(t('Credit card encryption key file generated. Card data will now be encrypted.'));
        watchdog('uc_credit', 'Credit card encryption key file generated. Card data will now be encrypted.');
      }
    }
  }
}