Added echoareas and fileareas
This commit is contained in:
@@ -12,6 +12,7 @@ use Illuminate\Validation\Validator as ValidatorResult;
|
||||
use App\Classes\FTN as FTNBase;
|
||||
use App\Models\{Address,Domain};
|
||||
use App\Rules\TwoByteInteger;
|
||||
use App\Traits\EncodeUTF8;
|
||||
|
||||
/**
|
||||
* Class Message
|
||||
@@ -21,6 +22,8 @@ use App\Rules\TwoByteInteger;
|
||||
*/
|
||||
class Message extends FTNBase
|
||||
{
|
||||
use EncodeUTF8;
|
||||
|
||||
private const cast_utf8 = [
|
||||
'message',
|
||||
'message_src',
|
||||
@@ -342,43 +345,7 @@ class Message extends FTNBase
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
$properties = (new \ReflectionClass($this))->getProperties();
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
// Dont serialize the validation error
|
||||
if ($property->name == 'errors')
|
||||
continue;
|
||||
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
if (! $property->isInitialized($this)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $property->getName();
|
||||
$encode = in_array($name,self::cast_utf8);
|
||||
|
||||
if ($property->isPrivate()) {
|
||||
$name = "\0{$class}\0{$name}";
|
||||
} elseif ($property->isProtected()) {
|
||||
$name = "\0*\0{$name}";
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
$value = $property->getValue($this);
|
||||
|
||||
$values[$name] = $encode ? utf8_encode($value) : $value;
|
||||
}
|
||||
|
||||
return $values;
|
||||
return $this->encode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
49
app/Http/Controllers/EchoareaController.php
Normal file
49
app/Http/Controllers/EchoareaController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\Echoarea;
|
||||
|
||||
class EchoareaController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or edit a echoarea
|
||||
*/
|
||||
public function add_edit(Request $request,Echoarea $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$this->authorize('admin',$o);
|
||||
|
||||
$request->validate([
|
||||
// http://ftsc.org/docs/old/fsp-1028.002
|
||||
'domain_id' => 'required|exists:domains,id',
|
||||
'name' => 'required|max:35|regex:/^[a-zA-Z-_~]{1,8}$/|unique:echoareas,name,'.($o->exists ? $o->id : 0),
|
||||
'description' => 'required',
|
||||
'active' => 'required|boolean',
|
||||
'public' => 'required|boolean',
|
||||
]);
|
||||
|
||||
foreach (['name','description','active','public','notes','domain_id'] as $key)
|
||||
$o->{$key} = $request->post($key);
|
||||
|
||||
$o->save();
|
||||
|
||||
return redirect()->action([self::class,'home']);
|
||||
}
|
||||
|
||||
return view('echoarea.addedit')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return view('echoarea.home');
|
||||
}
|
||||
}
|
48
app/Http/Controllers/FileareaController.php
Normal file
48
app/Http/Controllers/FileareaController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Filearea;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FileareaController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or edit a echoarea
|
||||
*/
|
||||
public function add_edit(Request $request,Filearea $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$this->authorize('admin',$o);
|
||||
|
||||
$request->validate([
|
||||
// http://ftsc.org/docs/old/fsp-1028.002
|
||||
'domain_id' => 'required|exists:domains,id',
|
||||
'name' => 'required|max:35|regex:/^[a-zA-Z-_~]{1,8}$/|unique:echoareas,name,'.($o->exists ? $o->id : 0),
|
||||
'description' => 'required',
|
||||
'active' => 'required|boolean',
|
||||
'public' => 'required|boolean',
|
||||
]);
|
||||
|
||||
foreach (['name','description','active','public','notes','domain_id'] as $key)
|
||||
$o->{$key} = $request->post($key);
|
||||
|
||||
$o->save();
|
||||
|
||||
return redirect()->action([self::class,'home']);
|
||||
}
|
||||
|
||||
return view('filearea.addedit')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return view('filearea.home');
|
||||
}
|
||||
}
|
@@ -10,7 +10,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\{Message,Process};
|
||||
use App\Models\{Echomail,Netmail,Setup};
|
||||
use App\Models\{Echoarea,Echomail,Netmail,Setup};
|
||||
|
||||
class ProcessPacket implements ShouldQueue
|
||||
{
|
||||
@@ -141,7 +141,10 @@ class ProcessPacket implements ShouldQueue
|
||||
$this->msg->user_from,
|
||||
));
|
||||
|
||||
// @todo Determine if we know about this echo area
|
||||
$ea = Echoarea::where('name',$this->msg->echoarea)
|
||||
->where('domain_id',$this->msg->fftn_o->zone->domain_id)
|
||||
->single();
|
||||
|
||||
// @todo Can the sender create it if it doesnt exist?
|
||||
// - Create it, or
|
||||
// - Else record in bad area
|
||||
@@ -155,7 +158,7 @@ class ProcessPacket implements ShouldQueue
|
||||
$o->tzoffset = $this->msg->date->utcOffset();
|
||||
|
||||
$o->fftn_id = ($x=$this->msg->fftn_o) ? $x->id : NULL;
|
||||
$o->echoarea = $this->msg->echoarea;
|
||||
$o->echoarea_id = $ea?->id;
|
||||
$o->msgid = $this->msg->msgid;
|
||||
|
||||
$o->msg = $this->msg->message_src;
|
||||
|
@@ -23,6 +23,16 @@ class Domain extends Model
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function echoareas()
|
||||
{
|
||||
return $this->hasMany(Echoarea::class);
|
||||
}
|
||||
|
||||
public function fileareas()
|
||||
{
|
||||
return $this->hasMany(Filearea::class);
|
||||
}
|
||||
|
||||
public function zones()
|
||||
{
|
||||
return $this->hasMany(Zone::class);
|
||||
|
31
app/Models/Echoarea.php
Normal file
31
app/Models/Echoarea.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Echoarea extends Model
|
||||
{
|
||||
use SoftDeletes,ScopeActive;
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function addresses()
|
||||
{
|
||||
return $this->belongsToMany(Address::class);
|
||||
}
|
||||
|
||||
public function domain()
|
||||
{
|
||||
return $this->belongsTo(Domain::class);
|
||||
}
|
||||
|
||||
public function echomail()
|
||||
{
|
||||
return Echomail::select('*')
|
||||
->where('echoarea_id',$this->id);
|
||||
}
|
||||
}
|
@@ -2,17 +2,22 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Exceptions\Exception;
|
||||
use Jenssegers\Mongodb\Eloquent\Model;
|
||||
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Interfaces\Packet;
|
||||
use App\Traits\{MsgID,UseMongo};
|
||||
use App\Traits\{EncodeUTF8,MsgID,UseMongo};
|
||||
|
||||
class Echomail extends Model implements Packet
|
||||
{
|
||||
use SoftDeletes,MsgID,UseMongo;
|
||||
use SoftDeletes,MsgID,UseMongo,EncodeUTF8;
|
||||
|
||||
protected $collection = FALSE;
|
||||
|
||||
private const cast_utf8 = [
|
||||
'msg'
|
||||
];
|
||||
|
||||
protected $dates = ['datetime'];
|
||||
|
||||
@@ -28,6 +33,11 @@ class Echomail extends Model implements Packet
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->encode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this model as a packet
|
||||
*/
|
||||
|
25
app/Models/Filearea.php
Normal file
25
app/Models/Filearea.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Filearea extends Model
|
||||
{
|
||||
use SoftDeletes,ScopeActive;
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function addresses()
|
||||
{
|
||||
return $this->belongsToMany(Address::class);
|
||||
}
|
||||
|
||||
public function domain()
|
||||
{
|
||||
return $this->belongsTo(Domain::class);
|
||||
}
|
||||
}
|
@@ -90,7 +90,6 @@ class Netmail extends Model implements Packet
|
||||
|
||||
$o->via = $via;
|
||||
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
50
app/Traits/EncodeUTF8.php
Normal file
50
app/Traits/EncodeUTF8.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Encode our data so that it can be serialised
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
trait EncodeUTF8
|
||||
{
|
||||
private function encode(): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
$properties = (new \ReflectionClass($this))->getProperties();
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
// Dont serialize the validation error
|
||||
if ($property->name == 'errors')
|
||||
continue;
|
||||
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
if (! $property->isInitialized($this)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $property->getName();
|
||||
$encode = in_array($name,self::cast_utf8);
|
||||
|
||||
if ($property->isPrivate()) {
|
||||
$name = "\0{$class}\0{$name}";
|
||||
} elseif ($property->isProtected()) {
|
||||
$name = "\0*\0{$name}";
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
$value = $property->getValue($this);
|
||||
|
||||
$values[$name] = $encode ? utf8_encode($value) : $value;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user