mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 16:50:24 +00:00
World download in ZIP format
This commit is contained in:
25
minecraft/change_world.cgi
Normal file
25
minecraft/change_world.cgi
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/local/bin/perl
|
||||
# Update the default world
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
require './minecraft-lib.pl';
|
||||
our (%in, %text, %config);
|
||||
&ReadParse();
|
||||
&error_setup($text{'worlds_err'});
|
||||
$in{'d'} || &error($text{'worlds_esel'});
|
||||
|
||||
my $conf = &get_minecraft_config();
|
||||
my $def = &find_value("level-name", $conf);
|
||||
if ($def ne $in{'d'}) {
|
||||
&lock_file(&get_minecraft_config_file());
|
||||
&save_directive("level-name", $in{'d'}, $conf);
|
||||
&flush_file_lines(&get_minecraft_config_file());
|
||||
&unlock_file(&get_minecraft_config_file());
|
||||
if ($in{'apply'} && &is_minecraft_server_running()) {
|
||||
&stop_minecraft_server();
|
||||
my $err = &start_minecraft_server();
|
||||
&error($err) if ($err);
|
||||
}
|
||||
}
|
||||
&redirect("list_worlds.cgi");
|
||||
@@ -82,7 +82,8 @@ else {
|
||||
print &ui_table_end();
|
||||
print &ui_form_end(
|
||||
$in{'new'} ? [ [ undef, $text{'create'} ] ]
|
||||
: [ [ 'delete', $text{'world_delete'} ] ],
|
||||
: [ [ 'delete', $text{'world_delete'} ],
|
||||
[ 'download', $text{'world_download'} ] ],
|
||||
);
|
||||
|
||||
&ui_print_footer("list_worlds.cgi", $text{'worlds_return'});
|
||||
|
||||
@@ -180,6 +180,7 @@ world_eupload=No world data to upload selected
|
||||
world_ezip=Uploaded world data does not appear to be in ZIP format
|
||||
world_eunzip=Failed to unzip world data : $1
|
||||
world_edat=ZIP file does not contain a level.dat file
|
||||
world_download=Download ZIP File
|
||||
|
||||
chooser_title=Select Item
|
||||
chooser_id=Item ID
|
||||
|
||||
@@ -96,6 +96,34 @@ elsif ($in{'delete'}) {
|
||||
|
||||
&ui_print_footer("list_worlds.cgi", $text{'worlds_return'});
|
||||
}
|
||||
elsif ($in{'download'} && !$ENV{'PATH_INFO'}) {
|
||||
# Redirect to download with a nice path
|
||||
&redirect("save_world.cgi/$in{'name'}.zip?name=$in{'name'}&download=1");
|
||||
}
|
||||
elsif ($in{'download'} && $ENV{'PATH_INFO'}) {
|
||||
# Download world as ZIP file
|
||||
$in{'name'} || &error("Missing world name");
|
||||
my $temp = &transname().".zip";
|
||||
my $out = &backquote_command(
|
||||
"cd ".quotemeta($config{'minecraft_dir'})." && ".
|
||||
"zip -r $temp ".quotemeta($in{'name'}));
|
||||
my @st = stat($temp);
|
||||
!$? && @st ||
|
||||
&error(&text('world_ezip', "<tt>".&html_escape($out)."</tt>"));
|
||||
print "Content-type: application/zip\n";
|
||||
print "Content-length: $st[7]\n";
|
||||
print "X-no-links: 1\n";
|
||||
print "Content-Disposition: Attachment\n";
|
||||
print "\n";
|
||||
my $fh = "ZIP";
|
||||
my $buf;
|
||||
&open_readfile($fh, $temp);
|
||||
&unlink_file($temp);
|
||||
while(read($fh, $buf, 1024)) {
|
||||
print $buf;
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
else {
|
||||
&error("No button clicked");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user