【发布时间】:2021-01-05 18:17:01
【问题描述】:
我正在设置一个内部服务器,该服务器将允许使用 HTTP 将匿名文件上传到特定目录。请注意,我试图避免实现基于 Python、PHP 等的东西,以使此设置尽可能简单,因为我可能不会成为将来最终支持该系统的人。
我有一个使用 Apache2 的 WebDAV 模块的基本设置,但我还想阻止覆盖当前存在的任何文件。 WebDAV 是否对此有扩展?
这是我当前的配置脚本:
### Base HTML Directory
DIR_BASE=/var/www/html
mkdir -p $DIR_BASE
# Ownership
find $DIR_BASE -type f -exec chown root:apache {} \;
find $DIR_BASE -type d -exec chown root:apache {} \;
# Permission
find $DIR_BASE -type f -exec chmod 0644 {} \;
find $DIR_BASE -type d -exec chmod 0755 {} \;
# SELinux - Allow Apache to serve contents
chcon -t httpd_sys_content_t $DIR_BASE -Rv
### Upload HTML Directory
DIR_UPLOAD=/var/www/html/uploads
mkdir -p $DIR_UPLOAD
# Ownership
find $DIR_UPLOAD -type f -exec chown root:apache {} \;
find $DIR_UPLOAD -type d -exec chown root:apache {} \;
# Permission
find $DIR_UPLOAD -type f -exec chmod 0644 {} \;
find $DIR_UPLOAD -type d -exec chmod 0775 {} \;
# SELinux - Allow Apache to write to directory
chcon -u system_u -t httpd_sys_rw_content_t $DIR_UPLOAD -Rv
### Web Service
# Upload Section
# <Directory "/var/www/html/uploads">
# Options None # Don't allow any secondary features, such as listing the files
# AllowOverride None # Don't allow overrides from other configuration files
# Allow from all # Anonymous Access
# Require all granted # Anonymous Access
# </Directory>
# <Location /uploads>
# Dav On # WebDAV for file upload functionality
# <LimitExcept PUT> # Limit to file upload only
# Order Allow,Deny # Anonymous Access
# Allow from all # Anonymous Access
# </LimitExcept>
# </Location>
cat > /etc/httpd/conf.d/uploads.conf << _EOF
Alias /uploads "/var/www/html/uploads"
<Directory "/var/www/html/uploads">
Options None
AllowOverride None
Allow from all
Require all granted
</Directory>
<Location /uploads>
Dav On
<LimitExcept PUT>
Order Allow,Deny
Allow from all
</LimitExcept>
</Location>
_EOF
restorecon -vF /etc/httpd/conf.d/uploads.conf
systemctl enable httpd
systemctl restart httpd
### Firewall
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
【问题讨论】:
-
使用SVN WebDav模块怎么样?它不一定会阻止覆盖,但会自动对所有上传进行版本控制,以便可以撤消任何覆盖。
-
这是一个可能的解决方案,但需要上传者也使用颠覆客户端。理想情况下,上传就像 curl 命令(或等效命令)一样简单。感谢您的建议。
-
我已经有一段时间没有进行测试了,但是可以通过某种方式安装一个 SVN/WebDav 页面,即在 Windows 资源管理器中,然后只需拖放数据。