-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
executable file
·71 lines (57 loc) · 1.62 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/local/opt/[email protected]/bin/php
<?php
require(__DIR__.'/vendor/autoload.php');
$ga = new PHPGangsta_GoogleAuthenticator();
$secrets = [
'ta' => 'SECRETONE',
'portfolio' => 'SECRETTWO',
];
while (1) {
fwrite(STDOUT, "Choose MFA\n");
$i = 0;
foreach ($secrets as $key => $secret) {
echo "[$i]: $key " . PHP_EOL;
$i++;
}
$index = intval(fgets(STDIN));
if (array_key_exists($index, array_keys($secrets))) {
$secret = $secrets[array_keys($secrets)[$index]];
break;
}
}
while (1) {
$oneCode = $ga->getCode($secret);
echo "\r".array_keys($secrets)[$index]." checking code: $oneCode";
//$shell="echo -n $oneCode | /usr/bin/pbcoby";
//echo $shell;
//`$shell`;
copy2clipboard($oneCode);
usleep(100);
}
echo "Secret is: " . $secret . "\n\n";
$qrCodeUrl = $ga->getQRCodeGoogleUrl('Blog', $secret);
echo "Google Charts URL for the QR-Code: " . $qrCodeUrl . "\n\n";
$oneCode = $ga->getCode($secret);
echo "Checking Code '$oneCode' and Secret '$secret':\n";
$checkResult = $ga->verifyCode($secret, $oneCode, 2); // 2 = 2*30sec clock tolerance
if ($checkResult) {
echo 'OK';
} else {
echo 'FAILED';
}
echo PHP_EOL;
function copy2clipboard($string){
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "a.txt", "a") // stderr is a file to write to
);
$process = proc_open('pbcopy', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $string);
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
return $return_value;
}
}