Jump to content

Recommended Posts

Posted

Is there a way to add a url to the $config->httpHosts var programmatically?  I am working on a multisite install and want to save editing this file all the time.

Thanks!

Posted

You can also just leave config httpHosts blank.

You could update it via API like this

        $hosts = wire("config")->httpHosts;
        $hosts[] = "ww.domain.ch";
        wire("config")->set("httpHosts", $hosts);

This should be in a autoload init(). But I'm not sure it be early enough to work.

Posted

I was thinking an api way to do this was in dev branch, but I wasn't sure if it made it to the stable branch or not yet!

Posted

The httpHost check is quite early in the bootstrap process, even before all the api variables are set or the database connection is established, so I doubt you'll find a way to hook anythings before that. 

Posted

No you can (with my example) add entries to the $config->httpHosts but it's won't have an effect cause the whitelist is checked before you can do this in a module or template or whatever. I'm not sure why you'd want this. It's not like you change this all the time.

Posted

You can change it, but wherever you do so it's most likely to late to be picked up by the internal check, that compares the actual httpHost to the whitelisted ones. The changes would only be available to everything running later. The only way to have it pick up for the internal check, too, is by editing the config file itself, which could be made automatically. 

Another option would be supplying no httpHosts all together and call the check manually after adding all the needed domains. But it's a question for Ryan to answer if this would actually be of use for the security.

@Soma 

I can understand that need. If you'd build some kind of SaaS software, where the user should be able to add their domains, you wouldn't want to edit those manually.

  • Like 2
Posted

I mentioned in the initial post I am working on a multi site install where I already have to create the url list in the module manually.  

That means every time I add a users website to my multisite, I have to manually add it 2 places.  One using the cms and one hand editing the config file.  It would be nice if I could add it manually only one time and make one read the other.

Anytime you have 2 manual lists, it creates an opportunity for something to become out of sync.  If I am going to update one time, I would prefer it to be via cms/database instead of file to edit as well.

  • Like 1
Posted

so what's wrong with changing

$config->httpHosts = array('domain1.com', 'domain1.com');

to something like that

$config->httpHosts = explode(PHP_EOL, __multisite_domains_textarea_content__);

in config.php?

Posted

Does the config file have the ability to access the database using processwires connection?

Or would I just use its own variables to make my own connection?

Posted
If I need to, I could open my own database connection and look up:
 
SELECT data FROM `modules` WHERE class = 'Multisite' LIMIT 0 , 1
 
That would return:
 
{"subdomains":"www.domainname1.com\nwww.domainname2.com"}
 
Then I could set the $config->httpHosts variable with that.

I am sure this query would be cached by mysql into ram since it would be ran so much.
Posted

That would be great, but I dont think the module would be accessible yet.  I know very little about processwire though so I could be wrong!

so what's wrong with changing

$config->httpHosts = array('domain1.com', 'domain1.com');

to something like that

$config->httpHosts = explode(PHP_EOL, __multisite_domains_textarea_content__);

in config.php?

Posted

That would be an option.  Its just a little bonus if I can do it all from cms.


I think Ryan is adding a way for cms to edit config file though...

Posted

Soma, I am using your version of multisite module, so it may be best if we add this to your module.  

We could have it load urls from config instead of its own box.   Even if there is a select box to tell it where to load them from and give the user the option.

Then when Ryan allows cms to edit config file to stable branch, there will be only one place required.

Posted

Ryan already has the module to edit config in backend since 2.5 in his repository.

I'm working on a new multisite version but doubt it will be ready anytime soon.

  • Like 2
Posted

That is helpful.  So the backend code is there but there is no UI in cms to use it yet?  (Edit config module)

Posted

A way to edit the static config file and have the module load that would be much better/faster than pulling them from the database.  I think I am going to pursue that route.

Posted

Found it! ProcessWireConfig

https://processwire.com/blog/posts/processwire-core-updates-2.5.10/

I uploaded this module and now I can edit config settings.  

Instead of editing the file, it simply creates a config.json in your assets folder and adds code to the end of your config file to check for and read this new file.

It adds the contents of that file to your $config array.

What improvements / features are you adding to your new version of multi site?

Posted

This feels like a bad idea, but I can't figure out why. Fiddling around I found that...

$config->httpHosts = '*';

...works. It allows my addon domains through. Is this a bad idea? Why?

Another way around it, although not all that neat, would be to edit an external CSV hosts file. Then...

$config->httpHosts = explode(',', file_get_contents("hosts.txt"));

...would read it in the config. You'd have to build your own way of updating that file which in my case wouldn't be a problem because I'm building a kind of second custom CMS for my site's users.

Still don't know how I'm going about this. I don't want to skip on good practices.

Posted

I think you can leave it blank and it will work, but it is not as safe security wise.

What you describe is what I talked about above.  ProcessWireConfig Allows you to do that.

This feels like a bad idea, but I can't figure out why. Fiddling around I found that...

$config->httpHosts = '*';

...works. It allows my addon domains through. Is this a bad idea? Why?

Another way around it, although not all that neat, would be to edit an external CSV hosts file. Then...

$config->httpHosts = explode(',', file_get_contents("hosts.txt"));

...would read it in the config. You'd have to build your own way of updating that file which in my case wouldn't be a problem because I'm building a kind of second custom CMS for my site's users.

Still don't know how I'm going about this. I don't want to skip on good practices.

  • 6 months later...
Posted

I tried to use this in a new project and ProcessWireConfig is no longer there.  It says:

Error reported by web service: Unable to find that module

Is this still a good way to do things?   

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...