Domain API Loop - php

How can I perform the following with this API?
Form is setup in PHP for registered user to enter domain name
On submit..
Check if domain is available >
If NO > output to XML > run the loop again in 5 minutes
If YES > output to XML > go ahead and purchase (register) the domain > end loop
Thank you!
Sample API code
<?php /** * Set the API URL */ $sApiUrl = "https://www.apiurl.com/";
/** * Set POST Parameters */ $aParams = Array(
'uid' => "--USERNAME--", // Username
'pw' => "--APIKEY--", // API Key
'command' => "querydomain", // Command to Rum
'sld' => "sampledomain", // Main part of the Domain
'tld' => "com"); // Domain Extension
/** * Run the cURL command */
$oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sApiUrl);
curl_setopt($oCurl, CURLOPT_POST, 1);
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $aParams);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
$sResponse = curl_exec($oCurl); curl_close($oCurl);
/** * Turn results into Simple XML Object */
$oOutput = new SimpleXmlElement($sResponse);
/** * Debugging output, so we can see what we just got */
print_r($oOutput);
?>
API Commands
check Checks whether a domain name is available for registration.
purchase Registers a new domain name.
transfer Requests a domain transfer to registrar.
extend Extends (renews) domain registration.
changepassword Changes the domain password.
sendpassword Send domain password to domain owner.
contacts Changes domains contacts.
querydomain Returns detailed information about the domain.
sendepp Sends gTLD epp key to domain owner.
refillaccount Refills your reseller account with funds.
changedomainns Changes domains name servers.
sendtransferemail Sends transfer authorisation request to domain owner.
addchildns Add child name server to domain.
updatechildns Update details for child name server.
removechildns Remove child name server from domain.
pushdomain Push domain to another registrar reseller.
getdnsrecords Get domain name server records for a domain.
enablednsdomain Create DNS domain service for domain.
adddnsrecord Add new DNS record to domain.
updatednsrecord Update DNS record for a domain.
removednsrecord Remove DNS record from a domain.
updatednssoa Update DNS SOA record for a domain.
disablednsdomain Destroy DNS domain service for a domain.
getmailrecords Get mail forwarding records for a domain.
addmailforwarder Add a mail forwarder to a domain.
removemailforwarder Remove a mail forwarder from a domain.
updatemailforwarder Update the details of a Mail Forwarder for a domain.
geturlrecords Get URL Forwarding records for a domain.
addurlforwarder Add a URL Forwarding record to a domain.
updateurlforwarder Update a URL Forwarding record for a domain.
removeurlforwarder Remove a URL Forwarding record for a domain.
getreglock Get registry lock details for a domain.
setreglock Set a registry lock for a domain.
updatecontact Update an address book entry.
getapiinfo Get information about the Domain System API.
transferout Push a domain name to another registrar, given their tag.
Outputted XML from example above
SimpleXMLElement Object
(
[results] => SimpleXMLElement Object
(
)
[errors] => SimpleXMLElement Object
(
[error] => SimpleXMLElement Object
(
[domain] => SimpleXMLElement Object
(
[name] => google.com
[status] => SimpleXMLElement Object
(
[code] => 211
[text] => Unavailable
[description] => The domain name you queried has been registered through another registrar.
)
)
)
)
[errorcount] => 1
[exectime] => 0.399 second(s)
[enviroment] => live
[version] => 2.3.9 beta
)

I can see what it is you are trying to do. However which part in particular are you having issues with? It looks as though you have the API already. Is it not functioning correctly?
Do you need help in writing the PHP to do your 'Yes'/'No' step above?
And why are you "checking again in 5 minutes"?

Related

SimplesamlPHP infinite redirection

I'd setup simplesamlphp to my localhost as a 3 different virtual host.
1. http://idp-saml.com
2. http://sp-saml.com
3. http://api-saml.com
When I tried to connect idp-saml.com using sp-saml.com then it works fine.
Now, I want to integrate it with my own application api-saml.com.
For that, I'd follow the below steps:
Create "authsouce" to sp-saml.com on 'authsources.php'.
'sp1' => array(
'saml:SP',
'privatekey' => 'sp-saml.pem',
'certificate' => 'sp-saml.crt',
'entityID' => 'http://api-saml.com',
'idp' => 'http://idp-saml.com',
)
Now, go to the Federation page and click on "SP1" metadata and copy SAML 2.0 Metadata XML
Then go to idp-saml.com and open metadata-converter.php and parse SAML 2.0 Metadata XML.
Copy both shib13-sp-remote and saml20-sp-remote to metadata\shib13-sp-remote.php and metadata\saml20-sp-remote.php on idp-saml.com virtual host and I can see api-saml.com under federation tab under SAML 2.0 SP Metadata (Trusted) section.
https://www.screencast.com/t/424rmDxRlRfV
Now, Go to api-saml.com directory and create index.php and add below code
require_once('sp-saml/lib/_autoload.php');
$saml_auth = new SimpleSAML_Auth_Simple('sp1');
if ($saml_auth->isAuthenticated()) {
$attributes = $saml_auth->getAttributes();
var_dump($attributes);
}
else {
$saml_auth->requireAuth();
}
Now, tried to access http://api-saml.com and it goes to idp-saml.com and ask me for login credentials. After adding credentials it does not redirect back me to api-saml.com and behave like infinite redirection. You can see https://www.screencast.com/t/VGhDHE1j
You app and the authsource SP metadata should be on the same domain. Your steps 1 and 2 should download the metadata from http://api-saml.com/simplesaml/... rather than from a domain that is distinct from your app.
The SP metadata contains information on authorized Assertion Consumer Service (ACS) urls - and the metadata you are generating and then loading into the IdP only lists paths under http://sp-saml.com as a legitimate return urls. When you attempt to use the authsource from a different domain then the IdP see an unauthorized return url, ignores it and instead uses the one from the metadata which isn't want you want.

Get IP address of the server sending a request via html form

I want to get the IP address of the server sending request via HTML FORM.
I made a test like this:
HTML FORM (form.html in server 1):
<form action="URL_OF_SERVER2/rec.php" method="post">
<input type="submit" value="submit">
</form>
PHP FILE: (rec.php)
<?php
echo $_SERVER['HTTP_REFERER'].'<br><br>'; // To get referal URL
echo $_SERVER['REMOTE_ADDR']; // To get IP Address
?>
But when i tested, i get my own IP Address and not the one of the server.
Second try:
<?php
echo $_SERVER['HTTP_REFERER'].'<br><br>'; // To get referal URL
$result = parse_url($_SERVER['HTTP_REFERER']);
echo gethostbyname($result['host']); // To get IP Address
?>
But this not get real IP but the one of cloudflare for example, i want make same system as perfectmoney, you put your real IP on your dashboard to accept only request coming from, even if you are behind cloudflare, perfectmoney detect the real IP.
On my dashboard i can put IPs by range: 127.0.0.1/24 , 127.0.0.* ... to accept only requests coming from and even if the domain name is behind cloudflare or another similar services.
$_SERVER['SERVER_ADDR']; is the server that executes the script's address. $_SERVER['REMOTE_ADDR']; is the client address (the one that sent the request to the server from the server's point of view.
See the $_SERVER array documentation for more info.
address of the server sending request
The server doesn't send a request. The browser sends a request, and the server sends a response.
If you want the IP of the browser sending a request, use $_SERVER['REMOTE_ADDR'].
If you want the IP of the server sending a response, use $_SERVER['SERVER_ADDR'].
Note: $_SERVER['REMOTE_ADDR'] may not actually represent the browser's IP if there are any proxies in the way.
Update: If you want the IP address of the REFERER server, you will have to do your own DNS lookup.
$data = parse_url( $_SERVER['HTTP_REFERER']);
print_r(dns_get_record($data['host']));
This will give you:
Array
(
[0] => Array
(
[host] => www.google.com
[class] => IN
[ttl] => 270
[type] => A
[ip] => 172.217.9.68
)
[1] => Array
(
[host] => www.google.com
[class] => IN
[ttl] => 14
[type] => AAAA
[ipv6] => 2607:f8b0:4009:816::2004
)
)
Note however that this is unreliable, as $_SERVER['HTTP_REFERER'] can easily be faked.

ip2location: get all ip(s) belonged to a domain

I want to have all ip(s) belonged to a domain, e.g. google.com, I recently have a look at this, https://github.com/ip2location/ip2location-cakephp. So, what I am going to do is likes this:
<?php
// clientIp() will iterate from 1.1.1.1 to 255.255.255.255
App::uses('IP2LocationCore', 'IP2Location.Model');
$IP2Location = new IP2LocationCore();
$record = $IP2Location->get($this->request->clientIp());
if(strcmp($record->domainName, 'google.com')) {
// log the ip to a text file
}
?>
My question is: is this solution feasible?, and anyway better than this?
I'm not much of a PHP person, so consider that in my reply!
It seems that what ip2location does is to take an IP address, and gives you its location. It does this (I imagine) by compiling information from assorted data sources.
However you need to start with an IP Address and it will give you the reverse domain that is associated with that. This could well be different than the forward look up address.
For instance I have a hostname vm.example.com that I use to point to a remote desktop session on Azure. If you did a reverse lookup on that address you would not get any information on my domain, you would get the Azure domain, because that's where the reverse is registered.
and as far as I'm aware, unless zone transfers are enabled, there is no way to get all of the hostnames in a domain. At least not without incrementing through the entire domain.
Is there a specific reason you want to do this?
Try using the PHP function gethostbynamel.
<?php
$hosts = gethostbynamel('google.com');
print_r($hosts);
?>
This will for example return:
Array
(
[0] => 173.194.113.35
[1] => 173.194.113.41
[2] => 173.194.113.46
[3] => 173.194.113.34
[4] => 173.194.113.40
[5] => 173.194.113.39
[6] => 173.194.113.33
[7] => 173.194.113.37
[8] => 173.194.113.32
[9] => 173.194.113.38
[10] => 173.194.113.36
)

Google Translate API returns 403 (PHP)

The question is about Google Translate API
I set a project and turn the billing on (with some money on the account)
I created a key for server app (also tryed to use a browser key) and added all 3 IPs I have (home and 2 servers)
What I see:
It does work in apis-explorer and in a browser address bar (https://www.googleapis.com/language/translate/v2/detect?q=an%20english%20text&key=MY_KEY)
It returns 403 error if I trying to get the same URL from PHP code:
$apiKey = 'MY_KEY';
$url = 'https://www.googleapis.com/language/translate/v2/detect?q=an%20english%20text&key=' . $apiKey . '';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
curl_close($handle);
print_r(json_decode($response, true));
thre result:
Array (
[error] => Array (
[errors] => Array (
[0] => Array (
[domain] => usageLimits
[reason] => ipRefererBlocked
[message] => There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.
[extendedHelp] => https://console.developers.google.com
))
[code] => 403
[message] => There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.
))
I checked the IPs dozens of times, tryed to use browser key with allowed URL as referer.
Out of ideas.
Thanks for admins, they helped to figure out.
By default - curl using our ipv6 address...
So we have three options here:
curl_setopt($handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
add ipv6 address to allowed list
Turn ipv6 off forthe server
I had to be more attentive and remember about ipv6 :-)
I am told that this is fixed by simply removing all Ip's from the edit allowed IP's option. This makes it so that it is less secure, but it will accept all IP's after that.

YouTube Analytics API PHP: usageLimits accessNotConfigured

I am using the [Google Analytics API PHP] by wanze. I was able to set up authentication (using web auth only) and everything and I stored the token in a session. On another page, I use this code to find all the accounts the user logged in with.
session_start();
include('GoogleAnalyticsAPI.class.php');
$ga = new GoogleAnalyticsAPI();
$ga->auth->setClientId('replaces'); // From the APIs console
$ga->auth->setClientSecret('replaces'); // From the APIs console
$ga->auth->setRedirectUri('replaced'); // Url to your app, must match one in the APIs console
// Get the Auth-Url
$url = $ga->auth->buildAuthUrl();
// Set the accessToken and Account-Id
$ga->setAccessToken($_SESSION['accessToken']);
$ga->setAccountId('ga:xxxxxxx');
// Load profiles
$profiles = $ga->getProfiles();
print_r($profiles);
$accounts = array();
foreach ($profiles['items'] as $item) {
$id = "ga:{$item['id']}";
$name = $item['name'];
$accounts[$id] = $name;
}
// Print out the Accounts with Id => Name. Save the Id (array-key) of the account you want to query data.
// See next chapter how to set the account-id.
print_r($accounts);
I this returned:
Array
(
[http_code] => 403
[error] => Array
(
[errors] => Array
(
[0] => Array
(
[domain] => usageLimits
[reason] => accessNotConfigured
[message] => Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.
[extendedHelp] => https://console.developers.google.com
)
)
[code] => 403
[message] => Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.
)
)
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home3/chalzzy/public_html/dashboard/dashboard.php</b> on line <b>21</b><br />
Array
(
)
I see in a lot of places that I need to remove or set all refers in a "Referrals" section in the console but I can't seem to fins that in the new or old console. If it is there and I can't find it, can you please give me a url or a screenshot?
Also, these are all the APIs I have installed for this project:
Thanks in advance,
Ben
Also, let me know if you need more details!
Hey (I'm sorry it was a very stupid question),
What you have to do is add to your APIs list "Analytics API" in the Developers Console.

Categories