JTSDNS
Author: Stefan Martens

E-Mail:
info@stefan1200.de

Homepage:
http://www.stefan1200.de


-= Copyright =-
This program is free for use, but please notify me if you found a bug or if you have some suggestion.
The author of this program is not responsible for any damage or data loss!
It is not allowed to sell this program for money, it has to be free to get!
It is only allowed to modify this program for your own use, don't send it to other peoples or release it!
You have to ask me for a permission first if you want to publish something which contains parts of my source code!

Teamspeak 3 is developed by TeamSpeak Systems GmbH, Sales & Licensing by Triton CI & Associates, Inc.
More information about Teamspeak 3: http://www.teamspeak.com

Launch4j was used to create the Windows executables of the JTSDNS. Launch4j use the BSD/MIT license.
More information about Launch4j: http://launch4j.sourceforge.net

procrun can be used to install the JTSDNS as a Windows service. procrun is an Apache Commons product and use the Apache license.
More information about procrun: http://commons.apache.org/proper/commons-daemon/procrun.html


-= Information =-
This is a TSDNS alternative using MySQL as database. In addition to this it also saves to database how often a hostname was requested and the last requested time.
Just import the jtsdns.sql to your MySQL database and, if you want, create your own website that adds or edits the entries in that JTSDNS table.
The names of the columns are quite self explaining. Like the real TSDNS application wildcards at hostnames are supported.

It can still have bugs, but one user use it already on a server without problems. For more information about the usage, just look in the readme.txt.


-= System requirements =-
This program runs on Windows and Linux (even without X server). On Mac OS X 10.4+ it should run too, but it is not tested.
Please send me a message if this program runs on Mac OS X without problems.
All you need is a Java SE runtime environment version 5 or newer.
You can get the latest version from www.java.com or http://www.oracle.com/technetwork/java/javase/downloads/index.html
Mac OS X 10.4 or newer users should have it already installed.
FreeBSD Users should look at http://www.freebsd.org/java/ to learn more about Java on FreeBSD.
Linux users should install the package openjdk-8-jre-headless / java-1.8.0-openjdk-headless.
On older linux you can also use sun-java5-jre, sun-java6-jre, openjdk-7-jre or java-1.7.0-openjdk.
An example on Debian or Ubuntu: apt-get install openjdk-8-jre-headless
An example on CentOS or Fedora -21: yum install java-1.8.0-openjdk-headless
An example on Fedora 22+: dnf install java-1.8.0-openjdk-headless
An example on OpenSUSE: zypper install java-1_8_0-openjdk-headless
The package gcj-jre (GNU Java) will not work!

Maybe you want to limit the maximum ram that the program use. This can be useful on a virtual server.
You can do this by using java command line arguments for the java virtual machine.
If you want to use 30 MB ram as maximum, you can start JTSDNS like this:
java -mx30M -jar JTSDNS.jar
Notice: If you choose a too low value, JTSDNS may not run or is not stable. I did no long time tests on this.


-= Configuring JTSDNS =-
First open the file JTSDNS.cfg using a text editor like Notepad or Notepad++, file is saved in ANSI format (encoding ISO-8859-1).
Configure the MySQL stuff and if you like activate the verbose mode.
The verbose mode is only recommend if you test something or you don't expect much TSDNS requests.

As last step just import the jtsdns.sql to your MySQL database and fill it with some data.
Like the real TSDNS application wildcards at hostnames are supported.
If the TS3 client request for ts3.stefan1200.de and only the entry *.stefan1200.de exists in the MySQL table,
the IP address of *.stefan1200.de will be returned.


-= General starting information =-
It is possible to change the directory where JTSDNS is looking for the config file.
Just set an app.home environment variable by adding the argument -Dapp.home=PATH_TO_JTSDNS while starting the JTSDNS.
This way you can also use the variable %apphome% at the logfile path, which will be replaced by the app.home path.
If no app.home environment variable exists, JTSDNS is looking for the config file in the current directory and
the variable %apphome% at the logfile path will be replaced with an empty string.

Examples:
java -Dapp.home="D:\My Services\JTSDNS\" -jar JTSDNS.jar
java -mx30M -Dapp.home="/home/username/my services/JTSDNS/" -jar JTSDNS.jar


-= Run JTSDNS on Linux =-
One solution is using screen. Installing screen is easy (if not already):
On Debian or Ubuntu:
apt-get install screen
On CentOS or Fedora:
yum install screen
On OpenSUSE:
yast -i screen

After you did this, you can change to the JTSDNS directory with cd and fire the following command:
screen -d -m -S jtsdns java -jar JTSDNS.jar
This starts the program in a special shell screen named jtsdns.

To open this shell screen named jtsdns, maybe to read the output of the program, just do:
screen -r jtsdns

To close an opened shell screen without quitting the program just press the following key combination:
CTRL + A + D

If you run into problems, check the section "System requirements" in this readme file.
It is possible to reduce the amount of memory the program may use.
This is important on Linux VServers.
The low memory example from there to start the program with the screen command:
screen -d -m -S jtsdns java -mx30M -jar JTSDNS.jar


-= Run JTSDNS on Windows =-
First way is to start the program as normal application on Windows.
To do this just run JTSDNS-Windows.exe, you can use the key combination CTRL + c to quit JTSDNS.
You can also use the JTSDNS-Windows_NoWindow.exe, but in this case the only way to quit JTSDNS is using Task Manager.
If you use the verbose mode, you should only use the JTSDNS-Windows.exe or you will never see the verbose output.

Of course you can put a shortcut of the JTSDNS-Windows_NoWindow.exe to the Windows Auto Start directory,
to start JTSDNS on Windows login, but make sure that the "Start in" directory is the JTSDNS directory.
To open the Windows Auto Start directory, just press the two keys Windows + R and enter: shell:startup

If wanted, you can run JTSDNS as a Windows Service, this allows JTSDNS to run in background without a logged in user.

To create a Windows service with the Apache procrun tool, I prepared a small script which do anything for you.
In the tools sub directory you find the script InstallWindowsService.cmd.
If you want, you can edit this script to change the name of the service.
But it should also work without changing anything, the default service name is JTSDNS.
Just run this script with Administrator permissions (right click on it and start as administrator).

The last step is to start the service like displayed at the end of this script.

Important:
The service needs the absolute path to the config file. But my script sends the current path to the JTSDNS.
This allows to use the variable %apphome% at the path for the log file.
If the path is not available (maybe the JTSDNS was not started using the service),
%apphome% will be replaced with an empty string.


-= Counting of TSDNS requests =-
The MySQL table column "usecount" shows the request count.
Every time a TS3 client is requesting the IP address of this hostname, this number will be incremented by 1.
Sometimes it seems that this number will be incremented by 2 or 3. Now it is important to know how the TS3 client works.
As an example you want to connect to ts3.stefan1200.de and the sub domain ts3.stefan1200.de is a real DNS sub domain.
The TS3 client tries to connect to the TSDNS service at ts3.stefan1200.de and stefan1200.de at the same time.
If both domains points to the same TSDNS service, the JTSDNS service gets two requests about the address ts3.stefan1200.de.
In this case the MySQL table column "usecount" for the address ts3.stefan1200.de will be incremented by 1, twice!
This is a wanted (and useful) behavior of the TS3 client and is nothing I can change on my end.


-= Credits =-
For bug reporting, sending suggestions and testing a thanks flies to:
- BigBear
- Boko / WebShell
- Evilblood
- Nobody_cbm / Software Galaxy
- Thomas / TSCoach


-= Changelog =-
Version 1.6.0 (31.03.2018)
+ Added support for NORESPONSE keyword from original TSDNS service. (thx to Evilblood for reporting this missing feature)
- Bugfix: If TSDNS hostname resolve to a DNS hostname, which itself resolves to IPv6, the brackets was not set correctly.
o Updated MySQL Connector/J to version 5.1.46.

Version 1.5.2 (28.08.2017)
- Bugfix: If you use IPv4 and IPv6 at a hostname at the same time,
          the JTSDNS forgot to seperate both entries with a comma for the TS3 client. (thx to Evilblood)
          It is still allowed to seperate both entries with a space in the database,
          but the JTSDNS will now send both seperated with a comma to the TS3 client.

Version 1.5.1 (27.08.2017)
- Bugfix: Shorter IPv6 addresses will now detected right. But still not all legal notations of IPv6 addresses will be detected right. (thx to Evilblood)
          If you have problems while using IPv6, only use one of this notations:
          [1234::89]
          [1234:abc:56:de::89]
          [1234:abc:56:de:0:0:0:89]
          JTSDNS 1.4, 1.4.1 and 1.5.0 only detect the long written notation: [1234:abc:56:de:0:0:0:89]
o Updated the exe files for Windows, created with the newest version of Launch4j.

Version 1.5.0 (30.07.2017)
! Complete recreation of the database query stuff.
  Now only one connection will be used for all requests. This connection keeps connected to the MySQL server.
  Expect a big increase in performance in an environment with many requests per minute.
  The new code should also help to lower the memory requirements, especally in big environments.
+ JTSDNS now try to stop the database and the server socket connection on a friendly way,
  if a task stop request (SIGTERM) will be received (e.g. by CTRL + c).
- Bugfix: The Windows service scripts from the tools directory was not working, if only a 64 bit Java Runtime is installed.
          Created two new scripts, which have to be used, if no 32 bit Java Runtime is installed.
o Updated MySQL Connector/J to version 5.1.42.

Version 1.4.1 (11.12.2016)
- Bugfix: Don't try to resolve hostname, if no entry was found in the database.

Version 1.4 (06.12.2016)
+ Added experimental IPv6 compatibility for TS3 client version 3.1. Please report errors to me.
+ Added hostname resolving, because the TS3 client version 3.1 only accept IP addresses.
  JTSDNS will allow using hostnames of TS3 servers, but will do a DNS resolve just before sending it to the TS3 client.
  Using this way you can continue using dynamic DNS addresses at the TSDNS service with the new TS3 client.
o Updated MySQL Connector/J to version 5.1.40.

Version 1.3 (28.08.2016)
+ Added optional MySQL Connector settings to the config file (settings about compression and encryption of the MySQL connections).
- Bugfix: JTSDNS is now compatible with the new Teamspeak version 3.1. (thx to BigBear)
o JTSDNS version will be printed to log file after starting JTSDNS.
o Updated MySQL Connector/J to version 5.1.39.

Version 1.2 (26.10.2015)
+ New way to create a Windows Service of the JTSDNS. Now it is possible to stop JTSDNS by stopping the service.
  This new way is also compatible with Windows 10 (and should be also compatible with Windows 8, 8.1, Server 2012 and 2012 R2).
  Check out the tools directory! Thanks to the team behind the tool procrun from Apache Commons!
o Logfile path value can contain the variable %apphome% now which will be replaced with the environment variable app.home.
  app.home will be set while starting the JTSDNS as a Windows service created by my script.
  But you can also set this app.home variable while adding the argument -Dapp.home=PATH_TO_JTSDNS while starting the JTSDNS.
  If no app.home environment variable exists, it will be replaced with an empty string.
o Recreated JTSDNS Windows executables with the current version of Launch4j (because of bugfixes).
o Updated MySQL Connector/J to version 5.1.36.

Version 1.1 (16.06.2014) - Updated release on 12.09.2014
o Small update, made MySQL table column hostname unique. Should give you a performance boost on big JTSDNS tables.
  Update your existing table using the following MySQL command:
  ALTER TABLE `jtsdns` ADD UNIQUE (`hostname`)

Version 1.1 (16.06.2014)
o Replaced the verbose config setting with the logfile setting. The logfile contains timestamps.

Version 1.0 (13.06.2014)
o First release