-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.php
More file actions
64 lines (54 loc) · 1.61 KB
/
deploy.php
File metadata and controls
64 lines (54 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once('db.php');
// Get and sanitize parameters
$directory_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['ID'] ?? '');
$deploysmart_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['DS'] ?? '');
// Prevent dual parameter usage
if ($directory_id && $deploysmart_id) {
http_response_code(400);
echo json_encode(["error" => "Provide either ID or DS, not both"]);
exit;
}
// Determine ID and file type
if ($directory_id) {
$id = $directory_id;
$file = 'applications.json';
$content_type = 'application/json';
$method = 'iso';
} elseif ($deploysmart_id) {
$id = $deploysmart_id;
$file = 'install.ps1';
$content_type = 'text/plain';
$method = 'powershell';
} else {
http_response_code(400);
echo json_encode(["error" => "Missing ID or DS parameter"]);
exit;
}
// Validate company existence and get ID
$stmt = $pdo->prepare("SELECT id FROM companies WHERE directory_id = ?");
$stmt->execute([$id]);
$company_id = $stmt->fetchColumn();
if (!$company_id) {
http_response_code(404);
echo json_encode(["error" => "Invalid ID"]);
exit;
}
// Determine file path
$base_path = __DIR__ . "/config/$id/";
$full_path = $base_path . $file;
if (!file_exists($full_path)) {
http_response_code(404);
echo json_encode(["error" => "$file not found"]);
exit;
}
// Serve file
header("Content-Type: $content_type");
readfile($full_path);
// ✅ Log deployment only on GET requests
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$stmt = $pdo->prepare("INSERT INTO deployments (company_id, method) VALUES (?, ?)");
$stmt->execute([$company_id, $method]);
}
exit;
?>