def allow_modules(): from AccessControl import ModuleSecurityInfo, ClassSecurityInfo from AccessControl import allow_module, allow_class, allow_type #copied from Products.PythonScript.module_access_examples.py ModuleSecurityInfo('re').declarePublic('compile', 'findall', 'match', 'search', 'split', 'sub', 'subn', 'error', 'I', 'L', 'M', 'S', 'X') import re allow_type(type(re.compile(''))) allow_type(type(re.match('x','x'))) import copy ModuleSecurityInfo('copy').declarePublic('deepcopy') """ Modulo Archetypes """ ModuleSecurityInfo('wres').declarePublic('archetypes') ModuleSecurityInfo('wres.archetypes').declarePublic('content') ModuleSecurityInfo('wres.archetypes.content').declarePublic('patient') allow_module('wres.archetypes.content.patient') ModuleSecurityInfo('wres.archetypes.content').declarePublic('doctor') allow_module('wres.archetypes.content.doctor') ModuleSecurityInfo('wres.archetypes.content').declarePublic('documentfolder') allow_module('wres.archeytpes.content.documentfolder') ModuleSecurityInfo('wres.archetypes.content').declarePublic('secretarydesktop') allow_module('wres.archeytpes.content.secretarydesktop') from wres.archetypes.content.secretarydesktop import SecretaryDesktopData allow_class(SecretaryDesktopData) """ Modulo Policy """ ModuleSecurityInfo('wres').declarePublic('policy') ModuleSecurityInfo('wres.policy').declarePublic('utils') ModuleSecurityInfo('wres.policy').declarePublic('cmedstat') ModuleSecurityInfo('wres.policy.utils').declarePublic('utils') allow_module('wres.policy.utils.utils') allow_module('wres.policy.cmedstat') """ Modulo Theme """ ModuleSecurityInfo('wres').declarePublic('theme') ModuleSecurityInfo('wres.theme').declarePublic('skins') ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_custom_scripts') ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_custom_templates') ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_custom_images') ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_auxiliary') # ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_widgets') ModuleSecurityInfo('wres.theme.skins').declarePublic('wres_theme_custom_styles')
def initialize(context): """initialize product (called by zope)""" from Products.PloneMeeting import monkey import Meeting import MeetingCategory import MeetingConfig import MeetingGroup import MeetingItem import MeetingUser import ToolPloneMeeting # Initialize portal tools tools = [ToolPloneMeeting.ToolPloneMeeting] ToolInit(PROJECTNAME + ' Tools', tools=tools, icon='tool.gif').initialize(context) # Initialize portal content all_content_types, all_constructors, all_ftis = process_types( listTypes(PROJECTNAME), PROJECTNAME) cmfutils.ContentInit(PROJECTNAME + ' Content', content_types=all_content_types, permission=DEFAULT_ADD_CONTENT_PERMISSION, extra_constructors=all_constructors, fti=all_ftis).initialize(context) # Give it some extra permissions to control them on a per class limit for i in range(0, len(all_content_types)): klassname = all_content_types[i].__name__ if klassname not in ADD_CONTENT_PERMISSIONS: continue context.registerClass(meta_type=all_ftis[i]['meta_type'], constructors=(all_constructors[i], ), permission=ADD_CONTENT_PERMISSIONS[klassname]) allow_module('collective.iconifiedcategory.safe_utils') allow_module('collective.contact.core') allow_module('collective.contact.plonegroup.safe_utils') allow_module('imio.annex.safe_utils') allow_module('imio.history.safe_utils') allow_module('Products.PloneMeeting.safe_utils') allow_module('Products.PloneMeeting.browser.meeting') allow_type(datetime)
# given as example in Products.PythonScripts.module_access_examples allow_module('base64') allow_module('binascii') allow_module('bisect') allow_module('colorsys') allow_module('crypt') ## allow_module('pprint') allow_module('quopri') ModuleSecurityInfo('json').declarePublic('dumps', 'loads') import re allow_module('fnmatch') allow_module('re') allow_type(type(re.compile(''))) allow_type(type(re.match('x','x'))) import cStringIO f = cStringIO.StringIO() allow_module('cStringIO') allow_module('StringIO') allow_type(type(f)) ModuleSecurityInfo('cgi').declarePublic('escape', 'parse_header') allow_module('datetime') import datetime ContainerAssertions[datetime.datetime] = 1 ContainerAssertions[datetime.time] = 1 ContainerAssertions[datetime.date] = 1 ContainerAssertions[datetime.timedelta] = 1
allow_module('base64') allow_module('binascii') allow_module('bisect') allow_module('colorsys') allow_module('crypt') ## allow_module('pprint') allow_module('quopri') ModuleSecurityInfo('json').declarePublic('dumps', 'loads') import re allow_module('fnmatch') allow_module('re') allow_type(type(re.compile(''))) allow_type(type(re.match('x', 'x'))) allow_type(type(re.finditer('x', 'x'))) allow_module('StringIO') import StringIO StringIO.StringIO.__allow_access_to_unprotected_subobjects__ = 1 allow_module('cStringIO') import cStringIO allow_type(cStringIO.InputType) allow_type(cStringIO.OutputType) allow_module('io') import io
############################################################################## """ Wendelin is a product containing general purpose tools to handle big data manipulations. """ from AccessControl import allow_module, allow_type # we neeed to allow access to numpy's internal types import numpy as np allow_module('numpy') for dtype in ('int8', 'int16', 'int32', 'int64', \ 'uint8', 'uint16', 'uint32', 'uint64', \ 'float16', 'float32', 'float64', \ 'complex64', 'complex128',): z = np.array([0,], dtype = dtype) allow_type(type(z[0])) allow_type(type(z)) allow_module('sklearn') allow_module('scipy') allow_module('wendelin.bigarray.array_zodb') allow_module('pandas') allow_type(np.timedelta64) allow_type(type(np.c_)) import pandas as pd allow_type(pd.Series) allow_type(pd.DatetimeIndex) allow_type(pd.DataFrame)
# given as example in Products.PythonScripts.module_access_examples allow_module('base64') allow_module('binascii') allow_module('bisect') allow_module('colorsys') allow_module('crypt') ## allow_module('pprint') ModuleSecurityInfo('json').declarePublic('dumps', 'loads') import re allow_module('fnmatch') allow_module('re') allow_type(type(re.compile(''))) allow_type(type(re.match('x','x'))) import cStringIO f = cStringIO.StringIO() allow_module('cStringIO') allow_module('StringIO') allow_type(type(f)) ModuleSecurityInfo('cgi').declarePublic('escape', 'parse_header') allow_module('datetime') import datetime ContainerAssertions[datetime.datetime] = 1 ContainerAssertions[datetime.time] = 1 ContainerAssertions[datetime.date] = 1 ContainerAssertions[datetime.timedelta] = 1
def initialize(context): # Stuff has been moved from module level to this method for a # better separation of import and installation. # For the general user this change does not make a difference. # For test authors (and people who use parts of Plone only) # it does speed up import *significantly*. from AccessControl import ModuleSecurityInfo from AccessControl import allow_class from AccessControl import allow_module from AccessControl import allow_type # protect OFS.ObjectManager ModuleSecurityInfo('OFS.ObjectManager').setDefaultAccess(0) ModuleSecurityInfo('OFS.ObjectManager').declareObjectPrivate() ModuleSecurityInfo('OFS.ObjectManager').declarePublic( 'BeforeDeleteException') # allow logging ModuleSecurityInfo('logging').declarePublic('getLogger') from logging import Logger allow_class(Logger) # various small utils functions # added for unescaping view names in urls when finding selected action ModuleSecurityInfo('urllib').declarePublic('unquote') allow_module('Products.CMFPlone.utils') # For content_status_modify from Products.CMFCore.WorkflowCore import ObjectDeleted from Products.CMFCore.WorkflowCore import ObjectMoved from Products.CMFCore.WorkflowCore import WorkflowException ModuleSecurityInfo( 'Products.CMFCore.WorkflowCore').declarePublic('ObjectDeleted') ModuleSecurityInfo( 'Products.CMFCore.WorkflowCore').declarePublic('ObjectMoved') ModuleSecurityInfo( 'Products.CMFCore.WorkflowCore').declarePublic('WorkflowException') allow_class(ObjectDeleted) allow_class(ObjectMoved) allow_class(WorkflowException) from Products.CMFPlone.PloneBatch import Batch allow_class(Batch) # Make Batch available at module level this_module.Batch = Batch ModuleSecurityInfo('StringIO').declarePublic('StringIO') from six import StringIO allow_class(StringIO) # Make Unauthorized importable TTW ModuleSecurityInfo('AccessControl').declarePublic('Unauthorized') # Make Forbidden importable TTW ModuleSecurityInfo('zExceptions').declarePublic('Forbidden') # Make ConflictError importable TTW ModuleSecurityInfo('ZODB.POSException').declarePublic('ConflictError') # Make ZCTextIndex ParseError importable TTW ModuleSecurityInfo('Products.ZCTextIndex.ParseTree') \ .declarePublic('ParseError') # Make DateTimeError importable TTW ModuleSecurityInfo('DateTime.interfaces').declarePublic('DateTimeError') ModuleSecurityInfo('DateTime.interfaces').declarePublic('SyntaxError') # BBB support for DateTime < 3 ModuleSecurityInfo('DateTime.DateTime').declarePublic('DateTimeError') ModuleSecurityInfo('DateTime.DateTime').declarePublic('SyntaxError') # Make CopyError importable TTW ModuleSecurityInfo('OFS.CopySupport').declarePublic('CopyError') # Make AllowSendto importable TTW ModuleSecurityInfo('Products.CMFPlone.PloneTool') \ .declarePublic('AllowSendto') # Make ZCatalog's mergeResults importable TTW ModuleSecurityInfo('Products.ZCatalog.Catalog') \ .declarePublic('mergeResults') # Make the navtree constructs available TTW allow_module('Products.CMFPlone.browser.navtree') # Allow access to the exception in the folder_delete script from OFS.ObjectManager import BeforeDeleteException allow_module('OFS.ObjectManager') allow_class(BeforeDeleteException) # Make cgi.escape available TTW ModuleSecurityInfo('cgi').declarePublic('escape') # We want to allow all methods on string type except 'format'. # That one needs special handling to avoid access to attributes. from Products.CMFPlone.utils import _safe_format rules = dict([(m, True) for m in dir(str) if not m.startswith('_')]) rules['format'] = _safe_format allow_type(str, rules) # Same for unicode instead of str. rules = dict([(m, True) for m in dir(unicode) if not m.startswith('_')]) rules['format'] = _safe_format allow_type(unicode, rules) # Apply monkey patches from Products.CMFPlone import patches # noqa # Register unicode splitter w/ ZCTextIndex # pipeline registry from Products.CMFPlone import UnicodeSplitter # noqa # Plone content # Usage of PloneFolder is discouraged. from Products.CMFPlone import PloneFolder contentClasses = (PloneFolder.PloneFolder, ) contentConstructors = (PloneFolder.addPloneFolder, ) # CMFCore tools from Products.CMFCore import CachingPolicyManager # Plone tools from Products.CMFPlone import PloneTool from Products.CMFPlone import MigrationTool from Products.CMFPlone import PloneControlPanel from Products.CMFPlone import WorkflowTool from Products.CMFPlone import URLTool from Products.CMFPlone import RegistrationTool from Products.CMFPlone import PropertiesTool from Products.CMFPlone import ActionsTool from Products.CMFPlone import TypesTool from Products.CMFPlone import CatalogTool from Products.CMFPlone import SkinsTool from Products.CMFPlone import QuickInstallerTool from Products.CMFPlone import TranslationServiceTool tools = ( PloneTool.PloneTool, WorkflowTool.WorkflowTool, CachingPolicyManager.CachingPolicyManager, PropertiesTool.PropertiesTool, MigrationTool.MigrationTool, PloneControlPanel.PloneControlPanel, RegistrationTool.RegistrationTool, URLTool.URLTool, ActionsTool.ActionsTool, TypesTool.TypesTool, CatalogTool.CatalogTool, SkinsTool.SkinsTool, QuickInstallerTool.QuickInstallerTool, TranslationServiceTool.TranslationServiceTool, ) from Products.CMFCore.utils import ContentInit from Products.CMFPlone.utils import ToolInit # Register tools and content ToolInit( 'Plone Tool', tools=tools, icon='tool.gif', ).initialize(context) ContentInit( 'Plone Content', content_types=contentClasses, permission=ADD_CONTENT_PERMISSION, extra_constructors=contentConstructors, ).initialize(context) from AccessControl.Permissions import view_management_screens from Products.CMFPlone.Portal import PloneSite from Products.CMFPlone.factory import zmi_constructor context.registerClass( instance_class=PloneSite, permission=view_management_screens, constructors=(zmi_constructor, ), ) from plone.app.folder import nogopip context.registerClass( nogopip.GopipIndex, permission='Add Pluggable Index', constructors=(nogopip.manage_addGopipForm, nogopip.manage_addGopipIndex), icon='index.gif', visibility=None )
# given as example in Products.PythonScripts.module_access_examples allow_module('base64') allow_module('binascii') allow_module('bisect') allow_module('colorsys') allow_module('crypt') ## allow_module('pprint') allow_module('quopri') ModuleSecurityInfo('json').declarePublic('dumps', 'loads') import re allow_module('fnmatch') allow_module('re') allow_type(type(re.compile(''))) allow_type(type(re.match('x', 'x'))) allow_type(type(re.finditer('x', 'x'))) import cStringIO, StringIO f_cStringIO = cStringIO.StringIO() f_StringIO = StringIO.StringIO() allow_module('cStringIO') allow_module('StringIO') allow_type(type(f_cStringIO)) allow_type(type(f_StringIO)) ModuleSecurityInfo('cgi').declarePublic('escape', 'parse_header') allow_module('datetime') import datetime ContainerAssertions[datetime.datetime] = 1
# given as example in Products.PythonScripts.module_access_examples allow_module('base64') allow_module('binascii') allow_module('bisect') allow_module('colorsys') allow_module('crypt') ## allow_module('pprint') ModuleSecurityInfo('json').declarePublic('dumps', 'loads') import re allow_module('fnmatch') allow_module('re') allow_type(type(re.compile(''))) allow_type(type(re.match('x', 'x'))) import cStringIO f = cStringIO.StringIO() allow_module('cStringIO') allow_module('StringIO') allow_type(type(f)) ModuleSecurityInfo('cgi').declarePublic('escape', 'parse_header') allow_module('datetime') import datetime ContainerAssertions[datetime.datetime] = 1 ContainerAssertions[datetime.time] = 1 ContainerAssertions[datetime.date] = 1 ContainerAssertions[datetime.timedelta] = 1
# # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## """ Wendelin is a product containing general purpose tools to handle big data manipulations. """ from AccessControl import allow_module, allow_type # we neeed to allow access to numpy's internal types import numpy as np allow_module('numpy') for dtype in ('int8', 'int16', 'int32', 'int64', \ 'uint8', 'uint16', 'uint32', 'uint64', \ 'float16', 'float32', 'float64', \ 'complex64', 'complex128',): z = np.array([0,], dtype = dtype) allow_type(type(z[0])) allow_type(type(z)) allow_module('sklearn') allow_module('scipy')
# given as example in Products.PythonScripts.module_access_examples allow_module("base64") allow_module("binascii") allow_module("bisect") allow_module("colorsys") allow_module("crypt") ## allow_module("pprint") ModuleSecurityInfo("json").declarePublic("dumps", "loads") import re allow_module("fnmatch") allow_module("re") allow_type(type(re.compile(""))) allow_type(type(re.match("x", "x"))) import cStringIO f = cStringIO.StringIO() allow_module("cStringIO") allow_module("StringIO") allow_type(type(f)) ModuleSecurityInfo("cgi").declarePublic("escape", "parse_header") allow_module("datetime") import datetime ContainerAssertions[datetime.datetime] = 1 ContainerAssertions[datetime.time] = 1
# # You MUST follow the rules in README_STYLE before checking in code # to the head. Code which does not follow the rules will be rejected. # from __future__ import absolute_import, unicode_literals from . import XWFMailingListManager from . import XWFMailingList from . import XWFVirtualMailingListArchive2 from AccessControl import ModuleSecurityInfo from AccessControl import allow_class, allow_type from .queries import MessageQuery q_security = ModuleSecurityInfo(b'Products.XWFMailingListManager.queries') q_security.declarePublic(b'MessageQuery') allow_class(MessageQuery) from datetime import datetime allow_type(datetime) import time allow_class(time) def initialize(context): # import lazily and defer initialization to the module XWFMailingListManager.initialize(context) XWFMailingList.initialize(context) XWFVirtualMailingListArchive2.initialize(context)
# -*- coding:utf-8 -*- from AccessControl import allow_type, ModuleSecurityInfo from RestrictedPython import compile_restricted import AccessControl.ZopeGuards as ZopeGuards import datetime import re # Make useful modules visible for name in ("datetime", "time", "re"): ModuleSecurityInfo(name).setDefaultAccess("allow") # Include their key types allow_type(type(re.compile(""))) allow_type(type(re.match("x", "x"))) allow_type(type(datetime.date)) # Make sure we get class methods allow_type(type(datetime.datetime)) # class methods allow_type(type(datetime.date(2017, 1, 1))) allow_type(type(datetime.datetime(2017, 1, 1))) allow_type(type(datetime.timedelta(1))) class PyScript(object): # set up this way in case we want to do some caching at some # point in the future. def __init__(self, code): self.code = compile_restricted(code, "<string>", "exec") def execute(self, my_locals=None, output=None): my_globals = ZopeGuards.get_safe_globals() my_globals["_getattr_"] = ZopeGuards.guarded_getattr
from AccessControl import ModuleSecurityInfo, allow_type from Products.PythonScripts.Utility import allow_module import csv import re import StringIO allow_module('re') ModuleSecurityInfo('re').declarePublic('compile', 'findall', 'match', 'search', 'split', 'sub', 'subn', 'error', 'I', 'L', 'M', 'S', 'X') allow_type(type(re.compile(''))) allow_type(type(re.match('x', 'x'))) allow_module('StringIO') ModuleSecurityInfo('StringIO').declarePublic('StringIO',) allow_type(type(StringIO.StringIO(""))) allow_module('csv') ModuleSecurityInfo('csv').declarePublic('reader', 'writer', 'register_dialect', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONNUMERIC', 'QUOTE_NONE', 'Error', 'Sniffer' ) # reader type allow_type(type(csv.reader(StringIO.StringIO("")))) # writer type allow_type(type(csv.writer(StringIO.StringIO("")))) # Sniffer type
data manipulations. """ from AccessControl import allow_module, allow_type, allow_class # we neeed to allow access to numpy's internal types import numpy as np allow_module('numpy') for dtype in ('int8', 'int16', 'int32', 'int64', \ 'uint8', 'uint16', 'uint32', 'uint64', \ 'float16', 'float32', 'float64', \ 'complex64', 'complex128'): z = np.array([ 0, ], dtype=dtype) allow_type(type(z[0])) allow_type(type(z)) sz = np.array([(0, )], dtype=[('f0', dtype)]) allow_type(type(sz[0])) allow_type(type(sz)) rz = np.rec.array(np.array([(0, )], dtype=[('f0', dtype)])) allow_type(type(rz[0])) allow_type(type(rz)) sz = np.array([('2017-07-12T12:30:20', )], dtype=[('date', 'M8[s]')]) allow_type(type(sz[0]['date'])) allow_module('sklearn') allow_module('scipy')