"; echo "

" . $status . "


" . $message . "
" . $action . "
"; $errorShown = true; } $apiKey = $_GET['apikey']; if ($_GET['debug']) { $debug = $_GET['debug']; } if ($debug) { $apiErrorsFile = file_get_contents ("../config/puzzlemap.apiErrors.json"); } else { $apiErrorsFile = file_get_contents ("./config/puzzlemap.apiErrors.json"); } $apiErrors = json_decode ($apiErrorsFile, true); $load = true; $instanceID = uniqid(); $referrer = $_SERVER['HTTP_REFERER']; $loadFailMessage = ""; $puzzleFile = ''; $projection = "3857"; $baseMap = ''; $spheraRoot = "https://www.spheraware.com/"; $loadLocal = false; $minZoom = "false"; $maxZoom = "false"; $configLocation = ""; $customCSS = []; $domainWhitelist = []; $whitelistString = ""; $userID = ""; $ip = $_SERVER['REMOTE_ADDR']; if (isset ($_GET["userid"])) { $userID = $_GET["userid"]; } // Load the correct API key file. if ($debug) { require ($_SERVER['DOCUMENT_ROOT'] . '/sandbox/puzzlemap/dist/api-keys.php'); } else { require ($_SERVER['DOCUMENT_ROOT'] . '/spherapps/puzzlemap/api-keys.php'); } // Enforce domain restrictions if (count ($domainWhitelist) > 0) { $uri = parse_url($_SERVER['HTTP_REFERER']); if ($uri) { $load = false; foreach ($domainWhitelist as $domain) { if (strpos(strtolower($uri['host']), strtolower($domain)) > 0) { $load = true; break; } } if (!$load) generateMessage ($apiErrors["DomainRestriction"]); } } /* // Enforce domain restrictions if (count ($domainWhitelist) > 0) { $load = false; $uri = parse_url($_SERVER['HTTP_REFERER']); $clientDomain = str_replace("www.","",$uri['host']); foreach ($domainWhitelist as $domain) { if ($domain == $clientDomain) $load = true; } if (!$load) generateMessage ($apiErrors["DomainRestriction"]); } // Enforce license / evaluation / user restrictions $conn = pg_connect("host=services.spheraware.net dbname=spheraware user=stats password=0e162ebb3f1112e18090a600e7a9551a"); if (!$conn) { $load = false; generateMessage ($apiErrors["Default"]); } else { if (strpos(strtolower($referrer), 'puzzlemap.fun') !== false) { $queryString = "select webstats.sph_eval_status('puzzlemap', '" . $apiKey . "', '". $ip . "','" . $userID . "')"; $result = @pg_query ($conn, $queryString); if (!$result) { $load = false; generateMessage ($apiErrors["Default"]); } else { $evalResponse = pg_fetch_result ($result,0); if ($evalResponse == "OVER-USED") { $load = false; generateMessage ($apiErrors["OverUsed"]); } else if ($evalResponse == "EXPIRED") { $load = false; generateMessage ($apiErrors["ExpiredEval"]); } } } } */ // If no errors were encountered, begin loading PuzzleMap. if ($load) { $zoomObject = '{"minZoom":"' . $minZoom . '","maxZoom":"' . $maxZoom . '"}'; echo ""; echo ''; echo ''; echo ''; $env = 'production'; $loadDependenciesFile = $_SERVER['DOCUMENT_ROOT'] . '/spherapps/puzzlemap/load-dependencies.php'; $loadAPIFile = $_SERVER['DOCUMENT_ROOT'] . '/spherapps/puzzlemap/load-api.php'; $loadDOMFile = $_SERVER['DOCUMENT_ROOT'] . '/spherapps/puzzlemap/load-dom.php'; if ($debug) { $env = 'sandbox'; $loadDependenciesFile = $_SERVER['DOCUMENT_ROOT'] . '/sandbox/puzzlemap/dist/load-dependencies.php'; $loadAPIFile = $_SERVER['DOCUMENT_ROOT'] . '/sandbox/puzzlemap/dist/load-api.php'; $loadDOMFile = $_SERVER['DOCUMENT_ROOT'] . '/sandbox/puzzlemap/dist/load-dom.php'; } require $loadDependenciesFile; if (count($customCSS)) { foreach ($customCSS as $cssFile) { echo ''; } } checkConfigs ($debug, $configLocation); require $loadAPIFile; echo ""; echo ""; /* Calls the stats logger */ $stats = 'action=logTraffic' . '&object=PuzzleMap' . '&hittype=embedload' . '&user=' . $userID . '&ip=' . $_SERVER['REMOTE_ADDR'] . '&referrer=' . $referrer. '&useragent=' . $_SERVER['HTTP_USER_AGENT'] . '&comment=Embedded load of puzzle ' . $puzzleFile . ' using API key ' . $apiKey; $stats = str_replace("\n", "", $stats); $stats = str_replace(" ", "", $stats); $stats = str_replace(" ", "+", $stats); file_get_contents('https://www.spheraware.com/spherapps/stats/log-stats.php?' . $stats); if ($loadLocal) { $rootURL = substr($referrer, 0, strrpos($referrer, '/')) . "/" . $puzzleFile; } else { $rootURL = $puzzleFile; } // Load a language-specific pzm, if english is not used $lang = strval($_GET["lang"]); $puzzlemapLanguage = ""; if (!empty($lang)) { $puzzlemapLanguage = $lang; $potentialRootURL = str_replace (".pzm", "." . $lang . ".pzm", $rootURL); if (remote_file_exists ($potentialRootURL)) { $rootURL = $potentialRootURL; } } $projFrom = 3857; if (!empty($projectionFrom)) { $projFrom = $projectionFrom; } $projTo = 3857; if (!empty($projectionTo)) { $projTo = $projectionTo; } ?> "; } else { // The switch statement in the API keys file sets 'load' to false if the API key is not found. // We thus enter this code block. generateMessage ($apiErrors["InvalidAPIKey"]); $stats = 'action=logTraffic' . '&object=PuzzleMap' . '&hittype=embedload' . '&ip=' . $ip . '&referrer=' . $_SERVER['HTTP_REFERER'] . '&useragent=' . $_SERVER['HTTP_USER_AGENT'] . '&comment=Unauthorized attempt using API key ' . $apiKey; $stats = str_replace("\n", "", $stats); $stats = str_replace(" ", "", $stats); $stats = str_replace(" ", "+", $stats); file_get_contents('https://www.spheraware.com/spherapps/stats/log-stats.php?' . $stats); } ?>