ElkArte Community

Extending Elk => Addons => Topic started by: ahrasis on November 01, 2014, 12:36:36 am

Title: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 01, 2014, 12:36:36 am
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
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: emanuele on November 01, 2014, 08:20:50 am
I don't know the mod, but looks interesting. ;)
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 02, 2014, 01:08:37 am
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.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 05, 2014, 12:12:46 pm
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.]
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: Spuds on November 05, 2014, 03:09:11 pm
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 :)
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 08, 2014, 10:00:29 pm
I just got time to look into this further. I manage to put things into a working condition with no error.

Quote from: Spuds – $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.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: emanuele on December 09, 2014, 04:36:35 pm
Well, in that code the domain name of $boardurl is defined by $_SERVER['server_name']. Couldit be a server configuration problem?
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 09, 2014, 10:40:55 pm
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.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 12, 2014, 03:09:53 am
Quote from: emanuele – 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?
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 12, 2014, 06:45:44 pm
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).
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 17, 2014, 02:46:22 am
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.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: emanuele on December 17, 2014, 05:48:38 am
Can you point me where exactly the code is? (File and line number for example. ;))
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 17, 2014, 05:56:39 am
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.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 17, 2014, 06:25:19 am
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?
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 21, 2014, 10:22:49 am
This addon is upgraded to beta and rename as MESFA - Multi ElkArte Sub Forum Addon.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on January 08, 2015, 10:44:50 am
I am releasing a beta #2 package and welcome any comment and feedback.

The new package is attached in the OP.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: emanuele on January 08, 2015, 10:56:26 am
Cool! :D
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: meetdilip on January 08, 2015, 10:58:27 am
Another contribution :hatsoff:
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on February 04, 2015, 01:44:24 am
There are some fixes after the latest release involving Profile.controller.php (missing $db = database(); ) and Stats.subs.php (missing p).

In the earlier, find:
Code: [Select]
		// SubForums
global $modSettings;
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
$result = $db->query('', '
SELECT COUNT(id_msg)
FROM {db_prefix}messages
WHERE id_member = {int:id_mem}{subforums_see_board:id_board}',
array('id_mem' => $memID)
);
list($tmp) = $db->fetch_row($result);
$db->free_result($result);
$context['num_posts'] = comma_format($tmp);
}
Change it to:
Code: [Select]
		// SubForums
global $modSettings;
if(isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]))
{
$db = database();
$result = $db->query('', '
SELECT COUNT(id_msg)
FROM {db_prefix}messages
WHERE id_member = {int:id_mem}{subforums_see_board:id_board}',
array('id_mem' => $memID)
);
list($tmp) = $db->fetch_row($result);
$db->free_result($result);
$context['num_posts'] = comma_format($tmp);
}

In the later, find:
Code: [Select]
	// Number polls voted in.
// SubForums
$result = $db->query('distinct_poll_votes', '
SELECT COUNT(DISTINCT id_poll)
FROM {db_prefix}log_polls AS p
LEFT JOIN {db_prefix}topics as t ON (p.id_poll = t.id_poll)
WHERE id_member = {int:current_member}{subforums_see_board:t-id_board}',
And change it to:

Code: [Select]
	// Number polls voted in.
// SubForums
$result = $db->query('distinct_poll_votes', '
SELECT COUNT(DISTINCT p.id_poll)
FROM {db_prefix}log_polls AS p
LEFT JOIN {db_prefix}topics as t ON (p.id_poll = t.id_poll)
WHERE id_member = {int:current_member}{subforums_see_board:t-id_board}',
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on February 04, 2015, 01:53:49 am
One more thing which is missing in the later (missing c),
Code: [Select]
 // SubForums
 global $modSettings;
 $result = $db->query('', '
 SELECT COUNT(*)
 FROM {db_prefix}categories'. (isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]) ? '
 WHERE FIND_IN_SET(c.id_cat, {string:cats}) != 0' : ''),
 array(
 'cats' => isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]) ? $modSettings['subforums'][$_SERVER['SERVER_NAME']]['cats'] : ''
 )
 );
 list ($num_categories) = $db->fetch_row($result);
 $db->free_result($result);

Change to:
Code: [Select]
 // SubForums
 global $modSettings;
 $result = $db->query('', '
 SELECT COUNT(*)
 FROM {db_prefix}categories as c'. (isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]) ? '
 WHERE FIND_IN_SET(c.id_cat, {string:cats}) != 0' : ''),
 array(
 'cats' => isset($modSettings['subforums'][$_SERVER['SERVER_NAME']]) ? $modSettings['subforums'][$_SERVER['SERVER_NAME']]['cats'] : ''
 )
 );
 list ($num_categories) = $db->fetch_row($result);
 $db->free_result($result);
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: TomW on March 17, 2015, 12:47:46 pm
Are these changes included in the latest downloadable version ?   Are there any known bugs left to fix ?  Thanks; this mod is extremely useful for me !
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on March 18, 2015, 03:28:10 am
Beta2 is the latest package. I haven't got time to see through it though it should be working just fine. Do update any bugs that you found in this topic so that I can see to it when I got some spare time.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 05, 2015, 11:38:01 pm
Firstly, this mod is not 100% hook as mentioned in the addon site, as there are several manual modifications done. Secondly, there are still some bugs that need fixing though no one complains about them in here.

Since I have some times to go through this, I will try to release beta 3 version soon. I wish I can made this mod fully hook when a more stable version is released later.

The last thing to do, if possible, will be working with simple portal so that each sub forums may have its own portal pages and blocks. This is something I need to learn more later.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 08, 2015, 09:38:09 pm
Modifications in replies #18 and #19 will be added in Beta 3 since I realized that I didn't package them together in Beta 2.

In addition to that I will add some fix to font awesome that is not shown properly due to cross domains limitation. The fix is as follows, I hope, which should covers both ssl and non ssl combination, if any.

Firstly, do find in default index.template.php:
Code: [Select]
<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';

Then, replace it with:
Code: [Select]
<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />
 <link rel="stylesheet" type="text/css" href="http://' .  $_SERVER['SERVER_NAME'] . '/themes/default/css/font-awesome.min.css" id="font-awesome.css" />';

</head>

I wish I can understand where ElkArte controls all its url so that one change can really change and fix all subforums url. Right now we still see default url as well as subforums url, which is not good for many things especially ssl.

Edited: Earlier suggested place would negate any changes made by mods using $context['html_headers'] so the changes are made accordingly. This change need to be made only on the related theme. This will be fixed when issue with combined css is solved.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 09, 2015, 08:28:52 pm
I will make a final test before releasing the Beta 3 package that covers combination of SSL and non SSL domain. This can be seen e.g. in https://www.sch.my and subforums under it http://elkarte.sch.my.

Rewriting this mod will be my main quest on once this mod is considered stable for ElkArte.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 16, 2015, 08:38:22 pm
Beta 3 is now available and attached in the first post. Can't find any bugs so far but if you find one, do share.

I will concentrate in making it a fully hook addon, if possible, later on.

And thank you for testing this addon.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: emanuele on March 01, 2016, 04:00:28 am
If I got it right, the subforums are defined based on the categories?
A possible improvement (not sure if needed or not, just throwing around an idea that crossed my mind) would be to add a column to "boards" with the "sub-forum" id and filter the boards with that.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on March 01, 2016, 10:27:07 am
A good idea. This way, same category(ies) will hide board(s) that is meant for specific url (domain or subdomain) only. I will try to see its implementation side.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on August 08, 2016, 09:39:03 pm
There is a minor change affecting this mod in Who.subs.php but those who are updating using patch file via package manager is not affected.

But those who overwrite or are using a clean installed Elkarte v 1.0.9 yet wish to use this addon, pending a new package for this addon, in subforuminst.xml (install folder) find:
Code: [Select]
foreach ($url_list as $k => $url)
{
// Get the request parameters..
$actions = @unserialize($url[0]);
if ($actions === false)
continue;

Replace it with:
Code: [Select]
foreach ($url_list as $k => $url)
{
// Get the request parameters..
$actions = Util::unserialize($url[0]);
if ($actions === false)
continue;

This is only to make sure the necessary changes are in place but I haven't tested it for bugs. So, if you are using it, do it at your own risk. Do report if there is any bugs.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: Hewret on September 05, 2016, 11:56:43 am
Hey,

Thanks for great addon.
I'm using Split Forum Mod by dougiefresh, but I'm going to migate on ElkArte.
I just installed your addon, but it's not working for me. I setted the subforum on example.forum.net/subforum, but I have 404 error there.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on September 06, 2016, 08:27:53 am
This addon doesn't work like split forum mod as it only supports domain and/or subdomain.

You can use it to create as many domains and/or subdomains as subforums, for instance as follows:
https://www.sch.my
http://elkarte.sch.my
http://x-mans.sch.my
http://sahabat.ahrasis.com
http://alfateh.pi3kum.com

You need to create several membergroups if you want to separate access from one (sub)forum to another.

It will definitely not work with subdirectory / folder as in split forum mod.



Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on September 16, 2016, 12:04:56 pm
Quote from: emanuele – If I got it right, the subforums are defined based on the categories?
A possible improvement (not sure if needed or not, just throwing around an idea that crossed my mind) would be to add a column to "boards" with the "sub-forum" id and filter the boards with that.
About this @emanuele, I think we covered this by membergroup not by subforum id. The idea is if all forums have all the same three categories, the boards inside any of them will still be subjected to membergroup and will only be shown to that membergroup only.

However, if we want to manage the board separately based on the subforum, that may be needed. This will be applied to multi subforum admin. Hurrmmm...

Currently, I am also thinking on how to limit a post by their subforum / membergroup / buddy. There was a mod in SMF that can do something like that.

Still not sure on how to rewrite the addon and all of the above yet.  ::)
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 02, 2016, 01:38:49 am
Though I have not updated this mod, (I forgot), there was version 1.0.0 Beta 3.0.3 for ElkArte 1.0.9. Now there is Beta 3.0.4. which should work on ElkArte 1.1 Beta 3. I attached both packages in here, so that those who wish to test them, may do so at their test site and at their own risks.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 09, 2016, 12:15:47 pm
This beta 304a is an update to beta 304 (304 actually failed to work properly in 1.1 Beta 3, but it is very much working for 1.0 branch). I have tested it on 1.0.9 with no major issues, so far.

Please do report of any error or misbehavior while using or testing this addon because I am considering an upgrade to RC1, if there is no major issues for 1.0 branch (though major issues for 1.1 branch are still a few).

The file is attached.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 11, 2016, 07:05:58 pm
There is an error in integrate buffer in php 7 which is fixed in beta 305 package attached below. Do report especially if you are facing uninstall error.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on November 13, 2016, 11:37:20 pm
Thank to @badmonkey and @emanuele in other posts (http://www.elkarte.net/community/index.php?topic=4096.msg29455#msg29455), we found the issue in uninstalling the addon and managed to fix it. You may find package Beta 305a which is attached below.

I am not smart enough to convert this addon to a fully hook version thus if you can, do contribute.

Note: This mod is only for ElkArte 1.0 branch and is still not ready for 1.1 Beta 3.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: badmonkey on November 14, 2016, 12:23:50 am
Glad to help, my friend. I only wish I could do more. 
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on February 12, 2017, 05:45:00 pm
As stated in open post for support:
Quote from: ahrasis – I have been trying to upgrade the Multi Tenancy Addon (previously known as Multi ElkArte SubForums Addon) (http://www.elkarte.net/community/index.php?topic=2162.0) to make compatible with 1.1 RC 1 with no luck in converting the database part of the code. I commented out the code in Tenancy.mod11.xml for testing other code which so far are working. I need help in fixing that database part which has been discussed in other topic (http://www.elkarte.net/community/index.php?topic=4088.0) in here. If anybody can offer assistance, I'd be very grateful and will also consider a token for it. Do reply in this topic or pm me personally. Thanking you in advance.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on December 24, 2017, 08:34:20 am
I am releasing MultiTenancy version B306 (I shouldn't be using RC1 since there are bugs, a lot of them in EA1.1) which should be compatible with ElkArte version 1.1. Do test and report any errors to help making this addon better. I will try rewrite the admin template for managing MultiTenancy in the future so it will be easier to maintain more sub forums. I will also try to separate master forum from sub forums so sub forum admins will only see its own boards and non others. Only in master forum will admins see boards across all sub forums.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on January 01, 2018, 11:30:02 pm
Version B306a is now released with more bug fixes for EA version 1.1 above. Report for bugs are welcome.

Should all are functioning well, I will attempt to slowly rewrite this addon. Any help / assistance / thoughts are highly appreciated.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on March 05, 2018, 06:47:18 am
B306b is now released with minor bug fixes for the RSS. I am thinking of totally disabling RSS in the future if this addon is used.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on April 02, 2018, 11:43:20 am
This addon is upgraded to Release Candidate 1 especially for ElkArte version 1.1.3 and above. Features / changes in this release include:
- Database table for this addon is renamed to tenancy, thus, old database table with the name subforums won't work anymore. Manual transfer have to be done if you need the old database table.
- Tenancy Manager (settings page) have been rewritten together with its styling so it will be more responsive if the admin need to work from his tablet or smartphone.
- $boardurl is no longer rewritten compared to all previous version, instead, $scripturl is now defined to $tenancyurl/index.php, so each domain will be safely running their own forum while the $boardurl remain the same.
- With this, we separate the ability to add, edit or delete tenant(s) a.k.a subforum(s) from all other domains, so only the primary domain shall have control over it and no access can be made from other domains.
- Only category(ies) and board(s) that are assigned to a particular domain can be listed and modified from that domain, instead of all like in the old days, in preparation for separate admin ability for each secondary domain(s).
- Plan to separate between accessible categories (via forum front) and editable categories and boards (via admin end) as stated above is already being made though is not perfected due to lack of time and knowledge to do it.

This new version is currently in use at domains mentioned in the first / opening post.

That's all I guess. Do report if there are any bugs found. Thank you.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on February 03, 2019, 12:15:37 am
Huh...!? It has been more than 10 months ago since I did any changes to this addon. Hoperfully, those who are using it really does not face any bugs though I found one i.e. when the multi tenancy addon is just installed but no tenancy has been created.

The said bugs are relating to user posts, messages or stats but once the tenancy has been created, the error will be gone. Meaning, it should check if the tenancy is not empty before finding posts, messages or stats based on this addon, otherwise, it should use default elkarte feature.

This relates to modifications in two files, which I should fix in RC2 or its rewritten version.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on March 12, 2019, 05:31:02 am
I have been busy with other things and I haven't fix the above mentioned bug yet because I think those who do not wish to create any tenancy, should not install the addon as the first place or uninstall it thereafter. A customized error message is also good but I am not into it too.

What I intend to do for now, if I am still free to do it, are:

The first task seems easy as I think I need only to change from the forme to the later but I am not sure whether it will work. Or may be leave this as an option to the admin whether he wants to use the former or the later.

The second task seems to require some check for the last directory, where if no symlinked folder exist, it should be created. This may not be so easy too.

The last task seems to require a real upgrade to this addon though I could currently achieve it with the manipulation of mysql database file. I hope I will find a way to do this more easily /  in a better way.

I am crossing my fingers now and will attempt to finish this in a week or two....
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on April 17, 2019, 12:08:54 am
I think I will be doing modification to Bootstrap.php for this addon, create a .tenancy folder[1]to set a settings file for each tenancy url[2]in order to allow each tenant to have their own sub forums either based on url or path/directory/folder or both.[3]

I already tested some of the code to ensure that page creation speed remain the same with the current version, if not better.

I do found some diffculty in liasing with nginx as the addon will need to add other url in the nginx vhost in order to allow access to the added tenancy url. This could be difficult if one do not have access to server terminal or advanced control panel, so for this part I am not sure on how to handle it yet, except by manually adding the permitted url in the nginx vhost file.
I think it should be ok to use a 644 permission for this.
If just url e.g. test.sch.my.php or if using folder e.g. test.sch.my.forum.main.php
The current one is based on url alone and cannot use folder.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: Spuds on April 17, 2019, 09:41:34 pm
I've just finally realized just what this addon really does, very cool  8)
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on April 18, 2019, 09:33:37 pm
If one is used to multiisite in wordpress, this addon idea is something like that.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on April 19, 2019, 12:15:32 am
Regarding modifications in the bootstrap.php, basically I am thinking to replace the following code:
Code: [Select]
		// Where the Settings.php file is located
$settings_loc = __DIR__ . '/Settings.php';

With this:
Code: [Select]
		global $dboardurl, $dhost, $tboardurl, $thost;

// Get default $boardurl and $cookiename from default Settings.php
$ds_loc = __DIR__ . '/Settings.php';
$bu_ori = array();
$handle = @fopen($ds_loc, 'r');
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle);
if(strpos($buffer, '$boardurl') !== FALSE)
$bu_ori[] = $buffer;
if(strpos($buffer, '$cookiename') !== FALSE)
$cn_ori[] = $buffer;
}
fclose($handle);
}
preg_match('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $bu_ori[0], $bu_match);
$dboardurl = $bu_match[0];
$dhost = parse_url($dboardurl, PHP_URL_HOST) . (!empty(parse_url($dboardurl, PHP_URL_PATH)) ? parse_url($dboardurl, PHP_URL_PATH) : '');
preg_match("/(?:(?:\"(?:\\\\\"|[^\"])+\")|(?:'(?:\\\'|[^'])+'))/is", $cn_ori[0], $cn_match);
$dcookie = str_replace("'", '', $cn_match[0]);

// Now define tenancy host and boardurl
$thost = $_SERVER['HTTP_HOST'] . (!empty(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME'])) ? str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) : '');
$tboardurl = parse_url($dboardurl, PHP_URL_SCHEME) . '://' . $thost;

// Where the Settings.php file is located
if ($dhost === $thost)
$settings_loc = $ds_loc;
else {
$settings_loc = __DIR__ . '/.tenancy/' . str_replace('/', '.', $thost) . '.php';
if (!file_exists($settings_loc)) {
copy($ds_loc, $settings_loc);
file_put_contents($settings_loc, str_replace($dhost, $thost, file_get_contents($settings_loc)));
file_put_contents($settings_loc, str_replace($dcookie, uniqid(), file_get_contents($settings_loc)));
}
}

This will basically check the default $boardurl and $cookiename in default Settings.php and create a new settings (copied from default) for each tenant in .tenancy folder with its own tenancy $boardurl and $cookiename.

Edited: I think this modification can be done via bootsrap.php extension like "class TenantBootstrap extend Bootstrap" something and then overwrite the whole "private function loadSettingsFile()" overriding with "public function bringUpBasics()" (since private cannot be overriden by child class or something like that) but I am not so sure on how to achieve that in ElkArte yet.

I think I might attend the later approach, later.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on April 19, 2019, 07:54:05 am
Ok. The above modifications to bootstrap.php are kinda ugly, so I rewrote again.

This time I modified the following:
Code: [Select]
		else
{
require_once($settings_loc);
}
}

To this (which I think is cleaner, easier to read and comprehend):
Code: [Select]
		else
{
require_once($settings_loc);
}
$this->resetBoardUrl();
}

/**
* Reset $boardurl in Settings.php
*/
private function resetBoardUrl()
{
global $boardurl, $dboardurl, $dhost, $tboardurl, $thost;

// Default $boardurl and host
if (!empty(parse_url($boardurl, PHP_URL_PATH))
$dhost = parse_url($boardurl, PHP_URL_HOST) . parse_url($boardurl, PHP_URL_PATH);
else
$dhost = parse_url($boardurl, PHP_URL_HOST);
$dboardurl = $boardurl;

// Tenancy $boardurl and host
if (!empty(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME'])))
$thost = $_SERVER['HTTP_HOST'] .  str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']);
else
$thost = $_SERVER['HTTP_HOST'];
$tboardurl = 'http' . (parse_url($boardurl, PHP_URL_SCHEME) === 'https' ? 's' : '') . '://' . $thost;

// Switch to tenancy $boardurl if default is not the same
if ($dboardurl != $tboardurl | $dhost != $thost)
$boardurl = $tboardurl;
}

This code does not need a settings file, so I am in dilemma whether to create it for each of the tenant or not. I can reuse the previous code in tenancy.admin.php and there tenancy.template.php can create the file upon adding a tenant.
Title: Re: Multi Tenancy - Multi Forums Via Various Domains In A Single Installation
Post by: ahrasis on January 04, 2021, 07:55:39 am
Installing ElkArte 1.1.7 (testing) package and running it with this addon seems working good so far. Hopefully nothing much is changed until ElkArte 2.0.0 or I will have to spend some times revisiting - fixing or re-writing this addon. I really hope ElkArte 2.0.0 is multisite ready like WP but that is hoping too much, I think.