diff --git a/Makefile b/Makefile index 8199699..3994d83 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/NEWS b/NEWS index de36d0c..172fc7a 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/ykval-config.php b/ykval-config.php index 4ed16e8..fda083a 100644 --- a/ykval-config.php +++ b/ykval-config.php @@ -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", diff --git a/ykval-db.php b/ykval-db.php index fb883b6..4260489 100644 --- a/ykval-db.php +++ b/ykval-db.php @@ -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; diff --git a/ykval-export-clients.php b/ykval-export-clients.php new file mode 100755 index 0000000..f0b8a2d --- /dev/null +++ b/ykval-export-clients.php @@ -0,0 +1,40 @@ +#!/usr/bin/php +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; + + +?> diff --git a/ykval-import-clients.php b/ykval-import-clients.php new file mode 100755 index 0000000..abc525a --- /dev/null +++ b/ykval-import-clients.php @@ -0,0 +1,60 @@ +#!/usr/bin/php +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"; diff --git a/ykval-import.php b/ykval-import.php index dca95e7..185ec51 100755 --- a/ykval-import.php +++ b/ykval-import.php @@ -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], diff --git a/ykval-verify.php b/ykval-verify.php index ff145d9..8f66ef9 100644 --- a/ykval-verify.php +++ b/ykval-verify.php @@ -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__']; }