#!/bin/bash # Patch apllying tool template # v0.1.2 # (c) Copyright 2013. Magento Inc. # # DO NOT CHANGE ANY LINE IN THIS FILE. # 1. Check required system tools _check_installed_tools() { local missed="" until [ -z "$1" ]; do type -t $1 >/dev/null 2>/dev/null if (( $? != 0 )); then missed="$missed $1" fi shift done echo $missed } REQUIRED_UTILS='sed patch' MISSED_REQUIRED_TOOLS=`_check_installed_tools $REQUIRED_UTILS` if (( `echo $MISSED_REQUIRED_TOOLS | wc -w` > 0 )); then echo -e "Error! Some required system tools, that are utilized in this sh script, are not installed:\nTool(s) \"$MISSED_REQUIRED_TOOLS\" is(are) missed, please install it(them)." exit 1 fi # 2. Determine bin path for system tools CAT_BIN=`which cat` PATCH_BIN=`which patch` SED_BIN=`which sed` PWD_BIN=`which pwd` BASENAME_BIN=`which basename` BASE_NAME=`$BASENAME_BIN "$0"` # 3. Help menu if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ] then $CAT_BIN << EOFH Usage: sh $BASE_NAME [--help] [-R|--revert] [--list] Apply embedded patch. -R, --revert Revert previously applied embedded patch --list Show list of applied patches --help Show this help message EOFH exit 0 fi # 4. Get "revert" flag and "list applied patches" flag REVERT_FLAG= SHOW_APPLIED_LIST=0 if [ "$1" = "-R" -o "$1" = "--revert" ] then REVERT_FLAG=-R fi if [ "$1" = "--list" ] then SHOW_APPLIED_LIST=1 fi # 5. File pathes CURRENT_DIR=`$PWD_BIN`/ APP_ETC_DIR=`echo "$CURRENT_DIR""app/etc/"` APPLIED_PATCHES_LIST_FILE=`echo "$APP_ETC_DIR""applied.patches.list"` # 6. Show applied patches list if requested if [ "$SHOW_APPLIED_LIST" -eq 1 ] ; then echo -e "Applied/reverted patches list:" if [ -e "$APPLIED_PATCHES_LIST_FILE" ] then if [ ! -r "$APPLIED_PATCHES_LIST_FILE" ] then echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be readable so applied patches list can be shown." exit 1 else $SED_BIN -n "/SUP-\|SUPEE-/p" $APPLIED_PATCHES_LIST_FILE fi else echo "" fi exit 0 fi # 7. Check applied patches track file and its directory _check_files() { if [ ! -e "$APP_ETC_DIR" ] then echo "ERROR: \"$APP_ETC_DIR\" must exist for proper tool work." exit 1 fi if [ ! -w "$APP_ETC_DIR" ] then echo "ERROR: \"$APP_ETC_DIR\" must be writeable for proper tool work." exit 1 fi if [ -e "$APPLIED_PATCHES_LIST_FILE" ] then if [ ! -w "$APPLIED_PATCHES_LIST_FILE" ] then echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be writeable for proper tool work." exit 1 fi fi } _check_files # 8. Apply/revert patch # Note: there is no need to check files permissions for files to be patched. # "patch" tool will not modify any file if there is not enough permissions for all files to be modified. # Get start points for additional information and patch data SKIP_LINES=$((`$SED_BIN -n "/^__PATCHFILE_FOLLOWS__$/=" "$CURRENT_DIR""$BASE_NAME"` + 1)) ADDITIONAL_INFO_LINE=$(($SKIP_LINES - 3))p _apply_revert_patch() { DRY_RUN_FLAG= if [ "$1" = "dry-run" ] then DRY_RUN_FLAG=" --dry-run" echo "Checking if patch can be applied/reverted successfully..." fi PATCH_APPLY_REVERT_RESULT=`$SED_BIN -e '1,/^__PATCHFILE_FOLLOWS__$/d' "$CURRENT_DIR""$BASE_NAME" | $PATCH_BIN $DRY_RUN_FLAG $REVERT_FLAG -p0` PATCH_APPLY_REVERT_STATUS=$? if [ $PATCH_APPLY_REVERT_STATUS -eq 1 ] ; then echo -e "ERROR: Patch can't be applied/reverted successfully.\n\n$PATCH_APPLY_REVERT_RESULT" exit 1 fi if [ $PATCH_APPLY_REVERT_STATUS -eq 2 ] ; then echo -e "ERROR: Patch can't be applied/reverted successfully." exit 2 fi } REVERTED_PATCH_MARK= if [ -n "$REVERT_FLAG" ] then REVERTED_PATCH_MARK=" | REVERTED" fi _apply_revert_patch dry-run _apply_revert_patch # 9. Track patch applying result echo "Patch was applied/reverted successfully." ADDITIONAL_INFO=`$SED_BIN -n ""$ADDITIONAL_INFO_LINE"" "$CURRENT_DIR""$BASE_NAME"` APPLIED_REVERTED_ON_DATE=`date -u +"%F %T UTC"` APPLIED_REVERTED_PATCH_INFO=`echo -n "$APPLIED_REVERTED_ON_DATE"" | ""$ADDITIONAL_INFO""$REVERTED_PATCH_MARK"` echo -e "$APPLIED_REVERTED_PATCH_INFO\n$PATCH_APPLY_REVERT_RESULT\n\n" >> "$APPLIED_PATCHES_LIST_FILE" exit 0 SUPEE-7405-CE-1-7-0-2 | CE_1.7.0.2 | v1 | cf09a622d30efae9499273206790f4ca27675593 | Tue Jan 19 16:06:09 2016 +0200 | 0398c4b951..cf09a622d3 __PATCHFILE_FOLLOWS__ diff --git app/code/core/Mage/Admin/Model/Observer.php app/code/core/Mage/Admin/Model/Observer.php index c30e6ff..4cdecdc 100644 --- app/code/core/Mage/Admin/Model/Observer.php +++ app/code/core/Mage/Admin/Model/Observer.php @@ -34,6 +34,7 @@ class Mage_Admin_Model_Observer { const FLAG_NO_LOGIN = 'no-login'; + /** * Handler for controller_action_predispatch event * @@ -42,16 +43,14 @@ class Mage_Admin_Model_Observer */ public function actionPreDispatchAdmin($observer) { - $session = Mage::getSingleton('admin/session'); /** @var $session Mage_Admin_Model_Session */ + $session = Mage::getSingleton('admin/session'); - /** - * @var $request Mage_Core_Controller_Request_Http - */ + /** @var $request Mage_Core_Controller_Request_Http */ $request = Mage::app()->getRequest(); $user = $session->getUser(); - $requestedActionName = $request->getActionName(); + $requestedActionName = strtolower($request->getActionName()); $openActions = array( 'forgotpassword', 'resetpassword', @@ -67,11 +66,26 @@ class Mage_Admin_Model_Observer } if (!$user || !$user->getId()) { if ($request->getPost('login')) { - $postLogin = $request->getPost('login'); - $username = isset($postLogin['username']) ? $postLogin['username'] : ''; - $password = isset($postLogin['password']) ? $postLogin['password'] : ''; - $session->login($username, $password, $request); - $request->setPost('login', null); + + /** @var Mage_Core_Model_Session $coreSession */ + $coreSession = Mage::getSingleton('core/session'); + + if ($coreSession->validateFormKey($request->getPost("form_key"))) { + $postLogin = $request->getPost('login'); + $username = isset($postLogin['username']) ? $postLogin['username'] : ''; + $password = isset($postLogin['password']) ? $postLogin['password'] : ''; + $session->login($username, $password, $request); + $request->setPost('login', null); + } else { + if ($request && !$request->getParam('messageSent')) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.') + ); + $request->setParam('messageSent', true); + } + } + + $coreSession->renewFormKey(); } if (!$request->getInternallyForwarded()) { $request->setInternallyForwarded(); diff --git app/code/core/Mage/Admin/Model/Redirectpolicy.php app/code/core/Mage/Admin/Model/Redirectpolicy.php new file mode 100644 index 0000000..38da208 --- /dev/null +++ app/code/core/Mage/Admin/Model/Redirectpolicy.php @@ -0,0 +1,72 @@ + + */ +class Mage_Admin_Model_Redirectpolicy +{ + /** + * @var Mage_Adminhtml_Model_Url + */ + protected $_urlModel; + + /** + * @param array $parameters array('urlModel' => object) + */ + public function __construct($parameters = array()) + { + /** @var Mage_Adminhtml_Model_Url _urlModel */ + $this->_urlModel = (!empty($parameters['urlModel'])) ? + $parameters['urlModel'] : Mage::getModel('adminhtml/url'); + } + + /** + * Redirect to startup page after logging in if request contains any params (except security key) + * + * @param Mage_Admin_Model_User $user + * @param Zend_Controller_Request_Http $request + * @param string|null $alternativeUrl + * @return null|string + */ + public function getRedirectUrl(Mage_Admin_Model_User $user, Zend_Controller_Request_Http $request = null, + $alternativeUrl = null) + { + if (empty($request)) { + return; + } + $countRequiredParams = ($this->_urlModel->useSecretKey() + && $request->getParam(Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME)) ? 1 : 0; + $countGetParams = count($request->getUserParams()) + count($request->getQuery()); + + return ($countGetParams > $countRequiredParams) ? + $this->_urlModel->getUrl($user->getStartupPageUrl()) : $alternativeUrl; + } +} diff --git app/code/core/Mage/Admin/Model/Resource/User.php app/code/core/Mage/Admin/Model/Resource/User.php index 70b5f37..e41cbd2 100755 --- app/code/core/Mage/Admin/Model/Resource/User.php +++ app/code/core/Mage/Admin/Model/Resource/User.php @@ -178,7 +178,7 @@ class Mage_Admin_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstrac */ protected function _afterSave(Mage_Core_Model_Abstract $user) { - $user->setExtra(unserialize($user->getExtra())); + $this->_unserializeExtraData($user); return $this; } @@ -190,10 +190,7 @@ class Mage_Admin_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstrac */ protected function _afterLoad(Mage_Core_Model_Abstract $user) { - if (is_string($user->getExtra())) { - $user->setExtra(unserialize($user->getExtra())); - } - return parent::_afterLoad($user); + return parent::_afterLoad($this->_unserializeExtraData($user)); } /** @@ -460,4 +457,21 @@ class Mage_Admin_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstrac return $this; } + + /** + * Unserializes user extra data + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Core_Model_Abstract + */ + protected function _unserializeExtraData(Mage_Core_Model_Abstract $user) + { + try { + $unsterilizedData = Mage::helper('core/unserializeArray')->unserialize($user->getExtra()); + $user->setExtra($unsterilizedData); + } catch (Exception $e) { + $user->setExtra(false); + } + return $user; + } } diff --git app/code/core/Mage/Admin/Model/Session.php app/code/core/Mage/Admin/Model/Session.php index 37f79a8..5fd6f4c 100644 --- app/code/core/Mage/Admin/Model/Session.php +++ app/code/core/Mage/Admin/Model/Session.php @@ -43,11 +43,38 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract protected $_isFirstPageAfterLogin; /** + * @var Mage_Admin_Model_Redirectpolicy + */ + protected $_urlPolicy; + + /** + * @var Mage_Core_Controller_Response_Http + */ + protected $_response; + + /** + * @var Mage_Core_Model_Factory + */ + protected $_factory; + + /** * Class constructor * */ - public function __construct() + public function __construct($parameters = array()) { + /** @var Mage_Admin_Model_Redirectpolicy _urlPolicy */ + $this->_urlPolicy = (!empty($parameters['redirectPolicy'])) ? + $parameters['redirectPolicy'] : Mage::getModel('admin/redirectpolicy'); + + /** @var Mage_Core_Controller_Response_Http _response */ + $this->_response = (!empty($parameters['response'])) ? + $parameters['response'] : new Mage_Core_Controller_Response_Http(); + + /** @var $user Mage_Core_Model_Factory */ + $this->_factory = (!empty($parameters['factory'])) ? + $parameters['factory'] : Mage::getModel('core/factory'); + $this->init('admin'); } @@ -87,7 +114,7 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract try { /** @var $user Mage_Admin_Model_User */ - $user = Mage::getModel('admin/user'); + $user = $this->_factory->getModel('admin/user'); $user->login($username, $password); if ($user->getId()) { $this->renewSession(); @@ -99,11 +126,13 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract $this->setUser($user); $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); - $requestUri = $this->_getRequestUri($request); - if ($requestUri) { + $alternativeUrl = $this->_getRequestUri($request); + $redirectUrl = $this->_urlPolicy->getRedirectUrl($user, $request, $alternativeUrl); + if ($redirectUrl) { Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user)); - header('Location: ' . $requestUri); - exit; + $this->_response->clearHeaders() + ->setRedirect($redirectUrl) + ->sendHeadersAndExit(); } } else { Mage::throwException(Mage::helper('adminhtml')->__('Invalid User Name or Password.')); diff --git app/code/core/Mage/Admin/Model/User.php app/code/core/Mage/Admin/Model/User.php index 34d8b35..57ec644 100644 --- app/code/core/Mage/Admin/Model/User.php +++ app/code/core/Mage/Admin/Model/User.php @@ -502,7 +502,7 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract */ public function validate() { - $errors = array(); + $errors = new ArrayObject(); if (!Zend_Validate::is($this->getUsername(), 'NotEmpty')) { $errors[] = Mage::helper('adminhtml')->__('User Name is required field.'); @@ -534,16 +534,21 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract if ($this->hasPasswordConfirmation() && $this->getNewPassword() != $this->getPasswordConfirmation()) { $errors[] = Mage::helper('adminhtml')->__('Password confirmation must be same as password.'); } + + Mage::dispatchEvent('admin_user_validate', array( + 'user' => $this, + 'errors' => $errors, + )); } if ($this->userExists()) { $errors[] = Mage::helper('adminhtml')->__('A user with the same user name or email aleady exists.'); } - if (empty($errors)) { + if (count($errors) === 0) { return true; } - return $errors; + return (array)$errors; } /** diff --git app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php index 5b4eb49..ca728b2 100644 --- app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php +++ app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php @@ -187,8 +187,14 @@ class Mage_Adminhtml_Block_Sales_Order_View_Tab_History */ public function getItemComment(array $item) { - $allowedTags = array('b','br','strong','i','u'); - return (isset($item['comment']) ? $this->escapeHtml($item['comment'], $allowedTags) : ''); + $strItemComment = ''; + if (isset($item['comment'])) { + $allowedTags = array('b', 'br', 'strong', 'i', 'u', 'a'); + /** @var Mage_Adminhtml_Helper_Sales $salesHelper */ + $salesHelper = Mage::helper('adminhtml/sales'); + $strItemComment = $salesHelper->escapeHtmlWithLinks($item['comment'], $allowedTags); + } + return $strItemComment; } /** diff --git app/code/core/Mage/Adminhtml/Block/Widget/Grid.php app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index c5c38be..6f6bbb1 100644 --- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -978,7 +978,10 @@ class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget $row[] = $column->getRowFieldExport($item); } } - $adapter->streamWriteCsv($row); + + $adapter->streamWriteCsv( + Mage::helper("core")->getEscapedCSVData($row) + ); } /** @@ -1008,7 +1011,9 @@ class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget $this->_exportIterateCollection('_exportCsvItem', array($io)); if ($this->getCountTotals()) { - $io->streamWriteCsv($this->_getExportTotals()); + $io->streamWriteCsv( + Mage::helper("core")->getEscapedCSVData($this->_getExportTotals()) + ); } $io->streamUnlock(); @@ -1674,5 +1679,4 @@ class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget $res = parent::getRowUrl($item); return ($res ? $res : '#'); } - } diff --git app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php index ef2e758..f7aaedf 100644 --- app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php +++ app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php @@ -87,7 +87,7 @@ class Mage_Adminhtml_Helper_Catalog_Product_Edit_Action_Attribute extends Mage_C { $session = Mage::getSingleton('adminhtml/session'); - if ($this->_getRequest()->isPost() && $this->_getRequest()->getActionName() == 'edit') { + if ($this->_getRequest()->isPost() && strtolower($this->_getRequest()->getActionName()) == 'edit') { $session->setProductIds($this->_getRequest()->getParam('product', null)); } diff --git app/code/core/Mage/Adminhtml/Helper/Sales.php app/code/core/Mage/Adminhtml/Helper/Sales.php index f80cbd1..1ce8780 100644 --- app/code/core/Mage/Adminhtml/Helper/Sales.php +++ app/code/core/Mage/Adminhtml/Helper/Sales.php @@ -110,4 +110,47 @@ class Mage_Adminhtml_Helper_Sales extends Mage_Core_Helper_Abstract } return $collection; } + + /** + * Escape string preserving links + * + * @param array|string $data + * @param null|array $allowedTags + * @return string + */ + public function escapeHtmlWithLinks($data, $allowedTags = null) + { + if (!empty($data) && is_array($allowedTags) && in_array('a', $allowedTags)) { + $links = []; + $i = 1; + $regexp = "/]*href\s*?=\s*?([\"\']??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU"; + while (preg_match($regexp, $data, $matches)) { + //Revert the sprintf escaping + $url = str_replace('%%', '%', $matches[2]); + $text = str_replace('%%', '%', $matches[3]); + //Check for an valid url + if ($url) { + $urlScheme = strtolower(parse_url($url, PHP_URL_SCHEME)); + if ($urlScheme !== 'http' && $urlScheme !== 'https') { + $url = null; + } + } + //Use hash tag as fallback + if (!$url) { + $url = '#'; + } + //Recreate a minimalistic secure a tag + $links[] = sprintf( + '%s', + htmlspecialchars($url, ENT_QUOTES, 'UTF-8', false), + parent::escapeHtml($text) + ); + $data = str_replace($matches[0], '%' . $i . '$s', $data); + ++$i; + } + $data = parent::escapeHtml($data, $allowedTags); + return vsprintf($data, $links); + } + return parent::escapeHtml($data, $allowedTags); + } } diff --git app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php index 11d421d..e302ac0 100644 --- app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php +++ app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php @@ -48,7 +48,7 @@ class Mage_Adminhtml_Model_System_Config_Backend_File extends Mage_Core_Model_Co protected function _beforeSave() { $value = $this->getValue(); - if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']){ + if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) { $uploadDir = $this->_getUploadDir(); @@ -61,7 +61,7 @@ class Mage_Adminhtml_Model_System_Config_Backend_File extends Mage_Core_Model_Co $uploader = new Mage_Core_Model_File_Uploader($file); $uploader->setAllowedExtensions($this->_getAllowedExtensions()); $uploader->setAllowRenameFiles(true); - $uploader->addValidateCallback('size', $this, 'validateMaxSize'); + $this->addValidators( $uploader ); $result = $uploader->save($uploadDir); } catch (Exception $e) { @@ -202,4 +202,14 @@ class Mage_Adminhtml_Model_System_Config_Backend_File extends Mage_Core_Model_Co { return array(); } + + /** + * Add validators for uploading + * + * @param Mage_Core_Model_File_Uploader $uploader + */ + protected function addValidators(Mage_Core_Model_File_Uploader $uploader) + { + $uploader->addValidateCallback('size', $this, 'validateMaxSize'); + } } diff --git app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php index 02c4023..dd13bde 100644 --- app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php +++ app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php @@ -43,4 +43,17 @@ class Mage_Adminhtml_Model_System_Config_Backend_Image extends Mage_Adminhtml_Mo { return array('jpg', 'jpeg', 'gif', 'png'); } + + /** + * Overwritten parent method for adding validators + * + * @param Mage_Core_Model_File_Uploader $uploader + */ + protected function addValidators(Mage_Core_Model_File_Uploader $uploader) + { + parent::addValidators($uploader); + $validator = new Mage_Core_Model_File_Validator_Image(); + $validator->setAllowedImageTypes($this->_getAllowedExtensions()); + $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, $validator, 'validate'); + } } diff --git app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php index a562116..391c12f 100644 --- app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php +++ app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php @@ -77,7 +77,7 @@ class Mage_Adminhtml_Model_System_Config_Backend_Image_Favicon extends Mage_Admi */ protected function _getAllowedExtensions() { - return array('ico', 'png', 'gif', 'jpg', 'jpeg', 'apng', 'svg'); + return array('ico', 'png', 'gif', 'jpg', 'jpeg', 'apng'); } /** @@ -86,7 +86,8 @@ class Mage_Adminhtml_Model_System_Config_Backend_Image_Favicon extends Mage_Admi * @param $token * @return string */ - protected function _getUploadRoot($token) { + protected function _getUploadRoot($token) + { return Mage::getBaseDir($token); } } diff --git app/code/core/Mage/Adminhtml/controllers/IndexController.php app/code/core/Mage/Adminhtml/controllers/IndexController.php index 78d2845..724dd73 100644 --- app/code/core/Mage/Adminhtml/controllers/IndexController.php +++ app/code/core/Mage/Adminhtml/controllers/IndexController.php @@ -224,38 +224,51 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action */ public function forgotpasswordAction() { - $email = (string) $this->getRequest()->getParam('email'); $params = $this->getRequest()->getParams(); - if (!empty($email) && !empty($params)) { - // Validate received data to be an email address - if (Zend_Validate::is($email, 'EmailAddress')) { - $collection = Mage::getResourceModel('admin/user_collection'); - /** @var $collection Mage_Admin_Model_Resource_User_Collection */ - $collection->addFieldToFilter('email', $email); - $collection->load(false); - - if ($collection->getSize() > 0) { - foreach ($collection as $item) { - $user = Mage::getModel('admin/user')->load($item->getId()); - if ($user->getId()) { - $newResetPasswordLinkToken = Mage::helper('admin')->generateResetPasswordLinkToken(); - $user->changeResetPasswordLinkToken($newResetPasswordLinkToken); - $user->save(); - $user->sendPasswordResetConfirmationEmail(); + if (!(empty($params))) { + $email = (string)$this->getRequest()->getParam('email'); + + if ($this->_validateFormKey()) { + if (!empty($email)) { + // Validate received data to be an email address + if (Zend_Validate::is($email, 'EmailAddress')) { + $collection = Mage::getResourceModel('admin/user_collection'); + /** @var $collection Mage_Admin_Model_Resource_User_Collection */ + $collection->addFieldToFilter('email', $email); + $collection->load(false); + + if ($collection->getSize() > 0) { + foreach ($collection as $item) { + /** @var Mage_Admin_Model_User $user */ + $user = Mage::getModel('admin/user')->load($item->getId()); + if ($user->getId()) { + $newResetPasswordLinkToken = Mage::helper('admin')->generateResetPasswordLinkToken(); + $user->changeResetPasswordLinkToken($newResetPasswordLinkToken); + $user->save(); + $user->sendPasswordResetConfirmationEmail(); + } + break; + } } - break; + $this->_getSession() + ->addSuccess( + $this->__( + 'If there is an account associated with %s you will receive an email with a link to reset your password.', + Mage::helper('adminhtml')->escapeHtml($email) + ) + ); + $this->_redirect('*/*/login'); + return; + } else { + $this->_getSession()->addError($this->__('Invalid email address.')); } + } else { + $this->_getSession()->addError($this->__('The email address is empty.')); } - $this->_getSession() - ->addSuccess(Mage::helper('adminhtml')->__('If there is an account associated with %s you will receive an email with a link to reset your password.', Mage::helper('adminhtml')->escapeHtml($email))); - $this->_redirect('*/*/login'); - return; } else { - $this->_getSession()->addError($this->__('Invalid email address.')); + $this->_getSession()->addError($this->__('Invalid Form Key. Please refresh the page.')); } - } elseif (!empty($params)) { - $this->_getSession()->addError(Mage::helper('adminhtml')->__('The email address is empty.')); } $this->loadLayout(); $this->renderLayout(); @@ -290,10 +303,10 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action */ public function resetPasswordPostAction() { - $resetPasswordLinkToken = (string) $this->getRequest()->getQuery('token'); - $userId = (int) $this->getRequest()->getQuery('id'); - $password = (string) $this->getRequest()->getPost('password'); - $passwordConfirmation = (string) $this->getRequest()->getPost('confirmation'); + $resetPasswordLinkToken = (string)$this->getRequest()->getQuery('token'); + $userId = (int)$this->getRequest()->getQuery('id'); + $password = (string)$this->getRequest()->getPost('password'); + $passwordConfirmation = (string)$this->getRequest()->getPost('confirmation'); try { $this->_validateResetPasswordLinkToken($userId, $resetPasswordLinkToken); @@ -303,6 +316,12 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action return; } + if (!$this->_validateFormKey()) { + $this->_getSession()->addError(Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.')); + $this->_redirect('*/*/'); + return; + } + $errorMessages = array(); if (iconv_strlen($password) <= 0) { array_push($errorMessages, Mage::helper('adminhtml')->__('New password field cannot be empty.')); diff --git app/code/core/Mage/Authorizenet/Helper/Admin.php app/code/core/Mage/Authorizenet/Helper/Admin.php new file mode 100644 index 0000000..a669db6 --- /dev/null +++ app/code/core/Mage/Authorizenet/Helper/Admin.php @@ -0,0 +1,77 @@ + + */ +class Mage_Authorizenet_Helper_Admin extends Mage_Authorizenet_Helper_Data +{ + + /** + * Retrieve place order url + * @param array $params + * @return string + */ + public function getSuccessOrderUrl($params) + { + $url = parent::getSuccessOrderUrl($params); + + if ($params['controller_action_name'] === 'sales_order_create' + or $params['controller_action_name'] === 'sales_order_edit' + ) { + /** @var Mage_Sales_Model_Order $order */ + $order = Mage::getModel('sales/order'); + $order->loadByIncrementId($params['x_invoice_num']); + + $url = $this->getAdminUrl('adminhtml/sales_order/view', array('order_id' => $order->getId())); + } + + return $url; + } + + /** + * Retrieve save order url params + * + * @param string $controller + * @return array + */ + public function getSaveOrderUrlParams($controller) + { + $route = parent::getSaveOrderUrlParams($controller); + + if ($controller === "sales_order_create" or $controller === "sales_order_edit") { + $route['action'] = 'save'; + $route['controller'] = 'sales_order_create'; + $route['module'] = 'admin'; + } + + return $route; + } +} diff --git app/code/core/Mage/Authorizenet/Helper/Data.php app/code/core/Mage/Authorizenet/Helper/Data.php index 2786189..9be381d 100755 --- app/code/core/Mage/Authorizenet/Helper/Data.php +++ app/code/core/Mage/Authorizenet/Helper/Data.php @@ -72,51 +72,23 @@ class Mage_Authorizenet_Helper_Data extends Mage_Core_Helper_Abstract public function getSaveOrderUrlParams($controller) { $route = array(); - switch ($controller) { - case 'onepage': - $route['action'] = 'saveOrder'; - $route['controller'] = 'onepage'; - $route['module'] = 'checkout'; - break; - - case 'sales_order_create': - case 'sales_order_edit': - $route['action'] = 'save'; - $route['controller'] = 'sales_order_create'; - $route['module'] = 'admin'; - break; - - default: - break; + if ($controller === "onepage") { + $route['action'] = 'saveOrder'; + $route['controller'] = 'onepage'; + $route['module'] = 'checkout'; } return $route; } /** - * Retrieve redirect ifrmae url - * - * @param array params + * Retrieve redirect iframe url + * @param $params * @return string */ public function getRedirectIframeUrl($params) { - switch ($params['controller_action_name']) { - case 'onepage': - $route = 'authorizenet/directpost_payment/redirect'; - break; - - case 'sales_order_create': - case 'sales_order_edit': - $route = 'adminhtml/authorizenet_directpost_payment/redirect'; - break; - - default: - $route = 'authorizenet/directpost_payment/redirect'; - break; - } - - return $this->_getUrl($route, $params); + return $this->_getUrl('authorizenet/directpost_payment/redirect', $params); } /** @@ -147,25 +119,7 @@ class Mage_Authorizenet_Helper_Data extends Mage_Core_Helper_Abstract */ public function getSuccessOrderUrl($params) { - $param = array(); - switch ($params['controller_action_name']) { - case 'onepage': - $route = 'checkout/onepage/success'; - break; - - case 'sales_order_create': - case 'sales_order_edit': - $route = 'adminhtml/sales_order/view'; - $order = Mage::getModel('sales/order')->loadByIncrementId($params['x_invoice_num']); - $param['order_id'] = $order->getId(); - return $this->getAdminUrl($route, $param); - - default : - $route = 'checkout/onepage/success'; - break; - } - - return $this->_getUrl($route, $param); + return $this->_getUrl('checkout/onepage/success', array()); } /** diff --git app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php index 0243186..0239198 100644 --- app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php +++ app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php @@ -86,9 +86,9 @@ class Mage_Authorizenet_Adminhtml_Authorizenet_Directpost_PaymentController } if (isset($paymentParam['method'])) { - $saveOrderFlag = Mage::getStoreConfig('payment/'.$paymentParam['method'].'/create_order_before'); + $result = array(); - $params = Mage::helper('authorizenet')->getSaveOrderUrlParams($controller); + //create order partially $this->_getOrderCreateModel()->setPaymentData($paymentParam); $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentParam); @@ -170,7 +170,7 @@ class Mage_Authorizenet_Adminhtml_Authorizenet_Directpost_PaymentController && isset($redirectParams['x_invoice_num']) && isset($redirectParams['controller_action_name']) ) { - $params['redirect_parent'] = Mage::helper('authorizenet')->getSuccessOrderUrl($redirectParams); + $params['redirect_parent'] = Mage::helper('authorizenet/admin')->getSuccessOrderUrl($redirectParams); $this->_getDirectPostSession()->unsetData('quote_id'); //cancel old order $oldOrder = $this->_getOrderCreateModel()->getSession()->getOrder(); diff --git app/code/core/Mage/Captcha/etc/config.xml app/code/core/Mage/Captcha/etc/config.xml index 0377c43..817e6f6 100755 --- app/code/core/Mage/Captcha/etc/config.xml +++ app/code/core/Mage/Captcha/etc/config.xml @@ -54,14 +54,14 @@ - + captcha/observer checkUserLogin - + @@ -94,7 +94,7 @@ - + captcha/observer @@ -105,7 +105,7 @@ checkRegisterCheckout - + diff --git app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php index 5dd4aeb..7c63cfc 100644 --- app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php +++ app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php @@ -135,7 +135,7 @@ class Mage_Catalog_Block_Product_View_Options_Type_Select . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="' . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />' . ''; + . $this->escapeHtml($_value->getTitle()) . ' ' . $priceStr . ''; if ($_option->getIsRequire()) { $selectHtml .= '