Fix last packet transfers shown, added file transfers

This commit is contained in:
Deon George 2023-07-19 15:16:25 +10:00
parent f4fc6c24a4
commit 39605af693
8 changed files with 249 additions and 37 deletions

View File

@ -11,7 +11,8 @@ use Illuminate\Support\Facades\Gate;
use App\Classes\File;
use App\Classes\FTN\Packet;
use App\Http\Requests\SetupRequest;
use App\Models\{Address,Domain,Echomail,Netmail,Setup};
use App\Models\File as FileModel;
use App\Models\{Address,Domain,Echomail,Netmail,Setup,System};
class HomeController extends Controller
{
@ -20,6 +21,27 @@ class HomeController extends Controller
return redirect(Auth::check() ? 'dashboard' : 'about');
}
public function file_contents(System $o,string $date)
{
$f = FileModel::select('files.*')
->distinct()
->leftJoin('file_seenby',['file_seenby.file_id'=>'files.id'])
->where(function($query) use ($o,$date) {
return $query
->where('created_at',$date)
->whereIn('fftn_id',$o->addresses->pluck('id'));
})
->Orwhere(function($query) use ($o,$date) {
return $query
->where('sent_at',$date)
->whereIn('address_id',$o->addresses->pluck('id'));
})
->get();
return view('file')
->with('f',$f);
}
public function network(Domain $o)
{
if (! $o->public && ! Gate::check('admin',$o))
@ -31,12 +53,12 @@ class HomeController extends Controller
->with('o',$o);
}
public function packet_contents(string $packet)
public function packet_contents(System $o,string $packet)
{
$nm = Netmail::select('netmails.*')
->distinct()
->leftJoin('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
->where(function($query) use ($packet) {
->where(function($query) use ($o,$packet) {
return $query
->where('sent_pkt',$packet)
->orWhere('netmail_path.recv_pkt',$packet);
@ -47,11 +69,17 @@ class HomeController extends Controller
->distinct()
->leftJoin('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
->leftJoin('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
->where(function($query) use ($packet) {
->where(function($query) use ($o,$packet) {
return $query
->where('sent_pkt',$packet)
->orWhere('recv_pkt',$packet);
->whereIn('echomail_seenby.address_id',$o->addresses->pluck('id'));
})
->orWhere(function($query) use ($o,$packet) {
return $query
->where('recv_pkt',$packet)
->whereIn('echomail_path.address_id',$o->addresses->pluck('id'));
})
->with('echoarea')
->get();
return view('packet')

View File

@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('netmails',function (Blueprint $table) {
$table->dropColumn(['recv_pkt']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
abort(500,'Cant go back');
}
};

View File

@ -0,0 +1,24 @@
@if($f->count())
<table class="table monotable">
<thead>
<tr>
<th colspan="3">Files</th>
</tr>
<tr>
<th>Origin</th>
<th>Name</th>
<th>Date</th>
</tr>
</thead>
<tbody>
@foreach ($f as $oo)
<tr>
<td>{{ $oo->fftn->ftn }}</td>
<td>{{ $oo->name }}</td>
<td>{{ $oo->datetime }}</td>
</tr>
@endforeach
</tbody>
</table>
@endif

View File

@ -34,6 +34,7 @@
<tr>
<th>From</th>
<th>MSGID</th>
<th>Echoarea</th>
<th>Date</th>
</tr>
</thead>
@ -43,6 +44,7 @@
<tr>
<td>{{ $oo->fftn->ftn }}</td>
<td>{{ $oo->msgid }}</td>
<td>{{ $oo->echoarea->name }}</td>
<td>{{ $oo->datetime }}</td>
</tr>
@endforeach

View File

@ -417,8 +417,10 @@
<div class="col-4">
The last Netmails sent (to you):
@if(($x=\App\Models\Netmail::whereIn('sent_id',$o->addresses->pluck('id'))
@if(($x=\App\Models\Netmail::select(['sent_pkt','sent_at',DB::raw('count(*) AS count')])
->whereIn('sent_id',$o->addresses->pluck('id'))
->whereNotNull('sent_at')
->groupBy(['sent_pkt','sent_at'])
->orderBy('sent_at','DESC')
->limit(10)
->get())->count())
@ -427,17 +429,17 @@
<thead>
<tr>
<th>Packet</th>
<th>Count</th>
<th>Sent</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x->groupBy('sent_pkt') as $oo)
@foreach ($x as $oo)
<tr>
<td class="packet">{{ $oo->first()->sent_pkt }}</td>
<td>{{ $oo->count() }}</td>
<td>{{ $oo->first()->sent_at }}</td>
<td class="packet">{{ $oo->sent_pkt }}</td>
<td>{{ $oo->sent_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
@ -450,29 +452,62 @@
<div class="col-4">
The last Echomails sent (to you):
@if(($x=\App\Models\Echomail::select(['echomails.id','echomail_seenby.sent_pkt','echomail_seenby.sent_at'])
@if(($x=\App\Models\Echomail::select(['sent_pkt','sent_at',DB::raw('count(*) AS count')])
->join('echomail_seenby',['echomail_seenby.echomail_id'=>'echomails.id'])
->whereNotNull('echomail_seenby.sent_at')
->whereNotNull('sent_at')
->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['sent_pkt','sent_at'])
->orderBy('sent_at','DESC')
->orderBy('sent_pkt')
->limit(10)
->get())->count())
<table class="table monotable">
<thead>
<tr>
<th>Packet</th>
<th>Count</th>
<th>Sent</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x->groupBy('sent_pkt') as $oo)
@foreach ($x as $oo)
<tr>
<td class="packet">{{ $oo->first()->sent_pkt }}</td>
<td>{{ $oo->count() }}</td>
<td>{{ $oo->first()->sent_at }}</td>
<td class="packet">{{ $oo->sent_pkt }}</td>
<td>{{ $oo->sent_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
</table>
@else
<strong class="highlight">None</strong>
@endif
</div>
<div class="col-4">
The last Files sent (to you):
@if(($x=\App\Models\File::select(['sent_at',DB::raw('count(*) AS count')])
->join('file_seenby',['file_seenby.file_id'=>'files.id'])
->whereNotNull('sent_at')
->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['sent_at'])
->orderBy('sent_at','DESC')
->limit(10)
->get())->count())
<table class="table monotable">
<thead>
<tr>
<th>Session</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x as $oo)
<tr>
<td class="files">{{ $oo->sent_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
@ -487,9 +522,10 @@
<div class="col-4">
The last Netmails received (you sent):
@if(($x=\App\Models\Netmail::select(['netmails.*','netmail_path.recv_pkt'])
@if(($x=\App\Models\Netmail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')])
->join('netmail_path',['netmail_path.netmail_id'=>'netmails.id'])
->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['recv_pkt','created_at'])
->orderBy('created_at','DESC')
->limit(10)
->get())->count())
@ -497,17 +533,17 @@
<thead>
<tr>
<th>Packet</th>
<th>Count</th>
<th>Received</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x->groupBy('recv_pkt') as $oo)
@foreach ($x as $oo)
<tr>
<td class="packet">{{ $oo->first()->recv_pkt }}</td>
<td>{{ $oo->count() }}</td>
<td>{{ $oo->first()->created_at }}</td>
<td class="packet">{{ $oo->recv_pkt }}</td>
<td>{{ $oo->created_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
@ -520,29 +556,60 @@
<div class="col-4">
The last Echomails received (you sent):
@if(($x=\App\Models\Echomail::select(['echomails.created_at','echomail_path.recv_pkt'])
@if(($x=\App\Models\Echomail::select(['recv_pkt','created_at',DB::raw('count(*) AS count')])
->join('echomail_path',['echomail_path.echomail_id'=>'echomails.id'])
->whereNotNull('echomail_path.recv_pkt')
->whereNotNull('recv_pkt')
->whereIn('address_id',$o->addresses->pluck('id'))
->groupBy(['recv_pkt','created_at'])
->orderBy('created_at','DESC')
->orderBy('recv_pkt')
->limit(10)
->get())->count())
<table class="table monotable">
<thead>
<tr>
<th>Packet</th>
<th>Count</th>
<th>Received</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x->groupBy('recv_pkt') as $oo)
@foreach ($x as $oo)
<tr>
<td class="packet">{{ $oo->first()->recv_pkt }}</td>
<td>{{ $oo->count() }}</td>
<td>{{ $oo->first()->created_at }}</td>
<td class="packet">{{ $oo->recv_pkt }}</td>
<td>{{ $oo->created_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
</table>
@else
<strong class="highlight">None</strong>
@endif
</div>
<div class="col-4">
The last Files received (from you):
@if(($x=\App\Models\File::select(['created_at',DB::raw('count(*) AS count')])
->whereIn('fftn_id',$o->addresses->pluck('id'))
->groupBy(['created_at'])
->orderBy('created_at','DESC')
->limit(10)
->get())->count())
<table class="table monotable">
<thead>
<tr>
<th>Session</th>
<th class="text-end">Count</th>
</tr>
</thead>
<tbody>
@foreach ($x as $oo)
<tr>
<td class="files">{{ $oo->created_at }}</td>
<td class="text-end">{{ $oo->count }}</td>
</tr>
@endforeach
</tbody>
@ -562,6 +629,7 @@
</div>
@include('widgets.modal_packet')
@include('widgets.modal_files')
@include('widgets.modal_purge')
@endsection

View File

@ -0,0 +1,58 @@
<!-- $o=System::class -->
<div class="modal fade" id="file-contents" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content bg-dark">
<div class="modal-header bg-success">
<h5 class="modal-title text-light">Summary File Contents for <span id="file"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<i id="spinner" class="spinner-grow spinner-grow-sm d-none"></i>
<div id="modal-content"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@section('page-scripts')
<script>
var file = new bootstrap.Modal(document.getElementById('file-contents'), {});
$(document).ready(function() {
$('.files').click(function(e) {
var item = this;
var icon = $('#spinner');
$('span#file').html(e.target.innerText);
file.show();
$.ajax({
type: 'POST',
data: {date: e.target.innerText.replace(/\s/,'@'),_token: '{{csrf_token()}}'},
beforeSend: function() {
icon.toggleClass('d-none');
$('#file-contents').find('div#modal-content').empty();
},
success: function(data) {
icon.toggleClass('d-none');
$('#file-contents').find('div#modal-content').html(data);
},
error: function(e) {
icon.toggleClass('d-none');
alert('That didnt work? Please try again....');
},
url: '{{ url('file/contents',['o'=>$o->id]) }}/'+e.target.innerText.replace(/\s/,'@'),
cache: false
})
return false;
});
});
</script>
@append

View File

@ -1,3 +1,4 @@
<!-- $o=System::class -->
<div class="modal fade" id="packet-contents" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content bg-dark">
@ -34,18 +35,19 @@
data: {packet: e.target.innerText,_token: '{{csrf_token()}}'},
beforeSend: function() {
icon.toggleClass('d-none');
$('#packet-contents').find('div#modal-content').empty();
},
success: function(data) {
icon.toggleClass('d-none');
$('div#modal-content').html(data);
$('#packet-contents').find('div#modal-content').html(data);
},
error: function(e) {
icon.toggleClass('d-none');
alert('That didnt work? Please try again....');
},
url: '{{ url('packet/contents') }}/'+e.target.innerText,
url: '{{ url('packet/contents',['o'=>$o->id]) }}/'+e.target.innerText,
cache: false
})

View File

@ -91,6 +91,9 @@ Route::middleware(['auth','verified','activeuser'])->group(function () {
Route::match(['get','post'],'ftn/system/movaddress/{so}/{o}',[SystemController::class,'mov_address'])
->where('so','[0-9]+')
->where('o','[0-9]+');
Route::post('file/contents/{o}/{date}',[HomeController::class,'file_contents'])
->where('o','[0-9]+')
->where('date','[0-9:\-@]+');
Route::get('ftn/system/recaddress/{id}',[SystemController::class,'rec_address'])
->where('o','[0-9]+');
Route::get('ftn/system/puraddress/{id}',[SystemController::class,'pur_address'])
@ -106,8 +109,9 @@ Route::middleware(['auth','verified','activeuser'])->group(function () {
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs'])
->where('o','[0-9]+');
Route::match(['get','post'],'link',[UserController::class,'link']);
Route::post('packet/contents/{o}',[HomeController::class,'packet_contents'])
->where('o','[0-9a-f]+');
Route::post('packet/contents/{o}/{packet}',[HomeController::class,'packet_contents'])
->where('o','[0-9]+')
->where('packet','[0-9a-f]+');
Route::get('permissions',[HomeController::class,'permissions']);
Route::get('regions/{o}',[DomainController::class,'api_regions'])
->where('o','[0-9]+');