/
tiki-map_upload.php
181 lines (180 loc) · 6.52 KB
/
tiki-map_upload.php
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-map_upload.php 44444 2013-01-05 21:24:24Z changi67 $
require_once ('tiki-setup.php');
$access->check_feature('feature_maps');
$access->check_permission('tiki_p_map_edit');
//get_strings tra('Layer Management')
if (!is_dir($prefs['map_path'])) {
$smarty->assign('msg', tr('Please create a directory named %0 to hold your map files.', $prefs['map_path']));
$smarty->display('error.tpl');
die;
}
$DSEP = DIRECTORY_SEPARATOR;
$max_file_size = ini_get("upload_max_filesize");
$smarty->assign('max_file_size', $max_file_size);
// checks to ensure no variable contains .. or ~ in file name or directory name
if (isset($_REQUEST["file"])) {
$_REQUEST["file"] = preg_replace('~\.\.~', '', $_REQUEST["file"]);
$_REQUEST["file"] = preg_replace('~\~~', '', $_REQUEST["file"]);
$_REQUEST["file"] = preg_replace('~/+~', '/', $_REQUEST["file"]);
}
if (isset($_REQUEST["directory"])) {
$_REQUEST["directory"] = preg_replace('~\.\.~', '', $_REQUEST["directory"]);
$_REQUEST["directory"] = preg_replace('~\~~', '', $_REQUEST["directory"]);
$_REQUEST["directory"] = preg_replace('~/+~', '/', $_REQUEST["directory"]);
}
if (isset($_REQUEST["dir"])) {
$_REQUEST["dir"] = preg_replace('~\~~', '', $_REQUEST["dir"]);
$_REQUEST["dir"] = preg_replace('~/+~', '/', $_REQUEST["dir"]);
$directory_path = inpath($prefs['map_path'] . $_REQUEST["dir"], $prefs['map_path'] . "data");
if ($directory_path) {
$dir = $DSEP . "data" . substr($directory_path, strlen($prefs['map_path']) + 4);
} else {
$dir = $DSEP . "data";
$directory_path = $prefs['map_path'] . $DSEP . "data";
}
$basedir = dirname($_REQUEST["dir"]);
if (substr($dir, 0, 5) != $DSEP . "data") {
$directory_path = $prefs['map_path'] . $DSEP . "data";
$dir = $DSEP . "data";
$basedir = $DSEP;
}
} else {
$directory_path = $prefs['map_path'] . $DSEP . "data";
$dir = $DSEP . "data";
$basedir = $DSEP;
}
$smarty->assign('dir', $dir);
$smarty->assign('basedir', $basedir);
//Do we have a file to upload?
if (isset($_REQUEST["upload"])) {
for ($i = 1; $i <= 6; $i++) {
if (isset($_FILES["userfile$i"]) && is_uploaded_file($_FILES["userfile$i"]['tmp_name'])) {
if (!@move_uploaded_file($_FILES["userfile$i"]['tmp_name'], $directory_path . $DSEP . $_FILES["userfile$i"]['name'])) {
$smarty->assign('msg', tra("Could not upload the file"));
$smarty->display("error.tpl");
die;
}
}
}
}
//Do we have a file to delete?
if (isset($_REQUEST["action"]) && isset($_REQUEST["file"])) {
if ($_REQUEST["action"] == "delete") {
$access->check_authenticity();
if (is_file($directory_path . $DSEP . $_REQUEST["file"]) && !preg_match("/^\./", $_REQUEST["file"])) {
$access->check_permission('tiki_p_map_delete');
unlink($directory_path . $DSEP . $_REQUEST["file"]);
} else {
$smarty->assign('msg', tra("File not found"));
$smarty->display("error.tpl");
die;
}
}
}
//Do we have a directory to create or delete?
if (isset($_REQUEST["action"]) && isset($_REQUEST["directory"])) {
if ($_REQUEST["action"] == "createdir") {
if (!preg_match("/\./", $_REQUEST["directory"])) {
$access->check_permission('tiki_p_map_create');
if (!@mkdir($directory_path . $DSEP . $_REQUEST["directory"])) {
$smarty->assign('msg', tra("The Directory is not empty"));
$smarty->display("error.tpl");
die;
}
} else {
$smarty->assign('msg', tra("Invalid directory name"));
$smarty->display("error.tpl");
die;
}
}
if ($_REQUEST["action"] == "deldir") {
$access->check_authenticity();
if (!preg_match("/^\./", $_REQUEST["directory"]) || !preg_match("/\.\//", $_REQUEST["directory"])) {
$access->check_permission('tiki_p_map_delete');
if (!@rmdir($directory_path . $DSEP . $_REQUEST["directory"])) {
$smarty->assign('msg', tra("The Directory is not empty"));
$smarty->display("error.tpl");
die;
}
}
}
}
//Do we have an index to create?
if (isset($_REQUEST["action"]) && isset($_REQUEST["indexfile"]) && isset($_REQUEST["filestoindex"])) {
if ($_REQUEST["action"] == "createindex") {
$access->check_permission('tiki_p_map_create');
if (preg_match("/\.\//", $_REQUEST["indexfile"]) || !preg_match("/\.shp/", $_REQUEST["indexfile"])) {
$smarty->assign('msg', tra("Invalid file name"));
$smarty->display("error.tpl");
die;
}
if (preg_match("/\.\//", $_REQUEST["filestoindex"])) {
$smarty->assign('msg', tra("Invalid files to index"));
$smarty->display("error.tpl");
die;
}
if (!isset($prefs['gdaltindex'])) {
$smarty->assign('msg', tra("I do not know where is gdaltindex. Set correctly the Map feature"));
$smarty->display("error.tpl");
die;
}
$indexfile = inpath(dirname($directory_path . $DSEP . $_REQUEST["indexfile"]), $directory_path);
$filestoindex = inpath(dirname($directory_path . $DSEP . $_REQUEST["filestoindex"]), $directory_path);
if ($indexfile && $filestoindex && is_file($prefs['gdaltindex'])) {
$indexfile = escapeshellarg($indexfile . $DSEP . basename($_REQUEST["indexfile"]));
$filestoindex = escapeshellarg($filestoindex . $DSEP . basename($_REQUEST["filestoindex"]));
$command = $prefs['gdaltindex'] . " " . $indexfile . " " . $filestoindex;
$return = shell_exec($command);
if ($return <> 0) {
$smarty->assign('msg', tra("I could not create the index file"));
$smarty->display("error.tpl");
die;
}
} else {
$smarty->assign('msg', tra("I could not create the index file"));
$smarty->display("error.tpl");
die;
}
}
}
// Get layers from the layers directory
$files = array();
$dirs = array();
if (is_dir($directory_path)) {
$h = opendir($directory_path);
while (($file = readdir($h)) !== false) {
// Ignore hidden files
if (!preg_match("/^(\.|CVS)/", $file)) {
// Put dirs in $dirs[] and files in $files[]
if (is_dir($directory_path . $DSEP . $file)) {
$dirs[] = $file;
} else {
$files[] = $file;
}
}
}
closedir($h);
}
// if $dirs[] exists, sort it and print all elements in it.
if (is_array($dirs)) {
sort($dirs);
}
// if $files[] exists, sort it and print all elements in it.
if (is_array($files)) {
sort($files);
}
$smarty->assign('files', $files);
$smarty->assign('dirs', $dirs);
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
// Get templates from the templates/modules directori
$smarty->assign('mid', 'map/tiki-map_upload.tpl');
$smarty->display("tiki.tpl");