The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to retrieve list of accounts user owns?

Discussion in 'cPanel Developers' started by dansgalaxy, Sep 4, 2009.

  1. dansgalaxy

    dansgalaxy Well-Known Member

    Joined:
    Jan 29, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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
     
  2. gearheadhost

    gearheadhost Member

    Joined:
    Jun 14, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  3. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    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.
     
  4. dansgalaxy

    dansgalaxy Well-Known Member

    Joined:
    Jan 29, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Reading, UK
    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?
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    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.
     
  6. dansgalaxy

    dansgalaxy Well-Known Member

    Joined:
    Jan 29, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Reading, UK
    cPanel Access Level:
    Root Administrator
    Right ok, :/

    I trying
    $xml = simplexml_load_file("https://root:ROOTPASS@domain.co.uk: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.)
     
Loading...

Share This Page