tontof / kriss_feed

A simple and smart (or stupid) feed reader
281 stars 53 forks source link

Cookie dir on reverse proxy #365

Open FanchTheSystem opened 8 years ago

FanchTheSystem commented 8 years ago

Hello !

I am using kriss feed with a reverse proxy.

So on the remote server kriss url is not the same as on the proxy one.

In fact I use http://kriss.mydomain.com with proxy to http://localhost:3456/kriss

In this configuration the variable $_SERVER["SCRIPT_NAME"] can't be used (as it is not the same url as exposed one)

In the function getUrl() of the index.php There is a check of the a variable named 'BASE_URL'

public static function getUrl()
    {
        $base =  isset($GLOBALS['BASE_URL'])?$GLOBALS['BASE_URL']:'';
        if (!empty($base)) {
            return $base;
        }

So I have added at the beginning of the index.php file

$BASE_URL='http://kriss.mydomain.com/';

It work well expect for cookie, so I can't connect or install Kriss Feed...

It is because when kriss try to find the cookiedir it use the variable $_SERVER["SCRIPT_NAME"] without a way to bypass it.

So to make it work on my server I have added this check for each cookiedir definition (one in init() function and one for login form :

   $cookiedir =  isset($GLOBALS['BASE_DIR'])?$GLOBALS['BASE_DIR']:'';
        if (empty($cookiedir)) {
           if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
              $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
           }
        }

It use a new variable I have set to :

$BASE_DIR='/';

So here is the full diff for index.php :

29a30,31
> $BASE_URL='http://kriss.mydomain.com/';
> $BASE_DIR='/';
4976,4979c4978,4983
<         $cookiedir = '';
<         if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
<             $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
<         }

---
>         $cookiedir =  isset($GLOBALS['BASE_DIR'])?$GLOBALS['BASE_DIR']:'';
>         if (empty($cookiedir)) {
>            if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
>               $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
>            }
>   }
8536,8539c8540,8545
<             $cookiedir = '';
<             if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
<                 $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
<             }

---
>       $cookiedir =  isset($GLOBALS['BASE_DIR'])?$GLOBALS['BASE_DIR']:'';
>             if (empty($cookiedir)) {
>                if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
>                   $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
>                }
>       }
tontof commented 8 years ago

Thanks for the feedback. That could effectively be very useful! I think the modification can be added in code.