Monday, May 04, 2015

Running RackTables on Windows 7

I recently worked with a client that had a rapidly growing number of connected networks and a growing collection of spreadsheets and Visio drawings to manage data centre documentation. I thought, "there must be a better way".
While there are a range of solutions out there to deal with portions of the client's needs, I could only one solution that met them all together in one low cost, easy to manage package.

RackTables is essentially a PHP/MySQL solution to documenting data centre assets that is developed to run with Linux distributions and packages. My client however runs a Microsoft Windows shop. While I managed to get a Linux box into their environment for an initial evaluation, the ongoing question is "will it run on Windows?".

Much to my pleasure, the short answer is "yes". The HowTo documented below shows how I set it up with Windows 7 and what I suspect the limitations are. It's worth noting that using this setup in a production environment comes with the usual caveats; security is your own risk and the instructions below come with no warranties whatsoever. The process may work equally as well on Windows Sever 2008 and later.

Features Not Available on Windows
Out of the box, there are certain features of RackTables that are tied to *nix environments through packages not built into Windows. Some features may be available with the use of additional windows applications. Effected features may include:


WAMP 
By far the cheapest and easiest solution to get PHP, MySQL and a web server onto Windows is to grab and install a pre-built stack that includes Apache, MySQL and PHP. There exists two such stacks that I know of. The SourceForge WAMP and the Bitnami WAMP. Notably Bitnami also hosts a WAMP Docker container; though that is beyond the scope of this write-up.
Installing WAMP is dead simple. I grabbed a copy from here and installed to the default directory c:\wamp
Interacting with WAMP is done by left-clicking the system tray icon and running through the pop-up menu to access configuration files, logs and management tools.

RackTables
Download the latest stable RackTables zip files and extract the wwwroot folder to c:\racktables
From the WAMP system tray icon menu, add an Apache alias (WAMP > Apache > Alias directories > Add an alias
Enter 'racktables' and 'C:\RackTables\wwwroot' as the alias and destination, then Enter to exit.

Edit the alias file,'C:\wamp\alias\racktables.conf' so it looks like:

Alias /racktables/ "c:/RackTables/wwwroot/"
# to give access to racktables from outside
# replace the lines
#
# Require local
#
# by
#
# Require all granted
#

Options Indexes FollowSymLinks MultiViews
AllowOverride all

Require local


Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
From the WAMP system tray icon menu, open a MySQL console (WAMP > MySQL > MySQL Console) and run the following SQL commands to create the database and a user:
CREATE DATABASE racktables_db CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON racktables_db.* to racktables_user@localhost IDENTIFIED BY "MY_SECRET_PASSWORD";

exit
Point your browser to RackTables on your Apache webserver. (e.g. http://localhost/racktables ) In my case, I already had a web server installed, so I setup apache on port 81. If everything goes well, you will get an error message. At the end of the error message is a link (labelled "here") to the RackTables installer; click it!

This should take you to the first of the seven installation steps.
 Click 'proceed'.

Click 'proceed'.

At this point you'll need to create an empty text file called c:\wamp\www\racktables\inc\secret.php
Then click the 'retry' button.

Keep the default settings which will have MySQL connections performed over TCP. You should only have to enter your chosen password (used in the SQL command earlier) and click 'retry'.

Click 'proceed'.

At step 4, RackTables will attempt to verify that you've secured the secret.php file that is has now configured. To do this I modified the file security settings as shown below and made the file read-only.


Hit the 'retry' button in the browser window and if it's all good you should get the confirmation shown below.

Click 'proceed'.

RackTables has now initialised its MySQL database. Click 'proceed'.

Set your 'admin' user password.
Click 'retry' and you should get the confirmation shown below.

Click 'proceed'.

Installation complete!

You should now be able to point your browser back to your RackTables installation  (e.g. http://localhost/racktables ), login as you admin user and get the main screen as shown below.


Enabling Features
OK, so in step 2 of the RackTables installation you would have noticed a couple of PHP extenstions that were marked 'not present'. There are three we can 'enable' as follows

System PATH Variable
Some of the extensions fail to be found because the DLL files can't be found. Evidence of this will show in your PHP error log. I added the following paths to my system PATH variable and restarted Apache to resolve this:

C:\wamp\bin\php\php5.5.12
C:\wamp\bin\php\php5.5.12\ext
SNMP
Simply go through the WAMP menu; WAMP > PHP > PHP Extensions > php_snmp. Make sure its enabled (ticked).

PCNTL
PCNTL is a PHP extension that provides process control functions. Apparently it relies on *nix functions and so it won't work on Windows.

HTTPS
This is really a security feature, so I've covered it below.

Security

OK, so Pierre Baron has listed his experience and the process noted below is based in part on that. The HTTPS setup is based on a WAMP forum article.

HTTPS
This is optional, however if you're exposing your Apache interface to a public network, its pretty much mandatory for security. Without HTTPS, passwords are transmitted in plain text and provide an easy way to bust into your WAMP environment, particularly if you allow administrative (write access) via a public interface/IP. The procedure below assumes you're just going to use a self-signed certificate. I'd recommend buying one if you have "public" users who don't know enough to sense a MITM attack. Ok, so here goes;

Open a command prompt to your Apache bin directory, such as
c:\wamp\bin\apache\apache2.4.9\bin
Create a self-signed private RSA key by running the command:
openssl genrsa -des3 -out server.key 1024
Make sure you use a strong password and keep it securely. In many cases the key you are creating is your first line of security. Create a copy of the key file:
copy server.key server.key.org
Create a public key by removing the pass phrase from the private key:
openssl rsa -in server.key.org -out server.key
Use this key to create a self-signed X509 certificate:
openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt -config C:\wamp\bin\apache\apache2.4.9\conf\openssl.cnf
Enter data into the certificate fields when prompted. Then create the folders:

C:\wamp\bin\apache\apache2.4.9\conf\ssl.crt
C:\wamp\bin\apache\apache2.4.9\conf\ssl.key
copy server.crt to the ssl.cert folder and server.key to the ssl.key 
Through the WAMP menu;
- enable the ssl module: WAMP > Apache > Apache modules > ssl_module
- enable the socache module: WAMP > Apache > Apache modules > socache_shmcb_module
- enable the php extension: WAMP > PHP > PHP extensions > php_openssl

Edit the file C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf and remove the # (comment) character from the line:
Include conf/extra/httpd-ssl.conf
And add the # (comment) character to the lines:
#Listen 0.0.0.0:80#Listen [::0]:80 

Open the file C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-ssl.conf
Firstly, do a search and replace all from 'c:/Apache24' to 'c:/wamp/bin/apache/apache2.4.9' or your equivalent. Find the line which says: . Right after it, change the document root and server name to suit your installation. An example would be:


# General setup for the virtual host
DocumentRoot "c:/wamp/www/"
ServerName severname.example.com:443
ServerAdmin admin@example.com
ErrorLog "C:/wamp/bin/apache/apache2.4.9/logs/ssl_error.log"

TransferLog "C:/wamp/bin/apache/apache2.4.9/logs/ssl_access.log"
 Then edit the following lines to match you certificate and key:

SSLCertificateFile "C:/wamp/bin/apache/apache2.4.9/conf/ssl.crt/server.crt"
SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.4.9/conf/ssl.key/server.key"
Change the line which says  or similar to and add the following lines inside those ... tags:
Options Indexes FollowSymLinks MultiViewsAllowOverride AllOrder allow,denyallow from all
To test your changes, run the following at your command prompt you opened previously (at the apache bin dir).
httpd -t
You should get a 'Syntax OK' message. If not, follow up the error message before restarting your Apache service.

Firewall
First and foremost only allow your Apache service (TCP port 443 if using HTTPS or TCP port 80 for plain HTTP) through your Windows (or equivalent) firewall and only to your public facing IP address (local connections shouldn't touch the firewall).

MySQL & phpMyAdmin
Go to the phpMyAdmin URL (e.g. http://localhost/phpmyadmin ) and select the 'Users' tab at the top of the main screen. Set a password for each of the three 'root' users that have GRANT = Yes. Set the password through the 'Edit Privileges' link and resulting screen. If you reload your web browser at this point, you will get an error message as the phpMyAdmin configuration doesn't have the root password any more.
Edit the file C:\wamp\apps\phpmyadmin4.1.14\config.inc.php (or the equivalent folder for your phpMyAdmin version). Enter your new root password in the line that looks like this:
$cfg['Servers'][$i]['password'] = 'my_root_password';
 Save the file and reload phpMyAdmin in your browser. Your user list should now look like this;
Note that you will need the new password if you wish to use the WAMP MySQL console!

Other Web Services
By default WAMP installs such that the phpMyAdmin, webgrind, SQL Buddy and phpSysInfo tools are only accessible from 'local' addresses. If you want to be ultra-secure, I'd edit the alias configurations under C:\wamp\alias and change the line 'Require local' to 'Require all denied' to disable them until they are needed.
Don't forget to restart the Apache service if you make changes.

OK, that wraps it up, you should have a RackTables box ready for use at:
https:/localhost/racktables
Enjoy!

10 comments:

Unknown said...

Hello,

I have followed your steps with a few hiccups but Rack Tables will not load but the localhost from wampserver does load. I have installed this on Windows Server 2012. My Apache service would not start after a few installs and google searches we found that the httpd needed to be commented out in dir:

\wamp\bin\apache\apache2.4.9\conf\extra\httpd-autoindex

# We include the /icons/ alias for FancyIndexed directory listings. If
# you do not use FancyIndexing, you may comment this out.
#
#Alias /icons/ "s:/Apache24/icons/"
#
#
# Options Indexes MultiViews
# AllowOverride None
# Require all granted
#

Im not sure if the above is causing my issue but wanted to see if you had any further ideas as to why the http://localhost/racktables will not load.

When I try to browse to it I get "This page can't be displayed". I'm guessing something is not pointed to the right dir.

Thanks

Unknown said...

Update :

I was using the wrong web address:

http://localhost:81/racktables/

Now after using the above I get

"Forbidden
You don't have permission to access /racktables/ on this server.
Apache/2.4.17 (Win64) PHP/7.0.0 Server at localhost Port 81"

Forgot I changed the port from 80 to 81.

Unknown said...

Update:

Used the link below to resolve, I finally have the racktables install page!

http://stackoverflow.com/questions/10600795/wamp-server-error-forbidden-you-dont-have-permission-to-access-phpmyadmin-on

Killed service before changing the file, then I made the changes below.


AllowOverride none
Require all denied

to


AllowOverride none
Require all granted



Dr. I thank you if you read this. Besides a few hiccups your steps are the best out on the interwebs!

Dr Paul said...

Thanks for the feedback gnorth2.
In general I'd recommend using an "allow from x.x.x.x" statement unless you're creating a public server in which case the change you've made makes sense.
Cheers,
Dr Paul.

Anonymous said...

I was getting a denied access page, with the included racktables.conf file in this post. I had to add the , to get it to work.

Anonymous said...

Darn html flags :) I had to add {less than symbol}Directory "same c: path as alias line"{greater than symbol} then every from line two and on followed up with a closing {less than symbol}/Directory{greater than symbol}

Davin Studer said...

Any idea if it will run on IIS?

Numair said...

How to download the database in rack table and install it to another

Dr Paul said...

Sorry Numair, I no longer have a Racktables instance running.

Numair said...

Sir is it possible to implement a new racktables version and import the old database in it