Creating secure remote logins to cPanel
cPanel provides a Perl module, Cpanel::LogMeIn, that allows you to query your server for a single-use URL. This URL can be used to grant remote access to cPanel, WHM, or Webmail without transmitting the user's password over the network.
How It Works
The Cpanel::LogMeIn::get_loggedin_url() function generates a temporary, single-use login URL for a specified service (cPanel, WHM, or Webmail). Once the URL is used, it expires and cannot be reused, making it much more secure than storing or transmitting passwords.
Example Perl Script
The following Perl script demonstrates how to use the Cpanel::LogMeIn module to generate a secure remote login URL:
#!/usr/bin/perl
use lib '/usr/local/cpanel';
use Cpanel::LogMeIn ();
my $user = USERNAME;
my $pass = PASSWORD;
my $host = DOMAIN;
my $service = 'cpanel';
my($login_ok,$login_message,$login_url) = Cpanel::LogMeIn::get_loggedin_url(
'user'=>$user,'pass'=>$pass,'hostname'=>$host,'service'=>$service,'goto_uri'=>'/'
);
if ($login_ok) { print "Location: $login_url\r\n\r\n"; }
else { print "Content-type: text/plain\r\n\r\n"; print "LOGIN FAILED: $login_message\n"; }
exit(0);
Parameters
- user - The cPanel username to log in as
- pass - The user's password (used server-side to authenticate and generate the URL)
- hostname - The domain or IP address of the server
- service - The service to log into:
cpanel,whm, orwebmail - goto_uri - The path within the panel to redirect to after login
Security Considerations
This approach is particularly useful for billing systems, support tools, or any application that needs to provide customers or administrators with one-click access to their control panel without exposing credentials. The generated URL is valid for a short time and can only be used once.