8 lines
376 B
PHP
8 lines
376 B
PHP
|
|
<?php declare(strict_types=1);
|
||
|
|
require __DIR__.'/bootstrap.php'; $pdo=db();
|
||
|
|
$id=$argv[1]??null; if(!$id){fwrite(STDERR,"uso: php new-device.php DEVICE_ID\n"); exit(2);}
|
||
|
|
$token=bin2hex(random_bytes(24));
|
||
|
|
$pdo->prepare("INSERT OR REPLACE INTO device(id,token,created_at) VALUES(:i,:t,datetime('now'))")
|
||
|
|
->execute([':i'=>$id,':t'=>$token]);
|
||
|
|
echo "device=$id token=$token\n";
|