Commit e3d595547a668575cc6acca575fab5d5f48ca0c2

Authored by Edmar Moretti
1 parent bba73139
Exists in master

Reformulação da ferramenta que faz o download do mapfile em uso para aumentar a segurança

ferramentas/salvamapa/forcedownload.php
1 1 <?php
2   -exit;
3   -//forca o download de um arquivo
4   -include("../../ms_configura.php");
5   -$f = $_GET['file'];
6   -$fName = basename($f);
7   -$d1 = basename(dirname($f));
8   -$fd = $dir_tmp."/".$d1."/".$fName;
9   -$fp = fopen($fd, 'rb');
  2 +include(dirname(__FILE__)."/../safe.php");
  3 +verificaBlFerramentas(basename(dirname(__FILE__)),$i3geoBlFerramentas,false);
  4 +//
  5 +//faz uma copia temporaria do mapfile
  6 +//
  7 +$arquivo = dirname($map_file)."/mapfile_".nomeRandomico(6).".map";
  8 +$mapa = ms_newMapObj($map_file);
  9 +$mapa->save($arquivo);
  10 +$mapa = ms_newMapObj($arquivo);
  11 +//
  12 +//modifica os layers
  13 +//
  14 +$c = $mapa->numlayers;
  15 +$remover = array(); //guarda os nomes dos metadados pq removeMetaData nao funciona
  16 +for ($i=0;$i < $c;++$i){
  17 + $l = $mapa->getlayer($i);
  18 + //
  19 + //tratamento para layers que contem dados via base de dados
  20 + //
  21 + $ct = $l->connectiontype;
  22 + if($ct != MS_INLINE && $ct != MS_WMS && $ct != MS_GRATICULE){
  23 + $l->set("connection","");
  24 + $l->set("data","");
  25 + }
  26 + //
  27 + //remove os metadata
  28 + //
  29 + $hashTable = $l->metadata;
  30 + $key = null;
  31 + while ($key = $hashTable->nextkey($key)){
  32 + if(!in_array(strtolower($key),array("tema","nomeoriginal"))){
  33 + //echo "Key: ".$key." value: ".$hashTable->get($key)."<br/>";
  34 + $l->setmetadata($key,"");
  35 + if($ct != MS_WMS){
  36 + $remover[] = strtoupper($key);
  37 + }
  38 + }
  39 + }
  40 +}
  41 +$remover = array_unique($remover);
  42 +
  43 +$mapa->save($arquivo);
  44 +$mapa = null;
  45 +removeCabecalho($arquivo,$remover);
10 46 header("Content-Type:text/plain");
11   -header('Content-Disposition: attachment; filename="'.$fName.'"');
12   -fpassthru($fp);
13   -?>
  47 +header('Content-Disposition: attachment; filename="'.basename($arquivo).'"');
  48 +readfile($arquivo);
  49 +
  50 +function removeCabecalho($arq,$remover){
  51 + global $locaplic;
  52 + //locaplic pode ser um endereco baseado no link simbolico. Por isso utiliza-se apenas o nome da pasta principal
  53 + $pasta = basename($locaplic);
  54 + $handle = fopen($arq, "r");
  55 + if ($handle){
  56 + $cabeca = array();
  57 + $cabeca[] = "MAP\n";
  58 + $grava = false;
  59 + while (!feof($handle)){
  60 + $linha = fgets($handle);
  61 + if(strpos(strtoupper($linha),"SYMBOLSET") !== false){
  62 + $cabeca[] = '"..'.explode($pasta,$linha)[1];
  63 + }
  64 + if(strpos(strtoupper($linha),"FONTSET") !== false){
  65 + $cabeca[] = '"..'.explode($pasta,$linha)[1];
  66 + }
  67 + if(strtoupper(trim($linha)) == "LAYER"){
  68 + $grava = true;
  69 + }
  70 + if($grava){
  71 + $final[] = rtrim($linha, "\r\n") . PHP_EOL;
  72 + }
  73 + }
  74 + fclose($handle);
  75 + }
  76 + $final = array_merge($cabeca,$final);
  77 + $handle = fopen($arq, "w+");
  78 + $testar = array("KEYIMAGE","TILEINDEX","TILEITEM","SYMBOL","LABELITEM","FILTERITEM","GROUP","ENCODING","TIP","CLASSE","ITENSDESC","CLASSESNOME","ITENSLINK","ESCALA","CLASSESSIMBOLO","MENSAGEM","EXTENSAO","CLASSESITEM","ESCONDIDO","CLASSESCOR","DOWNLOAD","CLASSESTAMANHO","ITENS","TEMA","APLICAEXTENSAO","IDENTIFICA");
  79 + $testar = array_merge($testar,$remover);
  80 + foreach ($final as $f){
  81 + //
  82 + //remove resultados em branco
  83 + //e grava a linha
  84 + //
  85 + $teste = strtoupper($f);
  86 + $teste = trim($teste);
  87 + $teste = str_replace(" ","",$teste);
  88 + $teste = str_replace("'","",$teste);
  89 + $teste = str_replace('"',"",$teste);
  90 + $teste = preg_replace('/[\n\r\t ]*/', '', $teste);
  91 + $passou = true;
  92 + foreach ($testar as $t) {
  93 + if($teste == $t){
  94 + $passou = false;
  95 + }
  96 + }
  97 + if($passou){
  98 + fwrite($handle,$f);
  99 + }
  100 + }
  101 + fclose($handle);
  102 +}
  103 +?>
14 104 \ No newline at end of file
... ...
ferramentas/salvamapa/geraminiatura.php
... ... @@ -25,27 +25,7 @@ $nomeImagem = str_replace(&quot;.&quot;,&quot;&quot;,$nomeImagem).&quot;.png&quot;;
25 25  
26 26 if(!file_exists($nomeImagem)){
27 27 $mapa = ms_newMapObj($base);
28   - if (isset($postgis_mapa)){
29   - if ($postgis_mapa != ""){
30   - $numlayers = $mapa->numlayers;
31   - for ($i=0;$i < $numlayers;$i++){
32   - $layern = $mapa->getlayer($i);
33   - if (!empty($postgis_mapa)){
34   - if ($layern->connectiontype == MS_POSTGIS){
35   - $lcon = $layern->connection;
36   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
37   - if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade
38   - {$layern->set("connection",$postgis_mapa);
39   - }
40   - else{
41   - $layern->set("connection",$postgis_mapa[$lcon]);
42   - }
43   - }
44   - }
45   - }
46   - }
47   - }
48   - }
  28 + substituiConObj($mapa,$postgis_mapa);
49 29 $mapa->setsize($_GET["w"],$_GET["h"]);
50 30 $sca = $mapa->scalebar;
51 31 $sca->set("status",MS_OFF);
... ... @@ -53,10 +33,6 @@ if(!file_exists($nomeImagem)){
53 33 $objImagemM->saveImage($nomeImagem);
54 34 }
55 35 ob_clean();
56   -header('Content-Length: '.filesize($nomeImagem));
57 36 header('Content-Type: image/png');
58   -header('Cache-Control: public, max-age=22222222');
59   -header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
60   -//fpassthru(fopen($nomeImagem, 'rb'));
61 37 readfile($nomeImagem);
62 38 ?>
63 39 \ No newline at end of file
... ...
ferramentas/salvamapa/index.js
... ... @@ -91,14 +91,9 @@ i3GEOF.salvaMapa = {
91 91 onde = $i(onde);
92 92 if(onde){
93 93 try{
94   - var map_file = i3GEO.parametros.mapfile,
95   - teste = i3GEO.configura.locaplic+"/testamapfile.php?map="+map_file,
96   - local = map_file.split("ms_tmp");
97   - down = i3GEO.configura.locaplic+"/ferramentas/salvamapa/forcedownload.php?file="+map_file;
98   - local = i3GEO.configura.locaplic+"/../ms_tmp"+local[1];
  94 + var down = i3GEO.configura.locaplic+"/ferramentas/salvamapa/forcedownload.php?g_sid=" + i3GEO.configura.sid;
99 95 onde.innerHTML = "" +
100   - "<a style='line-height:20px;font-size:12px;' href='"+down+"' target='_blank' >"+$trad('baixaArquivo',i3GEOF.salvaMapa.dicionario)+"</a><br>" +
101   - "<a style='line-height:20px;font-size:12px;' href='"+teste+"' target='_blank' >"+$trad('testaArquivo',i3GEOF.salvaMapa.dicionario)+"</a>";
  96 + "<a style='line-height:20px;font-size:12px;' href='"+down+"' target='_blank' >"+$trad('baixaArquivo',i3GEOF.salvaMapa.dicionario)+"</a><br>";
102 97 }
103 98 catch(erro){i3GEO.janela.tempoMsg(erro);}
104 99 }
... ...