clrghouz/app/Http/Controllers/HomeController.php
2021-06-29 20:45:57 +10:00

120 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use App\Classes\FTN\Packet;
use App\Models\{Address,Domain,Setup};
class HomeController extends Controller
{
public function network(Domain $o)
{
$o->load(['zones.system','zones.domain']);
return view('domain.view')
->with('o',$o);
}
/**
* Render a view that summarises the users permissions
*/
public function permissions()
{
return view('auth.permissions')
->with('user',Auth::user());
}
public function pkt(Request $request)
{
$pkt = NULL;
$file = NULL;
if ($request->post()) {
$request->validate([
'file' => 'required|filled|min:1',
]);
foreach ($request->allFiles() as $key => $filegroup) {
if ($key !== 'file')
continue;
foreach ($filegroup as $file) {
$pkt = new Packet($file);
break;
}
}
}
return view('pkt.debug')
->with('file',$file)
->with('result',$pkt);
}
public function search(Request $request): Collection
{
$this->middleware('auth');
$result = collect();
list($zone_id,$host_id,$node_id,$point_id,$domain) = sscanf($request->query('term'),'%d:%d/%d.%d@%s');
# Look for Opportunities
foreach (Address::select(['domain_id','addresses.zone_id','host_id','node_id','point_id','addresses.system_id'])
->join('systems',['systems.id'=>'addresses.system_id'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->when($zone_id,function($q,$zone_id) { return $q->where('zones.zone_id','ilike','%'.$zone_id.'%'); })
->when($host_id,function($q,$host_id) { return $q->where('host_id','ilike','%'.$host_id.'%'); })
->when($node_id,function($q,$node_id) { return $q->where('node_id','ilike','%'.$node_id.'%'); })
->orWhere('systems.name','ilike','%'.$request->query('term').'%')
->orWhere('systems.sysop','ilike','%'.$request->query('term').'%')
->limit(10)
->OrderBy('systems.name')
->with(['system'])
->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->system->name,$o->ftn),'value'=>url('ftn/system/addedit',[$o->system_id]),'category'=>'Systems']);
}
return $result;
}
/**
* System Setup
*
* @note: Protected by Route
*/
public function setup(Request $request)
{
$o = Setup::findOrNew(config('app.id'));
if ($request->post()) {
$request->validate([
'system_id' => 'required|exists:systems,id',
'binkp' => 'nullable|array',
'binkp.*' => 'nullable|numeric',
'options' => 'nullable|array',
'options.*' => 'nullable|numeric',
]);
if (! $o->exists) {
$o->id = config('app.id');
$o->zmodem = 0;
$o->emsi_protocols = 0;
$o->protocols = 0;
$o->permissions = 0;
}
$o->binkp = collect($request->post('binkp'))->sum();
$o->options = collect($request->post('options'))->sum();
$o->system_id = $request->post('system_id');
$o->save();
}
return view('setup')
->with('o',$o);
}
}