Remove redundant tables and code
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes;
|
||||
|
||||
/**
|
||||
* Class FileReceive
|
||||
* @package App\Classes
|
||||
*
|
||||
* This class represents a file being received.
|
||||
*/
|
||||
class FileReceive {
|
||||
public int $soff = 0;
|
||||
public int $toff = 0;
|
||||
public int $foff = 0;
|
||||
public int $ttot = 0;
|
||||
public int $stot = 0;
|
||||
public int $nf = 0;
|
||||
public int $allf = 0;
|
||||
public int $start = 0;
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes;
|
||||
|
||||
/**
|
||||
* Class FileSend
|
||||
* @package App\Classes
|
||||
*
|
||||
* This class represents a file being sent.
|
||||
*/
|
||||
class FileSend {
|
||||
public int $soff = 0;
|
||||
public int $stot = 0;
|
||||
public int $toff = 0;
|
||||
public int $foff = 0;
|
||||
public int $ttot = 0;
|
||||
public int $nf = 0;
|
||||
public int $allf = 0;
|
||||
public int $cps = 1;
|
||||
public int $start = 0;
|
||||
}
|
@@ -5,7 +5,8 @@ namespace App\Classes\Protocol;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Flysystem\UnreadableFileException;
|
||||
|
||||
use App\Classes\{FileReceive,Protocol,Protocol\Zmodem as ZmodemClass};
|
||||
use App\Classes\Protocol;
|
||||
use App\Classes\Protocol\Zmodem as ZmodemClass;
|
||||
use App\Classes\File\{Receive,Send};
|
||||
use App\Classes\Sock\{SocketClient,SocketException};
|
||||
use App\Interfaces\CRC as CRCInterface;
|
||||
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Classes\FTNPacket;
|
||||
|
||||
class FtnPkt extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ftn:pkt {file : Fidonet Packet File PKT} {--dump : Dump packet} {--detail : Dump Detail}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import Packet into Database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$pkt = new FTNPacket($this->argument('file'));
|
||||
|
||||
$this->info(sprintf('Packet: %s has %s messages. Addr: %s->%s (Date: %s)',
|
||||
$pkt->filename,
|
||||
$pkt->messages->count(),
|
||||
$pkt->pktsrc,
|
||||
$pkt->pktdst,
|
||||
$pkt->date
|
||||
));
|
||||
|
||||
foreach ($pkt->messages as $o)
|
||||
{
|
||||
$this->warn(sprintf('-- From: %s(%s)->%s(%s), Type: %s, Size: %d',
|
||||
$o->from,
|
||||
$o->fqfa,
|
||||
$o->to,
|
||||
$o->fqda,
|
||||
$o->type,
|
||||
strlen($o->message)
|
||||
));
|
||||
|
||||
if ($o->unknown->count())
|
||||
$this->error(sprintf('?? %s Unknown headers',$o->unknown->count()));
|
||||
}
|
||||
|
||||
if ($this->option('detail'))
|
||||
dd($o);
|
||||
|
||||
if ($this->option('dump'))
|
||||
echo $pkt->dump();
|
||||
}
|
||||
}
|
@@ -1,157 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Traits\ParseNodes;
|
||||
use App\Classes\FTNPacket;
|
||||
use App\Models\{Echomail,Netmail,Zone};
|
||||
|
||||
class ImportPacket extends Command
|
||||
{
|
||||
use ParseNodes;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'import:pkt {file : Packet File} {--f|force : Force import of duplicates}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import Mail Packet';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$pkt = new FTNPacket($this->argument('file'));
|
||||
|
||||
foreach ($pkt->messages as $o)
|
||||
{
|
||||
$o->date->setTimezone(($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
|
||||
|
||||
switch ($o->type)
|
||||
{
|
||||
case 'echomail':
|
||||
// See if we already have this message.
|
||||
$oo = Echomail::firstOrNew([
|
||||
'date'=>$o->date,
|
||||
'from_ftn'=>$this->get_node(['z'=>$o->fz,'n'=>$o->fn,'f'=>$o->ff,'p'=>$o->fp])->id,
|
||||
'msgid'=>$o->msgid,
|
||||
]);
|
||||
|
||||
if (md5(utf8_decode($eo->message)) == md5($o->message))
|
||||
{
|
||||
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
|
||||
break 2;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'netmail':
|
||||
// See if we already have this message.
|
||||
$oo = Netmail::firstOrNew([
|
||||
'date'=>$o->date,
|
||||
'from_ftn'=>$this->get_node(['z'=>$o->fz,'n'=>$o->fn,'f'=>$o->ff,'p'=>$o->fp])->id,
|
||||
'msgid'=>$o->msgid,
|
||||
]);
|
||||
|
||||
$oo->to_ftn = $this->get_node(['z'=>$o->tz,'n'=>$o->tn,'f'=>$o->tf,'p'=>$o->tp])->id;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
abort(500,'Unknown type: '.$o->type);
|
||||
}
|
||||
|
||||
if (md5(utf8_decode($oo->message)) == md5($o->message))
|
||||
{
|
||||
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
|
||||
if (! $this->option('force'))
|
||||
continue;
|
||||
}
|
||||
|
||||
$oo->pkt_from = $this->get_node(['z'=>$pkt->sz,'n'=>$pkt->sn,'f'=>$pkt->sf,'p'=>$pkt->sp])->id;
|
||||
$oo->pkt_to = $this->get_node(['z'=>$pkt->dz,'n'=>$pkt->dn,'f'=>$pkt->df,'p'=>$pkt->dp])->id;
|
||||
$oo->pkt = $pkt->filename;
|
||||
$oo->pkt_date = $pkt->date;
|
||||
$oo->flags = $o->flags;
|
||||
$oo->cost = $o->cost;
|
||||
$oo->from_user = utf8_encode($o->from);
|
||||
$oo->to_user = utf8_encode($o->to);
|
||||
$oo->subject = utf8_encode($o->subject);
|
||||
$oo->tz = $o->tzutc;
|
||||
$oo->replyid = $o->replyid;
|
||||
$oo->message = utf8_encode($o->message);
|
||||
$oo->origin = utf8_encode($o->origin);
|
||||
$oo->save();
|
||||
|
||||
foreach ($o->kludge as $k=>$v)
|
||||
{
|
||||
$oo->kludges()->attach($k,['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
foreach ($o->unknown as $v)
|
||||
{
|
||||
$oo->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
// Finish off the import
|
||||
switch($o->type) {
|
||||
case 'echomail':
|
||||
foreach ($o->seenby as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$oo->seenbys()->attach($no->id);
|
||||
}
|
||||
}
|
||||
|
||||
$seq = 0;
|
||||
foreach ($o->path as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$oo->paths()->attach($no->id,['sequence'=>$seq++]);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'netmail':
|
||||
$seq = 0;
|
||||
|
||||
foreach ($o->via as $v)
|
||||
{
|
||||
$data = preg_split('/\s/',$v);
|
||||
$ftno = $this->get_node(ftn_address_split($data[0]));
|
||||
unset($data[0]);
|
||||
|
||||
$oo->paths()->attach($ftno->id,['sequence'=>$seq++,'value'=>json_encode($data)]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\Node;
|
||||
|
||||
class NodeController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or edit a node
|
||||
*/
|
||||
public function add_edit(Request $request,Node $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
foreach ([
|
||||
'zone_id','host_id','node_id','point_id',
|
||||
'system','sysop','location','email',
|
||||
'address','port','notes','software_id','protocol_id',
|
||||
'sespass','pktpass','ticpass','fixpass'
|
||||
] as $key)
|
||||
$o->{$key} = $request->post($key);
|
||||
|
||||
foreach(['is_zc','is_rc','is_hub','is_host','active'] as $key)
|
||||
$o->{$key} = $request->post($key,FALSE);
|
||||
|
||||
$o->save();
|
||||
|
||||
return redirect()->action([self::class,'home']);
|
||||
}
|
||||
|
||||
return view('node.addedit')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return view('node.home');
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Flag extends Model
|
||||
{
|
||||
protected $fillable = ['flag'];
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kludge extends Model
|
||||
{
|
||||
//
|
||||
}
|
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Node extends Model
|
||||
{
|
||||
use ScopeActive;
|
||||
|
||||
protected $casts = [
|
||||
'is_zc'=>'boolean',
|
||||
'is_rc'=>'boolean',
|
||||
'is_hub'=>'boolean',
|
||||
'is_host'=>'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = ['zone_id','host_id','node_id','point_id'];
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
public function scopeHost()
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
* Node nodelist flags
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function flags()
|
||||
{
|
||||
return $this->belongsToMany(Flag::class);
|
||||
}
|
||||
|
||||
public function zone()
|
||||
{
|
||||
return $this->belongsTo(Zone::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* Render the node name in full 5D
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFTNAttribute()
|
||||
{
|
||||
return $this->zone_id
|
||||
? sprintf('%d:%d/%d.%d@%s',$this->zone->zone_id,$this->host_id,$this->node_id,$this->point_id,$this->zone->domain->name)
|
||||
: '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this nodes uplink
|
||||
*/
|
||||
public function getUplinkAttribute()
|
||||
{
|
||||
// @todo Need to work this out properly
|
||||
return static::where('zone_id','10')->where('host_id',1)->where('node_id',0)->where('point_id',0)->first();
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Find a record in the DB for a node string, eg: 10:1/1.0
|
||||
*
|
||||
* @param string $ftn
|
||||
* @return Node|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function findFTN(string $ftn): ?self
|
||||
{
|
||||
$matches = [];
|
||||
|
||||
// @todo domain can have more chars.
|
||||
if (! preg_match('#^([0-9]+):([0-9]+)/([0-9]+)(.([0-9]+))?(@([a-z]{0,8}))?$#',strtolower($ftn),$matches))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
|
||||
// Check our numbers are correct.
|
||||
foreach ([1,2,3] as $i) {
|
||||
if (! $matches[$i] || ($matches[$i] > 0xffff))
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
}
|
||||
if (isset($matches[5]) AND $matches[5] > 0xffff)
|
||||
throw new Exception('Invalid FTN: '.$ftn);
|
||||
|
||||
return (new self)->active()
|
||||
->select('nodes.*')
|
||||
->where('zones.zone_id',$matches[1])
|
||||
->where(function($query) use ($matches) {
|
||||
$query->where('hub_id',$matches[2])
|
||||
->orWhere('host_id',$matches[2]);
|
||||
})
|
||||
->join('zones',['zones.id'=>'nodes.zone_id'])
|
||||
->join('domains',['domains.id'=>'zones.domain_id'])
|
||||
->where('zones.active',TRUE)
|
||||
->where('node_id',$matches[3])
|
||||
->where('point_id',(isset($matches[5]) AND $matches[5]) ? $matches[5] : 0)
|
||||
->when(isset($matches[7]),function($query) use ($matches) {
|
||||
$query->where('domains.name',$matches[7]);
|
||||
})
|
||||
->when((! isset($matches[7]) OR ! $matches[7]),function($query) {
|
||||
$query->where('domains.default',TRUE);
|
||||
})
|
||||
->single();
|
||||
}
|
||||
|
||||
public function hasFlag($relation,$model): bool
|
||||
{
|
||||
return (bool) $this->{$relation}()
|
||||
->wherePivot($model->getForeignKey(),$model->{$model->getKeyName()})
|
||||
->count();
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Path extends Model
|
||||
{
|
||||
//
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Seenby extends Model
|
||||
{
|
||||
//
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Zone;
|
||||
|
||||
trait ParseNodes
|
||||
{
|
||||
/**
|
||||
* Parse a seenby or path list and return node models
|
||||
*/
|
||||
protected function parse_nodes(Zone $zo,string $line,$create=TRUE)
|
||||
{
|
||||
$net = FALSE;
|
||||
$result = collect();
|
||||
|
||||
foreach (explode(' ',$line) as $node)
|
||||
{
|
||||
if (preg_match('#/#',$node))
|
||||
{
|
||||
list($net,$node) = preg_split('#/#',$node);
|
||||
}
|
||||
|
||||
if (! $net)
|
||||
throw new \Exception('Missing Net?',$node);
|
||||
|
||||
$result->push($this->get_node(['z'=>$zo->id,'n'=>$net,'f'=>$node,'p'=>0],$create));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user