How to change cpanel accts and packages to x3 after uninstalling rvskin?

electric

Well-Known Member
Nov 5, 2001
790
11
318
Hello,

We are going to uninstall the "RVSKIN" cpanel theme from our servers. How can we change all accounts and WHM Packages that are using one of the rvskin themes to "x3"?

The rvskin includes a bunch of different themes that customers might be using:

rvskin
rvneo
rvdiy
rvgreen
rvblue
rvpink
rvlight
etc...

(They all start with the "rv" prefix...)

We want to modify all the accounts and packages that are using any of the "rvskin" themes to "x3".

Thanks!
 
Last edited:

electric

Well-Known Member
Nov 5, 2001
790
11
318
To clarify, a different way to accomplish what we want is to switch all WHM package themes and customer account themes that are not "paper_lantern" to "x3".

So any cpanel account or WHM package that is set to "paper_lantern" should be left as-is. Anything else should be switched to "x3".

Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello :)

You can simply edit your packages via:

"WHM Home » Packages » Edit a Package"

Change the theme configured for the package, and all accounts using that package will have their theme updated automatically.

Thank you.
 

electric

Well-Known Member
Nov 5, 2001
790
11
318
We have several hundred customer accounts, dozens of resellers, and about 80 different packages.

Updating every package one-by-one isn't realistic.

Also, your solution doesn't consider any cpanel accounts not associated with a package.

It also doesn't consider the scenario where reseller has modified a cpanel account in some way, yet chosen to keep it linked to the package without modifying the package settings. By updating the reseller's package, we would cause any custom modifications they've made to that account to be lost. (Which would result in a reseller customer who is mad at us for screwing around with his accounts...)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello :)

Yes, that's all important information to consider. You may want to manually modify the files in:

/var/cpanel/users/
/var/cpanel/packages/

Change the "RS=" value for the cPanel user files, and the "CPMOD=" value in the packages using a custom bash command (e.g. replace). After modifying the cPanel user files, then run:

Code:
/scripts/updateuserdomains
Thank you.
 

electric

Well-Known Member
Nov 5, 2001
790
11
318
Is there any way to automate this? As I mentioned, we have many hundreds of cpanel accounts and dozens of packages on our servers. Manually editing individual files is not realistic. (Especially since we have multiple servers...)

- - - Updated - - -

In other words, surely the cpanel devs must have a tool or code to do this already? I can't believe I'm the first/only cpanel customer to ask how to do this over the years...
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Is there any way to automate this? As I mentioned, we have many hundreds of cpanel accounts and dozens of packages on our servers. Manually editing individual files is not realistic. (Especially since we have multiple servers...).
I suggested using a custom bash command such as "replace" to complete this for all accounts with one or two commands. In a thread you replied to last week, a user suggests a custom script:

http://forums.cpanel.net/f8/how-modify-theme-rvblue-x3-all-accounts-406041.html#post1633941

However, if you are looking for native functionality within cPanel, that would require a feature request:

Submit A Feature Request

Thank you.
 

electric

Well-Known Member
Nov 5, 2001
790
11
318
For anyone who is reading this, here is some simple PHP code the uses the cpanel/WHM api to change the theme for all accounts that are NOT using "x3" or "paper_lantern":
PHP:
<?php

$whm_hostname = "your.serverdomain.com";
$whm_username = "root";
$whm_password = "password";

// Get list of all accounts on the server.
$result = doCpanelQuery("https://".$whm_hostname.":2087/json-api/listaccts");
$result = json_decode($result, true);

// Check if current theme is anything besides x3 or paper_lantern.
foreach($result['acct'] as $key=>$value) {

	if ( ($value['theme'] != "x3") && ($value['theme'] != "paper_lantern") ) {

		echo $value['user'] ." : " . $value['theme'] . " : ";

		// Change theme to x3.
		$result2 = doCpanelQuery("https://".$whm_hostname.":2087/json-api/modifyacct?user=".$value['user']."&RS=x3");
		$result2 = json_decode($result2, true);

		echo $result2['result'][0]['statusmsg'] . "<br />";

	}
}

function doCpanelQuery($query) {
	global $whm_username, $whm_password;
	$curl = curl_init();
	# Create Curl Object
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
	# Allow self-signed certs
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
	# Allow certs that do not match the hostname
	curl_setopt($curl, CURLOPT_HEADER,0);
	# Do not include header in output
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	# Return contents of transfer on curl_exec
	$header[0] = "Authorization: Basic " . base64_encode($whm_username.":".$whm_password) . "\n\r";
	curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
	# set the username and password
	curl_setopt($curl, CURLOPT_URL, $query);
	# execute the query
	$result = curl_exec($curl);
	if ($result == false) { die("curl_exec threw error \"" . curl_error($curl) . "\" for $query");}
	curl_close($curl);

	return $result;
}


?>
 

electric

Well-Known Member
Nov 5, 2001
790
11
318
And here is the PHP code for updating all WHM packages on the server that are NOT "x3" or "paper_lantern":

PHP:
<?php

// Changes cpanel theme for all WHM packages on the server.

$whm_hostname = "your.servername.com";
$whm_username = "root";
$whm_password = "password";

// Get list of all accounts on the server.
$result = doCpanelQuery("https://".$whm_hostname.":2087/json-api/listpkgs");
$result = json_decode($result, true);

// Check if current theme is anything besides x3 or paper_lantern.
foreach($result['package'] as $key=>$value) {

	if ( ($value['CPMOD'] != "x3") && ($value['theme'] != "paper_lantern") ) {

		echo $value['name'] ." : " . $value['CPMOD'] . " : ";

		// Change theme to x3.
		$result2 = doCpanelQuery("https://".$whm_hostname.":2087/json-api/editpkg?name=".$value['name']."&cpmod=x3");
		$result2 = json_decode($result2, true);

		echo $result2['result'][0]['statusmsg'] . "<br />";

	}
}

function doCpanelQuery($query) {
	global $whm_username, $whm_password;
	$curl = curl_init();
	# Create Curl Object
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
	# Allow self-signed certs
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
	# Allow certs that do not match the hostname
	curl_setopt($curl, CURLOPT_HEADER,0);
	# Do not include header in output
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	# Return contents of transfer on curl_exec
	$header[0] = "Authorization: Basic " . base64_encode($whm_username.":".$whm_password) . "\n\r";
	curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
	# set the username and password
	curl_setopt($curl, CURLOPT_URL, $query);
	# execute the query
	$result = curl_exec($curl);
	if ($result == false) { die("curl_exec threw error \"" . curl_error($curl) . "\" for $query");}
	curl_close($curl);

	return $result;
}


?>
Please note -- using the API method to update all WHM packages on your server will trigger an "update" to all accounts that are using that package. So if you have customized a cpanel account, but kept is assigned to a package that is updated, the cpanel account will be "synced" to the package your customization will be lost.