[nanny] Add new firefox win32 blocker



commit 5b194857b8999fed88650280415421261fc056b0
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Tue Jan 18 03:18:58 2011 +0100

    Add new firefox win32 blocker

 client/gnome/Makefile.am                           |    6 +
 client/gnome/admin/Makefile.am                     |    2 +-
 client/gnome/nanny-firefox-win32/Makefile.am       |    2 +
 .../nanny-firefox-win32/nanny-firefox-blocker      |  116 ++++++++++++++++++++
 configure.ac                                       |    1 +
 daemon/src/Win32WebContentFiltering.py             |   48 ++++++++
 6 files changed, 174 insertions(+), 1 deletions(-)
---
diff --git a/client/gnome/Makefile.am b/client/gnome/Makefile.am
index da547d1..de6639b 100644
--- a/client/gnome/Makefile.am
+++ b/client/gnome/Makefile.am
@@ -1,4 +1,10 @@
+if NANNY_POSIX_SUPPORT
 SUBDIRS=admin systray
+endif
+
+if NANNY_WIN32_SUPPORT
+SUBDIRS=admin systray nanny-firefox-win32
+endif
 
 clientgnomedir = $(pythondir)/nanny/client/gnome
 clientgnome_PYTHON = __init__.py
diff --git a/client/gnome/admin/Makefile.am b/client/gnome/admin/Makefile.am
index 4030e40..a45e46c 100644
--- a/client/gnome/admin/Makefile.am
+++ b/client/gnome/admin/Makefile.am
@@ -1,5 +1,5 @@
 SUBDIRS=data src
 
-sbin_SCRIPTS = nanny-admin-console nanny-desktop-blocker
+sbin_SCRIPTS = nanny-admin-console nanny-desktop-blocker 
 
 EXTRA_DIST = nanny-admin-console nanny-desktop-blocker
diff --git a/client/gnome/nanny-firefox-win32/Makefile.am b/client/gnome/nanny-firefox-win32/Makefile.am
new file mode 100644
index 0000000..57e7aa5
--- /dev/null
+++ b/client/gnome/nanny-firefox-win32/Makefile.am
@@ -0,0 +1,2 @@
+sbin_SCRIPTS=nanny-firefox-blocker
+EXTRA_DIST=nanny-firefox-blocker 
diff --git a/client/gnome/nanny-firefox-win32/nanny-firefox-blocker b/client/gnome/nanny-firefox-win32/nanny-firefox-blocker
new file mode 100644
index 0000000..b15278f
--- /dev/null
+++ b/client/gnome/nanny-firefox-win32/nanny-firefox-blocker
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2009,2010,2011 Junta de Andalucia
+# 
+# Authors:
+#   Roberto Majadas <roberto.majadas at openshine.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+import os
+import glob
+import sys
+import StringIO
+import win32com
+from win32com.shell import shell, shellcon
+import ctypes
+import win32ts
+
+if os.name == "nt" :
+    if not hasattr(sys, "frozen") :
+        root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+        nanny_lib_path = os.path.join(root_path, "lib", "python2.6", "site-packages")
+        sys.path.append(nanny_lib_path)
+    else:
+        sys.stdout = open(os.devnull, 'w')
+        sys.stderr = open(os.devnull, 'w')
+
+if __name__ == '__main__':
+    if len(sys.argv) == 2:
+        print sys.argv[1]
+        if os.path.exists("C:\\Documents and Settings\\%s" % sys.argv[1]) :
+            data_dir = "C:\\Documents and Settings\\%s" % sys.argv[1]
+            user_prefs_list = glob.glob(os.path.join(data_dir, "*", "Mozilla", "Firefox", "Profiles", "*", "prefs.js"))        
+        elif os.path.exists("C:\\Users\\%s\\AppData\\Roaming" % sys.argv[1]) :
+            data_dir = "C:\\Users\\%s\\AppData\\Roaming" % sys.argv[1]
+            user_prefs_list = glob.glob(os.path.join(data_dir, "Mozilla", "Firefox", "Profiles", "*", "prefs.js"))
+        else:
+            sys.exit(0)
+    else:
+        user_prefs_list = glob.glob(os.path.join(os.environ["APPDATA"], "Mozilla", "Firefox", "Profiles", "*", "prefs.js"))
+    
+    proxy_conf_ok = True
+
+    for pref_file in user_prefs_list :
+        sio = StringIO.StringIO()
+        rewrite_it = False
+        
+        with open(pref_file, "r") as f :
+            for line in f.readlines():
+                if "network.proxy.type" in line :
+                    proxy_conf_ok = False
+                    rewrite_it = True
+                else:
+                    sio.write(line)
+        
+        if rewrite_it == True :
+            print "Rewritting %s" % pref_file
+            with open(pref_file, "w") as f :
+                f.write(sio.getvalue())
+        else:
+            print "Not needed rewritting %s" % pref_file
+        
+        sio.close()
+
+    if proxy_conf_ok == False :
+        if len(sys.argv) == 2:
+            ret = os.system("taskkill.exe /F /IM firefox.exe /T > NUL")
+        else:
+            ret = os.system("taskkill.exe /F /IM firefox.exe /T > NUL")
+
+        if ret != 0 :
+            sys.exit(0)
+        
+        import gobject
+        import gtk
+        import gettext
+        import __builtin__
+        
+        __builtin__._ = gettext.gettext
+        
+        def launch_dialog() :
+            dlg = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK)
+            dlg.set_property("icon-name", "nanny")
+            dlg.set_markup("<b>%s</b>" % _("You change firefox proxy settings"))
+            dlg.format_secondary_markup(_("You can't change the proxy settings "
+                                      "because you are under parental control."))
+            
+            dlg.run()
+            dlg.destroy()
+            sys.exit(0)
+        
+        gobject.timeout_add (1, launch_dialog)
+        gobject.timeout_add (10000, sys.exit, 0)
+        
+        gtk.main()
+        
+        
+
+        
+        
+
+        
+
diff --git a/configure.ac b/configure.ac
index 8a96524..684e3b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -265,6 +265,7 @@ client/gnome/admin/data/ui/Makefile
 client/gnome/admin/data/icons/Makefile
 client/gnome/admin/src/Makefile
 client/gnome/admin/src/__init__.py
+client/gnome/nanny-firefox-win32/Makefile
 daemon/Makefile
 daemon/data/Makefile
 daemon/data/applists/Makefile
diff --git a/daemon/src/Win32WebContentFiltering.py b/daemon/src/Win32WebContentFiltering.py
index 35082b0..b1b3bfd 100644
--- a/daemon/src/Win32WebContentFiltering.py
+++ b/daemon/src/Win32WebContentFiltering.py
@@ -34,6 +34,7 @@ from twisted.enterprise import adbapi
 
 from nanny.daemon.proxy.TwistedProxy import ReverseProxyResource as ProxyService
 from nanny.daemon.proxy.Controllers import WebDatabase
+from nanny.daemon.Win32SessionFiltering import WinPopenAsUser
 
 import _winreg
 
@@ -55,6 +56,23 @@ class Win32WebContentFiltering(gobject.GObject) :
         gobject.GObject.__init__(self)
         self.quarterback = quarterback
         self.app = app
+        self.ffb = None
+
+        if not hasattr(sys, "frozen") :
+            file_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+            for x in range(6):
+                file_dir = os.path.dirname(file_dir)
+            root_path = file_dir
+            sbin_dir = os.path.join(root_path, "sbin")
+            if os.path.exists(os.path.join(sbin_dir, "nanny-firefox-blocker")) :
+                self.ffb = "python %s" % os.path.join(sbin_dir, "nanny-firefox-blocker")
+        else:
+            sbin_dir = os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( )))
+            if os.path.exists(os.path.join(sbin_dir, "nanny-firefox-blocker.exe")):
+                self.ffb = os.path.join(sbin_dir, "nanny-firefox-blocker.exe")
+
+        if self.ffb != None :
+            print "[Win32WebContentFiltering] firefox blocker blocker : '%s'" % self.ffb
 
         database_exists = False
         if os.path.exists(WEBDATABASE) :
@@ -75,6 +93,7 @@ class Win32WebContentFiltering(gobject.GObject) :
         self.quarterback.connect("remove-wcf-to-uid", self.__stop_proxy)
 
         self.update_proxy_settings_hd = None
+        self.update_proxy_settings_firefox_hd = None
 
         self.proxy_helper = Win32ProxyHelper(self.quarterback.usersmanager)
         
@@ -92,6 +111,9 @@ class Win32WebContentFiltering(gobject.GObject) :
         
         if self.update_proxy_settings_hd != None :
             gobject.source_remove(self.update_proxy_settings_hd)
+        if self.update_proxy_settings_firefox_hd != None :
+            gobject.source_remove(self.update_proxy_settings_firefox_hd)
+        
         self.proxy_helper.clean_all_proxy_conf()
 
     def __start_proxy(self, quarterback, uid):
@@ -119,7 +141,33 @@ class Win32WebContentFiltering(gobject.GObject) :
 
     def __launch_proxy_updater(self):
         self.update_proxy_settings_hd = gobject.timeout_add(1000, self.__update_proxy_settings)
+        self.update_proxy_settings_firefox_hd = gobject.timeout_add(5000, self.__update_proxy_settings_firefox)
+
+    def __update_proxy_settings_firefox(self):
+        session_uid = int(self.quarterback.win32top.get_current_user_session())
+        if session_uid != 0 :
+            if self.services.has_key(str(session_uid)) :
+                user_name = None
+                for uid, name, fullname in self.quarterback.usersmanager.get_users() :
+                    if uid == str(session_uid) :
+                        user_name = name
+                        break
+                
+                if user_name != None :
+                    reactor.callInThread(self.__launch_firefox_blocker, self, user_name)
+        
+        return True
 
+    def __launch_firefox_blocker(self, wcf, user_name):
+        import time
+        try:
+            p = WinPopenAsUser(wcf.ffb + " %s" % user_name)
+            while p.poll() == None:
+                time.sleep(1)
+        except:
+            print "[W32WebcontentFiltering] firefox blocker exception"
+        
+        
     def __update_proxy_settings(self):
         session_uid = int(self.quarterback.win32top.get_current_user_session())
         if session_uid != 0 :



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]