The Server Pages


TheServerPages Articles







Adding new functionality to CPanel

Author: Wojjie     Posted: 2004-06-27     Viewed: 13,613


You want to build some new functionality into the existing CPanel control panel, but do not know where to start. Well, it can be quite easy with some knowledge of HTML and PHP.


CPanel comes with a few themes users can use, all with different styles and ways of organizing information. All these themes are located in the following directory:


All the theme directories follow the structure of a normal website, except the html files have some CPanel specific tags.

(Ie. 'index.html' is the file rendered when accessing the directory)

Introduction to some CPanel tags:

All cpanel tags start with '<cpanel' followed by the command and parameters, then followed by a close '>'.

feature ex:
<cpanelfeature hotlink>
In the above example, the html inbetween the tags would be rendered if the feature 'hotlink' is enabled for the current account. (The short form name is used in this tag)

There is a list of features with the short form names in the file:
The format of this file is: short name:long name

hotlink:Hotlink Protection

if ex:
<cpanelif $isreseller>
In the above example, the html inbetween the tags would be rendered if $isreseller=1. You can use the print fuction to display the value of the variable, and you should get 0 if it is false, and 1 if it is true.

include ex:
<cpanel include="stdheader.html">
The same as a Server Side Include (SSI). The above example includes the file 'stdheader.html' which is located in the same directory.

langprint ex:
<cpanel langprint="frontend-lastlogin">
Prints the preset found in the selected language for the current account. Language files are found in:
The structure of the file is:
preset = string

frontend-lastlogin=Last login from
(Comments start with '//')

print ex:
<cpanel print="DOMAIN">
Used to print variables without the need of PHP or any other scripting languages.

Things to remeber/consider:

When any page or script is being accessed in the control panel, it is always executed as the user that is currently logged in.

When adding new files or scripts that are accessible through the control panel, you should always set ownership to: root:root (user:group), and chmod it to 644 for files, or 755 for directories. This will help prevent some hack attempts. For instance, if the script you add has a vulnerability that allows the attacker to modify a file, he will be unable to do so since no script has the right permissions to do so. If he is able to modify a script, he can easily have it send out other users passwords and logins to another server, which can be disasterous.

Last thing, never be lazy when developing scripts for CPanel, always excercise proper and secure programming techniques. If worst comes to worst, there are access logs in the directory:


How to add the functionality:

Best method to add functionality to CPanel is to place all the scripts you want to add in a directory and symbolic link it into every theme directory.

1. Place your scripts into a directory. You can place it within a directory under: '/usr/local/cpanel/3rdparty/'
2. Go into every theme directory you want to add to, and link the directory.

ln -s /usr/local/cpanel/3rdparty/myAddon

Next you will want to add a button to all themes you wish to have the functionality in.

Available PHP Environment Variables:

Here is a list of environment variables that may be found very useful when coding your own add-ons.

$_ENV["DNS"]Domain name account is tied to.
$_ENV["DOMAIN"]Similar to DNS.
$_ENV["HOME"]Path to home directory
$_ENV["SHELL"]Shell used for account
$_ENV["REMOTE_PASSWORD"]Account password
$_ENV["USER"]Account Username


Copyright © 2004-2015: