| 1 |
#!/usr/bin/perl |
|---|
| 2 |
|
|---|
| 3 |
# ispCP ω (OMEGA) a Virtual Hosting Control Panel |
|---|
| 4 |
# Copyright (c) 2007-2008 by ispCP |
|---|
| 5 |
# http://isp-control.net |
|---|
| 6 |
# |
|---|
| 7 |
# |
|---|
| 8 |
# License: |
|---|
| 9 |
# This program is free software; you can redistribute it and/or |
|---|
| 10 |
# modify it under the terms of the GPL General Public License |
|---|
| 11 |
# as published by the Free Software Foundation; either version 2.0 |
|---|
| 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 |
# GPL General Public License for more details. |
|---|
| 18 |
# |
|---|
| 19 |
# You may have received a copy of the GPL General Public License |
|---|
| 20 |
# along with this program. |
|---|
| 21 |
# |
|---|
| 22 |
# An on-line copy of the GPL General Public License can be found |
|---|
| 23 |
# http://www.fsf.org/licensing/licenses/gpl.txt |
|---|
| 24 |
# |
|---|
| 25 |
# The ispCP ω Home Page is at: |
|---|
| 26 |
# |
|---|
| 27 |
# http://isp-control.net |
|---|
| 28 |
# |
|---|
| 29 |
|
|---|
| 30 |
use strict; |
|---|
| 31 |
use warnings; |
|---|
| 32 |
|
|---|
| 33 |
################################################################################ |
|---|
| 34 |
## SUBROUTINES ## |
|---|
| 35 |
################################################################################ |
|---|
| 36 |
|
|---|
| 37 |
sub ask_hostname { |
|---|
| 38 |
push_el(\@main::el, 'ask_hostname()', 'Starting...'); |
|---|
| 39 |
|
|---|
| 40 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 41 |
my $hostname = undef; |
|---|
| 42 |
|
|---|
| 43 |
($rs, $hostname) = get_sys_hostname(); |
|---|
| 44 |
return $rs if ($rs != 0); |
|---|
| 45 |
|
|---|
| 46 |
my $qmsg = "\n\tPlease enter a fully qualified hostname. [$hostname]: "; |
|---|
| 47 |
print STDOUT $qmsg; |
|---|
| 48 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 49 |
|
|---|
| 50 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 51 |
$rdata = $hostname; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
if ($rdata =~ /^(((([\w][\w-]{0,253}){0,1}[\w])\.)*)([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 55 |
if ($rdata =~ /^([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 56 |
my $wmsg = "\tWARNING: $rdata is not a \"fully qualified hostname\". Be aware you cannot use this domain for websites."; |
|---|
| 57 |
print STDOUT $wmsg; |
|---|
| 58 |
} |
|---|
| 59 |
$main::ua{'hostname'} = $rdata; |
|---|
| 60 |
$main::ua{'hostname_local'} = ( ($1) ? $1 : $4); |
|---|
| 61 |
$main::ua{'hostname_local'} =~ s/^([^.]+).+$/$1/; |
|---|
| 62 |
} |
|---|
| 63 |
else { |
|---|
| 64 |
print STDOUT "\n\tHostname is not a valid domain name!\n"; |
|---|
| 65 |
return 1; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
push_el(\@main::el, 'ask_hostname()', 'Ending...'); |
|---|
| 69 |
return 0; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
sub ask_eth { |
|---|
| 73 |
push_el(\@main::el, 'ask_eth()', 'Starting...'); |
|---|
| 74 |
|
|---|
| 75 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 76 |
#my $cmd = "/sbin/ifconfig |awk \'BEGIN{FS=\":\";}{print \$2}\'|awk \'{if(NR==2)print \$1}\' 1>/tmp/ispcp-setup.ip"; |
|---|
| 77 |
my $cmd = "/sbin/ifconfig |grep -v inet6|grep inet|grep -v 127.0.0.1|awk ' {print \$2}'|head -n 1|awk -F: '{print \$NF}' 1>/tmp/ispcp-setup.ip"; |
|---|
| 78 |
|
|---|
| 79 |
$rs = sys_command($cmd); |
|---|
| 80 |
return ($rs, '') if ($rs != 0); |
|---|
| 81 |
|
|---|
| 82 |
($rs, $rdata) = get_file("/tmp/ispcp-setup.ip"); |
|---|
| 83 |
return ($rs, '') if ($rs != 0); |
|---|
| 84 |
|
|---|
| 85 |
chop($rdata); |
|---|
| 86 |
|
|---|
| 87 |
$rs = del_file("/tmp/ispcp-setup.ip"); |
|---|
| 88 |
$rs = sys_command($cmd); |
|---|
| 89 |
return $rs if ($rs != 0); |
|---|
| 90 |
|
|---|
| 91 |
my $eth = $rdata; |
|---|
| 92 |
my $qmsg = "\n\tPlease enter system network address. [$eth]: "; |
|---|
| 93 |
print STDOUT $qmsg; |
|---|
| 94 |
|
|---|
| 95 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 96 |
|
|---|
| 97 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 98 |
$main::ua{'eth_ip'} = $eth; |
|---|
| 99 |
} |
|---|
| 100 |
else { |
|---|
| 101 |
$main::ua{'eth_ip'} = $rdata; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
if (check_eth($main::ua{'eth_ip'}) != 0) { |
|---|
| 105 |
return 0; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
push_el(\@main::el, 'ask_eth()', 'Ending...'); |
|---|
| 109 |
return 1; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
sub check_eth { |
|---|
| 113 |
|
|---|
| 114 |
my ($ip) = @_; |
|---|
| 115 |
return 0 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)); |
|---|
| 116 |
|
|---|
| 117 |
$ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; |
|---|
| 118 |
my ($d1, $d2, $d3, $d4) = ($1, $2, $3, $4); |
|---|
| 119 |
|
|---|
| 120 |
return 0 if (($d1 <= 0) || ($d1 >= 255)); |
|---|
| 121 |
return 0 if (($d2 < 0) || ($d2 > 255)); |
|---|
| 122 |
return 0 if (($d3 < 0) || ($d3 > 255)); |
|---|
| 123 |
return 0 if (($d4 <= 0) || ($d4 >= 255)); |
|---|
| 124 |
|
|---|
| 125 |
return 1; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
sub ask_db_host { |
|---|
| 129 |
push_el(\@main::el, 'ask_db_host()', 'Starting...'); |
|---|
| 130 |
|
|---|
| 131 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 132 |
my $db_host = 'localhost'; |
|---|
| 133 |
my $qmsg = "\n\tPlease enter SQL server host. [$db_host]: "; |
|---|
| 134 |
|
|---|
| 135 |
print STDOUT $qmsg; |
|---|
| 136 |
|
|---|
| 137 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 138 |
|
|---|
| 139 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 140 |
$main::ua{'db_host'} = $db_host; |
|---|
| 141 |
} |
|---|
| 142 |
else { |
|---|
| 143 |
$main::ua{'db_host'} = $rdata; |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
push_el(\@main::el, 'ask_db_host()', 'Ending...'); |
|---|
| 147 |
return 0; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
sub ask_db_name { |
|---|
| 151 |
push_el(\@main::el, 'ask_db_name()', 'Starting...'); |
|---|
| 152 |
|
|---|
| 153 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 154 |
my $db_name = 'ispcp'; |
|---|
| 155 |
my $qmsg = "\n\tPlease enter system SQL database. [$db_name]: "; |
|---|
| 156 |
|
|---|
| 157 |
print STDOUT $qmsg; |
|---|
| 158 |
|
|---|
| 159 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 160 |
|
|---|
| 161 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 162 |
$main::ua{'db_name'} = $db_name; |
|---|
| 163 |
} |
|---|
| 164 |
else { |
|---|
| 165 |
$main::ua{'db_name'} = $rdata; |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
push_el(\@main::el, 'ask_db_name()', 'Ending...'); |
|---|
| 169 |
return 0; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
sub ask_db_user { |
|---|
| 174 |
push_el(\@main::el, 'ask_db_user()', 'Starting...'); |
|---|
| 175 |
|
|---|
| 176 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 177 |
my $db_user = 'root'; |
|---|
| 178 |
my $qmsg = "\n\tPlease enter system SQL user. [$db_user]: "; |
|---|
| 179 |
|
|---|
| 180 |
print STDOUT $qmsg; |
|---|
| 181 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 182 |
|
|---|
| 183 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 184 |
$main::ua{'db_user'} = $db_user; |
|---|
| 185 |
} |
|---|
| 186 |
else { |
|---|
| 187 |
$main::ua{'db_user'} = $rdata; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
push_el(\@main::el, 'ask_db_user()', 'Ending...'); |
|---|
| 191 |
return 0; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
sub ask_db_password { |
|---|
| 195 |
push_el(\@main::el, 'ask_db_password()', 'Starting...'); |
|---|
| 196 |
|
|---|
| 197 |
my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 198 |
my $db_password = 'none'; |
|---|
| 199 |
my $qmsg = "\n\tPlease enter system SQL password. [$db_password]: "; |
|---|
| 200 |
|
|---|
| 201 |
$pass1 = read_password($qmsg); |
|---|
| 202 |
|
|---|
| 203 |
if (!defined($pass1) || $pass1 eq '') { |
|---|
| 204 |
$main::ua{'db_password'} = ''; |
|---|
| 205 |
} |
|---|
| 206 |
else { |
|---|
| 207 |
$qmsg = "\tPlease repeat system SQL password: "; |
|---|
| 208 |
$pass2 = read_password($qmsg); |
|---|
| 209 |
|
|---|
| 210 |
if ($pass1 eq $pass2) { |
|---|
| 211 |
$main::ua{'db_password'} = $pass1; |
|---|
| 212 |
} |
|---|
| 213 |
else { |
|---|
| 214 |
print STDOUT "\n\tPasswords do not match!"; |
|---|
| 215 |
return 1; |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
push_el(\@main::el, 'ask_db_password()', 'Ending...'); |
|---|
| 220 |
return 0; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
sub ask_db_ftp_user { |
|---|
| 224 |
push_el(\@main::el, 'ask_db_ftp_user()', 'Starting...'); |
|---|
| 225 |
|
|---|
| 226 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 227 |
my $db_user = 'vftp'; |
|---|
| 228 |
my $qmsg = "\n\tPlease enter ispCP ftp SQL user. [$db_user]: "; |
|---|
| 229 |
|
|---|
| 230 |
print STDOUT $qmsg; |
|---|
| 231 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 232 |
|
|---|
| 233 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 234 |
$main::ua{'db_ftp_user'} = $db_user; |
|---|
| 235 |
} |
|---|
| 236 |
elsif( $rdata eq $main::ua{'db_user'}) { |
|---|
| 237 |
$qmsg = "\n\tftp SQL user must not be identical to system SQL user!"; |
|---|
| 238 |
print STDOUT $qmsg; |
|---|
| 239 |
return 1; |
|---|
| 240 |
} else { |
|---|
| 241 |
$main::ua{'db_ftp_user'} = $rdata; |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
push_el(\@main::el, 'ask_db_ftp_user()', 'Ending...'); |
|---|
| 245 |
return 0; |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
sub ask_db_ftp_password { |
|---|
| 249 |
push_el(\@main::el, 'ask_db_ftp_password()', 'Starting...'); |
|---|
| 250 |
|
|---|
| 251 |
my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 252 |
my $db_password = undef; |
|---|
| 253 |
my $qmsg = "\n\tPlease enter ispCP ftp SQL user password. [auto generate]: "; |
|---|
| 254 |
|
|---|
| 255 |
$pass1 = read_password($qmsg); |
|---|
| 256 |
|
|---|
| 257 |
if (!defined($pass1) || $pass1 eq '') { |
|---|
| 258 |
$db_password = gen_sys_rand_num(18); |
|---|
| 259 |
$db_password =~ s/('|"|`|#|;)//g; |
|---|
| 260 |
$main::ua{'db_ftp_password'} = $db_password; |
|---|
| 261 |
print STDOUT "\tispCP ftp SQL user password set to: $db_password\n"; |
|---|
| 262 |
} |
|---|
| 263 |
else { |
|---|
| 264 |
$qmsg = "\tPlease repeat ispCP ftp SQL user password: "; |
|---|
| 265 |
$pass2 = read_password($qmsg); |
|---|
| 266 |
|
|---|
| 267 |
if ($pass1 eq $pass2) { |
|---|
| 268 |
$main::ua{'db_ftp_password'} = $pass1; |
|---|
| 269 |
} |
|---|
| 270 |
else { |
|---|
| 271 |
print STDOUT "\n\tPasswords do not match!"; |
|---|
| 272 |
return 1; |
|---|
| 273 |
} |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
push_el(\@main::el, 'ask_db_ftp_password()', 'Ending...'); |
|---|
| 277 |
return 0; |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
sub ask_admin { |
|---|
| 281 |
push_el(\@main::el, 'ask_admin()', 'Starting...'); |
|---|
| 282 |
|
|---|
| 283 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 284 |
my $admin = 'admin'; |
|---|
| 285 |
my $qmsg = "\n\tPlease enter administrator login name. [$admin]: "; |
|---|
| 286 |
print STDOUT $qmsg; |
|---|
| 287 |
|
|---|
| 288 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 289 |
|
|---|
| 290 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 291 |
$main::ua{'admin'} = $admin; |
|---|
| 292 |
} |
|---|
| 293 |
else { |
|---|
| 294 |
$main::ua{'admin'} = $rdata; |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
push_el(\@main::el, 'ask_admin()', 'Ending...'); |
|---|
| 298 |
return 0; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
sub ask_admin_password { |
|---|
| 302 |
push_el(\@main::el, 'ask_admin_password()', 'Starting...'); |
|---|
| 303 |
|
|---|
| 304 |
my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 305 |
my $qmsg = "\n\tPlease enter administrator password: "; |
|---|
| 306 |
|
|---|
| 307 |
$pass1 = read_password($qmsg); |
|---|
| 308 |
|
|---|
| 309 |
if (!defined($pass1) || $pass1 eq '') { |
|---|
| 310 |
print STDOUT "\n\tPassword too short!"; |
|---|
| 311 |
return 1; |
|---|
| 312 |
} |
|---|
| 313 |
else { |
|---|
| 314 |
if (length($pass1) < 5) { |
|---|
| 315 |
print STDOUT "\n\tPassword too short!"; |
|---|
| 316 |
return 1; |
|---|
| 317 |
} |
|---|
| 318 |
$qmsg = "\tPlease repeat administrator password: "; |
|---|
| 319 |
$pass2 = read_password($qmsg); |
|---|
| 320 |
|
|---|
| 321 |
if ($pass1 =~ m/[a-zA-Z]/ && $pass1 =~ m/[0-9]/) { |
|---|
| 322 |
|
|---|
| 323 |
if ($pass1 eq $pass2) { |
|---|
| 324 |
$main::ua{'admin_password'} = $pass1; |
|---|
| 325 |
} else { |
|---|
| 326 |
print STDOUT "\n\tPasswords do not match!"; |
|---|
| 327 |
return 1; |
|---|
| 328 |
} |
|---|
| 329 |
} |
|---|
| 330 |
else { |
|---|
| 331 |
print STDOUT "\n\tPasswords must contain at least digits and chars!"; |
|---|
| 332 |
return 1; |
|---|
| 333 |
} |
|---|
| 334 |
} |
|---|
| 335 |
|
|---|
| 336 |
push_el(\@main::el, 'ask_admin_password()', 'Ending...'); |
|---|
| 337 |
return 0; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
sub ask_admin_email { |
|---|
| 341 |
push_el(\@main::el, 'ask_admin_email()', 'Starting...'); |
|---|
| 342 |
|
|---|
| 343 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 344 |
my $qmsg = "\n\tPlease enter administrator e-mail address: "; |
|---|
| 345 |
print STDOUT $qmsg; |
|---|
| 346 |
|
|---|
| 347 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 348 |
|
|---|
| 349 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 350 |
return 1; |
|---|
| 351 |
} |
|---|
| 352 |
else { |
|---|
| 353 |
if ($rdata =~ /^([\w\W]{1,255})\@([\w][\w-]{0,253}[\w]\.)*([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 354 |
$main::ua{'admin_email'} = $rdata; |
|---|
| 355 |
} else { |
|---|
| 356 |
print STDOUT "\n\tE-mail address not valid!"; |
|---|
| 357 |
return 1; |
|---|
| 358 |
} |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
push_el(\@main::el, 'ask_admin_email()', 'Ending...'); |
|---|
| 362 |
return 0; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
sub ask_vhost { |
|---|
| 366 |
|
|---|
| 367 |
push_el(\@main::el, 'ask_vhost()', 'Starting...'); |
|---|
| 368 |
|
|---|
| 369 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 370 |
my $eth = $main::ua{'eth_ip'}; |
|---|
| 371 |
my $addr = gethostbyaddr($main::ua{'eth_ip'}, AF_INET); |
|---|
| 372 |
|
|---|
| 373 |
if (!$addr) { |
|---|
| 374 |
$addr = $main::ua{'hostname'}; |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
my $vhost = "admin.$addr"; |
|---|
| 378 |
my $qmsg = "\n\tPlease enter the domain name where ispCP OMEGA will run on [$vhost]: "; |
|---|
| 379 |
|
|---|
| 380 |
print STDOUT $qmsg; |
|---|
| 381 |
|
|---|
| 382 |
$rdata = readline(\*STDIN); |
|---|
| 383 |
chop($rdata); |
|---|
| 384 |
|
|---|
| 385 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 386 |
$main::ua{'admin_vhost'} = $vhost; |
|---|
| 387 |
} |
|---|
| 388 |
else { |
|---|
| 389 |
if ($rdata =~ /^([\w][\w-]{0,253}[\w]\.)*([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 390 |
$main::ua{'admin_vhost'} = $rdata; |
|---|
| 391 |
} |
|---|
| 392 |
else { |
|---|
| 393 |
print STDOUT "\n\tVhost not valid!"; |
|---|
| 394 |
return 1; |
|---|
| 395 |
} |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
push_el(\@main::el, 'ask_vhost()', 'Ending...'); |
|---|
| 399 |
return 0; |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
sub ask_second_dns { |
|---|
| 403 |
push_el(\@main::el, 'ask_second_dns()', 'Starting...'); |
|---|
| 404 |
|
|---|
| 405 |
my $rdata = undef; |
|---|
| 406 |
my $qmsg = "\n\tIP of Secondary DNS. (optional) []: "; |
|---|
| 407 |
|
|---|
| 408 |
print STDOUT $qmsg; |
|---|
| 409 |
|
|---|
| 410 |
$rdata = readline(\*STDIN); |
|---|
| 411 |
chop($rdata); |
|---|
| 412 |
|
|---|
| 413 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 414 |
$main::ua{'secondary_dns'} = ''; |
|---|
| 415 |
} |
|---|
| 416 |
else { |
|---|
| 417 |
if (check_eth($rdata) != 0) { |
|---|
| 418 |
$main::ua{'secondary_dns'} = $rdata; |
|---|
| 419 |
} |
|---|
| 420 |
else { |
|---|
| 421 |
print STDOUT "\n\tNo valid IP, please retry!"; |
|---|
| 422 |
return 1; |
|---|
| 423 |
} |
|---|
| 424 |
} |
|---|
| 425 |
|
|---|
| 426 |
push_el(\@main::el, 'ask_second_dns()', 'Ending...'); |
|---|
| 427 |
return 0; |
|---|
| 428 |
} |
|---|
| 429 |
|
|---|
| 430 |
sub ask_mysql_prefix { |
|---|
| 431 |
push_el(\@main::el, 'ask_mysql_prefix()', 'Starting...'); |
|---|
| 432 |
|
|---|
| 433 |
my $rdata = undef; |
|---|
| 434 |
my $qmsg = "\n\tUse MySQL Prefix.\n\tPossible values: [i]nfront, [b]ehind, [n]one. [none]: "; |
|---|
| 435 |
|
|---|
| 436 |
print STDOUT $qmsg; |
|---|
| 437 |
|
|---|
| 438 |
$rdata = readline(\*STDIN); |
|---|
| 439 |
chop($rdata); |
|---|
| 440 |
|
|---|
| 441 |
if (!defined($rdata) || $rdata eq '' || $rdata eq 'none' || $rdata eq 'n') { |
|---|
| 442 |
$main::ua{'mysql_prefix'} = 'no'; |
|---|
| 443 |
$main::ua{'mysql_prefix_type'} = ''; |
|---|
| 444 |
} |
|---|
| 445 |
else { |
|---|
| 446 |
if ($rdata eq 'infront' || $rdata eq 'i') { |
|---|
| 447 |
$main::ua{'mysql_prefix'} = 'yes'; |
|---|
| 448 |
$main::ua{'mysql_prefix_type'} = 'infront'; |
|---|
| 449 |
} |
|---|
| 450 |
elsif ($rdata eq 'behind' || $rdata eq 'b') { |
|---|
| 451 |
$main::ua{'mysql_prefix'} = 'yes'; |
|---|
| 452 |
$main::ua{'mysql_prefix_type'} = 'behind'; |
|---|
| 453 |
} |
|---|
| 454 |
else { |
|---|
| 455 |
print STDOUT "\n\tNot allowed Value, please retry!"; |
|---|
| 456 |
return 1; |
|---|
| 457 |
} |
|---|
| 458 |
} |
|---|
| 459 |
|
|---|
| 460 |
push_el(\@main::el, 'ask_mysql_prefix()', 'Ending...'); |
|---|
| 461 |
return 0; |
|---|
| 462 |
} |
|---|
| 463 |
|
|---|
| 464 |
# Set up PMA User |
|---|
| 465 |
sub ask_db_pma_user { |
|---|
| 466 |
push_el(\@main::el, 'ask_db_pma_user()', 'Starting...'); |
|---|
| 467 |
|
|---|
| 468 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 469 |
my $db_user = 'pma'; |
|---|
| 470 |
|
|---|
| 471 |
my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user. [$db_user]: "; |
|---|
| 472 |
print STDOUT $qmsg; |
|---|
| 473 |
$rdata = readline(\*STDIN); chop($rdata); |
|---|
| 474 |
|
|---|
| 475 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 476 |
$main::ua{'db_pma_user'} = $db_user; |
|---|
| 477 |
} elsif( $rdata eq $main::ua{'db_user'}){ |
|---|
| 478 |
$qmsg = "\n\tphpMyAdmin Control user must not be identical to system SQL user!"; |
|---|
| 479 |
print STDOUT $qmsg; |
|---|
| 480 |
return 1; |
|---|
| 481 |
} elsif ($rdata eq $main::ua{'db_ftp_user'}) { |
|---|
| 482 |
$qmsg = "\n\tphpMyAdmin Control user must not be identical to ftp SQL user!"; |
|---|
| 483 |
print STDOUT $qmsg; |
|---|
| 484 |
return 1; |
|---|
| 485 |
} else { |
|---|
| 486 |
$main::ua{'db_pma_user'} = $rdata; |
|---|
| 487 |
} |
|---|
| 488 |
|
|---|
| 489 |
push_el(\@main::el, 'ask_db_pma_user()', 'Ending...'); |
|---|
| 490 |
return 0; |
|---|
| 491 |
} |
|---|
| 492 |
|
|---|
| 493 |
# Set up PMA Passwort |
|---|
| 494 |
sub ask_db_pma_password { |
|---|
| 495 |
|
|---|
| 496 |
my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 497 |
push_el(\@main::el, 'ask_db_pma_password()', 'Starting...'); |
|---|
| 498 |
|
|---|
| 499 |
my $db_password = undef; |
|---|
| 500 |
|
|---|
| 501 |
my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user password. [auto generate]: "; |
|---|
| 502 |
$pass1 = read_password($qmsg); |
|---|
| 503 |
|
|---|
| 504 |
if (!defined($pass1) || $pass1 eq '') { |
|---|
| 505 |
|
|---|
| 506 |
$db_password = gen_sys_rand_num(18); |
|---|
| 507 |
$db_password =~ s/('|"|`|#|;)//g; |
|---|
| 508 |
$main::ua{'db_pma_password'} = $db_password; |
|---|
| 509 |
print STDOUT "\tphpMyAdmin Control user password set to: $db_password\n"; |
|---|
| 510 |
|
|---|
| 511 |
} else { |
|---|
| 512 |
$qmsg = "\tPlease repeat ispCP phpMyAdmin Control user password: "; |
|---|
| 513 |
$pass2 = read_password($qmsg); |
|---|
| 514 |
|
|---|
| 515 |
if ($pass1 eq $pass2) { |
|---|
| 516 |
$main::ua{'db_pma_password'} = $pass1; |
|---|
| 517 |
} else { |
|---|
| 518 |
print STDOUT "\n\tPasswords do not match!"; |
|---|
| 519 |
return 1; |
|---|
| 520 |
} |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
push_el(\@main::el, 'ask_db_pma_password()', 'Ending...'); |
|---|
| 524 |
return 0; |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
# Set up FastCGI version |
|---|
| 528 |
sub ask_fastcgi { |
|---|
| 529 |
|
|---|
| 530 |
my $rdata = undef; |
|---|
| 531 |
|
|---|
| 532 |
push_el(\@main::el, 'ask_fastcgi()', 'Starting...'); |
|---|
| 533 |
|
|---|
| 534 |
my $qmsg = "\n\tFastCGI Version:[f]astcgi or f[c]gid. [fastcgi]: "; |
|---|
| 535 |
|
|---|
| 536 |
print STDOUT $qmsg; |
|---|
| 537 |
|
|---|
| 538 |
$rdata = readline(\*STDIN); |
|---|
| 539 |
chop($rdata); |
|---|
| 540 |
|
|---|
| 541 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 542 |
$main::ua{'php_fastcgi'} = 'fastcgi'; |
|---|
| 543 |
} |
|---|
| 544 |
else { |
|---|
| 545 |
if ($rdata eq 'fastcgi' || $rdata eq 'f') { |
|---|
| 546 |
$main::ua{'php_fastcgi'} = 'fastcgi'; |
|---|
| 547 |
} |
|---|
| 548 |
elsif ($rdata eq 'fcgid' || $rdata eq 'c') { |
|---|
| 549 |
$main::ua{'php_fastcgi'} = 'fcgid'; |
|---|
| 550 |
} |
|---|
| 551 |
else { |
|---|
| 552 |
print STDOUT "\n\tOnly '[f]astcgi' or 'f[c]gid' are allowed!"; |
|---|
| 553 |
return 1; |
|---|
| 554 |
} |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
push_el(\@main::el, 'ask_fastcgi()', 'Ending...'); |
|---|
| 558 |
return 0; |
|---|
| 559 |
} |
|---|
| 560 |
|
|---|
| 561 |
# Set up AWStats |
|---|
| 562 |
sub ask_awstats_on { |
|---|
| 563 |
|
|---|
| 564 |
my $rdata = undef; |
|---|
| 565 |
|
|---|
| 566 |
push_el(\@main::el, 'ask_awstats_on()', 'Starting...'); |
|---|
| 567 |
|
|---|
| 568 |
my $qmsg = "\n\tActivate AWStats. [no]: "; |
|---|
| 569 |
|
|---|
| 570 |
print STDOUT $qmsg; |
|---|
| 571 |
|
|---|
| 572 |
$rdata = readline(\*STDIN); |
|---|
| 573 |
chop($rdata); |
|---|
| 574 |
|
|---|
| 575 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 576 |
$main::ua{'awstats_on'} = 'no'; |
|---|
| 577 |
} |
|---|
| 578 |
else { |
|---|
| 579 |
if ($rdata eq 'yes' || $rdata eq 'y') { |
|---|
| 580 |
$main::ua{'awstats_on'} = 'yes'; |
|---|
| 581 |
} |
|---|
| 582 |
elsif ($rdata eq 'no' || $rdata eq 'n') { |
|---|
| 583 |
$main::ua{'awstats_on'} = 'no'; |
|---|
| 584 |
} |
|---|
| 585 |
else { |
|---|
| 586 |
print STDOUT "\n\tOnly '(y)es' and '(n)o' are allowed!"; |
|---|
| 587 |
return 1; |
|---|
| 588 |
} |
|---|
| 589 |
} |
|---|
| 590 |
|
|---|
| 591 |
push_el(\@main::el, 'ask_awstats_on()', 'Ending...'); |
|---|
| 592 |
|
|---|
| 593 |
return 0; |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
# Set up AWStats Static or Dynamic |
|---|
| 597 |
sub ask_awstats_dyn { |
|---|
| 598 |
|
|---|
| 599 |
my $rdata = undef; |
|---|
| 600 |
|
|---|
| 601 |
push_el(\@main::el, 'ask_awstats_dyn()', 'Starting...'); |
|---|
| 602 |
|
|---|
| 603 |
my $qmsg = "\n\tAWStats Mode:\n\tPossible values [d]ynamic and [s]tatic. [dynamic]: "; |
|---|
| 604 |
|
|---|
| 605 |
print STDOUT $qmsg; |
|---|
| 606 |
|
|---|
| 607 |
$rdata = readline(\*STDIN); |
|---|
| 608 |
chop($rdata); |
|---|
| 609 |
|
|---|
| 610 |
if (!defined($rdata) || $rdata eq '') { |
|---|
| 611 |
$main::ua{'awstats_dyn'} = '0'; |
|---|
| 612 |
} |
|---|
| 613 |
else { |
|---|
| 614 |
if ($rdata eq 'dynamic' || $rdata eq 'd') { |
|---|
| 615 |
$main::ua{'awstats_dyn'} = '0'; |
|---|
| 616 |
} |
|---|
| 617 |
elsif ($rdata eq 'static' || $rdata eq 's') { |
|---|
| 618 |
$main::ua{'awstats_dyn'} = '1'; |
|---|
| 619 |
} |
|---|
| 620 |
else { |
|---|
| 621 |
print STDOUT "\n\tOnly '[d]ynamic' or '[s]tatic' are allowed!"; |
|---|
| 622 |
return 1; |
|---|
| 623 |
} |
|---|
| 624 |
} |
|---|
| 625 |
|
|---|
| 626 |
push_el(\@main::el, 'ask_awstats_dyn()', 'Ending...'); |
|---|
| 627 |
return 0; |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
# Set up Crontab |
|---|
| 631 |
sub setup_crontab { |
|---|
| 632 |
|
|---|
| 633 |
push_el(\@main::el, 'setup_crontab()', 'Starting...'); |
|---|
| 634 |
|
|---|
| 635 |
my ($rs, $rdata, $awstats, $rkhunter, $ckrootkit) = (undef, undef, ''); |
|---|
| 636 |
my $cfg_dir = "$main::cfg{'CONF_DIR'}/cron.d"; |
|---|
| 637 |
my $bk_dir = "$cfg_dir/backup"; |
|---|
| 638 |
my $wrk_dir = "$cfg_dir/working"; |
|---|
| 639 |
my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 640 |
|
|---|
| 641 |
if (! -e "$bk_dir/ispcp") { |
|---|
| 642 |
|
|---|
| 643 |
($rs, $cfg_tpl) = get_tpl($cfg_dir, 'ispcp'); |
|---|
| 644 |
|
|---|
| 645 |
return $rs if ($rs != 0); |
|---|
| 646 |
|
|---|
| 647 |
$awstats = ""; |
|---|
| 648 |
if ($main::cfg{'AWSTATS_ACTIVE'} ne 'yes' || $main::cfg{'AWSTATS_MODE'} eq 1) { |
|---|
| 649 |
$awstats = "#"; |
|---|
| 650 |
} |
|---|
| 651 |
|
|---|
| 652 |
$rkhunter = `which rkhunter`; |
|---|
| 653 |
$ckrootkit = `which chkrootkit`; |
|---|
| 654 |
|
|---|
| 655 |
$rkhunter =~ s/[ \t\n]$//g; |
|---|
| 656 |
$ckrootkit =~ s/[ \t\n]$//g; |
|---|
| 657 |
|
|---|
| 658 |
my %tag_hash = ( |
|---|
| 659 |
'{LOG_DIR}' => $main::cfg{'LOG_DIR'}, |
|---|
| 660 |
'{CONF_DIR}' => $main::cfg{'CONF_DIR'}, |
|---|
| 661 |
'{QUOTA_ROOT_DIR}' => $main::cfg{'QUOTA_ROOT_DIR'}, |
|---|
| 662 |
'{TRAFF_ROOT_DIR}' => $main::cfg{'TRAFF_ROOT_DIR'}, |
|---|
| 663 |
'{TOOLS_ROOT_DIR}' => $main::cfg{'TOOLS_ROOT_DIR'}, |
|---|
| 664 |
'{BACKUP_ROOT_DIR}' => $main::cfg{'BACKUP_ROOT_DIR'}, |
|---|
| 665 |
'{AWSTATS_ROOT_DIR}' => $main::cfg{'AWSTATS_ROOT_DIR'}, |
|---|
| 666 |
'{RKHUNTER_LOG}' => $main::cfg{'RKHUNTER_LOG'}, |
|---|
| 667 |
'{CHKROOTKIT_LOG}' => $main::cfg{'CHKROOTKIT_LOG'}, |
|---|
| 668 |
'{AWSTATS_ENGINE_DIR}' => $main::cfg{'AWSTATS_ENGINE_DIR'}, |
|---|
| 669 |
'{AW-ENABLED}' => $awstats, |
|---|
| 670 |
'{RK-ENABLED}' => !length($rkhunter)? "#" : "", |
|---|
| 671 |
'{RKHUNTER}' => $rkhunter, |
|---|
| 672 |
'{CR-ENABLED}' => !length($ckrootkit)? "#" : "", |
|---|
| 673 |
'{CHKROOTKIT}' => $ckrootkit |
|---|
| 674 |
); |
|---|
| 675 |
|
|---|
| 676 |
($rs, $cfg) = prep_tpl(\%tag_hash, $cfg_tpl); |
|---|
| 677 |
return $rs if ($rs != 0); |
|---|
| 678 |
|
|---|
| 679 |
$rs = store_file("$bk_dir/ispcp", $cfg, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 680 |
return $rs if ($rs != 0); |
|---|
| 681 |
|
|---|
| 682 |
$cmd = "$main::cfg{'CMD_CP'} -p -f $bk_dir/ispcp $wrk_dir/"; |
|---|
| 683 |
|
|---|
| 684 |
$rs = sys_command_rs($cmd); |
|---|
| 685 |
return $rs if ($rs != 0); |
|---|
| 686 |
} |
|---|
| 687 |
|
|---|
| 688 |
if ($main::cfg{'ROOT_GROUP'} eq "wheel") { |
|---|
| 689 |
$cmd = "$main::cfg{'CMD_CP'} -f $wrk_dir/ispcp /usr/local/etc/ispcp/cron.d/"; |
|---|
| 690 |
} else { |
|---|
| 691 |
$cmd = "$main::cfg{'CMD_CP'} -f $wrk_dir/ispcp /etc/cron.d/"; |
|---|
| 692 |
} |
|---|
| 693 |
|
|---|
| 694 |
$rs = sys_command_rs($cmd); |
|---|
| 695 |
return $rs if ($rs != 0); |
|---|
| 696 |
|
|---|
| 697 |
push_el(\@main::el, 'setup_crontab()', 'Ending...'); |
|---|
| 698 |
return 0; |
|---|
| 699 |
} |
|---|
| 700 |
|
|---|
| 701 |
# Set up Bind |
|---|
| 702 |
sub setup_named { |
|---|
| 703 |
push_el(\@main::el, 'setup_named()', 'Starting...'); |
|---|
| 704 |
|
|---|
| 705 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 706 |
my $cfg_dir = "$main::cfg{'CONF_DIR'}/bind"; |
|---|
| 707 |
my $bk_dir = "$cfg_dir/backup"; |
|---|
| 708 |
my $wrk_dir = "$cfg_dir/working"; |
|---|
| 709 |
my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 710 |
|
|---|
| 711 |
return 0 if ($main::cfg{'CMD_NAMED'} eq 'no'); |
|---|
| 712 |
|
|---|
| 713 |
sys_command_rs("$main::cfg{'CMD_NAMED'} stop &> /tmp/ispcp-setup-services.log"); |
|---|
| 714 |
|
|---|
| 715 |
($rs, $cfg_tpl) = get_file("$cfg_dir/named.conf"); |
|---|
| 716 |
return $rs if ($rs != 0); |
|---|
| 717 |
|
|---|
| 718 |
if ((! -e "$bk_dir/named.conf.ispcp") && (-e $main::cfg{'BIND_CONF_FILE'})) { |
|---|
| 719 |
$cmd = "$main::cfg{'CMD_CP'} -p $main::cfg{'BIND_CONF_FILE'} $bk_dir/named.conf.system"; |
|---|
| 720 |
$rs = sys_command($cmd); |
|---|
| 721 |
return $rs if ($rs != 0); |
|---|
| 722 |
|
|---|
| 723 |
$cfg = get_file($main::cfg{'BIND_CONF_FILE'}); |
|---|
| 724 |
return $rs if ($rs != 0); |
|---|
| 725 |
|
|---|
| 726 |
$rs = store_file("$bk_dir/named.conf.ispcp", "$cfg_tpl", $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 727 |
return $rs if ($rs != 0); |
|---|
| 728 |
} |
|---|
| 729 |
|
|---|
| 730 |
$cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/named.conf.ispcp $main::cfg{'BIND_CONF_FILE'}"; |
|---|
| 731 |
$rs = sys_command($cmd); |
|---|
| 732 |
return $rs if ($rs != 0); |
|---|
| 733 |
|
|---|
| 734 |
$rs = store_file("$wrk_dir/named.conf", "$cfg_tpl", $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 735 |
return $rs if ($rs != 0); |
|---|
| 736 |
|
|---|
| 737 |
sys_command_rs("$main::cfg{'CMD_NAMED'} start &> /tmp/ispcp-setup-services.log"); |
|---|
| 738 |
|
|---|
| 739 |
push_el(\@main::el, 'setup_named()', 'Ending...'); |
|---|
| 740 |
return 0; |
|---|
| 741 |
} |
|---|
| 742 |
|
|---|
| 743 |
# |
|---|
| 744 |
# Add Bind CFG |
|---|
| 745 |
# |
|---|
| 746 |
|
|---|
| 747 |
sub add_named_cfg_data { |
|---|
| 748 |
push_el(\@main::el, 'add_named_cfg_data()', 'Starting...'); |
|---|
| 749 |
|
|---|
| 750 |
my ($base_vhost) = @_; |
|---|
| 751 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 752 |
|
|---|
| 753 |
if (!defined($base_vhost) || $base_vhost eq '') { |
|---|
| 754 |
push_el(\@main::el, 'add_named_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 755 |
return -1; |
|---|
| 756 |
} |
|---|
| 757 |
|
|---|
| 758 |
# |
|---|
| 759 |
# Initial data we need; |
|---|
| 760 |
# |
|---|
| 761 |
|
|---|
| 762 |
my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 763 |
my $sys_cfg = $main::cfg{'BIND_CONF_FILE'}; |
|---|
| 764 |
my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 765 |
|
|---|
| 766 |
my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 767 |
my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 768 |
my $working_dir = "$conf_dir/bind/working"; |
|---|
| 769 |
|
|---|
| 770 |
my $timestamp = time; |
|---|
| 771 |
my $backup_cfg = "$backup_dir/named.conf.$timestamp"; |
|---|
| 772 |
my $working_cfg = "$working_dir/named.conf"; |
|---|
| 773 |
|
|---|
| 774 |
# |
|---|
| 775 |
# BEGIN/END tags, and templates needed for this config; |
|---|
| 776 |
# |
|---|
| 777 |
|
|---|
| 778 |
my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', ''); |
|---|
| 779 |
|
|---|
| 780 |
( |
|---|
| 781 |
$rs, |
|---|
| 782 |
$dta_b, |
|---|
| 783 |
$dta_e, |
|---|
| 784 |
$entry_b, |
|---|
| 785 |
$entry_e, |
|---|
| 786 |
$entry |
|---|
| 787 |
) = get_tpl( |
|---|
| 788 |
$tpl_dir, |
|---|
| 789 |
'cfg_dta_b.tpl', |
|---|
| 790 |
'cfg_dta_e.tpl', |
|---|
| 791 |
'cfg_entry_b.tpl', |
|---|
| 792 |
'cfg_entry_e.tpl', |
|---|
| 793 |
'cfg_entry.tpl' |
|---|
| 794 |
); |
|---|
| 795 |
|
|---|
| 796 |
return $rs if ($rs != 0); |
|---|
| 797 |
|
|---|
| 798 |
# |
|---|
| 799 |
# Let's construct needed tags and entries; |
|---|
| 800 |
# |
|---|
| 801 |
|
|---|
| 802 |
my %tag_hash = ( |
|---|
| 803 |
'{DMN_NAME}' => $base_vhost, |
|---|
| 804 |
'{DB_DIR}' => $named_db_dir |
|---|
| 805 |
); |
|---|
| 806 |
|
|---|
| 807 |
my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', ''); |
|---|
| 808 |
|
|---|
| 809 |
( |
|---|
| 810 |
$rs, |
|---|
| 811 |
$entry_b_val, |
|---|
| 812 |
$entry_e_val, |
|---|
| 813 |
$entry_val |
|---|
| 814 |
) = prep_tpl( |
|---|
| 815 |
\%tag_hash, |
|---|
| 816 |
$entry_b, |
|---|
| 817 |
$entry_e, |
|---|
| 818 |
$entry |
|---|
| 819 |
); |
|---|
| 820 |
|
|---|
| 821 |
return $rs if ($rs != 0); |
|---|
| 822 |
|
|---|
| 823 |
# |
|---|
| 824 |
# Let's get System and Working config files; |
|---|
| 825 |
# |
|---|
| 826 |
|
|---|
| 827 |
my ($sys, $working) = ('', ''); |
|---|
| 828 |
|
|---|
| 829 |
($rs, $sys) = get_file($sys_cfg); |
|---|
| 830 |
return $rs if ($rs != 0); |
|---|
| 831 |
|
|---|
| 832 |
($rs, $working) = get_file($working_cfg); |
|---|
| 833 |
return $rs if ($rs != 0); |
|---|
| 834 |
|
|---|
| 835 |
($rs, $rdata) = get_tag($dta_b, $dta_e, $working); |
|---|
| 836 |
return $rs if ($rs != 0); |
|---|
| 837 |
|
|---|
| 838 |
# |
|---|
| 839 |
# Is the new domain entry exists ? |
|---|
| 840 |
# |
|---|
| 841 |
|
|---|
| 842 |
($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working); |
|---|
| 843 |
|
|---|
| 844 |
if ($rs == 0) { |
|---|
| 845 |
# Yes it exists ! Then we must delete it ! |
|---|
| 846 |
($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working); |
|---|
| 847 |
return $rs if ($rs != 0); |
|---|
| 848 |
} |
|---|
| 849 |
|
|---|
| 850 |
($rs, $rdata) = get_tag($entry_b, $entry_e, $working); |
|---|
| 851 |
return $rs if ($rs != 0); |
|---|
| 852 |
|
|---|
| 853 |
# |
|---|
| 854 |
# Let's construct the replacement and do it; |
|---|
| 855 |
# |
|---|
| 856 |
|
|---|
| 857 |
my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e"; |
|---|
| 858 |
|
|---|
| 859 |
($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl, "add_named_cfg_data"); |
|---|
| 860 |
return $rs if ($rs != 0); |
|---|
| 861 |
|
|---|
| 862 |
# |
|---|
| 863 |
# Here we'll backup production config file; |
|---|
| 864 |
# |
|---|
| 865 |
|
|---|
| 866 |
$rs = sys_command("cp -p $sys_cfg $backup_cfg"); |
|---|
| 867 |
return $rs if ($rs != 0); |
|---|
| 868 |
|
|---|
| 869 |
# |
|---|
| 870 |
# Let's save working copy; |
|---|
| 871 |
# |
|---|
| 872 |
|
|---|
| 873 |
$rs = store_file($working_cfg, $working, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 874 |
return $rs if ($rs != 0); |
|---|
| 875 |
|
|---|
| 876 |
# |
|---|
| 877 |
# Here we'll replace data in production config file with data in working |
|---|
| 878 |
# confing file. A little workaround will be done. If working copy data does not exist |
|---|
| 879 |
# in production config then we will add it; |
|---|
| 880 |
# |
|---|
| 881 |
|
|---|
| 882 |
($rs, $rdata) = get_tag($dta_b, $dta_e, $sys); |
|---|
| 883 |
|
|---|
| 884 |
if ($rs == 0) { # YES ! Data is here ! /in production config file/; |
|---|
| 885 |
($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working, "add_named_cfg_data"); |
|---|
| 886 |
return $rs if ($rs != 0); |
|---|
| 887 |
} |
|---|
| 888 |
elsif ($rs == -5) { |
|---|
| 889 |
$sys .= $working; |
|---|
| 890 |
} |
|---|
| 891 |
else { |
|---|
| 892 |
return $rs; |
|---|
| 893 |
} |
|---|
| 894 |
|
|---|
| 895 |
$rs = store_file($sys_cfg, $sys, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 896 |
return $rs if ($rs != 0); |
|---|
| 897 |
|
|---|
| 898 |
push_el(\@main::el, 'add_named_cfg_data()', 'Ending...'); |
|---|
| 899 |
return 0; |
|---|
| 900 |
} |
|---|
| 901 |
|
|---|
| 902 |
# |
|---|
| 903 |
# Add DNS DB Data |
|---|
| 904 |
# |
|---|
| 905 |
|
|---|
| 906 |
sub add_named_db_data { |
|---|
| 907 |
push_el(\@main::el, 'add_named_db_data()', 'Starting...'); |
|---|
| 908 |
|
|---|
| 909 |
my ($base_ip, $base_vhost) = @_; |
|---|
| 910 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 911 |
if (!defined($base_vhost) || $base_vhost eq '') { |
|---|
| 912 |
push_el(\@main::el, 'add_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 913 |
return -1; |
|---|
| 914 |
} |
|---|
| 915 |
|
|---|
| 916 |
# |
|---|
| 917 |
# Initial data we need; |
|---|
| 918 |
# |
|---|
| 919 |
|
|---|
| 920 |
my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 921 |
my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 922 |
my $sec_dns_ip = $main::cfg{'SECONDARY_DNS'}; |
|---|
| 923 |
|
|---|
| 924 |
# |
|---|
| 925 |
# Any secondary DNS defined; |
|---|
| 926 |
# |
|---|
| 927 |
|
|---|
| 928 |
if (!$sec_dns_ip) { |
|---|
| 929 |
$sec_dns_ip = $base_ip; |
|---|
| 930 |
} |
|---|
| 931 |
|
|---|
| 932 |
my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 933 |
my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 934 |
my $working_dir = "$conf_dir/bind/working"; |
|---|
| 935 |
|
|---|
| 936 |
my $db_fname = "$base_vhost.db"; |
|---|
| 937 |
|
|---|
| 938 |
my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| 939 |
my $working_cfg = "$working_dir/$db_fname"; |
|---|
| 940 |
|
|---|
| 941 |
# |
|---|
| 942 |
# Let's get needed tags and templates; |
|---|
| 943 |
# |
|---|
| 944 |
|
|---|
| 945 |
my ($entry, $dns2_b, $dns2_e) = ('', '', ''); |
|---|
| 946 |
|
|---|
| 947 |
($rs, $entry, $dns2_b, $dns2_e) = get_tpl( |
|---|
| 948 |
$tpl_dir, |
|---|
| 949 |
'db_master_e.tpl', |
|---|
| 950 |
'db_dns2_b.tpl', |
|---|
| 951 |
'db_dns2_e.tpl' |
|---|
| 952 |
); |
|---|
| 953 |
|
|---|
| 954 |
return $rs if ($rs != 0); |
|---|
| 955 |
|
|---|
| 956 |
my $seq = 0; |
|---|
| 957 |
|
|---|
| 958 |
# |
|---|
| 959 |
# RFC 1912 |
|---|
| 960 |
# |
|---|
| 961 |
|
|---|
| 962 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
|---|
| 963 |
my $time2 = sprintf "%4d%02d%02d00",$year+1900,$mon+1,$mday,$seq; |
|---|
| 964 |
|
|---|
| 965 |
# |
|---|
| 966 |
# Let's prepare them; |
|---|
| 967 |
# |
|---|
| 968 |
|
|---|
| 969 |
my %tag_hash = ( |
|---|
| 970 |
'{DMN_NAME}' => $base_vhost, |
|---|
| 971 |
'{DMN_IP}' => $base_ip, |
|---|
| 972 |
'{BASE_SERVER_IP}' => $base_ip, |
|---|
| 973 |
'{SECONDARY_DNS_IP}' => $sec_dns_ip, |
|---|
| 974 |
'{TIMESTAMP}' => $time2 |
|---|
| 975 |
); |
|---|
| 976 |
|
|---|
| 977 |
($rs, $entry, $dns2_b, $dns2_e) = prep_tpl( |
|---|
| 978 |
\%tag_hash, |
|---|
| 979 |
$entry, |
|---|
| 980 |
$dns2_b, |
|---|
| 981 |
$dns2_e |
|---|
| 982 |
); |
|---|
| 983 |
|
|---|
| 984 |
return $rs if ($rs != 0); |
|---|
| 985 |
|
|---|
| 986 |
# |
|---|
| 987 |
# Let's store generated data; |
|---|
| 988 |
# |
|---|
| 989 |
|
|---|
| 990 |
$rs = store_file($working_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 991 |
return $rs if ($rs != 0); |
|---|
| 992 |
|
|---|
| 993 |
$rs = store_file($sys_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 994 |
return $rs if ($rs != 0); |
|---|
| 995 |
|
|---|
| 996 |
push_el(\@main::el, 'add_named_db_data()', 'Ending...'); |
|---|
| 997 |
return 0; |
|---|
| 998 |
} |
|---|
| 999 |
|
|---|
| 1000 |
# |
|---|
| 1001 |
# Create PHP directory for Master User (FastCGI) |
|---|
| 1002 |
# |
|---|
| 1003 |
|
|---|
| 1004 |
sub setup_php_master_user_dirs { |
|---|
| 1005 |
push_el(\@main::el, 'setup_php_master_user_dirs()', 'Starting...'); |
|---|
| 1006 |
|
|---|
| 1007 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 1008 |
my $starter_dir = $main::cfg{'PHP_STARTER_DIR'}; |
|---|
| 1009 |
|
|---|
| 1010 |
# Create php4 directory for Master User |
|---|
| 1011 |
#$rs = make_dir("$starter_dir/master/php4", $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 1012 |
#return $rs if ($rs != 0); |
|---|
| 1013 |
|
|---|
| 1014 |
# Create php5 directory for Master User |
|---|
| 1015 |
$rs = make_dir("$starter_dir/master/php5", $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 1016 |
return $rs if ($rs != 0); |
|---|
| 1017 |
|
|---|
| 1018 |
push_el(\@main::el, 'setup_php_master_user_dirs()', 'Ending...'); |
|---|
| 1019 |
return 0; |
|---|
| 1020 |
} |
|---|
| 1021 |
|
|---|
| 1022 |
sub setup_php { |
|---|
| 1023 |
|
|---|
| 1024 |
my ($rs, $rdata, $cmd, $cfg_tpl, $cfg) = (undef, undef, undef, undef, undef); |
|---|
| 1025 |
|
|---|
| 1026 |
push_el(\@main::el, 'setup_php()', 'Starting...'); |
|---|
| 1027 |
|
|---|
| 1028 |
# |
|---|
| 1029 |
# Configure the fastcgi_ispcp.conf |
|---|
| 1030 |
# |
|---|
| 1031 |
|
|---|
| 1032 |
my $cfg_dir = "$main::cfg{'CONF_DIR'}/apache"; |
|---|
| 1033 |
my $bk_dir = "$cfg_dir/backup"; |
|---|
| 1034 |
|
|---|
| 1035 |
($rs, $cfg_tpl) = get_tpl("$cfg_dir/working", 'fastcgi_ispcp.conf'); |
|---|
| 1036 |
return $rs if ($rs != 0); |
|---|
| 1037 |
|
|---|
| 1038 |
my %tag_hash = ( |
|---|
| 1039 |
'{APACHE_SUEXEC_MIN_UID}' => $main::cfg{'APACHE_SUEXEC_MIN_UID'}, |
|---|
| 1040 |
'{APACHE_SUEXEC_MIN_GID}' => $main::cfg{'APACHE_SUEXEC_MIN_GID'}, |
|---|
| 1041 |
'{APACHE_SUEXEC_USER_PREF}' => $main::cfg{'APACHE_SUEXEC_USER_PREF'}, |
|---|
| 1042 |
'{PHP_STARTER_DIR}' => $main::cfg{'PHP_STARTER_DIR'}, |
|---|
| 1043 |
'{PHP_VERSION}' => $main::cfg{'PHP_VERSION'} |
|---|
| 1044 |
); |
|---|
| 1045 |
|
|---|
| 1046 |
($rs, $cfg) = prep_tpl(\%tag_hash, $cfg_tpl); |
|---|
| 1047 |
return $rs if ($rs != 0); |
|---|
| 1048 |
|
|---|
| 1049 |
$rs = store_file("$bk_dir/fastcgi_ispcp.conf.ispcp", $cfg, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 1050 |
return $rs if ($rs != 0); |
|---|
| 1051 |
|
|---|
| 1052 |
$cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/fastcgi_ispcp.conf.ispcp $main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.conf"; |
|---|
| 1053 |
$rs = sys_command($cmd); |
|---|
| 1054 |
return $rs if ($rs != 0); |
|---|
| 1055 |
|
|---|
| 1056 |
if ( -e "$main::cfg{'APACHE_MODS_DIR'}/fastcgi.load" && ! -e "$main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.load") { |
|---|
| 1057 |
$cmd = "$main::cfg{'CMD_CP'} -p $main::cfg{'APACHE_MODS_DIR'}/fastcgi.load $main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.load"; |
|---|
| 1058 |
$rs = sys_command($cmd); |
|---|
| 1059 |
return $rs if ($rs != 0); |
|---|
| 1060 |
|
|---|
| 1061 |
($rs, $rdata) = get_file("$main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.load"); |
|---|
| 1062 |
return $rs if ($rs != 0); |
|---|
| 1063 |
|
|---|
| 1064 |
$rdata = "<IfModule !mod_fastcgi.c>\n" . $rdata . "</IfModule>\n"; |
|---|
| 1065 |
$rs = save_file("$main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.load", $rdata); |
|---|
| 1066 |
return $rs if ($rs != 0); |
|---|
| 1067 |
} |
|---|
| 1068 |
|
|---|
| 1069 |
# |
|---|
| 1070 |
# Configure the fcgid_ispcp.conf |
|---|
| 1071 |
# |
|---|
| 1072 |
|
|---|
| 1073 |
$cfg_dir = "$main::cfg{'CONF_DIR'}/apache"; |
|---|
| 1074 |
$bk_dir = "$cfg_dir/backup"; |
|---|
| 1075 |
|
|---|
| 1076 |
($rs, $cfg_tpl) = get_tpl("$cfg_dir/working", 'fcgid_ispcp.conf'); |
|---|
| 1077 |
return $rs if ($rs != 0); |
|---|
| 1078 |
|
|---|
| 1079 |
%tag_hash = ( |
|---|
| 1080 |
'{PHP_VERSION}' => $main::cfg{'PHP_VERSION'} |
|---|
| 1081 |
); |
|---|
| 1082 |
|
|---|
| 1083 |
($rs, $cfg) = prep_tpl(\%tag_hash, $cfg_tpl); |
|---|
| 1084 |
return $rs if ($rs != 0); |
|---|
| 1085 |
|
|---|
| 1086 |
$rs = |
|---|