Permalink
Browse files

Moved the encryption logic from the DataContainer to the Widget class (

  • Loading branch information...
1 parent 3df566b commit f786f7961603ec7f6142d1c4066b6ca2dfd25ae9 @leofeyer leofeyer committed May 26, 2011
View
1 CHANGELOG.txt
@@ -14,6 +14,7 @@ Version 2.10.beta1 (XXXX-XX-XX)
- Changed: make "email" a unique field for users and members (#2493)
- Changed: do not show subpages if the website root page is not public (#2425)
- Changed: make the ellipsis string of the String class configurable (#2700)
+- Changed: moved the encryption logic from the DataContainer to the Widget class (#2603)
- Improved: optimized the back end page speed (#2400)
- Improved: added CSS and JS combining to the back end front end
- Improved: standardized event and newsletter templates (#2889)
View
30 system/drivers/DC_Table.php
@@ -3041,6 +3041,15 @@ protected function generateTree($table, $id, $arrPrevNext, $blnHasSorting, $intM
foreach ($showFields as $k=>$v)
{
+ // Decrypt the value
+ if ($GLOBALS['TL_DCA'][$table]['fields'][$v]['eval']['encrypt'])
+ {
+ $objRow->$v = deserialize($objRow->$v);
+
+ $this->import('Encryption');
+ $objRow->$v = $this->Encryption->decrypt($objRow->$v);
+ }
+
if (strpos($v, ':') !== false)
{
list($strKey, $strTable) = explode(':', $v);
@@ -3428,6 +3437,18 @@ protected function parentView()
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][1], $row[$i]['id']), 'class="blink"');
$imagePasteNew = $this->generateImage('new.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pastenew'][1], $row[$i]['id']));
+ // Decrypt encrypted value
+ foreach ($row[$i] as $k=>$v)
+ {
+ if ($GLOBALS['TL_DCA'][$table]['fields'][$k]['eval']['encrypt'])
+ {
+ $v = deserialize($v);
+
+ $this->import('Encryption');
+ $row[$i][$k] = $this->Encryption->decrypt($v);
+ }
+ }
+
// Make items sortable
if ($blnHasSorting)
{
@@ -3708,6 +3729,15 @@ protected function listView()
// Label
foreach ($showFields as $k=>$v)
{
+ // Decrypt the value
+ if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['encrypt'])
+ {
+ $row[$v] = deserialize($row[$v]);
+
+ $this->import('Encryption');
+ $row[$v] = $this->Encryption->decrypt($row[$v]);
+ }
+
if (strpos($v, ':') !== false)
{
list($strKey, $strTable) = explode(':', $v);
View
48 system/libraries/Encryption.php
@@ -97,20 +97,30 @@ public static function getInstance()
* @param mixed
* @return string
*/
- public function encrypt($strValue)
+ public function encrypt($varValue)
{
- if ($strValue == '')
+ // Recursively encrypt arrays
+ if (is_array($varValue))
+ {
+ foreach ($varValue as $k=>$v)
+ {
+ $varValue[$k] = $this->encrypt($v);
+ }
+
+ return $varValue;
+ }
+
+ if ($varValue == '')
{
return '';
}
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->resTd), MCRYPT_RAND);
mcrypt_generic_init($this->resTd, md5($GLOBALS['TL_CONFIG']['encryptionKey']), $iv);
-
- $strEncrypted = mcrypt_generic($this->resTd, $strValue);
+ $strEncrypted = mcrypt_generic($this->resTd, $varValue);
$strEncrypted = base64_encode($iv.$strEncrypted);
-
mcrypt_generic_deinit($this->resTd);
+
return $strEncrypted;
}
@@ -120,28 +130,38 @@ public function encrypt($strValue)
* @param mixed
* @return string
*/
- public function decrypt($strValue)
+ public function decrypt($varValue)
{
- if ($strValue == '')
+ // Recursively decrypt arrays
+ if (is_array($varValue))
{
- return '';
+ foreach ($varValue as $k=>$v)
+ {
+ $varValue[$k] = $this->decrypt($v);
+ }
+
+ return $varValue;
}
- $strValue = base64_decode($strValue);
+ if ($varValue == '')
+ {
+ return '';
+ }
+ $varValue = base64_decode($varValue);
$ivsize = mcrypt_enc_get_iv_size($this->resTd);
- $iv = substr($strValue, 0, $ivsize);
- $strValue = substr($strValue, $ivsize);
+ $iv = substr($varValue, 0, $ivsize);
+ $varValue = substr($varValue, $ivsize);
- if ($strValue == '')
+ if ($varValue == '')
{
return '';
}
mcrypt_generic_init($this->resTd, md5($GLOBALS['TL_CONFIG']['encryptionKey']), $iv);
- $strDecrypted = mdecrypt_generic($this->resTd, $strValue);
-
+ $strDecrypted = mdecrypt_generic($this->resTd, $varValue);
mcrypt_generic_deinit($this->resTd);
+
return $strDecrypted;
}
}
View
14 system/libraries/Widget.php
@@ -168,7 +168,13 @@ public function __set($strKey, $varValue)
break;
case 'value':
- $this->varValue = $varValue;
+ // Decrypt the value if it is encrypted
+ $this->varValue = deserialize($varValue);
+ if ($this->arrConfiguration['encrypt'])
+ {
+ $this->import('Encryption');
+ $this->varValue = $this->Encryption->decrypt($this->varValue);
+ }
break;
case 'class':
@@ -253,6 +259,12 @@ public function __get($strKey)
break;
case 'value':
+ // Encrypt the value
+ if ($this->arrConfiguration['encrypt'])
+ {
+ $this->import('Encryption');
+ return $this->Encryption->encrypt($this->varValue);
+ }
return $this->varValue;
break;
View
13 system/modules/backend/DataContainer.php
@@ -199,13 +199,6 @@ protected function row()
$xlabel .= ' <a href="' . $this->addToUrl('key=list') . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['lw_import'][1]) . '" onclick="Backend.getScrollOffset();">' . $this->generateImage('tablewizard.gif', $GLOBALS['TL_LANG']['MSC']['tw_import'][0], 'style="vertical-align:text-bottom;"') . '</a>';
}
- // Decrypt the value if it is encrypted
- if ($arrData['eval']['encrypt'])
- {
- $this->import('Encryption');
- $this->varValue = $this->Encryption->decrypt($this->varValue);
- }
-
// Input field callback
if (is_array($arrData['input_field_callback']))
{
@@ -278,12 +271,6 @@ protected function row()
$varValue = serialize($varValue);
}
- // Encrypt the value
- if ($arrData['eval']['encrypt'])
- {
- $varValue = $this->Encryption->encrypt($varValue);
- }
-
// Save the current value
try
{
View
4 system/modules/backend/ImageSize.php
@@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
View
4 system/modules/backend/InputUnit.php
@@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
View
4 system/modules/backend/ListWizard.php
@@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
View
4 system/modules/backend/ModuleWizard.php
@@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
View
4 system/modules/backend/OptionWizard.php
@@ -62,10 +62,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
View
4 system/modules/backend/TableWizard.php
@@ -74,10 +74,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'rows':
$this->intRows = $varValue;
break;
View
4 system/modules/backend/TextField.php
@@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
View
4 system/modules/backend/TimePeriod.php
@@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
View
4 system/modules/backend/TrblField.php
@@ -68,10 +68,6 @@ public function __set($strKey, $varValue)
{
switch ($strKey)
{
- case 'value':
- $this->varValue = deserialize($varValue);
- break;
-
case 'maxlength':
$this->arrAttributes[$strKey] = ($varValue > 0) ? $varValue : '';
break;
View
9 system/tmp/autoload.csv
@@ -83,3 +83,12 @@
"BackendModule","system/modules/backend/BackendModule.php"
"RepositoryBackendModule","system/modules/rep_client/RepositoryBackendModule.php"
"DatabaseInstaller","system/modules/rep_client/DatabaseInstaller.php"
+"Newsletter","system/modules/newsletter/Newsletter.php"
+"Password","system/modules/backend/Password.php"
+"Encryption","system/libraries/Encryption.php"
+"ContentAlias","system/modules/frontend/ContentAlias.php"
+"FileTree","system/modules/backend/FileTree.php"
+"ImageSize","system/modules/backend/ImageSize.php"
+"TrblField","system/modules/backend/TrblField.php"
+"RadioTable","system/modules/backend/RadioTable.php"
+"RadioButton","system/modules/backend/RadioButton.php"
View
1 system/tmp/classes.csv
@@ -29,3 +29,4 @@
"ModuleFaqList","1"
"ModuleSearch","1"
"RepositoryManager","1"
+"ContentAlias","1"
View
9 system/tmp/templates.csv
@@ -37,15 +37,18 @@
"mod_faqlist.html5","system/modules/faq/templates/mod_faqlist.html5"
"mod_search_advanced.html5","system/modules/frontend/templates/mod_search_advanced.html5"
"mod_search.html5","system/modules/frontend/templates/mod_search.html5"
-"ce_headline.html5","system/modules/frontend/templates/ce_headline.html5"
-"ce_accordion.html5","system/modules/frontend/templates/ce_accordion.html5"
-"ce_text.html5","system/modules/frontend/templates/ce_text.html5"
"search_default.html5","system/modules/frontend/templates/search_default.html5"
"be_preview.html5","system/modules/backend/templates/be_preview.html5"
"mod_logout_1cl.html5","system/modules/frontend/templates/mod_logout_1cl.html5"
"be_switch.html5","system/modules/backend/templates/be_switch.html5"
"repository_mgrlist.html5","system/modules/rep_client/templates/repository_mgrlist.html5"
"repository_mgrupdt.html5","system/modules/rep_client/templates/repository_mgrupdt.html5"
+"be_login.html5","system/modules/backend/templates/be_login.html5"
+"be_widget_pw.html5","system/modules/backend/templates/be_widget_pw.html5"
+"ce_headline.html5","system/modules/frontend/templates/ce_headline.html5"
+"ce_accordion.html5","system/modules/frontend/templates/ce_accordion.html5"
+"ce_text.html5","system/modules/frontend/templates/ce_text.html5"
+"be_widget_rdo.html5","system/modules/backend/templates/be_widget_rdo.html5"
"be_widget_chk.html5","system/modules/backend/templates/be_widget_chk.html5"
"be_widget.html5","system/modules/backend/templates/be_widget.html5"
"be_main.html5","system/modules/backend/templates/be_main.html5"

0 comments on commit f786f79

Please sign in to comment.