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.

Detecting cPanel with PHP

Discussion in 'cPanel Developers' started by Tyler.S, Oct 15, 2010.

  1. Tyler.S

    Tyler.S Member

    Joined:
    Sep 25, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ontario Canada
    I am currently developing a php script that will verify a server's configuration. I am wondering if there is anyway to use php to contact a server to verify it is using cpanel and to find out what version?

    I have thought about just using a port scanner and scanning the WHM and cPanel login ports but the issue I run into is just because these ports are open doesn't mean that it is cpanel using them.

    Any ideas? Or does anyone know where I can find some documentation on this?
     
  2. doni49

    doni49 Well-Known Member

    Joined:
    Oct 4, 2006
    Messages:
    74
    Likes Received:
    0
    Trophy Points:
    6
    Not sure what you're trying to accomplish, but you could have your script load the cPanel login page. Then your script could read the contents of the page and see if it's loading the login images etc.
     
  3. Tyler.S

    Tyler.S Member

    Joined:
    Sep 25, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ontario Canada
    Thanks for the reply and suggestion. Again I am constructing a PHP script that will scan a servers configuration and determine if it meets our product's system requirements. We do not require cPanel but we recommend it for it's ease of use for our product.

    I have constructed a function to scan and determine what php version, if they have sql installed and what version, what type of OS (ie. Linux/Windows) and so, but I want to be able to detect if cPanel/WHM is installed if a unix os has been detected.

    There are functions for sql and php checks but I am not aware of anything for cPanel/WHM. Now as far as your suggestion it is interesting but very involved and I was hoping for a less intertwined option.
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I do not understand how your product is executed or what environment it expects to be executed in. Do your (potential) users execute your PHP script on their servers? Or is the program executed by you and run externally of their servers (without authentication).

    If you're working external to their server, without authentication, I'm not sure that what you want is programmatically possible, from the WHM/cPanel side.

    Unless you have credentials to authenticate in to the server (whether those credentials are for WHM, cPanel, SSH, FTP, etc), you're not going to be able to get any definitive WHM/cPanel information.

    So, without credentials, the only option is to parse the HTML form served on one of the WHM/cPanel ports, as previously mentioned. It can be as simple as cURLing the page (which is very simple in PHP) and looking for a string (strpos()) within the content, say "© cPanel, Inc.". It wouldn't be 100% fool-proof, but the likelihood of someone having that string in a page they serve on port 2083 that also has a credential form would be small.

    If, on the other hand, you have the ability to login (via browser or SSH) then your work is cut out for you. Via the browser, you could make either the XML-API native call 'version' (if you have root or reseller credentials) or API2 StatsBar::stat via XML-API. If you have shell access you can just look for /usr/local/cpanel/version. (In future product releases, I believe the definitive source will be: /usr/local/cpanel/Cpanel/Version/Tiny.pm)

    Regards,
    -DavidN
     
  5. Tyler.S

    Tyler.S Member

    Joined:
    Sep 25, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ontario Canada
    Our product is installed on their server. But what I am creating is a system configuration verifier. It scans the server to see if it meets our requirements. And yes this script they download from us and then upload to their server via FTP and then browse to the PHP file there by executing the script and it scans their server.

    We are not looking for any login permissions or anything. So if I do choose to go with the port scanning options is there any ports other then 2082-2087 and what not that is normally only used by cPanel/WHM and is always open? Now I noticed 2077 used by cPanel WebDisk was open on my server but not to sure if it is because of the way I have it setup or if it is a default.

    I am just trying to avoid false positives.
     
  6. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Okay,

    So, yeah: you should be able to read, or at least verify that version file exist (/usr/local/cpanel/version). The likelihood of them even having the /usr/local/cpanel/ directory and NOT running cPanel is very slim.

    As far as the webdisk, I think that's default.

    -DavidN
     
Loading...

Share This Page