satyajitint / php-wsdl-creator

Automatically exported from code.google.com/p/php-wsdl-creator
GNU General Public License v3.0
0 stars 0 forks source link

DetermineNameSpace and DetermineEndPoint enhanced to be used behind reverse Proxy #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use php-wsdl-creater behind a Apache Reverse Proxy
2.
3.

What is the expected output? What do you see instead?
Use Reverse Proxy instead of App server name

What version of the product are you using? On what operating system?
SVN Trunk 20120812, Any ( win7-64/win7-32, windows 2003/windows 2008r2

Please provide any additional information below.

Code Fragment to enhance your code:
    /**
     * Determine the endpoint URI
     */
    public function DetermineEndPoint(){
    // HTTP / HTTPS
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $protocol = 'https';
    } else {
        $protocol = 'http';
    }

    // PORT
    if (isset($_SERVER['SERVER_PORT'])) {
        if (($protocol == 'https' && $_SERVER['SERVER_PORT'] != 443) ||
            ($protocol == 'http'  && $_SERVER['SERVER_PORT'] != 80)) {
            $port = ':'. $_SERVER['SERVER_PORT'];
        }else{
            $port =$_SERVER['SERVER_PORT'];
        }
    }
    // SERVER_NAME
    if (isset($_SERVER['X_FORWARDE_FOR'])) {
        $hostname=($_SERVER['X_FORWARDE_FOR'];
    }else{
        $hostname =$_SERVER['SERVER_NAME'];
    }
    return $protocol .'://'. $hostname . $port . $_SERVER['SCRIPT_NAME'];
}

    /**
     * Determine the namespace
     */
    public function DetermineNameSpace(){
            // SERVER_NAME
        if (isset($_SERVER['X_FORWARDE_FOR'])) {
            $hostname=($_SERVER['X_FORWARDE_FOR'];
        }else{
            $hostname =$_SERVER['SERVER_NAME'];
        }
        return 'http://'.$hostname.str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME']);
    }

Original issue reported on code.google.com by christia...@gmail.com on 23 Aug 2012 at 2:37

GoogleCodeExporter commented 9 years ago
Small typhos:

    /**
     * Determine the endpoint URI
     */
    public function DetermineEndPoint(){
    // HTTP / HTTPS
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $protocol = 'https';
    } else {
        $protocol = 'http';
    }

    // PORT
    if (isset($_SERVER['SERVER_PORT'])) {
        if (($protocol == 'https' && $_SERVER['SERVER_PORT'] != 443) ||
            ($protocol == 'http'  && $_SERVER['SERVER_PORT'] != 80)) {
            $port = ':'. $_SERVER['SERVER_PORT'];
        }else{
            $port =$_SERVER['SERVER_PORT'];
        }
    }
    // SERVER_NAME
    if (isset($_SERVER['X_FORWARDED_FOR'])) {
        $hostname=$_SERVER['X_FORWARDED_FOR'];
    }else{
        $hostname =$_SERVER['SERVER_NAME'];
    }
    return $protocol .'://'. $hostname .':'. $port . $_SERVER['SCRIPT_NAME'];
}

    /**
     * Determine the namespace
     */
    public function DetermineNameSpace(){
            // SERVER_NAME
        if (isset($_SERVER['X_FORWARDED_FOR'])) {
            $hostname=$_SERVER['X_FORWARDE_FOR'];
        }else{
            $hostname =$_SERVER['SERVER_NAME'];
        }
        return 'http://'.$hostname.str_replace(basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME']);
    }

Original comment by christia...@gmail.com on 24 Aug 2012 at 7:18

GoogleCodeExporter commented 9 years ago
Now also as Patch file

On more issue found: Line764 cause at demo.php 
//if(is_null($class)&&$this->IsOnlyGlobal()){
+       if(!isset($class)&&$this->IsOnlyGlobal()){ 

Tested with PHP Version 5.3.8, Apache, win7 

Original comment by christia...@gmail.com on 26 Aug 2012 at 12:55

Attachments:

GoogleCodeExporter commented 9 years ago
I'd prefer to init the $class variable with NULL, but thanks anyway!

The XFF header (as all X-headers) is a very special thing - and it could be 
faked, so I'd prefer to set the PhpWsdl->EndPoint and PhpWsdl->NameSpace 
manually in this case. I had a look at the Apache documentation:

http://httpd.apache.org/docs/trunk/mod/mod_proxy.html

There the XFF header is described as "The IP address of the client"!? Are you 
sure you receive the server name when accessing this header?

Original comment by schickwa...@googlemail.com on 26 Aug 2012 at 6:49

GoogleCodeExporter commented 9 years ago
http://httpd.apache.org/docs/trunk/mod/mod_proxy.html#forwardreverse

X-Forwarded-Host is correct not X-Forwarded-For

Still this works as expected now in our reverse Proxy scenario

I correct it to that, thanks

Original comment by christia...@gmail.com on 26 Aug 2012 at 8:48