2010-02-22 13:28:01 +00:00
|
|
|
<?php
|
|
|
|
require_once 'ykval-common.php';
|
|
|
|
require_once 'ykval-config.php';
|
|
|
|
require_once 'ykval-db.php';
|
|
|
|
|
|
|
|
header("content-type: text/plain");
|
|
|
|
|
2011-05-09 14:31:10 +00:00
|
|
|
if (!in_array ($_SERVER["REMOTE_ADDR"], $baseParams['__YKREV_IPS__'])) {
|
|
|
|
logdie("ERROR Authorization failed (logged ". $_SERVER["REMOTE_ADDR"] .")");
|
2010-02-22 13:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2012-06-12 13:27:51 +02:00
|
|
|
$db = Db::GetDatabaseHandle($baseParams, 'ykval-revoke');
|
2010-02-22 13:30:00 +00:00
|
|
|
if (!$db->connect()) {
|
|
|
|
logdie("ERROR Database connect error");
|
|
|
|
}
|
2010-02-22 13:28:01 +00:00
|
|
|
|
|
|
|
# Check if key exists
|
|
|
|
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
|
2010-06-01 07:43:32 +00:00
|
|
|
if (!$r) {
|
2010-02-22 13:28:01 +00:00
|
|
|
logdie("ERROR Unknown yubikey: $yk");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Enable/Disable the yubikey
|
|
|
|
if (!$db->updateBy('yubikeys', 'yk_publicname', $yk,
|
2010-06-10 10:01:23 +00:00
|
|
|
array('active'=>($do == "enable" ? "1" : "0")))) {
|
2010-02-22 13:28:01 +00:00
|
|
|
logdie("ERROR Could not $do for $yk (rows $rows)");
|
|
|
|
}
|
|
|
|
|
|
|
|
# We are done
|
|
|
|
logdie("OK Processed $yk with $do");
|
|
|
|
?>
|