Jump to content

ALIF - Admin Links In Frontend


horst

Recommended Posts

ALIF - Admin Links In Frontend

EDIT: latest version update with PHP 8 fixes on 05. Nov 2023 (!)
The version now is 1.1.9 (!)


This module combines some of the admin links that we want to use on the frontpages sometimes. It is a comfortable and easy way to do so. After you have installed and configured the module, you can inject the links into the frontpage with code like this in a template file:

echo $modules->isInstalled('AdminLinksInFrontend') ? $modules->get('AdminLinksInFrontend')->render() : '';

.

Credits: The comfortable Javascript Color Picker in the Configpage comes from Jan Odvarko (http://jscolor.com). Many thanks for this!

* Toolbar
 
The toolbar can be positioned by css values for top/bottom and left/right. It can expand in vertical or horizontal direction. The buttons are links to the PW admin, for logout, or for editing the page in admin, or informational ones. All settings, including the colors, can be defined in the modules config page. This is available for all PW versions from PW 2.3 up to now.
 
pw_alif_01.jpg
 
Depending on how you configure this part, it can be used for authors and editors too, maybe.
 
 
* Import / Export Settings
 
It has the possibility to export and import its settings via two textarea fields. When importing settings, you get a second screen where you can select which settings you want to import.
 
post-1041-0-93467100-1450162787_thumb.jp
 
* One-click User Account Switcher
 
For PW versions 2.6.8+, there is one really nice function available, that I use when developing / testing sites with different user / roles. A fast User-Account-Switcher that lets you view the same page from different user accounts with only one click. To enter this mode, you need to login as a superuser one time, and the feature needs to be enabled in the module of course. After that, you can log out, login with different user roles, etc. At least the toolbar buttons for the User-Account-Switcher will stay visible for you. :)
 
This is session based. There is also an extra button with a trash can and the text "Session", that helps you to leave this mode once you are finished.

pw_alif_02.jpg
 
As you can see in the screenshot, after clicking "guest",  I was logged out, but a regular login button, a warning for debug mode and my three defined buttons for user accounts are available. When clicking another user button I login with this account. Very handy.
 
ATTENTION!
 
The use of the One-click User Account Switcher is mainly intended for dev sites, not for public sites! You should be aware that there is a huge security risc when using this feature on public reachable sites! We completly leave ProcessWires comfort zone in regard of security, - and the only thing between your site and potentially hackattacks is this module. (Oh mom, - what have I done?)
 
PW 2.6.8+ has a comfortable function for admin tasks, that let us log into different user accounts via API without using passwords. This module uses this function! All data that is needed during a User Account Switcher session is stored in the session data on the server. So, if someone steel your session cookie, there is potentially risc that he can login as a superuser, depending of the user account buttons you have in your admin links collection! To prevent SessionHijacking, the module can be bound to a single IP address, it uses a fingerprint depending of IP(s) and UserAgent string. And you need to define a max time to live in minutes between 2 and 60, a User Account Switcher session may run.
 
A User Account Switcher session only can be initialized by a Superuser who also explicitly has set a permission called 'alif-user-account-switcher', what is defined by the module, when installing it. So, the prefered way to use this module is, to enable and use the User Account Switcher while the site is unpublic, and before it goes public, remove the permission from the superuser role. This way, you can use its menu function, but not the UAS anymore.

On a sidenote, for those rare cases where multiple superusers simultaneous developing on a site and want to use the ALIF, but the UAS should be used only by one, you can leave the 'alif-user-account-switcher' permission removed from the superuser role, but need to assign the role 'alif-superuser' to the single user account. This way, only that single superuser has the permission for UAS, whereas all other superusers doesn't have it.
.
.

* The Configpage

pw_alif_04.jpg
 

 
* Online demo

I have pasted it into this old site and enabled it to be present every time (when the site is in demo mode only!). So, it is an earlier state, but the switcher is functional there: http://pwlaf.biriba.de/dbinfo/
 

* Download

From our modules directory or from github repo

Edited by horst
  • Like 31
Link to comment
Share on other sites

Have seen that it was mentioned in last ProcessWire Weekly. (sighh, have hurried up with it)

I have tested it with PW versions 2.3, 2.4, 2.5, 2.6, 2.7 and with PHP 5.3 and 5.4. It works good from PW 2.4+ up! With PW 2.3, the Javascript Color Picker doesn't function. But 2.3 is really old and if someone has maintained a site until now without ALIF, he will do it fine in future too. :lol:

Only thing I want to know is: in wich PW version was "showIf" introduced to show / hide Inputfields in the admin? Would be nice if someone can point me to that.

So, it is ready for the masses now! ;)

Edited by horst
  • Like 5
Link to comment
Share on other sites

Added another little tool to the box that I sometimes use to detect best breakpoints for mediaqueries. A little Javascriptbox that displays the dimensions of body and a configurable custom container (by ID). What dimensions are shown, offsetWidth, ClientWidth, ScrollWidth, is dynamically configurable in the Top of the JSbox:

 

pw_alif_07.jpgpw_alif_08.jpg

 

To enable / disable it, select or drop the button in the config page, and, optionally, type in the id of a custom container.

  • Like 5
Link to comment
Share on other sites

  • 1 month later...

This is a pure info icon. It (only) recommends you that you have $config->debug set to true! So, maybe not that useful in develoment mode, but later, if you use a small set of admin links for editors too, it is useful to be rmembered to turn out debug mode when finished something on a production site.

Link to comment
Share on other sites

  • 3 weeks later...

hi horst,

i can't seem to get the user switcher working... after some setup problems i finally got the user-buttons to display. but when i click on "guest" i am logged out and don't see the user buttons any more. also the "enable login-button" seems to have no effect.

can you please help me how i can debug this? thanks!

Link to comment
Share on other sites

This morning, I finally had time to install this module. I am blown away to it's usefulness and wish I had made time to look at this a whole lot earlier. Great work, @horst!

Thanks Charles!

hi horst,

i can't seem to get the user switcher working... after some setup problems i finally got the user-buttons to display. but when i click on "guest" i am logged out and don't see the user buttons any more. also the "enable login-button" seems to have no effect.

can you please help me how i can debug this? thanks!

Bernhard, I'm not sure, but best thing would be, if you can run this locally and use an IDE with debugger. Everything in this regard is Sessionbased. You need to check / debug those functions in the module:

  •     public function hookBeforeProcessLogin(HookEvent $event) {
  •     public function hookBeforeProcessLogout(HookEvent $event) {
  •     public function hookAfterSessionLogout(HookEvent $event) {
  •     public function hookAfterSessionLogin(HookEvent $event) {

Also I don't know what you mean with: "after some setup problems"?

Link to comment
Share on other sites

hi horst,

i tried it on a fresh install today and got it working. don't know what was the reason but i'm too busy right now to investigate further :(

Also I don't know what you mean with: "after some setup problems"?

i was not sure what all the fields where doing

post-2137-0-30370400-1456420160_thumb.pn

my questions where like this:

"select users"

what is this doing? is this controlling access? will only users selected here see the switcher?

"start UAS session"

what is an UAS session?? ok got it now... user account switcher, but i thought that was a technical word i didn't know. and therefore i didn't know what this checkbox is doing at all.

i think step by step instructions would be good, like:

if you want to show the user switcher proceed as follows:

  • check the box "enable user account switcher
  • select users that should be shown in the switcher-panel
  • check the box to start the user account switcher (UAS) session
  • select the time, how long the UAS should be active (no good english i think)
  • click on "submit" button and go to frontend. the UAS-Panel should show up

edit: i think it would help to change the field label from

Configure and start the fast User Account Switcher

to

Configure and start the fast User Account Switcher (UAS)
 
maybe that sounds too much to you, but it was really not clear for me as i did not know anything about the workflow.
 
edit2: maybe a screencast with licecap would have also solved those questions ;)
Link to comment
Share on other sites

  • 3 months later...

Sorry it's me again, 'Warm up opcache with PW files' throws an error here (Tracy):

Cannot declare class ProcessWire\InputfieldForm, because the name is already in use
5×	
PHP Notice: Undefined index: dirname in .../AdminLinksInFrontend/libs/hn_basic.class.php:1748
21×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:60
634×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:249
1×	
PHP Notice: Use of undefined constant THOUSAND_SEPARATOR - assumed 'THOUSAND_SEPARATOR' in .../site/modules/AdminLinksInFrontend/libs/opcache.php:183

Link to comment
Share on other sites

Hhm, looks like the OPCache class is not ready to use with PW3 namespaces. Unfortunately I have no PW3 installl with OPCache installed where I can test it. :(

To the first error, I can say this sounds a bit weird, because I try to get the Page of Admin -> Setup (what is 22) and than checks if it has a children Page with the name of the OP-Cache Viewer. So this should return A) the page if existing, or B) a NullPage object. Both possible returns are objects. So, without able to test, it looks weird.

What ID does your Admin Setup Page have?

---

I suggest to uninstall the OPCache Viewer and only use the Admin Links In Frontend module until I got solved this. (What may take a while, :( )

Link to comment
Share on other sites

Ok, thanks. Don't worry about the errors, I use this module only occassionally, and I just took a look on the opcache viewer as there's opcache on the server.

As for issue No1, maybe there's an extra "children('include=hidden')" that doesn't needed?

// original - throws error
$p = $this->pages->get(22)->children('include=hidden')->get('name=' . AdminLinksInFrontend::opcPageName);

// works
$p = $this->pages->get(22)->get('name=' . AdminLinksInFrontend::opcPageName);

// in one go
$p = $this->pages->get('parent=22, name=' . AdminLinksInFrontend::opcPageName);
Admin->Setup has the id of 22 here too. I forgot to mention that it's PW 3.021 here but it seems you figured this out :)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi, Horst,

I just tried to install the module, but got 2 error messages right after downloading, regarding:

AdminLinksInFrontend.module, line 153
and
ProcessAdminLinksInFrontend.module, line 45

In both cases I had to remove the [...] part to get it working: 

self::$opcEnabled = opcache_get_status();//['opcache_enabled'];

I am running PW 3.0.23 in this particular case.

 

EDIT: Ok, now PW tells me why: I need to install PHP 5.4 or greater...

Sorry for bothering you!

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
On 12/10/2015 at 12:35 PM, horst said:

A User Account Switcher session only can be initialized by a Superuser who also explicitly has set a permission called 'alif-user-account-switcher', what is defined by the module, when installing it.

Just an FYI, that a recent change to the core might make this impossible to do via the admin:
https://github.com/processwire/processwire/commit/7943aa1064204db5415d661312037f1dd4199249

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...