echo "graph_category ykval\n";
    echo "yubikeys_enabled.label Enabled YubiKeys\n";
    echo "yubikeys_enabled.draw AREA\n";
    echo "yubikeys_disabled.label Disabled YubiKeys\n";
    echo "yubikeys_disabled.draw STACK\n";
    echo "yubikeys_1month.label YubiKeys seen last month\n";
    echo "yubikeys_1month.draw LINE2\n";
    echo "clients_enabled.label Enabled validation clients\n";
    echo "clients_enabled.draw LINE2\n";
    echo "clients_disabled.label Disabled validation clients\n";
    echo "clients_disabled.draw LINE2\n";
    exit(0);
}
$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-yubikeystats');
if (!$db->connect()) {
    logdie($myLog, 'ERROR Database connect error (1)');
}
function get_count($db, $table, $conditions)
{
    $res = $db->customQuery("SELECT count(1) as count FROM {$table} WHERE {$conditions}");
    if ($res) {
        $r = $res->fetch(PDO::FETCH_ASSOC);
        return $r['count'];
    }
    return Null;
}
if ($count = get_count($db, 'yubikeys', 'active=true')) {
    echo "yubikeys_enabled.value {$count}\n";
}
if ($count = get_count($db, 'yubikeys', 'active=false')) {
    echo "yubikeys_disabled.value {$count}\n";
示例#2
0
    $db->closeCursor($res);
} else {
    # Check if key exists
    $r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
    if (!$r) {
        logdie($myLog, "ERROR Unknown yubikey: {$yk}");
    }
    $yubikeys = array($yk);
}
/* Initialize the sync library. */
$sync = new SyncLib('ykval-resync:synclib');
$sync->addField('ip', $_SERVER['REMOTE_ADDR']);
$sync->addField('yk', $yk);
if (!$sync->isConnected()) {
    logdie($myLog, 'ERROR Database connect error (2)');
}
foreach ($yubikeys as $key) {
    if (($localParams = $sync->getLocalParams($key)) === FALSE) {
        logdie($myLog, 'ERROR Invalid Yubikey ' . $key);
    }
    $localParams['otp'] = $key . str_repeat('c', 32);
    // Fake an OTP, only used for logging.
    $myLog->log(LOG_DEBUG, "Auth data:", $localParams);
    /* Queue sync request */
    if (!$sync->queue($localParams, $localParams)) {
        logdie($myLog, 'ERROR Failed resync');
    }
}
# We are done
logdie($myLog, "OK Initiated resync of {$yk}");
示例#3
0
<?
include "config.php";

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: *');

if ($_SERVER['REQUEST_METHOD'] != "POST") {
	logdie("Not allowed");
}

if (isset($_SERVER['HTTP_REFERER']) and strpos($_SERVER['HTTP_REFERER'], $site) === false and strpos(strtolower($_SERVER['HTTP_REFERER']), $site_domain) === false) { 
	header('HTTP/1.0 403 Forbidden');
	logdie("Referer error.");
}

logtext("Request: Parsing parameters...");

logtext($_SERVER);
logtext($_POST);

logtext("Adding work...");

list($work_id, $work_task, $work_solution) = addWork();

$back = array();
$back["work_id"] = $work_id;
$back["work_task"] = $work_task;

$back = json_encode($back);
示例#4
0
    logdie($myLog, "ERROR Authorization failed (logged " . $_SERVER["REMOTE_ADDR"] . ")");
}
# Parse input
$yk = $_REQUEST["yk"];
$do = $_REQUEST["do"];
if (!$yk || !$do) {
    logdie($myLog, "ERROR Missing parameter");
}
if (!preg_match("/^([cbdefghijklnrtuv]{0,16})\$/", $yk)) {
    logdie($myLog, "ERROR Unknown yk value: {$yk}");
}
if ($do != "enable" && $do != "disable") {
    logdie($myLog, "ERROR Unknown do value: {$do}");
}
# Connect to db
$db = Db::GetDatabaseHandle($baseParams, 'ykval-revoke');
if (!$db->connect()) {
    logdie($myLog, "ERROR Database connect error");
}
# Check if key exists
$r = $db->findBy('yubikeys', 'yk_publicname', $yk, 1);
if (!$r) {
    logdie($myLog, "ERROR Unknown yubikey: {$yk}");
}
# Enable/Disable the yubikey
if (!$db->updateBy('yubikeys', 'yk_publicname', $yk, array('active' => $do == "enable" ? "1" : "0"))) {
    logdie($myLog, "ERROR Could not {$do} for {$yk} (rows {$rows})");
}
# We are done
logdie($myLog, "OK Processed {$yk} with {$do}");
if ($argc == 2 && strcmp($argv[1], "config") == 0) {
    echo "graph_title YK-VAL queue size\n";
    echo "graph_vlabel sync requests in queue\n";
    echo "graph_category ykval\n";
    foreach ($shortnames as $shortname) {
        echo "queuelength_{$shortname}.label sync {$shortname}\n";
        echo "queuelength_{$shortname}.draw AREASTACK\n";
        echo "queuelength_{$shortname}.type GAUGE\n";
    }
    exit(0);
}
$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength');
if (!$db->connect()) {
    logdie($myLog, 'ERROR Database connect error (1)');
}
$res = $db->customQuery('select server,count(server) as count from queue group by server');
if ($res) {
    $r = $res->fetchAll(PDO::FETCH_ASSOC);
} else {
    logdie($myLog, 'ERROR getting data from db');
}
foreach ($shortnames as $shortname) {
    $count = 0;
    foreach ($r as $result) {
        if (strpos($result['server'], "{$shortname}.") !== FALSE) {
            $count = $result['count'];
            break;
        }
    }
    echo "queuelength_{$shortname}.value {$count}\n";
}
示例#6
0
 public static function MySQL($host = "localhost", $username = "******", $passwort = "", $dbname = "localchat")
 {
     if (DEBUG) {
         echo "MySQL\n";
     }
     $conn = new mysqli($servername, $username, $password, $dbname);
     if ($conn->connect_error) {
         logdie("[connect] " . $conn->connect_error . "\n");
     }
     return true;
 }
示例#7
0
$data->users->{$user_name} = "web,$auth_address,$sign";
$json_out = json_encode($data, JSON_PRETTY_PRINT);

$f = fopen($users_json, "w");
fwrite($f, $json_out);
fclose($f);


logtext("Signing...");
$out = array();
exec("python zeronet.py --debug siteSign $site $privatekey --publish 2>&1", $out);
$out = implode("\n", $out);
logtext($out);
if (strpos($out, "content.json signed!") === false) {
	header("HTTP/1.0 500 Internal Server Error");
	logdie("Site sign error, please contact site owner!");
}

/*
logtext("Publishing...");
$server_ip = $_SERVER['SERVER_ADDR'];
$out = array();
exec("python zeronet.py --debug --ip_external $server_ip sitePublish $site 2>&1", $out);
$out = implode("\n", $out);
logtext($out);
if (strpos($out, "Successfuly published") === false) {
	header("HTTP/1.0 500 Internal Server Error");
	logdie("Publish error, please contact site owner!");
}
*/
    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}");