is one of
21 | echo. html to make standalone HTML files
22 | echo. dirhtml to make HTML files named index.html in directories
23 | echo. singlehtml to make a single large HTML file
24 | echo. pickle to make pickle files
25 | echo. json to make JSON files
26 | echo. htmlhelp to make HTML files and a HTML help project
27 | echo. qthelp to make HTML files and a qthelp project
28 | echo. devhelp to make HTML files and a Devhelp project
29 | echo. epub to make an epub
30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31 | echo. text to make text files
32 | echo. man to make manual pages
33 | echo. texinfo to make Texinfo files
34 | echo. gettext to make PO message catalogs
35 | echo. changes to make an overview over all changed/added/deprecated items
36 | echo. xml to make Docutils-native XML files
37 | echo. pseudoxml to make pseudoxml-XML files for display purposes
38 | echo. linkcheck to check all external links for integrity
39 | echo. doctest to run all doctests embedded in the documentation if enabled
40 | goto end
41 | )
42 |
43 | if "%1" == "clean" (
44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
45 | del /q /s %BUILDDIR%\*
46 | goto end
47 | )
48 |
49 |
50 | %SPHINXBUILD% 2> nul
51 | if errorlevel 9009 (
52 | echo.
53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
54 | echo.installed, then set the SPHINXBUILD environment variable to point
55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you
56 | echo.may add the Sphinx directory to PATH.
57 | echo.
58 | echo.If you don't have Sphinx installed, grab it from
59 | echo.http://sphinx-doc.org/
60 | exit /b 1
61 | )
62 |
63 | if "%1" == "html" (
64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
65 | if errorlevel 1 exit /b 1
66 | echo.
67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html.
68 | goto end
69 | )
70 |
71 | if "%1" == "dirhtml" (
72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
73 | if errorlevel 1 exit /b 1
74 | echo.
75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
76 | goto end
77 | )
78 |
79 | if "%1" == "singlehtml" (
80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
81 | if errorlevel 1 exit /b 1
82 | echo.
83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
84 | goto end
85 | )
86 |
87 | if "%1" == "pickle" (
88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
89 | if errorlevel 1 exit /b 1
90 | echo.
91 | echo.Build finished; now you can process the pickle files.
92 | goto end
93 | )
94 |
95 | if "%1" == "json" (
96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
97 | if errorlevel 1 exit /b 1
98 | echo.
99 | echo.Build finished; now you can process the JSON files.
100 | goto end
101 | )
102 |
103 | if "%1" == "htmlhelp" (
104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
105 | if errorlevel 1 exit /b 1
106 | echo.
107 | echo.Build finished; now you can run HTML Help Workshop with the ^
108 | .hhp project file in %BUILDDIR%/htmlhelp.
109 | goto end
110 | )
111 |
112 | if "%1" == "qthelp" (
113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
114 | if errorlevel 1 exit /b 1
115 | echo.
116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^
117 | .qhcp project file in %BUILDDIR%/qthelp, like this:
118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp
119 | echo.To view the help file:
120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc
121 | goto end
122 | )
123 |
124 | if "%1" == "devhelp" (
125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
126 | if errorlevel 1 exit /b 1
127 | echo.
128 | echo.Build finished.
129 | goto end
130 | )
131 |
132 | if "%1" == "epub" (
133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
134 | if errorlevel 1 exit /b 1
135 | echo.
136 | echo.Build finished. The epub file is in %BUILDDIR%/epub.
137 | goto end
138 | )
139 |
140 | if "%1" == "latex" (
141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
142 | if errorlevel 1 exit /b 1
143 | echo.
144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
145 | goto end
146 | )
147 |
148 | if "%1" == "latexpdf" (
149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
150 | cd %BUILDDIR%/latex
151 | make all-pdf
152 | cd %BUILDDIR%/..
153 | echo.
154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
155 | goto end
156 | )
157 |
158 | if "%1" == "latexpdfja" (
159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
160 | cd %BUILDDIR%/latex
161 | make all-pdf-ja
162 | cd %BUILDDIR%/..
163 | echo.
164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
165 | goto end
166 | )
167 |
168 | if "%1" == "text" (
169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
170 | if errorlevel 1 exit /b 1
171 | echo.
172 | echo.Build finished. The text files are in %BUILDDIR%/text.
173 | goto end
174 | )
175 |
176 | if "%1" == "man" (
177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
178 | if errorlevel 1 exit /b 1
179 | echo.
180 | echo.Build finished. The manual pages are in %BUILDDIR%/man.
181 | goto end
182 | )
183 |
184 | if "%1" == "texinfo" (
185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
186 | if errorlevel 1 exit /b 1
187 | echo.
188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
189 | goto end
190 | )
191 |
192 | if "%1" == "gettext" (
193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
194 | if errorlevel 1 exit /b 1
195 | echo.
196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
197 | goto end
198 | )
199 |
200 | if "%1" == "changes" (
201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
202 | if errorlevel 1 exit /b 1
203 | echo.
204 | echo.The overview file is in %BUILDDIR%/changes.
205 | goto end
206 | )
207 |
208 | if "%1" == "linkcheck" (
209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
210 | if errorlevel 1 exit /b 1
211 | echo.
212 | echo.Link check complete; look for any errors in the above output ^
213 | or in %BUILDDIR%/linkcheck/output.txt.
214 | goto end
215 | )
216 |
217 | if "%1" == "doctest" (
218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
219 | if errorlevel 1 exit /b 1
220 | echo.
221 | echo.Testing of doctests in the sources finished, look at the ^
222 | results in %BUILDDIR%/doctest/output.txt.
223 | goto end
224 | )
225 |
226 | if "%1" == "xml" (
227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
228 | if errorlevel 1 exit /b 1
229 | echo.
230 | echo.Build finished. The XML files are in %BUILDDIR%/xml.
231 | goto end
232 | )
233 |
234 | if "%1" == "pseudoxml" (
235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
236 | if errorlevel 1 exit /b 1
237 | echo.
238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
239 | goto end
240 | )
241 |
242 | :end
243 |
--------------------------------------------------------------------------------
/docs/readme.rst:
--------------------------------------------------------------------------------
1 | .. include:: ../README.rst
2 |
--------------------------------------------------------------------------------
/docs/usage.rst:
--------------------------------------------------------------------------------
1 | ========
2 | Usage
3 | ========
4 |
5 | Tomcat Module:
6 |
7 | .. image:: https://cdn.acugis.com/apache-tomcat-webmin-plugin/tomcat-module-plugin.gif
8 |
9 | Tomcat Module WAR Manager:
10 |
11 | .. image:: https://cdn.acugis.com/apache-tomcat-webmin-plugin/tomcat-module-war-deploy.gif
12 |
13 | Tomcat Module Configuration Editor:
14 |
15 | .. image:: https://cdn.acugis.com/apache-tomcat-webmin-plugin/tomcat-module-edit-configs.gif
16 |
--------------------------------------------------------------------------------
/edit_java.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | require './java-lib.pl';
5 | require '../webmin/webmin-lib.pl'; #for OS detection
6 |
7 | &ReadParse();
8 |
9 | &ui_print_header(undef, $text{'java_title'}, "");
10 |
11 | # Show tabs
12 | @tabs = ( [ "install", $text{'java_tabinstall'}, "edit_java.cgi?mode=install" ],
13 | [ "uninstall", $text{'java_tabuninstall'}, "edit_java.cgi?mode=uninstall" ],
14 | [ "default", $text{'java_tabdefault'}, "edit_java.cgi?mode=default" ]
15 | );
16 |
17 | print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "install", 1);
18 |
19 |
20 | print &ui_tabs_start_tab("mode", "install");
21 | print "$text{'java_desc1'}\n";
22 |
23 | print &ui_form_start("install_java.cgi", "form-data");
24 | print &ui_table_start($text{'java_install'}, undef, 2);
25 |
26 | my %jdk_version = &get_latest_jdk_version();
27 | @opt_avail_jdk = ();
28 | foreach $ver (keys %jdk_version) {
29 | push(@opt_avail_jdk, [ "$ver=$jdk_version{$ver}", $ver]);
30 | }
31 |
32 | my %openjdk_version = &get_openjdk_versions();
33 | @opt_avail_openjdk = ();
34 | foreach $ver (reverse sort { $a <=> $b } keys %openjdk_version) {
35 | push(@opt_avail_openjdk, [ "$ver=$openjdk_version{$ver}", $ver]);
36 | }
37 |
38 | print &ui_table_row($text{'jdk_installsource'},
39 | &ui_radio_table("source", 200,
40 | [ [ 200, $text{'openjdk_latest'}, &ui_select("openjdk_ver", undef, \@opt_avail_openjdk, 1, 0).
41 | '
'.
42 | &ui_checkbox("openjdk_headless", 1,undef, 1).$text{'openjdk_headless'}.
43 | &ui_hr()],
44 | [ 100, $text{'jdk_latest'}, &ui_select("jdk_ver", undef, \@opt_avail_jdk, 1, 0)],
45 | [ 0, $text{'source_local'}, &ui_textbox("file", undef, 40)." ". &file_chooser_button("file", 0) ],
46 | [ 1, $text{'source_uploaded'},&ui_upload("upload", 40) ],
47 | [ 2, $text{'source_ftp'}, &ui_textbox("url", undef, 40) ]
48 | ]), 2);
49 | print &ui_table_row($text{'java_def_jdk'},
50 | &ui_checkbox("def_jdk", 1,undef, 1).$text{'java_def_jdk_desc'}
51 | ,2);
52 |
53 |
54 | print &ui_table_end();
55 | print &ui_form_end([ [ "", $text{'java_installok'} ] ]);
56 | print &ui_tabs_end_tab();
57 |
58 |
59 | print &ui_tabs_start_tab("mode", "uninstall");
60 | print "$text{'java_desc2'}
\n";
61 |
62 | print &ui_form_start("uninstall_java.cgi", "post");
63 | print &ui_table_start($text{'java_uninstall'}, undef, 2);
64 |
65 | @jdk_vlist = &get_installed_jdk_versions();
66 | @opts_inst_jdk = ( );
67 | foreach $jdk_ver (@jdk_vlist) {
68 | push(@opts_inst_jdk, [ $jdk_ver, $jdk_ver ]);
69 | }
70 | print &ui_table_row($text{'java_installed'}, &ui_select("inst_jdk", undef, \@opts_inst_jdk, 1, 0)."
\n", 2);
71 | print &ui_table_row($text{'java_rm_def_jdk'}, &ui_checkbox("rm_def_jdk", 1,undef, 1), 2);
72 |
73 | print &ui_table_end();
74 | print &ui_form_end([ [ "", $text{'java_deleteok'} ] ]);
75 | print &ui_tabs_end_tab();
76 |
77 | print &ui_tabs_start_tab("mode", "default");
78 | print "$text{'java_desc3'}
\n";
79 |
80 | print &ui_form_start("default_java.cgi", "post");
81 | print &ui_table_start($text{'java_default'}, undef, 2);
82 |
83 | print &ui_table_row($text{'java_installed'}, &ui_select("inst_jdk2", undef, \@opts_inst_jdk, 1, 0)."
\n", 2);
84 |
85 | print &ui_table_end();
86 | print &ui_form_end([ [ "", $text{'java_defaultok'} ] ]);
87 | print &ui_tabs_end_tab();
88 |
89 | print &ui_tabs_end(1);
90 |
91 | &ui_print_footer("", $text{'index_return'});
92 |
--------------------------------------------------------------------------------
/edit_libs.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | &ReadParse();
5 |
6 | &ui_print_header(undef, $text{'libs_title'}, "");
7 |
8 | # Show tabs
9 | @tabs = ( [ "install", $text{'libs_tabinstall'}, "edit_libs.cgi?mode=install" ],
10 | [ "uninstall", $text{'libs_tabuninstall'}, "edit_libs.cgi?mode=uninstall" ]
11 | );
12 |
13 | print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "install", 1);
14 |
15 | # Display installation form
16 | print &ui_tabs_start_tab("mode", "install");
17 | print "$text{'libs_desc1'}
\n";
18 |
19 | print &ui_form_start("install_libs.cgi", "form-data");
20 | print &ui_table_start($text{'libs_install'}, undef, 2);
21 |
22 | print &ui_table_row($text{'libs_installsource'},
23 | &ui_radio_table("source", 0,
24 | [ [ 0, $text{'source_local'}, &ui_textbox("file", undef, 40)." ". &file_chooser_button("file", 0) ],
25 | [ 1, $text{'source_uploaded'},&ui_upload("upload", 40) ],
26 | [ 2, $text{'source_ftp'}, &ui_textbox("url", undef, 40) ]
27 | ]));
28 |
29 | print &ui_table_end();
30 | print &ui_form_end([ [ "", $text{'libs_installok'} ] ]);
31 | print &ui_tabs_end_tab();
32 |
33 |
34 | # Display deletion form
35 | print &ui_tabs_start_tab("mode", "uninstall");
36 | print "$text{'libs_desc2'}
\n";
37 |
38 | print &ui_form_start("uninstall_libs.cgi", "post");
39 | print &ui_table_start($text{'libs_delete'}, undef, 2);
40 |
41 | @libs_lists = &get_installed_libs();
42 | @opts_inst_libs = ( );
43 | foreach $lib_file (@libs_lists) {
44 | $lib_file =~ /^lib_([a-z0-9\.\-_\s]+)\.list$/i;
45 | push(@opts_inst_libs, [ $1, $1 ]);
46 | }
47 | print &ui_table_row($text{'libs_installed'}, &ui_select("inst_lib", undef, \@opts_inst_libs, 10, 1), 2);
48 |
49 | print &ui_table_end();
50 | print &ui_form_end([ [ "", $text{'libs_deleteok'} ] ]);
51 | print &ui_tabs_end_tab();
52 |
53 |
54 | print &ui_tabs_end(1);
55 |
56 | &ui_print_footer("", $text{'index_return'});
57 |
--------------------------------------------------------------------------------
/edit_manual.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # Show a page for manually editing an Tomcat server.xml config file
3 |
4 | require './tomcat-lib.pl';
5 | &ReadParse();
6 | &ui_print_header(undef, $text{'manual_title'}, "");
7 |
8 | my $catalina_home = get_catalina_home();
9 |
10 | # Work out and show the files
11 | @files = ( "$catalina_home/bin/setenv.sh",
12 | "$catalina_home/conf/context.xml",
13 | "$catalina_home/conf/server.xml",
14 | "$catalina_home/conf/tomcat-users.xml",
15 | "$catalina_home/conf/web.xml");
16 | $in{'file'} ||= $files[0];
17 | &indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
18 |
19 | print &ui_form_start("edit_manual.cgi");
20 | print "$text{'manual_file'}\n";
21 | print &ui_select("file", $in{'file'}, [ map { [ $_ ] } @files ], 1, 0);
22 | print &ui_submit($text{'manual_ok'});
23 | print &ui_form_end();
24 |
25 | # Show the file contents
26 | print &ui_form_start("save_manual.cgi", "form-data");
27 | print &ui_hidden("file", $in{'file'}),"\n";
28 | $data = &read_file_contents($in{'file'});
29 | print &ui_textarea("data", $data, 20, 80),"\n";
30 | print &ui_form_end([ [ "save", $text{'save'} ] ]);
31 |
32 | &ui_print_footer("", $text{'index_return'});
33 |
34 |
--------------------------------------------------------------------------------
/edit_proxy.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | foreign_require('apache', 'apache-lib.pl');
5 |
6 | sub get_proxy_file{
7 | my $domain_user = $_[0];
8 | my $proxy_file = '';
9 |
10 | if( -d '/etc/httpd/conf.d' ){
11 | $proxy_file = '/etc/httpd/conf.d/tomcat.conf';
12 | }elsif( -d '/etc/apache2/conf-enabled/'){ #ubuntu or debian
13 | $proxy_file = '/etc/apache2/conf-enabled/tomcat.conf';
14 | }
15 | return $proxy_file;
16 | }
17 |
18 | sub load_proxy_maps{
19 | my $proxy_file = $_[0];
20 |
21 | my %maps;
22 | open(my $fh, '<', $proxy_file) or return %maps;
23 | while(my $line = <$fh>){
24 | if($line =~ /^ProxyPass ([\/a-z0-9_\-\.]+) ([a-z:\/0-9\.\-]+)/i){
25 | $maps{$2} = $1;
26 | }
27 | }
28 | close $fh;
29 |
30 | return %maps;
31 | }
32 |
33 | sub add_proxy{
34 | my $proxy_file = $_[0];
35 | my $app_name = $_[1];
36 | my $default = $_[2];
37 | my $ssl_port = $_[3];
38 | my $wildcard = $_[4];
39 |
40 | my %idata = ('port_http'=>'8080', 'port_https'=>'8443');
41 |
42 | my $app_path = '/';
43 | if($default == 0){ #if app is not default
44 | $app_path .= $app_name;
45 | }
46 |
47 | if($wildcard == 1){
48 | $app_name = '';
49 | }
50 |
51 | my $lref = &read_file_lines($proxy_file);
52 | my $lnum = 0;
53 | my $proxy_header_section = 0;
54 | my $user_domain = 'localhost';
55 | foreach my $line (@$lref) {
56 | if($line =~ /^ProxyPass \/ |^ProxyPassReverse \/ /){ #another default app
57 | if($default == 1){ #if new app is default
58 | delete @{$lref}[$lnum]; #remove old default app
59 | }
60 | }elsif($line =~ /^ProxyPass.*\/$app_name$/){ #if its a line with our app
61 | delete @{$lref}[$lnum];
62 | }elsif($line =~ /^ProxyRequests Off$/){
63 | $proxy_header_section = 1; #proxy settings are found
64 | }elsif($line =~ /^ServerName (.*)$/){
65 | $user_domain = $1;
66 | }
67 | $lnum++;
68 | }
69 |
70 |
71 | my $conf_tail;
72 | if(@$lref[$lnum] eq ''){
73 | $conf_tail = pop @{$lref};
74 | }
75 | if($proxy_header_section == 0){
76 | my $line = "ProxyRequests Off
77 | ProxyPreserveHost On
78 |
79 | Order allow,deny
80 | Allow from all
81 | ";
82 | push(@$lref, $line);
83 | }
84 |
85 | my $proto = '';
86 | if($ssl_port == 1){
87 | $proto = 's';
88 | }
89 |
90 | push(@$lref, "ProxyPass $app_path http".$proto."://$user_domain:".$idata{'port_http'.$proto}."/$app_name");
91 | push(@$lref, "ProxyPassReverse $app_path http".$proto."://$user_domain:".$idata{'port_http'.$proto}."/$app_name");
92 | if($conf_tail){
93 | push(@$lref, $conf_tail); #Restore conf end
94 | }
95 |
96 | flush_file_lines($proxy_file);
97 | }
98 |
99 | sub remove_proxy{
100 | my ($proxy_file, $app_path) = @_;
101 |
102 | my $lref = &read_file_lines($proxy_file);
103 | my $lnum = 0;
104 | foreach my $line (@$lref) {
105 | if($line =~ /^ProxyPass $app_path |^ProxyPassReverse $app_path /){ #if its a line with our app
106 | delete @{$lref}[$lnum];
107 | }
108 | $lnum++;
109 | }
110 | flush_file_lines($proxy_file);
111 | }
112 |
113 | &ReadParse();
114 |
115 | my $form_submit = 0;
116 | if ($in{'submit_flag'}) {
117 | $form_submit = 1;
118 | }
119 |
120 | &ui_print_header(undef, $text{'proxy_title'}, "");
121 |
122 |
123 | my $proxy_file = get_proxy_file($remote_user);
124 | if($proxy_file eq ''){
125 | print "Error: Failed to find proxy file for user $remote_user"
126 | }
127 |
128 | if($form_submit == 1){
129 | if($in{'app_path'}){
130 | remove_proxy($proxy_file, $in{'app_path'});
131 | }else{
132 | add_proxy($proxy_file, $in{'app_name'}, $in{'app_default'}, $in{'proxy_ssl'}, $in{'app_wildcard'});
133 | }
134 | apache::restart_apache();
135 | }
136 |
137 | my %maps = load_proxy_maps($proxy_file);
138 | my @tds = ();
139 | print &ui_columns_start(['Path','URL'], undef, 0, \@tds, 'Apps with proxy ('.$proxy_file.')');
140 | foreach my $url (keys %maps) {
141 |
142 | my @cols;
143 | push(@cols, $maps{$url});
144 | push(@cols, "$url");
145 |
146 | print &ui_columns_row(\@cols, \@tds);
147 | }
148 | print &ui_columns_end();
149 |
150 |
151 | print &ui_form_start("edit_proxy.cgi", "post");
152 | print &ui_hidden('submit_flag', 1);
153 | print &ui_table_start($text{'proxy_add_options'}, undef, 2);
154 |
155 | my @apps = get_all_war_infos();
156 | @opt_apps = ( );
157 | foreach $app (@apps) {
158 | push(@opt_apps, [ $app, $app ]);
159 | }
160 | print &ui_table_row($text{'proxy_wildcard'},
161 | &ui_checkbox("app_wildcard", 1, $text{'proxy_wildcard_info'}, 0), 2);
162 | print &ui_table_hr();
163 | print &ui_table_row($text{'wars_installed'}, &ui_select("app_name", undef, \@opt_apps, 10, 1), 2);
164 | print &ui_table_row($text{'proxy_default_app'},
165 | &ui_checkbox("app_default", 1, $text{'proxy_app_default_warning'}, 0), 2);
166 | print &ui_table_row($text{'proxy_ssl'},
167 | &ui_checkbox("proxy_ssl", 1, $text{'proxy_ssl_info'}, 0), 2);
168 |
169 | print &ui_table_end();
170 | print &ui_form_end([ [ "", $text{'proxy_installok'} ] ]);
171 |
172 |
173 | print &ui_form_start("edit_proxy.cgi", "post");
174 | print &ui_hidden('submit_flag', 1);
175 | print &ui_table_start($text{'proxy_remove_options'}, undef, 2);
176 |
177 |
178 | @opt_paths = ( );
179 | foreach $path (keys %maps) {
180 | my $val = $maps{$path};
181 | push(@opt_paths, [ $val, $val ]);
182 | }
183 | print &ui_table_row($text{'proxy_list'}, &ui_select("app_path", undef, \@opt_paths, 10, 1), 2);
184 |
185 | print &ui_table_end();
186 | print &ui_form_end([ [ "", $text{'proxy_removeok'} ] ]);
187 |
188 | &ui_print_footer("", $text{'index_return'});
189 |
--------------------------------------------------------------------------------
/edit_war.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | &ReadParse();
5 |
6 | &ui_print_header(undef, $text{'wars_title'}, "");
7 |
8 | # Show tabs
9 | @tabs = ( [ "install", $text{'wars_tabinstall'}, "edit_wars.cgi?mode=install" ],
10 | [ "delete", $text{'wars_tabdelete'}, "edit_wars.cgi?mode=delete" ]
11 | );
12 |
13 | print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || "install", 1);
14 |
15 | # Display installation form
16 | print &ui_tabs_start_tab("mode", "install");
17 | print "$text{'wars_desc1'}
\n";
18 |
19 | print &ui_form_start("install_war.cgi", "form-data");
20 | print &ui_table_start($text{'war_install'}, undef, 2);
21 |
22 | print &ui_table_row($text{'war_installsource'},
23 | &ui_radio_table("source", 0,
24 | [ [ 0, $text{'source_local'}, &ui_textbox("file", undef, 40)." ". &file_chooser_button("file", 0) ],
25 | [ 1, $text{'source_uploaded'}, &ui_upload("upload", 40) ],
26 | [ 2, $text{'source_ftp'},&ui_textbox("url", undef, 40) ]
27 | ]));
28 |
29 | print &ui_table_end();
30 | print &ui_form_end([ [ "", $text{'war_installok'} ] ]);
31 | print &ui_tabs_end_tab();
32 |
33 |
34 | # Display deletion form
35 | print &ui_tabs_start_tab("mode", "delete");
36 | print "$text{'wars_desc2'}
\n";
37 |
38 | print &ui_form_start("delete_war.cgi", "post");
39 | print &ui_table_start($text{'wars_delete'}, undef, 2);
40 |
41 | @wlist = &get_all_war_infos();
42 | @opts = ( );
43 | foreach $d (@wlist) {
44 | push(@opts, [ $d, $d ]);
45 | }
46 | print &ui_table_row($text{'wars_installed'},
47 | &ui_select("mod", undef, \@opts, 10, 1)."
\n".
48 | &ui_checkbox("rmwar", 1, $text{'wars_rmwar'}, 0), 2);
49 |
50 | print &ui_table_end();
51 | print &ui_form_end([ [ "", $text{'wars_deleteok'} ] ]);
52 | print &ui_tabs_end_tab();
53 |
54 |
55 | print &ui_tabs_end(1);
56 |
57 | &ui_print_footer("", $text{'index_return'});
58 |
--------------------------------------------------------------------------------
/help/intro.html:
--------------------------------------------------------------------------------
1 | Apache_Tomcat">Apache Tomcat
2 |
3 |
Module produced by Cited, Inc. © 2019 AcuGIS, Cited, Inc.
4 |
5 | The Apache Tomcat® software is an open source implementation
6 | of the Java Servlet, JavaServer Pages, Java Expression Language and Java
7 | WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression
8 | Language and Java WebSocket specifications are developed under the
9 | Java Community
10 | Process.
11 |
12 |
13 | The Apache Tomcat software is developed in an open and participatory
14 | environment and released under the
15 | Apache License version 2. The
16 | Apache Tomcat project is intended to be a collaboration of the best-of-breed
17 | developers from around the world. We invite you to participate in this open
18 | development project. To learn more about getting involved,
19 | click here.
20 |
21 | Apache Tomcat software powers numerous large-scale, mission-critical web
22 | applications across a diverse range of industries and organizations. Some of
23 | these users and their stories are listed on the
24 | PoweredBy wiki page.
25 |
26 | Apache Tomcat, Tomcat, Apache, the Apache feather, and the Apache Tomcat
27 | project logo are trademarks of the Apache Software Foundation.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/images/edit-file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/edit-file.png
--------------------------------------------------------------------------------
/images/icon.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/icon.gif
--------------------------------------------------------------------------------
/images/jar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/jar.png
--------------------------------------------------------------------------------
/images/java.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/java.png
--------------------------------------------------------------------------------
/images/manual.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/manual.gif
--------------------------------------------------------------------------------
/images/mapping.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/mapping.png
--------------------------------------------------------------------------------
/images/war.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/images/war.png
--------------------------------------------------------------------------------
/index.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # index.cgi
3 |
4 | require './tomcat-lib.pl';
5 | require '../webmin/webmin-lib.pl'; #for OS detection
6 |
7 | # Check if config file exists
8 | if (! -r $config{'tomcat_config'}) {
9 | &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
10 | print &text('index_econfig', "$config{'tomcat_config'}",
11 | "$gconfig{'webprefix'}/config.cgi?$module_name"),"\n";
12 | &ui_print_footer("/", $text{"index"});
13 | exit;
14 | }
15 |
16 | if(-f "$module_root_directory/setup.cgi"){
17 | &redirect("setup.cgi?mode=checks");
18 | exit;
19 | }
20 |
21 | my %version = get_catalina_version();
22 |
23 | &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
24 | &help_search_link("tomcat", "man", "doc", "google"), undef, undef,
25 | "Tomcat $version{'number'} / Java $version{'jvm'}");
26 |
27 | push(@links, "edit_manual.cgi");
28 | push(@titles, $text{'manual_title'});
29 | push(@icons, "images/edit-file.png");
30 |
31 | push(@links, "edit_war.cgi");
32 | push(@titles, $text{'wars_title'});
33 | push(@icons, "images/war.png");
34 |
35 | push(@links, "edit_libs.cgi");
36 | push(@titles, $text{'libs_title'});
37 | push(@icons, "images/jar.png");
38 |
39 | push(@links, "edit_java.cgi");
40 | push(@titles, $text{'java_title'});
41 | push(@icons, "images/java.png");
42 |
43 | push(@links, "edit_proxy.cgi");
44 | push(@titles, $text{'proxy_title'});
45 | push(@icons, "images/mapping.png");
46 |
47 | &icons_table(\@links, \@titles, \@icons, 2);
48 |
49 | # Check if tomcat is running
50 | print &ui_hr().&ui_buttons_start();
51 | my ($running, $status) = &tomcat_service_ctl('status');
52 | print "$status
";
53 | if ($running == 1) {
54 | # Running .. offer to apply changes and stop
55 | print &ui_buttons_row("stop.cgi", $text{'index_stop'}, "$text{'index_stopmsg'}");
56 | print &ui_buttons_row("restart.cgi", $text{'index_restart'}, "$text{'index_restartmsg'}");
57 | }else {
58 | # Not running .. offer to start
59 | print &ui_buttons_row("start.cgi", $text{'index_start'}, $text{'index_startmsg'});
60 | }
61 |
62 |
63 | #Check for an update of tomcat, once a day
64 | my $latest_ver = upgrade_available();
65 | if($latest_ver){
66 | print &ui_buttons_row("tomcat_upgrade.cgi?mode=select_version", $text{'index_upgrade'}, "Tomcat can be updated to $latest_ver.");
67 | }elsif($config{'always_show_upgrade_btn'}){
68 | print &ui_buttons_row("tomcat_upgrade.cgi?mode=select_version", $text{'index_upgrade'}, "Upgrade Tomcat server");
69 | }
70 | print &ui_buttons_end();
71 |
72 |
73 | &ui_print_footer("/", $text{"index"});
74 |
--------------------------------------------------------------------------------
/install_check.sh:
--------------------------------------------------------------------------------
1 | # install_check.pl
2 |
3 | do 'tomcat-lib.pl';
4 |
5 | # is_installed(mode)
6 | # For mode 1, returns 2 if the server is installed and configured for use by
7 | # Webmin, 1 if installed but not configured, or 0 otherwise.
8 | # For mode 0, returns 1 if installed, 0 if not
9 | sub is_installed
10 | {
11 | return 0 if (!-r $config{'tomcat_config'} || !&has_command($config{'tomcat_path'}));
12 | return $_[0] ? 2 : 1;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/install_java.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | require './java-lib.pl';
5 | require '../webmin/webmin-lib.pl'; #require
6 | foreign_require('software', 'software-lib.pl');
7 |
8 | use File::Basename;
9 |
10 | sub extract_java_archive{
11 | my $jdk_archive = $_[0];
12 |
13 | my $java_dir = '/usr/java';
14 | if( ! -d $java_dir){
15 | &make_dir($java_dir, 0755, 1);
16 | }
17 |
18 | $cmd_out='';
19 | $cmd_err='';
20 | print "
Extracting $jdk_archive to $java_dir...
";
21 | local $out = &execute_command("tar -x -v --overwrite -f \"$jdk_archive\" -C/usr/java", undef, \$cmd_out, \$cmd_err, 0, 0);
22 |
23 | my $jdk_tar_first_line = ( split /\n/, $cmd_out )[0];
24 | my $jdk_dir = $java_dir."/".(split /\//, $jdk_tar_first_line)[0];
25 |
26 | if($cmd_err){
27 | $cmd_err = s/\n/
/g;
28 | &error("Error: tar: $cmd_err");
29 | }else{
30 | $cmd_out = s/\n/
/g;
31 | print &html_escape($cmd_out);
32 | }
33 |
34 | &set_ownership_permissions('root','root', 0755, $jdk_dir);
35 | &execute_command("chown -R root:root $jdk_dir", undef, \$cmd_out, \$cmd_err, 0, 0);
36 | if($cmd_err){
37 | $cmd_err = s/\n/
/g;
38 | &error("Error: chown: $cmd_err");
39 | }
40 |
41 | return $jdk_dir;
42 | }
43 |
44 | #$| = 1;
45 |
46 | if ($ENV{REQUEST_METHOD} eq "POST") {
47 | &ReadParse(\%getin, "GET");
48 | &ReadParseMime(undef, \&read_parse_mime_callback, [ $getin{'id'} ]);
49 | }
50 | else {
51 | &ReadParse();
52 | $no_upload = 1;
53 | }
54 | &error_setup($text{'install_err'});
55 | &ui_print_header(undef, $text{'java_title'}, "");
56 |
57 | my $jdk_path = '';
58 | if($in{'source'} == 200){
59 |
60 | my $jdk_name = (split /=/, $in{'openjdk_ver'})[1];
61 | my $openjdk_pkg = $jdk_name;
62 | if($in{'openjdk_headless'} == 1){
63 | $openjdk_pkg .= '-headless';
64 | }
65 |
66 | software::update_system_install($openjdk_pkg, undef);
67 | $jdk_path = get_jdk_dir_by_name($jdk_name);
68 |
69 | } else {
70 | if ($in{'source'} == 100) {
71 |
72 | my ($jdk_name, $url) = split /=/, $in{'jdk_ver'};
73 | $in{'url'} = $url;
74 | $in{'source'} = 2;
75 | }
76 | my $jdk_archive = process_file_source();
77 | $jdk_path = extract_java_archive($jdk_archive);
78 | }
79 |
80 | if($in{'def_jdk'} == 1){
81 | set_default_java($jdk_path);
82 | }
83 |
84 | print "
Done
";
85 | &ui_print_footer("", $text{'index_return'});
86 |
--------------------------------------------------------------------------------
/install_libs.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 |
5 | use File::Basename;
6 | use File::Path 'rmtree';
7 |
8 | sub inst_error{
9 | print "$main::whatfailed : $_[0] \n";
10 | &ui_print_footer("", $text{'index_return'});
11 | exit;
12 | }
13 |
14 | if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
15 | &ReadParseMime();
16 | }else {
17 | &ReadParse();
18 | $no_upload = 1;
19 | }
20 |
21 | $| = 1;
22 | &ui_print_header(undef, $text{'libs_install_title'}, "");
23 |
24 | my $lib_file = process_file_source();
25 | my @suffixlist = ('\.zip', '\.jar');
26 | ($lib_name,$path,$lib_suffix) = fileparse($lib_file,@suffixlist);
27 |
28 | my $unzip_dir = '';
29 | my @lib_jars;
30 |
31 | #Check if its a .zip or .jar
32 | print "Source: $lib_file
";
33 | if($lib_suffix eq ".zip"){
34 | $unzip_dir = unzip_file($lib_file);
35 |
36 | #make a list of extension jars
37 | opendir(DIR, $unzip_dir) or die $!;
38 | @lib_jars = grep { $_ = $unzip_dir.'/'.$_ ; -f && /\.jar$/ } readdir(DIR);
39 | closedir(DIR);
40 |
41 | }elsif($lib_suffix eq ".jar"){
42 | push(@lib_jars, $lib_file);
43 | }else{
44 | &error("Error: Unsupported file type $lib_suffix");
45 | &ui_print_footer("", $text{'index_return'});
46 | }
47 |
48 | print "
Installing $lib_name files...
";
49 | my $catalina_home = get_catalina_home();
50 |
51 | #move jars to Tomcat lib and save list of installed jars to lib file
52 | open(my $fh, '>', "$module_config_directory/lib_$lib_name.list") or die "open:$!";
53 | foreach $j (@lib_jars) {
54 | #move jars to Tomcat lib
55 | if(!move("$j", "$catalina_home/lib/")){
56 | &error("Error: Can't move file: $!");
57 | }
58 | my $j_name = basename($j);
59 | &set_ownership_permissions('tomcat','tomcat', 0444, "$catalina_home/lib/$j_name");
60 |
61 | print "$catalina_home/lib/$j_name
";
62 | print $fh "$j_name=$catalina_home/lib/$j_name\n";
63 | }
64 | close $fh;
65 |
66 | print "
Done.
";
67 |
68 | if($unzip_dir ne ''){
69 | &rmtree($unzip_dir); #remove temp dir
70 | }
71 |
72 | &ui_print_footer("", $text{'index_return'});
73 |
--------------------------------------------------------------------------------
/install_war.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | use File::Basename;
5 | use File::Path 'rmtree';
6 |
7 | sub inst_error{
8 | print "$main::whatfailed : $_[0] \n";
9 | &ui_print_footer("", $text{'index_return'});
10 | exit;
11 | }
12 |
13 | if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) { &ReadParseMime(); }
14 | else { &ReadParse(); $no_upload = 1; }
15 |
16 | $| = 1;
17 | $theme_no_table = 1 if ($in{'source'} == 2 || $in{'source'} == 4);
18 | &ui_print_header(undef, $text{'install_title'}, "");
19 |
20 | my $file = process_file_source();
21 |
22 | my @suffixlist = ('\.zip', '\.war');
23 | ($file_name,$path,$file_suffix) = fileparse($file,@suffixlist);
24 |
25 | my $unzip_dir = '';
26 | my @wars;
27 |
28 | #Check if its a .zip or .jar
29 | print "Source: $file
";
30 | if($file_suffix eq ".zip"){
31 | $unzip_dir = unzip_file($file);
32 |
33 | #make a list of extension jars
34 | opendir(DIR, $unzip_dir) or die $!;
35 | @wars = grep { $_ = $unzip_dir.'/'.$_ ; -f && /\.war$/ } readdir(DIR);
36 | closedir(DIR);
37 |
38 | }elsif($file_suffix eq ".war"){
39 | push(@wars, $file);
40 | }else{
41 | &error("Error: Unsupported file type $file_suffix");
42 | &ui_print_footer("", $text{'index_return'});
43 | }
44 |
45 | $catalina_home = get_catalina_home();
46 |
47 | foreach $war (@wars) {
48 | my $war_name = basename($war);
49 | if(!move($war, "$catalina_home/webapps/")){
50 | &error("Error: Can't move file: $!");
51 | }else{
52 | print "Install of $war_name is successful
";
53 | }
54 | &set_ownership_permissions('tomcat','tomcat', 0444, "$catalina_home/webapps/$war_name");
55 | }
56 |
57 | if($unzip_dir ne ''){
58 | &rmtree($unzip_dir); #remove temp dir
59 | }
60 |
61 | #tomcat_service_ctl('restart');
62 |
63 | &ui_print_footer("", $text{'index_return'});
64 |
--------------------------------------------------------------------------------
/java-lib.pl:
--------------------------------------------------------------------------------
1 | =head1 java-lib.pl
2 |
3 | Functions for managing Oracle JDK installations.
4 |
5 | foreign_require("tomcat", "tomcat-lib.pl");
6 | @sites = tomcat::list_tomcat_websites()
7 |
8 | =cut
9 |
10 | BEGIN { push(@INC, ".."); };
11 | use warnings;
12 | use WebminCore;
13 |
14 | foreign_require('software', 'software-lib.pl');
15 |
16 | sub search_pkg{
17 | my $pattern = $_[0];
18 |
19 | my @avail = ();
20 | if (defined(&software::update_system_search)) {
21 | # Call the search function
22 | @avail = &software::update_system_search($pattern);
23 | } else {
24 | # Scan through list manually
25 | @avail = &software::update_system_available();
26 | @avail = grep { $_->{'name'} =~ /\Q$pattern\E/i } @avail;
27 | }
28 | return sort @avail;
29 | }
30 |
31 | sub get_openjdk_patterns(){
32 | my %osinfo = &detect_operating_system();
33 |
34 | my %rv;
35 | if( ($osinfo{'real_os_type'} =~ /centos/i) or #CentOS
36 | ($osinfo{'real_os_type'} =~ /fedora/i) or #Fedora
37 | ($osinfo{'real_os_type'} =~ /rocky/i) or # Rocky
38 | ($osinfo{'real_os_type'} =~ /alma/i) or # Alma
39 | ($osinfo{'real_os_type'} =~ /scientific/i) ){
40 |
41 | $rv{'search'} = 'openjdk';
42 | $rv{'version'} = '^java-([0-9\.]+)-openjdk$';
43 |
44 | }elsif( $osinfo{'os_type'} =~ /debian/i){ #ubuntu
45 | $rv{'search'} = 'openjdk-[0-9]+-jdk$';
46 | $rv{'version'} = 'openjdk-([0-9]+)-jdk';
47 | }
48 | return %rv;
49 | }
50 |
51 | sub get_openjdk_versions(){
52 | my $cache_file = "$module_config_directory/openjdk_version_cache";
53 | my %openjdk_versions;
54 |
55 | if(-f $cache_file){
56 | read_file_cached($cache_file, \%openjdk_versions);
57 |
58 | if($openjdk_versions{'updated'} >= (time() - 86400)){ #if last update was less than a day ago
59 | delete $openjdk_versions{'updated'}; #remove the cache mtime key
60 | return %openjdk_versions;
61 | }
62 | }
63 |
64 | my %patterns = get_openjdk_patterns();
65 | my @avail = search_pkg($patterns{'search'});
66 | foreach $a (@avail) {
67 | if($a->{'name'} =~ /$patterns{'version'}/){
68 | $openjdk_versions{$1} = $a->{'name'};
69 | }
70 | }
71 |
72 | #cache the results
73 | $openjdk_versions{'updated'} = time();
74 | &write_file($cache_file, \%openjdk_versions);
75 | delete $openjdk_versions{'updated'}; #remove the cache mtime key
76 |
77 | return %openjdk_versions;
78 | }
79 |
80 | sub get_latest_jdk_version(){
81 |
82 | my %java_tar_gz;
83 | my $cache_file = "$module_config_directory/oracle_version_cache";
84 | if(-f $cache_file){
85 | read_file_cached($cache_file, \%java_tar_gz);
86 | if($java_tar_gz{'updated'} >= (time() - 86400)){ #if last update was less than a day ago
87 | delete $java_tar_gz{'updated'}; #remove the cache mtime key
88 | return %java_tar_gz;
89 | }
90 | }
91 |
92 | my $error;
93 | my $url = 'https://www.oracle.com/java/technologies/downloads/';
94 | $tmpfile = &transname("javase.html");
95 | &error_setup(&text('install_err3', $url));
96 | &http_download("www.oracle.com", 443, "/java/technologies/downloads/", $tmpfile, \$error,
97 | undef, 1, undef, 0, 0, 1);
98 |
99 | open($fh, '<', $tmpfile) or die "open:$!";
100 | while(my $line = <$fh>){
101 | #https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
102 | if($line =~ /(https:\/\/download.oracle.com\/java\/([0-9]+)\/latest\/jdk-[0-9]+_linux-x64_bin.tar.gz)/){
103 | #if($line =~ /"filepath":"(https:\/\/download.oracle.com\/otn-pub\/java\/jdk\/([a-z0-9-\.+]+)\/[a-z0-9]+\/jdk-[a-z0-9-\.]+_linux-x64_bin.tar.gz)/){
104 | $java_tar_gz{$2} = $1;
105 | #last;
106 | }
107 | }
108 | close $fh;
109 |
110 | #cache the results
111 | $java_tar_gz{'updated'} = time();
112 | &write_file($cache_file, \%java_tar_gz);
113 | delete $java_tar_gz{'updated'}; #remove the cache mtime key
114 |
115 | return %java_tar_gz;
116 | }
117 |
118 | sub get_installed_jdk_versions(){
119 | my @jdks = get_installed_oracle_jdk_versions();
120 |
121 | push(@jdks, get_installed_openjdk_versions());
122 | return @jdks;
123 | }
124 |
125 | sub get_installed_openjdk_versions{
126 |
127 | my @pkgs = ();
128 | my %patterns = get_openjdk_patterns();
129 |
130 | my $cmd_out='';
131 | my $cmd_err='';
132 | if(has_command('rpm')){
133 | local $out = &execute_command("rpm -qa --queryformat \"%{NAME}\n\" \"*$patterns['search']*\"", undef, \$cmd_out, \$cmd_err, 0, 0);
134 |
135 | my @lines = split /\n/, $cmd_out;
136 | foreach my $line (@lines){
137 | if($line =~ /^(java-[0-9\.]+-openjdk).*/i){ #package pgdg96-centos is not installed
138 | push(@pkgs, $1);
139 | }
140 | }
141 | }elsif(has_command('dpkg')){
142 | local $out = &execute_command("dpkg -l \"*openjdk*\"", undef, \$cmd_out, \$cmd_err, 0, 0);
143 |
144 | my %all_pkgs;
145 | my @lines = split /\n/, $cmd_out;
146 | foreach my $line (@lines){
147 | if($line =~ /^(..)\s+(openjdk-[0-9\.]*)-.*:.*/i){
148 | my $pkg = $2;
149 | if($1 =~ /[uirph]i/){
150 | $all_pkgs{$pkg} = 1;
151 | }
152 | }
153 | }
154 | @pkgs = keys %all_pkgs;
155 | }else{
156 | my @dirs;
157 | opendir(DIR, '/usr/java/') or return @dirs;
158 | @dirs
159 | = grep {
160 | /^jdk-[0-9\.]+/
161 | && -d "/usr/java/$_"
162 | } readdir(DIR);
163 | closedir(DIR);
164 | }
165 |
166 | return sort @pkgs;
167 | }
168 |
169 | sub get_installed_oracle_jdk_versions{
170 | my @dirs;
171 | opendir(DIR, '/usr/java/') or return @dirs;
172 | @dirs
173 | = grep {
174 | /^jdk[0-9\.\-_]+/
175 | && -d "/usr/java/$_"
176 | } readdir(DIR);
177 | closedir(DIR);
178 |
179 | return sort @dirs;
180 | }
181 |
182 | sub is_default_jdk{
183 | my $jdk_dir = $_[0];
184 |
185 | my %os_env;
186 | if(-f '/etc/profile.d/jdk.sh'){
187 | read_env_file('/etc/profile.d/jdk.sh', \%os_env);
188 | }elsif(-f '/etc/environment'){
189 | read_env_file('/etc/environment', \%os_env);
190 | }
191 |
192 | if($os_env{'JAVA_HOME'} eq $jdk_dir){
193 | return 1;
194 | }else{
195 | return 0;
196 | }
197 | }
198 |
199 | sub get_java_version(){
200 | local %version;
201 | local $out = &backquote_command('java \-version 2>&1');
202 |
203 | #Oracle Java <= 8
204 | if ($out =~ /Java\(TM\)\sSE\sRuntime\sEnvironment\s\(build\s([0-9]\.([0-9]+)\.[0-9]_([0-9]+)\-([a-z0-9]+))\)/) {
205 | $version{'full'} = $1;
206 | $version{'major'} = $2;
207 | $version{'release'} = $3;
208 | $version{'build'} = $4;
209 | $version{'vendor'} = 'oracle';
210 |
211 | #Oracle Java >=12 - Java(TM) SE Runtime Environment (build 12.0.1+12)
212 | }elsif ($out =~ /Java\(TM\)\sSE\sRuntime\sEnvironment\s\(build\s((\d+)\.\d+\.\d+\+(\d+))\)/) {
213 | $version{'full'} = $1;
214 | $version{'major'} = $2;
215 | $version{'release'} = 0;
216 | $version{'build'} = $3;
217 | $version{'vendor'} = 'oracle';
218 |
219 | # OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
220 | # OpenJDK Runtime Environment (build 11.0.9+11-Ubuntu-0ubuntu1.20.04)
221 | # OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
222 | }elsif ($out =~ /Runtime\sEnvironment\s\(build\s((\d+)\.(\d+)\.\d+[\+_](\d+))/) {
223 | if($2 eq '1'){ #1.8.x
224 | $version{'major'} = $3;
225 | $version{'release'} = $4;
226 | $version{'build'} = $5;
227 | }else{ #11.0.x
228 | $version{'major'} = $2;
229 | $version{'release'} = $3;
230 | $version{'build'} = $4;
231 | }
232 | $version{'full'} = $1;
233 |
234 | $version{'vendor'} = 'openjdk';
235 | }else {
236 | $version{'major'} = 0;
237 | $version{'full'} = $out;
238 | $version{'release'} = 0;
239 | $version{'build'} = 0;
240 | }
241 | return %version;
242 | }
243 |
244 | sub get_java_home(){
245 | my $java_path = &resolve_links('/usr/bin/java');
246 | $java_path =~ s/\/bin\/java//;
247 | return $java_path;
248 | }
249 |
250 | sub set_default_java{
251 | my $jdk_dir = $_[0];
252 |
253 | my $alt_cmd = "";
254 | if(has_command('alternatives')){ #CentOS
255 | $alt_cmd = 'alternatives';
256 | }elsif(has_command('update-alternatives')){ #ubuntu
257 | $alt_cmd = 'update-alternatives';
258 | }else{
259 | print "Warning: No alternatives command found
";
260 | }
261 |
262 | if($alt_cmd ne ""){
263 | print "Updating Java using $alt_cmd
";
264 | my @jdk_progs = ('java', 'jar', 'javac');
265 | foreach my $prog (@jdk_progs){
266 |
267 | $cmd_out='';
268 | $cmd_err='';
269 | local $out = &execute_command("$alt_cmd --install /usr/bin/$prog $prog $jdk_dir/bin/$prog 1", undef, \$cmd_out, \$cmd_err, 0, 0);
270 | $out.= &execute_command("$alt_cmd --set $prog $jdk_dir/bin/$prog", undef, \$cmd_out, \$cmd_err, 0, 0);
271 |
272 | if($cmd_err){
273 | $cmd_err = s/\n/
/g;
274 | &error("Error: $alt_cmd: $cmd_err");
275 | }elsif($cmd_out){
276 | $cmd_out = s/\n/
/g;
277 | print &html_escape($cmd_out);
278 | }
279 | }
280 | }
281 |
282 | print "
Setting Java environment variables...
";
283 | my %os_env;
284 | $os_env{'J2SDKDIR'} = $jdk_dir;
285 | $os_env{'JAVA_HOME'} = $jdk_dir;
286 | $os_env{'DERBY_HOME'}= "$jdk_dir/db";
287 | $os_env{'J2REDIR'} = "$jdk_dir/jre";
288 |
289 | if(-e '/etc/profile.d/'){
290 | $os_env{'PATH'} = "\$PATH:$jdk_dir/bin:$jdk_dir/db/bin:$jdk_dir/jre/bin";
291 | write_env_file('/etc/profile.d/jdk.sh', \%os_env, 1);
292 | }elsif(-e '/etc/environment'){
293 | read_env_file('/etc/environment', \%os_env);
294 | $os_env{'PATH'} = "$os_env{'PATH'}:$jdk_dir/bin:$jdk_dir/db/bin:$jdk_dir/jre/bin";
295 | write_env_file('/etc/environment', \%os_env, 0);
296 | }
297 | }
298 |
299 | sub unset_default_java{
300 | my $jdk_dir = $_[0];
301 | print "Removing Java environment variables ...
";
302 | if(-f '/etc/profile.d/jdk.sh'){
303 | unlink_file('/etc/profile.d/jdk.sh');
304 | }elsif(-f '/etc/environment'){
305 | my %os_env;
306 | read_env_file('/etc/environment', \%os_env);
307 | delete $os_env{'J2SDKDIR'};
308 | delete $os_env{'JAVA_HOME'};
309 | delete $os_env{'DERBY_HOME'};
310 | delete $os_env{'J2REDIR'};
311 | write_env_file('/etc/environment', \%os_env, 0);
312 | }
313 |
314 | my $alt_cmd = "";
315 | if(has_command('alternatives')){ #CentOS
316 | $alt_cmd = 'alternatives';
317 | }elsif(has_command('update-alternatives')){ #ubuntu
318 | $alt_cmd = 'update-alternatives';
319 | }else{
320 | print "Warning: No alternatives command found
";
321 | }
322 |
323 | if($alt_cmd ne ""){
324 | print "Removing Java using $alt_cmd
";
325 | my @jdk_progs = ('java', 'jar', 'javac');
326 | foreach my $prog (@jdk_progs){
327 |
328 | $cmd_out='';
329 | $cmd_err='';
330 | local $out = &execute_command("$alt_cmd --remove $prog $jdk_dir/bin/$prog", undef, \$cmd_out, \$cmd_err, 0, 0);
331 | if($cmd_err){
332 | &error("Error: $alt_cmd: $cmd_err");
333 | }else{
334 | $cmd_out = s/\r\n/
/g;
335 | print &html_escape($cmd_out);
336 | }
337 | }
338 | }
339 | }
340 |
341 | sub get_jdk_dir_by_name{
342 | my $jdk_name = $_[0];
343 | my $jdk_dir = '';
344 |
345 | if($jdk_name =~ /.*openjdk.*/){
346 |
347 | my $jdk_ver = (split /-/, $jdk_name)[1]; #get version from name
348 | my @known_dirs = ('java-'.$jdk_ver.'-openjdk', 'java-'.$jdk_ver.'-openjdk-amd64', 'jre-'.$jdk_ver.'-openjdk');
349 |
350 | foreach $jvm_name (@known_dirs){
351 | if(-d '/usr/lib/jvm/'.$jvm_name){
352 | $jdk_dir = '/usr/lib/jvm/'.$jvm_name;
353 | last;
354 | }
355 | }
356 |
357 | }else{
358 | $jdk_dir = '/usr/java/'.$jdk_name;
359 | }
360 | return $jdk_dir;
361 | }
362 |
363 | 1;
364 |
--------------------------------------------------------------------------------
/lang/en:
--------------------------------------------------------------------------------
1 | index_title=Tomcat Server
2 | index_title_upgrade=Tomcat Server Upgrade
3 | index_root=The root directory is $1.
4 |
5 | index_start=Start Server
6 | index_startmsg=Click this button to start the Tomcat server
7 | index_stop=Stop Server
8 | index_stopmsg=Click this button to stop the running Tomcat server
9 | index_restart=Restart Server
10 | index_restartmsg=Click this button to restart the running Tomcat server
11 | index_return=Tomcat
12 | index_install=Install Tomcat
13 | index_upgrade=Upgrade Tomcat
14 |
15 | users_title=Users
16 |
17 | wars_title=WARs
18 | manual_title=Edit config
19 | manual_ecannot=You are not allowed to edit the Tomcat server.xml config file
20 | manual_ok=Edit
21 | manual_efile=Selected file is not part of the Tomcat server configuration
22 | manual_file=Edit config file:
23 | manual_edata=Nothing entered!
24 | manual_err=Failed to save config file
25 |
26 | war_install=Install Application
27 | war_installsource=Install source (.war or .zip)
28 | war_installok=Deploy
29 | wars_tabinstall=Deploy
30 | wars_tabdelete=Undeploy
31 | wars_tablist=List
32 | wars_desc1=Tomcat applications can be installed using .war files from local or remote locations.
33 | wars_desc2=After deleting an application, Tomcat server will be restarted. If you keep, the war file, application will be redeployed!
34 | wars_delete=Delete Application
35 | wars_deleteok=Undeploy
36 | wars_rmwar=Remove war file too
37 | wars_installed=Installed Apps
38 |
39 | install_title=Install WAR
40 | install_err1=Invalid URL
41 | install_err2=Failed to install uploaded module
42 | install_err3=Failed to install module from $1
43 | install_efile=File does not exist
44 | install_ebrowser=Your browser does not support file uploads
45 |
46 | delete_title=Uninstall WAR
47 | delete_err=Failed to delete modules
48 | delete_enone=No modules selected
49 |
50 | start_err=Failed to start Tomcat
51 | stop_err=Failed to stop Tomcat
52 | restart_err=Failed to restart Tomcat
53 |
54 | java_title=Java
55 | java_tabinstall=Install
56 | java_tabuninstall=Uninstall
57 | java_tabdefault=Default
58 | java_desc1=Install Java Development Kit(JDK) from distribution repository or from Oracle .tar.gz archive
59 | java_desc2=Uninstall Oracle Java 8 files from /usr/share
60 | java_desc3=Set default Java, using update-alternatives and /etc/profile.d/jdk.sh
61 | java_install=Install Options
62 | java_uninstall=Uninstall Options
63 | java_default=update-alternatives Options
64 | jdk_installsource=JDK source
65 | jdk_latest=Oracle JDK
66 | java_installok=Install
67 | java_deleteok=Uninstall
68 | java_defaultok=Update
69 | java_def_jdk=Set as system default Java
70 | java_def_jdk_desc= ( using alternatives )
71 | java_rm_def_jdk=Remove, if default Java
72 | java_installed=JDK versions
73 | openjdk_latest=OpenJDK
74 | openjdk_headless=Headless package
75 | openjdk_headless_desc=only for OpenJDK
76 |
77 | libs_title=Libraries
78 | libs_desc1=Install libraries into Tomcat's lib/ directory
79 | libs_desc2=Uninstall librarues from Tomcat's lib/ directory
80 | libs_install=Libraries to be installed
81 | libs_delete=Libraries to be uninstalled
82 | libs_installsource=Library source(.zip or .jar)
83 | libs_tabinstall=Install
84 | libs_tabuninstall=Uninstall
85 | libs_installok=Install
86 | libs_deleteok=Uninstall
87 | libs_installed=Libraries found
88 | libs_install_title=Installing Tomcat library
89 | libs_uninstall_title=Uninstalling Tomcat libraries
90 |
91 | source_local=Local file
92 | source_uploaded=Uploaded file
93 | source_ftp=FTP or HTTP URL
94 | source_archive=Apache Archive
95 |
96 | source_err0=File Error
97 | source_err1=Upload Error
98 | source_err1.2=No upload file
99 | source_err2=Download error
100 | source_err3=Invalid URL
101 |
102 | setup_title=Setup
103 |
104 | base_options=Options
105 | base_major=Tomcat Major Version
106 | base_archive=Release
107 | base_installok=Download
108 | base_upgradeok=Upgrade
109 | base_installsource=Install source
110 | base_desc1=Download an archive of Apache Tomcat Server from Apache website and install it
111 | base_desc2=Select major and minor versions for upgrade/downgrade. All WARs will be moved and config will be copied to new install!
112 |
113 | proxy_title=Proxy
114 | proxy_add_options=Add proxy
115 | proxy_remove_options=Remove proxy
116 | proxy_default_app=Make this the default (/)
117 | proxy_app_default_warning=Will remove previous default path!
118 | proxy_ssl=Use SSL port
119 | proxy_ssl_info=Use Tomcat HTTPs port
120 | proxy_list=Available proxies
121 | proxy_installok=Add
122 | proxy_removeok=Remove
123 | proxy_wildcard=Add Wildcard map
124 | proxy_wildcard_info=Proxy Apache:80 to Tomcat:8080
125 |
--------------------------------------------------------------------------------
/module.info:
--------------------------------------------------------------------------------
1 | desc=Apache Tomcat
2 | os_support=*-linux freebsd archlinux
3 | category=servers
4 |
--------------------------------------------------------------------------------
/restart.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # restart.cgi
3 | # Restart the tomcat daemon
4 |
5 | require './tomcat-lib.pl';
6 | &ReadParse();
7 | &error_setup($text{'restart_err'});
8 | my ($rc, $err) = tomcat_service_ctl('restart');
9 | if ($rc != 0){
10 | &ui_print_header(undef, $text{'index_title'}, "");
11 | &error($err);
12 | &ui_print_footer("", $text{'index_return'});
13 | exit;
14 | }
15 | &redirect("");
16 |
--------------------------------------------------------------------------------
/save_manual.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # Update a manually edited config file
3 |
4 | require './tomcat-lib.pl';
5 | &error_setup($text{'manual_err'});
6 | &ReadParseMime();
7 |
8 | my $catalina_home = get_catalina_home();
9 |
10 | # Work out the file
11 | @files = ( "$catalina_home/bin/setenv.sh",
12 | "$catalina_home/conf/context.xml",
13 | "$catalina_home/conf/server.xml",
14 | "$catalina_home/conf/tomcat-users.xml",
15 | "$catalina_home/conf/web.xml");
16 | &indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
17 | $in{'data'} =~ s/\r//g;
18 | $in{'data'} =~ /\S/ || &error($text{'manual_edata'});
19 |
20 | # Write to it
21 | &open_lock_tempfile(DATA, ">$in{'file'}");
22 | &print_tempfile(DATA, $in{'data'});
23 | &close_tempfile(DATA);
24 |
25 | &webmin_log("manual", undef, $in{'file'});
26 | &redirect("");
27 |
28 |
--------------------------------------------------------------------------------
/scripts/alma-rocky.sh:
--------------------------------------------------------------------------------
1 | # !/bin/bash -e
2 | # Tomcat Module Script for Rocky Linux
3 | # Usage:
4 | # wget https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/master/scripts/rocky-linux.sh
5 | # chmod +x pre-installer
6 | # ./pre-installer.sh
7 |
8 | function get_deps(){
9 |
10 | yum -y install wget unzip bzip2
11 |
12 | }
13 |
14 | function setup_selinux(){
15 |
16 | #allow apache port for django app
17 | semanage port -a -t http_port_t -p tcp 7800
18 | semanage port -m -t http_port_t -p tcp 9000
19 |
20 | setsebool -P httpd_can_network_connect 1
21 | }
22 |
23 |
24 | function install_apache(){
25 |
26 | yum -y install httpd
27 |
28 | }
29 |
30 | function install_webmin(){
31 | wget -P/tmp 'https://download.webmin.com/developers-key.asc'
32 | rpm --import /tmp/developers-key.asc || true
33 | cp -f /tmp/developers-key.asc /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin-developers
34 |
35 | cat >/etc/yum.repos.d/webmin.repo < Tomcat to complete installation"
85 |
86 | }
87 |
88 | get_deps;
89 | #install_apache;
90 | #install_webmin;
91 | #download_certbot_module;
92 | setup_selinux;
93 | #install_certbot_module;
94 | download_tomcat_module;
95 | install_tomcat_module;
96 |
--------------------------------------------------------------------------------
/scripts/index.rst:
--------------------------------------------------------------------------------
1 | 1
2 |
--------------------------------------------------------------------------------
/scripts/pre-install.sh:
--------------------------------------------------------------------------------
1 | # !/bin/bash -e
2 | # Tomcat Module Script for CentOS and Ubuntu
3 | # For use on clean CentOS or Ubuntu box only
4 | # Usage:
5 | # wget https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/master/scripts/pre-install.sh
6 | # chmod +x pre-installer
7 | # ./pre-installer.sh
8 |
9 | function get_repo(){
10 | if [ -f /etc/centos-release ]; then
11 | REPO='rpm'
12 |
13 | elif [ -f /etc/debian_version ]; then
14 | REPO='apt'
15 | fi
16 | }
17 |
18 | function install_webmin(){
19 |
20 | if [ "${REPO}" == 'apt' ]; then
21 |
22 | echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
23 | wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
24 | apt-get -y update
25 | apt-get -y install webmin
26 |
27 | elif [ "${REPO}" == 'rpm' ]; then
28 |
29 |
30 |
31 |
32 |
33 | wget -P/tmp 'https://download.webmin.com/developers-key.asc'
34 | rpm --import /tmp/developers-key.asc || true
35 | cp -f /tmp/developers-key.asc /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin-developers
36 |
37 | cat >/etc/yum.repos.d/webmin.repo < Tomcat to complete installation"
73 |
74 | }
75 |
76 |
77 |
78 | function download_certbot_module(){
79 | pushd /tmp/
80 | wget https://github.com/cited/Certbot-Webmin-Module/archive/master.zip
81 | unzip master.zip
82 | mv Certbot-Webmin-Module-master certbot
83 | tar -czf /opt/certbot.wbm.gz certbot
84 | rm -rf certbot master.zip
85 | popd
86 | }
87 |
88 | function install_apache(){
89 | if [ "${REPO}" == 'apt' ]; then
90 | apt-get -y install apache2
91 | elif [ "${REPO}" == 'rpm' ]; then
92 | yum -y install httpd
93 | fi
94 | }
95 |
96 | function install_certbot_module(){
97 | pushd /opt/
98 | if [ "${REPO}" == 'apt' ]; then
99 | /usr/share/webmin/install-module.pl certbot.wbm.gz
100 | elif [ "${REPO}" == 'rpm' ]; then
101 | /usr/libexec/webmin/install-module.pl certbot.wbm.gz
102 | fi
103 | popd
104 | echo -e "Certbot is now installed. Go to Servers > Certbot to complete installation"
105 |
106 | }
107 |
108 | function get_deps(){
109 | if [ "${REPO}" == 'apt' ]; then
110 | apt-get -y install wget unzip
111 | elif [ "${REPO}" == 'rpm' ]; then
112 | yum -y install wget unzip bzip2
113 | fi
114 | }
115 |
116 | get_repo;
117 | get_deps;
118 | # Uncomment line(s) below if you wish to install Webmin, Apache HTTP Server, and Certbot as well.
119 | #install_webmin;
120 | #install_apache;
121 | #download_certbot_module;
122 | #install_certbot_module;
123 | download_tomcat_module;
124 | install_tomcat_module;
125 |
--------------------------------------------------------------------------------
/scripts/rocky-linux.sh:
--------------------------------------------------------------------------------
1 | # !/bin/bash -e
2 | # Tomcat Module Script for Rocky Linux
3 | # Usage:
4 | # wget https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/master/scripts/rocky-linux.sh
5 | # chmod +x pre-installer
6 | # ./pre-installer.sh
7 |
8 | function get_deps(){
9 |
10 | yum -y install wget unzip bzip2
11 |
12 | }
13 |
14 | function setup_selinux(){
15 |
16 | #allow apache port for django app
17 | semanage port -a -t http_port_t -p tcp 7800
18 | semanage port -m -t http_port_t -p tcp 9000
19 |
20 | setsebool -P httpd_can_network_connect 1
21 | }
22 |
23 |
24 | function install_apache(){
25 |
26 | yum -y install httpd
27 |
28 | }
29 |
30 | function install_webmin(){
31 | wget -P/tmp 'https://download.webmin.com/developers-key.asc'
32 | rpm --import /tmp/developers-key.asc || true
33 | cp -f /tmp/developers-key.asc /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin-developers
34 |
35 | cat >/etc/yum.repos.d/webmin.repo < Tomcat to complete installation"
85 |
86 | }
87 |
88 | get_deps;
89 | #install_apache;
90 | #install_webmin;
91 | #download_certbot_module;
92 | setup_selinux;
93 | #install_certbot_module;
94 | download_tomcat_module;
95 | install_tomcat_module;
96 |
--------------------------------------------------------------------------------
/scripts/tomcat.wbm.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/bb2fcedb75ad55abe9b5a8fde3de8836b3886a32/scripts/tomcat.wbm.gz
--------------------------------------------------------------------------------
/scripts/ubuntu.sh:
--------------------------------------------------------------------------------
1 | # !/bin/bash -e
2 | # Tomcat Module Script for CentOS and Ubuntu
3 | # For use on clean CentOS or Ubuntu box only
4 | # Usage:
5 | # wget https://raw.githubusercontent.com/cited/Tomcat-Webmin-Module/master/scripts/pre-install.sh
6 | # chmod +x pre-installer
7 | # ./pre-installer.sh
8 |
9 | function get_repo(){
10 | if [ -f /etc/centos-release ]; then
11 | REPO='rpm'
12 |
13 | elif [ -f /etc/debian_version ]; then
14 | REPO='apt'
15 | fi
16 | }
17 |
18 | function install_webmin(){
19 |
20 | if [ "${REPO}" == 'apt' ]; then
21 |
22 | echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
23 | wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
24 | apt-get -y update
25 | apt-get -y install webmin
26 |
27 | elif [ "${REPO}" == 'rpm' ]; then
28 |
29 |
30 |
31 |
32 |
33 | wget -P/tmp 'https://download.webmin.com/developers-key.asc'
34 | rpm --import /tmp/developers-key.asc || true
35 | cp -f /tmp/developers-key.asc /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin-developers
36 |
37 | cat >/etc/yum.repos.d/webmin.repo < Tomcat to complete installation"
73 |
74 | }
75 |
76 |
77 |
78 | function download_certbot_module(){
79 | pushd /tmp/
80 | wget https://github.com/cited/Certbot-Webmin-Module/archive/master.zip
81 | unzip master.zip
82 | mv Certbot-Webmin-Module-master certbot
83 | tar -czf /opt/certbot.wbm.gz certbot
84 | rm -rf certbot master.zip
85 | popd
86 | }
87 |
88 | function install_apache(){
89 | if [ "${REPO}" == 'apt' ]; then
90 | apt-get -y install apache2
91 | elif [ "${REPO}" == 'rpm' ]; then
92 | yum -y install httpd
93 | fi
94 | }
95 |
96 | function install_certbot_module(){
97 | pushd /opt/
98 | if [ "${REPO}" == 'apt' ]; then
99 | /usr/share/webmin/install-module.pl certbot.wbm.gz
100 | elif [ "${REPO}" == 'rpm' ]; then
101 | /usr/libexec/webmin/install-module.pl certbot.wbm.gz
102 | fi
103 | popd
104 | echo -e "Certbot is now installed. Go to Servers > Certbot to complete installation"
105 |
106 | }
107 |
108 | function get_deps(){
109 | if [ "${REPO}" == 'apt' ]; then
110 | apt-get -y install wget unzip
111 | elif [ "${REPO}" == 'rpm' ]; then
112 | yum -y install wget unzip bzip2
113 | fi
114 | }
115 |
116 | get_repo;
117 | get_deps;
118 | # Uncomment line(s) below if you wish to install Webmin, Apache HTTP Server, and Certbot as well.
119 | #install_webmin;
120 | #install_apache;
121 | #download_certbot_module;
122 | #install_certbot_module;
123 | download_tomcat_module;
124 | install_tomcat_module;
125 |
--------------------------------------------------------------------------------
/setup.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | require '../webmin/webmin-lib.pl'; #for OS detection
5 | foreign_require('software', 'software-lib.pl');
6 |
7 | sub add_tomcat_user{
8 | #check if tomcat user exists
9 | if(read_file_contents('/etc/passwd') !~ /\ntomcat:/){
10 | #add tomcat user
11 | local $out = &backquote_command('useradd -m tomcat', 0);
12 | }elsif(! -d '/home/tomcat'){
13 | &make_dir("/home/tomcat", 0755, 1);
14 | &set_ownership_permissions('tomcat','tomcat', undef, '/home/tomcat');
15 | }
16 | }
17 |
18 | sub setup_catalina_env{
19 | my $tomcat_ver = $_[0];
20 |
21 | my %os_env;
22 |
23 | print "
Setting CATALINA environment...";
24 |
25 | read_env_file('/etc/environment', \%os_env);
26 | $os_env{'CATALINA_HOME'} = "/home/tomcat/apache-tomcat-$tomcat_ver/";
27 | $os_env{'CATALINA_BASE'} = "/home/tomcat/apache-tomcat-$tomcat_ver/";
28 | write_env_file('/etc/environment', \%os_env, 0);
29 |
30 | open(my $fh, '>>', "/home/tomcat/apache-tomcat-$tomcat_ver/bin/setenv.sh") or die "open:$!";
31 | print $fh "CATALINA_PID=\"/home/tomcat/apache-tomcat-$tomcat_ver/temp/tomcat.pid\"\n";
32 | close $fh;
33 | }
34 |
35 | sub setup_tomcat_users{
36 | my $tomcat_ver = $_[0];
37 | my @pw_chars = ("A".."Z", "a".."z", "0".."9", "_", "-");
38 | my $manager_pass;
39 | my $admin_pass;
40 |
41 | $manager_pass .= $pw_chars[rand @pw_chars] for 1..32;
42 | $admin_pass .= $pw_chars[rand @pw_chars] for 1..32;
43 |
44 | #Save tomcat-users.xml
45 | open(my $fh, '>', "/home/tomcat/apache-tomcat-$tomcat_ver/conf/tomcat-users.xml") or die "open:$!";
46 | print $fh <
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | EOF
56 | close $fh;
57 | print "
Setting Tomcat users...";
58 | }
59 |
60 | sub install_tomcat_from_archive{
61 |
62 | add_tomcat_user();
63 | my $tomcat_ver = download_and_install($in{'source_archive'});
64 |
65 | setup_catalina_env($tomcat_ver);
66 | setup_tomcat_users($tomcat_ver);
67 | setup_tomcat_service($tomcat_ver);
68 | }
69 |
70 | sub get_apache_proxy_file(){
71 | my $proxy_file;
72 | my %osinfo = &detect_operating_system();
73 | if( ( $osinfo{'real_os_type'} =~ /centos/i) or #CentOS
74 | ( $osinfo{'real_os_type'} =~ /rocky/i) or #rocky
75 | ( $osinfo{'real_os_type'} =~ /alma/i) or #alma
76 | ($osinfo{'real_os_type'} =~ /fedora/i) ){ #Fedora
77 | if( ! -d '/etc/httpd/'){
78 | return 0;
79 | }
80 | $proxy_file = '/etc/httpd/conf.d/tomcat.conf';
81 |
82 | }elsif( ($osinfo{'real_os_type'} =~ /ubuntu/i) or
83 | ($osinfo{'real_os_type'} =~ /debian/i) ){ #ubuntu or debian
84 | if( ! -d '/etc/apache2/'){
85 | return 0;
86 | }
87 | $proxy_file = '/etc/apache2/conf-enabled/tomcat.conf';
88 | }
89 | return $proxy_file;
90 | }
91 |
92 | sub setup_default_apache_proxy(){
93 | my $proxy_file = get_apache_proxy_file();
94 | my %osinfo = &detect_operating_system();
95 |
96 | if(-f $proxy_file){
97 | return 0;
98 | }
99 |
100 | open(my $fh, '>', $proxy_file) or die "open:$!";
101 |
102 | if( ($osinfo{'real_os_type'} =~ /centos/i) or #CentOS
103 | ($osinfo{'real_os_type'} =~ /fedora/i) ){ #Fedora
104 |
105 | &execute_command('setsebool httpd_can_network_connect 1');
106 |
107 | print $fh "LoadModule proxy_module modules/mod_proxy.so\n";
108 | print $fh "LoadModule proxy_http_module modules/mod_proxy_http.so\n";
109 | print $fh "LoadModule rewrite_module modules/mod_rewrite.so\n";
110 |
111 | }elsif( $osinfo{'os_type'} =~ /debian/i){ #ubuntu or debian
112 |
113 | print $fh "LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so\n";
114 | print $fh "LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so\n";
115 | print $fh "LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so\n";
116 | }
117 |
118 | print $fh "ProxyRequests Off\n";
119 | print $fh "ProxyPreserveHost On\n";
120 | print $fh " \n";
121 | print $fh " Order allow,deny\n";
122 | print $fh " Allow from all\n";
123 | print $fh " \n";
124 | print $fh "ProxyPass / http://localhost:8080/\n";
125 | print $fh "ProxyPassReverse / http://localhost:8080/\n";
126 |
127 | close $fh;
128 |
129 | print "Added proxy configuration / -> 8080 in $proxy_file\n";
130 | }
131 |
132 | sub select_tomcat_archive{
133 | print "$text{'base_desc1'}\n";
134 | print &ui_form_start("setup.cgi", "form-data");
135 | print ui_hidden('mode', 'tomcat_install');
136 | print &ui_table_start($text{'base_options'}, undef, 2);
137 |
138 | my @tmver = &get_tomcat_major_versions();
139 | my $sel_tmver = $in{'tmver'} || $tmver[0];
140 | my @tm_opts = ( );
141 | foreach my $v (@tmver) {
142 | push(@tm_opts, [ $v, $v ]);
143 | }
144 |
145 | print <
147 | function update_select(){
148 | var majorSel = document.getElementById('base_major');
149 | var major = majorSel.options[majorSel.selectedIndex].value;
150 |
151 | get_pjax_content('/tomcat/setup.cgi?mode=tomcat_install_form&tmver='+major);
152 | }
153 |
154 | EOF
155 |
156 | print &ui_table_row($text{'base_major'},
157 | &ui_select("base_major", $sel_tmver, \@tm_opts, 1, 0, undef, undef, 'id="base_major" onchange="update_select()"'));
158 |
159 | my @tver = &major_tomcat_versions($sel_tmver);
160 | my @tver_opts = ( );
161 | foreach my $v (reverse @tver) {
162 | push(@tver_opts, [ $v, $v ]);
163 | }
164 |
165 | print &ui_table_row($text{'base_installsource'},
166 | &ui_radio_table("source", 100,
167 | [ [ 100, $text{'source_archive'}, &ui_select("source_archive", undef, \@tver_opts,1, 0)],
168 | [ 0, $text{'source_local'}, &ui_textbox("file", undef, 40)." ". &file_chooser_button("file", 0) ],
169 | [ 1, $text{'source_uploaded'}, &ui_upload("upload", 40) ],
170 | [ 2, $text{'source_ftp'},&ui_textbox("url", undef, 40) ]
171 | ]));
172 |
173 | print &ui_table_end();
174 | print &ui_form_end([ [ "", $text{'base_installok'} ] ]);
175 | }
176 |
177 | sub setup_selinux{
178 | my $tomcat_home = get_catalina_home();
179 |
180 | local $out = &execute_command("semanage fcontext -a -t bin_t \"$tomcat_home/bin(/.*)?\"", undef, \$cmd_out, \$cmd_err, 0, 0);
181 | print &html_escape($cmd_out.$cmd_err);
182 |
183 | local $out = &execute_command("restorecon -r -v \"$tomcat_home/bin\"", undef, \$cmd_out, \$cmd_err, 0, 0);
184 | print &html_escape($cmd_out.$cmd_err);
185 | }
186 |
187 | sub setup_checks{
188 |
189 | my %osinfo = &detect_operating_system();
190 |
191 | #Check for commands
192 | if (!&has_command('java')) {
193 | print 'Warning: Java is not found. Install it manually or from the '.
194 | "Java tab
";
195 | }
196 |
197 | my @pinfo = software::package_info('haveged', undef, );
198 | if(!@pinfo){
199 | if( ($osinfo{'real_os_type'} =~ /centos/i) or #CentOS
200 | ($osinfo{'real_os_type'} =~ /alma/i) or #Alma
201 | ($osinfo{'real_os_type'} =~ /rocky/i) ){ #Rocky
202 | @pinfo = software::package_info('epel-release', undef, );
203 | if(!@pinfo){
204 | print "Warning: haveged needs epel-release. Install it manually or ".
205 | "click here to have it downloaded and installed.
";
206 | }
207 | }
208 | print "Warning: haveged package is not installed. Install it manually or ".
209 | "click here to have it downloaded and installed.
";
210 | }
211 |
212 | my $tomcat_ver = installed_tomcat_version();
213 | if(!$tomcat_ver){
214 | print "Click here to install Tomcat from Apache site.
";
215 | }
216 |
217 | if (!&has_command('unzip')) {
218 | print 'Warning: unzip command is not found. Install it manually or '.
219 | "click here to have it downloaded and installed.
";
220 | }
221 |
222 | my $proxy_file = get_apache_proxy_file();
223 | my $www_name = '';
224 |
225 | if( ( $osinfo{'real_os_type'} =~ /centos/i) or #CentOS
226 | ( $osinfo{'real_os_type'} =~ /rocky/i) or #Rocky
227 | ( $osinfo{'real_os_type'} =~ /alma/i) or #Alma
228 | ($osinfo{'real_os_type'} =~ /fedora/i) ){ #Fedora
229 | $www_name = 'httpd';
230 |
231 | }elsif( ($osinfo{'real_os_type'} =~ /ubuntu/i) or
232 | ($osinfo{'real_os_type'} =~ /debian/i) ){ #ubuntu or debian
233 | $www_name = 'apache2';
234 | }
235 |
236 | @pinfo = software::package_info($www_name, undef, );
237 | if(!@pinfo){
238 | print "Warning: $www_name is not installed. Install it manually or ".
239 | "click here to have it downloaded and installed.
";
240 | }
241 |
242 | if(! -f $proxy_file){
243 | print "Apache default proxy is not configured. ".
244 | "click here
";
245 | }
246 |
247 | if(@pinfo){
248 | if( ($osinfo{'real_os_type'} =~ /alma/i) or #Alma
249 | ($osinfo{'real_os_type'} =~ /rocky/i) ){ #Rocky
250 |
251 | local $out = &execute_command("sestatus", undef, \$cmd_out, \$cmd_err, 0, 0);
252 | if($cmd_out =~ /SELinux status:\s+enabled/i){
253 | my $se_utils_pkg = 'policycoreutils-python-utils';
254 | @pinfo = software::package_info($se_utils_pkg, undef, );
255 | if(!@pinfo){
256 | print "Warning: $se_utils_pkg is not installed. Install it manually or ".
257 | "click here to have it downloaded and installed.
";
258 | }else{
259 | my $tomcat_home = get_catalina_home();
260 | local $out = &execute_command("ls -lZ $tomcat_home/bin/startup.sh", undef, \$cmd_out, \$cmd_err, 0, 0);
261 | if($cmd_out !~ /:bin_t:/i){
262 | printf "SELinux is enabled. Configured it from ".
263 | "here.
";
264 | }
265 | }
266 | }
267 | }
268 | }
269 | print 'If you don\'t see any warning above, you can complete setup from '.
270 | "here
";
271 | }
272 |
273 | #Remove all setup files
274 | sub setup_cleanup{
275 | my $file = $module_root_directory.'/setup.cgi';
276 | print "Completing Installation";
277 | &unlink_file($file);
278 | print &js_redirect("index.cgi");
279 | }
280 |
281 |
282 | &ui_print_header(undef, $text{'setup_title'}, "");
283 |
284 | if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
285 | &ReadParseMime();
286 | }else {
287 | &ReadParse(); $no_upload = 1;
288 | }
289 |
290 | my $mode = $in{'mode'} || "checks";
291 |
292 | if($mode eq "checks"){ setup_checks();
293 | &ui_print_footer('', $text{'index_return'});
294 | exit 0;
295 | }elsif($mode eq "cleanup"){ setup_cleanup();
296 | &ui_print_footer('', $text{'index_return'});
297 | exit 0;
298 | }elsif($mode eq "tomcat_install_form"){ select_tomcat_archive();
299 | }elsif($mode eq "tomcat_install"){ install_tomcat_from_archive();
300 | }elsif($mode eq "setup_apache_proxy"){ setup_default_apache_proxy();
301 | }elsif($mode eq "setup_selinux"){ setup_selinux();
302 | }else{
303 | print "Error: Invalid setup mode\n";
304 | }
305 |
306 | &ui_print_footer('setup.cgi', $text{'setup_title'});
307 |
--------------------------------------------------------------------------------
/start.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # start.cgi
3 | # Start the tomcat daemon
4 |
5 | require './tomcat-lib.pl';
6 | &ReadParse();
7 | &error_setup($text{'start_err'});
8 | my ($rc, $err) = tomcat_service_ctl('start');
9 | if ($rc != 0){
10 | &ui_print_header(undef, $text{'index_title'}, "");
11 | &error($err);
12 | &ui_print_footer("", $text{'index_return'});
13 | exit;
14 | }
15 | &redirect("");
16 |
--------------------------------------------------------------------------------
/stop.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 | &ReadParse();
5 | &error_setup($text{'stop_err'});
6 | my ($rc, $err) = tomcat_service_ctl('stop');
7 | if ($rc != 0){
8 | &ui_print_header(undef, $text{'index_title'}, "");
9 | &error($err);
10 | &ui_print_footer("", $text{'index_return'});
11 | exit;
12 | }
13 | &redirect("");
14 |
15 |
--------------------------------------------------------------------------------
/tomcat-lib.pl:
--------------------------------------------------------------------------------
1 | =head1 tomcat-lib.pl
2 |
3 | Functions for managing Tomcat server configuration files.
4 |
5 | foreign_require("tomcat", "tomcat-lib.pl");
6 | @sites = tomcat::list_tomcat_websites()
7 |
8 | =cut
9 |
10 | BEGIN { push(@INC, ".."); };
11 | use WebminCore;
12 | use File::Copy;
13 | init_config();
14 |
15 | sub get_tomcat_config
16 | {
17 | my $lref = &read_file_lines($config{'foobar_conf'});
18 | my @rv;
19 | my $lnum = 0;
20 | foreach my $line (@$lref) {
21 | my ($n, $v) = split(/\s+/, $line, 2);
22 | if ($n) {
23 | push(@rv, { 'name' => $n, 'value' => $v, 'line' => $lnum });
24 | }
25 | $lnum++;
26 | }
27 | return @rv;
28 | }
29 |
30 | # Returns a hash containing the version type, number and full version
31 | sub get_catalina_version
32 | {
33 | local %version;
34 | local $catalina_home = get_catalina_home();
35 | local $out = &backquote_command($catalina_home."/bin/catalina.sh version 2>&1 '.$k.': '.$1."";
69 | }
70 | }
71 | }
72 |
73 | $running = $out >> 8;
74 | if($ctl eq 'status'){
75 | # swap running values, to match init.d logic
76 | if($running == 0){
77 | $running = 1;
78 | }elsif($running > 0){
79 | $running = 0;
80 | }
81 | }
82 |
83 | }else{
84 | local $out = &execute_command("/etc/init.d/tomcat $ctl", undef, \$cmd_out, \$cmd_err, 0, 0);
85 |
86 | $running = $out >> 8;
87 | if($cmd_err ne ""){
88 | $status = $cmd_err;
89 | }else{
90 | $status = $cmd_out;
91 | }
92 | }
93 |
94 | return ($running, $status);
95 | }
96 |
97 | sub get_all_war_infos(){
98 | my $catalina_home = get_catalina_home();
99 | opendir(DIR, $catalina_home.'/webapps') or die $!;
100 | my @dirs
101 | = grep {
102 | ! /^\./ # Doesn't begins with a period
103 | && -d "$catalina_home/webapps/$_" # and is a directory
104 | } readdir(DIR);
105 | closedir(DIR);
106 |
107 | return sort @dirs;
108 | }
109 |
110 | sub file_basename
111 | {
112 | my $rv = $_[0];
113 | $rv =~ s/^.*[\/\\]//;
114 | return $rv;
115 | }
116 |
117 | sub sort_version {
118 | my @A = split(/\./, $a);
119 | my @B = split(/\./, $b);
120 | # a sort subroutine, expect $a and $b
121 | for(my $i=0; $i < 3; $i++){
122 | if ($A[$i] < $B[$i]) { return -1 } elsif ($A[$i] > $B[$i]) { return 1 }
123 | }
124 | return 0;
125 | }
126 |
127 | sub latest_tomcat_version{
128 | my $tomcat_ver = $_[0];
129 | my %version;
130 | if(-f "$module_config_directory/version"){
131 | read_file_cached("$module_config_directory/version", \%version);
132 |
133 | if( $version{'updated'} >= (time() - 86400)){ #if last update was less than a day ago
134 | return $version{'latest'} if ($version{'latest'} ne '0.0.0');
135 | }
136 | }
137 |
138 | my $major = (split /\./, $tomcat_ver)[0];
139 | my @all_ver = &major_tomcat_versions($major);
140 | my $latest_ver = $all_ver[-1];
141 |
142 | #renew the updated timestamp and latest version
143 | $version{'updated'} = time();
144 | $version{'latest'} = $latest_ver;
145 | &write_file("$module_config_directory/version", \%version);
146 |
147 | return $latest_ver;
148 | }
149 |
150 | sub installed_tomcat_version(){
151 | my %os_env;
152 | read_env_file('/etc/environment', \%os_env);
153 |
154 | if($os_env{'CATALINA_HOME'}){
155 | $os_env{'CATALINA_HOME'} =~ /\/home\/tomcat\/apache-tomcat-([0-9\.]+)/;
156 | return $1;
157 | }else{
158 | return undef;
159 | }
160 | }
161 |
162 | sub get_catalina_home(){
163 | my $tomcat_ver = installed_tomcat_version();
164 | return "/home/tomcat/apache-tomcat-$tomcat_ver";
165 | }
166 |
167 | sub download_and_install{
168 | my $tomcat_ver = $_[0];
169 | my $major = (split /\./, $tomcat_ver)[0];
170 |
171 | #download tomcat archive
172 | $in{'url'} = "https://archive.apache.org/dist/tomcat/tomcat-$major/v$tomcat_ver/bin/apache-tomcat-$tomcat_ver.tar.gz";
173 | $in{'source'} = 2;
174 |
175 | my $tmpfile = process_file_source();
176 |
177 | #extract tomcat archive
178 | my $cmd_out='';
179 | my $cmd_err='';
180 | print "
Extracting to /home/tomcat/apache-tomcat-$tomcat_ver/ ...
";
181 | local $out = &execute_command("tar -x -v --overwrite -f \"$tmpfile\" -C/home/tomcat/", undef, \$cmd_out, \$cmd_err, 0, 0);
182 |
183 | if($cmd_err ne ""){
184 | &error("Error: tar: $cmd_err");
185 | }else{
186 | $cmd_out = s/\n/
/g;
187 | print &html_escape($cmd_out);
188 | print "Done
";
189 | }
190 |
191 | #folder is created after tomcat is started, but we need it now
192 | &make_dir("/home/tomcat/apache-tomcat-$tomcat_ver/conf/Catalina/localhost/", 0755, 1);
193 |
194 | open(my $fh, '>', "/home/tomcat/apache-tomcat-$tomcat_ver/conf/Catalina/localhost/manager.xml") or die "open:$!";
195 | print $fh <
197 |
198 |
199 | EOF
200 | close $fh;
201 |
202 | #&set_ownership_permissions('tomcat','tomcat', undef, "/home/tomcat/apache-tomcat-$tomcat_ver/");
203 | &execute_command("chown -R tomcat:tomcat /home/tomcat/apache-tomcat-$tomcat_ver");
204 |
205 | return $tomcat_ver;
206 | }
207 |
208 | sub setup_catalina_env{
209 | my $tomcat_ver = $_[0];
210 |
211 | my %os_env;
212 |
213 | print "
Setting CATALINA environment...";
214 |
215 | read_env_file('/etc/environment', \%os_env);
216 | $os_env{'CATALINA_HOME'} = "/home/tomcat/apache-tomcat-$tomcat_ver/";
217 | $os_env{'CATALINA_BASE'} = "/home/tomcat/apache-tomcat-$tomcat_ver/";
218 | write_env_file('/etc/environment', \%os_env, 0);
219 |
220 | open(my $fh, '>>', "/home/tomcat/apache-tomcat-$tomcat_ver/bin/setenv.sh") or die "open:$!";
221 | print $fh "CATALINA_PID=\"/home/tomcat/apache-tomcat-$tomcat_ver/temp/tomcat.pid\"\n";
222 | close $fh;
223 | }
224 |
225 | sub get_installed_libs{
226 | opendir(DIR, $module_config_directory) or die $!;
227 | my @lib_lists
228 | = grep {
229 | /^lib_[a-z0-9\.\-_\s]+\.list$/i #
230 | && -f "$module_config_directory/$_" # and is a file
231 | } readdir(DIR);
232 | closedir(DIR);
233 |
234 | return sort @lib_lists;
235 | }
236 |
237 | sub process_file_source{
238 | my $file = '';
239 |
240 | if (($in{'source'} == 0) && ($in{'file'} ne "")) { # from local file
241 | &error_setup(&text('source_err0', $in{'file'}));
242 | $file = $in{'file'};
243 | if (!(-r $file)){
244 | &error($text{'source_err0'});
245 | }
246 |
247 | }elsif (($in{'source'} == 1) && ($in{'upload_filename'} ne "")) { # from uploaded file
248 | &error_setup($text{'source_err1'});
249 | $need_unlink = 1;
250 | if ($no_upload) {
251 | &error($text{'source_err1.2'});
252 | }
253 | $file = transname(file_basename($in{'upload_filename'}));
254 | open(MOD, ">$file");
255 | binmode(MOD);
256 | print MOD $in{'upload'};
257 | close(MOD);
258 |
259 | }elsif ($in{'source'} == 2 and $in{'url'} ne '') { # from ftp or http url (possible third-party)
260 | $url = $in{'url'};
261 | &error_setup(&text('source_err2', $url));
262 | $file = &transname(file_basename($url));
263 | $need_unlink = 1;
264 | my $error;
265 | $progress_callback_url = $url;
266 | if ($url =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
267 | $ssl = $1 eq 'https';
268 | $host = $2; $page = $3; $port = $ssl ? 443 : 80;
269 | if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
270 | my %cookie_headers = ('Cookie'=>'oraclelicense=accept-securebackup-cookie');
271 | &http_download($host, $port, $page, $file, \$error,
272 | \&progress_callback, $ssl, undef, undef, 0, 0, 1, \%cookie_headers);
273 | } elsif (
274 | $url =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
275 | $host = $1; $ffile = $3;
276 | &ftp_download($host, $ffile, $file, \$error, \&progress_callback);
277 | }else {
278 | &error($text{'source_err3'});
279 | }
280 | &error($error) if ($error);
281 | }
282 | return $file;
283 | }
284 |
285 | sub unzip_file{
286 | my $file = $_[0];
287 | my @suffixlist = ('.zip');
288 | ($lib_name,$path,$lib_suffix) = fileparse($file,@suffixlist);
289 |
290 | my $unzip_dir = "/tmp/.webmin/$lib_name";
291 |
292 | #if old temp extension dir exist, remove it
293 | #if( -d $unzip_dir and rmtree($unzip_dir) == 0){
294 | # &error("Failed to remove temp extension dir");
295 | # &ui_print_footer("", $text{'index_return'});
296 | # exit;
297 | #}
298 | &make_dir($unzip_dir, 0754, 1);
299 |
300 | my $unzip_out;
301 | my $unzip_err;
302 | print "
Unzipping to $unzip_dir ...
";
303 | local $out = &execute_command("unzip -u \"$file\" -d \"$unzip_dir\"", undef, \$unzip_out, \$unzip_err, 0, 0);
304 |
305 | if($unzip_err){
306 | &error("Error: unzip: $unzip_err");
307 | }else{
308 | $unzip_out = s/\r\n/
/g;
309 | print &html_escape($unzip_out);
310 | }
311 | return $unzip_dir;
312 | }
313 |
314 | sub get_tomcat_major_versions(){
315 | my @majors = ();
316 | my $url = "https://archive.apache.org/dist/tomcat/";
317 | &error_setup(&text('install_err3', $url));
318 | my $error = '';
319 | my $tmpfile = &transname('tomcat.html');
320 |
321 |
322 | &http_download('archive.apache.org', 80, "/dist/tomcat/", $tmpfile, \$error);
323 | if($error){
324 | error($error);
325 | }
326 |
327 | my @latest_versions;
328 | open(my $fh, '<', $tmpfile) or die "open:$!";
329 | while(my $line = <$fh>){
330 | if($line =~ /tomcat\-[0-9\.]+\/<\/a>/){
331 | push(@majors, $1);
332 | }
333 | }
334 | close $fh;
335 |
336 | return reverse sort sort_version @majors;
337 | }
338 |
339 | sub major_tomcat_versions{
340 | my $major = $_[0]; #Tomcat major version 6,7,8,9
341 |
342 | my $url = "https://archive.apache.org/dist/tomcat/tomcat-$major/";
343 | &error_setup(&text('install_err3', $url));
344 | my $error = '';
345 | my $tmpfile = &transname('tomcat.html');
346 |
347 |
348 | &http_download('archive.apache.org', 80, "/dist/tomcat/tomcat-$major/", $tmpfile, \$error);
349 | if($error){
350 | error($error);
351 | }
352 |
353 | my @latest_versions;
354 | open(my $fh, '<', $tmpfile) or die "open:$!";
355 | while(my $line = <$fh>){
356 | if($line =~ /v[0-9\.]+\/<\/a>/){
357 | push(@latest_versions, $1);
358 | }
359 | }
360 | close $fh;
361 |
362 | return sort sort_version @latest_versions;
363 | }
364 |
365 | sub setup_tomcat_service{
366 | my $tomcat_ver = $_[0];
367 | if (&has_command('systemctl')) {
368 |
369 | copy_source_dest("$module_root_directory/tomcat.service", '/etc/systemd/system/tomcat.service');
370 |
371 | my $ln = 0;
372 | $lref = read_file_lines('/etc/systemd/system/tomcat.service');
373 | foreach $line (@$lref){
374 | chomp $line;
375 | if($line =~ /\$TOMCAT_VER/){ #if its a section start
376 | $line =~ s/\$TOMCAT_VER/$tomcat_ver/;
377 | @{$lref}[$ln] = $line;
378 | }elsif($line =~ /\$CATALINA_HOME/){
379 | $line =~ s/\$CATALINA_HOME/\/home\/tomcat\/apache-tomcat-$tomcat_ver/;
380 | @{$lref}[$ln] = $line;
381 | }
382 | $ln=$ln+1;
383 | }
384 | &flush_file_lines('/etc/systemd/system/tomcat.service');
385 |
386 | &set_ownership_permissions('root','root', 0555, "/etc/systemd/system/tomcat.service");
387 |
388 | &backquote_command("systemctl daemon-reload", undef, \$cmd_out, \$cmd_err, 0, 0);
389 | }else{
390 | copy_source_dest("$module_root_directory/tomcat.init", '/etc/init.d/tomcat');
391 | &set_ownership_permissions('root','root', 0555, "/etc/init.d/tomcat");
392 | }
393 | print "
Setting Tomcat service ...";
394 | }
395 |
396 | sub upgrade_available(){
397 | my $tomcat_ver = installed_tomcat_version();
398 | my $latest_ver = latest_tomcat_version($tomcat_ver);
399 |
400 | my @versions = ($tomcat_ver, $latest_ver);
401 | @versions = sort sort_version @versions;
402 |
403 | if($versions[1] eq $tomcat_ver){
404 | return '';
405 | }else {
406 | return $latest_ver;
407 | }
408 | }
409 |
--------------------------------------------------------------------------------
/tomcat.init:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ### BEGIN INIT INFO
3 | # Provides: tomcat
4 | # Required-Start: $network
5 | # Required-Stop: $network
6 | # Default-Start: 2 3 4 5
7 | # Default-Stop: 0 1 6
8 | # Short-Description: Start/Stop Tomcat server
9 | ### END INIT INFO
10 |
11 | # Source function library.
12 | . /etc/environment; #Catalina variables
13 | . $CATALINA_HOME/bin/setenv.sh
14 |
15 | RETVAL=$?
16 |
17 | function start(){
18 | echo "Starting Tomcat"
19 | /bin/su - tomcat $CATALINA_HOME/bin/startup.sh
20 | RETVAL=$?
21 | }
22 |
23 | function stop(){
24 | echo "Stopping Tomcat"
25 | /bin/su - tomcat -c "$CATALINA_HOME/bin/shutdown.sh 60 -force"
26 | RETVAL=$?
27 | }
28 |
29 | case "$1" in
30 | start)
31 | start;
32 | ;;
33 | stop)
34 | stop;
35 | ;;
36 | restart)
37 | echo "Restarting Tomcat"
38 | stop;
39 | start;
40 | ;;
41 | status)
42 |
43 | if [ -f "${CATALINA_PID}" ]; then
44 | TOMCAT_PID=$(cat "${CATALINA_PID}")
45 | echo "Tomcat is running with PID ${TOMCAT_PID}";
46 | RETVAL=1
47 | else
48 | echo "Tomcat is not running";
49 | RETVAL=0
50 | fi
51 | ;;
52 | *)
53 | echo $"Usage: $0 {start|stop|restart|status}"
54 | exit 1
55 | ;;
56 | esac
57 | exit $RETVAL
58 |
--------------------------------------------------------------------------------
/tomcat.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=Tomcat $TOMCAT_VER
3 | After=multi-user.target
4 |
5 | [Service]
6 | User=tomcat
7 | Group=tomcat
8 |
9 | WorkingDirectory=$CATALINA_HOME
10 | Type=forking
11 | Restart=always
12 |
13 | EnvironmentFile=/etc/environment
14 |
15 | ExecStart=$CATALINA_HOME/bin/startup.sh
16 | ExecStop=$CATALINA_HOME/bin/shutdown.sh 60 -force
17 |
18 | [Install]
19 | WantedBy=multi-user.target
--------------------------------------------------------------------------------
/tomcat_upgrade.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | require './tomcat-lib.pl';
4 |
5 | sub select_tomcat_archive{
6 | print "$text{'base_desc2'}\n";
7 | print &ui_form_start("tomcat_upgrade.cgi", "form-data");
8 | print ui_hidden('mode', 'tomcat_upgrade');
9 | print &ui_table_start($text{'base_options'}, undef, 2);
10 |
11 | my $install_ver = installed_tomcat_version();
12 | my $install_major = (split /\./, $install_ver)[0];
13 |
14 | if($in{'tmver'}){
15 | $install_major = $in{'tmver'};
16 | }
17 |
18 | my @tmver = &get_tomcat_major_versions();
19 | my $sel_tmver = $install_major;
20 | my @tm_opts = ( );
21 | foreach my $v (@tmver) {
22 | push(@tm_opts, [ $v, $v ]);
23 | }
24 |
25 | print <
27 | function update_select(){
28 | var majorSel = document.getElementById('base_major');
29 | var major = majorSel.options[majorSel.selectedIndex].value;
30 |
31 | get_pjax_content('/tomcat/tomcat_upgrade.cgi?mode=select_version&tmver='+major);
32 | }
33 |
34 | EOF
35 |
36 | print &ui_table_row($text{'base_major'},
37 | &ui_select("base_major", $sel_tmver, \@tm_opts, 1, 0, undef, undef, 'id="base_major" onchange="update_select()"'));
38 |
39 | my @tver = &major_tomcat_versions($sel_tmver);
40 | my @tver_opts = ( );
41 | foreach my $v (reverse @tver) {
42 | push(@tver_opts, [ $v, $v ]);
43 | }
44 |
45 | print &ui_table_row($text{'base_installsource'},
46 | &ui_radio_table("source", 100,
47 | [ [ 100, $text{'source_archive'}, &ui_select("source_archive", undef, \@tver_opts,1, 0)],
48 | ]));
49 |
50 | print &ui_table_end();
51 | print &ui_form_end([ [ "", $text{'base_upgradeok'} ] ]);
52 | }
53 |
54 | sub migrate_settings_and_apps{
55 | my $old_ver = $_[0];
56 | my $new_ver = $_[1];
57 | my $apps_ref = $_[2];
58 |
59 | #Copy Settings
60 | my @files = ('bin/setenv.sh', 'conf/tomcat-users.xml');
61 | foreach my $file (@files){
62 | if( -f "/home/tomcat/apache-tomcat-$old_ver/$file"){
63 | copy_source_dest("/home/tomcat/apache-tomcat-$old_ver/$file",
64 | "/home/tomcat/apache-tomcat-$new_ver/$file");
65 | print "Copying $file to /home/tomcat/apache-tomcat-$new_ver/$file
";
66 | }
67 | }
68 |
69 | #make a list of installed apps
70 | my @exclude_apps = ('docs', 'examples', 'host-manager', 'manager', 'ROOT');
71 |
72 | #move apps
73 | print "Copying apps ...
";
74 | foreach my $app (@$apps_ref){
75 |
76 | next if grep( /^$app$/, @exclude_apps);
77 |
78 | if(!copy_source_dest( "/home/tomcat/apache-tomcat-$old_ver/webapps/$app",
79 | "/home/tomcat/apache-tomcat-$new_ver/webapps/$app")){
80 | &error("Error: Can't copy $app: $!");
81 | }else{
82 | print "$app
";
83 | }
84 |
85 | if(-f "/home/tomcat/apache-tomcat-$old_ver/webapps/$app.war"){
86 | if(!copy_source_dest( "/home/tomcat/apache-tomcat-$old_ver/webapps/$app.war",
87 | "/home/tomcat/apache-tomcat-$new_ver/webapps/$app.war")){
88 | &error("Error: Can't copy $app.war: $!");
89 | }else{
90 | print "$app.war
";
91 | }
92 | }
93 | }
94 | }
95 |
96 | sub upgrade_tomcat_from_archive{
97 |
98 | my $install_ver = installed_tomcat_version();
99 | my $latest_ver = $_[0];
100 |
101 | my @installed_apps = get_all_war_infos();
102 |
103 | #add_tomcat_user();
104 | download_and_install($latest_ver);
105 |
106 | tomcat_service_ctl('stop');
107 |
108 | setup_catalina_env($latest_ver);
109 | #setup_tomcat_users($latest_ver);
110 | setup_tomcat_service($latest_ver);
111 |
112 | migrate_settings_and_apps($install_ver, $latest_ver, \@installed_apps);
113 |
114 | print("Update done, starting new Tomcat ".$latest_ver);
115 | tomcat_service_ctl('start');
116 | }
117 |
118 |
119 | &ui_print_header(undef, $text{'index_title_upgrade'}, "", "intro", 1, 1);
120 | if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
121 | &ReadParseMime();
122 | }else {
123 | &ReadParse(); $no_upload = 1;
124 | }
125 | &error_setup($text{'start_err'});
126 |
127 | my $mode = $in{'mode'} || "select_version";
128 |
129 | if($mode eq "select_version"){
130 | select_tomcat_archive();
131 | }elsif($mode eq "tomcat_upgrade"){
132 | $err = upgrade_tomcat_from_archive($in{'source_archive'});
133 | }
134 |
135 | &ui_print_footer("", $text{'index_return'});
136 |
--------------------------------------------------------------------------------
/uninstall_java.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use File::Path 'rmtree';
4 |
5 | require './tomcat-lib.pl';
6 | require './java-lib.pl';
7 | require '../webmin/webmin-lib.pl'; #For OS Fetection
8 | &ReadParse();
9 |
10 | &error_setup($text{'delete_err'});
11 |
12 | my $jdk_name = $in{'inst_jdk'};
13 | $jdk_name || &error($text{'delete_enone'});
14 |
15 | my $jdk_dir = get_jdk_dir_by_name($jdk_name);
16 | my $def_jdk = is_default_jdk($jdk_dir);
17 |
18 | if(($def_jdk == 1) and ($in{'rm_def_jdk'} == 0)){
19 |
20 | &ui_print_header(undef, $text{'java_tabuninstall'}, "");
21 | print "Uninstall stopped, since $jdk_dir is default JDK.
";
22 |
23 | }else{
24 |
25 | if($jdk_name =~ /.*openjdk.*/){
26 | &redirect("/software/search.cgi?search=$jdk_name");
27 | return;
28 | }
29 |
30 | &ui_print_header(undef, $text{'delete_title'}, "");
31 |
32 | print "Removing $jdk_dir...
";
33 |
34 | if($def_jdk == 1){
35 | unset_default_java($jdk_dir);
36 | }
37 |
38 | if( -d $jdk_dir){
39 | rmtree($jdk_dir);
40 | }
41 |
42 | print "
Uninstall of $jdk_name is successful
";
43 | }
44 |
45 | &ui_print_footer("", $text{'index_return'});
46 |
--------------------------------------------------------------------------------
/uninstall_libs.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use File::Path 'rmtree';
4 |
5 | require './tomcat-lib.pl';
6 | &ReadParse();
7 |
8 | sub uninstall_lib{
9 | my $lib_name = $_[0];
10 |
11 | #get extension files
12 | my $lib_list = "$module_config_directory/lib_$lib_name.list";
13 | my %lib_files;
14 | &read_file($lib_list, \%lib_files);
15 |
16 | foreach $j (keys %lib_files){
17 | if( -e $lib_files{$j} or -l $lib_files{$j}){
18 | &unlink_file($lib_files{$j});
19 | print "$lib_files{$j}
";
20 | }elsif( -d $lib_files{$j}){
21 | rmtree($lib_files{$j});
22 | }else{
23 | print "Listed jar $j doesn't exist!
";
24 | }
25 | }
26 | &unlink_file($lib_list);
27 |
28 | print "
Uninstall of $lib_name is successful
";
29 | }
30 |
31 | &error_setup($text{'delete_err'});
32 | &ui_print_header(undef, $text{'libs_uninstall_title'}, "");
33 |
34 | @libs = split(/\0/, $in{'inst_lib'});
35 | @libs || &error($text{'delete_enone'});
36 |
37 | tomcat_service_ctl('stop');
38 |
39 | #delete each of the specified directories
40 | my $catalina_home = get_catalina_home();
41 | foreach $lib (@libs) {
42 | print "Removing $lib
";
43 | uninstall_lib($lib);
44 | }
45 |
46 | tomcat_service_ctl('start');
47 |
48 | &ui_print_footer("", $text{'index_return'});
49 |
--------------------------------------------------------------------------------