- Changed system/dbupdate_3.3.php to add oe_kurzbz to table public.tbl_msg_recipient and foreign key fk_tbl_msg_recipient_oe_kurzbz

- Removed not used constants for messaging from config/constants.php
- Renamed config entry assistent_function to ou_receivers and converted from string to array
- Moved controllers/MailJob.php to controllers/jobs/MailJob.php
- Controller MailJob now extends CLI_Controller
- Added new function parseText to helpers/hlp_common_helper.php
- Improved code function generateToken in helpers/hlp_common_helper.php
- helpers/hlp_sancho_helper.php now uses parseText function from hlp_common_helper
- Removed method parseVorlagetext from PhrasesLib.php
- PhrasesLib.php now uses parseText function from hlp_common_helper
- Removed method parseVorlagetext from VorlageLib
- Improved code of controller controllers/system/Messages.php (uses parseText too)
- Controller controllers/system/Vorlage.php now uses parseText
This commit is contained in:
Paolo
2019-06-12 17:27:35 +02:00
parent 056f0a0a2d
commit 2ef386c34e
10 changed files with 161 additions and 142 deletions
+50 -23
View File
@@ -24,39 +24,54 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------
/**
* generateToken() - generates a new token for diffent use
* - reading Messages from external
* - forgotten Password
*
* @return string
* Generates a new token for diffent use cases. Default token length is 64
* - Reading messages
* - Forgotten password
* - etc
* Returns null on failure
*/
function generateToken($length = 64)
{
$token = null;
$firstGeneratedToken = null;
// For PHP 7 you can use random_bytes()
if (function_exists('random_bytes'))
{
$token = base64_encode(random_bytes($length));
//base64 is about 33% longer, so we need to truncate the result
return strtr(substr($token, 0, $length), '+/=', '-_,');
try
{
$firstGeneratedToken = random_bytes($length); // try to generates cryptographically secure pseudo-random bytes...
}
catch (Exception $e) { $firstGeneratedToken = null; } // if fails $firstGeneratedToken is set to null
}
// for PHP >=5.3 and <7
if (function_exists('openssl_random_pseudo_bytes'))
// For PHP >= 5.3 and < 7 and openssl is available
elseif (function_exists('openssl_random_pseudo_bytes'))
{
$token = base64_encode(openssl_random_pseudo_bytes($length, $strong));
// is the token strong enough?
if($strong == true)
return strtr(substr($token, 0, $length), '+/=', '-_,');
$firstGeneratedToken = openssl_random_pseudo_bytes($length, $strong);
// If the token generation ended with errors OR the generated token is NOT strong enough
if ($firstGeneratedToken == false || $strong == false) $firstGeneratedToken = null; // $firstGeneratedToken is set to null
}
//fallback to mt_rand if php < 5.3 or no openssl available
$characters = '0123456789';
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+';
$charactersLength = strlen($characters)-1;
$token = '';
//select some random characters
for ($i = 0; $i < $length; $i++)
$token .= $characters[mt_rand(0, $charactersLength)];
if ($firstGeneratedToken != null) // If everything was fine
{
// base64 is about 33% longer, so we need to truncate the result
$token = strtr(substr(base64_encode($firstGeneratedToken), 0, $length), '+/=', '-_,');
}
// Fallback to mt_rand if:
// php < 5.3
// OR no openssl is available
// OR openssl_random_pseudo_bytes used an algorithm that is cryptographically NOT strong
// OR one of the previous methods failed
if ($token == null)
{
$token = ''; // set $token as an empty string
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+';
$charactersLength = strlen($characters) - 1;
// Select some random characters
for ($i = 0; $i < $length; $i++) $token .= $characters[mt_rand(0, $charactersLength)];
}
return $token;
}
@@ -224,3 +239,15 @@ function isDateWorkingDay($date, $days = null)
return true;
}
}
/**
* Parse the given given text using the given data parameter
* Use the CI parser which performs simple text substitution for pseudo-variable
*/
function parseText($text, $data)
{
$ci =& get_instance(); // get CI instance
$ci->load->library('parser'); // Loads CI parser library
return $ci->parser->parse_string($text, $data, true);
}
+1 -3
View File
@@ -98,9 +98,7 @@ function _parseMailContent($vorlage_kurzbz, $vorlage_data)
!isEmptyString($result->retval[0]->text))
{
// Parses template text
$parsedText = $ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $vorlage_data);
return $parsedText;
return parseText($result->retval[0]->text, $vorlage_data);
}
}
}