You are here

public static function CertWriter::writeCerts in Lockr 8.3

Same name and namespace in other branches
  1. 8.4 src/CertWriter.php \Drupal\lockr\CertWriter::writeCerts()
  2. 4.x src/CertWriter.php \Drupal\lockr\CertWriter::writeCerts()

Writes certs for the given environment.

2 calls to CertWriter::writeCerts()
LockrMigrateForm::submitForm in src/Form/LockrMigrateForm.php
Form submission handler.
LockrRegisterForm::submitForm in src/Form/LockrRegisterForm.php
Form submission handler.

File

src/CertWriter.php, line 13

Class

CertWriter
Utility class for handling writing certificates to the file system.

Namespace

Drupal\lockr

Code

public static function writeCerts($env, $texts) {
  $base = "private://lockr/{$env}";
  @mkdir($base, 0750, TRUE);
  $key_file = "{$base}/key.pem";
  $key_fp = fopen($key_file, 'w');
  fwrite($key_fp, $texts['key_text']);
  fclose($key_fp);
  chmod($key_file, 0640);
  $cert_file = "{$base}/crt.pem";
  $cert_fp = fopen($cert_file, 'w');
  fwrite($cert_fp, $texts['cert_text']);
  fclose($cert_fp);
  chmod($cert_file, 0640);
  $pair_file = "{$base}/pair.pem";
  $pair_fp = fopen($pair_file, 'w');
  fwrite($pair_fp, $texts['key_text']);
  fwrite($pair_fp, $texts['cert_text']);
  fclose($pair_fp);
  chmod($pair_file, 0640);
}