HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //scripts/run_plugin_lifecycle
#!/usr/local/cpanel/3rdparty/bin/perl

#                                      Copyright 2025 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package scripts::run_plugin_lifecycle;

use cPstrict;

=encoding utf-8

=head1 NAME

run_plugin_lifecycle

=head1 USAGE

run_plugin_lifecycle [--plugin <plugin name> --method <method name> | --help]

=head1 DESCRIPTION

This script triggers plugin specific initialization code in a standard way.

To implement plugin specific initialization code, create a module: Cpanel::<plugin_name>::Setup with an initialize() method.

=over

=item plugin - string

The name of the plugin to initialize.

=item method - string

The name of the method to call in the plugin Cpanel::<plugin_name>::Setup module.

Common methods are: install, uninstall, etc.

=item help

Show the help for this script.

=item verbose

Show more verbose output.

=back

=cut

use Common::JSONC            ();
use Common::Plugins::LoadRun ();
use Cpanel::Imports;

use parent qw( Cpanel::HelpfulScript );

use constant _OPTIONS => (
    'plugin=s',
    'method=s',
    'verbose!',
);

use constant PLUGIN_TO_MODULE => {
    'cpanel-socialbee-plugin' => 'Cpanel::SocialBee::LifeCycle',
    'cpanel-xovi-plugin'      => 'Cpanel::Xovi::LifeCycle',
    'cpanel-monitoring-plugin'=> 'Whostmgr::360Monitoring::LifeCycle',
};

use constant PLUGIN_TO_CONFIG_PATH => {
    'cpanel-socialbee-plugin' => '/var/cpanel/plugins/socialbee/lifecycle.jsonc',
    'cpanel-xovi-plugin'      => '/var/cpanel/plugins/xovi/lifecycle.jsonc',
};

__PACKAGE__->new(@ARGV)->run() if !caller;

=head2 I<OBJ>->run()

Runs this script.

=cut

sub run ($self) {
    my $plugin = $self->getopt('plugin');
    my $method = $self->getopt('method');

    if ( !$plugin || !$method ) {
        die $self->full_help();
    }

    my $module = PLUGIN_TO_MODULE->{$plugin};

    if ( !$module ) {
        die "Unknown plugin: $plugin\n";
    }

    my $config      = {};
    if ( exists PLUGIN_TO_CONFIG_PATH->{$plugin} ) {

        my $config_path = PLUGIN_TO_CONFIG_PATH->{$plugin};
        if ( $config_path && -e $config_path ) {
            $config = Common::JSONC::load_jsonc($config_path);
        }
        elsif ( $config_path && !-e _ ) {
            die "Could not find the config for $plugin. Did you forget to install this package?\n";
        }

        $config->{verbose} = $self->getopt('verbose') if defined $self->getopt('verbose');

        say $config->{$method}{description} if $config->{$method}{description};

        my $make_changes = !!0;
        if ( my $condition = $config->{$method}{condition} ) {
            require Cpanel::Plugins::Components::Rules;
            my $rules_obj = Cpanel::Plugins::Components::Rules->new( 'config' => $condition );
            $make_changes = $rules_obj->is_allowed();
            say "Condition not met for $plugin" if $config->{verbose} && !$make_changes;
            say "Condition met for $plugin"     if $config->{verbose} && $make_changes;
        }
        else {
            $make_changes = !!1;
            say "No condition provided, procceding" if $config->{verbose};
        }

        if ( !$make_changes ) {
            logger()->info("Nothing to do for $plugin.");
            say "Nothing to do for $plugin" if $config->{verbose};
            return 0;
        }
    }

    Common::Plugins::LoadRun::run_from_module( $module, $method );
}

1;