The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP proxy for users who cannot connect on port 2082 !

Discussion in 'cPanel Developers' started by hostultra, Jan 26, 2004.

  1. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    Some customers cannot connect on port 2082 because of firewall restrictions, this is especially common on corporate and college networks.

    This simple script will proxy the requests :)

    PHP:
    <?php
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="cPanel"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Access Denied';
    exit;
    } else {
    $url 'http://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@localhost:2082'.$_SERVER["PATH_INFO"];

    $ch curl_init();
    curl_setopt($chCURLOPT_GET,1);
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_USERAGENT$_SERVER["HTTP_USER_AGENT"]);
    curl_setopt($chCURLOPT_RETURNTRANSFER,1);

    $result=curl_exec ($ch);
    curl_close ($ch);
    $result str_replace('src="/''src="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    $result str_replace('background="/''background="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    $result str_replace('href="/''href="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    echo(
    $result);
    }
    ?>
     
  2. cyberwisdom

    cyberwisdom Well-Known Member

    Joined:
    Jun 2, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Hey I tried it and it didn't work.

    Were do I run it from? The user's directory or the main httpd directory?

    Thanx, looks awesome!
     
  3. AlexF

    AlexF Well-Known Member

    Joined:
    Nov 20, 2003
    Messages:
    148
    Likes Received:
    0
    Trophy Points:
    16
    I have the same problem but only for SSL port 2083 & 2087 for WHM. Theoretically, I could use this script, correct?
     
  4. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    You run it as a normal php script.
    It doesnt require to be anywhere special or have any special permissions.
    It will not work with phpsuexec.

    There is no use having it connect on the SSL port 2083 because the php script connects to localhost, no data is transmitted over a network between the php and localhost so encryption is pointless.
     
  5. cyberwisdom

    cyberwisdom Well-Known Member

    Joined:
    Jun 2, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Ahh, there's my problem, have phpsuxec enabled.

    hostultra, it actually does matter because the info transmitted to the php script from the user's computer is not encrypted and still needs to be protected.

    AlexF, you could run it as https://hostname.domain.com/cpanelscript.php

    If you haven't already created an ssl for your server's hostname, you must generate and install a self signed certificate and run the script via ssl.

    Whether you use 2082 or 2083 really doesn't matter as long as you are using the script thru SSL.
     
  6. rpmws

    rpmws Well-Known Member

    Joined:
    Aug 14, 2001
    Messages:
    1,824
    Likes Received:
    5
    Trophy Points:
    38
    Location:
    back woods of NC, USA
    I just tried this. I get the password box and when I login I get a "doc moved here" link. I click that and what looks to be the correct url in the browser which is basically the url without the 2082 port. I get a 404 at that point. :(
     
  7. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
    Re: Re: PHP proxy for users who cannot connect on port 2082 !

    Same here.
     
  8. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
  9. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
  10. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Is there an easy way to insert this into each account?

    /home/*/public_html/THIS_FILE.php ??
     
  11. cyberwisdom

    cyberwisdom Well-Known Member

    Joined:
    Jun 2, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
  12. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Good idea. But what about all of the other servers that I have? Is there a way to insert this all of those accounts?

    Also, can this be used for resellers to access WHM?
     
  13. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Actually, that puts it into the 'root' of the new account... not the public_html area
     
  14. AlexF

    AlexF Well-Known Member

    Joined:
    Nov 20, 2003
    Messages:
    148
    Likes Received:
    0
    Trophy Points:
    16
    Try /cpanel3-skel/public_html
     
  15. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Duhhh!!! Sometimes I need a kick in the head!!

    Is there a way to make this work with WHM?
     
  16. cyberwisdom

    cyberwisdom Well-Known Member

    Joined:
    Jun 2, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    In the script change it to port 2086 instead of 2082

    Code:
    $url = 'http://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@localhost:2082'.$_SERVER["PATH_INFO"];
    Change to this:
    Code:
    $url = 'http://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@localhost:2086'.$_SERVER["PATH_INFO"];
     
  17. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Oh well... it dosen't seem to work for WHM
     
  18. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    Is there anyway to make this work for WHM as well? I am willing to fork over some cash if so :)
     
  19. blaze64

    blaze64 Well-Known Member

    Joined:
    Feb 5, 2003
    Messages:
    159
    Likes Received:
    0
    Trophy Points:
    16
    EDIT
     
  20. SgtRyan

    SgtRyan Registered

    Joined:
    Feb 15, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    PHP:
    <?php
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="WHM"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Access Denied';
    exit;
    } else {
    $url 'http://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@localhost:2086'.$_SERVER["PATH_INFO"];

    $ch curl_init();
    curl_setopt($chCURLOPT_GET,1);
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_USERAGENT$_SERVER["HTTP_USER_AGENT"]);
    curl_setopt($chCURLOPT_RETURNTRANSFER,1);

    $result=curl_exec ($ch);
    curl_close ($ch);
    $result str_replace('src="/''src="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    $result str_replace('background="/''background="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    $result str_replace('href="/''href="'.$_SERVER["SCRIPT_NAME"].'/'$result);
    echo(
    $result);
    }
    ?>

    That will do it :)
     
Loading...

Share This Page