icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » Reseller Hosting » How to: cPanel Form on Website, v2

Reseller Hosting Questions about your reseller hosting account.

Reply
 
LinkBack Thread Tools Search this Thread
Old January 9th, 2008, 11:34 PM   #1 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
How to: cPanel Form on Website, v2

Alright now. Over a year later, here is a new version of the script that'll work no matter what browser you use. It requires a confirmation, however, in order for it to process the data entered by the form and then log into the cPanel. So, without further delay, here's how you do it!

Step 1: Form Code (html)
Code:
<form action="cpanel.php" method="POST">
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br />
<input type="hidden" name="port" value="2082">
<input type="hidden" name="server" value="website.com">
<input name="secure" type="checkbox" value="1" checked /> Secure Login?<br />
<input type="submit" name="submit" value="Login">
</form>
This code creates a basic HTML form with values that will be used in the "cpanel.php" script. You may modify this code in anyway, just be sure to keep the following: method="post", name="user", name="pass", name="secure", value="1", name="server", and name="submit". These are needed to retrieve the right information for the script "cpanel.php" to work.

Edit "website.com" with the website url of the cpanel you want to log into. Just the domain name without an ending slash or the www. This is the only editing needed in this whole script :O

Step 2: Creating cPanel.php (PHP4/5)
The following uses PHP commands to transfer the information from the form to the cPanel and perform a login.
PHP Code:
<?php
// cPanel Login - NO NEED TO EDIT ANYTHING AT THIS POINT!! (Unless told to do so)
if ($_POST["submit"]) {
if ((!
$_POST["user"]) || (!$_POST["pass"])) {
    echo(
"Please complete all fields.<p><a href=\"javascript:history.go(-1)\">&laquo; Go back.</a></p>");
} else {

if (
$_POST["secure"] == 1) { 
    
$action "https://".$_POST["server"].":".$_POST["port"] + 1
} else { 
    
$action "http://".$_POST["server"].":".$_POST["port"]; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Please Confirm Login</title>
</head>

<body>
<form action="<?=$action?>/login/" method="POST">
Attempting to login to cPanel server (<?=$server?>)... <br />
Please press the button below to confirm the log in atempt.
<p>
<input type="hidden" name="login_theme" value="cpanel">
<input type="hidden" name="user" value="<?=$_POST["user"]?>"><br>
<input type="hidden" name="pass" value="<?=$_POST["pass"]?>"><br>
<input type="submit" name="submit" value="Click here to continue">
</p></form>
</body>
</html>
<? } } ?>
Multiple Server Selection

This is helpful if you have many servers that you host clients on, and want one login form/php script to be able to point to any of those servers. I believe this works, haven't tested it (as in, if the server will accept the information or not). But this is how you would do it. Maybe adding access mask to allow it, not sure.

Step 1: Replace the html form input field.

Find the following html code from the login form:
Code:
<input type="hidden" name="server" value="website.com">
Replace it with the following:
Code:
<select name="server">
  <option selected="selected">Select Server</option>
  <option value="website1.com">Server 1</option>
  <option value="website2.com">Server 2</option>
  <option value="website3.com">Server 3</option>
</select><br />
Now, you edit the "Server 1" or so with the name of the server (can be whatever you want to identify it with...). For the values (e.g. "website1.com") put the url of the server, without the www nor ending with a slash.

Step 2: Make sure a server was selected... (optional)

Wouldn't want a 404, because the user didn't select a server, right? Well, either way, let's do this...

Find the following in cpanel.php
PHP Code:
if ((!$_POST["user"]) || (!$_POST["pass"])) { 
Replace it with this:
PHP Code:
if ((!$_POST["user"]) || (!$_POST["pass"]) || (!$_POST["server"])) { 
Now, if the user was trying to log onto "Select Server" (which has no value), instead of giving a 404, it'll tell them to double check everything...

Choose Service

Have you wanted to allow the login to not only be able to log into cPanel, but into webmail as well? Ah, well, this will allow you to do so, without losing the cpanel form as well!

However, you can just edit the numbers in the cpanel.php if you don't want a multi-functional form

Standard Port Numbers

Standard WHM - 2086
Secure WHM - 2087
Standard Webmail - 2095
Secure Webmail - 2096

Step 1: Replace the html form input field.

Find the following html code from the login form:
Code:
<input type="hidden" name="port" value="2082">
Replace with the following code:
Code:
Select Service<br />
<input name="port" type="radio" value="2082" checked="checked" /> cPanel<br />
<input type="radio" name="port" value="2086" /> WHM<br />
<input type="radio" name="port" value="2095" /> Webmail<br />
These are all standard ports. If you want to edit a port, just edit the value.

Unlike the last version of this script, your clients will need to "Confirm" their attempt to login. This can actually be more benefiting than just a requirement to have the script work, slowing bots or etc. This is needed so that it actually will submit the information to the cpanel server, for cpanel.php only processes what it was told to on the form, but cannot automatically login without confirmation :P

The first part asks if the "submit" button was clicked. then it checks to make sure both fields "user" (username) and "pass" (password) have information values, if not display the following error, "Please complete all fields." as well as a "go back" link. However, if all information is found, then it proceeds with checking if the "secure" value equals "1" (aka, if the user has checked that he/she wants a SSL connection). If so, it will login using "https" and port "2083" (the secure cPanel port), if the box was unchecked, it will login using "http" and port "2082" (the insecure cPanel standard port). Then it gives a confirmation-like message which is more so needed to submit the information that was processed, to the cpanel location. That process is the secure feature and server request checking, but not processing the username/password.

You may edit the HTML parts of the code as you wish, but keep the names and values of the form input items as well as the <form> tag(s). You can reorder them anyway you wish, just do not put them outside the <form> tags or change those attributes. Well, you can change the submit button's value, of course, but the others should be left alone.

And that's it! It should all work well as long as you edited just that one part in the html form. About to write up additional customizations possibly, in my next post.
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks GamingHybrid for this great post!
H&M's (January 12th, 2008)
Old January 10th, 2008, 12:11 AM   #2 (permalink)
Surpass Abuse Admin
Super #1
 
removed's Avatar
 
Joined in Mar 2005
Lives in Houston, TX
Hosted on NONE
7,797 posts
Gave thanks: 11
Thanked 278 times
Great guide. Cleaned up the posts a bit (deleted the one in the middle) so you should be good to go now.
__________________
Unofficial IRC Channel: #surpass EFNet
Unofficial = No official support. Support requests can be submitted to our helpdesk.
removed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 10th, 2008, 12:16 AM   #3 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Quote:
Originally Posted by removed View Post
Great guide. Cleaned up the posts a bit (deleted the one in the middle) so you should be good to go now.
Thank you, wanted to edit it in time. Just sent a PM about editing the first post, as the html form code and php code has been updated.

So, to anyone, please wait until removed confirms that he has edited the first post before using this tutorial.
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 10th, 2008, 12:54 AM   #4 (permalink)
Surpass Abuse Admin
Super #1
 
removed's Avatar
 
Joined in Mar 2005
Lives in Houston, TX
Hosted on NONE
7,797 posts
Gave thanks: 11
Thanked 278 times
Everything is good to go now.
__________________
Unofficial IRC Channel: #surpass EFNet
Unofficial = No official support. Support requests can be submitted to our helpdesk.
removed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks removed for this great post!
Patty (January 12th, 2008)
Old January 10th, 2008, 1:03 AM   #5 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Quote:
Originally Posted by removed View Post
Everything is good to go now.
Thank you, removed I appreciate it.

To anyone needing support, I'll give it! I'm subscribing to this thread. However, everything should go fine.
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks GamingHybrid for this great post!
Patty (January 12th, 2008)
Old January 12th, 2008, 11:41 AM   #6 (permalink)
Registered User
Excelling Contributor
 
Joined in Feb 2005
540 posts
Gave thanks: 86
Thanked 24 times
Great!!! I'll try it and post back here.
__________________
Patty

Pass 57 | Dime999 | SH 110
Patty is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 12th, 2008, 1:04 PM   #7 (permalink)
Registered User
Excelling Contributor
 
Joined in Feb 2005
540 posts
Gave thanks: 86
Thanked 24 times
Thank you very much, GamingHybrid!!!
It's working 100% now with both IE and FF. :
__________________
Patty

Pass 57 | Dime999 | SH 110
Patty is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks Patty for this great post!
GamingHybrid (January 14th, 2008)
Old January 14th, 2008, 7:16 AM   #8 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Quote:
Originally Posted by Patty View Post
Thank you very much, GamingHybrid!!!
It's working 100% now with both IE and FF. :
Hehe, no problem Patty The method being used isn't loose like the old one, so it is much more secure (which the other was too, in a sense, just not like this version)

I also hope you like the new addon features Thought it'd help since in the old thread, people were considering using the code with multiple forms (this reduces that need)

Anyways, hope you enjoy it and to anyone else, please do post feedback. It helps me improve as well as know if it is working correctly or not.
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 14th, 2008, 8:13 AM   #9 (permalink)
Registered User
Excelling Contributor
 
Joined in Feb 2005
540 posts
Gave thanks: 86
Thanked 24 times
Yeah, I love the addons!!! It's the icing in the cake! Great job!!
__________________
Patty

Pass 57 | Dime999 | SH 110

Last edited by Patty; January 14th, 2008 at 8:21 AM..
Patty is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks Patty for this great post!
GamingHybrid (January 14th, 2008)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On