def RemoveDirectory(params, options): if params.is_root(): return try: directory = GetObject(FindPath(options, params.Server, params.Name)) except pythoncom.com_error as details: rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "VirtualDirectory '%s' did not exist" % params.Name) directory = None if directory is not None: # Be robust should IIS get upset about unloading. try: directory.AppUnLoad() except: exc_val = sys.exc_info()[1] log(2, "AppUnLoad() for %s failed: %s" % (params.Name, exc_val)) # Continue trying to delete it. try: parent = GetObject(directory.Parent) parent.Delete(directory.Class, directory.Name) log(1, "Deleted Virtual Directory: %s" % (params.Name,)) except: exc_val = sys.exc_info()[1] log(1, "Failed to remove directory %s: %s" % (params.Name, exc_val))
def DeleteISAPIFilter(filterParams, options): _CallHook(filterParams, "PreRemove", options) server = FindWebServer(options, filterParams.Server) ob_path = server + "/Filters" try: filters = GetObject(ob_path) except pythoncom.com_error as details: # failure to open the filters just means a totally clean IIS install # (IIS5 at least has no 'Filters' key when freshly installed). log(2, "ISAPI filter path '%s' did not exist." % (ob_path,)) return try: assert filterParams.Name.strip("/"), "mustn't delete the root!" filters.Delete(_IIS_FILTER, filterParams.Name) log(2, "Deleted ISAPI filter '%s'" % (filterParams.Name,)) except pythoncom.com_error as details: rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "ISAPI filter '%s' did not exist." % (filterParams.Name,)) # Remove from the load order load_order = [b.strip() for b in filters.FilterLoadOrder.split(",") if b] if filterParams.Name in load_order: load_order.remove(filterParams.Name) filters.FilterLoadOrder = ",".join(load_order) filters.SetInfo() _CallHook(filterParams, "PostRemove", options) log(1, "Deleted Filter: %s" % (filterParams.Name,))
def Uninstall(params, options): _CallHook(params, "PreRemove", options) DeleteExtensionFileRecords(params, options) for vd in params.VirtualDirs: _CallHook(vd, "PreRemove", options) try: directory = GetObject(FindPath(options, vd.Server, vd.Name)) except pythoncom.com_error, details: rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "VirtualDirectory '%s' did not exist" % vd.Name) directory = None if directory is not None: # Be robust should IIS get upset about unloading. try: directory.AppUnLoad() except: exc_val = sys.exc_info()[1] log(2, "AppUnLoad() for %s failed: %s" % (vd.Name, exc_val)) # Continue trying to delete it. try: parent = GetObject(directory.Parent) parent.Delete(directory.Class, directory.Name) except: exc_val = sys.exc_info()[1] log(1, "Failed to remove directory %s: %s" % (vd.Name, exc_val)) _CallHook(vd, "PostRemove", options) log (1, "Deleted Virtual Directory: %s" % (vd.Name,))
def DeleteISAPIFilter(filterParams, options): _CallHook(filterParams, "PreRemove", options) server = FindWebServer(options, filterParams.Server) filters = GetObject(server+"/Filters") try: filters.Delete(_IIS_FILTER, filterParams.Name) log(2, "Deleted ISAPI filter '%s'" % (filterParams.Name,)) except pythoncom.com_error, details: rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "ISAPI filter '%s' did not exist." % (filterParams.Name,))
def CreateISAPIFilter(filterParams, options): server = FindWebServer(options, filterParams.Server) _CallHook(filterParams, "PreInstall", options) try: filters = GetObject(server + "/Filters") except pythoncom.com_error as exc: # Brand new sites don't have the '/Filters' collection - create it. # Any errors other than 'not found' we shouldn't ignore. if ( winerror.HRESULT_FACILITY(exc.hresult) != winerror.FACILITY_WIN32 or winerror.HRESULT_CODE(exc.hresult) != winerror.ERROR_PATH_NOT_FOUND ): raise server_ob = GetObject(server) filters = server_ob.Create(_IIS_FILTERS, "Filters") filters.FilterLoadOrder = "" filters.SetInfo() # As for VirtualDir, delete an existing one. assert filterParams.Name.strip("/"), "mustn't delete the root!" try: filters.Delete(_IIS_FILTER, filterParams.Name) log(2, "Deleted old filter '%s'" % (filterParams.Name,)) except pythoncom.com_error: pass newFilter = filters.Create(_IIS_FILTER, filterParams.Name) log(2, "Created new ISAPI filter...") assert os.path.isfile(filterParams.Path) newFilter.FilterPath = filterParams.Path newFilter.FilterDescription = filterParams.Description newFilter.SetInfo() load_order = [b.strip() for b in filters.FilterLoadOrder.split(",") if b] if filterParams.Name not in load_order: load_order.append(filterParams.Name) filters.FilterLoadOrder = ",".join(load_order) filters.SetInfo() _CallHook(filterParams, "PostInstall", options, newFilter) log(1, "Configured Filter: %s" % (filterParams.Name,)) return newFilter
rc = _GetWin32ErrorCode(details) if rc != winerror.ERROR_PATH_NOT_FOUND: raise log(2, "VirtualDirectory '%s' did not exist" % params.Name) directory = None if directory is not None: # Be robust should IIS get upset about unloading. try: directory.AppUnLoad() except: exc_val = sys.exc_info()[1] log(2, "AppUnLoad() for %s failed: %s" % (params.Name, exc_val)) # Continue trying to delete it. try: parent = GetObject(directory.Parent) parent.Delete(directory.Class, directory.Name) log(1, "Deleted Virtual Directory: %s" % (params.Name, )) except: exc_val = sys.exc_info()[1] log(1, "Failed to remove directory %s: %s" % (params.Name, exc_val)) def RemoveScriptMaps(vd_params, options): "Remove script maps from the already installed virtual directory" parent, name = vd_params.split_path() target_dir = GetObject(FindPath(options, vd_params.Server, parent)) installed_maps = list(target_dir.ScriptMaps) for _map in map(str, vd_params.ScriptMaps): if _map in installed_maps: installed_maps.remove(_map)
def CreateDirectory(params, options): _CallHook(params, "PreInstall", options) if not params.Name: raise ConfigurationError, "No Name param" slash = params.Name.rfind("/") if slash >= 0: parent = params.Name[:slash] name = params.Name[slash+1:] else: parent = "" name = params.Name webDir = GetObject(FindPath(options, params.Server, parent)) if parent: # Note that the directory won't be visible in the IIS UI # unless the directory exists on the filesystem. keyType = _IIS_WEBDIR else: keyType = _IIS_WEBVIRTUALDIR # We used to go to lengths to keep an existing virtual directory # in place. However, in some cases the existing directories got # into a bad state, and an update failed to get them working. # So we nuke it first. If this is a problem, we could consider adding # a --keep-existing option. try: # Also seen the Class change to a generic IISObject - so nuke # *any* existing object, regardless of Class existing = GetObject(FindPath(options, params.Server, params.Name)) webDir.Delete(existing.Class, existing.Name) log(2, "Deleted old directory '%s'" % (params.Name,)) except pythoncom.com_error: pass newDir = webDir.Create(keyType, name) log(2, "Creating new directory '%s'..." % (params.Name,)) friendly = params.Description or params.Name newDir.AppFriendlyName = friendly try: path = params.Path or webDir.Path newDir.Path = path except AttributeError: pass newDir.AppCreate2(params.AppProtection) newDir.HttpCustomHeaders = params.Headers log(2, "Setting directory options...") newDir.AccessExecute = params.AccessExecute newDir.AccessRead = params.AccessRead newDir.AccessWrite = params.AccessWrite newDir.AccessScript = params.AccessScript newDir.ContentIndexed = params.ContentIndexed newDir.EnableDirBrowsing = params.EnableDirBrowsing newDir.EnableDefaultDoc = params.EnableDefaultDoc if params.DefaultDoc is not None: newDir.DefaultDoc = params.DefaultDoc newDir.SetInfo() smp_items = [] for smp in params.ScriptMaps: item = "%s,%s,%s" % (smp.Extension, smp.Module, smp.Flags) # IIS gets upset if there is a trailing verb comma, but no verbs if smp.Verbs: item += "," + smp.Verbs smp_items.append(item) if params.ScriptMapUpdate == "replace": newDir.ScriptMaps = smp_items elif params.ScriptMapUpdate == "end": for item in smp_items: if item not in newDir.ScriptMaps: newDir.ScriptMaps = newDir.ScriptMaps + (item,) elif params.ScriptMapUpdate == "start": for item in smp_items: if item not in newDir.ScriptMaps: newDir.ScriptMaps = (item,) + newDir.ScriptMaps else: raise ConfigurationError, \ "Unknown ScriptMapUpdate option '%s'" % (params.ScriptMapUpdate,) newDir.SetInfo() _CallHook(params, "PostInstall", options, newDir) log(1, "Configured Virtual Directory: %s" % (params.Name,)) return newDir