mirror of
https://github.com/Yubico/yubikey-val.git
synced 2025-02-21 15:54:15 +01:00
more oracle compatibility
This commit is contained in:
parent
cf49385bf3
commit
9e9f20b959
@ -26,11 +26,7 @@ require_once 'ykval-db.php';
|
|||||||
$logname="ykval-checksum-clients";
|
$logname="ykval-checksum-clients";
|
||||||
$myLog = new Log($logname);
|
$myLog = new Log($logname);
|
||||||
|
|
||||||
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
$myLog->log(LOG_WARNING, "Could not connect to database");
|
$myLog->log(LOG_WARNING, "Could not connect to database");
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
require_once('ykval-log.php');
|
require_once('ykval-log.php');
|
||||||
require_once('ykval-db.php');
|
require_once('ykval-db.php');
|
||||||
|
|
||||||
class OciDb extends DB
|
class DbImpl extends DB
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
require_once('ykval-log.php');
|
require_once('ykval-log.php');
|
||||||
require_once('ykval-db.php');
|
require_once('ykval-db.php');
|
||||||
|
|
||||||
class PdoDb
|
class DbImpl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
20
ykval-db.php
20
ykval-db.php
@ -7,8 +7,26 @@
|
|||||||
|
|
||||||
require_once('ykval-log.php');
|
require_once('ykval-log.php');
|
||||||
|
|
||||||
class Db
|
abstract class Db
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* static function to determine database type and instantiate the correct subclass
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
public static function GetDatabaseHandle($baseParams, $logname)
|
||||||
|
{
|
||||||
|
if(substr($baseParams['__YKVAL_DB_DSN__'], 0, 3) == oci) {
|
||||||
|
require_once 'ykval-db-oci.php';
|
||||||
|
} else {
|
||||||
|
require_once 'ykval-db-pdo.php';
|
||||||
|
}
|
||||||
|
return new DbImpl($baseParams['__YKVAL_DB_DSN__'],
|
||||||
|
$baseParams['__YKVAL_DB_USER__'],
|
||||||
|
$baseParams['__YKVAL_DB_PW__'],
|
||||||
|
$baseParams['__YKVAL_DB_OPTIONS__'],
|
||||||
|
$logname . ':db');
|
||||||
|
}
|
||||||
|
|
||||||
function addField($name, $value)
|
function addField($name, $value)
|
||||||
{
|
{
|
||||||
$this->myLog->addField($name, $value);
|
$this->myLog->addField($name, $value);
|
||||||
|
@ -10,11 +10,7 @@ require_once 'ykval-db.php';
|
|||||||
$logname="ykval-export";
|
$logname="ykval-export";
|
||||||
$myLog = new Log($logname);
|
$myLog = new Log($logname);
|
||||||
|
|
||||||
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
$myLog->log(LOG_WARNING, "Could not connect to database");
|
$myLog->log(LOG_WARNING, "Could not connect to database");
|
||||||
@ -22,16 +18,19 @@ if (!$db->connect()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result = $db->customQuery("select id, active, created, secret, email, notes, otp from clients order by id");
|
$result = $db->customQuery("select id, active, created, secret, email, notes, otp from clients order by id");
|
||||||
while($row = $result->fetch(PDO::FETCH_ASSOC)){
|
while($row = $db->fetchArray($result)) {
|
||||||
echo $row['id'] .
|
echo $db->getRowValue($row, 'id'] .
|
||||||
"\t" . $row['active'] .
|
"\t" . $db->getRowValue($row, 'active') .
|
||||||
"\t" . $row['created'] .
|
"\t" . $db->getRowValue($row, 'created') .
|
||||||
"\t" . $row['secret'] .
|
"\t" . $db->getRowValue($row, 'secret') .
|
||||||
"\t" . $row['email'] .
|
"\t" . $db->getRowValue($row, 'email') .
|
||||||
"\t" . $row['notes'] .
|
"\t" . $db->getRowValue($row, 'notes') .
|
||||||
"\t" . $row['otp'] .
|
"\t" . $db->getRowValue($row, 'otp') .
|
||||||
"\n";
|
"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db->closeCursor($result);
|
||||||
|
$db->disconnect();
|
||||||
|
|
||||||
$result=null;
|
$result=null;
|
||||||
$db=null;
|
$db=null;
|
||||||
|
@ -10,11 +10,7 @@ require_once 'ykval-db.php';
|
|||||||
$logname="ykval-export";
|
$logname="ykval-export";
|
||||||
$myLog = new Log($logname);
|
$myLog = new Log($logname);
|
||||||
|
|
||||||
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
$myLog->log(LOG_WARNING, "Could not connect to database");
|
$myLog->log(LOG_WARNING, "Could not connect to database");
|
||||||
|
@ -10,11 +10,7 @@ require_once 'ykval-db.php';
|
|||||||
$logname="ykval-import";
|
$logname="ykval-import";
|
||||||
$myLog = new Log($logname);
|
$myLog = new Log($logname);
|
||||||
|
|
||||||
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
$myLog->log(LOG_WARNING, "Could not connect to database");
|
$myLog->log(LOG_WARNING, "Could not connect to database");
|
||||||
@ -35,7 +31,7 @@ while ($res=fgetcsv(STDIN, 0, "\t")) {
|
|||||||
|
|
||||||
$query="SELECT * FROM clients WHERE id='" . $params['id'] . "'";
|
$query="SELECT * FROM clients WHERE id='" . $params['id'] . "'";
|
||||||
$result=$db->customQuery($query);
|
$result=$db->customQuery($query);
|
||||||
if(!$result->fetch(PDO::FETCH_ASSOC)) {
|
if($db->rowCount($result) == 0) {
|
||||||
// We didn't have the id in database so we need to do insert instead
|
// We didn't have the id in database so we need to do insert instead
|
||||||
$query="INSERT INTO clients " .
|
$query="INSERT INTO clients " .
|
||||||
"(id,active,created,secret,email,notes,otp) VALUES " .
|
"(id,active,created,secret,email,notes,otp) VALUES " .
|
||||||
@ -53,6 +49,7 @@ while ($res=fgetcsv(STDIN, 0, "\t")) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$db->closeCursor($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,11 +10,7 @@ require_once 'ykval-db.php';
|
|||||||
$logname="ykval-import";
|
$logname="ykval-import";
|
||||||
$myLog = new Log($logname);
|
$myLog = new Log($logname);
|
||||||
|
|
||||||
$db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
$myLog->log(LOG_WARNING, "Could not connect to database");
|
$myLog->log(LOG_WARNING, "Could not connect to database");
|
||||||
@ -80,6 +76,7 @@ while ($res=fgetcsv(STDIN, 0, "\t")) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$db->closeCursor($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,11 +23,7 @@ if ($do != "enable" && $do != "disable") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Connect to db
|
# Connect to db
|
||||||
$db = new Db($baseParams['__YKVAL_DB_DSN__'],
|
$db = Db::GetDatabaseHandle($baseParams, 'ykval-revoke');
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
'ykval-revoke:db');
|
|
||||||
if (!$db->connect()) {
|
if (!$db->connect()) {
|
||||||
logdie("ERROR Database connect error");
|
logdie("ERROR Database connect error");
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,7 @@ class SyncLib
|
|||||||
$this->myLog = new Log($logname);
|
$this->myLog = new Log($logname);
|
||||||
global $baseParams;
|
global $baseParams;
|
||||||
$this->syncServers = $baseParams['__YKVAL_SYNC_POOL__'];
|
$this->syncServers = $baseParams['__YKVAL_SYNC_POOL__'];
|
||||||
|
$this->db = Db::GetDatabaseHandle($baseParams, $logname);
|
||||||
$this->db=new Db($baseParams['__YKVAL_DB_DSN__'],
|
|
||||||
$baseParams['__YKVAL_DB_USER__'],
|
|
||||||
$baseParams['__YKVAL_DB_PW__'],
|
|
||||||
$baseParams['__YKVAL_DB_OPTIONS__'],
|
|
||||||
$logname . ':db');
|
|
||||||
$this->isConnected=$this->db->connect();
|
$this->isConnected=$this->db->connect();
|
||||||
$this->server_nonce=md5(uniqid(rand()));
|
$this->server_nonce=md5(uniqid(rand()));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user