diff --git a/511.html b/511.html index 514f076..97a3eba 100644 --- a/511.html +++ b/511.html @@ -83,7 +83,7 @@ var table = new Tabulator("#wunderobs", { virtualDom: true, virtualDomBuffer: 300, - ajaxURL: "lsr.php?getCombinedTable=p", + ajaxURL: "main.php?service=lsr&getCombinedTable=p", ajaxConfig: "GET", autoResize: true, initialSort: [{ column: "start", dir: "desc" }], @@ -181,7 +181,7 @@ function lsr(lsr, id, source) { $.get({ - url: 'lsr.php?updater=true&lsr=' + lsr + "&id=" + id + "&table="+source, + url: 'main.php?service=lsr&updater=true&lsr=' + lsr + "&id=" + id + "&table="+source, error: function(xhr, error) { alert('Unable to update, please refresh page'); } @@ -195,7 +195,7 @@ function hide(hide, id, source) { $.get({ - url: 'lsr.php?updater=true&hide=' + hide + "&id=" + id + "&table="+source, + url: 'main.php?service=lsr&updater=true&hide=' + hide + "&id=" + id + "&table="+source, error: function(xhr, error) { alert('Unable to update, please refresh page'); } diff --git a/API_DOCUMENTATION.md b/API_DOCUMENTATION.md new file mode 100644 index 0000000..bb98e35 --- /dev/null +++ b/API_DOCUMENTATION.md @@ -0,0 +1,278 @@ +# Unified API Gateway Documentation + +## Overview +This API gateway serves as a single entry point for all API services that were previously separate PHP scripts. Each service is accessed via a `service` parameter that routes the request to the appropriate functionality. + +## Base URL +``` +main.php?service={service_name}[¶meters] +``` + +## Available Services + +### 1. cams +**Description**: Returns active camera information +**Usage**: `main.php?service=cams` +**Parameters**: None required +**Migration**: +- Old: `cam.php` +- New: `main.php?service=cams` + +### 2. camapi +**Description**: Returns camera API endpoints with filtering +**Usage**: `main.php?service=camapi[&cams&lat1={lat}&lon1={lon}&lat2={lat}&lon2={lon}&elevbottom={elev}&elevtop={elev}]` +**Parameters**: +- `cams` - Get RTSP cameras +- `lat1, lon1, lat2, lon2` - Bounding box coordinates +- `elevbottom, elevtop` - Elevation range +- `camstatic` - Get cameras near a point (requires `lat1`, `lon1`, `radius`) +- `camdb` - Get camera count +**Migration**: +- Old: `camapi.php?cams&lat1=...&lon1=...&lat2=...&lon2=...` +- New: `main.php?service=camapi&cams&lat1=...&lon1=...&lat2=...&lon2=...` + +### 3. camlist +**Description**: Returns camera list with active status +**Usage**: `main.php?service=camlist` +**Parameters**: None required +**Migration**: +- Old: `camlist.php` +- New: `main.php?service=camlist` + +### 4. admin +**Description**: Admin operations for cameras +**Usage**: `main.php?service=admin&action={action}` +**Parameters**: +- `action='checkurl'` - Check if URL exists (POST required) +- `action='newcam'` - Add new camera (POST required) +**Migration**: +- Old: `admin.php?action=checkurl` +- New: `main.php?service=admin&action=checkurl` + +### 5. camcircle +**Description**: Returns camera coverage circles +**Usage**: `main.php?service=camcircle` +**Parameters**: None required +**Migration**: +- Old: `camcircle.php` +- New: `main.php?service=camcircle` + +### 6. db +**Description**: Returns weather station data +**Usage**: `main.php?service=db[&outside]` +**Parameters**: +- `outside` - Get outside weather data +**Migration**: +- Old: `db.php` +- New: `main.php?service=db` +- Old: `db.php?outside` +- New: `main.php?service=db&outside` + +### 7. fire +**Description**: Returns fire information +**Usage**: `main.php?service=fire` +**Parameters**: None required +**Migration**: +- Old: `fire.php` +- New: `main.php?service=fire` + +### 8. individualcam +**Description**: Returns individual camera images +**Usage**: `main.php?service=individualcam&camid={camid}[&dtg={datetime}&camimages={count}]` +**Parameters**: +- `camid` - Camera ID (required) +- `dtg` - Date/time to get images before +- `camimages` - Number of images to return (default: 20) +**Migration**: +- Old: `individualcam.php?camid=...` +- New: `main.php?service=individualcam&camid=...` + +### 9. lsr +**Description**: Returns local storm reports and related data +**Usage**: `main.php?service=lsr[&{various parameters}]` +**Parameters**: +- No parameters - Get all reports +- `ohgo` - Get Ohio traffic data +- `ohgotable` - Get Ohio traffic table data +- `lsrohgo`, `ohgohide` - Update records +- `vtec` - Get data for specific VTEC code +- `preflagreports` - Get pre-flagged reports +- `reports` - Get reports within polygon +- `outages` - Get power outages within polygon +- `rtcad` - Get real-time CAD reports +- `verify` - Get verification reports +- `stats` - Get statistics +- `metars` - Get METARs +- `news` - Get news data +- `news2` - Get news data (version 2) +- `news3` - Get news data (version 3) +- `wv511`, `ky511` - Get state traffic data +- `getCombinedTable` - Get combined traffic data +- `updater` - Update records +**Migration**: +- Old: `lsr.php` +- New: `main.php?service=lsr` +- Old: `lsr.php?ohgo` +- New: `main.php?service=lsr&ohgo` + +### 10. nws +**Description**: Returns NWS personnel stats +**Usage**: `main.php?service=nws[&{various parameters}]` +**Parameters**: +- No parameters - Get all NWS data +- `officestats`, `officestats11`, `regionstats`, `drilldown` - Various statistics +- `datetime` - Date for statistics +**Migration**: +- Old: `nws.php` +- New: `main.php?service=nws` + +### 11. powerapi +**Description**: Returns power outage information +**Usage**: `main.php?service=powerapi[&{various parameters}]` +**Parameters**: +- No parameters - Get current power outages +- `states` - Get state boundaries +- `max` - Get max outages (requires `start` and `end`) +- `county` - Get county power outages +- `countyarchive` - Get archived county outages (requires `start` and `end`) +- `archivepoint` - Get archived point outages (requires `start` and `end`) +- `svr` - Severe weather reports +- `svrpolys` - Get severe weather polygons +- `powerids` - Get specific power outages (requires comma-separated IDs) +- `poweridsgeojson` - Get specific power outages as GeoJSON +- `polygongeojson` - Get power outages in polygon (requires GeoJSON string) +**Migration**: +- Old: `powerapi.php` +- New: `main.php?service=powerapi` +- Old: `powerapi.php?states` +- New: `main.php?service=powerapi&states` + +### 12. searchapi +**Description**: Returns search results for power outages +**Usage**: `main.php?service=searchapi[&{various parameters}]` +**Parameters**: +- No parameters - Get current power outages +- `county` - Get county data +- `countyarchive` - Get archived county data +- `archivepoint` - Get archived point data +- `svr` - Get severe weather data +**Migration**: +- Old: `searchapi.php` +- New: `main.php?service=searchapi` + +### 13. ohgo +**Description**: Returns Ohio traffic information +**Usage**: `main.php?service=ohgo` +**Parameters**: None required +**Migration**: +- Old: `ohgo.php` +- New: `main.php?service=ohgo` + +### 14. power +**Description**: Returns power outage information (simplified) +**Usage**: `main.php?service=power` +**Parameters**: None required +**Migration**: +- Old: `power.php` +- New: `main.php?service=power` + +### 15. stormdata +**Description**: Returns storm data (POST only) +**Usage**: POST to `main.php?service=stormdata` +**Parameters** (in POST body as JSON): +- `request_type` - Type of request (ohgo, ohgonopoly, power, powernopoly, wupoly, campoly) +- `start_time`, `end_time` - Time range +- `area_geojson` - Area as GeoJSON +- `buffer` - Buffer time in hours +**Migration**: +- Old: `stormdata.php` +- New: `main.php?service=stormdata` (POST request) + +### 16. warntrack +**Description**: Returns warning tracking data +**Usage**: `main.php?service=warntrack` +**Parameters**: None required +**Migration**: +- Old: `warntrack.php` +- New: `main.php?service=warntrack` + +### 17. ver +**Description**: Returns version information +**Usage**: `main.php?service=ver[&{various parameters}]` +**Parameters**: +- No parameters - Get version polygons +- `lsrslist` - Get LSRs list +- `reset` - Reset LSRs +- `lsrs` - Update LSRs +- `inc` - Update increment +- `hide` - Update hide status +**Migration**: +- Old: `ver.php` +- New: `main.php?service=ver` + +### 18. update_field +**Description**: Updates table fields (POST only) +**Usage**: POST to `main.php?service=update_field` +**Parameters** (in POST body): +- `camid` - Camera ID +- `field` - Field to update (hydro, airport) +- `value` - Value to set +**Migration**: +- Old: `update_field.php` +- New: `main.php?service=update_field` (POST request) + +### 19. mp4 +**Description**: Generates MP4/gif from images (POST only) +**Usage**: POST to `main.php?service=mp4` +**Parameters** (in POST body): +- `data` - Array of image paths +- `images` - Number of images +- `delay` - Delay between images +- `lastdelay` - Delay for last image +- `maxh`, `maxv` - Max dimensions +**Migration**: +- Old: `mp4.php` +- New: `main.php?service=mp4` (POST request) + +## Error Handling +- Invalid service parameters return HTTP 400 with available services +- Database errors return appropriate error messages +- Missing required parameters return HTTP 400 with descriptive error messages + +## Security Considerations +- All user-provided input is properly escaped using `pg_escape_string()` +- SQL injection prevention through parameterized queries +- Input validation for numeric and boolean values + +## Migration Guide + +### For Web Applications +1. Update all API calls to use the new endpoint format +2. Replace direct script calls with `main.php?service={service_name}` +3. Ensure all existing parameters are preserved +4. Test all functionality to verify compatibility + +### For JavaScript Applications +```javascript +// Old approach +fetch('cam.php') + .then(response => response.json()) + +// New approach +fetch('main.php?service=cams') + .then(response => response.json()) +``` + +### For Server-to-Server Communication +```php +// Old approach +$result = file_get_contents('http://yourserver/camapi.php?cams&lat1=...&lon1=...'); + +// New approach +$result = file_get_contents('http://yourserver/main.php?service=camapi&cams&lat1=...&lon1=...'); +``` + +## Testing +- All services maintain the same output format as the original scripts +- Backwards compatibility is preserved for parameter usage +- JSON output remains consistent with previous implementations \ No newline at end of file diff --git a/admin.html b/admin.html index ad327eb..9ae4f06 100644 --- a/admin.html +++ b/admin.html @@ -167,7 +167,7 @@ padding-horizontal: 15px; function isValidUrl(string) { $.ajax({ - url: 'admin.php?action=checkurl', + url: 'main.php?service=admin&action=checkurl', type: 'POST', dataType: "json", data: {url:string}, @@ -191,7 +191,7 @@ function isValidUrl(string) { $('#newcam').submit(function(e){ e.preventDefault(); $.ajax({ - url: 'admin.php?action=newcam', + url: 'main.php?service=admin&action=newcam', type: 'post', data:$('#newcam').serialize(), success:function(data){ diff --git a/admin.php b/admin.php deleted file mode 100644 index 350240e..0000000 --- a/admin.php +++ /dev/null @@ -1,61 +0,0 @@ - false AND lastsuccess IS NOT NULL AND (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) order by elevation desc"; -$result = pg_query($query) or die('Query failed: ' . pg_last_error()); - -// Printing results in HTML -$array = array(); -while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { - // Ensure hydro is a proper boolean - $line['hydro'] = ($line['hydro'] === 't' || $line['hydro'] === true); - // Ensure airport is a proper boolean - $line['airport'] = ($line['airport'] === 't' || $line['airport'] === true); - $array[] = $line; -} -echo json_encode($array); - -// Free resultset -pg_free_result($result); - -// Closing connection -pg_close($dbconn); -?> diff --git a/camapi.php b/camapi.php deleted file mode 100644 index 232353b..0000000 --- a/camapi.php +++ /dev/null @@ -1,102 +0,0 @@ - %s and lat < %s and lon > %s and lon < %s order by lastsuccess desc limit 25 - - -//no gets, curent point outage info -//error_reporting(-1); // reports all errors -//ini_set("display_errors", "1"); // shows all errors -//ini_set("log_errors", 1); -//ini_set("error_log", "php-error.log"); - - -//county/state max - -if (isset($_GET['cams'])) { -if($_GET['lat1']) { -$lat1 = pg_escape_string($_GET['lat1']); -if($_GET['lon1']) { -$lon1 = pg_escape_string($_GET['lon1']); -if($_GET['lat2']) { -$lat2 = pg_escape_string($_GET['lat2']); -if($_GET['lon2']) { -$lon2 = pg_escape_string($_GET['lon2']); -if($_GET['elevbottom']) { -$elevbottom = pg_escape_string($_GET['elevbottom']); -if($_GET['elevtop']) { -$elevtop = pg_escape_string($_GET['elevtop']); - - -$result = pg_query_params($dbconn, -"select camid,url,description from cams where method = 'rtsp' and active = true and cwa = 'RLX' and elevation > $5 and elevation < $6 and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and lat < $1 and lat > $2 and lon < $3 and lon > $4 order by elevation desc", -array($lat1,$lat2,$lon1,$lon2,$elevbottom,$elevtop)) or die('Query failed: ' . pg_last_error()); - - - -//$result = pg_query_params($dbconn, -//select distinct on (county,state) max(outage),county,state from (select distinct on (county,state,update) county,state,sum(outages) as outage, update as time, sum(served) as served from countyoutages where update > '2023-04-01' and update < '2023-04-02' and cwa = 'RLX' group by county,state,update) as potato group by county,state; -//"select camid,url,description from cams where method = 'rtsp' and active = true $1 '162.210.14.137' and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and lat < $2 and lat > $3 and lon < $4 and lon > $5", -//array($res,$lat1,$lat2,$lon1,$lon2)) or die('Query failed: ' . pg_last_error()); -while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { - $array[] = $line; -} -echo json_encode($array); -pg_free_result($result); -pg_close($dbconn); - -}}}}}}} - -if (isset($_GET['camstatic'])) { - -if($_GET['lat1']) { -$lat1 = pg_escape_string($_GET['lat1']); -if($_GET['lon1']) { -$lon1 = pg_escape_string($_GET['lon1']); -if($_GET['radius']) { -$radius = pg_escape_string($_GET['radius']); -$rad = $radius / 70; - -$lat1 = floatval($lat1); -$lon1 = floatval($lon1); -$radius = floatval($rad); -$query = "select * from cams where method = 'rtsp' and active = true and cwa = 'RLX' and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and st_dwithin(geom, ST_SetSRID(ST_Point(" . strval($lon1) . ", " . strval($lat1) . "), 4326)," . strval($radius) . ") order by elevation desc"; - - - -$result = pg_query($dbconn,$query) or die('Query failed: ' . pg_last_error()); - -while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { - $array[] = $line; -} -echo json_encode($array); -pg_free_result($result); -pg_close($dbconn); - - - -}}}} - - - -if (isset($_GET['camdb'])) { -$result = pg_query($dbconn, -"SELECT COUNT(*) FROM camdb") or die('Query failed: ' . pg_last_error()); -while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { - $array[] = $line; -} -echo json_encode($array); -pg_free_result($result); -pg_close($dbconn); -} - - - - - - -?> diff --git a/camcircle.php b/camcircle.php deleted file mode 100644 index fd6dcf6..0000000 --- a/camcircle.php +++ /dev/null @@ -1,43 +0,0 @@ - false AND lastsuccess IS NOT NULL AND (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) order by elevation desc"; -//$query = "SELECT cwa,lat,lon,lastimage,county,elevation,camid,state,description FROM cams WHERE active <> false AND lastsuccess IS NOT NULL AND (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) order by elevation desc"; -//$query = "SELECT json_build_object('type', 'FeatureCollection','features', json_agg(json_build_object('type','Feature', 'geometry', ST_AsGeoJSON(WITH subquery_points AS (SELECT geom AS point_geometry FROM cams WHERE active = true and totalfails < 50) SELECT ST_Buffer(point_geometry::geography, 8000) AS circle_geometry FROM subquery_points)))"; -//"SELECT json_build_object('type', 'FeatureCollection','features', json_agg(json_build_object('type','Feature', 'geometry', ST_AsGeoJSON(realgeom)::json,'properties',json_build_object('time',startguess,'county',county,'state',state,'outage',outagen,'lastchange',lastchange,'cause',cause))order by startguess asc)) FROM power WHERE cwa = $1 and active = true" -$query = "WITH subquery_points AS ( - SELECT geom AS point_geometry - FROM cams - WHERE active = true and lastsuccess IS NOT NULL AND (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < 60 -) -SELECT jsonb_build_object( - 'type', 'FeatureCollection', - 'features', jsonb_agg(jsonb_build_object( - 'type', 'Feature', - 'geometry', ST_AsGeoJSON(ST_Buffer(point_geometry::geography, 8000))::jsonb - )) -) AS feature_collection -FROM subquery_points"; - - - -$result = pg_query($query) or die('Query failed: ' . pg_last_error()); - -// Printing results in HTML - -while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { - $array[] = $line; - -} -print_r($array[0]['feature_collection']); - -// Free resultset -pg_free_result($result); - -// Closing connection -pg_close($dbconn); -?> diff --git a/camlist.php b/camlist.php deleted file mode 100644 index 588be90..0000000 --- a/camlist.php +++ /dev/null @@ -1,56 +0,0 @@ - 'success', - 'data' => $data, - 'count' => count($data) - ]; - - // Free resultset - pg_free_result($result); - - // Close connection - pg_close($dbconn); - -} catch (Exception $e) { - http_response_code(500); - $response = [ - 'status' => 'error', - 'message' => $e->getMessage() - ]; -} - -// Output JSON -echo json_encode($response, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK); -?> \ No newline at end of file diff --git a/cams.html b/cams.html index d909c21..0910660 100644 --- a/cams.html +++ b/cams.html @@ -501,7 +501,7 @@ for (var ii in sortcams) { // Load settings when the page loads window.onload = function() { loadSettings(); - $.getJSON('cam.php', function(data) { + $.getJSON('main.php?service=cams', function(data) { var wild = Math.random(); allcams = data; console.log('Camera data:', data); // Debug: log camera data @@ -535,7 +535,7 @@ for (var ii in sortcams) { } filter(); sortcams(); // Apply saved sort - $.getJSON('camapi.php?camdb', function(data){ + $.getJSON('main.php?service=camapi&camdb', function(data){ document.getElementById("camcount").textContent = "Total Images: " + data[0].count; }); }); @@ -544,7 +544,7 @@ for (var ii in sortcams) { function refreshcams() { -$.getJSON('cam.php', function(data){ +$.getJSON('main.php?service=cams', function(data){ var wild = Math.random(); //console.log(data); for(var i in data){ @@ -565,7 +565,7 @@ $.getJSON('cam.php', function(data){ } }} }); -$.getJSON('camapi.php?camdb', function(data){ +$.getJSON('main.php?service=camapi&camdb', function(data){ document.getElementById("camcount").textContent = "Total Images: " + data[0].count; }); diff --git a/circlemap.html b/circlemap.html index 89a22c3..9efbaa0 100644 --- a/circlemap.html +++ b/circlemap.html @@ -204,7 +204,7 @@ style: function (feature) { }).addTo(mymap); -$.getJSON('camcircle.php', function(data) { +$.getJSON('main.php?service=camcircle', function(data) { var geojsonFeature = data; geoJSONcircle.addData(geojsonFeature); diff --git a/db.html b/db.html index 2e0dd6f..23b76cd 100644 --- a/db.html +++ b/db.html @@ -19,7 +19,7 @@
- - - - - - - - - - - - - - - - - - -