SimplemachinesIntegration

(redirected from Cookbook.SimplemachinesUserSystemIntegration)

Summary: How to use the authentification of the Simplemachines forum to control the access to a PmWiki installation
Version: 2006-1-21
Prerequisites: PmWiki 2.1
Status:
Maintainer: Anno
Categories: Integration, Security

Question

How can I use the user authentification of the Simplemachines forum to control the access to my pmwiki installation?

Answer

This recipe enables all registered users on a Simplemachines forum to edit the wiki pages. The wiki pages in the Site group can only be edited by the users with the status administrator.

The recipe currently requires to edit the pmwiki.php file, as it wouldn't work when included only from the config.php file.

Installation instructions

1. create a file called forumauth.php with this content:

 <?php
 //Simplemachines authentication
 $pos = strpos($_SERVER['REQUEST_URI'], "action=edit");
 if (is_numeric($pos)){
 	require_once('/path/to/your/forum/SSI.php');
 	if (!$user_info['username']) {
 		echo "You have to be registered and logged in at the Forums
 		in order to edit this wiki document.<br /><br />
 		1.) First  <a href='http://www.yoursite.com/forum/index.php'?action=login' 	
 		target='_blank'>click here</a> 
  		to open a new window where you can log in at the Forums,
 		(leave that window  open after you logged in)<br />
 		2.) Then  <a href='{$_SERVER['REQUEST_URI']}'>click 
 		here</a> to edit the wiki page.";
 		exit;
 	}
 }

Modify

 /path/to/your/forum/SSI.php

and

 http://www.yoursite.com/forum/index.php

to fit your forum.

Copy the file forumauth.php to the pmwiki local/ directory.

2. Edit Site.EditForm and
replace:

 (:input e_author:) 

with:

 {$Author}

3. Add this to your local/config.php file:

 $DefaultPasswords['edit'] = ($user_info['username']) ? '' : '*';
 $DefaultPasswords['admin'] = ($user_info['is_admin']) ? '' : '*';
 $Author = $user_info['username'];

4. Add this to the top of the local/config.php file, immediately after <?php

 require_once('forumauth.php');

Notes

  • This recipe was last tested on PmWiki version: 2.1beta20
  • This recipe requires at least PmWiki version: 2.1beta20

Releases

Anno 2006-1-21 Version 1.0

Comments

Sorry, but this does not work, at least on my server. How to debug??? I have pmwiki installed at wiki.example.com and SMF is on example.com/smf/ - will this still work then?

It should, as long you set the paths correctly. Anno May 19, 2007, at 05:52 AM

Also I wonder how to follow your steps, because if I follow 1 - 3, I can not edit Site.EditForm anymore, because it asks me to be logged in (and that, in return, does not work)...

I changed the directions to first change the Site.EditForm Anno May 19, 2007, at 05:52 AM

Hi! how do I get it to work also for read authorisation? If I add

 $DefaultPasswords['read'] = ($user_info['username']) ? '' : '*';

it will not work and ask me for a password. Any easy fix so that you need to be a forum member to be able to read and write?


If you want to give permission to edit pages only to SMF Forum Administrator(s),

add this to your local/config.php file :

 $DefaultPasswords['edit'] = ($user_info['is_admin']) ? '' : '*';
 $DefaultPasswords['admin'] = ($user_info['is_admin']) ? '' : '*';
 $Author = $user_info['is_admin'];

instead of this:

 $DefaultPasswords['edit'] = ($user_info['username']) ? '' : '*';
 $DefaultPasswords['admin'] = ($user_info['is_admin']) ? '' : '*';
 $Author = $user_info['username'];

Hi there,

the recipe above made editing a bit annoying, because all single quotes were framed in backslashes like this: \'\
So neither bold nor italic text was possble. I racked my brain and finally found a workaround. Because it also gives some aditional functionality, I'd like to share it with you.
The following recipe works fine with my installation of SMF 1.1.4 and PmWiki 2.1.27:

Installation instructions

1. Create forumauth.php as described above with this content:

 <?php
 //Simplemachines authentication
 $pos = strpos($_SERVER['REQUEST_URI'], "action=edit");
 if (is_numeric($pos)){
        if(!require_once('/path/to/your/forum/smf_api.php'))
        die('Unable to connect to authentication database: Please try again later');
			smf_authenticateUser();
				if (!$smf_user_info['username']) {
 		echo "You need to be registered and logged in at the Forums
 		in order to edit this wiki document.<br /><br />
 		1.) First  <a href='http://www.yoursite.com/forum/index.php'?action=login' 	
 		target='_blank'>click here</a> 
  		to open a new window where you can log in at the Forums,
 		(leave that window  open after you logged in)<br />
 		2.) Then  <a href='{$_SERVER['REQUEST_URI']}'>click 
 		here</a> to edit the wiki page.";
 		exit;
 	}
 }

Modify

 /path/to/your/forum/smf_api.php

and

 http://www.yoursite.com/forum/index.php

to fit your forum.

Place forumauth.php inside your local/ directory.

2. Edit Site.EditForm and
replace:

 (:input e_author:) 

with:

 {$Author}

3. Add this to your local/config.php file:

 require_once('forumauth.php');
 $DefaultPasswords['edit'] = ($smf_user_info['username']) ? '' : '*';
 $DefaultPasswords['admin'] = ($smf_user_info['is_admin']) ? '' : '*';
 $Author = $smf_user_info['username'];

If you like to give edit permission just to one or more groups in your forum instead to all registered and logged-in users, you can use these lines instead:

 require_once('forumauth.php');
 $DefaultPasswords['edit'] = ($smf_user_info['ID_GROUP'] == #) ? '' : '*';
 $DefaultPasswords['admin'] = ($smf_user_info['is_admin']) ? '' : '*';
 $Author = $smf_user_info['username'];

You have to replace the # with the group-ID. You can get the group-ID on the membergroup-site in your forums.
You can give permission to multiple groups by chaining the groups like this:

 $DefaultPasswords['edit'] = (($smf_user_info['ID_GROUP'] == 1) or ($smf_user_info['ID_GROUP'] == 2)) ? '' : '*';

4. You need the smf_api.php-File in version 1.1, so don't waste your time to download it from the SMF-Homepage (at least as long as that site isn't updated): Get it in the SMF-Forum. You need to be registered to see the attached file.
Place the downloaded file in your forum directory, right next to the index.php and SSI.php. ;-)

That's it.

Greetings! TrashQueen

See Also

Contributors

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.