2021-05-03 12:53:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-06-24 10:16:37 +00:00
|
|
|
use Illuminate\Http\Request;
|
2021-06-26 14:34:15 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2021-06-17 14:08:30 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-08-19 13:35:48 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
2021-06-17 14:08:30 +00:00
|
|
|
|
2021-06-29 10:43:29 +00:00
|
|
|
use App\Classes\FTN\Packet;
|
2021-08-19 13:35:48 +00:00
|
|
|
use App\Models\{Address,Domain,Setup};
|
2021-06-14 11:33:18 +00:00
|
|
|
|
2021-05-03 12:53:40 +00:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2021-06-14 11:33:18 +00:00
|
|
|
public function network(Domain $o)
|
2021-05-03 12:53:40 +00:00
|
|
|
{
|
2021-08-19 13:35:48 +00:00
|
|
|
if (! $o->public && ! Gate::check('admin',$o))
|
|
|
|
abort(404);
|
|
|
|
|
2021-06-25 13:38:57 +00:00
|
|
|
$o->load(['zones.system','zones.domain']);
|
|
|
|
|
2021-06-14 11:33:18 +00:00
|
|
|
return view('domain.view')
|
|
|
|
->with('o',$o);
|
2021-05-03 12:53:40 +00:00
|
|
|
}
|
2021-06-15 12:19:14 +00:00
|
|
|
|
2021-06-17 14:08:30 +00:00
|
|
|
/**
|
|
|
|
* Render a view that summarises the users permissions
|
|
|
|
*/
|
|
|
|
public function permissions()
|
|
|
|
{
|
|
|
|
return view('auth.permissions')
|
|
|
|
->with('user',Auth::user());
|
|
|
|
}
|
|
|
|
|
2021-07-02 13:19:50 +00:00
|
|
|
/**
|
|
|
|
* Show a packet dump
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2021-06-29 10:43:29 +00:00
|
|
|
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) {
|
2021-06-29 13:42:35 +00:00
|
|
|
try {
|
2021-07-15 14:54:23 +00:00
|
|
|
$pkt = Packet::open($file);
|
2021-06-29 13:42:35 +00:00
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
2021-07-15 14:54:23 +00:00
|
|
|
return redirect()->back()->withErrors(sprintf('%s (%s:%d)',$e->getMessage(),$e->getFile(),$e->getLine()));
|
2021-06-29 13:42:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 10:43:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-08 02:01:10 +00:00
|
|
|
return view('pkt')
|
2021-06-29 10:43:29 +00:00
|
|
|
->with('file',$file)
|
2021-08-20 14:33:41 +00:00
|
|
|
->with('result',$pkt)
|
|
|
|
->with('hexdump',$file ? hex_dump(file_get_contents($file)) : '');
|
2021-06-29 10:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 13:19:50 +00:00
|
|
|
/**
|
|
|
|
* Process searching
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2021-06-26 14:34:15 +00:00
|
|
|
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
|
2021-07-02 13:19:50 +00:00
|
|
|
foreach (Address::select(['systems.name',DB::raw('systems.id AS system_id'),'zones.zone_id','region_id','host_id','node_id','point_id'])
|
2021-06-26 14:34:15 +00:00
|
|
|
->join('zones',['zones.id'=>'addresses.zone_id'])
|
2021-07-02 13:19:50 +00:00
|
|
|
->rightjoin('systems',['systems.id'=>'addresses.system_id'])
|
|
|
|
->when($zone_id || $host_id || $node_id,function($query) use ($zone_id,$host_id,$node_id) {
|
|
|
|
return $query
|
2021-07-17 07:15:00 +00:00
|
|
|
->when($zone_id,function($q,$zone_id) { return $q->where('zones.zone_id',$zone_id); })
|
2021-07-02 13:19:50 +00:00
|
|
|
->where(function($q) use ($host_id) {
|
|
|
|
return $q
|
2021-07-17 07:15:00 +00:00
|
|
|
->when($host_id,function($q,$host_id) { return $q->where('region_id',$host_id); })
|
|
|
|
->when($host_id,function($q,$host_id) { return $q->orWhere('host_id',$host_id); });
|
2021-07-02 13:19:50 +00:00
|
|
|
})
|
|
|
|
->when($node_id,function($q,$node_id) { return $q->where('node_id','ilike','%'.$node_id.'%'); });
|
|
|
|
})
|
2021-06-26 14:34:15 +00:00
|
|
|
->orWhere('systems.name','ilike','%'.$request->query('term').'%')
|
|
|
|
->orWhere('systems.sysop','ilike','%'.$request->query('term').'%')
|
|
|
|
->OrderBy('systems.name')
|
|
|
|
->get() as $o)
|
|
|
|
{
|
2021-07-02 13:19:50 +00:00
|
|
|
$ftn = NULL;
|
|
|
|
|
|
|
|
if ($o->zone_id && ($o->region_id||$o->host_id) && is_numeric($o->node_id) && is_numeric($o->point_id))
|
|
|
|
$ftn = sprintf('%d:%d/%d.%d',$o->zone_id,$o->host_id ?: $o->region_id,$o->node_id,$o->point_id);
|
|
|
|
|
|
|
|
$result->push(['id'=>$o->system_id,'name'=>$o->name.($ftn ? ' '.$ftn : ''),'value'=>url('ftn/system/addedit',[$o->system_id]),'category'=>'Systems']);
|
2021-06-26 14:34:15 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 13:19:50 +00:00
|
|
|
return $result->unique(['id'])->take(10)->values();
|
2021-06-26 14:34:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:19:14 +00:00
|
|
|
/**
|
|
|
|
* System Setup
|
|
|
|
*
|
|
|
|
* @note: Protected by Route
|
|
|
|
*/
|
2021-06-24 10:16:37 +00:00
|
|
|
public function setup(Request $request)
|
2021-06-15 12:19:14 +00:00
|
|
|
{
|
2021-06-24 10:16:37 +00:00
|
|
|
$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);
|
2021-06-15 12:19:14 +00:00
|
|
|
}
|
2021-05-03 12:53:40 +00:00
|
|
|
}
|