August 8th, 2010
srcdswatch is a quick Python script I threw together to monitor a srcds server (Source Engine Dedicated Server). It pings the server occasionally in addition to monitoring the process. There’s also a web-based control interface to start, stop, and restart the server, and you can also perform a Steam update from there. I haven’t really used it yet, but it seems to work well from my testing. It is fully threaded so nothing will ever block something else (aside from the GIL).
http://github.com/sk89q/scripts/tree/master/srcdswatch/
Python 2.6-2.7 is required and you also need the SRCDS library.
Note that you have to put the direct path to srcds in the configuration file (no batch files), because the script won’t terminate childĀ processesĀ and you may end up with several srcds instances if you use a batch file.
Tags: Source engine, srcds
Posted in Software | View Comments
May 12th, 2010
Courtesy of Valve, Portal is now free until May 24th for both PC, and yes, Mac! Portal is a really great puzzle game and if you haven’t yet played it, so you should really take the opportunity. Get your friends in on it too!
http://store.steampowered.com/app/400
Tags: free, Portal, Steam
Posted in Games | View Comments
April 11th, 2010
Following someone’s suggestion, my PHP security checklist is now in a printable cheat sheet form.
Download: phpsec_cheatsheet.pdf

Tags: PHP, Security
Posted in PHP, Security | View Comments
April 3rd, 2010
Streams is a feature of PHP that was introduced in PHP 4.3 to unify the methods for working on files, sockets, and other similar resources. PHP 4.3 came out a long time ago, but many PHP developers never learned how to properly use streams in PHP, much to my dismay. Many use cURL for accessing HTTP resources, but I’m not a huge fan of cURL, because it has an awful interface in PHP and it presents yet another dependency. While the HTTP stream handler in PHP isn’t perfect, it works very well for most situations.
To begin, let’s consider what examples of streams could be:
- A file on a hard drive
- A HTTP connection to a website
- A UDP connection to a server
- A ZIP file
- A SSH tunnel
- A Vorbis/OGG file
What are some common operations on all of those? Primarily, they share the ability to be read from and written to. The power of PHP’s streams is that you can access all of them using the same set of functions, and if there’s something you wish to “stream-ify,” you can write your own “stream wrapper.” In addition to reading and writing, the streams framework in PHP also allows for other operations, such as renaming and deleting.
Read the rest of this entry »
Tags: PHP, streams
Posted in PHP | View Comments
March 31st, 2010
I adapted Fran Rogers’s Lua MediaWiki extension into a library named Looah. It runs Lua code in a sandbox from PHP, which allows you to execute Lua code provided by users. Right now it supports limits on recursion depth, the number of executed lines, and the execution time. However, Looah doesn’t support a memory usage limit, so you still need to be careful in that regard.
There is a PHP extension to run Lua code, but it doesn’t handle sandboxing, so Looah is able to augment that extension (although I have not tested that). Looah can use the Lua binary instead.
The limits on the number of lines executed and recursion depth are enforced by a wrapper written in Lua. Functions are blacklisted according to this list. The time limit is enforced in both the Lua wrapper and outside in PHP, provided that you are not using the Lua extension for PHP. If you use the Lua extension, then only the Lua wrapper is enforcing a time limit, which leaves the risk of a C function called in the Lua script locking up.
Using Looah is very simple:
1 2
| $lua = new Looah();
$result = $lua->execute("print(1234 + 5)"); |
Note that the Lua script cannot call functions in PHP, and the PHP script cannot call functions in Lua. Everything that is returned is also a string.
Tags: Lua, PHP, sandbox
Posted in PHP, Security | View Comments