Compare commits

...

3 Commits

Author SHA1 Message Date
28b48e5bef Set default example mail server to smtp
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 34s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m47s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
2024-10-26 13:12:31 +11:00
d2d1094c1a Update HAPROXY process to understand v1 2024-10-26 13:12:31 +11:00
271bf937cf Add configuration items to determine DNS records returned and sort order 2024-10-26 13:12:31 +11:00
3 changed files with 141 additions and 68 deletions

View File

@ -31,7 +31,7 @@ REDIS_PASSWORD=
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mail.dege.lan
MAIL_HOST=smtp
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
@ -47,8 +47,9 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
FIDO_DIR=fido
FIDO_PACKET_KEEP=
FIDO_PACKET_KEEP=false
FIDO_STRICT=false
FIDO_HAPROXY=false
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=
@ -58,6 +59,12 @@ AWS_ENDPOINT=
AWS_DEFAULT_REGION=home
AWS_USE_PATH_STYLE_ENDPOINT=true
MATRIX_SERVER=
MATRIX_AS_TOKEN=
MATRIX_HS_TOKEN=
#MATRIX_SERVER=
#MATRIX_AS_TOKEN=
#MATRIX_HS_TOKEN=
#FIDO_DNS_NS=
#FIDO_DNS_AAAA=
#FIDO_DNS_ORDER_AAAA=
#FIDO_DNS_A=
#FIDO_DNS_ORDER_A=

View File

@ -59,9 +59,55 @@ final class SocketClient {
if ((! $originate) && config('fido.haproxy')) {
Log::debug(sprintf('%s:+ HAPROXY connection host [%s] on port [%d] (%s)',self::LOGKEY,$this->address_remote,$this->port_remote,$this->type));
if ($this->read(5,12) !== "\x0d\x0a\x0d\x0a\x00\x0d\x0aQUIT\x0a")
if (($x=$this->read(5,6)) === 'PROXY ')
$vers = 1;
elseif (($x === "\x0d\x0a\x0d\x0a\x00\x0d") && ($this->read('5,6') === "\x0aQUIT\x0a"))
$vers = 2;
else
throw new HAproxyException('Failed to initialise HAPROXY connection');
switch ($vers) {
case 1:
// Protocol/Address Family
switch ($x=$this->read(5,5)) {
case 'TCP4 ':
$p = 4;
break;
case 'TCP6 ':
$p = 6;
break;
default:
throw new HAproxyException(sprintf('HAPROXY protocol [%d] is not handled',$x));
}
$read = $this->read(5,104-11);
// IPv4
if (($p === 4) || ($p === 6)) {
$parse = collect(sscanf($read,'%s %s %s %s'));
$src = Arr::get($parse,0);
$dst = Arr::get($parse,1);
$src_port = (int)Arr::get($parse,2);
$dst_port = (int)Arr::get($parse,3);
$len = $parse->map(fn($item)=>strlen($item))->sum()+3;
// The last 2 chars should be "\r\n"
if (($x=substr($read,$len)) !== "\r\n")
throw new HAproxyException(sprintf('HAPROXY parsing failed for version [%d] [%s] (%s)',$p,$read,hex_dump($x)));
} else {
throw new HAproxyException(sprintf('HAPROXY version [%d] is not handled [%s]',$p,$read));
}
$this->port_remote = $src_port;
break;
case 2:
// Version/Command
$vc = $this->read_ch(5);
@ -83,7 +129,6 @@ final class SocketClient {
// Protocol/Address Family
$pa = $this->read_ch(5);
$p = NULL;
switch ($x=($pa>>4)&0x7) {
case 1: // AF_INET
@ -94,8 +139,7 @@ final class SocketClient {
$p = 6;
break;
default:
throw new HAproxyException(sprintf('HAPROXY protocol [%d] is not handled',$x));
}
switch ($x=($pa&0x7)) {
@ -122,17 +166,24 @@ final class SocketClient {
}
$src_port = unpack('n',$this->read(5,2));
$dst_port = unpack('n',$this->read(5,2));
$dst_port = Arr::get(unpack('n',$this->read(5,2)),1);
$this->port_remote = Arr::get($src_port,1);
break;
default:
throw new HAproxyException('Failed to initialise HAPROXY connection');
}
$this->address_remote = $src;
$this->port_remote = Arr::get($src_port,1);
Log::debug(sprintf('%s:- HAPROXY src [%s:%d] dst [%s:%d]',
self::LOGKEY,
$this->address_remote,
$this->port_remote,
$dst,
Arr::get($dst_port,1),
$dst_port,
));
}
@ -190,7 +241,8 @@ final class SocketClient {
{
Log::info(sprintf('%s:+ Creating connection to [%s:%d]',self::LOGKEY,$address,$port));
$sort = collect(['AAAA','A']);
$type = collect(config('fido.ip'))
->filter(fn($item)=>$item['enabled']);
if (filter_var($address,FILTER_VALIDATE_IP))
$resolved = collect([[
@ -199,9 +251,9 @@ final class SocketClient {
]]);
else
// We only look at AAAA/A records
$resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A))
->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; })
->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); });
$resolved = collect(dns_get_record($address,$type->map(fn($item)=>$item['type'])->sum()))
->filter(fn($item)=>$type->has(Arr::get($item,'type')))
->sort(fn($a,$b)=>$type->get(Arr::get($a,'type'))['order'] < $type->get(Arr::get($b,'type'))['order']);
if (! $resolved->count())
throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address));

View File

@ -43,4 +43,18 @@ return [
'down' => 35,
'delist' => 45,
],
// IP Address Resolution preferences
'ip' => [
'AAAA' => [
'enabled' => env('FIDO_DNS_AAAA',TRUE),
'order' => env('FIDO_DNS_ORDER_AAAA',2),
'type' => DNS_AAAA,
],
'A' => [
'enabled' => env('FIDO_DNS_A',TRUE),
'order' => env('FIDO_DNS_ORDER__ORDER',1),
'type' => DNS_A,
],
],
];