[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-logonpy/usr/share/se3/logonpy/ -> se3Logon.py (source)

   1  # -*- coding: utf-8 -*-
   2  import sys, os, posix
   3  from se3Utils import *
   4  
   5  class se3Logon:
   6  
   7      def __init__ (self, path2BatFiles, path2Templates, user, computer, master, arch, urlse3):
   8          """
   9              Open logon bat, some initializations
  10          """
  11          try: 
  12              self.__logonU = open ("%s/machine/%s/logon.cmd" % (path2BatFiles, computer), 'w')
  13              self.__logonC = open ("%s/machine/%s/startup.cmd" % (path2BatFiles, computer), 'w')
  14              self.__logoffU = open ("%s/machine/%s/logoff.cmd" % (path2BatFiles, computer), 'w')
  15              self.__logoffC = open ("%s/machine/%s/shutdown.cmd" % (path2BatFiles, computer), 'w')
  16              self.__logonU.write ("start /B cscript //B %SYSTEMROOT%\Printers.vbs\r\n")
  17              self.__logonC.write ("start /B cscript //B %SYSTEMROOT%\Printers.vbs\r\n")
  18              self.__logonC.write ("echo Machine ok>%SYSTEMROOT%\System32\Grouppolicy\Se3.log\r\n")
  19              self.__logoffC.write ("del /s /f /q %SYSTEMROOT%\System32\Grouppolicy\Se3.log\r\n")
  20  
  21              self.__tplPath = path2Templates
  22              self.__batPath = path2BatFiles
  23              self.__user = user
  24              self.__computer = computer
  25              self.__master = master
  26              self.__arch = arch
  27              self.__urlse3 = urlse3
  28  
  29          except OSError:
  30              print "Can't create %s/%s/.bat" % (computer, user)
  31              sys.exit (1)
  32  
  33      def __del__ (self):
  34          """
  35              Close logon bat
  36          """
  37          try:
  38              if not os.access ("%s/machine/%s/gpt.ini" % (self.__batPath, self.__computer), os.F_OK):
  39                      self.__logonU.write ("gpupdate /force\r\n")
  40              else:
  41                      self.__logonU.write ("gpupdate /Target:computer /force\r\n")
  42              self.__logonC.write ("reg add \"HKEY_USERS\.DEFAULT\Control Panel\Keyboard\" /v InitialKeyboardIndicators /d 2 /f\r\n") # not working with gpo
  43  
  44              if self.__arch == "Vista":
  45                  # Remove public folder from explorer
  46                  self.__logonC.write ("reg delete HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{4336a54d-038b-4685-ab02-99bb52d3fb8b} /f\r\n")
  47                  self.__logonC.write ("reg delete HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{4336a54d-038b-4685-ab02-99bb52d3fb8b} /f\r\n")
  48                  self.__logonC.write ("reg delete HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{59031a47-3f72-44a7-89c5-5595fe6b30ee} /f\r\n")
  49                  self.__logonC.write ("reg delete HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{59031a47-3f72-44a7-89c5-5595fe6b30ee} /f\r\n")
  50                  self.__logonC.write ("reg delete HKEY_LOCAL_MACHINE\Software\Wpkg\Running /f\r\n")
  51  
  52              self.__logonU.write ("time /T >> %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
  53              self.__logonU.write ("echo fin execution du logon.cmd de %USERNAME%--->> %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
  54              self.__logonC.write ("del /Q /S /F %SYSTEMROOT%\System32\GroupPolicy\User\r\n")
  55              self.__logoffC.write ("del /Q /S /F %SYSTEMROOT%\System32\GroupPolicy\User\r\n")
  56              self.__logoffU.write ("del /Q /S /F %USERPROFILE%\Application Data\Microsoft\Wallpaper1.bmp\r\n")
  57              self.__logonU.write ("del /Q /S /F %SYSTEMROOT%\System32\GroupPolicy\User\Registry.pol>>%SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
  58              self.__logoffU.write ("del /Q /S /F %SYSTEMROOT%\System32\GroupPolicy\User\Scripts\Logon\Logon.cmd>>%SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
  59              self.__logoffU.write ("del /Q /S /F %SYSTEMROOT%\Web\Wallpaper\*_se3.*>>%SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
  60              self.__logonC.write ("cacls %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt /E /G Utilisateurs:F\r\n")
  61              self.__logonU.close ()
  62              self.__logonC.close ()
  63              self.__logoffU.write ("\r\n")
  64              self.__logoffC.write ("\r\n")
  65              self.__logoffU.close ()
  66              self.__logoffC.close ()
  67              
  68          except OSError:
  69             print "Can't write %s/%s.cmd" % (self.__user, self.__computer)
  70  
  71  
  72      def winsAdd (self):
  73          """
  74              Restrictions rules
  75          """
  76          try:
  77              self.__logonC.write ("nbtstat -RR\r\n")
  78  
  79          except OSError:
  80              print "Can't write admin %s.cmd" %  self.__computer
  81  
  82  
  83      def addFirefoxAutoConfig (self):
  84          """
  85              Add firefox autconfig files to logon script
  86          """
  87          try:
  88  #           self.__logonC.write ("cacls %SYSTEMROOT%\System32\GroupPolicy\User\\registry.pol /E /G adminse3:F\r\n")
  89  #            self.__logonC.write ("cacls %SYSTEMROOT%\System32\GroupPolicy\User\Scripts\scripts.ini /E /G adminse3:F\r\n")
  90  #            self.__logonC.write ("cacls %SYSTEMROOT%\System32\GroupPolicy\User\Scripts\Logon\logon.cmd /E /G adminse3:F\r\n")
  91  #            self.__logonC.write ("cacls %SYSTEMROOT%\System32\GroupPolicy\User\Scripts\Logoff\logoff.cmd /E /G adminse3:F\r\n")
  92              self.__logonC.write ("Set FIREFOXCFG=%ProgramFiles%\\Mozilla Firefox\\firefox.cfg\r\n")
  93              self.__logonC.write ("Set ALLJS=%ProgramFiles%\\Mozilla Firefox\\greprefs\\all.js\r\n")
  94              self.__logonC.write ("echo //BEGIN CE prefs >\"%FIREFOXCFG%\"\r\n")
  95              self.__logonC.write ("echo lockPref(\"autoadmin.global_config_url\", \"%s/firefox-profile.php?username=\" + getenv(\"USERNAME\") + \"&computername=\" + getenv(\"COMPUTERNAME\") + \"&userdomain=\" + getenv(\"USERDOMAIN\") + \"?\"); >>\"%%FIREFOXCFG%%\"\r\n" % self.__urlse3)
  96              self.__logonC.write ("find \"general.config.obscure_value', 0\" \"%ALLJS%\" || echo pref('general.config.obscure_value', 0); >> \"%ALLJS%\"\r\n")
  97              self.__logonC.write ("find \"general.config.filename\" \"%ALLJS%\" || echo pref('general.config.filename', 'firefox.cfg'); >> \"%ALLJS%\"\r\n")
  98              self.__logonC.write ("net time \\\\%s\r\n" % self.__master)
  99          except: pass
 100  
 101  
 102      def addgetGPOversion (self):
 103          """
 104              get GPO version from registry and write it to gpt.ini
 105          """
 106          try:
 107              self.__logonC.write ("for /f \"tokens=2 delims=x\" %%a in ('reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\State\\Machine\\GPO-List\\0\" /v Version ^| findstr REG_DWORD') do set /a VERSION=0x%%a\r\n")
 108              self.__logonC.write ("if \"%VERSION%\"==\"\" set VERSION=65537\r\n")           
 109              self.__logonC.write ("echo [general]>%SYSTEMROOT%\\System32\\GroupPolicy\\gpt.ini\r\n")
 110              self.__logonC.write ("echo Version=%VERSION%>>%SYSTEMROOT%\\System32\\GroupPolicy\\gpt.ini\r\n")
 111              self.__logonC.write ("echo gPCUserExtensionNames=[{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{0F6B957E-509E-11D1-A7CC-0000F87571E3}][{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{40B66650-4972-11D1-A7CA-0000F87571E3}]>>%SYSTEMROOT%\\System32\\GroupPolicy\\gpt.ini\r\n")
 112              self.__logonC.write ("echo gPCMachineExtensionNames=[{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{0F6B957D-509E-11D1-A7CC-0000F87571E3}][{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{40B6664F-4972-11D1-A7CA-0000F87571E3}]>>%SYSTEMROOT%\\System32\\GroupPolicy\\gpt.ini\r\n")
 113              self.__logonC.write ("time /T >> %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
 114              self.__logonC.write ("echo GPO startup ok>> %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
 115              self.__logonC.write ("echo %VERSION%>> %SYSTEMDRIVE%\\netinst\\logs\\domscripts.txt\r\n")
 116          except: pass
 117  
 118  
 119      def addTemplateslogon (self, templates):
 120          """
 121              Add templates logon, ignore se3printers.bat
 122          """
 123          try:
 124              for template in templates:
 125                  if os.access ("%s/%s/logon.bat" % (self.__tplPath, template), os.F_OK):
 126                      file = open ("%s/%s/logon.bat" \
 127                                    % (self.__tplPath, template))
 128                      for line in file.readlines ():
 129                          if self.__arch == "Vista" and line.find ("net use") != -1 \
 130                                                    and line.find ("persistent") == -1:
 131                              line = line[:-2] + (" /persistent:no\r\n")
 132                          if line.find ("se3printers.bat") == -1:
 133                              self.__logonU.writelines (line)
 134                      self.__logonU.writelines ("\r\n")
 135                      file.close ()
 136                  if os.access ("%s/%s/logon_%s.bat" % (self.__tplPath, template, self.__arch), os.F_OK):
 137                      file = open ("%s/%s/logon_%s.bat" \
 138                                    % (self.__tplPath, template, self.__arch))
 139                      for line in file.readlines ():
 140                          if self.__arch == "Vista" and line.find ("net use") != -1 \
 141                                                    and line.find ("persistent") == -1:
 142                              line = line[:-2] + (" /persistent:no\r\n")
 143                          if line.find("se3printers.bat") == -1:
 144                              self.__logonU.writelines (line)
 145                      self.__logonU.writelines ("\r\n")
 146                      file.close ()
 147                  if os.access ("%s/%s/startup.bat" % (self.__tplPath, template), os.F_OK):
 148                      file = open ("%s/%s/startup.bat" \
 149                                    % (self.__tplPath, template))
 150                      for line in file.readlines ():
 151                          self.__logonC.writelines (line)
 152                      self.__logonC.writelines ("\r\n")
 153                      file.close ()
 154      
 155          except OSError:
 156              print "Can't write %s logon in %s/%s.bat" % (template, self.__user, self.__computer)
 157  
 158  
 159      def addTemplateslogoff (self, templates):
 160          """
 161              Add templates logoff, ignore se3printers.bat
 162          """
 163          try:
 164              for template in templates:
 165                  if os.access ("%s/%s/logoff.bat" % (self.__tplPath, template), os.F_OK):
 166                      file = open ("%s/%s/logoff.bat" \
 167                                    % (self.__tplPath, template))
 168                      for line in file.readlines ():
 169                          self.__logoffU.writelines (line)
 170                      self.__logoffU.writelines ("\r\n")
 171                      file.close ()
 172                  if os.access ("%s/%s/logoff_%s.bat" % (self.__tplPath, template, self.__arch), os.F_OK):
 173                      file = open ("%s/%s/logoff_%s.bat" \
 174                                    % (self.__tplPath, template, self.__arch))
 175                      for line in file.readlines ():
 176                          self.__logoffU.writelines (line)
 177                      self.__logoffU.writelines ("\r\n")
 178                      file.close ()
 179                  if os.access ("%s/%s/shutdown.bat" % (self.__tplPath, template), os.F_OK):
 180                      file = open ("%s/%s/shutdown.bat" \
 181                                    % (self.__tplPath, template))
 182                      for line in file.readlines ():
 183                          self.__logoffC.writelines (line)
 184                      self.__logoffC.writelines ("\r\n")
 185                      file.close ()
 186  
 187          except OSError:
 188              print "Can't write %s logoff in %s/%s.bat" % (template, self.__user, self.__computer)
 189      def addReglogon (self):
 190          """
 191              Add regedit job at logon
 192          """
 193          try:
 194              if os.access ("%s/machine/%s/user.reg" % (self.__batPath, self.__computer), os.F_OK):
 195                  self.__logonU.writelines ("\\\\%s\Netlogon\Cpau.exe -wait -lwop -hide -dec -file \\\\%s\Netlogon\Machine\Reg_helper.job\r\n" \
 196                  % (self.__master, self.__master))
 197          except OSError:
 198              print "Can't write reg file for user %s and computer %s logon.cmd" % (self.__user, self.__computer)


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1