Archive

Posts Tagged ‘dynamic IP’

Wordpress Installation, Finished

February 3rd, 2009

Found this from a month and a half ago, waiting as a draft:

So, I mostly finished the WordPress installation. I got everything for WordPress up and running, tested my Blogger URL redirection script and then switched over my subdomain redirection.

The blogger redirection takes two parts, but is in fact quite simple. First, I went into the directory where the Blogger content had lived – /srv/www/htdocs/blog and moved everything in there into another directory, out of the way. I then created a .htaccess in the directory like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
</IfModule>

All this does is used mod_rewrite to serve blog/index.php up for every page request. In index.php, I handle the important URL forms for Blogger – archives, tags, feeds, and posts – and redirect to the appropriate place. For archives, I just parse out the year and month from the Blogger URL and redirect to the proper page for WP. The feed is straight redirection. The tags (”labels” in Blogger parlance) are pulled out of the URL, have spaces (after urldecode()) replaced with dashes and are redirected to the right tag for WP.

The posts, on the other hand, were a bit more difficult. My solution ended up being parsing the post name out of the URL. When I used the import tool, WP kept the original Blogger URLs in the wp_postmeta table with a meta_key of “blogger_permalink”. I just looked for a Blogger permalink matching the title from the Blogger URL, found the corresponding post ID and redirected to the proper new WP URL.

The code for index.php, for me, looks something like:

<?php
// redirect old Blogger URLs in /blog to new WordPress in /wp
$request = mysql_real_escape_string(str_replace("/blog", "", $_SERVER['REQUEST_URI']));
 
// handle constant stuff like feeds and top-level pages
// TODO
if(strpos($request, "_archive.html"))
{
    // redirect to an archive
    $request = substr($request, strpos($request, "/", 1)+1);
    $ary = explode("_", $request);
    $redirect_to = "http://blog.jasonantman.com/".$ary[0]."/".$ary[1]."/";
    header("Location: ".$redirect_to);
    die();
}
elseif(strpos($request, "labels/"))
{
    // redirect to a tag page
    $redirect_to = substr($request, strpos($request, "labels/")+7);
    $redirect_to = str_replace(".html", "", $redirect_to);
    $redirect_to = urldecode($redirect_to);
    $redirect_to = str_replace(" ", "-", $redirect_to);
    $redirect_to = "http://blog.jasonantman.com/tags/".strtolower($redirect_to)."/";
    header("Location: ".$redirect_to);
    die();
}
elseif(strpos($request, "/blogger.html"))
{
    // redirect to main blog
    header("Location: http://blog.jasonantman.com/");
    die();
}
elseif(strpos($request, "/atom.xml"))
{
    // redirect to new feed
    header("Location: http://blog.jasonantman.com/feed/");
    die();
}
 
// handle the posts, months, tags, etc.
$fail = false;
$redirect_to = "";
$conn = mysql_connect()   or die("Error. MySQL connection failed at mysql_connect");
if(! $conn)
{
    error_log("SCRIPT ".$_SERVER['PHP_SELF'].": "."Unable to connect to MySQL.");
    $fail = true;
}
$select = mysql_select_db('wordpress');
if(! $select)
{
    error_log("SCRIPT ".$_SERVER['PHP_SELF'].": "."Unable to select DB wordpress.");
    $fail = true;
}
$query = "SELECT m.meta_key,m.meta_value,p.post_name,p.post_date FROM wp_postmeta AS m LEFT JOIN wp_posts AS p ON m.post_id=p.ID WHERE m.meta_key='blogger_permalink' AND m.meta_value='".$request."';";
$result = mysql_query($query);
if(! $result)
{
    error_log("SCRIPT ".$_SERVER['PHP_SELF'].": "."Error in query: ".$query." ERROR: ".mysql_error());
    $fail = true;
}
if(mysql_num_rows($result) < 1)
{
    // couldn't find an appropriate page
    // TODO: find a better way... for now just redirect to the month page
    $ary = explode("/", $request);
    if(count($ary) > 3)
    {
        $redirect_to = "http://blog.jasonantman.com/".$ary[1]."/".$ary[2]."/";
    }
    else
    {
        $redirect_to = "http://blog.jasonantman.com/";
    }
}
else
{
    $row = mysql_fetch_assoc($result);
    $redirect_to = "http://blog.jasonantman.com/".date("Y", strtotime($row['post_date']))."/".date("m", strtotime($row['post_date']))."/".$row['post_name'];
}
 
if($fail)
{
    // redirect to main page with 302
    Header( "Location: http://blog.jasonantman.com/" ); // implicit 302
}
else
{
    // redirect to the post or month
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: ".$redirect_to );
}
 
?>

So, it now looks like I’m pretty much done with setup, and even get to keep my links. The one interesting problem that will crop up is due to the fact that, at the moment, I’m hosting off of a dynamically IPed residential internet connection, so I’m at http://jantman.dyndns.org:10011. The problem lies in the fact that Blogger used this for its’ URIs and Permalinks, and it seems that (though http://blog.jasonantman.com uses a 302 not a 301 to redirect) Google, Technorati, etc. have indexed my site with this hostname and port, instead of the redirecting subdomain. Normally this wouldn’t be a problem, but I plan on soon moving to a business hosting account with 5 static IPs and port 80 open. Which means that soon the subdomain will become “real”… and all of those pesky dyndns.org:10011 links will be obsolete. The only way I can think of fixing this is, once I make the switch to static IP and port 80 (which will also include moving all of my subdomains to name-based virtual hosts) I’ll have to craft RewriteRules or redirect rules to replace http://jantman.dyndns.org:10011/wp/ with http://blog.jasonantman.com/, update DynDNS with my new static IP, and keep a default vhost listening on 10011 to provide rule-based redirection to the new subdomain. Eek.

Projects , , ,

IT Conspiracy

December 15th, 2006

The “true” Internet is based on freedom. The original ‘net, a system of BBS’s and mailservers each with their own address format, was free.

More and more, that freedom is fading away. We have ads. Popups. Content filters. KGB-esque ISP’s. The great advent of centralized, high-bandwidth IPS’s, instead of person-to-person dial-up connections, has changed what the Internet is.

Now, I don’t want to sound like I’m bashing progress. I’m vary glad to have a home internet connection of 10 mbps down / 1.5 mbps up.

The problem that I have is that the concept of freedom on the Internet is based on its’ distributed architecture. In the old days, with dial-up links, there was no real backbone, per se, and the ‘net was really owned by its’ users, by everyone.

Part I: The Block

In 2006, we see an increasing trend towards the ‘net being owned and run by monopolies. Not to group them together, but companies such as Google, AOL, and Microsoft aim to provide an all-encompassing Internet experience. The former is a wonderful resource, while the latter two are evil. However, as these monsters evolve, and the Internet moves from a distributed architecture to that of one central pipeline, is freedom gradually fading away?

The case in point, and impetus for all this, was a recent event:
When I got my first high-bandwidth home connection, CableVision’s Optimum Online, it was amazing. And, though I’m sure they didn’t know it, it was perfect. My “dynamic” IP was leased for a few months at a time, so my domains just pointed right to it. I’d change them when it rolled over. Aside from the rollover day, and the fact that my IP didn’t reverse-validate (only a problem when trying to run a mail server, though I solved that by relaying outgoing mail), I had a completely functional connection.

Then, FiOS exploded on suburbia. Fiber-optic, high-bandwidth lines to the residence, claiming 5mbps down/1mpbs up. I was hooked. Verizon installed it on the first day it was available. The technician was still as amazed as I was, and was a real technician, not one of the trained morons that take over once the bugs are worked out.

The connection speed was amazing. Then I went to change over my domain names. Could it be possible? Yes. A conspiracy. Optimum had in their TOS that you couldn’t run a server, but I always figured it was a way to get rid of unruly customers. Well, Verizon thought otherwise. All incoming requests were blocked on port 80. Yes, they were attempting to actually prevent anyone from hosting their own web sites.

Well, simple fix. I had my domain names registered through GoDaddy, so I just bound Apache to port 10011 (an unused port) and forwarded my domains to http://xxx.xxx.xxx.xxx:10011. Beautiful. For about 24 hours. Then they stopped working. I was in a panic. I had returned to college, and had no access to my machines. I frantically called my mother at home. The her ‘net was working. She could ping my machines. What could it be?

It took me a minute to think of it. I instructed her on how to find the WAN IP. She read it off. Sure enough, it changed. I updated the IP, logged in, and, of course! The Verizon DHCP lease was less than 72 hours. Enter dynDNS.org, a wonderful (and free service) that provides DNS resolution with a client program resident on one of your servers or routers, keeping their DNS records for you up-to-date. A bit of a kludge, but now jantman.dyndns.org pointed to my IP, and jasonantman.com pointed to jantman.dyndns.org:10011.

For over a year, it’s worked. I’ve harbored resentment against Verizon, but at over 100% more expensive, I can’t possibly afford their static IP FiOS. So, I’ve just been infinitely upset at Verizon’s desire to quash free speech, freedom of use and, in my opinion, part of what the Internet’s about.

Part II: The Conspiracy

Since then, my father (who works at a very large state agency) has never been able to view my web page. Nobody else has complained of this problem. I get indexed by the search engine bots, and get plenty of hits. But my father can’t see my web site.

Now, I know that his entire organization, (supposedly back-end also) is run on Windoze, or, as I prefer to call it, the Blue Plague. So, I was already suspicious of their IT infrastructure.

Well, finally, I gave in, and asked him to e-mail his IT guys. The response that I got: They block any web requests to any port other than 80.

From a security standpoint, I can see this as being a potentially useful trick. However, the sheer reality of it is baffling. Residential ISP’s block any requests to a server on port 80, and meanwhile, large companies block all outgoing HTTP requests to anything other than port 80.

At what point will the users take back the Internet, and put ourselves in control again? How is it that we have allowed pop-ups, spyware, and our ISP’s and corporations telling us what content they want us to get, and what content we can provide to other people?

When will we users finally stand up and say, “This is what we want. This is what is expected of you, and we will not let you tell us otherwise”?

Ideas and Rants , , , ,