root/tags/omega-1.0.0-rc2/engine/ispcp-db-passwd

Revision 479, 4.4 kB (checked in by malte, 2 years ago)

--

Line 
1 #!/usr/bin/perl
2
3 # ISPCP(tm) - Virtual Hosting Control System
4 # Copyright (c) 2001-2004 by moleSoftware GmbH
5 # http://www.molesoftware.com
6 #
7 #
8 # License:
9 #    This program is free software; you can redistribute it and/or
10 #    modify it under the terms of the MPL Mozilla Public License
11 #    as published by the Free Software Foundation; either version 1.1
12 #    of the License, or (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    MPL Mozilla Public License for more details.
18 #
19 #    You may have received a copy of the MPL Mozilla Public License
20 #    along with this program.
21 #
22 #    An on-line copy of the MPL Mozilla Public License can be found
23 #    http://www.mozilla.org/MPL/MPL-1.1.html
24 #
25 #
26 # The ISPCP Home Page is at:
27 #
28 #    http://www.vhcs.net
29
30
31 use FindBin;
32 use lib "$FindBin::Bin/";
33 require 'ispcp_common_code.pl';
34
35 use strict;
36
37 use warnings;
38
39 sub db_passwd_start_up {
40
41     my ($rs, $rdata) = (undef, undef);
42
43     push_el(\@main::el, 'db_passwd_start_up()', 'Starting...');
44
45     # config check;
46
47     $rs = get_conf();
48
49     return $rs if ($rs != 0);
50
51     push_el(\@main::el, 'db_passwd_start_up()', 'Ending...');
52
53     return 0;
54
55 }
56
57 sub get_user_pass {
58
59     my ($check_with) = @_;
60
61     my ($rs, $rdata, $upass, $upass_check, $upass_current) = (undef, undef, undef, undef, undef);
62
63     push_el(\@main::el, 'get_user_pass()', 'Starting...');
64
65     if ($check_with eq '') {
66
67         $upass = read_password('Please Enter Your New Database Password:');
68
69         if ($upass eq '') {
70
71             return (1, '');
72
73         }
74
75         $upass_check = read_password('Please Repeat Your New Database Password:');
76
77         if ($upass ne $upass_check) {
78
79             print STDERR ">>> Enterred passwords differ. Please try again !\n";
80
81             return (1, '');
82
83         } else {
84
85             return (0, $upass);
86
87         }
88
89     } else {
90
91         $upass_current = read_password('Please Enter Your Current Password:');
92
93         if ($upass_current ne $check_with) {
94
95             print STDERR ">>> Enterred password does not match. Please try again !\n";
96
97             return (1, '');
98
99         }
100
101         $upass = read_password('Please Enter Your New Database Password:');
102
103         if ($upass eq '') {
104
105             return (0, '');
106
107         }
108
109         $upass_check = read_password('Please Repeat Your New Database Password:');
110
111         if ($upass ne $upass_check) {
112
113             print STDERR ">>> Enterred passwords differ. Please try again !\n";
114
115             return (1, '');
116
117         } else {
118
119             return (0, $upass);
120
121         }
122
123     }
124
125     push_el(\@main::el, 'get_user_pass()', 'Ending...');
126
127     return 0;
128
129 }
130
131 my ($rs, $rdata) = (undef, undef);
132
133 $rs = db_passwd_start_up();
134
135 if ($rs != 0) {
136
137     my $el_data = pop_el(\@main::el);
138
139     my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
140
141     print STDERR "$msg\n";
142
143     exit 1;
144
145 }
146
147         my $current_db_pass = undef ;
148
149 if(exists  $main::cfg{'DATABASE_PASSWORD'} && $main::cfg{'DATABASE_PASSWORD'}) {
150         $current_db_pass = $main::cfg{'DATABASE_PASSWORD'};
151 }
152 else {
153         $current_db_pass = '';
154 }
155
156
157 if ($current_db_pass eq '') { # We have not DATABASE password;
158
159     ($rs, $rdata) = get_user_pass('');
160
161 } else {
162
163     ($rs, $current_db_pass) = decrypt_db_password($current_db_pass);
164
165     if ($rs != 0) {
166
167         my $el_data = pop_el(\@main::el);
168
169         my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
170
171         print STDERR "$msg\n";
172
173         exit 1;
174
175     }
176
177     ($rs, $rdata) = get_user_pass($current_db_pass);
178
179 }
180
181 if ($rs == 0) {
182
183     my $new_db_pass = $rdata;
184
185     if ($new_db_pass ne '') {
186
187         ($rs, $rdata) = encrypt_db_password($new_db_pass);
188
189         if ($rs != 0) {
190
191             my $el_data = pop_el(\@main::el);
192
193             my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
194
195             print STDERR "$msg\n";
196
197             exit 1;
198
199         }
200
201     }
202
203     $rs = set_conf_val('DATABASE_PASSWORD', $rdata);
204
205     if ($rs != 0) {
206
207         my $el_data = pop_el(\@main::el);
208
209         my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
210
211         print STDERR "$msg\n";
212
213         exit 1;
214
215     }
216
217     $rs = store_conf();
218
219     if ($rs != 0) {
220
221         my $el_data = pop_el(\@main::el);
222
223         my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
224
225         print STDERR "$msg\n";
226
227         exit 1;
228
229     }
230
231     print STDOUT "Database Password Updated Successfully!\n";
232
233 }
234
Note: See TracBrowser for help on using the browser.