-
Notifications
You must be signed in to change notification settings - Fork 5
/
acctinfo
executable file
·4734 lines (4436 loc) · 175 KB
/
acctinfo
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/local/cpanel/3rdparty/bin/perl
# Copyright 2006 - 2024, WebPros International, LLC. and Peter Elsner <[email protected]>
# All rights reserved.
#
# 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 WEBPROS INTERNATIONAL, LLC D/B/A/ CPANEL (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.
#
# SCRIPT: acctinfo
# PURPOSE: Get as much information for a username or domain entered at command line as possible.
# AUTHOR: Peter Elsner <[email protected]>
# CREATED: 06/17/2006
# CURRENT MAINTAINER: Peter Elsner <[email protected]>
use strict;
my $VERSION = "2.5.53";
use Getopt::Long;
use Cpanel::MysqlUtils;
use Term::ANSIColor qw(:constants);
use Cpanel::FindBin ();
use Cpanel::Sys::Hostname ();
use Cpanel::Config::LoadCpUserFile ();
use Cpanel::Config::LoadUserOwners ();
use Cpanel::Config::LoadUserDomains ();
use Cpanel::Version::Compare ();
use Cpanel::Config::Users ();
use Cpanel::Config::LoadWwwAcctConf ();
use Cpanel::Config::LoadCpConf ();
use Cpanel::SafeRun::Timed ();
use Cpanel::JSON ();
use JSON::PP;
use Cpanel::ResellerFunctions ();
use Cpanel::Usage ();
use Cpanel::Validate::IP ();
use Cpanel::Version ();
use Cpanel::PwCache ();
use Cpanel::LoginDefs ();
use Cpanel::Config::CpUser ();
use Cpanel::PwCache ();
use Cpanel::PwCache::Get ();
use LWP::UserAgent;
use File::Basename;
use Time::Piece;
use Time::Seconds;
use String::Random;
#use Path::Iterator::Rule;
use Math::Round;
use NetAddr::IP;
use DateTime;
use Date::Parse;
use Text::Tabs;
$tabstop = 4;
use Net::DNS;
use Socket;
use DBI;
use integer;
#use Cpanel::CountryCodes;
our $sslsyscertdir;
our $stderr;
our $stdout;
our $OPT_TIMEOUT;
our $success;
our $command;
our $sslsubject;
our $startdate;
our $expiredate;
our $isExpired;
our $isSelfSigned;
our $result;
our @FilesToScan;
our @InstalledMods = timed_run_noerr( 0, 'httpd', '-M' );
our $RUID2Enabled;
our $ProfileNode;
$Term::ANSIColor::AUTORESET = 1;
my $all = undef;
my $listdbs = undef;
my $listssls = undef;
my $listsubs = undef;
my $listaddons = undef;
my $listparked = undef;
my $listaliased = undef;
my $domains = undef;
my $reselleraccts = undef;
my $resellerperms = undef;
my $resellerprivs = undef;
my $chk_cph_blocks = undef;
my $helpME = undef;
my $SearchFor = undef;
my $cruft = undef;
my $mail = undef;
my $showHeader = undef;
my $scan = undef;
my $wpinfo = undef;
my $sitejetinfo = undef;
my $showpass = undef;
my $showtoken = undef;
my $showteaminfo = undef;
my $acct_over_quota = 0;
my $coreEP="https://www.wpvulnerability.net/core";
my $pluginEP="https://www.wpvulnerability.net/plugin";
my $themeEP="https://www.wpvulnerability.net/theme";
our $isInNamedConf = 0;
our $spincounter;
our @HasCAA;
GetOptions(
'listdbs' => \$listdbs,
'listssls' => \$listssls,
'domains' => \$domains,
'listsubs' => \$listsubs,
'listaddons' => \$listaddons,
'listaliased' => \$listaliased,
'listparked' => \$listaliased,
'reselleraccts' => \$reselleraccts,
'resellerperms' => \$resellerperms,
'resellerprivs' => \$resellerperms,
'all' => \$all,
'help' => \$helpME,
'cruft' => \$cruft,
'mail' => \$mail,
'header' => \$showHeader,
'cphulkblocks' => \$chk_cph_blocks,
'scan' => \$scan,
'wpinfo' => \$wpinfo,
'sitejetinfo' => \$sitejetinfo,
'showpass' => \$showpass,
'showtoken' => \$showtoken,
'teams' => \$showteaminfo,
);
if ( $> != 0 ) {
die "Sorry, acctinfo script can only be run as root\n";
}
my $debugHookJSON = get_whmapi1( 'get_tweaksetting', 'key=debughooks' );
my $debugHookVal = $debugHookJSON->{data}->{tweaksetting}->{value};
my $debugHookChanged = 0;
if ( $debugHookVal eq "logall" ) {
# Temporarily set it to logdata to prevent interference in output
get_whmapi1( 'set_tweaksetting', 'key=debughooks', 'value=logdata' );
$debugHookChanged = 1;
}
print BOLD BLUE "acctinfo - Version: " . YELLOW $VERSION . "\n";
if ($helpME) {
Usage();
}
getProfileNode();
my $conf = Cpanel::Config::LoadWwwAcctConf::loadwwwacctconf();
#my $HOMEDIR = $conf->{'HOMEDIR'};
my $HOMEDIR;
my $HOMEMATCH = $conf->{'HOMEMATCH'};
my $SERVER_IP = $conf->{'ADDR'};
my $NS1 = $conf->{'NS'};
my $NS2 = $conf->{'NS2'};
my $NS3 = $conf->{'NS3'};
my $NS4 = $conf->{'NS4'};
my $cpconf = Cpanel::Config::LoadCpConf::loadcpconf();
my $DBPrefix = $cpconf->{'database_prefix'};
my $ACLSEnabled = $cpconf->{'acls'};
my ( $os_release, $os_ises ) = get_release_version();
my $IS_USERNAME = 1;
my $QUERY = @ARGV[0];
chomp($QUERY);
if ( $QUERY eq "" ) {
Usage();
}
$QUERY = lc($QUERY);
if ( index( $QUERY, '.' ) != -1 ) {
$IS_USERNAME = 0;
}
my $MAINDOMAIN;
my $HOSTNAME = Cpanel::Sys::Hostname::gethostname();
my $username = $QUERY;
if ( $IS_USERNAME == 0 ) {
# FULL DOMAIN NAME ENTERED
my $xwww = substr( $QUERY, 0, 4 ); ## Strip www. if entered!
if ( $xwww eq "www." ) {
$QUERY = substr( $QUERY, 4 );
}
my $DataJSON = get_whmapi1( 'getdomainowner', "domain=$QUERY" );
$username = $DataJSON->{data}->{user};
}
my $ValUserJSON = get_whmapi1( 'validate_system_user', "user=$username" );
my $isReserved = $ValUserJSON->{data}->{reserved};
my $ASreason = $ValUserJSON->{metadata}->{reason};
my $UserExists = $ValUserJSON->{data}->{exists};
if ($isReserved) {
print RED "[WARN] You entered a reserved Username [ $username ]\n";
print YELLOW
"Some data may be missing from cPanel configuration files...\n";
print WHITE
"See https://docs.cpanel.net/knowledge-base/accounts/reserved-invalid-and-misconfigured-username/\n";
}
my $DataJSON = get_whmapi1( 'accountsummary', "user=$username" );
my $systemUser = $DataJSON->{metadata}->{result};
if ( $IS_USERNAME && !$systemUser ) {
$MAINDOMAIN = "";
$username = $QUERY;
}
else {
$username = $DataJSON->{data}->{acct}->[0]->{user};
$MAINDOMAIN = $DataJSON->{data}->{acct}->[0]->{domain};
$HOMEDIR = "/" . $DataJSON->{data}->{acct}->[0]->{partition};
my $quotaused = $DataJSON->{data}->{acct}->[0]->{diskused};
my $maxquota = $DataJSON->{data}->{acct}->[0]->{disklimit};
}
my $UserSuspended = $DataJSON->{data}->{acct}->[0]->{suspended};
my $ASreason = $DataJSON->{metadata}->{reason};
my $UserExists = $ValUserJSON->{data}->{exists};
if ( !$UserExists or $ASreason ne "OK" ) {
if ($cruft) {
cruft_check();
}
print RED "Error - $QUERY not found on $HOSTNAME\n";
print YELLOW "Try using the --cruft switch (acctinfo $QUERY --cruft)\n";
if ($debugHookChanged) {
get_whmapi1( 'set_tweaksetting', 'key=debughooks', 'value=logall' );
}
exit;
}
my $isReserved = $ValUserJSON->{data}->{reserved};
if ($isReserved) {
if ( $username eq "" and $IS_USERNAME ) {
$username = $QUERY;
}
print RED "\n[WARN] - "
. YELLOW $QUERY
. WHITE " is tied to a reserved username! "
. BOLD CYAN "(some info may be missing from some files)\n";
if ($username) {
my $RandomString = new String::Random;
my $SuggestedUser = $RandomString->randpattern("cccccc");
print YELLOW
"You can use the following API call to change $username to for example: $username$SuggestedUser\n";
print BOLD MAGENTA
"/usr/sbin/whmapi1 modifyacct user=$username newuser=$username$SuggestedUser\n";
}
}
my $username = $DataJSON->{data}->{acct}->[0]->{user};
my $MAINDOMAIN = $DataJSON->{data}->{acct}->[0]->{domain};
my $quotaused = $DataJSON->{data}->{acct}->[0]->{diskused};
my $maxquota = $DataJSON->{data}->{acct}->[0]->{disklimit};
if ($scan) {
scan();
if ($debugHookChanged) {
get_whmapi1( 'set_tweaksetting', 'key=debughooks', 'value=logall' );
}
exit;
}
# Load /var/cpanel/users/$username into (used for FEATURELIST only right now - see CPANEL-30573)
my $user_conf = Cpanel::Config::LoadCpUserFile::load($username);
my $DOMAIN = "";
my $IS_PARKED = "";
my $IS_ADDON = "";
my $IS_SUB = "";
my $maindocroot = "";
my ( $subdocroot, $addondocroot, $parkeddocroot );
my @OtherDomains = "";
my @SUBDOMAINS = "";
my @ADDONDOMAINS = "";
my @PARKEDDOMAINS = "";
my @users_domains = (
$user_conf->{'DOMAIN'},
$user_conf->{'DOMAINS'} ? @{ $user_conf->{'DOMAINS'} } : ()
);
push @OtherDomains, $MAINDOMAIN;
my $DomainInfoJSON = get_whmapi1('get_domain_info');
my $DomainInfoLines;
for $DomainInfoLines ( @{ $DomainInfoJSON->{data}->{domains} } ) {
if ( $DomainInfoLines->{user} eq $username ) {
if ( $DomainInfoLines->{domain_type} eq "sub" ) {
push( @OtherDomains, $DomainInfoLines->{domain} );
push( @SUBDOMAINS, $DomainInfoLines->{domain} );
my $docroot_status = "";
$docroot_status = RED " [MISSING]" unless ( -d $DomainInfoLines->{docroot} );
$IS_SUB = expand(
"$DomainInfoLines->{domain} is a sub domain of $MAINDOMAIN \n\t\\_ "
)
. YELLOW
. "(DocumentRoot: "
. WHITE $DomainInfoLines->{docroot} . ") $docroot_status\n"
unless ( $DomainInfoLines->{domain} ne $QUERY );
$subdocroot = $DomainInfoLines->{docroot}
unless ( $DomainInfoLines->{domain} ne $QUERY );
}
if ( $DomainInfoLines->{domain_type} eq "addon" ) {
push( @OtherDomains, $DomainInfoLines->{domain} );
my $docroot_status = "";
$docroot_status = RED " [MISSING]" unless ( -d $DomainInfoLines->{docroot} );
my $sitejet_status = ( -e "$HOMEDIR/$username/.cpanel/sitejet/$DomainInfoLines->{domain}" ) ? MAGENTA "[Sitejet Enabled]" : "";
push( @ADDONDOMAINS,
$DomainInfoLines->{domain} . " "
. $sitejet_status
. YELLOW "\n\t\t \\_ [ Sub: "
. $DomainInfoLines->{parent_domain} . " ]"
. "\n\t\t \\_ [ DocumentRoot: "
. $DomainInfoLines->{docroot}
. " ] $docroot_status" );
$IS_ADDON = expand(
"$DomainInfoLines->{domain} $sitejet_status is an AddOn domain of $MAINDOMAIN \n\t\\_ "
)
. YELLOW
. "(DocumentRoot: "
. WHITE $DomainInfoLines->{docroot} . ") $docroot_status\n"
unless ( $DomainInfoLines->{domain} ne $QUERY );
$addondocroot = $DomainInfoLines->{docroot}
unless ( $DomainInfoLines->{domain} ne $QUERY );
}
if ( $DomainInfoLines->{domain_type} eq "parked" ) {
push( @OtherDomains, $DomainInfoLines->{domain} );
push( @PARKEDDOMAINS, $DomainInfoLines->{domain} );
my $docroot_status = "";
$docroot_status = RED " [MISSING]" unless ( -d $DomainInfoLines->{docroot} );
$IS_PARKED = expand(
"$DomainInfoLines->{domain} is an alias (parked) domain of $MAINDOMAIN\n\t\\_ "
)
. YELLOW
. "(DocumentRoot: "
. WHITE $DomainInfoLines->{docroot} . ") $docroot_status\n"
unless ( $DomainInfoLines->{domain} ne $QUERY );
$parkeddocroot = $DomainInfoLines->{docroot}
unless ( $DomainInfoLines->{domain} ne $QUERY );
}
if ( $DomainInfoLines->{domain_type} eq "main" ) {
$maindocroot = $DomainInfoLines->{docroot};
}
}
}
shift @SUBDOMAINS;
shift @ADDONDOMAINS;
shift @PARKEDDOMAINS;
shift @OtherDomains;
my $subcnt = @SUBDOMAINS;
my $addoncnt = @ADDONDOMAINS;
my $parkcnt = @PARKEDDOMAINS;
my $othercnt = @OtherDomains;
if ($cruft) {
cruft_check();
}
my $PACKAGE = $DataJSON->{data}->{acct}->[0]->{plan};
my $THEME = $DataJSON->{data}->{acct}->[0]->{theme};
my $IPADDR = $user_conf->{'IP'};
my $CHILD_WORKLOADS = $user_conf->{'CHILD_WORKLOADS'};
my $BACKUPENABLED = $DataJSON->{data}->{acct}->[0]->{backup};
my $MAXADDON = $DataJSON->{data}->{acct}->[0]->{maxaddons};
my $MAXPARK = $DataJSON->{data}->{acct}->[0]->{maxparked};
my $MAXSUB = $DataJSON->{data}->{acct}->[0]->{maxsub};
my $MAXFTP = $DataJSON->{data}->{acct}->[0]->{maxftp};
my $MAXSQL = $DataJSON->{data}->{acct}->[0]->{maxsql};
my $MAXLST = $DataJSON->{data}->{acct}->[0]->{maxlst};
my $SitejetAPI = $user_conf->{SITEJET_API_TOKEN};
my $SUSPEND_TIME = $DataJSON->{data}->{acct}->[0]->{suspendtime};
my $FEATURELIST = $user_conf->{'FEATURELIST'};
my $STARTDATE = $DataJSON->{data}->{acct}->[0]->{startdate};
my @ResolvedIP;
my $ResolvedIP;
my $HAS_AUTOSSL = "No";
my $HAS_AUTOSSLFEATURE =
get_whmapi1( 'verify_user_has_feature', "user=$username", 'feature=autossl' );
if ( $HAS_AUTOSSLFEATURE->{data}->{has_feature} ) {
$HAS_AUTOSSL = "Yes";
}
my $HAS_AUTOSSL_TEXT;
my $AutoSSL_Disabled = 0;
my $AutoSSL_DisabledJSON =
get_whmapi1( 'get_featurelist_data', 'featurelist=disabled' );
for my $AutoSSL_DisabledID ( @{ $AutoSSL_DisabledJSON->{data}->{features} } ) {
if ( $AutoSSL_DisabledID->{id} eq "autossl" ) {
$AutoSSL_Disabled = $AutoSSL_DisabledID->{value};
last;
}
}
if ( !$AutoSSL_Disabled ) {
$HAS_AUTOSSL_TEXT = "(AutoSSL disabled in the \"disabled\" feature list)";
}
my $AutoSSL_Disabled;
if ( !( -e ("/var/cpanel/features/$FEATURELIST") ) ) {
$AutoSSL_Disabled = "$FEATURELIST not found in /var/cpanel/features!";
$HAS_AUTOSSL_TEXT =
RED "[WARN] - Missing from the /var/cpanel/features/ directory";
}
else {
my $AutoSSL_DisabledJSON =
get_whmapi1( 'get_featurelist_data', "featurelist=$FEATURELIST" );
for
my $AutoSSL_DisabledID ( @{ $AutoSSL_DisabledJSON->{data}->{features} } )
{
if ( $AutoSSL_DisabledID->{id} eq "autossl" ) {
$AutoSSL_Disabled = $AutoSSL_DisabledID->{value};
last;
}
}
if ( !$AutoSSL_Disabled ) {
$HAS_AUTOSSL_TEXT =
"(AutoSSL disabled in the \"$FEATURELIST\" feature list)";
}
}
if ( $HAS_AUTOSSL_TEXT eq "" ) {
$HAS_AUTOSSL_TEXT =
"(AutoSSL enabled in the \"$FEATURELIST\" feature list)";
}
$BACKUPENABLED = ($BACKUPENABLED) ? "Yes" : "No";
$ResolvedIP = ($IS_USERNAME) ? Cpanel::SafeRun::Timed::timedsaferun( 8, '/usr/local/cpanel/scripts/cpdig', $MAINDOMAIN, 'A') : Cpanel::SafeRun::Timed::timedsaferun( 8, '/usr/local/cpanel/scripts/cpdig', $QUERY, 'A');
#if ($IS_USERNAME) {
# $ResolvedIP = Cpanel::SafeRun::Timed::timedsaferun( 8, '/usr/local/cpanel/scripts/cpdig', $MAINDOMAIN, 'A' );
#}
#else {
# $ResolvedIP = Cpanel::SafeRun::Timed::timedsaferun( 8, '/usr/local/cpanel/scripts/cpdig', $QUERY, 'A' );
#}
@ResolvedIP=split /\n/, $ResolvedIP;
my $IPTYPE = ( $IPADDR eq $SERVER_IP ) ? "shared" : "dedicated";
#my $IPTYPE = "";
#if ( $IPADDR eq $SERVER_IP ) {
# $IPTYPE = "shared";
#}
#else {
# $IPTYPE = "dedicated";
#}
my $ip_on_localhost=0;
if ( $IPADDR eq '127.0.0.1' ) {
$IPTYPE = RED "[WARN] - $username\'s IP address is configured to localhost!";
$ip_on_localhost=1;
}
my $REAL_OWNER = $DataJSON->{data}->{acct}->[0]->{owner};
my $RO_TEXT = "";
if ( $REAL_OWNER ne $username and $REAL_OWNER ne "root" ) {
$RO_TEXT = " (Which is under the reseller: $REAL_OWNER)";
}
my $sitejet_status = ( -e "$HOMEDIR/$username/.cpanel/sitejet/$MAINDOMAIN" ) ? MAGENTA " [Sitejet Enabled]" : "";
# Check if main domain (username) is a reseller.
my @ACCTSOWNEDBYRESELLER = undef;
my @SORTEDRESELLERACCTS = undef;
my @LISTOFACCTS = undef;
my $Is_Reseller = 0;
my $ResellerAcctsCnt = 0;
my $ResellerDomain = "";
my $vcu_account = "";
my $ResellersAcct = "";
my $RESELLER = "";
my $FOUND = "";
my $ResellerSharedIP = "None";
my @ResellerIPS = undef;
my $ResellerIP = "None";
my $ResellerIPS = "None";
my @ALL_RESELLERS = Cpanel::ResellerFunctions::getresellerslist();
unshift @ALL_RESELLERS, 'root';
foreach $RESELLER (@ALL_RESELLERS) {
chomp($RESELLER);
if ( $RESELLER eq $username ) {
$Is_Reseller = 1;
# Grab resellers shared IP (if configured) from /var/cpanel/mainips/$RESELLER.
if ( -e ("/var/cpanel/mainips/$RESELLER") ) {
$ResellerSharedIP =
timed_run( 2, 'cat', "/var/cpanel/mainips/$RESELLER" );
chomp($ResellerSharedIP);
}
if ( -e ("/var/cpanel/dips/$RESELLER") ) {
open( RESELLERIPS, "/var/cpanel/dips/$RESELLER" );
@ResellerIPS = <RESELLERIPS>;
close(RESELLERIPS);
}
}
}
my $TOTAL_DOMAINS = Cpanel::Config::LoadUserDomains::counttrueuserdomains();
chomp($TOTAL_DOMAINS);
print WHITE "There are "
. YELLOW $TOTAL_DOMAINS
. WHITE " total accounts on ("
. GREEN ON_BLACK $HOSTNAME
. WHITE ")\n";
if ($IS_USERNAME) {
print "\n";
}
else {
print GREEN ON_BLACK "\nThe username for "
. BRIGHT_BLUE $QUERY
. GREEN ON_BLACK " is: "
. YELLOW $username . "\n";
}
if ( $CHILD_WORKLOADS ne "" ) {
print
"$username is a child node on this server. Please run acctinfo on the parent server\n";
exit;
}
my $user_child_nodesJSON = get_whmapi1('list_user_child_nodes');
my $linked_nodes;
for my $child_nodes ( @{ $user_child_nodesJSON->{data}->{payload} } ) {
if ( $child_nodes->{user} eq $username ) {
$linked_nodes =
YELLOW "The "
. CYAN $child_nodes->{user}
. YELLOW " account is linked to the: "
. CYAN $child_nodes->{alias}
. YELLOW " server for type: "
. CYAN $child_nodes->{type};
}
}
# Get home directory from /etc/passwd
our $SSLProvider = getSSLProvider();
my $RealHome = Cpanel::PwCache::gethomedir($username);
my $OnCloud=($RealHome =~ m{remote-storage}) ? 1 : 0;
my $RealShell = Cpanel::PwCache::Get::getshell($username);
my $UID = Cpanel::PwCache::Get::getuid($username);
my $GID = Cpanel::Config::CpUser::get_cpgid($username);
my $UID_MIN = Cpanel::LoginDefs::get_uid_min();
my $GID_MIN = Cpanel::LoginDefs::get_gid_min();
if ( $UID < $UID_MIN or $GID < $GID_MIN ) {
print RED
"[WARN] - UID/GID for $username is less than $UID_MIN/$GID_MIN as set in /etc/login.defs\n";
}
# Check for missing hash in /etc/shadow
my $PWHashLine = timed_run( 2, 'grep', "^$username", '/etc/shadow' );
my ($PWHash) = ( split( /:/, $PWHashLine ) )[1];
if ( $PWHash eq "" ) {
print RED "[WARN] * $username is missing password hash in /etc/shadow\n";
}
print GREEN ON_BLACK "The main domain is " . YELLOW $MAINDOMAIN . $sitejet_status . GREEN ON_BLACK $RO_TEXT . "\n";
if ( $QUERY eq $HOSTNAME ) {
print RED
"[WARN] - $QUERY is the same as hostname $HOSTNAME! (Can cause email issues such as User not found)\n";
}
my $LastLoginIP;
if ( -e $RealHome && !$UserSuspended ) {
my $LastLoginIPdata = get_uapi( 'LastLogin', 'get_last_or_current_logged_in_ip', "--user=$username" );
$LastLoginIP = $LastLoginIPdata->{result}->{data};
chomp($LastLoginIP);
if ( $LastLoginIP eq "''" ) {
$LastLoginIP = "";
}
}
print expand(
"\t\\_ " . YELLOW . "(DocumentRoot: " . WHITE $maindocroot . ")\n" );
if ( $maindocroot eq "" ) {
print expand( RED "\t \\_ [WARN] - DocumentRoot is blank!\n" );
}
if ( $OnCloud ) {
print GREEN expand( "\tcPCloud Instance Detected...\n");
my $namespaces=timed_run( 3, 'kubectl', 'get', 'namespaces' );
my @namespaces=split /\n/, $namespaces;
foreach my $namespace(@namespaces) {
chomp($namespace);
next unless( $namespace =~ m/$username/ );
print expand( YELLOW "\t " . $namespace . "\n");
last;
}
my $serviceweb=timed_run( 3, 'kubectl', '-n', "cpsc-service-web-$username", 'get', 'all' );
my @servicewebs=split /\n/, $serviceweb;
foreach my $line(@servicewebs) {
chomp($line);
print expand( CYAN "\t\t\\_ $line\n" ) if ( $line =~ m{pod/cpsc-service-web} );
}
print "\n";
}
print WHITE "Real Home Directory (/etc/passwd): "
. CYAN $RealHome
. YELLOW " - Checking permissions...";
print "\n";
checkperms2() unless( $UserSuspended );
securitychk() unless( $UserSuspended );
# Check if user is in demo mode
open( DEMO, "/etc/demousers" );
my @DEMOUSERS = <DEMO>;
close(DEMO);
my $demouser;
foreach $demouser (@DEMOUSERS) {
chomp($demouser);
if ( $demouser eq $username ) {
print RED "[WARN] - $username is in demo mode!\n";
last;
}
}
# Check if bandwidth limit exceeded
if ( -e ("/var/cpanel/bwlimited/$username")
or -e ("/var/cpanel/bwlimited/$MAINDOMAIN")
or -e ("/var/cpanel/bwlimited/$QUERY") )
{
print RED
"[WARN] - $MAINDOMAIN ($username) may have exceeded their bandwidth limit!\n";
}
if ($Is_Reseller) {
print GREEN ON_BLACK "This account is also a reseller!\n";
if ($ResellerSharedIP) {
print GREEN "Reseller's Shared IP: " . WHITE $ResellerSharedIP . "\n";
}
if (@ResellerIPS) {
print GREEN "Reseller's IP Delegation\n";
foreach $ResellerIP (@ResellerIPS) {
chomp($ResellerIP);
if ( $ResellerIP ne "" ) {
print expand( YELLOW "\t \\_ $ResellerIP\n" );
}
else {
print expand( YELLOW "\t \\_ Open Delegation " )
. CYAN
. "(any IP on this server can be used by "
. WHITE $username
. CYAN . ")\n";
}
}
}
else {
print GREEN "Reseller's IP Delegation: ";
print YELLOW "Open Delegation "
. CYAN
. "(any IP on this server can be used by "
. WHITE $username
. CYAN . ")\n";
}
}
print GREEN "$IS_PARKED\n" unless ( $IS_PARKED eq "" );
print GREEN "$IS_ADDON\n" unless ( $IS_ADDON eq "" );
print GREEN "$IS_SUB\n" unless ( $IS_SUB eq "" );
if ( $showHeader || $all ) {
print CYAN "Header information for " . GREEN $QUERY . "\n"
unless ($IS_USERNAME);
print CYAN "Header information for " . GREEN $MAINDOMAIN . "\n"
unless ( !$IS_USERNAME );
display_header($QUERY) unless ($IS_USERNAME);
display_header($MAINDOMAIN) unless ( !$IS_USERNAME );
}
# domainfwdip and domainfwdmap checks
if ( -e '/var/cpanel/domainfwdip' ) {
if ( -s '/var/cpanel/domainmap' ) {
open( my $fh, '<', '/var/cpanel/domainmap');
my @domainmaps=<$fh>;
close( $fh );
foreach my $line(@domainmaps) {
chomp($line);
my ($fwddom,$fwdurl) = ( split( /\=/, $line ));
#if ( $fwddom eq $MAINDOMAIN or $fwddom eq $QUERY ) {
if ( $IS_USERNAME ) {
if ( $fwddom eq $MAINDOMAIN ) {
print RED "[WARN] - $fwddom is currently forwarding to $fwdurl\n";
}
}
else {
if ( $fwddom eq $QUERY ) {
print RED "[WARN] - $fwddom is currently forwarding to $fwdurl\n";
}
}
}
}
}
print WHITE "Shell: " . CYAN $RealShell . "\n";
my $jailapacheTweakJSON = get_whmapi1( 'get_tweaksetting', 'key=jailapache' );
my $jaTweak = $jailapacheTweakJSON->{data}->{tweaksetting}->{value};
if ( $RealShell =~ m/jailshell/ && $RUID2Enabled && $jaTweak ) {
print expand( YELLOW
"\t\\_ Seeing 404's? ModRuid2 enabled w/Experimental Jail Apache Tweak.\n"
);
print expand(
YELLOW "\t\\_ Try disabling to see if that solves the error.\n" );
}
ChkForIntegration();
# check if user is in /etc/ftpusers
my $ftpblock = "";
if ( -e ("/etc/ftpusers") ) {
open( FTPUSERS, "/etc/ftpusers" );
my @FTPUSERS = <FTPUSERS>;
close(FTPUSERS);
my $ftpblock;
foreach $ftpblock (@FTPUSERS) {
chomp($ftpblock);
if ( $ftpblock eq $username ) {
print RED
"[WARN] - $username found in /etc/ftpusers file (FTP authentication will fail!\n";
last;
}
}
}
if ( -e ("/etc/proftpd/$username.suspended") and ( !$UserSuspended ) ) {
print RED
"[WARN] - $username.suspended file found /etc/proftpd directory. Can cause FTP password updates to fail!\n";
}
if ( -e ("/etc/proftpd/$username.unsuspended_failed") ) {
print RED
"[WARN] - $username.unsuspended_failed file found /etc/proftpd directory. Can cause FTP password updates to fail!\n";
}
# Check to make sure UID/GID is greater than what is defined in /etc/login.defs
print WHITE "UID/GID: " . CYAN $UID . "/" . $GID . "\n";
my $quotaJSON = get_whmapi1( 'accountsummary', "user=$username" );
my $quotaused = $quotaJSON->{data}->{acct}->[0]->{diskused};
my $maxquota = $quotaJSON->{data}->{acct}->[0]->{disklimit};
my $inodeslimit = $quotaJSON->{data}->{acct}->[0]->{inodeslimit};
my $inodesused = $quotaJSON->{data}->{acct}->[0]->{inodesused};
print "Disk Quota: $quotaused used of $maxquota allowed / Inodes Used: $inodesused used of $inodeslimit allowed";
if ( $quotaused > $maxquota ) {
$acct_over_quota = 1 unless ( $maxquota eq "unlimited" );
print RED "[WARN] - $username appears to be over quota!"
unless ( $maxquota eq "unlimited" );
}
if ( $inodesused > $inodeslimit ) {
$acct_over_quota = 1 unless ( $inodeslimit eq "unlimited" );
print RED "[WARN] - $username appears to have maxed out inodes!" unless ( $inodeslimit eq "unlimited" );
}
print "\n";
my $skip_bwcheck = 0;
if ( !( -e ("/var/cpanel/features/$FEATURELIST") ) ) {
print YELLOW
"[INFO] - Skipping bandwidth check! Feature list \"$FEATURELIST\" missing from /var/cpanel/features/\n";
$skip_bwcheck = 1;
}
if ( $UserSuspended ) {
print YELLOW
"[INFO] - Skipping bandwidth check! Account is suspended\n";
$skip_bwcheck = 1;
}
if ( $skip_bwcheck == 0 ) {
my $bwdataJSON = get_uapi(
'StatsBar', 'get_stats',
'display=bandwidthusage', "--user=$username"
);
my $bwused = $bwdataJSON->{result}->{data}->[0]->{count};
my $bwmax = $bwdataJSON->{result}->{data}->[0]->{max};
print "Bandwidth: $bwused used of $bwmax allowed\n"
unless ( $bwused eq "" or $bwmax eq "" );
}
# Check for custom style (Paper Lantern Theme)
my $custom_style_path = "$RealHome/var/cpanel/styled/current_style";
my $custom_style_link;
my $custom_style;
my @custom_style_array;
my $custom_style_array;
if ( -e ("$custom_style_path") ) {
$custom_style_link = readlink($custom_style_path);
@custom_style_array = split( "\/", $custom_style_link );
$custom_style = $custom_style_array[-1];
}
my $undefined_package = ( $PACKAGE eq "undefined" ) ? RED " [WARNING: PACKAGE SHOULD NEVER BE UNDEFINED]" : "";
print WHITE "Hosting Package: "
. CYAN $PACKAGE . $undefined_package
. WHITE " ("
. "Feature List: "
. GREEN $FEATURELIST
. WHITE ") "
. $HAS_AUTOSSL_TEXT . "\n";
my $deprecated_theme_warning = "";
if ( $THEME eq "x3" ) {
$deprecated_theme_warning = RED "\n\t\\_ WARNING - The x3 theme is deprecated. cPanel UI not loading? This is probably why!";
}
if ( Cpanel::Version::compare( Cpanel::Version::getversionnumber(), '>=', '11.106.0.0') ) {
if ( $THEME eq "paper_lantern" ) {
$deprecated_theme_warning = RED "\n\t\\_ WARNING - The paper_lantern theme is deprecated as of version 106 and will be removed in a future version.";
}
}
if ( $sitejetinfo ) {
my $sitejet_domain = ( $IS_USERNAME ) ? $MAINDOMAIN : $QUERY;
if ( -e "$RealHome/.cpanel/sitejet/$sitejet_domain" ) {
my $insecure = ($showtoken) ? 1 : 0;
print WHITE "Sitejet Builder Data [ " . GREEN "API Token: " . YELLOW $SitejetAPI . WHITE " ]\n" unless( !$insecure );
print WHITE "Sitejet Builder Data [ " . GREEN "API Token: " . YELLOW "REDACTED --showtoken to reveal" . WHITE " ]\n" unless( $insecure );
my $SjJSON = get_uapi( 'Sitejet', 'get_all_user_sitejet_info', "--user=$username", "domain=$sitejet_domain" );
print expand( YELLOW "\t\\_ Website ID: " . CYAN $SjJSON->{result}->{data}->[0]->{metadata}->{websiteId} . "\n" );
print expand( YELLOW "\t\\_ Template Name: " . CYAN $SjJSON->{result}->{data}->[0]->{metadata}->{templateName} . YELLOW " [ Template ID: " . CYAN $SjJSON->{result}->{data}->[0]->{metadata}->{templateId} . YELLOW " ]\n" );
my $isPublished = ( $SjJSON->{result}->{data}->[0]->{metadata}->{publish_status} ) ? "Yes" : "No";
if ( $isPublished eq "Yes" ) {
print expand( YELLOW "\t\\_ Published: " . CYAN $isPublished . YELLOW " Latest Published Date: " . CYAN scalar(localtime($SjJSON->{result}->{data}->[0]->{metadata}->{latest_publish_date})));
}
else {
print expand( YELLOW "\t\\_ Published: " . CYAN "No" );
}
print "\n\n";
}
}
if ($custom_style) {
print WHITE "Theme: "
. CYAN $THEME
. " (Style: $custom_style) "
. $deprecated_theme_warning . "\n";
}
else {
print WHITE "Theme: " . CYAN $THEME . expand( $deprecated_theme_warning . "\n" );
}
print WHITE "Max Addon/Alias/Sub Domains: "
. CYAN $MAXADDON
. WHITE " / "
. CYAN $MAXPARK
. WHITE " / "
. CYAN $MAXSUB . "\n";
print WHITE "Max SQL Databases: " . CYAN $MAXSQL . "\n";
print WHITE "Max Mailman Lists: " . CYAN $MAXLST . "\n";
print WHITE "Max FTP Accounts: " . CYAN $MAXFTP . "\n";
print WHITE "Has AutoSSL Feature "
. CYAN $HAS_AUTOSSL . " ["
. YELLOW $SSLProvider
. CYAN "]\n";
print WHITE "cPanel Backup Enabled: " . CYAN $BACKUPENABLED;
if ( -e "$RealHome/.jbm" ) {
my $jb4Path = '/usr/local/jetapps/usr/bin/jetbackup';
my $jb5Path = '/usr/local/jetapps/usr/bin/jetbackup5/jetbackup';
my $JB4Version;
my $JB5Version;
my $JBVersion;
if ( -x $jb4Path ) {
my ( $jb4_1, $jb4_2, $jb4_3 ) = (
split(
/\s+/,
Cpanel::SafeRun::Timed::timedsaferun(
4, "$jb4Path", '--version', "| head -1"
)
)
)[ 1, 2, 3 ];
$JB4Version = $jb4_1 . " " . $jb4_2 . " " . $jb4_3;
}
if ( -x $jb5Path ) {
my ( $jb5_1, $jb5_2, $jb5_3, $jb5_4 ) = (
split(
/\s+/,
Cpanel::SafeRun::Timed::timedsaferun(
4, "$jb5Path", '--version'
)
)
)[ 7, 8, 9, 10 ];
$JB5Version = $jb5_1 . " " . $jb5_2 . " " . $jb5_3 . " " . $jb5_4;
}
chomp($JB4Version);
chomp($JB5Version);
if ( $JB4Version && $JB5Version ) {
$JBVersion = $JB4Version . " / " . $JB5Version;
}
$JBVersion = ($JB4Version) ? $JB4Version : "" unless ($JBVersion);
$JBVersion = ($JB5Version) ? $JB5Version : "" unless ($JBVersion);
print " (" . BOLD GREEN "JetBackup Manager " . $JBVersion . " detected)";
}
print "\n";
# List any linked server nodes
if ($linked_nodes) {
print WHITE "Linked Nodes:\n";
print expand( CYAN "\t\\_ $linked_nodes\n" );
}
nginx_caching();
my $PHPDefaultVersion;
custom_UD();
my $cageFSStats = check_for_cagefs();
if ($cageFSStats) {
print WHITE "CageFS: " . CYAN $cageFSStats . "\n";
}
else {
print WHITE "CageFS: " . CYAN . "Not installed/enabled!\n";
}
# Check for php-selector (CloudLinux)
my $clPHPVer = "";
$PHPDefaultVersion = get_system_php_version();
print "Default System PHP Version: " . CYAN $PHPDefaultVersion . "\n";
my $HasPrecedence = MAGENTA " cPanel EA4 PHP version has precedence";
my $found=timed_run( 0, 'grep', $QUERY, '/etc/userdomains' );
my $docroot;
my $phpdomain;
my $phpFPMStat;
my $pmMaxChildren;
my $pmMaxRequests;
my $pmProcTimeout;
my $PHPversion;
my $result;
if ( $found ) {
( $docroot, $phpdomain, $phpFPMStat, $pmMaxChildren, $pmMaxRequests, $pmProcTimeout, $PHPversion) = get_php_version($QUERY);
$result=$QUERY;
}
else {
( $docroot, $phpdomain, $phpFPMStat, $pmMaxChildren, $pmMaxRequests, $pmProcTimeout, $PHPversion) = get_php_version($MAINDOMAIN);
$result=$MAINDOMAIN;
}
my $PHPiniFile;
my $PHPiniLoad;
my $PHPiniScan;
my $skipEA4 = 0;
if ( $PHPversion eq "inherit" ) {
if ($cageFSStats) {
$HasPrecedence = MAGENTA " CloudLinux PHP Selector has precedence";
my $clPHP =
timed_run( 2, 'grep', '^php', "$RealHome/.cl.selector/defaults.cfg" );
$clPHPVer =~ s/\s+//g;
($clPHPVer) = ( split( /=/, $clPHP ) )[1];
chomp($clPHPVer);
$clPHPVer = alltrim($clPHPVer);
my $clPHPVer1;
my $clPHPVer2;
if ( $clPHPVer eq "native" ) {
my $clPHPVerLine = timed_run_noerr( 4, '/usr/bin/selectorctl', '--current', '--show-native-version');
( $clPHPVer1, $clPHPVer2 ) = ( split( /\s+/, $clPHPVerLine ) )[ 0, 1 ];
$clPHPVer = $clPHPVer1 . " " . $clPHPVer2;
}
$PHPiniFile = timed_run( 0, 'su', '-s', '/bin/bash', "$username", '-c',
'php -i|grep "^Configuration File"' );
$PHPiniLoad = timed_run( 0, 'su', '-s', '/bin/bash', "$username", '-c',
'php -i| grep "^Loaded Configuration File"' );
$PHPiniScan = timed_run( 0, 'su', '-s', '/bin/bash', "$username", '-c',
'php -i|grep "^Scan this dir"' );
$skipEA4 = 1;
}
}
print "EA4 PHP Version [ $result ]: " . CYAN $PHPversion;
print WHITE "\nCloudLinux PHP Version: " . CYAN $clPHPVer unless ( !$clPHPVer );
print MAGENTA $HasPrecedence . "\n";
if ( !$skipEA4 ) {
if ( $PHPversion eq "inherit" ) {
$PHPiniFile =
timed_run( 5, "$PHPDefaultVersion -i|grep '^Configuration File'" );
$PHPiniLoad = timed_run( 5,
"$PHPDefaultVersion -i|grep '^Loaded Configuration File'" );
$PHPiniScan =
timed_run( 5, "$PHPDefaultVersion -i|grep '^Scan this dir'" );
}
else {
$PHPiniFile =
timed_run( 5, "$PHPversion -i|grep '^Configuration File'" );
$PHPiniLoad =
timed_run( 5, "$PHPversion -i|grep '^Loaded Configuration File'" );
$PHPiniScan = timed_run( 5, "$PHPversion -i|grep '^Scan this dir'" );
}
}
chomp($PHPiniFile);
chomp($PHPiniLoad);
chomp($PHPiniScan);
my $PHPHandlerJSON;
my $PHPHandler;
if ( ! $UserSuspended ) {
$PHPHandlerJSON = get_uapi( 'LangPHP', 'php_get_domain_handler', 'type=vhost', "vhost=$MAINDOMAIN", "--user=$username");
$PHPHandler = $PHPHandlerJSON->{result}->{data}->{php_handler};
}
my $suPHPConfPathFound;
if ( -e ("$docroot/.htaccess") ) {
$suPHPConfPathFound =