1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2024-12-03 03:24:15 +01:00
yubikey-val/ykval-revoke.php
2012-05-29 11:07:19 +02:00

50 lines
1.2 KiB
PHP

<?php
require_once 'ykval-common.php';
require_once 'ykval-config.php';
require_once 'ykval-db.php';
header("content-type: text/plain");
if (!in_array ($_SERVER["REMOTE_ADDR"], $baseParams['__YKREV_IPS__'])) {
logdie("ERROR Authorization failed (logged ". $_SERVER["REMOTE_ADDR"] .")");
}
# Parse input
$yk = $_REQUEST["yk"];
$do = $_REQUEST["do"];
if (!$yk || !$do) {
logdie("ERROR Missing parameter");
}
if (!preg_match("/^([cbdefghijklnrtuv]{0,16})$/", $yk)) {
logdie("ERROR Unknown yk value: $yk");
}
if ($do != "enable" && $do != "disable") {
logdie("ERROR Unknown do value: $do");
}
# Connect to db
$db = new Db($baseParams['__YKVAL_DB_DSN__'],
$baseParams['__YKVAL_DB_USER__'],
$baseParams['__YKVAL_DB_PW__'],
$baseParams['__YKVAL_DB_OPTIONS__'],
'ykval-revoke:db');
if (!$db->connect()) {
logdie("ERROR Database connect error");
}
# Check if key exists
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
if (!$r) {
logdie("ERROR Unknown yubikey: $yk");
}
# Enable/Disable the yubikey
if (!$db->updateBy('yubikeys', 'yk_publicname', $yk,
array('active'=>($do == "enable" ? "1" : "0")))) {
logdie("ERROR Could not $do for $yk (rows $rows)");
}
# We are done
logdie("OK Processed $yk with $do");
?>