Our initial reaction was that it was simple enough; BusinessObjects Enterprise supposedly logs the IP Address of every user that accesses InfoView right? Wrong! As it turns out, BusinessObjects Enterprise logs the IP Address of the web server that is sending the request to access InfoView.
So now it was time to move on to plan B. Every web server should maintain a log of requests made to it, including the IP Address of the request. So there we go, simple right? Wrong! Apache Tomcat, that wonderful piece of software we have all grown so fond of, has its log disabled by default. And to make matters worse, enabling its log and to specifically log IP Addresses is a whole other story by itself.
Now I have to admit that we are not really aware of Apache Tomcat's configurations so in a sense, we are not really proficient in configuring it. But after several hours of Googling the issue and coming out empty, we decided to take a different route.
Enter Java to the rescue. From our point of view, InfoView's log in page is nothing more than a very simple JSP page. So keeping that in mind, why not harness the power of Java, grab the IP Address of the incoming request from the request object, and dump it to a very simple text file? As you probably have guessed, that is exactly what we did.
First, let's see some code then I'll show you which file to add that code to. Keep in mind that we are running on a Java installation of BusinessObjects Enterprise on a Windows 2003 Server machine, which means the underlying web server is Apache Tomcat. If your running the .NET installation of BusinessObjects Enterprise, the concept is exactly the same. You just have to make some code modifications appropriate for .NET:
<%
try {
// Create Engine.
//
// The Engine is the underlying mechanism that does the actual writing on
// the file system. It is instructed to append data to the given file to
// avoid overwriting the file every time we open it for writing.
FileWriter Engine = new FileWriter( "C:\\IpList.txt" , true );
// Create Buffered Writer.
//
// Write text to a character output stream, buffering characters so as to
// provide for the efficient writing of single characters.
BufferedWriter BWriter = new BufferedWriter( Engine );
// Create Internet Address Object.
//
// This is initially empty because we are still going to get it from the
// request object.
InetAddress RemoteAddress = null;
// HTTP Header Available.
//
// Proves useful if the client is behind a proxy as it will contain the IP
// Address of the client and not the proxy.
if( request.getHeader( "x-forwarded-for" ) != null ) {
RemoteAddress = InetAddress.getByName(
request.getHeader( "x-forwarded-for" )
);
}
else {
RemoteAddress = InetAddress.getByName( request.getRemoteAddr( ) );
}
// Write To Buffer.
BWriter.write( RemoteAddress.toString( ) );
BWriter.newLine( );
// Close File.
//
// Very important as it also implicilty writes the data from the buffer to
// the file on the file system.
BWriter.close( );
}
catch( Exception Ex ) {
// Destroy Exception Object.
//
// There is really nothing we can do if an exception occurs except free
// the memory allocated by the exception object created.
Ex = null;
}
%>
As you can see, the code is actually very very simple. I mean a person taking a beginners course in Java will quite easily understand it. On Line 9, I am creating a new file writing engine, which in return is passed to the buffered writer created on Line 15. Lines 27 - 34 are the most interesting because that is where all the work is done.
I created a condition in case a connecting user is behind a proxy. If they are, the request object will most likely contain they IP Address of the proxy and not the user. Regardless of whether or not there is a proxy, the idea is still the same; get the IP Address from the request object.
After that, it is as simple as writing it to a flat file, which is exactly what is happening on Lines 37 - 44.
So there you have it, simple and to the point. So where to dump this code? We chose to prepend it to InfoView's log in JSP page. You can find it at the following location:
\[BO-INSTALL-DIRECTORY]\Tomcat\webapps\businessobjects\enterprise115
\desktoplaunch\InfoView\logon\logon.jsp
Make sure you import the following two packages:
- java.io.*
- java.net.*
No comments:
Post a Comment
Feel free to write any comments or ideas!