-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathphp-bma.php
More file actions
48 lines (42 loc) · 1.1 KB
/
php-bma.php
File metadata and controls
48 lines (42 loc) · 1.1 KB
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
<?php
require_once('classes/Authenticator.php');
function usage() {
echo "Usage:\r\n";
echo "\tphp php-bma.php new region\r\n";
echo "\tphp php-bma.php generate serial secret\r\n";
echo "\tphp php-bma.php restore serial restore_code\r\n\r\n";
}
$auth = false;
$method = isset($argv[1]) ? $argv[1] : null;
switch($method) {
case "new":
if (count($argv) == 3) {
$auth = Authenticator::generate($argv[2]);
$message = "New Authenticator requested";
}
break;
case "generate":
if (count($argv) == 4) {
$auth = Authenticator::factory($argv[2], $argv[3]);
$message = "Generate codes";
}
break;
case "restore":
if (count($argv) == 4) {
$auth = Authenticator::restore($argv[2], $argv[3]);
$message = "Restore requested";
}
break;
}
if($auth === false) {
usage();
exit(1);
}
echo $message." - Serial: ".$auth->serial()." Secret: ".$auth->secret()." Restore: " . $auth->restore_code() . "\r\n\r\n";
while(true) {
$code = $auth->code();
echo "key: $code\r\n";
$wait = 1 + ($auth->waitingtime() - $auth->elapsedtime()) / 1000;
echo 'waiting for '.$wait." sec\r\n\r\n";
sleep($wait);
}