Skip to content

Commit

Permalink
Merge pull request #84 from ammopt/createKeyFile
Browse files Browse the repository at this point in the history
New createKeyFile.php cron script
  • Loading branch information
ammopt authored Jul 17, 2024
2 parents 83f9055 + 1851c69 commit 11cc1e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
34 changes: 34 additions & 0 deletions code/web/cron/createKeyFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../bootstrap.php';

global $serverName;

$passkeyFile = ROOT_DIR . "/../../sites/$serverName/conf/passkey";
if (!file_exists($passkeyFile)) {
// Return the file path (note that all ini files are in the conf/ directory)
$methods = [
'aes-256-gcm',
'aes-128-gcm',
];
foreach ($methods as $cipher) {
if (in_array($cipher, openssl_get_cipher_methods())) {
//Generate a 32 character password which will encode to 64 characters in hex notation
$key = bin2hex(openssl_random_pseudo_bytes(32));
break;
}
}
$passkeyFhnd = fopen($passkeyFile, 'w');
fwrite($passkeyFhnd, $cipher . ':' . $key);
fclose($passkeyFhnd);

//Make sure the file is not readable by anyone except the aspen user
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$runningOnWindows = true;
} else {
$runningOnWindows = false;
}
if (!$runningOnWindows) {
exec('chown aspen:aspen_apache ' . $passkeyFile);
exec('chmod 440 ' . $passkeyFile);
}
}
5 changes: 5 additions & 0 deletions code/web/release_notes/24.08.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
// jacob

// pedro
- Updated the way the passkey file is generated. (*PA*)

To generate the passkey file, the following command should be run (as root):

`php /usr/local/aspen-discovery/code/web/cron/createKeyFile.php <serverName>`

// lucas

Expand Down
34 changes: 0 additions & 34 deletions code/web/services/API/SystemAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,40 +571,6 @@ public function checkWhichUpdatesHaveRun($availableUpdates) {
return $availableUpdates;
}

/** @noinspection PhpUnused */
function createKeyFile() {
global $serverName;
$passkeyFile = ROOT_DIR . "/../../sites/$serverName/conf/passkey";
if (!file_exists($passkeyFile)) {
// Return the file path (note that all ini files are in the conf/ directory)
$methods = [
'aes-256-gcm',
'aes-128-gcm',
];
foreach ($methods as $cipher) {
if (in_array($cipher, openssl_get_cipher_methods())) {
//Generate a 32 character password which will encode to 64 characters in hex notation
$key = bin2hex(openssl_random_pseudo_bytes(32));
break;
}
}
$passkeyFhnd = fopen($passkeyFile, 'w');
fwrite($passkeyFhnd, $cipher . ':' . $key);
fclose($passkeyFhnd);

//Make sure the file is not readable by anyone except the aspen user
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$runningOnWindows = true;
} else {
$runningOnWindows = false;
}
if (!$runningOnWindows) {
exec('chown aspen:aspen_apache ' . $passkeyFile);
exec('chmod 440 ' . $passkeyFile);
}
}
}

function doesKeyFileExist() {
global $serverName;
$passkeyFile = ROOT_DIR . "/../../sites/$serverName/conf/passkey";
Expand Down

0 comments on commit 11cc1e1

Please sign in to comment.