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.

Check if domain is already on the server!? help please

Discussion in 'General Discussion' started by webadpro, Jan 15, 2006.

  1. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Hi,
    Is there a php script in cpanel, to check if the domain or username is already taken by someone else on the server!?

    Please help me,
    Regards,
    Pat
     
  2. WebScHoLaR

    WebScHoLaR Well-Known Member

    Joined:
    Dec 14, 2005
    Messages:
    511
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Planet Earth
    You can check it by running the following two commands from the shell:

    grep username /etc/userdomains (For Username)

    OR

    grep domain.com /etc/userdomains (For Domain Name)
     
  3. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Yeah,

    But as a php script!?
     
  4. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    I don't think he means running php in cpanel - just checking if the [cpanel] user exists in a php script. A side note: cpanel does allow php scripts to run in the cpanel /usr/local/cpanel/base/frontend/skin directory.

    The best option would be to keep track of the accounts in a database, separate of cpanel. You could update the database with the accounting module (described below)

    Alternatives:

    You could use the php accounting module to get a list of the accounts:
    http://www.cpanel.net/remoteaccess-php.html
    use the listaccts() function to get a 2-dimensional array of all the accounts with details like the domain. Then write your own function to check on them.


    For these options, you may need to disable some php security to allow access to these files. I wouldn't recommend it, but it's an option.
    Use php to scan the /etc/passwd file for the username. Read the contents of the file and search for the username string. Use php to scan the /var/named/ directory for the domain. Check if the file /var/named/$domain.db exists.
     
  5. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Anyone else could help out here!?
     
  6. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    What's wrong? My response gives you two ways to do it.
     
  7. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Not 100% true tho,

    Since, Listacct only show you your accounts and not all the accounts on the server itself.

    Now, I'm trying to figure out, how to use you second method but I'm having a lot of hard time.

    Do you know how I could make this using the file_exists command?

    Best Regards,
    Pat
     
  8. elleryjh

    elleryjh Well-Known Member

    Joined:
    Apr 12, 2003
    Messages:
    479
    Likes Received:
    0
    Trophy Points:
    16
    Yeah, as I explained in my first post "Check if the file /var/named/$domain.db exists."

    PHP:

    $domain 
    "something.com";
    if (
    file_exists("/var/named/$domain.db")){
       
    //  There is a DNS entry on this server.
    }
    else{
        
    // There is no DNS entry on this server
    }

    EDIT: The above checks for a domain. As I explained before, in order to check for a username, you would have to grep or use one of PHP's functions to scan /etc/password. If you don't know how to do this, pay someone to do it for you.
     
    #8 elleryjh, Apr 24, 2006
    Last edited: Apr 25, 2006
  9. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    My thread on how to extend the remote access features may also come in useful: http://forums.cpanel.net/showthread.php?t=46362

    This demonstrates the general process for integrating WHM/cPanel functionality into your own site, such as the ability to check if a given domain is taken.
     
  10. webadpro

    webadpro Member

    Joined:
    Dec 7, 2005
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Thanks Everyone!

    Well, I know how to use whmreq because I've been using for a while, and my script is almost done, but I was just wondering.

    I'll look into it further, to know how to do what you've told me.

    But I don't want to pay no one, since everyone has to start somewhere!!

    Thank you very much.

    Best Regards,
    Pat
     
    #10 webadpro, Apr 25, 2006
    Last edited: Apr 25, 2006
Loading...

Share This Page