-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.php
35 lines (32 loc) · 964 Bytes
/
entrypoint.php
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
<?php
$arguments = isset($argv[2]) ? $argv[2] : '[]';
$arguments = json_decode($arguments, true);
shell_exec('mkdir ~/.ssh');
if (isset($arguments['workspace'])) {
chdir($arguments['workspace']['path']);
$key = $arguments['workspace']['keys']['private'];
shell_exec('echo "' . $key . '" > ~/.ssh/id_rsa');
}
shell_exec('chmod -R 600 ~/.ssh');
$vargs = $arguments['vargs'];
$commands = isset($vargs['commands']) ? $vargs['commands'] : [];
foreach ($commands as $command) {
echo "[+] $command\n";
$exit = execute($command);
if ($exit) {
exit(1);
}
}
function execute($cmd) {
$proc = proc_open($cmd, [['pipe','r'],['pipe','w'],['pipe','w']], $pipes);
while(($line = fgets($pipes[1])) !== false) {
fwrite(STDOUT,$line);
}
while(($line = fgets($pipes[2])) !== false) {
fwrite(STDERR,$line);
}
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
return proc_close($proc);
}