From 959e4ad698326bfd90065bb4519b87ac4af54f89 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 16 May 2021 17:12:15 -0600 Subject: [PATCH] Serve HTML if available when no endpoint sent or endpoint not found --- index.php | 32 +++++++++++++------- publicsite/index.html | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 publicsite/index.html diff --git a/index.php b/index.php index 6a690cb..14457fb 100644 --- a/index.php +++ b/index.php @@ -82,20 +82,32 @@ if (count($route) > 0 && strpos($route[count($route) - 1], "?") === 0) { } } -// Deny access if authenticator returns false (add your logic to authenticator.php) -if (!authenticaterequest()) { - http_response_code(401); - die("401 Unauthorized: You need to supply valid credentials."); -} - if (empty($ENDPOINT)) { - http_response_code(404); - die("404 No endpoint specified."); + if (file_exists(__DIR__ . "/publicsite/index.html")) { + http_response_code(200); + header("Content-Type: text/html"); + exit(file_get_contents(__DIR__ . "/publicsite/index.html")); + } else { + http_response_code(404); + die("404 No endpoint specified."); + } } if (!isset($APIS[$ENDPOINT])) { - http_response_code(404); - die("404 Requested endpoint not known."); + if (preg_match("/[a-zA-Z0-9_\-]+/", $ENDPOINT) === 1 && file_exists(__DIR__ . "/publicsite/$ENDPOINT.html")) { + http_response_code(200); + header("Content-Type: text/html"); + exit(file_get_contents(__DIR__ . "/publicsite/$ENDPOINT.html")); + } else { + http_response_code(404); + die("404 Requested endpoint not known."); + } +} + +// Deny access if authenticator returns false (add your logic to authenticator.php) +if (!authenticaterequest()) { + http_response_code(401); + die("401 Unauthorized: You need to supply valid credentials."); } $APIENDPOINTCONFIG = $APIS[$ENDPOINT]; diff --git a/publicsite/index.html b/publicsite/index.html new file mode 100644 index 0000000..afce948 --- /dev/null +++ b/publicsite/index.html @@ -0,0 +1,69 @@ + + + + Data Server + + + + + +
+
+
+
+
+ +
+
+
+

Netsyms Technologies

+

Data and API Server

+
+
+
+
+
+ +
+
+

This server is not for public use except when accessed via software and apps + released by Netsyms Technologies. Do not use these APIs in other ways + without express permission. +

+

+ Source code for this subdomain is available for you to use on your own + server with your own third-party API keys. + Get the Code +

+
+
+ +
+
+
+
+

/gis: Earth, Weather, and Mapping

+
    +
  • geocode/reverse/?latitude=23.45&longitude=32.12
  • +
  • weather/?latitude=23.45&longitude=32.12
  • +
+
+
+
+
+ +
+
+
+
+

/net: Network and Internet

+
    +
  • whois/?domain=ntsm.io
  • +
+
+
+
+
+
+ +