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.

Domains in cPanel / Force IP Resolve in PHP

Discussion in 'cPanel Developers' started by mattmindshelf, Mar 29, 2012.

  1. mattmindshelf

    mattmindshelf Member

    Joined:
    Jul 7, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    We've got a system using the cPanel API to add domains / subdomains.

    As part of the overall system, we have a website crawler which indexes content for any one of the above domains / subdomains.

    I've tried PHP functions fsockopen and stream_socket_client (binding the socket to the dedicated IP address of the server) in hope to index these sites, even if the DNS externally isn't correct.

    Is there any way I can configure cPanel / WHM / BIND to use to local zone files irrespective of external DNS set up if the domain in question is configured on the server itself?

    Hope there's a solution and someone can help!
    Thank you in advance,
     
  2. mattmindshelf

    mattmindshelf Member

    Joined:
    Jul 7, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    OK we've managed to find a route to do this and it involves editing the hosts file on the fly. Obviously root owns this file, so it can't be performed by the PHP user with our server set up.

    We're using the cPanel XML API to create the domains / sub-domains. I'm now looking at the hooks for cPanel events.

    Is there any advice anyone can give? This essentially involves taking the domain / subdomain from the hook arguments and adding our dedicated IP address to the hosts file.

    From what I understand, the required hooks will need to be escalated from the cPanel user to the root user - I've looked through documentation and also read various forum posts.

    Rather than scripting in perl, I'd like to run scripts as PHP.

    Can anyone provide me with any advice / guidance as to the best way to achieve this?

    Thanks in advance,
     
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    You can use the escalateprivs setting with cPanel's Standardized Hooks system to escalate user privileges after subdomain creation:

    Taxonomy of the Standardized Hooks System


    The hook for subdomains is:

    Code:
    Cpanel:
       Api2::SubDomain::addsubdomain:
          stage: post
          escalateprivs: 1
          exectype: script
    

    The hook for domains is:

    Code:
    Whostmgr:
       Accounts::Create:
          stage: post
          escalateprivs: 0
    
    Note that you must use a script hook in order to escalate privileges for Cpanel - Api2::SubDomain::addsubdomain. The Whostmgr - Accounts::Create hook already runs as root.
     
Loading...

Share This Page