Skip to content

Commit

Permalink
Added more vault settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 30, 2023
1 parent 9bfbbe7 commit daac17e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.idea/
users.json
default.vault
admin.vault
16 changes: 8 additions & 8 deletions Web/data/fileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
class fileManager
{
private string $usersFile;
private string $vaultFile;
private string $defaultVault;

public function __construct()
{
$this->usersFile = __DIR__ . '/../' . USERS_FILE;
$this->vaultFile = __DIR__ . '/../' . VAULT_FILE;
$this->usersFile = __DIR__ . '/../' . SECURE_LOCATION . USERS_FILE;
$this->defaultVault = __DIR__ . '/../' . SECURE_LOCATION . DEFAULT_USER . '.vault';

if (!file_exists($this->usersFile)) {
$this->initialiseUsers();
}

if (!file_exists($this->vaultFile)) {
if (!file_exists($this->defaultVault)) {
$this->initialiseVault();
}
}
Expand All @@ -32,18 +32,18 @@ public function getUserData(string $username)
private function initialiseUsers(): void
{
$UserFile = fopen($this->usersFile, "w");
fwrite($UserFile, '{"users" : []}');
fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD,PASSWORD_DEFAULT).'"}]');
fclose($UserFile);
}

private function initialiseVault(): void
{
$VaultFile = fopen($this->vaultFile, "w");
$VaultFile = fopen($this->defaultVault, "w");

$em = new encryptionManager();
$EncryptedData = $em->encrypt('"users" : []',$em->generateKey(TEMPORARY_PASSWORD));
$EncryptedData = $em->encrypt('[{}]',$em->generateKey(PASSWORD_DEFAULT));

fwrite($VaultFile, $EncryptedData[0].'[!]'.$EncryptedData[1]);
fwrite($VaultFile, $EncryptedData[0].FILE_SEPARATOR.$EncryptedData[1]);
fclose($VaultFile);
}
}
4 changes: 3 additions & 1 deletion Web/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

// Filesystem storage settings
const USERS_FILE = 'users.json';
const VAULT_FILE = 'default.vault';
const DEFAULT_USER = 'admin';
const SECURE_LOCATION = ''; // relative to this file.
const FILE_SEPARATOR = '[SEP]';

// Database storage settings
const DB_HOST = '';
Expand Down

0 comments on commit daac17e

Please sign in to comment.