scripts

Demo Page
Submitted by devans on Tue, 2009-12-15 22:03The following are demo versions or proofs of concept of the ideas outlined in a number of my scripts and projects contained within this site.
All of these web applications will be made Open Source during 2010 and the source code will be made available on this site, in addition to which a forum will be established for the exchange of ideas in support of future enhancements to these projects either by myself or the Open Source community at large.
Stay tuned for this release!
1). Multi or Two Factor Authentication Demo
This solution provides a web-based two-factor or multi-factor (something you know plus something you have) proof of concept using a very low-tech solution much stronger than the traditional token-based variants. Further details are available on the demo site.
2). Dinofile - Secure File Server
This solution provides a web-based secure file transfer and storage system where files are transmitted over SSL and stored in an encrypted (256-bit AES) format on a non web accessible partition.
3). Ad Serving Solution
This solution provides for an Advertisement Serving solution similar in operation to that provided by the largest online agencies.

Minimal Apache Web Server httpd.conf configuration file
Submitted by devans on Wed, 2009-12-09 15:53Following an install of Apache on Windows you are faced with the somewhat daunting process of wading through the httpd.conf file and deciding upon what is required for your particular circumstance.
As a matter of course, I typically save the default httpd.conf file to another name and use a vastly trimmed down variant in place thereof.
What I have pasted below represents such an example and trims the config file to a much more manageable 55-lines of code having stripped the unnecessary elements along with all of the comments.
PidFile logs/httpd.pid
Listen 80
ServerName localhost
ServerTokens Prod
ServerSignature Off
FileETag None
UseCanonicalName Off
HostnameLookups Off
AddDefaultCharset IS-8859-1
ServerAdmin webadmin@localhost
ServerRoot "c:/www/Apache22"

Using Forfiles in a BAT script to Purge Old Data on Windows
Submitted by devans on Fri, 2009-11-13 12:25As somewhat a continuance from my post regarding the use 7-Zip as part of an overall backup solution therein also lies the need for a file retention strategy too.
If we simply allow the creation of daily or weekly backups to run unchecked then dependant upon the size of the archive, the frequency of the backup job and ultimately the amount of available disk space we reach some kind of threshold. This necessitates the need for a retention strategy.

Using 7-Zip in a BAT script as part of your Backup Strategy
Submitted by devans on Fri, 2009-11-13 11:43When performing file compression most people instinctively refer to WinZip. Beginning with Microsoft Windows ME (who can forget that quality release!), the Windows Operating System included their own tool for file compression.
While these along with many others provide a means to an end they are all limited in one particular way or another. Enter 7-Zip!
While I myself have only been using 7-Zip for the past 2 to 3 years it has none the less been around since the latter part of 2001.

PHP Encryption - Example Using Mcrypt
Submitted by devans on Mon, 2008-07-21 12:48What now follows is an example of how to use the Mcrypt encryption function that is part of the PHP scripting language. In order to use Mcrypt with PHP you will need to include the mcrypt library files by editing the php.ini file accordingly.
If you need a primer in what the Mcrypt function is capable of performing I suggest you check out http://us.php.net/manual/en/book.mcrypt.php as I will only be providing an example on how to use the encryption and decryption functionality.
The encryption function used is simply called - mcrypt_encrypt
The decryption function used is simply called - mcrypt_decrypt
Here's an example PHP script that performs both the encryption and decryption function in the same script so you can see it at work.
<?php
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = hash ("md5", "It's all just apples and oranges.");
$text = "The quick brown fox jumps over the lazy dog.";
echo "<p><b>Initialization Vector Size = </b>" .$iv_size." characters</p>";
echo "<p><b>Initialization Vector = </b>" .$iv ."</p>";
echo "<p><b>KEY (Password Used after MD5 Hash) = </b>" .$key. "</p>";
echo "<p><b>Plain Text String Length = </b>" .strlen($text) . " characters</p>";
echo "<p><b><u>Plain Text = </u></b><font color='blue'>" .$text."</font></p>";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv);
echo "<p><b>Encrypted Text String Length = </b>".strlen($crypttext) . " characters</p>";
echo "<p><b><u>Encrypted Text = </u></b><font color='red'>".$crypttext ."</font></p>";
echo "<i>The Mcrypt_decrypt function pads out the RETURN STRING (decrypttext) with null characters '\0' to pad to the same block size as (crypttext), which is in this case 64 characters in length.</i><br>";
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_CBC, $iv);
$decrypted = rtrim($decrypttext, "\0");
echo "<p><b>Decrypted Text (decrypttext) = </b>" .$decrypttext . " - <i>With the nulls used to pad still present. These need to be trimmed off.</i></p>";
echo "<p><b>Decrypted Text (decrypttext) = </b>" .$decrypted . " - <i>With the nulls used to pad out the blocksize of the encrypted text removed.</i></p>";
?>
And here is the what the script returns:
Initialization Vector Size = 32 characters
Initialization Vector = $pÍ£Ûö¹Ôe¤º¨yr ízkO½Z6¨“szö
KEY (Password Used after MD5 Hash) = c54dcf123bf2548c7cdb862ef36e87e0
Plain Text String Length = 44 characters
Plain Text = The quick brown fox jumps over the lazy dog.
Encrypted Text String Length = 64 characters
Encrypted Text = ÙPKàoB,ãU0šÎmÑç{ÛîêPnëkèu¸–…ê`~ì÷Ni‡dݹ!ò×V@ˆKWH„õ„Ò
The Mcrypt_decrypt function pads out the RETURN STRING (decrypttext) with null characters '�' to pad to the same block size as (crypttext), which is in this case 64 characters in length.
Decrypted Text (decrypttext) = The quick brown fox jumps over the lazy dog.�������������������� - With the nulls used to pad still present. These need to be trimmed off.
Decrypted Text (decrypttext) = The quick brown fox jumps over the lazy dog. - With the nulls used to pad out the blocksize of the encrypted text removed.
As you step through the script (top) compare the output above for a self explanatory view of the results of each line. A basic understanding of PHP should be all that is required to grasp what is happening here.
Enjoy!

RSS Feed

