diff --git a/minecraft/index.cgi b/minecraft/index.cgi
index 26a9d0413..971537261 100755
--- a/minecraft/index.cgi
+++ b/minecraft/index.cgi
@@ -37,6 +37,23 @@ elsif ($err) {
return;
}
+# Check if new version is out, if we haven't checked in the last 6 hours
+if (time() - $config{'last_check'} > 6*60*60) {
+ my $sz = &check_server_download_size();
+ $config{'last_check'} = time();
+ &save_module_config();
+ my $jar = $config{'minecraft_jar'} ||
+ $config{'minecraft_dir'}."/"."minecraft_server.jar";
+ my @st = stat($jar);
+ if (@st && $sz && $st[7] != $sz) {
+ print "
\n";
+ print &ui_form_start("download.cgi");
+ print "$text{'index_upgradedesc'}\n";
+ print &ui_form_end([ [ undef, $text{'index_upgrade'} ] ]);
+ print "\n";
+ }
+ }
+
my @links = ( "edit_conf.cgi", "edit_users.cgi",
"view_logs.cgi", "list_conns.cgi",
"list_worlds.cgi", "edit_cmds.cgi",
diff --git a/minecraft/lang/en b/minecraft/lang/en
index cb86b290d..db987bd5f 100644
--- a/minecraft/lang/en
+++ b/minecraft/lang/en
@@ -17,6 +17,8 @@ index_atbootdesc=Change this option to control whether the Minecraft server is s
index_return=module index
index_download=Download Server
index_downloaddesc=Click this button to download and install the latest version of the Minecraft server JAR file.
+index_upgradedesc=A new Minecraft server version is now available for download.
+index_upgrade=Upgrade Now
check_edir=The base directory $1 does not exist
check_ejar=The server JAR file $1 does not exist
diff --git a/minecraft/minecraft-lib.pl b/minecraft/minecraft-lib.pl
index 1fd0680fd..631ee4485 100644
--- a/minecraft/minecraft-lib.pl
+++ b/minecraft/minecraft-lib.pl
@@ -570,4 +570,39 @@ eval("\$str = \"$str\"");
return $str;
}
+# check_server_download_size()
+# Returns the size in bytes of the minecraft server that is available
+# for download
+sub check_server_download_size
+{
+my ($host, $port, $page, $ssl) = &parse_http_url($server_jar_url);
+
+# Make HTTP connection
+my @headers;
+push(@headers, [ "Host", $host ]);
+push(@headers, [ "User-agent", "Webmin" ]);
+push(@headers, [ "Accept-language", "en" ]);
+alarm(5);
+my $h = &make_http_connection($host, $port, $ssl, "HEAD", $page, \@headers);
+alarm(0);
+return undef if (!ref($h));
+
+# Read headers
+my $line;
+($line = &read_http_connection($_[0])) =~ tr/\r\n//d;
+if ($line !~ /^HTTP\/1\..\s+(200)(\s+|$)/) {
+ return undef;
+ }
+my %header;
+while(1) {
+ $line = &read_http_connection($_[0]);
+ $line =~ tr/\r\n//d;
+ $line =~ /^(\S+):\s+(.*)$/ || last;
+ $header{lc($1)} = $2;
+ }
+
+&close_http_connection($h);
+return $header{'content-length'};
+}
+
1;