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