2

I am working on a project for work and have seemed to run into a small problem. The project is a similar program to Web Nanny, but branded to my client's company. It will have features such as website blocking by URL, keyword and web activity logs. I would also need it to be able to "pause" downloads until an acceptable username and password is entered.

I found a script to monitor the URL visited in Internet Explorer (shown below), but it seems to slow the browser down considerably. I have not found any support or ideas onhow to implement this in other browsers.

So, my questions are:

1). How to I monitor other browser activity / visited URLs? 2). How do I prevent downloading unless an acceptable username and password is entered?


from  win32com.client import Dispatch,WithEvents
import time,threading,pythoncom,sys

stopEvent=threading.Event()
class EventSink(object):

    def OnNavigateComplete2(self,*args):
        print "complete",args
        stopEvent.set()


def waitUntilReady(ie):
    if ie.ReadyState!=4:
        while 1:
            print "waiting"
            pythoncom.PumpWaitingMessages()
            stopEvent.wait(.2)
            if stopEvent.isSet() or ie.ReadyState==4:
                stopEvent.clear()
                break;

time.clock()
ie=Dispatch('InternetExplorer.Application',EventSink)
ev=WithEvents(ie,EventSink)
ie.Visible=1
ie.Navigate("http://www.google.com")

waitUntilReady(ie)
print "location",ie.LocationName
ie.Navigate("http://www.aol.com")
waitUntilReady(ie)
print "location",ie.LocationName
print ie.LocationName,time.clock()
print ie.ReadyState
Zac Brown
  • 5,905
  • 19
  • 59
  • 107

2 Answers2

2

I would recommend looking into a nice web proxy. If the machines are all on the same network you can implement a transparent caching web proxy and put filtering rules on it. They tend to be high speed and can do lots of cool things.

I have had some luck with Squid. Would this solve your situation?

halfer
  • 19,824
  • 17
  • 99
  • 186
TheJacobTaylor
  • 4,063
  • 1
  • 21
  • 23
  • Actually, I use squid on my home network. But, what I need is some kind of protection, written in Python, that can be installed on each individual machine. My client's shop is a computer repair shop, so when the system is fixed, they will add the software as an extra. Thank you for your prompt response. Thank you for your prompt response. – Zac Brown Jun 08 '10 at 02:51
  • In that case, I would recommend looking into software the protects the entire machine at the network. There are many packages out there Norton Internet Security being one. I am sure there are open source versions out there as well. Browsers are easy to replace (removing your plugin). Network configuration is typically a little harder. – TheJacobTaylor Jun 08 '10 at 03:32
  • I think a web proxy might just be the key for what I want. How would I go about building one in Python? I would use it for the URL and keyword blocking. Then, I would write a client ot put on the computer that checks every few seconds to make sure the browser is set to use a proxy. If it isn't, it sets that! It seems like a pretty easy way of doing things as well. How would I go about doing this in Python? Know of any good tutorials for building web proxies? – Zac Brown Jun 08 '10 at 18:15
  • Thanks for the great idea Jacob! Sorry it took so long for me to say this, but a proxy was exactly what I needed. I coded one the other night, and have modified it to work with my software to provide the best protection possible(ish)! Thanks again! – Zac Brown Jul 31 '10 at 03:22
  • @Zachary Brown Excellent, I am glad that it worked out for you. – TheJacobTaylor Aug 03 '10 at 23:48
0

You need to implement this as a C++ BHO, sink DWebBrowserEvents2::OnBeforeNavigate and implement your logic there as it is a place that will block the navigate synchronously until you return, and you can cancel the navigation there as well.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
  • I am sorry, but this answer did not seem clear to me. :( Could you please explain a little bit? Thanks for the prompt response. – Zac Brown Jun 08 '10 at 15:15
  • What I'm saying is the way you're doing it isn't the way it's meant to be done. If you want to do it the right way, a way that will be fast, you need to implement a Browser Helper Object in C++ and sink the proper COM event dispatching interfaces. I will edit my answer and add links to documentation for you. It won't be easy or trivial to do it this way, btw. – i_am_jorf Jun 08 '10 at 17:13
  • OK, thanks. I will check it out. I was hoping there was a way to do this in pure Python, is that possible? I don't know C++, so I think this will be very difficult. I will check out the links though. Thanks! – Zac Brown Jun 08 '10 at 17:48