<?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>diginc &#187; code</title>
	<atom:link href="http://diginc.us/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://diginc.us</link>
	<description>\'dij-iŋk\</description>
	<lastBuildDate>Thu, 19 May 2011 14:49:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using IPTables with Dynamic IP hostnames like dyndns.org</title>
		<link>http://diginc.us/linux/2010/using-iptables-with-dynamic-ip-hostnames-like-dyndns-org/</link>
		<comments>http://diginc.us/linux/2010/using-iptables-with-dynamic-ip-hostnames-like-dyndns-org/#comments</comments>
		<pubDate>Wed, 26 May 2010 15:51:42 +0000</pubDate>
		<dc:creator>diginc</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://diginc.us/?p=172</guid>
		<description><![CDATA[Whenever IPTables has a hostname in a rule it looks up the hostname&#8217;s IP address and uses that instead of the actual hostname &#8211; so it&#8217;s stuck with the IP until the next time IPTables is flushed/restarted. Here&#8217;s a quick &#8230; <a href="http://diginc.us/linux/2010/using-iptables-with-dynamic-ip-hostnames-like-dyndns-org/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Whenever IPTables has a hostname in a rule it looks up the hostname&#8217;s IP address and uses that instead of the actual hostname &#8211; so it&#8217;s stuck with the IP until the next time IPTables is flushed/restarted.  Here&#8217;s a quick little python script to stick in a crontab which checks the IP of your dynamic IP hostname (free ones provided by dyndns.org) and will restart iptables if it catches a change in your hostname.  The script was made for CentOS so should work on Red Hat based distributions &#8211; if you don&#8217;t have an /etc/init.d/iptables file you&#8217;ll have to modify the reload iptables command in the source.  Viewable Source After Jump</p>
<p>I just set this up as root and in root&#8217;s crontab.</p>
<p><a href="/examples/iptables_dyndns_update.py">Download Source</a></p>
<p><span id="more-172"></span></p>
<p><strong>Source:</strong></p>

<div class="wp_codebox"><table><tr id="p1723"><td class="code" id="p172code3"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> gettextoutput<span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Return (status, output) of executing cmd in a shell.&quot;&quot;&quot;</span>
    pipe = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'{ '</span> + <span style="color: #dc143c;">cmd</span> + <span style="color: #483d8b;">'; } 2&gt;&amp;1'</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
    pipe = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span> + <span style="color: #483d8b;">' 2&gt;&amp;1'</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
    text = pipe.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> text<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>: text = text<span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> text
&nbsp;
home_dyndns = <span style="color: #483d8b;">&quot;example.dyndns.org&quot;</span>
log_dyndns = <span style="color: #483d8b;">&quot;./new_home_ip_check.log&quot;</span>
last_dyndns = gettextoutput<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cat &quot;</span> + log_dyndns<span style="color: black;">&#41;</span>
cur_dyndns = gettextoutput<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;host &quot;</span> + home_dyndns<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Log: &quot;</span>+ last_dyndns
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Cur: &quot;</span>+ cur_dyndns
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> last_dyndns == cur_dyndns:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;IPs match, no restart necessary&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Updating last IP with current&quot;</span>
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;echo '&quot;</span> + cur_dyndns + <span style="color: #483d8b;">&quot;' &gt; &quot;</span> + log_dyndns<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Restarting iptables to update&quot;</span>
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/etc/init.d/iptables restart&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Output looks like:</strong></p>

<div class="wp_codebox"><table><tr id="p1724"><td class="code" id="p172code4"><pre class="bash" style="font-family:monospace;">Log: example.dyndns.org has address 114.76.37.112
Cur: example.dyndns.org has address 114.76.37.112
IPs match, no restart necessary
&nbsp;
Log: example.dyndns.org has address 114.76.37.113
Cur: example.dyndns.org has address 114.76.37.112
Updating <span style="color: #c20cb9; font-weight: bold;">last</span> IP with current
Restarting iptables to update
Flushing firewall rules:                                   <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Setting chains to policy ACCEPT: filter                    <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Unloading iptables modules:                                <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Applying iptables firewall rules:                          <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Loading additional iptables modules: ip_conntrack_netbios_n<span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://diginc.us/linux/2010/using-iptables-with-dynamic-ip-hostnames-like-dyndns-org/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Bash Script: Confirm domains in your DNS Bind server are still pointed at your address (haven&#8217;t moved to other DNS)</title>
		<link>http://diginc.us/linux/2010/bash-script-confirm-domains-in-your-dns-bind-server-are-still-pointed-at-your-address-havent-moved-to-other-dns/</link>
		<comments>http://diginc.us/linux/2010/bash-script-confirm-domains-in-your-dns-bind-server-are-still-pointed-at-your-address-havent-moved-to-other-dns/#comments</comments>
		<pubDate>Fri, 07 May 2010 16:02:13 +0000</pubDate>
		<dc:creator>diginc</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Bind]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://diginc.us/?p=161</guid>
		<description><![CDATA[Here&#8217;s a quick script I wrote last year which I forgot about until today. I thought I should share it since it works fairly well with some modifications &#8211; it could be refined/improved quite a bit; I&#8217;m not the best &#8230; <a href="http://diginc.us/linux/2010/bash-script-confirm-domains-in-your-dns-bind-server-are-still-pointed-at-your-address-havent-moved-to-other-dns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick script I wrote last year which I forgot about until today.  I thought I should share it since it works fairly well with some modifications &#8211; it could be refined/improved quite a bit; I&#8217;m not the best bash/shell scripter.  Be prepared to get your hands dirty with mods if you want to use this.  Here&#8217;s a quick run down &#038; description of what&#8217;s going on.</p>
<p>The script&#8217;s input is the bind9 file containing all zone entries you want to confirm are pointed to your server, I suggest making a copy &#8211; not working with any live configs.  The script will run an lookup using `<code>host -t ns</code>` on google&#8217;s DNS server to find out what the outside world thinks the domains&#8217; name servers are; I tried `<code>whois</code>` in the past but it was too unreliable due to timeouts &#038; limits on the number of calls per minute.  Then it checks the results of that host lookup against the hostnames, all capitalized hostnames, and IP addresses of your DNS servers (3 in my case).  If any one of the DNS servers matches than we know the domain is still using our DNS.  The other options are 1) it doesn&#8217;t find any DNS servers that are ours 2) it finds the phrase &#8216;not found&#8217; which host returns if the domain is expired or there are no &#8216;NS&#8217; type records in DNS.  The script echos to shell what DNS servers match as it runs, but it only logs the DNS servers that don&#8217;t have any matches (so they can be removed by automation or manually later).</p>
<p>With the zone-audit.log output I then can remove the domains that aren&#8217;t using our DNS since they&#8217;re no longer in use.  Please leave feedback in the comments if you think of a good improvement.</p>
<p>Code after the jump or <a href="/examples/confirm-dns-zones.php">Here</a><br />
<span id="more-161"></span></p>

<div class="wp_codebox"><table><tr id="p1616"><td class="code" id="p161code6"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">domains</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'s/^zone\s*\&quot;\([^\&quot;]*\)\&quot;\s* {[^\r]*/\1/p'</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>confirm-dns-zones<span style="color: #000000; font-weight: bold;">/</span>named.master<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>confirm-dns-zones<span style="color: #000000; font-weight: bold;">/</span>zone-audit.log
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$domains</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Checking <span style="color: #007800;">$i</span>&quot;</span>
  <span style="color: #007800;">domain_ns</span>=<span style="color: #000000; font-weight: bold;">`</span>host <span style="color: #660033;">-t</span> ns <span style="color: #007800;">$i</span> 8.8.8.8 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$domain_ns</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'NS1.EXAMPLE'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'ns1.example'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'4.3.2.1'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> contains DNS1 (4.3.2.1)&quot;</span>
    <span style="color: #007800;">match_dns1</span>=TRUE
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;">#echo &quot;DNS1 NOT FOUND&quot;</span>
    <span style="color: #007800;">match_dns1</span>=FALSE
  <span style="color: #000000; font-weight: bold;">fi</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'NS2.EXAMPLE'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'ns2.example'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'4.3.2.2'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> contains DNS2 (4.3.2.2)&quot;</span>
    <span style="color: #007800;">match_dns2</span>=TRUE
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;">#echo &quot;DNS2 NOT FOUND&quot;</span>
    <span style="color: #007800;">match_dns2</span>=FALSE
  <span style="color: #000000; font-weight: bold;">fi</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'NS3.EXAMPLE'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'ns3.example'</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'4.3.2.3'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> contains DNS3 (4.3.2.3)&quot;</span>
    <span style="color: #007800;">match_dns3</span>=TRUE
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;">#echo &quot;DNS3 NOT FOUND&quot;</span>
    <span style="color: #007800;">match_dns3</span>=FALSE
  <span style="color: #000000; font-weight: bold;">fi</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$match_dns1</span> == FALSE <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">$match_dns2</span> == FALSE <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">$match_dns3</span> == FALSE <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;* ERROR: <span style="color: #007800;">$i</span> - None of our DNS found for this domain using 8.8.8.8&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>confirm-dns-zones<span style="color: #000000; font-weight: bold;">/</span>zone-audit.log
  <span style="color: #000000; font-weight: bold;">fi</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$domain_ns</span> =~ <span style="color: #ff0000;">'not found'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;* Possible script error or missing DNS / Expired domain&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;* ERROR: <span style="color: #007800;">$i</span> - Possible script error or missing DNS / Expired domain&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>confirm-dns-zones<span style="color: #000000; font-weight: bold;">/</span>zone-audit.log
  <span style="color: #000000; font-weight: bold;">fi</span> 
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;----------------&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span>
  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://diginc.us/linux/2010/bash-script-confirm-domains-in-your-dns-bind-server-are-still-pointed-at-your-address-havent-moved-to-other-dns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Encrypt forms&#8217; passwords before submitting with jquery</title>
		<link>http://diginc.us/code/2010/encrypt-forms-passwords-before-submitting-with-jquery/</link>
		<comments>http://diginc.us/code/2010/encrypt-forms-passwords-before-submitting-with-jquery/#comments</comments>
		<pubDate>Wed, 05 May 2010 19:49:07 +0000</pubDate>
		<dc:creator>diginc</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://diginc.us/?p=153</guid>
		<description><![CDATA[If a site&#8217;s login/registration isn&#8217;t encrypted using SSL why would you risk sending a user&#8217;s password in plain text to the form&#8217;s processing script? Because you didn&#8217;t know any better and didn&#8217;t read this how-to, that&#8217;s why. With today&#8217;s average &#8230; <a href="http://diginc.us/code/2010/encrypt-forms-passwords-before-submitting-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If a site&#8217;s login/registration isn&#8217;t encrypted using SSL why would you risk sending a user&#8217;s password in plain text to the form&#8217;s processing script?  Because you didn&#8217;t know any better and didn&#8217;t read this how-to, that&#8217;s why.  With today&#8217;s average computer and connection speed adding a little encryption and downloading small library (in addition to jquery&#8217;s 76k or so) isn&#8217;t a big deal.  Here&#8217;s how I&#8217;m encrypting a password before form submission:</p>
<p><a href="/examples/pre-encrypt-password.php">Browser/Client side password encryption example</a><br />
<a href="/examples/pre-encrypt-password.zip">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://diginc.us/code/2010/encrypt-forms-passwords-before-submitting-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: diginc.us @ 2012-05-19 22:50:27 -->
