[nanny] Add Win32UsersManager



commit 63c44ac755e5519a1a8c55cbdb02d2aa1bd5a21a
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Tue Sep 14 19:37:40 2010 +0200

    Add Win32UsersManager

 daemon/src/Makefile.am          |    3 +-
 daemon/src/QuarterBack.py       |   13 +++++---
 daemon/src/Win32UsersManager.py |   57 +++++++++++++++++++++++++++++++++++++++
 daemon/src/__init__.py          |    7 ++++-
 4 files changed, 73 insertions(+), 7 deletions(-)
---
diff --git a/daemon/src/Makefile.am b/daemon/src/Makefile.am
index d874fda..36f349c 100644
--- a/daemon/src/Makefile.am
+++ b/daemon/src/Makefile.am
@@ -12,7 +12,8 @@ corelib_PYTHON =	 __init__.py 			\
 			LinuxWebContentFiltering.py 	\
 			LinuxUsersManager.py		\
 			LinuxSessionFiltering.py	\
-			LinuxSessionCKFiltering.py
+			LinuxSessionCKFiltering.py	\
+			Win32UsersManager.py
 
 if HAS_HACHOIR_REGEX
 dgimporterdir = $(pythondir)/nanny/daemon
diff --git a/daemon/src/QuarterBack.py b/daemon/src/QuarterBack.py
index 29ec76c..0b257a9 100644
--- a/daemon/src/QuarterBack.py
+++ b/daemon/src/QuarterBack.py
@@ -30,11 +30,14 @@ import pickle
 import time
 from datetime import datetime, timedelta
 
-from LinuxFiltering import LinuxFiltering as FirewallFilter
-from LinuxWebContentFiltering import LinuxWebContentFiltering as WebContentFilter
-from LinuxUsersManager import LinuxUsersManager as UsersManager
-from LinuxSessionCKFiltering import LinuxSessionCKFiltering as SessionFilter
-from FilterManager import FilterManager as FilterManager
+if os.name == "posix" :
+    from LinuxFiltering import LinuxFiltering as FirewallFilter
+    from LinuxWebContentFiltering import LinuxWebContentFiltering as WebContentFilter
+    from LinuxUsersManager import LinuxUsersManager as UsersManager
+    from LinuxSessionCKFiltering import LinuxSessionCKFiltering as SessionFilter
+    from FilterManager import FilterManager as FilterManager
+elif os.name == "nt" :
+    from Win32UsersManager import Win32UsersManager as UsersManager
 
 from Chrono import Chrono
 
diff --git a/daemon/src/Win32UsersManager.py b/daemon/src/Win32UsersManager.py
new file mode 100644
index 0000000..eb26356
--- /dev/null
+++ b/daemon/src/Win32UsersManager.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2009,2010 Junta de Andalucia
+# 
+# Authors:
+#   Roberto Majadas <roberto.majadas at openshine.com>
+#   Cesar Garcia Tapia <cesar.garcia.tapia at openshine.com>
+#   Luis de Bethencourt <luibg at openshine.com>
+#   Pablo Vieytes <pvieytes 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 time
+import win32com.client
+
+class Win32UsersManager:
+    def __init__(self):
+        self.last_time = None
+        self.users = None
+        
+    def get_users (self):
+        if self.last_time != None and time.time() - self.last_time <= 60 :
+            return users
+
+        users=[]
+        oWMI = win32com.client.GetObject(r"winmgmts:\\.\root\cimv2")
+        qry = "Select * from Win32_UserAccount Where LocalAccount = True and Disabled = False"
+        qry = oWMI.ExecQuery(qry)
+        if qry.count > 0:
+            for result in qry:
+                uid = str(result.SID).split("-")[-1]
+                users.append(uid, unicode(result.Name), unicode(result.FullName))
+        self.last_time = time.time()
+        return users
+
+    def has_changes (self):
+        if self.last_time == None :
+            return True
+        
+        if time.time() - self.last_time > 60 :
+            return True
+
+        return False
diff --git a/daemon/src/__init__.py b/daemon/src/__init__.py
index e950344..7b98044 100644
--- a/daemon/src/__init__.py
+++ b/daemon/src/__init__.py
@@ -23,7 +23,12 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 # USA
 
-from LinuxUsersManager import LinuxUsersManager as UsersManager
+import 
+if os.name == "posix" :
+    from LinuxUsersManager import LinuxUsersManager as UsersManager
+elif os.name == "nt" :
+    from Win32UsersManager import Win32UsersManager as UsersManager
+
 from QuarterBack import QuarterBack
 from Daemon import Daemon
 



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