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

webadpro

Member
Dec 7, 2005
16
0
151
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
 

WebScHoLaR

Well-Known Member
Dec 14, 2005
508
3
168
Planet Earth
webadpro said:
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
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)
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
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.
 

webadpro

Member
Dec 7, 2005
16
0
151
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
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
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.
 
Last edited:

webignition

Well-Known Member
Jan 22, 2005
1,876
1
166
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.
 

webadpro

Member
Dec 7, 2005
16
0
151
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
 
Last edited: