Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* // !!!
|
Chris@76
|
18
|
Chris@76
|
19 void PackageGet()
|
Chris@76
|
20 // !!!
|
Chris@76
|
21
|
Chris@76
|
22 void PackageGBrowse()
|
Chris@76
|
23 // !!!
|
Chris@76
|
24
|
Chris@76
|
25 void PackageDownload()
|
Chris@76
|
26 // !!!
|
Chris@76
|
27
|
Chris@76
|
28 void PackageUpload()
|
Chris@76
|
29 // !!!
|
Chris@76
|
30
|
Chris@76
|
31 void PackageServerAdd()
|
Chris@76
|
32 // !!!
|
Chris@76
|
33
|
Chris@76
|
34 void PackageServerRemove()
|
Chris@76
|
35 // !!!
|
Chris@76
|
36 */
|
Chris@76
|
37
|
Chris@76
|
38 // Browse the list of package servers, add servers...
|
Chris@76
|
39 function PackageGet()
|
Chris@76
|
40 {
|
Chris@76
|
41 global $txt, $scripturl, $context, $boarddir, $sourcedir, $modSettings;
|
Chris@76
|
42
|
Chris@76
|
43 isAllowedTo('admin_forum');
|
Chris@76
|
44 require_once($sourcedir . '/Subs-Package.php');
|
Chris@76
|
45
|
Chris@76
|
46 // Use the Packages template... no reason to separate.
|
Chris@76
|
47 loadLanguage('Packages');
|
Chris@76
|
48 loadTemplate('Packages', 'admin');
|
Chris@76
|
49
|
Chris@76
|
50 $context['page_title'] = $txt['package'];
|
Chris@76
|
51
|
Chris@76
|
52 // Here is a list of all the potentially valid actions.
|
Chris@76
|
53 $subActions = array(
|
Chris@76
|
54 'servers' => 'PackageServers',
|
Chris@76
|
55 'add' => 'PackageServerAdd',
|
Chris@76
|
56 'browse' => 'PackageGBrowse',
|
Chris@76
|
57 'download' => 'PackageDownload',
|
Chris@76
|
58 'remove' => 'PackageServerRemove',
|
Chris@76
|
59 'upload' => 'PackageUpload',
|
Chris@76
|
60 );
|
Chris@76
|
61
|
Chris@76
|
62 // Now let's decide where we are taking this...
|
Chris@76
|
63 if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
|
Chris@76
|
64 $context['sub_action'] = $_REQUEST['sa'];
|
Chris@76
|
65 // We need to support possible old javascript links...
|
Chris@76
|
66 elseif (isset($_GET['pgdownload']))
|
Chris@76
|
67 $context['sub_action'] = 'download';
|
Chris@76
|
68 else
|
Chris@76
|
69 $context['sub_action'] = 'servers';
|
Chris@76
|
70
|
Chris@76
|
71 // We need to force the "Download" tab as selected.
|
Chris@76
|
72 $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget';
|
Chris@76
|
73
|
Chris@76
|
74 // Now create the tabs for the template.
|
Chris@76
|
75 $context[$context['admin_menu_name']]['tab_data'] = array(
|
Chris@76
|
76 'title' => $txt['package_manager'],
|
Chris@76
|
77 //'help' => 'registrations',
|
Chris@76
|
78 'description' => $txt['package_manager_desc'],
|
Chris@76
|
79 'tabs' => array(
|
Chris@76
|
80 'browse' => array(
|
Chris@76
|
81 ),
|
Chris@76
|
82 'packageget' => array(
|
Chris@76
|
83 'description' => $txt['download_packages_desc'],
|
Chris@76
|
84 ),
|
Chris@76
|
85 'installed' => array(
|
Chris@76
|
86 'description' => $txt['installed_packages_desc'],
|
Chris@76
|
87 ),
|
Chris@76
|
88 'perms' => array(
|
Chris@76
|
89 'description' => $txt['package_file_perms_desc'],
|
Chris@76
|
90 ),
|
Chris@76
|
91 'options' => array(
|
Chris@76
|
92 'description' => $txt['package_install_options_ftp_why'],
|
Chris@76
|
93 ),
|
Chris@76
|
94 ),
|
Chris@76
|
95 );
|
Chris@76
|
96
|
Chris@76
|
97 $subActions[$context['sub_action']]();
|
Chris@76
|
98 }
|
Chris@76
|
99
|
Chris@76
|
100 function PackageServers()
|
Chris@76
|
101 {
|
Chris@76
|
102 global $txt, $scripturl, $context, $boarddir, $sourcedir, $modSettings, $smcFunc;
|
Chris@76
|
103
|
Chris@76
|
104 // Ensure we use the correct template, and page title.
|
Chris@76
|
105 $context['sub_template'] = 'servers';
|
Chris@76
|
106 $context['page_title'] .= ' - ' . $txt['download_packages'];
|
Chris@76
|
107
|
Chris@76
|
108 // Load the list of servers.
|
Chris@76
|
109 $request = $smcFunc['db_query']('', '
|
Chris@76
|
110 SELECT id_server, name, url
|
Chris@76
|
111 FROM {db_prefix}package_servers',
|
Chris@76
|
112 array(
|
Chris@76
|
113 )
|
Chris@76
|
114 );
|
Chris@76
|
115 $context['servers'] = array();
|
Chris@76
|
116 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
117 {
|
Chris@76
|
118 $context['servers'][] = array(
|
Chris@76
|
119 'name' => $row['name'],
|
Chris@76
|
120 'url' => $row['url'],
|
Chris@76
|
121 'id' => $row['id_server'],
|
Chris@76
|
122 );
|
Chris@76
|
123 }
|
Chris@76
|
124 $smcFunc['db_free_result']($request);
|
Chris@76
|
125
|
Chris@76
|
126 $context['package_download_broken'] = !is_writable($boarddir . '/Packages') || !is_writable($boarddir . '/Packages/installed.list');
|
Chris@76
|
127
|
Chris@76
|
128 if ($context['package_download_broken'])
|
Chris@76
|
129 {
|
Chris@76
|
130 @chmod($boarddir . '/Packages', 0777);
|
Chris@76
|
131 @chmod($boarddir . '/Packages/installed.list', 0777);
|
Chris@76
|
132 }
|
Chris@76
|
133
|
Chris@76
|
134 $context['package_download_broken'] = !is_writable($boarddir . '/Packages') || !is_writable($boarddir . '/Packages/installed.list');
|
Chris@76
|
135
|
Chris@76
|
136 if ($context['package_download_broken'])
|
Chris@76
|
137 {
|
Chris@76
|
138 if (isset($_POST['ftp_username']))
|
Chris@76
|
139 {
|
Chris@76
|
140 loadClassFile('Class-Package.php');
|
Chris@76
|
141 $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
|
Chris@76
|
142
|
Chris@76
|
143 if ($ftp->error === false)
|
Chris@76
|
144 {
|
Chris@76
|
145 // I know, I know... but a lot of people want to type /home/xyz/... which is wrong, but logical.
|
Chris@76
|
146 if (!$ftp->chdir($_POST['ftp_path']))
|
Chris@76
|
147 {
|
Chris@76
|
148 $ftp_error = $ftp->error;
|
Chris@76
|
149 $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
|
Chris@76
|
150 }
|
Chris@76
|
151 }
|
Chris@76
|
152 }
|
Chris@76
|
153
|
Chris@76
|
154 if (!isset($ftp) || $ftp->error !== false)
|
Chris@76
|
155 {
|
Chris@76
|
156 if (!isset($ftp))
|
Chris@76
|
157 {
|
Chris@76
|
158 loadClassFile('Class-Package.php');
|
Chris@76
|
159 $ftp = new ftp_connection(null);
|
Chris@76
|
160 }
|
Chris@76
|
161 elseif ($ftp->error !== false && !isset($ftp_error))
|
Chris@76
|
162 $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
|
Chris@76
|
163
|
Chris@76
|
164 list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
|
Chris@76
|
165
|
Chris@76
|
166 if ($found_path || !isset($_POST['ftp_path']))
|
Chris@76
|
167 $_POST['ftp_path'] = $detect_path;
|
Chris@76
|
168
|
Chris@76
|
169 if (!isset($_POST['ftp_username']))
|
Chris@76
|
170 $_POST['ftp_username'] = $username;
|
Chris@76
|
171
|
Chris@76
|
172 $context['package_ftp'] = array(
|
Chris@76
|
173 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
|
Chris@76
|
174 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : (isset($modSettings['package_port']) ? $modSettings['package_port'] : '21'),
|
Chris@76
|
175 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : (isset($modSettings['package_username']) ? $modSettings['package_username'] : ''),
|
Chris@76
|
176 'path' => $_POST['ftp_path'],
|
Chris@76
|
177 'error' => empty($ftp_error) ? null : $ftp_error,
|
Chris@76
|
178 );
|
Chris@76
|
179 }
|
Chris@76
|
180 else
|
Chris@76
|
181 {
|
Chris@76
|
182 $context['package_download_broken'] = false;
|
Chris@76
|
183
|
Chris@76
|
184 $ftp->chmod('Packages', 0777);
|
Chris@76
|
185 $ftp->chmod('Packages/installed.list', 0777);
|
Chris@76
|
186
|
Chris@76
|
187 $ftp->close();
|
Chris@76
|
188 }
|
Chris@76
|
189 }
|
Chris@76
|
190 }
|
Chris@76
|
191
|
Chris@76
|
192 // Browse a server's list of packages.
|
Chris@76
|
193 function PackageGBrowse()
|
Chris@76
|
194 {
|
Chris@76
|
195 global $txt, $boardurl, $context, $scripturl, $boarddir, $sourcedir, $forum_version, $context, $smcFunc;
|
Chris@76
|
196
|
Chris@76
|
197 if (isset($_GET['server']))
|
Chris@76
|
198 {
|
Chris@76
|
199 if ($_GET['server'] == '')
|
Chris@76
|
200 redirectexit('action=admin;area=packages;get');
|
Chris@76
|
201
|
Chris@76
|
202 $server = (int) $_GET['server'];
|
Chris@76
|
203
|
Chris@76
|
204 // Query the server list to find the current server.
|
Chris@76
|
205 $request = $smcFunc['db_query']('', '
|
Chris@76
|
206 SELECT name, url
|
Chris@76
|
207 FROM {db_prefix}package_servers
|
Chris@76
|
208 WHERE id_server = {int:current_server}
|
Chris@76
|
209 LIMIT 1',
|
Chris@76
|
210 array(
|
Chris@76
|
211 'current_server' => $server,
|
Chris@76
|
212 )
|
Chris@76
|
213 );
|
Chris@76
|
214 list ($name, $url) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
215 $smcFunc['db_free_result']($request);
|
Chris@76
|
216
|
Chris@76
|
217 // If the server does not exist, dump out.
|
Chris@76
|
218 if (empty($url))
|
Chris@76
|
219 fatal_lang_error('couldnt_connect', false);
|
Chris@76
|
220
|
Chris@76
|
221 // If there is a relative link, append to the stored server url.
|
Chris@76
|
222 if (isset($_GET['relative']))
|
Chris@76
|
223 $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative'];
|
Chris@76
|
224
|
Chris@76
|
225 // Clear any "absolute" URL. Since "server" is present, "absolute" is garbage.
|
Chris@76
|
226 unset($_GET['absolute']);
|
Chris@76
|
227 }
|
Chris@76
|
228 elseif (isset($_GET['absolute']) && $_GET['absolute'] != '')
|
Chris@76
|
229 {
|
Chris@76
|
230 // Initialize the requried variables.
|
Chris@76
|
231 $server = '';
|
Chris@76
|
232 $url = $_GET['absolute'];
|
Chris@76
|
233 $name = '';
|
Chris@76
|
234 $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
|
Chris@76
|
235
|
Chris@76
|
236 // Clear any "relative" URL. Since "server" is not present, "relative" is garbage.
|
Chris@76
|
237 unset($_GET['relative']);
|
Chris@76
|
238
|
Chris@76
|
239 $token = checkConfirm('get_absolute_url');
|
Chris@76
|
240 if ($token !== true)
|
Chris@76
|
241 {
|
Chris@76
|
242 $context['sub_template'] = 'package_confirm';
|
Chris@76
|
243
|
Chris@76
|
244 $context['page_title'] = $txt['package_servers'];
|
Chris@76
|
245 $context['confirm_message'] = sprintf($txt['package_confirm_view_package_content'], htmlspecialchars($_GET['absolute']));
|
Chris@76
|
246 $context['proceed_href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . urlencode($_GET['absolute']) . ';confirm=' . $token;
|
Chris@76
|
247
|
Chris@76
|
248 return;
|
Chris@76
|
249 }
|
Chris@76
|
250 }
|
Chris@76
|
251 // Minimum required parameter did not exist so dump out.
|
Chris@76
|
252 else
|
Chris@76
|
253 fatal_lang_error('couldnt_connect', false);
|
Chris@76
|
254
|
Chris@76
|
255 // Attempt to connect. If unsuccessful... try the URL.
|
Chris@76
|
256 if (!isset($_GET['package']) || file_exists($_GET['package']))
|
Chris@76
|
257 $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
|
Chris@76
|
258
|
Chris@76
|
259 // Check to be sure the packages.xml file actually exists where it is should be... or dump out.
|
Chris@76
|
260 if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package']))
|
Chris@76
|
261 fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
|
Chris@76
|
262
|
Chris@76
|
263 // Might take some time.
|
Chris@76
|
264 @set_time_limit(600);
|
Chris@76
|
265
|
Chris@76
|
266 // Read packages.xml and parse into xmlArray. (the true tells it to trim things ;).)
|
Chris@76
|
267 loadClassFile('Class-Package.php');
|
Chris@76
|
268 $listing = new xmlArray(fetch_web_data($_GET['package']), true);
|
Chris@76
|
269
|
Chris@76
|
270 // Errm.... empty file? Try the URL....
|
Chris@76
|
271 if (!$listing->exists('package-list'))
|
Chris@76
|
272 fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
|
Chris@76
|
273
|
Chris@76
|
274 // List out the packages...
|
Chris@76
|
275 $context['package_list'] = array();
|
Chris@76
|
276
|
Chris@76
|
277 $listing = $listing->path('package-list[0]');
|
Chris@76
|
278
|
Chris@76
|
279 // Use the package list's name if it exists.
|
Chris@76
|
280 if ($listing->exists('list-title'))
|
Chris@76
|
281 $name = $listing->fetch('list-title');
|
Chris@76
|
282
|
Chris@76
|
283 // Pick the correct template.
|
Chris@76
|
284 $context['sub_template'] = 'package_list';
|
Chris@76
|
285
|
Chris@76
|
286 $context['page_title'] = $txt['package_servers'] . ($name != '' ? ' - ' . $name : '');
|
Chris@76
|
287 $context['package_server'] = $server;
|
Chris@76
|
288
|
Chris@76
|
289 // By default we use an unordered list, unless there are no lists with more than one package.
|
Chris@76
|
290 $context['list_type'] = 'ul';
|
Chris@76
|
291
|
Chris@76
|
292 $instmods = loadInstalledPackages();
|
Chris@76
|
293
|
Chris@76
|
294 $installed_mods = array();
|
Chris@76
|
295 // Look through the list of installed mods...
|
Chris@76
|
296 foreach ($instmods as $installed_mod)
|
Chris@76
|
297 $installed_mods[$installed_mod['package_id']] = $installed_mod['version'];
|
Chris@76
|
298
|
Chris@76
|
299 // Get default author and email if they exist.
|
Chris@76
|
300 if ($listing->exists('default-author'))
|
Chris@76
|
301 {
|
Chris@76
|
302 $default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author'));
|
Chris@76
|
303 if ($listing->exists('default-author/@email'))
|
Chris@76
|
304 $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email'));
|
Chris@76
|
305 }
|
Chris@76
|
306
|
Chris@76
|
307 // Get default web site if it exists.
|
Chris@76
|
308 if ($listing->exists('default-website'))
|
Chris@76
|
309 {
|
Chris@76
|
310 $default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website'));
|
Chris@76
|
311 if ($listing->exists('default-website/@title'))
|
Chris@76
|
312 $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title'));
|
Chris@76
|
313 }
|
Chris@76
|
314
|
Chris@76
|
315 $the_version = strtr($forum_version, array('SMF ' => ''));
|
Chris@76
|
316 if (!empty($_SESSION['version_emulate']))
|
Chris@76
|
317 $the_version = $_SESSION['version_emulate'];
|
Chris@76
|
318
|
Chris@76
|
319 $packageNum = 0;
|
Chris@76
|
320 $packageSection = 0;
|
Chris@76
|
321
|
Chris@76
|
322 $sections = $listing->set('section');
|
Chris@76
|
323 foreach ($sections as $i => $section)
|
Chris@76
|
324 {
|
Chris@76
|
325 $context['package_list'][$packageSection] = array(
|
Chris@76
|
326 'title' => '',
|
Chris@76
|
327 'text' => '',
|
Chris@76
|
328 'items' => array(),
|
Chris@76
|
329 );
|
Chris@76
|
330
|
Chris@76
|
331 $packages = $section->set('title|heading|text|remote|rule|modification|language|avatar-pack|theme|smiley-set');
|
Chris@76
|
332 foreach ($packages as $thisPackage)
|
Chris@76
|
333 {
|
Chris@76
|
334 $package = array(
|
Chris@76
|
335 'type' => $thisPackage->name(),
|
Chris@76
|
336 );
|
Chris@76
|
337
|
Chris@76
|
338 if (in_array($package['type'], array('title', 'text')))
|
Chris@76
|
339 $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
|
Chris@76
|
340 // It's a Title, Heading, Rule or Text.
|
Chris@76
|
341 elseif (in_array($package['type'], array('heading', 'rule')))
|
Chris@76
|
342 $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
|
Chris@76
|
343 // It's a Remote link.
|
Chris@76
|
344 elseif ($package['type'] == 'remote')
|
Chris@76
|
345 {
|
Chris@76
|
346 $remote_type = $thisPackage->exists('@type') ? $thisPackage->fetch('@type') : 'relative';
|
Chris@76
|
347
|
Chris@76
|
348 if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://')
|
Chris@76
|
349 {
|
Chris@76
|
350 if (isset($_GET['absolute']))
|
Chris@76
|
351 $current_url = $_GET['absolute'] . '/';
|
Chris@76
|
352 elseif (isset($_GET['relative']))
|
Chris@76
|
353 $current_url = $_GET['relative'] . '/';
|
Chris@76
|
354 else
|
Chris@76
|
355 $current_url = '';
|
Chris@76
|
356
|
Chris@76
|
357 $current_url .= $thisPackage->fetch('@href');
|
Chris@76
|
358 if (isset($_GET['absolute']))
|
Chris@76
|
359 $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
|
Chris@76
|
360 else
|
Chris@76
|
361 $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url;
|
Chris@76
|
362 }
|
Chris@76
|
363 else
|
Chris@76
|
364 {
|
Chris@76
|
365 $current_url = $thisPackage->fetch('@href');
|
Chris@76
|
366 $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
|
Chris@76
|
367 }
|
Chris@76
|
368
|
Chris@76
|
369 $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
|
Chris@76
|
370 $package['link'] = '<a href="' . $package['href'] . '">' . $package['name'] . '</a>';
|
Chris@76
|
371 }
|
Chris@76
|
372 // It's a package...
|
Chris@76
|
373 else
|
Chris@76
|
374 {
|
Chris@76
|
375 if (isset($_GET['absolute']))
|
Chris@76
|
376 $current_url = $_GET['absolute'] . '/';
|
Chris@76
|
377 elseif (isset($_GET['relative']))
|
Chris@76
|
378 $current_url = $_GET['relative'] . '/';
|
Chris@76
|
379 else
|
Chris@76
|
380 $current_url = '';
|
Chris@76
|
381
|
Chris@76
|
382 $server_att = $server != '' ? ';server=' . $server : '';
|
Chris@76
|
383
|
Chris@76
|
384 $package += $thisPackage->to_array();
|
Chris@76
|
385
|
Chris@76
|
386 if (isset($package['website']))
|
Chris@76
|
387 unset($package['website']);
|
Chris@76
|
388 $package['author'] = array();
|
Chris@76
|
389
|
Chris@76
|
390 if ($package['description'] == '')
|
Chris@76
|
391 $package['description'] = $txt['package_no_description'];
|
Chris@76
|
392 else
|
Chris@76
|
393 $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description'])));
|
Chris@76
|
394
|
Chris@76
|
395 $package['is_installed'] = isset($installed_mods[$package['id']]);
|
Chris@76
|
396 $package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']);
|
Chris@76
|
397 $package['is_newer'] = $package['is_installed'] && ($installed_mods[$package['id']] > $package['version']);
|
Chris@76
|
398
|
Chris@76
|
399 // This package is either not installed, or installed but old. Is it supported on this version of SMF?
|
Chris@76
|
400 if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer']))
|
Chris@76
|
401 {
|
Chris@76
|
402 if ($thisPackage->exists('version/@for'))
|
Chris@76
|
403 $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for'));
|
Chris@76
|
404 }
|
Chris@76
|
405 // Okay, it's already installed AND up to date.
|
Chris@76
|
406 else
|
Chris@76
|
407 $package['can_install'] = false;
|
Chris@76
|
408
|
Chris@76
|
409 $already_exists = getPackageInfo(basename($package['filename']));
|
Chris@76
|
410 $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version'];
|
Chris@76
|
411
|
Chris@76
|
412 $package['href'] = $url . '/' . $package['filename'];
|
Chris@76
|
413 $package['name'] = $smcFunc['htmlspecialchars']($package['name']);
|
Chris@76
|
414 $package['link'] = '<a href="' . $package['href'] . '">' . $package['name'] . '</a>';
|
Chris@76
|
415 $package['download']['href'] = $scripturl . '?action=admin;area=packages;get;sa=download' . $server_att . ';package=' . $current_url . $package['filename'] . ($package['download_conflict'] ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id'];
|
Chris@76
|
416 $package['download']['link'] = '<a href="' . $package['download']['href'] . '">' . $package['name'] . '</a>';
|
Chris@76
|
417
|
Chris@76
|
418 if ($thisPackage->exists('author') || isset($default_author))
|
Chris@76
|
419 {
|
Chris@76
|
420 if ($thisPackage->exists('author/@email'))
|
Chris@76
|
421 $package['author']['email'] = $thisPackage->fetch('author/@email');
|
Chris@76
|
422 elseif (isset($default_email))
|
Chris@76
|
423 $package['author']['email'] = $default_email;
|
Chris@76
|
424
|
Chris@76
|
425 if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '')
|
Chris@76
|
426 $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author'));
|
Chris@76
|
427 else
|
Chris@76
|
428 $package['author']['name'] = $default_author;
|
Chris@76
|
429
|
Chris@76
|
430 if (!empty($package['author']['email']))
|
Chris@76
|
431 {
|
Chris@76
|
432 // Only put the "mailto:" if it looks like a valid email address. Some may wish to put a link to an SMF IM Form or other web mail form.
|
Chris@76
|
433 $package['author']['href'] = preg_match('~^[\w\.\-]+@[\w][\w\-\.]+[\w]$~', $package['author']['email']) != 0 ? 'mailto:' . $package['author']['email'] : $package['author']['email'];
|
Chris@76
|
434 $package['author']['link'] = '<a href="' . $package['author']['href'] . '">' . $package['author']['name'] . '</a>';
|
Chris@76
|
435 }
|
Chris@76
|
436 }
|
Chris@76
|
437
|
Chris@76
|
438 if ($thisPackage->exists('website') || isset($default_website))
|
Chris@76
|
439 {
|
Chris@76
|
440 if ($thisPackage->exists('website') && $thisPackage->exists('website/@title'))
|
Chris@76
|
441 $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title'));
|
Chris@76
|
442 elseif (isset($default_title))
|
Chris@76
|
443 $package['author']['website']['name'] = $default_title;
|
Chris@76
|
444 elseif ($thisPackage->exists('website'))
|
Chris@76
|
445 $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
|
Chris@76
|
446 else
|
Chris@76
|
447 $package['author']['website']['name'] = $default_website;
|
Chris@76
|
448
|
Chris@76
|
449 if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '')
|
Chris@76
|
450 $authorhompage = $thisPackage->fetch('website');
|
Chris@76
|
451 else
|
Chris@76
|
452 $authorhompage = $default_website;
|
Chris@76
|
453
|
Chris@76
|
454 if (strpos(strtolower($authorhompage), 'a href') === false)
|
Chris@76
|
455 {
|
Chris@76
|
456 $package['author']['website']['href'] = $authorhompage;
|
Chris@76
|
457 $package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>';
|
Chris@76
|
458 }
|
Chris@76
|
459 else
|
Chris@76
|
460 {
|
Chris@76
|
461 if (preg_match('/a href="(.+?)"/', $authorhompage, $match) == 1)
|
Chris@76
|
462 $package['author']['website']['href'] = $match[1];
|
Chris@76
|
463 else
|
Chris@76
|
464 $package['author']['website']['href'] = '';
|
Chris@76
|
465 $package['author']['website']['link'] = $authorhompage;
|
Chris@76
|
466 }
|
Chris@76
|
467 }
|
Chris@76
|
468 else
|
Chris@76
|
469 {
|
Chris@76
|
470 $package['author']['website']['href'] = '';
|
Chris@76
|
471 $package['author']['website']['link'] = '';
|
Chris@76
|
472 }
|
Chris@76
|
473 }
|
Chris@76
|
474
|
Chris@76
|
475 $package['is_remote'] = $package['type'] == 'remote';
|
Chris@76
|
476 $package['is_title'] = $package['type'] == 'title';
|
Chris@76
|
477 $package['is_heading'] = $package['type'] == 'heading';
|
Chris@76
|
478 $package['is_text'] = $package['type'] == 'text';
|
Chris@76
|
479 $package['is_line'] = $package['type'] == 'rule';
|
Chris@76
|
480
|
Chris@76
|
481 $packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1;
|
Chris@76
|
482 $package['count'] = $packageNum;
|
Chris@76
|
483
|
Chris@76
|
484 if (!in_array($package['type'], array('title', 'text')))
|
Chris@76
|
485 $context['package_list'][$packageSection]['items'][] = $package;
|
Chris@76
|
486
|
Chris@76
|
487 if ($package['count'] > 1)
|
Chris@76
|
488 $context['list_type'] = 'ol';
|
Chris@76
|
489 }
|
Chris@76
|
490
|
Chris@76
|
491 $packageSection++;
|
Chris@76
|
492 }
|
Chris@76
|
493
|
Chris@76
|
494 // Lets make sure we get a nice new spiffy clean $package to work with. Otherwise we get PAIN!
|
Chris@76
|
495 unset($package);
|
Chris@76
|
496
|
Chris@76
|
497 foreach ($context['package_list'] as $ps_id => $packageSection)
|
Chris@76
|
498 {
|
Chris@76
|
499 foreach ($packageSection['items'] as $i => $package)
|
Chris@76
|
500 {
|
Chris@76
|
501 if ($package['count'] == 0 || isset($package['can_install']))
|
Chris@76
|
502 continue;
|
Chris@76
|
503
|
Chris@76
|
504 $context['package_list'][$ps_id]['items'][$i]['can_install'] = false;
|
Chris@76
|
505
|
Chris@76
|
506 $packageInfo = getPackageInfo($url . '/' . $package['filename']);
|
Chris@76
|
507 if (is_array($packageInfo) && $packageInfo['xml']->exists('install'))
|
Chris@76
|
508 {
|
Chris@76
|
509 $installs = $packageInfo['xml']->set('install');
|
Chris@76
|
510 foreach ($installs as $install)
|
Chris@76
|
511 if (!$install->exists('@for') || matchPackageVersion($the_version, $install->fetch('@for')))
|
Chris@76
|
512 {
|
Chris@76
|
513 // Okay, this one is good to go.
|
Chris@76
|
514 $context['package_list'][$ps_id]['items'][$i]['can_install'] = true;
|
Chris@76
|
515 break;
|
Chris@76
|
516 }
|
Chris@76
|
517 }
|
Chris@76
|
518 }
|
Chris@76
|
519 }
|
Chris@76
|
520 }
|
Chris@76
|
521
|
Chris@76
|
522 // Download a package.
|
Chris@76
|
523 function PackageDownload()
|
Chris@76
|
524 {
|
Chris@76
|
525 global $txt, $scripturl, $boarddir, $context, $sourcedir, $smcFunc;
|
Chris@76
|
526
|
Chris@76
|
527 // Use the downloaded sub template.
|
Chris@76
|
528 $context['sub_template'] = 'downloaded';
|
Chris@76
|
529
|
Chris@76
|
530 // Security is good...
|
Chris@76
|
531 checkSession('get');
|
Chris@76
|
532
|
Chris@76
|
533 // To download something, we need a valid server or url.
|
Chris@76
|
534 if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package'])))
|
Chris@76
|
535 fatal_lang_error('package_get_error_is_zero', false);
|
Chris@76
|
536
|
Chris@76
|
537 if (isset($_GET['server']))
|
Chris@76
|
538 {
|
Chris@76
|
539 $server = (int) $_GET['server'];
|
Chris@76
|
540
|
Chris@76
|
541 // Query the server table to find the requested server.
|
Chris@76
|
542 $request = $smcFunc['db_query']('', '
|
Chris@76
|
543 SELECT name, url
|
Chris@76
|
544 FROM {db_prefix}package_servers
|
Chris@76
|
545 WHERE id_server = {int:current_server}
|
Chris@76
|
546 LIMIT 1',
|
Chris@76
|
547 array(
|
Chris@76
|
548 'current_server' => $server,
|
Chris@76
|
549 )
|
Chris@76
|
550 );
|
Chris@76
|
551 list ($name, $url) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
552 $smcFunc['db_free_result']($request);
|
Chris@76
|
553
|
Chris@76
|
554 // If server does not exist then dump out.
|
Chris@76
|
555 if (empty($url))
|
Chris@76
|
556 fatal_lang_error('couldnt_connect', false);
|
Chris@76
|
557
|
Chris@76
|
558 $url = $url . '/';
|
Chris@76
|
559 }
|
Chris@76
|
560 else
|
Chris@76
|
561 {
|
Chris@76
|
562 // Initialize the requried variables.
|
Chris@76
|
563 $server = '';
|
Chris@76
|
564 $url = '';
|
Chris@76
|
565 }
|
Chris@76
|
566
|
Chris@76
|
567 if (isset($_REQUEST['byurl']) && !empty($_POST['filename']))
|
Chris@76
|
568 $package_name = basename($_REQUEST['filename']);
|
Chris@76
|
569 else
|
Chris@76
|
570 $package_name = basename($_REQUEST['package']);
|
Chris@76
|
571
|
Chris@76
|
572 if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($boarddir . '/Packages/' . $package_name)))
|
Chris@76
|
573 {
|
Chris@76
|
574 // Find the extension, change abc.tar.gz to abc_1.tar.gz...
|
Chris@76
|
575 if (strrpos(substr($package_name, 0, -3), '.') !== false)
|
Chris@76
|
576 {
|
Chris@76
|
577 $ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.'));
|
Chris@76
|
578 $package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_';
|
Chris@76
|
579 }
|
Chris@76
|
580 else
|
Chris@76
|
581 $ext = '';
|
Chris@76
|
582
|
Chris@76
|
583 // Find the first available.
|
Chris@76
|
584 $i = 1;
|
Chris@76
|
585 while (file_exists($boarddir . '/Packages/' . $package_name . $i . $ext))
|
Chris@76
|
586 $i++;
|
Chris@76
|
587
|
Chris@76
|
588 $package_name = $package_name . $i . $ext;
|
Chris@76
|
589 }
|
Chris@76
|
590
|
Chris@76
|
591 // First make sure it's a package.
|
Chris@76
|
592 $packageInfo = getPackageInfo($url . $_REQUEST['package']);
|
Chris@76
|
593 if (!is_array($packageInfo))
|
Chris@76
|
594 fatal_lang_error($packageInfo);
|
Chris@76
|
595
|
Chris@76
|
596 // Use FTP if necessary.
|
Chris@76
|
597 create_chmod_control(array($boarddir . '/Packages/' . $package_name), array('destination_url' => $scripturl . '?action=admin;area=packages;get;sa=download' . (isset($_GET['server']) ? ';server=' . $_GET['server'] : '') . (isset($_REQUEST['auto']) ? ';auto' : '') . ';package=' . $_REQUEST['package'] . (isset($_REQUEST['conflict']) ? ';conflict' : '') . ';' . $context['session_var'] . '=' . $context['session_id'], 'crash_on_error' => true));
|
Chris@76
|
598 package_put_contents($boarddir . '/Packages/' . $package_name, fetch_web_data($url . $_REQUEST['package']));
|
Chris@76
|
599
|
Chris@76
|
600 // Done! Did we get this package automatically?
|
Chris@76
|
601 if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto']))
|
Chris@76
|
602 redirectexit('action=admin;area=packages;sa=install;package=' . $package_name);
|
Chris@76
|
603
|
Chris@76
|
604 // You just downloaded a mod from SERVER_NAME_GOES_HERE.
|
Chris@76
|
605 $context['package_server'] = $server;
|
Chris@76
|
606
|
Chris@76
|
607 $context['package'] = getPackageInfo($package_name);
|
Chris@76
|
608
|
Chris@76
|
609 if (!is_array($context['package']))
|
Chris@76
|
610 fatal_lang_error('package_cant_download', false);
|
Chris@76
|
611
|
Chris@76
|
612 if ($context['package']['type'] == 'modification')
|
Chris@76
|
613 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
|
Chris@76
|
614 elseif ($context['package']['type'] == 'avatar')
|
Chris@76
|
615 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
|
Chris@76
|
616 elseif ($context['package']['type'] == 'language')
|
Chris@76
|
617 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
|
Chris@76
|
618 else
|
Chris@76
|
619 $context['package']['install']['link'] = '';
|
Chris@76
|
620
|
Chris@76
|
621 $context['package']['list_files']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $context['package']['filename'] . '">[ ' . $txt['list_files'] . ' ]</a>';
|
Chris@76
|
622
|
Chris@76
|
623 // Free a little bit of memory...
|
Chris@76
|
624 unset($context['package']['xml']);
|
Chris@76
|
625
|
Chris@76
|
626 $context['page_title'] = $txt['download_success'];
|
Chris@76
|
627 }
|
Chris@76
|
628
|
Chris@76
|
629 // Upload a new package to the directory.
|
Chris@76
|
630 function PackageUpload()
|
Chris@76
|
631 {
|
Chris@76
|
632 global $txt, $scripturl, $boarddir, $context, $sourcedir;
|
Chris@76
|
633
|
Chris@76
|
634 // Setup the correct template, even though I'll admit we ain't downloading ;)
|
Chris@76
|
635 $context['sub_template'] = 'downloaded';
|
Chris@76
|
636
|
Chris@76
|
637 // !!! TODO: Use FTP if the Packages directory is not writable.
|
Chris@76
|
638
|
Chris@76
|
639 // Check the file was even sent!
|
Chris@76
|
640 if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '')
|
Chris@76
|
641 fatal_lang_error('package_upload_error_nofile');
|
Chris@76
|
642 elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name'])))
|
Chris@76
|
643 fatal_lang_error('package_upload_error_failure');
|
Chris@76
|
644
|
Chris@76
|
645 // Make sure it has a sane filename.
|
Chris@76
|
646 $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']);
|
Chris@76
|
647
|
Chris@76
|
648 if (strtolower(substr($_FILES['package']['name'], -4)) != '.zip' && strtolower(substr($_FILES['package']['name'], -4)) != '.tgz' && strtolower(substr($_FILES['package']['name'], -7)) != '.tar.gz')
|
Chris@76
|
649 fatal_lang_error('package_upload_error_supports', false, array('zip, tgz, tar.gz'));
|
Chris@76
|
650
|
Chris@76
|
651 // We only need the filename...
|
Chris@76
|
652 $packageName = basename($_FILES['package']['name']);
|
Chris@76
|
653
|
Chris@76
|
654 // Setup the destination and throw an error if the file is already there!
|
Chris@76
|
655 $destination = $boarddir . '/Packages/' . $packageName;
|
Chris@76
|
656 // !!! Maybe just roll it like we do for downloads?
|
Chris@76
|
657 if (file_exists($destination))
|
Chris@76
|
658 fatal_lang_error('package_upload_error_exists');
|
Chris@76
|
659
|
Chris@76
|
660 // Now move the file.
|
Chris@76
|
661 move_uploaded_file($_FILES['package']['tmp_name'], $destination);
|
Chris@76
|
662 @chmod($destination, 0777);
|
Chris@76
|
663
|
Chris@76
|
664 // If we got this far that should mean it's available.
|
Chris@76
|
665 $context['package'] = getPackageInfo($packageName);
|
Chris@76
|
666 $context['package_server'] = '';
|
Chris@76
|
667
|
Chris@76
|
668 // Not really a package, you lazy bum!
|
Chris@76
|
669 if (!is_array($context['package']))
|
Chris@76
|
670 {
|
Chris@76
|
671 @unlink($destination);
|
Chris@76
|
672 loadLanguage('Errors');
|
Chris@76
|
673 fatal_lang_error('package_upload_error_broken', false, $txt[$context['package']]);
|
Chris@76
|
674 }
|
Chris@76
|
675 // Is it already uploaded, maybe?
|
Chris@76
|
676 elseif ($dir = @opendir($boarddir . '/Packages'))
|
Chris@76
|
677 {
|
Chris@76
|
678 while ($package = readdir($dir))
|
Chris@76
|
679 {
|
Chris@76
|
680 if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($boarddir . '/Packages/' . $package) && file_exists($boarddir . '/Packages/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
|
Chris@76
|
681 continue;
|
Chris@76
|
682
|
Chris@76
|
683 $packageInfo = getPackageInfo($package);
|
Chris@76
|
684 if (!is_array($packageInfo))
|
Chris@76
|
685 continue;
|
Chris@76
|
686
|
Chris@76
|
687 if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version'])
|
Chris@76
|
688 {
|
Chris@76
|
689 @unlink($destination);
|
Chris@76
|
690 loadLanguage('Errors');
|
Chris@76
|
691 fatal_lang_error('package_upload_error_exists');
|
Chris@76
|
692 }
|
Chris@76
|
693 }
|
Chris@76
|
694 closedir($dir);
|
Chris@76
|
695 }
|
Chris@76
|
696
|
Chris@76
|
697 if ($context['package']['type'] == 'modification')
|
Chris@76
|
698 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
|
Chris@76
|
699 elseif ($context['package']['type'] == 'avatar')
|
Chris@76
|
700 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
|
Chris@76
|
701 elseif ($context['package']['type'] == 'language')
|
Chris@76
|
702 $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
|
Chris@76
|
703 else
|
Chris@76
|
704 $context['package']['install']['link'] = '';
|
Chris@76
|
705
|
Chris@76
|
706 $context['package']['list_files']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $context['package']['filename'] . '">[ ' . $txt['list_files'] . ' ]</a>';
|
Chris@76
|
707
|
Chris@76
|
708 unset($context['package']['xml']);
|
Chris@76
|
709
|
Chris@76
|
710 $context['page_title'] = $txt['package_uploaded_success'];
|
Chris@76
|
711 }
|
Chris@76
|
712
|
Chris@76
|
713 // Add a package server to the list.
|
Chris@76
|
714 function PackageServerAdd()
|
Chris@76
|
715 {
|
Chris@76
|
716 global $smcFunc;
|
Chris@76
|
717
|
Chris@76
|
718 // Validate the user.
|
Chris@76
|
719 checkSession();
|
Chris@76
|
720
|
Chris@76
|
721 // If they put a slash on the end, get rid of it.
|
Chris@76
|
722 if (substr($_POST['serverurl'], -1) == '/')
|
Chris@76
|
723 $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1);
|
Chris@76
|
724
|
Chris@76
|
725 // Are they both nice and clean?
|
Chris@76
|
726 $servername = trim($smcFunc['htmlspecialchars']($_POST['servername']));
|
Chris@76
|
727 $serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl']));
|
Chris@76
|
728
|
Chris@76
|
729 // Make sure the URL has the correct prefix.
|
Chris@76
|
730 if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0)
|
Chris@76
|
731 $serverurl = 'http://' . $serverurl;
|
Chris@76
|
732
|
Chris@76
|
733 $smcFunc['db_insert']('',
|
Chris@76
|
734 '{db_prefix}package_servers',
|
Chris@76
|
735 array(
|
Chris@76
|
736 'name' => 'string-255', 'url' => 'string-255',
|
Chris@76
|
737 ),
|
Chris@76
|
738 array(
|
Chris@76
|
739 $servername, $serverurl,
|
Chris@76
|
740 ),
|
Chris@76
|
741 array('id_server')
|
Chris@76
|
742 );
|
Chris@76
|
743
|
Chris@76
|
744 redirectexit('action=admin;area=packages;get');
|
Chris@76
|
745 }
|
Chris@76
|
746
|
Chris@76
|
747 // Remove a server from the list.
|
Chris@76
|
748 function PackageServerRemove()
|
Chris@76
|
749 {
|
Chris@76
|
750 global $smcFunc;
|
Chris@76
|
751
|
Chris@76
|
752 checkSession('get');
|
Chris@76
|
753
|
Chris@76
|
754 $smcFunc['db_query']('', '
|
Chris@76
|
755 DELETE FROM {db_prefix}package_servers
|
Chris@76
|
756 WHERE id_server = {int:current_server}',
|
Chris@76
|
757 array(
|
Chris@76
|
758 'current_server' => (int) $_GET['server'],
|
Chris@76
|
759 )
|
Chris@76
|
760 );
|
Chris@76
|
761
|
Chris@76
|
762 redirectexit('action=admin;area=packages;get');
|
Chris@76
|
763 }
|
Chris@76
|
764
|
Chris@76
|
765 ?> |