Skip to content

Commit 26ba226

Browse files
author
Jason Fenton
committed
Commit: Version 1.0.0 (July 17, 2024)
1 parent 28bbf54 commit 26ba226

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

README.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
# Coldfusion OpenSRS API Domain availability lookup
2-
OpenSRS domain availability lookup for Coldfusion/Lucee.
2+
OpenSRS domain availability lookup for Coldfusion/Lucee server.
3+
4+
# License
5+
6+
Copyright (c) 1997-2024 interVations
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
20+
# About
21+
22+
This CFC is to facilitate making calls to the OpenSRS Domains API.
323

424
As a reseller of domains from OpenSRS/Tucows for over ten(10) years, we code exclusively using Coldfusion/Lucee.
525

626
We are embarking on a unique integration of the OpenSRS API platform with an aim to give our many customers the tools they need for everyday domain management tasks.
727

8-
The Coldfusion OpenSRS API Domain availability lookup code is just a small piece. We are publishing it here for free for all to use without limitations, we just ask that you support this repository by sponsoring us by buying us a coffee.
28+
The Coldfusion OpenSRS API Domain availability lookup code is just a small piece. We are publishing it here for free for all to use without limitations, we just ask that you support this repository by sponsoring us by buying us a coffee at the link below.
929

1030
# <img src="https://github.com/images/modules/search/mona-love.png" alt="Sponsor"> Sponsor this project
1131
https://buymeacoffee.com/intervations
@@ -14,6 +34,20 @@ By sponsoring this project, you help move it up our list of projects to do.
1434

1535
We intend to sell copies of the final skin product which will be accessable in a private repository. Depending on how much you sponsor, you will be given a generous discount of the final price.
1636

37+
## Usage
38+
39+
<cfset objOpenSRS = createObject("component","apiOpenSRS") />
40+
<cfset stResults = objOpenSRS.searchDomainAvailability(domain_name=url.domain)>
41+
42+
<cfloop array="#stResults#" index="domain">
43+
#domain.domain# - #domain.status#
44+
</cfloop>
45+
46+
See also a functional example at:
47+
48+
https://demo.intervations.com.au/opensrs-api-v1.0-domain-availability-lookup/
49+
50+
1751
# Need further information or have feedback?
1852

1953
Submit a question or feedback using the Issues tab on this respository, or you can always contact the team directly by emailing [email protected].

apiOpenSRS.cfc

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--- @@Copyright: interVations 1997-2024, https://www.intervations.com.au --->
2+
<!--- @@displayname: OpenSRS Domains API --->
3+
<!--- @@Description: This component is for interacting with the OpenSRS Domains API --->
4+
<!--- @@Developer: Jason Fenton ([email protected]) --->
5+
6+
<cfcomponent>
7+
8+
<cffunction name="searchDomainAvailability" access="remote" returntype="array">
9+
<cfargument name="domain_name" type="string" required="yes">
10+
11+
<cfset lookupKey = 0>
12+
13+
<cfsavecontent variable="lookupTLDs">
14+
<item key='0'>.au</item><item key='1'>.com.au</item><item key='2'>.net.au</item><item key='3'>.org.au</item><item key='4'>.asn.au</item><item key='5'>.id.au</item><item key='6'>.com</item><item key='7'>.net</item><item key='8'>.org</item><item key='9'>.biz</item><item key='10'>.info</item><item key='11'>.mobi</item><item key='12'>.co</item>
15+
</cfsavecontent>
16+
17+
<cfscript>
18+
Variables.xml = "<?xml version='1.0' encoding='UTF-8' standalone='no' ?><!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'><OPS_envelope><header><version>0.9</version></header><body><data_block><dt_assoc><item key='protocol'>XCP</item><item key='action'>name_suggest</item><item key='object'>domain</item><item key='attributes'><dt_assoc><item key='services'><dt_array><item key='0'>lookup</item></dt_array></item><item key='searchstring'>#arguments.domain_name#</item><item key='tlds'><dt_array>#lookupTLDs#</dt_array></item></dt_assoc></item></dt_assoc></data_block></body></OPS_envelope>";
19+
20+
variables.signature = lcase(hash(Variables.xml & "yourOpenSRSAPIKey", "md5")); // change yourOpenSRSAPIKey to your OpenSRS API Key.
21+
variables.signature = lcase(hash(Variables.signature & "yourOpenSRSAPIKey", "md5")); // change yourOpenSRSAPIKey to your OpenSRS API Key.
22+
23+
cfhttp(method="post", url="https://horizon.opensrs.net:55443") { // change to https://rr-n1-tor.opensrs.net:55443 for production use.
24+
cfhttpparam(type="header", name="Content-Type", value="text/xml");
25+
cfhttpparam(type="header", name="X-Username", value=yourOpenSRSUsername; // change yourOpenSRSUsername to your OpenSRS Username.
26+
cfhttpparam(type="header", name="X-Signature", value=variables.signature);
27+
cfhttpparam(type="body", value=Variables.xml);
28+
}
29+
30+
if (cfhttp.statusCode eq "200 OK") {
31+
// Parse the XML response
32+
responseXML = xmlParse(cfhttp.fileContent);
33+
34+
// Extract lookup domain data
35+
lookupDomains = [];
36+
lookupItems = xmlSearch(responseXML, "/OPS_envelope/body/data_block/dt_assoc/item[@key='attributes']/dt_assoc/item[@key='lookup']/dt_assoc/item[@key='items']/dt_array/item");
37+
38+
for (item in lookupItems) {
39+
domain = xmlSearch(item, "dt_assoc/item[@key='domain']")[1].xmlText;
40+
status = xmlSearch(item, "dt_assoc/item[@key='status']")[1].xmlText;
41+
arrayAppend(lookupDomains, { "domain": domain, "status": status });
42+
}
43+
} else {
44+
// Something went wrong
45+
writeOutput("<h3>Error</h3>");
46+
writeDump(cfhttp);
47+
}
48+
</cfscript>
49+
50+
<cfreturn lookupDomains>
51+
</cffunction>
52+
53+
</cfcomponent>

0 commit comments

Comments
 (0)