From 7e5ff77002157f9ce4ea367e5b8d0bfd4908dce7 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 10 Nov 2015 08:55:11 +0100 Subject: [PATCH] (auth) add dropKey to api handler --- .../mvc/app/library/OPNsense/Auth/API.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/opnsense/mvc/app/library/OPNsense/Auth/API.php b/src/opnsense/mvc/app/library/OPNsense/Auth/API.php index f8855f62f..78c369e37 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Auth/API.php +++ b/src/opnsense/mvc/app/library/OPNsense/Auth/API.php @@ -91,6 +91,33 @@ class API implements IAuthConnector return null; } + /** + * remove user api key + * @param string $username username + * @param string $apikey api key + * @return bool key found + */ + public function dropKey($username, $apikey) + { + $configObj = Config::getInstance()->object(); + foreach ($configObj->system->children() as $key => $value) { + if ($key == 'user' && (string)$username == (string)$value->name) { + if (isset($value->apikeys)) { + $indx=0; + foreach ($value->apikeys->children() as $apiNodeId => $apiNode) { + if ($apiNodeId == 'item' && (string)$apiNode->key == $apikey) { + unset($value->apikeys->item[$indx]); + Config::getInstance()->save(); + return true; + } + $indx++; + } + } + } + } + return false; + } + /** * authenticate user against local database (in config.xml) * @param string $username username to authenticate