Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Transfer tool hooks

Discussion in 'cPanel Developers' started by Anoop P Alias, Feb 26, 2019.

  1. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    101
    Likes Received:
    14
    Trophy Points:
    18
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. plesk4lyf

    plesk4lyf Member PartnerNOC

    Joined:
    May 21, 2018
    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Sydney
    cPanel Access Level:
    Root Administrator
    Hi Anoop,

    Although the script hook method is deprecated, they are still working and I've been using without an issue:

    Guide to Standardized Hooks - Script Hooks - Developer Documentation - cPanel Documentation

    /scripts/restoreacct
    The /scripts/restoreacct script's hooks trigger each time that the system restores an account.

    pre hook script:

    /scripts/prerestoreacct

    This script accepts the following arguments:

    • cpuser — The account's new (local) username.
    • olduser — The account's old (remote) username.
    • extractdir — The directory to which the system will extract the cpmove file.
    post hook script:

    /scripts/postrestoreacct

    This script accepts the following arguments:

    • user — The account's new (local) username.
    • olduser — The account's old (remote) username.
    • domain — The account's main domain.
    • user_homedir — The absolute path to the account's home directory.
    Just place a script that bash can execute. Here's an example if you want to test it:

    1. Make a file /scripts/postrestoreacct

    2. Put in it:
    #!/bin/bash

    ARRAY=($@)
    ARRAYLENGTH=${#ARRAY[@]}
    for (( ARG=0 ; ARG < $ARRAYLENGTH ; ARG++ ))
    do

    echo "ARG$ARG=${ARRAY[$ARG]}"

    done

    3. chmod it to execute:
    chmod +x /scripts/postrestoreacct

    4. Restore a test account

    If done correctly, you should see in the output of the restore log

    [ 7511][RESTORE:1 ][A:demouser ]: Progress: 79% (2019-02-27 04:42:23 +0000)
    [ 7511][RESTORE:1 ][A:demouser ]: PostRestoreActions
    [ 7511][RESTORE:1 ][A:demouser ]: Updating Caches …
    [ 7511][RESTORE:1 ][A:demouser ]: Enabling IPv6 for account …
    [ 7511][RESTORE:1 ][A:demouser ]: Updating Nameserver IP Address Report
    [ 7511][RESTORE:1 ][A:demouser ]: Syncing contact information
    [ 7511][RESTORE:1 ][A:demouser ]: Running postrestore script
    [ 7511][RESTORE:1 ][A:demouser ]: ARG0=demouser
    [ 7511][RESTORE:1 ][A:demouser ]: ARG1=demouser
    [ 7511][RESTORE:1 ][A:demouser ]: ARG2=demowebsite.com
    [ 7511][RESTORE:1 ][A:demouser ]: ARG3=/home/demouser

    [ 7511][RESTORE:1 ][A:demouser ]: PostRestoreActions

    Knowing the argument positions to the script, you can do simple things to trigger on restore, like change a theme:
    uapi --user="$1" Styles update type=default name=basic

    Or set to the system version of PHP:
    whmapi1 php_set_vhost_versions version=inherit vhost-0="$3"
     
  3. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    5,768
    Likes Received:
    440
    Trophy Points:
    233
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    As indicated by @plesk4lyf the hooks system is really the way to go and if the event isn't hookable you can create a hookable event Guide to Standardized Hooks - Hookable Events in Custom Modules - Developer Documentation - cPanel Documentation though I wouldn't use the script hooks as they are deprecated. They are still usable at this time though.

    The whostmgr functions would be what you want to look at Guide to Standardized Hooks - Whostmgr Functions - Developer Documentation - cPanel Documentation
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice