예제 #1
0
}
if (!is_null($user_id) && !is_null($authid)) {
    $sql = "SELECT * FROM `authdata` WHERE `user_id`='{$user_id}' AND `auth_id`='{$authid}'";
    $row = queryRow($sql);
}
if ($row) {
    $time = date('Y-m-d H:i:s');
    $region = $row['region'];
    if ($region != "CN" && $region != "EU") {
        $region = "US";
    }
    $sql = "SELECT * FROM `synctime` WHERE `region`='{$region}'";
    $rowSYNC = queryRow($sql);
    if (strtotime($time) - strtotime($rowSYNC['last_sync']) > 86400) {
        $auth = Authenticator::factory($row['serial'], $row['secret']);
        $sql = "UPDATE `synctime` SET `sync`=\"" . $auth->getsync() . "\" ,`last_sync`=\"{$time}\" WHERE `region`='{$region}'";
        update($sql);
    } else {
        $auth = Authenticator::factory($row['serial'], $row['secret'], $rowSYNC['sync']);
    }
    //显示数据
    header('Content-type: text/json');
    $wait = $auth->sleeptime() / 1000;
    $arr = array('code' => $auth->code(), 'time' => $wait);
    echo json_encode($arr);
} else {
    header('Content-type: text/json');
    $wait = 0;
    $arr = array('code' => "@@@@@@", 'time' => $wait);
    echo json_encode($arr);
}
예제 #2
0
    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";