Viewing File: /usr/local/cpanel/base/frontend/jupiter/ssh/my_ssh.live.pl

#!/usr/local/cpanel/3rdparty/bin/perl
# Written by Serhii.bo
# Liveapi proxy for ssh management plugin

use strict;
use warnings "all";
use Cpanel::LiveAPI ();
use Whostmgr::Accounts::Shell;
use Cpanel::JSON;
use Cpanel::AdminBin::Call;
use Cpanel::DynamicUI::App;
use Cpanel::CachedCommand::Utils;
use Cpanel::Themes;
use CGI qw();


our ($resp, $shell_stat, $cpanel);
my $request = CGI->new;
$cpanel = Cpanel::LiveAPI->new();
my $cur_shell = $cpanel->cpanelprint('$hasvalidshell');
my $upd_shell = $request->param('shell');
my $shell_state = $request->param('sh_stat');

sub json_response {
    my $data = shift;
    print "Content-type: application/javascript\nCache-control: no-cache\r\n\r\n";
    print Cpanel::JSON::Dump($data);
}

if ('POST' eq $request->request_method && defined($upd_shell)) {
    $resp = Cpanel::AdminBin::Call::call('HostingCommon', 'SSH', 'mng_shell', $upd_shell);

    my $cache_name = Cpanel::DynamicUI::App::_get_cache_file_name();
    my $current_theme = Cpanel::Themes::get_user_theme($ENV{'USER'});
    my $full_cache_name = "$cache_name" . "$current_theme";

    Cpanel::CachedCommand::Utils::destroy( 'name' => "$full_cache_name");

    json_response({user=>$ENV{'USER'}, shell=>"$upd_shell", cache => $full_cache_name});
    exit(1);
} elsif ('POST' eq $request->request_method && defined($shell_state)) {
    $shell_stat = $cpanel->cpanelprint('$hasvalidshell');
    json_response({user=>$ENV{'USER'}, sh_stat=>$shell_stat});
    exit(1);
} else {
    json_response({user=>$ENV{'USER'}});
    exit(1);
}
$cpanel->end();
Back to Directory File Manager