Member of the EVE Tweet Fleet
Dec 16

Displaying the configured 403 error in Symfony 1.4

By Xeross Posted in Developing, How-To's, Tech Leave a Comment

Today I had to figure out how to trigger a 403 error and display the appropriate error page. I wanted to use the configured 403 page that the authentication system displays on failure. So after a bit of digging I found that to display this page you call the following (From the controller):

$this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));

To set the HTTP status code to 403 you would use (Again from the controller):

$this->getContext()->getResponse()->setStatusCode(403);

This should give you a 403 response with the configured permission/access denied page.

Note: I haven’t worked with Symfony a lot so there might be a better way, yet I haven’t been able to found one, if there’s a better way, let me know in the comments!

Tagged with:
Oct 01

IRC Bots and Message Queues

By Xeross Posted in Developing, Tech Leave a Comment

As I have recently once again become frustrated by how my IRC bot evolved into a horrible mess of code and I have decided on yet another rewrite after seeing how hook.io (Written in NodeJS) handles IRC bots I decided to take a look at implementing something similar.

I recalled that I experimented with message queues before with various pieces of other software and that a message queue might just provide the functionality that’s similar to hook.io that I wanted.

So after some researching I decided to settle on RabbitMQ, it’s fast, simple to set-up and has a nice status/admin plugin that is helpful both during development and a live environment.

I also decided to use Gevent for this rewrite rather than Twisted which I’ve always used for my previous bots. Sure asynchronous code can be written clearly, but the clarity and ease-of-use of blocking/synchronous code is just way better in my opinion. And with Gevent I can write synchronous code (And use blocking libraries) and it’ll make them async in the background (Thanks to how Python generators work).

The basic functionality version of the new bot is finished, I currently have a few node types (Processes with a certain task) implemented:

  • A proxy: this just connects to an IRC server, registers and pushes any packets onto the message queue (And listens for packets to send too), so now rebooting the bot won’t make it close all connections.
  • A client: does the actual IRC interaction and hands the proxy packets to send to the server.
  • A logger: simply outputs all messages sent between the nodes
  • A command line interface: a simple command line application that implements some basic IRC commands (PRIVMSG, JOIN, PART) to send to the client manually

It’s all very basic, the proxy and client need to be changed so that they manage multiple IRC servers, a management node will be implemented that will orchestrate everything and plugins, etc. will also be their own nodes.

Some might say this is over-engineering, I’d call it flexibility and reliability. It does what I want and it does it in a clean effective fashion. Not to forget I learn more about using message queues which seem to be gaining popularity lately.

This is still long from being a working functional IRC bot but I already feel like I am making a cleaner and more organized start, and hopefully this will be the first one that actually runs in production fairly smoothly.

~Xeross

Tagged with:
Aug 27

Bug Analysis

By Xeross Posted in Developing, Tech Leave a Comment

Recently there was a problem with a website that is still in development (That will remain unnamed). For some reason, when you logged in on the admin, everything worked, but when you refreshed the page the tabs that were loaded through ajax would somehow have you logged out (And another refresh after that you were completely logged out).

Someone else had already been trying to figure out this problem for more than a day and was breaking his head over it. Nowhere did the session get destroyed in the admin, or during the ajax requests, and the only location were it got destroyed was in the logout call and on the website when you tried to access a page that doesn’t exist.

I decided to take a look at it, with a mentality of, anything can happen, even if it doesn’t make sense. So first thing I tried was commenting out the session_destroy call in the index, which indeed seemed to resolve the problem.

But the index should never be loaded in the first place. So time to fire-up firebug and let it log all requests made by a single admin page load.

For some reason the admin was indeed loading the website for some odd reason. Now to my surprise as someone suggested, Internet Explorer (Yes you are reading that right) shows where the request originated. Turned out it was being requested through a <script> tag somehow. Coincidentally it seemed that that same script was also erroring.

So after commenting that out (And having the session_destroy enabled again) I tested it again, and yep you remained logged in. Now of course still not satisfied, I had to figure out why it was loading the front-page.

So opening the script there was nothing in there that did even attempt to make a request, so it couldn’t be in the script (This was an exception to the everything is possible rule because this really was too impossible). So then I tried opening the script in the browser, and hey I was redirected to the frontpage.

Okay, I’m getting redirected, but why. Ah yes perhaps the .htaccess will tell me. Upon opening the .htaccess file I found out that it would redirect requests to any folder or file that didn’t exist to the frontpage (With the path of the file as page to request).

So after disabling this rewrite rule the file did indeed not exist, for some reason it got deleted on the dev server. So upon re-upload it worked again. After this to prevent this in the future I also added an exception for js/css files into the htaccess so that those missing would be easier to detect.

Of course I could’ve made more rigorous changes to the project to make this problem impossible to happen, but I was asked to help debug and the way it was built was decided by a team that probably had reasons for why they did it the way they did it (I made suggestions and they’d discuss them).

Conclusion

  1. Go in with an ‘anything can happen’ mentality, even if it seems impossible it might just not be
  2. If you’ve been trying to figure out a bug for quite some time, ask someone else to take a look, he/she might have a different viewpoint that’ll help solve the issue
  3. Internet Explorer can actually be useful
  4. Why the fuck didn’t other browsers implement the request origin feature (Or why did they make them hard to find I might have overlooked them).

it was a fun challenge to solve this bug, and it made me learn a good deal about solving issues that you wouldn’t get if you were always working on projects you are the sole developer of.

~Xeross

Tagged with:
Aug 18

Framework Selection Madness

By Xeross Posted in Developing, Tech Comments (10)

We’re currently researching what framework to use for our new project at work. After having crossed a few of the list (CodeIgniter had some odd behaviour and all kinds of artifacts from PHP4 days, and FeulPHP is too new to use in a serious project), we are left with Kohana (Which was a CI derivative but 3.0 was a full rewrite), and Django (One of the most used web frameworks for Python).

Unfortunately after just barely scratching the surface of Kohana it became apparent that the lack of documentation will be a problem. Sure we can figure out stuff ourselves but that’s wasted time, and has no advantages over a well documented system.

Now there’s Django which I am really fond of, but as is understandable there is some hesitance to use a new language, which comes with all kinds of stuff that behave differently than PHP.

In my eyes Kohana is a no-go due to this lack of documentation, especially compared to how easy the same thing was in Django (While writing one of my own projects). There’s already been made use of Symfony so we might end up using that. So it’s back to research again, with new contestants.

~Xeross

Tagged with:
Jul 30

Open Source Projects/Code \o/

By Xeross Posted in Developing, Tech Leave a Comment

Recently I’ve decided to start more actively pushing my code onto GitHub, considering I’ve never had the intention to keep most of it private, yet I had never found the time to properly push it to GitHub.

xJsonRpc-*

JSON-RPC client/server libraries for various languages, so far I’ve implemented both a PHP server, and a Python Twisted Cyclone handler (Server too)

tcpbuffer

Package count reducing proxy, Not really my code, but I added all required dependencies to the repository and created a Makefile

Tweerity

A python library/framework for writing applications using the streaming Twitter API, this was written by a friend of mine, and I helped adding mention events (Unfortunately he didn’t merge from my branch, but applied the code himself)

That’s it, I’m probably going to give my own projects their own pages on here at one point, but that doesn’t have any fixed date. Well I hope any of this is helpful for someone.

~Xeross

Tagged with:
Aug 08

WordPress Theme Development Test Pack

By Xeross Posted in Developing, Tech, Wordpress Leave a Comment

I have recreated the page, post and category structure/data as seen on http://wp-themes.com/.

And I have exported this into a WordPress export XML and made this available for download.

The file can be downloaded here

Tagged with:
Apr 17

OGame 1.2 PM Fix

By Xeross Posted in Developing, Tech Comments (2)

This script will fix the personal messages in OGame 1.2.

Download

Over at userscripts.org

Changelog

1.0 – 17/Apr/2010

Initial Release

1.1 – 25/Apr/2010

Added an additional search&replace for ‘

Code

// ==UserScript==
// @name           OGame 1.2 PM Fix (v1.1)
// @namespace      http://theelitist.net/ogame-12-pm-fix/
// @description    Fixes The numerous nn and backslashes in PMs
// @include        http://*.ogame.*/game/index.php?page=showmessage*
// ==/UserScript==

(function() {
    var body = document.getElementsByTagName('body')[0];
    body.innerHTML = body.innerHTML.replace(//g, "");
    body.innerHTML = body.innerHTML.replace(/n/g, "<br />");
    body.innerHTML = body.innerHTML.replace(/'/g, "'");
})();

Post any bugs/suggestions here in the comments or at userscripts.org

~Xeross

Tagged with:
Jan 22

OGame (1.X) Dropdown Text Color Fix

By Xeross Posted in Developing, Tech Comments (2)

This script will fix the dropdown text color in OGame, I made it for Firefox (Only tested with 3.6) it makes the select tags inherit the text color so the text inside em is readable.

Download

Over at userscripts.org

Changelog

1.1 – 25/Jan/2010

Removed jQuery loading because OGame already includes it, fixes galaxy overview

1.0 – 22/Jan/2010

Initial Release

Code

// ==UserScript==
// @name           OGame (1.X) Dropdown Text Color Fix
// @namespace      http://theelitist.net/ogame-select-tag-fix/
// @description    Fixes OGame (1.X) Dropdown Text Color
// @include        *.ogame.org*
// @exclude        *board.ogame.org*
// ==/UserScript==

// Modify the CSS
$(document).ready(function() {
	$("select").css("color", "inherit");
});

Post any bugs/suggestions here in the comments or at userscripts.org

Tagged with:
Dec 12

Back in the game

By Xeross Posted in Developing, EVE Online, Gaming, Tech Leave a Comment

After being unable to use the computer for almost anything I finally fixed my Windows 7 installation (Link), so now I can finally get back into my normal rythm. I’ve installed EVE, CoD2 and WoW so I’m ready to roll again.

I’ll be primarily focusing on getting the corp website online when doing anything EVE related, my CMS is as good as finished so I just need to implement the design and EVE specific modules.

Other than that I can get back into blogging and following everyone’s blog again so that’s good too, and ofcourse continue helping out my clients.

Well that’s it for this update, I’ll be writing a detailed post on the Windows 7 issue soon.

Regards, Xeross

Aug 30

Passing additional arguments to a callback function in Javascript

By Xeross Posted in Developing, How-To's, Tech Comments (4)

jQuery PNG LogoI was working on my CMS (Just took a brake to write this), and I tried to figure out how to pass additional arguments to a javascript callback. After some searching I found what I was looking for, I told the people in the jQuery IRC channel and someone gave me shorter and cleaner code that does the same. So let me run you through the code (Note: This is jquery but the same method would also work with normal Javascript) .

In this example I will use an argument that defines where to load the data got from an AJAX request in.

//Custom function that's used instead of the long jQuery Syntax
function loadUrl(url, destination)
{
    // Use a get request to get the page at URL
    $.get(url, function(html, status) { loadedPage(html, status, destination) });
}

// The callback function
function loadedPage(html, status, destination)
{
    // If the AJAX call failed stop the function
    if(status != "success")
        return;

    // Set the html of destination (Which is in this case a jQuery Selector) to the jquery repsonse
    $(destination).html(html);
}

If you haven’t figured out how to pass the additional arguments from the above example I’ll explain in detail, Let’s take a closer look at line 5(Formatted for readability).

$.get(url,
    function(html, status)
    {
        loadedPage(html, status, destination)
    }
);

As you can see we are using a custom defined function for the callback, What we do is make a function that has the arguments that get passed to the callback.

function(html, status)
{

}

And in that function we call our real callback function but with the additional arguments we passed to loadUrl()

function(html, status)
{
    loadedPage(html, status, destination)
}

And that’s it, this can be done with as many additional parameters as you like just add them to the call of the real callback function.

Leave a comment if you have any questions or feedback.

Regards, Xeross

Tagged with: