-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.php
56 lines (43 loc) · 1.53 KB
/
run.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
$session=trim(isset($_REQUEST['session'])?$_REQUEST['session']:"");
$output=trim(isset($_REQUEST['output'])?$_REQUEST['output']:"");
if($output=="")
$output="html";
//you can send base encoded certificate to pass to gpg
$certificate=trim(isset($_REQUEST['certificate'])?$_REQUEST['certificate']:"");
if($session=="")
$session=shell_exec("./random_card.sh");
//header("Content-Type: text/plain");
//echo $output;
//exit;
//setup main command
$cmdexec="./run.sh $output $session";
$temp="";
if ( $certificate!="" ) {
$dir="/tmp/.gpg-" . getenv('USER');
$cmd="GNUPGHOME=$dir";
putenv($cmd);
//setup gpg dummy dir
if ( ! file_exists($dir) ) {
mkdir ( $dir , 0700 );
$x=`gpg-connect-agent "KILLAGENT" /bye`;
}
$temp=trim(`mktemp`);
//puth gpg to output main command;
$cmdexec.=" | gpg -e -z 9 --recipient-file $temp -a";
//decode and save certificate
//file_put_contents($temp,base64_decode($certificate));
file_put_contents($temp,$certificate);
//set header as plain text
//header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=\"card-$session.$output.asc\"");
} else if($output != 'html' )
header("Content-Type: application/$output");
//run main command
$out=trim(shell_exec($cmdexec));
//delete temp certificate file
if($temp!="")
unlink($temp);
//send output to user
echo "$out";
?>