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

Revision 595, 4.5 kB (checked in by rats, 2 years ago)

in addition to #256 changed some license things

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