modified: templates/itemeditor_command_storage.html
This commit is contained in:
@@ -111,23 +111,74 @@
|
|||||||
<div class="info-icon">
|
<div class="info-icon">
|
||||||
<i class="fas fa-server"></i>
|
<i class="fas fa-server"></i>
|
||||||
</div>
|
</div>
|
||||||
<h3>Self-Hosting on Your Webserver</h3>
|
<h3>Self-Hosting</h3>
|
||||||
<p class="code-description">You can run this command storage system on your own webserver for production use:</p>
|
<p class="code-description">Host this system on your own webserver with this simple PHP script:</p>
|
||||||
<ol class="info-steps">
|
<pre class="code-block" style="font-size: 0.75rem; line-height: 1.4;"><?php
|
||||||
<li>Install <strong>Python 3.10+</strong> and <strong>Flask</strong> on your server</li>
|
header('Content-Type: application/json');
|
||||||
<li>Deploy the Flask app using a production WSGI server like <strong>Gunicorn</strong> or <strong>uWSGI</strong></li>
|
$storage_file = 'commands.json';
|
||||||
<li>Use a reverse proxy (e.g. <strong>Nginx</strong> or <strong>Apache</strong>) to route traffic to the Flask app</li>
|
|
||||||
<li>Optional: Use <strong>Docker</strong> for easy deployment (see <code>Dockerfile</code> in the project)</li>
|
// Store command (POST)
|
||||||
<li>Access via: <br><code>https://your-domain/projects/itemeditor/storage</code></li>
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
<li>API endpoint: <br><code>https://your-domain/projects/itemeditor/storage/<uuid></code></li>
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
</ol>
|
$command = $data['command'] ?? '';
|
||||||
<p class="code-block">GET https://your-domain/projects/itemeditor/storage/<uuid>
|
|
||||||
{
|
if (strlen($command) > 10000) {
|
||||||
"command": "your command here",
|
http_response_code(400);
|
||||||
"created_at": "...",
|
echo json_encode(['error' => 'Too long']);
|
||||||
"expires_at": "..."
|
exit;
|
||||||
}</p>
|
}
|
||||||
<p class="code-description">For best performance and security, do <strong>not</strong> use the Flask development server in production. Use Gunicorn + Nginx or Docker for real deployments.</p>
|
|
||||||
|
$uuid = bin2hex(random_bytes(16));
|
||||||
|
$expires = time() + 1800; // 30 min
|
||||||
|
|
||||||
|
$storage = file_exists($storage_file)
|
||||||
|
? json_decode(file_get_contents($storage_file), true)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
$storage[$uuid] = [
|
||||||
|
'command' => $command,
|
||||||
|
'expires_at' => $expires
|
||||||
|
];
|
||||||
|
|
||||||
|
file_put_contents($storage_file, json_encode($storage));
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'url' => "https://yourserver.com/storage.php?id=$uuid"
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve command (GET)
|
||||||
|
if (isset($_GET['id'])) {
|
||||||
|
$storage = file_exists($storage_file)
|
||||||
|
? json_decode(file_get_contents($storage_file), true)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
$uuid = $_GET['id'];
|
||||||
|
|
||||||
|
if (!isset($storage[$uuid])) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(['error' => 'Not found']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($storage[$uuid]['expires_at'] < time()) {
|
||||||
|
unset($storage[$uuid]);
|
||||||
|
file_put_contents($storage_file, json_encode($storage));
|
||||||
|
http_response_code(410);
|
||||||
|
echo json_encode(['error' => 'Expired']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($storage[$uuid]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?></pre>
|
||||||
|
<p style="color: #cfcfcf; font-size: 0.9rem; margin-top: 1rem;">
|
||||||
|
<strong>Setup:</strong> Save as <code>storage.php</code> on your webserver.
|
||||||
|
Make sure the directory is writable for <code>commands.json</code>.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user