forcedownload.php
3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
require __DIR__ . '/../../pacotes/composer/vendor/autoload.php';
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
use Defuse\Crypto\File;
include(dirname(__FILE__)."/../safe.php");
verificaBlFerramentas(basename(dirname(__FILE__)),$i3geoBlFerramentas,false);
//
//o usuario deve ter entrado pelo i3Geo
//
if(empty($fingerprint)){
return;
}
//
//verifica se deve ser utilizado o metodo de criptografia
//
include(dirname(__FILE__)."/../../ms_configura.php");
if(isset($i3geoKeys)){
if( $i3geoKeys["salvaMapfile"] != "" ){
$keyAscii = $i3geoKeys["salvaMapfile"];
$key = Key::loadFromAsciiSafeString($keyAscii);
/*
$secret_data = "teste";
$ciphertext = Crypto::encrypt($secret_data, $key);
$data = Crypto::decrypt($ciphertext, $key);
echo $ciphertext;
echo $data;
*/
$inputFilename = $map_file;
$outputFilename = dirname(dirname($map_file))."/mapfile_".nomeRandomico(6).".map";
File::encryptFile($inputFilename, $outputFilename, $key);
//File::decryptFile($outputFilename, $outputFilename.".map", $key);
header("Content-Type:text/plain");
header('Content-Disposition: attachment; filename="'.basename($outputFilename).'"');
readfile($outputFilename);
return;
}
}
//
//faz uma copia temporaria do mapfile
//
$arquivo = dirname(dirname($map_file))."/mapfile_".nomeRandomico(6).".map";
$mapa = ms_newMapObj($map_file);
$mapa->save($arquivo);
$mapa = ms_newMapObj($arquivo);
//
//modifica os layers
//
$c = $mapa->numlayers;
$remover = array(); //guarda os nomes dos metadados pq removeMetaData nao funciona
for ($i=0;$i < $c;++$i){
$l = $mapa->getlayer($i);
//
//tratamento para layers que contem dados via base de dados
//
$ct = $l->connectiontype;
if($ct != MS_INLINE && $ct != MS_WMS && $ct != MS_GRATICULE){
$l->set("connection","");
$l->set("data","");
//
//remove os metadata
//
$hashTable = $l->metadata;
$key = null;
while ($key = $hashTable->nextkey($key)){
if(!in_array(strtolower($key),array("tema","nomeoriginal"))){
//echo "Key: ".$key." value: ".$hashTable->get($key)."<br/>";
$l->setmetadata($key,"");
if($ct != MS_WMS){
$remover[] = strtoupper($key);
}
}
}
}
}
$remover = array_unique($remover);
$mapa->save($arquivo);
$mapa = null;
removeCabecalho($arquivo,$remover);
header("Content-Type:text/plain");
header('Content-Disposition: attachment; filename="'.basename($arquivo).'"');
readfile($arquivo);
function removeCabecalho($arq,$remover){
global $locaplic;
//locaplic pode ser um endereco baseado no link simbolico. Por isso utiliza-se apenas o nome da pasta principal
$pasta = basename($locaplic);
$handle = fopen($arq, "r");
if ($handle){
$cabeca = array();
//$cabeca[] = "MAP\n";
$grava = false;
while (!feof($handle)){
$linha = fgets($handle);
if(strpos(strtoupper($linha),"SYMBOLSET") !== false){
//$cabeca[] = '"..'.explode($pasta,$linha)[1];
}
if(strpos(strtoupper($linha),"FONTSET") !== false){
//$cabeca[] = '"..'.explode($pasta,$linha)[1];
}
if(strtoupper(trim($linha)) == "LAYER"){
$grava = true;
}
if($grava){
$final[] = rtrim($linha, "\r\n") . PHP_EOL;
}
}
fclose($handle);
}
$final = array_merge($cabeca,$final);
$handle = fopen($arq, "w+");
$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");
$testar = array_merge($testar,$remover);
foreach ($final as $f){
//
//remove resultados em branco
//e grava a linha
//
$teste = strtoupper($f);
$teste = trim($teste);
$teste = str_replace(" ","",$teste);
$teste = str_replace("'","",$teste);
$teste = str_replace('"',"",$teste);
$teste = preg_replace('/[\n\r\t ]*/', '', $teste);
$passou = true;
foreach ($testar as $t) {
if($teste == $t){
$passou = false;
}
}
if($passou){
fwrite($handle,$f);
}
}
fclose($handle);
}
?>