#!/usr/local/cpanel/3rdparty/bin/perl
package scripts::whmlogin;
# cpanel - scripts/whmlogin Copyright 2019 cPanel L.L.C.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
use strict;
use warnings;
use Cpanel::SafeRun::Object ();
use Cpanel::JSON ();
exit( __PACKAGE__->run(@ARGV) ) unless caller();
sub run {
my ( $self, @args ) = @_;
if (@args) {
my $help = grep( m/help/, @args ) ? 1 : 0;
my $msg = "Generate a single use auto-login url for WHM\nUsage: $0\n";
if ($help) {
print STDOUT $msg;
return 0;
}
print STDERR "Invalid arguments: @args\n\n$msg";
return 1;
}
my $run = Cpanel::SafeRun::Object->new_or_die(
'program' => '/usr/local/cpanel/bin/whmapi1',
'args' => [ '--output=json', 'create_user_session', 'user=root', 'service=whostmgrd' ]
);
my $json = $run->stdout();
my $out = Cpanel::JSON::Load($json);
if ( !$out->{'metadata'}{'result'} ) { die "whmapi1 create_user_session failed: $out->{'metadata'}{'reason'}" }
print $out->{data}{url} . "\n";
return 0;
}
@KyuuKazami