Custom UAPI Module - cPanel Variables
I'm working on a custom UAPI module that will be called from WHM API 1. So far I've been able to perform basic functions and return the information I need. However I'm stuck trying to figure out how to properly retrieve the home direction of the current user.
I found that I could access the CPDATA variables like:
However, that only provides variables from the /var/cpanel/users/user file which does not include the home dir. I need to be able to access the home direction of the current user and I'm having trouble finding the proper way to do that. I'm calling my custom UAPI function with:
my $user = $Cpanel::CPDATA{'USER'};
However, that only provides variables from the /var/cpanel/users/user file which does not include the home dir. I need to be able to access the home direction of the current user and I'm having trouble finding the proper way to do that. I'm calling my custom UAPI function with:
example.com:2087/json-api/cpanel?cpanel_jsonapi_user=myuser&cpanel_jsonapi_module=WPAPI&cpanel_jsonapi_func=myfunction&cpanel_jsonapi_apiversion=3
-
Hello, The following UAPI function is available if you want to obtain the account's home directory path: UAPI Functions - DomainInfo::domains_data - Software Development Kit - cPanel Documentation If you need to obtain the document root utilized by a specific domain name, then you'd use the following UAPI function: UAPI Functions - DomainInfo::single_domain_data - Software Development Kit - cPanel Documentation Thank you. 0 -
Michael, Thanks for the info.. I tried those functions but I kept getting errors.. I must not be using them properly. I'm getting this error: Can't call method "uapi" on an undefined value at /usr/local/cpanel/Cpanel/API/WPAPI.pm line 45.\n" I have included the LiveAPI use Cpanel::LiveAPI ();
so in my code:sub function { # $Cpanel::CPDATA pulls data from /var/cpanel/users/user file my $user = $Cpanel::CPDATA{'USER'}; my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once. # Get domain user data. my $get_userdata = $cpliveapi->uapi( 'DomainInfo', 'domains_data', { 'format' => 'hash', } ); ....
0 -
Hello, The LiveAPI System provides environments for applications in the cPanel interface. Is your custom application running within cPanel? If not, try testing this UAPI function via the command line first to verify it works. EX: uapi --user=username DomainInfo domains_data format=hash
Thank you.0 -
Running that command in your example above in the command prompt returns the correct info.. I am writing a UAPI custom module that will be accessed via the WHM API 1.. So I execute the functions of this module by calling the API from: myserver.com:2087/json-api/cpanel?cpanel_jsonapi_user=myuser&cpanel_jsonapi_module=WPAPI&cpanel_jsonapi_func=myfunction&cpanel_jsonapi_apiversion=3 Maybe I'm not using it like it was intended? What I'm trying to accomplish is to have our billing system perform various custom tasks.. So that's why I'm using the WHM API 1 to call this custom uapi module. Since the billing system has the cPanel API token for the root user, I want to use it to be able to perform things like install and manage different web applications for sites. Is there a better way to go about accomplishing this? Thanks! 0 -
I wasn't having trouble with the API call, that is working just fine and returning data. What I'm having trouble is getting the home dir info using sub function { # $Cpanel::CPDATA pulls data from /var/cpanel/users/user file my $user = $Cpanel::CPDATA{'USER'}; my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once. # Get domain user data. my $get_userdata = $cpliveapi->uapi( 'DomainInfo', 'domains_data', { 'format' => 'hash', } ); ....
I'm getting this error: Can't call method "uapi" on an undefined value at /usr/local/cpanel/Cpanel/API/WPAPI.pm line 45.\n" Thanks for your input and assistance!0 -
Could you provide some more information about how you are setting up the LiveAPI script? For instance, where do you call it from? Is it uploaded to a website, or as part of a plugin you open in the cPanel interface? Thank you. 0 -
Here's a simple example: UAPI module MyExample.pm (/usr/local/cpanel/Cpanel/API/MyExample.pm) package Cpanel::API::MyExample; use strict; our $VERSION = '1.0'; # Cpanel Dependencies use Cpanel (); use Cpanel::API (); use Cpanel::Locale (); use Cpanel::Logger (); use Cpanel::LiveAPI (); # Globals my $logger; my $locale; # Functions go here. sub getUserInfo { # $Cpanel::CPDATA pulls data from /var/cpanel/users/user file my $user = $Cpanel::CPDATA{'USER'}; my ( $args, $result ) = @_; # Build the results. my $success = "true"; if ($success) { $result->data("$user"); return 1; } else { return 0; } } 1;
I call it with WPAPI (using the API token in the headers):
I need to be able to find user's Home Directory. When I add the LiveAPI code mentioned earlier in this thread, that's when I get the error: Can't call method "uapi" on an undefined value at /usr/local/cpanel/Cpanel/API/WPAPI.pm line 45.\n" Am I not able to use that uapi function that way? If so, how could I get additional user information like their home directory? Thanks!0 -
cPanelMichael, Thanks for you suggestions! Are there any other ways to be able to write custom functions for the WHM API? I was hoping to use WHM/cPanel's existing API and add some custom functionality but it looks like I'm going to need to create my own custom API separate from cPanel/WHM. 0 -
Are there any other ways to be able to write custom functions for the WHM API?
Could you provide a specific example of what you'd like to do? Thanks.0 -
I decided to change my approach a little bit. Instead I'm going to create a cPanel php live plugin and I'll use single signon to automatically login and take the user to my cPanel plugin logged in as the user. I created an API2 module that my cPanel plugin calls. But I'm getting some permissions denied errors when I have it download some files to /var/mysoftware What would be the best way to allow my cPanel plugin to download some files to /var/mysoftware (which will be used by other users using this plugin). I have it check if the software hasn't been loaded or if it is outdated, then it downloads to that directory. 0 -
Just a little update, I get the permission denied errors if I try download with a shell command using system.. When using LWP::Simple, it returns 200 status but doesn't actually save the file to /var/mysoftware and no errors in the error log. I'm trying to figure out how to write to a /var or /opt/ directory using a UAPI module? 0 -
It may be helpful if I give you an example scenario with details of what I'm trying to accomplish. In this example, we'll have a cPanel plugin that will give the user some options for installing Wordpress. So when the user pull up my plugin they will be given a few options on some plugins and themes that will be auto-installed for them with their Wordpress installation. Once they select the desired options, the plugin will then install and customize the installation. So I have my cPanel plugin, Installer, which can be accessed through: 0 -
Hello, Do you notice any debugging data in the /home/$user/.cpanel/LiveAPI.log.rand when encountering the permissions error? Thank you. 0 -
No, the only files in that directory are: ./ caches/ datastore/ live-engine-connector-6G3GSJ2ISf.sock= live-engine-connector-Ohm6XdvRqO.sock= live-engine-connector-ypeNFypAbt.sock= nvdata.cache ../ contactinfo email_accounts.json live-engine-connector-mfeHRjXM7h.sock= live-engine-connector-_pdrnrFVCW.sock= nvdata/
0 -
I recommend sending an email to integration@cpanel.net so that one of our Integration Developers can take a closer look at the issue you are facing and determine if the action you are attempting to perform in your code is supported. Thank you. 0
Please sign in to leave a comment.
Comments
17 comments