1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-01-20 10:52:15 +01:00

Merge branch 'master' of github.com:Yubico/yubikey-val-server-php

This commit is contained in:
Fredrik Thulin 2012-05-25 10:59:43 +02:00
commit 4b50b225c9
8 changed files with 129 additions and 9 deletions

View File

@ -1,4 +1,4 @@
VERSION = 2.14
VERSION = 2.16
PACKAGE = yubikey-val
CODE = COPYING Makefile NEWS ykval-checksum-clients.php \
ykval-common.php ykval-config.php ykval-db.php ykval-db.sql \

17
NEWS
View File

@ -1,4 +1,19 @@
* Version 2.14 unreleased
* Version 2.16 unreleased
* Version 2.15 released 2012-05-24
* Add export/import scripts for clients table.
* Insert default values in $sl and $timeout if they are empty.
And they will be empty if the client didn't request them.
* Version 2.14 released 2012-05-22
* Add support for reconnecting to database after errors.
* Fixes for PHP warnings.
* Detect timeouts and errors in munin checks.
* Version 2.13 released 2012-05-16

View File

@ -5,7 +5,7 @@ $baseParams = array ();
$baseParams['__YKVAL_DB_DSN__'] = "mysql:dbname=ykval;host=127.0.0.1";
$baseParams['__YKVAL_DB_USER__'] = 'ykval_verifier';
$baseParams['__YKVAL_DB_PW__'] = 'lab';
$baseParams['__YKVAL_DB_OPTIONS__'] = array();
$baseParams['__YKVAL_DB_OPTIONS__'] = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
# For the validation server sync
$baseParams['__YKVAL_SYNC_POOL__'] = array("http://api2.example.com/wsapi/2.0/sync",

View File

@ -104,12 +104,17 @@ class Db
}
private function query($query, $returnresult=false) {
if($this->dbh) {
if(!$this->isConnected()) {
$this->connect();
}
if($this->isConnected()) {
$this->myLog->log(LOG_DEBUG, 'DB query is: ' . $query);
$this->result = $this->dbh->query($query);
if (! $this->result){
try {
$this->result = $this->dbh->query($query);
} catch (PDOException $e) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true)));
$this->dbh = Null;
return false;
}
if ($returnresult) return $this->result;

40
ykval-export-clients.php Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/php
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/usr/share/ykval:/etc/ykval");
require_once 'ykval-config.php';
require_once 'ykval-db.php';
$logname="ykval-export";
$myLog = new Log($logname);
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
$baseParams['__YKVAL_DB_USER__'],
$baseParams['__YKVAL_DB_PW__'],
$baseParams['__YKVAL_DB_OPTIONS__'],
$logname . ':db');
if (!$db->connect()) {
$myLog->log(LOG_WARNING, "Could not connect to database");
exit(1);
}
$result = $db->customQuery("select id, active, created, secret, email, notes, otp from clients order by id");
while($row = $result->fetch(PDO::FETCH_ASSOC)){
echo $row['id'] .
"\t" . $row['active'] .
"\t" . $row['created'] .
"\t" . $row['secret'] .
"\t" . $row['email'] .
"\t" . $row['notes'] .
"\t" . $row['otp'] .
"\n";
}
$result=null;
$db=null;
?>

60
ykval-import-clients.php Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/php
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/usr/share/ykval:/etc/ykval");
require_once 'ykval-config.php';
require_once 'ykval-db.php';
$logname="ykval-import";
$myLog = new Log($logname);
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
$baseParams['__YKVAL_DB_USER__'],
$baseParams['__YKVAL_DB_PW__'],
$baseParams['__YKVAL_DB_OPTIONS__'],
$logname . ':db');
if (!$db->connect()) {
$myLog->log(LOG_WARNING, "Could not connect to database");
error_log("Could not connect to database");
exit(1);
}
while ($res=fgetcsv(STDIN, 0, "\t")) {
$params=array("id"=>$res[0],
"active"=>$res[1],
"created"=>$res[2],
"secret"=>$res[3],
"email"=>$res[4],
"notes"=>$res[5],
"otp"=>$res[6]);
$query="SELECT * FROM clients WHERE id='" . $params['id'] . "'";
$result=$db->customQuery($query);
if(!$result->fetch(PDO::FETCH_ASSOC)) {
// We didn't have the id in database so we need to do insert instead
$query="INSERT INTO clients " .
"(id,active,created,secret,email,notes,otp) VALUES " .
"('" . $params["id"] . "', " .
"'" . $params["active"] . "', " .
"'" . $params['created'] . "'," .
"'" . $params['secret'] . "'," .
"'" . $params['email'] . "'," .
"'" . $params['notes'] . "'," .
"'" . $params['otp'] . "')";
if(!$db->customQuery($query)){
$myLog->log(LOG_ERR, "Failed to insert new client with query " . $query);
error_log("Failed to insert new client with query " . $query);
exit(1);
}
}
}
$myLog->log(LOG_NOTICE, "Successfully imported clients to database");
echo "Successfully imported clients to database\n";

View File

@ -23,7 +23,7 @@ if (!$db->connect()) {
}
while ($res=fscanf(STDIN, "%d\t%d\t%d\t%s\t%d\t%d\t%d\t%d\t%s\t%s\t")) {
while ($res=fgetcsv(STDIN, 0, "\t")) {
$params=array("active"=>$res[0],
"created"=>$res[1],
"modified"=>$res[2],

View File

@ -81,10 +81,10 @@ if (isset($sl) && strcasecmp($sl, 'fast')==0) {
if (isset($sl) && strcasecmp($sl, 'secure')==0) {
$sl=$baseParams['__YKVAL_SYNC_SECURE_LEVEL__'];
}
if (!isset($sl)) {
if (!isset($sl) || $sl == '') {
$sl=$baseParams['__YKVAL_SYNC_DEFAULT_LEVEL__'];
}
if (!isset($timeout)) {
if (!isset($timeout) || $timeout == '') {
$timeout=$baseParams['__YKVAL_SYNC_DEFAULT_TIMEOUT__'];
}