#!/usr/local/bin/perl #ssullivan@liquidweb.com #change all cPanel account themes (11.25 or greater) use LWP::UserAgent; use strict; my $minversion = "11.25.0"; print "Generating hash..."; system("QUERY_STRING=\\\"regen=1\\\" /usr/local/cpanel/whostmgr/bin/whostmgr ./setrhash &> /dev/null"); my $accessHash = '/root/.accesshash'; if (-e $accessHash) { print "success!\n"; my $hash = `cat /root/.accesshash`; $hash =~ s/\n//g; my $auth = "WHM root:" . $hash; my $ua = LWP::UserAgent->new; my $request1 = HTTP::Request->new( GET => "http://127.0.0.1:2086/xml-api/version" ); $request1->header( Authorization => $auth ); my $response1 = $ua->request($request1); my $version = $response1->content; open(outfile, ">version.xml"); print outfile $version; close (outfile); my $rawversionGrep = `grep -R "" ./version.xml | cut -d ">" -f 2|cut -d "<" -f 1`; $rawversionGrep =~ s/^\s+//; #remove leading spaces $rawversionGrep =~ s/\s+$//; #remove trailing spaces system("rm -rf ./version.xml"); if ($rawversionGrep ge $minversion) { print "Found cPanel 11.25.0 or greater.\n"; } else { print "You need cPanel 11.25.0 or greater to run this script.\n"; exit; } my $request = HTTP::Request->new( GET => "http://127.0.0.1:2086/xml-api/listaccts" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); my $list = $response->content; open(outfile, ">userList.out"); print outfile $list; close (outfile); my $rawuserGrep = `grep -R "" ./userList.out`; open (outfile, ">userList.out"); print outfile $rawuserGrep; close (outfile); my $userGrep = `cat ./userList.out | cut -d ">" -f 2 | cut -d "<" -f 1`; open (outfile, ">userList.out"); print outfile $userGrep; close (outfile); print "Change all accounts to what theme? \n"; my $input = ; #create the array, new slot by newline my @userArray = split(/\n/,$userGrep); my $size = @userArray; for (my $i = 0; $i < $size; $i++) { my $request = HTTP::Request->new( GET => "http://127.0.0.1:2086/xml-api/modifyacct?user=$userArray[$i]&CPTHEME=$input" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); print $response->content; my $list = $response->content; print "$userArray[$i] set to $input\n"; print "------------------------------\n"; } system ("rm -rf ./userList.out"); print "All themes set to $input\n"; exit; } else { print "failed!\n"; print "WARNING: Failed to automatically generate hash! Please try logging into WHM and click `Setup Remote Access Key` and then re-run this script. Also please report this problem to ssullivan.\n"; exit; }