pratik_asabe Posted March 12, 2019 Share Posted March 12, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 13, 2019 Share Posted March 13, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
pratik_asabe Posted March 13, 2019 Author Share Posted March 13, 2019 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, )); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 14, 2019 Share Posted March 14, 2019 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 0 Quote Link to comment Share on other sites More sharing options...
pratik_asabe Posted March 14, 2019 Author Share Posted March 14, 2019 Thanks a lot, Brian! You are great!! it works like a charm. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.