2010-02-22 14:28:01 +01:00
|
|
|
<?php
|
2013-02-04 17:36:04 +01:00
|
|
|
|
2015-07-20 22:01:16 +02:00
|
|
|
# Copyright (c) 2009-2015 Yubico AB
|
2013-02-04 17:36:04 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2010-02-22 14:28:01 +01:00
|
|
|
require_once 'ykval-common.php';
|
|
|
|
require_once 'ykval-config.php';
|
|
|
|
require_once 'ykval-db.php';
|
2012-06-14 16:16:29 +02:00
|
|
|
require_once 'ykval-log.php';
|
2010-02-22 14:28:01 +01:00
|
|
|
|
|
|
|
header("content-type: text/plain");
|
|
|
|
|
2012-06-14 16:16:29 +02:00
|
|
|
$myLog = new Log('ykval-revoke');
|
|
|
|
$myLog->addField('ip', $_SERVER['REMOTE_ADDR']);
|
|
|
|
|
2011-05-09 16:31:10 +02:00
|
|
|
if (!in_array ($_SERVER["REMOTE_ADDR"], $baseParams['__YKREV_IPS__'])) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Authorization failed (logged ". $_SERVER["REMOTE_ADDR"] .")");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Parse input
|
|
|
|
$yk = $_REQUEST["yk"];
|
|
|
|
$do = $_REQUEST["do"];
|
|
|
|
if (!$yk || !$do) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Missing parameter");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
if (!preg_match("/^([cbdefghijklnrtuv]{0,16})$/", $yk)) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Unknown yk value: $yk");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
if ($do != "enable" && $do != "disable") {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Unknown do value: $do");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Connect to db
|
2012-06-12 13:27:51 +02:00
|
|
|
$db = Db::GetDatabaseHandle($baseParams, 'ykval-revoke');
|
2010-02-22 14:30:00 +01:00
|
|
|
if (!$db->connect()) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Database connect error");
|
2010-02-22 14:30:00 +01:00
|
|
|
}
|
2010-02-22 14:28:01 +01:00
|
|
|
|
|
|
|
# Check if key exists
|
|
|
|
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
|
2010-06-01 09:43:32 +02:00
|
|
|
if (!$r) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Unknown yubikey: $yk");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Enable/Disable the yubikey
|
|
|
|
if (!$db->updateBy('yubikeys', 'yk_publicname', $yk,
|
2010-06-10 12:01:23 +02:00
|
|
|
array('active'=>($do == "enable" ? "1" : "0")))) {
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "ERROR Could not $do for $yk (rows $rows)");
|
2010-02-22 14:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# We are done
|
2012-06-14 16:16:29 +02:00
|
|
|
logdie($myLog, "OK Processed $yk with $do");
|