<?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:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
>

<channel>
  <title>AskApache Search Results: </title>
  <link>http://www.askapache.com/osq?</link>
  <description>Web Development</description>
  <pubDate>Sun, 06 Jul 2008 21:33:32 +0000</pubDate>
  <generator>AskApache</generator>
  <language>en</language>

  <openSearch:totalResults>30</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>10</openSearch:itemsPerPage>

                    <item>
          <title>.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</title>
          <link>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html</link>
          <comments>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html#comments</comments>
          <pubDate>Sun, 06 Jul 2008 19:18:12 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[Security]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[WordPress Plugins]]></category>

		<category><![CDATA[htaccess]]></category>

          <guid>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html</guid>
                      <description><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/07/http-security-askapache.png'><img src="http://z.askapache.com/uploads/2008/07/http-security-askapache-165x200.png" alt="" title="http-security-askapache" width="165" height="200" class="alignnone size-thumbnail wp-image-1054" /></a>I finally got around to updating this plugin, its now half-way decent code-wise.  I've added a lot of new security modules and improved the old ones.  The original plugin page and description <a href="http://www.askapache.com/wordpress/htaccess-password-protect.html">can be found here</a>.<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/07/http-security-askapache.png'><img src="http://z.askapache.com/uploads/2008/07/http-security-askapache-165x200.png" alt="" title="http-security-askapache" width="165" height="200" class="alignnone size-thumbnail wp-image-1054" /></a>I finally got around to updating this plugin, its now half-way decent code-wise.  I&#8217;ve added a lot of new security modules and improved the old ones.  The original plugin page and description <a href="http://www.askapache.com/wordpress/htaccess-password-protect.html">can be found here</a>.  You can thank <a href="http://ocaoimh.ie/2008/07/03/more-ways-to-stop-spammers-and-unwanted-traffic/">this guy</a> for this update, his article about blocking spam with .htaccess inspired me to do it.<br class="C" /></p>
<h2>.htaccess Security Modules</h2>
<ul class="ul1">
<li id="l-sid700" class="alternate">
<p><strong>Directory Protection</strong><br />Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="http://www.askapache.com/htaccess/apache-htaccess.html">Disable</a>]</p>
</li>
<li id="l-sid800">
<p><strong>Password Protect wp-login.php</strong><br />Requires a valid user/pass to access the login page - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
</li>
<li id="l-sid900" class="alternate">
<p><strong>Password Protect wp-admin</strong><br />Requires a valid user/pass to access any non-static (css, js, images) file in this directory. - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
</li>
<li id="l-sid1000">
<p><strong>Protect wp-content</strong><br />Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
</li>
<li id="l-sid1010" class="alternate">
<p><strong>Protect wp-includes</strong><br />Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1011">
<p><strong>Common Exploits</strong><br />Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1012" class="alternate">
<p><strong>Stop Hotlinking</strong><br />Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1015">
<p><strong>Safe Request Methods</strong><br />Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a> - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1017" class="alternate">
<p><strong>Forbid Proxies</strong><br />Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1018">
<p><strong>Real wp-comments-post.php</strong><br />Denies any POST attempt made to a non-existing wp-comments-post.php - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1019" class="alternate">
<p><strong>HTTP PROTOCOL</strong><br />Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only  - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1020">
<p><strong>SPECIFY CHARACTERS</strong><br />Denies any request for a url containing characters other than &#8220;a-zA-Z0-9.+/-?=&#038;&#8221;  - REALLY helps but may break your site depending on your links. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1021" class="alternate">
<p><strong>BAD Content Length</strong><br />Denies any POST request that doesnt have a Content-Length Header - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1022">
<p><strong>BAD Content Type</strong><br />Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1023" class="alternate">
<p><strong>Directory Traversal</strong><br />Denies Requests containing ../ or ./. which is a directory traversal exploit attempt - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1024">
<p><strong>PHPSESSID Cookie</strong><br />Only blocks when a PHPSESSID cookie is sent by the user and it contains characters other than 0-9a-z - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1025" class="alternate">
<p><strong>NO HOST:</strong><br />Denies requests that dont contain a HTTP HOST Header. - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1026">
<p><strong>Bogus Graphics Exploit</strong><br />Denies obvious exploit using bogus graphics  - *** Safe, Use. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1027" class="alternate">
<p><strong>No UserAgent, No Post</strong><br />Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1028">
<p><strong>No Referer, No Comment</strong><br />Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1029" class="alternate">
<p><strong>Trackback Spam</strong><br />Denies obvious trackback spam.   See <a href="http://ocaoimh.ie/2008/07/03/more-ways-to-stop-spammers-and-unwanted-traffic/">Holy Shmoly!</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
</li>
<li id="l-sid1030">
<p><strong>SSL-Only Site</strong><br />Redirects all non-SSL (https) requests to your https-enabled url [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-301">301</a>]</p>
</li>
<li id="l-sid2000" class="alternate">
<p><strong>Anti-Spam, Anti-Exploits</strong><br />Denies Obvious Spam and uses advanced mod_security protection [<a href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html">Read More</a>]</p>
</li>
</ul>
<h2>.htaccess Security Module Screenshot</h2>
<p><a rel="lb" href='http://z.askapache.com/uploads/2008/07/http-security-askapache.png'><img src="http://z.askapache.com/uploads/2008/07/http-security-askapache1.png" alt="" title="http-security-askapache1" /></a></p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Encrypted WordPress Site Backups</title>
          <link>http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html</link>
          <comments>http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html#comments</comments>
          <pubDate>Fri, 04 Jul 2008 16:28:00 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[Linux Unix BSD]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Shell Scripting]]></category>

		<category><![CDATA[WordPress]]></category>

          <guid>http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html</guid>
                      <description><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/07/sbackup.png'><img src="http://z.askapache.com/uploads/2008/07/sbackup-132x200.png" alt="Bash Shell Script for Encrypted WordPress Backups" title="Bash Shell Script for Encrypted WordPress Backups" width="132" height="200" /></a>Enter your DOMAIN_ROOT and the location of your wp-config.php, and this script finds all the mysql settings by parsing the wp-config.php file, creates GPG encrypted backups, and saves your settings for future quickness.<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/07/sbackup.png'><img src="http://z.askapache.com/uploads/2008/07/sbackup-264x400.png" alt="Bash Shell Script for Encrypted WordPress Backups" title="Bash Shell Script for Encrypted WordPress Backups" width="264" height="400" /></a>Because backups contain all your sensitive information, its smart to encrypt any sql backups.. and while we&#8217;re at it, also encrypt any site backups.</p>
<p>This simple shell-script is a useful and easy way to securely backup your wordpress site files and database without confusing you.  Just generate a GPG key once, enter in 3 settings once, and from then on it runs without any user-input whenever you want.<br class="C" /></p>
<h2>What it Does</h2>
<p>When run, this script asks you for the location of your websites document root and the location of your wp-config.php file.  It also asks you for your encryption UID.  Then this script saves those settings in a file called .sbackup so that the next time you run the script it will run without having to re-enter that information, making it nice for cronjobs or quick and easy on-demand backups.  Another cool feature that I added is this script automatically parses your wp-config.php file for the mysql database name, user, host, and password, meaning you don&#8217;t have to compromise your security or take the time to type those settings in manually.</p>
<h2>What is Backed Up</h2>
<p>This script creates a tarred and gzipped archive of your entire document root in the folder <code>~/backups/domain.com/domain.com-date.tgz</code> and also creates a backup of your WordPress database in a format that is ideal for restoring from.  Both of these files are then encrypted using your GPG key and can then be safely downloaded as a password and key is required to decrypt them.</p>
<h2>Generating a GPG Key</h2>
<p>If you don&#8217;t already have one setup for your shell account run this command remembering the uid which you will enter in the shell script.</p>
<pre>
gpg &#45;-gen-key
</pre>
<h3>Decrypting Files</h3>
<pre>
gpg -r UID &#45;-output FILENAME.tgz &#45;-decrypt FILENAME.tgz.asc
</pre>
<h2>The Shell Script</h2>
<p><a href='http://z.askapache.com/uploads/2008/07/site-backup.sh'>site-backup</a></p>
<pre>
#!/bin/bash
# SiteBack Version 3.1, 2008-07-04
# GNU Free Documentation License 1.2
# 07-04-08 - AskApache (www.askapache.com)
umask 022
&nbsp;
### SHELL OPTIONS
set +o noclobber # allowed to clobber files
set +o noglob # globbing on
set +o xtrace # change to - to enable tracing
set +o verbose # change to - to enable verbose debugging
set -e # abort on first error
&nbsp;
shopt -s extglob
&nbsp;
###########################################################################&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
###
### SETTINGS
###
###########################################################################==-==-==-==-==-==-==-==-==-==-==#
&nbsp;
DT=$(date +%x); DT=${DT//\/}
DTX=$(date +%x-%H%M); DTX=${DTX//\/}
BDIR=${HOME}/backups
RUN_FILE=${BDIR}/$$.bk.log
MY_CONFIG=&quot;.sbackup&quot;
DOMAIN=;DB_NAME=;DB_USER=;DB_PASSWORD=;DB_HOST=;WP_CONFIG=;SQL_DEST=;ARC_DEST=;ENCRYPT_USER=
E_SUCCESS=0;E_YN=0;E_YES=251;E_NO=250;E_RETURN=65;C0=;C1=;C2=;C3=;C4=;C5=;C6=;C7=;C8=;C9=
&nbsp;
###########################################################################&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
###
### FUNCTIONS
###
###########################################################################==-==-==-==-==-==-==-==-==-==-==#
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# script_title
#==-==-==-==-==-==-==-==-==-==-==#
function script_title(){
 # SET WINDOW TITLE AND COLORS IF CLIENT CAPABLE
 case ${TERM:-dummy} in
&nbsp;&nbsp;xterm*|vt*|ansi|rxvt|gnome*)
&nbsp;&nbsp;C0=&quot;\033[0m&quot;;C1=&quot;\033[1;30m&quot;;C2=&quot;\033[1;32m&quot;;C3=&quot;\033[0;32m&quot;;C4=&quot;\033[1;37m&quot;
&nbsp;&nbsp;C5=&quot;\033[0;36m&quot;;C6=&quot;\033[1;35m&quot;;C7=&quot;\033[0;37m&quot;;C8=&quot;\033[30;42m&quot;;C9=&quot;\033[1;36m&quot;
 esac&nbsp;&nbsp;
 echo -e &quot;${C1} __________________________________________________________________________ &quot;
 echo -e &quot;| ${C2}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ___&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; __&nbsp;&nbsp;&nbsp;&nbsp;___&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; __&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;| ${C2}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/ _ | ___ / /__ / _ | ___&nbsp;&nbsp;___ _____/ /&nbsp;&nbsp;___&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;| ${C2}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; / __ |(_-&lt;/&nbsp;&nbsp;&#039;_// __ |/ _ \/ _ \`/ __/ _ \/ -_)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;| ${C3}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/_/ |_/___/_/\_\/_/ |_/ .__/\_,_/\__/_//_/\__/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;| ${C3}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /_/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&quot;
 echo -e &quot;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${C4} SITE BACKUP SCRIPT Version 3.1 ${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
 echo -e &quot;${C1} __________________________________________________________________________ ${C0} \n\n&quot;
}
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# pm
#==-==-==-==-==-==-==-==-==-==-==#
function pm(){
 START=$(date +%s) &amp;&amp; touch ${RUN_FILE}
 case &quot;${2:-title}&quot; in
&nbsp;&nbsp;&quot;title&quot;) echo -en &quot;\n\n${C2}&gt;&gt;&gt; ${C4}${1} ${C0} \n\n&quot;; ;;
&nbsp;&nbsp; &quot;info&quot;) echo -e &quot;${C6}=&gt; ${C4}${1} ${C0}&quot;; ;;
&nbsp;&nbsp; &quot;item&quot;) echo -e &quot;${C4}&#45;- ${C0}${1} &quot;; ;;
 esac
}
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# yes_no
#==-==-==-==-==-==-==-==-==-==-==#
function yes_no(){
 local ans
 echo -en &quot;${1} [y/n] &quot; ; read -n 1 ans
 case &quot;$ans&quot; in
&nbsp;&nbsp;n|N) E_YN=$E_NO ;;
&nbsp;&nbsp;y|Y) E_YN=$E_YES ;;
 esac
}
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# do_sleep
#==-==-==-==-==-==-==-==-==-==-==#
function do_sleep (){ 
 local END DIFF
 echo -en &quot;${C5}${3:-.}&quot;; while [ -r &quot;$RUN_FILE&quot; ]; do sleep ${2:-3}; echo -en &quot;${3:-.}&quot;; done;
 echo -e &quot;${C0}&quot;; sleep 1; END=$(date +%s);DIFF=$(( $END - $START ))
 echo -e &quot;\n${C8} [T: ${SECONDS}] COMPLETED IN ${DIFF} SEC ${C0} \n\n&quot;; sleep 1; 
 return 0; 
}
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# get_settings
#==-==-==-==-==-==-==-==-==-==-==#
function get_settings(){
 local cha HOSTED_SITES G
 clear; script_title
 if [[ -r &quot;$MY_CONFIG&quot; ]]; then
&nbsp;&nbsp;OIFS=$IFS; while IFS=: read DOMAIN DOMAINROOT WP_CONFIG ENCRYPT_USER; do
&nbsp;&nbsp; DOMAIN=${DOMAIN}; DOMAINROOT=${DOMAINROOT}; WP_CONFIG=${WP_CONFIG}; ENCRYPT_USER=${ENCRYPT_USER}; E_YN=$E_YES; break
&nbsp;&nbsp;done &lt;${MY_CONFIG}; IFS=$OIFS
 else
 echo -en &quot;\n What domain would you like to backup?&nbsp;&nbsp;&quot;; read -e DOMAIN; echo
 until [ -d &quot;$DOMAINROOT&quot; ]; do echo -en &quot;\n Where is the domain root?&nbsp;&nbsp;&quot;; read -e DOMAINROOT; echo; done
 [[ -r &quot;$DOMAINROOT/wp-config.php&quot; ]] &amp;&amp; WP_CONFIG=$DOMAINROOT/wp-config.php
 until [[ -r &quot;$WP_CONFIG&quot; ]]; do echo -en &quot;\n Where is the wp-config.php file?&nbsp;&nbsp;&quot;; read -e WP_CONFIG; echo; done
 echo -en &quot;\n What userid to use for encryption?&nbsp;&nbsp;&quot;; read -e ENCRYPT_USER; echo
 fi
&nbsp;
 [[ -r &quot;$WP_CONFIG&quot; ]] &amp;&amp; G=$(sed -e &quot;/define(&#039;DB_\(NAME\|USER\|PASSWORD\|HOST\)/!d&quot; \
 -e &quot;s/[^&#039;]*&#039;DB_\(NAME\|USER\|PASSWORD\|HOST\)&#039;[^&#039;]*&#039;\([^&#039;]*\)&#039;.*$/DB_\1=&#039;\2&#039;;/g&quot; ${WP_CONFIG}) &amp;&amp; eval $G;
 mkdir -p ${BDIR}/${DOMAIN}
 SQL_DEST=${BDIR}/${DOMAIN}/${DOMAIN}-${DT}.sql;&nbsp;&nbsp;[[ -r &quot;${SQL_DEST}.asc&quot; ]] &amp;&amp; SQL_DEST=${BDIR}/${DOMAIN}/${DOMAIN}-${DTX}.sql
 ARC_DEST=${BDIR}/${DOMAIN}/${DOMAIN}-${DT}.tgz; [[ -r &quot;${ARC_DEST}.asc&quot; ]] &amp;&amp; ARC_DEST=${BDIR}/${DOMAIN}/${DOMAIN}-${DTX}.tgz
&nbsp;
 if [[ &quot;$E_YN&quot; != &quot;$E_YES&quot; ]]; then
&nbsp;&nbsp;for a in &quot;DOMAIN&quot; &quot;DOMAINROOT&quot; &quot;WP_CONFIG&quot; &quot;ENCRYPT_USER&quot; &quot;DB_NAME&quot; &quot;DB_USER&quot; &quot;DB_PASSWORD&quot; &quot;DB_HOST&quot;; do echo -e &quot;${a}: ${!a}&quot;; done
&nbsp;&nbsp;echo; yes_no &quot;ARE THESE SETTINGS CORRECT&quot;
 fi

 while [[ &quot;$E_YN&quot; != &quot;$E_YES&quot; ]]; do
&nbsp;&nbsp;for a in &quot;DOMAIN&quot; &quot;DOMAINROOT&quot; &quot;WP_CONFIG&quot; &quot;ENCRYPT_USER&quot; &quot;DB_NAME&quot; &quot;DB_USER&quot; &quot;DB_PASSWORD&quot; &quot;DB_HOST&quot;; do
&nbsp;&nbsp; echo -en &quot;\n (Enter for Default: ${!a} )\n ${a}:&gt; &quot;
&nbsp;&nbsp; read -e cha; echo; [[ ${#cha} -gt 2 ]] &amp;&amp; eval &quot;$a&quot;=$cha
&nbsp;&nbsp;done
&nbsp;&nbsp;yes_no &quot;ARE THESE SETTINGS CORRECT&quot;
 done
&nbsp;&nbsp; 
 echo -e &quot;${DOMAIN}:${DOMAINROOT}:${WP_CONFIG}:${ENCRYPT_USER}&quot; &gt; $MY_CONFIG
}
&nbsp;
#&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-=&#45;-#
# exit_cleanup
#==-==-==-==-==-==-==-==-==-==-==#
function exit_cleanup(){
 cd $OLDPWD
 [[ -r ${SQL_DEST} ]] &amp;&amp; rm ${SQL_DEST}
 [[ -r ${ARC_DEST} ]] &amp;&amp; rm ${ARC_DEST}
}
&nbsp;
############################################################################################################
###
### MAIN CODE
###
############################################################################################################
&nbsp;
#=# CATCH SCRIPT KILLED BY USER
trap exit_cleanup SIGHUP SIGINT SIGTERM
&nbsp;
#=# MAKE MAIN SCRIPT NICE&nbsp;&nbsp;
renice 19 -p $$ &amp;&gt;/dev/null
&nbsp;
cd `dirname $0`
&nbsp;
get_settings
&nbsp;
pm &quot;CREATING SQL BACKUP&quot;
mysqldump &#45;-opt -u${DB_USER} -p${DB_PASSWORD} -h ${DB_HOST} -r ${SQL_DEST} \
&#45;-add-drop-table ${DB_NAME} 1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; sleep 2 1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; rm ${RUN_FILE} 2&gt;&amp;1&amp; 
do_sleep 1 1 &quot;:&quot;
&nbsp;
pm &quot;ENCRYPTING SQL BACKUP&quot;
gpg &#45;-armor &#45;-recipient ${ENCRYPT_USER} &#45;-output ${SQL_DEST}.asc &#45;-encrypt ${SQL_DEST} \
1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; sleep 2 1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; rm ${RUN_FILE} 2&gt;&amp;1&amp; 
do_sleep 1 1 &quot;:&quot;; rm ${SQL_DEST}
&nbsp;
pm &quot;CREATING ARCHIVE BACKUP&quot;
tar -czf ${ARC_DEST} . 1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; rm ${RUN_FILE} 2&gt;&amp;1&amp; 
do_sleep 1 5 &quot;:&quot;
&nbsp;
pm &quot;ENCRYPTING ARCHIVE BACKUP&quot;
gpg &#45;-armor &#45;-recipient ${ENCRYPT_USER} &#45;-output ${ARC_DEST}.asc &#45;-encrypt ${ARC_DEST} \
1&gt;&amp;2 &amp;&gt;/dev/null &amp;&amp; rm ${RUN_FILE} 2&gt;&amp;1&amp; 
do_sleep 1 1 &quot;:&quot;; rm ${ARC_DEST}
&nbsp;
echo -e &quot;${C1} __________________________________________________________________________ &quot;
echo -e &quot;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&quot;
echo -e &quot;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${C4} COMPLETED SUCCESSFULLY ${C1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&quot;
echo -e &quot;${C1} __________________________________________________________________________ ${C0} \n\n&quot;
&nbsp;
cd $OLDPWD
&nbsp;
exit $?
</pre>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Fsockopen Power Plays</title>
          <link>http://www.askapache.com/php/fsockopen-socket.html</link>
          <comments>http://www.askapache.com/php/fsockopen-socket.html#comments</comments>
          <pubDate>Wed, 02 Jul 2008 11:42:56 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[Hacking]]></category>

		<category><![CDATA[PHP]]></category>

          <guid>http://www.askapache.com/php/fsockopen-socket.html</guid>
                      <description><![CDATA[<p><a class="IFL" rel="lb" href='http://z.askapache.com/uploads/2008/07/fsockopen-lightning.jpg'><img src="http://z.askapache.com/uploads/2008/07/fsockopen-lightning-200x150.jpg" alt="Fsockopen Power" title="fsockopen-lightning" width="200" height="150" /></a><strong>PHP's function <a href="http://php.net/manual/en/function.fsockopen.php">fsockopen</a> lets you open an Internet or Unix domain socket connection for connecting to a resource, and is one of the most powerful functions.</strong><br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a class="IFL" rel="lb" href='http://z.askapache.com/uploads/2008/07/fsockopen-lightning.jpg'><img src="http://z.askapache.com/uploads/2008/07/fsockopen-lightning-200x150.jpg" alt="Fsockopen Power" title="fsockopen-lightning" width="200" height="150" /></a><strong>PHP&#8217;s function <a href="http://php.net/manual/en/function.fsockopen.php">fsockopen</a> lets you open an Internet or Unix domain socket connection for connecting to a resource, and is one of the most powerful functions.</strong>  fsockopen could be described as creating a direct link to the wire connected to a resource, which means you can send any information (<em>EBCDIC, ASCII, Hex, C arrays, Raw</em>) directly to the target server.<br class="C" /></p>
<h2>A Socket is like /dev/null</h2>
<p>In unix you can send anything to the <code>/dev/null</code> device, <em>for Windows think Recycle Bin</em>, and likewise you can send anything to a socket created with fsockopen.  I&#8217;ve seen fsockopen code that sends custom exploits to cisco routers, including being used by the metasploit framework.  I&#8217;ve seen fsockopen telnet emulation, smtp/pop3 login, and a lot of other advanced raw networking that is exciting for me see.</p>
<h3>Some Definitions for Fsockopen</h3>
<dl>
<dt><a href="http://www.askapache.com/glossary/#client" title="client">client</a></dt>
<dd>A program that establishes connections for the purpose of sending requests.</dd>
<dt><a href="http://www.askapache.com/glossary/#server" title="server">server</a></dt>
<dd>An application program that accepts connections in order to service requests by sending back responses.</dd>
</dl>
<h3>Simple Socket Explantion</h3>
<p>A web server host listens on TCP port 80.  When a client host wishes to view a resource on the web server, it establishes a TCP connection with the server host by opening a socket to send the request for the resource.  When the connection is established, the client and server exchange requests and responses (respectively) until the connection is closed or aborted.</p>
<h2>HTTP and fsockopen</h2>
<p><a class="IFR" href='http://www.askapache.com/php/speedy-form-post.html' title='Snoopy Fsockopen HTTP Class for PHP'><img src='http://z.askapache.com/uploads/2008/02/snoopy-fsockopen.thumbnail.png' alt='Snoopy Fsockopen HTTP Class for PHP' /></a>The <a href="http://snoopy.sourceforge.net/">Snoopy</a> class is bundled with WordPress distributions and uses fsockopen to achieve most of its cool features.  WordPress core, plugins, and other included files and classes also use the fsockopen function to communicate via HTTP.<br class="C" /></p>
<h2>Fsockopen Examples</h2>
<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/07/fsockopen-warning.jpg'><img src="http://z.askapache.com/uploads/2008/07/fsockopen-warning-200x181.jpg" alt="fsockopen warning" title="fsockopen warning" width="100" height="91" /></a>Note the warning sign, fsockopen is dangerous in the sense that you can crash your server, perform a DOS against your own server or other site, use up all your servers available sockets and fd descriptors, use up your bandwidth, etc.. Shouldn&#8217;t be a problem unless you are being malicious or careless.<br class="C" /></p>
<p>Here are some BOSS fsockopen functions I hacked together yesterday for use in my <a href="http://wordpress.org/extend/plugins/askapache-crazy-cache/">AskApache Crazy Cache WordPress Plugin</a>.  I&#8217;ve used code and ideas from 100&#8217;s of authors, projects, and docs to try to make this the very best I can.</p>
<h3>Intro</h3>
<p>This is a working example employing as many of the best-practices, tips, and tricks for using fsockopen on remote streams that I could find.</p>
<pre>
&lt;?php
// max time for script execution
if(!@defined(&#039;AA_MAX_TIME&#039;)) define(&#039;AA_MAX_TIME&#039;,&nbsp;&nbsp;60);
&nbsp;
// max time for socket reads
if(!@defined(&#039;AA_RECV_TIME&#039;)) define(&#039;AA_RECV_TIME&#039;, 30);
&nbsp;
// max time for socket connect
if(!@defined(&#039;AA_CONN_TIME&#039;)) define(&#039;AA_CONN_TIME&#039;, 5);
&nbsp;
// linebreak
if(!@defined(&#039;AA_LF&#039;)) define(&#039;AA_LF&#039;, chr(13).chr(10));
&nbsp;
// ignore TCP RST i.e. browser stop button
@ignore_user_abort(1);
&nbsp;
// set the script execution time
@set_time_limit(AA_MAX_TIME); 
&nbsp;
// set the default socket timeout value
@ini_set(&quot;default_socket_timeout&quot;,AA_RECV_TIME);
&nbsp;
// output implicitly
@ob_implicit_flush(1);
&nbsp;
// for binary freads
@set_magic_quotes_runtime(0);
&nbsp;
// keep track of script execution time
$aa_time=time();
&nbsp;
// download each of these urls using fsockopen 
aa_dl(&#039;http://httpd.apache.org&#039;);
aa_dl(&#039;http://www.w3.org&#039;);
aa_dl(&#039;http://www.google.com&#039;);
aa_dl(&#039;http://www.freebsd.org/cgi/man.cgi?query=connect&amp;sektion=2&amp;apropos=0&amp;manpath=FreeBSD+7.0-RELEASE&#039;);
aa_dl(&#039;http://www.askapache.com/htaccess/apache-htaccess.html&#039;);
aa_dl(&#039;http://www.php.net&#039;);
aa_dl(&#039;http://en.wikipedia.org/wiki/Main_Page&#039;);
&nbsp;
/*&nbsp;&nbsp;returns a socket pointer if valid or displays an error message
&nbsp;&nbsp;&nbsp;&nbsp;sets stream timeout, starts the clock to check for socket read time */
function askapache_get_sock($target,$port){
&nbsp;&nbsp;global $aa_time_start;
&nbsp;&nbsp;$aa_time_start=time();
&nbsp;&nbsp;if(false===($fp = @fsockopen($target,$port,$errno,$errstr,AA_CONN_TIME))||!is_resource($fp)) 
&nbsp;&nbsp;&nbsp;&nbsp;return askapache_sock_strerror($errno,$errstr);
&nbsp;&nbsp;@stream_set_timeout($fp, AA_RECV_TIME);
&nbsp;&nbsp;return $fp;
}
&nbsp;
/*&nbsp;&nbsp;writes request, then reads response until EOF, script max, or socket max
&nbsp;&nbsp;&nbsp;&nbsp;returns response on success.&nbsp;&nbsp;Uses buffer to allow size&gt;100megs */
function askapache_txrx($fp,$request,$chunk=1024){
&nbsp;&nbsp;$rec=$buf=&#039;&#039;;
&nbsp;&nbsp;if(!@fwrite($fp, $request, strlen($request)))die(&#039;fwrite error&#039;);
&nbsp;&nbsp;while ( !@feof($fp) &amp;&amp; askapache_time_ok(askapache_time_passed())){
&nbsp;&nbsp;&nbsp;&nbsp;$buf = @fread($fp, $chunk);
&nbsp;&nbsp;&nbsp;&nbsp;$rec .= $buf;
&nbsp;&nbsp;}
&nbsp;&nbsp;if(!@fclose($fp))die(&#039;fclose error&#039;);
&nbsp;&nbsp;return $rec;
}
&nbsp;
/* initiates the socket and download for the passed url.
&nbsp;&nbsp; automatically handles gzip, chunked, both, and plain downloads.
&nbsp;&nbsp; uses the long2ip/ip2long for ip validation, uses gethostbyname to 
&nbsp;&nbsp; get the ipv4 address which saves fsockopen from having to do the lookup
&nbsp;&nbsp; final data is saved to $rbody but currently only displays headers.*/
function aa_dl($url=NULL){
&nbsp;&nbsp;global $aa_time;
&nbsp;&nbsp;$ub = @parse_url($url);
&nbsp;&nbsp;if(!isset($ub[&#039;host&#039;])||empty($ub[&#039;host&#039;])) die(&quot;bad url $url&quot;); 
&nbsp;&nbsp;$proto&nbsp;&nbsp; = ($ub[&#039;scheme&#039;]==&#039;https&#039;)?&#039;ssl://&#039;:&#039;&#039;;
&nbsp;&nbsp;$port&nbsp;&nbsp; = (isset($ub[&#039;port&#039;])&amp;&amp;!empty($ub[&#039;port&#039;])) ? $ub[&#039;port&#039;]:($proto!=&#039;&#039;)?443:80;
&nbsp;&nbsp;$path&nbsp;&nbsp; = (isset($ub[&#039;path&#039;])&amp;&amp;!empty($ub[&#039;path&#039;])) ? $ub[&#039;path&#039;]:&#039;/&#039;;
&nbsp;&nbsp;$query&nbsp;&nbsp; = (isset($ub[&#039;query&#039;])&amp;&amp;!empty($ub[&#039;query&#039;])) ? &#039;?&#039;.$ub[&#039;query&#039;] : &#039;&#039;;
&nbsp;&nbsp;$host&nbsp;&nbsp; = $ub[&#039;host&#039;];
&nbsp;&nbsp;$ipp&nbsp;&nbsp;&nbsp;&nbsp; = @gethostbyname($host);
&nbsp;&nbsp;$ip&nbsp;&nbsp;&nbsp;&nbsp; = ($ipp!=$host) ? long2ip(ip2long($ipp)) : $host;
&nbsp;&nbsp;
&nbsp;&nbsp;$headers=array(
&nbsp;&nbsp; &quot;GET {$path}{$query} HTTP/1.1&quot;,
&nbsp;&nbsp; &quot;Host: {$host}&quot;,
&nbsp;&nbsp; &#039;User-Agent: Mozilla/5.0 (AskApache/; +http://www.askapache.com/)&#039;,
&nbsp;&nbsp; &#039;Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,*/*;q=0.5&#039;,
&nbsp;&nbsp; &#039;Accept-Language: en-us,en;q=0.5&#039;,
&nbsp;&nbsp; &#039;Accept-Encoding: gzip,deflate&#039;,
&nbsp;&nbsp; &#039;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&#039;,
&nbsp;&nbsp; &#039;Connection: close&#039;,&#039;Referer: http://www.askapache.com&#039;
&nbsp;&nbsp;);
&nbsp;&nbsp;$request=join(AA_LF,$headers).AA_LF.AA_LF;
&nbsp;&nbsp;
&nbsp;&nbsp;$fp=askapache_get_sock($proto.$ip, $port);
&nbsp;&nbsp;if($fp){
&nbsp;&nbsp;&nbsp;&nbsp;$rbody=$rec=&#039;&#039;;$resp_headers=array();
&nbsp;&nbsp;&nbsp;&nbsp;$rec=askapache_txrx($fp,$request);
&nbsp;&nbsp;&nbsp;&nbsp;list($resp_headers, $rbody) = explode(AA_LF.AA_LF, trim($rec), 2);
&nbsp;&nbsp;echo &quot;\n&lt;p&gt;$request&lt;/p&gt;\n&lt;p&gt;$resp_headers&lt;/p&gt;\n&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$gzip2=(stripos($resp_headers,&#039;Content-Encoding&#039;)!==false &amp;&amp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stripos($resp_headers,&#039;gzip&#039;)!==false)?1:0;
&nbsp;&nbsp;&nbsp;&nbsp;$chunk=(stripos($resp_headers,&#039;Transfer-Encoding&#039;)!==false &amp;&amp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stripos($resp_headers,&#039;chunked&#039;)!==false)?1:0;
&nbsp;&nbsp;&nbsp;&nbsp;$rbody=aa_decode_body($rbody,$chunk,$gzip2);
&nbsp;&nbsp;&nbsp;&nbsp;unset($rbody);
&nbsp;&nbsp;}
}
&nbsp;
/* based on http://us.php.net/manual/en/function.fsockopen.php#75175 
&nbsp;&nbsp; ungzips and/or re-assembles transfer-encoded:chunked responses
&nbsp;&nbsp; returns the good response on success */
function aa_decode_body ($str, $chunked, $gzipped){
&nbsp;&nbsp;if($gzipped &amp;&amp; !$chunked) return aa_gzdecode($str);
&nbsp;&nbsp;if(!$gzipped &amp;&amp; !$chunked) return $str;
&nbsp;&nbsp;$tmp = $str; $str = &#039;&#039;;
&nbsp;&nbsp;do {
&nbsp;&nbsp;&nbsp;&nbsp;$tmp = ltrim($tmp);
&nbsp;&nbsp;&nbsp;&nbsp;$pos = strpos($tmp,AA_LF);
&nbsp;&nbsp;&nbsp;&nbsp;$len = hexdec(substr($tmp, 0, $pos));
&nbsp;&nbsp;&nbsp;&nbsp;if($gzipped) $str .= gzinflate(substr($tmp,($pos+12),$len));
&nbsp;&nbsp;&nbsp;&nbsp;else $str .=substr($tmp,($pos+2),$len);
&nbsp;&nbsp;&nbsp;&nbsp;$tmp = substr($tmp,($len+$pos+2));
&nbsp;&nbsp;$chk=trim($tmp);
&nbsp;&nbsp;} while (!empty($chk));
&nbsp;&nbsp;return $str;
}
&nbsp;
/*&nbsp;&nbsp;based on http://us2.php.net/manual/en/function.gzencode.php#82520 
&nbsp;&nbsp;saves the gzipped data to a tempfile, then outputs the decoded
&nbsp;&nbsp;data to the output buffer using readgzfile, returning the decoded
&nbsp;&nbsp;buffer and deleting the tempfile on success */
function aa_gzdecode($data){
&nbsp;&nbsp;$g=tempnam(&#039;/tmp&#039;,&#039;ff&#039;);
&nbsp;&nbsp;@file_put_contents($g,$data);
&nbsp;&nbsp;ob_start(); readgzfile($g); $d=ob_get_clean(); @unlink($g);
&nbsp;&nbsp;return $d;
}
&nbsp;
/*&nbsp;&nbsp;very cool!&nbsp;&nbsp;this is run during socket reads and checks whether the script
&nbsp;&nbsp;execution time limit or the socket read time limit has been met, killing
&nbsp;&nbsp;the script if so, otherwise returns true.&nbsp;&nbsp;Run with a cron-like process */
function askapache_time_ok($sock_time=0) {
&nbsp;&nbsp;global $aa_time;
&nbsp;&nbsp;if (time()-$aa_time&gt;AA_MAX_TIME) 
&nbsp;&nbsp;&nbsp;&nbsp;die(&#039;killed script.. time exceeded &#039;.AA_MAX_TIME.&#039; Total: &#039;.$total);
&nbsp;&nbsp;if ($sock_time&gt;AA_RECV_TIME) 
&nbsp;&nbsp;&nbsp;&nbsp;die(&#039;Killed socket.. time exceeded &#039;.AA_RECV_TIME.&#039; Total: &#039;.$sock_time);
&nbsp;&nbsp;return true;
}
&nbsp;
/* input for askapache_time_ok to keep track of each socket read time time. */
function askapache_time_passed() {
&nbsp;&nbsp;global $aa_time_start;
&nbsp;&nbsp;return (time() - $aa_time_start);
}
&nbsp;
/*&nbsp;&nbsp;handles fsockopen errors, printing them out though you may want to die on err */
function askapache_sock_strerror($errno,$errstr){
&nbsp;&nbsp;switch($errno){
&nbsp;&nbsp;&nbsp;&nbsp;case -3:&nbsp;&nbsp;$err=&quot;Socket creation failed&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case -4:&nbsp;&nbsp;$err=&quot;DNS lookup failure&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case -5:&nbsp;&nbsp;$err=&quot;Connection refused or timed out&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case 111: $err=&quot;Connection refused&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case 113: $err=&quot;No route to host&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case 110: $err=&quot;Connection timed out&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;case 104: $err=&quot;Connection reset by client&quot;; break;
&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;$err=&quot;Connection failed&quot;; break;
&nbsp;&nbsp;}
&nbsp;&nbsp;echo &#039;&lt;p&gt;Fsockopen failed!&#039;.&quot;\n[&quot;.$errno.&quot;] &quot;.$err.&quot; (&quot;.$errstr.&quot;)&lt;/p&gt;&quot;;
&nbsp;&nbsp;return false;
}
?&gt;
</pre>
<hr class="C" />
<h2>Debugging Fsockopen</h2>
<p>If you really want to know more about fsockopen, you can do what I did and read all the relevant php source files, your OS sys, lib, and user files relevant to fsockopen, and of course you can always trace php using the fsockopen function to get an under-the-hood look at what in the world fsockopen is doing.  Personally, I was trying to find more error codes and error strings to display when an fsockopen call failed, and I ended up finding over 50..</p>
<h3>Tracing fsockopen using Strace</h3>
<p>Once you save the above file on your site, you can use the strace tool to debug it.  This is a tad overboard but way cool nevertheless!</p>
<p><code>strace -e trace=connect php -nef fsockopen-test.php</code></p>
<pre>
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;192.87.106.226&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
</pre>
<p><code>strace -e trace=network php -nef fsockopen-test.php</code></p>
<pre>
socket(PF_FILE, SOCK_STREAM, 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 3
connect(3, {sa_family=AF_FILE, path=&quot;/var/run/.nscd_socket&quot;}, 110) = -1 ENOENT (No such file or directory)
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
send(3, &quot;\274\221\1\0\0\1\0\0\0\0\0\0\5httpd\6apache\3org\0\0\1&quot;&#46;.., 34, 0) = 34
recvfrom(3, &quot;\274\221\201\200\0\1\0\1\0\0\0\0\5httpd\6apache\3org\0&quot;&#46;.., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, [16]) = 50
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = -1 EAFNOSUPPORT (Address family not supported by protocol)
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;192.87.106.226&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
send(3, &quot;GET / HTTP/1.1\r\nHost: httpd.apac&quot;&#46;.., 356, MSG_DONTWAIT) = 356
recv(3, &quot;HTTP/1.1 200 OK\r\nDate: Wed, 02 J&quot;&#46;.., 8192, MSG_DONTWAIT) = 2609
recv(3, &quot;&quot;, 8192, MSG_DONTWAIT)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
</pre>
<p><code>strace -q -e trace=all php -nef fsockopen-test.php</code></p>
<pre>
mmap2(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76ba000
munmap(0xb76ba000, 266240)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
socket(PF_FILE, SOCK_STREAM, 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 3
connect(3, {sa_family=AF_FILE, path=&quot;/var/run/.nscd_socket&quot;}, 110) = -1 ENOENT (No such file or directory)
close(3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
open(&quot;/etc/hosts&quot;, O_RDONLY)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 3
fcntl64(3, F_GETFD)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=948, &#46;..}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f6e000
read(3, &quot;# /etc/hosts - dh2 generated\n127&quot;&#46;.., 4096) = 948
read(3, &quot;&quot;, 4096)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
close(3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
munmap(0xb7f6e000, 4096)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, 28) = 0
send(3, &quot;X~\1\0\0\1\0\0\0\0\0\0\2en\twikipedia\3org\0\0\1&quot;&#46;.., 34, 0) = 34
gettimeofday({1214998196, 656179}, NULL) = 0
poll([{fd=3, events=POLLIN, revents=POLLIN}], 1, 5000) = 1
ioctl(3, FIONREAD, [100])&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
recvfrom(3, &quot;X~\201\200\0\1\0\3\0\0\0\0\2en\twikipedia\3org\0\0\1&quot;&#46;.., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(&quot;66.33.216.129&quot;)}, [16]) = 100
close(3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
time(NULL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1214998196
gettimeofday({1214998196, 656754}, NULL) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl64(3, F_GETFL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0&#215;2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)&nbsp;&nbsp;= 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(&quot;208.80.152.2&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP, revents=POLLOUT}], 1, 10000) = 1
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
send(3, &quot;GET /wiki/Main_Page HTTP/1.1\r\nHo&quot;&#46;.., 370, MSG_DONTWAIT) = 370
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0
time(NULL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;HTTP/1.0 200 OK\r\nDate: Wed, 02 J&quot;&#46;.., 8192, MSG_DONTWAIT) = 2896
time(NULL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;\214!\337i\307\336\23w\253wy\215\26EL\227;\227\253\261&quot;&#46;.., 8192, MSG_DONTWAIT) = 5792
time(NULL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1214998196
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;4\201\273\214\17yI\347\257\371\373\344\332\330\227\245&quot;&#46;.., 8192, MSG_DONTWAIT) = 7487
time(NULL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 1214998197
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 30000) = 1
recv(3, &quot;&quot;, 8192, MSG_DONTWAIT)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0
close(3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0
write(1, &quot;\n&lt;pre&gt;GET /wiki/Main_Page HTTP/1&quot;&#46;.., 1300
</pre>
<hr class="C" />
<h2>More Fsockopen Info</h2>
<h3>TCP Multiplexing</h3>
<p><a href="http://rfc.askapache.com/rfc793/rfc793.html#page-10">RFC 793</a>: To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host.  Concatenated with the network and host addresses from the internet communication layer, this forms a socket.  A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.</p>
<p>The binding of ports to processes is handled independently by each Host.  However, it proves useful to attach frequently used processes (e.g., a &#8220;logger&#8221; or timesharing service) to fixed sockets which are made known to the public.  These services can then be accessed through the known addresses.  Establishing and learning the port addresses of other processes may involve more dynamic mechanisms.</p>
<h3>TCP Connections</h3>
<p>The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream.  The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.</p>
<p>When two processes wish to communicate, their TCP&#8217;s must first establish a connection (initialize the status information on each side).  When their communication is complete, the connection is terminated or closed to free the resources for other uses.</p>
<p>Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.</p>
<h3>Fsockopen Practical Uses</h3>
<ul>
<li>Download Web Pages, Files, etc.</li>
<li><a href="http://www.askapache.com/php/speedy-form-post.html">Upload a file</a></li>
<li><a href="http://www.askapache.com/php/speedy-form-post.html">Send POST data to a form</a></li>
<li>Emulate cron</li>
<li>Download plugin updates</li>
<li><a href="http://www.askapache.com/online-tools/request-method-scanner/">Scan sites for exploits</a></li>
<li><a href="http://www.askapache.com/online-tools/curl-google-feed/">Auto Login to Google</a></li>
<li><a href="http://www.askapache.com/wordpress/crazy-cache-wordpress-plugin.html">Pass wp-nonces via cookie headers</a>, and more</li>
</ul>
<h3>Transfer-Encoding</h3>
<p><a href="http://www.ietf.org/rfc/rfc2068">RFC 2068</a></p>
<pre>19.4.6 Introduction of Transfer-Encoding
&nbsp;
&nbsp;&nbsp; HTTP/1.1 introduces the Transfer-Encoding header field (section
&nbsp;&nbsp; 14.40).&nbsp;&nbsp;Proxies/gateways MUST remove any transfer coding prior to
&nbsp;&nbsp; forwarding a message via a MIME-compliant protocol.
&nbsp;
&nbsp;&nbsp; A process for decoding the &quot;chunked&quot; transfer coding (section 3.6)
&nbsp;&nbsp; can be represented in pseudo-code as:
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;length := 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read chunk-size, chunk-ext (if any) and CRLF
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (chunk-size &gt; 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read chunk-data and CRLF
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; append chunk-data to entity-body
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length := length + chunk-size
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read chunk-size and CRLF
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read entity-header
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (entity-header not empty) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; append entity-header to existing header fields
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read entity-header
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-Length := length
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Remove &quot;chunked&quot; from Transfer-Encoding
</pre>
<h3>Socket-Related Man Pages</h3>
<pre>
DESCRIPTION
This&nbsp;&nbsp;manual&nbsp;&nbsp;page&nbsp;&nbsp;describes the Linux networking socket layer user interface. The BSD compatible sockets are the uniform interface between
the user process and the network protocol stacks in the kernel.&nbsp;&nbsp;The protocol modules are&nbsp;&nbsp;grouped&nbsp;&nbsp;into&nbsp;&nbsp;protocol&nbsp;&nbsp;families&nbsp;&nbsp;like&nbsp;&nbsp;PF_INET,
PF_IPX, PF_PACKET and socket types like SOCK_STREAM or SOCK_DGRAM.&nbsp;&nbsp;See socket(2) for more information on families and types.
&nbsp;
SOCKET LAYER FUNCTIONS
These&nbsp;&nbsp;functions&nbsp;&nbsp;are&nbsp;&nbsp;used by the user process to send or receive packets and to do other socket operations. For more information see their
respective manual pages.
&nbsp;
socket(2) creates a socket, connect(2) connects a socket to a remote socket address, the bind(2) function binds a socket to a&nbsp;&nbsp;local&nbsp;&nbsp;socket
address,&nbsp;&nbsp;listen(2)&nbsp;&nbsp;tells&nbsp;&nbsp;the socket that new connections shall be accepted, and accept(2) is used to get a new socket with a new incoming
connection.&nbsp;&nbsp;socketpair(2) returns two connected anonymous sockets (only implemented for a few local families like PF_UNIX)
&nbsp;
send(2), sendto(2), and sendmsg(2) send data over a socket, and recv(2), recvfrom(2), recvmsg(2) receive data from a&nbsp;&nbsp;socket.&nbsp;&nbsp; poll(2)&nbsp;&nbsp;and
select(2)&nbsp;&nbsp;wait&nbsp;&nbsp;for&nbsp;&nbsp;arriving&nbsp;&nbsp;data&nbsp;&nbsp;or a readiness to send data.&nbsp;&nbsp;In addition, the standard I/O operations like write(2), writev(2), send-
file(2), read(2), and readv(2) can be used to read and write data.
&nbsp;
getsockname(2) returns the local socket address and getpeername(2) returns the remote socket address.&nbsp;&nbsp;getsockopt(2) and&nbsp;&nbsp;setsockopt(2)&nbsp;&nbsp;are
used to set or get socket layer or protocol options.&nbsp;&nbsp;ioctl(2) can be used to set or read some other options.
&nbsp;
close(2) is used to close a socket.&nbsp;&nbsp;shutdown(2) closes parts of a full duplex socket connection.
&nbsp;
Seeking, or calling pread(2) or pwrite(2) with a non-zero position is not supported on sockets.
&nbsp;
It&nbsp;&nbsp;is possible to do non-blocking IO on sockets by setting the O_NONBLOCK flag on a socket file descriptor using fcntl(2).&nbsp;&nbsp;Then all opera-
tions that would block will (usually) return with EAGAIN (operation should be retried later); connect(2) will return EINPROGRESS error.&nbsp;&nbsp;The
user can then wait for various events via poll(2) or select(2).
</pre>
<p>From the <a href="http://www.freebsd.org/cgi/man.cgi?query=socket&#038;sektion=2&#038;apropos=0&#038;manpath=FreeBSD+7.0-RELEASE">FreeBSD man page for socket(2)</a></p>
<pre>
Sockets of type SOCK_STREAM are full-duplex byte streams, similar to
pipes.&nbsp;&nbsp;A stream socket must be in a connected state before any data may
be sent or received on it.&nbsp;&nbsp;A connection to another socket is created
with a connect(2) system call.&nbsp;&nbsp;Once connected, data may be transferred
using read(2) and write(2) calls or some variant of the send(2) and
recv(2) functions.&nbsp;&nbsp;(Some protocol families, such as the Internet family,
support the notion of an &#96;`implied connect&#039;&#039;, which permits data to be
sent piggybacked onto a connect operation by using the sendto(2) system
call.)&nbsp;&nbsp;When a session has been completed a close(2) may be performed.
Out-of-band data may also be transmitted as described in send(2) and
received as described in recv(2).
&nbsp;
The communications protocols used to implement a SOCK_STREAM insure that
data is not lost or duplicated.&nbsp;&nbsp;If a piece of data for which the peer
protocol has buffer space cannot be successfully transmitted within a
reasonable length of time, then the connection is considered broken and
calls will indicate an error with -1 returns and with ETIMEDOUT as the
specific code in the global variable errno.&nbsp;&nbsp;The protocols optionally
keep sockets &#96;`warm&#039;&#039; by forcing transmissions roughly every minute in
the absence of other activity.&nbsp;&nbsp;An error is then indicated if no response
can be elicited on an otherwise idle connection for an extended period
(e.g. 5 minutes).&nbsp;&nbsp;A SIGPIPE signal is raised if a process sends on a
broken stream; this causes naive processes, which do not handle the sig-
nal, to exit.
</pre>
<p>Have Fun   ;)</p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/php/fsockopen-socket.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Adding Print Capability to your Site with CSS</title>
          <link>http://www.askapache.com/css/css-print-site-stylesheet.html</link>
          <comments>http://www.askapache.com/css/css-print-site-stylesheet.html#comments</comments>
          <pubDate>Tue, 01 Jul 2008 04:38:56 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[XHTML]]></category>

          <guid>http://www.askapache.com/css/css-print-site-stylesheet.html</guid>
                      <description><![CDATA[<p><a class="IFR" rel="lb" href='http://z.askapache.com/uploads/2008/07/printer.jpg'><img src="http://z.askapache.com/uploads/2008/07/printer-200x182.jpg" alt="css printer friendly website" title="css printer friendly website" width="200" height="182" /></a>Its really nice to be able to print out a webpage you are reading using your browsers built-in print feature.  Using CSS you can easily transform your site into a print-friendly site.<br /><br />Today I received an email from a visitor to my site requesting that I add a way to <strong>print site articles</strong> on AskApache<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a class="IFL" rel="lb" href='http://z.askapache.com/uploads/2008/07/printer.jpg'><img src="http://z.askapache.com/uploads/2008/07/printer-200x182.jpg" alt="css printer friendly website" title="css printer friendly website" width="200" height="182" /></a>Its really nice to be able to print out a webpage you are reading using your browsers built-in print feature.  Using CSS you can easily transform your site into a print-friendly site.</p>
<p>Today I received an email from a visitor to my site requesting that I add a way to <strong>print site articles</strong> on AskApache<br class="C" /></p>
<blockquote><p>Finally, you have so much great stuff that I need to print it take it offline so I can consume it. However, your theme prints just awful with huge empty spaces between paragraphs and especially with some of your example code, i.e. see <a href="http://www.askapache.com/htaccess/htaccess-fresh.html">&#8220;Redirect All Feeds to Feedburner’s MyBrand&#8221;</a>.  Not sure if you care but it would really be great for those of us who print if you could clean it up for nicer printing to fully print your examples and to get rid of the excessive whitespace.</p>
</blockquote>
<p class="anote">Go ahead and hit print preview to see how effective this simple CSS print method is!</p>
<h2>Making AskApache Printer-Friendly</h2>
<p>The first thing I did was to create a blank style sheet named <a href="http://z.askapache.com/c/apacheprint-176.css">apacheprint.css</a> and then I added this XHTML to my <code>&lt;head&gt;&lt;/head&gt;</code></p>
<pre>
&lt;link href=&quot;http://z.askapache.com/c/apacheprint-176.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;print&quot; /&gt;
</pre>
<p>Amazingly, to make my site printer-friendly, all I had to do was edit the apacheprint.css file to control how browsers will print my site.</p>
<h2>Resetting the CSS</h2>
<p>Next I added the Yahoo Reset.css and Base.css files to my apacheprint.css file.  That code looks like this.</p>
<pre>
html {color:#000; background:#FFF;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td {margin:0; padding:0;}
table {border-collapse:collapse; border-spacing:0;}
fieldset,img {border:0;}
address,caption,cite,code,dfn,em,strong,th,var {font-style:normal; font-weight:normal;}
li {list-style:none;}
caption,th {text-align:left;}
h1,h2,h3,h4,h5,h6 {font-size:100%; font-weight:normal;}
q:before,q:after {content:&#039;&#039;;}
abbr,acronym {border:0; font-variant:normal;}
sup {vertical-align:text-top;}
sub {vertical-align:text-bottom;}
input,textarea,select {font-family:inherit; font-size:inherit; font-weight:inherit;}
input,textarea,select {*font-size:100%;}
legend {color:#000;}
code {display:inline;text-indent:3px;}
h1 {font-size:138.5%;}
h2 {font-size:123.1%;}
h3 {font-size:108%;}
h1,h2,h3 {margin:1em 0;}
h1,h2,h3,h4,h5,h6,strong {font-weight:bold;}
abbr,acronym {border-bottom:1px dotted #000; cursor:help;}
em {font-style:italic;}
blockquote,ul,ol,dl {margin:1em;}
ol,ul,dl {margin-left:2em;}
ol li {list-style:decimal outside;}
ul li {list-style:disc outside;}
dl dd {margin-left:1em;}
th,td {border:1px solid #000; padding:.5em;}
th {font-weight:bold; text-align:center;}
caption {margin-bottom:.5em; text-align:center;}
p,fieldset,table,pre {margin-bottom:1em;}
input[type=text],input[type=password],textarea {width:12.25em; *width:11.9em;}
</pre>
<h2>Hiding Unfriendly Content</h2>
<p>Ok so I don&#8217;t want to display the sidebar, header, footer, and several other elements on this site, so I added them to apacheprint.css with the instruction to not display them.</p>
<pre>
#HeadW,#HeadW,
#NavM,#HeadW,
#FootW,#FootW,
#simg,#simg,
#BTNfs,#BTNfs,
#sidebar,#sidebar,
#content #pagebar,#pagebar,
#content #digg,#digg,
#content #bcomme,#bcomme,
#content #comments,#comments,
#content #related1p,#related1p,
#content .rnote,
.flef,.flef,
#content #npl,#npl {display:none !important;}
&nbsp;
#searchbox_002660089121042511758:kk7rwc2gx0i,#searchbox_002660089121042511758:kk7rwc2gx0i,
form#searchbox_002660089121042511758:kk7rwc2gx0i,form#searchbox_002660089121042511758:kk7rwc2gx0i,
#snaptalent,#snaptalent,
h2.HAC {display:none !important;}
</pre>
<h2>Misc CSS Fixes</h2>
<p>Once that was done I tested my site using the &#8220;print preview&#8221; browser feature, and found some other things I needed to fix.</p>
<pre>
#GlobalW,
#content,
#htaccess {width:auto !important; height:auto !important; overflow:visible !important; background:transparent !important; background-image:none !important; padding:0 !important; margin:0 !important; float:none !important;}
&nbsp;
.item {width:auto !important; height:100% !important; overflow:visible !important; float:none !important;}
.post-content {width:auto !important; height:auto !important; float:none !important;}
.item .post-content {width:90% !important;padding:0 6% 0 0 !important;max-width:100% !important;margin:0 auto !important;}
&nbsp;
.C {clear:both; padding:0; margin:0; line-height:5px; font-size:10px; border-bottom-width:0px;}
#content .post-content h2 {margin-top:1em;}
#content h1#sing {margin:0; width:100%; padding:0;}
.item {padding:0; margin:0;}
#content .commentlist li,#content .commentlist li.alt {margin:0.25em;}
</pre>
<h2>Correct Page Breaks and Width</h2>
<p>In order to print correctly, I also added the following.</p>
<pre>
html,body {background-color:#FFF; color:#000; font-size: 12pt;}
img&nbsp;&nbsp;{max-width: 100%;}
h1,h2,h3,h4,h5,h6 {page-break-after: avoid;}
ul, ol, li {page-break-inside: avoid;}
table table,tr,td {page-break-before: avoid;page-break-after: avoid;}
</pre>
<h3>Making Comments Appear on Separate Page</h3>
<p>I created a class called .pb in my main css file</p>
<pre>
.pb { page-break-before: always; }
</pre>
<p>that creates a page break and then added that class to a hr element before my comment div.</p>
<pre>
&lt;hr class=&quot;pb&quot; /&gt;
</pre>
<h2>Wrapping Code in PRE</h2>
<p>I use <code>&lt;pre&gt;</code> tags to markup code in my posts, but printing doesn&#8217;t show you a scrollbar like my site does, so I added this fine CSS pre hack to wrap the lines when printing.</p>
<pre>
pre {page-break-inside: avoid; font-size: 7pt !important; max-width:95% !important; overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */ white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ /* width: 99%; */ word-wrap: break-word; /* Internet Explorer 5.5+ */}
</pre>
<h2>Displaying links for print</h2>
<p>I opted not to do this because I have way to many links in my posts, but here is how I can display the links next to the link name in p and li tags.  Note that it will not print relative links or anchor links or javascript links.</p>
<pre>
.item p a:link:after,
.item p a:visited:after,
.item li a:link:after,
.item li a:visited:after { content: &quot; (&quot; attr(href) &quot;) &quot;;}
.item p a[href^=&quot;/&quot;]:after,
.item li a[href^=&quot;/&quot;]:after,
.item p a[href^=&quot;#&quot;]:after,
.item p a[href^=&quot;javascript&quot;]:after,
.item li a[href^=&quot;#&quot;]:after,
.item li a[href^=&quot;javascript&quot;]:after,
.item p a[href^=&quot;http://www.askapache&quot;]:after,
.item p a[href^=&quot;http://www.askapache&quot;]:after,
.item li a[href^=&quot;http://www.askapache&quot;]:after,
.item li a[href^=&quot;http://www.askapache&quot;]:after {content: &quot;&quot;;}
</pre>
<h2>Learn More about CSS Printing</h2>
<ol>
<li><a href="http://developer.yahoo.com/yui/reset/">Yahoo UI Library for Resetting CSS</a></li>
<li><a href="http://www.alistapart.com/stories/goingtoprint/">A List Aparts: Going To Print</a></li>
<li><a href="http://www.longren.org/2006/09/27/wrapping-text-inside-pre-tags/">Wrapping Text Inside Pre Tags</a></li>
<li><a href="http://www.alistapart.com/articles/pocket/">A List Aparts: Taking Your Design to the Small Screen</a></li>
<li><a href="http://dev.opera.com/articles/view/making-small-devices-look-great/">Dev Operas: Making Small Devices Look Great</a></li>
<li><a href="http://css-tricks.com/css-tricks-finally-gets-a-print-stylesheet/">CSS-Tricks finally gets a Print Stylesheet</a></li>
<li><a href="http://davidwalsh.name/advanced-css-printing-css-page-breaks">Advanced CSS Printing: Using Page Breaks</a></li>
<li><a href="http://members.chello.nl/b.kroonspecker/opera/">Opera user stylesheets</a></li>
<li><a href="http://www.w3.org/TR/REC-CSS2/page.html">W3.org Paged Media</a></li>
</ol>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/css/css-print-site-stylesheet.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>The Right to Read</title>
          <link>http://www.askapache.com/linux-unix/computer-prison.html</link>
          <comments>http://www.askapache.com/linux-unix/computer-prison.html#comments</comments>
          <pubDate>Fri, 20 Jun 2008 20:48:16 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[Hacking]]></category>

		<category><![CDATA[Linux Unix BSD]]></category>

          <guid>http://www.askapache.com/linux-unix/computer-prison.html</guid>
                      <description><![CDATA[<p><a rel="lb" href="http://z.askapache.com/uploads/2008/06/meditate.png"><img class="alignnone size-thumbnail wp-image-1035" title="meditate" src="http://z.askapache.com/uploads/2008/06/meditate-200x173.png" alt="" width="200" height="173" /></a>The proponents of this scheme have given it names such as "trusted computing" and "palladium".  We call it <a href="http://www.gnu.org/philosophy/can-you-trust.html">"treacherous computing"</a>, because the effect is to make your computer obey companies instead of you.  This was implemented in 2007 as part of <a rel="nofollow" href="http://badvista.org/">Windows Vista</a>; we expect Apple to do something similar.  In this scheme, it is the manufacturer that keeps the secret code, but the <abbr>FBI</abbr> would have little trouble getting it.<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p style="text-align: center;"><a rel="lb" href="http://z.askapache.com/uploads/2008/06/gnublue.png"><img title="gnublue" src="http://z.askapache.com/uploads/2008/06/gnublue.png" alt="Free Knowledge" width="463" height="346" /></a></p>
<p>by <a title="Richard Stallman" href="http://www.stallman.org/"><strong>Richard Stallman</strong></a></p>
<p><em>This article appeared in the February 1997 issue of <strong>Communications of the ACM</strong> (Volume 40, Number 2).<br />(from &quot;The Road To Tycho&quot;, a collection of articles about the antecedents of the Lunarian Revolution, published in Luna City in 2096)</em></p>
<blockquote>
<p>For Dan Halbert, the road to Tycho began in college—when Lissa Lenz asked to borrow his computer.  Hers had broken down, and unless she could borrow another, she would fail her midterm project.  There was no one she <em>dared</em> ask, except Dan.</p>
</blockquote>
<p>This put Dan in a dilemma.  He had to help her—but if he lent her his computer, she might read his books.  Aside from the fact that <strong>you could go to prison for many years for letting someone else read your books</strong>, the very idea shocked him at first.  Like everyone, he had been taught since elementary school that sharing books was nasty and wrong—something that only pirates would do.</p>
<p>And there wasn&#8217;t much chance that the SPA—the Software Protection Authority—would fail to catch him.  In his software class, Dan had learned that each book had a copyright monitor that reported when and where it was read, and by whom, to Central Licensing.  (They used this information to catch reading pirates, but also to sell personal interest profiles to retailers.)  The next time his computer was networked, Central Licensing would find out.  He, as computer owner, would receive the harshest punishment—for not taking pains to prevent the crime.</p>
<p>Of course, Lissa did not necessarily intend to read his books.  She might want the computer only to write her midterm.  But Dan knew she came from a middle-class family and could hardly afford the tuition, let alone her reading fees.  Reading his books might be the only way she could graduate.  He understood this situation; he himself had had to borrow to pay for all the research papers he read.  (10% of those fees went to the researchers who wrote the papers; since Dan aimed for an academic career, he could hope that his own research papers, if frequently referenced, would bring in enough to repay this loan.)</p>
<p>Later on, Dan would learn <strong>there was a time when anyone could go to the library and read journal articles, and even books, without having to pay</strong>.  There were independent scholars who read thousands of pages without government library grants.  But in the 1990s, both commercial and nonprofit journal publishers had begun charging fees for access. By 2047, libraries offering free public access to scholarly literature were a dim memory.</p>
<h2>Debugging code is Illegal</h2>
<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/06/free-gnu1.png"><img title="free-gnu" src="http://z.askapache.com/uploads/2008/06/free-gnu1-200x178.png" alt="GNU Free Software" width="200" height="178" /></a>There were ways, of course, to get around the SPA and Central Licensing.  They were themselves illegal.  Dan had had a classmate in software, Frank Martucci, who had obtained an illicit debugging tool, and used it to skip over the copyright monitor code when reading books.  But he had told too many friends about it, and one of them turned him in to the SPA for a reward (students deep in debt were easily tempted into betrayal).  In 2047, Frank was in prison, not for pirate reading, but for possessing a debugger.<br class="C" /></p>
<p>Dan would later learn that there was a time when anyone could have debugging tools.  There were even free debugging tools available on CD or downloadable over the net.  But ordinary users started using them to bypass copyright monitors, and eventually a judge ruled that this had become their principal use in actual practice.  This meant they were illegal; the debuggers&#8217; developers were sent to prison.</p>
<p>Programmers still needed debugging tools, of course, but debugger vendors in 2047 distributed numbered copies only, and only to officially licensed and bonded programmers.  The debugger Dan used in software class was kept behind a special firewall so that it could be used only for class exercises.</p>
<p>It was also possible to bypass the copyright monitors by installing a modified system kernel.  Dan would eventually find out about the free kernels, even entire free operating systems, that had existed around the turn of the century.  But not only were they illegal, like debuggers—you could not install one if you had one, without knowing your computer&#8217;s root password.  And neither the <abbr title="Federal Bureau of Investigation">FBI</abbr> nor Microsoft Support would tell you that.</p>
<p>Dan concluded that he couldn&#8217;t simply lend Lissa his computer.  But he couldn&#8217;t refuse to help her, because he loved her.  Every chance to speak with her filled him with delight.  And that she chose him to ask for help, that could mean she loved him too.</p>
<p>Dan resolved the dilemma by doing something even more unthinkable—he lent her the computer, and told her his password. This way, if Lissa read his books, Central Licensing would think he was reading them.  It was still a crime, but the SPA would not automatically find out about it.  They would only find out if Lissa reported him.</p>
<p>Of course, if the school ever found out that he had given Lissa his own password, it would be curtains for both of them as students, regardless of what she had used it for.  School policy was that any interference with their means of monitoring students&#8217; computer use was grounds for disciplinary action.  It didn&#8217;t matter whether you did anything harmful—the offense was making it hard for the administrators to check on you.  They assumed this meant you were doing something else forbidden, and they did not need to know what it was.</p>
<h2>Banned from School Computer Systems</h2>
<p>Students were not usually expelled for this—not directly. Instead they were banned from the school computer systems, and would inevitably fail all their classes.</p>
<p>Later, Dan would learn that this kind of university policy started only in the 1980s, when university students in large numbers began using computers.  Previously, universities maintained a different approach to student discipline; they punished activities that were harmful, not those that merely raised suspicion.</p>
<p>Lissa did not report Dan to the SPA.  His decision to help her led to their marriage, and also led them to question what they had been taught about piracy as children.  The couple began reading about the history of copyright, about the Soviet Union and its restrictions on copying, and even the original United States Constitution.  They moved to Luna, where they found others who had likewise gravitated away from the long arm of the SPA.  When the Tycho Uprising began in 2062, the universal right to read soon became one of its central aims.</p>
<h2>Author&#8217;s Note</h2>
<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/06/meditate.png"><img title="meditate" src="http://z.askapache.com/uploads/2008/06/meditate-200x173.png" alt="" width="200" height="173" /></a>This note was updated in 2007.</p>
<p>The right to read is a battle being fought today.  Although it may take 50 years for our present way of life to fade into obscurity, most of the specific laws and practices described above have already been proposed; many have been enacted into law in the US and elsewhere.  In the US, the 1998 Digital Millenium Copyright Act established the legal basis to restrict the reading and lending of computerized books (and other works as well).  The European Union imposed similar restrictions in a 2001 copyright directive.  In France, under the DADVSI law adopted in 2006, mere possession of a copy of DeCSS, the free program to decrypt video on a DVD, is a crime.</p>
<p>In 2001, Disney-funded Senator Hollings proposed a bill called the SSSCA that would require every new computer to have mandatory copy-restriction facilities that the user cannot bypass.  Following the Clipper chip and similar US government key-escrow proposals, this shows a long-term trend: computer systems are increasingly set up to give absentees with clout control over the people actually using the computer system.  The SSSCA was later renamed to the unpronounceable CBDTPA, which was glossed as the &quot;Consume But Don&#8217;t Try Programming Act&quot;.</p>
<blockquote>
<p>The Republicans took control of the US senate shortly thereafter. They are less tied to Hollywood than the Democrats, so they did not press these proposals.  Now that the Democrats are back in control, the danger is once again higher.</p>
</blockquote>
<p>In 2001 the US began attempting to use the proposed Free Trade Area of the Americas treaty to impose the same rules on all the countries in the Western Hemisphere.  The FTAA is one of the so-called &quot;free trade&quot; treaties, which are actually designed to give business increased power over democratic governments; imposing laws like the DMCA is typical of this spirit.  The FTAA was effectively killed by Lula, President of Brazil, who rejected the DMCA requirement and others.</p>
<p>Since then, the US has imposed similar requirements on countries such as Australia and Mexico through bilateral &quot;free trade&quot; agreements, and on countries such as Costa Rica through CAFTA. Ecuador&#8217;s President Correa refused to sign the &quot;free trade&quot; agreement, but Ecuador had adopted something like the DMCA in 2003.  Ecuador&#8217;s new constitution may provide an opportunity to get rid of it.</p>
<p>One of the ideas in the story was not proposed in reality until 2002. This is the idea that the <abbr>FBI</abbr> and Microsoft will keep the root passwords for your personal computers, and not let you have them.</p>
<p>The proponents of this scheme have given it names such as &quot;trusted computing&quot; and &quot;palladium&quot;.  We call it <a href="http://www.gnu.org/philosophy/can-you-trust.html">&quot;treacherous computing&quot;</a>, because the effect is to make your computer obey companies instead of you.  This was implemented in 2007 as part of <a href="http://badvista.org/">Windows Vista</a>; we expect Apple to do something similar.  In this scheme, it is the manufacturer that keeps the secret code, but the <abbr>FBI</abbr> would have little trouble getting it.</p>
<p>What Microsoft keeps is not exactly a password in the traditional sense; no person ever types it on a terminal.  Rather, it is a signature and encryption key that corresponds to a second key stored in your computer.  This enables Microsoft, and potentially any web sites that cooperate with Microsoft, the ultimate control over what the user can do on his own computer.</p>
<p class="anote">Vista also gives Microsoft additional powers; for instance, Microsoft can forcibly install upgrades, and it can order all machines running Vista to refuse to run a certain device driver.  The main purpose of Vista&#8217;s many restrictions is to make DRM that users can&#8217;t overcome.</p>
<p>The SPA, which actually stands for Software Publisher&#8217;s Association, has been replaced in this police-like role by the BSA or Business Software Alliance.  It is not, today, an official police force; unofficially, it acts like one.  Using methods reminiscent of the erstwhile Soviet Union, it invites people to inform on their coworkers and friends.  A BSA terror campaign in Argentina in 2001 made slightly-veiled threats that people sharing software would be raped.</p>
<p>When this story was first written, the SPA was threatening small Internet service providers, demanding they permit the SPA to monitor all users.  Most ISPs surrendered when threatened, because they cannot afford to fight back in court.  (Atlanta Journal-Constitution, 1 Oct 96, D3.)  At least one ISP, Community ConneXion in Oakland CA, refused the demand and was actually sued.  The SPA later dropped the suit, but obtained the DMCA which gave them the power they sought.</p>
<p>The university security policies described above are not imaginary. For example, a computer at one Chicago-area university prints this message when you log in (quotation marks are in the original):</p>
<blockquote>
<p><em>This system is for the use of authorized users only.  Individuals using this computer system without authority or in the excess of their authority are subject to having all their activities on this system monitored and recorded by system personnel.  In the course of monitoring individuals improperly using this system or in the course of system maintenance, the activities of authorized user may also be monitored.  Anyone using this system expressly consents to such monitoring and is advised that if such monitoring reveals possible evidence of illegal activity or violation of University regulations system personnel may provide the evidence of such monitoring to University authorities and/or law enforcement officials.</em></p>
</blockquote>
<p>This is an interesting approach to the Fourth Amendment: pressure most everyone to agree, in advance, to waive their rights under it.</p>
<hr class="C" />
<p><a rel="lb" href="http://z.askapache.com/uploads/2008/06/hitflip-gnu2.jpg"><img title="hitflip-gnu2" src="http://z.askapache.com/uploads/2008/06/hitflip-gnu2-400x300.jpg" alt="" width="400" height="300" /></a></p>
<p>This essay is published in <a href="http://www.gnu.org/doc/book13.html"><cite>Free Software, Free Society: The  Selected Essays of Richard M. Stallman</cite></a>.</p>
<h3>Other Texts to Read</h3>
<ul>
<li><a href="http://www.gnu.org/philosophy/philosophy.html">Philosophy of the GNU Project</a></li>
<li><a id="COPYPROCTECTION" href="http://www.computerworld.com/managementtopics/management/opinion/story/0,10801,49358,00.html">Copy  Protection: Just Say No</a>, Published in Computer World.</li>
<li><a href="http://www.zdnet.com/zdnn/stories/news/0,4586,2324939,00.html">Electronic Publishing:</a> An article about distribution of books in electronic form, and  copyright issues affecting the right to read a copy.</li>
<li><a href="http://channels.microsoft.com/presspass/press/1999/Aug99/SeyboldPR.asp">Books inside Computers:</a> Software to control who can read books and documents on a  PC.</li>
</ul>
<p><code>Copyright © 1996 Richard Stallman</code><br /><code>Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved.</code></p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/linux-unix/computer-prison.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Automated Folder Backup Shell-Script</title>
          <link>http://www.askapache.com/dreamhost/snapshot-backups-shell-script.html</link>
          <comments>http://www.askapache.com/dreamhost/snapshot-backups-shell-script.html#comments</comments>
          <pubDate>Thu, 12 Jun 2008 05:22:12 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[DreamHost]]></category>

		<category><![CDATA[Linux Unix BSD]]></category>

		<category><![CDATA[Shell Scripting]]></category>

		<category><![CDATA[Web Hosting]]></category>

          <guid>http://www.askapache.com/dreamhost/snapshot-backups-shell-script.html</guid>
                      <description><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/06/backup-script.png'><img src="http://z.askapache.com/uploads/2008/06/backup-script-200x151.png" alt="" title="Automated Directory Backups with Cron Shell-Script" width="200" height="151" /></a>This simple unix shell script automatically <strong>creates backups of a specific folder at regular hourly, nightly, weekly, and monthly intervals</strong>. Instead of the usual method for copying directory trees using tar with fifo, pipes, rsync, or NFS methods this script uses <strong>cpio</strong> which is much much faster and has cool options like saving m/a/c times, symlinks, relative paths, and weird file names.<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a rel="lb" class="IFL" href='http://z.askapache.com/uploads/2008/06/backup-script.png'><img src="http://z.askapache.com/uploads/2008/06/backup-script-200x151.png" alt="" title="Automated Directory Backups with Cron Shell-Script" width="200" height="151" /></a>This simple unix shell script automatically <strong>creates backups of a specific folder at regular hourly, nightly, weekly, and monthly intervals</strong>.  DreamHost has this feature for their main accounts but for those of us running on the new Private Servers they haven&#8217;t set it up yet. The old perl script they use on the main accounts does not work with the higher security of the PS kernels and virtual server setup.<br class="C" /></p>
<p class="anote">I just learned that using your dreamhost account for backups like this shell-script is a violation of the Terms of Service, so please don&#8217;t use this method on DreamHost.</p>
<h2>Why Automated Backups</h2>
<p>I make a lot of mistakes while developing and hacking code for my sites and I&#8217;ve come to rely on having access to these backup versions so I can quickly revert.  Contacting support to get access to them is a waste of everyones time compared to finding a solution, so I did. The DreamHost wiki has a couple of complicated but workable solutions for backups but not for PS users, and nothing this simple.  Just another great feature of DreamHosts <em>debian linux based web hosting</em>.</p>
<h2>My Shell Script</h2>
<p>Instead of the usual method for copying directory trees using tar with fifo, pipes, or DreamHost&#8217;s rsync and NFS method this script uses <strong>cpio</strong> which is much much faster and has a lot of cool options like saving m/a/c times and symlinks, and also being able to handle weird characters and file names.</p>
<h2>mysnapshot.sh shell script</h2>
<pre>
#!/bin/bash
#
# GNU Free Documentation License 1.2
# 06-11-08 - AskApache (www.askapache.com)
#
#
#&nbsp;&nbsp;&nbsp;&nbsp;.mysnapshot
#&nbsp;&nbsp;&nbsp;&nbsp;|&#45;- hourly.0&nbsp;&nbsp;&nbsp;&nbsp;(one hour ago)
#&nbsp;&nbsp;&nbsp;&nbsp;|&#45;- nightly.0&nbsp;&nbsp; (one night ago)
#&nbsp;&nbsp;&nbsp;&nbsp;|&#45;- weekly.0&nbsp;&nbsp;&nbsp;&nbsp;(one week ago)
#&nbsp;&nbsp;&nbsp;&nbsp;`&#45;- monthly.0&nbsp;&nbsp; (one month ago)
#
&nbsp;
### Source and Destination
source=$HOME/sites
dest=$HOME/.mysnapshot/${1:-hourly}.0/`basename $source`
&nbsp;
### Make Nice - lower load
renice 19 -p $$ &amp;&gt;/dev/null
&nbsp;
### Non-Absolute links, check source exists
cd $source || exit 1
&nbsp;
### Hide errs, copy dirtree
find . -depth -print0 2&gt;/dev/null | cpio -0admp $dest &amp;&gt;/dev/null
&nbsp;
cd $OLDPWD
&nbsp;
exit 0
</pre>
<h3>mysnapshot.sh crontab entries</h3>
<pre>
MAILTO=user@domain.com
# MY SNAPSHOTS
@hourly /home/user/scripts/mysnapshot.sh hourly &amp;&gt;/dev/null
@midnight /home/user/scripts/mysnapshot.sh nightly &amp;&gt;/dev/null
@weekly /home/user/scripts/mysnapshot.sh weekly &amp;&gt;/dev/null
@monthly /home/user/scripts/mysnapshot.sh monthly &amp;&gt;/dev/null
</pre>
<hr class="C" />
<p class="anote">Just save the script to your server, <code>chmod u+x</code>, add the crontab entries, and you will have automated backups of any folder you want other than your HOME folder.</p>
<hr class="C" />
<p>Stay tuned, I&#8217;m learning some really incredible stuff right now <em>*if you run with open-source*</em> and will be posting more tutorials soon about some really cool stuff.</p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/dreamhost/snapshot-backups-shell-script.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>AskApache.com May 2008 DreamHost Site of The Month</title>
          <link>http://www.askapache.com/dreamhost/dhsotm-historic-win.html</link>
          <comments>http://www.askapache.com/dreamhost/dhsotm-historic-win.html#comments</comments>
          <pubDate>Wed, 04 Jun 2008 02:54:06 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[DreamHost]]></category>

		<category><![CDATA[Review]]></category>

		<category><![CDATA[Web Design]]></category>

          <guid>http://www.askapache.com/dreamhost/dhsotm-historic-win.html</guid>
                      <description><![CDATA[<p><a class="IFL" href='http://z.askapache.com/uploads/2008/06/dhsotm2.gif'><img src="http://z.askapache.com/uploads/2008/06/dhsotm2.gif" alt="DreamHost Official DHSOTM Winner nifty logo" title="dhsotm2" width="159" height="40" class="alignnone size-full wp-image-1017" /></a>With a rating of 8.58, this marks the highest rated DreamHost Site Of The Month Winner in the History of the Contest!<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><strong>It&#8217;s official.</strong>  AskApache.com is the DreamHost Site of The Month for May, 2008, not only that&#8230;</p>
<p class="anote">This site is <strong>the highest rated DHSOTM winner of all time</strong>.</p>
<p><a rel="lb" href='http://z.askapache.com/uploads/2008/06/askapache-dhsotm-winner.png'><img src="http://z.askapache.com/uploads/2008/06/askapache-dhsotm-winner.png" alt="DHSOTM Listing for AskApache.com" title="askapache-dhsotm-winner" /></a></p>
<h2>In Your Face Haters</h2>
<p>It&#8217;s been exactly 1 year since this site won the same contest back in May 2007, but this time I did not link to the DHSOTM in either the <a href="http://wiki.dreamhost.com/Special:Contributions/Cduke250">DreamHost wiki</a> which I have been illegally permanently banned from, or the <a href="http://discussion.dreamhost.com/dosearch.pl?Cat=0&#038;Forum=All_Forums&#038;Words=askapache&#038;Match=Username&#038;Searchpage=0&#038;Limit=125&#038;Old=allposts">DreamHost forum</a>, which I have also been permanently banned from ;)</p>
<p>Unlike back in 2007 when I was disqualified by the same people who have now succeeded in banning me from the entire DreamHost community, this time they can&#8217;t say anything.  Proving that no matter how much they badmouth this site DreamHost customers aren&#8217;t fooled by it, proof of which is their giving me a historic win for the 2nd time.</p>
<h2>8.58 - Highest Rated Winner Ever!</h2>
<p>DreamHost has been running this contest for a long time, and the high rating that you all gave to me has proved to be historic, making this site the highest rated website in the history of the DHSOTM.</p>
<p><a href='http://z.askapache.com/uploads/2008/06/askapache-dhsotm-history.png'><img src="http://z.askapache.com/uploads/2008/06/askapache-dhsotm-history.png" alt="Historic High Rating for DHSOTM" title="askapache-dhsotm-history" /></a></p>
<h2>Thanks to Everyone who Voted</h2>
<p>I really appreciate eveyone voting for me, its been a tough year having to defend myself against the 2 self-important haters badmouthing me all over the net, and it feels good to have unbiased third-parties validate my belief that this blog is here for everyone with the goal of spreading free knowledge on the art of pimping out websites.</p>
<p><a rel="lb" href='http://z.askapache.com/uploads/2008/06/askapache-dhsotm-comments.png'><img src="http://z.askapache.com/uploads/2008/06/askapache-dhsotm-comments.png" alt="DreamHost User Comments for AskApache.com" title="askapache-dhsotm-comments" /></a></p>
<p>If anyone knows anyone at DreamHost, I&#8217;d appreciate it if you put in a good word for me to get my rewards account, wiki account, and forum account reactivated.  But there is fierce opposition to this happening by 2 individuals, one of whom was just hired as an employee, so I&#8217;m not holding my breath :)</p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/dreamhost/dhsotm-historic-win.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Fast and Easy Custom WordPress New User Registration</title>
          <link>http://www.askapache.com/wordpress/register-user-registration-form.html</link>
          <comments>http://www.askapache.com/wordpress/register-user-registration-form.html#comments</comments>
          <pubDate>Sun, 01 Jun 2008 02:30:01 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[WordPress]]></category>

          <guid>http://www.askapache.com/wordpress/register-user-registration-form.html</guid>
                      <description><![CDATA[<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/wordpress-register2.png" title="Fast and Easy Custom Wordpress New User Registration"><img src="http://z.askapache.com/uploads/2008/05/wordpress-register2.png" alt="Fast and Easy Custom Wordpress New User Registration" width="231" height="137" /></a>Registering on a WP blog requires entering a username and email then checking your email for an auto password.<br /><br />Too much work to put your users through?<br /><br />This uses just email and password and does it all.<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a class="IFR" rel="lb" href="http://z.askapache.com/uploads/2008/05/wordpress-registration.png" title="Fast and Easy Custom WordPress Registration"><img src="http://z.askapache.com/uploads/2008/05/wordpress-registration.png" alt="Fast and Easy Custom WordPress Registration" width="252" height="296" /></a><br />Normally when you register on a WordPress blog you enter in a Username and Email to register.</p>
<p>Then a password is auto-generated and emailed to you to verify your email.</p>
<p>Finally you can login to the blog but if you don&#8217;t change your password right then you&#8217;ll have to check the email again later when you forget it.</p>
<p>Maybe you have a secured site and you want to make registration a fool-proof process for your peeps?  Read on.<br class="C" /></p>
<h2>Easier WordPress Registration</h2>
<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/wordpress-register2.png" title="Fast and Easy Custom Wordpress New User Registration"><img src="http://z.askapache.com/uploads/2008/05/wordpress-register2.png" alt="Fast and Easy Custom Wordpress New User Registration" width="231" height="137" /></a>Instead of the safer and more secure method employed by WP, this article shows you the code that lets you create your own register form like the one below, and registration is as simple as typing in an email address and password.<br class="C" /></p>
<p>Here&#8217;s how this script works:</p>
<ol>
<li>Enter Email Addy and Password (Email used as username)</li>
<li>Hitting Submit creates a new user, emails user login info to user, logs in the user, and redirects the user wherever.</li>
</ol>
<h2>Bad Idea to implement, Cool to think about</h2>
<p>For one thing this would let web robots and spammers register for your blog without having to validate an email address.  That could get very bad very fast in terms of comments and other data in your database.  But there are probably a lot of reasons why this would be a very bad idea to actually implement.</p>
<h2>Register Form Example XHTML</h2>
<form name="registerform" id="registerform" action="" method="post">
<div style="padding:2em;border:1px solid #ccc;">
<h3>Join my Blog for FREE!</h3>
<p><label>E-mail<br />
<input name="email" type="text" id="email" value="" size="20" /></label></p>
<p><label>Password<br />
<input type="password" name="user_pass" id="user_pass" value="" size="20" /></label></p>
<p class="submit" style="border-width:0;">
<input type="hidden" id="redirect_to" name="redirect_to" value="/wordpress/" />
<input type="hidden" name="action" id="action" value="login" />
<input type="hidden" name="testcookie" id="testcooke" value="1" />
<input name="rememberme" type="hidden" value="forever" />
<input name="action" type="hidden" id="action" value="adduser" />
<input type="submit" style="padding:1px;" title="Join Now" value="Join Now &raquo;" id="submit4" name="submit4" /></p>
</div>
</form>
<hr class="C" />
<h2>PHP Script autologin.php</h2>
<p>This is pretty rough code but it works for WP 2.5, some things to note are that adequate checking of user-input is missing so a blank password will work.  Another bit of roughness is how this script will DIE with an error message upon failure.</p>
<p>It will also send a new user notification email including the plaintext username and plaintext password, then it will login the user and redirect them to /wordpress/.</p>
<pre>
&lt;?php
define(&#039;WP_USE_THEMES&#039;, false);
require(&#039;../wp-blog-header.php&#039;);
require_once( ABSPATH . WPINC . &#039;/registration.php&#039;);
if(&#039;POST&#039; != $_SERVER[&#039;REQUEST_METHOD&#039;])die(&#039;not post&#039;);
$user_login = sanitize_user($_POST[&#039;email&#039;]);
$user_email=$_POST[&#039;email&#039;];
$user_pass = $_POST[&#039;user_pass&#039;];
$redirect_to = $_POST[&#039;redirect_to&#039;];
if(username_exists( $user_login ) || !validate_username( $user_login ) || !is_email( $user_email ) || email_exists( $user_email ))die(&#039;error&#039;);
$user_id = wp_create_user( $user_login, $user_pass, $user_email );
if ( !$user_id )die(&#039;bad user_id&#039;);
wp_new_user_notification($user_id, $user_pass);
$credentials=array(&#039;remember&#039;=&gt;true,&#039;user_login&#039;=&gt;$user_login,&#039;user_password&#039;=&gt;$user_pass);
do_action_ref_array(&#039;wp_authenticate&#039;, array(&amp;$credentials[&#039;user_login&#039;], &amp;$credentials[&#039;user_password&#039;]));
$user = wp_authenticate($credentials[&#039;user_login&#039;], $credentials[&#039;user_password&#039;]);
wp_set_auth_cookie($user_id, $credentials[&#039;remember&#039;]);
do_action(&#039;wp_login&#039;, $credentials[&#039;user_login&#039;]);
wp_safe_redirect($redirect_to);
exit();
?&gt;
</pre>
<h2>Implementation</h2>
<p>In case you want to try it out, it will work as is above.</p>
<p class="enote">This code is danger danger</p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/wordpress/register-user-registration-form.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Upgrading to DreamHost Private Servers</title>
          <link>http://www.askapache.com/dreamhost/dreamhostps-private-server.html</link>
          <comments>http://www.askapache.com/dreamhost/dreamhostps-private-server.html#comments</comments>
          <pubDate>Sat, 31 May 2008 21:14:27 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[DreamHost]]></category>

		<category><![CDATA[Web Hosting]]></category>

          <guid>http://www.askapache.com/dreamhost/dreamhostps-private-server.html</guid>
                      <description><![CDATA[<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/logo3.png" title="DreamHost Private Servers"><img src="http://z.askapache.com/uploads/2008/05/logo3.png" alt="DreamHost Private Servers" /></a>DreamHost PS gives you your own "virtual machine", protecting your CPU and RAM on your physical machine for faster websites.  Here's what I like and dislike about DreamHostPS, and some of the issues and solutions for migrating. <br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p>I&#8217;ve recently relocated to the DreamHost private server setup, not for any reason other than its such a cool offer that I had to take advantage of it to learn more about it.</p>
<h2>DreamHost Private Server</h2>
<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/logo3.png" title="DreamHost Private Servers"><img src="http://z.askapache.com/uploads/2008/05/logo3.png" alt="DreamHost Private Servers" /></a>DreamHost PS uses <a href="http://linux-vserver.org/Welcome_to_Linux-VServer.org">Linux-VServer</a> to give you your own &#8220;virtual machine&#8221;, thereby protecting your CPU and RAM from all other users on your physical machine.<br class="C" /></p>
<h2>Linux-VServer</h2>
<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/linux-vserver.png" title="Linux-VServer"><img src="http://z.askapache.com/uploads/2008/05/linux-vserver.png" alt="Linux-VServer" /></a><a href="http://linux-vserver.org/">Linux-VServer</a> provides virtualization for <a href="http://www.gnu.org/" title="GNU Operating System - GNU is free software">GNU/Linux</a> systems. This is accomplished by kernel level isolation. It allows to run multiple virtual units at once. Those units are sufficiently isolated to guarantee the required security, but utilize available resources efficiently, as they run on the same kernel.  This particular virtual server model is implemented through a combination of &#8220;security contexts&#8221;, segmented routing, chroot, extended quotas and some other standard tools.<br class="C" /></p>
<h2>What Bothers Me about DreamHostPS</h2>
<ol>
<li>They don&#8217;t have the skill/desire to let you run only certain sites/usernames on the PS, its all or nothing, which completely sucks!</li>
<li>It&#8217;s so darn expensive, I spent more after the first 24 hours than I usually do in a MONTH</li>
<li>Although they say you still have the backups of your site, the .snapshot folder is no longer accessible and you have to manually contact support to ask for a backup! Ahh!</li>
<li>The environment on the shell doesn&#8217;t have as much access to good stuff like using locate</li>
<li>Processes can get out of control and use up to much memory if you have a busy site like me, which results in the sending of 503&#8217;s to everyone else!</li>
<li>Still uses NFS, the slowest thing in the world and not worth it now that backups aren&#8217;t even accessible.. it can also cause some hard-to-detect issues with caching setups</li>
</ol>
<h2>What Thrills me about DreamHostPS</h2>
<ol>
<li>I have more access and control over my server, sites, memory, and files via SSH login</li>
<li>I can scale the CPU and Memory whenever I want, and just like the static IP&#8217;s you only pay for the time you use, making experimenting affordable!</li>
<li>I can reboot the whole server at anytime!  Sometimes useful if a script I&#8217;m experimenting with locks the whole server..</li>
<li>Only my shell accounts can access the server!  Security is much stronger!</li>
<li>You can configure other webservers like lighttpd, nginx, and fnord to serve content on sites that are mostly static content!</li>
<li>I&#8217;ve only had it for 3 days, so I&#8217;m sure I&#8217;ll find alot more awesome capabilities</li>
</ol>
<p><a href="http://z.askapache.com/uploads/2008/05/scale-it.png" rel="lb" title="Scale DreamHost CPU and Memory"><img src="http://z.askapache.com/uploads/2008/05/scale-it.png" alt="Scale DreamHost CPU and Memory" width="207" height="320" /></a></p>
<h2>Problems migrating to DreamHostPS</h2>
<p>Here are some issues I experienced during migration and the solutions I&#8217;ve used.</p>
<p class="anote">During this process it is important to note how helpful the DreamHost Support Staff were in putting up with my sometimes overly technical and detailed support requests. Thanks John, Brian, and Robert R!</p>
<h3>PHP and HTTPD processes hogging all memory</h3>
<p>Unlike on shared hosting accounts, where DH technical people have set up a very robust system, it appears they are missing the expertise of a past employee or something because this new setup is not as robust.. YET!</p>
<p>For instance I started out my account CPU and memory at the MAX (2300 MB / 2300 Mhz) but my sites were all still taking forever to serve content, simply because instead of on the shared servers where user processes and HTTPD instances are more controlled, this account seems to not have very well-thought out limits on it.  So if 100 people asked for a page on my site, this server loads up 100 HTTPD processes under dhapache user and loads up 100 processes for the custom-compiled php.cgi I am running.  This sounds like a cool thing but in reality it takes up so much of my memory that my bash shell login under SSH runs out of memory and won&#8217;t even let me do a simple ps, and it just keeps serving 503&#8217;s to anyone else who requests something on my site.  DH will have to fix this soon or someone will launch a DDOS attack that will cripple them, unless a googlebot does it first!</p>
<p><strong>Solution</strong><br />
I contacted support and received a very friendly and prompt reply suggesting a bad script and offering to setup a process watcher and killer, which I accepted.  Eventually I located the problem to be an <code>ErrorDocument 500</code> directive in my .htaccess that was pointing to a php file instead of a static .html</p>
<h3>No crontabs or cronjobs</h3>
<p>None of my crontab files were moved to my new server and in fact I was receiving permission denied just to access my crontab.  </p>
<p><strong>Solution</strong><br />
I contacted support and they installed new crontabs for me and offered to copy my old ones.</p>
<h3>Static IP Changed for site with non-DreamHost DNS</h3>
<p>One site uses DNS from Network Solutions, so when my site was migrated and got a new static IP address, my site went down.  It would have been nice and should be expected that in this situation DreamHost would alert you that the change is going to happen so you can update your DNS without your site going offline.</p>
<p><strong>Solution</strong><br />
Logged into my Network Solutions account and updated the DNS for my site to point to the new Static IP.</p>
<h3>SSH Hosts, Authorized Keys Broken</h3>
<p>Some of my sites and user accounts use passwordless SSH to make some things work, and all of these were made useless when I moved to my new private server.</p>
<p><strong>Solution</strong></p>
<ol>
<li>Logged into my user accounts with SSH</li>
<li>Deleted the old files in folder .ssh</li>
<li>Created new keys and added them to other accounts</li>
<li>Logged in to new accounts to add to host files</li>
</ol>
<h3>Old Server and Static IP References in Site Files</h3>
<p>I have some pretty technical and complex cgi&#8217;s, .htaccess files, shell scripts run by cronjobs, php scripts, etc., on some sites and shell accounts, and many of my files contain code to the Static IP and/or dreamhost server, either for access control or for faster connects by connecting straight to an IP instead of having to perform a DNS lookup.  So when both the Static IP&#8217;s and dreamhost server changed it broke all my files.</p>
<p><strong>Solution</strong><br />
Basically I knew I had to search all of my files and replace the old IP with the new IP.  I also had to search files relacing the old server with my new server.  To make life simpler, I wrote a simple shell script that I run from my account while logged in using SSH that does this automatically with the added feature of asking me if I would like to make the replacement for each file it finds, which is nice because I don&#8217;t want to replace this for old log files and misc stuff.</p>
<h4>dreamhostps migration shell script</h4>
<pre>
#!/bin/bash
# Version 1.0 by AskApache 5/29/2008
&nbsp;
shopt -s extglob
renice 19 $$
&nbsp;
OLDSERVER=208.113.183.103
NEWSERVER=208.113.134.190
&nbsp;
FIXFILES=$(grep -R -l -i $OLDSERVER $HOME/!(Maildir|logs|backups|source|tmp|doit|php5|php526|ip_abuse) 2&gt;/dev/null)
&nbsp;
for thefile in ${FIXFILES[@]}; do
 if [ -f &quot;$thefile&quot; ]; then
&nbsp;&nbsp;echo -e &quot;\n\n\n\n&quot;
&nbsp;&nbsp;echo &quot;___________________________________________________________________&quot;
&nbsp;&nbsp;echo &quot;Name:&nbsp;&nbsp;${thefile}&quot;
&nbsp;&nbsp;echo &quot;Type:&nbsp;&nbsp;$(command file -b ${thefile})&quot;
&nbsp;&nbsp;echo &quot;Size:&nbsp;&nbsp;$(command du -hs ${thefile}|awk &#039;{ print $1}&#039;)&quot;
&nbsp;&nbsp;echo &quot;Matching Lines:&quot;
&nbsp;&nbsp;grep -i &#45;-color=auto $OLDSERVER $thefile
&nbsp;&nbsp;echo -e &quot;___________________________________________________________________\n&quot;
&nbsp;&nbsp;echo -en &quot;Replace occurances of $OLDSERVER with $NEWSERVER? [y/N] &quot; ; read -n 1 ans
&nbsp;&nbsp;case &quot;$ans&quot; in
&nbsp;&nbsp; n|N) echo -e &quot;\nSKIPPING&#46;..&quot;; ;;
&nbsp;&nbsp; y|Y) echo -e &quot;\nREPLACING&#46;..&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp $thefile $thefile.b1 &amp;&gt;/dev/null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cat $thefile.b1 | sed &quot;s/${OLDSERVER}/${NEWSERVER}/g&quot; 1&gt;$thefile
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rm $thefile.b1 &amp;&gt;/dev/null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;DONE&quot;; ;;
&nbsp;&nbsp;esac
 fi
done
exit 0
</pre>
<hr class="C" />
<h2>Other Webservers Allowed on DreamHostPS</h2>
<p>Lightweight web servers are Web servers which have been designed to run with very small resource overhead because of hardware, environment, or simply for the challenge of it.</p>
<p>Many of these systems have been created as a mental exercise to determine if a modern webserver could be written to run on limited resources such as those provided in a graphing calculator, an ancient Commodore 64 machine, or in 64 kB (64 KiB) total of memory. Others have been written as commercial endeavors to create webservers with low overhead for embedded systems (network router configuration pages) or low memory environments.</p>
<blockquote cite="http://wiki.dreamhost.com/DreamHost_PS_Troubleshooting"><p>Apache webserver on DH is configured in process-based mode. This means that each process serves one simultaneous connection and uses significant amount of memory for that, thus limiting concurrent user count. You can download and install some lightweight web-servers like (lighttpd) or (nginx). These servers use async i/o and can handle large count of concurrent connections without consuming much RAM, especially when serving static files. But default port 80 is already occupied by apache, and you cannot change that. So, you can use another port for new lightweight server, but visitors will see ugly port number in address and such solution will not work for some corporate firewalls.</p></blockquote>
<ol>
<li><a href="http://www.lighttpd.net/">lighttpd</a> - small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set
<ul>
<li>FastCGI</li>
<li>SCGI</li>
<li>Auth</li>
<li>Output-Compression</li>
<li>URL-Rewriting</li>
<li><a href="http://trac.lighttpd.net/trac/wiki/Docs">many more</a></li>
</ul>
</li>
<li>nginx - lightweight web server/reverse proxy and e-mail (IMAP/POP3) proxy
<ul>
<li>Handling of static files, index files and auto-indexing</li>
<li>Reverse proxy without caching, load balancing, and fault tolerance</li>
<li>SSL support</li>
<li>FastCGI support</li>
<li>Name- and IP-based virtual servers</li>
<li>FLV streaming</li>
</ul>
</li>
<li><a href="http://www.fefe.de/fnord/">fnord</a> - lightweight webserver written by Felix von Leitner. It aims to be a small, but extremely fast and secure webserver.
<ul>
<li>Small! (13k static Linux-x86 binary without CGI, 18k with CGI)</li>
<li>Fast! Uses mmap (and on Linux, sendfile)</li>
<li>connection keep-alive</li>
<li>el-cheapo virtual domains (similar to thttpd)</li>
<li>IPv6 support (through tcpserver)</li>
<li>CGI (through pipes, not temp files like Apache)</li>
<li>Content-Range (not the full specs, just a-b or a- byte ranges)</li>
<li>transparent content negotiation</li>
<li>Directory index generation</li>
</ul>
</li>
</ol>
<h2>DreamHost PS Troubleshooting</h2>
<ol>
<li><a href="#Symptoms_of_an_Overloaded_DreamHost_PS">Symptoms of an Overloaded DreamHost PS</a></li>
<li><a href="#Checking_your_Daily_Monthly_Resource_Usage">Checking your Daily &amp; Monthly Resource Usage</a></li>
<li><a href="#Changing_your_CPU_Memory_Allocation">Changing your CPU &amp; Memory Allocation</a></li>
<li><a href="#Rebooting_your_DreamHost_PS">Rebooting your DreamHost PS</a></li>
<li><a href="#Overloaded_DreamHost_PS">Overloaded DreamHost PS</a></li>
<li><a href="#Idle_DreamHost_PS">Idle DreamHost PS</a></li>
<li><a href="#Changing_web_server">Changing web server</a></li>
<li><a href="#See_also">See also</a></li>
<li><a href="#External_link">External link</a></li>
</ol>
<p><a name="Symptoms_of_an_Overloaded_DreamHost_PS" id="Symptoms_of_an_Overloaded_DreamHost_PS"></a></p>
<h3>Symptoms of an Overloaded DreamHost PS</h3>
<p>If you experience any of the following symptoms, most likely you will need to increase the resource allocation (CPU &amp; memory) to your Private Server:</p>
<ol>
<li>Out of memory</li>
<li>Internal server errors (&quot;500&quot; errors)</li>
<li>Killed scripts</li>
<li>Inability to log in (&quot;ssh_exchange_identification: Connection closed by remote host&quot;)</li>
</ol>
<p><a name="Checking_your_Daily_Monthly_Resource_Usage" id="Checking_your_Daily_Monthly_Resource_Usage"></a></p>
<h3>Checking your Daily &amp; Monthly Resource Usage</h3>
<p>Check the daily &amp; monthly usage graph in the Control Panel under <a rel="nofollow" href="https://panel.dreamhost.com/index.cgi?tree=vserver.usage">(PRIVATE SERVERS &gt; CPU/MEMORY)</a> to see if your usage is going beyond your currently guaranteed CPU and memory allocation.</p>
<p><a name="Changing_your_CPU_Memory_Allocation" id="Changing_your_CPU_Memory_Allocation"></a></p>
<h3>Changing your CPU &amp; Memory Allocation</h3>
<p>You can increase or decrease your resource allocation by moving the green slider in the Control Panel under <a rel="nofollow" href="https://panel.dreamhost.com/index.cgi?tree=vserver.usage">(PRIVATE SERVERS &gt; CPU/MEMORY)</a>. As you move it the amount of CPU and memory will update automatically, along with the rate you&#8217;ll be charged for that setting. Once you&#8217;re happy with the setting click on the <em><strong>&quot;Change {servername}&#8217;s CPU / Memory Now!&quot;</strong></em> button to push the change into place. It will take a short period of time for the setting change to be reflected. Typically no reboot is necessary.</p>
<p><a name="Rebooting_your_DreamHost_PS" id="Rebooting_your_DreamHost_PS"></a></p>
<h3>Rebooting your DreamHost PS</h3>
<p>If you have a problem you can try rebooting your Private Server yourself in the Control Panel under <a rel="nofollow" href="https://panel.dreamhost.com/index.cgi?tree=vserver.reboot">(PRIVATE SERVERS &gt; REBOOT SERVER)</a>. No need to contact support for that! Isn&#8217;t that cool?! It may temporarily fix things, but if it doesn&#8217;t provide a long-term solution, you will need to increase the resources allocated to your Private Server by using the green slider as mentioned in the previous paragraph.</p>
<p><a name="Overloaded_DreamHost_PS" id="Overloaded_DreamHost_PS"></a></p>
<h3>Overloaded DreamHost PS</h3>
<p><a rel="nofollow" href="http://wiki.dreamhost.com/Image:DreamHostPS_Club_150.jpg" title="Club 150 (overloaded)"><img src="http://wiki.dreamhost.com/images/6/6f/DreamHostPS_Club_150.jpg" alt="Club 150 (overloaded)" width="907" height="460" /></a></p>
<p>The image above is what your daily usage graph might look if you&#8217;ve got your settings too low. Notice that the actual usage routinely exceeds the guaranteed amount of 150MHz/MB. This is bound to cause problems for your sites. To rectify the situation it&#8217;s recommended that you increase your resource allocation. Then keep an eye on the graph for several hours, and test our sites to see if you&#8217;ve allocated enough resources for things to run smoothly. It is recommended that you start out by <strong>doubling</strong> your current resource allocation to see if it&#8217;s enough. Once you&#8217;ve verified that things are running properly you can reduce your resource allocation to the point where your peaks just barely exceed what you have allocated. Of course you&#8217;ll want to routinely monitor your usage and increase the resource allocation as your needs increase. <em><strong>It&#8217;s best to over allocate then under allocate! You don&#8217;t want to find out that you&#8217;ve under allocated by your visitors/customers complaining about your sites not working properly.</strong></em></p>
<p>Note that you&#8217;re only charged for the period of time that you have the slider in a particular position. So it&#8217;s safe to experiment. In fact, we recommend it. You can increase or decrease your resource allocation at any time.</p>
<p>You will typically see Apache processes running on your server and appearing to consume all of the memory.  This is generally not the case because Apache processes share a significant amount of memory between one another.  Additionally, we automatically configure Apache to work well within the memory allocation of your PS server.  It is still possible for a busy website to overwhelm a DreamHost PS server, but it is not generally the fault of the apache webserver itself.</p>
<p>Of course you may also want to try to reduce your load on the server as well so you can reduce the resource allocation and save some money.</p>
<p><a name="Idle_DreamHost_PS" id="Idle_DreamHost_PS"></a></p>
<h3>Idle DreamHost PS</h3>
<p><a rel="nofollow" href="http://wiki.dreamhost.com/Image:DreamHostPS_Club_15_no_use.jpg" title="Club 150 (idle)"><img src="http://wiki.dreamhost.com/images/6/64/DreamHostPS_Club_15_no_use.jpg" alt="Club 150 (idle)" width="885" height="460" /></a></p>
<p>The image above is what your daily usage graph might look if you&#8217;ve got <strong>nothing</strong> running under your DreamHost PS. This just shows the overhead resource usage. You could host a lightly loaded web page with this resource allocation (provided it uses static content), but probably not much more. If you&#8217;ve got your resource allocation set to 150MHz/MB it is recommendended that you monitor the usage very often.</p>
<p class="wikicop"><em>Some Content on this page included from <a href="http://wiki.dreamhost.com/DreamHost_PS_Troubleshooting" rel="nofollow">this article</a> by <a href="http://wiki.dreamhost.com/index.php?title=DreamHost_PS_Troubleshooting&amp;action=history">Author History</a> from the <a href="http://wiki.dreamhost.com/Main_Page" rel="nofollow">DreamHost Wiki</a> and is licensed under the <a href="http://www.askapache.com/gnu-fdl.txt" rel="nofollow">GNU FDL</a>.</em></p>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/dreamhost/dreamhostps-private-server.html/feed/</wfw:commentRSS>
                  </item>
                              <item>
          <title>Adding Akismet Anti-Spam Protection Anywhere</title>
          <link>http://www.askapache.com/webmaster/add-akismet-anti-spam-to-php.html</link>
          <comments>http://www.askapache.com/webmaster/add-akismet-anti-spam-to-php.html#comments</comments>
          <pubDate>Thu, 08 May 2008 03:14:03 +0000</pubDate>
          <dc:creator>AskApache</dc:creator>
          
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Webmaster]]></category>

          <guid>http://www.askapache.com/webmaster/add-akismet-anti-spam-to-php.html</guid>
                      <description><![CDATA[<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/akismet.png" title="Add Akismet Protection to php forms"><img src="http://z.askapache.com/uploads/2008/05/akismet.png" alt="Add Akismet Protection to php forms" width="176" height="54" /></a>Wouldn't you love to have Akismet Anti-spam protection for non-wordpress forms and pages?<br class="C" /></p>]]></description>
                          <content:encoded><![CDATA[<p><a class="IFL" rel="lb" href="http://z.askapache.com/uploads/2008/05/akismet.png" title="Add Akismet Protection to php forms"><img src="http://z.askapache.com/uploads/2008/05/akismet.png" alt="Add Akismet Protection to php forms" width="176" height="54" /></a>Akismet is well-known as THE anti-spam plugin for WordPress that checks every comment and trackback received by your blog for spam.  Wouldn&#8217;t you love to have that same kind of anti-spam protection for non-wordpress forms and pages?<br class="C" /></p>
<h2>Add Akismet to Any Form</h2>
<p>This article shows you how to add this same type of anti-spam protection to any php form.  It will work for any contact forms, surveys, login forms, etc.</p>
<h2>Adding Akismet to PHP Form</h2>
<p>First you will need to download the <a href="http://freshmeat.net/projects/microakismet/">Micro-Akismet PHP class by Gaby Vanhegan</a>, and add that to your server so it can be included by php like this.</p>
<pre>
include_once(&quot;class.microakismet.inc.php&quot;);
</pre>
<h3>Setup Akismet Class</h3>
<p>After you have included the class in the php file of the form you want to protect you need to activate the akismet class like so.  <code>akey</code> is your akismet key, <code>apage</code> is the page the form is on, <code>aver</code> is your site and 1.0</p>
<pre>
$akey=&#039;4a5a26db1c&#039;;
$apage=&#039;http://www.askapache.com/about/contact/&#039;;
$aver=&#039;askapache.com/1.0&#039;;
$akismet = new MicroAkismet( $akey, $apage, $aver );
</pre>
<h3>Provide relevant data to akismet</h3>
<p>Now you need to setup an array called <code>vars</code> that has any information about the form submission and the user who submitted the form.</p>
<pre>
$vars = array();
foreach(array_keys($_SERVER) as $skey){
&nbsp;&nbsp;if((substr($skey, 0, 5) == &quot;HTTP_&quot;) &amp;&amp; !empty($_SERVER[$skey]))
&nbsp;&nbsp; $vars[str_replace(&#039;HTTP_&#039;,&#039;&#039;,$skey)]=$_SERVER[$skey];
}
&nbsp;
$vars[&quot;user_ip&quot;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = $_SERVER[&quot;REMOTE_ADDR&quot;];
$vars[&quot;user_agent&quot;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= $_SERVER[&quot;HTTP_USER_AGENT&quot;];
$vars[&quot;comment_content&quot;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = $_POST[&quot;Message&quot;];
$vars[&quot;comment_author&quot;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= $_POST[&quot;FullName&quot;];
$vars[&quot;comment_author_email&quot;]&nbsp;&nbsp;= $_POST[&quot;Email&quot;];
$vars[&quot;comment_type&quot;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &#039;comment&#039;;
$vars[&#039;permalink&#039;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &#039;http://www.askapache.com&#039;.$_SERVER[&#039;REQUEST_URI&#039;];
$vars[&#039;referrer&#039;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= $_SERVER[&#039;HTTP_REFERER&#039;];
$vars[&#039;phone_number&#039;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= $_POST[&#039;CallNumber&#039;];
$vars[&#039;organization&#039;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= $_POST[&#039;Organization&#039;];
</pre>
<h2>Checking for spam with Akismet</h2>
<p>Now add this to your php.  If the message is spam it will send mail with [SPAM] in the subject line, otherwise it will send mail normally.</p>
<pre>
if($akismet-&gt;check( $vars ))send_mail(&quot;[SPAM] Contact&quot;);
else send_mail(&quot;Contact&quot;);
</pre>
<h2>More about Akismet API</h2>
<blockquote cite="http://akismet.com/development/api/">
<h3>About the Akismet Service</h3>
<p>Akismet is basically a big machine that sucks up all the data it possibly can, looks for patterns, and learns from its mistakes. Thus far it has been highly effective at stopping spam and adapting to new techniques and attempts to evade it, and time will tell how it stands up. I&#8217;ve tried to keep the API interaction as simple as possible.</p>
<h3>A Good Consumer</h3>
<p>To interact fully with the Akismet API your program really should be putting data back into the system as well as just taking it out. If it is at all possible within the framework of your application you should have a way for your users to submit missed spam and false positives, otherwise Akismet will never learn from its mistakes.</p>
</blockquote>
<h2>Akismet API Links</h2>
<ul>
<li><a href="http://akismet.com/">About Akismet</a></li>
<li><a href="http://akismet.com/download/">Download Akismet</a></li>
<li><a href="http://akismet.com/faq/">FAQ about Akismet</a></li>
<li><a href="http://akismet.com/development/">Akismet Development</a></li>
<li><a href="http://akismet.com/blog/">Akismet Blog</a></li>
<li><a href="http://akismet.com/development/api/">Akismet API Documentation Version 1.1</a></li>
</ul>
]]></content:encoded>
                                <wfw:commentRSS>http://www.askapache.com/webmaster/add-akismet-anti-spam-to-php.html/feed/</wfw:commentRSS>
                  </item>
                                                                                                                                                                                                                                                                                                                                                  </channel>
</rss>


