How to retrieve list of accounts user owns?

dansgalaxy

Well-Known Member
Jan 29, 2007
91
0
156
Reading, UK
cPanel Access Level
Root Administrator
Hi,

Im developing/developed a Process Manager Plugin for cPanel to show a users processes etc, i would like to extend the ability of this so resellers can view and kill their users processes as well as their own.

To do this i need to somehow get a list of the accounts which the reseller owns... How can i do this?



Also on a side note does anyone know how to return a process owner from just the PID?

Thanks.
Dan
 

gearheadhost

Member
Jun 14, 2009
14
0
51
to get the accounts owned by USER do...

grep USER /etc/trueuserowners | cut -f1 -d :

if you want to get a domain name and a user name do...

for n in `grep USER /etc/trueuserowners | cut -f1 -d :`; do echo $n; grep $n /etc/trueuserdomains | cut -f1 -d : ; done

and for the PID owner

ps aux | grep PID | grep -v grep | awk {'print $1'}

replace PID with the PID obviously
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
In case anyone who finds this thread in the future is looking for an XML API solution, the listaccts function can return this information for you:

Code:
/xml-api/listaccts?searchtype=owner&search=DavidG
The above URL returns all accounts owned by DavidG on that server.
 

dansgalaxy

Well-Known Member
Jan 29, 2007
91
0
156
Reading, UK
cPanel Access Level
Root Administrator
In case anyone who finds this thread in the future is looking for an XML API solution, the listaccts function can return this information for you:

Code:
/xml-api/listaccts?searchtype=owner&search=DavidG
The above URL returns all accounts owned by DavidG on that server.
Ah great, that seems the easiest way :)

Been a while since i looked at how to use the API..

What would be the best way to return that in a cPanel Plugin?
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Ah great, that seems the easiest way :)

Been a while since i looked at how to use the API..

What would be the best way to return that in a cPanel Plugin?
The trickiest thing I see here is storing the login credentials (user/hash or user/pass) for the XML API. cPanel plugins run as the cPanel user, which means the cPanel user must have access to all files the plugin references. This essentially opens up privilege escalation possibilities if done improperly.

I'm not a master of Unix system permissions, but maybe others have recommendations on how to do this securely.
 

dansgalaxy

Well-Known Member
Jan 29, 2007
91
0
156
Reading, UK
cPanel Access Level
Root Administrator
The trickiest thing I see here is storing the login credentials (user/hash or user/pass) for the XML API. cPanel plugins run as the cPanel user, which means the cPanel user must have access to all files the plugin references. This essentially opens up privilege escalation possibilities if done improperly.

I'm not a master of Unix system permissions, but maybe others have recommendations on how to do this securely.
Right ok, :/

I trying
$xml = simplexml_load_file("https://root:[email protected]:2087/xml-api/listaccts?
searchtype=owner&search=".$user);

Which seems to be working, although it would be good to have a way so dont have the root info hardcoded into script :/

Perhaps a good idea could be to have cPanel WHM have a sort of script key, so have an API to allow you to run root scripts etc like this using a key which is managed in WHM, this way dont have to have root info and root can always disable the key for a script if its being misused :/

(im not talking about the root hash key im thinking a seperate hash key for each script which needs to do something like this.)