Add many domains

qlwik

New member
Joined
Nov 2, 2011
Messages
7
Hello,
I have a problem with adding many domains at once by php script, I use script found in internet, it works only on one hosting, on any other it can't login properly, what can be the reason?:

<?
set_time_limit(0);
function get_page ($url,$var,$proxy,$ref)
{
$ch = curl_init();
if(isset($proxy))
curl_setopt ($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $var);
curl_setopt($ch, CURLOPT_REFERER, $ref);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}

$ip="my_hosting_ip";
$username="my_user";
$password="my_password";

$result=get_page ("http://".$ip.":2222/CMD_LOGIN","referer=%2FCMD_ADDITIONAL_DOMAINS%3F&username=".$username."&password=".$password,"","http://".$ip.":2222/CMD_ADDITIONAL_DOMAINS?");
$bufer="";
$file=fopen("dom.txt","r"); //domains are located here
while(!feof($file))
{
$bufer=fgets($file,100);
$bufer=ereg_replace("\n", "", $bufer);
$bufer=ereg_replace("\r", "", $bufer);
$result=get_page ("http://".$ip.":2222/CMD_DOMAIN","action=create&domain=". $bufer."&ubandwidth=unlimited&uquota=unlimited&cgi=ON&php=ON","","");
print $bufer." – ".$result;
}
fclose ($file);

?>
 
Do you have root access on SSH? Or you buy hosting with Directadmin?

There can be several answers:

Enabled SSL on directadmin and/or enabled force_hostname in directadmin.conf

Or enabled check_referer in directadmin.conf

You might need to run directadmin in debug mode and see what is wrong.

Feel free to PM me for a quote, if you want me to do the job.
 
I'm talking about shared accounts on hostings using direct admin, I figured out on that one hosting, where script works, there is saved a cookie (cookie.txt) with a key session like:
#HttpOnly_xxxx.com FALSE / FALSE 0 session r38wlTqFBu3X8sNFu1f3Tshj645RKx590B5keuzqm0LvtiAnhnp8EHzKK2jezmnx

and on hostings where it doesn't work there is only:
#HttpOnly_xxxx.com FALSE / FALSE 0 session
and no key, maybe there is a reason?

they are using http so there is no ssl
 
Does the PHP script have enough permissions to write in the directory where you're trying to save cookie.txt?

Will you show output of

PHP:
<?php
var_dump(exec('id'));
?>

?
 
cookie.txt have ofcourse read and write, i run it from my localhost linux,
directadmin is on bought hosting so I have no access,
<?php
var_dump(exec('id'));
?>
run on that hosting said:
Warning: exec() has been disabled for security reasons
 
My guess is that PHP script on bought hosting has no permissions to write to a directory (is it a public_html?).

Create a tmp directory near to your script, chmod the directory to 777 (in directadmin or with FTP) and try with:


PHP:
 curl_setopt ($ch, CURLOPT_COOKIEJAR, "./tmp/cookie.txt");
 curl_setopt($ch, CURLOPT_COOKIEFILE,"./tmp/cookie.txt");

If it does not help, then try to specify the absolute path and not the relative path to tmp/cookie.txt. It will look something like
/home/<USERNAME>/domains/<DOMAIN>/public_html/tmp/cookie.txt

Of course if you'd have tmp/ directory created in public_html.
 
No no, script have full rights of write and read, it is in add.php file, next to cookie.txt and dom.txt with domains to add. All files are in my computer at home with linux (i run it by: /usr/bin/php add.php), script create domains on bought hosting, for example hosting.com. I found one hosting where domains are created, but on any other hostings it doesn't work, on output of script there shows "Please enter login and password" so script can't properly login to directadmin.

By the way is there possible to login to directadmin directly from link? I was trying:
http://xxx.com:2222/CMD_LOGIN?referer=/CMD_ADDITIONAL_DOMAINS?&username=my_user&password=my_password

but it doesn't work too
 
OK, try to set

PHP:
curl_setopt ($ch, CURLOPT_HEADER, 1);

and

PHP:
var_dump ($result);
$bufer="";

What are the headers?

By the way, what error do you have there? How do you define that you can not login properly?
 
Well i get resoult of add.php on my linux console, at the end of it (its long) I get:
<h1>DirectAdmin Login Page</h1>
<table cellspacing=1 cellpadding=5>
<tr>
<td class=listtitle colspan=2>Please enter your Username and Password</td></tr>
<form action="/CMD_LOGIN" method="POST" name="form">
<input type=hidden name=referer value="/CMD&#95DOMAIN">
<tr><td class=list align=right>Username:</td><td class=list><input type=text name=username></td></tr>
<tr><td class=list align=right>Password:</td><td class=list><input type=password name=password></td></tr>
<tr><td class=listtitle align=right colspan=2><input type=submit value='Login'></td></tr>
</form>
</table>

so I guess script can't get through login windows,
I changed it what You said but still not working.
 
@SeLLeRoNe,

Even though, one should go through authorization.

@qlwik,

That's not exactly what I asked for. By the way there is no message about invalid login and password, so something might be wrong configured or whatever else.

Let's try it one more time:

set
PHP:
curl_setopt ($ch, CURLOPT_HEADER, 1);

and lines of code

PHP:
$ip="my_hosting_ip";
 $username="my_user";
 $password="my_password";

 $result=get_page ("http://".$ip.":2222/CMD_LOGIN","referer=%2FCMD_ADDITIONAL_DOMAINS%3F&username=".$username."&password=".$password,"","http://".$ip.":2222/CMD_ADDITIONAL_DOMAINS?");

change to

PHP:
$ip="my_hosting_ip";
 $username="my_user";
 $password="my_password";

 $result=get_page ("http://".$ip.":2222/CMD_LOGIN","referer=%2FCMD_ADDITIONAL_DOMAINS%3F&username=".$username."&password=".$password,"","http://".$ip.":2222/CMD_ADDITIONAL_DOMAINS?");
var_dump($result);
exit;

And what you see?
 
Well interesting, now in resoult i get code of page with list of domains, so he is loged in now, but don't add domain,

@SeLLeRoNe
thank you for link, that script works, but it can create only one domain, and i need to add list of domains, if nothing helps i will have to use it.

thank you all for interest.
 
Well interesting, now in resoult i get code of page with list of domains, so he is loged in now, but don't add domain,


PHP:
exit()

makes the script to abort executing in the place where it's added.

So you goes through authorization, but since cookies are not stored right, that might be the problem.
 
Back
Top