mirror of
https://github.com/Yubico/yubikey-ksm.git
synced 2025-01-31 16:52:12 +01:00
Added support for reading db config from /etc/ykksm/
This commit is contained in:
parent
d43308eb56
commit
6279082493
@ -55,10 +55,17 @@ sub usage {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Support dbconfig-common generated database settings, if available
|
||||||
|
our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype);
|
||||||
|
if( -e '/etc/ykksm/config-db.cfg' ) {
|
||||||
|
require '/etc/ykksm/config-db.cfg';
|
||||||
|
} else {
|
||||||
|
$dbtype = 'mysql';
|
||||||
|
$dbname = 'ykksm';
|
||||||
|
}
|
||||||
|
|
||||||
my $verbose = 0;
|
my $verbose = 0;
|
||||||
my $db = "dbi:mysql:ykksm";
|
my $db = "dbi:$dbtype:$dbname";
|
||||||
my $dbuser;
|
|
||||||
my $dbpasswd;
|
|
||||||
while ($ARGV[0] =~ m/^-(.*)/) {
|
while ($ARGV[0] =~ m/^-(.*)/) {
|
||||||
my $cmd = shift @ARGV;
|
my $cmd = shift @ARGV;
|
||||||
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
||||||
@ -70,7 +77,7 @@ while ($ARGV[0] =~ m/^-(.*)/) {
|
|||||||
} elsif ($cmd eq "--db-user") {
|
} elsif ($cmd eq "--db-user") {
|
||||||
$dbuser = shift;
|
$dbuser = shift;
|
||||||
} elsif ($cmd eq "--db-passwd") {
|
} elsif ($cmd eq "--db-passwd") {
|
||||||
$dbpasswd = shift;
|
$dbpass = shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +85,7 @@ if ($#ARGV>=0) {
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1});
|
||||||
my $sth = $dbh->prepare ('SELECT serialnr, publicname, internalname, aeskey '.
|
my $sth = $dbh->prepare ('SELECT serialnr, publicname, internalname, aeskey '.
|
||||||
'FROM yubikeys '.
|
'FROM yubikeys '.
|
||||||
'ORDER BY serialnr, publicname')
|
'ORDER BY serialnr, publicname')
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
$db_dsn = "mysql:dbname=ykksm;host=127.0.0.1";
|
//ykksm will use the configuration stored in /etc/ykksm/config-db.php, if that file exists. If it does not exist, the below values will be used.
|
||||||
$db_username = "ykksmreader";
|
|
||||||
$db_password = "yourpassword";
|
if(!include '/etc/ykksm/config-db.php') {
|
||||||
|
$dbuser='ykksmreader';
|
||||||
|
$dbpass='yourpassword';
|
||||||
|
$basepath='';
|
||||||
|
$dbname='ykksm';
|
||||||
|
$dbserver='';
|
||||||
|
$dbport='';
|
||||||
|
}
|
||||||
|
|
||||||
|
$db_dsn = "$dbtype:dbname=$dbname;host=127.0.0.1";
|
||||||
|
$db_username = $dbuser;
|
||||||
|
$db_password = $dbpass;
|
||||||
$db_options = array();
|
$db_options = array();
|
||||||
$logfacility = LOG_LOCAL0;
|
$logfacility = LOG_AUTH;
|
||||||
?>
|
?>
|
||||||
|
17
ykksm-export
17
ykksm-export
@ -53,10 +53,17 @@ sub usage {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Support dbconfig-common generated database settings, if available
|
||||||
|
our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype);
|
||||||
|
if( -e '/etc/ykksm/config-db.cfg' ) {
|
||||||
|
require '/etc/ykksm/config-db.cfg';
|
||||||
|
} else {
|
||||||
|
$dbtype = 'mysql';
|
||||||
|
$dbname = 'ykksm';
|
||||||
|
}
|
||||||
|
|
||||||
my $verbose = 0;
|
my $verbose = 0;
|
||||||
my $db = "dbi:mysql:ykksm";
|
my $db = "dbi:$dbtype:$dbname";
|
||||||
my $dbuser;
|
|
||||||
my $dbpasswd;
|
|
||||||
while ($ARGV[0] =~ m/^-(.*)/) {
|
while ($ARGV[0] =~ m/^-(.*)/) {
|
||||||
my $cmd = shift @ARGV;
|
my $cmd = shift @ARGV;
|
||||||
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
||||||
@ -68,7 +75,7 @@ while ($ARGV[0] =~ m/^-(.*)/) {
|
|||||||
} elsif ($cmd eq "--db-user") {
|
} elsif ($cmd eq "--db-user") {
|
||||||
$dbuser = shift;
|
$dbuser = shift;
|
||||||
} elsif ($cmd eq "--db-passwd") {
|
} elsif ($cmd eq "--db-passwd") {
|
||||||
$dbpasswd = shift;
|
$dbpass = shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +83,7 @@ if ($#ARGV>=0) {
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1});
|
||||||
my $sth = $dbh->prepare
|
my $sth = $dbh->prepare
|
||||||
('SELECT serialnr, publicname, internalname, aeskey, lockcode, created FROM yubikeys')
|
('SELECT serialnr, publicname, internalname, aeskey, lockcode, created FROM yubikeys')
|
||||||
or die "Couldn't prepare statement: " . $dbh->errstr;
|
or die "Couldn't prepare statement: " . $dbh->errstr;
|
||||||
|
17
ykksm-import
17
ykksm-import
@ -57,11 +57,18 @@ sub usage {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Support dbconfig-common generated database settings, if available
|
||||||
|
our ($dbuser, $dbpass, $basepath, $dbname, $dbserver, $dbport, $dbtype);
|
||||||
|
if( -e '/etc/ykksm/config-db.cfg' ) {
|
||||||
|
require '/etc/ykksm/config-db.cfg';
|
||||||
|
} else {
|
||||||
|
$dbtype = 'mysql';
|
||||||
|
$dbname = 'ykksm';
|
||||||
|
}
|
||||||
|
|
||||||
my $verbose = 0;
|
my $verbose = 0;
|
||||||
my $creator;
|
my $creator;
|
||||||
my $db = "dbi:mysql:ykksm";
|
my $db = "dbi:$dbtype:$dbname";
|
||||||
my $dbuser;
|
|
||||||
my $dbpasswd;
|
|
||||||
while ($ARGV[0] =~ m/^-(.*)/) {
|
while ($ARGV[0] =~ m/^-(.*)/) {
|
||||||
my $cmd = shift @ARGV;
|
my $cmd = shift @ARGV;
|
||||||
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
if (($cmd eq "-v") || ($cmd eq "--verbose")) {
|
||||||
@ -75,7 +82,7 @@ while ($ARGV[0] =~ m/^-(.*)/) {
|
|||||||
} elsif ($cmd eq "--db-user") {
|
} elsif ($cmd eq "--db-user") {
|
||||||
$dbuser = shift;
|
$dbuser = shift;
|
||||||
} elsif ($cmd eq "--db-passwd") {
|
} elsif ($cmd eq "--db-passwd") {
|
||||||
$dbpasswd = shift;
|
$dbpass = shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +121,7 @@ print "signed by: " . $signed_by . "\n";
|
|||||||
|
|
||||||
die "Input not signed?" if !$signed_by;
|
die "Input not signed?" if !$signed_by;
|
||||||
|
|
||||||
my $dbh = DBI->connect($db, $dbuser, $dbpasswd, {'RaiseError' => 1});
|
my $dbh = DBI->connect($db, $dbuser, $dbpass, {'RaiseError' => 1});
|
||||||
my $inserth = $dbh->prepare_cached(qq{
|
my $inserth = $dbh->prepare_cached(qq{
|
||||||
INSERT INTO yubikeys (creator, created, serialnr,
|
INSERT INTO yubikeys (creator, created, serialnr,
|
||||||
publicname, internalname, aeskey, lockcode)
|
publicname, internalname, aeskey, lockcode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user