1
0
mirror of https://github.com/typemill/typemill.git synced 2025-07-30 19:00:32 +02:00

Add authorization to version check

This commit is contained in:
trendschau
2023-11-08 23:31:06 +01:00
parent e3815f6315
commit f196a6cba0
2 changed files with 22 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Typemill\Models\Validation;
use Typemill\Static\Translations;
use Typemill\Static\License;
class ControllerApiSystemVersions extends Controller
{
@@ -28,6 +29,7 @@ class ControllerApiSystemVersions extends Controller
$type = $params['type'];
$data = $params['data'];
$url = 'https://typemill.net/api/v1/checkversion';
$url2 = 'http://localhost/typemillPlugins/api/v1/checkversion';
if($type == 'plugins')
{
@@ -48,19 +50,33 @@ class ControllerApiSystemVersions extends Controller
}
$url = 'https://themes.typemill.net/api/v1/getthemes?themes=' . urlencode($themeList);
}
$authstring = License::getPublicKeyPem();
if(!$authstring)
{
$response->getBody()->write(json_encode([
'message' => Translations::translate('Please check if there is a readable file public_key.pem in your settings folder.')
]));
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
$authstring = hash('sha256', substr($authstring, 0, 50));
$opts = array(
'http'=>array(
'method'=>"GET",
'http' => array(
'method' =>"GET",
'ignore_errors' => true,
'timeout' => 5,
'header'=>"Referer: http://typemill-version2.net"
'timeout' => 5,
'header' =>
"Accept: application/json\r\n" .
"Authorization: $authstring\r\n" .
"Connection: close\r\n",
)
);
$context = stream_context_create($opts);
$versions = file_get_contents($url, false, $context);
$versions = file_get_contents($url2, false, $context);
$versions = json_decode($versions, true);
$updateVersions = [];

View File

@@ -160,7 +160,7 @@ class License
$authstring = $this->getPublicKeyPem();
$authstring = hash('sha256', substr($authstring, 0, 50));
$options = array (
'http' => array (
'method' => 'POST',