| 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 |
require 'ispcp-setup-methods.pl'; |
|---|
| 38 |
|
|---|
| 39 |
use strict; |
|---|
| 40 |
use warnings; |
|---|
| 41 |
use Socket; |
|---|
| 42 |
|
|---|
| 43 |
%main::ua = (); |
|---|
| 44 |
|
|---|
| 45 |
################################################################################ |
|---|
| 46 |
## SUBROUTINES ## |
|---|
| 47 |
################################################################################ |
|---|
| 48 |
|
|---|
| 49 |
sub welcome_note { |
|---|
| 50 |
|
|---|
| 51 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 52 |
|
|---|
| 53 |
push_el(\@main::el, 'welcome_note()', 'Starting...'); |
|---|
| 54 |
|
|---|
| 55 |
my $welcome_message = <<MSG; |
|---|
| 56 |
|
|---|
| 57 |
\tWelcome to ispCP '$main::cfg{'Version'}' Setup Dialog. |
|---|
| 58 |
\tThis program will set up ispCP OMEGA system on your server. |
|---|
| 59 |
MSG |
|---|
| 60 |
|
|---|
| 61 |
print STDOUT $welcome_message; |
|---|
| 62 |
|
|---|
| 63 |
push_el(\@main::el, 'welcome_note()', 'Ending...'); |
|---|
| 64 |
|
|---|
| 65 |
return 0; |
|---|
| 66 |
|
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
sub get_sys_hostname { |
|---|
| 70 |
push_el(\@main::el, 'get_sys_hostname()', 'Starting...'); |
|---|
| 71 |
|
|---|
| 72 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 73 |
my $cmd = "$main::cfg{'CMD_HOSTNAME'} 1>/tmp/ispcp-setup.hostname"; |
|---|
| 74 |
|
|---|
| 75 |
$rs = sys_command($cmd); |
|---|
| 76 |
return ($rs, '') if ($rs != 0); |
|---|
| 77 |
|
|---|
| 78 |
($rs, $rdata) = get_file("/tmp/ispcp-setup.hostname"); |
|---|
| 79 |
return ($rs, '') if ($rs != 0); |
|---|
| 80 |
|
|---|
| 81 |
chomp($rdata); |
|---|
| 82 |
|
|---|
| 83 |
if ($rdata !~ m/\./) { # hostname contains no dot -> use "hostname -f" |
|---|
| 84 |
my $cmd = "$main::cfg{'CMD_HOSTNAME'} -f 1>/tmp/ispcp-setup.hostname"; |
|---|
| 85 |
|
|---|
| 86 |
$rs = sys_command($cmd); |
|---|
| 87 |
return ($rs, '') if ($rs != 0); |
|---|
| 88 |
|
|---|
| 89 |
($rs, $rdata) = get_file("/tmp/ispcp-setup.hostname"); |
|---|
| 90 |
return ($rs, '') if ($rs != 0); |
|---|
| 91 |
|
|---|
| 92 |
chomp($rdata); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
$rs = del_file("/tmp/ispcp-setup.hostname"); |
|---|
| 96 |
return ($rs, '') if ($rs != 0); |
|---|
| 97 |
|
|---|
| 98 |
push_el(\@main::el, 'get_sys_hostname()', 'Ending...'); |
|---|
| 99 |
return (0, $rdata); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
sub user_dialog { |
|---|
| 103 |
|
|---|
| 104 |
my $rs = undef; |
|---|
| 105 |
|
|---|
| 106 |
push_el(\@main::el, 'user_dialog()', 'Starting...'); |
|---|
| 107 |
|
|---|
| 108 |
$rs = welcome_note(); |
|---|
| 109 |
|
|---|
| 110 |
return $rs if ($rs != 0); |
|---|
| 111 |
|
|---|
| 112 |
my $qmsg = "\n\tNext you are asked to enter a \"fully qualified hostname\" (FQHN).\n" . |
|---|
| 113 |
"\tFor more infos read http://en.wikipedia.org/wiki/FQDN.\n\n"; |
|---|
| 114 |
print STDOUT $qmsg; |
|---|
| 115 |
|
|---|
| 116 |
do { |
|---|
| 117 |
$rs = ask_hostname(); |
|---|
| 118 |
} while ($rs == 1); |
|---|
| 119 |
|
|---|
| 120 |
return $rs if ($rs != 0); |
|---|
| 121 |
|
|---|
| 122 |
do { |
|---|
| 123 |
|
|---|
| 124 |
$rs = ask_eth(); |
|---|
| 125 |
|
|---|
| 126 |
} while ($rs == 1); |
|---|
| 127 |
|
|---|
| 128 |
do { |
|---|
| 129 |
$rs = ask_vhost(); |
|---|
| 130 |
} while ($rs == 1); |
|---|
| 131 |
|
|---|
| 132 |
# |
|---|
| 133 |
# SQL Questions |
|---|
| 134 |
# |
|---|
| 135 |
|
|---|
| 136 |
$rs = ask_db_host(); |
|---|
| 137 |
|
|---|
| 138 |
return $rs if ($rs != 0); |
|---|
| 139 |
|
|---|
| 140 |
$rs = ask_db_name(); |
|---|
| 141 |
|
|---|
| 142 |
return $rs if ($rs != 0); |
|---|
| 143 |
|
|---|
| 144 |
$rs = ask_db_user(); |
|---|
| 145 |
|
|---|
| 146 |
return $rs if ($rs != 0); |
|---|
| 147 |
|
|---|
| 148 |
do { |
|---|
| 149 |
|
|---|
| 150 |
$rs = ask_db_password(); |
|---|
| 151 |
|
|---|
| 152 |
} while ($rs == 1); |
|---|
| 153 |
|
|---|
| 154 |
# |
|---|
| 155 |
# ispCP ftp SQL user questions; |
|---|
| 156 |
# |
|---|
| 157 |
|
|---|
| 158 |
do { |
|---|
| 159 |
$rs = ask_db_ftp_user(); |
|---|
| 160 |
} while ($rs == 1); |
|---|
| 161 |
|
|---|
| 162 |
do { |
|---|
| 163 |
$rs = ask_db_ftp_password(); |
|---|
| 164 |
} while ($rs == 1); |
|---|
| 165 |
|
|---|
| 166 |
# |
|---|
| 167 |
# PMA user for SQL |
|---|
| 168 |
# |
|---|
| 169 |
|
|---|
| 170 |
do { |
|---|
| 171 |
$rs = ask_db_pma_user(); |
|---|
| 172 |
} while ($rs == 1); |
|---|
| 173 |
|
|---|
| 174 |
do { |
|---|
| 175 |
$rs = ask_db_pma_password(); |
|---|
| 176 |
} while ($rs == 1); |
|---|
| 177 |
|
|---|
| 178 |
# |
|---|
| 179 |
# Admin questions |
|---|
| 180 |
# |
|---|
| 181 |
|
|---|
| 182 |
$rs = ask_admin(); |
|---|
| 183 |
|
|---|
| 184 |
return $rs if ($rs != 0); |
|---|
| 185 |
|
|---|
| 186 |
do { |
|---|
| 187 |
|
|---|
| 188 |
$rs = ask_admin_password(); |
|---|
| 189 |
|
|---|
| 190 |
} while ($rs == 1); |
|---|
| 191 |
|
|---|
| 192 |
do { |
|---|
| 193 |
|
|---|
| 194 |
$rs = ask_admin_email(); |
|---|
| 195 |
|
|---|
| 196 |
} while ($rs == 1); |
|---|
| 197 |
|
|---|
| 198 |
# |
|---|
| 199 |
# Configuration questions |
|---|
| 200 |
# |
|---|
| 201 |
|
|---|
| 202 |
do { |
|---|
| 203 |
$rs = ask_second_dns(); |
|---|
| 204 |
} while ($rs == 1); |
|---|
| 205 |
|
|---|
| 206 |
do { |
|---|
| 207 |
$rs = ask_mysql_prefix(); |
|---|
| 208 |
} while ($rs == 1); |
|---|
| 209 |
|
|---|
| 210 |
# |
|---|
| 211 |
# FastCGI-Version questions |
|---|
| 212 |
# |
|---|
| 213 |
|
|---|
| 214 |
do { |
|---|
| 215 |
$rs = ask_fastcgi(); |
|---|
| 216 |
} while ($rs == 1); |
|---|
| 217 |
|
|---|
| 218 |
# |
|---|
| 219 |
# AWStats questions |
|---|
| 220 |
# |
|---|
| 221 |
|
|---|
| 222 |
do { |
|---|
| 223 |
|
|---|
| 224 |
$rs = ask_awstats_on(); |
|---|
| 225 |
|
|---|
| 226 |
} while ($rs == 1); |
|---|
| 227 |
|
|---|
| 228 |
if ($main::ua{'awstats_on'} eq 'yes') { |
|---|
| 229 |
do { |
|---|
| 230 |
|
|---|
| 231 |
$rs = ask_awstats_dyn(); |
|---|
| 232 |
|
|---|
| 233 |
} while ($rs == 1); |
|---|
| 234 |
} else { |
|---|
| 235 |
# Just a dummy to prevent warnings |
|---|
| 236 |
$main::ua{'awstats_dyn'} = 0; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
$qmsg = "\n\tStarting Installation...\n"; |
|---|
| 240 |
|
|---|
| 241 |
print STDOUT $qmsg; |
|---|
| 242 |
|
|---|
| 243 |
push_el(\@main::el, 'user_dialog()', "hostname: $main::ua{'hostname'}"); |
|---|
| 244 |
push_el(\@main::el, 'user_dialog()', "eth: $main::ua{'eth_ip'}"); |
|---|
| 245 |
push_el(\@main::el, 'user_dialog()', "panel_vhost: $main::ua{'admin_vhost'}"); |
|---|
| 246 |
push_el(\@main::el, 'user_dialog()', "db_host: $main::ua{'db_host'}"); |
|---|
| 247 |
push_el(\@main::el, 'user_dialog()', "db_name: $main::ua{'db_name'}"); |
|---|
| 248 |
push_el(\@main::el, 'user_dialog()', "db_user: $main::ua{'db_user'}"); |
|---|
| 249 |
push_el(\@main::el, 'user_dialog()', "db_password: $main::ua{'db_password'}"); |
|---|
| 250 |
push_el(\@main::el, 'user_dialog()', "admin: $main::ua{'admin'}"); |
|---|
| 251 |
push_el(\@main::el, 'user_dialog()', "admin_password"); |
|---|
| 252 |
push_el(\@main::el, 'user_dialog()', "admin_email: $main::ua{'admin_email'}"); |
|---|
| 253 |
push_el(\@main::el, 'user_dialog()', "awstats_on: $main::ua{'awstats_on'}"); |
|---|
| 254 |
push_el(\@main::el, 'user_dialog()', "awstats_dyn: $main::ua{'awstats_dyn'}"); |
|---|
| 255 |
push_el(\@main::el, 'user_dialog()', "mysql_prefix: $main::ua{'mysql_prefix'}"); |
|---|
| 256 |
push_el(\@main::el, 'user_dialog()', "mysql_prefix_type: $main::ua{'mysql_prefix_type'}"); |
|---|
| 257 |
push_el(\@main::el, 'user_dialog()', 'Ending...'); |
|---|
| 258 |
|
|---|
| 259 |
return 0; |
|---|
| 260 |
|
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
sub setup_start_up { |
|---|
| 264 |
|
|---|
| 265 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 266 |
|
|---|
| 267 |
push_el(\@main::el, 'setup_start_up()', 'Starting...'); |
|---|
| 268 |
|
|---|
| 269 |
# config check; |
|---|
| 270 |
|
|---|
| 271 |
$rs = get_conf(); |
|---|
| 272 |
|
|---|
| 273 |
return $rs if ($rs != 0); |
|---|
| 274 |
|
|---|
| 275 |
push_el(\@main::el, 'setup_start_up()', 'Ending...'); |
|---|
| 276 |
|
|---|
| 277 |
return 0; |
|---|
| 278 |
|
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
sub setup_shut_down { |
|---|
| 282 |
|
|---|
| 283 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 284 |
|
|---|
| 285 |
my $cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-gui-permissions.sh"; |
|---|
| 286 |
|
|---|
| 287 |
$rs = sys_command($cmd); |
|---|
| 288 |
|
|---|
| 289 |
return $rs if ($rs != 0); |
|---|
| 290 |
|
|---|
| 291 |
$cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-engine-permissions.sh"; |
|---|
| 292 |
|
|---|
| 293 |
$rs = sys_command($cmd); |
|---|
| 294 |
|
|---|
| 295 |
return $rs if ($rs != 0); |
|---|
| 296 |
|
|---|
| 297 |
push_el(\@main::el, 'setup_shut_down()', 'Starting...'); |
|---|
| 298 |
|
|---|
| 299 |
my $shut_down_message = <<MSG; |
|---|
| 300 |
|
|---|
| 301 |
\tCongratulations! |
|---|
| 302 |
|
|---|
| 303 |
\tispCP '$main::cfg{'Version'}' Setup completed successfully! |
|---|
| 304 |
|
|---|
| 305 |
\tPlease type http://$main::ua{'admin_vhost'} in your browser, |
|---|
| 306 |
\tlog in with your Administrator Account and perform Database Updates if exists. |
|---|
| 307 |
|
|---|
| 308 |
MSG |
|---|
| 309 |
print STDOUT $shut_down_message; |
|---|
| 310 |
|
|---|
| 311 |
if (sys_command_rs("which rkhunter > /dev/null") eq 0 ) { |
|---|
| 312 |
print STDOUT "\tSetup is now updating rkhunter:\n"; |
|---|
| 313 |
sys_command("rkhunter --update"); |
|---|
| 314 |
print STDOUT "\n\n"; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
push_el(\@main::el, 'setup_shut_down()', 'Ending...'); |
|---|
| 318 |
|
|---|
| 319 |
return 0; |
|---|
| 320 |
|
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
sub check_host_interface { |
|---|
| 324 |
|
|---|
| 325 |
push_el(\@main::el, 'check_host_interface()', 'Starting...'); |
|---|
| 326 |
|
|---|
| 327 |
my ($rs, $rdata, $cmd) = (undef, undef, undef); |
|---|
| 328 |
|
|---|
| 329 |
$cmd = "$main::cfg{'CMD_IFCONFIG'} $main::ua{'eth'} 1>/tmp/ispcp-setup-iface.stdout 2>/tmp/ispcp-setup-iface.stderr"; |
|---|
| 330 |
|
|---|
| 331 |
$rs = sys_command($cmd); |
|---|
| 332 |
|
|---|
| 333 |
if ($rs != 0) { |
|---|
| 334 |
|
|---|
| 335 |
push_el(\@main::el, 'check_host_interface()', "ERROR: Can't find $main::ua{'eth'} device!"); |
|---|
| 336 |
|
|---|
| 337 |
return $rs; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
$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"; |
|---|
| 341 |
|
|---|
| 342 |
$rs = sys_command($cmd); |
|---|
| 343 |
|
|---|
| 344 |
($rs, $rdata) = get_file("/tmp/ispcp-setup-iface-data.stdout"); |
|---|
| 345 |
|
|---|
| 346 |
return $rs if ($rs != 0); |
|---|
| 347 |
|
|---|
| 348 |
$rdata =~ /([^\n]+)\n([^\n]+)\n/; |
|---|
| 349 |
|
|---|
| 350 |
$main::ua{'eth_hwaddr'} = $1; |
|---|
| 351 |
|
|---|
| 352 |
$main::ua{'eth_ip'} = $2; |
|---|
| 353 |
|
|---|
| 354 |
$rs = del_file("/tmp/ispcp-setup-iface.stdout"); |
|---|
| 355 |
|
|---|
| 356 |
return $rs if ($rs != 0); |
|---|
| 357 |
|
|---|
| 358 |
$rs = del_file("/tmp/ispcp-setup-iface.stderr"); |
|---|
| 359 |
|
|---|
| 360 |
return $rs if ($rs != 0); |
|---|
| 361 |
|
|---|
| 362 |
$rs = del_file("/tmp/ispcp-setup-iface-data.stdout"); |
|---|
| 363 |
|
|---|
| 364 |
return $rs if ($rs != 0); |
|---|
| 365 |
|
|---|
| 366 |
$rs = del_file("/tmp/ispcp-setup-iface-data.stderr"); |
|---|
| 367 |
|
|---|
| 368 |
return $rs if ($rs != 0); |
|---|
| 369 |
|
|---|
| 370 |
push_el(\@main::el, 'check_host_interface()', 'Ending...'); |
|---|
| 371 |
|
|---|
| 372 |
return 0; |
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
sub check_host_sql { |
|---|
| 376 |
|
|---|
| 377 |
push_el(\@main::el, 'check_host_sql()', 'Starting...'); |
|---|
| 378 |
|
|---|
| 379 |
my ($rs, $rdata, $sql) = (undef, undef, undef); |
|---|
| 380 |
|
|---|
| 381 |
$sql = "show databases;"; |
|---|
| 382 |
|
|---|
| 383 |
$main::db_host = $main::ua{'db_host'}; |
|---|
| 384 |
|
|---|
| 385 |
$main::db_user = $main::ua{'db_user'}; |
|---|
| 386 |
|
|---|
| 387 |
$main::db_pwd = $main::ua{'db_password'}; |
|---|
| 388 |
|
|---|
| 389 |
$main::db_name = ""; |
|---|
| 390 |
|
|---|
| 391 |
@main::db_connect = ( |
|---|
| 392 |
"DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 393 |
$main::db_user, |
|---|
| 394 |
$main::db_pwd |
|---|
| 395 |
); |
|---|
| 396 |
|
|---|
| 397 |
($rs, $rdata) = doSQL($sql); |
|---|
| 398 |
|
|---|
| 399 |
return $rs if ($rs != 0); |
|---|
| 400 |
|
|---|
| 401 |
$main::db = undef; |
|---|
| 402 |
|
|---|
| 403 |
push_el(\@main::el, 'check_host_sql()', 'Ending...'); |
|---|
| 404 |
|
|---|
| 405 |
return 0; |
|---|
| 406 |
} |
|---|
| 407 |
|
|---|
| 408 |
sub check_host_system { |
|---|
| 409 |
|
|---|
| 410 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 411 |
|
|---|
| 412 |
push_el(\@main::el, 'check_host_system()', 'Starting...'); |
|---|
| 413 |
|
|---|
| 414 |
#$rs = check_host_interface(); |
|---|
| 415 |
|
|---|
| 416 |
#return $rs if ($rs != 0); |
|---|
| 417 |
|
|---|
| 418 |
$rs = check_host_sql(); |
|---|
| 419 |
|
|---|
| 420 |
return $rs if ($rs != 0); |
|---|
| 421 |
|
|---|
| 422 |
push_el(\@main::el, 'check_host_system()', 'Ending...'); |
|---|
| 423 |
|
|---|
| 424 |
return 0; |
|---|
| 425 |
|
|---|
| 426 |
} |
|---|
| 427 |
|
|---|
| 428 |
sub setup_system_users { |
|---|
| 429 |
|
|---|
| 430 |
my ($rs, $rdata, $cmd) = (undef, undef, undef); |
|---|
| 431 |
|
|---|
| 432 |
push_el(\@main::el, 'setup_system_users()', 'Starting...'); |
|---|
| 433 |
|
|---|
| 434 |
## Mailbox user |
|---|
| 435 |
my ($fuid, $fgid) = ($main::cfg{'MTA_MAILBOX_UID_NAME'}, $main::cfg{'MTA_MAILBOX_GID_NAME'}); |
|---|
| 436 |
my ($uid, $gid) = (undef, undef); |
|---|
| 437 |
|
|---|
| 438 |
my @udata = (); |
|---|
| 439 |
my @gdata = (); |
|---|
| 440 |
|
|---|
| 441 |
@gdata = getgrnam($fgid); |
|---|
| 442 |
|
|---|
| 443 |
if (scalar(@gdata) == 0) { # we have not this one group data; |
|---|
| 444 |
$cmd = "$main::cfg{'CMD_GROUPADD'} $fgid"; |
|---|
| 445 |
$rs = sys_command($cmd); |
|---|
| 446 |
|
|---|
| 447 |
return $rs if ($rs != 0); |
|---|
| 448 |
|
|---|
| 449 |
@gdata = getgrnam($fgid); |
|---|
| 450 |
} |
|---|
| 451 |
|
|---|
| 452 |
$gid = $gdata[2]; |
|---|
| 453 |
|
|---|
| 454 |
@udata = getpwnam($fuid); |
|---|
| 455 |
|
|---|
| 456 |
if (scalar(@udata) == 0) { # we have not this one user data; |
|---|
| 457 |
if ($main::cfg{'ROOT_GROUP'} eq "wheel") { |
|---|
| 458 |
$cmd = "$main::cfg{'CMD_USERADD'} $fuid -c vmail-user -s /bin/false"; |
|---|
| 459 |
} else { |
|---|
| 460 |
$cmd = "$main::cfg{'CMD_USERADD'} -c vmail-user -g $gid -s /bin/false $fuid"; |
|---|
| 461 |
} |
|---|
| 462 |
$rs = sys_command($cmd); |
|---|
| 463 |
|
|---|
| 464 |
return $rs if ($rs != 0); |
|---|
| 465 |
|
|---|
| 466 |
@udata = getpwnam($fuid); |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
$uid = $udata[2]; |
|---|
| 470 |
$main::ua{'su_uid'} = $uid; |
|---|
| 471 |
$main::ua{'su_gid'} = $gid; |
|---|
| 472 |
|
|---|
| 473 |
## FCGI Master user |
|---|
| 474 |
my ($muid, $mgid, $prefix) = ($main::cfg{'APACHE_SUEXEC_MIN_UID'}, $main::cfg{'APACHE_SUEXEC_MIN_GID'}, $main::cfg{'APACHE_SUEXEC_USER_PREF'}); |
|---|
| 475 |
my ($vuuid, $vugid) = (undef, undef); |
|---|
| 476 |
|
|---|
| 477 |
@gdata = getgrnam($prefix.$mgid); |
|---|
| 478 |
@udata = getpwnam($prefix.$muid); |
|---|
| 479 |
|
|---|
| 480 |
if (scalar(@gdata) == 0) { # we do not have this group |
|---|
| 481 |
if ($main::cfg{'ROOT_GROUP'} eq "wheel") { |
|---|
| 482 |
$cmd = "$main::cfg{'CMD_GROUPADD'} $prefix$mgid -g $mgid"; |
|---|
| 483 |
} else { |
|---|
| 484 |
$cmd = "$main::cfg{'CMD_GROUPADD'} -g $mgid $prefix$mgid"; |
|---|
| 485 |
} |
|---|
| 486 |
$rs = sys_command($cmd); |
|---|
| 487 |
|
|---|
| 488 |
return $rs if ($rs != 0); |
|---|
| 489 |
|
|---|
| 490 |
} |
|---|
| 491 |
|
|---|
| 492 |
# create user and folder |
|---|
| 493 |
if (scalar(@udata) == 0) { # we do not have this user |
|---|
| 494 |
if ($main::cfg{'ROOT_GROUP'} eq "wheel") { |
|---|
| 495 |
$cmd = "$main::cfg{'CMD_USERADD'} $prefix$muid $prefix$muid -d $main::cfg{'PHP_STARTER_DIR'}/master -m -c vu-master -g $prefix$mgid -s /bin/false -u $muid $prefix$muid"; |
|---|
| 496 |
} else { |
|---|
| 497 |
$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"; |
|---|
| 498 |
} |
|---|
| 499 |
$rs = sys_command($cmd); |
|---|
| 500 |
|
|---|
| 501 |
return $rs if ($rs != 0); |
|---|
| 502 |
} else { |
|---|
| 503 |
# change folder permissions and owner |
|---|
| 504 |
$rs = setfmode("$main::cfg{'PHP_STARTER_DIR'}/master", "$prefix$muid", "$prefix$mgid", 0755); |
|---|
| 505 |
return $rs if ($rs != 0); |
|---|
| 506 |
} |
|---|
| 507 |
|
|---|
| 508 |
$main::ua{'vu_uid'} = $muid; |
|---|
| 509 |
$main::ua{'vu_gid'} = $mgid; |
|---|
| 510 |
## |
|---|
| 511 |
|
|---|
| 512 |
push_el(\@main::el, 'setup_system_users()', 'Ending...'); |
|---|
| 513 |
|
|---|
| 514 |
return 0; |
|---|
| 515 |
|
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
sub setup_system_dirs { |
|---|
| 519 |
|
|---|
| 520 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 521 |
|
|---|
| 522 |
push_el(\@main::el, 'setup_system_dirs()', 'Starting...'); |
|---|
| 523 |
|
|---|
| 524 |
$rs = make_dir($main::cfg{'APACHE_WWW_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 525 |
return $rs if ($rs != 0); |
|---|
| 526 |
|
|---|
| 527 |
$rs = make_dir($main::cfg{'APACHE_USERS_LOG_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 528 |
return $rs if ($rs != 0); |
|---|
| 529 |
|
|---|
| 530 |
$rs = make_dir($main::cfg{'APACHE_BACKUP_LOG_DIR'}, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 531 |
return $rs if ($rs != 0); |
|---|
| 532 |
|
|---|
| 533 |
$rs = make_dir($main::cfg{'MTA_VIRTUAL_CONF_DIR'}, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 534 |
return $rs if ($rs != 0); |
|---|
| 535 |
|
|---|
| 536 |
$rs = make_dir($main::cfg{'MTA_VIRTUAL_MAIL_DIR'}, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 537 |
return $rs if ($rs != 0); |
|---|
| 538 |
|
|---|
| 539 |
$rs = make_dir($main::cfg{'LOG_DIR'}, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 540 |
return $rs if ($rs != 0); |
|---|
| 541 |
|
|---|
| 542 |
$rs = make_dir($main::cfg{'BACKUP_FILE_DIR'}, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0755); |
|---|
| 543 |
return $rs if ($rs != 0); |
|---|
| 544 |
|
|---|
| 545 |
$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); |
|---|
| 546 |
return $rs if ($rs != 0); |
|---|
| 547 |
|
|---|
| 548 |
# AWStats dir, use of $main::ua{'awstats_on'}, instead of $main::cfg{'AWSTATS_ACTIVE'}, |
|---|
| 549 |
# because variable not yet set. |
|---|
| 550 |
if ($main::ua{'awstats_on'} eq 'yes') { |
|---|
| 551 |
$rs = make_dir($main::cfg{'AWSTATS_CACHE_DIR'}, $main::cfg{'APACHE_USER'}, $main::cfg{'APACHE_GROUP'}, 0755); |
|---|
| 552 |
|
|---|
| 553 |
return $rs if ($rs != 0); |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
push_el(\@main::el, 'setup_system_dirs()', 'Ending...'); |
|---|
| 557 |
|
|---|
| 558 |
return 0; |
|---|
| 559 |
|
|---|
| 560 |
} |
|---|
| 561 |
|
|---|
| 562 |
sub setup_config { |
|---|
| 563 |
|
|---|
| 564 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 565 |
|
|---|
| 566 |
push_el(\@main::el, 'setup_config()', 'Starting...'); |
|---|
| 567 |
|
|---|
| 568 |
$rs = set_conf_val('SERVER_HOSTNAME', $main::ua{'hostname'}); |
|---|
| 569 |
return $rs if ($rs != 0); |
|---|
| 570 |
|
|---|
| 571 |
$rs = set_conf_val('BASE_SERVER_IP', $main::ua{'eth_ip'}); |
|---|
| 572 |
return $rs if ($rs != 0); |
|---|
| 573 |
|
|---|
| 574 |
$rs = set_conf_val('BASE_SERVER_VHOST', $main::ua{'admin_vhost'}); |
|---|
| 575 |
return $rs if ($rs != 0); |
|---|
| 576 |
|
|---|
| 577 |
$rs = set_conf_val('DATABASE_HOST', $main::ua{'db_host'}); |
|---|
| 578 |
return $rs if ($rs != 0); |
|---|
| 579 |
|
|---|
| 580 |
$rs = set_conf_val('DATABASE_NAME', $main::ua{'db_name'}); |
|---|
| 581 |
return $rs if ($rs != 0); |
|---|
| 582 |
|
|---|
| 583 |
$rs = set_conf_val('DATABASE_USER', $main::ua{'db_user'}); |
|---|
| 584 |
return $rs if ($rs != 0); |
|---|
| 585 |
|
|---|
| 586 |
if ($main::ua{'db_password'} ne '') { |
|---|
| 587 |
($rs, $rdata) = encrypt_db_password($main::ua{'db_password'}); |
|---|
| 588 |
return $rs if ($rs != 0); |
|---|
| 589 |
|
|---|
| 590 |
$rs = set_conf_val('DATABASE_PASSWORD', $rdata); |
|---|
| 591 |
return $rs if ($rs != 0); |
|---|
| 592 |
} |
|---|
| 593 |
|
|---|
| 594 |
$rs = set_conf_val('MTA_MAILBOX_MIN_UID', $main::ua{'su_uid'}); |
|---|
| 595 |
return $rs if ($rs != 0); |
|---|
| 596 |
|
|---|
| 597 |
$rs = set_conf_val('MTA_MAILBOX_UID', $main::ua{'su_uid'}); |
|---|
| 598 |
return $rs if ($rs != 0); |
|---|
| 599 |
|
|---|
| 600 |
$rs = set_conf_val('MTA_MAILBOX_GID', $main::ua{'su_gid'}); |
|---|
| 601 |
return $rs if ($rs != 0); |
|---|
| 602 |
|
|---|
| 603 |
$rs = set_conf_val('APACHE_SUEXEC_MIN_UID', $main::ua{'vu_uid'}); |
|---|
| 604 |
return $rs if ($rs != 0); |
|---|
| 605 |
|
|---|
| 606 |
$rs = set_conf_val('APACHE_SUEXEC_MIN_GID', $main::ua{'vu_gid'}); |
|---|
| 607 |
return $rs if ($rs != 0); |
|---|
| 608 |
|
|---|
| 609 |
$rs = set_conf_val('DEFAULT_ADMIN_ADDRESS', $main::ua{'admin_email'}); |
|---|
| 610 |
return $rs if ($rs != 0); |
|---|
| 611 |
|
|---|
| 612 |
$rs = set_conf_val('AWSTATS_ACTIVE', $main::ua{'awstats_on'}); |
|---|
| 613 |
return $rs if ($rs != 0); |
|---|
| 614 |
|
|---|
| 615 |
$rs = set_conf_val('AWSTATS_MODE', $main::ua{'awstats_dyn'}); |
|---|
| 616 |
return $rs if ($rs != 0); |
|---|
| 617 |
|
|---|
| 618 |
$rs = set_conf_val('PHP_FASTCGI', $main::ua{'php_fastcgi'}); |
|---|
| 619 |
return $rs if ($rs != 0); |
|---|
| 620 |
|
|---|
| 621 |
$rs = set_conf_val('SECONDARY_DNS', $main::ua{'secondary_dns'}); |
|---|
| 622 |
return $rs if ($rs != 0); |
|---|
| 623 |
|
|---|
| 624 |
$rs = set_conf_val('MYSQL_PREFIX', $main::ua{'mysql_prefix'}); |
|---|
| 625 |
return $rs if ($rs != 0); |
|---|
| 626 |
|
|---|
| 627 |
$rs = set_conf_val('MYSQL_PREFIX_TYPE', $main::ua{'mysql_prefix_type'}); |
|---|
| 628 |
return $rs if ($rs != 0); |
|---|
| 629 |
|
|---|
| 630 |
$rs = store_conf(); |
|---|
| 631 |
return $rs if ($rs != 0); |
|---|
| 632 |
|
|---|
| 633 |
push_el(\@main::el, 'setup_config()', 'Ending...'); |
|---|
| 634 |
|
|---|
| 635 |
return 0; |
|---|
| 636 |
|
|---|
| 637 |
} |
|---|
| 638 |
|
|---|
| 639 |
sub setup_sql { |
|---|
| 640 |
|
|---|
| 641 |
my ($rs, $rdata, $cfg_tpl, $cfg) = (undef, undef, undef, undef); |
|---|
| 642 |
|
|---|
| 643 |
push_el(\@main::el, 'setup_sql()', 'Starting...'); |
|---|
| 644 |
|
|---|
| 645 |
# |
|---|
| 646 |
# check for existing database; |
|---|
| 647 |
# |
|---|
| 648 |
|
|---|
| 649 |
my $sql = "SHOW TABLES;"; |
|---|
| 650 |
|
|---|
| 651 |
($rs, $rdata) = doSQL($sql); |
|---|
| 652 |
|
|---|
| 653 |
if ($rs == 0) { # Yes, we have one ! Let's drop it; |
|---|
| 654 |
|
|---|
| 655 |
my $store_db_name = $main::db_name; |
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
# Let's reset data; |
|---|
| 659 |
$main::db = undef; |
|---|
| 660 |
$main::db_name = ''; |
|---|
| 661 |
|
|---|
| 662 |
@main::db_connect = ( |
|---|
| 663 |
"DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 664 |
$main::db_user, |
|---|
| 665 |
$main::db_pwd |
|---|
| 666 |
); |
|---|
| 667 |
|
|---|
| 668 |
$sql = "DROP DATABASE IF EXISTS $store_db_name;"; |
|---|
| 669 |
|
|---|
| 670 |
($rs, $rdata) = doSQL($sql); |
|---|
| 671 |
|
|---|
| 672 |
return $rs if ($rs != 0); |
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
# Let's reset data; |
|---|
| 676 |
$main::db = undef; |
|---|
| 677 |
|
|---|
| 678 |
$main::db_name = $store_db_name; |
|---|
| 679 |
|
|---|
| 680 |
@main::db_connect = ( |
|---|
| 681 |
"DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 682 |
$main::db_user, |
|---|
| 683 |
$main::db_pwd |
|---|
| 684 |
); |
|---|
| 685 |
|
|---|
| 686 |
} |
|---|
| 687 |
|
|---|
| 688 |
# |
|---|
| 689 |
# Now we'll create our database; |
|---|
| 690 |
# |
|---|
| 691 |
|
|---|
| 692 |
($rs, $rdata) = get_file("$main::cfg{'CONF_DIR'}/database/database.sql"); |
|---|
| 693 |
|
|---|
| 694 |
return $rs if ($rs != 0); |
|---|
| 695 |
|
|---|
| 696 |
$rdata =~ s/\{DATABASE_NAME\}/$main::db_name/gi; |
|---|
| 697 |
|
|---|
| 698 |
$rs = store_file("/tmp/db.sql", $rdata, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 699 |
|
|---|
| 700 |
return $rs if ($rs != 0); |
|---|
| 701 |
|
|---|
| 702 |
# Escape " and ' |
|---|
| 703 |
$main::db_pwd =~ s/([\'\"])/\\$1/g; |
|---|
| 704 |
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"; |
|---|
| 705 |
|
|---|
| 706 |
$rs = sys_command($cmd); |
|---|
| 707 |
return $rs if ($rs != 0); |
|---|
| 708 |
|
|---|
| 709 |
# |
|---|
| 710 |
# English language table; |
|---|
| 711 |
# |
|---|
| 712 |
|
|---|
| 713 |
my $languages_sql = "$main::cfg{'CONF_DIR'}/database/languages.sql"; |
|---|
| 714 |
|
|---|
| 715 |
$cmd = "$main::cfg{'CMD_MYSQL'} --host=\"$main::db_host\" --user=\"$main::db_user\" --pass=\"$main::db_pwd\" $main::db_name < $languages_sql 1>/tmp/db.sql.stdout 2>/tmp/db.sql.stderr"; |
|---|
| 716 |
|
|---|
| 717 |
$rs = sys_command($cmd); |
|---|
| 718 |
return $rs if ($rs != 0); |
|---|
| 719 |
|
|---|
| 720 |
|
|---|
| 721 |
$rs = del_file("/tmp/db.sql"); |
|---|
| 722 |
return $rs if ($rs != 0); |
|---|
| 723 |
|
|---|
| 724 |
$rs = del_file("/tmp/db.sql.stdout"); |
|---|
| 725 |
return $rs if ($rs != 0); |
|---|
| 726 |
|
|---|
| 727 |
$rs = del_file("/tmp/db.sql.stderr"); |
|---|
| 728 |
return $rs if ($rs != 0); |
|---|
| 729 |
|
|---|
| 730 |
# |
|---|
| 731 |
# Let's populate our base with some data; |
|---|
| 732 |
# |
|---|
| 733 |
|
|---|
| 734 |
my $admin_password = crypt_md5_data($main::ua{'admin_password'}); |
|---|
| 735 |
|
|---|
| 736 |
$sql = "INSERT INTO admin (admin_id, admin_name, admin_pass, admin_type, email) VALUES (1, '$main::ua{'admin'}','$admin_password', 'admin','$main::ua{'admin_email'}')"; |
|---|
| 737 |
|
|---|
| 738 |
($rs, $rdata) = doSQL($sql); |
|---|
| 739 |
|
|---|
| 740 |
return $rs if ($rs != 0); |
|---|
| 741 |
|
|---|
| 742 |
$sql = "INSERT INTO user_gui_props (user_id) values (1)"; |
|---|
| 743 |
|
|---|
| 744 |
($rs, $rdata) = doSQL($sql); |
|---|
| 745 |
|
|---|
| 746 |
return $rs if ($rs != 0); |
|---|
| 747 |
|
|---|
| 748 |
$sql = "INSERT INTO server_ips VALUES (1, '$main::ua{'eth_ip'}', '$main::ua{'hostname'}', '$main::ua{'hostname'}');"; |
|---|
| 749 |
|
|---|
| 750 |
($rs, $rdata) = doSQL($sql); |
|---|
| 751 |
|
|---|
| 752 |
return $rs if ($rs != 0); |
|---|
| 753 |
|
|---|
| 754 |
# |
|---|
| 755 |
# we'll add ispCP ftp SQL user here. |
|---|
| 756 |
# |
|---|
| 757 |
$main::db = undef; |
|---|
| 758 |
|
|---|
| 759 |
@main::db_connect = ( |
|---|
| 760 |
"DBI:mysql:mysql:$main::db_host", |
|---|
| 761 |
$main::db_user, |
|---|
| 762 |
$main::db_pwd |
|---|
| 763 |
); |
|---|
| 764 |
|
|---|
| 765 |
my $vftp_sql_user = $main::ua{'db_ftp_user'}; |
|---|
| 766 |
my $vftp_sql_password = $main::ua{'db_ftp_password'}; |
|---|
| 767 |
my $hostname = $main::ua{'db_host'}; |
|---|
| 768 |
|
|---|
| 769 |
$sql = "DELETE FROM tables_priv WHERE Host = '$main::cfg{'SERVER_HOSTNAME'}' AND Db = '$main::db_name' AND User = '$vftp_sql_user'"; |
|---|
| 770 |
|
|---|
| 771 |
($rs, $rdata) = doSQL($sql); |
|---|
| 772 |
return $rs if ($rs != 0); |
|---|
| 773 |
|
|---|
| 774 |
$sql = "DELETE FROM user WHERE Host = '$hostname' AND User = '$vftp_sql_user'"; |
|---|
| 775 |
|
|---|
| 776 |
($rs, $rdata) = doSQL($sql); |
|---|
| 777 |
return $rs if ($rs != 0); |
|---|
| 778 |
|
|---|
| 779 |
$sql = "FLUSH PRIVILEGES"; |
|---|
| 780 |
|
|---|
| 781 |
($rs, $rdata) = doSQL($sql); |
|---|
| 782 |
return $rs if ($rs != 0); |
|---|
| 783 |
|
|---|
| 784 |
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE ON $main::db_name.ftp_group TO '$vftp_sql_user'\@'$hostname' IDENTIFIED BY '$vftp_sql_password'"; |
|---|
| 785 |
|
|---|
| 786 |
($rs, $rdata) = doSQL($sql); |
|---|
| 787 |
return $rs if ($rs != 0); |
|---|
| 788 |
|
|---|
| 789 |
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE ON $main::db_name.ftp_users TO '$vftp_sql_user'\@'$hostname' IDENTIFIED BY '$vftp_sql_password'"; |
|---|
| 790 |
|
|---|
| 791 |
($rs, $rdata) = doSQL($sql); |
|---|
| 792 |
return $rs if ($rs != 0); |
|---|
| 793 |
|
|---|
| 794 |
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE ON $main::db_name.quotalimits TO '$vftp_sql_user'\@'$hostname' IDENTIFIED BY '$vftp_sql_password'"; |
|---|
| 795 |
|
|---|
| 796 |
($rs, $rdata) = doSQL($sql); |
|---|
| 797 |
return $rs if ($rs != 0); |
|---|
| 798 |
|
|---|
| 799 |
$sql = "GRANT SELECT,INSERT,UPDATE,DELETE ON $main::db_name.quotatallies TO '$vftp_sql_user'\@'$hostname' IDENTIFIED BY '$vftp_sql_password'"; |
|---|
| 800 |
|
|---|
| 801 |
($rs, $rdata) = doSQL($sql); |
|---|
| 802 |
return $rs if ($rs != 0); |
|---|
| 803 |
|
|---|
| 804 |
# |
|---|
| 805 |
# Create the PMA user |
|---|
| 806 |
# |
|---|
| 807 |
$main::db = undef; |
|---|
| 808 |
|
|---|
| 809 |
@main::db_connect = ( |
|---|
| 810 |
"DBI:mysql:mysql:$main::db_host", |
|---|
| 811 |
$main::db_user, |
|---|
| 812 |
$main::db_pwd |
|---|
| 813 |
); |
|---|
| 814 |
|
|---|
| 815 |
my $pma_sql_user = $main::ua{'db_pma_user'}; |
|---|
| 816 |
my $pma_sql_password = $main::ua{'db_pma_password'}; |
|---|
| 817 |
|
|---|
| 818 |
$sql = "DELETE FROM tables_priv WHERE Host = '$main::cfg{'SERVER_HOSTNAME'}' AND Db = '$main::db_name' AND User = '$pma_sql_user'"; |
|---|
| 819 |
|
|---|
| 820 |
($rs, $rdata) = doSQL($sql); |
|---|
| 821 |
return $rs if ($rs != 0); |
|---|
| 822 |
|
|---|
| 823 |
$sql = "DELETE FROM user WHERE Host = '$hostname' AND User = '$pma_sql_user'"; |
|---|
| 824 |
|
|---|
| 825 |
($rs, $rdata) = doSQL($sql); |
|---|
| 826 |
return $rs if ($rs != 0); |
|---|
| 827 |
|
|---|
| 828 |
$sql = "FLUSH PRIVILEGES"; |
|---|
| 829 |
|
|---|
| 830 |
($rs, $rdata) = doSQL($sql); |
|---|
| 831 |
return $rs if ($rs != 0); |
|---|
| 832 |
|
|---|
| 833 |
$sql = "GRANT USAGE ON mysql.* TO \'$pma_sql_user\'\@\'$hostname\' IDENTIFIED BY \'$pma_sql_password\';"; |
|---|
| 834 |
|
|---|
| 835 |
($rs, $rdata) = doSQL($sql); |
|---|
| 836 |
return $rs if ($rs != 0); |
|---|
| 837 |
|
|---|
| 838 |
$sql = "GRANT SELECT (Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv) ON mysql.user TO \'$pma_sql_user\'\@\'$hostname\';"; |
|---|
| 839 |
|
|---|
| 840 |
($rs, $rdata) = doSQL($sql); |
|---|
| 841 |
return $rs if ($rs != 0); |
|---|
| 842 |
|
|---|
| 843 |
$sql = "GRANT SELECT ON mysql.db TO \'$pma_sql_user\'\@\'$hostname\';"; |
|---|
| 844 |
|
|---|
| 845 |
($rs, $rdata) = doSQL($sql); |
|---|
| 846 |
return $rs if ($rs != 0); |
|---|
| 847 |
|
|---|
| 848 |
$sql = "GRANT SELECT ON mysql.host TO \'$pma_sql_user\'\@\'$hostname\';"; |
|---|
| 849 |
|
|---|
| 850 |
($rs, $rdata) = doSQL($sql); |
|---|
| 851 |
return $rs if ($rs != 0); |
|---|
| 852 |
|
|---|
| 853 |
$sql = "GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO \'$pma_sql_user\'\@\'$hostname\';"; |
|---|
| 854 |
|
|---|
| 855 |
($rs, $rdata) = doSQL($sql); |
|---|
| 856 |
return $rs if ($rs != 0); |
|---|
| 857 |
|
|---|
| 858 |
# |
|---|
| 859 |
# Insert pma user and password to config file |
|---|
| 860 |
# together with some other information |
|---|
| 861 |
# |
|---|
| 862 |
|
|---|
| 863 |
my $cfg_dir = "$main::cfg{'GUI_ROOT_DIR'}/tools/pma/"; |
|---|
| 864 |
my $tmp_dir = "$main::cfg{'GUI_ROOT_DIR'}/phptmp"; |
|---|
| 865 |
|
|---|
| 866 |
my $blowfish = gen_sys_rand_num(31); |
|---|
| 867 |
$blowfish =~ s/'/\\'/gi; |
|---|
| 868 |
|
|---|
| 869 |
($rs, $cfg_tpl) = get_tpl($cfg_dir, 'config.inc.php'); |
|---|
| 870 |
|
|---|
| 871 |
return $rs if ($rs != 0); |
|---|
| 872 |
|
|---|
| 873 |
my %tag_hash = ( |
|---|
| 874 |
'{PMA_USER}' => $pma_sql_user, |
|---|
| 875 |
'{PMA_PASS}' => $pma_sql_password, |
|---|
| 876 |
'{HOSTNAME}' => $hostname, |
|---|
| 877 |
'{TMP_DIR}' => $tmp_dir, |
|---|
| 878 |
'{BLOWFISH}' => $blowfish |
|---|
| 879 |
); |
|---|
| 880 |
|
|---|
| 881 |
($rs, $cfg) = prep_tpl(\%tag_hash, $cfg_tpl); |
|---|
| 882 |
|
|---|
| 883 |
return $rs if ($rs != 0); |
|---|
| 884 |
|
|---|
| 885 |
$rs = store_file("$cfg_dir/config.inc.php", $cfg, "$main::cfg{'APACHE_SUEXEC_USER_PREF'}$main::cfg{'APACHE_SUEXEC_MIN_UID'}", "$main::cfg{'APACHE_GROUP'}", 0440); |
|---|
| 886 |
|
|---|
| 887 |
return $rs if ($rs != 0); |
|---|
| 888 |
|
|---|
| 889 |
push_el(\@main::el, 'setup_sql()', 'Ending...'); |
|---|
| 890 |
|
|---|
| 891 |
return 0; |
|---|
| 892 |
|
|---|
| 893 |
} |
|---|
| 894 |
|
|---|
| 895 |
sub setup_hosts { |
|---|
| 896 |
|
|---|
| 897 |
my ($rs, $data, $cmd) = (undef, undef, undef); |
|---|
| 898 |
|
|---|
| 899 |
push_el(\@main::el, 'setup_hosts()', 'Starting...'); |
|---|
| 900 |
|
|---|
| 901 |
my $hostname = $main::ua{'hostname'}; |
|---|
| 902 |
my $host = $main::ua{'hostname_local'}; |
|---|
| 903 |
|
|---|
| 904 |
my $hostname_local = "$hostname.local"; |
|---|
| 905 |
|
|---|
| 906 |
my $ip = $main::ua{'eth_ip'}; |
|---|
| 907 |
|
|---|
| 908 |
my $hosts_file = "/etc/hosts"; |
|---|
| 909 |
|
|---|
| 910 |
$cmd = "$main::cfg{'CMD_CP'} -p -f $hosts_file $hosts_file.bkp"; |
|---|
| 911 |
|
|---|
| 912 |
$rs = sys_command_rs($cmd); |
|---|
| 913 |
|
|---|
| 914 |
return $rs if ($rs != 0); |
|---|
| 915 |
|
|---|
| 916 |
$data = "# 'hosts' file configuration.\n\n"; |
|---|
| 917 |
$data .= "127.0.0.1\t$hostname_local\tlocalhost\n"; |
|---|
| 918 |
$data .= "$ip\t$hostname\t$host\n"; |
|---|
| 919 |
$data .= "::ffff:$ip\t$hostname\t$host\n"; |
|---|
| 920 |
$data .= "::1\tip6-localhost ip6-loopback\n"; |
|---|
| 921 |
$data .= "fe00::0\tip6-localnet\n"; |
|---|
| 922 |
$data .= "ff00::0\tip6-mcastprefix\n"; |
|---|
| 923 |
$data .= "ff02::1\tip6-allnodes\n"; |
|---|
| 924 |
$data .= "ff02::2\tip6-allrouters\n"; |
|---|
| 925 |
$data .= "ff02::3\tip6-allhosts\n"; |
|---|
| 926 |
|
|---|
| 927 |
$rs = store_file($hosts_file, $data, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 928 |
return $rs if ($rs != 0); |
|---|
| 929 |
|
|---|
| 930 |
push_el(\@main::el, 'setup_hosts()', 'Ending...'); |
|---|
| 931 |
|
|---|
| 932 |
return 0; |
|---|
| 933 |
|
|---|
| 934 |
} |
|---|
| 935 |
|
|---|
| 936 |
sub setup_host_system { |
|---|
| 937 |
push_el(\@main::el, 'setup_host_system()', 'Starting...'); |
|---|
| 938 |
|
|---|
| 939 |
my ($rs, $rdata) = (undef, undef); |
|---|
| 940 |
|
|---|
| 941 |
$rs = setup_system_users(); |
|---|
| 942 |
return $rs if ($rs != 0); |
|---|
| 943 |
|
|---|
| 944 |
$rs = setup_system_dirs(); |
|---|
| 945 |
return $rs if ($rs != 0); |
|---|
| 946 |
|
|---|
| 947 |
$rs = setup_config(); |
|---|
| 948 |
return $rs if ($rs != 0); |
|---|
| 949 |
|
|---|
| 950 |
$rs = setup_sql(); |
|---|
| 951 |
return $rs if ($rs != 0); |
|---|
| 952 |
|
|---|
| 953 |
$rs = setup_crontab(); |
|---|
| 954 |
return $rs if ($rs != 0); |
|---|
| 955 |
|
|---|
| 956 |
$rs = setup_hosts(); |
|---|
| 957 |
return $rs if ($rs != 0); |
|---|
| 958 |
|
|---|
| 959 |
$rs = setup_named(); |
|---|
| 960 |
return $rs if ($rs != 0); |
|---|
| 961 |
|
|---|
| 962 |
$rs = setup_php_master_user_dirs(); |
|---|
| 963 |
return $rs if ($rs != 0); |
|---|
| 964 |
|
|---|
| 965 |
$rs = setup_php(); |
|---|
| 966 |
return $rs if ($rs != 0); |
|---|
| 967 |
|
|---|
| 968 |
$rs = setup_httpd(); |
|---|
| 969 |
return $rs if ($rs != 0); |
|---|
| 970 |
|
|---|
| 971 |
$rs = setup_mta(); |
|---|
| 972 |
return $rs if ($rs != 0); |
|---|
| 973 |
|
|---|
| 974 |
$rs = setup_po(); |
|---|
| 975 |
return $rs if ($rs != 0); |
|---|
| 976 |
|
|---|
| 977 |
$rs = setup_ftpd(); |
|---|
| 978 |
return $rs if ($rs != 0); |
|---|
| 979 |
|
|---|
| 980 |
$rs = setup_ispcpd(); |
|---|
| 981 |
return $rs if ($rs != 0); |
|---|
| 982 |
|
|---|
| 983 |
push_el(\@main::el, 'setup_host_system()', 'Ending...'); |
|---|
| 984 |
return 0; |
|---|
| 985 |
} |
|---|
| 986 |
|
|---|
| 987 |
################################################################################ |
|---|
| 988 |
## MAIN ## |
|---|
| 989 |
################################################################################ |
|---|
| 990 |
|
|---|
| 991 |
# Clear screen |
|---|
| 992 |
system('clear'); |
|---|
| 993 |
|
|---|
| 994 |
my $rs = undef; |
|---|
| 995 |
|
|---|
| 996 |
$rs = setup_start_up(); |
|---|
| 997 |
|
|---|
| 998 |
if ($rs != 0) { |
|---|
| 999 |
|
|---|
| 1000 |
my $el_data = pop_el(\@main::el); |
|---|
| 1001 |
|
|---|
| 1002 |
my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 1003 |
|
|---|
| 1004 |
print STDERR "$msg\n"; |
|---|
| 1005 |
|
|---|
| 1006 |
exit 1; |
|---|
| 1007 |
|
|---|
| 1008 |
} |
|---|
| 1009 |
|
|---|
| 1010 |
$rs = user_dialog(); |
|---|
| 1011 |
|
|---|
| 1012 |
if ($rs != 0) { |
|---|
| 1013 |
|
|---|
| 1014 |
my $el_data = pop_el(\@main::el); |
|---|
| 1015 |
|
|---|
| 1016 |
my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 1017 |
|
|---|
| 1018 |
print STDERR "$msg\n"; |
|---|
| 1019 |
|
|---|
| 1020 |
exit 1; |
|---|
| 1021 |
|
|---|
| 1022 |
} |
|---|
| 1023 |
|
|---|
| 1024 |
$rs = check_host_system(); |
|---|
| 1025 |
|
|---|
| 1026 |
if ($rs != 0) { |
|---|
| 1027 |
|
|---|
| 1028 |
my $el_data = pop_el(\@main::el); |
|---|
| 1029 |
|
|---|
| 1030 |
my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 1031 |
|
|---|
| 1032 |
print STDERR "$msg\n"; |
|---|
| 1033 |
|
|---|
| 1034 |
exit 1; |
|---|
| 1035 |
|
|---|
| 1036 |
} |
|---|
| 1037 |
|
|---|
| 1038 |
$rs = setup_host_system(); |
|---|
| 1039 |
|
|---|
| 1040 |
if ($rs != 0) { |
|---|
| 1041 |
|
|---|
| 1042 |
my $el_data = pop_el(\@main::el); |
|---|
| 1043 |
|
|---|
| 1044 |
my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 1045 |
|
|---|
| 1046 |
print STDERR "$msg\n"; |
|---|
| 1047 |
|
|---|
| 1048 |
exit 1; |
|---|
| 1049 |
|
|---|
| 1050 |
} |
|---|
| 1051 |
|
|---|
| 1052 |
$rs = setup_shut_down(); |
|---|
| 1053 |
|
|---|
| 1054 |
if ($rs != 0) { |
|---|
| 1055 |
|
|---|
| 1056 |
my $el_data = pop_el(\@main::el); |
|---|
| 1057 |
|
|---|
| 1058 |
my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 1059 |
|
|---|
| 1060 |
print STDERR "$msg\n"; |
|---|
| 1061 |
|
|---|
| 1062 |
exit 1; |
|---|
| 1063 |
|
|---|
| 1064 |
} |
|---|