2

Warning: This is long and can probably only be answered by a professional perl programmer or someone involved with a domain registrar or registry company.

I run a website hosting, design, and domain registration business. We are a registrar for some TLDs and a couple of them require us to have a whois server for domains registered with us. I have a whois server set up which is working but I know it's not doing it the right way, so I'm trying to figure out what I need to change.

My script is set up so going to whois.xxxxxxxxxx.com via browser or doing whois -h whois.xxxxxxxxxx.com from shell works. A whois on a domain registered with us gives whois data and a domain not registered with us says it's not registered with us.

If needed, I can give the whois url, or it can be figured out from my profile. I just don't want to put it here to look like advertising or for search engines to end up going to.

The problem is how my script does it. My whois url is set up in apache's httpd.conf file as a normal subdomain to listen on port 80, and it's also set up to listen on port 43. When called via browser, it works properly, gives a form to provide a domain and checks our database for that domain. How it works when called from shell is fine as well, but how it distinguishes between the 2 is weird, and how it gets the domain is also weird. It works, but it can't be the right way to do it.

How it distinguishes between shell and http is:

if ($ENV{REQUEST_METHOD} ne "GET") {
    &shell_process;
  }
  else {
    &http_process;
}

It would seem more logical for this to work:

if ($ENV{SERVER_PORT} eq 43) {
    &shell_process;
  }
  else {
    &http_process;
}

That doesn't work because even when called through port 43 as a whois request, the ENV vars are saying "SERVER_PORT = 80".

How it gets the domain name when called from shell is:

$domain = lc($ENV{REQUEST_METHOD});

You would think the domain would be the QUERY_STRING or more likely, in the ARGV vars, but it's not.

Here are the ENV vars (that matter) when called via http:

SERVER_NAME = whois.xxxxxxxxxxxxx.com
REQUEST_METHOD = GET
QUERY_STRING = domain=roughdraft.ws&submit=+Get+Whois+
SERVER_PORT = 80
REQUEST_URI = /index.cgi?domain=premierwebsitesolutions.ws&submit=+Get+Whois+
HTTP_HOST = whois.xxxxxxxxxxxxxx.com

Here are the ENV vars (that matter) when called via shell:

SERVER_NAME = whois.xxxxxxxxxxxxxx.com
REQUEST_METHOD = premierwebsitesolutions.ws
QUERY_STRING = 
SERVER_PORT = 80
REQUEST_URI = 

Notice the SERVER_PORT stays 80 either way, even though through shell it's set up on port 43.

Notice how via shell the REQUEST_METHOD is the domain being looked up.

I've done lots of searching and did find swhoisd: Simple Whois Daemon, but that's only for small databases. I also found the Daemon::Whois perl module, but it uses a cdb database which I know nothing about, it has no instructions to it, and it's a daemon which I don't really need because the script works fine when called through apache on port 43.

Does anyone know how this is supposed to be done? Can I get the script to see that it was called via port 43? Is it normal to use REQUEST_METHOD this way? Is a whois server supposed to be running as a daemon?

Thanks for helping, or trying to.

Mike

pwsowner
  • 23
  • 3

2 Answers2

1

WHOIS is not a HTTP-like protocol, so attempting to serve it through Apache on port 43 will not work correctly. You will need to write a separate daemon to serve WHOIS — if you don't want to use Daemon::Whois, you will probably at least want to use something like Net::Daemon to simplify things for you.

  • The Net::Daemon looks like what I need. It even comes with better instruction and samples than the Daemon::Whois. I've found answers to a lot of questions on this site, but couldn't find this one, so decided to sign up and ask. I'm glad I did. Thanks – pwsowner May 16 '14 at 23:03
  • BTW, I'm kind of curious who this is for. Any chance you can tell me in a comment or by email (check my profile for the address)? –  May 17 '14 at 00:04
  • Myself, premierwebsitesolutions.com. We started as a reseller for domains back in 2002, became a registrar for .ws a couple years later which required having a whois server, then became a registrar for other TLDs later. Some of them also require us having a whois server. Our current method is working, but I knew it wasn't the proper way. If you want to see how our current method works, try looking up premierwebsitesolutions.ws or .com through our whois server, whois.p...w...s....com. (don't want robots to start going there) – pwsowner May 17 '14 at 14:58
  • Just for completion, even years later, there is an Apache module called `mod_whois` exactly catering to this need. See https://sourceforge.net/projects/modwhois/ and you have even a "Next Generation" one at https://github.com/centralnic/mod_whoisng ; so all can be done inside Apache, but I am not saying it is the best option. – Patrick Mevzek Jan 08 '18 at 21:29
  • @PatrickMevzek Ironically -- as you've noted on one of my other questions! -- such a module is increasingly unnecessary nowadays, as most registries are moving towards thick WHOIS. –  Jan 08 '18 at 21:33
  • A registry could want to use it :-) And of course, you do not need a specific module to use Apache for RDAP... – Patrick Mevzek Jan 08 '18 at 21:34
0

https://stackoverflow.com/a/933373/66519 states something could be set to detect cli vs web. It applies to php in this case. Based on the lack of answers here maybe it might help you get to something useful. Sorry for the formatting I am using the mobile SO app.

Community
  • 1
  • 1
ojblass
  • 21,146
  • 22
  • 83
  • 132