Initial echomail import

This commit is contained in:
Deon George
2019-04-27 23:57:39 +10:00
parent 6515c91270
commit 9ba790e72c
14 changed files with 387 additions and 20 deletions

32
app/Traits/GetNode.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Traits;
use App\Models\{Node,Zone};
trait GetNode
{
/**
* Get an FTN record
* If the record doesnt exist, we'll create it
*/
protected function get_node($z,$n,$f,$p=0,$create=TRUE)
{
$zo = Zone::firstOrCreate(['id'=>$z]);
$no = Node::firstOrNew(['zone_id'=>$zo->id,'host_id'=>$n,'node_id'=>$f,'point_id'=>$p]);
if (! $no->exists AND $create)
{
$no->active = FALSE;
$no->system = 'AUTO DISCOVERED';
$no->sysop = 'UNKNOWN';
$no->location = '';
$no->baud = 0;
$no->save();
}
return ($no->exists) ? $no : NULL;
}
}

31
app/Traits/ParseNodes.php Normal file
View File

@@ -0,0 +1,31 @@
<?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 $zone,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($zone->id,$net,$node,0),$create);
}
return $result;
}
}