|
|
|
@ -81,6 +81,26 @@ Class DirScanner {
@@ -81,6 +81,26 @@ Class DirScanner {
|
|
|
|
|
return !empty($realpath) ? md5($realpath) : ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//判断Nginx防盗链MD5加密方式字符串是否合格 |
|
|
|
|
private function isNginxSecureLinkMd5PatternValid($pattern) { |
|
|
|
|
$valid = true; |
|
|
|
|
|
|
|
|
|
$fieldsNeeded = [ |
|
|
|
|
'{secure_link_expires}', |
|
|
|
|
'{uri}', |
|
|
|
|
'{remote_addr}', |
|
|
|
|
'{secret}', |
|
|
|
|
]; |
|
|
|
|
foreach($fieldsNeeded as $needle) { |
|
|
|
|
if (strstr($pattern, $needle) === false) { |
|
|
|
|
$valid = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $valid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据文件生成防盗链网址 |
|
|
|
|
//参考:https://nginx.org/en/docs/http/ngx_http_secure_link_module.html#secure_link |
|
|
|
@ -159,6 +179,9 @@ Class DirScanner {
@@ -159,6 +179,9 @@ Class DirScanner {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($pattern) && is_string($pattern)) { |
|
|
|
|
if ($this->isNginxSecureLinkMd5PatternValid($pattern) == false) { |
|
|
|
|
throw new Exception("Invalid Nginx secure link md5 pattern: {$pattern}", 500); |
|
|
|
|
} |
|
|
|
|
$this->nginxSecureLinkMd5Pattern = $pattern; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -204,6 +227,9 @@ Class DirScanner {
@@ -204,6 +227,9 @@ Class DirScanner {
|
|
|
|
|
*/ |
|
|
|
|
public function setNginxSecureLinkMd5Pattern($pattern) { |
|
|
|
|
if (!empty($pattern) && is_string($pattern)) { |
|
|
|
|
if ($this->isNginxSecureLinkMd5PatternValid($pattern) == false) { |
|
|
|
|
throw new Exception("Invalid Nginx secure link md5 pattern: {$pattern}", 500); |
|
|
|
|
} |
|
|
|
|
$this->nginxSecureLinkMd5Pattern = $pattern; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|