0

I want to build a page of links that will let me login to edit a specific MSM (Multi Site Manager) site. Instead, EE opens the site I was editing last. This has often resulted in adding templates to the wrong site and then having to move them. Or editing content on the wrong site. Making changes and not seeing them on the site. Or being very confused when trying to edit content because I can't find it.

We're using ExpressionEngine 2.7.3 with Multi Site Manager 2.1.6 - and we've renamed admin.php for security purposes.

What I've Tried

I looked at: Creating Custom CP Links to Other Site Channels in MSM with Zoo Flexible Admin which discusses the commented-out base64 page parameter. Since I'm not interested in loading a specific page, I'm not terribly worried about that functionality. But the question seems to indicate that I can build a link with C=sites&site_id=1 to switch to site 1. This doesn't quite work for me.

So next, I examined the msm_sites links. This revealed that the link to switch to a site is constructed as described in the question above, but with additional parameters. Here's all of them, with some bogus values:

S=QSBsb25nIHRpbWUgYWdvLCBpbiBhIGdhbGF4eSBmYXIsIGZhciBhd2F5
D=cp
C=sites
site_id=1
page=TGl2ZSBsb25nIGFuZCBwcm9zcGVy

Exploration reveals that the S ("session" I'm guessing) parameter is probably the value of {cp_session_id}. I can't include that in my link, because it will only be good during the current session. I'm guessing the D param is for "destination" or something. And D=cp looks good to me. The C ("controller" maybe?) and site_id parameters look promising, so I include those. And since I don't care about which page I end up on, I leave out the page parameter as well, leaving me with an HREF that looks like:

http://ee.example.com/notadmin.php?D=cp&C=sites&site_id=1

However, when I load this URL and log in, I end up at the control panel for the site I was editing last. Much sadness. Very growl. My best guess is that EE is discarding my request to switch sites because I don't provide the S parameter. I don't know how to get around this.

My partial solution is creating an accessory that color codes the control panel background to improve the chances that I'll notice I'm working in the wrong site. But I'd really like to be able to use my handy page-full-of-links method. Any suggestions?

1 Answer 1

1

I can think of two possible approaches:

I assume you're administering all sites through a single shared control panel? If so, you could consider switching to using per-site control panels - all it takes is copying admin.php (or whatever you renamed it to) into each site's public root and then editing the path to the system directory and setting which site to use for each one as described in that file.

$assign_to_config['site_name']  = 'domain2_short_name';
$assign_to_config['cp_url'] = 'http://domain2.com/admin.php';

Alternatively, if you want to stick with a single shared control panel, you could probably manipulate the value of the exp_cp_last_site_id cookie to suit your needs. That alone should log you in to your chosen site. Depending on how you're generating your page full of links (is it an EE template?), you could make an add-on that does the heavy lifting, or depending on security settings you might be able to manipulate the cookie via JavaScript. If it were me, I'd make an add-on and have each link go to an EE ACT url to direct it through a module method which figures everything out, resetting the cookie value before redirecting to the control panel.

2
  • consider switching to using per-site control panels Yes, we use the same CP for four sites. However, this is not a configuration I would change lightly. Sounds like I might explore this if the other options you suggest don't pan out. you could make an add-on that does the heavy lifting I'd like to explore this further. The page of links, by necessity, is not generated by EE at all, it's merely HTML. Is it possible to have a plugin run post login and checks for a site ID? May 19, 2016 at 14:35
  • Probably could do that with an extension, but I'm not sure where it would get the new site ID from (i.e., the one it needs to switch to). Probably easier to create a module method - so your external links would look like an-EE-site.com/?ACT=123&site_id=4 - those links could then be hardcoded into a static external HTML page and would still work fine. Then your action method would take the the site_id from $_POST, (re)set the cookie value and redirect to the login page. May 19, 2016 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.