コード例 #1
0
ファイル: auth.py プロジェクト: pombredanne/trachacks
class TracForgeLoginModule(LoginModule):
    """Replacement for LoginModule to slave to another environment."""

    master_path = Option('tracforge', 'master_path', doc='Path to master Trac')

    master_env = property(lambda self: open_environment(self.master_path))
    master_href = property(lambda self: Href(self.master_env.base_url))

    # INavigationContributor methods
    def get_active_navigation_item(self, req):
        return 'login'

    def get_navigation_items(self, req):
        if req.authname and req.authname != 'anonymous':
            yield ('metanav', 'login', 'logged in as %s' % req.authname)
            yield ('metanav', 'logout',
                   html.A('Logout',
                          href=self.master_href.logout(
                              referer=req.href(req.path_info))))
        else:
            yield ('metanav', 'login',
                   html.A('Login',
                          href=self.master_href.login(
                              referer=req.href(req.path_info))))

    # Internal methods
    def _get_name_for_cookie(self, req, cookie):
        return LoginModule(self.master_env)._get_name_for_cookie(req, cookie)
コード例 #2
0
 def match_request(self, req):
     if req.path_info.startswith('/projects'):
         path_info = req.path_info[10:]
         if path_info:
             self.log.debug('TracForgeDispatch: Starting WSGI relaunch for %s (%s)', path_info, req.method)
             project = path_info.split('/', 1)[0]
             # Check that we aren't trying to recurse (possible link loop)
             if project == os.path.basename(self.env.path):
                 req.redirect(req.href())
                 
             # Assert permissions on the desination environment
             try:
                 project_env = open_environment(os.path.join(os.path.dirname(self.env.path), project))
             except IOError:
                 raise TracError('No such project "%s"'%project)
            
             authname = RequestDispatcher(self.env).authenticate(req)
             project_perm = PermissionCache(project_env, authname)
             project_perm.assert_permission('PROJECT_VIEW')
             self.log.debug('TracForgeDispath: Access granted, running relaunch')
             self.log.debug('TracForgeDispatch: Status of req.args is %r', req.__dict__.get('args', 'NOT FOUND'))
             #self.log.debug('TracForgeDispatch: wsgi.input contains %s', req.read())
             self._send_project(req, path_info)
             self.log.debug('TracForgeDispatch: Relaunch completed, terminating request')
             self.log.debug('TracForgeDispatch: Response was %r', req._response)
             
             req._tf_print = True
             
             raise RequestDone, 'request done'
コード例 #3
0
 def _get_env(self):
     if not self._env:
         assert self.exists, "Can't use a non-existant project"
         try:
             self._env = open_environment(self.env_path)
             self._valid = True
         except Exception, e:
             self._env = BadEnv(self.env_path, e)
コード例 #4
0
ファイル: model.py プロジェクト: nyuhuhuu/trachacks
 def _get_env(self):
     if not self._env:
         assert self.exists, "Can't use a non-existant project"
         try:
             self._env = open_environment(self.env_path)
             self._valid = True
         except Exception, e:
             self._env = BadEnv(self.env_path, e)
コード例 #5
0
ファイル: util.py プロジェクト: jun66j5/TraM
def __open_environment(env_path, run_once=False):
    if run_once:
        return open_environment(env_path)

    global env_cache, env_cache_lock
    env = None
    env_cache_lock.acquire()
    try:
        if not env_path in env_cache:
            env_cache[env_path] = open_environment(env_path)
        env = env_cache[env_path]
    finally:
        env_cache_lock.release()

    # Re-parse the configuration file if it changed since the last the time it
    # was parsed
    env.config.parse_if_needed()

    return env
コード例 #6
0
ファイル: wsgiplugin.py プロジェクト: getpenelope/WSGITrac
    def _send_index(self, environ, start_response):
        projects = []

        for env_name in os.listdir(self.path):
            env_path = os.path.join(self.path, env_name)
            try:
              env = open_environment(env_path)
              env_perm = PermissionCache(PermissionSystem(env).get_user_permissions(environ.get("REMOTE_USER", "anonymous")))

              if env_perm.has_permission('WIKI_VIEW'):
                  projects.append({
                      'name': env.project_name,
                      'description': env.project_description,
                      # XXX: get rid of the double / in the beginning
                      'href': construct_url(environ, path_info="/"+env_name),
                  })
            except Exception:
              pass

        projects.sort(lambda x, y: cmp(x['name'].lower(), y['name'].lower()))
        start_response("200 OK", [('content-type', 'text/html')])
        return self.template.render({"projects":projects}, format='xhtml', template = "wsgiplugin.index")
コード例 #7
0
    def process_request(self, req):
        parent_dir = os.path.dirname(self.env.path)
        #env_paths = dict([(filename, os.path.join(parent_dir, filename))
        #                  for filename in os.listdir(parent_dir)])
        projects = []
                          
        for env_name in os.listdir(parent_dir):
            env_path = os.path.join(parent_dir, env_name)
            
            # Don't list this environment
            if env_path == self.env.path:
                continue
            
            try:
                env = open_environment(env_path)

                try:
                    #self.log.debug(env.path)
                    env_perm = PermissionCache(env, req.authname)
                    #self.log.debug(env_perm.perms)
                    if env_perm.has_permission('PROJECT_VIEW'):
                        projects.append({
                            'name': env.project_name,
                            'description': env.project_description,
                            'href': req.href.projects(env_name),
                        })
                except Exception, e:
                    # Only show errors to admins to prevent excessive disclosure
                    if req.perm.has_permission('TRACFORGE_ADMIN'):
                        projects.append({
                            'name': env.project_name,
                            'description': to_unicode(e)
                        })
            except Exception, e:
                if req.perm.has_permission('TRACFORGE_ADMIN'):
                    projects.append({
                        'name': env_path,
                        'description': to_unicode(e),
                    })
コード例 #8
0
 def process_request(self, req):
     raise TracError('How did I get here?')
     path_info = req.path_info[10:]
     
     if path_info:
         project = path_info.split('/', 1)[0]
         
         # Check that we aren't trying to recurse (possible link loop)
         if project == os.path.basename(self.env.path):
             req.redirect(req.href())
             
         # Assert permissions on the desination environment
         project_path = os.path.join(os.path.dirname(self.env.path), project)
         try:
             project_env = open_environment(project_path)
         except IOError:
             raise TracError('No such project "%s" at %s'% (project,project_path))
         project_perm = PermissionCache(project_env, req.authname)
         project_perm.assert_permission('PROJECT_VIEW')
         
         return self._send_project(req, path_info)
     else:
         return self._send_index(req)
コード例 #9
0
ファイル: config.py プロジェクト: pombredanne/trachacks
 def accessor(self, *args, **kwords):
     val = super(EnvironmentOption, self).accessor(*args, **kwords)
     assert val, 'You must configure a valid Trac environment path for [%s] %s' % (
         self.section, self.name)
     return open_environment(val)
コード例 #10
0
ファイル: config.py プロジェクト: nyuhuhuu/trachacks
 def accessor(self, *args, **kwords):
     val = super(EnvironmentOption, self).accessor(*args, **kwords)
     assert val, "You must configure a valid Trac environment path for [%s] %s" % (self.section, self.name)
     return open_environment(val)