-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
370 lines (340 loc) · 12.5 KB
/
install.php
File metadata and controls
370 lines (340 loc) · 12.5 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/**
* TaskFlow Installer
* Copy this single file to your web server and open it in a browser.
* It will download TaskFlow from GitHub and set up the admin account.
*
* Copyright (c) 2026 Florian Hesse
* https://comnic-it.de
*/
$repoOwner = 'floppy007';
$repoName = 'taskflow';
$branch = 'main';
$error = '';
$success = false;
$downloaded = 0;
$installDir = __DIR__;
$dataDir = $installDir . '/data';
// Check if already fully installed
if (file_exists($installDir . '/index.php') && file_exists($dataDir . '/users.json')) {
header('Location: index.php');
exit;
}
// Check if files are downloaded but no user yet
$filesExist = file_exists($installDir . '/index.php') && file_exists($installDir . '/api.php');
// HTTP context for GitHub API
function ghContext() {
return stream_context_create([
'http' => [
'timeout' => 30,
'header' => "User-Agent: TaskFlow-Installer\r\n",
'follow_location' => true
]
]);
}
// Download a single file from GitHub raw
function downloadFile($owner, $repo, $branch, $path, $destDir) {
$url = "https://raw.githubusercontent.com/$owner/$repo/$branch/$path";
$content = @file_get_contents($url, false, ghContext());
if ($content === false) return false;
$destPath = $destDir . '/' . $path;
$destFolder = dirname($destPath);
if (!is_dir($destFolder)) @mkdir($destFolder, 0755, true);
return file_put_contents($destPath, $content) !== false;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'download') {
// Step 1: Get file list from GitHub API (tree)
$apiUrl = "https://api.github.com/repos/$repoOwner/$repoName/git/trees/$branch?recursive=1";
$treeJson = @file_get_contents($apiUrl, false, ghContext());
if ($treeJson === false) {
$error = 'Could not connect to GitHub API. Check your internet connection.';
} else {
$tree = json_decode($treeJson, true);
if (!isset($tree['tree'])) {
$error = 'Invalid response from GitHub API.';
} else {
// Filter files (skip data/*.json, install.php, .git*)
$files = [];
foreach ($tree['tree'] as $item) {
if ($item['type'] !== 'blob') continue;
$path = $item['path'];
// Skip files we don't want
if ($path === 'install.php') continue;
if (preg_match('#^data/(users|projects)\.json$#', $path)) continue;
if (strpos($path, '.git') === 0 && $path !== '.gitignore') continue;
$files[] = $path;
}
// Download each file
$total = count($files);
$ok = 0;
$failed = [];
foreach ($files as $file) {
if (downloadFile($repoOwner, $repoName, $branch, $file, $installDir)) {
$ok++;
} else {
$failed[] = $file;
}
}
$downloaded = $ok;
if (empty($failed)) {
// Create data dir if needed
if (!is_dir($dataDir)) @mkdir($dataDir, 0755, true);
$filesExist = true;
} else {
$error = "Downloaded $ok/$total files. Failed: " . implode(', ', array_slice($failed, 0, 5));
if (count($failed) > 5) $error .= ' ...and ' . (count($failed) - 5) . ' more';
}
}
}
}
if ($action === 'createuser') {
// Step 2: Create admin user
$name = trim($_POST['name'] ?? '');
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$passwordConfirm = $_POST['password_confirm'] ?? '';
if (!$name || !$username || !$password) {
$error = 'Please fill in all fields.';
} elseif (strlen($password) < 4) {
$error = 'Password must be at least 4 characters.';
} elseif ($password !== $passwordConfirm) {
$error = 'Passwords do not match.';
} else {
if (!is_dir($dataDir)) {
@mkdir($dataDir, 0755, true);
}
if (!is_writable($dataDir)) {
$error = 'The /data directory is not writable. Set permissions: chmod 755 data';
} else {
// .htaccess
$htaccess = $dataDir . '/.htaccess';
if (!file_exists($htaccess)) {
file_put_contents($htaccess, "Order deny,allow\nDeny from all\n");
}
$users = [[
'id' => 1,
'username' => $username,
'password' => password_hash($password, PASSWORD_DEFAULT),
'name' => $name,
'role' => 'admin',
'createdAt' => date('c')
]];
$usersOk = file_put_contents($dataDir . '/users.json', json_encode($users, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$projectsOk = file_put_contents($dataDir . '/projects.json', json_encode([], JSON_PRETTY_PRINT));
if ($usersOk !== false && $projectsOk !== false) {
$success = true;
@unlink(__FILE__);
} else {
$error = 'Could not write data files.';
}
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" type="image/png" href="logo.png">
<title>TaskFlow - Installation</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<style>
* {margin:0;padding:0;box-sizing:border-box}
body {
font-family:'Inter',sans-serif;
background:#f8fafc;
min-height:100vh;
display:flex;
align-items:center;
justify-content:center;
padding:20px;
}
.install-box {
background:#fff;
border-radius:16px;
box-shadow:0 10px 40px rgba(0,0,0,.1);
padding:40px;
width:100%;
max-width:460px;
animation:slideUp .6s cubic-bezier(.16,1,.3,1);
}
@keyframes slideUp {
from {opacity:0;transform:translateY(30px)}
to {opacity:1;transform:translateY(0)}
}
.logo {text-align:center;margin-bottom:24px}
.logo img {width:240px;height:auto}
.title {
text-align:center;
font-size:22px;
font-weight:700;
color:#0f172a;
margin-bottom:4px;
}
.subtitle {
text-align:center;
font-size:14px;
color:#64748b;
margin-bottom:28px;
}
.form-group {margin-bottom:16px}
.form-label {
display:block;
font-size:13px;
font-weight:600;
color:#374151;
margin-bottom:6px;
}
.form-input {
width:100%;
padding:10px 14px;
border:1px solid #e2e8f0;
border-radius:10px;
font-size:14px;
font-family:inherit;
transition:border-color .2s;
outline:none;
}
.form-input:focus {
border-color:#667eea;
box-shadow:0 0 0 3px rgba(102,126,234,.15);
}
.btn {
width:100%;
padding:12px;
border:none;
border-radius:10px;
font-size:15px;
font-weight:600;
font-family:inherit;
cursor:pointer;
background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
color:#fff;
transition:transform .2s,box-shadow .2s;
margin-top:8px;
text-decoration:none;
display:inline-block;
text-align:center;
}
.btn:hover {
transform:translateY(-1px);
box-shadow:0 6px 20px rgba(102,126,234,.3);
}
.btn:active {transform:scale(.98)}
.error {
background:#fef2f2;
color:#dc2626;
padding:10px 14px;
border-radius:10px;
font-size:13px;
margin-bottom:16px;
border:1px solid #fecaca;
}
.success-box {text-align:center;padding:20px 0}
.success-icon {font-size:48px;margin-bottom:16px;color:#10b981}
.success-text {font-size:16px;color:#0f172a;font-weight:600;margin-bottom:8px}
.success-sub {font-size:13px;color:#64748b;margin-bottom:24px}
.info {
background:#f0fdf4;
color:#166534;
padding:10px 14px;
border-radius:10px;
font-size:12px;
margin-bottom:16px;
border:1px solid #bbf7d0;
}
.steps {display:flex;gap:8px;margin-bottom:24px;justify-content:center}
.step {
width:32px;height:32px;border-radius:50%;
display:flex;align-items:center;justify-content:center;
font-size:13px;font-weight:700;
background:#e2e8f0;color:#64748b;
}
.step.active {background:linear-gradient(135deg,#667eea,#764ba2);color:#fff}
.step.done {background:#10b981;color:#fff}
.step-line {width:40px;height:2px;background:#e2e8f0;align-self:center}
.step-line.done {background:#10b981}
</style>
</head>
<body>
<div class="install-box">
<div class="logo">
<?php if (file_exists(__DIR__ . '/logo.png')): ?>
<img src="logo.png" alt="TaskFlow">
<?php else: ?>
<div style="font-size:32px;font-weight:800;text-align:center;margin-bottom:8px;background:linear-gradient(135deg,#667eea,#764ba2);-webkit-background-clip:text;-webkit-text-fill-color:transparent">TaskFlow</div>
<?php endif; ?>
</div>
<?php if ($success): ?>
<div class="steps">
<div class="step done">1</div>
<div class="step-line done"></div>
<div class="step done">2</div>
</div>
<div class="success-box">
<div class="success-icon">✓</div>
<div class="success-text">Installation complete!</div>
<div class="success-sub">TaskFlow has been set up successfully. The installer has been removed.</div>
<a href="index.php" class="btn" style="width:auto;padding:12px 32px">Open TaskFlow</a>
</div>
<?php elseif ($filesExist): ?>
<div class="steps">
<div class="step done">1</div>
<div class="step-line done"></div>
<div class="step active">2</div>
</div>
<div class="title">Create Admin Account</div>
<div class="subtitle">Set up your administrator login</div>
<?php if ($downloaded > 0): ?>
<div class="info"><?= $downloaded ?> files downloaded successfully.</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post">
<input type="hidden" name="action" value="createuser">
<div class="form-group">
<label class="form-label">Full Name</label>
<input type="text" name="name" class="form-input" placeholder="e.g. Max Mustermann" value="<?= htmlspecialchars($_POST['name'] ?? '') ?>" required autofocus>
</div>
<div class="form-group">
<label class="form-label">Username</label>
<input type="text" name="username" class="form-input" placeholder="e.g. admin" value="<?= htmlspecialchars($_POST['username'] ?? '') ?>" required>
</div>
<div class="form-group">
<label class="form-label">Password</label>
<input type="password" name="password" class="form-input" placeholder="Min. 4 characters" required>
</div>
<div class="form-group">
<label class="form-label">Confirm Password</label>
<input type="password" name="password_confirm" class="form-input" placeholder="Repeat password" required>
</div>
<button type="submit" class="btn">Create Account & Finish</button>
</form>
<?php else: ?>
<div class="steps">
<div class="step active">1</div>
<div class="step-line"></div>
<div class="step">2</div>
</div>
<div class="title">Installation</div>
<div class="subtitle">Download TaskFlow from GitHub</div>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<div class="info">
This will download all files from<br>
<strong>github.com/<?= $repoOwner ?>/<?= $repoName ?></strong>
</div>
<form method="post">
<input type="hidden" name="action" value="download">
<button type="submit" class="btn" onclick="this.textContent='Downloading...';this.disabled=true;this.form.submit()">Download & Install TaskFlow</button>
</form>
<?php endif; ?>
</div>
</body>
</html>