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