joer80 Posted July 30, 2015 Share Posted July 30, 2015 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! Link to comment Share on other sites More sharing options...
bernhard Posted July 30, 2015 Share Posted July 30, 2015 i think you could make your config file get the content of the multisite hosts field 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 31, 2015 Share Posted July 31, 2015 please share your solution and experience with us when you are done Link to comment Share on other sites More sharing options...
Soma Posted July 31, 2015 Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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! Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 31, 2015 Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 So are you saying I can use the api to add entries, but I cant pull them from the database? Link to comment Share on other sites More sharing options...
Soma Posted July 31, 2015 Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 31, 2015 Share Posted July 31, 2015 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. 2 Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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. 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 31, 2015 Share Posted July 31, 2015 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? Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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? Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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? Link to comment Share on other sites More sharing options...
Soma Posted July 31, 2015 Share Posted July 31, 2015 How about multisite reading config. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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... Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
Soma Posted July 31, 2015 Share Posted July 31, 2015 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. 2 Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 That is helpful. So the backend code is there but there is no UI in cms to use it yet? (Edit config module) Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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? Link to comment Share on other sites More sharing options...
heldercervantes Posted July 31, 2015 Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted July 31, 2015 Author Share Posted July 31, 2015 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. Link to comment Share on other sites More sharing options...
joer80 Posted February 10, 2016 Author Share Posted February 10, 2016 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? Link to comment Share on other sites More sharing options...
adrian Posted February 10, 2016 Share Posted February 10, 2016 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? I don't think it was ever in the modules directory, was it? You can get it from here: https://github.com/ryancramerdesign/ProcessWireConfig Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now