This commit is contained in:
cutemeli
2025-12-22 10:35:30 +00:00
parent 0bfc6c8425
commit 5ce7ca2c5d
38927 changed files with 0 additions and 4594700 deletions

View File

@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,74 +0,0 @@
# wappspector
Command-line interface utility to analyze the file structure of a web hosting server and identify the frameworks and CMS used in the websites hosted on it.
[![unit-test](https://github.com/plesk/wappspector/actions/workflows/unit-test.yml/badge.svg)](https://github.com/plesk/wappspector/actions/workflows/unit-test.yml)
## Matchers
### Technology & Frameworks
| Technology | Version | Check type |
|-------------|------------|----------------------------------|
| PHP | - | Any `*.php` file |
| Ruby | 2, 3 | `Rakefile` in root dir |
| Python | 2, 3 | Any `*.py` file |
| Laravel | 8, 9, 10 | `artisan` file in root dir |
| Symfony | 3, 4, 5, 6 | `symfony.lock` file in root dir |
| CodeIgniter | 4 | `spark` file in root dir |
| CakePHP | 3, 4 | `bin/cake` file |
| Yii | 2 | `yii` file in root dir |
| Composer | - | `composer.json` file in root dir |
| .NET | - | Any `*.dll` file |
| Node.js | - | `package.json` file in root dir |
### CMS
| Name | Major version | Check type |
|------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| WordPress | 2 - 6 | Existence and contents of `wp-includes/version.php` |
| Joomla! | 1 - 4 | Existence and contents of `configuration.php` in root dir |
| Drupal | 6 - 10 | Existence and contents of `/modules/system/system.info` or `/core/modules/system/system.info.yml` |
| PrestaShop | 1.6, 1.7.8, 8.0 | Existence and contents of `/config/settings.inc.php` |
| TYPO3 | 7.6, 8.7, 9, 10, 11, 12 | Existence and contents of `/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php` or `/typo3/sysext/core/Classes/Information/Typo3Version.php` or `/t3lib/config_default.php` |
### Site builders
| Name | Check type |
|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Sitejet | The `index.html` file exists and contains the `ed-element` and `webcard.apiHost=` strings |
| WebPresenceBuilder | The `index.html` file contains the `<meta name="generator" content="Web Presence Builder <vesrion>">` tag or contains the following DOM structure: the `div` tag with the `page` ID contains the `div` tags with the `watermark` and `layout` IDs |
| Site.pro | The `sitepro` folder exists and the `sitepro` string is contained in the `web.config` or `.htaccess` files |
| Duda.co | The `Style` folder contains the `desktop.css`, `mobile.css`, or `tablet.css` files. The style file contains the `dmDudaonePreviewBody` or `dudaSnipcartProductGalleryId` strings, or the `Scripts/runtime.js` file contains the `duda` string |
| Siteplus | The `index.html` file exists and contains the `edit.site` string, and the `/bundle/publish/<version>` directory exists and contains the `bundle.js` file. The `bundle.js` file contains the `siteplus` string |
## How to build phar
```shell
composer global require clue/phar-composer
composer install
php -d phar.readonly=off ~/.composer/vendor/bin/phar-composer build .
```
Run the created `wappspector.phar`:
```shell
./wappspector.phar ./test-data
```
## Changing matchers order
To change the matchers order or to disable some of them, you should override `matchers` entry of DI container.
```php
$diContainer = \Plesk\Wappspector\DIContainer::build();
$matchers = $diContainer->get('matchers');
array_unshift($matchers, \Some\New\Matcher::class);
$diContainer->set('matchers', $matchers);
```
or
```php
// only detect WordPress installs
$diContainer = \Plesk\Wappspector\DIContainer::build();
$diContainer->set('matchers', [\Plesk\Wappspector\Matchers\Wordpress::class]);
```
## Testing
```shell
./vendor/bin/phpunit
```

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../vendor/autoload.php';
use Plesk\Wappspector\DIContainer;
use Symfony\Component\Console\Application;
$diContainer = DIContainer::build();
$app = $diContainer->get(Application::class);
$app->run();

View File

@@ -1,48 +0,0 @@
{
"name": "plesk/wappspector",
"version": "0.2.8",
"description": "Command-line interface utility to analyze the file structure of a web hosting server and identify the frameworks and CMS used in the websites hosted on it.",
"type": "project",
"license": "Apache-2.0",
"bin": [
"bin/wappspector.php"
],
"scripts": {
"test": "phpunit",
"rector": "rector --dry-run",
"rector:fix": "rector",
"lint": "phpcs -s --parallel=4",
"lint:fix": "phpcbf",
"ci:standards": "phpcs -s --parallel=4 --report=json",
"ci:rector": "rector --dry-run --output-format=json"
},
"scripts-descriptions": {
"lint": "Run linters"
},
"autoload": {
"psr-4": {
"Plesk\\Wappspector\\": "src/",
"Test\\": "tests/"
}
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^10",
"psr/log": "^2.0",
"rector/rector": "^1.0",
"slevomat/coding-standard": "^8.8.0",
"squizlabs/php_codesniffer": "^3.7.2",
"symfony/console": "^5.0"
},
"require": {
"php": ">=8.0",
"league/flysystem": "^3.0",
"php-di/php-di": "^6.0 || ^7.0"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}

View File

@@ -1,146 +0,0 @@
<?php
namespace Plesk\Wappspector\Command;
use FilesystemIterator;
use JsonException;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\Wappspector;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
#[AsCommand(name: 'wappspector:inspect')]
class Inspect extends Command
{
public function __construct(private Wappspector $wappspector)
{
parent::__construct();
$this->addArgument('path', InputArgument::OPTIONAL, 'Root path', getcwd());
$this->addOption('json', '', InputOption::VALUE_NONE, 'JSON output');
$this->addOption('recursive', '', InputOption::VALUE_NEGATABLE, 'Traverse directories recursive', true);
$this->addOption('depth', '', InputOption::VALUE_OPTIONAL, 'Depth of recurse', 1);
$this->addOption(
'max',
'',
InputOption::VALUE_REQUIRED,
'Maximum number of technologies that can be found for directory. Default = 0 (no limit)',
0
);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$isJson = (bool)$input->getOption('json');
$logger = new ConsoleLogger($output);
$result = [];
$matchersLimit = (int)$input->getOption('max');
try {
foreach ($this->getPath($input) as $path) {
$result = [...$result, ...$this->wappspector->run($path, '/', $matchersLimit)];
}
$result = $this->filterResults($result);
if ($isJson) {
$this->jsonOutput($output, $result);
return Command::SUCCESS;
}
$this->tableOutput($output, $result);
return Command::SUCCESS;
} catch (Throwable $exception) {
$logger->error($exception->getMessage());
return Command::FAILURE;
}
}
/**
* @throws JsonException
*/
private function jsonOutput(OutputInterface $output, array $result): void
{
$output->writeln(json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
}
/**
* @param MatchResultInterface[] $matchers
* @return void
*/
private function tableOutput(OutputInterface $output, array $matchers): void
{
$rows = [];
foreach ($matchers as $matchResult) {
$rows[] = [
$matchResult->getId(),
$matchResult->getName(),
$matchResult->getPath(),
$matchResult->getVersion() ?? '-',
];
}
$table = new Table($output);
$table
->setHeaders(['ID', 'Technology', 'Path', 'Version'])
->setRows($rows);
$table->render();
}
private function getPath(InputInterface $input): iterable
{
$path = $input->getArgument('path');
$path = realpath($path);
if (!$input->getOption('recursive')) {
yield $path;
return;
}
$flags = FilesystemIterator::KEY_AS_PATHNAME
| FilesystemIterator::CURRENT_AS_FILEINFO
| FilesystemIterator::SKIP_DOTS;
$itFlags = RecursiveIteratorIterator::SELF_FIRST;
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $flags), $itFlags);
$it->setMaxDepth((int)$input->getOption('depth'));
foreach ($it as $path => $item) {
/** @var SplFileInfo $item */
if (str_contains($path, '/.')) {
continue;
}
if (!$item->isDir()) {
continue;
}
yield $path;
}
}
/**
* @param MatchResultInterface[] $result
* @return MatchResultInterface[]
*/
private function filterResults(array $result): array
{
return array_values(
array_filter($result, static function (MatchResultInterface $matcher) {
static $uniq = [];
$key = $matcher->getId() . ':' . $matcher->getPath();
if (array_key_exists($key, $uniq)) {
return false;
}
$uniq[$key] = true;
return true;
})
);
}
}

View File

@@ -1,21 +0,0 @@
<?php
namespace Plesk\Wappspector;
use DI\Container;
use DI\ContainerBuilder;
use Exception;
class DIContainer
{
/**
* @throws Exception
*/
public static function build(): Container
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions(__DIR__ . '/container.php');
return $containerBuilder->build();
}
}

View File

@@ -1,16 +0,0 @@
<?php
namespace Plesk\Wappspector;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
class FileSystemFactory
{
public function __invoke(string $path): Filesystem
{
$adapter = new LocalFilesystemAdapter($path, null, LOCK_EX, LocalFilesystemAdapter::SKIP_LINKS);
return new Filesystem($adapter);
}
}

View File

@@ -1,25 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
declare(strict_types=1);
namespace Plesk\Wappspector\Helper;
use League\Flysystem\Filesystem;
class InspectorHelper
{
public function fileContentContainsString(string $fileContent, string $searchString): bool
{
return str_contains($fileContent, $searchString);
}
public function fileContentMatchesString(string $fileContent, string $searchPattern): bool
{
return preg_match($searchPattern, $fileContent) === 1;
}
public function fileContainsString(Filesystem $fs, string $filePath, string $searchString): bool
{
return $fs->fileExists($filePath) && str_contains($fs->read($filePath), $searchString);
}
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class CakePHP extends MatchResult
{
public const ID = 'cakephp';
public const NAME = 'CakePHP';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class CodeIgniter extends MatchResult
{
public const ID = 'codeigniter';
public const NAME = 'CodeIgniter';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Composer extends MatchResult
{
public const ID = 'composer';
public const NAME = 'Composer';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class DotNet extends MatchResult
{
public const ID = 'dotnet';
public const NAME = '.NET';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Drupal extends MatchResult
{
public const ID = 'drupal';
public const NAME = 'Drupal';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Duda extends MatchResult
{
public const ID = 'duda';
public const NAME = 'duda.co';
}

View File

@@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class EmptyMatchResult implements MatchResultInterface
{
public function getId(): string
{
return 'unknown';
}
public function getName(): string
{
return 'Unknown';
}
public function getPath(): string
{
return '';
}
public function getVersion(): ?string
{
return null;
}
public function getApplication(): ?string
{
return null;
}
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Joomla extends MatchResult
{
public const ID = 'joomla';
public const NAME = 'Joomla!';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Laravel extends MatchResult
{
public const ID = 'laravel';
public const NAME = 'Laravel';
}

View File

@@ -1,102 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
use JsonSerializable;
use League\Flysystem\PathTraversalDetected;
use League\Flysystem\WhitespacePathNormalizer;
class MatchResult implements MatchResultInterface, JsonSerializable
{
public const ID = null;
public const NAME = null;
public function __construct(
protected string $path,
protected ?string $version = null,
protected ?string $application = null,
) {
try {
$this->path = (new WhitespacePathNormalizer())->normalizePath($this->path);
} catch (PathTraversalDetected) {
$this->path = '/';
}
}
public function getId(): string
{
return static::ID;
}
public function getName(): string
{
return static::NAME;
}
public function getPath(): string
{
return $this->path;
}
public function getVersion(): ?string
{
return $this->version;
}
public function getApplication(): ?string
{
return $this->application;
}
public function jsonSerialize(): array
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'path' => $this->getPath(),
'version' => $this->getVersion(),
'application' => $this->getApplication(),
];
}
public static function createById(
string $id,
?string $path = null,
?string $version = null,
?string $application = null
): MatchResultInterface {
$classname = match ($id) {
CakePHP::ID => CakePHP::class,
CodeIgniter::ID => CodeIgniter::class,
Composer::ID => Composer::class,
DotNet::ID => DotNet::class,
Drupal::ID => Drupal::class,
Joomla::ID => Joomla::class,
Laravel::ID => Laravel::class,
NodeJs::ID => NodeJs::class,
Php::ID => Php::class,
Prestashop::ID => Prestashop::class,
Python::ID => Python::class,
Ruby::ID => Ruby::class,
Symfony::ID => Symfony::class,
Typo3::ID => Typo3::class,
Wordpress::ID => Wordpress::class,
Yii::ID => Yii::class,
Sitejet::ID => Sitejet::class,
WebPresenceBuilder::ID => WebPresenceBuilder::class,
Sitepro::ID => Sitepro::class,
Duda::ID => Duda::class,
Siteplus::ID => Siteplus::class,
default => null,
};
if (!$classname) {
return new EmptyMatchResult();
}
return new $classname(path: $path ?? '', version: $version, application: $application);
}
}

View File

@@ -1,25 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
interface MatchResultInterface
{
/**
* Internal ID of the technology
*/
public function getId(): string;
/**
* Human-readable technology name
*/
public function getName(): string;
public function getPath(): string;
public function getVersion(): ?string;
public function getApplication(): ?string;
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class NodeJs extends MatchResult
{
public const ID = 'nodejs';
public const NAME = 'Node.js';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Php extends MatchResult
{
public const ID = 'php';
public const NAME = 'PHP';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Prestashop extends MatchResult
{
public const ID = 'prestashop';
public const NAME = 'PrestaShop';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Python extends MatchResult
{
public const ID = 'python';
public const NAME = 'Python';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Ruby extends MatchResult
{
public const ID = 'ruby';
public const NAME = 'Ruby';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Sitejet extends MatchResult
{
public const ID = 'sitejet';
public const NAME = 'Sitejet';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Siteplus extends MatchResult
{
public const ID = 'siteplus';
public const NAME = 'Siteplus';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Sitepro extends MatchResult
{
public const ID = 'sitepro';
public const NAME = 'Site.pro';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Symfony extends MatchResult
{
public const ID = 'symfony';
public const NAME = 'Symfony';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Typo3 extends MatchResult
{
public const ID = 'typo3';
public const NAME = 'TYPO3';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class WebPresenceBuilder extends MatchResult
{
public const ID = 'webpresencebuilder';
public const NAME = 'WebPresenceBuilder';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Wordpress extends MatchResult
{
public const ID = 'wordpress';
public const NAME = 'WordPress';
}

View File

@@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\MatchResult;
class Yii extends MatchResult
{
public const ID = 'yii';
public const NAME = 'Yii';
}

View File

@@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\CakePHP as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class CakePHP implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$path = rtrim($path, '/');
if (!$fs->fileExists($path . '/bin/cake')) {
return new EmptyMatchResult();
}
$version = $this->detectVersion($fs, $path);
return new MatchResult($path, $version);
}
private function detectVersion(Filesystem $fs, string $path): ?string
{
$version = null;
$versionFile = $path . '/vendor/cakephp/cakephp/VERSION.txt';
if ($fs->fileExists($versionFile)) {
$versionData = explode("\n", trim($fs->read($versionFile)));
$version = trim(array_pop($versionData));
}
return $version;
}
}

View File

@@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\CodeIgniter as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class CodeIgniter implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$path = rtrim($path, '/');
if (!$fs->fileExists($path . '/spark')) {
return new EmptyMatchResult();
}
return new MatchResult($path, $this->detectVersion($fs, $path));
}
/**
* @throws FilesystemException
*/
private function detectVersion(Filesystem $fs, string $path): ?string
{
$versionFile = $path . '/vendor/codeigniter4/framework/system/CodeIgniter.php';
if (!$fs->fileExists($versionFile)) {
return null;
}
preg_match("/CI_VERSION\\s*=\\s*'([^']+)'/", $fs->read($versionFile), $matches);
if ($matches !== []) {
return $matches[1];
}
return null;
}
}

View File

@@ -1,40 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use JsonException;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\Composer as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class Composer implements MatcherInterface
{
use UpLevelMatcherTrait;
private function getPath(string $path): string
{
return rtrim($path, '/') . '/composer.json';
}
/**
* @throws FilesystemException
*/
protected function doMatch(Filesystem $fs, string $path): MatchResultInterface
{
$composerJsonFile = $this->getPath($path);
if (!$fs->fileExists($composerJsonFile)) {
return new EmptyMatchResult();
}
$json = [];
try {
$json = json_decode($fs->read($composerJsonFile), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
// ignore composer.json errors
}
return new MatchResult($path, $json['version'] ?? 'dev', $json['name'] ?? 'unknown');
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use League\Flysystem\StorageAttributes;
use Plesk\Wappspector\MatchResult\DotNet as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class DotNet implements MatcherInterface
{
use UpLevelMatcherTrait;
private const HEX_SIGNATURE = '4d5a';
/**
* @throws FilesystemException
*/
public function doMatch(Filesystem $fs, string $path): MatchResultInterface
{
foreach ($fs->listContents($path) as $item) {
/** @var StorageAttributes $item */
if (!$item->isFile() || !str_ends_with($item->path(), '.dll')) {
continue;
}
$handle = $fs->readStream($item->path());
$hex = bin2hex(fread($handle, 4));
if (str_contains($hex, self::HEX_SIGNATURE)) {
return new MatchResult($path);
}
}
return new EmptyMatchResult();
}
}

View File

@@ -1,53 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\Drupal as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class Drupal implements MatcherInterface
{
/**
* Drupal has changed the way how the version number is stored multiple times, so we need this comprehensive array
*/
private const VERSIONS = [
[
'file' => 'modules/system/system.info',
'regex' => "/version\\s*=\\s*\"(\\d\\.[^']+)\"[\\s\\S]*project\\s*=\\s*\"drupal\"/",
],
[
'file' => 'core/modules/system/system.info.yml',
'regex' => "/version:\\s*'(\\d+\\.[^']+)'[\\s\\S]*project:\\s*'drupal'/",
],
];
/**
* @throws FilesystemException
*/
public function match(Filesystem $fs, string $path): MatchResultInterface
{
// Iterate through version patterns
foreach (self::VERSIONS as $version) {
$versionFile = rtrim($path, '/') . '/' . $version['file'];
if (!$fs->fileExists($versionFile)) {
continue;
}
$version = $this->detectVersion($version['regex'], $versionFile, $fs);
return new MatchResult($path, $version);
}
return new EmptyMatchResult();
}
private function detectVersion(string $regexPattern, string $versionFile, Filesystem $fs): ?string
{
preg_match($regexPattern, $fs->read($versionFile), $matches);
return count($matches) ? $matches[1] : null;
}
}

View File

@@ -1,60 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\Duda as MatchResult;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class Duda implements MatcherInterface
{
private const CSS_FILES = [
'/Style/desktop.css',
'/Style/mobile.css',
'/Style/tablet.css',
];
private const RUNTIME_JS_FILE = '/Scripts/runtime.js';
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$rTrimPath = rtrim($path, '/');
$cssFile = $this->getCssFile($fs, $rTrimPath);
$inspectorHelper = new InspectorHelper();
if ($cssFile !== null) {
$cssFileContent = $fs->read($rTrimPath . $cssFile);
if (
$inspectorHelper->fileContentContainsString($cssFileContent, 'dmDudaonePreviewBody') ||
$inspectorHelper->fileContentContainsString($cssFileContent, 'dudaSnipcartProductGalleryId')
) {
return new MatchResult($path);
}
}
if (!$fs->fileExists($rTrimPath . self::RUNTIME_JS_FILE)) {
return new EmptyMatchResult();
}
return $inspectorHelper->fileContainsString($fs, $rTrimPath . self::RUNTIME_JS_FILE, 'duda')
? new MatchResult($path)
: new EmptyMatchResult();
}
private function getCssFile(Filesystem $fs, string $path): ?string
{
foreach (self::CSS_FILES as $cssFile) {
if ($fs->fileExists($path . $cssFile)) {
return $cssFile;
}
}
return null;
}
}

View File

@@ -1,124 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\Joomla as MatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class Joomla implements MatcherInterface
{
private const CONFIG_FILE = 'configuration.php';
/**
* Joomla has changed the way how the version number is stored multiple times, so we need this comprehensive array
*/
private const VERSION = [
"files" => [
"/includes/version.php",
"/libraries/joomla/version.php",
"/libraries/cms/version/version.php",
"/libraries/src/Version.php",
],
"regex_release" => "/\\\$?RELEASE\s*=\s*'([\d.]+)';/",
"regex_devlevel" => "/\\\$?DEV_LEVEL\s*=\s*'([^']+)';/",
"regex_major" => "/\\\$?MAJOR_VERSION\s*=\s*([\d.]+);/",
"regex_minor" => "/\\\$?MINOR_VERSION\s*=\s*([\d.]+);/",
"regex_patch" => "/\\\$?PATCH_VERSION\s*=\s*([\d.]+);/",
];
/**
* @throws FilesystemException
*/
private function isJoomla(Filesystem $fs, string $path): bool
{
$configFile = rtrim($path, '/') . '/' . self::CONFIG_FILE;
if (!$fs->fileExists($configFile)) {
return false;
}
$configContents = $fs->read($configFile);
if (
stripos($configContents, 'JConfig') === false
&& stripos($configContents, 'mosConfig') === false
) {
return false;
}
// False positive "Akeeba Backup Installer"
if (stripos($configContents, 'class ABIConfiguration') !== false) {
return false;
}
// False positive mock file in unit test folder
if (stripos($configContents, 'Joomla.UnitTest') !== false) {
return false;
}
// False positive mock file in unit test folder
return stripos($configContents, "Joomla\Framework\Test") === false;
}
/**
* @throws FilesystemException
*/
private function detectVersion(Filesystem $fs, string $path): ?string
{
// Iterate through version files
foreach (self::VERSION['files'] as $file) {
$versionFile = rtrim($path, '/') . '/' . $file;
if (!$fs->fileExists($versionFile)) {
continue;
}
$fileContents = $fs->read($versionFile);
preg_match(self::VERSION['regex_major'], $fileContents, $major);
preg_match(self::VERSION['regex_minor'], $fileContents, $minor);
preg_match(self::VERSION['regex_patch'], $fileContents, $patch);
if (count($major) && count($minor) && count($patch)) {
return $major[1] . '.' . $minor[1] . '.' . $patch[1];
}
if (count($major) && count($minor)) {
return $major[1] . '.' . $minor[1] . 'x';
}
if ($major !== []) {
return $major[1] . '.x.x';
}
// Legacy handling for all version < 3.8.0
preg_match(self::VERSION['regex_release'], $fileContents, $release);
preg_match(self::VERSION['regex_devlevel'], $fileContents, $devlevel);
if (count($release) && count($devlevel)) {
return $release[1] . '.' . $devlevel[1];
}
if ($release !== []) {
return $release[1] . '.x';
}
}
return null;
}
/**
* @throws FilesystemException
*/
public function match(Filesystem $fs, string $path): MatchResultInterface
{
if (!$this->isJoomla($fs, $path)) {
return new EmptyMatchResult();
}
return new MatchResult($path, $this->detectVersion($fs, $path));
}
}

View File

@@ -1,58 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use JsonException;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\Laravel as MatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
class Laravel implements MatcherInterface
{
use UpLevelMatcherTrait;
private const VERSION_FILE = 'vendor/laravel/framework/src/Illuminate/Foundation/Application.php';
private const COMPOSER_JSON = 'composer.json';
private const ARTISAN = 'artisan';
/**
* @throws FilesystemException
*/
protected function doMatch(Filesystem $fs, string $path): MatchResultInterface
{
$path = rtrim($path, '/');
if (!$fs->fileExists($path . '/' . self::ARTISAN)) {
return new EmptyMatchResult();
}
return new MatchResult($path, $this->detectVersion($path, $fs));
}
private function detectVersion(string $path, Filesystem $fs): ?string
{
$result = null;
$versionFile = $path . '/' . self::VERSION_FILE;
if ($fs->fileExists($versionFile)) {
preg_match("/VERSION\\s*=\\s*'([^']+)'/", $fs->read($versionFile), $matches);
if ($matches !== []) {
$result = $matches[1];
}
} else {
$composerJsonFile = $path . '/' . self::COMPOSER_JSON;
if ($fs->fileExists($composerJsonFile)) {
try {
$json = json_decode($fs->read($composerJsonFile), true, 512, JSON_THROW_ON_ERROR);
if ($laravelPackage = $json['require']['laravel/framework'] ?? null) {
$result = str_replace('^', '', $laravelPackage);
}
} catch (JsonException) {
// ignore composer.json errors
}
}
}
return $result;
}
}

View File

@@ -1,14 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
interface MatcherInterface
{
/**
* Checks filesystem by provided path and returns the list of found objects.
*/
public function match(Filesystem $fs, string $path): MatchResultInterface;
}

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use JsonException;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\NodeJs as MatchResult;
class NodeJs implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$packageFile = rtrim($path, '/') . '/package.json';
if (!$fs->fileExists($packageFile)) {
return new EmptyMatchResult();
}
$json = [];
try {
$json = json_decode($fs->read($packageFile), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
// ignore package.json errors
}
return new MatchResult($path, null, $json['name'] ?? null);
}
}

View File

@@ -1,34 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use League\Flysystem\StorageAttributes;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Php as MatchResult;
class Php implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
try {
$list = $fs->listContents($path);
foreach ($list as $item) {
/** @var StorageAttributes $item */
if ($item->isFile() && str_ends_with($item->path(), '.php')) {
return new MatchResult($path);
}
if ($item->isDir() && $item->path() === ltrim(rtrim($path, '/') . '/src', '/')) {
return $this->match($fs, rtrim($path, '/') . '/src');
}
}
} catch (FilesystemException) {
// skip dir if it is inaccessible
}
return new EmptyMatchResult();
}
}

View File

@@ -1,50 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Prestashop as MatchResult;
class Prestashop implements MatcherInterface
{
protected const VERSIONS = [
[
'filename' => '/config/settings.inc.php',
'regexp' => '/define\\(\'_PS_VERSION_\', \'(.+)\'\\)/',
],
];
/**
* @throws FilesystemException
*/
public function match(Filesystem $fs, string $path): MatchResultInterface
{
foreach (self::VERSIONS as $version) {
$versionFile = rtrim($path, '/') . '/' . $version['filename'];
if (!$fs->fileExists($versionFile)) {
continue;
}
return new MatchResult($path, $this->getVersion($version, $fs, $versionFile));
}
return new EmptyMatchResult();
}
public function getVersion(array $version, Filesystem $fs, string $versionFile): ?string
{
$result = null;
try {
if (preg_match($version['regexp'], $fs->read($versionFile), $matches) && count($matches) > 1) {
$result = $matches[1];
}
} catch (FilesystemException) {
// ignore filesystem extensions
}
return $result;
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\StorageAttributes;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Python as MatchResult;
class Python implements MatcherInterface
{
use UpLevelMatcherTrait;
protected function doMatch(Filesystem $fs, string $path): MatchResultInterface
{
foreach ($fs->listContents($path) as $item) {
/** @var StorageAttributes $item */
if ($item->isFile() && str_ends_with($item->path(), '.py')) {
return new MatchResult($path);
}
}
return new EmptyMatchResult();
}
}

View File

@@ -1,28 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Ruby as MatchResult;
class Ruby implements MatcherInterface
{
use UpLevelMatcherTrait;
private const RAKEFILE = 'Rakefile';
/**
* @throws FilesystemException
*/
protected function doMatch(Filesystem $fs, string $path): MatchResultInterface
{
if (!$fs->fileExists(rtrim($path, '/') . '/' . self::RAKEFILE)) {
return new EmptyMatchResult();
}
return new MatchResult($path);
}
}

View File

@@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Sitejet as MatchResult;
class Sitejet implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$indexHtmlPath = rtrim($path, '/') . '/index.html';
if (!$fs->fileExists($indexHtmlPath)) {
return new EmptyMatchResult();
}
$fileContent = $fs->read($indexHtmlPath);
$inspectorHelper = new InspectorHelper();
return $inspectorHelper->fileContentContainsString($fileContent, 'ed-element')
&& $inspectorHelper->fileContentContainsString($fileContent, 'webcard.apiHost=')
? new MatchResult($path)
: new EmptyMatchResult();
}
}

View File

@@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Siteplus as MatchResult;
class Siteplus implements MatcherInterface
{
private const PUBLISH_DIR_PATH = '/bundle/publish';
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$rTrimPath = rtrim($path, '/');
$inspectorHelper = new InspectorHelper();
if (!$inspectorHelper->fileContainsString($fs, $rTrimPath . '/index.html', 'edit.site')) {
return new EmptyMatchResult();
}
if (!$fs->directoryExists($rTrimPath . self::PUBLISH_DIR_PATH)) {
return new EmptyMatchResult();
}
$publishDirList = $fs->listContents($rTrimPath . self::PUBLISH_DIR_PATH, false);
// do not check if the item is a directory as on the server when the files a copied the type of the
// directory is determined as 'file'.
// By default, there should be just 1 directory in the publish directory
$versionDirPath = $publishDirList->toArray()[0]['path'] ?? null;
if ($versionDirPath === null) {
return new EmptyMatchResult();
}
return $inspectorHelper->fileContainsString($fs, $versionDirPath . '/bundle.js', 'siteplus')
? new MatchResult($rTrimPath, $this->getSiteplusVersion($versionDirPath))
: new EmptyMatchResult();
}
private function getSiteplusVersion(string $versionDirPath): string
{
// get the last part of the path
$versionDirPathParts = explode('/', $versionDirPath);
return end($versionDirPathParts);
}
}

View File

@@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Sitepro as MatchResult;
class Sitepro implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$rTrimPath = rtrim($path, '/');
$siteproFolderPath = $rTrimPath . '/sitepro';
if (!$fs->directoryExists($siteproFolderPath)) {
return new EmptyMatchResult();
}
$inspectorHelper = new InspectorHelper();
return $inspectorHelper->fileContainsString($fs, $rTrimPath . '/web.config', 'sitepro')
|| $inspectorHelper->fileContainsString($fs, $rTrimPath . '/.htaccess', 'sitepro')
? new MatchResult($path)
: new EmptyMatchResult();
}
}

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use JsonException;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Symfony as MatchResult;
class Symfony implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$symfonyLockFile = rtrim($path, '/') . '/symfony.lock';
if (!$fs->fileExists($symfonyLockFile)) {
return new EmptyMatchResult();
}
$json = [];
try {
$json = json_decode($fs->read($symfonyLockFile), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
// ignore symfony.lock errors
}
return new MatchResult($path, $json["symfony/framework-bundle"]["version"] ?? null);
}
}

View File

@@ -1,58 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Typo3 as MatchResult;
class Typo3 implements MatcherInterface
{
/**
* Version detection information for TYPO3 CMS 4.x and 6.x
*/
protected const VERSIONS = [
[
'filename' => 'typo3/sysext/core/Classes/Information/Typo3Version.php',
'regexp' => '/VERSION = \'(.*?)\'/',
],
[
'filename' => 'typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php',
'regexp' => '/define\\(\'TYPO3_version\', \'(.*?)\'\\)/',
],
[
'filename' => 't3lib/config_default.php',
'regexp' => '/TYPO_VERSION = \'(.*?)\'/',
],
];
public function match(Filesystem $fs, string $path): MatchResultInterface
{
foreach (self::VERSIONS as $version) {
$versionFile = rtrim($path, '/') . '/' . $version['filename'];
if (!$fs->fileExists($versionFile)) {
continue;
}
if ($version = $this->detectVersion($version['regexp'], $versionFile, $fs)) {
return new MatchResult($path, $version);
}
}
return new EmptyMatchResult();
}
public function detectVersion(string $regexPattern, string $versionFile, Filesystem $fs): ?string
{
try {
preg_match($regexPattern, $fs->read($versionFile), $matches);
return count($matches) > 1 ? $matches[1] : null;
} catch (FilesystemException) {
// ignore file reading problem
return null;
}
}
}

View File

@@ -1,34 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
trait UpLevelMatcherTrait
{
abstract protected function doMatch(Filesystem $fs, string $path): MatchResultInterface;
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$matcher = $this->safeScanDir($fs, $path);
if ($matcher instanceof EmptyMatchResult) {
$matcher = $this->safeScanDir($fs, rtrim($path) . '/../');
}
return $matcher;
}
private function safeScanDir(Filesystem $fs, string $path): MatchResultInterface
{
try {
$result = $this->doMatch($fs, $path);
} catch (FilesystemException) {
// skip dir if it is inaccessible
$result = new EmptyMatchResult();
}
return $result;
}
}

View File

@@ -1,69 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use DOMDocument;
use DOMXPath;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\WebPresenceBuilder as MatchResult;
use Throwable;
class WebPresenceBuilder implements MatcherInterface
{
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$indexHtmlPath = rtrim($path, '/') . '/index.html';
if (!$fs->fileExists($indexHtmlPath)) {
return new EmptyMatchResult();
}
$fileContent = $fs->read($indexHtmlPath);
$inspectorHelper = new InspectorHelper();
return $inspectorHelper->fileContentMatchesString(
$fileContent,
'/<meta name="generator" content="Web Presence Builder.*">/'
) || $this->fileContainsDOMStructure($fileContent)
? new MatchResult($path)
: new EmptyMatchResult();
}
private function fileContainsDOMStructure(string $fileContent): bool
{
$dom = new DOMDocument();
try {
libxml_use_internal_errors(true);
$domIsLoaded = $dom->loadHTML($fileContent);
libxml_clear_errors();
} catch (Throwable) {
return false;
}
if ($domIsLoaded === false) {
return false;
}
$xpath = new DOMXPath($dom);
// Find the <div> with id="page"
$pageDiv = $xpath->query("//div[@id='page']");
if ($pageDiv->length === 0) {
return false;
}
$pageNode = $pageDiv->item(0);
// Check for direct children with the required IDs
$watermarkDiv = $xpath->query("./div[@id='watermark']", $pageNode);
$layoutDiv = $xpath->query("./div[@id='layout']", $pageNode);
return $watermarkDiv->length > 0 && $layoutDiv->length > 0;
}
}

View File

@@ -1,57 +0,0 @@
<?php
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Wordpress as MatchResult;
class Wordpress implements MatcherInterface
{
private const VERSION_FILE = 'wp-includes/version.php';
/**
* @throws FilesystemException
*/
private function detectVersion(Filesystem $fs, string $path): ?string
{
$versionFile = rtrim($path, '/') . '/' . self::VERSION_FILE;
preg_match("/\\\$wp_version\\s*=\\s*'([^']+)'/", $fs->read($versionFile), $matches);
if ($matches !== []) {
return $matches[1];
}
return null;
}
/**
* @throws FilesystemException
*/
private function isWordpress(Filesystem $fs, string $path): bool
{
$versionFile = rtrim($path, '/') . '/' . self::VERSION_FILE;
if (!$fs->fileExists($versionFile)) {
return false;
}
$fileContents = $fs->read($versionFile);
return stripos($fileContents, '$wp_version =') !== false;
}
/**
* @throws FilesystemException
*/
public function match(Filesystem $fs, string $path): MatchResultInterface
{
if (!$this->isWordpress($fs, $path)) {
return new EmptyMatchResult();
}
return new MatchResult($path, $this->detectVersion($fs, $path));
}
}

View File

@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Yii as MatchResult;
class Yii implements MatcherInterface
{
private const VERSIONS = [
[
'file' => 'yii',
'versionFile' => '/vendor/yiisoft/yii2/BaseYii.php',
'versionRegexp' => '/public static function getVersion\(\)\s*\{\s*return \'([^\']+)\';\s*}/',
],
[
'file' => 'framework/yiic',
'versionFile' => '/framework/YiiBase.php',
'versionRegexp' => '/public static function getVersion\(\)\s*\{\s*return \'([^\']+)\';\s*}/',
],
];
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$path = rtrim($path, '/');
foreach (self::VERSIONS as $version) {
if (!$fs->fileExists($path . '/' . $version['file'])) {
continue;
}
return new MatchResult($path, $this->detectVersion($fs, $path, $version));
}
return new EmptyMatchResult();
}
private function detectVersion(Filesystem $fs, string $path, array $versionInfo): ?string
{
$version = null;
$yii2VersionFile = $path . $versionInfo['versionFile'];
if ($fs->fileExists($yii2VersionFile)) {
preg_match($versionInfo['versionRegexp'], $fs->read($yii2VersionFile), $matches);
if (isset($matches[1])) {
$version = $matches[1];
}
}
return $version;
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace Plesk\Wappspector;
use Plesk\Wappspector\Matchers\MatcherInterface;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Throwable;
final class Wappspector
{
/**
* @param callable $fsFactory
*/
public function __construct(private $fsFactory, private array $matchers)
{
}
/**
* @return MatchResultInterface[]
* @throws Throwable
*/
public function run(string $path, string $basePath = '/', int $matchersLimit = 0): iterable
{
$fs = ($this->fsFactory)($basePath);
$result = [];
/** @var MatcherInterface $matcher */
foreach ($this->matchers as $matcher) {
if (($match = $matcher->match($fs, $path)) instanceof EmptyMatchResult) {
continue;
}
$result[] = $match;
if ($matchersLimit > 0 && count($result) >= $matchersLimit) {
break;
}
}
return $result;
}
}

View File

@@ -1,58 +0,0 @@
<?php
use DI\Container;
use Plesk\Wappspector\Command\Inspect;
use Plesk\Wappspector\FileSystemFactory;
use Plesk\Wappspector\Matchers;
use Plesk\Wappspector\Wappspector;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application;
return [
'matchers' => [
Matchers\Wordpress::class,
Matchers\Joomla::class,
Matchers\Drupal::class,
Matchers\Prestashop::class,
Matchers\Typo3::class,
Matchers\Laravel::class,
Matchers\Symfony::class,
Matchers\CodeIgniter::class,
Matchers\CakePHP::class,
Matchers\Yii::class,
Matchers\DotNet::class,
Matchers\Ruby::class,
Matchers\Python::class,
Matchers\NodeJs::class,
Matchers\Sitejet::class,
Matchers\WebPresenceBuilder::class,
Matchers\Sitepro::class,
Matchers\Duda::class,
Matchers\Siteplus::class,
// Low priority wrappers. Should go last.
Matchers\Composer::class,
Matchers\Php::class,
],
Wappspector::class => static function (Container $container): Wappspector {
$matchers = [];
foreach ($container->get('matchers') as $matcher) {
$matchers[] = $container->get($matcher);
}
return new Wappspector($container->get(FileSystemFactory::class), $matchers);
},
Inspect::class => static function (ContainerInterface $container): Inspect {
return new Inspect($container->get(Wappspector::class));
},
Application::class => static function (ContainerInterface $container): Application {
$application = new Application('Wappspector');
$inspectCommand = $container->get(Inspect::class);
$application->add($inspectCommand);
$application->setDefaultCommand($inspectCommand->getName(), true);
return $application;
},
];