1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
Add the readConfig($filename) function to read the virtual user data from
a configuration file instead of hard-coding it into the module.
Invoke readConfig('/etc/dbix-password.conf') at module load time so
that all users may benefit from a system-wide config file.
Add the clearConfig() function to start the configuration from scratch.
--- a/Password.pm
+++ b/Password.pm
@@ -7,6 +7,64 @@
my $virtual1 = {};
+#We want to end up with such a structure:
+#my $virtual1 = {
+# 'acs' => {
+# 'username' => 'root',
+# 'password' => 'o.r,3',
+# 'port' => '',
+# 'database' => 'acs',
+# 'attributes' => {},
+# 'connect' => 'DBI:mysql:database=acs;host=localhost',
+# 'driver' => 'mysql',
+# 'host' => 'localhost'
+# },
+# 'personales' => {
+# 'username' => 'root',
+# 'password' => 'p.E.1',
+# 'port' => '',
+# 'database' => 'acs',
+# 'attributes' => {},
+# 'connect' => 'DBI:mysql:database=PaginasPersonales;host=
+#localhost',
+# 'driver' => 'mysql',
+# 'host' => 'localhost'
+# },
+#};
+
+sub clearConfig()
+{
+ $virtual1 = {};
+ return 1;
+}
+
+sub readConfig($)
+{
+ my ($config) = @_;
+ my $f;
+ my @user;
+
+ return undef unless -r $config;
+
+ open ($f, $config) || die "Opening config file $config: $!";
+
+ my @fields = qw(user username password port database connect driver
+host);
+
+ while (<$f>) {
+ next if /^(#.*)?$/; #skip comments and blanks
+ @user = m/:?'([^']*)':?/g;
+ foreach (1 .. $#fields) { #write fields
+ $virtual1->{$user[0]}->{$fields[$_]} = $user[$_];
+ };
+ $virtual1->{$user[0]}->{attributes} ||= {};
+ }
+ close $f;
+ return $user[0];
+}
+
+#Now let's fill %virtual1 with values
+readConfig('/etc/dbix-password.conf');
my %driver_cache;
@@ -90,15 +148,18 @@
DBIx::Password::getDriver($user);
DBIx::Password::checkVirtualUser($user);
+ DBIx::Password::clearConfig();
+ DBIx::Password::readConfig("$ENV{HOME}/.my.secret.file");
+
=head1 DESCRIPTION
Don't you hate keeping track of database passwords and such throughout
your scripts? How about the problem of changing those passwords
-on a mass scale? This module is one possible solution. When you
-go to build this module it will ask you to create virtual users.
+on a mass scale? This module is one possible solution. It stores all your
+virtual users and data in /etc/dbix-password.conf.
For each user you need to specify the database module to use,
-the database connect string, the username and the password. You
-will be prompted to give a name to this virtual user.
+the database connect string, the username and the password.
+You will have to give a name to this virtual user.
You can add as many as you like.
I would recommend that if you are only using this with
@@ -125,21 +186,13 @@
This is a rewrite of the module Tangent::DB that I did
for slashcode.
-Hope you enjoy it.
-
-=head1 INSTALL
+If your program does not need the system-wide information stored
+in the /etc/dbix-password.conf file, you may use the clearConfig()
+and readConfig() functions to get the data from another source.
+At any time, readConfig() may also be used to merge the data from
+another file into the currently-loaded configuration.
-Basically:
-
-perl Makefile.PL
-
-make
-
-make test
-
-make install
-
-Be sure to answer the questions as you make the module
+Hope you enjoy it.
=head1 HOME
--- a/README
+++ b/README
@@ -14,11 +14,10 @@
Don't you hate keeping track of database passwords and such
throughout your scripts? How about the problem of changing those
passwords on a mass scale? This module is one possible solution.
- When you go to build this module it will ask you to create
- virtual users. For each user you need to specify the database
+ When you go to build this module it will ask you to create. For each user you need to specify the database
module to use, the database connect string, the username and the
- password. You will be prompted to give a name to this virtual
- user. You can add as many as you like.
+ password. You will have to give a name to this virtual
+ user. All virtual users are stored in /etc/dbix-password.conf
I would recommend that if you are only using this with web
applications that you change the final permissions on this
|