Gossamer Forum
Home : Products : DBMan : Customization :

Access Control

Quote Reply
Access Control
I would like to restrict from the specified URLs
But, this command does not work.
Currently, it won't recgnize the URLs.
Please help me to correct this.

@BAD_LISTS = (
"http://www.samurai-restaurant.com/Services/index.html",
"http://www.samurai-restaurant.com/Menu/home.html",
"http://www.samurai-restaurant.com/add.html"
);

$referer = $ENV{HTTP_REFERER};
foreach $list (@BAD_LISTS) {

if ($referer = $list)
{
print "Location: /error.html\n\n";
exit;
}
else {
.....
}
Quote Reply
Re: [haruchan] Access Control In reply to
We were just talking about this in another topic.

Instead of

if ($referer = $list)

use

if ($referer eq $list)

It's a very common mistake.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
I just made a mistake here.
I meant if ($referer == $list) which is same as if ($referer eq $list).
Also, I checked with
if ($referer eq $list), but the result is same.



Quote Reply
Re: [haruchan] Access Control In reply to
Hmmm. I thought that == was for numerical comparisons, while eq was for strings. Live and learn. :-)

Seems like it should work, then. Maybe it has to do with where you have it in the script.

Hopefully someone else will have an idea. I don't have any experience with referrers. You might try doing a search here in the forum, but not just in the DBMan section. Look in the general Perl programming area.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
I think the position is ok, because it works if I put like below.

$referer = $ENV{HTTP_REFERER};

if ($referer eq "http://www.domain.com/test.html")
{
print "Location: /error.html\n\n";
exit;
}
elsif ($referer eq "http://www.domain.com/tests.html")
{
print "Location: /error.html\n\n";
exit;
}
else
{
...
}
Quote Reply
Re: [haruchan] Access Control In reply to
Then it would mean that in your original code the problem was with the array.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
I fount out, it works with the first URL, but not the second or the thrid.

@BAD_LISTS = (
"http://www.samurai-restaurant.com/Services/index.html",
"http://www.samurai-restaurant.com/Menu/home.html",
"http://www.samurai-restaurant.com/add.html"
);

I hope someone help me.


Quote Reply
Re: [haruchan] Access Control In reply to
I'm perfectly willing to help you troubleshoot it, even if I don't have the answers.

When you used the series of "if" statements, did you use all of the same URLs that you have in your array? It would help to know that those URLs are recognized as bad before we try to work out what might be wrong with the array.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
Thank you for reply. Sorry if I misunderstood, but all URLs directs to error.html if I put individually.

Actually, this one works:

$url1 = "http://www.samurai-restaurant.com/Services/index.html";
$url2 = "http://www.samurai-restaurant.com/Menu/home.html";
$url3 = "http://www.samurai-restaurant.com/add.html";
if ($referer =~ /$url1|$url2|$url3/i)
{
print "Location: /error.html\n\n";
exit;
}
else {
.....
}

So, I think there should be something missing
to specify the each URL in @BAD_LISTS
Quote Reply
Re: [haruchan] Access Control In reply to
I think the problem with your array may be the linefeeds between each one. I've run into that problem before. It would be just as easy to define them like:

$BAD_LISTS[0] = "http://....";
$BAD_LISTS[1] = "http://...";

and so on.

Then you can use the rest of your original code.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Feb 23, 2006, 9:40 PM
Quote Reply
Re: [JPDeni] Access Control In reply to
For now, this works. I will use this until I find the solution.
Thank you.

if($list =~ /$referer/i)
Quote Reply
Re: [haruchan] Access Control In reply to
I made a big mistake.

In my way, if($list =~ /$referer/i)

I screw up everything under subdirectories.
Now, I need more help about your way.

$BAD_LISTS[0] = "http://....";
$BAD_LISTS[1] = "http://...";

I tried some, but they do not work. Please guide me to correct it.
if($referer eq $BAD_LIST[$i] )
if($referer eq $BAD_LIST[$_] )

I cannot find out what should be in [].

Thank you in advance.
Quote Reply
Re: [haruchan] Access Control In reply to
I hope I didn't confuse you by not putting in the whole URLs. Here's what you want:


And so on, one for each URL you want to ban.


Once you have all of the URLs in the array, just use the array as you did before:

Code:
referer = $ENV{HTTP_REFERER};
foreach $list (@BAD_LISTS) {
if ($referer eq $list) {
print "Location: /error.html\n\n";
exit;
}
}


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Feb 24, 2006, 3:01 PM
Quote Reply
Re: [JPDeni] Access Control In reply to
Unfortunately, it does not work.
The result is

$list=http://www.samurai-restaurant.com/Services/index.htmlhttp://www.samurai-restaurant.com/Menu/home.htmlhttp://www.samurai-restaurant.com/add.html
Quote Reply
Re: [haruchan] Access Control In reply to
Please post the exact full code you're using so I can figure out what's going on.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
I put entire db.cgi code within else {}.
Since it was working before this addon, the db.cgi configuration should be correct.
Actually, all I did for this cgi was, changing script path from $db_script_path = "."; to "./";.
I already tried both before and after changing the path.
I put this addon between the first line and the comment area (company info).

#!/usr/local/bin/perl

$BAD_LISTS[0]=http://www.samurai-restaurant.com/Services/index.html;
$BAD_LISTS[1]=http://www.samurai-restaurant.com/Menu/home.html;
$BAD_LISTS[2]=http://www.samurai-restaurant.com/add.html;

referer = $ENV{HTTP_REFERER};
foreach $list (@BAD_LISTS) {
if ($referer eq $list) {
print "Location: /error.html\n\n";
exit;
}
else {
whole db.cgi except the first line.
}}
Quote Reply
Re: [haruchan] Access Control In reply to
I see why only the first URL worked. The way you have it, if the first one doesn't match, it goes on to the rest of the db.cgi file. You need to change it to the following.

Code:
foreach $list (@BAD_LISTS) {
if ($referer eq $list) {
print "Location: /error.html\n\n";
exit;
}
}


If it matches any of the URLs in @BAD_LISTS, it will go to the external location and exit the script, so you don't need an "else."


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Access Control In reply to
Thank you again.
It was just "else {}" which I do not need after all.
I thought "if" and "else" were the set.
Quote Reply
Re: [haruchan] Access Control In reply to
Quote:
It was just "else {}" which I do not need after all.

Right


Quote:
I thought "if" and "else" were the set.

Nope. If the "if" condition isn't met and there is no "else" the script just goes on to the next command. You can't have an "else" unless you have an "if," but you can have an "if" without an "else." :-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.