diff options
author | Simon Rettberg | 2022-11-22 17:11:06 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-11-22 17:11:06 +0100 |
commit | 4f6e34bc5aa07285dd4d28ee34c483c8b7fbd89a (patch) | |
tree | 2bcbba1e518f779346ec1a2dd541891a056951dd | |
parent | [pam] Support browser-based login (diff) | |
download | bwlp-webadmin-4f6e34bc5aa07285dd4d28ee34c483c8b7fbd89a.tar.gz bwlp-webadmin-4f6e34bc5aa07285dd4d28ee34c483c8b7fbd89a.tar.xz bwlp-webadmin-4f6e34bc5aa07285dd4d28ee34c483c8b7fbd89a.zip |
api: Refactor supplying satellite list to user
-rw-r--r-- | shib/api.php | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/shib/api.php b/shib/api.php index 533ae78..38b2d7a 100644 --- a/shib/api.php +++ b/shib/api.php @@ -20,6 +20,24 @@ function slxAutoloader($class) } spl_autoload_register('slxAutoloader'); +function getSatelliteList($orgId) +{ + // Determine satellite(s) + $res = Database::simpleQuery("SELECT satellitename, addresses, certsha256 FROM satellite" + . " WHERE organizationid = :organizationid AND userid IS NULL", array('organizationid' => $orgId)); + $sat2 = array(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $addrs = json_decode($row['addresses'], true); + if (!is_array($addrs) || empty($addrs)) + continue; + $sat2[$row['satellitename']] = array( + 'addresses' => $addrs, + 'certHash' => $row['certsha256'] + ); + } + return $sat2; +} + $response = array(); if (empty($_SERVER['persistent-id'])) { @@ -95,12 +113,9 @@ if (empty($_SERVER['persistent-id'])) { // This one we send to the running master server handler $rpc = $response; $rpc['role'] = $role; - // This one we only send to the user - // TODO - /* - $response['satellites'] = $sat1; - $response['satellites2'] = $sat2; - */ + if (isset($response['organizationId'])) { + $response['satellites2'] = getSatelliteList($response['organizationId']); + } } else { $response['status'] = 'unregistered'; } @@ -125,21 +140,6 @@ if (empty($_SERVER['persistent-id'])) { $response['status'] = 'anonymous'; } else { // Seems ok! - // Determine satellite(s) - $res = Database::simpleQuery("SELECT satellitename, addresses, certsha256 FROM satellite" - . " WHERE organizationid = :organizationid AND userid IS NULL", array('organizationid' => $user['organizationid'])); - $sat1 = array(); // Legacy - $sat2 = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $addrs = json_decode($row['addresses'], true); - if (!is_array($addrs) || empty($addrs)) - continue; - $sat1[$row['satellitename']] = $addrs[0]; - $sat2[$row['satellitename']] = array( - 'addresses' => $addrs, - 'certHash' => $row['certsha256'] - ); - } // $response['status'] = 'ok'; $response['firstName'] = $firstName; @@ -152,8 +152,7 @@ if (empty($_SERVER['persistent-id'])) { $rpc['userId'] = $login; $rpc['role'] = $role; // This one we only send to the user - $response['satellites'] = $sat1; - $response['satellites2'] = $sat2; + $response['satellites2'] = getSatelliteList($user['organizationid']); } } } |