-
Notifications
You must be signed in to change notification settings - Fork 3
/
checks.cgi
119 lines (92 loc) · 3.35 KB
/
checks.cgi
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
require 'checks-lib.pl';
require 'jru-lib.pl';
require '../webmin/webmin-lib.pl'; #for OS detection
foreign_require('software', 'software-lib.pl');
sub install_firewalld {
software::update_system_install("firewalld", undef);
#allow webmin
exec_cmd('firewall-cmd --permanent --zone=public --add-port=10000/tcp');
exec_cmd('firewall-cmd --permanent --zone=public --add-port=80/tcp');
exec_cmd('firewall-cmd --permanent --zone=public --add-port=443/tcp');
exec_cmd('firewall-cmd --permanent --zone=public --add-port=8080/tcp');
exec_cmd('systemctl restart firewalld');
exec_cmd('firewall-cmd --list-all');
}
sub disable_info_page_is_enabled(){
my $prop_file = get_prop_file();
my $ln=0;
my $lref = &read_file_lines($prop_file);
foreach my $line (@$lref){
if($line =~ /infoPageIsEnabled=true/){
@{$lref}[$ln] = "infoPageIsEnabled=false";
print "Disabled infoPageIsEnabled in application.properties</br>";
last;
}
$ln=$ln+1;
}
flush_file_lines($prop_file);
print "infoPageIsEnabled disabled</br>";
}
sub remove_demodir(){
my $demo_dir = get_jasper_home().'/reports/demo';
&unlink_file($demo_dir);
print $demo_dir.' removed</br>';
}
sub encrypt_prop_passwords(){
#/home/tomcat/apache-tomcat-9.0.6/webapps/JasperReportsIntegration/WEB-INF/classes# java -cp ".:../lib/*" main/CommandLine encryptPasswords ../../../../jasper_reports/conf/application.properties
my $web_inf = get_catalina_home().'/webapps/JasperReportsIntegration/WEB-INF';
my $cmd = "cd $web_inf/classes; java -cp '.:../lib/*' main/CommandLine encryptPasswords ".get_jasper_home()."/conf/application.properties";
exec_cmd($cmd);
print "Password encrypted</br>";
}
sub enter_allowed_ips(){
print &ui_form_start("checks.cgi");
print ui_hidden('mode', 'update_allowed_ips');
print "$text{'checks_enter_ips_desc'}: 127.0.0.1,10.10.10.10,192.168.178.31</br>";
print $text{'checks_ip_list'}.&ui_textbox("ip_list", '', 40);
print &ui_submit('save');
print &ui_form_end();
}
sub update_allowed_ips(){
my $prop_file = get_prop_file();
#validate the input
my @ips = split(/,/, $in{'ip_list'});
foreach my $ip (@ips){
if( (check_ipaddress($ip) == 1) ||
(check_ip6address($ip) == 0)){
next;
}else{
print "IP $ip is invalid</br>";
return;
}
}
my $ln=0;
my $lref = &read_file_lines($prop_file);
foreach my $line (@$lref){
if($line =~ /(?:# )ipAddressListAllowed=/){
@{$lref}[$ln] = "ipAddressListAllowed=".$in{'ip_list'};
last;
}
$ln=$ln+1;
}
flush_file_lines($prop_file);
print "ipAddressListAllowed updated to ".$in{'ip_list'}."</br>";
}
&ui_print_header(undef, $text{'checks_title'}, "");
if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
&ReadParseMime();
}else {
&ReadParse(); $no_upload = 1;
}
%osinfo = &detect_operating_system();
my $mode = $in{'mode'} || "checks";
if($mode eq "install_firewalld"){ install_firewalld();
}elsif($mode eq "disable_infopage"){ disable_info_page_is_enabled();
}elsif($mode eq "remove_demodir"){ remove_demodir();
}elsif($mode eq "enc_prop_pwd"){ encrypt_prop_passwords();
}elsif($mode eq "enter_allowed_ips"){ enter_allowed_ips();
}elsif($mode eq "update_allowed_ips"){ update_allowed_ips();
}else{
print "Error: Invalid checks mode\n";
}
&ui_print_footer("", $text{'index_return'}, 'security.cgi', $text{'security_return'});