views:

124

answers:

7

Howdy,

I have a simple basic program in mind to keep my kids off certain websites for prolonged periods of time.

Basically, I would like to run a little background process that would have something like this :

if (user is on website for > 20 minutes every 24 hours )
   {
     browser redirect user to specified website
   }

I realise I could easily get a third party program that would do this, but I'd enjoy doing it myself ! The problem is that I have absolutely no idea how to understake such a project - or even what languages I could use to make something like this. I have a fairly decent knowledge of PHP and Java and am always learning, so any suggestions for a way to go about this would be really appreciated !

Thanks a lot :)

A: 

If you are using FireFox, you can probably achieve this with a GreaseMonkey script.

Chris Judge
Thanks for the response, ideally I would like to do something a little more complex though ! :)
John Murphy
+2  A: 

There is no simple basic program that will do this.

Something like this requires that they are always using the same browser, and that it publishes an inter-process API that allows you to see what websites are being viewed and navigate to other websites. That's a lot of assumptions. Your kids could always use a different browser, or they could kill the process on the system. No matter what software you install on their machine, there is almost invariably a way for them to get around it. There's not going to be an easy way to do it.

The best solution is hard. Basically, it's firewalling. Set up a firewall in your house and put a filter on packets being forwarded. Inspect the packets to find HTTP requests, and intercept them. Log what's being requested and if it exceeds your limit, rewrite the packets how you want.

It might be a better idea to just look for a commercial software that does what you want.

Erick Robertson
I had the same general idea of making a firewall. Note that this only prohibits further *requests* though. If I park myself on my favourite flash gaming site and play the same game for hours, this strategy would do nothing to stop me. A slightly different direction would be to rewrite the packet to include a meta refresh after a certain timeout for such static pages. Very complex though.
Mark Peters
Thanks a lot for the thoughts ! :) Well, to be honest, the point isn't so much to keep my kids from doing this, but so that I can learn how I would go about doing something like this myself.I am a second year CS student, so its more of a goal of learning experience than a parenting one !
John Murphy
I like the way you completely dismiss the possibility to write a local http proxy for doing so ...
Riduidel
I like the way kids seem to be able to bypass anything local, given enough time.
Erick Robertson
Not to mention that even if you used a proxy the kids could still edit the internet options to go around the proxy. Or just use an anonymizer website.
controlfreak123
My kids won't be able to bypass anything. They are very young and can barely use a keyboard let alone terminate processes running in task manager, so this wouldn't be a problem at all.
John Murphy
A: 

I think you could achieve that kind of feature with a programmable proxy. In the ruby world, there was, during _why's existence, the fantastic MouseHole. Unfortunatly, those times are gone. Nowadays, using Java, I would take a look at things like this document. Finally, you can also take a look at proxomitron.

Riduidel
A: 

Parent your kids directly, instead of by proxy.

Rather than creating a proxy to parent your kids, you should do so directly. It will allow you to effect their growth more directly, increase your bond with them, and make you an all-around better parent. It will enrich both of your lives far more than using a cold unhuman firewall to notify them "You have been spending too much time on this site. Time to go outside."

Erick Robertson
I know how to parent my kids, thank you. It's more a case of wanting to learn how to write this code.
John Murphy
A: 

I see two simple way to approach this problem:

  1. You can write an extension for your preferred browser. Look, for example, at Firefox Building an Extension tutorial.
  2. You can write a http(s) proxy and set your browser to use it.

I do not recommend the 2nd one, IMHO it requires too much work for a simple in-home solution.

andcoz
Perfect, thanks a lot for the link ! :)
John Murphy
A: 

Short answer is that this is a fairly difficult problem to solve because of the reasons cited by Erick.

The only way to do it would be to set up something along the lines of WireShark that would analyze all network traffic on the machine and look for requests made to a certain url pattern (facebook) and start a timer whenever it happens. However, there are additional complexities when one wants to say, "I don't want to spend more than 20 minutes here a day" because it's nearly impossible in todays web to define what it means to spend 20 minutes at a site. See this thread on the OS X Hints forums for a helpful discussion on why this is hard. It basically boils down to the way websites do requests for you these days rather than you manually clicking. Of course, if you don't care about the user actually being there, but just giving them 20 minutes a day from the first time the log on to the site, then the problem becomes a little easier.

You could figure out how to write software for your router as one possible project. Using Tomato or DD-WRT gets you the ability to control what's running on your router and would give the centralized access you need to place a sniffer on the whole network (especially if you have multiple PCs you're trying to do this to). Of course, that adds the complexity in of trying to figure out what it means for one person to spend time on the website over against another. If all your PCs are single user then the problems not that hard but if you have multiple users per PC then you run into not even being able to key off of the IP address as a unique user.

If you don't want to program your router, then you'd have to write up a network sniffer and install it on every machine. Something like jNetStream might give you a nice head start as writing a network sniffer probably doesn't qualify as a "simple" program like you thought you were going to write.

Anyway, once you get that set up and running you'd just have to figure out how to hook it into your OS. I doubt any language is really "inappropriate" for that task so have at it!

Tim Visher
A: 

You need to program a (smart) http proxy server for that. This is generaly considered a non trivial activity. But hey, there are hackers out their who say it can be done:

A HTTP Proxy Server in 20 Lines of node.js Code (It uses the node.js library)

Just add you're own logic and there you are. King of the proxy hill ;-)

Kdeveloper