lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
Apache: ModRewrite Test
A simple test for ModRewrite that I needed this week and find myself searching for every now and again:

# Turn Engine On
RewriteEngine on

# Rewrite Test
RewriteRule ^test_rewrite\.htm$ http://www.klenwell.com/is/ApacheModRewriteTestOk [R]


Full explanation on the wiki: www.klenwell.com/is/

Labels:

PHP: File Upload Errors
Here's an array for use with file uploads:

$PHP_FILE_ERROR = array
(
UPLOAD_ERR_OK => "There is no error, the file uploaded with
success",
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the
upload_max_filesize directive in php.ini",
UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE
directive that was specified in the HTML form",
UPLOAD_ERR_PARTIAL => "The uploaded file was only partially
uploaded",
UPLOAD_ERR_NO_FILE => "No file was uploaded",
UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder",
UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension",
);


More info: Handling file uploads (php.net)

Labels:

Why You Lock Down Your Server
Scanning my (Yule) logs and found this:

205.237.78.206 - - [21/Dec/2007:15:33:22 -0800] "GET /phpMyAdmin-2.5.6/main.phpmain.php HTTP/1.0" 404 346 "-" "-"
205.237.78.206 - - [21/Dec/2007:15:33:22 -0800] "GET /phpMyAdmin-2.5.4/main.phpmain.php HTTP/1.0" 404 346 "-" "-"
205.237.78.206 - - [21/Dec/2007:15:33:23 -0800] "GET /phpMyAdmin-2.5.1/main.phpmain.php HTTP/1.0" 404 346 "-" "-"
205.237.78.206 - - [21/Dec/2007:15:33:23 -0800] "GET /phpMyAdmin-2.2.3/main.phpmain.php HTTP/1.0" 404 346 "-" "-"
205.237.78.206 - - [21/Dec/2007:15:33:23 -0800] "GET /phpMyAdmin-2.9.1/main.phpmain.php HTTP/1.0" 404 346 "-" "-"
205.237.78.206 - - [21/Dec/2007:15:33:23 -0800] "GET /phpMyAdmin-2.9.0/main.phpmain.php HTTP/1.0" 404 346 "-" "-"


And this:
122.126.109.119 - - [24/Dec/2007:13:40:18 -0800] "CONNECT mail2.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:14:23:26 -0800] "CONNECT mail2.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:14:57:22 -0800] "CONNECT mail3.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:15:18:50 -0800] "CONNECT mail3.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:16:07:36 -0800] "CONNECT mail3.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:16:52:45 -0800] "CONNECT mail3.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:17:53:10 -0800] "CONNECT mail2.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:18:34:42 -0800] "CONNECT mail3.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"
122.126.109.119 - - [24/Dec/2007:18:56:36 -0800] "CONNECT mail2.xps.idv.tw:25 HTTP/1.0" 405 353 "-" "-"


I suspect 205.237.78.206 must be hacked.

Merry Christmas.
7-Zip from the Command Line
Looking for practical examples for using 7-Zip from the command line with Linux or Cygwin? I was and wasn't finding much love on the internet. I finally discovered the documentation that comes packaged with 7-Zip and that helped me figure out what I wanted to do.

I've added the examples to my wiki:

7-Zip Command Line Examples

(I'd add them here, but the lines are kinda long and would probably get cut off or broken weirdly.)
PHP: Is Machine Online?
If you're running PHP on a Windows like I am, the following code will quickly tell you whether you are online:

// is machine online? (for XP)
// returns ip if machine is online, false if offline (per ipconf)
/*____________________________________________________________________________*/
function is_machine_online()
{
$ip = false; // return

$re_ip = '%(([0-9]+\.){3}([0-9]+))%'; // ip regex

// WIN only (add ifconfig in future for Unix)
if ( substr( PHP_OS, 0, 3 ) != 'WIN' )
{
trigger_error("this fx currently only works with WIN", E_USER_WARNING);
return false;
}

exec('ipconfig', $OUT, $failed);
if ( $failed ) return false;

foreach ( $OUT as $ln )
{
if ( stripos($ln, 'ip address') === FALSE ) continue;
if ( preg_match($re_ip, $ln, $MATCH) )
{
$ip = $MATCH[0];
break;
}
}

return $ip;
}
/*____________________________________________________________________________*/


Usage:
if ( $test = 1 )
{
$debug = 0;
print 'testing is_machine_online()';
print '<pre>';

// test code here
print $is = ( is_machine_online() ) ? 'is online' : 'not online';

print '</pre>';
}

Labels:

The Greps of Wrath
Careful using grep recursively on directories containing images. I wasn't actually using grep, but the code below to change some relatively specific numeric sequences:

# multiple files
# NOTE: in cygwin on XP must have parameter "-i.tmpbak" which create a backup of each file
# which then get deleted below (remove .tmpbak on Unix to edit directly)
find /dirname -name "*"|xargs perl -w -i.tmpbak -p -e "s/search_text/replace_text/g"

# delete temp files
# with prompt before each delete
find -name "*.tmpbak" -ok rm {} \;

# with no prompt (list first then run again with delete command)
find -name "*.tmpbak"
find -name "*.tmpbak" -delete


End up corrupting all my images -- I assume because it matched the search text I had using. But maybe there was another reason.

Labels: