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.

multi-server login script for your site

Discussion in 'General Discussion' started by bmcclure, Sep 18, 2003.

  1. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    Here was our situation:

    We had our Linux (CPanel) servers and our Windows (Ensim) servers. We wanted a login box on our homepage that covered ALL customers, however, and we didn't want to make them choose Windows/Linux when logging in. I came up with a solution. The customer enters their domain name and where they want to go, and the script handles the rest. It works by looking up the IP of the customers' domain and seeing if it matches any of this script's IPs. If so, it redirects accordingly. If not, it gives an error.

    Here's the script (with comments for the form fields you'll need to submit). Change to yoru liking and enjoy. Please let me know what you think, and send me any improvements you make.

    You'll need to customize the variables and the errors at least.

    Thanks!

    You can see this at work by going to http://www.andhosting.com and filling out the login box. We also use the full version at www.andhosting.com/login.

    PHP:
    <?
    // Host lookup Login Script by Ben McClure of andHosting.com.
    // Please send comments/fixes/updates to [email]bmcclure@andhosting.com[/email].
    // Distribute this script freely, but please leave the above lines.
    //
    // You will need the following fields, either as options or as hidden fields, in a form and set this script as the action.
    // pretype -- can either be 'http' or 'https'
    // urlname -- a text field, required. For andhosting.com this could either be 'andhosting' or 'www.andhosting'
    // domaintype -- should be '.com', '.net', '.org', '.biz', etc.
    // logintype -- can be 'cpanel', 'rpanel', 'webmail', or 'modernbill'
    //
    $businessname="andHosting.com"// The name of your hosting company
    $mblocation="www.andhosting.com/modernbill"// Location to modernbill without [url]http://[/url] and without a trailing slash
    $cpanelip="64.144.30.161"// The IP of your CPanel server
    $ensimip="64.241.226.85"// The IP of your Ensim server

    // Edit the rest if you dare...

    if($logintype == "modernbill") {
        
    header("Location: " $pretype "://" $mblocation "/");
    } else {
    if(
    $urlname == "") {
                            
    $pagetitle "Error";
                            include(
    '../include/header.inc');
                            echo 
    "You need to enter a domain name if you want to log in. Please go back and try again.";
                            include(
    '../include/footer.inc');
    } else {
    $hname=$urlname "." $domaintype;
    $hostip=gethostbyname($hname);
        if (
    $hostip==$cpanelip) {
            if (
    $logintype=="cpanel") {
                
    header("Location: " $pretype "://" $urlname "." $domaintype "/cpanel/");
            } elseif (
    $logintype=="rpanel") {
                
    header("Location: " $pretype "://" $urlname "." $domaintype "/whm/");
            } elseif (
    $logintype=="webmail") {
                
    header("Location: " $pretype "://" $urlname "." $domaintype "/webmail/");
            }
        } elseif (
    $hostip==$ensimip) {
            if (
    $logintype=="cpanel") {
                
    header("Location: " $pretype "://" $hostip "/admin/");
            } elseif (
    $logintype=="rpanel") {
                
    header("Location: " $pretype "://" $hostip "/admin/");
            } elseif (
    $logintype=="webmail") {
                
    header("Location: " $pretype "://" $hostip "/admin/");
            }
        } else {
        
    $pagetitle "Error";
        include(
    '../include/header.inc');
        echo 
    "$hname appears to point to $hostip. This isn't a valid $businessname address. Please check the name and try again.";
        include(
    '../include/footer.inc');
        }
    }
    }
    ?>
     
    #1 bmcclure, Sep 18, 2003
    Last edited: Sep 18, 2003
  2. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    And here's something more simple that gets the same effect. Better if you are using html pages as well.

    Create file submit.php and add the following:

    <?
    #$domain = "domain.com";
    ?>
    <head>
    <title>Logging In...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="refresh" content="1;URL=http://<? print "$user:$pass@$domain"; ?>:2082">
    </head>
    <body>
    <p><b>Hi <? echo $user ?>!</b></p>
    <p><b>Please wait while you are logged in!</b></p>
    </body>


    Heres the login form to be placed in html page(s):


    <body>
    <form name=login method="post" action="submit.php">
    <table border=1 cellpadding=3>
    <tr>
    <td colspan=2 align=center>
    <h2><b>Client Login</b></h2>
    </td>
    </tr>
    <tr>
    <td>Username:</td>
    <td>
    <input type=text name=user size=15 maxlength="26">
    @
    <input type="text" value="yourdomain.com" name="domain" maxlength="65" size="15">

    </td>
    </tr>
    <tr>
    <td>Password:</td>
    <td>
    <input type="password" name="pass" size="20">
    </td>
    </tr>
    <tr>
    <td colspan=2 align=center>
    <input type="submit" value="Login!" name="button">
    </td>
    </tr>
    </table>
    </form>
    </body>


    You can adjust the tables as needed.

    members can login to any server, you can also use this for reseller login by just making a submit2.php and entering the first code but changing 2082 to 2086

    Make a secure login by using 2083 for secure cpanel or use your sites SSL cert.

    cPanel.net Support Ticket Number:
     
  3. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    Same effect? That ONLY works if you have CPanel on each server and only want to allow them to log into their control panel. That's what I was trying to work around in a matter that I wouldn't need to keep updating.

    cPanel.net Support Ticket Number:
     
  4. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    True it for Cpanel only and thats why I posted it in the Cpanel forum. Not really thinking of Ensim here.

    cPanel.net Support Ticket Number:
     
  5. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    Well I would have posted it in the "login box for cpanel and ensim forum" but for soem reason I can't find that one...

    Not saying there's anything wrong with your code, sometimes simple is the way to go, I chose the path of PHP for error handling and more features. I chose to handle Ensim (or any other control panel) as well because they don't have CPanel for Windows yet...

    cPanel.net Support Ticket Number:
     
  6. stwman11

    stwman11 Member

    Joined:
    Oct 20, 2003
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    Thank you!

    Thank you for the suggestion! I'm using the code best suited for html, but will be keeping both for future use! It works GREAT!!!!!

    Thanks again for all the replies!!!!

    Steve
     
  7. hot_wired13

    hot_wired13 Active Member

    Joined:
    Oct 17, 2003
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    127.0.0.1
    ok, i read ur php code twice. what if that client's domain has an ip of its own (as in, not main server ip)? wont that mess everything up?
     
  8. 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
    Even if the domain has an ip of its own you can still log in with its main server ip.
     
  9. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    I am rewriting the code, actually. In the past coupel months I've went from that script, to creating some very complicated PHP scripts...

    Yes, it will mess things up. Yes, you can use the main shared IP to log into the control panel, but since the script uses IP lookup, it won't know what that main shared IP is. You can always add one line and oen block of code for each IP you'd like, so you could put your dedicated IP clients in there separately. The code is pretty messy though. I'll post my new script when I've got it done.
     
  10. EdG

    EdG Member

    Joined:
    Dec 15, 2003
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    Planet_Master - my login script based on your code, help plz
    hi planet_master, your code helped me a lot as I wanted to allow users to login to cpanel just by entering their details on the main page of my site...

    So I edited your code a bit for my site and have the following:

    <?
    $domain = "jg-hosting.com";
    ?>

    <html>
    <head>
    <title>Cpanel Login - Progress</title>
    <script language="Javascript">
    function redirect_home()
    {
    window.location="\index.php";
    }
    function redirect_cpanel()
    {
    window.location="<? echo "http://" . $user . ":" . $pass . "@" . $domain . ":2082"; ?>";
    }
    </script>
    <link href="style.css" rel="stylesheet" type="text/css">
    </head>
    <body>

    <table align="center" id="slvbar" class="slvbar" background="bt_bg.png">
    <tr valign="center">
    <td>
    </td>
    </tr>
    </table>

    <table align="center" id="sectbl" class="tbl">
    <tr valign="center" align="center">
    <td>

    <?
    if (empty($user))
    {
    echo "Sorry you didn't enter a username, we are now returning you to the JG-Hosting home page.<br><br>";
    echo ('<script language="Javascript">
    var the_timeout = setTimeout("redirect_home();",3500);
    </script>');
    if (empty($pass))
    {
    echo "Sorry you didn't enter a password, we are now returning you to the JG-Hosting home page.";
    echo ('<script language="Javascript">
    var the_timeout = setTimeout("redirect_home();",3500);
    </script>');
    }
    }
    elseif (empty($pass))
    {
    echo "Sorry you didn't enter a password, we are now returning you to the JG-Hosting home page.<br><br>";
    echo ('<script language="Javascript">
    var the_timeout = setTimeout("redirect_home();",3500);
    </script>');
    if (empty($user))
    {
    echo "Sorry you didn't enter a username, we are now returning you to the JG-Hosting home page.";
    echo ('<script language="Javascript">
    var the_timeout = setTimeout("redirect_home();",3500);
    </script>');
    }
    }
    else
    {
    echo "Welcome " . $user . "<br><br>";
    echo "Please wait while you are logged in. <br>";
    echo ('<script language="Javascript">
    var the_timeout = setTimeout("redirect_cpanel();",3500);
    </script>');
    }
    ?>

    </td>
    </tr>
    </table>

    <table align="center" id="slvbar" class="slvbar" background="bt_bg.png">
    <tr valign="center">
    <td>
    </td>
    </tr>
    </table>

    I used javascript to redirect so that I could send the user back to home or to cpanel as I didn't know how to handle redirects properly with php and tried but didn't manage it....

    The above code is fine for me except that if someone enters no username or password it says "Sorry you didn't enter a username......" then "Sorry you didn't enter a password..." but I want it to say "Sorry you didn't enter a username or password" instead. Can anyone please tell me how to do this?
     
  11. ivaserver

    ivaserver Well-Known Member

    Joined:
    Aug 9, 2002
    Messages:
    111
    Likes Received:
    0
    Trophy Points:
    16
    bmcclure
    great script

    I have your script working for Cpanel and Helm

    i do have a problem though

    I have multiple Cpanel servers and have not got a clue if your script can be edited to work with more than one cpanel ip

    any thoughts?

    Best wishes
    Ivaserver
     
  12. EdG

    EdG Member

    Joined:
    Dec 15, 2003
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    Surely you can just add another ip at the top of the script e.g. $cpanelip2 and add it to the script?

    BTW, I have sorted out my script so it will say the following errors have occured, if any and list them instead of saying both had occured....
     
  13. ivaserver

    ivaserver Well-Known Member

    Joined:
    Aug 9, 2002
    Messages:
    111
    Likes Received:
    0
    Trophy Points:
    16
    works great now thanks EdG

    why didn't i think of that !! it was late here in the UK

    Best wishes
    Ivaserver
     
  14. EdG

    EdG Member

    Joined:
    Dec 15, 2003
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    Your welcome....so what's helm like?
    I got something right :D!!! lol I'm new to php
     
  15. Solokron

    Solokron Well-Known Member

    Joined:
    Aug 8, 2003
    Messages:
    849
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Seattle
    cPanel Access Level:
    DataCenter Provider
    Works great! How can I get this to work with multiple cpanel servers?

    I tried modifying...

    $cpanel1="xxx.xxx.xxx.xxx"; // The IP of your CPanel server
    $cpanel2="xxx.xxx.xxx.xxx"; // The IP of your CPanel server
    $ensimip="xxx.xxx.xxx.xxx"; // The IP of your Ensim server

    and

    duplicating the

    } elseif ($hostip==$cpanel2) {
    if ($logintype=="cpanel")

    section to no avail.
     
  16. Solokron

    Solokron Well-Known Member

    Joined:
    Aug 8, 2003
    Messages:
    849
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Seattle
    cPanel Access Level:
    DataCenter Provider
    Nevermind. I have it working now. :)

     
  17. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    I'm glad people are gettin guse out of this script, I plan to release a much more robust login script in the near future from one of my sites, I will link to it from this forum when it's done. Thanks guys!
     
  18. osfdeath

    osfdeath Well-Known Member

    Joined:
    Aug 29, 2003
    Messages:
    144
    Likes Received:
    0
    Trophy Points:
    16
  19. bmcclure

    bmcclure Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    196
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Racine, WI
    Thansk for the thread, that kind of shoots down my current modificatiosn to the script I was goign to use. In its curent form, it doesn't pass usernames or passwords via HTTP, so my form will still work how it is. The reason mine doesn't pass that information is that it's meant for Ensim and CPanel, and Ensim uses a web form to login. I have also expanded my version to include Hsphere (not too hard, same as ensim as far as login).

    Thanks for the info! That seems a boneheaded mvoe by Microsoft. If you thougth it was dangerous to pass that information, don't do it, but let those of us who use it every day as a feature of our business keep it!

    *proudly using Mozilla Firebird to post this message... kills IE*
     
  20. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    If I remember right, Mozilla did not even have this "function", right? Or is it there possible to user logindetails in URLs?

    Thanks
    Mike
     
Loading...

Share This Page