I like to provide developer insight on things that especially concern this new upcoming contactless technology called Near Field Communication (NFC).

Tuesday, January 30, 2007

JSR 257 RI SDK FAQ

This article, with an ALLCAPS title, answers Frequently Asked Questions about the the Contactless Communication API (Java Specification Request no. 257) Reference Implementation Software Development Kit.

Nokia JSR 257 RI SDK Emulator Learn about what it is, what you can and can't do with it, and how to work with it.

What is the JSR 257 RI SDK?

A software development kit released by Nokia, only eight days after the Final Release of the Contactless Communication API, that enables software developers to write their own NFC applications in Java, without the need for an extra, proprietary SDK from Nokia.

When more NFC phones, built according to these specifications, will be produced, your NFC MIDlets will also run on these phones.

The SDK comes with a big bunch of documentation. Some very intriguing features such as Bluetooth configuration and NFC Peer communication are listed in the docs, but appear to be missing from the implementation.
I figure that Nokia already has the actual implementation for these things, but that they are still in beta testing phase, or awaiting the NFC Forum's official release.

What can I do with it?

You can write NFC MIDlets that will run on both the physical 6131 NFC phone (as soon as you get your hands on that) and on the emulator supplied with the SDK.
You can do everything that's written in the NFC Forum specs about NFC tags. You can write Plain text records, URI records, and Smart Poster records to them in order to make your environment fully touchable.

What can I not do with it?

You can't, yet, develop applications for communication between two NFC peers.
Which makes sense, since the specs haven't yet been released by the NFC Forum.

How do I work with it?

If you have developed applications with a Nokia SDK before, you'll probably have all the required software installed. If you're new to development on Nokia platforms, please take a look at the Installation Instructions document that comes with the package.

The SDK comes with precompiled sample applications that can be run in an emulator. If you want to run them on your 6131 NFC, you'll have to recompile them for physical use.

You can ofcourse edit the sample applications' text files manually and then invoke ant at build time, but I'd suggest you first import the projects into NetBeans before you start developing, which will save you a lot of time.

Importing and debugging Nokia's NFC sample applications with NetBeans 5.5

NetBeans is an Open Source Java IDE that comes with many nifty features. It does not only feature code completion and a debug mode, but also allows you to design MIDlets instead of coding the screens by hand. Importing Nokia's sample applications into NetBeans saves time, prevents typos, and increases developer convenience.

In short

  • This article covers how to import one of Nokia's sample applications, Contactless, into NetBeans IDE 5.5.

  • Using NetBeans IDE saves time with features such as code completion, syntax checking and debugging.

About Nokia's Contactless sample application

Contactless is part of Nokia's JSR 257 RI SDK, the first SDK that allows Java developers to write their very own NFC MIDlets. For now, the Nokia 6131 NFC is the only phone to support JSR 257. The JSR 257 API, currently, can only be used to operate on NFC tags, and not yet on NFC peers.

NetBeans bundled with Mobility Pack

The mobility utilities don't come standard with NetBeans 5.5, but with a special add-on called Mobility Pack. I'll assume you've downloaded and installed first a Java JDK, and then both NetBeans and Mobility Pack.

Why use NetBeans?

First off, since I've been using it for a few years now, and I find it a very adequate IDE. The JSR 257 RI SDK comes with only a buildfile and some sources, so editing the sources had to be done using a text editor.

Text editors don't know much about code and/or code completion, so many times I have to bounce back and forth between my editor and the API documentation to get the correct names.

And how about context compiling? If you type something into NetBeans, it will do a quick 'background check' on whether your syntax is correct, and if you've imported what you are using on the spot.
If not, you'll get a red line under the line where NetBeans thinks you've erred.

And another thing I frankly haven't yet used with this SDK: The MIDP designer mode. Using NetBeans + Mobility pack, you can create your MIDlet's screens in a visual design mode.

Using NetBeans will save me time not having to switch between editor and API documentation, will prevent me from getting compiler syntax errors, and has many more features that make my life easier. I can even debug my applications with it!

Adding the JSR 257 RI SDK emulator

Here, we'll cover how to use the emulator shipped with Nokia's JSR 257 RI SDK into NetBeans 5.5. These instructions are not specifically for the RI SDK, but can be used with any emulator package that conforms to the standard specifications. This means that you can import virtually any J2ME emulator into NetBeans using these instructions.

Select Tools -> Java Platform Manager.

NetBeans 5.5 Java Platform Manager dialog

Click Add Platform, and select Java Micro Edition Platform Emulator.

NetBeans 5.5 Add Java Platform dialog

Frankly, the platforms listed showed up automagically! Appearantly, NetBeans had already found them in my c:\Nokia\Devices directory.



As you can see, I have some more emulators in my Devices directory. We'll only need the JSR 257 emulator. Click Next, and you'll get a page about the Platform Details. If all looks OK to you, and you agree with the Platform Name, click Finish.

Importing the project

In this example, we'll import the project called Contactless into our NetBeans IDE.

Select File -> New Project -> Mobile -> Import Wireless Toolkit Project.

NetBeans New Project dialog
Click Next, and in the next screen, specify a different WTK location.

NetBeans Specify WTK Project dialog
Here, you must locate your Nokia JSR 257 RI SDK's sample applications.
On my computer, they're located at C:\Nokia\Devices\JSR_257_RI_1_0\samples\contactless.

NetBeans 5.5 Name and Location dialog
We'll keep the name ImportedProject-Contactless.
Please note that NetBeans will not copy the source files from the Contactless project into your new project folder. When you change your source files, the original files will be affected, so that you can keep compiling your project in Wireless Toolkit, if you prefer to.

Next is Default Platform Selection. Don't use J2ME Wireless Toolkit 2.2 here, but use the platform we've just added.

NetBeans 5.5 Default Platform Selection dialog
Now click Finish. Congratulations! You have now successfully imported the Contactless project into NetBeans.

The project should look like this:

NetBeans 5.5 ImportedProject-Contactless
Because the emulator conforms to the standard conventions, you now have the Debug option for free! Just select Run -> Debug (F5) to start debugging in the supplied emulator.

The emulator doesn't look as if it's the prettiest S40 emulator around, but it works OK:

Nokia NFC emulator
When the MIDlet enables its NFC functions, the emulator will show the Contactless Simulator dialog that you can use to place various tags inside and out of the RF field.

Nokia NFC Contactless Simulator
Conclusion

This concludes on how to import a Nokia sample project into NetBeans. Using NetBeans instead of plain command-line Ant and a text editor might be an investment, but saves time in the future, and contributes greatly to developer productivity.

Thursday, January 25, 2007

Nokia 6131 NFC showed off at CES

Nokia showed off their 6131 NFC at the CES, January 8 - 11, Las Vegas. What's featured:

  • Smart Poster: The Hotel and Elvis posters house RFID tags that contain NDEF records with phone number information. By touching the tag, the user is prompted with a request to dial the number stored on the tag.
  • Business card exchange: Jason Fitzgerald's Exhibitor pass contains an RFID tag with his business card on it. By touching the tag, the user can give permission to store the business card in the phone's memory.
  • Smart Photograph: Basically the same as the Smart Poster concept, but this time the RFID tag is contained in a photo frame.
  • NFC Printing: Touching the printer causes the photo printer to establish a Bluetooth connection with the phone. (This is called pairing) The phone then sends the user's desired picture over to the printer.
  • Smart Photo Frame: An interactive, Bluetooth-enabled photo frame can be touched with the 6131 NFC in order to change the picture it currently holds. After touch, the user selects his desired picture which is then transferred over to the photo frame. The frame then immediately displays the picture.
  • Visa/Master Card payment: Transactions can be made by touching an NFC reader with the Nokia. Optionally, a passcode can be set for transactions that exceed a specified amount, so that the user has to enter their passcode before a transaction can be made.

Tuesday, January 23, 2007

Nokia releases new 6131 NFC phone

January 8, 2007: Nokia has brought out the details about their latest technology packed in an already familiar clamshell phone. The Nokia 6131 NFC is the first phone to enable Java developers to write MIDlets that can access functions according to the NFC Forum's specifications.

From the article:


"With Nokia 6131 NFC phone you can have your credit card, travel card and loyalty card in your phone and use it as a multi-purpose smart card. Use the Nokia 6131 NFC to pay for your purchases with speed and ease or access any mobile services, e.g. weather forecast and the latest news just by touching a tag."

NFC-aware MIDlets

In conjunction with the JSR 257 Reference Implementation, a developer is able to write NFC-aware MIDlets that need only be written once for the Java platform. With the Nokia 3220, developing NFC MIDlets had to be facilitated by the Nokia SDK for Payment and Ticketing. Hence, these MIDlets were only usable on a Nokia 3220 that had the special NFC Shell for Payment and Ticketing on them.

In theory, a MIDlet can be written that will communicate flawlessly with future NFC devices - even if these come from different brands or manufacturers. Because the JSR 257 implementation on this phone adheres to the official NFC Forum specifications, any device that has a similar implementation will be compatible with this phone, and vice versa.

Features

The Nokia 6131 NFC has some nifty features that will make the developer's life much easier. Whereas the Nokia 3220 had to be fed MIDlets using either a slow serial data cable, or an even slower GPRS connection, the 6131 NFC has Bluetooth available which allows MIDlets to be translated to the phone without any wires in-between.

The maximum JAR size is 1MB, which means that developers will have more room for shiny images and the like. This is a major improvement on the Nokia 3220's JAR size limit of a mere 128KiB. But you might even eliminate the need to add large PNG images to your JAR file completely, because the 6131 NFC also supports JSR-226, the Scalable 2D Vector Graphics API.

SVG format

This means that you can add images to your MIDlet in the SVG format. These images do not consist of mere pixels, but of vectors that will be automatically scaled to fit your screen. Hence, you won't have to worry about the screen size of the intended device. Which is a good thing, since some VGA phones with a whopping 640x480 resolution can already do MIDlets!

Web services

And if you're planning to do some serious service interaction with the 6131 NFC, you have the Web Services API (JSR-172) at your disposal. This means that you can simply use an existing Web Services Definition File (WSDL) to automatically generate a stub MIDlet! All you have to do is add images, change strings, customize things to your liking. The functional part as a whole has been dynamically generated from the WSDL file you supplied to the wscompile tool.

Your WSDL file has to be WS-I compliant, though. This means that it does not include some of the more complex types such as DateTime and the like.

Availability

The Nokia 6131 NFC is expected to be shipped in the first quarter of 2007.

Source:

Subscribe to Daniel's Atom Feed

So you read all the way down, huh? Did you find anything around here interesting? Then you might be interested in subscribing to my Atom Feed. You will then be automatically notified as soon as something new pops up on this blog.

For Internet Explorer 7 users:
  • Simply point your browser to http://www.nfc-development.org/feeds/posts/default

  • You will get a user-friendly page that says: "You are viewing a feed that contains frequently updated content"

  • Click on Subscribe to this feed, and click Subscribe on the dialog box that pops up.

  • The browser will now say: "You've successfully subscribed to this feed!"

  • Internet Explorer will now automatically check for new posts on this blog. To view them, go to Favorites Center (Alt-C or the star under the Back button) and click Feeds.
For Firefox 2.0 users:
  • Simply point your browser to http://www.nfc-development.org/feeds/posts/default
  • You will get a user-friendly page that says: "Subscribe to this feed using ..."

  • Leave the combo box on Live Bookmarks, click on Subscribe Now, and click OK on the dialog box that pops up.

  • Firefox will now dynamically add new posts from this blog to your Bookmarks. Click on Bookmarks, Bookmarks Toolbar Folder, and there's Daniel's Weblog!

Monday, January 22, 2007

Nokia releases JSR 257 implementation

Only eight days after the Final Release of the Contactless Communication API, (JSR 257) Nokia has released their Reference Implementation SDK.


The indicator 'Reference Implementation' means that it "supports the mandatory features of the JSR-257 specification". The package is based on the Nokia Prototype SDK 3.0, and comes with a Series 40 emulator that is able to simulate various NFC tags.

NFC Forum compliant

The Java API specs look promising. Since the Nokia 6131 NFC supports the JSR 257 out-of-the-box, you could use this SDK with even your own 6131 phone to create NFC MIDlets! And even better, JSR 257 is compliant with the specs from the NFC Forum - which means your applications will be able to interoperate with every other NFC device that was made after the specs were released.

With this implementation, you also won't be needing the special NFC Shell or the SDK for Payment and Ticketing anymore, as was with the Nokia 3220. Any homegrown or business developer could buy him or herself a 6131 NFC, download this SDK, and start developing. This will increase even more when the Sun Wireless Toolkit will incorporate this into their standard package.

Classes at a glance

When we take a look at the available classes in this API, a few classes are of note:

  • ISO14443Connection: "defines access to the ISO 14443-4 compliant contactless smart card."
  • TargetListener: "provides a mechanism for the application to be notified, when contactless targets are discovered by the device hardware."
  • NDEFTagConnection: "defines the basic functionality for exchanging NFC Forum formatted data with RFID tags and contactless smart cards."

Sample applications

The JSR-257 RI comes with three sample applications:

  • Contactless: Demonstrates reading and writing to NFC tags
  • Barcode: An application that demonstrates barcode decoding
  • NDEF: Sample application that can create different types of NDEF records and messages

Download

Get the stuff from here:

You'll need to have a Forum Nokia account before you can download this ZIP file.

Some background information:

Friday, January 19, 2007

How to Download and Install the IBM JCOP Tools

This article is about how to install the IBM JCOP Tools to your computer, and how to activate your installation.

Learn about how to contact IBM for an activation code that will allow you to start creating tiny JCOP Java applets for your IBM JCOP card.

Installing Eclipse

First off, you'll need the Eclipse SDK from the Eclipse website. Click on the big orange Download Eclipse button, and pick the most recent Eclipse SDK. (Current version as of yet is 3.2.1)

Installing IBM JCOP Tools

You can download the JCOP Tools from this direct download link: http://download.boulder.ibm.com/ibmdl/pub/software/dw/jcop/tools.zip

Simply extract the ZIP file into your Eclipse plugins/ directory.

Creating a new Java Card project

After you've started Eclipse, you'll have a new option in the File -> New -> Project ... menu. Select Java Card -> Java Card Project. If you have not activated your copy of the JCOP Tools yet, then you can do so by either pointing your card reader to a JCOP Engineering Sample card, validating a previous 2.2 installation of the JCOP Tools, or by entering an activation code.

Obtaining an activation code from IBM

To obtain an activation code from IBM, you'll have to send an email to the official address for JCOP Tools, scard@de.ibm.com. Here is an excerpt from an instructional email from IBM:

Quote:
C: To use the tools you need an activation code - please send the

following

information:

1. Your company name

2. The full postal address - the serial number will be sent via

International Courier to meet US Export control compliance.

3. Your contact telephone number

4. The serial number of your JCOP tools install (see section D

below)

5. Your planned usage/reason for needing the JCOP tools

6. If a student, a copy (fax or digital photo) of your student ID



D: For the serial number (item 3 above):

1. Ensure you have downloaded and installed the JCOP Tools

2. Start the Eclipse IDE

3. From the menu bar click on File > New > Project

4. In the New Project Dialog expand the Java Card folder

5. Select Java Card Project

6. Click Next

7. You should now see the JCOP Licensing Wizard

8. Click Next

9. Select Verify an Activation Code

10. Click Next

11. The Serial Number should appear on the next page, above the

Activation Code entry fields.

12. Once you have that number click on Cancel then Abort (Note:

the

Java Card project choice will be disabled until the next time you

restart

Eclipse)

Nokia Secure Chip SDK FAQ

This FAQ is intended to guide you on any questions concerning Nokia's Secure Chip SDK.

Read about how to send APDUs to the Nokia 3220's built-in smart card, and how to create a SecureChipConnection in your Java MIDlet.

What is the Nokia Secure Chip SDK?

This SDK enables you to write MIDlets that make use of the Nokia 3220's builtin smart card. You can send APDUs to both the internal and external smart cards, switch between various Secure Chip communication modes, (SC_ON, SC_OFF, SC_ONLY) and enable/disable the security PIN code.

Where can I get the Nokia Secure Chip SDK?

As with the NFC Shell for Payment and Ticketing and the SDK for Payment and Ticketing, you cannot buy this SDK in a store or order it from the website.
You will have to contact a Nokia representative by phone or e-mail.

Can I receive an event as soon as an RFID/NFC device enters the RF field?

When you have a MIDlet running in the foreground, you will be able to receive an event whenever an RFID/NFC device enters the 3220's RF field. This is even true for smart card readers.
Outside of the MIDlet, you will only be able to respond to Mifare tags. On exit, your MIDlet can instruct the phone to register a designated Mifare tag type with your MIDlet. Whenever you touch a tag with the corresponding data, your MIDlet will be launched.

Can I use the Secure Chip SDK to upload JCOP applets to the internal secure chip?

No, but you can use the freely downloadable Eclipse SDK in conjunction with the IBM JCOP Tools. The JCOP Tools come as a plugin for Eclipse.
Before you can use them, you'll need to activate your copy. To do this, you can either use a JCOP Development card, a prior 2.2 installation of the JCOP Tools, (current version is 3.1) or an activation code which can be freely obtained from an IBM representative.

Small note: I've tried to obtain an activation code myself. I have personally attempted to contact IBM US, IBM Netherlands and even IBM Germany! None of them knew anything about the JCOP Tools.
The email address that was provided,
scard@de.ibm.com
, did not respond to any correspondention. I was just lucky to have a 2.2 installation lying around, that I could use to activate my copy of the JCOP tools plugin.

Update on that small note: IBM finally replied after a few weeks. They provided me with some instructions on how to obtain an activation code.

How do I communicate with the Secure Chip?

The exact same way you would communicate using a regular smart card reader: Using APDUs. APDUs can either be sent to an external smart card, or to the internal chip. The last happens only in the special SC_INTERNAL mode, which can only be active when a MIDlet is running.

Nokia 3220 + NFC Shell for Payment and Ticketing FAQ

This FAQ is to guide you on any questions concerning the Nokia 3220 or the 3220's NFC Shell for Payment and Ticketing.

Learn about this special Nokia XPress-On cover, and how it turns your standard Nokia 3220 phone into an NFC device.

What is the NFC Shell for Payment and Ticketing?

The NFC Shell for PT turns a regular Nokia 3220 into a full-blown NFC device.
Out of the box, it comes with a MIDlet called ServiceDiscovery with which you can read and write the included Mifare stickers, or any other kind of RFID tag that will allow you to write to it.
If you want to write your own Java MIDlets to access the shell's functions, you need Nokia's SDK for Payment and Ticketing.

Where can I get the NFC Shell for Payment and Ticketing?

You'll have to contact a representative of Nokia. You can't buy them in a store, or order them from the website. Pricing information depends on the number of licenses you expect to be using.

Can I use the 3220's NFC functions when the phone is off?

No, you can't. NFC Devices are active devices that need battery power to back them.
Also, you'll need to be logged in to your SIM card (i.e. you have successfully entered your PIN) before the NFC Shell can be operated.

You said that the Nokia 3220 also behaves like a JCOP card.

Indeed it does. Not only can the Nokia behave like an NFC device, it also has a built-in smart card that can be either addressed from the outside or from an inside MIDlet, using the Secure Chip SDK.
I've used Eclipse in conjunction with the IBM JCOP Tools to address this card. Using a standard smart card reader, tiny JCOP Java applets can be uploaded to the phone.
Such an applet can be used to for instance, securely retrieve an amount stored on the phone.

Can I use a serial COM port connection to interface with the 3220?

Unfortunately, the 3220 does not support a serial CommConnection.

How do I install the Shell for Payment and Ticketing?

The NFC shell comes with a tiny connector that connects the NFC part of the shell with the phone. Because a standard 3220 is not equipped with NFC, it holds a stub at the place where the connector is supposed to be.

Be careful that once you insert the connector, it's not likely you're going to get it out again in one piece. The tiny plastic and copper connector is not very strong, you might even crush it to pieces when trying to remove it.

Next, power up the phone and enter your PIN. The phone will begin downloading the ServiceDiscovery MIDlet, and this should take several minutes. When finished, you can access your brand new MIDlet at Applications -> Collection -> Select Application.
You'll also get the Cover Browser, a MIDlet that enables you to check for any installable applications on the NFC Shell.

After use, the ServiceDiscovery MIDlet registers certain types so that it will be launched upon the touch of any RFID tag or device.

Nokia SDK for Payment and Ticketing FAQ

This FAQ is to guide you on any questions concerning the Nokia SDK for Payment and Ticketing.

Learn about where to get the Nokia SDK for Payment and Ticketing, whether it will enable you to communicate over NFC, and how to use your Nokia 3220 as a smart card reader.

What is the SDK for Payment and Ticketing?

This SDK enables you to write Java MIDlets for the Nokia 3220 that make use of the NFC Shell for Payment and Ticketing.
It comes with special precompiled Java classes that enable you to use RFID, NFC, Local Interactions, NTIP, and Nokia Phone UI functions.

Where can I get the SDK for Payment and Ticketing?

You'll have to contact a representative of Nokia. You can't buy them in a store, or order them from the website. Pricing information depends on the number of licenses you expect to be using.

Can I use the SDK to make two Nokia 3220's communicate over NFC?

Yes, you can. Using the NTIP protocol, you can even send low-level byte-array messages and figure out your own protocol on top of that.
Out of the box, 3220's equipped with the NFC Shell can exchange URLs, text messages and calls, using the ServiceDiscovery MIDlet. This, too is an NFC MIDlet.
By the way, you'll have to set both phones' time and date first.

Can I use the SDK to use my 3220 as a smart card reader?

Yes, you can. Even with the ServiceDiscovery MIDlet, you can already put a 'tag' into a Mifare chip that will be executed the next time you touch that tag. This is the Smart Poster concept: An RFID tag is placed on the back of a movie poster, and your 3220 picks up the URL embedded into that tag. Using your browser, you can visit the movie's website for more information, and download the trailer.

Can I register my own Mifare tag type that will launch my own MIDlet when I touch it?

Yes, you can. Just like the ServiceDiscovery MIDlet, you can instruct your MIDlet to register itself with a certain tag type. Then, when you've written a tag, touching it will cause the same MIDlet to be launched.

Can I use the SDK for Payment and Ticketing to communicate with other NFC devices?

Unfortunately, only if they speak the NTIP protocol. At the time of writing this article, there were not yet any devices that could speak a standard NFC protocol, so only Nokia devices could communicate well.

Installing awstats on Ubuntu HOWTO

This page will guide you through the process of installing awstats 6.5 on Ubuntu Dapper.

Installing awstats is a fairly pain-free process, but its default settings might not be inherently secure. You might not want to take throw these meticulously detailed website statistics out to the public, especially not for production sites.
This HOWTO will therefore attempt to leave you with a secure awstats installation.

Verify CGI is installed and enabled

We'll assume you already have apache2 running. Tell aptitude to install the latest awstats package:

Shell command:
$ sudo aptitude install awstats
Tells aptitude to install package awstats

Next, you'll need to have CGI installed and enabled on your server. It comes standard with the Ubuntu apache2 package, but make sure it's loaded when Apache starts:

Shell command:
$ ls -la /etc/apache2/mods-enabled/
Look up a list of enabled modules for apache2

It should note a symbolic link (cyan-colored) linked to /etc/apache2/mods-available/cgi.load.

Now check your virtual host configuration file whether the cgi-bin directory is routed correctly. Your actual virtual host file might be different than the one stated here:

Shell command:
$ sudo vim /etc/apache2/sites-enabled/000-default
Edit default virtual host file

Look for the section ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/.

Unless you want your awstats open to the public, you might want to add some access rules so that your awstats aren't available to everybody. Putting them in the virtual host config does require apache2 to be restarted, but saves you the trouble of editing redundant .htaccess files. And after initial configuration, chances are slim you'll have to review this part of the file again.

These are my recommended security settings:

/etc/apache2/sites-enabled/000-default
# Tell Apache where to find URLs that look like:
# http://dw.ig3.net/cgi-bin

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

# Enable icon support for awstats.

Alias /awstats-icon/ /usr/share/awstats/icon/

# Disallow .htaccess files

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

# Security measures to prevent unauthorized access

Order Allow,Deny

Allow from public_ip

Allow from 172.16.0.*

# Disallow .htaccess files

AllowOverride None

Options None

# Security measures to prevent unauthorized access

Order Allow,Deny

Allow from public_ip

Allow from 172.16.0.*

The Allow from directives specify which hosts and/or IP ranges are allowed to access your awstats. If you include both your public IP and your LAN's address range, everybody on your local network (or connected through a VPN or SSH SOCKS proxy) can see your stats. Replace public_ip and 172.16.0.* with your own public IP and LAN address range.

The line Alias /awstats-icon/ /usr/share/awstats/icon/ allows awstats to use its icons. Although not mandatory, it does look a lot prettier with.

Restart apache2 for the changes to take effect:

Shell command:
$ sudo /etc/init.d/apache2 restart
Tell apache2 to re-read its configuration file and restart

Configuring awstats

With that secured, let's move on to configuring awstats. We'll only describe here how to configure awstats for a single host.

Shell command:
$ sudo vim /etc/awstats/awstats.conf
Edit the awstats configuration file

Scroll down to the line

LogFile="/var/log/apache/access.log"

and replace that with

LogFile="/var/log/apache2/access.log"

Go to

SiteDomain=""

and fill in your own site's domain.

That should cover the required setup. There are many other well-documented optional features that you can set, but I'll leave those to you.

awstats needs to be updated periodically. During an update, it will scan through your apache2 log files and create a statistics page based on that.
The Ubuntu awstats package automatically creates a cron job for you that will take for these periodic updates. Let's see what they got us:

Shell command:
$ sudo vim /etc/cron.d/awstats
Edit the awstats cron job file
/etc/cron.d/awstats
0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a

-f /etc/awstats/awstats.conf -a

-r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl

-config=awstats -update >/dev/null

0,10,20,30,40,50 Tells the cron daemon to execute this line every 10 minutes.

www-data Specifies the user that will run this program. www-data is the same user that also runs the apache2 program in the background.

-f /etc/awstats/awstats.conf Tells the awstats.pl program where to find its config file.

-r /var/log/apache/access.log Tells the awstats.pl program where to find the Apache log files.

Almost correct, but our access.log file is located in /var/log/apache2, and not in /var/log/apache. Update the line:

/etc/cron.d/awstats
0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a

-f /etc/awstats/awstats.conf -a

-r /var/log/apache2/access.log ] && /usr/lib/cgi-bin/awstats.pl

-config=awstats -update >/dev/null

-config=awstats -update >/dev/null Tells awstats to use the config file awstats.conf, (located in /etc/awstats) to update its data, and to not send the results as an email.

Let's update our awstats for the first time. The cron daemon will take care that every 10 minutes, this command will be run:

Shell command:
$ sudo /usr/lib/cgi-bin/awstats.pl -config=awstats -update
Update awstats data for configuration file /etc/awstats.conf

This might take a while. You output should look like this:

Output:
Update for config "/etc/awstats/awstats.conf"

With data in log file "/var/log/apache2/access.log"...

Phase 1 : First bypass old records, searching new record...

Searching new records from beginning of log file...

Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...

Jumped lines in file: 0

Parsed lines in file: 23

Found 0 dropped records,

Found 0 corrupted records,

Found 0 old records,

Found 23 new qualified records.

Now go and check out your stats! They're located at /cgi-bin/awstats.pl.

Concatenating literal C++ strings

Did you know, that in the C programming language, and close brother C++, you can concatenate two strings without even using strcat or the += operator?

At school, they never told me that you could just write two strings contiguously, and that they would be concatenated automatically. But they are! And mind you, it doesn't work in Java!

C++:
string s = "C++" "string";

What would be the result?

Free-form language

Strictly speaking, nobody's telling the compiler to actually concatenate these strings. It might look similar to semicolon spamming:

C++:
int i = 13 + 14;;;;;

The compiler sees these as five statements. The fact that four are empty, is utterly irrelevant to the compiler. After all, C (and C++) is a free-form programming language that allows you to put arbitrary tabs and spaces wherever you desire. But you can't do that with variables. Right?

In mathematics, (and especially in complex algebra) to improve readability in formulas, multiplications like c = a x b can be simplified to c = a b. Could I do this with C++?

C++:
int a = 12;
int b = 7;
int c = a b; // Error: missing ';' before identifier 'b'

Space operator

Ofcourse it doesn't work, but why not? Because the binary = operator takes only one argument. And fortunately, there is no such thing as the space operator in C++. That would, in theory, make it possible to get a valid result out of line 3, but would render our favorite programming language awfully malformed. Every space character would have to be substituted because it would otherwise be mistaken for the space operator. What should we substitute it with? In the following example, MOO is used:

C++:
intMOOaMOO=MOO12;
intMOObMOO=MOO7;
intMOOcMOO=MOOa b;
Caution: Hypothetical code. Do not use in mission-critical business systems or intelligent refridgerators!

Illiterate strings

Then how about pasting two literal strings behind each other? You are probably thinking, isn't strcat or the += operator supposed to do that? Yes, but they operate on variable, non-literal (not, illiterate) strings. Literal strings can easily be concatenated in the following manner:

C++:
string s = "C++" "string";
const char* s2 =
"C++ strings "
"as well as"
"regular C strings";

This allows you to not cross the horizontal border and still make use of indentation.

Labels

Listed on NFC-Directory