Plugin Directory

Changeset 2887106


Ignore:
Timestamp:
03/26/2023 01:34:05 PM (3 years ago)
Author:
zlabs
Message:

php >=8, follows redirect

Location:
picgrab/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • picgrab/trunk/picgrab.php

    r467398 r2887106  
    3232
    3333    $resizerpath= realpath(dirname(__FILE__).'/resize.php');
    34     $zkey="UNIQUE-".filemtime($resizerpath);   
    35     $crypt = new encryption_class;
     34
     35    $crypt = new encryption_class();
    3636
    3737    $blogurl = get_bloginfo('home');
     
    7070      $imgurl=$imgurls[$i];
    7171      $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));
    7373      //error_log ($imgurl2);
    7474      $imgtag2 = str_replace ($imgurl,$imgurl2,$imgtag2);
  • picgrab/trunk/readme.txt

    r467398 r2887106  
    22Contributors: zlabs
    33Tags: pictures, resize, crop, cache
    4 Requires at least: 2.5
    5 Tested up to: 3.2.1
    6 Stable tag: 0.21
     4Requires at least: 6.1.1
     5Tested up to:
     6Stable tag: 0.3
    77
    88Picgrab is a plugin that download, resize and crop an image on the fly.
     
    3131Refer to [This post](http://fabrizio.zellini.org/resize-e-crop-immagini-in-php "Crop / Resize script") for more informations on resizer syntax.
    3232
    33 PicGrab require Php version >=5, gd and curl libraries.
     33PicGrab require Php version >=8, gd and curl libraries.
    3434
    3535== Installation ==
  • picgrab/trunk/resize.php

    r98061 r2887106  
    3838if (defined ('CRYPT') && CRYPT) {
    3939  $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);
    4444}
    4545if (preg_match ("/resize\.php/i",$imgpath)) {
  • picgrab/trunk/resizer.php

    r466320 r2887106  
    5555    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
    5656    curl_setopt($curl, CURLOPT_TIMEOUT, 15);
     57    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     58    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    5759    curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    5860    // get response
     
    6062    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    6163    $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE );
     64    $redirectURL = curl_getinfo($curl,CURLINFO_EFFECTIVE_URL );
    6265    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    }
    6978}
    7079
  • picgrab/trunk/std.encryption.class.inc

    r98061 r2887106  
    11<?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 Licence
    6 // 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 
    112if (!class_exists('encryption_class')) {
    123class encryption_class {
    134
    14     var $scramble1;     // 1st string of ASCII characters
    15     var $scramble2;     // 2nd string of ASCII characters
    165
    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
    2013
    2114    // ****************************************************************************
    2215    // class constructor
    2316    // ****************************************************************************
    24     function encryption_class ()
    25     {
    26         $this->errors = array();
     17    function __construct ()  {
    2718
    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    }
    4320
    4421    // ****************************************************************************
    45     function decrypt ($key, $source)
    46     // decrypt string into its original form
    47     {
    48         $this->errors = array();
    4922
    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;
    5334
    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";
    5838
    59         $target = null;
    60         $factor2 = 0;
    6139
    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");
    6541
    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 );
    7247
    73             // get an adjustment value using $fudgefactor
    74             $adj     = $this->_applyFudgeFactor($fudgefactor);
     48      return $ciphertext;
    7549
    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    }
    8051
    81             // extract character from $scramble1
    82             $char1 = substr($this->scramble1, $num1, 1);
    8352
    84             // append to $target string
    85             $target .= $char1;
    86 
    87             //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";
    88 
    89         } // for
    90 
    91         return rtrim($target);
    92 
    93     } // decrypt
    94 
    95     // ****************************************************************************
    96     function encrypt ($key, $source, $sourcelen = 0)
    97     // encrypt string into a garbled form
    98     {
    99         $this->errors = array();
    100 
    101         // convert $key into a sequence of numbers
    102         $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         } // if
    109 
    110         // pad $source with spaces up to $sourcelen
    111         while (strlen($source) < $sourcelen) {
    112             $source .= ' ';
    113         } // while
    114 
    115         $target = null;
    116         $factor2 = 0;
    117 
    118         for ($i = 0; $i < strlen($source); $i++) {
    119             // extract a character from $source
    120             $char1 = substr($source, $i, 1);
    121 
    122             // identify its position in $scramble1
    123             $num1 = strpos($this->scramble1, $char1);
    124             if ($num1 === false) {
    125                 $this->errors[] = "Source string contains an invalid character ($char1)";
    126                 return;
    127             } // if
    128 
    129             // get an adjustment value using $fudgefactor
    130             $adj     = $this->_applyFudgeFactor($fudgefactor);
    131 
    132             $factor1 = $factor2 + $adj;             // accumulate in $factor1
    133             $num2    = round($factor1) + $num1;     // generate offset for $scramble2
    134             $num2    = $this->_checkRange($num2);   // check range
    135             $factor2 = $factor1 + $num2;            // accumulate in $factor2
    136 
    137             // extract character from $scramble2
    138             $char2 = substr($this->scramble2, $num2, 1);
    139 
    140             // append to $target string
    141             $target .= $char2;
    142 
    143             //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";
    144 
    145         } // for
    146 
    147         return $target;
    148 
    149     } // encrypt
    150 
    151     // ****************************************************************************
    152     function getAdjustment ()
    153     // return the adjustment value
    154     {
    155         return $this->adj;
    156 
    157     } // setAdjustment
    158 
    159     // ****************************************************************************
    160     function getModulus ()
    161     // return the modulus value
    162     {
    163         return $this->mod;
    164 
    165     } // setModulus
    166 
    167     // ****************************************************************************
    168     function setAdjustment ($adj)
    169     // set the adjustment value
    170     {
    171         $this->adj = (float)$adj;
    172 
    173     } // setAdjustment
    174 
    175     // ****************************************************************************
    176     function setModulus ($mod)
    177     // set the modulus value
    178     {
    179         $this->mod = (int)abs($mod);    // must be a positive whole number
    180 
    181     } // setModulus
    182 
    183     // ****************************************************************************
    184     // private methods
    185     // ****************************************************************************
    186     function _applyFudgeFactor (&$fudgefactor)
    187     // return an adjustment value  based on the contents of $fudgefactor
    188     // NOTE: $fudgefactor is passed by reference so that it can be modified
    189     {
    190         $fudge = array_shift($fudgefactor);     // extract 1st number from array
    191         $fudge = $fudge + $this->adj;           // add in adjustment value
    192         $fudgefactor[] = $fudge;                // put it back at end of array
    193 
    194         if (!empty($this->mod)) {               // if modifier has been supplied
    195             if ($fudge % $this->mod == 0) {     // if it is divisible by modifier
    196                 $fudge = $fudge * -1;           // make it negative
    197             } // if
    198         } // if
    199 
    200         return $fudge;
    201 
    202     } // _applyFudgeFactor
    203 
    204     // ****************************************************************************
    205     function _checkRange ($num)
    206     // check that $num points to an entry in $this->scramble1
    207     {
    208         $num = round($num);         // round up to nearest whole number
    209 
    210         $limit = strlen($this->scramble1);
    211 
    212         while ($num >= $limit) {
    213             $num = $num - $limit;   // value too high, so reduce it
    214         } // while
    215         while ($num < 0) {
    216             $num = $num + $limit;   // value too low, so increase it
    217         } // while
    218 
    219         return $num;
    220 
    221     } // _checkRange
    222 
    223     // ****************************************************************************
    224     function _convertKey ($key)
    225     // convert $key into an array of numbers
    226     {
    227         if (empty($key)) {
    228             $this->errors[] = 'No value has been supplied for the encryption key';
    229             return;
    230         } // if
    231 
    232         $array[] = strlen($key);    // first entry in array is length of $key
    233 
    234         $tot = 0;
    235         for ($i = 0; $i < strlen($key); $i++) {
    236             // extract a character from $key
    237             $char = substr($key, $i, 1);
    238 
    239             // identify its position in $scramble1
    240             $num = strpos($this->scramble1, $char);
    241             if ($num === false) {
    242                 $this->errors[] = "Key contains an invalid character ($char)";
    243                 return;
    244             } // if
    245 
    246             $array[] = $num;        // store in output array
    247             $tot = $tot + $num;     // accumulate total for later
    248         } // for
    249 
    250         $array[] = $tot;            // insert total as last entry in array
    251 
    252         return $array;
    253 
    254     } // _convertKey
    255 
    256 // ****************************************************************************
    25753} // end encryption_class
    25854// ****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.