Jump to content
pratik_asabe

Need to modify a hook

Recommended Posts

Hello there, I recently added a hook for inserting a website name in webmail sidebar option instead of default server hostname:2096 I achieved domainname:2096, but problem with this hook is it is inserting website without checking first whether that child menu item is present or not there and because of that I'm getting an error on other module's product details page such as VPS service in which hook tries to set a URI for a menu child which does not exist and in result I'm unable to view my product details page, so I want an addition in my hook that checks always first if the menu child exists before it tries to add website name in it. 

hook is:

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{

$service = Menu::context('service');    
$domain = $service->domain;

if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
            $primarySidebar->getChild('Service Details Actions')
                           ->getChild('Login to Webmail')
                           ->setUri('http://'.$domain.'/webmail');
   }

 

I hope somebody will help me with what I'm trying to achieve. Thanks in advance.

Share this post


Link to post
Share on other sites
18 hours ago, pratik_asabe said:

I hope somebody will help me with what I'm trying to achieve.

take a look at the hook posted in the thread below and see it that helps you... in that hook, it's detecting if the server type is a cPanel product and only if it is, does it then add the updated cPanel/Webmail links - you should be able to adjust it for a different server type if you need to for VPS.

Share this post


Link to post
Share on other sites

Thanks a ton!! However while looking into your provided thread, I love the separate sidebar for the cPanel & webmail and I wanted to implement it on my system, however, I do not want to provide static cPanel link for my client instead I want to stick to the single sign-on link coz my client love that, so can you please provide me the updated hook to add single sign-on feature in your hook. Thanks a ton in advance!!

 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) {
    
    $service = Menu::context('service');    
    $servertype = $service->product->servertype;

    if ($servertype!="cpanel"){
        return;
    }

    $domain = $service->domain;
    $username = $service->username;
    $cpanelhref = 'http://'.$domain.':2082/login/';
    $webmailhref = 'http://'.$domain.':2095/login/';
    $command = 'DecryptPassword';
    $postData = array('password2' => $service->password);
    $results = localAPI($command, $postData);
    $password = $results['password'];
    
    $bodyhtml = '<form method="post" action="'.$cpanelhref.'" target="_blank">
<input type="hidden" name="user" value ="'.$username.'"/>
<input type="hidden" name="pass" value ="'.$password.'"/>
<input class="btn btn-success btn-sm btn-block" type="submit" value="'.Lang::trans('cpanellogin').'"/>
<input class="btn btn-primary btn-sm btn-block" type="submit" formaction="'.$webmailhref.'" value="'.Lang::trans('cpanelwebmaillogin').'"/>
</form>';  
   
    if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
            $primarySidebar->getChild('Service Details Actions')
                            ->removeChild('Login to cPanel')
                            ->removeChild('Login to Webmail');
    }    
            $primarySidebar->addChild('cPanel Login', array(
                            'label' => 'cPanel Logins',
                            'icon' => 'fa-server',
                            'order' => 20,
                            'footerHtml' => $bodyhtml,
                            ));
});

Share this post


Link to post
Share on other sites
23 hours ago, pratik_asabe said:

Thanks a ton!! However while looking into your provided thread, I love the separate sidebar for the cPanel & webmail and I wanted to implement it on my system, however, I do not want to provide static cPanel link for my client instead I want to stick to the single sign-on link coz my client love that, so can you please provide me the updated hook to add single sign-on feature in your hook. Thanks a ton in advance!!

try the attached file - i've modified the cPanel link to use SSO; by default, the webmail link doesn't use SSO as i'm unsure if WHMCS supports doing so - certainly, the sidebar link that it's sidebar generates doesn't use it.

cpanelsidebar.php

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines