|
| 1 | +#!/bin/bash |
| 2 | +# Patch apllying tool template |
| 3 | +# v0.1.2 |
| 4 | +# (c) Copyright 2013. Magento Inc. |
| 5 | +# |
| 6 | +# DO NOT CHANGE ANY LINE IN THIS FILE. |
| 7 | + |
| 8 | +# 1. Check required system tools |
| 9 | +_check_installed_tools() { |
| 10 | + local missed="" |
| 11 | + |
| 12 | + until [ -z "$1" ]; do |
| 13 | + type -t $1 >/dev/null 2>/dev/null |
| 14 | + if (( $? != 0 )); then |
| 15 | + missed="$missed $1" |
| 16 | + fi |
| 17 | + shift |
| 18 | + done |
| 19 | + |
| 20 | + echo $missed |
| 21 | +} |
| 22 | + |
| 23 | +REQUIRED_UTILS='sed patch' |
| 24 | +MISSED_REQUIRED_TOOLS=`_check_installed_tools $REQUIRED_UTILS` |
| 25 | +if (( `echo $MISSED_REQUIRED_TOOLS | wc -w` > 0 )); |
| 26 | +then |
| 27 | + 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)." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# 2. Determine bin path for system tools |
| 32 | +CAT_BIN=`which cat` |
| 33 | +PATCH_BIN=`which patch` |
| 34 | +SED_BIN=`which sed` |
| 35 | +PWD_BIN=`which pwd` |
| 36 | +BASENAME_BIN=`which basename` |
| 37 | + |
| 38 | +BASE_NAME=`$BASENAME_BIN "$0"` |
| 39 | + |
| 40 | +# 3. Help menu |
| 41 | +if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ] |
| 42 | +then |
| 43 | + $CAT_BIN << EOFH |
| 44 | +Usage: sh $BASE_NAME [--help] [-R|--revert] [--list] |
| 45 | +Apply embedded patch. |
| 46 | +
|
| 47 | +-R, --revert Revert previously applied embedded patch |
| 48 | +--list Show list of applied patches |
| 49 | +--help Show this help message |
| 50 | +EOFH |
| 51 | + exit 0 |
| 52 | +fi |
| 53 | + |
| 54 | +# 4. Get "revert" flag and "list applied patches" flag |
| 55 | +REVERT_FLAG= |
| 56 | +SHOW_APPLIED_LIST=0 |
| 57 | +if [ "$1" = "-R" -o "$1" = "--revert" ] |
| 58 | +then |
| 59 | + REVERT_FLAG=-R |
| 60 | +fi |
| 61 | +if [ "$1" = "--list" ] |
| 62 | +then |
| 63 | + SHOW_APPLIED_LIST=1 |
| 64 | +fi |
| 65 | + |
| 66 | +# 5. File pathes |
| 67 | +CURRENT_DIR=`$PWD_BIN`/ |
| 68 | +APP_ETC_DIR=`echo "$CURRENT_DIR""app/etc/"` |
| 69 | +APPLIED_PATCHES_LIST_FILE=`echo "$APP_ETC_DIR""applied.patches.list"` |
| 70 | + |
| 71 | +# 6. Show applied patches list if requested |
| 72 | +if [ "$SHOW_APPLIED_LIST" -eq 1 ] ; then |
| 73 | + echo -e "Applied/reverted patches list:" |
| 74 | + if [ -e "$APPLIED_PATCHES_LIST_FILE" ] |
| 75 | + then |
| 76 | + if [ ! -r "$APPLIED_PATCHES_LIST_FILE" ] |
| 77 | + then |
| 78 | + echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be readable so applied patches list can be shown." |
| 79 | + exit 1 |
| 80 | + else |
| 81 | + $SED_BIN -n "/SUP-\|SUPEE-/p" $APPLIED_PATCHES_LIST_FILE |
| 82 | + fi |
| 83 | + else |
| 84 | + echo "<empty>" |
| 85 | + fi |
| 86 | + exit 0 |
| 87 | +fi |
| 88 | + |
| 89 | +# 7. Check applied patches track file and its directory |
| 90 | +_check_files() { |
| 91 | + if [ ! -e "$APP_ETC_DIR" ] |
| 92 | + then |
| 93 | + echo "ERROR: \"$APP_ETC_DIR\" must exist for proper tool work." |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + |
| 97 | + if [ ! -w "$APP_ETC_DIR" ] |
| 98 | + then |
| 99 | + echo "ERROR: \"$APP_ETC_DIR\" must be writeable for proper tool work." |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + |
| 103 | + if [ -e "$APPLIED_PATCHES_LIST_FILE" ] |
| 104 | + then |
| 105 | + if [ ! -w "$APPLIED_PATCHES_LIST_FILE" ] |
| 106 | + then |
| 107 | + echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be writeable for proper tool work." |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + fi |
| 111 | +} |
| 112 | + |
| 113 | +_check_files |
| 114 | + |
| 115 | +# 8. Apply/revert patch |
| 116 | +# Note: there is no need to check files permissions for files to be patched. |
| 117 | +# "patch" tool will not modify any file if there is not enough permissions for all files to be modified. |
| 118 | +# Get start points for additional information and patch data |
| 119 | +SKIP_LINES=$((`$SED_BIN -n "/^__PATCHFILE_FOLLOWS__$/=" "$CURRENT_DIR""$BASE_NAME"` + 1)) |
| 120 | +ADDITIONAL_INFO_LINE=$(($SKIP_LINES - 3))p |
| 121 | + |
| 122 | +_apply_revert_patch() { |
| 123 | + DRY_RUN_FLAG= |
| 124 | + if [ "$1" = "dry-run" ] |
| 125 | + then |
| 126 | + DRY_RUN_FLAG=" --dry-run" |
| 127 | + echo "Checking if patch can be applied/reverted successfully..." |
| 128 | + fi |
| 129 | + PATCH_APPLY_REVERT_RESULT=`$SED_BIN -e '1,/^__PATCHFILE_FOLLOWS__$/d' "$CURRENT_DIR""$BASE_NAME" | $PATCH_BIN $DRY_RUN_FLAG $REVERT_FLAG -p0` |
| 130 | + PATCH_APPLY_REVERT_STATUS=$? |
| 131 | + if [ $PATCH_APPLY_REVERT_STATUS -eq 1 ] ; then |
| 132 | + echo -e "ERROR: Patch can't be applied/reverted successfully.\n\n$PATCH_APPLY_REVERT_RESULT" |
| 133 | + exit 1 |
| 134 | + fi |
| 135 | + if [ $PATCH_APPLY_REVERT_STATUS -eq 2 ] ; then |
| 136 | + echo -e "ERROR: Patch can't be applied/reverted successfully." |
| 137 | + exit 2 |
| 138 | + fi |
| 139 | +} |
| 140 | + |
| 141 | +REVERTED_PATCH_MARK= |
| 142 | +if [ -n "$REVERT_FLAG" ] |
| 143 | +then |
| 144 | + REVERTED_PATCH_MARK=" | REVERTED" |
| 145 | +fi |
| 146 | + |
| 147 | +_apply_revert_patch dry-run |
| 148 | +_apply_revert_patch |
| 149 | + |
| 150 | +# 9. Track patch applying result |
| 151 | +echo "Patch was applied/reverted successfully." |
| 152 | +ADDITIONAL_INFO=`$SED_BIN -n ""$ADDITIONAL_INFO_LINE"" "$CURRENT_DIR""$BASE_NAME"` |
| 153 | +APPLIED_REVERTED_ON_DATE=`date -u +"%F %T UTC"` |
| 154 | +APPLIED_REVERTED_PATCH_INFO=`echo -n "$APPLIED_REVERTED_ON_DATE"" | ""$ADDITIONAL_INFO""$REVERTED_PATCH_MARK"` |
| 155 | +echo -e "$APPLIED_REVERTED_PATCH_INFO\n$PATCH_APPLY_REVERT_RESULT\n\n" >> "$APPLIED_PATCHES_LIST_FILE" |
| 156 | + |
| 157 | +exit 0 |
| 158 | + |
| 159 | + |
| 160 | +SUPEE-2677 | EE_1.13.0.2 | v2 | d20e6763cd0df70c4ac6e418c9775a1ff0f2618f | Tue Jan 14 17:49:25 2014 +0200 | v1.13.0.2..HEAD |
| 161 | + |
| 162 | +__PATCHFILE_FOLLOWS__ |
| 163 | +diff --git app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php |
| 164 | +index 9e8d6be..0ac6a11 100644 |
| 165 | +--- app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php |
| 166 | ++++ app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php |
| 167 | +@@ -49,6 +49,11 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract |
| 168 | + */ |
| 169 | + protected $_storeId = null; |
| 170 | + |
| 171 | ++ /** |
| 172 | ++ * Images Storage root directory |
| 173 | ++ * @var string |
| 174 | ++ */ |
| 175 | ++ protected $_storageRoot; |
| 176 | + |
| 177 | + /** |
| 178 | + * Set a specified store ID value |
| 179 | +@@ -68,8 +73,13 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract |
| 180 | + */ |
| 181 | + public function getStorageRoot() |
| 182 | + { |
| 183 | +- return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY |
| 184 | +- . DS; |
| 185 | ++ if (!$this->_storageRoot) { |
| 186 | ++ $this->_storageRoot = realpath( |
| 187 | ++ Mage::getConfig()->getOptions()->getMediaDir() |
| 188 | ++ . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY |
| 189 | ++ ) . DS; |
| 190 | ++ } |
| 191 | ++ return $this->_storageRoot; |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | +@@ -198,10 +208,10 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract |
| 196 | + { |
| 197 | + if (!$this->_currentPath) { |
| 198 | + $currentPath = $this->getStorageRoot(); |
| 199 | +- $path = $this->_getRequest()->getParam($this->getTreeNodeName()); |
| 200 | +- if ($path) { |
| 201 | +- $path = $this->convertIdToPath($path); |
| 202 | +- if (is_dir($path)) { |
| 203 | ++ $node = $this->_getRequest()->getParam($this->getTreeNodeName()); |
| 204 | ++ if ($node) { |
| 205 | ++ $path = realpath($this->convertIdToPath($node)); |
| 206 | ++ if (is_dir($path) && false !== stripos($path, $currentPath)) { |
| 207 | + $currentPath = $path; |
| 208 | + } |
| 209 | + } |
| 210 | +@@ -223,7 +233,7 @@ class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract |
| 211 | + public function getCurrentUrl() |
| 212 | + { |
| 213 | + if (!$this->_currentUrl) { |
| 214 | +- $path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath()); |
| 215 | ++ $path = str_replace(realpath(Mage::getConfig()->getOptions()->getMediaDir()), '', $this->getCurrentPath()); |
| 216 | + $path = trim($path, DS); |
| 217 | + $this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') . |
| 218 | + $this->convertPathToUrl($path) . '/'; |
| 219 | +diff --git app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php |
| 220 | +index 19b3f45..af58ce3 100644 |
| 221 | +--- app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php |
| 222 | ++++ app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php |
| 223 | +@@ -89,7 +89,7 @@ class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object |
| 224 | + foreach ($collection as $key => $value) { |
| 225 | + $rootChildParts = explode(DIRECTORY_SEPARATOR, substr($value->getFilename(), $storageRootLength)); |
| 226 | + |
| 227 | +- if (array_key_exists($rootChildParts[0], $conditions['plain']) |
| 228 | ++ if (array_key_exists(end($rootChildParts), $conditions['plain']) |
| 229 | + || ($regExp && preg_match($regExp, $value->getFilename()))) { |
| 230 | + $collection->removeItemByKey($key); |
| 231 | + } |
0 commit comments