[SOLVED] WonderCMS on Nginx without editing nginx.conf

Post Reply
User avatar
Donjuan
Posts: 3
Joined: Sat Jan 05, 2019 1:23 pm

[SOLVED] WonderCMS on Nginx without editing nginx.conf

Post by Donjuan »

Unfortunately i don't have access to the nginx.conf file on the hosting service i choose.
The contents with the menus working if i edit the database.js. I just added "?page=" to every page. I know it's not an elegant solution, but the website is private and i don't need any SEO optimization.
My problem is i can't login to the CMS.
Is there a way to integrate the following code (for nginx.conf) in a functions.php? Or is there any other solution to make it work with my limitations?

Code: Select all

location ~ database.js {
	return 403;
}

autoindex off;

location / {
	if (!-e $request_filename) {
		rewrite ^/(.+)$ /index.php?page=$1 last;
	}
}
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: WonderCMS on Nginx without editing nginx.conf

Post by wiz »

Have you tried using example.com?page=loginURL (replace with your domain and your actual login URL, "loginURL" is the default login URL)
If that works, you can hardcode your login URL anywhere you want. Let me know if this works.
Is there a way to integrate the following code (for nginx.conf) in a functions.php? Or is there any other solution to make it work with my limitations?
I'm no expert by any means, but I don't it's possible to block direct access to the database.js with just PHP, as that should be probably solved on the server level (Apache, NGINX or IIS). You don't have to worry about this if your website is local and not actually public.

How did you add the "?page=" to all pages?
If you did this by editing index.php, you should note that WonderCMS overwrites the index.php with each update. This can be probably done better by creating a new menu function added to the functions.php file, and calling your new function in theme.php (instead of calling the menu function from index.php). Let me know if you need any help with this, I could give it a go. Edit: gave it a go, check my next post.
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: WonderCMS on Nginx without editing nginx.conf

Post by wiz »

Here's a way to create a functions.php file. It will display your the menu pages with "?page=".
This is a simple solution so you don't have to edit your index.php, thus preserving update functionality for future WonderCMS updates.

Step 1: Create/edit functions.php file in your theme folder. Copy/paste the below content into the functions.php file.

Code: Select all

<?php
	function newMenu() {
		$output = '';
		foreach (wCMS::get('config', 'menuItems') as $key => $value) {
			if ($value->visibility == "hide") {
				continue;
			}
			$output .= '<li' . (wCMS::$currentPage === $value->slug ? ' class="active"' : '') . '><a href="?page=' . $value->slug . '">' . $value->name . '</a></li>';
		}
		return $output;
	}
?>
Step 2: Save the above file.

Step 3: In your theme.php, replace with wCMS::menu() with newMenu() and save.
Your website menu should now work without clean URLs.


Possible issues we should discuss:
1. The login URL - let me know if the solution in my first post is ok.
2. Is it important to you to have the logout link on the top right of your site? This can be also probably fixed by a custom function in your functions.php.
User avatar
Donjuan
Posts: 3
Joined: Sat Jan 05, 2019 1:23 pm

Re: WonderCMS on Nginx without editing nginx.conf

Post by Donjuan »

Thank you for your quick respond.
Well first i integrated the ?page= directly in the database.js file.

Code: Select all

"slug": "?page=contactsite",
Your solution with the functions.php is elegant and works fine without editing the database.js file. Thank you for that.

I can open the example.com/?page=loginURL without any problems. I can put my password but after i click on the login button i get redirected to example.com/loginURL with the 404 error.
Do you have probably an idea to fix it with another functions.php entry?
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: WonderCMS on Nginx without editing nginx.conf

Post by wiz »

Just noticed what the issue on the login form is: the login URL without ?page is used, and it goes to an error page (since you don't have the clean URLs).

Here's a workaround (not with functions.php though)
1. On your current login page, right click login field and click inspect element.
2. Check my attached screenshot below. You will see a highlighted "form action" with your login URL. (example URL from screenshot: https://www.wondercms.com/demo/loginURL)
Instructions for step 2:<br />Right click on the field and click inspect (Firefox, Chrome), edit your highlighted login URL by adding the ?page parameter as explained in step 3
Instructions for step 2:
Right click on the field and click inspect (Firefox, Chrome), edit your highlighted login URL by adding the ?page parameter as explained in step 3
1-screenshot-inspect-element-and-edit-action-url.png (76.48 KiB) Viewed 15413 times
3. Change it to https://www.wondercms.com/demo/?page=loginURL (replace with your own domain add the ?page= parameter)
4. You can close the browser inspector and then enter your password and login successfully.
5. While being logged in, create a new page (example: mySecretLoginURL), which will be used as your new login URL.
6. Paste the below code on your mySecretLoginURL page. Replace the URL in the code below with same URL as step 3 above.

Code: Select all

<form action="https://www.wondercms.com/demo/?page=loginURL" method="post"><div class="input-group"><input type="password" class="form-control" id="password" name="password"><span class="input-group-btn"><button type="submit" class="btn btn-info">Login</button></span></div></form>
7. Make sure you hide this page from the menu (Settings-General) (note: it does not hide it from search engines like the original login URL does)
8. You can log out and visit the ?page=mySecretLoginURL to test out how your new/second login page works.


Edit: fixed typo in form action URL.
User avatar
Donjuan
Posts: 3
Joined: Sat Jan 05, 2019 1:23 pm

Re: WonderCMS on Nginx without editing nginx.conf

Post by Donjuan »

Perfect. It works pretty well. The problem is completely solved. Thank you very much for your great support!

The code in the database.js file looks like that:

Code: Select all

        "mysecretloginurl": {
            "title": "mySecretLoginURL",
            "keywords": "",
            "description": "",
            "content": "<form action=\"?page=mySecretLoginURL\" method=\"post\"><div class=\"input-group\"><input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\"><span class=\"input-group-btn\"><button type=\"submit\" class=\"btn btn-info\">Login<\/button><\/span><\/div><\/form>"
        }
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: WonderCMS on Nginx without editing nginx.conf

Post by wiz »

You're welcome and glad it works.

Marking thread as solved, drop by if you need any help.

Cheers and to a successful 2019!
Post Reply