Auto create nodes that are discovered by message packets
This commit is contained in:
@@ -10,7 +10,8 @@ use Illuminate\Support\Facades\Redis;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
use App\Classes\FTN as FTNBase;
|
||||
use App\Models\{Address,Setup,Software,Zone};
|
||||
use App\Http\Controllers\DomainController;
|
||||
use App\Models\{Address,Setup,Software,System,Zone};
|
||||
|
||||
class Packet extends FTNBase implements \Iterator, \Countable
|
||||
{
|
||||
@@ -415,31 +416,63 @@ class Packet extends FTNBase implements \Iterator, \Countable
|
||||
* Parse a message in a mail packet
|
||||
*
|
||||
* @param string $message
|
||||
* @throws InvalidPacketException
|
||||
* @throws InvalidPacketException|\Exception
|
||||
*/
|
||||
private function parseMessage(string $message): void
|
||||
{
|
||||
$msg = Message::parseMessage($message,$this->zone);
|
||||
|
||||
// If the message is invalid, we'll ignore it
|
||||
if ($msg->errors && (
|
||||
$msg->errors->messages()->has('from')
|
||||
|| $msg->errors->messages()->has('user_from')
|
||||
|| $msg->errors->messages()->has('user_to')
|
||||
))
|
||||
{
|
||||
$this->errors->push($msg);
|
||||
Log::error(sprintf('%s:! Skipping message [%s] due to errors (%s)...',self::LOGKEY,$msg->msgid,join(',',$msg->errors->messages()->keys())));
|
||||
if ($msg->errors) {
|
||||
// If the from address doenst exist, we'll create a new entry
|
||||
if ($msg->errors->messages()->has('from')) {
|
||||
Log::alert(sprintf('%s: - From FTN is not defined, creating new entry for [%s]',self::LOGKEY,$msg->fboss));
|
||||
|
||||
Address::unguard();
|
||||
$ao = Address::firstOrNew([
|
||||
'zone_id' => $msg->fzone->id,
|
||||
'region_id' => 0,
|
||||
'host_id' => $msg->fn,
|
||||
'node_id' => $msg->ff,
|
||||
'point_id' => $msg->fp,
|
||||
]);
|
||||
Address::reguard();
|
||||
|
||||
$ao->active = TRUE;
|
||||
$ao->role = DomainController::NODE_UNKNOWN;
|
||||
|
||||
// This shouldnt happen
|
||||
if ($ao->exists) {
|
||||
Log::error(sprintf('%s: - Attempting to create address [%s], but it exists?',self::LOGKEY,$msg->fboss));
|
||||
$this->errors->push($msg);
|
||||
return;
|
||||
}
|
||||
|
||||
System::unguard();
|
||||
$so = System::firstOrCreate([
|
||||
'name' => 'Discovered System',
|
||||
'sysop' => 'Unknown',
|
||||
'location' => '',
|
||||
'active' => TRUE,
|
||||
]);
|
||||
System::reguard();
|
||||
|
||||
$so->addresses()->save($ao);
|
||||
|
||||
} elseif($msg->errors->messages()->has('user_from') || $msg->errors->messages()->has('user_to')) {
|
||||
Log::error(sprintf('%s:! Skipping message [%s] due to errors (%s)...',self::LOGKEY,$msg->msgid,join(',',$msg->errors->messages()->keys())));
|
||||
$this->errors->push($msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->use_redis) {
|
||||
$key = $msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp);
|
||||
Redis::set($key,serialize($msg));
|
||||
$this->messages->push($key);
|
||||
|
||||
} else {
|
||||
if ($this->use_redis) {
|
||||
$key = $msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp);
|
||||
Redis::set($key,serialize($msg));
|
||||
$this->messages->push($key);
|
||||
|
||||
} else {
|
||||
$this->messages->push($msg);
|
||||
}
|
||||
$this->messages->push($msg);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user