GM-Alex / user-access-manager

Official mirror of https://plugins.svn.wordpress.org/user-access-manager/
39 stars 18 forks source link

File locking does not work when locked directory type Wordpress is selected #286

Open bunglegrind opened 5 years ago

bunglegrind commented 5 years ago

On a clean install, WP 5.2, with UAM latest stable, if I lock files with locked directory type option Wordpress selected, the locking does not work. Specifically, the rule created by UAM:

RewriteCond %{REQUEST_URI} ^.*\[0-9]{4}\[0-9]{2}.*$

in .htaccess does not match the uri. (example: http://wp.localhost/wp-content/uploads/2019/05/doe.pdf

Complete .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_URI} !.*\/sites\/[0-9]+\/.* RewriteCond %{REQUEST_URI} ^.*\[0-9]{4}\[0-9]{2}.*$ RewriteRule ^([^?]*)$ /index.php?uamfiletype=attachment&uamgetfile=$1 [QSA,L] RewriteRule ^(.*)\?(((?!uamfiletype).)*)$ /index.php?uamfiletype=attachment&uamgetfile=$1&$2 [QSA,L] RewriteRule ^(.*)\?(.*)$ /index.php?uamgetfile=$1&$2 [QSA,L] </IfModule>

In Settings->media "Organize my uploads into month- and year-based folders" is checked.

The problem is, in addition to the wrong regexp expression, that the "wordpress" option only checks the uri against the regexp expression, instead of checking all the media database to verify if the requested file is matching one of the WP media.

I kindly suggest you to rephrase the sentence above accordingly

bunglegrind commented 5 years ago

So, the issue concerns the PHP constant DIRECTORY_SEPARATOR which you are using in the RewriteCond rule in the getDirectoryMatch() methods. You should use a forward slash since you're matching a uri not a file path.

GM-Alex commented 5 years ago

Could you make a PR for this? That would be really nice.

bunglegrind commented 5 years ago

fine, but I need a clarification:

RewriteCond %{REQUEST_URI} !.*\/sites\/[0-9]+\/.*

1) what is the purpose of the rule above? 2) why are you escaping the forward slashes?

Cheers.

bunglegrind commented 5 years ago

Created. But there may be similar issues...

bunglegrind commented 4 years ago

Yes there are...almost every time you create a path.

bunglegrind commented 4 years ago

http://cmljnelson.blog/2018/07/26/which-way-do-your-slashes-face/

Probably wp_normalize_path should fix the issue (at least for the paths, concerning the uris replacing DIRECTORY_SEPARATOR with '/' is the right fix)