<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brady &#187; Code and Snippets</title>
	<atom:link href="http://l3rady.com/category/code-and-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://l3rady.com</link>
	<description>A moan, a groan, my life story and how me, a technically minded person just can't seem to fit in with anybody.</description>
	<lastBuildDate>Sat, 12 Jun 2010 22:25:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>CSS Dotted/Dashed HR Style</title>
		<link>http://l3rady.com/2009/10/13/css-dotteddashed-hr-style/</link>
		<comments>http://l3rady.com/2009/10/13/css-dotteddashed-hr-style/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 16:35:50 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=446</guid>
		<description><![CDATA[Ever had problems styling an HR element to be dotted or dashed and look correct in all browsers? Well here is a simple solution for you: hr.{ background-color:#fff; border:#000 1px dotted; border-style: none none dotted; color:#fff; }]]></description>
			<content:encoded><![CDATA[<p>Ever had problems styling an HR element to be dotted or dashed and look correct in all browsers?</p>
<p>Well here is a simple solution for you:</p>
<pre class="brush: css">
hr.{
	background-color:#fff;
	border:#000 1px dotted;
	border-style: none none dotted;
	color:#fff;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2009/10/13/css-dotteddashed-hr-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Get users SID from Active Directory via LDAP (objectsid)</title>
		<link>http://l3rady.com/2009/09/15/php-get-users-sid-from-active-directory-via-ldap-objectsid/</link>
		<comments>http://l3rady.com/2009/09/15/php-get-users-sid-from-active-directory-via-ldap-objectsid/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 10:39:50 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=435</guid>
		<description><![CDATA[Have you ever needed to read an AD users SID so you can use it as the unique identifier it is? Well I did but when I read out objectsid from AD for a user I found a load of weird symbols. It turned out that the data outputted was binary data. So after some [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed to read an AD users SID so you can use it as the unique identifier it is?</p>
<p>Well I did but when I read out objectsid from AD for a user I found a load of weird symbols. It turned out that the data outputted was binary data. So after some digging around to see how to translate the binary data to a human readable SID like S-1-5-21-823795046-756116320-56781596-16683 I got to work to write a PHP script that could do just that.</p>
<p>This is what I came up with:</p>
<pre class="brush: php">$suffix =&quot;@sub.mydomain.co.uk&quot;;
$base_dn = &quot;dc=sub,dc=mydomain,dc=co,dc=uk&quot;;
$server = &quot;127.0.0.1&quot;;

$USERNAME = &quot;username&quot;;
$PASSWORD = &quot;password&quot;;

$USERNAMETOSEARCH = &quot;user to get sid&quot;;

$ds = ldap_connect($server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$r = ldap_bind($ds, $USERNAME.$suffix, $PASSWORD);
$sr = ldap_search($ds, $base_dn, &quot;(samaccountname=&quot;.$USERNAMETOSEARCH.&quot;)&quot;);
$entries = ldap_get_entries($ds, $sr);

// All SID&#039;s begin with S-
$sid = &quot;S-&quot;;
// Convert Bin to Hex and split into byte chunks
$sidinhex = str_split(bin2hex($entries[0][&#039;objectsid&#039;][0]), 2);
// Byte 0 = Revision Level
$sid = $sid.hexdec($sidinhex[0]).&quot;-&quot;;
// Byte 1-7 = 48 Bit Authority
$sid = $sid.hexdec($sidinhex[6].$sidinhex[5].$sidinhex[4].$sidinhex[3].$sidinhex[2].$sidinhex[1]);
// Byte 8 count of sub authorities - Get number of sub-authorities
$subauths = hexdec($sidinhex[7]);
//Loop through Sub Authorities
for($i = 0; $i &lt; $subauths; $i++) {
	$start = 8 + (4 * $i);
	// X amount of 32Bit (4 Byte) Sub Authorities
	$sid = $sid.&quot;-&quot;.hexdec($sidinhex[$start+3].$sidinhex[$start+2].$sidinhex[$start+1].$sidinhex[$start]);
}

echo $sid;</pre>
<p>Now this is written in PHP but I&#8217;m sure this code can be pretty much be translated to any other language.</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2009/09/15/php-get-users-sid-from-active-directory-via-ldap-objectsid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Active Directory &#8211; Reading UserAccountControl</title>
		<link>http://l3rady.com/2009/09/14/php-active-directory-reading-useraccountcontrol/</link>
		<comments>http://l3rady.com/2009/09/14/php-active-directory-reading-useraccountcontrol/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 13:33:16 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=432</guid>
		<description><![CDATA[At the moment I&#8217;m doing a lot of work with Microsoft Active Directory and PHP. I&#8217;m building a few tools in PHP which reads data out of AD. Now one of the things I wanted to read out was to see if the account was locked or if its password never expired. I couldn&#8217;t find [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment I&#8217;m doing a lot of work with Microsoft Active Directory and PHP. I&#8217;m building a few tools in PHP which reads data out of AD.</p>
<p>Now one of the things I wanted to read out was to see if the account was locked or if its password never expired. I couldn&#8217;t find these entries in AD but after searching those entries are stored in &#8220;useraccountcontrol&#8221;. But when I looked it was just a number. How does that number tell you if the account is locked?</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms680832(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms680832(VS.85).aspx</a></p>
<p>On the above link is how that number is generated and once I understood that I got to work on writing a PHP script which translates that number into something more usable. Once I wrote the script I put it up on the Hot Scripts Forum to see if the code I wrote could be improved on and optimised. Here is what they came back with:</p>
<pre class="brush: php">
$userAccountArray = array(
  &#039;ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION&#039; =&gt; 0,
  &#039;ADS_UF_PASSWORD_EXPIRED&#039; =&gt; 0,
  &#039;ADS_UF_DONT_REQUIRE_PREAUTH&#039; =&gt; 0,
  &#039;ADS_UF_USE_DES_KEY_ONLY&#039; =&gt; 0,
  &#039;ADS_UF_NOT_DELEGATED&#039; =&gt; 0,
  &#039;ADS_UF_TRUSTED_FOR_DELEGATION&#039; =&gt; 0,
  &#039;ADS_UF_SMARTCARD_REQUIRED&#039; =&gt; 0,
  &#039;ADS_UF_MNS_LOGON_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_DONT_EXPIRE_PASSWD&#039; =&gt; 0,
  &#039;NOT_USED_8000&#039; =&gt; 0,
  &#039;NOT_USED_4000&#039; =&gt; 0,
  &#039;ADS_UF_SERVER_TRUST_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_WORKSTATION_TRUST_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_INTERDOMAIN_TRUST_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_NORMAL_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_TEMP_DUPLICATE_ACCOUNT&#039; =&gt; 0,
  &#039;ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED&#039; =&gt; 0,
  &#039;ADS_UF_PASSWD_CANT_CHANGE&#039; =&gt; 0,
  &#039;ADS_UF_PASSWD_NOTREQD&#039; =&gt; 0,
  &#039;ADS_UF_LOCKOUT&#039; =&gt; 0,
  &#039;ADS_UF_HOMEDIR_REQUIRED&#039; =&gt; 0,
  &#039;NOT_USED_4&#039; =&gt; 0,
  &#039;ADS_UF_ACCOUNTDISABLE&#039; =&gt; 0,
  &#039;ADS_UF_SCRIPT&#039; =&gt; 0
);

function ADUserAccountControl($val) {
	global $userAccountArray;
	$x = pow(2, count($userAccountArray) - 1);
	foreach($userAccountArray as $k =&gt; $v) {
		if(($val - $x) &gt;= 0){
			$userAccountArray[$k] = 1;
			$val -= $x;
		} else {
			$userAccountArray[$k] = 0;
		}
		$x = $x / 2;
	}
}
</pre>
<p>Simply pass your useraccountcontrol value to the function and read the results out of the array.</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2009/09/14/php-active-directory-reading-useraccountcontrol/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript Same Height Div&#8217;s Update</title>
		<link>http://l3rady.com/2008/08/14/javascript-same-height-divs-update/</link>
		<comments>http://l3rady.com/2008/08/14/javascript-same-height-divs-update/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 15:26:39 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=352</guid>
		<description><![CDATA[A while back I posted a way of making same height div’s but came across an issue when padding was involved. Well I’ve modified my code to take into account padding. Now the obvious thing to do would be to be to check padding on a div and subtract it from the height, but it’s [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I posted a way of making same height div’s but came across an issue when padding was involved. Well I’ve modified my code to take into account padding. Now the obvious thing to do would be to be to check padding on a div and subtract it from the height, but it’s not that easy. You would have to check three things: padding, paddingTop and paddingBottom. For some reason when I was checking padding I couldn’t get a value from JavaScript, this had me really stumped but after a nights sleep I came up with a better and more simpler way of sorting the padding issue. This is to let the code run and let it re-height the div’s and let the padding mess things up then run the same thing again and check for height differences from last time we checked. Oooohhh look the height has gone up 10px from last time thanks to a padding of 5px on the div. Now we know there is 10px of padding lets remove it. Sorted!</p>
<p>JavaScript Code:</p>
<pre class="brush: js">
function sameHeight(divs) // Bring in an array of your divs
{
var highest = 0;
var heighttu = 0;
for(i = 0; i &lt; divs.length; i++) // Loop through the divs
{
// Check to see if this div is the highest?
if(document.getElementById(divs[i]).offsetHeight &gt; highest)
{
// Yes its the highest so set the highest value to this div&#039;s height
highest = document.getElementById(divs[i]).offsetHeight;
}
}
// Loop through divs and set their hieght all the same
for(i = 0; i &lt; divs.length; i++)
{
document.getElementById(divs[i]).style.height = highest+&quot;px&quot;;
}
// now get offset hieght again and we may found we have gone higher this is because of padding
if(document.getElementById(divs[0]).offsetHeight &gt; highest)
{
// correct the height
highest = highest - (document.getElementById(divs[0]).offsetHeight - highest);
// Correct divs
for(i = 0; i &lt; divs.length; i++)
{
document.getElementById(divs[i]).style.height = highest+&quot;px&quot;;
}
}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2008/08/14/javascript-same-height-divs-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Same Height Div&#8217;s</title>
		<link>http://l3rady.com/2008/06/05/javascript-same-height-divs/</link>
		<comments>http://l3rady.com/2008/06/05/javascript-same-height-divs/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 10:50:25 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=90</guid>
		<description><![CDATA[Recently I had to make some divs the same height. Usually I would just pad the bottom of a div with page breaks but I couldn’t do that this time round as the page content is dynamic and the height of the divs could change. First thing I did was look online for answers and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to make some divs the same height. Usually I would just pad the bottom of a div with page breaks but I couldn’t do that this time round as the page content is dynamic and the height of the divs could change.</p>
<p>First thing I did was look online for answers and sure enough there were solutions but looking at them they seemed over complicated so I decided to write my own solution.</p>
<p>Javascript Code:</p>
<p>Update at: <a href="http://l3rady.com/2008/08/14/javascript-same-height-divs-update/">http://l3rady.com/2008/08/14/javascript-same-height-divs-update/</a></p>
<p>Simply pass an array of your divs to the function. Easy peasy&#8230;.</p>
<p>Just an extra word of warning&#8230; Be aware of using padding on the blocks you pass to this function. If the paddings are different in each block then they may not end up being the same height. Although you could modify the function to check for the use of padding and alter the heights accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2008/06/05/javascript-same-height-divs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Windows HDD usage with PHP and SNMP</title>
		<link>http://l3rady.com/2008/05/28/getting-windows-hdd-usage-with-php-and-snmp/</link>
		<comments>http://l3rady.com/2008/05/28/getting-windows-hdd-usage-with-php-and-snmp/#comments</comments>
		<pubDate>Wed, 28 May 2008 07:17:52 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=89</guid>
		<description><![CDATA[At work a couple of months back I was faced with a problem that many of our servers would run out of hard drive space without us knowing and that would cause the server to hang and/or stop responding. So I did a bit of research and came across. This little utilility would run on [...]]]></description>
			<content:encoded><![CDATA[<p>At work a couple of months back I was faced with a problem that many of our servers would run out of hard drive space without us knowing and that would cause the server to hang and/or stop responding. So I did a bit of research and came across. This little utilility would run on the server in command line and tell you what drives were available and some info of the drives like space used and available. Well with this I would echo out the data to a text file and send that across to a common holding ground. Then from there get my web server to constantly scan this folder for new logs. This method worked but it had its issues.</p>
<p>Well yesterday at work I was playing around with SNMP and after finding a site with <a href="http://snmpboy.msft.net/pub/w2kmibs/">W2K MIBS</a> I found lots of info you can pull from the server. Now I was already familiar with SNMP in PHP thanks to their <a href="http://uk.php.net/snmp">documentation</a> on their site. So using their snmpwalk function I was able to pull the relevant data to get HDD usage info.</p>
<pre class="brush: php">
$names = snmpwalk($row[&#039;ip&#039;], &quot;public&quot;, &#039;.1.3.6.1.2.1.25.2.3.1.3&#039;);
$used = snmpwalk($row[&#039;ip&#039;], &quot;public&quot;, &#039;.1.3.6.1.2.1.25.2.3.1.6&#039;);
$total = snmpwalk($row[&#039;ip&#039;], &quot;public&quot;, &#039;.1.3.6.1.2.1.25.2.3.1.5&#039;);
$alloc = snmpwalk($row[&#039;ip&#039;], &quot;public&quot;, &#039;.1.3.6.1.2.1.25.2.3.1.4&#039;);
</pre>
<p>Now that would give me an array of drive names, space used on those drives, total space available on those drives and the allocation units. Now the allocation units I didn&#8217;t realize I needed as I thought the numbers given in used and total were just measured in bytes but they aren&#8217;t. The numbers in used and total are how many blocks of allocation size (if that makes sense). So to get the true byte value from used and total you need to multiply them by the allocation size number.</p>
<p><em>25599569 * 4096 = 104855834624B = 97.65GB</em></p>
<p>So there you have it. Now you know how to get HDD usage from your server using PHP and SNMP.</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2008/05/28/getting-windows-hdd-usage-with-php-and-snmp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP File Upload Progress Bar Part 2</title>
		<link>http://l3rady.com/2008/02/07/php-file-upload-progress-bar-part-2/</link>
		<comments>http://l3rady.com/2008/02/07/php-file-upload-progress-bar-part-2/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 13:30:38 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://l3rady.com/2008/02/07/php-file-upload-progress-bar-part-2/</guid>
		<description><![CDATA[After further investigation PHP 5.2.0 now allows you to use the APC (Alternative PHP Cache) addition with the ability to track the progress of uploads. Within windows it is as simply adding the dll extension to your php.ini and putting some configs there to. With Linux I&#8217;m not too sure how you add this extension as [...]]]></description>
			<content:encoded><![CDATA[<p>After further investigation PHP 5.2.0 now allows you to use the APC (Alternative PHP Cache) addition with the ability to track the progress of uploads. Within windows it is as simply adding the dll extension to your php.ini and putting some configs there to. With Linux I&#8217;m not too sure how you add this extension as I don&#8217;t know Linux well. But anyway below is some nice and easy documentation on this.</p>
<p><a href="http://www.ibm.com/developerworks/library/os-php-v525/index.html">PHP File Upload Progress Bar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2008/02/07/php-file-upload-progress-bar-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP File Upload Progress Bar</title>
		<link>http://l3rady.com/2008/02/05/php-file-upload-progress-bar/</link>
		<comments>http://l3rady.com/2008/02/05/php-file-upload-progress-bar/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 21:34:22 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://l3rady.com/2008/02/05/php-file-upload-progress-bar/</guid>
		<description><![CDATA[As you may be aware in php it doesn’t have the functionality to report back the status of file uploads. For example upload percent complete, speed of upload and estimated time of completion. To be able to provide a progress bar the easiest way would be to use a perl script to do the uploading [...]]]></description>
			<content:encoded><![CDATA[<p>As you may be aware in php it doesn’t have the functionality to report back the status of file uploads. For example upload percent complete, speed of upload and estimated time of completion. To be able to provide a progress bar the easiest way would be to use a perl script to do the uploading for you as perl has this functionality. Now I build a file uploader for the public and I looked at providing a perl uploader but because I know very little about the language of perl I couldn’t get any examples to work for me, but the ones that did work needed some server side changes. These server side changes would be no good for most of my downloader’s as many of them don’t have root access to their server.</p>
<p>There is another solution out there but once again it involves making server side changes which hacks php and adds the additional functions to track the upload progress of a file.</p>
<p>The above hack for PHP can be found at http://pecl.php.net/package/uploadprogress. There isn’t much documentation out there for it but if you do a Google search you will find one or two examples.</p>
<p>The above hack I’m thinking about putting it in my module so that those that have the modified php will be able to run my uploader with the progress bar but those without would not get the upload progress bar. The thing in to build my module to use this hack I need a server that is running the hacked version of php. Thing is I’m stuck with a shared hosting account and I don’t have access to modify php. So if there is anyone out there that can lend me some space for a short time and is running the above hack please contact me so I can’t continue building my file uploader script</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2008/02/05/php-file-upload-progress-bar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ajax and JavaScript Exploiting</title>
		<link>http://l3rady.com/2007/08/18/ajax-and-javascript-exploiting/</link>
		<comments>http://l3rady.com/2007/08/18/ajax-and-javascript-exploiting/#comments</comments>
		<pubDate>Sat, 18 Aug 2007 17:12:04 +0000</pubDate>
		<dc:creator>Brady</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://l3rady.com/?p=17</guid>
		<description><![CDATA[You may be aware of website-codes.com if not let me tell you. The idea of it was to provide php scripts that could run from any webhost that didn&#8217;t have php support. How I would achieve this would be through a line of JavaScript that user would put on their site. Well the website has [...]]]></description>
			<content:encoded><![CDATA[<p>You may be aware of website-codes.com if not let me tell you. The idea of it was to provide php scripts that could run from any webhost that didn&#8217;t have php support. How I would achieve this would be through a line of JavaScript that user would put on their site. Well the website has been put on hold as I haven&#8217;t found time to code it.</p>
<p>Well anyway because I&#8217;ve been doing a lot of Ajax and JavaScript coding for where I work it had me thinking. If you could get Ajax to work on any webhost with only putting one line of code on their site? Well sure enough you can. I did a bit of testing there and then and it worked 100%. I couldn&#8217;t believe it. Because with JavaScript you can literally change the whole look and feel of a webpage, if you think hard enough you can see how this can be very dangerous to people’s websites. One thing that comes straight to mind is that you can use this one line of code to turn a whole page into a login page look-a-like (phishing) I now see why many public pages don&#8217;t allow JavaScript. E.G. MySpace.</p>
]]></content:encoded>
			<wfw:commentRss>http://l3rady.com/2007/08/18/ajax-and-javascript-exploiting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
