diff --git a/INSTALL.md b/INSTALL.md index 3aa46a8..d6053ed 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -65,7 +65,6 @@ DocumentRoot /path/to/friendica-directory/public/ ### Nginx Include this line your nginx config file. -<<<<<<< master ``` root /path/to/friendica-directory/public; ``` diff --git a/README.md b/README.md index 04b68a7..f03db63 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,10 @@ This is an opt-in directory, meaning that each node can choose not to submit its Please refer to the provided [installation instructions](INSTALL.md). +## Update from a previous version + +Please refer to the provided [update instructions](UPDATE.md). + ## See also - [Project Concepts](docs/Concepts.md) diff --git a/UPDATE.md b/UPDATE.md new file mode 100644 index 0000000..a8353df --- /dev/null +++ b/UPDATE.md @@ -0,0 +1,42 @@ +# Friendica Directory Update Instructions + +## 1. Update the source code + +If you installed Friendica Directory in `/path/to/friendica-directory`. + +### Using Git + +``` +cd /path/to/friendica-directory +git pull +composer install +``` + +### Using an archive + +1. Create a temporary folder to unpack the new archive. +2. Copy your old `config/local.json` to the new folder. +3. Swap the folder names. +4. Remove the temporary folder. + +Sample Linux commands: +``` +cd /path/to +mkdir friendica-directory-new +unzip friendica-.zip friendica-directory-new +cp friendica-directory/config/local.json friendica-directory-new/config +mv friendica-directory friendica-directory-old +mv friendica-directory-new friendica-directory +rm -r friendica-directory-old +``` + +## 2. Update the database structure + +The database structure may have changed since the last update, fortunately a console command allows to run the migration scripts up to the latest version: + +``` +cd /path/to/friendica-directory +bin/console dbupdate +``` + +You're all set! \ No newline at end of file diff --git a/VERSION b/VERSION index 50ffc5a..e010258 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.3 +2.0.5 diff --git a/src/classes/Controllers/Console.php b/src/classes/Controllers/Console.php index 480433c..286eed6 100644 --- a/src/classes/Controllers/Console.php +++ b/src/classes/Controllers/Console.php @@ -43,9 +43,7 @@ class Console extends \Asika\SimpleConsole\Console { $commandList = ''; foreach ($this->routes as $command => $class) { - $this->out($class); - - $commandList .= ' ' . $command . ' ' . $class::description . "\n"; + $commandList .= ' ' . $command . "\n"; } $help = << */ @@ -15,6 +17,15 @@ class ProfilePollQueue extends \Friendica\Directory\Model return false; } + $host = parse_url($url, PHP_URL_HOST); + if (!$host) { + return false; + } + + if (Network::isPublicHost($host)) { + return false; + } + $this->atlas->perform( 'INSERT IGNORE INTO `profile_poll_queue` SET `profile_url` = :profile_url', ['profile_url' => $url] diff --git a/src/classes/Pollers/Profile.php b/src/classes/Pollers/Profile.php index d4d71fd..06ce6f0 100644 --- a/src/classes/Pollers/Profile.php +++ b/src/classes/Pollers/Profile.php @@ -2,6 +2,8 @@ namespace Friendica\Directory\Pollers; +use Friendica\Directory\Utils\Network; + /** * @author Hypolite Petovan */ @@ -127,7 +129,12 @@ class Profile $noscrape = !!$params; //If the result was false, do a scrape after all. } - if (!$noscrape) { + $available = true; + + if ($noscrape) { + $available = Network::testURL($profile_uri); + $this->logger->debug('Testing ' . $profile_uri . ': ' . ($available?'Success':'Failure')); + } else { $this->logger->notice('Parsing profile page ' . $profile_uri); $params = \Friendica\Directory\Utils\Scrape::retrieveProfileData($profile_uri); } @@ -204,7 +211,7 @@ class Profile `account_type` = :account_type, `filled_fields` = :filled_fields, `last_activity` = :last_activity, - `available` = 1, + `available` = :available, `created` = NOW(), `updated` = NOW() ON DUPLICATE KEY UPDATE @@ -223,7 +230,7 @@ class Profile `account_type` = :account_type, `filled_fields` = :filled_fields, `last_activity` = :last_activity, - `available` = 1, + `available` = :available, `updated` = NOW()', [ 'profile_id' => $profile_id, @@ -242,6 +249,7 @@ class Profile 'account_type' => $account_type, 'filled_fields' => $filled_fields, 'last_activity' => $params['last-activity'] ?? null, + 'available' => $available, ] ); diff --git a/src/classes/Pollers/Server.php b/src/classes/Pollers/Server.php index 6773d31..99d4977 100644 --- a/src/classes/Pollers/Server.php +++ b/src/classes/Pollers/Server.php @@ -173,7 +173,9 @@ class Server ); //Add the admin to the directory - $this->profilePollQueueModel->add($probe_result['data']['admin']['profile']); + if (!empty($probe_result['data']['admin']['profile'])) { + $this->profilePollQueueModel->add($probe_result['data']['admin']['profile']); + } } if ($server) { diff --git a/src/classes/Utils/Network.php b/src/classes/Utils/Network.php index c6d6629..67e0084 100644 --- a/src/classes/Utils/Network.php +++ b/src/classes/Utils/Network.php @@ -23,7 +23,7 @@ class Network } curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_TIMEOUT, max(intval($timeout), 1)); //Minimum of 1 second timeout. + curl_setopt($ch, CURLOPT_TIMEOUT, max($timeout, 1)); //Minimum of 1 second timeout. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 8); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -36,6 +36,31 @@ class Network return $s; } + public static function testURL(string $url, int $timeout = 20): bool + { + $ch = curl_init($url); + if (!$ch) { + return false; + } + + curl_setopt($ch, CURLOPT_HEADER , 0); + curl_setopt($ch, CURLOPT_TIMEOUT , max($timeout, 1)); //Minimum of 1 second timeout. + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_MAXREDIRS , 8); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($ch, CURLOPT_NOBODY , true); + + curl_exec($ch); + + $responseCode = intval(curl_getinfo($ch, CURLINFO_RESPONSE_CODE)); + + $testSuccess = curl_errno($ch) === 0 && $responseCode < 400; + + curl_close($ch); + + return $testSuccess; + } + /** * Check if a hostname is public and non-reserved * diff --git a/src/classes/Utils/Scrape.php b/src/classes/Utils/Scrape.php index dfbc751..6c8fee5 100644 --- a/src/classes/Utils/Scrape.php +++ b/src/classes/Utils/Scrape.php @@ -56,7 +56,7 @@ class Scrape $scrape_start = microtime(true); $params = []; - $html = Network::fetchURL($url, $timeout); + $html = Network::fetchURL($url, false, $timeout); $scrape_fetch_end = microtime(true); diff --git a/src/sql/migrations/down/0001.sql b/src/sql/migrations/down/0001.sql new file mode 100644 index 0000000..e69de29 diff --git a/src/sql/migrations/up/0002.sql b/src/sql/migrations/up/0002.sql new file mode 100644 index 0000000..85dc9ed --- /dev/null +++ b/src/sql/migrations/up/0002.sql @@ -0,0 +1,2 @@ +ALTER table `profile` DROP INDEX `profile-ft`; +ALTER table `profile` ADD FULLTEXT KEY `profile-ft` (`name`, `pdesc`, `profile_url`, `locality`, `region`, `country`, `tags`);