Skip to content

Commit

Permalink
RESOLVED #JJ306: Upgrade to webtrees 2.1.12 - Merge (Git 40eaba6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon48 committed Dec 11, 2022
2 parents cd33595 + 40eaba6 commit 2848ef2
Show file tree
Hide file tree
Showing 74 changed files with 586 additions and 234 deletions.
1 change: 0 additions & 1 deletion app/Contracts/FilesystemFactoryInterface.php
Expand Up @@ -19,7 +19,6 @@

namespace Fisharebest\Webtrees\Contracts;

use Fisharebest\Webtrees\Tree;
use League\Flysystem\FilesystemOperator;

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Contracts/IdFactoryInterface.php
Expand Up @@ -32,6 +32,8 @@ public function uuid(): string;
/**
* An identifier for use in CSS/HTML
*
* @param string $prefix
*
* @return string
*/
public function id(string $prefix = 'id-'): string;
Expand Down
1 change: 0 additions & 1 deletion app/CustomTags/Gedcom7.php
Expand Up @@ -21,7 +21,6 @@

use Fisharebest\Webtrees\Contracts\CustomTagInterface;
use Fisharebest\Webtrees\Contracts\ElementInterface;
use Fisharebest\Webtrees\Elements\CountOfChildren;
use Fisharebest\Webtrees\Elements\Creation;
use Fisharebest\Webtrees\Elements\CustomElement;
use Fisharebest\Webtrees\Elements\DateValueExact;
Expand Down
1 change: 0 additions & 1 deletion app/Elements/AbstractElement.php
Expand Up @@ -30,7 +30,6 @@
use function e;
use function is_numeric;
use function nl2br;
use function preg_replace;
use function str_contains;
use function str_starts_with;
use function strip_tags;
Expand Down
2 changes: 0 additions & 2 deletions app/Elements/CountOfChildrenFam.php
Expand Up @@ -19,8 +19,6 @@

namespace Fisharebest\Webtrees\Elements;

use Fisharebest\Webtrees\Tree;

/**
* COUNT_OF_CHILDREN := {Size=1:3}
* The known number of children of this individual from all marriages or, if
Expand Down
1 change: 0 additions & 1 deletion app/Elements/NamePersonal.php
Expand Up @@ -25,7 +25,6 @@

use function e;
use function in_array;
use function trim;
use function view;

/**
Expand Down
6 changes: 2 additions & 4 deletions app/Fact.php
Expand Up @@ -32,14 +32,11 @@
use function implode;
use function in_array;
use function preg_match;
use function preg_match_all;
use function preg_replace;
use function str_contains;
use function str_ends_with;
use function usort;

use const PREG_SET_ORDER;

/**
* A GEDCOM fact or event object.
*/
Expand Down Expand Up @@ -320,7 +317,8 @@ public function canShow(int $access_level = null): bool
$access_level = $access_level ?? Auth::accessLevel($this->record->tree());

// Does this record have an explicit restriction notice?
$restriction = $this->attribute('RESN');
$element = new RestrictionNotice('');
$restriction = $element->canonical($this->attribute('RESN'));

if (str_ends_with($restriction, RestrictionNotice::VALUE_CONFIDENTIAL)) {
return Auth::PRIV_NONE >= $access_level;
Expand Down
1 change: 0 additions & 1 deletion app/Factories/FilesystemFactory.php
Expand Up @@ -22,7 +22,6 @@
use Fisharebest\Flysystem\Adapter\ChrootAdapter;
use Fisharebest\Webtrees\Contracts\FilesystemFactoryInterface;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\Tree;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\Local\LocalFilesystemAdapter;
Expand Down
2 changes: 2 additions & 0 deletions app/Factories/IdFactory.php
Expand Up @@ -52,6 +52,8 @@ public function uuid(): string
/**
* An identifier for use in CSS/HTML
*
* @param string $prefix
*
* @return string
*/
public function id(string $prefix = 'id-'): string
Expand Down
1 change: 0 additions & 1 deletion app/Gedcom.php
Expand Up @@ -98,7 +98,6 @@
use Fisharebest\Webtrees\Elements\EventTypeCitedFrom;
use Fisharebest\Webtrees\Elements\FamilyCensus;
use Fisharebest\Webtrees\Elements\FamilyEvent;
use Fisharebest\Webtrees\Elements\FamilyFact;
use Fisharebest\Webtrees\Elements\FamilyRecord;
use Fisharebest\Webtrees\Elements\FamilyResidence;
use Fisharebest\Webtrees\Elements\FileName;
Expand Down
2 changes: 1 addition & 1 deletion app/GedcomRecord.php
Expand Up @@ -389,7 +389,7 @@ public function getPrimaryName(): int
$this->getPrimaryName = 0;
// ...except when the language/name use different character sets
foreach ($this->getAllNames() as $n => $name) {
if ($name['type'] !== '_MARNM' && I18N::textScript($name['sort']) === $language_script) {
if (I18N::textScript($name['sort']) === $language_script) {
$this->getPrimaryName = $n;
break;
}
Expand Down
63 changes: 60 additions & 3 deletions app/Http/Middleware/BadBotBlocker.php
Expand Up @@ -22,6 +22,8 @@
use Fig\Http\Message\StatusCodeInterface;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Validator;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Iodev\Whois\Loaders\CurlLoader;
use Iodev\Whois\Modules\Asn\AsnRouteInfo;
use Iodev\Whois\Whois;
Expand Down Expand Up @@ -50,6 +52,9 @@
*/
class BadBotBlocker implements MiddlewareInterface
{
private const REGEX_OCTET = '(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
private const REGEX_IPV4 = '/\\b' . self::REGEX_OCTET . '(?:\\.' . self::REGEX_OCTET . '){3}\\b/';

// Cache whois requests. Try to avoid all caches expiring at the same time.
private const WHOIS_TTL_MIN = 28 * 86400;
private const WHOIS_TTL_MAX = 35 * 86400;
Expand All @@ -67,6 +72,7 @@ class BadBotBlocker implements MiddlewareInterface
'DataForSEO',
'DotBot',
'Grapeshot',
'Honolulu-bot', // Aggressive crawer, no info available
'ia_archiver',
'Linguee',
'MJ12bot',
Expand All @@ -75,6 +81,7 @@ class BadBotBlocker implements MiddlewareInterface
'PetalBot',
'proximic',
'SemrushBot',
'serpstatbot',
'SEOkicks',
'SiteKiosk',
'Turnitin',
Expand Down Expand Up @@ -160,6 +167,15 @@ class BadBotBlocker implements MiddlewareInterface
],
];

/**
* Some search engines operate from designated IP addresses.
*
* @see https://bot.seekport.com/
*/
private const ROBOT_IP_FILES = [
'SeekportBot' => 'https://bot.seekport.com/seekportbot_ips.txt',
];

/**
* Some search engines operate from within a designated autonomous system.
*
Expand Down Expand Up @@ -202,10 +218,26 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
}

foreach (self::ROBOT_IPS as $robot => $valid_ips) {
foreach (self::ROBOT_IPS as $robot => $valid_ip_ranges) {
if (str_contains($ua, $robot)) {
foreach ($valid_ip_ranges as $ip_range) {
$range = IPFactory::parseRangeString($ip_range);

if ($range instanceof RangeInterface && $range->contains($address)) {
continue 2;
}
}

return $this->response();
}
}

foreach (self::ROBOT_IP_FILES as $robot => $url) {
if (str_contains($ua, $robot)) {
foreach ($valid_ips as $ip) {
$range = IPFactory::parseRangeString($ip);
$valid_ip_ranges = $this->fetchIpRangesForUrl($robot, $url);

foreach ($valid_ip_ranges as $ip_range) {
$range = IPFactory::parseRangeString($ip_range);

if ($range instanceof RangeInterface && $range->contains($address)) {
continue 2;
Expand Down Expand Up @@ -297,6 +329,31 @@ private function fetchIpRangesForAsn(string $asn): array
}, random_int(self::WHOIS_TTL_MIN, self::WHOIS_TTL_MAX));
}

/**
* Fetch a list of IP addresses from a remote file.
*
* @param string $ua
* @param string $url
*
* @return array<string>
*/
private function fetchIpRangesForUrl(string $ua, string $url): array
{
return Registry::cache()->file()->remember('url-ip-list-' . $ua, static function () use ($url): array {
try {
$client = new Client();
$response = $client->get($url, ['timeout' => 5]);
$contents = $response->getBody()->getContents();

preg_match_all(self::REGEX_IPV4, $contents, $matches);

return $matches[0];
} catch (GuzzleException $ex) {
return [];
}
}, random_int(self::WHOIS_TTL_MIN, self::WHOIS_TTL_MAX));
}

/**
* @return ResponseInterface
*/
Expand Down
3 changes: 2 additions & 1 deletion app/Http/RequestHandlers/AutoCompleteFolder.php
Expand Up @@ -35,7 +35,8 @@ class AutoCompleteFolder extends AbstractAutocompleteHandler
private MediaFileService $media_file_service;

/**
* @param SearchService $search_service
* @param MediaFileService $media_file_service
* @param SearchService $search_service
*/
public function __construct(MediaFileService $media_file_service, SearchService $search_service)
{
Expand Down
5 changes: 2 additions & 3 deletions app/Http/RequestHandlers/CreateMediaObjectAction.php
Expand Up @@ -29,7 +29,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function in_array;
use function response;

/**
Expand Down Expand Up @@ -66,7 +65,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$note = Validator::parsedBody($request)->string('media-note');
$title = Validator::parsedBody($request)->string('title');
$type = Validator::parsedBody($request)->string('type');
$restriction = Validator::parsedBody($request)->string('restriction');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');

$file = $this->media_file_service->uploadFile($request);

Expand All @@ -76,7 +75,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface

$gedcom = "0 @@ OBJE\n" . $this->media_file_service->createMediaFileGedcom($file, $type, $title, $note);

if (in_array($restriction, ['none', 'privacy', 'confidential', 'locked'], true)) {
if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
}

Expand Down
6 changes: 2 additions & 4 deletions app/Http/RequestHandlers/CreateNoteAction.php
Expand Up @@ -26,8 +26,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function in_array;

/**
* Process a form to create a new note object.
*/
Expand All @@ -42,14 +40,14 @@ public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$note = Validator::parsedBody($request)->string('note');
$restriction = Validator::parsedBody($request)->isInArray(['none', 'privacy', 'confidential', 'locked'])->string('restriction');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');

// Convert HTML line endings to GEDCOM continuations
$note = strtr($note, ["\r\n" => "\n1 CONT "]);

$gedcom = '0 @@ NOTE ' . $note;

if (in_array($restriction, ['none', 'privacy', 'confidential', 'locked'], true)) {
if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
}

Expand Down
5 changes: 2 additions & 3 deletions app/Http/RequestHandlers/CreateRepositoryAction.php
Expand Up @@ -26,7 +26,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function in_array;
use function preg_replace;
use function response;
use function trim;
Expand All @@ -48,7 +47,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$name = Validator::parsedBody($request)->string('name');
$address = Validator::parsedBody($request)->string('address');
$url = Validator::parsedBody($request)->string('url');
$restriction = Validator::parsedBody($request)->string('restriction');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');

// Fix non-printing characters
$name = trim(preg_replace('/\s+/', ' ', $name));
Expand All @@ -63,7 +62,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$gedcom .= "\n1 WWW " . $url;
}

if (in_array($restriction, ['none', 'privacy', 'confidential', 'locked'], true)) {
if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
}

Expand Down
6 changes: 2 additions & 4 deletions app/Http/RequestHandlers/CreateSourceAction.php
Expand Up @@ -26,8 +26,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function in_array;

/**
* Process a form to create a new source.
*/
Expand All @@ -48,7 +46,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$repository = Validator::parsedBody($request)->string('source-repository');
$call_number = Validator::parsedBody($request)->string('source-call-number');
$text = Validator::parsedBody($request)->string('source-text');
$restriction = Validator::parsedBody($request)->string('restriction');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');

// Fix non-printing characters
$title = trim(preg_replace('/\s+/', ' ', $title));
Expand Down Expand Up @@ -87,7 +85,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}
}

if (in_array($restriction, ['none', 'privacy', 'confidential', 'locked'], true)) {
if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
}

Expand Down
6 changes: 2 additions & 4 deletions app/Http/RequestHandlers/CreateSubmitterAction.php
Expand Up @@ -26,8 +26,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function in_array;

/**
* Process a form to create a new submitter.
*/
Expand All @@ -45,7 +43,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$address = Validator::parsedBody($request)->string('submitter_address');
$email = Validator::parsedBody($request)->string('submitter_email');
$phone = Validator::parsedBody($request)->string('submitter_phone');
$restriction = Validator::parsedBody($request)->string('restriction');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');

// Fix non-printing characters
$name = trim(preg_replace('/\s+/', ' ', $name));
Expand All @@ -64,7 +62,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$gedcom .= "\n1 PHON " . $phone;
}

if (in_array($restriction, ['none', 'privacy', 'confidential', 'locked'], true)) {
if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/RequestHandlers/DataFixUpdateAll.php
Expand Up @@ -82,8 +82,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
return response([]);
}

$start = Validator::queryParams($request)->string('start');
$end = Validator::queryParams($request)->string('end');
$start = Validator::queryParams($request)->string('start', '');
$end = Validator::queryParams($request)->string('end', '');

if ($start === '' || $end === '') {
return $this->createUpdateRanges($tree, $module, $rows, $params);
Expand Down
1 change: 1 addition & 0 deletions app/Http/RequestHandlers/MapDataAdd.php
Expand Up @@ -109,6 +109,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
'marker_position' => $marker_position,
'parent' => $parent,
'leaflet_config' => $this->leaflet_js_service->config(),
'url' => route(MapDataList::class, ['parent_id' => $parent->id()])
]);
}
}
1 change: 0 additions & 1 deletion app/Http/RequestHandlers/MapDataSave.php
Expand Up @@ -30,7 +30,6 @@
use function e;
use function redirect;
use function round;
use function route;

/**
* Controller for maintaining geographic data.
Expand Down
1 change: 0 additions & 1 deletion app/Http/RequestHandlers/MediaFileDownload.php
Expand Up @@ -27,7 +27,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function assert;
use function redirect;

/**
Expand Down

0 comments on commit 2848ef2

Please sign in to comment.