More Geekiness (Auto Signature)
Some new geekiness going on. I have a journal/blog over at SweetnLeo.com, where I talk about things relating to GaiaOnline. I wanted a way of making this available inside Gaia, so I came up with this.
It’s an image that shows the last 4 blog titles. How it works if I have a script that uses MagpieRSS to pull the feed from the blog, and then using PHP + GD I generate a simple image. When I make a blog post, it pings the update image script, meaning when I add a new entry the image will update.
It gives me a way to show what’s going on. Now to make it more pretty (as it’s just plain text right now).
Object Oriented Fun
Currently my attempt is to rewrite my progress so far in a more OO manner. What I’ve previously done is use classes and objects, but infrequently. Let’s see if I can do this better, third time around.
Apache AuthMySQL
I had the pleasure of trying to figure out how to use AuthMySQL the other day, as I wanted to password protect my folders (in a simple fashion, since the content wasn’t essential) but wanted to avoid the whole flat-file .htpasswd system.
Lots of searching on Google helped, but it was funny that I found I didn’t have the Mod_Auth_MySQL module in XAMPP. It turns out the later releases of XAMPP removed the module for some reason. (There was a reason for it, but I wasn’t really interested in it, since I just wanted it working on my local machine!).
Getting the XAMPP Module
Getting it was actually pretty simple. You just need to find and download the 1.6.2 version of XAMPP. Make sure you download the correct version based on your operating system (since grabbing the Windows file wouldn’t work on Linux etc…).
It sounds insane downloading the entire thing for just one file, but unfortunately that’s really all you can do (unless you manage to find it elsewhere).
Once you have the mod_auth_mysql.so file, put it in your xampp/apache/modules folder, and then edit the xampp/apache/httpd.conf file.
Down around the file (was line 132 for me) is a line that looks like:
;LoadModule mysql_auth_module modules/mod_auth_mysql.so
The semi-colon at the front is basically a “comment”, disabling the module. Remove it, and then save the file. Restart apache (in Windows you can use the XAMPP manager).
Creating the Database Table
This is MySQL authentication, so we need to create the table. The table is pretty simple, at the most it needs 3 fields, a username, a password and a group.
Here’s a quick create script, but you can obviously make (or use) your own. I would suggest you don’t use plain passwords, rather if you use the MySQL md5 function, apache can work with that.
CREATE TABLE IF NOT EXISTS `auth_user` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`username` varchar(25) NOT NULL,
`password` varchar(32) NOT NULL,
`usergroup` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
);Then add a user to the database.
INSERT INTO `auth_user` (`username`, `password`, `usergroup`) VALUE ('username', 'password', 'groupname');The group field should just be a group name, a simple string. We’re being simple here, but things can get more complicated if you want (such as multiple groups).
Setting Up
You can set up the authentication in your .htaccess file, like anything else.
Edit your file and add the following:
# MySQL Auth
AuthMySQLHost {your database host}
AuthMySQLUser {database username}
AuthMySQLPassword {database password}
AuthMySQLDB {database name}
AuthMySQLUserTable {user table}
AuthMySQLNameField {username field name}
AuthMySQLPasswordField {password field name}
AuthMySQLGroupField {group field name}
AuthMySQLNoPasswd on
AuthMySQLPwEncryption md5
AuthMySQLEnable on
# Standard auth stuff
AuthType Basic
AuthName "{Public name}"Anything in {brackets} were added by me, and should be replaced (with no brackets).
Finally, on the folders you want to protect, just add the regular directives.
# If you want to allow any valid-user
Require valid-user
# If you want to allow only a specific group(s)
Require group groupname secondgroupnameThat’s really it.
(Greasemonkey) Gaia Avatar Undo
I had another case of “distracted Greasemonkey writer”, where I’m on a web page and wondering why this certain something really doesn’t work that well.
Anyway, it resulted in me writing a new script, which I call the Avatar Undo. Like my last one, this is for GaiaOnline.com, and basically it adds a simple “undo” button to the avatar page. It records what items you put on, and in what order. Then when you click undo, it will go back and reverse those changes.
It is obviously not perfect, since it cannot compensate for server-side changes (like other items being removed due to layering clashes), however it is pretty good for the simple stuff.
This is something we all should hope Gaia adds, sometime in the future.
It can be found on my Gaia-based website, as well as on Userscripts.org.
Remember, this is a greasemonkey script, so if you don’t have it, go get it!
IDs starting with Numbers
We all know the ID and NAME conventions on HTML tags. The ID must start with a letter, and then afterwards can be any number, letter, hyphen, underscore or colon. So creating an ID of 56green would not work, as it begins with the number 5. Where as S6green would be perfectly valid.
Recently I wrote a greasemonkey script, and I found (to my horror) the website had used alphanumeric strings as their IDs. That was fine, but the catch was they didn’t check to see if each string followed the standards, meaning half started with a number.
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-”), underscores (“_”), colons (“:”), and periods (“.”).
It didn’t bother them, as the elements were not directly referred to. However it was a pain for me and my script, and so I had to find a way to call the element.
In my example, the name of the element will be 25tuna.
$('#25tuna').hide();
// In this case, nothing would happen. The element would not hide,
// even if it was still on the page.
$('#25tuna').length
// Would = 0, even though we can see the element sitting on the page.Instead, I ended up having to use a workaround for the issue.
$('div[id="25tuna"]').length; // now will equal 1
$('div[id="25tuna"]').hide(); // should now workSo while you can’t refer to the element using the regular notation, you can use it through attribute notation (since ID is another attribute on an HTML element).
This is not ideal, and does introduce its own performance issues. If it’s a case where you are able to alter the HTML element on the page directly (being your own website), do that and make the ID/NAME attributes conform. It will save effort and frustration.
However if you are writing a greasemonkey script (in jQuery like I did) then you may find this is your only option.
phpbb3 + Flyspray Part 2
In my previous post I mentioned how I wanted to bridge phpbb3 and Flyspray. Well, I’ve done that, but due to the way Flyspray works, it was basically a complete pain.
I love Flyspray, I really do, but I think it is time I moved on to a new bug tracking system. Unfortunately though I don’t know of that many (if you do, definitely please contact me through the comments!). I’ve tried Trac, but on the host I use it is an absolute nightmare to get installed. What I’d really like is a simple PHP-based system like Flyspray, but one that does get updated regularly.
The trouble I had with Flyspray is I basically had to hack it to get it working with my forum. In the end I get phpbb to do the authentication (on each page load), and if the Flyspray user doesn’t exist it manually creates it.
It definitely isn’t the ideal solution, the DokuWiki bridge that someone else (awesome person) wrote works perfectly, but that comes down to DokuWiki being easier to modify with plugins.
So yes, if you are interested in bridging Flyspray and phpBB3, it is possible. However it basically is bypassing all of Flyspray’s authentication and saying “This is the ID of the logged in user”. You also have to rename their Database and User classes, since they clash with phpBB.
All in all, if you’re looking for a bug tracking system that can easily bridge with a forum, look for something else.
phpbb3 + Flyspray
I am currently working on a mini-project, and part of it requires a forum as well as a wiki and a bug tracking system. I have already set up phpBB3 with Dokuwiki, and they’re bridged so the accounts are linked. That’s absolutely great!
What I’m currently trying to work on is installing Flyspray, and then writing my own bridge between Flyspray and phpBB. The way I theorize it, I’ll create a hidden group in phpBB called “flyspray” or something, and then when you access Flyspray it will check to see if you’re a member of that group using phpBB’s functions.
We’ll have to wait and see if it works, but if it does I’ll see about making the bridge public.
Wish me luck!
Trust Nobody
One important lesson when developing applications (I’m focusing on websites here, but this applies to all types of applications) is to ditch user trust.
In a nut shell, do not trust any input you receive from a user. Seriously, do not assume it is clean and good, treat all user input (whether it be cookies, text from a text box or something else) as potentially dangerous. Check it, filter it, escape it.
Never let input from a user go straight into your database or on to a page without it being filtered. If you let it straight into the database you leave yourself open to SQL Injections and other attacks.
Keep that in mind when you are developing an application, any and all user input needs to be checked out, torn to pieces, ripped apart, put back together before being considered safe.
Striped Backgrounds
Just a FYI for all of you web designers out there about pretty striped backgrounds.
I’m actually unsure if this is a LCD screen thing, or all of them in general. I actually don’t remember it from my old CRT screen, but let’s face it, who has a CRT these days? (OK, I’ll admit it I have one…)
Some websites like having a striped background, with an image like the following.
It does look pretty neat, and when it’s full-paged background it can give a webpage an interesting look.
The trouble is, scrolling. On screens like mine images like that do not work well when scrolling. The background does this weird flickering thing when scrolling along, and it does mean the website looks less cool, and more cheap.
I’d seriously advise you skip the tiny little stripes in background images. Try larger ones, they can look pretty good as well. Or, you know, a solid colour doesn’t hurt either.
Add a CSS class to any disabled button
This adds the class of “myclass” to any input with a type of “button” that is marked as disabled. This way you can easily style disabled buttons across a multitude of browsers.
$('input[type=button][disabled=disabled]').each(function(){
$(this).addClass('myclass');
});
Posted by Cody in
