Tons of changes, enforce valid login for some API actions
parent
02f50b551d
commit
1c356dbe87
@ -1,2 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,39 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
|
|
||||||
$okapi = "http://opencaching.us/okapi/";
|
$okapi = "http://opencaching.us/okapi/";
|
||||||
|
|
||||||
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
|
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
|
||||||
sendError("Missing information.", true);
|
sendError("Missing information.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) {
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) {
|
||||||
sendError("Latitude (lat) is in the wrong format.", true);
|
sendError("Latitude (lat) is in the wrong format.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) {
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) {
|
||||||
sendError("Longitude (long) is in the wrong format.", true);
|
sendError("Longitude (long) is in the wrong format.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$lat = $VARS['lat'];
|
$lat = $VARS['lat'];
|
||||||
$long = $VARS['long'];
|
$long = $VARS['long'];
|
||||||
|
|
||||||
$limit = 25;
|
$limit = 25;
|
||||||
if (!is_empty($VARS['limit']) && is_numeric($VARS['limit'])) {
|
if (!is_empty($VARS['limit']) && is_numeric($VARS['limit'])) {
|
||||||
$limit = intval($VARS['limit']);
|
$limit = intval($VARS['limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = file_get_contents($okapi . "services/caches/search/nearest?center=" . $lat . "|" . $long . "&limit=" . $limit . "&consumer_key=" . GEOCACHE_KEY);
|
$json = file_get_contents($okapi . "services/caches/search/nearest?center=" . $lat . "|" . $long . "&limit=" . $limit . "&consumer_key=" . GEOCACHE_KEY);
|
||||||
|
|
||||||
if (!$json)
|
if (!$json)
|
||||||
sendError("Something went wrong, try again later.", true);
|
sendError("Something went wrong, try again later.", true);
|
||||||
|
|
||||||
$caches = json_decode($json)->results;
|
$caches = json_decode($json)->results;
|
||||||
|
|
||||||
$list = "";
|
$list = "";
|
||||||
foreach ($caches as $val) {
|
foreach ($caches as $val) {
|
||||||
$list .= $val . "|";
|
$list .= $val . "|";
|
||||||
}
|
}
|
||||||
echo file_get_contents($okapi . "services/caches/geocaches?consumer_key=" . GEOCACHE_KEY . "&cache_codes=" . rtrim($list, "|"));
|
echo file_get_contents($okapi . "services/caches/geocaches?consumer_key=" . GEOCACHE_KEY . "&cache_codes=" . rtrim($list, "|"));
|
||||||
|
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require/include this to make login required.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($_SESSION['loggedin'] != true) {
|
||||||
|
sendError('SESSION EXPIRED: Please reauthenticate.', true);
|
||||||
|
}
|
@ -1,8 +1,105 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Takes the latitude and longitude and gets nearby places from OSM.
|
||||||
* To change this template file, choose Tools | Templates
|
*
|
||||||
* and open the template in the editor.
|
* Uses WGS84 in the DD.DD format, because I say so.
|
||||||
*/
|
*/
|
||||||
|
require 'required.php';
|
||||||
|
|
||||||
|
$placebase;
|
||||||
|
try {
|
||||||
|
$placebase = new medoo([
|
||||||
|
'database_type' => PDB_TYPE,
|
||||||
|
'database_name' => PDB_NAME,
|
||||||
|
'server' => PDB_SERVER,
|
||||||
|
'username' => PDB_USER,
|
||||||
|
'password' => PDB_PASS,
|
||||||
|
'charset' => PDB_CHARSET
|
||||||
|
]);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
|
sendError('Location database error. Try again later.', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
||||||
|
|
||||||
|
if (is_empty($VARS['lat'])) {
|
||||||
|
sendError("Missing required latitude (lat) variable.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_empty($VARS['long'])) {
|
||||||
|
sendError("Missing required longitude (long) variable.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['lat'])) {
|
||||||
|
sendError("Latitude (lat) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['long'])) {
|
||||||
|
sendError("Longitude (long) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lat = number_format((float) $VARS['lat'], 5, '.', '');
|
||||||
|
$long = number_format((float) $VARS['long'], 5, '.', '');
|
||||||
|
|
||||||
|
$radius = 5;
|
||||||
|
if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
|
||||||
|
$radius = floatval($VARS['radius']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
|
||||||
|
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
|
||||||
|
|
||||||
|
if (is_empty($VARS['names'])) {
|
||||||
|
$places = $placebase->select('places', '*', ['AND' => [
|
||||||
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
||||||
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
||||||
|
"LIMIT" => 100
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$places = $placebase->select('places', '*', ['AND' => [
|
||||||
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
||||||
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
||||||
|
'name[!]' => ''],
|
||||||
|
"LIMIT" => 100
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$data['status'] = 'OK';
|
||||||
|
$data['places'] = $places;
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
$geo['name'] = "Places";
|
||||||
|
$geo['type'] = 'FeatureCollection';
|
||||||
|
$geo['features'] = [];
|
||||||
|
foreach ($places as $place) {
|
||||||
|
if (!$database->has('locations', ['osmid' => $place['osmid']])) {
|
||||||
|
$database->insert('locations', ['osmid' => $place['osmid'], 'teamid' => 0]);
|
||||||
|
}
|
||||||
|
$gameinfo = $database->select('locations', ['teamid', 'owneruuid'], ['osmid' => $place['osmid']])[0];
|
||||||
|
$geo['features'][] = array("type" => "Feature",
|
||||||
|
"geometry" => [
|
||||||
|
"type" => "Point",
|
||||||
|
"coordinates" => [
|
||||||
|
floatval($place['longitude']),
|
||||||
|
floatval($place['latitude'])
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"properties" => [
|
||||||
|
"osm_id" => intval($place['osmid']),
|
||||||
|
"name" => ($place['name'] == '' ? null : $place['name']),
|
||||||
|
"name:en" => ($place['name'] == '' ? null : $place['name']),
|
||||||
|
"amenity" => ($place['amenity'] == '' ? null : $place['amenity']),
|
||||||
|
"historic" => ($place['historic'] == '' ? null : $place['historic']),
|
||||||
|
"tourism" => ($place['tourism'] == '' ? null : $place['tourism']),
|
||||||
|
"gameinfo" => ['teamid' => $gameinfo['teamid'], 'owneruuid' => $gameinfo['owneruuid']]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo json_encode($geo);
|
@ -1,74 +1,75 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains global settings and things that should be loaded at the
|
* This file contains global settings and things that should be loaded at the
|
||||||
* top of each file.
|
* top of each file.
|
||||||
*/
|
*/
|
||||||
ob_start();
|
ob_start();
|
||||||
|
session_start();
|
||||||
header("Access-Control-Allow-Origin: *");
|
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
if (strtolower($_GET['format']) == 'plain') {
|
|
||||||
define("JSON", false);
|
if (strtolower($_GET['format']) == 'plain') {
|
||||||
header('Content-Type: text/plain');
|
define("JSON", false);
|
||||||
} else {
|
header('Content-Type: text/plain');
|
||||||
define("JSON", true);
|
} else {
|
||||||
header('Content-Type: application/json');
|
define("JSON", true);
|
||||||
}
|
header('Content-Type: application/json');
|
||||||
|
}
|
||||||
// Composer
|
|
||||||
require 'vendor/autoload.php';
|
// Composer
|
||||||
// API response formatters
|
require 'vendor/autoload.php';
|
||||||
require 'response.php';
|
// API response formatters
|
||||||
// Settings file
|
require 'response.php';
|
||||||
require 'settings.php';
|
// Settings file
|
||||||
|
require 'settings.php';
|
||||||
// Database settings
|
|
||||||
// Also inits database and stuff
|
// Database settings
|
||||||
$database;
|
// Also inits database and stuff
|
||||||
try {
|
$database;
|
||||||
$database = new medoo([
|
try {
|
||||||
'database_type' => DB_TYPE,
|
$database = new medoo([
|
||||||
'database_name' => DB_NAME,
|
'database_type' => DB_TYPE,
|
||||||
'server' => DB_SERVER,
|
'database_name' => DB_NAME,
|
||||||
'username' => DB_USER,
|
'server' => DB_SERVER,
|
||||||
'password' => DB_PASS,
|
'username' => DB_USER,
|
||||||
'charset' => DB_CHARSET
|
'password' => DB_PASS,
|
||||||
]);
|
'charset' => DB_CHARSET
|
||||||
} catch (Exception $ex) {
|
]);
|
||||||
header('HTTP/1.1 500 Internal Server Error');
|
} catch (Exception $ex) {
|
||||||
sendError('Database error. Try again later.', true);
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
}
|
sendError('Database error. Try again later.', true);
|
||||||
|
}
|
||||||
// Show errors and stuff?
|
|
||||||
define("DEBUG", false);
|
// Show errors and stuff?
|
||||||
|
define("DEBUG", false);
|
||||||
// Use POST instead of GET?
|
|
||||||
if (!is_empty($_GET['post']) && $_GET['post'] == '1') {
|
// Use POST instead of GET?
|
||||||
define("GET", false);
|
if (!is_empty($_GET['post']) && $_GET['post'] == '1') {
|
||||||
} else {
|
define("GET", false);
|
||||||
define("GET", true);
|
} else {
|
||||||
}
|
define("GET", true);
|
||||||
|
}
|
||||||
|
|
||||||
if (!DEBUG) {
|
|
||||||
error_reporting(0);
|
if (!DEBUG) {
|
||||||
} else {
|
error_reporting(0);
|
||||||
error_reporting(E_ALL);
|
} else {
|
||||||
ini_set('display_errors', 'On');
|
error_reporting(E_ALL);
|
||||||
}
|
ini_set('display_errors', 'On');
|
||||||
$VARS;
|
}
|
||||||
if (GET) {
|
$VARS;
|
||||||
$VARS = $_GET;
|
if (GET) {
|
||||||
} else {
|
$VARS = $_GET;
|
||||||
$VARS = $_POST;
|
} else {
|
||||||
}
|
$VARS = $_POST;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Checks if a string or whatever is empty.
|
/**
|
||||||
* @param $str The thingy to check
|
* Checks if a string or whatever is empty.
|
||||||
* @return boolean True if it's empty or whatever.
|
* @param $str The thingy to check
|
||||||
*/
|
* @return boolean True if it's empty or whatever.
|
||||||
function is_empty($str) {
|
*/
|
||||||
return (!isset($str) || $str == '' || $str == null);
|
function is_empty($str) {
|
||||||
}
|
return (!isset($str) || $str == '' || $str == null);
|
||||||
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
User-agent: *
|
User-agent: *
|
||||||
|
Disallow: /
|
||||||
|
Reference in New Issue