environment-variables - Apache check if user is browsing their home directory
问题描述
I for example I've got webserver's root directory /var/www/. And user's home directory: /var/www/testuser/. I also have basic authorization setted up, so there is a user with username testuser which successfully authorized. How can I check if the testuser is browsing their home directory by the means of webserver alone? This is how far I've got:
# Getting "testuser" out of "/testuser/echo.php"
SetEnvIf Request_URI ^/(.*)/ URI_HOME=$1
# Getting base64 encoded part out of Authorization header
SetEnvIf Authorization "^Basic (.*)$" X_HTTP_AUTHORIZATION=$1
# Converting base64 part to plain text, extracting username and comparing it with home directory
SetEnvIfExpr "tolower(unbase64(%{ENV:X_HTTP_AUTHORIZATION})) == %{ENV:URI_HOME}" USER_IS_IN_HOME_DIR
The major problem is that Apache doesn't have REMOTE_USER setted up on the stage when SetEnvIf is working. So I absolutely have to parse Authorization header from request. I almost done it, but I have to cut out part after column to make comparison proper.
How can I do it?
解决方案
以下似乎工作:
SetEnvIf Request_URI ^/(.*)/ URI_HOME=$1
SetEnvIf Authorization "^Basic (.*)$" X_HTTP_AUTHORIZATION=$1
SetEnvIfExpr "unbase64(%{ENV:X_HTTP_AUTHORIZATION}) -strcmatch '%{ENV:URI_HOME}:*'" USER_IS_IN_HOME_DIR
任何想法如何改进它?
推荐阅读
- windows-10 - DigitalPersona U.are.U 4500 指纹读取器 SDK 不适用于 Windows 10
- php - 如何从我的 ArrayCollection 中获取数据?
- r - 根据数据子集的汇总统计重新排序因子
- javascript - Coinbase pro web socket 获取货币的当前价格
- asp.net-mvc - asp.net mvc中的外键问题?
- awk - 如何正确使用 awk 命令
- kubernetes - GKE 中的 VPC 原生集群无法在 GKE 1.14 中通信
- django - 如何从一个 Django 实例运行多个站点?
- c# - 为什么我的角色不能总是运行他的移动动画?
- javascript - 将 d3 js 更新到新版本不起作用