Browse Source

working on installer and php

chunkymap-regen now adds htaccess files
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
b2e1462569
  1. 2
      chunkymap-cronjob
  2. 29
      chunkymap-regen.py
  3. 2
      chunkymap-regen.sh
  4. 92
      chunkymap.php

2
chunkymap-cronjob

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
# NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root
#python /home/owner/minetest/utils/chunkymap-regen.py #python /home/owner/minetest/util/chunkymap-regen.py
flock -n /var/run/chunkymap-regen.lockfile -c /home/owner/minetest/util/chunkymap-regen.sh flock -n /var/run/chunkymap-regen.lockfile -c /home/owner/minetest/util/chunkymap-regen.sh

29
chunkymap-regen.py

@ -114,8 +114,26 @@ def get_dict_from_conf_file(path,assignment_operator="="):
ins.close() ins.close()
return results return results
def deny_http_access(dir_path):
htaccess_name = ".htaccess"
htaccess_path = os.path.join(dir_path, htaccess_name)
outs = open(htaccess_path)
outs.write("IndexIgnore *"+"\n")
outs.write("<Files .htaccess>"+"\n")
outs.write("order allow,deny"+"\n")
outs.write("deny from all"+"\n")
outs.write("</Files>"+"\n")
outs.write("<Files *.php>"+"\n")
outs.write("order allow,deny"+"\n")
outs.write("deny from all"+"\n")
outs.write("</Files>"+"\n")
outs.close()
if os.path.isfile(mtmn_path) and os.path.isfile(colors_path): if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
chunkymap_data_path=os.path.join(website_root,"chunkymapdata") chunkymap_data_path=os.path.join(website_root,"chunkymapdata")
yaml_name = "generated.yml" yaml_name = "generated.yml"
yaml_path = os.path.join(chunkymap_data_path, yaml_name) yaml_path = os.path.join(chunkymap_data_path, yaml_name)
@ -123,6 +141,14 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
os.mkdir(chunkymap_data_path) os.mkdir(chunkymap_data_path)
chunkymap_players_name = "players" chunkymap_players_name = "players"
chunkymap_players_path = os.path.join(chunkymap_data_path, chunkymap_players_name) chunkymap_players_path = os.path.join(chunkymap_data_path, chunkymap_players_name)
htaccess_path = os.path.join(chunkymap_data_path,".htaccess")
if not os.path.isfile(htaccess_path):
deny_http_access(chunkymap_data_path)
htaccess_path = os.path.join(chunkymap_players_path,".htaccess")
if not os.path.isfile(htaccess_path):
deny_http_access(chunkymap_players_path)
if not os.path.isdir(chunkymap_players_path): if not os.path.isdir(chunkymap_players_path):
os.mkdir(chunkymap_players_path) os.mkdir(chunkymap_players_path)
players_path = os.path.join(world_path, "players") players_path = os.path.join(world_path, "players")
@ -263,6 +289,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
print "Could not finish deleting '"+dest_png_path+"'" print "Could not finish deleting '"+dest_png_path+"'"
try: try:
os.rename(png_path, dest_png_path) os.rename(png_path, dest_png_path)
print("(moved to '"+dest_png_path+"')")
except: except:
print "Could not finish moving '"+png_path+"' to '"+dest_png_path+"'" print "Could not finish moving '"+png_path+"' to '"+dest_png_path+"'"
try: try:
@ -270,6 +297,7 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
os.remove(dest_mapper_out_path) os.remove(dest_mapper_out_path)
if is_save_output_ok: if is_save_output_ok:
os.rename(mapper_out_path, dest_mapper_out_path) os.rename(mapper_out_path, dest_mapper_out_path)
print("(moved to '"+dest_mapper_out_path+"')")
else: else:
if os.path.isfile(mapper_out_path): if os.path.isfile(mapper_out_path):
os.remove(mapper_out_path) os.remove(mapper_out_path)
@ -305,6 +333,5 @@ if os.path.isfile(mtmn_path) and os.path.isfile(colors_path):
outs.write("total_generated_count:"+str(total_generated_count) + "\n") outs.write("total_generated_count:"+str(total_generated_count) + "\n")
outs.close() outs.close()
else: else:
print "failed since this folder must contain colors.txt and minetestmapper-numpy.py" print "failed since this folder must contain colors.txt and minetestmapper-numpy.py"

2
chunkymap-regen.sh

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
# NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root # NOTE: only works since all scripts in /etc/cron.*/ or crontab run as root
python /home/owner/minetest/utils/chunkymap-regen.py python /home/owner/minetest/util/chunkymap-regen.py

92
chunkymap.php

@ -50,6 +50,19 @@ function endsWith($haystack, $needle) {
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
} }
function is_int($val) {
$result = true;
$int_chars="0123456789-";
for ($i=0; $i<strlen($val); $i++) {
$digit_index = strpos($int_chars, substr($val, $i, 1));
if ($digit_index===false) {
$result = false;
break;
}
}
return $result;
}
function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) { function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) {
global $chunkymapdata_path; global $chunkymapdata_path;
global $map_dict; global $map_dict;
@ -61,32 +74,19 @@ function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) {
$x_opener="chunk_x"; $x_opener="chunk_x";
$z_opener="z"; $z_opener="z";
$dot_and_ext = ".png"; $dot_and_ext = ".png";
$x = $map_dict["chunkx_min"]; $chunkx_min = 0;
$z = $map_dict["chunkz_min"]; $chunkz_min = 0;
$x_count = $map_dict["chunkx_max"] - $map_dict["chunkx_min"] $chunkx_max = 0;
$z_count = $map_dict["chunkz_max"] - $map_dict["chunkz_min"] $chunkz_max = 0;
echo "<table border=\"0\">"; if ($map_dict != null) {
while ($z <= $map_dict["chunkz_max"]) { $chunkx_min = $map_dict["chunkx_min"];
echo " <tr>"; $chunkz_min = $map_dict["chunkz_min"];
while ($x <= $map_dict["chunkx_max"]) { $chunkx_max = $map_dict["chunkx_max"];
echo " <td>"; $chunkz_max = $map_dict["chunkz_max"];
$chunk_luid = "x".$x."z".$z;
$chunk_img_name = $x_opener.$x.$z_opener.$z."$dot_and_ext";
$chunk_img_path = $chunkymapdata_path.'/'.$chunk_img_name;
if (is_file($chunk_img_path)) {
echo "<img src=\"$chunk_img_path\"/ style=\"width:$zoom_min_1_max_100%\">";
}
echo " <br/>".$x.",0,".$z
echo " </td>";
$x++;
} }
echo " </tr>"; else {
$z++; //NOTE: no need to detect range if using $map_dict
} $chunkz_max = 0;
echo "</table>";
//NOTE: no need to detect range since using $map_dict
/*
$x_max = 0;
$x_min = 0; $x_min = 0;
$z_min = 0; $z_min = 0;
$z_max = 0; $z_max = 0;
@ -101,11 +101,51 @@ function echo_chunkymap_table($center_x, $center_z, $zoom_min_1_max_100) {
$z_len = strlen($file_lower) - strlen($x_opener) - $x_len - strlen($z_opener) - $dot_and_ext; $z_len = strlen($file_lower) - strlen($x_opener) - $x_len - strlen($z_opener) - $dot_and_ext;
$x = substr($file_lower, strlen($x_opener), $x_len); $x = substr($file_lower, strlen($x_opener), $x_len);
$z = substr($file_lower, $z_opener_index + strlen($z_opener), $z_len); $z = substr($file_lower, $z_opener_index + strlen($z_opener), $z_len);
if (is_int($x) and is_int($z)) {
if ($x<$chunkx_min) {
$chunkx_min=(int)$x;
}
if ($x>$chunkx_max) {
$chunkx_max=(int)$x;
}
if ($z<$chunkz_min) {
$chunkz_min=(int)$z;
} }
if ($z>$chunkz_max) {
$chunkz_max=(int)$z;
} }
} }
else {
echo "misnamed chunk tile image '$file' had coordinates ".$x.",".$z." for x,z.";
} }
} }
*/ }
}
}
}
}
$x = $chunkx_min;
$z = $chunkz_min;
$x_count = $chunkx_max - $chunkx_min;
$z_count = $chunkz_max - $chunkz_min;
echo "<table border=\"0\">";
while ($z <= $chunkz_max) {
echo " <tr>";
while ($x <= $chunkx_max) {
echo " <td>";
$chunk_luid = "x".$x."z".$z;
$chunk_img_name = $x_opener.$x.$z_opener.$z."$dot_and_ext";
$chunk_img_path = $chunkymapdata_path.'/'.$chunk_img_name;
if (is_file($chunk_img_path)) {
echo "<img src=\"$chunk_img_path\"/ style=\"width:$zoom_min_1_max_100%\">";
}
echo " <br/>".$x.",0,".$z
echo " </td>";
$x++;
}
echo " </tr>";
$z++;
}
echo "</table>";
} }
?> ?>
Loading…
Cancel
Save