Low-level customization: userconfig.cfg and persistent logins

This short tutorial covers the userconfig.cfg file and how to use it. It also describes the settings needed to enable persistent user login, i.e. carrying logins over from one browser session to another.

LnBlog has a lot of configuration settings. However, not all of them have a nice settings dialog that allows you to change them graphically.

The blogconfig.php file in the root of your LnBlog installation is full of settings like this this. That file has PHP definitions for various configuration constants. They're "constant" in that you can't change them programatically, i.e. inside a plugin or other script, but you can change them using a configuration file. That file is called userconfig.cfg and it is located in your LnBlog/userdata folder.

If you look at the blogconfig.php documentation, you'll see that many of the constants defined there are listed as having a default value. The values of those constants can be changed by adding a line to your userconfig.cfg file. Of course, you could just just edit blogconfig.php, but that file changes with every version of LnBlog, so you'd have to re-do all your chages with every upgrade. Since userconfig.cfg lives in your userdata folder, you can easily carry it over from one version of the software to another.

The format of userconfig.cfg is simple: name=value pairs, one per line. You can add comments by starting a line with a hash (#) character. When LnBlog loads a page, it will read the userconfig.cfg and for each line it will define a constant with the name given before the equal sign and assign it the value after the equal sign. Because this is loaded before other constants are defined, the values set here will take precedence over the defaults.

As an example, let's set some of the values that control user login security. LnBlog's default user authentication settings are, well, a little paranoid. In the current version (0.7.3) and earlier, a login token is stored on the server in a session variable and on the client in a cookie. A user is only authenticated if the client's token matches the server's. This is good because it prevents account hijacking by stealing cookies (the login token incorporates a timestamp and IP address, so simply copying the cookie won't get you authenticated), but it's a little inconvenient, as your login only lasts as long as your HTTP session does.

To fix this, we will add two lines to our userconfig.cfg. Note that this file is case-sensitive. If you do not have a userconfig.cfg file in your userdata directory, create it with a text editor.

Open up your userconfig.cfg in a text editor and add the code below.
AUTH_USE_SESSION = false
LOGIN_EXPIRE_TIME = 2592000

The first line turns off the paranoid authentication check so that LnBlog will only check for a predefined value in a cookie. The second line sets the expiration time of that cookie. The default value (false) expires the cookie when your browser session end. The number indicates the number of seconds after which the login cookie should expire. The value given above is equivalent to 30 days.

There are a number of other userconfig.cfg settings that might prove interesting. ENTRY_DATE_FORMAT is the format string used to display the post date on entries. Another good one is KEEP_EDIT_HISTORY, which determines whether changes to entries and articles should just overwrite the old data or whether the system should keep a backup copy. The COMMENT_NOFOLLOW configuration constant determines whether links in entry comments should have the rel="nofollow" attribute added to them. And lastly, the ANON_POST_NAME and NO_SUBJECT constants determine what name and subject should be given to comments when the user doesn't enter one.

Hopefully that gives you an idea of how to set some of the more esoteric configuration options in LnBlog. In a future posting, I'll describe userconfig.php, which is similar in purpose, but both much more powerful and much harder to use.

New plugins: RecentComments and PrivateBlog

I've added a couple of new plugins to the plugins page.

The RecentComments plugin is a sidebar panel that shows a list of the most recently posted plugins. It's got configuration options to control the display of the poster's name and the entry it's posted to.

The new verions of PrivateBlog, which used to be part of the standard set, lets you block access to a blog by all except a given list of logged-in users. You can allow access by username or by group membership. In addition to redirecting pages, the new version also blanks out all entries, articles, and comments that might be displayed by other plugins (like in the sidebar). However, this only works for dynamic PHP pages: static files like RSS feeds are not blocked. So if you really want the blog to be truly private, you might want to consider turning off the RSS plugins.

Also, I fixed some broken and missing links on the plugins page. The two plugins I added yesterday now have links associated with them and the links to the two editor plugins are fixed now.

LnBlog 0.7.3

Well, I finally got around to finishing up LnBlog 0.7.3. You can grab the archive here or get it from the download page.

This release contains mainly minor bug fixes. You can find the details in the change log. It also adds support for per-category RSS feeds to the standard RSS plugins and MetaWeblog API. Note that these are statically generated, just as the regular RSS feeds. Also, I've moved the Archive and GoogleSearch out of the main distribution and onto the plugins page.

That's about it for now. I'll be putting up a couple new plugins up in the next day or two, so stay tuned. In the mean time, please leave a comment or e-mail me if you have any problems, bugs, or suggestions.

ContactForm plugin

Ask and ye shall receive! By popular demand, I cooked up a little contact form plugin today. You can download it from the plugins page. To install, just extract it from the ZIP archive and drop it in your LnBlog/userdata/plugins folder. (Note: This is the new recommended location for non-standard plugins. You can still use LnBlog/plugins or your per-blog plugins folder as well.)

Basically, this plugin provides a contact page that users can use to send e-mail to the blog owner. It also puts a link to the contact page in the sidebar. Note that the blog owner must have an e-mail address set.

This is just the initial release, so I'll expand and integrate this more later. You know, putting the link in user profiles, allowing more than just the blog owner to be e-mailed, etc. I'm trying to go with that whole open-source "releaswe early, release often" thing here. Plus this is only the second plugin I've done that generates and entire page, so I wanted to work on the basic design before worrying too much about features.

LnBlog 0.7.2 is up

I've uploaded LnBlog 0.7.2. You can get it from the download page or just grab the archive here.

This is a bug fix release. The specific fixes are:

  • Fixed errors when trying to edit the sitemap.
  • Fixed the plugin configuration not showing when using PHP5.
  • Added delete links for articles.
  • Added a checkbox on the article edit screen to set the "sticky" state.


Many thanks to MoonMind for pointing out these errors.

As usual, please let me know about any problems, ideas, or feedback by e-mail or by leaving a comment.

LnBlog in Linux Format

I discovered something rather cool this weekend. While browsing through a copy of the June 2006 Linux Format in Barnes & Noble, I found a reference to LnBlog! In fact, LnBlog was featured on the first page of their "Hot Picks" section. I had no idea it was going to be listed, so this was a pleasant surprise for me.

Their write-up provided a pretty good summary and was generally positive. It was a little out of date, in that it covered LnBlog 0.6.4, but that's unavoidable, as they always write these things way ahead of time. The only real criticism the author had was that there is a lack of end-user documentation. I'm working on fixing that, but it's slow going. Now, if there were 36 hours in a day, then it might be another story.

As a point of interest, I was so pleased by this that I actually shelled out the $16 or whatever it was to buy a copy of the magazine. When I showed the column on LnBlog to my wife Sarah, it took several minutes to convince her that I actually wrote the software. (She's obviously not very interested in software.) The thing that convinced her was that the screenshot with the column used the skepticats theme, which includes a picture of our cat Loki in the banner. When she asked, "How did they get a picture of Loki?" and I explained that I put it in that theme because I wrote the program, it finally started to sink in. After that, she thought it was really cool.

Linking to uploaded files

Here's a little piece of trivia for all those who don't read the documentation (which, in reality, is almost everybody): you don't need to know the URL of a post to link to a file uploaded to it. LnBlog takes care of that for you.

How does this work? Well, for files uploaded to a post, it's actually quite easy. When you give the link URL, only specify the name of the file. No path, no domain, just the file name. When you submit the post and view it in your browser, you'll see that the link displays the absolute URI of the file. Basically, when your post is displayed, whether in a browser or RSS feed, LnBlog will scan it for links and image references and convert any bare file name (meaning a relative URL with no slashes in it) into an absolute URI based on the URI of the post.

The handy thing about this is that it's so transparent. This conversion works automatically in both HTML and LBCode markup modes and is done on the href attributes of anchor (<a>) tags and the src attributes of image tags. It works very nicely with the new feature in version 0.7.1 that lets you upload files at the same time you make the post. All you need to do is give the file name and the URI calculation is done for you.

This feature was originally added because I was sick of making a post, uploading my files, and then editing the post because I didn't know the full URI of the files until after the post was submitted. I had to do that because LnBlog bases the URI of a post, and hence the path where its files are stored, on the date and time at which it was made.

Of course, I could have just made a single upload directory and put all my files there, but I didn't really like that idea. I wanted to keep things more "semantic" than that. For some files, like releases of LnBlog, it makes sense to put them in a central directory at or near the blog root. However, some files really are only related to one particular post. To me, it makes sense to keep those files with the post they're meant for. And so I decided to take the guess work out of figuring out the URI for that post.

LnBlog 0.7.1 "No Need for Web Browsers"

It's release time again! You can now get LnBlog 0.7.1, "No Need for Web Browsers" here or from the download page. Unlike the last release, upgrading from version 0.7.0 to the new version is as simple as usual. Just rename the old folder, upload the new one in its place, and move over your old userdata folder.

This is a feature enhancement release, including some small features and a big feature. The big feature, which turned out to be surprisingly easy to implement, is support for the MetaWeblog API. This is like the Blogger API, in that it allows you to add and edit posts, but better, because it also allows you to add post metadata and upload files to a blog. Note that, like with LnBlog's implementation of the Blogger API, blog and entry IDs are based on the URL, so that the ID of this weblog would be "lnblog", while the ID of this entry would be "lnblog/entries/2006/05/22_1811".

To go along with this, I've also written a small Python program that I call CLIblog-MW, which is bundled with this release. It's a simple script written for Python 2.3 that allows you to make MetaWeblog API calls from the command line and print out the response from the server. This will allow you, with a little scripting, to automate postings and file uploads. For documentation, run the script with the -h option. Among the more useful features are the ability to store authentication information in a profile file and the ability to create new posts based on the contents of a text file.

The other significant feature is a change to the entry add/edit page. You can now upload files when you initially create a post or edit it. You can set the number of possible file uploads in the system.ini file by setting the AllowInitUpload value in the entryconfig section. By way of example, the following code will give you four upload boxes on the page: [entryconfig] AllowInitUpload=4 The default number of boxes, if no value is specified, is one. To disable the upload boxes on the entry add/edit pages, set this to zero.

The last little changes include a compression of the entry input type selection. Now you select the markup type from a drop-down box rather than three radio buttons. You will also find links on the admin page to edit the system.ini and groups.ini files. This is a poor substitute for a proper configuration interface, but it's better than nothing. And last, there are fixes to the return values for some Blogger API methods. In particular, the newPost method was returning a URL when it should have been a unique ID.

As usual, please let me know about any bugs or ideas for improvement. I've put up a support page that lists the various methods for getting support, including my e-mail, the SourceForge forums, and the SourceForge issue tracker. Or you can just leave a comment on this post. Whatever works for you.