feat: delete
This commit is contained in:
@@ -431,25 +431,130 @@ class ChannelProjectService
|
||||
private function runBuilder(array $cmd, string $errorPrefix, string $cwd): array
|
||||
{
|
||||
$timeout = (float) config('coruna.channel_builder.timeout', 600);
|
||||
$probe = $this->builderProbe($cmd, $cwd);
|
||||
Log::info('channel_builder start', $probe + [
|
||||
'error_prefix' => $errorPrefix,
|
||||
'timeout' => $timeout,
|
||||
]);
|
||||
|
||||
$started = microtime(true);
|
||||
$process = Process::timeout((int) max(1, $timeout))
|
||||
->path($cwd)
|
||||
->run($cmd);
|
||||
$ms = (int) ((microtime(true) - $started) * 1000);
|
||||
$stdout = trim($process->output());
|
||||
$stderr = trim($process->errorOutput());
|
||||
|
||||
if (! $process->successful()) {
|
||||
$detail = trim($process->errorOutput() ?: $process->output());
|
||||
$detail = mb_substr($detail !== '' ? $detail : 'builder exited '.$process->exitCode(), 0, 800);
|
||||
Log::error('Channel builder failed', [
|
||||
$hint = trim($this->builderFailHint((int) $process->exitCode(), $cmd, $cwd).' '
|
||||
.$this->hardeningHint($stderr."\n".$stdout, $process->exitCode()));
|
||||
Log::error('channel_builder failed', $probe + [
|
||||
'error_prefix' => $errorPrefix,
|
||||
'exit_code' => $process->exitCode(),
|
||||
'detail' => $detail,
|
||||
'cmd' => $cmd,
|
||||
'ms' => $ms,
|
||||
'stdout' => mb_substr($stdout, 0, 2000),
|
||||
'stderr' => mb_substr($stderr, 0, 2000),
|
||||
'hint' => $hint,
|
||||
]);
|
||||
$detail = $stderr !== '' ? $stderr : $stdout;
|
||||
if ($detail === '') {
|
||||
$detail = 'builder exited '.$process->exitCode();
|
||||
}
|
||||
if ($hint !== '') {
|
||||
$detail .= ';'.$hint;
|
||||
}
|
||||
|
||||
throw new RuntimeException("{$errorPrefix}: {$detail}");
|
||||
throw new RuntimeException($errorPrefix.': '.mb_substr($detail, 0, 2500));
|
||||
}
|
||||
|
||||
Log::info('channel_builder ok', [
|
||||
'error_prefix' => $errorPrefix,
|
||||
'ms' => $ms,
|
||||
'cwd' => $cwd,
|
||||
'python' => $cmd[0] ?? '',
|
||||
]);
|
||||
|
||||
return $this->parseResultMarker($process->output(), $errorPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $cmd
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function builderProbe(array $cmd, string $cwd): array
|
||||
{
|
||||
$python = (string) ($cmd[0] ?? '');
|
||||
$script = (string) ($cmd[1] ?? '');
|
||||
$uid = function_exists('posix_geteuid') ? posix_geteuid() : getmyuid();
|
||||
$user = function_exists('posix_getpwuid')
|
||||
? ((posix_getpwuid((int) $uid)['name'] ?? null) ?: (string) $uid)
|
||||
: (string) $uid;
|
||||
|
||||
return [
|
||||
'cwd' => $cwd,
|
||||
'cwd_exists' => is_dir($cwd),
|
||||
'cmd' => $cmd,
|
||||
'php_user' => $user,
|
||||
'php_uid' => $uid,
|
||||
'python' => $python,
|
||||
'python_is_abs' => $python !== '' && $python[0] === '/',
|
||||
'python_is_link' => $python !== '' && @is_link($python),
|
||||
'python_is_file' => $python !== '' && @is_file($python),
|
||||
'python_link' => ($python !== '' && @is_link($python)) ? (string) @readlink($python) : null,
|
||||
'script' => $script,
|
||||
'script_exists' => $script !== '' && is_file($script),
|
||||
'path_env' => (string) (getenv('PATH') ?: ''),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $cmd
|
||||
*/
|
||||
private function builderFailHint(int $exit, array $cmd, string $cwd): string
|
||||
{
|
||||
if ($exit !== 127) {
|
||||
return '';
|
||||
}
|
||||
$python = (string) ($cmd[0] ?? '');
|
||||
$script = (string) ($cmd[1] ?? '');
|
||||
$bits = ['exit 127 = 命令不存在'];
|
||||
if ($python === '' || $python === 'python3') {
|
||||
$bits[] = '未找到可用 python(.env CORUNA_CHANNEL_BUILDER_NEW_PYTHON 为空且无 .venv)';
|
||||
} elseif (! @is_file($python) && ! @is_link($python)) {
|
||||
$bits[] = '解释器路径不存在: '.$python;
|
||||
} else {
|
||||
$target = @is_link($python) ? (string) @readlink($python) : '';
|
||||
if ($target !== '') {
|
||||
$bits[] = 'venv python 软链指向 '.$target.'(目标机上可能没有这个 python)';
|
||||
}
|
||||
}
|
||||
if ($script !== '' && ! is_file($script)) {
|
||||
$bits[] = '脚本不存在: '.$script;
|
||||
}
|
||||
if (! is_dir($cwd)) {
|
||||
$bits[] = '工作目录不存在: '.$cwd;
|
||||
}
|
||||
|
||||
return implode(';', $bits);
|
||||
}
|
||||
|
||||
private function hardeningHint(string $output, ?int $exit = null): string
|
||||
{
|
||||
$hay = strtolower($output);
|
||||
if (str_contains($hay, 'tips from bt security')
|
||||
|| str_contains($hay, 'your request has been recorded')
|
||||
|| $exit === 9 || $exit === 137) {
|
||||
return '堡塔防入侵拦截了 www 执行 python。软件商店 → 堡塔防入侵 → 看 www 拦截日志,把 venv python 与 /usr/bin/python3.10 加白后再建渠道';
|
||||
}
|
||||
if (! str_contains($hay, 'py7zr') && ! str_contains($hay, 'permission denied')
|
||||
&& ! str_contains($hay, 'cannot open shared object')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '宝塔系统加固常去掉 /usr/bin/python3.10 与 venv 里 .so 的执行权限。'
|
||||
.'请把 /www/wwwroot/coruna-lab 加入加固排除,并 chmod 755 系统 python 与 venv 下 *.so';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user