Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-09-01 13:32:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Is gho_if_referer still working with TXP 4.5.7?

Does someone have a version newer than my v2008.1 or a fixed version of the plugin that’s working with Textpattern 4.5.7?

Or can someone tell why I’m getting errors with my code?

<txp:gho_if_referer string="http://localhost:8888/directoryName/"> MyClassName</txp:gho_if_referer>

Errors (translated):

Tag error: <txp:gho_if_referer string="http://localhost:8888/directoryName/"> ->  Notice: Undefined variable: string while parsing form navis on page textseiten

textpattern/lib/txplib_publish.php:426 gho_if_referer()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/publish/taghandlers.php:3789 parse()
textpattern/lib/txplib_publish.php:426 if_section()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/lib/txplib_misc.php:1974 parse()
textpattern/publish/taghandlers.php:305 parse_form()
textpattern/lib/txplib_publish.php:426 output_form()
textpattern/lib/txplib_publish.php:326 processTags()
textpattern/publish.php:544 parse()

Plus 2x error Undefined variable: match with the same Textpattern file instances

The plugin code itself is one of the tiniest I’ve seen:

function gho_if_referer($atts, $text){
    $yes = array('yes', '1', 'true', 'enable');
    if (empty($atts['string'])){
        $match == false;
    } elseif ((isset($atts['regexp']) && in_array($atts['regexp'], $yes)) && eregi($string, $_SERVER['HTTP_REFERER'])){
        $match == true;
    } elseif (strpos($_SERVER['HTTP_REFERER'], $string)){
        $match == true;
    } else {
        $match == false;
    };
    return parse(EvalElse($text, $match));
}

Replacing eregi by preg_match gives me the same errors, BTW.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#2 2016-09-01 19:41:24

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Is gho_if_referer still working with TXP 4.5.7?

Hi Uli, try to replace $string with $atts['string'] in the code.

Offline

#3 2016-09-01 20:19:05

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

Thanks, Oleg, good shot, that removed the string error!

Do you have any idea that I could try for the two match errors?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2016-09-01 20:56:15

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Is gho_if_referer still working with TXP 4.5.7?

uli wrote #300933:

Do you have any idea that I could try for the two match errors?

Replace $match == with $match =. I wonder how this plugin worked at all.

Offline

#5 2016-09-01 21:35:52

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

Yay, match errors are gone now! Now I’m getting a single Notice: Undefined index: HTTP_REFERER with all of the above code references.

I wonder how this plugin worked at all.

Yes, I understand, and though it might look like a fault on my level of PHP: $match == is not a previous attempt of mine to fix the thing :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2016-09-02 20:37:43

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Is gho_if_referer still working with TXP 4.5.7?

uli wrote #300936:

Now I’m getting a single Notice: Undefined index: HTTP_REFERER with all of the above code references.

This happens when $_SERVER['HTTP_REFERER'] is not set, e.g. when you access the site directly from the browsers address bar. Replace if (empty($atts['string'])) with

if (empty($atts['string']) || empty($_SERVER['HTTP_REFERER']))

to get rid of this warning. Another flaw is

elseif (strpos($_SERVER['HTTP_REFERER'], $string))

should be

elseif (strpos($_SERVER['HTTP_REFERER'], $string) !== false)

FWIW, $_SERVER['HTTP_REFERER'] is set by the client, so potentially unreliable/harmful.

Offline

#7 2016-09-02 21:13:44

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

Thanks for stopping by here once again, Oleg!

undefined index is gone now, but I seem to have called the Undefined variable: string error back somehow. TXP references remain exactly the same.

For clarity, here’s the code I’ve put together so far:

function gho_if_referer($atts, $text){
	$yes = array('yes', '1', 'true', 'enable');
    if (empty($atts['string']) || empty($_SERVER['HTTP_REFERER'])){
        $match = false;
    } elseif ((isset($atts['regexp']) && in_array($atts['regexp'], $yes)) && eregi($atts['string'], $_SERVER['HTTP_REFERER'])){
        $match = true;
    } elseif (strpos($_SERVER['HTTP_REFERER'], $string) !== false){
        $match = true;
    } else {
        $match = false;
    };
    return parse(EvalElse($text, $match));
}

Edit: Pasted in the exact error message.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2016-09-02 21:24:45

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

$_SERVER['HTTP_REFERER'] is set by the client, so potentially unreliable/harmful.

I intend to just add different CSS classes. Could that be exploited, too?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#9 2016-09-02 21:39:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Is gho_if_referer still working with TXP 4.5.7?

uli wrote #300989:

undefined index is gone now, but I seem to have called the Undefined variable: string error back somehow.

Maybe it’s the reference to string towards the end of the second elseif, replaced here:

function gho_if_referer($atts, $text){
	$yes = array('yes', '1', 'true', 'enable');
    if (empty($atts['string']) || empty($_SERVER['HTTP_REFERER'])){
        $match = false;
    } elseif ((isset($atts['regexp']) && in_array($atts['regexp'], $yes)) && eregi($atts['string'], $_SERVER['HTTP_REFERER'])){
        $match = true;
    } elseif (strpos($_SERVER['HTTP_REFERER'], $atts['string']) !== false){
        $match = true;
    } else {
        $match = false;
    };
    return parse(EvalElse($text, $match));
}
uli wrote #300990:

I intend to just add different CSS classes. Could that be exploited, too?

I doubt that. I think Oleg meant that while it generally sends the referer in normal use, it is manipulable so if you were using it to allow access to something (maybe a download) only available to people coming from a certain referer, it could be got around. Oleg, correct me if I’m wrong.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2016-09-02 21:59:49

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

That seems to be the final blow of hammer! No errors so far.

Big thanks to both of you! :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#11 2016-09-02 22:06:40

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Is gho_if_referer still working with TXP 4.5.7?

Oh no, I was wrong, it always gives out true now!

Edit: Changed eregi to preg_match cause as soon as I try the regexp attribute I got an additional warning on top of my

Tag error: 
<txp:gho_if_referer string="http://localhost:8888/directoryName/$" regexp="true"> ->  
Warning: preg_match(): Delimiter must not be alphanumeric or backslash

(Tried $ in order to find out how the plugin judges my referer string, why it gives out true.)

Last edited by uli (2016-09-02 22:22:16)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2016-09-03 08:04:58

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Is gho_if_referer still working with TXP 4.5.7?

uli wrote #300996:

Warning: preg_match(): Delimiter must not be alphanumeric or backslash

I think that means that if you use the regex option, your string must begin and end with markers for the pattern. Traditionally that’s a slash, which is a problem with an url, because you’d need to escape (\/) all slashes in your url.

Try using another non-alphanumeric delimiter around your string, e.g.:

<txp:gho_if_referer string="#http://localhost:8888/directoryName/$#" regexp="true"> … 

But it would probably be better if the plugin added those of its own accord. Here’s a stab at that (adding a hash to the beginning and end of the string for the case where regex = yes, true, 1 or enable):

function gho_if_referer($atts, $text){
	$yes = array('yes', '1', 'true', 'enable');
    if (empty($atts['string']) || empty($_SERVER['HTTP_REFERER'])){
        $match = false;
    } elseif ((isset($atts['regexp']) && in_array($atts['regexp'], $yes)) && preg_match('#'.$atts['string'].'#', $_SERVER['HTTP_REFERER'])){
        $match = true;
    } elseif (strpos($_SERVER['HTTP_REFERER'], $atts['string']) !== false){
        $match = true;
    } else {
        $match = false;
    };
    return parse(EvalElse($text, $match));
}

I don’t know if $_SERVER['HTTP_REFERER'] also passes the hash section of a possible referer. If so, maybe # is not a good choice for a delimiter either.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB