| 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-2008 by ispCP |
|---|
| 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 | |
|---|
| 35 | use lib "$FindBin::Bin/.."; |
|---|
| 36 | require 'ispcp_common_code.pl'; |
|---|
| 37 | |
|---|
| 38 | use strict; |
|---|
| 39 | use warnings; |
|---|
| 40 | use Socket; |
|---|
| 41 | |
|---|
| 42 | %main::ua = (); |
|---|
| 43 | |
|---|
| 44 | ################################################################################ |
|---|
| 45 | ## SUBROUTINES ## |
|---|
| 46 | ################################################################################ |
|---|
| 47 | |
|---|
| 48 | sub welcome_note { |
|---|
| 49 | |
|---|
| 50 | my ($rs, $rdata) = (undef, undef); |
|---|
| 51 | |
|---|
| 52 | push_el(\@main::el, 'welcome_note()', 'Starting...'); |
|---|
| 53 | |
|---|
| 54 | my $welcome_message = <<MSG; |
|---|
| 55 | |
|---|
| 56 | \tWelcome to ispCP '$main::cfg{'Version'}' Setup Dialog. |
|---|
| 57 | \tThis program will set up ispCP OMEGA system on your server. |
|---|
| 58 | MSG |
|---|
| 59 | |
|---|
| 60 | print STDOUT $welcome_message; |
|---|
| 61 | |
|---|
| 62 | push_el(\@main::el, 'welcome_note()', 'Ending...'); |
|---|
| 63 | |
|---|
| 64 | return 0; |
|---|
| 65 | |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | sub get_sys_hostname { |
|---|
| 69 | |
|---|
| 70 | my ($rs, $rdata) = (undef, undef); |
|---|
| 71 | |
|---|
| 72 | push_el(\@main::el, 'get_sys_hostname()', 'Starting...'); |
|---|
| 73 | |
|---|
| 74 | my $cmd = "$main::cfg{'CMD_HOSTNAME'} 1>/tmp/ispcp-setup.hostname"; |
|---|
| 75 | |
|---|
| 76 | $rs = sys_command($cmd); |
|---|
| 77 | |
|---|
| 78 | return ($rs, '') if ($rs != 0); |
|---|
| 79 | |
|---|
| 80 | ($rs, $rdata) = get_file("/tmp/ispcp-setup.hostname"); |
|---|
| 81 | |
|---|
| 82 | return ($rs, '') if ($rs != 0); |
|---|
| 83 | |
|---|
| 84 | chop($rdata); |
|---|
| 85 | |
|---|
| 86 | $rs = del_file("/tmp/ispcp-setup.hostname"); |
|---|
| 87 | |
|---|
| 88 | push_el(\@main::el, 'get_sys_hostname()', 'Ending...'); |
|---|
| 89 | |
|---|
| 90 | return (0, $rdata); |
|---|
| 91 | |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | sub ask_hostname { |
|---|
| 95 | |
|---|
| 96 | my ($rs, $rdata) = (undef, undef); |
|---|
| 97 | |
|---|
| 98 | push_el(\@main::el, 'ask_hostname()', 'Starting...'); |
|---|
| 99 | |
|---|
| 100 | my $hostname = undef; |
|---|
| 101 | |
|---|
| 102 | ($rs, $hostname) = get_sys_hostname(); |
|---|
| 103 | |
|---|
| 104 | return $rs if ($rs != 0); |
|---|
| 105 | |
|---|
| 106 | my $qmsg = "\tPlease enter fully qualified hostname. [$hostname]: "; |
|---|
| 107 | |
|---|
| 108 | print STDOUT $qmsg; |
|---|
| 109 | |
|---|
| 110 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 111 | |
|---|
| 112 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 113 | |
|---|
| 114 | $rdata = $hostname; |
|---|
| 115 | |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if ($rdata =~ /^((([\w][\w-]{0,253}[\w])\.)*)([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 119 | |
|---|
| 120 | $main::ua{'hostname'} = $rdata; |
|---|
| 121 | $main::ua{'hostname_local'} = ( ($1) ? $1 : $4); |
|---|
| 122 | $main::ua{'hostname_local'} =~ s/^([^.]+).+$/$1/; |
|---|
| 123 | } else { |
|---|
| 124 | |
|---|
| 125 | print STDOUT "\n\tHostname is not a valid domain name!\n"; |
|---|
| 126 | return 1; |
|---|
| 127 | |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | push_el(\@main::el, 'ask_hostname()', 'Ending...'); |
|---|
| 131 | |
|---|
| 132 | return 0; |
|---|
| 133 | |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | sub ask_eth { |
|---|
| 137 | |
|---|
| 138 | my ($rs, $rdata) = (undef, undef); |
|---|
| 139 | |
|---|
| 140 | push_el(\@main::el, 'ask_eth()', 'Starting...'); |
|---|
| 141 | |
|---|
| 142 | #my $cmd = "/sbin/ifconfig |awk \'BEGIN{FS=\":\";}{print \$2}\'|awk \'{if(NR==2)print \$1}\' 1>/tmp/ispcp-setup.ip"; |
|---|
| 143 | |
|---|
| 144 | 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"; |
|---|
| 145 | |
|---|
| 146 | $rs = sys_command($cmd); |
|---|
| 147 | |
|---|
| 148 | return ($rs, '') if ($rs != 0); |
|---|
| 149 | |
|---|
| 150 | ($rs, $rdata) = get_file("/tmp/ispcp-setup.ip"); |
|---|
| 151 | |
|---|
| 152 | return ($rs, '') if ($rs != 0); |
|---|
| 153 | |
|---|
| 154 | chop($rdata); |
|---|
| 155 | |
|---|
| 156 | $rs = del_file("/tmp/ispcp-setup.ip"); |
|---|
| 157 | |
|---|
| 158 | $rs = sys_command($cmd); |
|---|
| 159 | |
|---|
| 160 | return $rs if ($rs != 0); |
|---|
| 161 | |
|---|
| 162 | my $eth = $rdata; |
|---|
| 163 | |
|---|
| 164 | my $qmsg = "\n\tPlease enter system network address. [$eth]: "; |
|---|
| 165 | |
|---|
| 166 | print STDOUT $qmsg; |
|---|
| 167 | |
|---|
| 168 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 169 | |
|---|
| 170 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 171 | |
|---|
| 172 | $main::ua{'eth_ip'} = $eth; |
|---|
| 173 | |
|---|
| 174 | } else { |
|---|
| 175 | |
|---|
| 176 | $main::ua{'eth_ip'} = $rdata; |
|---|
| 177 | |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | if (check_eth($main::ua{'eth_ip'}) != 0) { |
|---|
| 181 | return 0; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | push_el(\@main::el, 'ask_eth()', 'Ending...'); |
|---|
| 185 | |
|---|
| 186 | return 1; |
|---|
| 187 | |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | sub check_eth { |
|---|
| 191 | |
|---|
| 192 | my ($ip) = @_; |
|---|
| 193 | |
|---|
| 194 | return 0 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)); |
|---|
| 195 | |
|---|
| 196 | $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; |
|---|
| 197 | my ($d1, $d2, $d3, $d4) = ($1, $2, $3, $4); |
|---|
| 198 | |
|---|
| 199 | return 0 if (($d1 <= 0) || ($d1 >= 255)); |
|---|
| 200 | |
|---|
| 201 | return 0 if (($d2 < 0) || ($d2 > 255)); |
|---|
| 202 | |
|---|
| 203 | return 0 if (($d3 < 0) || ($d3 > 255)); |
|---|
| 204 | |
|---|
| 205 | return 0 if (($d4 <= 0) || ($d4 >= 255)); |
|---|
| 206 | |
|---|
| 207 | return 1; |
|---|
| 208 | |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | sub ask_db_host { |
|---|
| 212 | |
|---|
| 213 | my ($rs, $rdata) = (undef, undef); |
|---|
| 214 | |
|---|
| 215 | push_el(\@main::el, 'ask_db_host()', 'Starting...'); |
|---|
| 216 | |
|---|
| 217 | my $db_host = 'localhost'; |
|---|
| 218 | |
|---|
| 219 | my $qmsg = "\n\tPlease enter SQL server host. [$db_host]: "; |
|---|
| 220 | |
|---|
| 221 | print STDOUT $qmsg; |
|---|
| 222 | |
|---|
| 223 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 224 | |
|---|
| 225 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 226 | |
|---|
| 227 | $main::ua{'db_host'} = $db_host; |
|---|
| 228 | |
|---|
| 229 | } else { |
|---|
| 230 | |
|---|
| 231 | $main::ua{'db_host'} = $rdata; |
|---|
| 232 | |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | push_el(\@main::el, 'ask_db_host()', 'Ending...'); |
|---|
| 236 | |
|---|
| 237 | return 0; |
|---|
| 238 | |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | sub ask_db_name { |
|---|
| 242 | |
|---|
| 243 | my ($rs, $rdata) = (undef, undef); |
|---|
| 244 | |
|---|
| 245 | push_el(\@main::el, 'ask_db_name()', 'Starting...'); |
|---|
| 246 | |
|---|
| 247 | my $db_name = 'ispcp'; |
|---|
| 248 | |
|---|
| 249 | my $qmsg = "\n\tPlease enter system SQL database. [$db_name]: "; |
|---|
| 250 | |
|---|
| 251 | print STDOUT $qmsg; |
|---|
| 252 | |
|---|
| 253 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 254 | |
|---|
| 255 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 256 | |
|---|
| 257 | $main::ua{'db_name'} = $db_name; |
|---|
| 258 | |
|---|
| 259 | } else { |
|---|
| 260 | |
|---|
| 261 | $main::ua{'db_name'} = $rdata; |
|---|
| 262 | |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | push_el(\@main::el, 'ask_db_name()', 'Ending...'); |
|---|
| 266 | |
|---|
| 267 | return 0; |
|---|
| 268 | |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | sub ask_db_user { |
|---|
| 273 | |
|---|
| 274 | my ($rs, $rdata) = (undef, undef); |
|---|
| 275 | |
|---|
| 276 | push_el(\@main::el, 'ask_db_user()', 'Starting...'); |
|---|
| 277 | |
|---|
| 278 | my $db_user = 'root'; |
|---|
| 279 | |
|---|
| 280 | my $qmsg = "\n\tPlease enter system SQL user. [$db_user]: "; |
|---|
| 281 | |
|---|
| 282 | print STDOUT $qmsg; |
|---|
| 283 | |
|---|
| 284 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 285 | |
|---|
| 286 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 287 | |
|---|
| 288 | $main::ua{'db_user'} = $db_user; |
|---|
| 289 | |
|---|
| 290 | } else { |
|---|
| 291 | |
|---|
| 292 | $main::ua{'db_user'} = $rdata; |
|---|
| 293 | |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | push_el(\@main::el, 'ask_db_user()', 'Ending...'); |
|---|
| 297 | |
|---|
| 298 | return 0; |
|---|
| 299 | |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | sub ask_db_password { |
|---|
| 303 | |
|---|
| 304 | my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 305 | |
|---|
| 306 | push_el(\@main::el, 'ask_db_password()', 'Starting...'); |
|---|
| 307 | |
|---|
| 308 | my $db_password = 'none'; |
|---|
| 309 | |
|---|
| 310 | my $qmsg = "\n\tPlease enter system SQL password. [$db_password]: "; |
|---|
| 311 | |
|---|
| 312 | $pass1 = read_password($qmsg); |
|---|
| 313 | |
|---|
| 314 | if (!defined($pass1) || $pass1 eq '') { |
|---|
| 315 | |
|---|
| 316 | $main::ua{'db_password'} = ''; |
|---|
| 317 | |
|---|
| 318 | } else { |
|---|
| 319 | |
|---|
| 320 | $qmsg = "\tPlease repeat system SQL password: "; |
|---|
| 321 | |
|---|
| 322 | $pass2 = read_password($qmsg); |
|---|
| 323 | |
|---|
| 324 | if ($pass1 eq $pass2) { |
|---|
| 325 | |
|---|
| 326 | $main::ua{'db_password'} = $pass1; |
|---|
| 327 | |
|---|
| 328 | } else { |
|---|
| 329 | print STDOUT "\n\tPasswords do not match!"; |
|---|
| 330 | return 1; |
|---|
| 331 | |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | push_el(\@main::el, 'ask_db_password()', 'Ending...'); |
|---|
| 337 | |
|---|
| 338 | return 0; |
|---|
| 339 | |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | sub ask_db_ftp_user { |
|---|
| 343 | |
|---|
| 344 | my ($rs, $rdata) = (undef, undef); |
|---|
| 345 | |
|---|
| 346 | push_el(\@main::el, 'ask_db_ftp_user()', 'Starting...'); |
|---|
| 347 | |
|---|
| 348 | my $db_user = 'vftp'; |
|---|
| 349 | |
|---|
| 350 | my $qmsg = "\n\tPlease enter ispCP ftp SQL user. [$db_user]: "; |
|---|
| 351 | |
|---|
| 352 | print STDOUT $qmsg; |
|---|
| 353 | |
|---|
| 354 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 355 | |
|---|
| 356 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 357 | |
|---|
| 358 | $main::ua{'db_ftp_user'} = $db_user; |
|---|
| 359 | |
|---|
| 360 | } else { |
|---|
| 361 | |
|---|
| 362 | $main::ua{'db_ftp_user'} = $rdata; |
|---|
| 363 | |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | push_el(\@main::el, 'ask_db_ftp_user()', 'Ending...'); |
|---|
| 367 | |
|---|
| 368 | return 0; |
|---|
| 369 | |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | sub ask_db_ftp_password { |
|---|
| 373 | |
|---|
| 374 | my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 375 | |
|---|
| 376 | push_el(\@main::el, 'ask_db_ftp_password()', 'Starting...'); |
|---|
| 377 | |
|---|
| 378 | my $db_password = undef; |
|---|
| 379 | |
|---|
| 380 | my $qmsg = "\n\tPlease enter ispCP ftp SQL user password. [auto generate]: "; |
|---|
| 381 | |
|---|
| 382 | $pass1 = read_password($qmsg); |
|---|
| 383 | |
|---|
| 384 | if (!defined($pass1) || $pass1 eq '') { |
|---|
| 385 | |
|---|
| 386 | $db_password = gen_sys_rand_num(18); |
|---|
| 387 | $db_password =~ s/'//g;; |
|---|
| 388 | $main::ua{'db_ftp_password'} = $db_password; |
|---|
| 389 | print STDOUT "\tispCP ftp SQL user password set to: $db_password\n"; |
|---|
| 390 | |
|---|
| 391 | } else { |
|---|
| 392 | |
|---|
| 393 | $qmsg = "\tPlease repeat ispCP ftp SQL user password: "; |
|---|
| 394 | |
|---|
| 395 | $pass2 = read_password($qmsg); |
|---|
| 396 | |
|---|
| 397 | if ($pass1 eq $pass2) { |
|---|
| 398 | |
|---|
| 399 | $main::ua{'db_ftp_password'} = $pass1; |
|---|
| 400 | |
|---|
| 401 | } else { |
|---|
| 402 | print STDOUT "\n\tPasswords do not match!"; |
|---|
| 403 | return 1; |
|---|
| 404 | |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | push_el(\@main::el, 'ask_db_ftp_password()', 'Ending...'); |
|---|
| 410 | |
|---|
| 411 | return 0; |
|---|
| 412 | |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | sub ask_db_pma_user { |
|---|
| 416 | |
|---|
| 417 | my ($rs, $rdata) = (undef, undef); |
|---|
| 418 | push_el(\@main::el, 'ask_db_pma_user()', 'Starting...'); |
|---|
| 419 | my $db_user = 'pma'; |
|---|
| 420 | |
|---|
| 421 | my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user. [$db_user]: "; |
|---|
| 422 | print STDOUT $qmsg; |
|---|
| 423 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 424 | |
|---|
| 425 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 426 | $main::ua{'db_pma_user'} = $db_user; |
|---|
| 427 | } else { |
|---|
| 428 | $main::ua{'db_pma_user'} = $rdata; |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | push_el(\@main::el, 'ask_db_pma_user()', 'Ending...'); |
|---|
| 432 | return 0; |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | sub ask_db_pma_password { |
|---|
| 436 | |
|---|
| 437 | my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 438 | push_el(\@main::el, 'ask_db_pma_password()', 'Starting...'); |
|---|
| 439 | |
|---|
| 440 | my $db_password = undef; |
|---|
| 441 | |
|---|
| 442 | my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user password. [auto generate]: "; |
|---|
| 443 | $pass1 = read_password($qmsg); |
|---|
| 444 | |
|---|
| 445 | if (!defined($pass1) || $pass1 eq '') { |
|---|
| 446 | |
|---|
| 447 | $db_password = gen_sys_rand_num(18); |
|---|
| 448 | $main::ua{'db_pma_password'} = $db_password; |
|---|
| 449 | print STDOUT "\tphpMyAdmin Control user password set to: $db_password\n"; |
|---|
| 450 | |
|---|
| 451 | } else { |
|---|
| 452 | $qmsg = "\tPlease repeat ispCP phpMyAdmin Control user password: "; |
|---|
| 453 | $pass2 = read_password($qmsg); |
|---|
| 454 | |
|---|
| 455 | if ($pass1 eq $pass2) { |
|---|
| 456 | $main::ua{'db_pma_password'} = $pass1; |
|---|
| 457 | } else { |
|---|
| 458 | print STDOUT "\n\tPasswords do not match!"; |
|---|
| 459 | return 1; |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | push_el(\@main::el, 'ask_db_pma_password()', 'Ending...'); |
|---|
| 464 | return 0; |
|---|
| 465 | |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | sub ask_admin { |
|---|
| 469 | |
|---|
| 470 | my ($rs, $rdata) = (undef, undef); |
|---|
| 471 | |
|---|
| 472 | push_el(\@main::el, 'ask_admin()', 'Starting...'); |
|---|
| 473 | |
|---|
| 474 | my $admin = 'admin'; |
|---|
| 475 | |
|---|
| 476 | my $qmsg = "\n\tPlease enter administrator login name. [$admin]: "; |
|---|
| 477 | |
|---|
| 478 | print STDOUT $qmsg; |
|---|
| 479 | |
|---|
| 480 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 481 | |
|---|
| 482 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 483 | |
|---|
| 484 | $main::ua{'admin'} = $admin; |
|---|
| 485 | |
|---|
| 486 | } else { |
|---|
| 487 | |
|---|
| 488 | $main::ua{'admin'} = $rdata; |
|---|
| 489 | |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | push_el(\@main::el, 'ask_admin()', 'Ending...'); |
|---|
| 493 | |
|---|
| 494 | return 0; |
|---|
| 495 | |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | sub ask_admin_password { |
|---|
| 499 | |
|---|
| 500 | my ($rs, $pass1, $pass2) = (undef, undef, undef); |
|---|
| 501 | |
|---|
| 502 | push_el(\@main::el, 'ask_admin_password()', 'Starting...'); |
|---|
| 503 | |
|---|
| 504 | my $qmsg = "\n\tPlease enter administrator password: "; |
|---|
| 505 | |
|---|
| 506 | $pass1 = read_password($qmsg); |
|---|
| 507 | |
|---|
| 508 | if (!defined($pass1) || $pass1 eq '') { |
|---|
| 509 | print STDOUT "\n\tPassword too short!"; |
|---|
| 510 | return 1; |
|---|
| 511 | } else { |
|---|
| 512 | if (length($pass1) < 5) { |
|---|
| 513 | print STDOUT "\n\tPassword too short!"; |
|---|
| 514 | return 1; |
|---|
| 515 | } |
|---|
| 516 | $qmsg = "\tPlease repeat administrator password: "; |
|---|
| 517 | $pass2 = read_password($qmsg); |
|---|
| 518 | |
|---|
| 519 | if ($pass1 =~ m/[a-zA-Z]/ && $pass1 =~ m/[0-9]/) { |
|---|
| 520 | |
|---|
| 521 | if ($pass1 eq $pass2) { |
|---|
| 522 | $main::ua{'admin_password'} = $pass1; |
|---|
| 523 | } else { |
|---|
| 524 | print STDOUT "\n\tPasswords do not match!"; |
|---|
| 525 | return 1; |
|---|
| 526 | } |
|---|
| 527 | } |
|---|
| 528 | else { |
|---|
| 529 | print STDOUT "\n\tPasswords must contain at least digits and chars!"; |
|---|
| 530 | return 1; |
|---|
| 531 | } |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | push_el(\@main::el, 'ask_admin_password()', 'Ending...'); |
|---|
| 535 | |
|---|
| 536 | return 0; |
|---|
| 537 | |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | sub ask_admin_email { |
|---|
| 541 | |
|---|
| 542 | my ($rs, $rdata) = (undef, undef); |
|---|
| 543 | |
|---|
| 544 | push_el(\@main::el, 'ask_admin_email()', 'Starting...'); |
|---|
| 545 | |
|---|
| 546 | my $qmsg = "\n\tPlease enter admininistrator email address: "; |
|---|
| 547 | |
|---|
| 548 | print STDOUT $qmsg; |
|---|
| 549 | |
|---|
| 550 | $rdata = readline(\*STDIN); chop($rdata); |
|---|
| 551 | |
|---|
| 552 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 553 | |
|---|
| 554 | return 1; |
|---|
| 555 | |
|---|
| 556 | } else { |
|---|
| 557 | |
|---|
| 558 | if ($rdata =~ /^([\w\W]{1,255})\@([\w][\w-]{0,253}[\w]\.)*([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 559 | |
|---|
| 560 | $main::ua{'admin_email'} = $rdata; |
|---|
| 561 | |
|---|
| 562 | } else { |
|---|
| 563 | print STDOUT "\n\tE-Mail address not valid!"; |
|---|
| 564 | return 1; |
|---|
| 565 | |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | push_el(\@main::el, 'ask_admin_email()', 'Ending...'); |
|---|
| 571 | |
|---|
| 572 | return 0; |
|---|
| 573 | |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | sub ask_vhost { |
|---|
| 577 | |
|---|
| 578 | my ($rs, $rdata) = (undef, undef); |
|---|
| 579 | |
|---|
| 580 | push_el(\@main::el, 'ask_vhost()', 'Starting...'); |
|---|
| 581 | |
|---|
| 582 | my $eth = $main::ua{'eth_ip'}; |
|---|
| 583 | |
|---|
| 584 | my $addr = gethostbyaddr($main::ua{'eth_ip'}, AF_INET); |
|---|
| 585 | |
|---|
| 586 | if (!$addr) { |
|---|
| 587 | $addr = $main::ua{'hostname'}; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | my $vhost = "admin.$addr"; |
|---|
| 591 | |
|---|
| 592 | my $qmsg = "\n\tPlease enter the domain name where ispCP OMEGA will run on [$vhost]: "; |
|---|
| 593 | |
|---|
| 594 | print STDOUT $qmsg; |
|---|
| 595 | |
|---|
| 596 | $rdata = readline(\*STDIN); |
|---|
| 597 | chop($rdata); |
|---|
| 598 | |
|---|
| 599 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 600 | $main::ua{'admin_vhost'} = $vhost; |
|---|
| 601 | } |
|---|
| 602 | else { |
|---|
| 603 | if ($rdata =~ /^([\w][\w-]{0,253}[\w]\.)*([\w][\w-]{0,253}[\w])\.([a-zA-Z]{2,6})$/) { |
|---|
| 604 | $main::ua{'admin_vhost'} = $rdata; |
|---|
| 605 | } |
|---|
| 606 | else { |
|---|
| 607 | print STDOUT "\n\tVhost not valid!"; |
|---|
| 608 | return 1; |
|---|
| 609 | } |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | push_el(\@main::el, 'ask_vhost()', 'Ending...'); |
|---|
| 613 | |
|---|
| 614 | return 0; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | sub ask_awstats_on { |
|---|
| 618 | |
|---|
| 619 | my $rdata = undef; |
|---|
| 620 | |
|---|
| 621 | push_el(\@main::el, 'ask_awstats_on()', 'Starting...'); |
|---|
| 622 | |
|---|
| 623 | my $qmsg = "\n\tActivate AWStats. [no]: "; |
|---|
| 624 | |
|---|
| 625 | print STDOUT $qmsg; |
|---|
| 626 | |
|---|
| 627 | $rdata = readline(\*STDIN); |
|---|
| 628 | chop($rdata); |
|---|
| 629 | |
|---|
| 630 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 631 | $main::ua{'awstats_on'} = 'no'; |
|---|
| 632 | } |
|---|
| 633 | else { |
|---|
| 634 | if ($rdata eq 'yes' || $rdata eq 'y') { |
|---|
| 635 | $main::ua{'awstats_on'} = 'yes'; |
|---|
| 636 | } |
|---|
| 637 | elsif ($rdata eq 'no' || $rdata eq 'n') { |
|---|
| 638 | $main::ua{'awstats_on'} = 'no'; |
|---|
| 639 | } |
|---|
| 640 | else { |
|---|
| 641 | print STDOUT "\n\tOnly '(y)es' and '(n)o' are allowed!"; |
|---|
| 642 | return 1; |
|---|
| 643 | } |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | push_el(\@main::el, 'ask_awstats_on()', 'Ending...'); |
|---|
| 647 | |
|---|
| 648 | return 0; |
|---|
| 649 | } |
|---|
| 650 | |
|---|
| 651 | sub ask_awstats_dyn { |
|---|
| 652 | |
|---|
| 653 | my $rdata = undef; |
|---|
| 654 | |
|---|
| 655 | push_el(\@main::el, 'ask_awstats_dyn()', 'Starting...'); |
|---|
| 656 | |
|---|
| 657 | my $qmsg = "\n\tAWStats Mode:\n\tPossible values [d]ynamic and [s]tatic. [dynamic]: "; |
|---|
| 658 | |
|---|
| 659 | print STDOUT $qmsg; |
|---|
| 660 | |
|---|
| 661 | $rdata = readline(\*STDIN); |
|---|
| 662 | chop($rdata); |
|---|
| 663 | |
|---|
| 664 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 665 | $main::ua{'awstats_dyn'} = '0'; |
|---|
| 666 | } |
|---|
| 667 | else { |
|---|
| 668 | if ($rdata eq 'dynamic' || $rdata eq 'd') { |
|---|
| 669 | $main::ua{'awstats_dyn'} = '0'; |
|---|
| 670 | } |
|---|
| 671 | elsif ($rdata eq 'static' || $rdata eq 's') { |
|---|
| 672 | $main::ua{'awstats_dyn'} = '1'; |
|---|
| 673 | } |
|---|
| 674 | else { |
|---|
| 675 | print STDOUT "\n\tOnly '[d]ynamic' or '[s]tatic' are allowed!"; |
|---|
| 676 | return 1; |
|---|
| 677 | } |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | push_el(\@main::el, 'ask_awstats_dyn()', 'Ending...'); |
|---|
| 681 | |
|---|
| 682 | return 0; |
|---|
| 683 | } |
|---|
| 684 | |
|---|
| 685 | sub ask_php_version { |
|---|
| 686 | |
|---|
| 687 | my $rdata = undef; |
|---|
| 688 | |
|---|
| 689 | push_el(\@main::el, 'ask_php_version()', 'Starting...'); |
|---|
| 690 | |
|---|
| 691 | my $qmsg = "\n\tUse which PHP Version? (4 or 5). [5]: "; |
|---|
| 692 | |
|---|
| 693 | print STDOUT $qmsg; |
|---|
| 694 | |
|---|
| 695 | $rdata = readline(\*STDIN); |
|---|
| 696 | chop($rdata); |
|---|
| 697 | |
|---|
| 698 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 699 | $main::ua{'php_version'} = '5'; |
|---|
| 700 | } |
|---|
| 701 | else { |
|---|
| 702 | if ($rdata eq 'php4' || $rdata eq '4') { |
|---|
| 703 | $main::ua{'php_version'} = '4'; |
|---|
| 704 | } |
|---|
| 705 | elsif ($rdata eq 'php5' || $rdata eq '5') { |
|---|
| 706 | $main::ua{'php_version'} = '5'; |
|---|
| 707 | } |
|---|
| 708 | else { |
|---|
| 709 | print STDOUT "\n\tOnly 'php(4)' and 'php(5)' are allowed!"; |
|---|
| 710 | return 1; |
|---|
| 711 | } |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | push_el(\@main::el, 'ask_php_version()', 'Ending...'); |
|---|
| 715 | |
|---|
| 716 | return 0; |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| 719 | sub ask_second_dns { |
|---|
| 720 | |
|---|
| 721 | my $rdata = undef; |
|---|
| 722 | |
|---|
| 723 | push_el(\@main::el, 'ask_php_version()', 'Starting...'); |
|---|
| 724 | |
|---|
| 725 | my $qmsg = "\n\tIP of Secondary DNS. (optional) []: "; |
|---|
| 726 | |
|---|
| 727 | print STDOUT $qmsg; |
|---|
| 728 | |
|---|
| 729 | $rdata = readline(\*STDIN); |
|---|
| 730 | chop($rdata); |
|---|
| 731 | |
|---|
| 732 | if (!defined($rdata) || $rdata eq '') { |
|---|
| 733 | $main::ua{'secondary_dns'} = ''; |
|---|
| 734 | } |
|---|
| 735 | else { |
|---|
| 736 | if (check_eth($rdata) != 0) { |
|---|
| 737 | $main::ua{'secondary_dns'} = $rdata; |
|---|
| 738 | } |
|---|
| 739 | else { |
|---|
| 740 | print STDOUT "\n\tNo valid IP, please retry!"; |
|---|
| 741 | return 1; |
|---|
| 742 | } |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | push_el(\@main::el, 'ask_php_version()', 'Ending...'); |
|---|
| 746 | |
|---|
| 747 | return 0; |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | sub ask_mysql_prefix { |
|---|
| 751 | |
|---|
| 752 | my $rdata = undef; |
|---|
| 753 | |
|---|
| 754 | push_el(\@main::el, 'ask_php_version()', 'Starting...'); |
|---|
| 755 | |
|---|
| 756 | my $qmsg = "\n\tUse MySQL Prefix.\n\tPossible values: [i]nfront, [b]ehind, [n]one. [none]: "; |
|---|
| 757 | |
|---|
| 758 | print STDOUT $qmsg; |
|---|
| 759 | |
|---|
| 760 | $rdata = readline(\*STDIN); |
|---|
| 761 | chop($rdata); |
|---|
| 762 | |
|---|
| 763 | if (!defined($rdata) || $rdata eq '' || $rdata eq 'none' || $rdata eq 'n') { |
|---|
| 764 | $main::ua{'mysql_prefix'} = 'no'; |
|---|
| 765 | $main::ua{'mysql_prefix_type'} = ''; |
|---|
| 766 | } |
|---|
| 767 | else { |
|---|
| 768 | if ($rdata eq 'infront' || $rdata eq 'i') { |
|---|
| 769 | $main::ua{'mysql_prefix'} = 'yes'; |
|---|
| 770 | $main::ua{'mysql_prefix_type'} = 'infront'; |
|---|
| 771 | } |
|---|
| 772 | elsif ($rdata eq 'behind' || $rdata eq 'b') { |
|---|
| 773 | $main::ua{'mysql_prefix'} = 'yes'; |
|---|
| 774 | $main::ua{'mysql_prefix_type'} = 'behind'; |
|---|
| 775 | } |
|---|
| 776 | else { |
|---|
| 777 | print STDOUT "\n\tNot allowed Value, please retry!"; |
|---|
| 778 | return 1; |
|---|
| 779 | } |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | push_el(\@main::el, 'ask_php_version()', 'Ending...'); |
|---|
| 783 | |
|---|
| 784 | return 0; |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | sub user_dialog { |
|---|
| 788 | |
|---|
| 789 | my $rs = undef; |
|---|
| 790 | |
|---|
| 791 | push_el(\@main::el, 'user_dialog()', 'Starting...'); |
|---|
| 792 | |
|---|
| 793 | $rs = welcome_note(); |
|---|
| 794 | |
|---|
| 795 | return $rs if ($rs != 0); |
|---|
| 796 | |
|---|
| 797 | do { |
|---|
| 798 | $rs = ask_hostname(); |
|---|
| 799 | } while ($rs == 1); |
|---|
| 800 | |
|---|
| 801 | return $rs if ($rs != 0); |
|---|
| 802 | |
|---|
| 803 | do { |
|---|
| 804 | |
|---|
| 805 | $rs = ask_eth(); |
|---|
| 806 | |
|---|
| 807 | } while ($rs == 1); |
|---|
| 808 | |
|---|
| 809 | do { |
|---|
| 810 | $rs = ask_vhost(); |
|---|
| 811 | } while ($rs == 1); |
|---|
| 812 | |
|---|
| 813 | # |
|---|
| 814 | # SQL Questions |
|---|
| 815 | # |
|---|
| 816 | |
|---|
| 817 | $rs = ask_db_host(); |
|---|
| 818 | |
|---|
| 819 | return $rs if ($rs != 0); |
|---|
| 820 | |
|---|
| 821 | $rs = ask_db_name(); |
|---|
| 822 | |
|---|
| 823 | return $rs if ($rs != 0); |
|---|
| 824 | |
|---|
| 825 | $rs = ask_db_user(); |
|---|
| 826 | |
|---|
| 827 | return $rs if ($rs != 0); |
|---|
| 828 | |
|---|
| 829 | do { |
|---|
| 830 | |
|---|
| 831 | $rs = ask_db_password(); |
|---|
| 832 | |
|---|
| 833 | } while ($rs == 1); |
|---|
| 834 | |
|---|
| 835 | # |
|---|
| 836 | # ispCP ftp SQL user questions; |
|---|
| 837 | # |
|---|
| 838 | |
|---|
| 839 | $rs = ask_db_ftp_user(); |
|---|
| 840 | return $rs if ($rs != 0); |
|---|
| 841 | |
|---|
| 842 | do { |
|---|
| 843 | $rs = ask_db_ftp_password(); |
|---|
| 844 | } while ($rs == 1); |
|---|
| 845 | |
|---|
| 846 | # |
|---|
| 847 | # PMA user for SQL |
|---|
| 848 | # |
|---|
| 849 | |
|---|
| 850 | $rs = ask_db_pma_user(); |
|---|
| 851 | return $rs if ($rs != 0); |
|---|
| 852 | |
|---|
| 853 | do { |
|---|
| 854 | $rs = ask_db_pma_password(); |
|---|
| 855 | } while ($rs == 1); |
|---|
| 856 | |
|---|
| 857 | # |
|---|
| 858 | # Admin questions |
|---|
| 859 | # |
|---|
| 860 | |
|---|
| 861 | $rs = ask_admin(); |
|---|
| 862 | |
|---|
| 863 | return $rs if ($rs != 0); |
|---|
| 864 | |
|---|
| 865 | do { |
|---|
| 866 | |
|---|
| 867 | $rs = ask_admin_password(); |
|---|
| 868 | |
|---|
| 869 | } while ($rs == 1); |
|---|
| 870 | |
|---|
| 871 | do { |
|---|
| 872 | |
|---|
| 873 | $rs = ask_admin_email(); |
|---|
| 874 | |
|---|
| 875 | } while ($rs == 1); |
|---|
| 876 | |
|---|
| 877 | # |
|---|
| 878 | # Configuration questions |
|---|
| 879 | # |
|---|
| 880 | |
|---|
| 881 | do { |
|---|
| 882 | $rs = ask_php_version(); |
|---|
| 883 | } while ($rs == 1); |
|---|
| 884 | |
|---|
| 885 | do { |
|---|
| 886 | $rs = ask_second_dns(); |
|---|
| 887 | } while ($rs == 1); |
|---|
| 888 | |
|---|
| 889 | do { |
|---|
| 890 | $rs = ask_mysql_prefix(); |
|---|
| 891 | } while ($rs == 1); |
|---|
| 892 | |
|---|
| 893 | # |
|---|
| 894 | # AWStats questions |
|---|
| 895 | # |
|---|
| 896 | |
|---|
| 897 | do { |
|---|
| 898 | |
|---|
| 899 | $rs = ask_awstats_on(); |
|---|
| 900 | |
|---|
| 901 | } while ($rs == 1); |
|---|
| 902 | |
|---|
| 903 | if ($main::ua{'awstats_on'} eq 'yes') { |
|---|
| 904 | do { |
|---|
| 905 | |
|---|
| 906 | $rs = ask_awstats_dyn(); |
|---|
| 907 | |
|---|
| 908 | } while ($rs == 1); |
|---|
| 909 | } else { |
|---|
| 910 | # Just a dummy to prevent warnings |
|---|
| 911 | $main::ua{'awstats_dyn'} = 0; |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | my $qmsg = "\n\tStarting Installation...\n"; |
|---|
| 915 | |
|---|
| 916 | print STDOUT $qmsg; |
|---|
| 917 | |
|---|
| 918 | push_el(\@main::el, 'user_dialog()', "hostname: $main::ua{'hostname'}"); |
|---|
| 919 | push_el(\@main::el, 'user_dialog()', "eth: $main::ua{'eth_ip'}"); |
|---|
| 920 | push_el(\@main::el, 'user_dialog()', "panel_vhost: $main::ua{'admin_vhost'}"); |
|---|
| 921 | push_el(\@main::el, 'user_dialog()', "db_host: $main::ua{'db_host'}"); |
|---|
| 922 | push_el(\@main::el, 'user_dialog()', "db_name: $main::ua{'db_name'}"); |
|---|
| 923 | push_el(\@main::el, 'user_dialog()', "db_user: $main::ua{'db_user'}"); |
|---|
| 924 | push_el(\@main::el, 'user_dialog()', "db_password: $main::ua{'db_password'}"); |
|---|
| 925 | push_el(\@main::el, 'user_dialog()', "admin: $main::ua{'admin'}"); |
|---|
| 926 | push_el(\@main::el, 'user_dialog()', "admin_password"); |
|---|
| 927 | push_el(\@main::el, 'user_dialog()', "admin_email: $main::ua{'admin_email'}"); |
|---|
| 928 | push_el(\@main::el, 'user_dialog()', "awstats_on: $main::ua{'awstats_on'}"); |
|---|
| 929 | push_el(\@main::el, 'user_dialog()', "awstats_dyn: $main::ua{'awstats_dyn'}"); |
|---|
| 930 | push_el(\@main::el, 'user_dialog()', "mysql_prefix: $main::ua{'mysql_prefix'}"); |
|---|
| 931 | push_el(\@main::el, 'user_dialog()', "mysql_prefix_type: $main::ua{'mysql_prefix_type'}"); |
|---|
| 932 | push_el(\@main::el, 'user_dialog()', "php_version: $main::ua{'php_version'}"); |
|---|
| 933 | push_el(\@main::el, 'user_dialog()', 'Ending...'); |
|---|
| 934 | |
|---|
| 935 | return 0; |
|---|
| 936 | |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | sub setup_start_up { |
|---|
| 940 | |
|---|
| 941 | my ($rs, $rdata) = (undef, undef); |
|---|
| 942 | |
|---|
| 943 | push_el(\@main::el, 'setup_start_up()', 'Starting...'); |
|---|
| 944 | |
|---|
| 945 | # config check; |
|---|
| 946 | |
|---|
| 947 | $rs = get_conf(); |
|---|
| 948 | |
|---|
| 949 | return $rs if ($rs != 0); |
|---|
| 950 | |
|---|
| 951 | push_el(\@main::el, 'setup_start_up()', 'Ending...'); |
|---|
| 952 | |
|---|
| 953 | return 0; |
|---|
| 954 | |
|---|
| 955 | } |
|---|
| 956 | |
|---|
| 957 | sub setup_shut_down { |
|---|
| 958 | |
|---|
| 959 | my ($rs, $rdata) = (undef, undef); |
|---|
| 960 | |
|---|
| 961 | my $cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-gui-permissions.sh"; |
|---|
| 962 | |
|---|
| 963 | $rs = sys_command($cmd); |
|---|
| 964 | |
|---|
| 965 | return $rs if ($rs != 0); |
|---|
| 966 | |
|---|
| 967 | $cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-engine-permissions.sh"; |
|---|
| 968 | |
|---|
| 969 | $rs = sys_command($cmd); |
|---|
| 970 | |
|---|
| 971 | return $rs if ($rs != 0); |
|---|
| 972 | |
|---|
| 973 | push_el(\@main::el, 'setup_shut_down()', 'Starting...'); |
|---|
| 974 | |
|---|
| 975 | my $shut_down_message = <<MSG; |
|---|
| 976 | |
|---|
| 977 | \tCongratulations! |
|---|
| 978 | |
|---|
| 979 | \tispCP '$main::cfg{'Version'}' Setup completed successfully! |
|---|
| 980 | |
|---|
| 981 | \tPlease type http://$main::ua{'admin_vhost'} in your browser! |
|---|
| 982 | |
|---|
| 983 | MSG |
|---|
| 984 | print STDOUT $shut_down_message; |
|---|
| 985 | |
|---|
| 986 | if (sys_command_rs("which rkhunter > /dev/null") eq 0 ) { |
|---|
| 987 | print STDOUT "\tSetup is now updating rkhunter:\n"; |
|---|
| 988 | sys_command("rkhunter --update"); |
|---|
| 989 | print STDOUT "\n\n"; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | push_el(\@main::el, 'setup_shut_down()', 'Ending...'); |
|---|
| 993 | |
|---|
| 994 | return 0; |
|---|
| 995 | |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | sub check_host_interface { |
|---|
| 999 | |
|---|
| 1000 | push_el(\@main::el, 'check_host_interface()', 'Starting...'); |
|---|
| 1001 | |
|---|
| 1002 | my ($rs, $rdata, $cmd) = (undef, undef, undef); |
|---|
| 1003 | |
|---|
| 1004 | $cmd = "$main::cfg{'CMD_IFCONFIG'} $main::ua{'eth'} 1>/tmp/ispcp-setup-iface.stdout 2>/tmp/ispcp-setup-iface.stderr"; |
|---|
| 1005 | |
|---|
| 1006 | $rs = sys_command($cmd); |
|---|
| 1007 | |
|---|
| 1008 | if ($rs != 0) { |
|---|
| 1009 | |
|---|
| 1010 | push_el(\@main::el, 'check_host_interface()', "ERROR: Can't find $main::ua{'eth'} device!"); |
|---|
| 1011 | |
|---|
| 1012 | return $rs; |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | $cmd = "$main::cfg{'CMD_CAT'} /tmp/ispcp-setup-iface.stdout | awk 'BEGIN { i=0 } { i++ } { if (i == 1) { print \$5 } } { if (i == 2) { print substr(\$2, 6) } }' 1>/tmp/ispcp-setup-iface-data.stdout 2>/tmp/ispcp-setup-iface-data.stderr"; |
|---|
| 1016 | |
|---|
| 1017 | $rs = sys_command($cmd); |
|---|
| 1018 | |
|---|
| 1019 | ($rs, $rdata) = get_file("/tmp/ispcp-setup-iface-data.stdout"); |
|---|
| 1020 | |
|---|
| 1021 | return $rs if ($rs != 0); |
|---|
| 1022 | |
|---|
| 1023 | $rdata =~ /([^\n]+)\n([^\n]+)\n/; |
|---|
| 1024 | |
|---|
| 1025 | $main::ua{'eth_hwaddr'} = $1; |
|---|
| 1026 | |
|---|
| 1027 | $main::ua{'eth_ip'} = $2; |
|---|
| 1028 | |
|---|
| 1029 | $rs = del_file("/tmp/ispcp-setup-iface.stdout"); |
|---|
| 1030 | |
|---|
| 1031 | return $rs if ($rs != 0); |
|---|
| 1032 | |
|---|
| 1033 | $rs = del_file("/tmp/ispcp-setup-iface.stderr"); |
|---|
| 1034 | |
|---|
| 1035 | return $rs if ($rs != 0); |
|---|
| 1036 | |
|---|
| 1037 | $rs = del_file("/tmp/ispcp-setup-iface-data.stdout"); |
|---|
| 1038 | |
|---|
| 1039 | return $rs if ($rs != 0); |
|---|
| 1040 | |
|---|
| 1041 | $rs = del_file("/tmp/ispcp-setup-iface-data.stderr"); |
|---|
| 1042 | |
|---|
| 1043 | return $rs if ($rs != 0); |
|---|
| 1044 | |
|---|
| 1045 | push_el(\@main::el, 'check_host_interface()', 'Ending...'); |
|---|
| 1046 | |
|---|
| 1047 | return 0; |
|---|
| 1048 | } |
|---|
| 1049 | |
|---|
| 1050 | sub check_host_sql { |
|---|
| 1051 | |
|---|
| 1052 | push_el(\@main::el, 'check_host_sql()', 'Starting...'); |
|---|
| 1053 | |
|---|
| 1054 | my ($rs, $rdata, $sql) = (undef, undef, undef); |
|---|
| 1055 | |
|---|
| 1056 | $sql = "show databases;"; |
|---|
| 1057 | |
|---|
| 1058 | $main::db_host = $main::ua{'db_host'}; |
|---|
| 1059 | |
|---|
| 1060 | $main::db_user = $main::ua{'db_user'}; |
|---|
| 1061 | |
|---|
| 1062 | $main::db_pwd = $main::ua{'db_password'}; |
|---|
| 1063 | |
|---|
| 1064 | $main::db_name = ""; |
|---|
| 1065 | |
|---|
| 1066 | @main::db_connect = ( |
|---|
| 1067 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 1068 | $main::db_user, |
|---|
| 1069 | $main::db_pwd |
|---|
| 1070 | ); |
|---|
| 1071 | |
|---|
| 1072 | ($rs, $rdata) = doSQL($sql); |
|---|
| 1073 | |
|---|
| 1074 | return $rs if ($rs != 0); |
|---|
| 1075 | |
|---|
| 1076 | $main::db = undef; |
|---|
| 1077 | |
|---|
| 1078 | push_el(\@main::el, 'check_host_sql()', 'Ending...'); |
|---|
| 1079 | |
|---|
| 1080 | return 0; |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|
| 1083 | sub check_host_system { |
|---|
| 1084 | |
|---|
| 1085 | my ($rs, $rdata) = (undef, undef); |
|---|
| 1086 | |
|---|
| 1087 | push_el(\@main::el, 'check_host_system()', 'Starting...'); |
|---|
| 1088 | |
|---|
| 1089 | #$rs = check_host_interface(); |
|---|
| 1090 | |
|---|
| 1091 | #return $rs if ($rs != 0); |
|---|
| 1092 | |
|---|
| 1093 | $rs = check_host_sql(); |
|---|
| 1094 | |
|---|
| 1095 | return $rs if ($rs != 0); |
|---|
| 1096 | |
|---|
| 1097 | push_el(\@main::el, 'check_host_system()', 'Ending...'); |
|---|
| 1098 | |
|---|
| 1099 | return 0; |
|---|
| 1100 | |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | sub setup_system_users { |
|---|
| 1104 | |
|---|
| 1105 | my ($rs, $rdata) = (undef, undef); |
|---|
| 1106 | |
|---|
| 1107 | push_el(\@main::el, 'setup_system_users()', 'Starting...'); |
|---|
| 1108 | |
|---|
| 1109 | ## Mailbox user |
|---|
| 1110 | my ($fuid, $fgid) = ($main::cfg{'MTA_MAILBOX_UID_NAME'}, $main::cfg{'MTA_MAILBOX_GID_NAME'}); |
|---|
| 1111 | my ($uid, $gid) = (undef, undef); |
|---|
| 1112 | |
|---|
| 1113 | my @udata = (); |
|---|
| 1114 | my @gdata = (); |
|---|
| 1115 | |
|---|
| 1116 | @gdata = getgrnam($fgid); |
|---|
| 1117 | |
|---|
| 1118 | if (scalar(@gdata) == 0) { # we have not this one group data; |
|---|
| 1119 | my $cmd = "$main::cfg{'CMD_GROUPADD'} $fgid"; |
|---|
| 1120 | $rs = sys_command($cmd); |
|---|
| 1121 | |
|---|
| 1122 | return $rs if ($rs != 0); |
|---|
| 1123 | |
|---|
| 1124 | @gdata = getgrnam($fgid); |
|---|
| 1125 | } |
|---|
| 1126 | |
|---|
| 1127 | $gid = $gdata[2]; |
|---|
| 1128 | |
|---|
| 1129 | @udata = getpwnam($fuid); |
|---|
| 1130 | |
|---|
| 1131 | if (scalar(@udata) == 0) { # we have not this one user data; |
|---|
| 1132 | my $cmd = "$main::cfg{'CMD_USERADD'} -c vmail-user -g $gid -s /bin/false $fuid"; |
|---|
| 1133 | $rs = sys_command($cmd); |
|---|
| 1134 | |
|---|
| 1135 | return $rs if ($rs != 0); |
|---|
| 1136 | |
|---|
| 1137 | @udata = getpwnam($fuid); |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | $uid = $udata[2]; |
|---|
| 1141 | $main::ua{'su_uid'} = $uid; |
|---|
| 1142 | $main::ua{'su_gid'} = $gid; |
|---|
| 1143 | |
|---|
| 1144 | ## FCGI Master user |
|---|
| 1145 | my ($muid, $mgid, $prefix) = ($main::cfg{'APACHE_SUEXEC_MIN_UID'}, $main::cfg{'APACHE_SUEXEC_MIN_GID'}, $main::cfg{'APACHE_SUEXEC_USER_PREF'}); |
|---|
| 1146 | my ($vuuid, $vugid) = (undef, undef); |
|---|
| 1147 | |
|---|
| 1148 | @gdata = getgrnam($prefix.$mgid); |
|---|
| 1149 | @udata = getpwnam($prefix.$muid); |
|---|
| 1150 | |
|---|
| 1151 | if (scalar(@gdata) == 0) { # we do not have this group |
|---|
| 1152 | my $cmd = "$main::cfg{'CMD_GROUPADD'} -g $mgid $prefix$mgid"; |
|---|
| 1153 | $rs = sys_command($cmd); |
|---|
| 1154 | |
|---|
| 1155 | return $rs if ($rs != 0); |
|---|
| 1156 | |
|---|
| 1157 | } |
|---|
| 1158 | |
|---|
| 1159 | if (scalar(@udata) == 0) { # we do not have this user |
|---|
| 1160 | my $cmd = "$main::cfg{'CMD_USERADD'} -d $main::cfg{'PHP_STARTER_DIR'}/master -m -c vu-master -g $prefix$mgid -s /bin/false -u $muid $prefix$muid"; |
|---|
| 1161 | $rs = sys_command($cmd); |
|---|
| 1162 | |
|---|
| 1163 | return $rs if ($rs != 0); |
|---|
| 1164 | |
|---|
| 1165 | } |
|---|
| 1166 | |
|---|
| 1167 | $main::ua{'vu_uid'} = $muid; |
|---|
| 1168 | $main::ua{'vu_gid'} = $mgid; |
|---|
| 1169 | ## |
|---|
| 1170 | |
|---|
| 1171 | push_el(\@main::el, 'setup_system_users()', 'Ending...'); |
|---|
| 1172 | |
|---|
| 1173 | return 0; |
|---|
| 1174 | |
|---|
| 1175 | } |
|---|
| 1176 | |
|---|
| 1177 | sub setup_system_dirs { |
|---|
| 1178 | |
|---|
| 1179 | my ($rs, $rdata) = (undef, undef); |
|---|
| 1180 | |
|---|
| 1181 | push_el(\@main::el, 'setup_system_dirs()', 'Starting...'); |
|---|
| 1182 | |
|---|
| 1183 | $rs = make_dir($main::cfg{'APACHE_WWW_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 1184 | |
|---|
| 1185 | return $rs if ($rs != 0); |
|---|
| 1186 | |
|---|
| 1187 | $rs = make_dir($main::cfg{'APACHE_USERS_LOG_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 1188 | |
|---|
| 1189 | return $rs if ($rs != 0); |
|---|
| 1190 | |
|---|
| 1191 | $rs = make_dir($main::cfg{'APACHE_BACKUP_LOG_DIR'}, 'root', 'root', 0755); |
|---|
| 1192 | |
|---|
| 1193 | return $rs if ($rs != 0); |
|---|
| 1194 | |
|---|
| 1195 | $rs = make_dir($main::cfg{'MTA_VIRTUAL_CONF_DIR'}, 'root', 'root', 0755); |
|---|
| 1196 | |
|---|
| 1197 | return $rs if ($rs != 0); |
|---|
| 1198 | |
|---|
| 1199 | $rs = make_dir($main::cfg{'MTA_VIRTUAL_MAIL_DIR'}, 'root', 'root', 0755); |
|---|
| 1200 | |
|---|
| 1201 | return $rs if ($rs != 0); |
|---|
| 1202 | |
|---|
| 1203 | $rs = make_dir($main::cfg{'LOG_DIR'}, 'root', 'root', 0755); |
|---|
| 1204 | |
|---|
| 1205 | return $rs if ($rs != 0); |
|---|
| 1206 | |
|---|
| 1207 | $rs = make_dir($main::cfg{'BACKUP_FILE_DIR'}, 'root', 'root', 0755); |
|---|
| 1208 | |
|---|
| 1209 | return $rs if ($rs != 0); |
|---|
| 1210 | |
|---|
| 1211 | $rs = make_dir($main::cfg{'PHP_STARTER_DIR'}, "$main::cfg{'APACHE_SUEXEC_USER_PREF'}$main::cfg{'APACHE_SUEXEC_MIN_UID'}", "$main::cfg{'APACHE_SUEXEC_USER_PREF'}$main::cfg{'APACHE_SUEXEC_MIN_GID'}", 0755); |
|---|
| 1212 | |
|---|
| 1213 | return $rs if ($rs != 0); |
|---|
| 1214 | |
|---|
| 1215 | # AWStats dir, use of $main::ua{'awstats_on'}, instead of $main::cfg{'AWSTATS_ACTIVE'}, |
|---|
| 1216 | # because variable not yet set. |
|---|
| 1217 | if ($main::ua{'awstats_on'} eq 'yes') { |
|---|
| 1218 | $rs = make_dir($main::cfg{'AWSTATS_CACHE_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 1219 | |
|---|
| 1220 | return $rs if ($rs != 0); |
|---|
| 1221 | } |
|---|
| 1222 | |
|---|
| 1223 | push_el(\@main::el, 'setup_system_dirs()', 'Ending...'); |
|---|
| 1224 | |
|---|
| 1225 | return 0; |
|---|
| 1226 | |
|---|
| 1227 | } |
|---|
| 1228 | |
|---|
| 1229 | sub setup_config { |
|---|
| 1230 | |
|---|
| 1231 | my ($rs, $rdata) = (undef, undef); |
|---|
| 1232 | |
|---|
| 1233 | push_el(\@main::el, 'setup_config()', 'Starting...'); |
|---|
| 1234 | |
|---|
| 1235 | $rs = set_conf_val('SERVER_HOSTNAME', $main::ua{'hostname'}); |
|---|
| 1236 | |
|---|
| 1237 | return $rs if ($rs != 0); |
|---|
| 1238 | |
|---|
| 1239 | $rs = set_conf_val('BASE_SERVER_IP', $main::ua{'eth_ip'}); |
|---|
| 1240 | |
|---|
| 1241 | return $rs if ($rs != 0); |
|---|
| 1242 | |
|---|
| 1243 | $rs = set_conf_val('BASE_SERVER_VHOST', $main::ua{'admin_vhost'}); |
|---|
| 1244 | |
|---|
| 1245 | return $rs if ($rs != 0); |
|---|
| 1246 | |
|---|
| 1247 | $rs = set_conf_val('DATABASE_HOST', $main::ua{'db_host'}); |
|---|
| 1248 | |
|---|
| 1249 | return $rs if ($rs != 0); |
|---|
| 1250 | |
|---|
| 1251 | $rs = set_conf_val('DATABASE_NAME', $main::ua{'db_name'}); |
|---|
| 1252 | |
|---|
| 1253 | return $rs if ($rs != 0); |
|---|
| 1254 | |
|---|
| 1255 | $rs = set_conf_val('DATABASE_USER', $main::ua{'db_user'}); |
|---|
| 1256 | |
|---|
| 1257 | return $rs if ($rs != 0); |
|---|
| 1258 | |
|---|
| 1259 | if ($main::ua{'db_password'} ne '') { |
|---|
| 1260 | |
|---|
| 1261 | ($rs, $rdata) = encrypt_db_password($main::ua{'db_password'}); |
|---|
| 1262 | |
|---|
| 1263 | return $rs if ($rs != 0); |
|---|
| 1264 | |
|---|
| 1265 | $rs = set_conf_val('DATABASE_PASSWORD', $rdata); |
|---|
| 1266 | |
|---|
| 1267 | return $rs if ($rs != 0); |
|---|
| 1268 | |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | $rs = set_conf_val('MTA_MAILBOX_MIN_UID', $main::ua{'su_uid'}); |
|---|
| 1272 | |
|---|
| 1273 | return $rs if ($rs != 0); |
|---|
| 1274 | |
|---|
| 1275 | $rs = set_conf_val('MTA_MAILBOX_UID', $main::ua{'su_uid'}); |
|---|
| 1276 | |
|---|
| 1277 | return $rs if ($rs != 0); |
|---|
| 1278 | |
|---|
| 1279 | $rs = set_conf_val('MTA_MAILBOX_GID', $main::ua{'su_gid'}); |
|---|
| 1280 | |
|---|
| 1281 | return $rs if ($rs != 0); |
|---|
| 1282 | |
|---|
| 1283 | $rs = set_conf_val('APACHE_SUEXEC_MIN_UID', $main::ua{'vu_uid'}); |
|---|
| 1284 | |
|---|
| 1285 | return $rs if ($rs != 0); |
|---|
| 1286 | |
|---|
| 1287 | $rs = set_conf_val('APACHE_SUEXEC_MIN_GID', $main::ua{'vu_gid'}); |
|---|
| 1288 | |
|---|
| 1289 | return $rs if ($rs != 0); |
|---|
| 1290 | |
|---|
| 1291 | $rs = set_conf_val('DEFAULT_ADMIN_ADDRESS', $main::ua{'admin_email'}); |
|---|
| 1292 | |
|---|
| 1293 | return $rs if ($rs != 0); |
|---|
| 1294 | |
|---|
| 1295 | $rs = set_conf_val('AWSTATS_ACTIVE', $main::ua{'awstats_on'}); |
|---|
| 1296 | |
|---|
| 1297 | return $rs if ($rs != 0); |
|---|
| 1298 | |
|---|
| 1299 | $rs = set_conf_val('AWSTATS_MODE', $main::ua{'awstats_dyn'}); |
|---|
| 1300 | |
|---|
| 1301 | return $rs if ($rs != 0); |
|---|
| 1302 | |
|---|
| 1303 | $rs = set_conf_val('PHP_VERSION', $main::ua{'php_version'}); |
|---|
| 1304 | |
|---|
| 1305 | return $rs if ($rs != 0); |
|---|
| 1306 | |
|---|
| 1307 | $rs = set_conf_val('SECONDARY_DNS', $main::ua{'secondary_dns'}); |
|---|
| 1308 | |
|---|
| 1309 | return $rs if ($rs != 0); |
|---|
| 1310 | |
|---|
| 1311 | $rs = set_conf_val('MYSQL_PREFIX', $main::ua{'mysql_prefix'}); |
|---|
| 1312 | |
|---|
| 1313 | return $rs if ($rs != 0); |
|---|
| 1314 | |
|---|
| 1315 | $rs = set_conf_val('MYSQL_PREFIX_TYPE', $main::ua{'mysql_prefix_type'}); |
|---|
| 1316 | |
|---|
| 1317 | return $rs if ($rs != 0); |
|---|
| 1318 | |
|---|
| 1319 | $rs = store_conf(); |
|---|
| 1320 | |
|---|
| 1321 | return $rs if ($rs != 0); |
|---|
| 1322 | |
|---|
| 1323 | push_el(\@main::el, 'setup_config()', 'Ending...'); |
|---|
| 1324 | |
|---|
| 1325 | return 0; |
|---|
| 1326 | |
|---|
| 1327 | } |
|---|
| 1328 | |
|---|
| 1329 | sub setup_sql { |
|---|
| 1330 | |
|---|
| 1331 | my ($rs, $rdata, $cfg_tpl, $cfg) = (undef, undef, undef, undef); |
|---|
| 1332 | |
|---|
| 1333 | push_el(\@main::el, 'setup_sql()', 'Starting...'); |
|---|
| 1334 | |
|---|
| 1335 | # |
|---|
| 1336 | # check for existing database; |
|---|
| 1337 | # |
|---|
| 1338 | |
|---|
| 1339 | my $sql = "show tables;"; |
|---|
| 1340 | |
|---|
| 1341 | ($rs, $rdata) = doSQL($sql); |
|---|
| 1342 | |
|---|
| 1343 | if ($rs == 0) { # Yes, we have one ! Let's drop it; |
|---|
| 1344 | |
|---|
| 1345 | my $store_db_name = $main::db_name; |
|---|
| 1346 | |
|---|
| 1347 | |
|---|
| 1348 | # Let's reset data; |
|---|
| 1349 | |
|---|
| 1350 | |
|---|
| 1351 | $main::db = undef; |
|---|
| 1352 | |
|---|
| 1353 | $main::db_name = ''; |
|---|
| 1354 | |
|---|
| 1355 | @main::db_connect = ( |
|---|
| 1356 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 1357 | $main::db_user, |
|---|
| 1358 | $main::db_pwd |
|---|
| 1359 | ); |
|---|
| 1360 | |
|---|
| 1361 | $sql = "drop database $store_db_name;"; |
|---|
| 1362 | |
|---|
| 1363 | ($rs, $rdata) = doSQL($sql); |
|---|
| 1364 | |
|---|
| 1365 | return $rs if ($rs != 0); |
|---|
| 1366 | |
|---|
| 1367 | |
|---|
| 1368 | # Let's reset data; |
|---|
| 1369 | $main::db = undef; |
|---|
| 1370 | |
|---|
| 1371 | $main::db_name = $store_db_name; |
|---|
| 1372 | |
|---|
| 1373 | @main::db_connect = ( |
|---|
| 1374 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 1375 | $main::db_user, |
|---|
| 1376 | $main::db_pwd |
|---|
| 1377 | ); |
|---|
| 1378 | |
|---|
| 1379 | } |
|---|
| 1380 | |
|---|
| 1381 | # |
|---|
| 1382 | # Now we'll create our database; |
|---|
| 1383 | # |
|---|
| 1384 | |
|---|
| 1385 | ($rs, $rdata) = get_file("$main::cfg{'CONF_DIR'}/database/database.sql"); |
|---|
| 1386 | |
|---|
| 1387 | return $rs if ($rs != 0); |
|---|
| 1388 | |
|---|
| 1389 | $rdata =~ s/\{DATABASE_NAME\}/$main::db_name/gi; |
|---|
| 1390 | |
|---|
| 1391 | $rs = store_file("/tmp/db.sql", $rdata, 'root', 'root', 0644); |
|---|
| 1392 | |
|---|
| 1393 | return $rs if ($rs != 0); |
|---|
| 1394 | |
|---|
| 1395 | my $cmd = "$main::cfg{'CMD_MYSQL'} --host=$main::db_host --user=$main::db_user --pass=$main::db_pwd < /tmp/db.sql 1>/tmp/db.sql.stdout 2>/tmp/db.sql.stderr"; |
|---|
| 1396 | |
|---|
| 1397 | $rs = sys_command($cmd); |
|---|
|
|---|