Skip to main content

UAPI Root

Comments

5 comments

  • cPanelMichael
    Hello :) Could you elaborate on this question? For instance, per it's description: UAPI accesses the cPanel interface's features.Use this API to access and modify cPanel account data and settings.
    This is documented here: Guide to UAPI How are you authenticating? Thank you.
    0
  • manoj_ghimire
    I have realised that UAPI is like an app for all cpanel users. I was going in different direction. we can call whm api accountsummary likethis ==>
    hostname.com:2087/json-api/accountsummary?api.version=1&user=username
    from perl script. What I actually want to make is a custom api getspamdstat, so that I can call my custom module
    hostname.com:2087/json-api/getspamstat?api.version=1&month=jan
    to get the JSON format data. Can you please help me on this? I have looked on
    0
  • cPanelMichael
    Could you elaborate further on the custom script you want to develop? What type of information are you attempting to obtain? Thank you.
    0
  • AndrewH.
    Looks like what you want is to make a custom WHM API 1 function. Unfortunately we do not have full modular support for 3rd party API development in WHM like we do in cPanel. That said, if you want to make something that will work I can recommend going about this route but there are caveats. The first to be aware of is that any updates to your system will likely overwrite the modifications you make that are necessary. Second is this is not fully supported so you have to go into it knowing there is the possibility that you will break your server and we may not be able to help you. That out of the way.... To add a new WHM API 1 call you just need to add in a snippit of code similar to this to my %APPLIST = (....
    'getspamstat' => [ { 'version' => 1, 'args' => [qw(any args you need)], #this is not required if this requires no args 'code' => sub { my ( $metadata, $args ) = @_; return Path::To::Module::somefunction( $args, $metadata ); }, #Put this in if you want only root to use it, remove it if you want anyone with WHM access to use it. 'check' => sub { return Whostmgr::ACLS::hasroot(); }, }, ],
    And for your somefuncton you want to return something similar to this
    sub somefunction { my ( $args, $metadata ) = @_; ...some code... $metadata->{'result'} = 1; #if success, if failure use 0 $metadata->{'reason'} = 'OK'; return { 'somekey' => $ref_to_data_to_return }; }
    That should be enough to get you going on this. Good luck and please feel free to respond if you run into any hiccups!
    0
  • manoj_ghimire
    cPAndrewHodge Thanks I will try it. is %APPLIST global variable for cpanel. cPanelMichael I am basically trying to get the stats of the spamassasin. Stats about total mails scanned from date1 to date 2, total spams at the same date range and total clean mails. Here is the function i am working on:
    sub get_spam_stat { #Spamd Log File my ($args, $metadata) = @_; my $spamcount; #my $log_facility = $opt{'syslog'} || '/var/log/spamlog'; #Spamd executable Path my $spamd_bin = '/usr/local/cpanel/3rdparty/bin/spamd'; my $fh = IO::File->new(); my @array; if ($fh->open("< $spamd_bin")) { while (<$fh>) { if (/^my \$log_facility/) { last; } } @array = (split/\|\|/); if ($array[1]) { chomp($array[1]); $array[1] =~ s/['; ]//g; } else { die "Cannot parse message."; } $fh->close(); } else { $metadata->{'result'} = 0; $metadata->{'resaon'} = "$!"; return; } if ($array[1] =~ /var|log|[\w]+/i) { my ($spam_count, $spam_checked, $clean_mails); $fh = IO::File->new(); if ($fh->open("< $array[1]")) { while (<$fh>) { if (/spamd:.*identified/) { $spam_count++; } if (/spamd:.*checking.*message/) { $spam_checked++; } if (/spamd:.*clean.*message/) { $clean_mails++; } } $fh->close(); } $metadata->{'result'} = 1; $metadata->{'reason'} = 'OK'; return {'spam_stats' => [{'total_spams'=> $spam_count, 'total_msg_checked' => $spam_checked, 'clean_msg' => $clean_mails}]}; } }
    0

Please sign in to leave a comment.