protected-resources-list/plugins/api/API.php

26 lines
582 B
PHP

<?php
class API extends Plugin
{
public function onInit(PluginContext $context): void
{
parent::onInit($context);
if (!isset($this->config["key"])) {
$this->config["key"] = sha1(rand() . uniqid());
$this->context->getConfig()->save();
}
$headers = getallheaders();
if ($headers and isset($headers["X-Auth"]) and $headers["X-Auth"] == md5($this->config["key"])) {
$_SESSION["auth"] = true;
}
}
public function getKey(): string
{
return $this->config["key"];
}
}