views:

176

answers:

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
+2  A: 

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?

Jacob

TheJacobTaylor
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.
Zachary Brown
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
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?
Zachary Brown
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!
Zachary Brown
@Zachary Brown Excellent, I am glad that it worked out for you.
TheJacobTaylor
A: 

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.

jeffamaphone
I am sorry, but this answer did not seem clear to me. :( Could you please explain a little bit? Thanks for the prompt response.
Zachary Brown
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.
jeffamaphone
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!
Zachary Brown