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.

Hooking nginx into cPanel/WHM

Discussion in 'cPanel Developers' started by ralphlw, Oct 12, 2009.

  1. ralphlw

    ralphlw Member

    Joined:
    Jan 2, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    It isn't hard to do the only problem is getting a supported post hook to have new accounts have their own .conf file in the nginx configuration directory and just include every file in there.
     
  2. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    maybe the cpanel staff can provide the hook so we can play with it :)
     
  3. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    What cPanel/WHM function(s) do you need to hook? There is a possibility we may already offer the ability to do post hooks on the functionality you need to hook.
     
  4. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    add new account, domain parking, domain addon, domain forwarding :)

    we need the hook to reload the script to generate new vhost.conf for nginx :)
     
  5. nvez

    nvez Active Member
    PartnerNOC

    Joined:
    Jul 17, 2006
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    Let me introduce you to ..

    /scripts/postwwwacct

    That's for after creating a new account.

    For the others, I'm sure cPanel has something in place or you can dig for that yourself.

    If they don't offer it, you could easily have a cronjob that runs every 5 minutes for the others.
     
  6. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    what i'm affraid is if there is a trouble if restarting nginx every 5 minutes :)
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You can find some more information on /scripts/postwwwacct at:

    ScriptHooks < DevHooks < TWiki

    Domain parking, addon domains and domain forwarding are handled by cPanel API functions. Part of this API architecture is the ability to create function hooks to execute your own shell script after these functions are executed. You can read more about this at:

    Hooking into cPanel Functionality

    We have some documentation on the Addon Domains API functions at: AddonDomainRef < DeveloperResources/ApiRef < TWiki

    We have documentation on Park Domains API functions at:

    ParkRef < DeveloperResources/ApiRef < TWiki

    The API 1 function call for adding a redirect (as used by the cPanel interface) is:

    <cpanel Mime="add_redirect(path, type, url, domain, wildcard, rdwww)">

    Mime is the module name
    add_redirect is the function name

    path is the path within the URL to redirect (if any)

    type is either temp or permanent

    url is the URL to redirect to

    domain is .* if ** All Public Domains ** is selected, otherwise it is the domain/addon domain/etc to redirect.

    wildcard is: 1 if this is a wildcard redirect

    rdwww is: 2 if "Only redirect with www. " is selected, 0 if "Redirect with or without www." is selected, or 1 if "Do Not Redirect www." is selected.
     
  8. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    how to adding it so if anyone adding a domain name it will run nginx.sh to regenerate the file vhost.conf
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Friendly Moderator Note

    I have moved our discussion about APIs and Hooks to a new thread in the cPanel/WHM Developer Discussions forum, where you are likely to receive more relevant feedback.
     
  10. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    So anyone want to share the cpanel hook for reloading vhost.conf file when a user using addon domain, domain parking, etc ?
     
  11. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    currently i know the file responsible for domain addon add and domain addon deleting which is doadddomain.html and dodeldomain.html.

    how i can put a code on it so it will run /scripts/nginx.sh after a domain successful added or deleted ?

    for doadddomain.html, i know it's should be put after the code below

    Code:
    <cpanelif !$CPERROR{'addondomain'}>
       <cpanel print="$FORM{'domain'}"> &nbsp;<cpanel langprint="AODCreateYes">!<br />
      <!--  <cpanel Ftp="addftp($FORM{'user'},$FORM{'pass'},$FORM{'dir'},,,$FORM{'dir'})"> -->
    <!--    If you would like to create an ftp account to upload files to this new domain, you can do so here: <a href="../ftp/addftp.html?domain$
    <br/>   <cpanel langprint="AODGoFileMgr">: <a target="_blank" href="../files/index.html?dir=<cpanel print="$homedir">/<cpanel print="$FORM{'d$
    
    </cpanelif>
    
    and for dodeldomain.html it's should be put after the code below

    Code:
    <cpanelif !$CPERROR{'addondomain'}>
       <cpanel langprint="AODAddedPre">&nbsp; <cpanel print="$FORM{'domain'}"> &nbsp;<cpanel langprint="RDRedRemText">!
        <br /><cpanel Ftp="delftp($FORM{'domain'})">
    </cpanelif>
    
    the problem is i don't know what is the syntax to run /scripts/nginx.sh (my nginx generation is nginx.sh)
     
  12. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Modifying the theme files will not accomplish what you want. DavidG earlier linked to our integration documentation. Please read the documents pertaining to 'hook' abilities.
     
  13. nsetiono

    nsetiono Active Member

    Joined:
    Mar 29, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    is there any sample how to use the hook ?

    i really newbie here about cpanel hook and really don't know what i must do and how to use the hook :(
     
  14. cPanelDon

    cPanelDon cPanel Quality Assurance Analyst
    Staff Member

    Joined:
    Nov 5, 2008
    Messages:
    2,557
    Likes Received:
    7
    Trophy Points:
    38
    Location:
    Houston, Texas, U.S.A.
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Please carefully review the documentation; this will be the best resource to help learn. If you have specific questions about something feel free to ask; however, if you need assistance creating something I would consider locating and hiring someone to develop the solution for you.

    The following advertising forums might help with locating a company to help:
    Server Management and Server Repair - cPanel Forums

    For details and examples, please thoroughly review the following documentation; the following link that cPanelDavidG provided should help:
    Hooking into cPanel Functionality

    Additional, more specific documentation pages linked from the above:
    WritingFunctionHooks < DevHooks < TWiki
    ScriptHooks < DevHooks < TWiki
    CustomEventHandler < DevHooks < TWiki
     

Share This Page