Пример #1
0
    def test_old_style(self):
        """
        L{Logger} handles old style log strings.
        """
        observer = LogPublisher()

        observed = []
        observer.addObserver(observed.append)

        sio = StringIO()
        observer.addObserver(textFileLogObserver(sio))

        logger = Logger(observer=observer)

        index = 0
        logger.info("test")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"{msg}")
        self.assertEqual(observed[index]["msg"], u"test")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "test")

        index += 1
        logger.info("test {}")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"{msg}")
        self.assertEqual(observed[index]["msg"], u"test {}")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "test {}")

        index += 1
        logger.info("test {foo}")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"{msg}")
        self.assertEqual(observed[index]["msg"], u"test {foo}")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "test {foo}")
Пример #2
0
    def test_utf8(self):
        """
        L{Logger} handles utf8 log strings and format args.
        """
        observer = LogPublisher()

        observed = []
        observer.addObserver(observed.append)

        sio = StringIO()
        observer.addObserver(textFileLogObserver(sio))

        logger = Logger(observer=observer)

        index = 0
        logger.info("t\xc3\xa9st")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"{msg}")
        self.assertEqual(observed[index]["msg"], u"t\xe9st")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "t\xc3\xa9st")

        index += 1
        logger.info("{str}", str="t\xc3\xa9st")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"{str}")
        self.assertEqual(observed[index]["str"], u"t\xe9st")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "t\xc3\xa9st")

        index += 1
        logger.info("T\xc3\xa9st {str}", str="t\xc3\xa9st")
        self.assertEqual(observed[index]["log_level"], LogLevel.info)
        self.assertEqual(observed[index]["log_format"], u"T\xe9st {str}")
        self.assertEqual(observed[index]["str"], u"t\xe9st")
        self.assertEqual(sio.getvalue().splitlines()[index].split("#info] ")[1], "T\xc3\xa9st t\xc3\xa9st")
Пример #3
0
            if config.Scheduling.iSchedule.DKIM.PrivateExchanges:
                if not os.path.exists(config.Scheduling.iSchedule.DKIM.PrivateExchanges):
                    try:
                        os.makedirs(config.Scheduling.iSchedule.DKIM.PrivateExchanges)
                    except IOError, e:
                        msg = "DKIM: Cannot create public key private exchange directory: %s" % (config.Scheduling.iSchedule.DKIM.PrivateExchanges,)
                        log.error(msg)
                        raise ConfigurationError(msg)
                if not os.path.isdir(config.Scheduling.iSchedule.DKIM.PrivateExchanges):
                    msg = "DKIM: Invalid public key private exchange directory: %s" % (config.Scheduling.iSchedule.DKIM.PrivateExchanges,)
                    log.error(msg)
                    raise ConfigurationError(msg)
                PublicKeyLookup_PrivateExchange.directory = config.Scheduling.iSchedule.DKIM.PrivateExchanges

            log.info("DKIM: Enabled")
        else:
            log.info("DKIM: Disabled")


    @staticmethod
    def getConfiguration(config):
        """
        Return a tuple of the parameters derived from the config that are used to initialize the DKIMRequest.

        @param config: configuration to look at
        @type config: L{Config}
        """

        domain = config.Scheduling.iSchedule.DKIM.Domain if config.Scheduling.iSchedule.DKIM.Domain else config.ServerHostName
        selector = config.Scheduling.iSchedule.DKIM.KeySelector
Пример #4
0
            if config.Scheduling.iSchedule.DKIM.PrivateExchanges:
                if not os.path.exists(config.Scheduling.iSchedule.DKIM.PrivateExchanges):
                    try:
                        os.makedirs(config.Scheduling.iSchedule.DKIM.PrivateExchanges)
                    except IOError, e:
                        msg = "DKIM: Cannot create public key private exchange directory: %s" % (config.Scheduling.iSchedule.DKIM.PrivateExchanges,)
                        log.error(msg)
                        raise ConfigurationError(msg)
                if not os.path.isdir(config.Scheduling.iSchedule.DKIM.PrivateExchanges):
                    msg = "DKIM: Invalid public key private exchange directory: %s" % (config.Scheduling.iSchedule.DKIM.PrivateExchanges,)
                    log.error(msg)
                    raise ConfigurationError(msg)
                PublicKeyLookup_PrivateExchange.directory = config.Scheduling.iSchedule.DKIM.PrivateExchanges

            log.info("DKIM: Enabled")
        else:
            log.info("DKIM: Disabled")


    @staticmethod
    def getConfiguration(config):
        """
        Return a tuple of the parameters derived from the config that are used to initialize the DKIMRequest.

        @param config: configuration to look at
        @type config: L{Config}
        """

        domain = config.Scheduling.iSchedule.DKIM.Domain if config.Scheduling.iSchedule.DKIM.Domain else config.ServerHostName
        selector = config.Scheduling.iSchedule.DKIM.KeySelector
Пример #5
0
                principalCollections=(principalCollection,)
            )
            if _reactor._started:
                directoryBackedAddressBookCollection.provisionDirectory()
            else:
                addSystemEventTrigger("after", "startup", directoryBackedAddressBookCollection.provisionDirectory)
        else:
            # remove /directory from previous runs that may have created it
            try:
                FilePath(directoryPath).remove()
                log.info("Deleted: {path}", path=directoryPath)
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    log.error("Could not delete: {path} : {error}", path=directoryPath, error=e)

    log.info("Setting up root resource: {cls}", cls=rootResourceClass)

    root = rootResourceClass(
        config.DocumentRoot,
        principalCollections=(principalCollection,),
    )

    root.putChild("principals", principalCollection)
    if config.EnableCalDAV:
        root.putChild("calendars", calendarCollection)
    if config.EnableCardDAV:
        root.putChild('addressbooks', addressBookCollection)
        if config.DirectoryAddressBook.Enabled and config.EnableSearchAddressBook:
            root.putChild(config.DirectoryAddressBook.name, directoryBackedAddressBookCollection)

    # /.well-known
Пример #6
0
                principalCollections=(principalCollection,)
            )
            if _reactor._started:
                directoryBackedAddressBookCollection.provisionDirectory()
            else:
                addSystemEventTrigger("after", "startup", directoryBackedAddressBookCollection.provisionDirectory)
        else:
            # remove /directory from previous runs that may have created it
            try:
                FilePath(directoryPath).remove()
                log.info("Deleted: %s" % directoryPath)
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    log.error("Could not delete: %s : %r" % (directoryPath, e,))

    log.info("Setting up root resource: %r" % (rootResourceClass,))

    root = rootResourceClass(
        config.DocumentRoot,
        principalCollections=(principalCollection,),
    )

    root.putChild("principals", principalCollection)
    if config.EnableCalDAV:
        root.putChild("calendars", calendarCollection)
    if config.EnableCardDAV:
        root.putChild('addressbooks', addressBookCollection)
        if config.DirectoryAddressBook.Enabled and config.EnableSearchAddressBook:
            root.putChild(config.DirectoryAddressBook.name, directoryBackedAddressBookCollection)

    # /.well-known
Пример #7
0
from twext.python.log import Logger
from txweb2 import http_headers
from txweb2 import responsecode
from txweb2.dav.resource import DAVResource, davPrivilegeSet
from txweb2.dav.resource import TwistedGETContentMD5
from txweb2.dav.util import bindMethods
from txweb2.http import HTTPError, StatusResponse
from txweb2.static import File

log = Logger()

try:
    from txweb2.dav.xattrprops import xattrPropertyStore as DeadPropertyStore
except ImportError:
    log.info("No dead property store available; using nonePropertyStore.")
    log.info("Setting of dead properties will not be allowed.")
    from txweb2.dav.noneprops import NonePropertyStore as DeadPropertyStore


class DAVFile(DAVResource, File):
    """
    WebDAV-accessible File resource.

    Extends txweb2.static.File to handle WebDAV methods.
    """
    def __init__(self,
                 path,
                 defaultType="text/plain",
                 indexNames=None,
                 principalCollections=()):
Пример #8
0
        if username:
            uid = getpwnam(username).pw_uid
        else:
            uid = -1

        if groupname:
            gid = getgrnam(groupname).gr_gid
        else:
            gid = -1

        try:
            os.chmod(dirpath, mode)
            os.chown(dirpath, uid, gid)
        except (OSError, IOError), e:
            log.error("Unable to change mode/owner of %s: %s"
                           % (dirpath, e))

        log.info("Created directory: %s" % (dirpath,))

    if not os.path.isdir(dirpath):
        raise ConfigurationError("%s is not a directory: %s"
                                 % (description, dirpath))

    if access and not os.access(dirpath, access):
        raise ConfigurationError(
            "Insufficient permissions for server on %s directory: %s"
            % (description, dirpath)
        )

Пример #9
0
from twext.python.log import Logger
from txweb2 import http_headers
from txweb2 import responsecode
from txweb2.dav.resource import DAVResource, davPrivilegeSet
from txweb2.dav.resource import TwistedGETContentMD5
from txweb2.dav.util import bindMethods
from txweb2.http import HTTPError, StatusResponse
from txweb2.static import File

log = Logger()


try:
    from txweb2.dav.xattrprops import xattrPropertyStore as DeadPropertyStore
except ImportError:
    log.info("No dead property store available; using nonePropertyStore.")
    log.info("Setting of dead properties will not be allowed.")
    from txweb2.dav.noneprops import NonePropertyStore as DeadPropertyStore

class DAVFile (DAVResource, File):
    """
    WebDAV-accessible File resource.

    Extends txweb2.static.File to handle WebDAV methods.
    """
    def __init__(
        self, path,
        defaultType="text/plain", indexNames=None,
        principalCollections=()
    ):
        """
Пример #10
0
                    request.authzUser = davxml.Principal(
                        davxml.HRef.fromString("/principals/wikis/%s/" % (wikiName,))
                    )

        elif self.useSacls and not hasattr(request, "checkedSACL") and not hasattr(request, "checkingSACL"):
            yield self.checkSacl(request)

        if config.RejectClients:
            #
            # Filter out unsupported clients
            #
            agent = request.headers.getHeader("user-agent")
            if agent is not None:
                for reject in config.RejectClients:
                    if reject.search(agent) is not None:
                        log.info("Rejecting user-agent: %s" % (agent,))
                        raise HTTPError(StatusResponse(
                            responsecode.FORBIDDEN,
                            "Your client software (%s) is not allowed to access this service." % (agent,)
                        ))

        if config.EnableResponseCache and request.method == "PROPFIND" and not getattr(request, "notInCache", False) and len(segments) > 1:
            try:
                authnUser, authzUser = (yield self.authenticate(request))
                request.authnUser = authnUser
                request.authzUser = authzUser
            except (UnauthorizedLogin, LoginFailed):
                response = (yield UnauthorizedResponse.makeResponse(
                    request.credentialFactories,
                    request.remoteAddr
                ))
Пример #11
0
            log.info("Setting up directory address book: %r" % (directoryBackedAddressBookResourceClass,))

            directoryBackedAddressBookCollection = directoryBackedAddressBookResourceClass(
                principalCollections=(principalCollection,)
            )
            addSystemEventTrigger("after", "startup", directoryBackedAddressBookCollection.provisionDirectory)
        else:
            # remove /directory from previous runs that may have created it
            try:
                FilePath(directoryPath).remove()
                log.info("Deleted: %s" %    directoryPath)
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    log.error("Could not delete: %s : %r" %  (directoryPath, e,))

    log.info("Setting up root resource: %r" % (rootResourceClass,))

    root = rootResourceClass(
        config.DocumentRoot,
        principalCollections=(principalCollection,),
    )

    if config.EnableCardDAV and not config.EnableCalDAV:
        # TODO need a better way to do this when both services are enabled
        root.saclService = "addressbook"


    root.putChild("principals", principalCollection)
    if config.EnableCalDAV:
        root.putChild("calendars", calendarCollection)
    if config.EnableCardDAV:
Пример #12
0
    directory = getDirectory()

    triggerPath = os.path.join(config.ServerRoot, TRIGGER_FILE)
    if os.path.exists(triggerPath):
        try:
            # Migrate locations/resources now because upgrade_to_1 depends
            # on them being in resources.xml
            (yield migrateFromOD(config, directory))
        except Exception, e:
            raise UpgradeError("Unable to migrate locations and resources from OD: %s" % (e,))

    docRoot = config.DocumentRoot

    if not os.path.exists(docRoot):
        log.info("DocumentRoot (%s) doesn't exist; skipping migration" % (docRoot,))
        return

    versionFilePath = os.path.join(docRoot, ".calendarserver_version")

    onDiskVersion = 0
    if os.path.exists(versionFilePath):
        try:
            with open(versionFilePath) as versionFile:
                onDiskVersion = int(versionFile.read().strip())
        except IOError:
            log.error("Cannot open %s; skipping migration" %
                (versionFilePath,))
        except ValueError:
            log.error("Invalid version number in %s; skipping migration" %
                (versionFilePath,))
Пример #13
0
@inlineCallbacks
def upgradeData(config, directory):

    triggerPath = os.path.join(config.ServerRoot, TRIGGER_FILE)
    if os.path.exists(triggerPath):
        try:
            # Migrate locations/resources now because upgrade_to_1 depends
            # on them being in resources.xml
            yield migrateFromOD(directory)
        except Exception, e:
            raise UpgradeError("Unable to migrate locations and resources from OD: %s" % (e,))

    docRoot = config.DocumentRoot

    if not os.path.exists(docRoot):
        log.info("DocumentRoot (%s) doesn't exist; skipping migration" % (docRoot,))
        return

    versionFilePath = os.path.join(docRoot, ".calendarserver_version")

    onDiskVersion = 0
    if os.path.exists(versionFilePath):
        try:
            with open(versionFilePath) as versionFile:
                onDiskVersion = int(versionFile.read().strip())
        except IOError:
            log.error(
                "Cannot open %s; skipping migration" %
                (versionFilePath,)
            )
        except ValueError:
Пример #14
0
    triggerPath = os.path.join(config.ServerRoot, TRIGGER_FILE)
    if os.path.exists(triggerPath):
        try:
            # Migrate locations/resources now because upgrade_to_1 depends
            # on them being in resources.xml
            yield migrateFromOD(directory)
        except Exception, e:
            raise UpgradeError(
                "Unable to migrate locations and resources from OD: %s" %
                (e, ))

    docRoot = config.DocumentRoot

    if not os.path.exists(docRoot):
        log.info("DocumentRoot ({path}) doesn't exist; skipping migration",
                 path=docRoot)
        return

    versionFilePath = os.path.join(docRoot, ".calendarserver_version")

    onDiskVersion = 0
    if os.path.exists(versionFilePath):
        try:
            with open(versionFilePath) as versionFile:
                onDiskVersion = int(versionFile.read().strip())
        except IOError:
            log.error(
                "Cannot open {path}; skipping migration",
                path=versionFilePath,
            )
        except ValueError:
Пример #15
0
            )
            if _reactor._started:
                directoryBackedAddressBookCollection.provisionDirectory()
            else:
                addSystemEventTrigger("after", "startup", directoryBackedAddressBookCollection.provisionDirectory)
        else:
            # remove /directory from previous runs that may have created it
            directoryPath = os.path.join(config.DocumentRoot, config.DirectoryAddressBook.name)
            try:
                FilePath(directoryPath).remove()
                log.info("Deleted: {path}", path=directoryPath)
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    log.error("Could not delete: {path} : {error}", path=directoryPath, error=e)

    log.info("Setting up root resource: {cls}", cls=rootResourceClass)

    root = rootResourceClass(
        config.DocumentRoot,
        principalCollections=(principalCollection,),
    )

    root.putChild("principals", principalCollection)
    if config.EnableCalDAV:
        root.putChild("calendars", calendarCollection)
    if config.EnableCardDAV:
        root.putChild('addressbooks', addressBookCollection)
        if config.DirectoryAddressBook.Enabled and config.EnableSearchAddressBook:
            root.putChild(config.DirectoryAddressBook.name, directoryBackedAddressBookCollection)

    # /.well-known