From 7dee3a175a41a602fc13520a22a135f9a203ab9b Mon Sep 17 00:00:00 2001 From: LogMANOriginal Date: Thu, 9 Aug 2018 19:14:10 +0200 Subject: [PATCH] [index] Add '?action=list' to list bridges (#493) Adds a new action '?action=list' to return a list of bridges as JSON formatted text. Each bridge brings following information: - status (active/inactive) - uri - name - parameters - maintainer - description For inactive bridges only the status is returned. Bridges that cannot be instantiated are considered inactive. --- index.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index e281b01..f141d49 100644 --- a/index.php +++ b/index.php @@ -99,7 +99,46 @@ try { $action = array_key_exists('action', $params) ? $params['action'] : null; $bridge = array_key_exists('bridge', $params) ? $params['bridge'] : null; - if($action === 'display' && !empty($bridge)) { + // Return list of bridges as JSON formatted text + if($action === 'list') { + + $list = new StdClass(); + $list->bridges = array(); + $list->total = 0; + + foreach(Bridge::listBridges() as $bridgeName) { + + $bridge = Bridge::create($bridgeName); + + if($bridge === false) { // Broken bridge, show as inactive + + $list->bridges[$bridgeName] = array( + 'status' => 'inactive' + ); + + continue; + + } + + $status = Bridge::isWhitelisted($whitelist_selection, strtolower($bridgeName)) ? 'active' : 'inactive'; + + $list->bridges[$bridgeName] = array( + 'status' => $status, + 'uri' => $bridge->getURI(), + 'name' => $bridge->getName(), + 'parameters' => $bridge->getParameters(), + 'maintainer' => $bridge->getMaintainer(), + 'description' => $bridge->getDescription() + ); + + } + + $list->total = count($list->bridges); + + header('Content-Type: application/json'); + echo json_encode($list, JSON_PRETTY_PRINT); + + } elseif($action === 'display' && !empty($bridge)) { // DEPRECATED: 'nameBridge' scheme is replaced by 'name' in bridge parameter values // this is to keep compatibility until futher complete removal if(($pos = strpos($bridge, 'Bridge')) === (strlen($bridge) - strlen('Bridge'))) {