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.

Alternative to "/scripts/postrestoreacct" (event after account transfer from other server)

Discussion in 'cPanel Developers' started by jleckie, Apr 26, 2016.

  1. jleckie

    jleckie Member

    Joined:
    Feb 4, 2016
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Midwest
    cPanel Access Level:
    Root Administrator
    So here is where I found information pertaining to my use case/this script.

    I've read that /scripts/postrestoreacct is deprecated, and from that same page:

    On both the System and Whostmgr "functions" pages, I see no events that replicate this functionality of triggering custom code once the files from a transferred account have finished migrating.

    What I'm trying to do:

    Create a "Standardized Hook" that listens for an event that signifies that the files pertaining to a cPanel account that has been transferred from another server have successfully been copied. I want to then modify the contents of one of the files included in some sub-directory. I've been searching for about a week and I have yet to find anything that can point me in the right direction to implement this functionality(other than the deprecated "/scripts/postrestoreacct".)

    If anybody has any ideas, they would be much appreciated!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,814
    Likes Received:
    672
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Does this hook need to be exclusive to accounts that are transferred, or, since accounts are created by the system during the transfer process, is the Accounts::Create event a suitable alternative for you?

    Thank you.
     
  3. jleckie

    jleckie Member

    Joined:
    Feb 4, 2016
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Midwest
    cPanel Access Level:
    Root Administrator
    Hey Michael!

    This hook does in fact need to be exclusive to accounts that are transferred. What I'm intending to do is replace hardcoded database credentials on an incoming account(website). The process would ideally look like this:
    1. Initiate cPanel account transfer
    2. Fire "Accounts::Create" event + my custom "Standardized Hook" that creates a database + user and assigns permissions of that database to that user(this is done)
    3. Detect when the files for the account have arrived, and programmatically swap out the hardcoded database name, database user, and database user password
    From what I can tell, when the Accounts::Create event fires, the files have yet to be completely transferred. My way of determining this was to compare the output from "tail -f /usr/local/cpanel/logs/error_log" to the visual(GUI) output of the "WHM Transfer Tool". The account creation event fires before the files have finished streaming over. If my code executes before all of the files are transferred, I'm not sure that the particular file that I want to edit will exist. I was looking into how the "Transfer Tool" moves files, and I believe I read somewhere that it behaves similarly to PktAcct::Create in that it compresses the entire directory, moves it over and unpacks("restores") it. So I would assume that when it is done unpacking, it will fire an event off somewhere that I can hook into... Any ideas?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,814
    Likes Received:
    672
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    We recently published a document on transferring accounts via WHM API 1 at:

    WHM API 1 Function Calls - Transfer and Restore Walkthrough - cPanel Knowledge Base - cPanel Documentation

    This might help give you an idea of how to better implement the hook. My initial thought is that you could develop a script that performs a specific action when the WHM API 1 "get_transfer_session_state" function shows a completed status:

    WHM API 1 Functions - get_transfer_session_state - Software Development Kit - cPanel Documentation

    However, there are likely a few different alternatives to that idea, depending on how you prefer to develop the script.

    Thank you.
     
Loading...
Similar Threads - Alternative scripts postrestoreacct
  1. partizanes
    Replies:
    3
    Views:
    145
  2. ITGabs
    Replies:
    1
    Views:
    391

Share This Page