root/tags/omega-1.0.0-rc3/engine/setup/ispcp-update

Revision 983, 23.7 KB (checked in by rats, 11 months ago)

Updated: Updatescript!

Line 
1#!/usr/bin/perl
2
3# ispCP ω (OMEGA) a Virtual Hosting Control Panel
4# Copyright (c) 2007-2008 by ispCP
5# http://isp-control.net
6#
7#
8# License:
9#    This program is free software; you can redistribute it and/or
10#    modify it under the terms of the GPL General Public License
11#    as published by the Free Software Foundation; either version 2.0
12#    of the License, or (at your option) any later version.
13#
14#    This program is distributed in the hope that it will be useful,
15#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17#    GPL General Public License for more details.
18#
19#    You may have received a copy of the GPL General Public License
20#    along with this program.
21#
22#    An on-line copy of the GPL General Public License can be found
23#    http://www.fsf.org/licensing/licenses/gpl.txt
24#
25# The ispCP ω Home Page is at:
26#
27#    http://isp-control.net
28#
29
30use FindBin;
31use lib "$FindBin::Bin/..";
32
33require 'ispcp_common_code.pl';
34use strict;
35use warnings;
36
37%main::ua = ();
38$main::vhcs2conf = undef;
39$main::cfg_re = '^[ \t]*([\_A-Za-z0-9]+) *= *([^\n\r]*)[\n\r]';
40
41################################################################################
42##                                SUBROUTINES                                 ##
43################################################################################
44
45sub get_vhcs2conf {
46
47    push_el(\@main::el, 'get_conf()', 'Starting...');
48
49    my ($rs, $fline) = get_file($main::vhcs2conf);
50    return -1 if ($rs != 0);
51
52    my @frows = split(/\n/, $fline);
53    my $i = '';
54
55    for ($i = 0; $i < scalar(@frows); $i++) {
56        $frows[$i] = "$frows[$i]\n";
57
58        if ($frows[$i] =~ /$main::cfg_re/) {
59                        $main::vhcs2{$1} = $2;
60        }
61    }
62
63    return -1 if (setup_main_vars() != 0);
64
65    push_el(\@main::el, 'get_conf()', 'Ending...');
66
67    return 0;
68}
69
70sub ask_vhcs2conf {
71        my ($rs, $rdata) = (undef, undef);
72
73        push_el(\@main::el, 'ask_vhcs2conf()', 'Starting...');
74
75        # Get path to vhcs2.conf
76        print STDOUT "\tPlease enter path to vhcs2.conf [/etc/vhcs2/vhcs2.conf]: ";
77
78        $rdata = readline(\*STDIN);
79        chop($rdata);
80
81        if (!defined($rdata) || $rdata eq '') {
82                $rdata = '/etc/vhcs2/vhcs2.conf';
83        }
84
85        # set VHCS2 config
86        $main::vhcs2conf = $rdata;
87
88        # Get VHCS2 config
89        $rs = get_vhcs2conf();
90        return $rs if ($rs != 0);
91
92        $rs = setup_main_vars();
93        return $rs if ($rs != 0);
94
95        push_el(\@main::el, 'ask_vhcs2conf()', 'Ending...');
96
97        return 0;
98
99}
100
101sub ask_awstats_on {
102
103        my $rdata = undef;
104
105        push_el(\@main::el, 'ask_awstats_on()', 'Starting...');
106
107        my $qmsg = "\n\tActivate AWStats. [no]: ";
108
109        print STDOUT $qmsg;
110
111        $rdata = readline(\*STDIN);
112        chop($rdata);
113
114        if (!defined($rdata) || $rdata eq '') {
115                $main::ua{'awstats_on'} = 'no';
116        }
117        else {
118                if ($rdata eq 'yes' || $rdata eq 'y') {
119                        $main::ua{'awstats_on'} = 'yes';
120                }
121                elsif ($rdata eq 'no' || $rdata eq 'n') {
122                        $main::ua{'awstats_on'} = 'no';
123                }
124                else {
125                        print STDOUT "\n\tOnly '(y)es' and '(n)o' are allowed!";
126                        return 1;
127                }
128        }
129
130        push_el(\@main::el, 'ask_awstats_on()', 'Ending...');
131
132        return 0;
133}
134
135sub ask_awstats_dyn {
136
137        my $rdata = undef;
138
139        push_el(\@main::el, 'ask_awstats_dyn()', 'Starting...');
140
141        my $qmsg = "\n\tAWStats Mode:\n\tPossible values [d]ynamic and [s]tatic. [dynamic]: ";
142
143        print STDOUT $qmsg;
144
145        $rdata = readline(\*STDIN);
146        chop($rdata);
147
148        if (!defined($rdata) || $rdata eq '') {
149                $main::ua{'awstats_dyn'} = '0';
150        }
151        else {
152                if ($rdata eq 'dynamic' || $rdata eq 'd') {
153                        $main::ua{'awstats_dyn'} = '0';
154                }
155                elsif ($rdata eq 'static' || $rdata eq 's') {
156                        $main::ua{'awstats_dyn'} = '1';
157                }
158                else {
159                        print STDOUT "\n\tOnly '[d]ynamic' or '[s]tatic' are allowed!";
160                        return 1;
161                }
162        }
163
164        push_el(\@main::el, 'ask_awstats_dyn()', 'Ending...');
165        return 0;
166}
167
168sub ask_php_version {
169
170        my $rdata = undef;
171
172        push_el(\@main::el, 'ask_php_version()', 'Starting...');
173
174        my $qmsg = "\n\tUse which PHP Version? (4 or 5). [5]: ";
175
176        print STDOUT $qmsg;
177
178        $rdata = readline(\*STDIN);
179        chop($rdata);
180
181        if (!defined($rdata) || $rdata eq '') {
182                $main::ua{'php_version'} = '5';
183        }
184        else {
185                if ($rdata eq 'php4' || $rdata eq '4') {
186                        $main::ua{'php_version'} = '4';
187                }
188                elsif ($rdata eq 'php5' || $rdata eq '5') {
189                        $main::ua{'php_version'} = '5';
190                }
191                else {
192                        print STDOUT "\n\tOnly 'php(4)' and 'php(5)' are allowed!";
193                        return 1;
194                }
195        }
196
197        push_el(\@main::el, 'ask_php_version()', 'Ending...');
198        return 0;
199}
200
201sub ask_db_pma_user {
202
203        my ($rs, $rdata) = (undef, undef);
204        push_el(\@main::el, 'ask_db_pma_user()', 'Starting...');
205        my $db_user = 'pma';
206
207        my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user. [$db_user]: ";
208        print STDOUT $qmsg;
209        $rdata = readline(\*STDIN); chop($rdata);
210
211        if (!defined($rdata) || $rdata eq '') {
212                $main::ua{'db_pma_user'} = $db_user;
213        } else {
214                $main::ua{'db_pma_user'} = $rdata;
215        }
216
217        push_el(\@main::el, 'ask_db_pma_user()', 'Ending...');
218        return 0;
219}
220
221sub ask_db_pma_password {
222
223        my ($rs, $pass1, $pass2) = (undef, undef, undef);
224        push_el(\@main::el, 'ask_db_pma_password()', 'Starting...');
225
226        my $db_password = undef;
227
228        my $qmsg = "\n\tPlease enter ispCP phpMyAdmin Control user password. [auto generate]: ";
229        $pass1 = read_password($qmsg);
230
231        if (!defined($pass1) || $pass1 eq '') {
232
233                $db_password = gen_sys_rand_num(18);
234                $main::ua{'db_pma_password'} = $db_password;
235                print STDOUT "\tphpMyAdmin Control user password set to: $db_password\n";
236
237        } else {
238                $qmsg = "\tPlease repeat ispCP phpMyAdmin Control user password: ";
239                $pass2 = read_password($qmsg);
240
241                if ($pass1 eq $pass2) {
242                        $main::ua{'db_pma_password'} = $pass1;
243                } else {
244                        print STDOUT "\n\tPasswords do not match!";
245                        return 1;
246                }
247        }
248
249        push_el(\@main::el, 'ask_db_pma_password()', 'Ending...');
250        return 0;
251}
252
253sub welcome_note {
254        my ($rs, $rdata) = (undef, undef);
255
256        push_el(\@main::el, 'welcome_note()', 'Starting...');
257
258        my $welcome_message = <<MSG;
259
260\tWelcome to ispCP '$main::cfg{'Version'}' Update Dialog.
261\tThis program will update your VHCS / ispCP OMEGA system on your server.
262\tPlease make sure you have a backup of your server data.
263
264\tNOTE: During the migration process some or all services might require to be
265\tshut down or restarted.
266
267\tPlease select from which version you want to update:
268\t(1) VHCS 2.4.7 or VHCS 2.4.7.1
269\t(2) VHCS 2.4.8 RC1
270\t(3) ispCP OMEGA 1.0.0 RC2 (incl. b and c)
271\t(0) abort
272MSG
273
274        print STDOUT $welcome_message;
275        print STDOUT "\tYour selection: ";
276
277        $rdata = readline(\*STDIN);
278        chop($rdata);
279
280        while ($rdata < 0 || $rdata > 3) {
281                print STDOUT "\tPlease select an item mentioned above: ";
282                $rdata = readline(\*STDIN);
283                chop($rdata);
284        }
285
286        $main::ua{'update'} = $rdata;
287
288        if (($main::ua{'update'} eq 1) || ($main::ua{'update'} eq 2)) {
289
290                my $vhcs_update_msg = <<MSG;
291
292\tMake sure you have installed ispCP OMEGA first as described in the INSTALL
293\tdocument.
294
295\tContinue?
296\t(1) Yes
297\t(0) No
298MSG
299
300                print STDOUT $vhcs_update_msg;
301                print STDOUT "\tYour selection: ";
302
303                $rdata = readline(\*STDIN);
304                chop($rdata);
305
306                while ($rdata < 0 || $rdata > 1) {
307                        print STDOUT "\tPlease select an item mentioned above: ";
308                        $rdata = readline(\*STDIN);
309                        chop($rdata);
310                }
311
312                # Set to 0 if not ready
313                if ($rdata == 0) {
314                        $main::ua{'update'} = $rdata;
315                }
316        }
317
318        push_el(\@main::el, 'welcome_note()', 'Ending...');
319
320        return 0;
321}
322
323sub stop_services {
324        push_el(\@main::el, 'stop_services()', 'Starting...');
325    my ($lock_file) = @_;
326
327    if (-e $lock_file) {
328        exit_werror("\tVHCS2's backups engine is currently running. Aborting...");
329    }
330
331    if ( -e "/etc/init.d/vhcs2_daemon" ) {
332        print STDOUT "\t";
333        sys_command("/etc/init.d/vhcs2_daemon stop");
334    }
335
336    if ( -e "/etc/init.d/ispcp_daemon" ) {
337        print STDOUT "\t";
338        sys_command("$main::cfg{'CMD_ISPCPD'} stop");
339    }
340
341    if ( -e "/etc/init.d/ispcp_network" ) {
342        print STDOUT "\t";
343        sys_command("$main::cfg{'CMD_ISPCPN'} stop");
344    }
345
346        push_el(\@main::el, 'stop_services()', 'Ending...');
347    return 0;
348}
349
350sub start_services {
351
352    sys_command("$main::cfg{'CMD_ISPCPD'} start");
353    sys_command("$main::cfg{'CMD_ISPCPN'} start");
354    sleep(2);
355
356    #Restart servers to make them use the newly generated config
357    sys_command("$main::cfg{'CMD_HTTPD'} restart");
358    sleep(2);
359    sys_command("$main::cfg{'CMD_MTA'} restart");
360    sleep(2);
361    if (-e "$main::cfg{'CMD_NAMED'}") {
362        sys_command("$main::cfg{'CMD_NAMED'} restart");
363        sleep(2);
364    }
365    sys_command("$main::cfg{'CMD_POP'} restart");
366    sleep(2);
367    if (-e "$main::cfg{'CMD_POP_SSL'}") {
368        sys_command("$main::cfg{'CMD_POP_SSL'} restart");
369        sleep(2);
370    }
371    sys_command("$main::cfg{'CMD_IMAP'} restart");
372    sleep(2);
373    if (-e "$main::cfg{'CMD_IMAP_SSL'}") {
374        sys_command("$main::cfg{'CMD_IMAP_SSL'} restart");
375        sleep(2);
376    }
377    sys_command("$main::cfg{'CMD_FTPD'} restart");
378    sleep(2);
379    sys_command("$main::cfg{'CMD_AUTHD'} restart");
380
381    return 0;
382}
383
384sub rebuild_configs {
385        push_el(\@main::el, 'rebuild_configs()', 'Starting...');
386        if ($main::ua{'update'} ge 1) {
387                do 'ispcp-setup';
388        }
389
390        my $rs = undef;
391
392        # The folowing functions are specified in 'ispcp-setup'
393        $rs = setup_crontab();
394        return 1 if ($rs != 0);
395
396        $rs = setup_named();
397        return 2 if ($rs != 0);
398
399        $rs = setup_php_master_user_dirs();
400        return 3 if ($rs != 0);
401
402        $rs = setup_php();
403        return 4 if ($rs != 0);
404
405        $rs = setup_httpd();
406        return 5 if ($rs != 0);
407
408        $rs = setup_mta();
409        return 6 if ($rs != 0);
410
411        $rs = setup_po();
412        return 7 if ($rs != 0);
413
414        $rs = setup_ftpd();
415        return 8 if ($rs != 0);
416
417        $rs = setup_ispcpd();
418        return 9 if ($rs != 0);
419
420        push_el(\@main::el, 'rebuild_configs()', 'Ending...');
421        return 0;
422}
423
424sub migrate_vhcs2 {
425        push_el(\@main::el, 'migrate_vhcs2()', 'Starting...');
426
427        my ($rdata, $rs, $sql) = (undef, undef, undef);
428
429    print STDOUT "\tDropping empty ispcp table...";
430
431    ($rs, $rdata) = doSQL("DROP DATABASE IF EXISTS `ispcp`;");
432
433    if ($rs != 0) {
434        print STDOUT "failed!\n";
435        exit_werror($rdata, $rs);
436    }
437
438    print STDOUT "done\n";
439
440    print STDOUT "\tCreating new database...";
441
442    if (sys_command("mysqladmin -u\'$main::db_user\' -p\'$main::db_pwd\' create ispcp ") != 0) {
443        print STDOUT "failed!\n";
444        exit_werror();
445    }
446
447    print STDOUT "done\n";
448
449    print STDOUT "\tCopying database...";
450
451    if (sys_command("mysqldump --opt -u\'$main::db_user\' -p\'$main::db_pwd\' $main::vhcs2{'DATABASE_NAME'} | mysql -u\'$main::db_user\' -p\'$main::db_pwd\' $main::db_name") != 0) {
452        print STDOUT "failed!\n";
453        exit_werror();
454    }
455
456    print STDOUT "done\n";
457
458    print STDOUT "\tUpgrading database structure...";
459
460        # Update from VHCS 2.4.7
461        if ($main::ua{'update'} eq 1) {
462                ($rs, $rdata) = get_file("$main::cfg{'ROOT_DIR'}/engine/setup/vhcs2.4.7-ispcp.sql");
463                return $rs if ($rs != 0);
464        }
465        # Update from VHCS 2.4.8
466        elsif ($main::ua{'update'} eq 2) {
467                ($rs, $rdata) = get_file("$main::cfg{'ROOT_DIR'}/engine/setup/vhcs2.4.8-ispcp.sql");
468                return $rs if ($rs != 0);
469        }
470
471        $rdata =~ s/\{DATABASE\}/$main::db_name/gi;
472        $rs = store_file("/tmp/db.sql", $rdata, 'root', 'root', 0644);
473        return $rs if ($rs != 0);
474
475        $rs = sys_command("mysql -u\'$main::db_user\' -p\'$main::db_pwd\' < /tmp/db.sql");
476        if ($rs != 0) {
477        print STDOUT "failed!\n";
478                exit_werror("SQL Update failed.");
479        }
480
481    print STDOUT "\tdone\n";
482
483        push_el(\@main::el, 'migrate_vhcs2()', 'Ending...');
484        return 0;
485}
486
487sub remove_vhcs2 {
488        my ($rs, $cmd, $rdata) = (undef, undef, undef);
489
490        push_el(\@main::el, 'remove_vhcs2()', 'Starting...');
491
492        print STDOUT "\tNow you can remove VHCS2. Do you want to remove VHCS2 auomaticly? (yes|no) [yes]: ";
493        $rdata = readline(\*STDIN);
494        chop($rdata);
495
496        if (!defined($rdata) || $rdata eq '') {
497                $rdata = 'yes';
498        }
499
500        # Remove VHCS2 files
501        if ($rdata eq 'yes') {
502                # Get vhcs2.conf
503                $rs = get_conf($main::vhcs2conf);
504                return $rs if ($rs != 0);
505
506                # Remove VHCS2 Web/Engine folder
507                print STDOUT "\tRemoving $main::vhcs2{'ROOT_DIR'}...";
508                del_dir($main::vhcs2{'ROOT_DIR'});
509                print STDOUT "done\n";
510
511                # Remove VHCS2 Config folder
512                print STDOUT "\tRemoving $main::vhcs2{'CONF_DIR'}...";
513                del_dir($main::vhcs2{'CONF_DIR'});
514                print STDOUT "done\n";
515
516                # Remove VHCS2 Log folder
517                print STDOUT "\tRemoving $main::vhcs2{'LOG_DIR'}...";
518                del_dir($main::vhcs2{'LOG_DIR'});
519                print STDOUT "done\n";
520
521                # Remove VHCS2 Postfix folders
522                print STDOUT "\tRemoving $main::vhcs2{'MTA_VIRTUAL_CONF_DIR'}...";
523                del_dir($main::vhcs2{'MTA_VIRTUAL_CONF_DIR'});
524                print STDOUT "done\n";
525
526                # Remove VHCS2 logrotation
527                print STDOUT "\tRemoving logrotation...";
528                del_file("/etc/logrotate.d/vhcs2");
529                print STDOUT "done\n";
530
531                # Remove Bind files
532                print STDOUT "\tRemoving old bind files...";
533                del_file("/etc/bind/vhcs.conf");
534
535                # Remove old Include if exists
536                ($rs, $rdata) = get_file("/etc/bind/named.conf");
537                if ($rs != 0) {
538                print STDOUT "failed!\n";
539                exit_werror("Could not open /etc/bind/named.conf");
540        }
541
542                $rdata =~ s/include "\/etc\/bind\/vhcs.conf";//gi;
543                $rs = store_file("/etc/bind/named.conf", $rdata, 'root', 'root', 0644);
544                if ($rs != 0) {
545                print STDOUT "failed!\n";
546                exit_werror("Could not store /etc/bind/named.conf");
547        }
548                print STDOUT "done\n";
549
550                # Remove VHCS2 crontab
551                print STDOUT "\tDo you really want to remove crontab? All custom entries will be deleted. (yes|no) [no]: ";
552                $rdata = readline(\*STDIN);
553                chop($rdata);
554
555                if (!defined($rdata) || $rdata eq '') {
556                        $rdata = 'no';
557                }
558                if ($rdata eq 'yes') {
559                        print STDOUT "\tRemoving crontab...";
560                        sys_command("crontab -r");
561                        print STDOUT "done\n";
562                }
563
564                # Remove VHCS2 apache files
565                print STDOUT "\tRemoving apache vhost file...";
566                if ( -e "/usr/sbin/a2dissite" ) {
567                        $rs = sys_command("/usr/sbin/a2dissite vhcs2.conf");
568
569                        if ($rs == 0) {
570                                $rs = sys_command("unlink $main::vhcs2{'APACHE_CONF_FILE'}");
571                        if ($rs != 0) {
572                                print STDOUT "failed!\n";
573                                exit_werror();
574                        }
575                    }
576                }
577                else {
578                    $rs = sys_command("unlink /etc/apache2/sites-enabled/vhcs2.conf");
579                    if ($rs != 0) {
580                        print STDOUT "failed!\n";
581                        exit_werror();
582                    }
583                }
584                print STDOUT "done\n";
585
586                # Restart apache
587                $cmd = $main::cfg{'CMD_HTTPD'};
588                sys_command_rs("$cmd stop");
589                sleep(5);
590            sys_command_rs("$cmd start");
591            sleep(5);
592
593                # Remove VHCS2 Daemons
594                if (-e "/usr/sbin/vhcs2-mkdirs.pl") {
595                        print STDOUT "\tRemoving vhcs2-mkdirs.pl";
596                        del_file("/usr/sbin/vhcs2-mkdirs.pl");
597                }
598
599                # Remove VHCS2 Daemons
600                print STDOUT "\tRemoving Daemons";
601                del_file($main::vhcs2{'CMD_VHCS2D'});
602                del_file($main::vhcs2{'CMD_VHCS2N'});
603
604        }
605
606        push_el(\@main::el, 'remove_vhcs2()', 'Ending...');
607        return 0;
608}
609
610sub update_pma {
611        push_el(\@main::el, 'update_pma()', 'Starting...');
612
613        my ($rs, $cfg, $cfg_tpl, $sql, $rdata) = (undef, undef, undef, undef, undef);
614        my $hostname = $main::cfg{'DATABASE_HOST'};
615
616        #
617        # PMA user for SQL
618        #
619
620        $rs = ask_db_pma_user();
621        return $rs if ($rs != 0);
622
623        do {
624                $rs = ask_db_pma_password();
625        } while ($rs == 1);
626
627        my $pma_sql_user = $main::ua{'db_pma_user'};
628        my $pma_sql_password = $main::ua{'db_pma_password'};
629
630        $sql = "delete from tables_priv where Host = '$main::cfg{'SERVER_HOSTNAME'}' and Db = '$main::cfg{'DATABASE_NAME'}' and User = '$pma_sql_user'";
631
632        ($rs, $rdata) = doSQL($sql);
633        return $rs if ($rs != 0);
634
635        $sql = " delete from user where Host = '$hostname' and User = '$pma_sql_user'";
636
637        ($rs, $rdata) = doSQL($sql);
638        return $rs if ($rs != 0);
639
640        $sql = "flush privileges";
641
642        ($rs, $rdata) = doSQL($sql);
643        return $rs if ($rs != 0);
644
645        $sql = "GRANT USAGE ON mysql.* TO \'$pma_sql_user\'\@\'$hostname\' IDENTIFIED BY \'$pma_sql_password\';";
646
647        ($rs, $rdata) = doSQL($sql);
648        return $rs if ($rs != 0);
649
650        $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\';";
651
652        ($rs, $rdata) = doSQL($sql);
653        return $rs if ($rs != 0);
654
655        $sql = "GRANT SELECT ON mysql.db TO \'$pma_sql_user\'\@\'$hostname\';";
656
657        ($rs, $rdata) = doSQL($sql);
658        return $rs if ($rs != 0);
659
660        $sql = "GRANT SELECT ON mysql.host TO \'$pma_sql_user\'\@\'$hostname\';";
661
662        ($rs, $rdata) = doSQL($sql);
663        return $rs if ($rs != 0);
664
665        $sql = "GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO \'$pma_sql_user\'\@\'$hostname\';";
666
667        ($rs, $rdata) = doSQL($sql);
668        return $rs if ($rs != 0);
669
670        #
671        # Insert pma user and password to config file
672        # together with some other information
673        #
674
675        my $cfg_dir = "$main::cfg{'GUI_ROOT_DIR'}/tools/pma/";
676        my $tmp_dir = "$main::cfg{'GUI_ROOT_DIR'}/phptmp";
677
678        my $blowfish = gen_sys_rand_num(31);
679        $blowfish =~ s/'/\\'/gi;
680
681        ($rs, $cfg_tpl) = get_tpl($cfg_dir, 'config.inc.php');
682
683        return $rs if ($rs != 0);
684
685        my %tag_hash = (
686                                        '{PMA_USER}' => $pma_sql_user,
687                                        '{PMA_PASS}' => $pma_sql_password,
688                                        '{HOSTNAME}' => $main::cfg{'DATABASE_HOST'},
689                                        '{TMP_DIR}'  => $tmp_dir,
690                                        '{BLOWFISH}' => $blowfish
691                                   );
692
693        ($rs, $cfg) = prep_tpl(\%tag_hash, $cfg_tpl);
694
695        return $rs if ($rs != 0);
696
697        $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);
698
699        return $rs if ($rs != 0);
700
701        push_el(\@main::el, 'update_pma()', 'Ending...');
702        return 0;
703}
704
705sub patch_ispcp_rc2 {
706        push_el(\@main::el, 'patch_ispcp_rc2()', 'Starting...');
707
708        my ($rs, $rdata) = (undef, undef);
709
710        print STDOUT "\tUpgrading system values ...";
711
712        # PHP Version
713        do {
714                $rs = ask_php_version();
715        } while ($rs == 1);
716
717        # AWStats questions
718        do {
719                $rs = ask_awstats_on();
720        } while ($rs == 1);
721
722        if ($main::ua{'awstats_on'} eq 'yes') {
723                do {
724                        $rs = ask_awstats_dyn();
725                } while ($rs == 1);
726        } else {
727                # Just a dummy to prevent warnings
728                $main::ua{'awstats_dyn'} = 0;
729        }
730
731        # update ispcp.conf
732        $main::cfg_file = '/etc/ispcp/ispcp.conf';
733        $rs = get_conf();
734        if ($rs != 0) {
735                exit_werror("failed to get /etc/ispcp/ispcp.conf!");
736        }
737        # copy changed variables to new ispcp.conf
738        $rs = set_conf_val('DEFAULT_ADMIN_ADDRESS', $main::cfg{'DEFAULT_ADMIN_ADDRESS'});
739        return $rs if ($rs != 0);
740        $rs = set_conf_val('SERVER_HOSTNAME', $main::cfg{'SERVER_HOSTNAME'});
741        return $rs if ($rs != 0);
742        $rs = set_conf_val('BASE_SERVER_IP', $main::cfg{'BASE_SERVER_IP'});
743        return $rs if ($rs != 0);
744        $rs = set_conf_val('BASE_SERVER_VHOST', $main::cfg{'BASE_SERVER_VHOST'});
745        return $rs if ($rs != 0);
746        $rs = set_conf_val('DATABASE_HOST', $main::cfg{'DATABASE_HOST'});
747        return $rs if ($rs != 0);
748        $rs = set_conf_val('DATABASE_NAME', $main::cfg{'DATABASE_NAME'});
749        return $rs if ($rs != 0);
750        $rs = set_conf_val('DATABASE_USER', $main::cfg{'DATABASE_USER'});
751        return $rs if ($rs != 0);
752        $rs = set_conf_val('MYSQL_PREFIX', $main::cfg{'MYSQL_PREFIX'});
753        return $rs if ($rs != 0);
754        $rs = set_conf_val('MYSQL_PREFIX_TYPE', $main::cfg{'MYSQL_PREFIX_TYPE'});
755        return $rs if ($rs != 0);
756        $rs = set_conf_val('FTPD_CONF_FILE', $main::cfg{'FTPD_CONF_FILE'});
757        return $rs if ($rs != 0);
758        $rs = set_conf_val('SECONDARY_DNS', $main::cfg{'SECONDARY_DNS'});
759        return $rs if ($rs != 0);
760        $rs = set_conf_val('MTA_MAILBOX_MIN_UID', $main::cfg{'MTA_MAILBOX_MIN_UID'});
761        return $rs if ($rs != 0);
762        $rs = set_conf_val('MTA_MAILBOX_UID', $main::cfg{'MTA_MAILBOX_UID'});
763        return $rs if ($rs != 0);
764        $rs = set_conf_val('MTA_MAILBOX_GID', $main::cfg{'MTA_MAILBOX_GID'});
765        return $rs if ($rs != 0);
766        $rs = set_conf_val('APACHE_SUEXEC_MIN_UID', $main::cfg{'APACHE_SUEXEC_MIN_UID'});
767        return $rs if ($rs != 0);
768        $rs = set_conf_val('APACHE_SUEXEC_MIN_GID', $main::cfg{'APACHE_SUEXEC_MIN_GID'});
769        return $rs if ($rs != 0);
770
771        $rs = set_conf_val('AWSTATS_ACTIVE', $main::ua{'awstats_on'});
772        return $rs if ($rs != 0);
773        $rs = set_conf_val('AWSTATS_MODE', $main::ua{'awstats_dyn'});
774        return $rs if ($rs != 0);
775        $rs = set_conf_val('PHP_VERSION', $main::ua{'php_version'});
776        return $rs if ($rs != 0);
777
778        # store into /etc/ispcp/ispcp.conf
779        $rs = store_conf();
780        if ($rs != 0) {
781                print STDOUT "failed!\n";
782                exit_werror("Storing new ispcp.conf failed!");
783        }
784        print STDOUT "\tdone\n";
785
786        # database upgrade
787    print STDOUT "\tUpgrading database structure...";
788
789        ($rs, $rdata) = get_file("$main::cfg{'ROOT_DIR'}/engine/setup/ispcp1.0.0rc2-ispcp.sql");
790        return $rs if ($rs != 0);
791
792        $rdata =~ s/\{DATABASE\}/$main::db_name/gi;
793        $rs = store_file("/tmp/db.sql", $rdata, 'root', 'root', 0644);
794        return $rs if ($rs != 0);
795
796        $rs = sys_command("mysql -u\'$main::db_user\' -p\'$main::db_pwd\' < /tmp/db.sql");
797        if ($rs != 0) {
798        print STDOUT "failed!\n";
799                exit_werror("SQL Update failed.");
800        }
801
802    print STDOUT "done\n";
803
804    # Rebuild system configs:
805    print STDOUT "\tRebuilding system configurations...";
806
807        $rs = rebuild_configs();
808
809        if ($rs != 0) {
810        print STDOUT "failed!\n";
811                exit_werror("Config Rebuild failed.");
812        }
813
814        print STDOUT "done\n";
815
816        # Update PMA's config.inc.php
817        print STDOUT "\tUpdating PMA's config.inc.php...";
818
819        $rs = update_pma();
820
821        if ($rs != 0) {
822        print STDOUT "failed!\n";
823                exit_werror("Updating PMA's config.inc.php failed.");
824        }
825
826        print STDOUT "done\n";
827
828
829
830        push_el(\@main::el, 'patch_ispcp_rc2()', 'Ending...');
831        return 0;
832}
833
834sub prepare_update {
835        my ($rs, $rdata) = (undef, undef);
836
837        push_el(\@main::el, 'user_dialog()', 'Starting...');
838
839        $rs = welcome_note();
840
841        return $rs if ($rs != 0);
842
843        # Abort
844        if ($main::ua{'update'} eq 0) {
845                exit_werror("\tScript was aborted by user");
846        }
847        # VHCS update
848        elsif (($main::ua{'update'} eq 1) || ($main::ua{'update'} eq 2)) {
849
850                # look up vhcs2.conf
851                $rs = ask_vhcs2conf();
852
853                if ($rs != 0) {
854                        my $el_data = pop_el(\@main::el);
855                        my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
856
857                        print STDERR "$msg\n";
858
859                        exit 1;
860                }
861                stop_services("/tmp/vhcs2-backup-all.lock");
862                $rs = migrate_vhcs2();
863                return $rs if ($rs != 0);
864                $rs = remove_vhcs2();
865                return $rs if ($rs != 0);
866        }
867        # ispCP 1.0.0 RC2 Update
868        elsif ($main::ua{'update'} eq 3) {
869                stop_services("/tmp/vhcs2-backup-all.lock");
870
871                # get ispcp.old.conf
872                $main::cfg_file = '/etc/ispcp/ispcp.old.conf';
873                $rs = get_conf();
874                if ($rs != 0) {
875                        do {
876                                print STDOUT "\tPlease enter path to ispcp.old.conf [/etc/ispcp/ispcp.old.conf]: ";
877
878                                $rdata = readline(\*STDIN);
879                                chop($rdata);
880
881                                $main::cfg_file = $rdata;
882                                $rs = get_conf();
883                        } while ($rs == 0);
884                }
885
886                $rs = patch_ispcp_rc2();
887                return $rs if ($rs != 0);
888
889                # set permissions
890                my $cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-gui-permissions.sh";
891                $rs = sys_command($cmd);
892                return $rs if ($rs != 0);
893
894                $cmd = "$main::cfg{'CMD_SHELL'} $main::cfg{'ROOT_DIR'}/engine/setup/set-engine-permissions.sh";
895                $rs = sys_command($cmd);
896                return $rs if ($rs != 0)
897        }
898
899        # re-create config files
900        print STDOUT "\tRebuilding customers ...\n";
901
902        $rs = sys_command_rs("perl $main::cfg{'ROOT_DIR'}/engine/ispcp-rqst-mngr");
903        if ($rs != 0) {
904        print STDOUT "failed!\n";
905                exit_werror("Rebuild failed.");
906        }
907
908        print STDOUT "done\n";
909
910        # start services
911        start_services();
912
913        exit 0;
914
915        push_el(\@main::el, 'user_dialog()', 'Ending...');
916}
917
918sub exit_werror {
919    my ($msg, $code) = @_;
920
921    if (!defined($code) || $code <= 0 ) {
922        $code = 1;
923    }
924
925    if (defined($msg) && $msg ne '' ) {
926        print STDERR "\n$msg\n";
927    }
928
929    exit $code;
930}
931
932################################################################################
933##                                    MAIN                                    ##
934################################################################################
935
936my $rs = undef;
937
938$rs = prepare_update();
939
940if ($rs != 0) {
941        my $el_data = pop_el(\@main::el);
942        my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
943
944        print STDERR "$msg\n";
945
946        exit 1;
947}
948
949$rs = update_ispcp();
950
951if ($rs != 0) {
952        my $el_data = pop_el(\@main::el);
953        my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
954
955        print STDERR "$msg\n";
956
957        exit 1;
958}
959
960$rs = update_shut_down();
961
962if ($rs != 0) {
963        my $el_data = pop_el(\@main::el);
964        my ($sub_name, $msg) = split(/$main::el_sep/, $el_data);
965
966        print STDERR "$msg\n";
967
968        exit 1;
969}
Note: See TracBrowser for help on using the browser.