/[Development]/mod_auth_ibmdb2/scripts/user_imp
ViewVC logotype

Contents of /mod_auth_ibmdb2/scripts/user_imp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations)
Sun Oct 22 12:28:07 2006 UTC (3 years, 10 months ago) by tessus
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -2 lines
removed unnecessary env variable
1 #!/usr/local/bin/php
2 <?php
3
4 // $Id: user_imp,v 1.3 2006/10/22 12:28:07 tessus Exp $
5
6 if( $argc != 2 )
7 {
8 echo "\nUsage: user_imp USER-FILE\n";
9 echo "\n USER-FILE user file generated by htpasswd\n\n";
10
11 exit(1);
12 }
13
14 if( !file_exists( $argv[1] ) )
15 {
16 echo "\n$argv[1] does not exist!\n\n";
17
18 exit(1);
19 }
20
21 if( !is_readable( $argv[1] ) )
22 {
23 echo "\n$argv[1] is not readable!\n\n";
24
25 exit(1);
26 }
27
28 putenv ("DB2INSTANCE=db2inst1");
29 putenv ("LD_LIBRARY_PATH=:/home/db2inst1/sqllib/lib");
30 putenv ("LIBPATH=:/home/db2inst1/sqllib/lib");
31
32 require ('./config.php');
33
34 $handle = fopen ($argv[1], "r");
35
36 while (!feof ($handle))
37 {
38 $line = fgets($handle, 512);
39
40 list($username,$password) = explode(":",$line);
41
42 if( $username != '' )
43 {
44 if( substr( $password, -1 ) == "\n" )
45 $password = substr($password,0,-1);
46 $arr["$username"] = $password;
47 }
48 }
49
50 fclose ($handle);
51
52 $conn = db2_connect( $dbname, $dbuser, $dbpwd );
53
54 echo "\nImporting users into table '$usertable' in database '$dbname'\n\n";
55
56 $i = 0;
57 $ni = 0;
58
59 foreach ($arr as $u => $p)
60 {
61 $insert = "insert into $usertable ($namefield, $passwordfield) values ('$u', '$p')";
62 $res=@db2_exec( $conn, $insert );
63
64 if( $res != FALSE )
65 {
66 echo "User $u imported.\n";
67 $i++;
68 }
69 else
70 {
71 echo "User $u NOT imported.\n";
72 $ni++;
73 }
74 }
75
76 echo "\n";
77 echo "Users imported: $i\n";
78 echo "Users rejected: $ni\n";
79 echo "\n";
80
81 return 0;
82
83 ?>

CVS admin
ViewVC Help
Powered by ViewVC 1.1.5