-
Notifications
You must be signed in to change notification settings - Fork 2
/
cpeval2
3623 lines (3143 loc) · 130 KB
/
cpeval2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# cpeval2 - Performs a pre-migration evaluation of third-party and cPanel servers
# See COPYRIGHT section in pod_data below or run 'perldoc' on this file for copyright and license information.
use strict;
use warnings;
my $pod_data = << 'END_POD';
=head1 NAME
cpeval2
=head1 DESCRIPTION
Checks account and configuration information on third-party (non-cPanel) source and cPanel destination servers, performs a configuration comparison, and outputs a form ready for sending to a customer to explain any required or recommended changes.
=head1 SYNOPSIS
=for comment
Keep the usage() sub in sync with the options here.
=end comment
=over
=item Mode 1:
B<cpeval2>
=back
=over
=item Mode 2:
B<cpeval2> S<I<INPUTFILE>>
B<cpeval2> S<B<--es> I<INPUTFILE>>
=back
=over
=item Other:
B<cpeval2> S<B<--cpanel-source>>
B<cpeval2> S<B<--create-keys>>
B<cpeval2> S<B<--updateuserdomains>>
B<cpeval2> S<B<--full-help>>
=back
=head1 DEFINITIONS
=over
=item C<INPUTFILE>
An input file is a text file containing cpeval2 prefixed output from "Mode 1" on both source and destination servers, concatenated into a single file. The prefixed output begins with "s:" for the source server, and "d:" for the destination server.
=back
=head1 FLAGS
=over
=item B<--cpanel-source>
Necessary to run cpeval2 in "Mode 1" on a cPanel source server. Without this flag cpeval2 assumes that a cPanel server is the destination.
=item B<--create-keys>
For use only on a destination (cPanel) server. Creates a unique SSH key-pair to be used for a dedicated migration user account on the source server, and provides copy/paste output that can be executed on the source server to create the account. It is automatically used the first time you run cpeval2 on a cPanel server.
=item B<--updateuserdomains>
For use only on a third-party source (non-cPanel) server. Downloads and executes the updateuserdomains-universal script to populate /etc/trueuserdomains. It is automatically used if /etc/trueuserdomains is more than 30 minutes old or does not exist.
=item B<--es>
For use only with "Mode 2", this provides output in Spanish.
=back
=head1 EXAMPLES
=over
=item Run cpeval2 for the first time on a third-party source or cPanel destination server (Mode 1):
B<cpeval2>
=item Run cpeval2 for the first time on a cPanel source server (Mode 1):
B<cpeval2 --cpanel-source>
=item Run cpeval2 after "Mode 1" prefixed output from both servers has been copied into "cpeval2-compare.txt":
B<cpeval2 cpeval2-compare.txt>
=item Run cpeval2 after "Mode 1" prefixed output from both servers has been copied into "cpeval2-compare.txt", and provide the output in Spanish:
B<cpeval2 --es cpeval2-compare.txt>
=item Download and run the updateuserdomains-universal script:
B<cpeval2 --updateuserdomains>
=back
=head1 COPYRIGHT
This software is Copyright 2018 by cPanel, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THE SOFTWARE LICENSED HEREUNDER IS PROVIDED "AS IS" AND CPANEL HEREBY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, RELATING TO THE SOFTWARE, ITS THIRD PARTY COMPONENTS, AND ANY DATA ACCESSED THEREFROM, OR THE ACCURACY, TIMELINESS, COMPLETENESS, OR ADEQUACY OF THE SOFTWARE, ITS THIRD PARTY COMPONENTS, AND ANY DATA ACCESSED THEREFROM, INCLUDING THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. CPANEL DOES NOT WARRANT THAT THE SOFTWARE OR ITS THIRD PARTY COMPONENTS ARE ERROR-FREE OR WILL OPERATE WITHOUT INTERRUPTION. IF THE SOFTWARE, ITS THIRD PARTY COMPONENTS, OR ANY DATA ACCESSED THEREFROM IS DEFECTIVE, YOU ASSUME THE SOLE RESPONSIBILITY FOR THE ENTIRE COST OF ALL REPAIR OR INJURY OF ANY KIND, EVEN IF CPANEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DEFECTS OR DAMAGES. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY CPANEL, ITS AFFILIATES, LICENSEES, DEALERS, SUB-LICENSORS, AGENTS OR EMPLOYEES SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF ANY WARRANTY.
=cut
END_POD
# ADDING CHECKS
# There are 4 things that need to be done. Using the PHP check as an example:
# When run WITHOUT an input file (e.g., lwp-request x.x.x.x/cpeval2 | perl):
# (1) print_php_info() # prints PHP: 5.3.24
# (2) print_prefixed_php_info() # prints s:Ensim:PHP:5.1
# When run WITH an input file (e.g., ./cpeval2 outfile):
# (3) parse_output_file()
# (4) print_parsed_php_info( $src_php, $dst_php )
use Getopt::Long;
use IPC::Open3;
use IO::Socket::INET;
use Pod::Usage;
use POSIX qw( strftime );
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
my $VERSION = '1.40';
my $OPTS = opts_get();
create_cpmig_user() if $OPTS->{'createuser'};
my $DEBUG = 0;
my $PANEL_REGEX = 's:(?:cPanel|Plesk[0-9]+(?:SMB)?|Ensim|DirectAdmin)';
my $PREFIX; # d: or s:Plesk9 or s:DirectAdmin, etc.
my $APACHE_BIN;
my $PYTHON_BIN;
my $IS_CPANEL = 0;
my $IS_CPANEL_DEST = 0;
my $IS_CPANEL_SOURCE = 0;
my $IS_PLESK = 0;
my $IS_PLESK_SMB10 = 0;
my $IS_ENSIM = 0;
my $IS_DA = 0;
my $SRC_PANEL; # cPanel, Ensim, DirectAdmin, Plesk8, Plesk10SMB, etc.
my $SRC_PANEL_NOVERSION; # cPanel, Ensim, DirectAdmin, Plesk
my $SRC_PANEL_VERSION; # e.g. "Plesk 12.0.18"
my $DST_PANEL_VERSION; # e.g. "cPanel 11.44.0.18"
my $CPANEL_VERSION; # e.g. "11.44.0.18"
my $OS_DIST; # e.g. "CentOS"
my $OS_VERSION; # e.g. "7.2"
my ( @HOSTING_TYPE_FORWARD, @HOSTING_TYPE_NOHOSTING );
my @PLESK_RESELLER_USERNAME_CONFLICTS;
my $HAS_PGSQL = 0;
my $EULA_ACCEPTED = 0;
my ( $PLESK_MAJOR_VERSION, $PLESK_MINOR_VERSION );
my @BADUSERS; # if mysql username conflicts are detected, skip any bad users since they need renaming anyway
my $TUD_BY_USER;
my $TUD_BY_DOMAIN;
my $TUD_USER_NUM = 0;
get_control_panel_and_set_prefix();
verify_mysql_connectivity();
my $TICKET = get_ticket();
my $CPMIGUSER = 'cpmig' . $TICKET;
if ( $OPTS->{'createkeys'} ) {
die "create-keys should only be run on the cPanel destination host.\n" unless $IS_CPANEL_DEST;
create_cpmig_keypair( $CPMIGUSER, $TICKET );
exit;
}
if ( $OPTS->{'updateuserdomains'} ) {
die "cpeval2 --updateuserdomains is only for non-cPanel servers.\nUse /scripts/updateuserdomains instead.\n" if $IS_CPANEL;
}
## behave like the original cpeval
if ( !$OPTS->{'inputfile'} ) {
( $TUD_BY_USER, $TUD_BY_DOMAIN ) = _get_trueuserdomains_hashrefs();
$TUD_USER_NUM = scalar keys %{$TUD_BY_USER};
print_control_panel_info();
print_os_info();
print_perl_info();
print_mysql_info();
print_php_info();
print_apache_info();
print_cpu_info();
print_mem_info();
print_number_of_accounts();
print_dedicated_ipaddrs();
print_mysql_db_count();
print_postgres_db_count();
check_destination_var_usage();
print_custom_apache_modules();
print_custom_php_modules();
print_htype_fwd();
print_htype_none();
print_plesk_duplicate_email_users();
print_reseller_username_conflicts();
print "\n" . '-' x 40 . "\n\n";
print_prefixed_panel_info();
print_prefixed_os_info();
print_prefixed_php_info();
print_prefixed_mysql_info();
print_prefixed_bad_username_info(); # this sub MUST come before print_mysql_username_conflict_info();
print_prefixed_duplicate_users();
print_prefixed_dedicated_ip_addr_info();
print_prefixed_hosting_types();
print_prefixed_tomcat_info();
print_prefixed_coldfusion_info();
print_prefixed_reseller_username_conflicts();
print_prefixed_user_config_problems();
print_prefixed_php_information();
print_prefixed_cpanel_eula_accepted_check();
print_prefixed_mysql_username_conflict_info();
print_prefixed_mysql_openfileslimit();
print_prefixed_mysql_skip_networking();
print_prefixed_mysql_old_style_passwords_info();
print_prefixed_dns_clustering_info();
}
## parse output file; this prints info we can just copy/paste into the ticket
else {
parse_output_file( $OPTS->{'inputfile'} );
}
unless ( $OPTS->{'inputfile'} ) {
print_header('DISK SPACE');
print "Please review this output now, compare with the output from the other server, and check for possible issues:\n\n";
print `df -Ph | column -t | head -1 ; df -Ph | column -t | sort | uniq | egrep -v '^Filesystem|/var/named/run-root/var/run/dbus|/var/named/chroot|/usr/local/psa/handlers/|/virtfs/| /tmp\$'`;
print "\nA few things to keep in mind are:\n";
print " * pkgacct-* packages accounts in /home . Is /home on /, or is it separate?\n";
print " * Need to change the partition that accounts are packaged to? Check the 'MigrationsReference' article\n";
print " * Is more space being used on the source than what is available on the destination?\n";
print " * If there's, say, 50GB free on the source, the largest account that can be copied is a little less than 25GB (half of 50)\n";
if ($IS_PLESK) {
print " * Plesk stores users' data under /var [ /var/www/vhosts/\${DOMAIN}/ ] [ /var/qmail/mailnames/\${DOMAIN}/ ] [ /var/lib/mysql ]\n";
if ( $^O =~ /freebsd/i ) {
print " * commonly, customers with FreeBSD will have different locations for their services\n"
. " * if pkgacct fails to find the locations of the user's data, you will need to get the locations of the data from /etc/psa/psa.conf, then create directories and symlinks so pkgacct can package correctly\n"
. " * variables to grep for in the psa.conf are HTTPD_VHOSTS_D, QMAIL_MAILNAMES_D, MYSQL_VAR_D, PGSQL_DATA_D\n";
}
}
}
if ( $IS_CPANEL_DEST and -f '/var/cpanel/transfers_devel' ) {
print "\n\n!! /var/cpanel/transfers_devel exists! Server may be using _DEVEL migrations scripts !!\n";
}
submit_stats_info();
check_for_missing_scp();
auto_create_keypair( $CPMIGUSER, $TICKET ) unless $OPTS->{'inputfile'};
print_dest_existing_accounts();
print "\n";
exit 0;
##########
sub _version_cmp {
## no critic (AmbiguousNames) # Not ambiguous, just simple.
my ( $first, $second ) = @_;
my ( $a1, $b1, $c1, $d1 ) = split /[\._]/, $first;
my ( $a2, $b2, $c2, $d2 ) = split /[\._]/, $second;
for my $ref ( \$a1, \$b1, \$c1, \$d1, \$a2, \$b2, \$c2, \$d2, ) { # Fill empties with 0
$$ref = 0 unless defined $$ref;
}
return $a1 <=> $a2 || $b1 <=> $b2 || $c1 <=> $c2 || $d1 <=> $d2;
}
sub version_compare {
# example: return if version_compare($ver_string, qw( >= 1.2.3.3 ));
# Must be no more than four version numbers separated by periods and/or underscores.
my ( $ver1, $mode, $ver2 ) = @_;
return if ( !defined($ver1) || ( $ver1 =~ /[^\._0-9]/ ) );
return if ( !defined($ver2) || ( $ver2 =~ /[^\._0-9]/ ) );
# Shamelessly copied the comparison logic out of Cpanel::Version::Compare
my %modes = (
'>' => sub {
return if $_[0] eq $_[1];
return _version_cmp(@_) > 0;
},
'<' => sub {
return if $_[0] eq $_[1];
return _version_cmp(@_) < 0;
},
'==' => sub { return $_[0] eq $_[1] || _version_cmp(@_) == 0; },
'!=' => sub { return $_[0] ne $_[1] && _version_cmp(@_) != 0; },
'>=' => sub {
return 1 if $_[0] eq $_[1];
return _version_cmp(@_) >= 0;
},
'<=' => sub {
return 1 if $_[0] eq $_[1];
return _version_cmp(@_) <= 0;
}
);
return if ( !exists $modes{$mode} );
return $modes{$mode}->( $ver1, $ver2 );
}
sub print_news_cpanel {
print q{};
return;
}
sub print_news_plesk {
# print q{ !! PLESK BLOCKERS !!
# };
#
# sleep 3;
return;
}
sub print_news_ensim {
# No current blockers listed. Last removed was Case 107517.
return;
}
sub print_news_da {
# print q{ !! DA BLOCKERS !!
# };
#
# sleep 3;
return;
}
sub mysql_test {
my $mysql_output = `mysql -e 'select 1' 2>&1`;
return $mysql_output;
}
sub print_header {
my $text = shift;
print "\n\n" . '=' x 50 . "\n$text\n" . '=' x 50 . "\n\n";
return;
}
## determine the control panel, and set the prefix
sub get_control_panel_and_set_prefix { ## no critic (ExcessComplexity)
# CPANEL
if ( -f '/usr/local/cpanel/cpanel' ) { ## no critic (CascadingIfElse)
$IS_CPANEL = 1;
if ( $OPTS->{'cpanelsource'} ) {
$PREFIX = 's:cPanel:';
$IS_CPANEL_SOURCE = 1;
}
else {
$PREFIX = 'd:';
$IS_CPANEL_DEST = 1;
}
}
# PLESK
elsif ( -f '/usr/local/psa/version' ) {
if ( -d '/etc/sw/keys/keys' ) {
my @dir_contents;
opendir( my $dir_fh, '/etc/sw/keys/keys' );
@dir_contents = grep { !/ \A \. \.? \Z /x } readdir $dir_fh;
closedir $dir_fh;
if (@dir_contents) {
my $plesk_key = pop @dir_contents;
if ( open my $key_fh, '<', "/etc/sw/keys/keys/$plesk_key" ) {
while (<$key_fh>) {
if (/PPA\./) {
die("We're very sorry, but this appears to be a Plesk Automation (PPA) server which is not supported for migration.\n");
}
if (/Small Business Panel 10/) {
$PREFIX = 's:Plesk10SMB:';
$IS_PLESK_SMB10 = 1;
last;
}
}
close $key_fh;
}
}
}
if ( !$PREFIX ) {
if ( open my $psa_fh, '<', '/usr/local/psa/version' ) {
while (<$psa_fh>) {
if (m{ \A (\d+)\.(\d+)? }xms) {
$PLESK_MAJOR_VERSION = $1;
$PLESK_MINOR_VERSION = defined $2 ? $2 : '0';
if ( $PLESK_MAJOR_VERSION == 11 and $PLESK_MINOR_VERSION and $PLESK_MINOR_VERSION >= 5 ) {
# print_plesk_version_unsupported( "${plesk_major_version}.${plesk_minor_version}" );
}
$PREFIX = 's:Plesk' . $PLESK_MAJOR_VERSION . ':';
$IS_PLESK = 1;
}
}
close $psa_fh;
}
}
}
# ENSIM
elsif ( -f '/usr/bin/getapplversion' ) {
$PREFIX = 's:Ensim:';
$IS_ENSIM = 1;
}
# DA
elsif ( -f '/usr/local/directadmin/directadmin' ) {
$PREFIX = 's:DirectAdmin:';
$IS_DA = 1;
}
# Not one of the above
else {
die "[!] Unknown control panel\n";
}
print_news_cpanel() if ($IS_CPANEL);
print_news_plesk() if ( $IS_PLESK or $IS_PLESK_SMB10 );
print_news_ensim() if ($IS_ENSIM);
print_news_da() if ($IS_DA);
return;
}
sub check_trueuserdomains {
my $tud = '/etc/trueuserdomains';
my $dip = '/etc/domainips';
my $uudu = 'http://httpupdate.cpanel.net/cpanelsync/transfers_PUBLIC/pkgacct/updateuserdomains-universal';
my $max_age = 30; #minutes
my $skip_update = 0;
unless ($IS_CPANEL) {
if ( -f $tud ) {
my $age = int( ( time() - ( stat(_) )[9] ) / 60 );
die("${tud} exists, but unable to determine modification time!\n\n") unless defined($age);
if ( not $OPTS->{'updateuserdomains'} and $age <= $max_age ) {
print "\n${tud} is less than ${max_age} minutes old, not auto-updating.\n";
print "Use cpeval2 --updateuserdomains to force an update.\n";
$skip_update = 1;
}
}
if ( $OPTS->{'updateuserdomains'} or not $skip_update ) {
print "${tud} doesn't exist, is more than ${max_age} minutes old, or you forced an update.\n";
print "\nDownloading and running updateuserdomains-universal via curl...\n";
delete local $ENV{'PERL5LIB'}; # Like CPANEL-18856
if ( system( 'curl -s --connect-timeout 30 --max-time 60 ' . $uudu . ' | perl -x' ) != 0 ) {
print "\nDownloading and running updateuserdomains-universal via wget...\n";
if ( system( 'wget --timeout=60 -q -O - ' . $uudu . ' | perl -x' ) != 0 ) {
print "\nFailed to download and run updateuserdomains-universal!\n";
sleep 2;
}
}
}
}
unless ($IS_CPANEL_DEST) {
if ( -f $tud and -z _ ) {
die "\n${tud} exists, but is empty!\n\n";
}
if ( not -f $tud or not -f $dip ) {
die "\n${tud} OR ${dip} missing!\nUse updateuserdomains to generate them.\n\n";
}
}
print "\n";
return;
}
sub check_destination_var_usage {
return unless $IS_CPANEL_DEST;
my $var_usage;
if ( open my $df_fh, '-|', '/bin/df', '-hP', '/var' ) {
while (<$df_fh>) {
# Filesystem Size Used Avail Use% Mounted on
# /dev/simfs 20G 6.2G 14G 31% /
if (m# \A /(?:\S+) \s+ ([0-9A-Z\.]+) \s+ ([0-9A-Z\.]+) \s+ ([0-9A-Z\.]+) \s+ ([0-9]+)% \s+ (\S+) #xms) {
$var_usage = "[Size: $1] [Used: $2] [Avail: $3] [Use%: $4] [Mount point: $5]\n";
}
}
close $df_fh;
}
if ($var_usage) {
print_format( '/var', $var_usage );
}
return;
}
sub print_plesk_version_unsupported {
my $plesk_version = shift;
print "We're very sorry, but the Plesk server is using a version of Plesk that our migrations scripts do not support at this time ($plesk_version).\n\n";
print "Our developers are actively working on support for this version of Plesk. We do not yet have an estimated time of completion.\n";
print "Unfortunately, we will not be able to migrate the accounts at this time. We hope to see support for Plesk $plesk_version soon, and we appreciate your interest in cPanel!\n";
exit;
}
sub verify_mysql_connectivity {
my $mysql_output = mysql_test();
if ( $mysql_output =~ /ERROR/ ) {
# If /root/.my.cnf exists, take no action other than providing a hint as to what the issue may be
if ( -e '/root/.my.cnf' ) {
print "Could not connect to MySQL (query failed: mysql -e 'select 1').\n";
print "/root/.my.cnf already exists. Inspect it manually.\n";
if ( $IS_PLESK and version_compare( $PLESK_MAJOR_VERSION . "." . $PLESK_MINOR_VERSION, '>=', '10.2' ) ) {
print "Hint: try user 'admin' and the password from /usr/local/psa/bin/admin --show-password OR the contents of /etc/psa/.psa.shadow.\n";
}
elsif ( $IS_PLESK or $IS_PLESK_SMB10 ) {
print "Hint: try user 'admin' and the contents of /etc/psa/.psa.shadow.\n";
}
elsif ($IS_DA) {
print "Hint: try the credentials from /usr/local/directadmin/conf/mysql.conf .\n";
}
elsif ($IS_ENSIM) {
print "Hint: try with the user 'root' and the password from this command:\n";
print 'ensim-python -c "import sys ; sys.path.append(\'/usr/lib/opcenter/mysql\') ; import mysqlbe ; print mysqlbe.read_mysqlpass()"' . "\n";
}
elsif ($IS_CPANEL) {
print "Hint: try with mysql user 'root' and the server's root password.\n";
}
else {
print "[!] Unable to determine control panel\n";
}
exit;
}
# If /root/.my.cnf does not exist, attempt to create it unless the server uses cPanel
else {
print "Could not connect to MySQL (/root/.my.cnf does not exist).";
if ($IS_CPANEL) {
print "\n";
}
else {
print "Trying to create /root/.my.cnf now.\n";
}
umask 0077; # so /root/.my.cnf is 0600
if ( $IS_PLESK or $IS_PLESK_SMB10 ) {
if ( -e '/etc/psa/.psa.shadow' ) {
open my $psa_fh, '<', '/etc/psa/.psa.shadow' or die "$!\n";
chomp( my $mysql_password = readline($psa_fh) );
close $psa_fh;
if ( !$mysql_password ) {
die "Could not obtain mysql password from /etc/psa/.psa.shadow\n";
}
else {
open my $mycnf_fh, '>', '/root/.my.cnf' or die "$!\n";
print $mycnf_fh "[client]\nuser=admin\npassword=\"" . $mysql_password . "\"\n";
close $mycnf_fh;
}
}
else {
die "Attempted to obtain mysql password from /etc/psa/.psa.shadow, but it does not appear to exist\n";
}
}
elsif ($IS_DA) {
if ( -e '/usr/local/directadmin/conf/mysql.conf' ) {
open my $mysqlconf_fh, '<', '/usr/local/directadmin/conf/mysql.conf' or die "$!\n";
my $mysql_password;
while (<$mysqlconf_fh>) {
if (m{ \A passwd=(.*) \z }xms) {
chomp( $mysql_password = $1 );
}
}
close $mysqlconf_fh;
if ( !$mysql_password ) {
die "Could not obtain mysql password from /usr/local/directadmin/conf/mysql.conf\n";
}
else {
open my $mycnf_fh, '>', '/root/.my.cnf' or die "$!\n";
print $mycnf_fh "[client]\nuser=da_admin\npassword=\"" . $mysql_password . "\"\n";
close $mycnf_fh;
}
}
else {
die "Attempted to obtain mysql password from /usr/local/directadmin/conf/mysql.conf, but it does not appear to exist\n";
}
}
elsif ($IS_ENSIM) {
chomp( my $mysql_password = `ensim-python -c "import sys ; sys.path.append('/usr/lib/opcenter/mysql') ; import mysqlbe ; print mysqlbe.read_mysqlpass()"` );
if ( !$mysql_password ) {
die 'Unable to determine mysql pass via this command: ' . "ensim-python -c \"import sys ; sys.path.append('/usr/lib/opcenter/mysql') ; import mysqlbe ; print mysqlbe.read_mysqlpass()\"\n";
}
else {
open my $mycnf_fh, '>', '/root/.my.cnf' or die "$!\n";
print $mycnf_fh "[client]\nuser=root\npassword=\"" . $mysql_password . "\"\n";
close $mycnf_fh;
}
}
elsif ($IS_CPANEL) {
die "You will need to manually create /root/.my.cnf\n";
}
else {
die "[!] Unable to determine control panel\n";
}
# After creating /root/.my.cnf, see if we can connect to MySQL now. If not, remove our /root/.my.cnf and exit
my $final_check = mysql_test();
if ( $final_check =~ /ERROR/ ) {
#unlink '/root/.my.cnf' or die "Could not remove our custom /root/.my.cnf\n";
die "Still unable to connect to MySQL, even after creating /root/.my.cnf . Check contents of our custom /root/.my.cnf\n";
}
else {
print "We can now connect to MySQL, proceeding.\n";
}
}
}
return;
}
## print control panel version
sub print_control_panel_info {
my $panel_version;
if ($IS_CPANEL) {
if ( open my $file_fh, '<', '/usr/local/cpanel/version' ) {
chomp( $panel_version = readline $file_fh );
close $file_fh;
}
if ($panel_version) {
if ( $OPTS->{'cpanelsource'} ) {
$SRC_PANEL_VERSION = "cPanel " . $panel_version;
}
else {
$DST_PANEL_VERSION = "cPanel " . $panel_version;
$CPANEL_VERSION = $panel_version;
}
}
else {
$DST_PANEL_VERSION = "cPanel (version unknown)";
}
}
elsif ( $IS_PLESK or $IS_PLESK_SMB10 ) {
if ( open my $file_fh, '<', '/usr/local/psa/version' ) {
while (<$file_fh>) {
if (m{ \A ([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}) }xms) {
$panel_version = $1;
}
}
close $file_fh;
}
if ($panel_version) {
$SRC_PANEL_VERSION = "Plesk " . $panel_version;
}
else {
$SRC_PANEL_VERSION = "Plesk (version unknown)";
}
}
elsif ($IS_ENSIM) {
$panel_version = `/usr/bin/getapplversion` or die("Unable to discern Ensim version");
if ( $panel_version =~ /^([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})-.*$/ ) {
$panel_version = $1;
}
if ($panel_version) {
$SRC_PANEL_VERSION = "Ensim " . $panel_version;
}
else {
$SRC_PANEL_VERSION = "Ensim (version unknown)";
}
}
elsif ($IS_DA) {
$panel_version = `/usr/local/directadmin/directadmin v` or die("Unable to discern DirectAdmin version");
if ( $panel_version =~ /^Version: DirectAdmin v.([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})$/ ) {
$panel_version = $1;
}
if ($panel_version) {
$SRC_PANEL_VERSION = "DirectAdmin " . $panel_version;
}
else {
$SRC_PANEL_VERSION = "DirectAdmin (version unknown)";
}
}
print "[ " . $DST_PANEL_VERSION . " ]\n" if $DST_PANEL_VERSION;
print "[ " . $SRC_PANEL_VERSION . " ]\n" if $SRC_PANEL_VERSION;
return;
}
sub print_os_info {
my $os;
if ( $^O =~ /linux/i ) {
$os = 'Linux';
}
elsif ( $^O =~ /freebsd/i ) {
$os = 'FreeBSD';
}
else {
$os = 'Unknown';
}
if ( $os eq 'Linux' ) {
my @release_files = qw(
adamantix_version
arch-release
conectiva-release
debian_release
debian_version
fedora-release
gentoo-release
immunix-release
knoppix-version
libranet_version
mandrakelinux-release
mandrake-release
pardus-release
redflag-release
redhat-release
redhat_version
slackware-release
slackware-version
SuSE-release
tinysofa-release
trustix-release
turbolinux-release
va-release
yellowdog-release
yoper-release
);
for my $release_file (@release_files) {
my $release_file_path = '/etc/' . $release_file;
if ( -e $release_file_path ) {
if ( open my $rel_fh, '<', $release_file_path ) {
while (<$rel_fh>) {
if (/(\d+\.\d+)/) { $OS_VERSION = $1; last; }
elsif (/(\d+)/) { $OS_VERSION = $1; last; }
}
close $rel_fh;
}
$release_file =~ s/release//g;
$release_file =~ s/version//g;
$release_file =~ s/[-_]//g;
if ( $release_file eq 'redhat' ) {
$release_file = 'Redhat/CentOS';
}
$OS_DIST = $release_file; # global
$os .= " (" . $release_file;
$os .= defined($OS_VERSION) ? " " . $OS_VERSION . ")" : ")";
last;
}
}
}
# print 'OS: ' . "$os\n";
print_format( 'OS', $os );
return;
}
sub print_format {
my ( $str1, $str2 ) = @_;
# It's going to be difficult to replace format, we don't know if the target system we're running on has Perl6::Form or other replacements, so silence perlcritic about this.
## no critic (CommaSeparatedStatements, Formats)
format =
@>>>>>>>>>>>>>>>>>>>> @< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$str1, ':', $str2
.
write;
## use critic
return;
}
sub print_perl_info {
# Previously read in output from 'perl -v', then tried to use $^V, but these proved to be unreliable.
my $perl_version = $];
if ( $perl_version && $perl_version =~ /^(\d+)\.(\d{3})(\d{3})/ ) {
$perl_version = join( '.', ( $1 + 0 ), ( $2 + 0 ), ( $3 + 0 ) );
}
if ( !$perl_version ) {
$perl_version = 'Unknown';
}
else {
if ( version_compare( $perl_version, qw( < 5.6.2.0 ) ) ) {
$perl_version = $perl_version . ' [ PERL MUST BE 5.6.2+ ]';
}
}
print_format( 'Perl', $perl_version );
return;
}
sub print_mysql_info {
my $mysql_version = `mysql --version`;
if ( $mysql_version =~ /Ver [0-9]{1,2}\.[0-9]{1,2} Distrib ([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}[a-z]?)/ ) {
$mysql_version = $1;
}
else {
$mysql_version = 'Unknown';
}
if ( $mysql_version ne 'Unknown' ) {
if ( version_compare( $mysql_version, qw( < 4.1 ) ) ) {
$mysql_version .= " :UNSUPPORTED\n";
}
}
print_format( 'MySQL', $mysql_version );
return;
}
sub print_php_info {
my $php_version = `php -v 2>/dev/null`;
my $php_major_version;
my $cpanel_php_handler;
if ( $php_version =~ m{ \A PHP \s (\S+) \s }xms ) {
$php_version = $1;
}
else {
$php_version = 'Unknown';
}
if ( $php_version =~ /^(\d)+\./ ) {
$php_major_version = $1;
}
if ( $php_major_version and $IS_CPANEL == 1 ) {
my $phpconf = `/usr/local/cpanel/bin/rebuild_phpconf --current 2> /dev/null`;
if ( $phpconf && -f '/etc/cpanel/ea4/is_ea4' ) { # EA4
$php_version .= " [EA4]";
my $pkg;
foreach my $line ( split( /\n/, $phpconf ) ) {
if ( $line =~ /DEFAULT PHP: (ea-php\d{1,2})/ ) {
$pkg = $1;
next;
}
if ( $line =~ /${pkg} SAPI: (.+)$/ ) {
$cpanel_php_handler = $1;
last;
}
}
}
elsif ( open my $file_fh, '<', '/usr/local/apache/conf/php.conf.yaml' ) { # EA3
$php_version .= " [EA3]";
while (<$file_fh>) {
if (/^php${php_major_version}:\s(\S+)/) {
$cpanel_php_handler = $1;
last;
}
}
close $file_fh;
}
}
if ($cpanel_php_handler) {
$php_version .= " (handler: $cpanel_php_handler)";
}
print_format( 'PHP', $php_version );
return;
}
sub print_apache_info {
my $apache_version;
my @apache_binaries = qw( httpd apache2 http2 httpd2 apache );
for my $apache_binary (@apache_binaries) {
$APACHE_BIN = _find_bin($apache_binary);
if ($APACHE_BIN) {
last;
}
}
if ($APACHE_BIN) {
$apache_version = `$APACHE_BIN -v`;
if ( $apache_version =~ m{ \A Server \s version: \s Apache/(\S+) \s }xms ) {
$apache_version = $1;
}
}
else {
$apache_version = 'Unknown';
}
print_format( 'Apache', $apache_version );
return;
}
sub mem_rounded {
my ($mem_size) = @_;
my $chip_size = 1;
my $chip_guess = ( $mem_size / 8 ) - 1;
while ( $chip_guess != 0 ) {
$chip_guess >>= 1;
$chip_size <<= 1;
}
my $mem_round = ( int( $mem_size / $chip_size ) + 1 ) * $chip_size;
return $mem_round;
}
sub print_cpu_info {
my ( $model, $mhz ) = ();
my $numcores = 0;
if ( open my $cpuinfo_fh, '<', '/proc/cpuinfo' ) {
for my $line ( readline $cpuinfo_fh ) {
if ( $line =~ /^model name/m ) {
$line =~ s/^model name\s+:\s+//;
$line =~ s/\(R\)//g;
$line =~ s/\(tm\)//g;
$line =~ s/\s{2,}/ /;
$line =~ s/\s*\@/ \@/;
$model = $line;
chomp $model;
$numcores++;
}
if ( $line =~ /^cpu MHz/m ) {
$line =~ s/^cpu MHz\s+:\s+//;
$mhz = $line;
chomp $mhz;
}
}
close $cpuinfo_fh;
}
else {
return;
}
print_format( 'CPU', $model . ' w/ ' . $numcores . ' cores' );
return;
}
sub print_mem_info {
if ( $^O =~ /freebsd/i ) {
my $sysctl = {};
my $sysctl_output = `/sbin/sysctl -a`;
foreach my $line ( split( /\n/, $sysctl_output ) ) {
if ( $line =~ m/^([^:]+):\s+(.+)\s*$/s ) {
$sysctl->{$1} = $2;
}
}
my $mem_hw = mem_rounded( $sysctl->{"hw.physmem"} );
my $mem_inactive = $sysctl->{"vm.stats.vm.v_inactive_count"} * $sysctl->{"hw.pagesize"};
my $mem_cache = $sysctl->{"vm.stats.vm.v_cache_count"} * $sysctl->{"hw.pagesize"};
my $mem_free = $sysctl->{"vm.stats.vm.v_free_count"} * $sysctl->{"hw.pagesize"};
my $mem_total = $mem_hw / 1024 / 1024;
my $mem_avail = int( ( $mem_inactive + $mem_cache + $mem_free ) / 1024 / 1024 );