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.

WHM plugin: Save account custom parameters

Discussion in 'cPanel Developers' started by tizoo, Aug 19, 2012.

  1. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    In the plugin (whm/cpanel) that we are currently developping we need to save custom parameters related to some cPanel accounts.

    We want those informations to be backuped and transfered with the normal backup and transfer function of cPanel and we don't want that users can modify them. Thus we thought about using a file saved in this directory :

    Code:
    /var/cpanel/userdata/<username>/my_plugin.conf
    But it seems that this file is not transfered when the account is transfered on another server.

    Another idea was using the cpanel information file :

    Code:
    /var/cpanel/users/oneuser
    But we didn't find anything in the API showing the possibility to use custom configurations for cPanel accounts and we don't know if it's a good idea as this file is maybe overwrite (instead of modified) by some WHM/cPanel specific function.

    Another possibility was to save those informations in a file directly in the user account but with rights that prevent the user to modify it. But this possibility is not really valid in a unix point of view.

    Is there another place where we can save custom account parameters in a easy way ?

    Thanks for any tips.

    Cheers,
    Philippe
     
  2. 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
    Only the users home directory is transferred with an account copy. Everything else is recreated through the Whostmgr::Accounts::Create and PkgAcct::Restore processes. As far as I understand it, /var/cpanel/users/$user will be re-created during a transfer so you won't be able to send it over.

    You could however use a custom hook for PkgAcct::Create and PkgAcct::Restore hooks to read your information from your custom config file, save it to the user's home directory (both in PkgAcct::Create (pre)) , and restore it to the proper location after the account is transferred (PkgAcct::Restore (pre or post)):

    Account Packaging, Backups, and Transfers Functions


    In order to modify the information via the XML/JSON API, you can make your own custom API2 function ( Writing cPanel Modules ) and call it via the XML/JSON API ( cPanel XML and JSON APIs ).
     
  3. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi Dave,

    Thank you for your answer. I also came to the conclusion that this directory is created when copying a package.

    Using cpanel hooks may be a solution but not really KISS, which means more problems, bugs, and so on.

    A solution could be using the file

    Code:
    /var/cpanel/users/<username>
    As it is backuped, transfered when copying an account on another server and deleted when deleting an account. Although the file could be easily manipulated with PHP we don't think it's a good solution as it would be more secure to manipulate it through a cPanel API but this doesn't exist for custom parameters and maybe this file would be modified in the future by the cPanel guys.

    Another idea is using an encrypted file in the user home directory...

    Maybe cPanel guys could told us whether there is another solution than using the complexe manipulation you described or not ?

    Thanks in advance for any tips

    Philippe
     
  4. 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
    If you're willing to write perl to accomplish this task, you can use the cPanel modules /usr/local/cpanel/Cpanel/Config/LoadCpUserFile.pm and /usr/local/cpanel/Cpanel/Config/SaveCpUserFile.pm to manipulate the user file within your custom API2 tag.

    You could also use the NVDATA part of the API to store and retrieve data in/from /home/$user/.cpanel/ and use whatever encryption methods you prefer.
     
  5. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi Dave,

    Finally we decided to use a file owned by root in the home directory of the user, which was the simplest solution.

    Thanks for your differents suggestions.

    Cheers,
    Philippe
     
Loading...

Share This Page