Kastang Ramblings of a Geek

16Jun/110

Can a Single [Space] Seriously F*ck Your Day Up? Yes.

I came across a GitHub Commit for a script called Bumblebee today. It appears the author added a single [space] to a piece of production code that would essentially render a system useless.

THE OFFENDING LINE:

rm -rf /usr /lib/nvidia-current/xorg/xorg

THE FIXED LINE:

rm -rf /usr/lib/nvidia-current/xorg/xorg

The "Fixed Line" would be read on linux system as "recursively remove (without prompting the user) /usr/lib/nvidia-current/xorg/xorg. The system read the "Offending Line" command as "recursively remove (without prompting the user) /usr THEN recursively remove (without prompting the user) /lib/nvidia-current/xorg/xorg". Chances are the directory /lib/nvidia-current/xorg/xorg does't exist, which would prompt rm to return an error. Unfortunately, rm reads argments in the order they are received meaning the users entire /usr directory would have been removed before an error occurred.

I was surprised that the comments for the fixed commit were relatively comic (though, chances are most of the commit comments came from users on Reddit or other news sources). The number of Memes that have been applied (in the commit comments) to this situation are impressive. Those who kept proper backups of their systems would more then likely have been able to repair their systems within a matter of hours.

Looking at the commit history, it looks like this issue happened a few weeks ago. Seeing that the project is still being actively maintained by the author; it appears its users accepted the fact the people do make mistakes and continued to use the software. This should be a reminder to everyone that maintaining current system backups are vital because disaster can strike at any time.

10Jun/110

Vanilla2: Enable HTML in Inbox Conversations

For an unknown reason, Vanilla2 does not allow HTML in Inbox conversations. As far as I can tell, this issue has existed since the release of Vanilla2 last year. This bug has remained at least until the latest revision of Vanilla - 2.0.17.10. This solution can be easily fixed by modifying one line:

/applications/conversations/views/messages/messages.php:

On or around Line 36, change Gdn_Format::To to Gdn_Format::Html.

After the change, HTML will render properly in Inbox Conversations.

Tagged as: , No Comments
25Apr/110

xkcd Comic Downloader

I have created a simple Perl script that will locally store every xkcd comic and generate a HTML file to view all xkcd comics on a single page. After the initial run of this script, each additional run will do incremental updates (only new comics will be downloaded since the last time the script was executed).

The script can be run from a command line:

perl xkcd.pl

or, by setting xkcd.pl to executable and running it as:

./xkcd.pl

The latest revision of the code can be found on Github. Please read the README file on Github for Perl requirements.

Tagged as: , , No Comments
19Mar/110

WoW Realm Status PHP Class

I am working on a PHP Class called RealmStatus that will pull WoW Realm information from the WoW Realm Status Page without XML feeds available.

The RealmStatus Class currently supports the following operations:
--getAllServers() - Returns an associative array of all Server Names, Statuses, Populations, Types, and Locale.
--getServerType($) - Returns the type of a given server.
--getServerStatus($) - Returns the status of a given server.
--getServerPopulation($) - Returns the population of a given server.
--getServerLocale($) - Returns the locale of a given server.

For a detailed explanation of the operations, please read the function headers in the RealmStatus.php and example.php files.

The files can be pulled from GitHub here.

Filed under: Coding, PHP, WoW No Comments
4Dec/100

Using Python to Parse WoW Server XML.

THIS CODE IS OBSOLETE. Blizzard changed the way information can be grabbed from their servers. Please view my PHP Class which will work.

The below Python script will parse the WoW Server XML file and return status, type, name, and load about a specified WoW Server. It also stores the Server XML file into a cache.txt file so constant requests to the script will not result in an IP ban on Blizzards servers.

Python 2.6+ must be used for this script to function correctly. It will work out of the box with no third party libraries required.

Please change the SERVER_NAME (on line 32) variable to your servers name.

#!/usr/bin/python
 
"""
Author: Josh Grochowski (Kastang)
 
This script will parse the WoW Server Status XML file and return
information about a specified server. This Python script works
for me, but it may not work for you. Use this script at your
own risk. 
 
Python 2.6+ must be used.
"""
 
"""
The below four lines assume this script will be loaded onto a
webserver. If you are planning to run this script in a CLI
enviornment, feel free to remove the below four lines of code.
"""
import cgitb
cgitb.enable()
print "Content-Type: text/html;charset=utf-8"
print
 
#Imports
from xml.etree.ElementTree import parse
import urllib, os, time
 
#WoW Server Status Path
WOW_XML = "http://www.worldofwarcraft.com/realmstatus/status.xml"
 
#Change SERVER_NAME to the your server.
SERVER_NAME = "Eitrigg"
 
#Display information for the Realm information.
rStatus = ["Offline", "Online"]
rType = ["", "PVE", "PVP", "RP", "RP PVP"]
rLoad = ["", "Low", "Medium", "High"]
 
#Modification time of the cache file.
modTime =  os.stat("cache.txt").st_mtime
 
#Current system time.
currTime =  time.time()
 
"""
If this function is called, the cache file will be
updated with the newest information from the WoW
Server Status XML file.
"""
def updateCache():
    cache = open("cache.txt", "w")
    cache.writelines(urllib.urlopen(WOW_XML))
 
"""
Given a Realm name and XML file, it will find the
XML string containing information about the specified
Realm and return it to the requesting function.
"""
def findRealm(realm, xml):
        for l in xml.findall('rs/r'):
                if l.get('n') == realm:
                        return l
 
        return False
 
#Displays information about the specified Server.
def printOutput(server):
    print "Realm Name: " + server.get('n')
    print "Realm Type: " + rType[int(server.get('t'))]
    print "Realm Status: " + rStatus[int(server.get('s'))]
    print "Realm Load: " + rLoad[int(server.get('l'))]
 
"""
If the cache file has not been updated for 10 minutes,
it will be updated. Otherwise, the existing file will
be used to find current information about the specified
realm. 
 
If the specified Realm is not a valid WoW Realm, nothing
will be returned. 
 
"""
def main():
    if (currTime - modTime) > 600:
        updateCache()
 
    xml = parse("cache.txt").getroot()
    server = findRealm(SERVER_NAME, xml)
 
    if server != False:
        printOutput(server)
 
if __name__ == "__main__":
    main()

A sample output can be seen below:

# python realmstatus.py
Realm Name: Eitrigg
Realm Type: PVE
Realm Status: Online
Realm Load: High
Tagged as: , , No Comments