Changing IP of multiple sites through Shell

[email protected]

Active Member
Nov 6, 2003
29
0
156
Earth
Hi,

Basically

http://******:2087/scripts2/dochangeip?user=USERNAME&oldip=OLDIP&customip=NEWIP

changes a single sites IP address.



I'm looking for changing IP address of sites through shell, and if you let me know how to do, i would appreciate.

Sample: /scripts/changeip.sh?user=USERNAME&oldip=OLDIP&customip=NEWIP


PS: There are /scripts/changeip.sh, /scripts/changeip2.sh and /scripts/changeip3.sh scripts but i'm unsure whether these work.


Best wishes,
CK
 

yaax

Well-Known Member
Jun 15, 2003
67
0
156
There is no way do it with existing cpanel scripts, so when I was need to move one big reseller with many sites to his dedicated ip I wrote such script myself using CPanel API.

You need to save this script like any name for example script.cgi, update there your root hash key and then execute it from root with next parameters:
./script.cgi reseller oldip newip

So this script will list all reseller sites of reseller with username 'reseller' and will change their 'oldip' to 'newip'

PHP:
#!/usr/bin/perl

BEGIN {

        push (@INC,"/usr/local/cpanel");

}
use Cpanel::Accounting;

my($whm) = Cpanel::Accounting->new;

$whm->{host} = "localhost";

$whm->{user} = "root";

$whm->{accesshash} = '';

$whm->{usessl} = 1;

my($self,$user) = @_;
   my($response);
   
   my($par);
   $par="/scripts2/listaccts?searchtype=owner&search=$ARGV[0]&acctp=999&nohtml=1";
   print "$par\n";
   my (@PAGE) = $whm->whmreq($par);

   if ($whm->{error} ne "") {
        print "There was an error while processing your request:
        Cpanel::Accounting returned [$whm->{error}]\n";
        exit;
   }

   foreach $_ (@PAGE) {
        s/\n//g;
       $response .= $_ . "\n";
   }

   print $response;

   my(%ACCTS);

   foreach $_ (@PAGE) {
      s/\n//g;
      my($acct,$contents) = split(/=/, $_);
      my(@CONTENTS)=split(/\,/,$contents);
      @{$ACCTS{$acct}} = @CONTENTS;
   }

   foreach $acct (sort keys %ACCTS) {

        @ACCTCT = @{$ACCTS{$acct}};

        print "$acct @ACCTCT\n";
        print "changing ip for account $acct from $ARGV[1] to $ARGV[2]...\n";

        my($response1);
        my (@PAGE1) = $whm->whmreq("/scripts2/dochangeip?user=$acct&oldip=$ARGV[1]&customip=$ARGV[2]");
   
        if ($whm->{error} ne "") {
                print "There was an error while processing your request:
                Cpanel::Accounting returned [$whm->{error}]\n";
                #exit;
        }

        foreach $_ (@PAGE1) {
                s/\n//g;
                $response1 .= $_ . "\n";
        }

        print $response1;
   }
 
Last edited: