-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
use Kirby\CLI\CLI; | ||
use Kirby\Http\Remote; | ||
use Kirby\Http\Url; | ||
use Kirby\Toolkit\I18n; | ||
|
||
return [ | ||
'description' => 'Performs security checks of the site', | ||
'command' => static function (CLI $cli): void { | ||
$kirby = $cli->kirby(); | ||
$system = $kirby->system(); | ||
$updateStatus = $system->updateStatus(); | ||
$messages = [ | ||
...array_column($updateStatus?->messages() ?? [], 'text'), | ||
...$updateStatus->exceptionMessages() | ||
]; | ||
|
||
if ($kirby->option('debug', false) === true) { | ||
$messages[] = I18n::translate('system.issues.debug'); | ||
} | ||
|
||
if ($kirby->environment()->https() !== true) { | ||
$messages[] = I18n::translate('system.issues.https'); | ||
} | ||
|
||
// checks exposable urls of the site | ||
// works only site url is absolute since can't get it in CLI mode | ||
// and CURL won't work for relative urls | ||
if (Url::isAbsolute($kirby->url())) { | ||
$urls = [ | ||
'content' => $system->exposedFileUrl('content'), | ||
'git' => $system->exposedFileUrl('git'), | ||
'kirby' => $system->exposedFileUrl('kirby'), | ||
'site' => $system->exposedFileUrl('site') | ||
]; | ||
|
||
foreach ($urls as $key => $url) { | ||
if (empty($url) === false && Remote::get($url)->code() < 400) { | ||
$messages[] = I18n::translate('system.issues.' . $key); | ||
} | ||
} | ||
} | ||
|
||
if (empty($messages) === false) { | ||
foreach ($messages as $message) { | ||
$cli->error('> ' . $message); | ||
} | ||
} else { | ||
$cli->success('No security warnings were detected'); | ||
} | ||
} | ||
]; |