<?php

/*
    Copyright 2008 Michael Sumner
    Email: msumner@dnmedia.com
    Web: http://www.DNMedia.com
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

$dynadotUser "YOUR DYNADOT USERNAME HERE";
$dynadotPass "YOUR DYNADOT PASSWORD HERE";
$phone "YOUR PHONE NUMBER HERE";
$pass "YOUR PASSWORD TO ACCESS THE APP HERE";
    
// Edit below this line at your own risk. //////////////////////////////////

$user $_GET['user'];
$req explode(" "$_GET['req']);

$domain $req[0];
$thePass $req[1];

if((
$user == $phone) && ($pass == $thePass))
{    
    
// Initialize Https Connection.
    
$user_agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    
$ch curl_init();
    
curl_setopt($chCURLOPT_POST1);
    
curl_setopt($chCURLOPT_SSL_VERIFYHOST2);
    
curl_setopt($chCURLOPT_USERAGENT$user_agent);
    
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
    
curl_setopt($chCURLOPT_COOKIEJARdirname(__FILE__).'/cookie.txt');
    
curl_setopt($chCURLOPT_COOKIEFILEdirname(__FILE__).'/cookie.txt');
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
    
// Log In
    
$url 'https://www.dynadot.com/account/signin.html';
    
$params 'signin_username=' $dynadotUser '&signin_password=' $dynadotPass '&signin=Sign%20In';    
    
curl_setopt($chCURLOPT_POSTFIELDS$params);
    
curl_setopt($chCURLOPT_URL$url);    
    
$result curl_exec($ch);

    
// Perform the Search
    
$url 'https://www.dynadot.com/account/search/search.html';
    
$params 'domain=' $domain '&search=Search';
        
    
curl_setopt($chCURLOPT_POSTFIELDS$params);
    
curl_setopt($chCURLOPT_URL$url);
    
$result curl_exec($ch);
        
    
// Check Availability
    
$result strstr($result'<td class="subjectTitle">Search Results</td>');
    
$piece strstr($result$domain);
    
$piece strstr($piece'<td valign="top">');
    
$status substr($piece17strpos($piece'</td>') - 17);
        
    
// If Available, Add to Cart and Check Out
    
if($status == "Available")
    {
        
// Grab Input Name and Value
        
$result substr($result0strpos($result$domain));
        
$result substr($resultstrrpos($result'domain_'));
        
$name substr($result0strpos($result'"'));
        
$result substr($resultstrrpos($result'value=') + 7);
        
$value substr($result0strpos($result'"'));
            
        
// Add to Cart
        
$url 'https://www.dynadot.com/account/search/search.html';
        
$params $name '=' $value '&add_submit=Add%20and%20Checkout';
        
curl_setopt($chCURLOPT_POSTFIELDS$params);
        
curl_setopt($chCURLOPT_URL$url);
        
$result curl_exec($ch);
            
        
// Check Out
        
$url 'https://www.dynadot.com/order/submit.html';
        
$params 'submit=Submit%20my%20Order';
        
curl_setopt($chCURLOPT_POSTFIELDS$params);
        
curl_setopt($chCURLOPT_URL$url);
        
$result curl_exec($ch);
        
        echo 
"The domain was registered.";
    }
    else
    {
        echo 
"The domain was not available.";
    }
    
    
// Log Out
    
$url 'https://www.dynadot.com/account/signout.html';
    
$params '';
    
curl_setopt($chCURLOPT_POSTFIELDS$params);
    
curl_setopt($chCURLOPT_URL$url);
    
$result curl_exec($ch);
        
    
// Close the https connection.
    
curl_close($ch);
    
}else{

    echo 
"You are not authorized to access this application.";
    
}

?>