Category Archives: Railo

MovieBox demo app on GitHub


Just a quick note, I have a project up on GitHub called MovieBox. This was based on keyStream by Cory Fail, but is built on top of the ColdBox framework. Right now it is in a holding pattern because I am going to rewrite it using AngularJS for the frontend and Taffy for the backend REST API. I have been wanting a good learning project for Angular, bower, gulpjs, et al so this will be my guinea pig..

This project does have some pretty good bits, it can scan a directory of movies and pull the metadata from themoviedb.org and update your library accordingly. You will need to specify the default location of your movie directory which is set in /config/Coldbox.cfc under custom settings. Currently the indexer does not run automatically, it must be forced by calling http://localhost/wtf/indexMovies. There is a SQL script for the database creation (mySQL format, but may work on others) to setup the database schema. It expects a data source named moviebox to be setup in the web/server administrator. Additionally, it is assumes the movies are stored as X:/movies/moviename or even better X:/movies/moviename (year).

All videos should be available to the web server under the /media directory. Assuming you are using Nginx as the front end proxy it is an easy as creating an alias in your site definition, but it should be easy enough to do in other servers.

If your server does not support SES URLs you must edit the /config/Routes.cfm and add “index.cfm” to the setBaseURL() line. Also, I would definitely recommend using the development branch as it is the most updated (and also contains the SQL script for database generation).

Aside from that, everything should work great. 🙂  The indexer will attempt to download the movie poster and backdrop and will copy the data into the movie folder as well as the data folder under the web root. If the data folder does not exist it will be created for you. If you have a lot of data, expect the initial look up to take a while. Subsequent scans will ignore titles that are already known.

You can check it out here: https://github.com/robertz/moviebox/tree/development

CommandBox is not just for ColdBox


A few weeks ago I think it was Ray who had posted something about CommandBox. I had heard about it before its release, but I totally missed it when it was unveiled at Into the Box.

I have to say it has quite a few features that I really love. Being able to completely setup a ColdBox application scaffold with just one command is great. The package management system is another awesome feature in and of itself; one that other languages have had a leg up on ColdFusion for a very long time.

One feature that might be easily overlooked (I certainly did) is the embedded server. I did play around with it initially then I promptly forgot all about it. Which brings me to today when I wanted to check out a project from github (Taffy, but that is another post), I wasn’t anywhere near my home machine and I really didn’t want to install Railo Express just to test something out. Turns out it wasn’t an issue, I just extracted all the files out to a directory, fired up CommandBox, typed “server start” and fired up a Railo server I could play around with without any additional configuration needed.

Incidentally, you can access the web/server administrator and it will retain your configuration data for that folder so your settings will persist which also is really awesome.

If you haven’t looked into CommandBox because you don’t use ColdBox it might be worth a look. I look forward to seeing where this project goes in the future. You can see the intro video here: http://www.ortussolutions.com/products/commandbox

themoviedb.org API and ColdFusion


Last week while hanging out in the #coldfusion IRC channel I came across a nifty new app called keyStream created by Cory Fail. In a nutshell, it is a ColdFusion application that allows you to stream your media to your devices while you are attached to your home network. This appeals to my tender sensibilities since I tend to watch movies online more than on a TV.

KeyStream is a great application, one thing that was missing for me was being able to hit an API to pull down movie metadata. If you have a lot of media files it is nice to have an automated way of scanning through a whole directory of files in one fell swoop ala XBMC or comparable media applications. With that in mind, I set to see how difficult it would be to interface with tmdb.org in ColdFusion and I found that it actually was not that difficult.

Here is the TMDBService object for ColdBox although it could easily be ported:

First step though is getting an API key. Cruise over to themoviedb.org and sign up for an API key. It is free so even us starving developers can afford it.

Doing a lookup basically requires two steps. First we will pass the movie name in as a string to the findMovie(name, year) function which goes to the APIs /search/movie endpoint. This will return a list of matches back from tmdb.org, if there is an exact match it will be pushed up to the top of the list. Assuming the first position is the movie we want it is time to go to the APIs /movie/{id} endpoint(getMovieData(id) function in the gist if you are following along), passing it the id we got in the first call. This is where we get all the fun stuff such as the poster and backdrop data, overview, release date and IMDB rating. If you would want to see it when viewing your media, this is where you would find it.

To speed the process up a little bit I created the scrape() method that fires these two calls in one swoop. It assumes it will always have an exact match in the movie title, things get a little hairy when there isn’t an exact match but this is still a work in progress.

 

The final step is to call the APIs /configuration endpoint if you are wanting to download the cover and background art. This data tells you where to look on their image server for the images since they are sorted out by size and then it is just a matter of making a cfhttp call out and downloading the images to your local server. Assuming there is enough interest I could provide a more detailed accounting of getting this done. The finished product could look something like this:

Nginx and locking down your WEB-INF folder


I was working on some URL rewriting rules on my server this evening when I was taking a break at work. Just out of curiosity I tried hitting some of the files that are available in the WEB-INF directory and was surprised to find out that I could easily view all my context logs and anything that was not a ColdFusion template. In retrospect, I should not have been surprised but I should have taken steps to prevent that from ever happening.

I have a drop.conf file that gets loaded on every site so blocking directory access on all my sites was just a matter of adding the directive to block access to the directory and restarting nginx.

In hindsight, I should have checked that a long time ago. Hopefully someone will learn from my mistake.

Demo site back up


The past year or so has been extremely busy. Between obligations at work and spending time with my family I really do not have a lot of “extra” time. I fell into the funk I guess every developer gets in to and as a result all my side projects fell off the map.

I have been doing my best to get in to a learning mindset instead of just coasting. To kick things off I started writing my own framework which lead me to wanting to get other things going again. The site is sparse now, but I will be adding things as I go along. The chat demo is working which shows how to setup a quick and easy CF chat as well as demonstrates automatically scrolling a div when adding text to it. A few new features are following as I get them ironed out and as time permits.

http://demos.kisdigital.com

 

 

Nginx connector for Railo/ACF part deux


Edit: This post is now outdated. See this post: https://kisdigital.wordpress.com/2013/03/04/my-final-nginxrailo-connector/

Almost a year ago I posted about an improved connector for nginx proxy to Railo. While I consider myself fortunate moving from Apache over to nginx, it is rather unfortunate that I did not have the time to really test my server setup and understand what was happening under the hood. Then I posted it.

Six months or so ago I drifted away from personal development. My family and work demand much of my attention and I don’t have a lot of “extra” time, but lately I have been trying to spend more time learning new things. As a web developer if your server stack is not solid you are going to be in bad shape so I figured it would be a good time to go back and revisit this.

I thought it would be best to look around and see what folks a lot smarter than me were doing which brought me to KBeezie’s Nginx configuration examples and it was a lot of help. My new server template is based off of his examples, I also went and did some digging in the Railo user group. Special thanks to Serge Droganov in the Railo group  for pointing me the right direction getting the administrator locked down.

This is my default new site template. First we have the default handler that looks to see if the URI exists, if not it looks at the rewrite rules to see if there is a match. If not I want to just load the default document. Here the rewrite rules are enabled SES URLs for the server that will work both with and without the index.cfm in the url (i.e., http://example.com/cool/page or http://example.com/index.cfm/cool/page). My preference leans toward SES URLs because they are much cleaner, but you know what they say about opinions. Standard URLs will work just fine as well.

Second I am hiding the Railo Administrator as it just makes sense. Adding the “internal;” directive to /railo-context/admin/ tells Nginx that you do not want to world to get to it, only rewrites coming from another rewrite rule on the server should be allowed.

Next I am moving my Railo Administrator to http://example.com/secret/location/(server|web).cfm. I was going to try to get a little bit fancier with it, but it works well. Since this is an internal rewrite, we are allowed to pass through to the administrator.

Finally we have the @rewrites named location block that is used by our default handler. If the page being requested does not exist it will try to find a match among these rewrite rules and dispatch the request. These can be built upon later to do some interesting things, but by default it just handles serving the SES urls.

The rest of the directives here describe how to handle static content and what URIs you want dropped automatically such as configuration files, directories, etc which are described in the dropped.conf file. I also included the railo.conf at the bottom of the file which handles passing off ColdFusion files to the app server. It has not changed much from my original post, but I will include it here anyway.

The only changes here are moving the railo-context code out and just keeping it in the server configuration blocks.

I definitely suggest you check out KBeezies. A lot of it is targeted towards PHP, but quite a bit of it is applicable to A/CF and also the Nginx Wiki.

The basics of installing Railo on Linux


With the advent of the automated installer, installing Railo has never been easier. However, the one thing I see quite often are permission errors because the Railo user does not have write access to the folders it needs access to. Please take everything I am about to say here with a grain of salt because this is my opinion of how things should be done. I have installed multiple systems and regardless which distribution you use it should work equally well.

Lets assume we have created a new stock installation of Linux. If I am logged in as root, the very first thing I do is create a new user account and make sure your account is in the sudoers file. Once that is accomplished login with your new user account and make sure you have access to sudo. If everything went well, go ahead and lock down your sshd configuration to block the root user from remote login. In this example my new username will be robert.

I will do a little forward thinking here. I like to host my websites in my home directory so I do not have to go digging through the file system when I want to add a web site. I like to keep things organized so I will create a folder in my home directory mkdir ~/sites. While I am at it, I may as well create a location for the default web site so I will also mkdir ~/sites/localhost.

Now comes the fun stuff. First we will need to install Apache. Assuming you are running a Debian distro this is as simple as running sudo apt-get install apache2. Since I plan on serving sites out of my home folder I am going to go ahead and set Apache to run as my user account. Depending on your distribution you will either find these set in your httpd.conf file or in the case of Deb based systems you can find these variables in /etc/apache2/envvars. Here are the lines I modified on my system in envvars:

export APACHE_RUN_USER=robert
export APACHE_RUN_GROUP=robert

With those changes made I saved the envvars file. While we are at it, lets go ahead and modify the default Apache host in /etc/apache2/sites-available/default:

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 ServerName localhost
 DocumentRoot /home/robert/sites/localhost
 DirectoryIndex index.cfm
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /home/robert/sites/localhost/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log
 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Next I will use an editor and create /home/robert/sites/localhost/index.cfm. This is generally just a file with “It works” in it just to make sure everything is in working order and restart Apache with sudo service apache2 restart just to make sure all the changes I have made are in working order.

Now that has been accomplished I will grab the latest copy of the Railo installer. If I am not already in my home directory, I will cd to get back. Now I am ready to use wget to download the latest file with wget http://www.getrailo.org/down.cfm?item=/railo/remote/download/3.3.1.000/tomcat/linux/railo-3.3.1.000-pl1-linux-x64-installer.run. I generally grab the version that includes its own JRE because I have occasionally had issue with OpenJDK, again, this is my preference, your mileage may vary. Make the file you downloaded executable with chmod +x railo-3.3.1.000-pl1-linux-x64-installer.run and then run the installer. You must be root to run the file so, sudo ./railo-3.3.1.000-pl1-linux-x64-installer.run and you will be in business.

The Railo installer does a pretty good job of detecting your system and determining your default values for you. When Railo asks you what user to run Railo as I will choose my username (robert). Once the installer has finished doing its thing it is time to take a look at our installation and make sure everything is on the up and up. First, lets take a look at our Railo installation directory and make sure I own it by ls -la /opt.  If all went well it should show the railo directory owned by robert:robert. If not, I will make sure I own the directory with sudo chown -R robert:robert /opt/railo.

Once that has been done I generally edit my server.xml and point the default host localhost  docBase to my newly created locahost directory in ~/sites/localhost. This probably isn’t necessary, but I like keeping everything nice and homogeneous.

<Host name="127.0.0.1" appBase="webapps"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
     <Context path="" docBase="/home/robert/sites/localhost" />
</Host>

Once that is completed, the only thing left to do is restart Railo with sudo /opt/railo/railo_ctl restart. If my changes were successful I should now see a WEB-INF folder in /home/robert/sites/localhost and by pointing my browser to the IP address of my server I should see my “It works!” page.

I suppose there is probably as many different configurations out there as there are admins. This configuration works fine for me as I am generally the only person working on my server. In situations where you have multiple users this is definitely not the best scenario and you would probably want a solution based on group permissions.

One thing I do see a lot that just makes me cringe are folks who run the Railo process as the root user. One one hand I could see where this would be beneficial since root has write access anywhere on the server and this does alleviate many issues folks new to Linux face. On the other hand, it can potentially be a huge security risk because if your web server is compromised the attacker holds the key to your kingdom (or server in this case). For this reason I always suggest running Railo on a non-privileged account.

Adding new sites to Railo demystified


One of the questions that comes up quite often on the Railo Google Group is how to add sites to Railo after the initial installation. I can understand the frustration many new users feel because I was in their shoes many moons ago. I will agree that ACF does a fair bit of magic with the JRun connector, but with a little know how you will have your sites up and running in no time at all.

As a rule of thumb, every site you configure with Railo requires you to edit two configuration files no matter what OS you are running on. First you will need to add an entry in Railo’s server.xml to make it aware of your new site and finally add the site to Apache. I am going to assume you are using Jordan’s excellent Railo installer and you have completed the install process and Railo is connected to Apache. If you are on Windows you can refer to this post which covers installing the Apache connector.

First let us add our new context to Railo. Assuming you used the installer with your default options you can find your server.xml file in /opt/railo/tomcat/conf. The default context is already configured for you and we won’t mess with that. Commented out you will see a template for adding additional sites.

<!--
  Add additional VIRTUALHOSTS by copying the following example config:
  REPLACE:
  [ENTER DOMAIN NAME] with a domain, IE: www.mysite.com
  [ENTER SYSTEM PATH] with your web site's base directory. IE: /home/user/public_html/ or C:\websites\www.mysite.com\ etc...
  Don't forget to remove comments! ;)
-->
<!--
  <Host name="[ENTER DOMAIN NAME]" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Context path="" docBase="[ENTER SYSTEM PATH]" />
  </Host>
-->

So using this as a template, we are going to add in a new Railo host

<Host name="www.domain.com" appBase="webapps"
     unpackWARs="true" autoDeploy="true"
     xmlValidation="false" xmlNamespaceAware="false">
     <Context path="" docBase="/var/www/www.domain.com" />
</Host>

As you can see, we are adding a new host for http://www.domain.com where the template had [ENTER DOMAIN HERE]. Next we enter the docBase where [ENTER SYSTEM PATH] is the location of the web root in the file system. In this case I have my webroot in /var/www/www.domain.com. This is important because the WEB-INF for this context will be created in this directory. Also note that this directory must be writable to the user assigned to the Railo service otherwise Railo will not be able to write the WEB-INF folder and all sorts of tomfoolery will happen. After saving the file you will need to restart the Railo service for your changes to take effect. On Linux this is easy as:

sudo /opt/railo/railo_ctl restart

If your changes were successful you should now be the proud new owner of a WEB-INF folder in /var/www/www.domain.com. If everything went smoothly here you are ready to move to the next step, which is adding your host configuration to Apache. If the folder is not there, more than likely there is a permission issue with your Railo user account. To see which user your Railo service is running under go to open up /opt/railo/railo_ctl with your favorite editor or just cat the file and look for the $TOMCAT_OWNER variable and check the permission on your webroot and make sure that user has write access to the folder.

So assuming everything went smoothly getting your site setup in Railo the next step is getting your virtual host configured in Apache. The location of your configuration files depends on your distribution, but assuming you are running Apache 2.2 on a Debian-based distribution you will need to add a new virtual host into /etc/apache2/sites-available.

Here are the contents of the /etc/apache2/sites-available/www.domain.com.conf file:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.domain.com
        DocumentRoot /var/www/www.domain.com
        DirectoryIndex index.cfm
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/www.domain.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        RewriteEngine on
        RewriteRule ^/railo-context/admin/(.*) - [F]
        RewriteRule ^/securelocation/(.*) /railo-context/admin/$1 [PT]

        ErrorLog ${APACHE_LOG_DIR}/www.domain.com-error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/www.domain.com-access.log combined

</VirtualHost>

This is a basic virtual host configuration file. I set the DocumentRoot for this host. It should exactly match the docBase set when adding the Railo host. We also set the Apache directory permissions for the web root directory. For extra credit we are also adding some default rewrite rules to hide the Railo administrator and move it to a more secure location. The rewrite rules require that mod_rewrite is enabled on your server so check your main httpd.conf file to ensure it is enabled otherwise you will receive an error when trying to start Apache and it will fail.

To enable the new site we will need to create a symlink in /etc/apache2/sites-enabled. Forgive me if the parameters are wrong below, I am just doing this from memory.

sudo ln -s /etc/apache2/sites-available/www.domain.com.conf /etc/apache2/sites-enabled/www.domain.com.conf

Now it is time to restart Apache to start serving from your new virtual host. This is generally as simple as sudo service apache2 restart, but this may vary from distribution to distribution.

Once Apache is restarted, you should now be able to point your browser to http://www.domain.com and view your web site. You can reach your admin pages by going to http://www.domain.com/securelocation/web.cfm.

See which tags are supported in CFScript in Railo


I cannot take credit for this little snippet of code, Micha posted this in the Railo newsgroup a while back.

<cfscript>
tags=getTagList().cf;
keys=StructKeyArray(tags);
ArraySort(keys,"textnocase");
loop array="#keys#" index="name"	{
	tag=getTagData("cf",name);
	echo("<b>cf"&name&"</b> - ");
	echo(StructKeyExists(tag,'script'));
	echo('<br>');
}
</cfscript>

You can also easily get this information by checking the Tag Reference in the Railo admin, but it is nice to be able to see  a list of all the tags and whether or not it is supported in cfscript in one place.

Edit:
I have a modified version that just shows the script ready tags you can view.

Railo installer issues on Arch Linux


The Railo installer does a great job across multiple operating systems but it is not completely infallible (although it does come awfully close). The installer will complete, but there are two extra steps you will need to take to get things up and running smoothly on Arch Linux.

First, fire up your favorite editor and open up /opt/railo/tomcat/conf/server.xml and scroll down until you find the HTTP connector block. You will see something along the lines of “@@tomcatport@@” listed where the port should be. Replace this value with whichever port you want Tomcat listening on.

Next we need to move the railo_ctl file from /opt/railo/ to /etc/rc.d/, this is the folder that Arch Linux uses for its daemon services instead of /etc/init.d/ like Debian and RHEL systems use. Once the file is in there, chmod 0755 /etc/rc.d/railo_ctl to set the permissions on the file.

Finally, if you want Railo to startup automatically on boot there is one final modification to make. With your favorite editor open up /etc/rc.conf and add railo_ctl to the DAEMONS line and it will now start when you boot your machine.  You should now be ready to start Railo up, just sudo /etc/rc.d/railo_ctl start and you should be in business.