Jump to content

How to create module commands


souzadavi

Recommended Posts

Hello guys, I would like to developed a new module command button inside of cPanel server module. I attached under here a image to see where I would like to have a new button.

14460-7b6327a97be0fd269dfb5b68ecd37a3d.p

 

I didn't figured out how to create it, please any one know could get it done? I would like only some directions to get it done...

 

thanks

Link to comment
Share on other sites

It depends on that you want to do with that button. In fact you can't add in the usual way  (cPanel module is not open source) so you'll need to use jQuery in an action hook like follows.

<?php

add_hook('AdminAreaHeaderOutput', 1, function($vars)
{
    $output .= <<<HTML
    <script type="text/javascript">
    $(document).ready(function(){
        $("#modcmdbtns").append(' <button type="button" class="btn btn-danger"><i class="fa fa-shower" aria-hidden="true"></i> Bath Time</button>');
    });
    </script>
HTML;

    return $output;
});

Here's the result:

Attachments not working... well... the code adds a red button right after the last button "Change Password"

Edited by Kian
Link to comment
Share on other sites

I'using another hook, my script is like that:

add_hook('AdminClientServicesTabFields', 1, function($vars)
{
    $id = $vars['id'];
    $output .= <<<HTML
    <script src='/assets/js/softaculous_clone.js'></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#modcmdbtns").append(' <button type="button" class="btn btn-danger" onclick="softaculous_clone($id);" id="btnCloneSoftaculous"><i class="fa fa-wordpress" aria-hidden="true"></i> Clone WP</button>');
    });
    </script>
HTML;

    echo  $output;
});

My guess is about the .js file, how could it does to be safe.  I`m trying to use customs function, to call the php function, but i'm not sure if is the right way.

function softaculous_clone(idService){

    var data = {
        id: idService,
        modop: "custom",
        a: "softaculous_clone",
    }
    var request = new XMLHttpRequest();
    request.open('POST', '/clientarea.php?action=productdetails', true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.onload = function() {
        if (request.status >= 200 && request.status < 400) cb(request.responseText);
        else console.log(1, 'Houve um erro :(');
    };
    request.onerror = function() {
        console.log(2, 'Houve um erro :(');
    };
    request.send(data);

}

 

thanks, any information will be very appreciated. 

Link to comment
Share on other sites

@Kian I didn't find a way to call a php file safely from ajax. On the button I tried to use the function runModuleCommand but it doesn't find the softaculous function.

onclick="runModuleCommand('custom','softaculousclone')"I

929181569_Capturadetelade2020-04-2120-24-41.png.4712758e448c5398fb16b96ab9a1879d.png

I think because the function isnt on cpanel server modules. So do you know how can I call a ajax php function from that button "Bath Time" safe?

 

thanks

Link to comment
Share on other sites

  • 11 months later...
On 4/25/2020 at 4:46 AM, souzadavi said:

I get it done with the resource: https://www.softaculous.com/docs/api/api/#import-an-installation-from-remote-server 

If somebody need the script i can send it, let me know..

 

 

 

PS.: the whmcs oficial ticket support team never help is really bad!

 

Hi @souzadavi can you share the script ? I need to modify for another function to calling some value from database & show it on products/services page 🙂

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated