Redirect domain.com to www.domain.com, universal

July 3rd, 2009

I still get allot of these requests, so I thought I would share this. You can add this rewrite rule to the .htaccess file located at the domains documentroot or in the virtualhost or directory context of the apache configuration to achieve the desired result.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}$1 [QSA,R=301,L]

Uncategorized

Updates to blacknode.net websites.

June 9th, 2009

Over the next few weeks, I plan on making an honest effort towards the design of the blacknode.net website. The website will contain projects and articles related to the current interests of the Blacknode Network.

The initial design focus will be on graphics and branding. A logo is already in the works, but graphic art has never been one of my strengths. I have not decided on the logic portion of the site. I know it will be MySQL driven, but I have not decided on a specific language. I am leaning towards python though, but I am not sure I need a full MVC framework, such as django or plone/tg2.

Any readers interested in contributing to the early development stages, drop me a line. The site will publish various articles submitted by users. So feel free to submit papers as well.

~JR

BNN

City Public Service server fail

May 21st, 2009

I hate the utility company in san antonio. Not only can they not read a fucking meter correctly,  they cannot administer a webserver to boot. I sent this email tonight detailing an issue their server has had for over a year:

From: Jared Rodriguez <jrod@blacknode.net>
To: feedback@cpsenergy.com
Subject: Concerning cpsenergy.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Please have your technical staff configure your server to handle HTTP
host request for cpsenergy.com properly. At present, your server is
responding to requests inappropriately:

~ $ host cpsenergy.com
cpsenergy.com has address 208.188.159.143
cpsenergy.com mail is handled by 10 dmsmail.cpsenergy.com.
cpsenergy.com mail is handled by 5 mail.cpsenergy.com.

~ $ nc 208.188.159.143 80
HEAD / HTTP/1.1
Host: cpsenergy.com

HTTP/1.1 400 Bad Request
Content-Length: 39
Content-Type: text/html
Date: Thu, 21 May 2009 05:11:10 GMT
Connection: close

~ $ nc 208.188.159.143 80
HEAD / HTTP/1.1
Host: www.cpsenergy.com

HTTP/1.1 200 OK
Connection: close
Date: Thu, 21 May 2009 05:11:30 GMT
Server: Microsoft-IIS/6.0
Content-Length: 23019
Content-Type: text/html
Set-Cookie: ASPSESSIONIDAAQCDRCA=GFEKMIDCODDEABMGDIMHBIFI; path=/
Cache-control: private

I know IIS is crap, but you still should be able to configure it to at
least meet rfc standards. There is nothing wrong with the following request:

HEAD / HTTP/1.1
Host: cpsenergy.com

So the 400 error is just plain wrong according to rfc2616:10.4.1, which
states:

"The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without modifications."

The server not handling client "Host:" header strings other than
www.cpsenergy.com is not a breach in HTTP header syntax, its a problem
with your implementation. Also, its really annoying to type
cpsenergy.com and get a 400 when any rational server would spit out a
301/2 to http(s)://www.cpsenergy.com, or a 200 and load some other
content. Its just plain lazy in my opinion.

Jared

Uncategorized

Welcome

May 7th, 2009

Redirect index.php to root of current directory

May 1st, 2009

An SEO conscious customer was having duplicate content issues for:

http://domain.com/something/
and
http://domain.com/something/index.php

Simply rewriting index.php to / will not be effective as httpd makes an internal redirect to the DirectoryIndex, causing a redirect loop.

In order to distinguish between the internal redirect and a client request, the %{THE_REQUEST} server variable is used.

When placed in the in the Directory context in the httpd.conf or in the .htaccess file located in the document root or desired origin directory, the following rule will achieve the desired results:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ (.*)/index.php\ HTTP/
RewriteRule .*index.php$ http://%{HTTP_HOST}%1/ [L]

Note, this should be placed before any query_string rewriting you are doing for things like clean urls.

This will work recursively from its origin, so:

http://domain.com/something/index.php
and
http://domain.com/something/else/index.php

will be rewritten to:

http://domain.com/something/
and
http://domain.com/something/else/

Apache, SEO, System Administration , , , ,

Stop the plesk adminstrator from recieving dr.web license failures

March 8th, 2009

… And other things that might annoy him/her

There was a request that went around for months from a plesk administrator griping about the various messages that appear in his mailbox, such as the dr.web license notification. By default, messages to the root and postmaster accounts are sent to the plesk administrator. This is accomplished via qmail aliases.

# cd /var/qmail/alias/
# ls -al
total 28
drwxr-sr-x 2 alias qmail 4096 Mar 9 01:59 .
drwxr-xr-x 11 root qmail 4096 Sep 29 21:14 ..
-rw-r–r– 1 root qmail 26 Dec 10 2007 .qmail-mailer-daemon
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-postmaster
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-root

Typically these look something link this:
# cat .qmail-postmaster
&plesk_admin_address@foo.bar.com

To keep the customer happy, I made a slight amendment to the alias:

# cat .qmail-postmaster
|cat >/dev/null
# cat .qmail-root
|cat >/dev/null

Removing the aliases will cause all kinds of noise in the logs and actually break the server’s already fragile rfc compliance (rfc2821:4.5.1) . This allows the messages to be ‘handled’ silently. Since most plesk ‘administrators’ don’t care to know how many failed ssh attempts there were in a month, or how much disk space they are using, it is usually a working solution when you can’t get dr.web to stfu.

Plesk, Programming, System Administration, pets

WoW is dead to me

January 22nd, 2009

I have been lured by friends, family, and co-workers into subscribing to the monstrosity known as WoW since the first servers went online. I have attempted to get into the game several times, unsuccessfully. Each time I try, I role a character to level 30 or so and loose interest.

After noticing that familiar entry on my bank statement this afternoon, I decided to lay WoW to rest once and for all (again.. for the fifth time). I still play Eve Online and I prefer the black skies.

Uncategorized

Learning python

December 11th, 2008

I have started to rewrite some of my existing code in python in an earnest effort to master the language (I have been putting it off for a long while now). Anyway, I was working on a parser for a # commented file, this is how I stripped the comments from each line in C:


while(fgets(line, sizeof(line)-1, fp)) {
  char *hash; //ptr to hash mark denoting a comment
  if(line[0] == '#' || line[0] == '\n')
    continue;
  if((hash = strchr(line,'#')) != NULL)
  line[hash - line] = '\0'; //line + hash = memory location of hash
  printf("%s", line);
}

Now that I am beginning to get a handle on python, I am really starting to appreciate its elegance. This line of code accomplishes the same task:

line.strip()[:line.find("#")].strip()

I have not compared the performance of the above line to my c code , but I would assume using all the nested objects would incur a performance hit. I may test this later, but I am pretty sure my c code would be much faster.

Programming, Python

tomcat + mod_jk + rhel5

November 13th, 2008

v0.5

Because I’m tired of my peers thinking that the process is difficult, I decided to write a quick guide detailing the process of installing tomcat on rhel5 and configuring mod_jk with apache.

RHEL5 provides tomcat5 via RHN, unless you have access to another secure and maintained repository that provides tomcat, I recommend using RedHat’s package.

To install tomcat:

yum install tomcat5
/etc/init.d/tomcat5 start
chkconfig --levels 345 tomcat5 on

This will install and start the tomcat5 web server on port 8080. The redhat tomcat rpms are nearly identical in implementation to the jpackage rpms. $CATALINA_HOME is still /usr/share/tomcat5. That directory contains symlinks to other places.  So /usr/share/tomcat5/conf is a link to /etc/tomcat5.

To test the installation, I use the tomcats sample webapp which can be acquired and deployed like so:

wget http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war
mv sample.war /usr/share/tomcat5/webapps

The cool thing about .war files is the way tomcat interacts with them. Simply moving the sample.war to $CATALINA_HOME/wabapps will deploy the web base application. Tomcat will automatically extract, or explode sample.war to $CATALINA_HOME/wabapps/sample.

You can access the newly deployed application via the tomcat web server.

http://foo.bar:8080/sample/

If you have installed the tomcat5-webapps package, you will notice some other directories populating the webapps directory. There is a special webapp directory called ROOT which represents the root of the tomcat server, which can always be accessed by going to the root of the server.

http://foo.bar:8080/

Unless you plan on running tomcat on port 80, you are going to want apache to hand off, or connect, requests to the tomcat server. This is where mod_jk comes into the picture. mod_jk is an apache module known as a connector.

First, download the correct binary for your architecture and install it:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/mod_jk-1.2.23-apache-2.2.x-linux-i686.so

***
For x86_64 change to:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/mod_jk-1.2.23-apache-2.2.x-linux-x86_64.so
***

chmod +x mod_jk-1.2.23-apache-2.2.x-linux-i686.so
cp -av mod_jk-1.2.23-apache-2.2.x-linux-i686.so /etc/httpd/modules/mod_jk.so

vim /etc/httpd/conf.d/mod_jk.conf

LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties
JkShmFile /var/log/httpd/mod_jk.shm
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info


vim /etc/httpd/conf/workers.properties

workers.tomcat_home=/usr/share/tomcat5

workers.java_home=/usr/lib/jvm/java

worker.list=jkworker

worker.jkworker.port=8009
worker.jkworker.host=localhost
worker.jkworker.type=ajp13

Now restart apache:

/etc/init.d/httpd configtest
/etc/init.d/httpd restart

At this point you have everything you need to run jsp pages and servlets with tomcat, while still hanging on to familiar httpd virtual hosting and configuration. If you have not read the tomcat documentation on connectors, then you should at this point.

In order to use mod_jk to connect to a tomcat webapp, we need to mount it via the apache configuration. The JkMount directive takes care of this for us. To demonstrate this run the following:

mkdir /usr/share/tomcat5/webapps/test/

vim /usr/share/tomcat5/webapps/test/index.jsp

Hello, I am a jsp script!

<%
// get client locale
java.util.Locale locale = request.getLocale();

// get Dateformat for client’s locale
java.text.DateFormat dateFormat =
java.text.DateFormat.getDateTimeInstance(
java.text.DateFormat.LONG,
java.text.DateFormat.LONG, locale);

%>

The time is:
<%=dateFormat.format( new java.util.Date() ) %>

Now add the following somewhere in the apache configuration:

JkMount /test/* jkworker

JkMount works similar to the apache alias directive. It can be used in the main configuration or virtualhost context. For testing purposes, you can append the mount line to your mod_jk.conf file.

Restart apache and hit the following:

http://localhost/test/

Tomcat ships with a web based administration webapp and also a manager webapp that can be used to deploy other webapps. To use these features, you need to install them from rhn if they have not already been installaed:

yum install tomcat5-admin-webapps

In order to access these webapps, you need to first authenticate. In tomcat, you can define users and user roles. Users and roles are defined in $CATALINA_HOME/conf/tomcat-users.xml (/etc/tomat5/tomcat-users.xml). The admin webapps require authenticated users to have certain roles before they are granted access. For the admin webapp, a user who has the role ‘admin’ is granted access. For the manager webapp, the user will need the ‘manager’ role.

By default, the admin and manager roles are not created so you must define them and assign a user to them. I typically create an ‘admin’ user and give that user both the admin and manager roles. Open up /etc/tomat5/tomcat-users.xml and edit it to look like this:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”admin”/>
<role rolename=”tomcat”/>
<role rolename=”manager”/>
<role rolename=”role1″/>
<user username=”admin” password=”SuperSecretPassword” roles=”admin,tomcat,manager”/>
<user username=”tomcat” password=”tomcat” roles=”tomcat”/>
<user username=”both” password=”tomcat” roles=”tomcat,role1″/>
<user username=”role1″ password=”tomcat” roles=”role1″/>
</tomcat-users>

Now you can access both the manager and the admin panel with the admin user. Try this out:

httpd://yourdomain.net:8080/admin
httpd://yourdomain.net:8080/manager

If you don’t want to type the port, you can mount the apps with JkMount /admin/* jkworker or JkMount /manager/* jkworker.

At present, this guide is far from complete. However, I think something like this would have helped me the first time I had to install tomcat on a shared server. Please feel free to post comments and flames.

jrod@blacknode.net

Apache, Plesk, System Administration, Tomcat

Eve Quantum Rise, at least im not alone

November 11th, 2008


The eve online trinity cluster is being updated with the new patch. Along with some game mechanics changes, such as the speed nerf, which I am very pleased with, some very cool things are being done to improve the io performance of the clusters stackless python implementation. This translates to each solar system blade being able to support more concurrent users, which will help reduce lag in jitta and when local explodes due to large scale fleet(blob) warfare.

Anyway, I am waiting for the servers to come back up. With the speed nerf, I may even get back in my arazu. Check out the vid:

http://www.eve-online.com/news/downtimenews.asp

Uncategorized