mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-03-09 10:38:56 -04:00
* Initial setup in a new environment
The result of running the npm build and editing the .env file
* Revert "Initial setup in a new environment"
This reverts commit 23e06dea7f.
* Language interpolation update
I have edited all the interpolations in the en-US tree. To be consistent in using named parameters and not just positional numbers, I also edited the relevant lines in two controllers (Sales.php and Items.php) to send named variables to the lang() calls. The language string 'Sales.invoice_number_duplicate' contains an interploation for 'invoice_number'. This is sent when used by Controllers/Sales.php, but not sent when used by Views/sales/form.php, which means that string will contain a double space where the invoice number should be. The language string 'Customers.csv_import_partially_failed' contains no interpolations but two parameters are not being sent where it is used by Controllers/Customers.php. The string appears to be a near duplicate of 'Items.csv_import_partially_failed' which contains two interpolations. Either the Customers controller needs to be edited, or the Customers language string needs to be revised to look like the Items string.
---------
Co-authored-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
93 lines
2.2 KiB
PHP
93 lines
2.2 KiB
PHP
<?php
|
|
|
|
use CodeIgniter\Encryption\Encryption;
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
function check_encryption(): bool
|
|
{
|
|
$old_key = config('Encryption')->key;
|
|
|
|
if((empty($old_key)) || (strlen($old_key) < 64))
|
|
{
|
|
//Create Key
|
|
$encryption = new Encryption();
|
|
$key = bin2hex($encryption->createKey());
|
|
config('Encryption')->key = $key;
|
|
|
|
//Write to .env
|
|
$config_path = ROOTPATH . '.env';
|
|
$new_config_path = WRITEPATH . '/backup/.env' ;
|
|
$backup_path = WRITEPATH . '/backup/.env.bak';
|
|
|
|
//Copy to backup
|
|
if(!copy($config_path, $backup_path))
|
|
{
|
|
log_message('error', "Unable to copy $config_path to $backup_path");
|
|
}
|
|
|
|
@chmod($config_path, 0660);
|
|
@chmod($backup_path, 0660);
|
|
|
|
$config_file = file_get_contents($config_path);
|
|
$config_file = preg_replace("/(encryption\.key.*=.*)('.*')/", "$1'$key'", $config_file);
|
|
|
|
if(!empty($old_key))
|
|
{
|
|
$old_line = "# encryption.key = '$old_key' REMOVE IF UNNEEDED\r\n";
|
|
$insertion_point = stripos($config_file, 'encryption.key');
|
|
$config_file = substr_replace($config_file, $old_line, $insertion_point,0);
|
|
}
|
|
|
|
$handle = @fopen($config_path, 'w+');
|
|
|
|
if(empty($handle))
|
|
{
|
|
log_message('error', "Unable to open $config_path for updating");
|
|
return false;
|
|
}
|
|
|
|
@chmod($config_path, 0660);
|
|
$write_failed = !fwrite($handle, $config_file);
|
|
fclose($handle);
|
|
|
|
if($write_failed)
|
|
{
|
|
log_message('error', "Unable to write to $config_path for updating.");
|
|
return false;
|
|
}
|
|
log_message('info', "File $config_path has been updated.");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function abort_encryption_conversion()
|
|
{
|
|
$config_path = ROOTPATH . '.env';
|
|
$backup_path = WRITEPATH . '/backup/.env.bak';
|
|
|
|
$config_file = file_get_contents($backup_path);
|
|
|
|
$handle = @fopen($config_path, 'w+');
|
|
|
|
if(empty($handle))
|
|
{
|
|
log_message('error', "Unable to open $config_path to undo encryption conversion");
|
|
}
|
|
else
|
|
{
|
|
@chmod($config_path, 0660);
|
|
$write_failed = !fwrite($handle, $config_file);
|
|
fclose($handle);
|
|
|
|
if($write_failed)
|
|
{
|
|
log_message('error', "Unable to write to $config_path to undo encryption conversion.");
|
|
return;
|
|
}
|
|
log_message('info', "File $config_path has been updated to undo encryption conversion");
|
|
}
|
|
}
|