Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ajax_locale_delete_local_key.pl

#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - whostmgr/docroot/cgi/ajax_locale_delete_local_key.pl
#                                      Copyright 2026 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

use cPstrict;

use CGI                           ();    ## no critic (PreferredModules)
use Cpanel::JSON                  ();
use Cpanel::Locale                ();
use Cpanel::Locale::Utils::Custom ();
use Cpanel::SafeRun::Object       ();
use Whostmgr::ACLS                ();

no bytes;                                # brings in bytes::functions && keeps bytes symantics as-is

_check_acls();

my $cgi    = CGI->new();
my $key    = $cgi->param('key');
my $theme  = $cgi->param('theme');
my $locale = $cgi->param('locale');

my $saved   = 0;
my $error   = 0;
my $value   = '';
my $charset = 'utf-8';

if ( $key && $theme && $locale && $locale !~ m{\W} && length($locale) <= 64 ) {

    $theme = '' if $theme eq '/';

    if ( Cpanel::Locale::Utils::Custom::del_key( $key, $locale, $theme, 1 ) ) {
        $saved = 1;

        Cpanel::SafeRun::Object->new(
            'program' => '/usr/local/cpanel/bin/build_locale_databases',
            'args'    => [ '--clean', '--quiet', "--locale=$locale" ],
        );

        local $Cpanel::CPDATA{'RS'} = $theme eq '/' ? '' : $theme;
        my $lh = Cpanel::Locale->get_handle($locale);
        $charset = $lh->encoding();
        {
            no warnings 'once';
            $value = ${ $lh->get_language_class() . '::Lexicon' }{$key} || $Cpanel::Locale::en::Lexicon{$key} || $key;    # compiled keys are not put back in CDB tied hash but kept in object;
        }
    }
    else {
        $error = "del_key() returned false";
    }
}

my $json = Cpanel::JSON::Dump(
    {
        'status' => $error ? 0      : 1,
        'text'   => $error ? $error : $value,
        'saved'  => $saved,
    }
);

print $cgi->header( '-type' => 'text/plain', '-charset' => $charset, '-Content_length' => bytes::length($json) );
print $json;

sub _check_acls {
    Whostmgr::ACLS::init_acls();

    if ( !Whostmgr::ACLS::checkacl('locale-edit') ) {
        print "Status: 401\r\nContent-type: text/plain\r\n\r\n";
        print Cpanel::JSON::Dump( { 'status' => 0, 'text' => "Permission denied" } );
        exit();
    }
}
Back to Directory File Manager