-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
254 lines (230 loc) Β· 8.64 KB
/
deploy.php
File metadata and controls
254 lines (230 loc) Β· 8.64 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
/**
* Web-Based Deployment Script
* PodaBio - Deploy code from GitHub via browser
*
* SECURITY: This script requires admin authentication and CSRF token
* DELETE THIS FILE after deployment or restrict access via .htaccess
*/
require_once __DIR__ . '/config/constants.php';
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/includes/session.php';
require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/helpers.php';
require_once __DIR__ . '/includes/security.php';
// Check if user is admin
function isAdmin() {
$user = getCurrentUser();
if (!$user) {
return false;
}
// Check if user email is admin
$adminEmails = ['phil@redwoodempiremedia.com', 'cursor@poda.bio', 'phil624@gmail.com'];
return in_array(strtolower($user['email']), array_map('strtolower', $adminEmails));
}
function requireAdmin() {
requireAuth();
if (!isAdmin()) {
http_response_code(403);
die('Access denied. Admin privileges required.');
}
}
requireAdmin();
$csrfToken = generateCSRFToken();
$output = [];
$success = false;
$error = null;
// Handle deployment request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Verify CSRF token
if (!verifyCSRFToken($_POST['csrf_token'] ?? '')) {
$error = 'Invalid CSRF token. Please refresh the page and try again.';
} else {
$projectDir = __DIR__;
// Step 1: Git Pull
$output[] = "π¦ Step 1: Pulling latest code from GitHub...";
$gitPull = shell_exec("cd {$projectDir} && git pull origin main 2>&1");
if ($gitPull === null) {
$error = "Failed to execute git pull. Check server permissions.";
} else {
$output[] = $gitPull;
// Check if git pull was successful
if (strpos($gitPull, 'Already up to date') !== false ||
strpos($gitPull, 'Updating') !== false ||
strpos($gitPull, 'Fast-forward') !== false) {
$output[] = "β
Code updated successfully";
// Step 2: Check database migration
$output[] = "";
$output[] = "ποΈ Step 2: Checking database migration status...";
try {
$pdo = getDB();
$tableExists = $pdo->query("SHOW TABLES LIKE 'podcast_directories'")->rowCount() > 0;
$newTableExists = $pdo->query("SHOW TABLES LIKE 'social_icons'")->rowCount() > 0;
if ($newTableExists) {
$output[] = "β
Migration already completed - social_icons table exists";
} elseif ($tableExists) {
$output[] = "π podcast_directories table found, running migration...";
// Run migration
$pdo->beginTransaction();
try {
$pdo->exec('RENAME TABLE podcast_directories TO social_icons');
$pdo->exec("ALTER TABLE social_icons COMMENT = 'Social icons and platform links for pages'");
$pdo->commit();
$count = $pdo->query('SELECT COUNT(*) as count FROM social_icons')->fetch()['count'];
$output[] = "β
Migration completed successfully! Migrated {$count} records.";
} catch (Exception $e) {
$pdo->rollBack();
throw $e;
}
} else {
$output[] = "β οΈ Neither table exists. Migration may not be needed.";
}
$success = true;
} catch (Exception $e) {
$error = "Migration failed: " . $e->getMessage();
}
} else {
$error = "Git pull may have failed. Check the output above.";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deploy - PodaBio</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: #f5f5f5;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 30px;
}
h1 {
color: #333;
margin-bottom: 10px;
}
.warning {
background: #fff3cd;
border: 1px solid #ffc107;
border-radius: 4px;
padding: 15px;
margin: 20px 0;
color: #856404;
}
.warning strong {
display: block;
margin-bottom: 5px;
}
.btn {
background: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-top: 20px;
}
.btn:hover {
background: #0056b3;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.output {
background: #1e1e1e;
color: #d4d4d4;
padding: 20px;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 14px;
white-space: pre-wrap;
margin: 20px 0;
max-height: 500px;
overflow-y: auto;
}
.success {
color: #28a745;
font-weight: bold;
margin-top: 15px;
}
.error {
color: #dc3545;
background: #f8d7da;
border: 1px solid #f5c6cb;
border-radius: 4px;
padding: 15px;
margin: 20px 0;
}
.info {
color: #0c5460;
background: #d1ecf1;
border: 1px solid #bee5eb;
border-radius: 4px;
padding: 15px;
margin: 20px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>π Deploy to Production (poda.bio)</h1>
<div class="warning">
<strong>β οΈ Security Warning</strong>
This script has admin-level access. Delete this file after deployment or restrict access via .htaccess.
</div>
<?php if ($error): ?>
<div class="error">
<strong>β Error:</strong> <?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success">
β
Deployment Complete!
</div>
<div class="info">
<strong>Next steps:</strong><br>
1. Test PHP backend: <a href="https://poda.bio/index.php" target="_blank">https://poda.bio/index.php</a><br>
2. Test admin panel: <a href="https://poda.bio/admin/userdashboard.php" target="_blank">https://poda.bio/admin/userdashboard.php</a><br>
3. Verify React app loads (check browser console)<br>
4. Test database connectivity<br>
5. Test file uploads<br>
6. <strong>Delete this deploy.php file for security</strong>
</div>
<?php endif; ?>
<?php if (!empty($output)): ?>
<div class="output"><?php echo htmlspecialchars(implode("\n", $output)); ?></div>
<?php endif; ?>
<form method="POST" action="">
<input type="hidden" name="csrf_token" value="<?php echo $csrfToken; ?>">
<button type="submit" class="btn" <?php echo ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error) ? 'disabled' : ''; ?>>
<?php echo ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error) ? 'Deployment Complete' : 'Deploy from GitHub'; ?>
</button>
</form>
<div class="info" style="margin-top: 30px;">
<strong>What this does:</strong><br>
1. Pulls latest code from GitHub (main branch)<br>
2. Checks and runs database migrations if needed<br>
3. Verifies deployment success
</div>
</div>
</body>
</html>