pluginhandler: better error reporting for incorrect usage

master
Andrew Dolgov 5 years ago
parent 865c54abcb
commit e53cd12ffd

@ -1203,30 +1203,30 @@ class Handler_Public extends Handler {
public function pluginhandler() { public function pluginhandler() {
$host = new PluginHost(); $host = new PluginHost();
$plugin = basename(clean($_REQUEST["plugin"])); $plugin_name = clean_filename($_REQUEST["plugin"]);
$method = clean($_REQUEST["pmethod"]); $method = clean($_REQUEST["pmethod"]);
$host->load($plugin, PluginHost::KIND_USER, 0); $host->load($plugin_name, PluginHost::KIND_USER, 0);
$host->load_data(); $host->load_data();
$pclass = $host->get_plugin($plugin); $plugin = $host->get_plugin($plugin_name);
if ($pclass) { if ($plugin) {
if (method_exists($pclass, $method)) { if (method_exists($plugin, $method)) {
if ($pclass->is_public_method($method)) { if ($plugin->is_public_method($method)) {
$pclass->$method(); $plugin->$method();
} else { } else {
user_error("pluginhandler: Requested private method '$method' of plugin '$plugin'."); user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.");
header("Content-Type: text/json"); header("Content-Type: text/json");
print error_json(6); print error_json(6);
} }
} else { } else {
user_error("pluginhandler: Requested unknown method '$method' of plugin '$plugin'."); user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.");
header("Content-Type: text/json"); header("Content-Type: text/json");
print error_json(13); print error_json(13);
} }
} else { } else {
user_error("pluginhandler: Requested method '$method' of unknown plugin '$plugin'."); user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.");
header("Content-Type: text/json"); header("Content-Type: text/json");
print error_json(14); print error_json(14);
} }

@ -5,15 +5,18 @@ class PluginHandler extends Handler_Protected {
} }
function catchall($method) { function catchall($method) {
$plugin = PluginHost::getInstance()->get_plugin(clean($_REQUEST["plugin"])); $plugin_name = clean($_REQUEST["plugin"]);
$plugin = PluginHost::getInstance()->get_plugin($plugin_name);
if ($plugin) { if ($plugin) {
if (method_exists($plugin, $method)) { if (method_exists($plugin, $method)) {
$plugin->$method(); $plugin->$method();
} else { } else {
user_error("PluginHandler: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING);
print error_json(13); print error_json(13);
} }
} else { } else {
user_error("PluginHandler: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING);
print error_json(14); print error_json(14);
} }
} }

Loading…
Cancel
Save