<?php
# Primary Sidebar cPanel Login Form
# Written by brian!
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) {
$client = Menu::context('client');
$clientid = 4;
if ($client->id == $clientid) {
$service = Menu::context('service');
$servertype = $service->product->servertype;
if ($servertype != ""){
return;
}
$username = 'username';
$password = 'password';
$cpanelhref = 'https://www.domain.com:2083/login/';
$webmailhref = 'https://www.domain.com:2096/login/';
$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,
));
}
});
there are a handful of variables that you will have to update...
$clientid -> this is the client's ID value - you can get it from their client summary in the admin area.
username & password -> obviously change these to those given by your client.
cpanelhref & webmailhref -> replace domain.com with the url of your client.
if you don't want to show the webmail link, then just remove the last <input> line from the hook.
for the given user, assuming you get the username, password and URL correct, it should log them directly into cPanel without asking for login details.