We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37059
    • 368 Posts
    I'm attempting to get a site on a local development server to where I can access it using two different hostnames. (I'm using multiple sites in one installation with a single gateway plugin.) So far I have been making reasonable progress, but while I was working a little while ago I suddenly started getting "access denied" to my main manager user when trying to do anything in the manager. I can still log in (but not log out!) but the manager won't let me do anything.

    Here's what I was doing, best I can remember, just before I got locked out:

    I had two contexts in my site, web and site2. I duplicated the site2 context as site1, deleted everything in it and moved all the resources from web to the new site1 context. Then I edited my single gateway plugin to direct the domain for site1 to the new context.

    I went back to try and edit the site1 context in order to set its homepage, and that's when I started getting access denied. Now I can't even clear the cache.

    Thinking my single gateway plugin might be screwing things up, I went into the database and manually set 'disabled' on that plugin to '1.' No changed. I also tried logging in with several different browsers, but all gave the same result: I can log in, but I can't do anything once there.

    If anything occurs to anybody, I'd really appreciate some suggestions.

    Thanks!
      Jason
      • 3749
      • 24,544 Posts
      Make sure you have a Context Access ACL entry for the Administrator group for each context with a policy of Administrator.

      And a Context Access ACL with a context of 'mgr' and a policy of Administrator-- If you've modified or deleted that one, you may need to go into the DB to fix it.

      You may also need to clear the cache manually by deleting all files in the core/cache directory.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 3749
        • 24,544 Posts
        The modx_access_context table should look like this:

          id  target  principal_class    principal  authority  policy  
         1   web     modUserGroup      0             9999        3 
         2   mgr     modUserGroup      1             0           2 
         3   web     modUserGroup      1             0           2 
        
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 37059
          • 368 Posts
          Thanks for the quick reply, Bob. That part of my mox_access_context table looks exactly like the one you show.

          I decided to go ahead and pull a known good remote database since I kinda needed to do that anyway. After applying it, naturally everything works again. I'm going to go back through, doing the steps I did before, and see if I get locked out again. I'll post any results to this thread.
            Jason
            • 37059
            • 368 Posts
            Okay, for reference, I found the problem. It was my plugin after all; I didn't clear core/cache when I disabled it as a test the first time.

            Here is the code I'm using:

            <?php
            /* Setup context mapping */
            switch ($modx->getOption('http_host')) {
            	case 'site1.local:80':
            	case 'site1.local':
            	case 'www.site1domain.com:80':
            	case 'www.site1domain.com':
            		// if the http_host is of a specific domain, switch the context
            		$modx->switchContext('site1');
            	break;
            	  
            	case 'site2.local:80':
            	case 'site2.local':
            	case 'www.site2domain.com:80':
            	case 'www.site2domain.com':
            		// if the http_host is of a specific domain, switch the context
            		$modx->switchContext('site2');
            	break;
            
            	default:
            		// fallback, go to main context
            		$modx->initialize('web');
            	break;
            }
            


            The problem with this code is, I was trying to access the manager at site1.local/manager or site2.local/manager. Obviously, that causes the plugin to try and load a context other than the Manager!

            While it would be possible to put some kind of conditional on the plugin code so that it wouldn't run if the manager was being requested, I simply added another local domain to use for the main web context (which I was planning to do anyway) and I can access the manager through that context just fine.
              Jason
              • 37059
              • 368 Posts
              Yet another followup smiley

              Turns out there's a very simple way to keep this script from executing if you're in the manager, from the OneGateway section of the docs. Just add this at the top of the plugin code:

              <?php
              /* don't execute if in the Manager */
              if ($modx->context->get('key') == 'mgr') {
                  return;
              }
              
                Jason