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;
|
2020-08-20 12:33:13 +00:00
|
|
|
|
2020-09-18 14:08:00 +00:00
|
|
|
use App\Ldap\Entry;
|
2020-08-23 02:30:18 +00:00
|
|
|
use App\Classes\LDAP\Server;
|
2020-09-21 12:20:59 +00:00
|
|
|
use LdapRecord\Models\ModelNotFoundException;
|
2020-08-22 12:26:06 +00:00
|
|
|
|
2020-08-20 12:33:13 +00:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2021-12-08 12:26:12 +00:00
|
|
|
/**
|
|
|
|
* Application home page
|
|
|
|
*/
|
2020-09-18 14:08:00 +00:00
|
|
|
public function home()
|
|
|
|
{
|
2020-09-23 12:14:38 +00:00
|
|
|
$base = (new Entry)->baseDN() ?: 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'))
|
2020-09-21 12:20:59 +00:00
|
|
|
->with('bases',$base->transform(function($item) {
|
2020-09-13 11:30:04 +00:00
|
|
|
return [
|
2020-09-23 12:14:38 +00:00
|
|
|
'title'=>$item->getRdn(),
|
|
|
|
'item'=>Crypt::encryptString($item->getDn()),
|
2020-09-13 11:30:04 +00:00
|
|
|
'lazy'=>TRUE,
|
|
|
|
'icon'=>'fa-fw fas fa-sitemap',
|
2021-12-08 12:26:12 +00:00
|
|
|
'tooltip'=>$item->getDn(),
|
2020-09-13 11:30:04 +00:00
|
|
|
];
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-12-08 12:26:12 +00:00
|
|
|
/**
|
|
|
|
* LDAP Server INFO
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
*/
|
2020-09-18 14:08:00 +00:00
|
|
|
public function info()
|
|
|
|
{
|
2021-03-02 11:19:00 +00:00
|
|
|
$root = (new Entry)->rootDSE();
|
|
|
|
|
2020-09-21 12:20:59 +00:00
|
|
|
try {
|
2021-03-02 11:19:00 +00:00
|
|
|
$attrs = collect($root->getAttributes())
|
2021-12-08 12:26:12 +00:00
|
|
|
->transform(function($item) {
|
2020-09-21 12:20:59 +00:00
|
|
|
foreach ($item as $k=>$v) {
|
|
|
|
if (preg_match('/[0-9]+\.[0-9]+\.[0-9]+/',$v)) {
|
|
|
|
$format = sprintf(
|
|
|
|
'<abbr class="pb-1" title="%s"><i class="fas fa-list-ol pr-2"></i>%s</abbr>%s<p class="mb-0">%s</p>',
|
|
|
|
$v,
|
|
|
|
Server::getOID($v,'title'),
|
|
|
|
($x=Server::getOID($v,'ref')) ? sprintf('<abbr class="pl-2" title="%s"><i class="fas fa-comment-dots"></i></abbr>',$x) : '',
|
|
|
|
Server::getOID($v,'desc'),
|
2020-09-18 14:08:00 +00:00
|
|
|
);
|
2020-09-21 12:20:59 +00:00
|
|
|
$item[$k] = $format;
|
|
|
|
}
|
2020-09-18 14:08:00 +00:00
|
|
|
}
|
2020-09-21 12:20:59 +00:00
|
|
|
return $item;
|
|
|
|
});
|
|
|
|
|
|
|
|
// @todo If we cant get server info, we should probably show a nice error dialog
|
|
|
|
} catch (ModelNotFoundException $e) {
|
|
|
|
$attrs = collect();
|
|
|
|
}
|
2020-09-18 14:08:00 +00:00
|
|
|
|
2021-12-03 02:36:25 +00:00
|
|
|
return view('frames.dn')
|
2021-12-08 12:26:12 +00:00
|
|
|
->with('o',$root)
|
|
|
|
->with('dn',__('Server Info'));
|
2020-09-18 14:08:00 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 12:26:12 +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'));
|
|
|
|
|
2021-12-03 02:36:25 +00:00
|
|
|
return view('frames.dn')
|
2021-12-08 12:26:12 +00:00
|
|
|
->with('o',(new Server)->fetch($dn))
|
|
|
|
->with('dn',$dn);
|
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
|
|
|
}
|