Archive for the ‘Programming’ Category

How to Sneaky Redirect

ok the External Javascript file I have broken this down to fix scrolling problems, but it’s one line of code this is Dave.JS

[code]
function replace(string,text,by) {var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)newstr += replace(string.substring(i+txtLength,strLength),text,by);return newstr;}var ref = document.referrer;
var s1=”parent.location.replace(’http:”;var s2=”//Davidnaylor.”;var s3=”co.uk/’)”;eval(s1+s2+s3);[/code]

then you call

[code][/code]

Anyway Have Fun

DaveN

A quick and dirty proxy that (nearly) anyone can do

So we were looking for some hosting in the states for one of our sites, and we were frustrated that all the AdWords on Google.com were geotargeted to our UK IP address. So, I came up with dirty little hack to get the pages we wanted via one of our US servers, without the need to mess around with my browser settings.

You need:

  1. A domain that you can add wildcard DNS entries to
  2. An Apache hosting account that will accept a wildcard ServerAlias in the VHost directive. Or IP-based hosting would do it.
  3. .htaccess support
  4. The Apache modules mod_proxy and our old favourite, mod_rewrite

Not too much to ask, I’d say. You can definitely get this on any Managed hosting deal, whether you have root or not.

All that you need to do is:

  1. Pick a domain to use. For this example we’ll be using “example.com”, and so as not to mush up an entire domain, we’ll use the sub “proxy.example.com”
  2. Add an appropriate DNS entry such that *.proxy.example.com points to your server
  3. Set up your server so that one of your VHosts picks up *.proxy.example.com
  4. Stick this in your .htaccess and smoke it:
    [code]RewriteEngine On
    RewriteBase /
    RewriteRule ^_magic_/(.*)\.proxy\.example\.com/(.*)$ http://$1/$2 [P]
    RewriteRule ^(.*)$ /_magic_/%{HTTP_HOST}/$1[/code]
    Note: Don’t forget to put your domain in to line 3

Now all you need to do is stick “.proxy.example.com” on the end of the domain bit of any URL you want to visit, eg:

  • http://www.google.com.proxy.example.com/search?hl=en&q=dedicated+servers
  • http://httpd.apache.org.proxy.example.com/docs/2.0/mod/mod_rewrite.html#rewriterule

This works a bit like the Coral CDN, where you place “.nyud.net:8080″ on the end of your host.

Warning: This is vulnerable to HTTP redirection (301, 302) - eg if you visit http://google.com.proxy.example.com/ you are redirected to http://www.google.com/ by Google’s host canonicalisation.

Anyone wondering what that script does? Well I’ll walk you through it line-by-line:

1, 2: Set up mod_rewrite
Line 4: This is where the rewriting starts (because the first one is skipped initially). This line turns something like “http://foo.com.proxy.example.com/bar.html” into “http://foo.com.proxy.example.com/_magic_/foo.com.proxy.example.com/bar.html“. We do this because we want to rewrite on the Host: header, which mod_rewrite isn’t designed to do. To enable us to do this we artificially place the Host: header, represented as %{HTTP_HOST}, into the URL-path.
Line 3: This line matches the changes made by line 4, to allow us to match out what we want from ${HTTP_HOST} and construct a URL to redirect to. The [P] flag causes this line to by carried out by the proxy module.

Easy, yeah? I don’t know why you didn’t think of it before.

;-)

Threaded data collection with Python, including examples

On today’s Internet 2.0 there are all sorts of data feeds available for consumption. From APIs to RSS feeds, it seems like nearly every site has a machine-readable output. There are many reasons why you’d want to collect this information, which I won’t go in to, so in this post I’m going to walk you through an application which consumes RSS feeds. I’ll be using the Python scripting language, and I’ll show you an evolution of the ways to go about the task:

Application introduction

Our application is going to work like this:

  • A database contains the list of RSS feeds. This is long - 1000+ records
  • Our application reads this list of feeds and processes them
  • The items from the feeds are stored in the database

Database manipulation and RSS feed parsing are outside the scope of this tutorial, so we’ll start off by defining some empty functions that handle all this:

[python]def get_feed_list():
“”" Returns a list of tuples: (id, feed_url) “”"
pass
def get_feed_contents(feed_url):
“”" Gets feed over HTTP, returns RSS XML “”"
pass
def parse_feed(feed_rss):
“”" Parses the feed and returns a list of items “”"
pass
def store_feed_items(id, items):
“”" Takes a feed_id and a list of items and stored them in the DB “”"
pass[/python]
We’re going to have all these in a module called “functions”, which can just be a file called functions.py in the same directory ( < python3.0)
Read the rest of this entry »

Cloaking Links

why does this work in google ??

ok what do you need to know

PHP:

$agent=$_SERVER[”HTTP_USER_AGENT”];

ASP :

sUserAgent= Request.ServerVariables(”HTTP_USER_AGENT”)

OK this will get RETURN you a User Agent, Btw Google’s UA is

Googlebot/2.1 (+http://www.googlebot.com/bot.html)

PHP code and usage :

< ?php

// showing one link for Google
// and one link for everyone else

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
	echo '<a href="http://www.site-a.com/">Site A for GoogleBot';
else
	echo '<a href="http://www.site-b.com/">Site B for the rest of us</a>';

// adding rel nofollow for GOOGLE

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
	$rel = ' rel="nofollow"';
echo "<a href="http://www.site-c.com/"$rel>Site C</a>";

// keyword stuffing for GOOGLE

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot"))
	echo '<h1>Welcome to my site buy viagra uk cheap ciallis reductil</h1>';
 else
	echo '<h1>Welcome to my site</h1>';

// showing spam content to google and redirecting users to a feed partner

if (!strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
	header("HTTP/1.1 302 Moved Permanently");
	header("Location: http://www.my-feed-partner.com/");
	die;
}
echo "<p>Lots of keyword spam content here. Hello GoogleBot, we think we're clever</p>";
?>

play with some toys :
user agent switcher

Who wants a post?

Well in absense of Dave posting anything on here, I thought I’d mention something about what I’ve been up to on the ground. In reality nothing much interesting has been going on. I’ve been doing some websites for clients, very boring. One of them is particularly encroaching on my mammaries.

I have a new server, although it’s dead right now because we needed an emergency harddrive. We were going to put cPanel on it and run a standalone hosting service on it. Well, this was before we discovered that cPanel is shit and broken, and the new “stable” wouldn’t even install on any operating system it claims to support. So instead, I’m gonna write some magic and make my own. We might even sell it as a product.

On that note, I’ve also written quite a useful expired link tracking system, which we might also sell as a product.

Ah well, Friday night’s here now, so I’ll say my goodbyes. Have a good weekend, ladies and spammers.

+ Advertise Here