Dynamic gzip compression support
authorJamie Cameron <jcameron@webmin.com>
Sun, 27 Mar 2011 01:59:53 +0000 (18:59 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sun, 27 Mar 2011 01:59:53 +0000 (18:59 -0700)
CHANGELOG
miniserv.pl
webmin/change_advanced.cgi
webmin/config.info.ru_RU [new file with mode: 0644]
webmin/edit_advanced.cgi
webmin/lang/en

index c401fae..4119afc 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -141,5 +141,5 @@ Major Dutch updates, thanks to Gandyman.
 Majoe French translation update, thanks to ButterflyOfFire.
 Allow per-language language overrides to be defined, in custom-lang.$code files.
 Updated numerous modules to improve support for Debian 6 and Ubuntu 10.10.
-If a browser asks for gzip compression and a file with a .gz extension exists in the same directory as a static file, Webmin will now serve the gzipped file instead.
+If a browser asks for gzip compression and a file with a .gz extension exists in the same directory as a static file, Webmin will now serve the gzipped file instead. If the Compress::Zlib perl module is installed and dynamic compression is enabled in the Webmin Configuration module, all non-image files will be served compressed.
 Added support for Amazon Linux.
index a2738d0..24e8d56 100755 (executable)
@@ -267,6 +267,14 @@ if ($use_ssl) {
                }
        }
 
+# Load gzip library if enabled
+if ($config{'gzip'} eq '1') {
+       eval "use Compress::Zlib";
+       if (!$@) {
+               $use_gzip = 1;
+               }
+       }
+
 # Setup syslog support if possible and if requested
 if ($use_syslog) {
        open(ERRDUP, ">&STDERR");
@@ -2430,6 +2438,31 @@ if (&get_type($full) eq "internal/cgi" && $validated != 4) {
                $rv = 0;
                }
        }
+elsif ($use_gzip && $acceptenc{'gzip'} && &should_gzip_file($full)) {
+       # Load and compress file
+       print DEBUG "handle_request: outputting gzipped file $full\n";
+       open(FILE, $full) || &http_error(404, "Failed to open file");
+       {
+               local $/ = undef;
+               $data = <FILE>;
+               }
+       close(FILE);
+       @stopen = stat($file);
+       $data = Compress::Zlib::memGzip($data);
+       local $resp = "HTTP/1.0 $ok_code $ok_message\r\n".
+                     "Date: $datestr\r\n".
+                     "Server: $config{server}\r\n".
+                     "Content-type: ".&get_type($full)."\r\n".
+                     "Content-length: ".length($data)."\r\n".
+                     "Last-Modified: ".&http_date($stopen[9])."\r\n".
+                     "Content-Encoding: gzip\r\n".
+                     "Expires: ".&http_date(time()+$config{'expires'})."\r\n";
+       &write_data($resp);
+       $rv = &write_keep_alive();
+       &write_data("\r\n");
+       &reset_byte_count();
+       &write_data($data);
+       }
 else {
        # A file to output
        print DEBUG "handle_request: outputting file $full\n";
@@ -5735,3 +5768,12 @@ if ($config{'errorlog'} ne '-') {
        }
 select(STDERR); $| = 1; select(STDOUT);
 }
+
+# should_gzip_file(filename)
+# Returns 1 if some path should be gzipped
+sub should_gzip_file
+{
+my ($path) = @_;
+return $path !~ /\.(gif|png|jpg|jpeg|tif|tiff)$/i;
+}
+
index 92206e6..1b06860 100755 (executable)
@@ -100,6 +100,13 @@ else {
 # Save password pass option
 $miniserv{'pass_password'} = $in{'pass'};
 
+# Save gzip option
+if ($in{'gzip'} == 1) {
+       eval "use Compress::Zlib";
+       $@ && &error(&text('advanced_egzip', '<tt>Compress::Zlib</tt>'));
+       }
+$miniserv{'gzip'} = $in{'gzip'};
+
 &lock_file($ENV{'MINISERV_CONFIG'});
 &put_miniserv_config(\%miniserv);
 &unlock_file($ENV{'MINISERV_CONFIG'});
diff --git a/webmin/config.info.ru_RU b/webmin/config.info.ru_RU
new file mode 100644 (file)
index 0000000..08d46c9
--- /dev/null
@@ -0,0 +1,4 @@
+cron_mode=Çàäàâàòü âðåìÿ â "Îáíîâëåíèè ïî ðàñïèñàíèþ" êàê,1,0-Ïðîñòîé èíòåðôåéñ,1-Cron time selector
+warn_days=Çà ñêîëüêî äíåé ïðåäóïðåæäàòü ïîëüçîâàòåëåé îá èñòå÷åíèè ñðîêà äåéñòâèÿ ïàðîëÿ,0,5
+third_url=URL ñïèñêà ñòîðîííèõ ìîäóëåé,3,Íà www.webmin.com
+standard_url=URL ñïèñêà ñòàíäàðòíûõ ìîäóëåé,3,Íà www.webmin.com
index b953aa9..f1b8966 100755 (executable)
@@ -110,6 +110,13 @@ if (&foreign_check("proc")) {
                }
        }
 
+# Gzip static files?
+print &ui_table_row($text{'advanced_gzip'},
+       &ui_radio("gzip", $miniserv{'gzip'},
+                 [ [ '', $text{'advanced_gzipauto'} ],
+                   [ 0, $text{'advanced_gzip0'} ],
+                   [ 1, $text{'advanced_gzip1'} ] ]));
+
 print &ui_table_end();
 print &ui_form_end([ [ "save", $text{'save'} ] ]);
 
index 214a2fa..97ca0ed 100644 (file)
@@ -793,6 +793,11 @@ advanced_nice=CPU priority for scheduled jobs
 advanced_pri=Priority level
 advanced_sclass=IO class for scheduled jobs
 advanced_sprio=IO priority for scheduled jobs
+advanced_gzip=Server gzip compressed static files?
+advanced_gzipauto=If pre-compressed .gz file exists
+advanced_gzip0=Never
+advanced_gzip1=Always compress dynamically
+advanced_egzip=Gzip compression cannot be enabled unless the $1 perl module is installed
 
 syslog_errorlog=Webmin error log