phpldapadmin/app/Http/Controllers/HomeController.php

137 lines
3.0 KiB
PHP
Raw Normal View History

2020-08-20 12:33:13 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
2020-09-15 12:40:32 +00:00
use Illuminate\Support\Arr;
2020-09-18 14:08:00 +00:00
use Illuminate\Support\Collection;
2020-09-15 12:40:32 +00:00
use Illuminate\Support\Facades\Auth;
2020-09-13 11:30:04 +00:00
use Illuminate\Support\Facades\Crypt;
2020-09-18 14:08:00 +00:00
use Illuminate\Support\Facades\File;
2023-02-14 10:38:42 +00:00
use LdapRecord\Query\ObjectNotFoundException;
2020-08-20 12:33:13 +00:00
2020-08-23 02:30:18 +00:00
use App\Classes\LDAP\Server;
use App\Exceptions\InvalidUsage;
2020-08-22 12:26:06 +00:00
2020-08-20 12:33:13 +00:00
class HomeController extends Controller
{
2023-01-27 08:59:31 +00:00
/**
* Debug Page
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function debug()
{
return view('debug');
}
/**
* Application home page
*/
2020-09-18 14:08:00 +00:00
public function home()
{
$base = Server::baseDNs() ?: collect();
2020-08-22 12:26:06 +00:00
return view('home')
2020-09-13 11:30:04 +00:00
->with('server',config('ldap.connections.default.name'))
->with('bases',$base->transform(function($item) {
2020-09-13 11:30:04 +00:00
return [
'title'=>$item->getRdn(),
'item'=>Crypt::encryptString($item->getDn()),
2020-09-13 11:30:04 +00:00
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
2020-09-13 11:30:04 +00:00
];
}));
}
/**
* LDAP Server INFO
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
2023-02-14 10:38:42 +00:00
* @throws ObjectNotFoundException
*/
2020-09-18 14:08:00 +00:00
public function info()
{
// Load our attributes
$s = new Server;
$s->schema('objectclasses');
$s->schema('attributetypes');
2020-09-18 14:08:00 +00:00
return view('frames.info')
->with('s',$s);
2020-09-18 14:08:00 +00:00
}
/**
* Render a specific DN
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function dn_frame(Request $request)
2020-09-18 14:08:00 +00:00
{
2020-09-13 11:30:04 +00:00
$dn = Crypt::decryptString($request->post('key'));
return view('frames.dn')
->with('o',(new Server)->fetch($dn))
->with('dn',$dn);
2020-09-18 14:08:00 +00:00
}
/**
* Show the Schema Viewer
*
* @note Our route will validate that types are valid.
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
* @throws InvalidUsage
*/
public function schema_frame(Request $request)
2023-02-14 10:38:42 +00:00
{
$s = new Server;
// If an invalid key, we'll 404
if ($request->type && $request->key && ($s->schema($request->type)->has($request->key) === FALSE))
abort(404);
return view('frames.schema')
->with('type',$request->type)
->with('key',$request->key);
2023-02-14 10:38:42 +00:00
}
2020-09-18 14:08:00 +00:00
/**
* Sort the attributes
*
* @param Collection $attrs
* @return Collection
*/
private function sortAttrs(Collection $attrs): Collection
{
return $attrs->sortKeys();
2020-08-22 12:26:06 +00:00
}
2020-09-15 12:40:32 +00:00
/**
* Return the image for the logged in user or anonymous
*
* @param Request $request
* @return mixed
*/
public function user_image(Request $request)
{
$image = NULL;
$content = NULL;
if (Auth::check()) {
$image = Arr::get(Auth::user()->getAttribute('jpegphoto'),0);
$content = 'image/jpeg';
}
if (! $image) {
$image = File::get('../resources/images/user-secret-solid.svg');
$content = 'image/svg+xml';
}
return response($image)
->header('Content-Type',$content);
}
2020-08-20 12:33:13 +00:00
}