Files
wevads-platform/scripts/hamid-code.php
2026-02-26 04:53:11 +01:00

38 lines
1.0 KiB
PHP
Executable File

<?php
header('Content-Type: application/json');
$code = $_POST['code'] ?? '';
$lang = $_POST['language'] ?? 'python';
if (empty($code)) { echo json_encode(['error' => 'Code required']); exit; }
$forbidden = ['rm -rf', 'mkfs', 'dd if=', '> /dev/'];
foreach ($forbidden as $f) {
if (stripos($code, $f) !== false) {
echo json_encode(['error' => 'Forbidden']); exit;
}
}
$tmp = '/tmp/hamid_' . uniqid();
$out = [];
switch ($lang) {
case 'python':
file_put_contents("$tmp.py", $code);
exec("timeout 10 python3 $tmp.py 2>&1", $out);
@unlink("$tmp.py");
break;
case 'php':
file_put_contents("$tmp.php", "<?php\n$code");
exec("timeout 10 php $tmp.php 2>&1", $out);
@unlink("$tmp.php");
break;
case 'bash':
file_put_contents("$tmp.sh", $code);
exec("timeout 10 bash $tmp.sh 2>&1", $out);
@unlink("$tmp.sh");
break;
}
echo json_encode(['success' => true, 'output' => implode("\n", $out), 'language' => $lang]);