Alt-PHP-Faq

Vitamin Supplements| Cortavet| Cortaflex| Cortaflex| Health Supplements| Equine Supplements| Manuka Honey| Fat Loss 4 Idiots| Explosive Cashins CB Traffic Warrior Freedom Blogging Profit The Profit Spy Push Button Monkey GPunisher Blogging Syndicate Content Lockdown Turbo Commissions Auto Cash Funnel Traffic Reloaded Affiliate Scalper Mass Money Makers


Question :

Using Curl can I access the OpenSRS admin control panel (tucows)

Answer :

<?php
/*
Curl must be compiled into PHP and have SSL support
TODO
----

Add credit card payment option https://rr-n1-tor.opensrs.net/resellers/index?action=ccp
Add renew domain function (Requires to page lookup)
*/
function opensrs_login ($srs_username,$srs_password,$cookie)
{
    
/*
    This function logs into the OpenSRS system, it sends the default cookie sting to make the system think
    you have been to the login page first. The initial system we wrote went to the login page first andf obtained
    the first cookie and then sent that. However unless they change the system this way will also work without
    needing the additional request.
    
    You would just need to goto the login page get the cookie and then send it with
    //curl_setopt ($ch, CURLOPT_COOKIEFILE, "/tmp/srs/cookie.txt");
    rather than using the line
    curl_setopt($ch,CURLOPT_COOKIE,"CheckCookie=CheckCookie; domain=.opensrs.net; path=/resellers"); 
    
    However we don't feel this is needed
    
    */
    
$ch curl_init ("https://rr-n1-tor.opensrs.net/resellers/index?action=login&username=$srs_username&password=$srs_password");
    
$cookie_new fopen ("$cookie""w"); // Save the cookie in a tmp file
    
$webpage fopen ("/dev/null""w"); // We don't need to save the webpage so dev/null it

    
curl_setopt ($chCURLOPT_WRITEHEADER$cookie_new); // We need to save the cookie sent on a good login
    
curl_setopt($ch,CURLOPT_COOKIE,"CheckCookie=CheckCookie; domain=.opensrs.net; path=/resellers"); 
    
curl_setopt ($chCURLOPT_FILE$webpage);
    
curl_setopt ($chCURLOPT_HEADER0);

    
curl_exec ($ch);
    
curl_close ($ch);
    
fclose ($cookie_new);
    
fclose ($webpage);
    
    if( !
opensrs_check_cookie ($cookie) )
    {
        return 
false;
    }
    
    
// If we are at this point we have logged into the SRS system and have a valid cookie
    
return true;
    
}

function 
opensrs_sendpassword ($srs_domain,$webpage_file,$cookie,$contact="admin")
{
    
/* 
    This function will request the managment password be sent to either the admin or owner contact
    it defaults to the admin contact if no contact option is set
    */
    
GLOBAL $srs_error_message// This is used to return an error messages
    
    
if($contact != "admin")
    {
        
$contact "owner";
    }
    
    if( !
opensrs_check_cookie ($cookie) )
    {
        
$srs_error_message "Login cookie not found, have you logged in!";
        return 
false;
    }
    
    
$ch curl_init ("https://rr-n1-tor.opensrs.net/resellers/index?action=send_password&send_to=".$contact."&sub_user=0&domain=".$srs_domain."&type=password");
    
$webpage fopen ("$webpage_file""w"); // We want to save the page so we can check for errors

    
curl_setopt ($chCURLOPT_COOKIEFILE"$cookie"); // Send the cookie that shows we have already logged in
    
curl_setopt ($chCURLOPT_FILE$webpage); // Tell it where to write the log page
    
curl_setopt ($chCURLOPT_HEADER0); // We don't want to save headers

    
curl_exec ($ch);
    
curl_close ($ch);
    
fclose ($webpage);
    
    
// Now open the webpage retreived and look for error messages
    
    
$webpage fopen ("$webpage_file""r");
    while (!
feof ($webpage)) {
        
$buffer fgets($webpage4096);
        
        if( 
strstr($buffer,"Error") )
        {
            
$error_found 1;
            
$srs_error_message "Error in sending Password";
        }
        
        if( 
strstr($buffer,"Domain not in database") )
        {
            
$error_found 1;
            
$srs_error_message "Domain ($srs_domain) not in database";
        }        
        
    }
    
fclose ($webpage);
    
    
unlink("$webpage_file"); // Remove the webpage
    
    
if($error_found == 1)
    {
        return 
false;
    }
    
    
// If we are at this point we found the login cookie, and we found no errors
    
return true;    
}

function 
opensrs_get_contacts ($srs_domain,$webpage_file,$cookie)
{
    GLOBAL 
$srs_admin_contact,$srs_owner_contact,$srs_error_message;

    if( !
opensrs_check_cookie ($cookie) )
    {
        
$srs_error_message "Login cookie not found, have you logged in!";
        return 
false;
    }
    

    
$ch curl_init ("https://rr-n1-tor.opensrs.net/resellers/index?action=view_domain&name=".$srs_domain);
    
$webpage fopen ("$webpage_file""w"); // We want to save the page so we can pull out the contacts

    
curl_setopt ($chCURLOPT_COOKIEFILE"$cookie"); // Send the cookie that shows we have already logged in
    
curl_setopt ($chCURLOPT_FILE$webpage); // Tell it where to write the log page
    
curl_setopt ($chCURLOPT_HEADER0); // We don't want to save headers

    
curl_exec ($ch);
    
curl_close ($ch);
    
fclose ($webpage);
    
    
// Now open the webpage retreived and look for error messages
    
    
$webpage fopen ("$webpage_file""r");
    while (!
feof ($webpage)) {
        
$buffer fgets($webpage4096);
        
        if( 
strstr($buffer,"Error") )
        {
            
$error_found 1;
            
$srs_error_message "Error in getting contacts";
        }
        
        if( 
strstr($buffer,"Domain not in database") )
        {
            
$error_found 1;
            
$srs_error_message "Domain ($srs_domain) not in database";
        }
        
        if( 
strstr($buffer,"E-Mail Login Password") )
        {
            
$buffer ereg_replace"\t""" $buffer);
            
$buffer ereg_replace"\(""" $buffer);
            
$buffer ereg_replace"\)""" $buffer);
            
$buffer ereg_replace"\<\/a\>""" $buffer);
            
$buffer trim($buffer);
            
            if ( 
strstr($buffer,"Admin Contact") )
            {
                
$buffer ereg_replace"E-Mail Login Password to the Admin Contact""" $buffer);
                
$buffer ereg_replace" """ $buffer);
                
$srs_admin_contact $buffer;
                
            }else
            {
                
$buffer ereg_replace"E-Mail Login Password to the Owner Contact""" $buffer);
                
$buffer ereg_replace" """ $buffer);
                
$srs_owner_contact $buffer;
            }
        }        
        
    }
    
fclose ($webpage);
    
    
unlink("$webpage_file"); // Remove the webpage    

    
if($error_found == 1)
    {
        return 
false;
    }
    
    return 
true;    

}

function 
opensrs_payment_info ($webpage_file,$cookie)
{
    if( !
opensrs_check_cookie ($cookie) )
    {
        
$srs_error_message "Login cookie not found, have you logged in!";
        return 
false;
    }
    

    
$ch curl_init ("https://rr-n1-tor.opensrs.net/resellers/index?action=view_payments");
    
$webpage fopen ("$webpage_file""w"); // We want to save the page so we can pull out the contacts

    
curl_setopt ($chCURLOPT_COOKIEFILE"$cookie"); // Send the cookie that shows we have already logged in
    
curl_setopt ($chCURLOPT_FILE$webpage); // Tell it where to write the log page
    
curl_setopt ($chCURLOPT_HEADER0); // We don't want to save headers

    
curl_exec ($ch);
    
curl_close ($ch);
    
fclose ($webpage);
    
    
$webpage fopen ("$webpage_file""r");
    while (!
feof ($webpage)) {
        
$buffer fgets($webpage4096);

        if( 
strstr($buffer,"Error") )
        {
            
$error_found 1;
            
$srs_error_message "Error in getting account balance";
        }
        
//<b>Current Account Balance:</b> $97.50 <br>
        
if( strstr($buffer,"Current Account Balance:") )
        {
            
$buffer ereg_replace'<b>'"" $buffer);
            
$buffer ereg_replace'</b>'"" $buffer);
            
$buffer ereg_replace'<br>'"" $buffer);
            
$buffer ereg_replace':'"" $buffer);
            
$buffer ereg_replace'Current Account Balance'"" $buffer);
            
$buffer ereg_replace' '"" $buffer);
            
$buffer trim($buffer);
            
$amount $buffer;
        }        

    }
    
fclose ($webpage);

    
unlink("$webpage_file"); // Remove the webpage    
    
return $amount;

}

function 
opensrs_check_cookie ($cookie)
{
    if( ! 
is_readable ($cookie) )
    {
        return 
false;
    }
    
    
$error_found 1// Set as default, if a valid login it will be reset
    
$cookie_file fopen ("$cookie""r");
    while (!
feof ($cookie_file)) {
        
$buffer fgets($cookie_file4096);

        if( 
strstr($buffer,"Set-Cookie: RESELLER_LIVE_KEY") )
        {
            
$error_found 0;
        }

    }
    
fclose ($cookie_file);
    
    if( 
$error_found == )
    {
        return 
false;
    }
    
    return 
true;
}

function 
random_cookie ($dir="/tmp")
{

    
mt_srand();
    
$cookie mt_rand (100010000);
    while(
file_exists("$dir/$cookie") )
    {
        
mt_srand();
        
$cookie mt_rand (100010000);
    }
    return 
$cookie;
}    

/* No more functions just the code now*/
$srs_username "USERNAME";
$srs_password "";

$temp_dir "/tmp"// this should have read/write for the webserver user /tmp is less secure 

if( (!is_writable($temp_dir)) || (!is_readable($temp_dir)) )
{
    echo 
"Error $temp_dir has not got correct permissions<BR>";
    exit(
0);
}

$cookie "$temp_dir/".random_cookie ($temp_dir);
$webpage_file "$temp_dir/".random_cookie ($temp_dir);

if( 
opensrs_login ($srs_username,$srs_password,$cookie) )
{
    
/*
    if( opensrs_sendpassword ("php4hosting.com",$webpage_file,$cookie) )
    {
        echo "Password sent<BR>";
    }else
    {
        echo "Failed to send password<BR>";
        echo "$srs_error_message<BR>";
    }
    
    

    if( opensrs_get_contacts ("php4hosting.com",$webpage_file,$cookie) )
    {
        echo "$srs_admin_contact<BR>";
        echo "$srs_owner_contact<BR>";
    }else
    {
        echo "Failed to get contacts<BR>";
        echo "$srs_error_message<BR>";
    }
*/    
    
echo opensrs_payment_info ($webpage_file,$cookie);
    
}else
{
    echo 
"Failed to login to openSRS system<BR>";
}

// remove files that pose a security risk
if( file_exists($cookie) )
{
    
unlink($cookie);
}

if( 
file_exists($webpage) )
{
    
unlink($webpage);
}
?>



Categories Return to Main PHP Faq

Code


 

Questions

Code
How do I get a user's IP address?
How do I generate a random number from php?
How do I insert javascript in php code?
How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?
How can I create thumbnails using PHP?
Can I create PDF files from php?
How can I use PGP with PHP?
I keep getting "headers already sent" whilst trying to use sessions
Is it possible to send HTML mail with php?
How do I user authentication in php?
How do i upload files from php to my ISP / server?
How do I format a number correctly?
How do I set the browser timeout?
How can I create random passwords?
Is there a way to encrypt text from php?
How can I limit search results so that there is a "Next 10" and "Previous 10"?
How do I find out weather a number is odd or even?
How can I protect pages using MySQL and PHP?
What's the difference between the *connect and *pconnect database functions?
How to access a COM object from within my PHP page?
How do I check whether a string contains HTML?
How to output a number with leading zero's?
How to count number of parameters given in URL by POST?
Is it possible to spell check texts from php?
Does anyone know some URLS for good tutorials on PHP?
How can I do error handling in php?
How do I get the total size of a certain directory?
How can I get the DNS servers of a domain name?
How do I make links on mail and www links on my pages?
How do I work with dates in php?
Is it possible to connect to a ftp server with php?
Is it possible to validate an e-mail in php?
I keep getting "Data Missing" when I click the "back" button in my browser. How can I stop this?
How can I mail the content of a form?
I have an array of values and want to show them all reccursivly how?
Use ereg_replace to replace only the first occurence of a string instead of all?
How do I find out if an array has values posted to each of its elements? I need to know that EVERY element has been filled out.
How do you colour code the source in the answers on alt-php-faq.org?
I have upgraded to PHP-4.0.5, since doing that some of my scripts are just showing the source code?
 

Return to the main FAQ list



Design & Layout Copyright © 2000- 2008 PHP MySQL Web Hosting Comments to Webmaster
Hosted by PHP 4 Hosting - PHP and MySQL Webhosting and Domain Names