ttrss/classes/pluginhandler.php

30 lines
958 B
PHP
Raw Normal View History

2012-12-23 11:52:18 +01:00
<?php
class PluginHandler extends Handler_Protected {
function csrf_ignore(string $method): bool {
2012-12-23 11:52:18 +01:00
return true;
}
function catchall(string $method): void {
2019-08-16 14:29:24 +02:00
$plugin_name = clean($_REQUEST["plugin"]);
$plugin = PluginHost::getInstance()->get_plugin($plugin_name);
$csrf_token = ($_POST["csrf_token"] ?? "");
2012-12-23 11:52:18 +01:00
2013-03-16 09:26:14 +01:00
if ($plugin) {
if (method_exists($plugin, $method)) {
if (validate_csrf($csrf_token) || $plugin->csrf_ignore($method)) {
$plugin->$method();
} else {
user_error("Rejected {$plugin_name}->{$method}(): invalid CSRF token.", E_USER_WARNING);
print Errors::to_json(Errors::E_UNAUTHORIZED);
}
2013-03-16 09:26:14 +01:00
} else {
user_error("Rejected {$plugin_name}->{$method}(): unknown method.", E_USER_WARNING);
print Errors::to_json(Errors::E_UNKNOWN_METHOD);
2013-03-16 09:26:14 +01:00
}
} else {
user_error("Rejected {$plugin_name}->{$method}(): unknown plugin.", E_USER_WARNING);
print Errors::to_json(Errors::E_UNKNOWN_PLUGIN);
2012-12-23 11:52:18 +01:00
}
}
}