mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use \App\GoogleDriveFile;
|
|
use \App\Config;
|
|
|
|
class CheckFilePerm
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next,$type,$permission = 'r')
|
|
{
|
|
if (GoogleDriveFile::checkConfig() && Config::getData('is_Google_Drive_enabled') == 'true')
|
|
{
|
|
if ($type == 'file')
|
|
{
|
|
$dir = GoogleDriveFile::find($request->d);
|
|
if ($dir != null)
|
|
{
|
|
if (\Auth::check())
|
|
{
|
|
if ($dir->canUser(\Auth::user(),$permission) == false)
|
|
{
|
|
clog('navigate','danger','Vous n\'avez pas la permission d\'accéder a ce fichier',\Auth::user()->id);
|
|
return redirect('/admin')->with('error','Vous n\'avez pas la permission d\'accéder a ce fichier');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (strpos($dir->getPermission('rank.0'),$permission) === false)
|
|
{
|
|
clog('navigate','danger','Un utilisateur non authentifié a tenter de télécharger un fichier privé','0');
|
|
abort(401,'Vous n\'avez pas la permission d\'accéder a ce fichier');
|
|
}
|
|
}
|
|
return $next($request);
|
|
}
|
|
if (\Auth::check())
|
|
{
|
|
if (\Auth::user()->permission('config_edit'))
|
|
{
|
|
return $next($request);
|
|
}
|
|
}
|
|
abort(401,'Vous n\'avez pas la permission d\'accéder a ce fichier');
|
|
}
|
|
abort(500);
|
|
}
|
|
else
|
|
{
|
|
clog('navigate','danger','Google Drive n\'est pas activé ou les identifiants sont incorrect',\Auth::user()->id);
|
|
return redirect('/admin')->with('error','Google Drive n\'est pas activé ou les identifiants sont incorrect');
|
|
}
|
|
}
|
|
}
|