MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/proxydomains
#!/usr/bin/perl
# cpanel - proxydomains                           Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use Cpanel::Proxy ();
use Getopt::Long;
use Pod::Usage;

if ( $> != 0 ) {
    die "Must be root to run /scripts/proxydomains";
}

# process arguments

my $help;
my $user;
my $domain;
my $man;
my $subdomain;

GetOptions( 'help' => \$help, 'man' => \$man, 'user=s' => \$user, 'domain=s' => \$domain, 'subdomain=s' => \$subdomain );

my $action = shift || ( $help = 1 );
$action = lc $action if $action;

# validate

if ( $user && $domain ) {
    pod2usage("User and Domain can not be specified at the same time");
}

if ( !$help && $action ne 'add' && $action ne 'remove' ) {
    pod2usage("Invalid action specified");
}

if ( defined $subdomain && $subdomain ne 'webmail' && $subdomain ne 'webdisk' && $subdomain ne 'whm' && $subdomain ne 'cpanel' ) {
    pod2usage("Invalid subdomain specified, must be: whm, cpanel, webmail or webdisk");
}

pod2usage( { -verbose => 2 } ) if $man;
pod2usage(1) if $help;

# dispatch

my %args = ();
my $function;

if ($subdomain) {
    $args{'subdomain'} = $subdomain;
}

if ( $action eq 'add' ) {
    if ($user) {
        print "Adding proxy subdomains for user ${user}.\n";
        $args{'user'} = $user;
        my ( $status, $msg ) = Cpanel::Proxy::setup_proxy_subdomains(%args);    # issafe
        print $msg . "\n";
        exit !$status;
    }
    elsif ($domain) {
        print "Adding proxy subdomains for domain ${domain}.\n";
        $args{'domain'} = $domain;
        my ( $status, $msg ) = Cpanel::Proxy::setup_proxy_subdomains(%args);    # issafe
        print $msg . "\n";
        exit !$status;
    }
    else {
        print "Adding proxy subdomains for all users.\n";
        print "This may take several minutes if there are many accounts on the system.\n";
        my $rsp = Cpanel::Proxy::setup_all_proxy_subdomains(%args);             # issafe
        foreach my $response ( @{$rsp} ) {
            print $response->{'domain'} . ' - ' . $response->{'msg'} . "\n";
        }
        exit;
    }
}
elsif ( $action eq 'remove' ) {
    if ($user) {
        print "Removing proxy subdomains for user ${user}.\n";
        $args{'user'} = $user;
        my ( $status, $msg ) = Cpanel::Proxy::remove_proxy_subdomains(%args);    # issafe
        print $msg . "\n";
        exit !$status;
    }
    elsif ($domain) {
        print "Removing proxy subdomains for domain ${domain}.\n";
        $args{'domain'} = $domain;
        my ( $status, $msg ) = Cpanel::Proxy::remove_proxy_subdomains(%args);    # issafe
        print $msg . "\n";
        exit !$status;
    }
    else {
        print "Removing proxy subdomains for all users.\n";
        print "This may take several minutes if there are many accounts on the system.\n";
        my $rsp = Cpanel::Proxy::remove_all_proxy_subdomains(%args);             # issafe
        foreach my $response ( @{$rsp} ) {
            print $response->{'domain'} . ' - ' . $response->{'msg'} . "\n";
        }
        exit;
    }
}

__END__

=head1 NAME

proxydomains - Add/Remove proxy subdomains

=head1 SYNOPSIS

proxydomains [action] [options]

    Options:
      --help        Brief help message
      --man         Full help message
      --user=       User to configure
      --domain=     Domain to configure
      --subdomain=  Proxy subdomain to manipulate

    Actions:
      add          Create proxy subdomains
      remove       Remove proxy subdomains

=head1 DESCRIPTION

Proxydomains creates the DNS records required to use cpanel.domain.com,
webmail.domain.com, webdisk.domain.com and whm.domain.com proxy redirect
domains.  This script will add the required subdomains to the main domain's
DNS record without creating any matching VirtualHost entry in httpd.conf.
When the proxy domains setting in the WebHostManger Tweak Settings has also
been enabled, this will allow http and https connections to cpanel.domain.com
to be internally proxied to port 2082, webmail.domain.com to port 2095,
webdisk.domain.com to port 2077 and whm.domain.com to port 2086.

When no --user or --domain argument is supplied this script will attempt to
configure the proxy subdomains for all cPanel accounts. 

When --subdomain is specified, this script will only add or remove the
specified proxy subdomain.  When no --subdomain is specified, it will
add or remove all four proxy subdomains.

=cut