| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # ispCP ω (OMEGA) a Virtual Hosting Control Panel |
|---|
| 4 | # Copyright (c) 2001-2006 by moleSoftware GmbH |
|---|
| 5 | # http://www.molesoftware.com |
|---|
| 6 | # Copyright (c) 2006-2007 by isp Control Panel |
|---|
| 7 | # http://isp-control.net |
|---|
| 8 | # |
|---|
| 9 | # |
|---|
| 10 | # License: |
|---|
| 11 | # This program is free software; you can redistribute it and/or |
|---|
| 12 | # modify it under the terms of the MPL Mozilla Public License |
|---|
| 13 | # as published by the Free Software Foundation; either version 1.1 |
|---|
| 14 | # of the License, or (at your option) any later version. |
|---|
| 15 | # |
|---|
| 16 | # This program is distributed in the hope that it will be useful, |
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | # MPL Mozilla Public License for more details. |
|---|
| 20 | # |
|---|
| 21 | # You may have received a copy of the MPL Mozilla Public License |
|---|
| 22 | # along with this program. |
|---|
| 23 | # |
|---|
| 24 | # An on-line copy of the MPL Mozilla Public License can be found |
|---|
| 25 | # http://www.mozilla.org/MPL/MPL-1.1.html |
|---|
| 26 | # |
|---|
| 27 | # |
|---|
| 28 | # The ispCP ω Home Page is at: |
|---|
| 29 | # |
|---|
| 30 | # http://isp-control.net |
|---|
| 31 | # |
|---|
| 32 | |
|---|
| 33 | use FindBin; |
|---|
| 34 | use lib "$FindBin::Bin/.."; |
|---|
| 35 | require 'ispcp_common_code.pl'; |
|---|
| 36 | |
|---|
| 37 | use strict; |
|---|
| 38 | use warnings; |
|---|
| 39 | |
|---|
| 40 | sub welcome_note { |
|---|
| 41 | |
|---|
| 42 | my ($rs, $rdata) = (undef, undef); |
|---|
| 43 | |
|---|
| 44 | push_el(\@main::el, 'welcome_note()', 'Starting...'); |
|---|
| 45 | |
|---|
| 46 | my $welcome_message = <<MSG; |
|---|
| 47 | |
|---|
| 48 | Welcome in ISPCP OMEGA '$main::cfg{'VersionH'}' Uninstall Program. |
|---|
| 49 | |
|---|
| 50 | This program will uninstall ispCP OMEGA system from your server. |
|---|
| 51 | |
|---|
| 52 | /!\\ WARNING: All domain users and their accounts will be removed. /!\\ |
|---|
| 53 | |
|---|
| 54 | Please press 'Enter' to continue. |
|---|
| 55 | MSG |
|---|
| 56 | |
|---|
| 57 | print STDOUT $welcome_message; |
|---|
| 58 | |
|---|
| 59 | $rdata = readline(\*STDIN); |
|---|
| 60 | chop($rdata); |
|---|
| 61 | |
|---|
| 62 | push_el(\@main::el, 'welcome_note()', 'Ending...'); |
|---|
| 63 | |
|---|
| 64 | return 0; |
|---|
| 65 | |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | sub user_dialog { |
|---|
| 69 | |
|---|
| 70 | my ($rs, $rdata) = (undef, undef); |
|---|
| 71 | |
|---|
| 72 | push_el(\@main::el, 'user_dialog()', 'Starting...'); |
|---|
| 73 | |
|---|
| 74 | $rs = welcome_note(); |
|---|
| 75 | |
|---|
| 76 | return $rs if ($rs != 0); |
|---|
| 77 | |
|---|
| 78 | return 0; |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | sub uninstall_start_up { |
|---|
| 83 | |
|---|
| 84 | my ($rs, $rdata) = (undef, undef); |
|---|
| 85 | |
|---|
| 86 | push_el(\@main::el, 'uninstall_start_up()', 'Starting...'); |
|---|
| 87 | |
|---|
| 88 | # config check; |
|---|
| 89 | |
|---|
| 90 | $rs = get_conf(); |
|---|
| 91 | |
|---|
| 92 | return $rs if ($rs != 0); |
|---|
| 93 | |
|---|
| 94 | push_el(\@main::el, 'uninstall_start_up()', 'Ending...'); |
|---|
| 95 | |
|---|
| 96 | return 0; |
|---|
| 97 | |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | sub uninstall_shut_down { |
|---|
| 101 | |
|---|
| 102 | my ($rs, $rdata) = (undef, undef); |
|---|
| 103 | |
|---|
| 104 | push_el(\@main::el, 'uninstall_shut_down()', 'Starting...'); |
|---|
| 105 | |
|---|
| 106 | $rs = del_file("/tmp/ispcp-uninstall-services.log"); |
|---|
| 107 | |
|---|
| 108 | return $rs if ($rs != 0); |
|---|
| 109 | |
|---|
| 110 | my $shut_down_message = <<MSG; |
|---|
| 111 | |
|---|
| 112 | Congratulations ! |
|---|
| 113 | |
|---|
| 114 | ISPCP OMEGA '$main::cfg{'VersionH'}' uninstall completed successfully ! |
|---|
| 115 | |
|---|
| 116 | Thank you for using ISPCP OMEGA product ! |
|---|
| 117 | |
|---|
| 118 | MSG |
|---|
| 119 | |
|---|
| 120 | print STDOUT $shut_down_message; |
|---|
| 121 | |
|---|
| 122 | push_el(\@main::el, 'uninstall_shut_down()', 'Ending...'); |
|---|
| 123 | |
|---|
| 124 | return 0; |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | sub check_host_sql { |
|---|
| 129 | |
|---|
| 130 | push_el(\@main::el, 'check_host_sql()', 'Starting...'); |
|---|
| 131 | |
|---|
| 132 | my ($rs, $rdata, $sql) = (undef, undef, undef); |
|---|
| 133 | |
|---|
| 134 | $sql = "show databases;"; |
|---|
| 135 | |
|---|
| 136 | my $store_db_name = $main::db_name; |
|---|
| 137 | |
|---|
| 138 | $main::db_name = ""; |
|---|
| 139 | |
|---|
| 140 | @main::db_connect = ( |
|---|
| 141 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 142 | $main::db_user, |
|---|
| 143 | $main::db_pwd |
|---|
| 144 | ); |
|---|
| 145 | |
|---|
| 146 | ($rs, $rdata) = doSQL($sql); |
|---|
| 147 | |
|---|
| 148 | return $rs if ($rs != 0); |
|---|
| 149 | |
|---|
| 150 | $main::db = undef; |
|---|
| 151 | |
|---|
| 152 | $main::db_name = $store_db_name; |
|---|
| 153 | |
|---|
| 154 | @main::db_connect = ( |
|---|
| 155 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 156 | $main::db_user, |
|---|
| 157 | $main::db_pwd |
|---|
| 158 | ); |
|---|
| 159 | |
|---|
| 160 | push_el(\@main::el, 'check_host_sql()', 'Ending...'); |
|---|
| 161 | |
|---|
| 162 | return 0; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | sub check_host_system { |
|---|
| 166 | |
|---|
| 167 | my ($rs, $rdata) = (undef, undef); |
|---|
| 168 | |
|---|
| 169 | push_el(\@main::el, 'check_host_system()', 'Starting...'); |
|---|
| 170 | |
|---|
| 171 | $rs = check_host_sql(); |
|---|
| 172 | |
|---|
| 173 | return $rs if ($rs != 0); |
|---|
| 174 | |
|---|
| 175 | push_el(\@main::el, 'check_host_system()', 'Ending...'); |
|---|
| 176 | |
|---|
| 177 | return 0; |
|---|
| 178 | |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | sub uninstall_system_users { |
|---|
| 182 | |
|---|
| 183 | my ($rs, $rdata, $rows, $sql) = (undef, undef, undef, undef); |
|---|
| 184 | |
|---|
| 185 | push_el(\@main::el, 'uninstall_system_users()', 'Starting...'); |
|---|
| 186 | |
|---|
| 187 | my ($fuid, $fgid) = ($main::cfg{'MTA_MAILBOX_UID_NAME'}, $main::cfg{'MTA_MAILBOX_GID_NAME'}); |
|---|
| 188 | |
|---|
| 189 | my ($muid, $mgid) = ($main::cfg{'APACHE_SUEXEC_MIN_UID'}, $main::cfg{'APACHE_SUEXEC_MIN_GID'}); |
|---|
| 190 | |
|---|
| 191 | my ($upref) = ($main::cfg{'APACHE_SUEXEC_USER_PREF'}); |
|---|
| 192 | |
|---|
| 193 | my ($uid, $gid) = (undef, undef); |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | my @udata = (); |
|---|
| 197 | |
|---|
| 198 | my @gdata = (); |
|---|
| 199 | |
|---|
| 200 | # |
|---|
| 201 | # MTA Mailbox User |
|---|
| 202 | # |
|---|
| 203 | @udata = getpwnam($fuid); |
|---|
| 204 | @gdata = getgrnam($fuid); |
|---|
| 205 | |
|---|
| 206 | if (scalar(@udata) != 0) { # we have not this one user data; |
|---|
| 207 | |
|---|
| 208 | my $cmd = "$main::cfg{'CMD_USERDEL'} $fuid"; |
|---|
| 209 | |
|---|
| 210 | $rs = sys_command($cmd); |
|---|
| 211 | |
|---|
| 212 | return $rs if ($rs != 0); |
|---|
| 213 | |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (scalar(@gdata) != 0) { # we have not this one group data; |
|---|
| 217 | |
|---|
| 218 | my $cmd = "$main::cfg{'CMD_GROUPDEL'} $fuid"; |
|---|
| 219 | |
|---|
| 220 | $rs = sys_command($cmd); |
|---|
| 221 | |
|---|
| 222 | return $rs if ($rs != 0); |
|---|
| 223 | |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | # |
|---|
| 227 | # PHP Master |
|---|
| 228 | # |
|---|
| 229 | |
|---|
| 230 | @udata = getpwnam("$upref$muid"); |
|---|
| 231 | |
|---|
| 232 | if (scalar(@udata) != 0) { # we have not this one user data; |
|---|
| 233 | |
|---|
| 234 | my $cmd = "$main::cfg{'CMD_USERDEL'} $upref$muid"; |
|---|
| 235 | |
|---|
| 236 | $rs = sys_command($cmd); |
|---|
| 237 | |
|---|
| 238 | return $rs if ($rs != 0); |
|---|
| 239 | |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | @gdata = getgrnam("$upref$mgid"); |
|---|
| 243 | |
|---|
| 244 | if (scalar(@gdata) != 0) { # we have not this one group data; |
|---|
| 245 | |
|---|
| 246 | my $cmd = "$main::cfg{'CMD_GROUPDEL'} $upref$mgid"; |
|---|
| 247 | |
|---|
| 248 | $rs = sys_command($cmd); |
|---|
| 249 | |
|---|
| 250 | return $rs if ($rs != 0); |
|---|
| 251 | |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | # |
|---|
| 255 | # Virtual User |
|---|
| 256 | # |
|---|
| 257 | |
|---|
| 258 | $sql = "select domain_uid,domain_gid from domain"; |
|---|
| 259 | |
|---|
| 260 | ($rs, $rows) = doSQL($sql); |
|---|
| 261 | |
|---|
| 262 | return $rs if ($rs != 0); |
|---|
| 263 | |
|---|
| 264 | if (scalar(@$rows) != 0) { |
|---|
| 265 | |
|---|
| 266 | foreach (@$rows) { |
|---|
| 267 | |
|---|
| 268 | my $query_user = $_; |
|---|
| 269 | |
|---|
| 270 | @udata = getpwnam("$upref@$query_user[0]"); |
|---|
| 271 | |
|---|
| 272 | if (scalar(@udata) != 0) { # we have not this one user data; |
|---|
| 273 | |
|---|
| 274 | my $cmd = "$main::cfg{'CMD_USERDEL'} $upref@$query_user[0]"; |
|---|
| 275 | |
|---|
| 276 | $rs = sys_command($cmd); |
|---|
| 277 | |
|---|
| 278 | return $rs if ($rs != 0); |
|---|
| 279 | |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | @gdata = getgrnam("$upref@$query_user[1]"); |
|---|
| 283 | |
|---|
| 284 | if (scalar(@gdata) != 0) { # we have not this one group data; |
|---|
| 285 | |
|---|
| 286 | my $cmd = "$main::cfg{'CMD_GROUPDEL'} $upref@$query_user[0]"; |
|---|
| 287 | |
|---|
| 288 | $rs = sys_command($cmd); |
|---|
| 289 | |
|---|
| 290 | return $rs if ($rs != 0); |
|---|
| 291 | |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | push_el(\@main::el, 'uninstall_system_users()', 'Ending...'); |
|---|
| 300 | |
|---|
| 301 | return 0; |
|---|
| 302 | |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | sub uninstall_system_dirs { |
|---|
| 306 | |
|---|
| 307 | my ($rs, $rdata) = (undef, undef); |
|---|
| 308 | |
|---|
| 309 | push_el(\@main::el, 'uninstall_system_dirs()', 'Starting...'); |
|---|
| 310 | |
|---|
| 311 | $rs = del_dir($main::cfg{'APACHE_WWW_DIR'}); |
|---|
| 312 | |
|---|
| 313 | return $rs if ($rs != 0); |
|---|
| 314 | |
|---|
| 315 | $rs = del_dir($main::cfg{'APACHE_USERS_LOG_DIR'}); |
|---|
| 316 | |
|---|
| 317 | return $rs if ($rs != 0); |
|---|
| 318 | |
|---|
| 319 | $rs = del_dir($main::cfg{'APACHE_BACKUP_LOG_DIR'}); |
|---|
| 320 | |
|---|
| 321 | return $rs if ($rs != 0); |
|---|
| 322 | |
|---|
| 323 | $rs = del_dir($main::cfg{'MTA_VIRTUAL_CONF_DIR'}); |
|---|
| 324 | |
|---|
| 325 | return $rs if ($rs != 0); |
|---|
| 326 | |
|---|
| 327 | $rs = del_dir($main::cfg{'MTA_VIRTUAL_MAIL_DIR'}); |
|---|
| 328 | |
|---|
| 329 | return $rs if ($rs != 0); |
|---|
| 330 | |
|---|
| 331 | $rs = del_dir($main::cfg{'LOG_DIR'}); |
|---|
| 332 | |
|---|
| 333 | return $rs if ($rs != 0); |
|---|
| 334 | |
|---|
| 335 | $rs = del_dir($main::cfg{'PHP_STARTER_DIR'}); |
|---|
| 336 | |
|---|
| 337 | return $rs if ($rs != 0); |
|---|
| 338 | |
|---|
| 339 | push_el(\@main::el, 'uninstall_system_dirs()', 'Ending...'); |
|---|
| 340 | |
|---|
| 341 | return 0; |
|---|
| 342 | |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | sub uninstall_sql { |
|---|
| 346 | |
|---|
| 347 | my ($rs, $rdata) = (undef, undef); |
|---|
| 348 | |
|---|
| 349 | push_el(\@main::el, 'uninstall_sql()', 'Starting...'); |
|---|
| 350 | |
|---|
| 351 | # |
|---|
| 352 | # check for existing database; |
|---|
| 353 | # |
|---|
| 354 | |
|---|
| 355 | my $sql = "show tables;"; |
|---|
| 356 | |
|---|
| 357 | ($rs, $rdata) = doSQL($sql); |
|---|
| 358 | |
|---|
| 359 | if ($rs == 0) { # Yes, we have one ! Let's drop it; |
|---|
| 360 | |
|---|
| 361 | my $store_db_name = $main::db_name; |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | # Let's reset data; |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | $main::db = undef; |
|---|
| 368 | |
|---|
| 369 | $main::db_name = ''; |
|---|
| 370 | |
|---|
| 371 | @main::db_connect = ( |
|---|
| 372 | "DBI:mysql:$main::db_name:$main::db_host", |
|---|
| 373 | $main::db_user, |
|---|
| 374 | $main::db_pwd |
|---|
| 375 | ); |
|---|
| 376 | |
|---|
| 377 | $sql = "drop database $store_db_name;"; |
|---|
| 378 | |
|---|
| 379 | ($rs, $rdata) = doSQL($sql); |
|---|
| 380 | |
|---|
| 381 | return $rs if ($rs != 0); |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | # Let's reset data; |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | $main::db = undef; |
|---|
| 388 | |
|---|
| 389 | $main::db_name = $store_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 | } |
|---|
| 398 | |
|---|
| 399 | push_el(\@main::el, 'uninstall_sql()', 'Ending...'); |
|---|
| 400 | |
|---|
| 401 | return 0; |
|---|
| 402 | |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | sub uninstall_crontab { |
|---|
| 406 | |
|---|
| 407 | my $rs = undef; |
|---|
| 408 | |
|---|
| 409 | push_el(\@main::el, 'uninstall_crontab()', 'Starting...'); |
|---|
| 410 | |
|---|
| 411 | if ( -e "/etc/cron.d/ispcp") { |
|---|
| 412 | $rs = del_file("/etc/cron.d/ispcp"); |
|---|
| 413 | |
|---|
| 414 | return $rs if ($rs != 0); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | push_el(\@main::el, 'uninstall_crontab()', 'Ending...'); |
|---|
| 418 | |
|---|
| 419 | return 0; |
|---|
| 420 | |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | sub uninstall_resolver { |
|---|
| 424 | |
|---|
| 425 | push_el(\@main::el, 'uninstall_resolver()', 'Starting...'); |
|---|
| 426 | |
|---|
| 427 | my $resolv_file = "/etc/resolv.conf"; |
|---|
| 428 | |
|---|
| 429 | my ($rs, $cmd) = (undef, undef); |
|---|
| 430 | |
|---|
| 431 | if ( -e "$resolv_file.bkp" ) { |
|---|
| 432 | |
|---|
| 433 | $cmd = "$main::cfg{'CMD_MV'} $resolv_file.bkp $resolv_file"; |
|---|
| 434 | |
|---|
| 435 | $rs = sys_command_rs($cmd); |
|---|
| 436 | |
|---|
| 437 | return $rs if ($rs != 0); |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | push_el(\@main::el, 'uninstall_resolver()', 'Ending...'); |
|---|
| 441 | |
|---|
| 442 | return 0; |
|---|
| 443 | |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | sub uninstall_logrotate { |
|---|
| 447 | |
|---|
| 448 | push_el(\@main::el, 'uninstall_logrotate()', 'Starting...'); |
|---|
| 449 | |
|---|
| 450 | my ($rs, $cmd) = (undef, undef); |
|---|
| 451 | |
|---|
| 452 | my $logrorate_d = "/etc/logrorate.d"; |
|---|
| 453 | |
|---|
| 454 | if ( -e "$logrorate_d/ispcp" ) { |
|---|
| 455 | |
|---|
| 456 | $rs = del_file("$logrorate_d/ispcp"); |
|---|
| 457 | |
|---|
| 458 | return $rs if ($rs != 0); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | push_el(\@main::el, 'uninstall_logrotate()', 'Ending...'); |
|---|
| 462 | |
|---|
| 463 | return 0; |
|---|
| 464 | |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | sub uninstall_named { |
|---|
| 468 | |
|---|
| 469 | my ($rs, $rdata) = (undef, undef); |
|---|
| 470 | |
|---|
| 471 | push_el(\@main::el, 'uninstall_named()', 'Starting...'); |
|---|
| 472 | |
|---|
| 473 | my $cfg_dir = "$main::cfg{'CONF_DIR'}/bind"; |
|---|
| 474 | |
|---|
| 475 | my $bk_dir = "$cfg_dir/backup"; |
|---|
| 476 | |
|---|
| 477 | my $wrk_dir = "$cfg_dir/working"; |
|---|
| 478 | |
|---|
| 479 | my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 480 | |
|---|
| 481 | sys_command_rs("$main::cfg{'CMD_NAMED'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 482 | |
|---|
| 483 | if (-e "$bk_dir/named.conf.system") { |
|---|
| 484 | |
|---|
| 485 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/named.conf.system $main::cfg{'BIND_CONF_FILE'}"; |
|---|
| 486 | |
|---|
| 487 | $rs = sys_command($cmd); |
|---|
| 488 | |
|---|
| 489 | return $rs if ($rs != 0); |
|---|
| 490 | |
|---|
| 491 | $rs = del_file("$bk_dir/named.conf.system"); |
|---|
| 492 | |
|---|
| 493 | return $rs if ($rs != 0); |
|---|
| 494 | |
|---|
| 495 | $rs = del_file("$bk_dir/named.conf.ispcp"); |
|---|
| 496 | |
|---|
| 497 | return $rs if ($rs != 0); |
|---|
| 498 | |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | sys_command_rs("$main::cfg{'CMD_NAMED'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 502 | |
|---|
| 503 | push_el(\@main::el, 'uninstall_named()', 'Ending...'); |
|---|
| 504 | |
|---|
| 505 | return 0; |
|---|
| 506 | |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | sub uninstall_httpd { |
|---|
| 510 | |
|---|
| 511 | my ($rs, $rdata) = (undef, undef); |
|---|
| 512 | |
|---|
| 513 | push_el(\@main::el, 'uninstall_httpd()', 'Starting...'); |
|---|
| 514 | |
|---|
| 515 | my $cfg_dir = "$main::cfg{'CONF_DIR'}/apache"; |
|---|
| 516 | |
|---|
| 517 | my $bk_dir = "$cfg_dir/backup"; |
|---|
| 518 | |
|---|
| 519 | my $wrk_dir = "$cfg_dir/working"; |
|---|
| 520 | |
|---|
| 521 | my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 522 | |
|---|
| 523 | sys_command_rs("$main::cfg{'CMD_HTTPD'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 524 | |
|---|
| 525 | sys_command_rs("a2dissite ispcp.conf &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 526 | |
|---|
| 527 | $rs = del_file("$main::cfg{'APACHE_SITES_DIR'}/ispcp.conf"); |
|---|
| 528 | |
|---|
| 529 | return $rs if ($rs != 0); |
|---|
| 530 | |
|---|
| 531 | sys_command_rs("a2dissite 00_master.conf &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 532 | |
|---|
| 533 | $rs = del_file("$main::cfg{'APACHE_SITES_DIR'}/00_master.conf"); |
|---|
| 534 | |
|---|
| 535 | return $rs if ($rs != 0); |
|---|
| 536 | |
|---|
| 537 | sys_command_rs("a2dismod fastcgi_ispcp &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 538 | |
|---|
| 539 | $rs = del_file("$main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.conf"); |
|---|
| 540 | |
|---|
| 541 | return $rs if ($rs != 0); |
|---|
| 542 | |
|---|
| 543 | $rs = del_file("$main::cfg{'APACHE_MODS_DIR'}/fastcgi_ispcp.load"); |
|---|
| 544 | |
|---|
| 545 | return $rs if ($rs != 0); |
|---|
| 546 | |
|---|
| 547 | sleep(5); |
|---|
| 548 | |
|---|
| 549 | sys_command_rs("$main::cfg{'CMD_HTTPD'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 550 | |
|---|
| 551 | push_el(\@main::el, 'uninstall_httpd()', 'Ending...'); |
|---|
| 552 | |
|---|
| 553 | return 0; |
|---|
| 554 | |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | sub uninstall_mta { |
|---|
| 558 | |
|---|
| 559 | my ($rs, $rdata) = (undef, undef); |
|---|
| 560 | |
|---|
| 561 | push_el(\@main::el, 'uninstall_mta()', 'Starting...'); |
|---|
| 562 | |
|---|
| 563 | my $cfg_dir = "$main::cfg{'CONF_DIR'}/postfix"; |
|---|
| 564 | |
|---|
| 565 | my $bk_dir = "$cfg_dir/backup"; |
|---|
| 566 | |
|---|
| 567 | my $wrk_dir = "$cfg_dir/working"; |
|---|
| 568 | |
|---|
| 569 | my $vrl_dir = "$cfg_dir/ispcp"; |
|---|
| 570 | |
|---|
| 571 | my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 572 | |
|---|
| 573 | sys_command_rs("$main::cfg{'CMD_MTA'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 574 | |
|---|
| 575 | if (-e "$bk_dir/main.cf.system") { |
|---|
| 576 | |
|---|
| 577 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/main.cf.system $main::cfg{'POSTFIX_CONF_FILE'}"; |
|---|
| 578 | |
|---|
| 579 | $rs = sys_command($cmd); |
|---|
| 580 | |
|---|
| 581 | return $rs if ($rs != 0); |
|---|
| 582 | |
|---|
| 583 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/master.cf.system $main::cfg{'POSTFIX_MASTER_CONF_FILE'}"; |
|---|
| 584 | |
|---|
| 585 | $rs = sys_command($cmd); |
|---|
| 586 | |
|---|
| 587 | return $rs if ($rs != 0); |
|---|
| 588 | |
|---|
| 589 | $rs = del_file("$bk_dir/main.cf.system"); |
|---|
| 590 | |
|---|
| 591 | return $rs if ($rs != 0); |
|---|
| 592 | |
|---|
| 593 | $rs = del_file("$bk_dir/master.cf.system"); |
|---|
| 594 | |
|---|
| 595 | return $rs if ($rs != 0); |
|---|
| 596 | |
|---|
| 597 | $rs = del_file("$bk_dir/main.cf.ispcp"); |
|---|
| 598 | |
|---|
| 599 | return $rs if ($rs != 0); |
|---|
| 600 | |
|---|
| 601 | $rs = del_file("$bk_dir/master.cf.ispcp"); |
|---|
| 602 | |
|---|
| 603 | return $rs if ($rs != 0); |
|---|
| 604 | |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | if ( -e "/var/spool/postfix/private/ispcp-arpl" ) { |
|---|
| 608 | $rs = del_file("/var/spool/postfix/private/ispcp-arpl"); |
|---|
| 609 | |
|---|
| 610 | return $rs if ($rs != 0); |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | $rs = sys_command("$main::cfg{'CMD_NEWALIASES'} &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 614 | |
|---|
| 615 | return $rs if ($rs != 0); |
|---|
| 616 | |
|---|
| 617 | sys_command_rs("$main::cfg{'CMD_MTA'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 618 | |
|---|
| 619 | push_el(\@main::el, 'uninstall_mta()', 'Ending...'); |
|---|
| 620 | |
|---|
| 621 | return 0; |
|---|
| 622 | |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | sub uninstall_po { |
|---|
| 626 | |
|---|
| 627 | my ($rs, $rdata) = (undef, undef); |
|---|
| 628 | |
|---|
| 629 | push_el(\@main::el, 'uninstall_po()', 'Starting...'); |
|---|
| 630 | |
|---|
| 631 | my $cfg_dir = "$main::cfg{'CONF_DIR'}/courier"; |
|---|
| 632 | |
|---|
| 633 | my $bk_dir = "$cfg_dir/backup"; |
|---|
| 634 | |
|---|
| 635 | my $wrk_dir = "$cfg_dir/working"; |
|---|
| 636 | |
|---|
| 637 | my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 638 | |
|---|
| 639 | sys_command_rs("$main::cfg{'CMD_AUTHD'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 640 | |
|---|
| 641 | sys_command_rs("$main::cfg{'CMD_IMAP'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 642 | |
|---|
| 643 | sys_command_rs("$main::cfg{'CMD_POP'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 644 | |
|---|
| 645 | if (-e "$bk_dir/imapd.system") { |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | # Let's backup system configs; |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/imapd.system $main::cfg{'COURIER_CONF_DIR'}/imapd"; |
|---|
| 652 | |
|---|
| 653 | $rs = sys_command($cmd); |
|---|
| 654 | |
|---|
| 655 | return $rs if ($rs != 0); |
|---|
| 656 | |
|---|
| 657 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/pop3d.system $main::cfg{'COURIER_CONF_DIR'}/pop3d"; |
|---|
| 658 | |
|---|
| 659 | $rs = sys_command($cmd); |
|---|
| 660 | |
|---|
| 661 | return $rs if ($rs != 0); |
|---|
| 662 | |
|---|
| 663 | if (exists $main::cfg{'AUTHLIB_CONF_DIR'} && $main::cfg{'AUTHLIB_CONF_DIR'}) { |
|---|
| 664 | |
|---|
| 665 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/authdaemonrc.system $main::cfg{'AUTHLIB_CONF_DIR'}/authdaemonrc"; |
|---|
| 666 | |
|---|
| 667 | $rs = sys_command($cmd); |
|---|
| 668 | |
|---|
| 669 | return $rs if ($rs != 0); |
|---|
| 670 | |
|---|
| 671 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/authmodulelist.system $main::cfg{'AUTHLIB_CONF_DIR'}/authmodulelist"; |
|---|
| 672 | |
|---|
| 673 | $rs = sys_command($cmd); |
|---|
| 674 | |
|---|
| 675 | return $rs if ($rs != 0); |
|---|
| 676 | |
|---|
| 677 | if (-e "$bk_dir/userdb.system") { |
|---|
| 678 | |
|---|
| 679 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/userdb.system $main::cfg{'AUTHLIB_CONF_DIR'}/userdb"; |
|---|
| 680 | |
|---|
| 681 | $rs = sys_command($cmd); |
|---|
| 682 | |
|---|
| 683 | } |
|---|
| 684 | |
|---|
| 685 | } else { |
|---|
| 686 | |
|---|
| 687 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/authdaemonrc.system $main::cfg{'COURIER_CONF_DIR'}/authdaemonrc"; |
|---|
| 688 | |
|---|
| 689 | $rs = sys_command($cmd); |
|---|
| 690 | |
|---|
| 691 | return $rs if ($rs != 0); |
|---|
| 692 | |
|---|
| 693 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/authmodulelist.system $main::cfg{'COURIER_CONF_DIR'}/authmodulelist"; |
|---|
| 694 | |
|---|
| 695 | $rs = sys_command($cmd); |
|---|
| 696 | |
|---|
| 697 | return $rs if ($rs != 0); |
|---|
| 698 | |
|---|
| 699 | if (-e "$bk_dir/userdb.system") { |
|---|
| 700 | |
|---|
| 701 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/userdb.system $main::cfg{'COURIER_CONF_DIR'}/userdb"; |
|---|
| 702 | |
|---|
| 703 | $rs = sys_command($cmd); |
|---|
| 704 | |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | return $rs if ($rs != 0); |
|---|
| 710 | |
|---|
| 711 | $rs = del_file("$bk_dir/imapd.system"); |
|---|
| 712 | |
|---|
| 713 | return $rs if ($rs != 0); |
|---|
| 714 | |
|---|
| 715 | $rs = del_file("$bk_dir/pop3d.system"); |
|---|
| 716 | |
|---|
| 717 | return $rs if ($rs != 0); |
|---|
| 718 | |
|---|
| 719 | $rs = del_file("$bk_dir/authdaemonrc.system"); |
|---|
| 720 | |
|---|
| 721 | return $rs if ($rs != 0); |
|---|
| 722 | |
|---|
| 723 | $rs = del_file("$bk_dir/authmodulelist.system"); |
|---|
| 724 | |
|---|
| 725 | return $rs if ($rs != 0); |
|---|
| 726 | |
|---|
| 727 | if (-e "$bk_dir/userdb.system") { |
|---|
| 728 | |
|---|
| 729 | $rs = del_file("$bk_dir/userdb.system"); |
|---|
| 730 | |
|---|
| 731 | return $rs if ($rs != 0); |
|---|
| 732 | |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | $rs = del_file("$bk_dir/imapd.ispcp"); |
|---|
| 736 | |
|---|
| 737 | return $rs if ($rs != 0); |
|---|
| 738 | |
|---|
| 739 | $rs = del_file("$bk_dir/pop3d.ispcp"); |
|---|
| 740 | |
|---|
| 741 | return $rs if ($rs != 0); |
|---|
| 742 | |
|---|
| 743 | $rs = del_file("$bk_dir/authdaemonrc.ispcp"); |
|---|
| 744 | |
|---|
| 745 | return $rs if ($rs != 0); |
|---|
| 746 | |
|---|
| 747 | $rs = del_file("$bk_dir/authmodulelist.ispcp"); |
|---|
| 748 | |
|---|
| 749 | return $rs if ($rs != 0); |
|---|
| 750 | |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | $rs = sys_command($main::cfg{'CMD_MAKEUSERDB'}); |
|---|
| 754 | |
|---|
| 755 | return $rs if ($rs != 0); |
|---|
| 756 | |
|---|
| 757 | sys_command_rs("$main::cfg{'CMD_AUTHD'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 758 | |
|---|
| 759 | sys_command_rs("$main::cfg{'CMD_IMAP'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 760 | |
|---|
| 761 | sys_command_rs("$main::cfg{'CMD_POP'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 762 | |
|---|
| 763 | push_el(\@main::el, 'uninstall_po()', 'Ending...'); |
|---|
| 764 | |
|---|
| 765 | return 0; |
|---|
| 766 | |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | sub uninstall_ftpd { |
|---|
| 770 | |
|---|
| 771 | my ($rs, $rdata) = (undef, undef); |
|---|
| 772 | |
|---|
| 773 | push_el(\@main::el, 'uninstall_ftpd()', 'Starting...'); |
|---|
| 774 | |
|---|
| 775 | my $cfg_dir = "$main::cfg{'CONF_DIR'}/proftpd"; |
|---|
| 776 | |
|---|
| 777 | my $bk_dir = "$cfg_dir/backup"; |
|---|
| 778 | |
|---|
| 779 | my ($cfg_tpl, $cfg, $cmd) = (undef, undef, undef); |
|---|
| 780 | |
|---|
| 781 | sys_command_rs("$main::cfg{'CMD_FTPD'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 782 | |
|---|
| 783 | if (-e "$bk_dir/proftpd.conf.system") { |
|---|
| 784 | |
|---|
| 785 | $cmd = "$main::cfg{'CMD_CP'} -p $bk_dir/proftpd.conf.system $main::cfg{'FTPD_CONF_FILE'}"; |
|---|
| 786 | |
|---|
| 787 | $rs = sys_command($cmd); |
|---|
| 788 | |
|---|
| 789 | return $rs if ($rs != 0); |
|---|
| 790 | |
|---|
| 791 | $rs = del_file("$bk_dir/proftpd.conf.system"); |
|---|
| 792 | |
|---|
| 793 | return $rs if ($rs != 0); |
|---|
| 794 | |
|---|
| 795 | $rs = del_file("$bk_dir/proftpd.conf.ispcp"); |
|---|
| 796 | |
|---|
| 797 | return $rs if ($rs != 0); |
|---|
| 798 | |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | sys_command_rs("$main::cfg{'CMD_FTPD'} start &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 802 | |
|---|
| 803 | push_el(\@main::el, 'uninstall_ftpd()', 'Ending...'); |
|---|
| 804 | |
|---|
| 805 | return 0; |
|---|
| 806 | |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | sub uninstall_ispcpd { |
|---|
| 810 | |
|---|
| 811 | my ($rs, $rdata) = (undef, undef); |
|---|
| 812 | |
|---|
| 813 | push_el(\@main::el, 'uninstall_ispcpd()', 'Starting...'); |
|---|
| 814 | |
|---|
| 815 | sys_command_rs("$main::cfg{'CMD_ISPCPD'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 816 | |
|---|
| 817 | sys_command_rs("$main::cfg{'CMD_ISPCPN'} stop &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 818 | |
|---|
| 819 | if ( -x "/usr/lib/lsb/install_initd" ) { #LSB 3.1 Core section 20.4 compatibility |
|---|
| 820 | |
|---|
| 821 | sys_command_rs("/usr/lib/lsb/install_initd $main::cfg{'CMD_ISPCPD'} &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 822 | sys_command_rs("/usr/lib/lsb/install_initd $main::cfg{'CMD_ISPCPN'} &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 823 | |
|---|
| 824 | } |
|---|
| 825 | |
|---|
| 826 | $rs = del_file("$main::cfg{'CMD_ISPCPD'}"); |
|---|
| 827 | |
|---|
| 828 | return $rs if ($rs != 0); |
|---|
| 829 | |
|---|
| 830 | $rs = del_file("$main::cfg{'CMD_ISPCPN'}"); |
|---|
| 831 | |
|---|
| 832 | return $rs if ($rs != 0); |
|---|
| 833 | |
|---|
| 834 | if ( ! -x "/usr/lib/lsb/install_initd" && -x "/usr/sbin/update-rc.d" ) { |
|---|
| 835 | |
|---|
| 836 | sys_command_rs("/usr/sbin/update-rc.d ispcp_daemon remove &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 837 | sys_command_rs("/usr/sbin/update-rc.d ispcp_network remove &> /tmp/ispcp-uninstall-services.log"); |
|---|
| 838 | |
|---|
| 839 | } |
|---|
| 840 | |
|---|
| 841 | push_el(\@main::el, 'uninstall_ispcpd()', 'Ending...'); |
|---|
| 842 | |
|---|
| 843 | return 0; |
|---|
| 844 | |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | sub uninstall_host_system { |
|---|
| 848 | |
|---|
| 849 | my ($rs, $rdata) = (undef, undef); |
|---|
| 850 | |
|---|
| 851 | push_el(\@main::el, 'uninstall_host_system()', 'Starting...'); |
|---|
| 852 | |
|---|
| 853 | $rs = uninstall_system_users(); |
|---|
| 854 | |
|---|
| 855 | return $rs if ($rs != 0); |
|---|
| 856 | |
|---|
| 857 | $rs = uninstall_system_dirs(); |
|---|
| 858 | |
|---|
| 859 | return $rs if ($rs != 0); |
|---|
| 860 | |
|---|
| 861 | $rs = uninstall_sql(); |
|---|
| 862 | |
|---|
| 863 | return $rs if ($rs != 0); |
|---|
| 864 | |
|---|
| 865 | $rs = uninstall_crontab(); |
|---|
| 866 | |
|---|
| 867 | return $rs if ($rs != 0); |
|---|
| 868 | |
|---|
| 869 | $rs = uninstall_resolver(); |
|---|
| 870 | |
|---|
| 871 | return $rs if ($rs != 0); |
|---|
| 872 | |
|---|
| 873 | $rs = uninstall_httpd(); |
|---|
| 874 | |
|---|
| 875 | return $rs if ($rs != 0); |
|---|
| 876 | |
|---|
| 877 | $rs = uninstall_mta(); |
|---|
| 878 | |
|---|
| 879 | return $rs if ($rs != 0); |
|---|
| 880 | |
|---|
| 881 | $rs = uninstall_po(); |
|---|
| 882 | |
|---|
| 883 | return $rs if ($rs != 0); |
|---|
| 884 | |
|---|
| 885 | $rs = uninstall_ftpd(); |
|---|
| 886 | |
|---|
| 887 | return $rs if ($rs != 0); |
|---|
| 888 | |
|---|
| 889 | $rs = uninstall_named(); |
|---|
| 890 | |
|---|
| 891 | return $rs if ($rs != 0); |
|---|
| 892 | |
|---|
| 893 | $rs = uninstall_ispcpd(); |
|---|
| 894 | |
|---|
| 895 | return $rs if ($rs != 0); |
|---|
| 896 | |
|---|
| 897 | push_el(\@main::el, 'uninstall_host_system()', 'Ending...'); |
|---|
| 898 | |
|---|
| 899 | return 0; |
|---|
| 900 | |
|---|
| 901 | } |
|---|
| 902 | |
|---|
| 903 | ################################################################################ |
|---|
| 904 | ## MAIN ## |
|---|
| 905 | ################################################################################ |
|---|
| 906 | |
|---|
| 907 | my $rs = undef; |
|---|
| 908 | |
|---|
| 909 | $rs = uninstall_start_up(); |
|---|
| 910 | |
|---|
| 911 | if ($rs != 0) { |
|---|
| 912 | |
|---|
| 913 | my $el_data = pop_el(\@main::el); |
|---|
| 914 | |
|---|
| 915 | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 916 | |
|---|
| 917 | print STDERR "$msg\n"; |
|---|
| 918 | |
|---|
| 919 | exit 1; |
|---|
| 920 | |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | $rs = user_dialog(); |
|---|
| 924 | |
|---|
| 925 | if ($rs != 0) { |
|---|
| 926 | |
|---|
| 927 | my $el_data = pop_el(\@main::el); |
|---|
| 928 | |
|---|
| 929 | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 930 | |
|---|
| 931 | print STDERR "$msg\n"; |
|---|
| 932 | |
|---|
| 933 | exit 1; |
|---|
| 934 | |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | $rs = check_host_system(); |
|---|
| 938 | |
|---|
| 939 | if ($rs != 0) { |
|---|
| 940 | |
|---|
| 941 | my $el_data = pop_el(\@main::el); |
|---|
| 942 | |
|---|
| 943 | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 944 | |
|---|
| 945 | print STDERR "$msg\n"; |
|---|
| 946 | |
|---|
| 947 | exit 1; |
|---|
| 948 | |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | $rs = uninstall_host_system(); |
|---|
| 952 | |
|---|
| 953 | if ($rs != 0) { |
|---|
| 954 | |
|---|
| 955 | my $el_data = pop_el(\@main::el); |
|---|
| 956 | |
|---|
| 957 | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 958 | |
|---|
| 959 | print STDERR "$msg\n"; |
|---|
| 960 | |
|---|
| 961 | exit 1; |
|---|
| 962 | |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | $rs = uninstall_shut_down(); |
|---|
| 966 | |
|---|
| 967 | if ($rs != 0) { |
|---|
| 968 | |
|---|
| 969 | my $el_data = pop_el(\@main::el); |
|---|
| 970 | |
|---|
| 971 | my ($sub_name, $msg) = split(/$main::el_sep/, $el_data); |
|---|
| 972 | |
|---|
| 973 | print STDERR "$msg\n"; |
|---|
| 974 | |
|---|
| 975 | exit 1; |
|---|
| 976 | |
|---|
| 977 | } |
|---|