Changeset 2887106
- Timestamp:
- 03/26/2023 01:34:05 PM (3 years ago)
- Location:
- picgrab/trunk
- Files:
-
- 5 edited
-
picgrab.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
resize.php (modified) (1 diff)
-
resizer.php (modified) (2 diffs)
-
std.encryption.class.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
picgrab/trunk/picgrab.php
r467398 r2887106 32 32 33 33 $resizerpath= realpath(dirname(__FILE__).'/resize.php'); 34 $zkey="UNIQUE-".filemtime($resizerpath); 35 $crypt = new encryption_class ;34 35 $crypt = new encryption_class(); 36 36 37 37 $blogurl = get_bloginfo('home'); … … 70 70 $imgurl=$imgurls[$i]; 71 71 $resizeparm = $resizeparms[$i]; 72 $imgurl2 = $resizerbase."?url=".urlencode($crypt->encrypt($ zkey,$imgurl))."&size=".urlencode($crypt->encrypt($zkey,$resizeparm));72 $imgurl2 = $resizerbase."?url=".urlencode($crypt->encrypt($imgurl))."&size=".urlencode($crypt->encrypt($resizeparm)); 73 73 //error_log ($imgurl2); 74 74 $imgtag2 = str_replace ($imgurl,$imgurl2,$imgtag2); -
picgrab/trunk/readme.txt
r467398 r2887106 2 2 Contributors: zlabs 3 3 Tags: pictures, resize, crop, cache 4 Requires at least: 2.55 Tested up to: 3.2.16 Stable tag: 0. 214 Requires at least: 6.1.1 5 Tested up to: 6 Stable tag: 0.3 7 7 8 8 Picgrab is a plugin that download, resize and crop an image on the fly. … … 31 31 Refer to [This post](http://fabrizio.zellini.org/resize-e-crop-immagini-in-php "Crop / Resize script") for more informations on resizer syntax. 32 32 33 PicGrab require Php version >= 5, gd and curl libraries.33 PicGrab require Php version >=8, gd and curl libraries. 34 34 35 35 == Installation == -
picgrab/trunk/resize.php
r98061 r2887106 38 38 if (defined ('CRYPT') && CRYPT) { 39 39 $resizepath= realpath(dirname(__FILE__).'/resize.php'); 40 $key="UNIQUE-".filemtime($resizepath); 41 $crypt = new encryption_class ;42 $dimensions = $crypt->decrypt($ key, $dimensions);43 $imgpath = $crypt->decrypt($ key, $imgpath);40 41 $crypt = new encryption_class(); 42 $dimensions = $crypt->decrypt($dimensions); 43 $imgpath = $crypt->decrypt($imgpath); 44 44 } 45 45 if (preg_match ("/resize\.php/i",$imgpath)) { -
picgrab/trunk/resizer.php
r466320 r2887106 55 55 curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); 56 56 curl_setopt($curl, CURLOPT_TIMEOUT, 15); 57 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 58 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 57 59 curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 58 60 // get response … … 60 62 $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 61 63 $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE ); 64 $redirectURL = curl_getinfo($curl,CURLINFO_EFFECTIVE_URL ); 62 65 curl_close ($curl); 63 if ($httpCode!=200 && $httpCode!=201){ 64 error_log("httpCode is [$httpCode] for [$url]"); 65 return null; 66 } 67 // parse response 68 return $response; 66 67 // error_log("httpCode is [$httpCode] for [$url]"); 68 if ($httpCode == 301){ 69 return grab($redirectURL, $contentType); 70 } else { 71 if ($httpCode!=200 && $httpCode!=201){ 72 error_log("httpCode is [$httpCode] for [$url]"); 73 return null; 74 } 75 // parse response 76 return $response; 77 } 69 78 } 70 79 -
picgrab/trunk/std.encryption.class.inc
r98061 r2887106 1 1 <?php 2 // ******************************************************************************3 // A reversible password encryption routine by:4 // Copyright 2003-2007 by A J Marston <http://www.tonymarston.net>5 // Distributed under the GNU General Public Licence6 // Modification: May 2007, M. Kolar <http://mkolar.org>:7 // No need for repeating the first character of scramble strings at the end;8 // instead using the exact inverse function transforming $num2 to $num1.9 // ******************************************************************************10 11 2 if (!class_exists('encryption_class')) { 12 3 class encryption_class { 13 4 14 var $scramble1; // 1st string of ASCII characters15 var $scramble2; // 2nd string of ASCII characters16 5 17 var $errors; // array of error messages 18 var $adj; // 1st adjustment value (optional) 19 var $mod; // 2nd adjustment value (optional) 6 function base64url_encode( $data ){ 7 return rtrim( strtr( base64_encode( $data ), '+/', '-_'), '='); 8 } 9 function base64url_decode( $data ){ 10 return base64_decode( strtr( $data, '-_', '+/') . str_repeat('=', 3 - ( 3 + strlen( $data )) % 4 )); 11 } 12 20 13 21 14 // **************************************************************************** 22 15 // class constructor 23 16 // **************************************************************************** 24 function encryption_class () 25 { 26 $this->errors = array(); 17 function __construct () { 27 18 28 // Each of these two strings must contain the same characters, but in a different order. 29 // Use only printable characters from the ASCII table. 30 // Do not use single quote, double quote or backslash as these have special meanings in PHP. 31 // Each character can only appear once in each string. 32 $this->scramble1 = '! #$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'; 33 $this->scramble2 = 'f^jAE]okIOzU[2&q1{3`h5w_794p@6s8?BgP>dFV=m D<TcS%Ze|r:lGK/uCy.Jx)HiQ!#$~(;Lt-R}Ma,NvW+Ynb*0X'; 34 35 if (strlen($this->scramble1) <> strlen($this->scramble2)) { 36 trigger_error('** SCRAMBLE1 is not same length as SCRAMBLE2 **', E_USER_ERROR); 37 } // if 38 39 $this->adj = 1.75; // this value is added to the rolling fudgefactors 40 $this->mod = 3; // if divisible by this the adjustment is made negative 41 42 } // constructor 19 } 43 20 44 21 // **************************************************************************** 45 function decrypt ($key, $source)46 // decrypt string into its original form47 {48 $this->errors = array();49 22 50 // convert $key into a sequence of numbers 51 $fudgefactor = $this->_convertKey($key); 52 if ($this->errors) return; 23 function decrypt($ciphertext){ 24 $key = "AbsakjIDjjosdx1234"; 25 // $c = base64_decode($ciphertext); 26 $c = $this->base64url_decode($ciphertext); 27 $ivlen = openssl_cipher_iv_length($cipher="aes-128-cbc"); 28 $iv = substr($c, 0, $ivlen); 29 $hmac = substr($c, $ivlen, $sha2len=32); 30 $ciphertext_raw = substr($c, $ivlen+$sha2len); 31 $original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv); 32 33 return $original_plaintext; 53 34 54 if (empty($source)) { 55 $this->errors[] = 'No value has been supplied for decryption'; 56 return; 57 } // if 35 } 36 function encrypt( $plaintext ) { 37 $key = "AbsakjIDjjosdx1234"; 58 38 59 $target = null;60 $factor2 = 0;61 39 62 for ($i = 0; $i < strlen($source); $i++) { 63 // extract a character from $source 64 $char2 = substr($source, $i, 1); 40 $ivlen = openssl_cipher_iv_length($cipher="aes-128-cbc"); 65 41 66 // identify its position in $scramble2 67 $num2 = strpos($this->scramble2, $char2); 68 if ($num2 === false) { 69 $this->errors[] = "Source string contains an invalid character ($char2)"; 70 return; 71 } // if 42 $iv = openssl_random_pseudo_bytes($ivlen); 43 $ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv); 44 $hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary=true); 45 //$ciphertext = base64_encode( $iv.$hmac.$ciphertext_raw ); 46 $ciphertext = $this->base64url_encode( $iv.$hmac.$ciphertext_raw ); 72 47 73 // get an adjustment value using $fudgefactor 74 $adj = $this->_applyFudgeFactor($fudgefactor); 48 return $ciphertext; 75 49 76 $factor1 = $factor2 + $adj; // accumulate in $factor1 77 $num1 = $num2 - round($factor1); // generate offset for $scramble1 78 $num1 = $this->_checkRange($num1); // check range 79 $factor2 = $factor1 + $num2; // accumulate in $factor2 50 } 80 51 81 // extract character from $scramble182 $char1 = substr($this->scramble1, $num1, 1);83 52 84 // append to $target string85 $target .= $char1;86 87 //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";88 89 } // for90 91 return rtrim($target);92 93 } // decrypt94 95 // ****************************************************************************96 function encrypt ($key, $source, $sourcelen = 0)97 // encrypt string into a garbled form98 {99 $this->errors = array();100 101 // convert $key into a sequence of numbers102 $fudgefactor = $this->_convertKey($key);103 if ($this->errors) return;104 105 if (empty($source)) {106 $this->errors[] = 'No value has been supplied for encryption';107 return;108 } // if109 110 // pad $source with spaces up to $sourcelen111 while (strlen($source) < $sourcelen) {112 $source .= ' ';113 } // while114 115 $target = null;116 $factor2 = 0;117 118 for ($i = 0; $i < strlen($source); $i++) {119 // extract a character from $source120 $char1 = substr($source, $i, 1);121 122 // identify its position in $scramble1123 $num1 = strpos($this->scramble1, $char1);124 if ($num1 === false) {125 $this->errors[] = "Source string contains an invalid character ($char1)";126 return;127 } // if128 129 // get an adjustment value using $fudgefactor130 $adj = $this->_applyFudgeFactor($fudgefactor);131 132 $factor1 = $factor2 + $adj; // accumulate in $factor1133 $num2 = round($factor1) + $num1; // generate offset for $scramble2134 $num2 = $this->_checkRange($num2); // check range135 $factor2 = $factor1 + $num2; // accumulate in $factor2136 137 // extract character from $scramble2138 $char2 = substr($this->scramble2, $num2, 1);139 140 // append to $target string141 $target .= $char2;142 143 //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";144 145 } // for146 147 return $target;148 149 } // encrypt150 151 // ****************************************************************************152 function getAdjustment ()153 // return the adjustment value154 {155 return $this->adj;156 157 } // setAdjustment158 159 // ****************************************************************************160 function getModulus ()161 // return the modulus value162 {163 return $this->mod;164 165 } // setModulus166 167 // ****************************************************************************168 function setAdjustment ($adj)169 // set the adjustment value170 {171 $this->adj = (float)$adj;172 173 } // setAdjustment174 175 // ****************************************************************************176 function setModulus ($mod)177 // set the modulus value178 {179 $this->mod = (int)abs($mod); // must be a positive whole number180 181 } // setModulus182 183 // ****************************************************************************184 // private methods185 // ****************************************************************************186 function _applyFudgeFactor (&$fudgefactor)187 // return an adjustment value based on the contents of $fudgefactor188 // NOTE: $fudgefactor is passed by reference so that it can be modified189 {190 $fudge = array_shift($fudgefactor); // extract 1st number from array191 $fudge = $fudge + $this->adj; // add in adjustment value192 $fudgefactor[] = $fudge; // put it back at end of array193 194 if (!empty($this->mod)) { // if modifier has been supplied195 if ($fudge % $this->mod == 0) { // if it is divisible by modifier196 $fudge = $fudge * -1; // make it negative197 } // if198 } // if199 200 return $fudge;201 202 } // _applyFudgeFactor203 204 // ****************************************************************************205 function _checkRange ($num)206 // check that $num points to an entry in $this->scramble1207 {208 $num = round($num); // round up to nearest whole number209 210 $limit = strlen($this->scramble1);211 212 while ($num >= $limit) {213 $num = $num - $limit; // value too high, so reduce it214 } // while215 while ($num < 0) {216 $num = $num + $limit; // value too low, so increase it217 } // while218 219 return $num;220 221 } // _checkRange222 223 // ****************************************************************************224 function _convertKey ($key)225 // convert $key into an array of numbers226 {227 if (empty($key)) {228 $this->errors[] = 'No value has been supplied for the encryption key';229 return;230 } // if231 232 $array[] = strlen($key); // first entry in array is length of $key233 234 $tot = 0;235 for ($i = 0; $i < strlen($key); $i++) {236 // extract a character from $key237 $char = substr($key, $i, 1);238 239 // identify its position in $scramble1240 $num = strpos($this->scramble1, $char);241 if ($num === false) {242 $this->errors[] = "Key contains an invalid character ($char)";243 return;244 } // if245 246 $array[] = $num; // store in output array247 $tot = $tot + $num; // accumulate total for later248 } // for249 250 $array[] = $tot; // insert total as last entry in array251 252 return $array;253 254 } // _convertKey255 256 // ****************************************************************************257 53 } // end encryption_class 258 54 // ****************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.