From 8d13f3397873078a7e420f97fd51b1e55a470b58 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 17 Sep 2024 13:05:20 +0200 Subject: [PATCH] Add /access --- www/.php/credentials.sample.inc | 16 ++ www/access.php | 100 ++++++++++ www/index.xhtml | 4 +- www/res/access-multiple.js | 206 ++++++++++++++++++++ www/res/access-single.js | 331 ++++++++++++++++++++++++++++++++ www/res/access.js | 79 ++++++++ www/res/avatar.png | Bin 0 -> 3941 bytes www/res/style.css | 257 ++++++++++++++++++++++++- 8 files changed, 983 insertions(+), 10 deletions(-) create mode 100644 www/access.php create mode 100644 www/res/access-multiple.js create mode 100644 www/res/access-single.js create mode 100644 www/res/access.js create mode 100644 www/res/avatar.png diff --git a/www/.php/credentials.sample.inc b/www/.php/credentials.sample.inc index 9246a39..766de78 100644 --- a/www/.php/credentials.sample.inc +++ b/www/.php/credentials.sample.inc @@ -2,6 +2,8 @@ global $GITEA_TOKEN; global $CREDENTIALS; global $CLIENT_CREDENTIALS; +global $CLIENT_ACCESS; +global $COMBINED_ACCESS; $GITEA_TOKEN = 'token'; @@ -14,3 +16,17 @@ $CLIENT_CREDENTIALS = [ 'username' => 'password', ], ]; + +$CLIENT_ACCESS = [ + 'WGX' => [ + 'name' => 'Winzergenossenschaft', + 'api' => 'https://example.com/elwig/api/v1', + ], +]; + +$COMBINED_ACCESS = [ + 'HOLDING' => [ + 'name' => 'Name', + 'clients' => ['WGX'], + ], +]; diff --git a/www/access.php b/www/access.php new file mode 100644 index 0000000..092a4fa --- /dev/null +++ b/www/access.php @@ -0,0 +1,100 @@ + $data) { + if ($name === $info[1] && (sizeof($info) === 2 || $info[2] === '')) { + $client = $data; + $client['id'] = $name; + } +} +foreach ($COMBINED_ACCESS as $name => $data) { + if ($name === $info[1] && (sizeof($info) === 2 || $info[2] === '')) { + $client = $data; + $client['id'] = $name; + } +} +if ($_SERVER['PATH_INFO'] !== "/$client[id]/") { + header('Status: 308'); + header("Location: /access/$client[id]/"); + exit(); +} else if ($client === null) { + header('Status: 404'); + header('Content-Length: 0'); + exit(); +} + +if ($client['api']) { + $data = "window.ELWIG_API = \"$client[api]\";"; +} else { + $data = "window.CLIENTS = {"; + $first = true; + foreach ($client['clients'] as $id) { + $c = $CLIENT_ACCESS[$id]; + if (!$first) $data .= ", "; + $data .= "\"$id\": {\"name\": \"$c[name]\", \"short\": \"$c[short]\", \"api\": \"$c[api]\"}"; + $first = false; + } + $data .= "};"; +} + +header('Content-Type: application/xhtml+xml; charset=UTF-8'); +echo "\n"; ?> + + + + <?php echo $client['name']; ?> - Elwig + + + + +