Skip to main content
Topic: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation (Read 4368 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Addon Name
The addon will now be known as Multi Tenancy .

Purpose
Helping forum admin to create multiple forums via various domains in a single ElkArte installation.

Features
- Own database table for this addon named as tenancy that will not affect default ElkArte database tables.
- Electable (various) category and access group for each domain / forum.
- Assignable default (one) theme , language, registered group for each domain / forum
- A responsive settings page style-able via css so the main forum admin can manage from his tablet or smartphone.
- Rewrite $scripturl to $tenancyurl, so each domain can safely run their own forums while the $boardurl remain the same.
- Only the primary domain shall have the ability to add, edit or delete tenant(s) a.k.a subforum(s).
- The secondary domains' admins can only list and modify category(ies) and board(s) that are assigned to their respective domain.

Rewrite
I will try to rewrite and improve this addon with a fully hook version and I will update the OP from time to time, if there is any improvement.

Live Test Sites
https://sahabat.ahrasis.com, https://x-skda.sch.my, https://x-mans.sch.my, https://elkarte.sch.my etc... on a personal private home server, so they may be down sometimes.

I hope this addon will be useful.  ;D

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #1
I don't know the mod, but looks interesting. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #2
Yes. It is interesting as subforums addon allows any subdomain(s) (including domain) to act as if it is a forum on its own. User just need to point them to the same directory. Category or categories can be shared and assigned to any of these subforums. Currently I only have two more files to find and replace (manual mod). Progress is as per picture attached. When this is working, may be a rewrite to fully hook will be made.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #3
I converted all the files for this Sub Forums Addon but I can't get it installed. Everytime I try to install the installation page when blank. I can still go back to package browser and other admin / user pages just fine.

What could be wrong?

I attached the packaged file here so that somebody/anybody can help me with it.

Note: I merely converted it for the time being. Any fixing or transform it to a fully hook version will come later.

[Edited: Package removed for further correction.]

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #4
Couple of minor things you need to do.

1) Go through the .xml file and update things like
include_once(SOURCEDIR .'/SubForums/Subforums-DB.php'); since you are installing the files in addons so that needs to be include_once(SOURCEDIR .'/addons/SubForums/Subforums-DB.php'); 
Do as needed for other includes or things will go bad.

2) The dbinstall.php file ...
- First I think you need to move $db=database(); to after SSI.php is included (generally at the top is fine like you have it but if someone trys to do a standalone install it will not work, well at least I don't think so). 
- You also need some table specific functions which are not in database() but in db_table();  That may seem confusing but those functions are rarely used so they are on their own. 
I'd them after the // Load the ELK DB Functions comment.
Code: [Select]
// Load the ELK DB Functions
$db = database();
$dbtbl = db_table();
- Lastly update a few of the calls, the first two are in db (database class) but prefixed with "db_", the last two are in the db_table class so use $dbtbl.
- $db-list_table needs to be $db->db_list_table
- $db->table_structure needs to be  $db->db_table_structure
- $db->drop_table needs to be $dbtbl->db_drop_table
- $db->create_table needs to be $dbtbl->db_create_table

That should at least install, then the debugging begins :)
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #5
I just got time to look into this further. I manage to put things into a working condition with no error.

$db->table_structure needs to be  $db->db_table_structure
I am currently using $dbtbl->db_table_structure instead. This seems working correctly. Otherwise, I would face problem in re-installation process.

However, I can't figure out why the url is not pointing to the right place. I have testing sites running on the following:
elk1.ahrasis.com
elk2.ahrasis.com
qom.ahrasis.com
main.ahrasis.com (main site)

All links for each subforum are supposed to point to their own url and not to the main site.

I think something is not working here:
Code: [Select]
// define the url's
$base_boardurl = $boardurl;
$parts = parse_url($boardurl);
$boardurl = $parts['scheme'] .'://'. $_SERVER['SERVER_NAME'] .(!empty($parts['port']) ? ':'. $parts['port'] : '') . (!empty($parts['path']) ? $parts['path'] : '');
$board_language = $language;

// load the setting
SubForums_LoadSettings();

I attached the latest test package. Hopefully, somebody would come to the rescue and help fix this main part.

Edited: Wrong package. Removed and added the correct one.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #6
Well, in that code the domain name of $boardurl is defined by $_SERVER['server_name']. Couldit be a server configuration problem?
Bugs creator.
Features destroyer.
Template killer.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #7
Negative. It is tested in the same server that run subforums mod for SMF, but I will try it on another server. Something in the code may be missing or need replacement. I will have to go through them again one by one.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #8
Well, in that code the domain name of $boardurl is defined by $_SERVER['server_name']. Couldit be a server configuration problem?

I changed that to $_SERVER['HTTP_HOST'] with no luck as well. Could it be something in ElkArte? How do I "force" ElkArte to respect the browser current url via other means?

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #9
For the time being I modified the $boardurl in Settings.php by replacing current $boardurl with this one:
Code: [Select]
$boardurl = 'http://'. $_SERVER['SERVER_NAME'] .(!empty($parts['port']) ? ':'. $parts['port'] : '') . (!empty($parts['path']) ? $parts['path'] : '');

The url is now working as expected but not as it is supposed to (it should do more but I will to see to that later).

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #10
After several testing, I find out that the parse_url is not working at all. It could be ElkArte built-in code that prevented or overrode this. $parts['scheme'], $parts['host'], $parts['port'], $parts['path'] though parse_url is applied to $boardurl via $parts = parse_url($boardurl);.

How do I make it works? Hacking Settings.php is only my temporary solution. Any help to overcome this problem is very much appreciated.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #11
Can you point me where exactly the code is? (File and line number for example. ;))
Bugs creator.
Features destroyer.
Template killer.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #12
Subforums.php, line 14-41.

Code: [Select]
if (!defined('ELK'))
die('Hacking attempt...');

/**
* Init..
**/
global $SubforumFunc, $base_boardurl, $boardurl, $board_language, $language;

// define the url's
$base_boardurl = $boardurl;
$parts = parse_url($boardurl);
$boardurl = $parts['scheme'] .'://'. $_SERVER['SERVER_NAME'] .(!empty($parts['port']) ? ':'. $parts['port'] : '') . (!empty($parts['path']) ? $parts['path'] : '');
$board_language = $language;

// load the setting
SubForums_LoadSettings();

// setup function array
$SubforumFunc = array(
'isAllowed' => 'Subforums_isAllowed',
'LoadTheme' => 'Subforums_LoadTheme',
'getContext' => 'Subforums_GetContext',
'getScripturl' => 'Subforums_GetScripturl',
'getMemberurl' => 'Subforums_GetMemberurl',
'isOwnurl' => 'Subforums_isOwnurl',
'checkurl' => 'Subforums_checkurl',
'updateStats' => 'Subforums_updStats',
);

Since parse_url here is not working for unknown-to-me reason, I have to do the above mentioned hack. But now I temporarily changed QueryString.php instead of Setting.php to include $boardurl = 'http://' . $_SERVER['SERVER_NAME'] just before $scripturl = $boardurl . '/index.php'.

Latest package is attached.

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #13
Just to make sure that I tested it right, I put the following codes inside index.template.php and the return is invalid input.

Code: [Select]
echo isset($parts['host']) ? $parts['host'] : 'Invalid input<br />';
echo isset($parts['scheme']) ? $parts['scheme'] : 'Invalid input<br />';

It should return with the url and the http if it is working, right?

Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation

Reply #14
This addon is upgraded to beta and rename as MESFA - Multi ElkArte Sub Forum Addon.