/[docman]/adduser-dbi.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /adduser-dbi.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Thu Sep 6 12:43:23 2001 UTC (22 years, 6 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
script to add users if SQL datatabse is used for storage

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     # perl script to add users to Document Manager's users table in RDBMS
4    
5     use Digest::MD5 qw(md5_hex);
6     use DBI;
7    
8     # php dbi to Perl dbi translation of database drivers (DBDs)
9     my %dbi_trans = (
10     "pgsql" => "Pg",
11     "mysql" => "mysql",
12     "odbc" => "ODBC",
13     "oracle" => "Oracle"
14     );
15    
16     my $login = shift @ARGV;
17    
18     if (defined $login && $login eq "-h") {
19     print "Usage: $0 [login] [full name] [password] [email]\n";
20     exit;
21     }
22    
23     while (! $login) {
24     print "login: ";
25     $login=<STDIN>; chomp $login;
26     }
27    
28     my $fullname = shift @ARGV;
29     while (! $fullname) {
30     print "full name: ";
31     $fullname=<STDIN>; chomp $fullname;
32     }
33    
34     my $passwd = shift @ARGV;
35     if (! $passwd) {
36     print "password [auth_pop3]: ";
37     $passwd=<STDIN>; chomp $passwd;
38     if ($passwd eq "") {
39     $passwd="auth_pop3";
40     }
41     }
42     if (substr($passwd,0,5) ne "auth_") {
43     $passwd=md5_hex($login.$passwd);
44     }
45    
46     my $email = shift @ARGV;
47     while (! $email || $email !~ /\w@\w/) {
48     print "e-mail: ";
49     $email=<STDIN>; chomp $email;
50     print "e-mail address needs to have user\@domain for auth_pop3",
51     " to work!\n" if ($email !~ /\w@\w/);
52     }
53    
54     my $conffile=".docman.conf";
55    
56     while (! -e $conffile) {
57     print "docman conf file [docman.conf]: ";
58     $conffile=<STDIN>; chomp $conffile;
59     if ($conffile eq "") {
60     $conffile="docman.conf";
61     }
62     }
63    
64     my $dbi_sql; # this will be filled from docman's config file
65     my $dbi; # this will be filled with connect string
66    
67     open(CONF,$conffile) || die "open $conffile: $!";
68     while(<CONF>) {
69     chomp;
70     if (/(\$dbi[^;]+;)/i) {
71     eval $1;
72     }
73     }
74     close(CONF);
75    
76     if (! defined $dbi) {
77     print STDERR "ERROR: can't find DBI connect docman conf file, aborting!\n";
78     exit 1;
79     } else {
80     ($php_dbd,$db,$db_login,$db_passwd) = split(/:/,$dbi);
81     }
82    
83     if (! defined $dbi_sql) {
84     print STDERR "ERROR: can't find SQL query in docman conf file, aborting!\n";
85     exit 1;
86     } else {
87     if ($dbi_sql =~ m/select\s+(.+)\s+from\s+(.+)/i) {
88     ($cols,$table) = ($1,$2);
89     } else {
90     print STDERR "ERROR: can't parse SQL query '$dbi_sql', aborting!\n";
91     exit 1;
92     }
93     }
94    
95     my $dbh = DBI->connect("DBI:".$dbi_trans{$php_dbd}.":dbname=$db","$db_login","$db_passwd") || die $DBI::errstr;
96     my $sql = "insert into $table ($cols) values ('$login','$fullname','$passwd','$email')";
97     $dbh->do("$sql") || die $dbh->errstr();
98     $dbh->disconnect;
99    

  ViewVC Help
Powered by ViewVC 1.1.26