Exemplo n.º 1
0
    def handle_restart_action(self, action):
        CheckAuthenticator(self.request)
        if not self.available():
            self.status = _(
                u'text_not_allowed_manage_server',
                default=u'You are not allowed to manage the Zope server.'
            )
            return

        try:
            user = '******' % getSecurityManager().getUser().getUserName()
        except:
            user = '******'
        logger.info("Restart requested by %s" % user)
        shutdown(1)
        url = self.request.get('URL')
        # TODO: returning html has no effect in button handlers
        self.request.response.setHeader('X-Theme-Disabled', 'True')
        return """<html><head>
            <meta http-equiv="refresh" content="5; url={0}">
        </head><body>{1}</body></html>""".format(
            escape(url, 1),
            _('plone_restarting',
                default=u"Zope is restarting. This page will refresh in 30"
                        u" seconds...")
        )
Exemplo n.º 2
0
    def handle_restart_action(self, action):
        CheckAuthenticator(self.request)
        if not self.available():
            self.status = _(
                u'text_not_allowed_manage_server',
                default=u'You are not allowed to manage the Zope server.'
            )
            return

        try:
            user = '******' % getSecurityManager().getUser().getUserName()
        except:
            user = '******'
        logger.info("Restart requested by %s" % user)
        shutdown(1)
        url = self.request.get('URL')
        # TODO: returning html has no effect in button handlers
        self.request.response.setHeader('X-Theme-Disabled', 'True')
        return """<html><head>
            <meta http-equiv="refresh" content="5; url={0}">
        </head><body>{1}</body></html>""".format(
            escape(url, 1),
            _('plone_restarting',
                default=u"Zope is restarting. This page will refresh in 30"
                        u" seconds...")
        )
Exemplo n.º 3
0
 def manage_shutdown(self, REQUEST=None):
     """Shut down the application"""
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     LOG.info("Shutdown requested by %s" % user)
     shutdown(0)
     return """<html>
 def manage_shutdown(self, REQUEST=None):
     """Shut down the application"""
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     LOG.info("Shutdown requested by %s" % user)
     shutdown(0)
     return """<html>
Exemplo n.º 5
0
 def manage_restart(self, URL1, REQUEST=None):
     """ Shut down the application for restart.
     """
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     LOG.info("Restart requested by %s" % user)
     shutdown(1)
     return """<html>
     <head><meta HTTP-EQUIV=REFRESH CONTENT="10; URL=%s/manage_main">
     </head>
     <body>Zope is restarting</body></html>
     """ % escape(URL1, 1)
 def manage_restart(self, URL1, REQUEST=None):
     """ Shut down the application for restart.
     """
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     LOG.info("Restart requested by %s" % user)
     shutdown(1)
     return """<html>
     <head><meta HTTP-EQUIV=REFRESH CONTENT="10; URL=%s/manage_main">
     </head>
     <body>Zope is restarting</body></html>
     """ % escape(URL1, 1)
Exemplo n.º 7
0
 def handle_shutdown_action(self, action):
     CheckAuthenticator(self.request)
     if not self.available():
         self.status = _(
             u'text_not_allowed_manage_server',
             default=u'You are not allowed to manage the Zope server.')
         return
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     logger.info("Shutdown requested by %s" % user)
     shutdown(0)
     # TODO: returning html has no effect in button handlers
     self.request.response.setHeader('X-Theme-Disabled', 'True')
     return """<html><head></head><body>{0}</body></html>""".format(
         _('plone_shutdown', default="Zope is shutting down."))
Exemplo n.º 8
0
 def handle_shutdown_action(self, action):
     CheckAuthenticator(self.request)
     if not self.available():
         self.status = _(
             u'text_not_allowed_manage_server',
             default=u'You are not allowed to manage the Zope server.'
         )
         return
     try:
         user = '******' % getSecurityManager().getUser().getUserName()
     except:
         user = '******'
     logger.info("Shutdown requested by %s" % user)
     shutdown(0)
     # TODO: returning html has no effect in button handlers
     self.request.response.setHeader('X-Theme-Disabled', 'True')
     return """<html><head></head><body>{0}</body></html>""".format(
         _('plone_shutdown', default="Zope is shutting down.")
     )
Exemplo n.º 9
0
    def signalHandler(self, signum, frame):
        """Meta signal handler that dispatches to registered handlers."""
        signame = get_signal_name(signum)
        logger.info("Caught signal %s" % signame)

        for handler in self.registry.get(signum, []):
            # Never let a bad handler prevent the standard signal
            # handlers from running.
            try:
                handler()
            except SystemExit as rc:
                # On Unix, signals are delivered to the main thread, so a
                # SystemExit does the right thing.  On Windows, we are on
                # our own thread, so throwing SystemExit there isn't a great
                # idea.  Just shutdown the main loop.
                if LIFETIME:
                    logger.debug("Trapped SystemExit(%s) - "
                                 "doing Lifetime shutdown" % rc)
                    shutdown(rc)
                else:
                    raise
            except:
                logger.exception("A handler for %s failed!'" % signame)
            wakeSelect()  # trigger a walk around the Lifetime loop.
Exemplo n.º 10
0
    def signalHandler(self, signum, frame):
        """Meta signal handler that dispatches to registered handlers."""
        signame = get_signal_name(signum)
        logger.info("Caught signal %s" % signame)

        for handler in self.registry.get(signum, []):
            # Never let a bad handler prevent the standard signal
            # handlers from running.
            try:
                handler()
            except SystemExit as rc:
                # On Unix, signals are delivered to the main thread, so a
                # SystemExit does the right thing.  On Windows, we are on
                # our own thread, so throwing SystemExit there isn't a great
                # idea.  Just shutdown the main loop.
                if LIFETIME:
                    logger.debug("Trapped SystemExit(%s) - "
                                 "doing Lifetime shutdown" % rc)
                    shutdown(rc)
                else:
                    raise
            except:
                logger.exception("A handler for %s failed!'" % signame)
            wakeSelect()  # trigger a walk around the Lifetime loop.
Exemplo n.º 11
0
    def manage_customizeSystem(self, btn, key, lang, REQUEST, RESPONSE=None):
      """ ConfManager.manage_customizeSystem """
      
      message = ''
      params = []
      
      ##### Import ####
      if key == 'Import':
        if btn == 'Import':
          f = REQUEST['file']
          createIfNotExists = 1
          if f:
            filename = f.filename
            self.importConfPackage( f, createIfNotExists)
          else:
            filename = REQUEST['init']
            self.importConfPackage( filename, createIfNotExists)
          message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%filename)
      
      ##### History ####
      elif key == 'History':
        old_active = self.getConfProperty('ZMS.Version.active', 0)
        new_active = REQUEST.get('active', 0)
        old_nodes = self.getConfProperty('ZMS.Version.nodes', ['{$}'])
        new_nodes = standard.string_list(REQUEST.get('nodes', ''))
        self.setConfProperty('ZMS.Version.active', new_active)
        self.setConfProperty('ZMS.Version.nodes', new_nodes)
        nodes = []
        if old_active == 1 and new_active == 0:
          nodes = old_nodes
        if old_active == 1 and new_active == 1:
          nodes = standard.difference_list( old_nodes, self.getConfProperty('ZMS.Version.nodes', ['{$}']))
        for node in nodes:
          ob = self.getLinkObj( node)
          if ob is not None:
            message += '[%s: %i]'%(node, ob.packHistory())
        message = self.getZMILangStr('MSG_CHANGED')+message
      
      ##### Clients ####
      elif key == 'Clients':
        if btn == 'Change':
          home = self.getHome()
          s = REQUEST.get('portal_master', '').strip()
          if s != home.id:
            self.setConfProperty('Portal.Master', s)
          l = []
          portal_clients = REQUEST.get('portal_clients', [])
          if not isinstance(portal_clients, list):
            portal_clients  = [portal_clients]
          portal_clients = sorted([(int(x[:x.find(':')]), x[x.find(':')+1:]) for x in portal_clients])
          portal_clients = [x[1] for x in portal_clients]
          for id in portal_clients:
            folder = getattr(home, id, None)
            if folder is not None:
              for node in folder.objectValues('ZMS'):
                node.setConfProperty('Portal.Master', home.id)
                l.append(id)
          self.setConfProperty('Portal.Clients', l)
          message = self.getZMILangStr('MSG_CHANGED')
      
      ##### MediaDb ####
      elif key == 'MediaDb':
        if btn == 'Create':
          location = REQUEST['mediadb_location'].strip()
          _mediadb.manage_addMediaDb(self, location)
          message = self.getZMILangStr('MSG_CHANGED')
        elif btn == 'Pack':
          message = _mediadb.manage_packMediaDb(self)
        elif btn == 'Remove':
          message = _mediadb.manage_delMediaDb(self)
      
      ##### Custom ####
      elif key == 'Custom':
        k = REQUEST.get( 'conf_key', '')
        if btn == 'Change':
          v = REQUEST.get( 'conf_value', '')
          self.setConfProperty( k, v)
          if REQUEST.get('portal_clients'):
            for portalClient in self.getPortalClients():
              portalClient.setConfProperty( k, v)
          params.append('conf_key')
          message = self.getZMILangStr('MSG_CHANGED')
        elif btn == 'Delete':
          self.delConfProperty( k)
          if REQUEST.get('portal_clients'):
            for portalClient in self.getPortalClients():
              portalClient.delConfProperty( k)
          message = self.getZMILangStr('MSG_DELETED')%int(1)
      
      ##### InstalledProducts ####
      elif key == 'InstalledProducts':
        if btn == 'Change':
          self.setConfProperty('InstalledProducts.lesscss', REQUEST.get('lesscss', ''))
          self.setConfProperty('InstalledProducts.pil.thumbnail.max', REQUEST.get('pil_thumbnail_max', self.getConfProperty('InstalledProducts.pil.thumbnail.max')))
          self.setConfProperty('InstalledProducts.pil.hires.thumbnail.max', REQUEST.get('pil_hires_thumbnail_max', self.getConfProperty('InstalledProducts.pil.hires.thumbnail.max')))
          message = self.getZMILangStr('MSG_CHANGED')
        elif btn == 'Import':
          zmsext = REQUEST.get('zmsext', '')
          # hand over import to Deployment Library if available
          revobj = self.getMetaobjRevision('zms3.deployment')
          revreq = '0.2.0'
          if revobj >= revreq:
            target = 'manage_deployment'
            target = self.url_append_params(target, {'zmsext': zmsext})
            return RESPONSE.redirect(target)
          # otherwise import now
          target = 'manage_customize'
          isProcessed = False
          try:
            ZMSExtension  = standard.extutil()
            filesToImport = ZMSExtension.getFilesToImport(zmsext, self.getDocumentElement())
            if len(filesToImport)>0:
              for f in filesToImport:
                self.importConf(f, createIfNotExists=True, syncIfNecessary=False)
              self.synchronizeObjAttrs()
              isProcessed = True
          except:
            isProcessed = False
          if isProcessed:
            message = self.getZMILangStr('MSG_IMPORTED')%('<code class="alert-success">'+self.str_item(ZMSExtension.getFiles(zmsext))+'</code>')
            target = self.url_append_params(target, {'manage_tabs_message': message})
          else:
            message = self.getZMILangStr('MSG_EXCEPTION') 
            message += ': <code class="alert-danger">%s</code>'%('No conf files found.')
            target = self.url_append_params(target, {'manage_tabs_error_message': message})
            standard.writeError(self, "[ConfManager.manage_customizeSystem] No conf files found.")
          return RESPONSE.redirect(target + '#%s'%key)
        elif btn == 'ImportExample':
          zmsext = REQUEST.get('zmsext', '')
          target = 'manage_main'
          ZMSExtension  = standard.extutil()
          isProcessed = False
          try:
            if ZMSExtension.getExample(zmsext) is not None:
              destination = self.getLinkObj(self.getConfProperty('ZMS.Examples', {}))
              if destination is None:
                destination = self.getDocumentElement()
              ZMSExtension.importExample(zmsext, destination, REQUEST)
              isProcessed = True
          except:
            isProcessed = False
          if isProcessed:
            return True
          else:
            return False
        elif btn == 'InstallTheme':
          zmsext = REQUEST.get('zmsext', '')
          target = 'manage_main'
          ZMSExtension  = standard.extutil()
          standard.writeBlock(self, "[ConfManager.manage_customizeSystem] InstallTheme:"+str(zmsext))
          if ZMSExtension.installTheme(self, zmsext):
            return True
          else:
            return False

      ##### Instance ####
      elif key == 'Instance':
        if btn == 'Restart':
          target = 'manage_customize'
          
          if 'ZMANAGED' in os.environ:
            from Lifetime import shutdown
            from cgi import escape
            from .standard import writeBlock
            try:
              user = '******' % REQUEST['AUTHENTICATED_USER']
            except:
              user = '******'
            writeBlock(self, " Restart requested by %s" % user)
            shutdown(1)
            message = self.getZMILangStr('ZMS3 instance restarted.')
            target = self.url_append_params(target, {'manage_tabs_message': message})
            return """<html>
            <head><meta HTTP-EQUIV=REFRESH CONTENT="10; URL=%s">
            </head>
            <body>Restarting...</body></html>
            """ % escape(target + '#%s'%key, 1)
          else:       
            return "No daemon."
      
      ##### Manager ####
      elif key == 'Manager':
        if btn == 'Add':
          meta_type = REQUEST.get('meta_type', '')
          if meta_type == 'Sequence':
            obj = _sequence.Sequence()
            self._setObject(obj.id, obj)
            message = 'Added '+meta_type
          elif meta_type == 'ZMSLog':
            obj = zmslog.ZMSLog()
            self._setObject(obj.id, obj)
            message = 'Added '+meta_type
          else:
            obj = ConfDict.forName(meta_type+'.'+meta_type)()
            self._setObject(obj.id, obj)
            message = 'Added '+meta_type
        elif btn == 'Remove':
          ids = REQUEST.get('ids', [])
          if ids:
            message = 'Removed '+', '.join(ids)
            self.manage_delObjects(ids=ids)
      
      # Return with message.
      if RESPONSE:
        d = {'lang': lang,'manage_tabs_message': message}
        for param in params:
          d[param] = REQUEST.get( param, '')
        return RESPONSE.redirect( self.url_append_params( 'manage_customize', d) + '#%s'%key)
      
      return message