Skip to content

Commit

Permalink
bug fix:加密文件夹、隐藏文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiCoco committed Dec 21, 2019
1 parent b3483f0 commit 6ce40c9
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ public function searchShow($id,$clientId = 1): RedirectResponse
*/
public function handleEncrypt()
{
$currentUrl = request()->get('currentUrl');
$password = request()->get('password');
$route = decrypt(request()->get('route'));
$requestPath = decrypt(request()->get('requestPath'));
Expand All @@ -497,15 +498,13 @@ public function handleEncrypt()
'expires' => time() + (int)$this->expires * 60, // 目录密码过期时间
];
Session::put($encryptKey, $data);

$encryptDir = Tool::handleEncryptItem(setting('encrypt_path'));
$encryptPath = Str::after($encryptKey, 'password:');
$directory_password = $encryptDir['p>' . $encryptPath];
if (strcmp($password, $directory_password) === 0) {
return redirect()->route($route, ['query' => Tool::encodeUrl($requestPath)]);
return redirect($currentUrl);
}
Tool::showMessage('密码错误', false);

return view(
config('olaindex.theme') . 'password',
compact('route', 'requestPath', 'encryptKey')
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Middleware/HandleHideDir.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace App\Http\Middleware;

use App\Utils\Tool;
Expand All @@ -26,9 +25,8 @@ public function handle($request, Closure $next)
if ($requestPath === '' || blank($hideDir)) {
return $next($request);
}
if (in_array($requestPath, $hideDir, false)) {
if (in_array($requestPath, $hideDir, false) && !auth()->check()) {
Tool::showMessage('非法请求', false);

return response()->view(config('olaindex.theme') . 'message');
}
return $next($request);
Expand Down
1 change: 1 addition & 0 deletions resources/views/default/password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<div class="card-body">
<form action="{{ route('password') }}" method="post">
@csrf
<input type="hidden" name="currentUrl" value="{{ request()->url() }}">
<div class="form-group">
<label class="form-control-label" for="password">请输入密码</label>
<input type="password" class="form-control" id="password" name="password" required>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/default/show/audio.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
audio: [{
name: '{{ $file['name'] }}',
artist: '{{ $file['name'] }}',
url: "{{ route('download',['clientId' => $clientId,'query' => \App\Utils\Tool::encodeUrl($originPath))] }}",
url: "{{ route('download',['clientId' => $clientId,'query' => \App\Utils\Tool::encodeUrl($originPath)]) }}",
cover: 'cover.jpg'
}]
});
Expand Down
1 change: 1 addition & 0 deletions resources/views/mdui/password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="mdui-col-md-6 mdui-col-offset-md-3 mdui-p-a-3">
<form action="{{ route('password') }}" method="post">
@csrf
<input type="hidden" name="clientId" value="{{ request()->route()->parameter('clientId') }}">
<div class="mdui-textfield mdui-textfield-floating-label">
<i class="mdui-icon material-icons">https</i>
<label class="mdui-textfield-label" for="password">此文件夹或文件受到保护,您需要提供访问密码才能查看</label>
Expand Down

0 comments on commit 6ce40c9

Please sign in to comment.