Initial echomail import
This commit is contained in:
32
app/Traits/GetNode.php
Normal file
32
app/Traits/GetNode.php
Normal 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
31
app/Traits/ParseNodes.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user