Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: 1 [2] 3   Go Down

Author Topic: hotlinking to redirect to the page that contains the image  (Read 55197 times)

0 Members and 1 Guest are viewing this topic.

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #20 on: October 08, 2013, 09:40:25 am »

Ahh Ok

For the plugin sef_url

I'm going to uninstall, I'll try without plugin, that I did not try.
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #21 on: October 08, 2013, 10:58:50 am »

Hello André,

I tested clean, without htaccess and without sef_url plugin.

It seems that does not work on my server. I see no need to disturb more.

With hotlink image is enough for me.

Thank you so much, always.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #22 on: October 08, 2013, 11:03:41 am »

Of course it won't work without the .htaccess file.
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #23 on: October 08, 2013, 07:35:15 pm »

Thank you very much Master,

There was a conflict with the plugin sef_url (removed).

Working perfectly 100%, first script you created, here

This htaccess file is ready for redirect.php script, as follows:

Code: [Select]
<Files ".htaccess">
Order Allow,Deny
Deny from All
</Files>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f

RewriteCond %{REQUEST_FILENAME} \.([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg])$ [NC]

<FilesMatch "^(normal_(.*)|thumb_(.*)).([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg])$">
RewriteCond %{HTTP_REFERER} !^$
</FilesMatch>

RewriteCond %{HTTP_REFERER} !^http(s)?://(.*)?example.com [NC]

RewriteCond %{REQUEST_URI} !^/example\.jpg$ [NC]

RewriteRule ^(.*\.([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg]))$ http://example.com/redirect.php?$1 [R,NC,L]

RewriteCond %{REQUEST_FILENAME} -f

RewriteCond %{REQUEST_FILENAME} \.(7z|aac|arj|as(f|x)|avi|bz2|divx|docx?|f4(a|v)|flv|gtar|gz|lzh|m4(a|v)|midi?|mkv|mov(ie)|mp(2|3|4|e?g)|og(g|m)|pdf|qt|ra(m|r)|sw(c|f)|tar|tgz|wm(a|v)|zip)$ [NC]

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http(s)?://(.*)?example.com [NC]

RewriteRule ^(.*\.(7z|aac|arj|as(f|x)|avi|bz2|divx|docx?|f4(a|v)|flv|gtar|gz|lzh|m4(a|v)|midi?|mkv|mov(ie)|mp(2|3|4|e?g)|og(g|m)|pdf|qt|ra(m|r)|sw(c|f)|tar|tgz|wm(a|v)|zip))$ http://example.com/redirect.php?$1 [R,NC,L]


Note: To be used in the root folder. Do not forget to replace example.com with your domain and example.jpg your image to redirect.

This other htaccess file does not work with redirect.php, is a different file (free choice, what each one likes).

Regards.
« Last Edit: October 12, 2013, 03:12:23 am by Niecher »
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: Re: hotlinking to redirect to the page that contains the image
« Reply #24 on: October 09, 2013, 01:38:45 am »

Adjust the last line of your .htaccess file to
Code: [Select]
RewriteRule ^(.*\.(jpg|jpeg|png|gif))$ http://www.allvip.us/redirect.php?$1 [NC,R,L]and use this code for redirect.php
Code: [Select]
<?php
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');

$file $superCage->server->getEscaped('QUERY_STRING');
if (
strpos($file$CONFIG['fullpath']) === FALSE) {
    
header("Location: no_hotlinking.html");
} else {
    
$file str_replace($CONFIG['fullpath'], ''$file);
    
$pos strrpos($file'/') + 1;
    
$filepath substr($file0$pos);
    
$filename substr($file$pos);
    
$pid mysql_result(cpg_db_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}'"), 0);
    if (
$pid) {
        
header("Location: displayimage.php?pid=".$pid);
    } else {
        
header("Location: no_hotlinking.html");
    }
}


thanks a lot.it worked.
I only edited a little the code for the .htaccess:

Code: [Select]

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?allvip.us [NC]   
RewriteRule ^(.*\.(jpg|jpeg|png|gif))$ http://www.allvip.us/gallery/redirect.php?$1 [NC,R,L]


because my gallery is not at allvip.us  is in the folder gallery -  allvip.us/gallery
I placed the .htaccess , redirect.php and no_hotlinking.html in the gallery folder.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #25 on: October 09, 2013, 03:26:41 am »

In created a new .htaccess in the gallery folder only with your code and my original .htaccess with other website rules is still in the public_html
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #26 on: October 09, 2013, 12:45:44 pm »

Hello allvip,

Thank you very much for your idea and request, this is a good hotlinking.

Regards.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #27 on: October 09, 2013, 09:35:28 pm »

even more thanks to andre that took the time to make it
thanks andre for the code is VERY, VERY  important to a website.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #28 on: February 13, 2014, 11:34:20 am »

If anyone wants all the gallery pages to redirect from example.com to www.example.com (useful for CloudFlare.CloudFlare has no point if users access the site without www.
CoudFlare runs only for www.)

code by Andre Reply #14:

http://forum.coppermine-gallery.net/index.php/topic,77210.0.html

Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #29 on: July 22, 2014, 06:33:59 pm »

Redirect.php is making the CPU time and MySQL time very hight.

Greg told me:

This will result in a full scan of the cpg pictures table for every request because:

    There is no index available that MySQL can use to find the result based on filepath and filename.
    There is no information given to MySQL to allow it to stop after the first (and ONLY) match is found - it will complete the scan...

For the second issue - just adding 'LIMIT 1' to the SQL statement will tell MySQL to stop looking after the first match... We know there can only be one match (the same filepath/filename can only exist once - but MySQL doesn't know that...)

For the first issue - we need to add some kind of index. The perhaps obvious choice would be a 2 column unique index on filepath and filename. Unfortunatly we hit a MySQL limitation of 1000 byte key... Both filepath and filename at defined as varchar(255) - or 510 characters - but when saved in UTF8 - can take up to 3 bytes per character - which exceeds the limit.
We can reduce the amount of data in the index - or take an approach with 1 column index(es).

I would suggest adding the following index (via phpMyAdmin) using your correct cpg table prefix - expecting that in most cases your actual fieldlengths are smaller than 255...:

Code: [Select]
ALTER TABLE `cpg_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))
and changing the SQL statement to:

Code: [Select]
SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}' LIMIT 1
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #30 on: July 22, 2014, 06:37:41 pm »

In phpMyAdmin I clicked the coppermine database - click SQL button on top - click clear - paste ALTER TABLE ... - click Go.

Error

SQL query:

ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1061 - Duplicate key name 'filepath_filename'

with:

Code: [Select]
ALTER TABLE `cpg15x_pictures`  ADD INDEX `filename` (`filename`)

Error
SQL query:

ALTER TABLE `cpg15x_pictures`  ADD INDEX `filename` (`filename`)

MySQL said: Documentation
#1061 - Duplicate key name 'filename'

« Last Edit: July 23, 2014, 01:12:35 pm by allvip »
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #31 on: July 22, 2014, 06:39:47 pm »

I can not even tell if the database is optimize.
Is proabibly not a coppermine dev problem,but please help.

How to optimize the database or just the cpg pictures table?
How to make redirect.php take less resources?
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #32 on: July 22, 2014, 06:41:47 pm »

I can give my host cpanel password to Greg,Andre or Jeff Bailey.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #33 on: July 23, 2014, 10:20:39 am »

ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1061 - Duplicate key name 'filepath_filename'

I assume you try to add the index more than once? If so, that error message is obvious. I just applied both queries on my Coppermine database successfully.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #34 on: July 23, 2014, 11:04:14 am »

How can I tell if the pictures table is indexed now?
« Last Edit: July 23, 2014, 11:12:37 am by allvip »
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: Re: hotlinking to redirect to the page that contains the image
« Reply #35 on: July 23, 2014, 11:11:20 am »

I assume you try to add the index more than once?

Yes.Twice.
The first time the error was:

Error
SQL query:

ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1062 - Duplicate entry 'userpics/10001/-barbara_palvin_8.jpg' for key 'filepath_filename'

I deleted -barbara_palvin_8.jpg and tryed again.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #36 on: July 23, 2014, 11:19:34 am »

How can I tell if the pictures table is indexed now?
Code: [Select]
SHOW INDEX FROM cpg15x_pictures
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #37 on: July 23, 2014, 11:30:13 am »

Is that ok?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #38 on: July 23, 2014, 12:00:08 pm »

As you can see, the index exists.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #39 on: July 23, 2014, 12:12:49 pm »

Can you please,please help me index all the tables.
Is important for the database to use less server resources.
Is the default coppermine database.Nothing changed.
I belive all the copermine databases look the same.
Logged
Pages: 1 [2] 3   Go Up
 

Page created in 0.026 seconds with 20 queries.