PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/includes/acp/acp_attachments.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 1459 lines | 1269 code | 142 blank | 48 comment | 105 complexity | 22f5f8cce42b4b97235e920e16af058b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @package acp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * @package acp
  19. */
  20. class acp_attachments
  21. {
  22. var $u_action;
  23. var $new_config;
  24. function main($id, $mode)
  25. {
  26. global $db, $user, $auth, $template, $cache;
  27. global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
  28. $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
  29. $error = $notify = array();
  30. $submit = (isset($_POST['submit'])) ? true : false;
  31. $action = request_var('action', '');
  32. $form_key = 'acp_attach';
  33. add_form_key($form_key);
  34. if ($submit && !check_form_key($form_key))
  35. {
  36. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  37. }
  38. switch ($mode)
  39. {
  40. case 'attach':
  41. $l_title = 'ACP_ATTACHMENT_SETTINGS';
  42. break;
  43. case 'extensions':
  44. $l_title = 'ACP_MANAGE_EXTENSIONS';
  45. break;
  46. case 'ext_groups':
  47. $l_title = 'ACP_EXTENSION_GROUPS';
  48. break;
  49. case 'orphan':
  50. $l_title = 'ACP_ORPHAN_ATTACHMENTS';
  51. break;
  52. default:
  53. trigger_error('NO_MODE', E_USER_ERROR);
  54. break;
  55. }
  56. $this->tpl_name = 'acp_attachments';
  57. $this->page_title = $l_title;
  58. $template->assign_vars(array(
  59. 'L_TITLE' => $user->lang[$l_title],
  60. 'L_TITLE_EXPLAIN' => $user->lang[$l_title . '_EXPLAIN'],
  61. 'U_ACTION' => $this->u_action)
  62. );
  63. switch ($mode)
  64. {
  65. case 'attach':
  66. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  67. $sql = 'SELECT group_name, cat_id
  68. FROM ' . EXTENSION_GROUPS_TABLE . '
  69. WHERE cat_id > 0
  70. ORDER BY cat_id';
  71. $result = $db->sql_query($sql);
  72. $s_assigned_groups = array();
  73. while ($row = $db->sql_fetchrow($result))
  74. {
  75. $row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];
  76. $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
  77. }
  78. $db->sql_freeresult($result);
  79. $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
  80. $display_vars = array(
  81. 'title' => 'ACP_ATTACHMENT_SETTINGS',
  82. 'vars' => array(
  83. 'legend1' => 'ACP_ATTACHMENT_SETTINGS',
  84. 'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
  85. 'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
  86. 'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
  87. 'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
  88. 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  89. 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
  90. 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),
  91. 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true),
  92. 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
  93. 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
  94. 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
  95. 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
  96. 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
  97. 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  98. 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
  99. 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  100. 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  101. 'legend2' => $l_legend_cat_images,
  102. 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  103. 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  104. 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
  105. 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
  106. 'img_imagick' => array('lang' => 'IMAGICK_PATH', 'validate' => 'string', 'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
  107. 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
  108. 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
  109. )
  110. );
  111. $this->new_config = $config;
  112. $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : $this->new_config;
  113. $error = array();
  114. // We validate the complete config if whished
  115. validate_config_vars($display_vars['vars'], $cfg_array, $error);
  116. // Do not write values if there is an error
  117. if (sizeof($error))
  118. {
  119. $submit = false;
  120. }
  121. // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
  122. foreach ($display_vars['vars'] as $config_name => $null)
  123. {
  124. if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
  125. {
  126. continue;
  127. }
  128. $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
  129. if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
  130. {
  131. $size_var = request_var($config_name, '');
  132. $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
  133. }
  134. if ($submit)
  135. {
  136. set_config($config_name, $config_value);
  137. }
  138. }
  139. $this->perform_site_list();
  140. if ($submit)
  141. {
  142. add_log('admin', 'LOG_CONFIG_ATTACH');
  143. // Check Settings
  144. $this->test_upload($error, $this->new_config['upload_path'], false);
  145. if (!sizeof($error))
  146. {
  147. trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
  148. }
  149. }
  150. $template->assign_var('S_ATTACHMENT_SETTINGS', true);
  151. if ($action == 'imgmagick')
  152. {
  153. $this->new_config['img_imagick'] = $this->search_imagemagick();
  154. }
  155. // We strip eventually manual added convert program, we only want the patch
  156. if ($this->new_config['img_imagick'])
  157. {
  158. // Change path separator
  159. $this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
  160. $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
  161. // Check for trailing slash
  162. if (substr($this->new_config['img_imagick'], -1) !== '/')
  163. {
  164. $this->new_config['img_imagick'] .= '/';
  165. }
  166. }
  167. $supported_types = get_supported_image_types();
  168. // Check Thumbnail Support
  169. if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
  170. {
  171. $this->new_config['img_create_thumbnail'] = 0;
  172. }
  173. $template->assign_vars(array(
  174. 'U_SEARCH_IMAGICK' => $this->u_action . '&amp;action=imgmagick',
  175. 'S_THUMBNAIL_SUPPORT' => (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true)
  176. );
  177. // Secure Download Options - Same procedure as with banning
  178. $allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
  179. $sql = 'SELECT *
  180. FROM ' . SITELIST_TABLE;
  181. $result = $db->sql_query($sql);
  182. $defined_ips = '';
  183. $ips = array();
  184. while ($row = $db->sql_fetchrow($result))
  185. {
  186. $value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
  187. if ($value)
  188. {
  189. $defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
  190. $ips[$row['site_id']] = $value;
  191. }
  192. }
  193. $db->sql_freeresult($result);
  194. $template->assign_vars(array(
  195. 'S_SECURE_DOWNLOADS' => $this->new_config['secure_downloads'],
  196. 'S_DEFINED_IPS' => ($defined_ips != '') ? true : false,
  197. 'S_WARNING' => (sizeof($error)) ? true : false,
  198. 'WARNING_MSG' => implode('<br />', $error),
  199. 'DEFINED_IPS' => $defined_ips,
  200. 'L_SECURE_TITLE' => $user->lang['DEFINE_' . $allow_deny . '_IPS'],
  201. 'L_IP_EXCLUDE' => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
  202. 'L_REMOVE_IPS' => $user->lang['REMOVE_' . $allow_deny . '_IPS'])
  203. );
  204. // Output relevant options
  205. foreach ($display_vars['vars'] as $config_key => $vars)
  206. {
  207. if (!is_array($vars) && strpos($config_key, 'legend') === false)
  208. {
  209. continue;
  210. }
  211. if (strpos($config_key, 'legend') !== false)
  212. {
  213. $template->assign_block_vars('options', array(
  214. 'S_LEGEND' => true,
  215. 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
  216. );
  217. continue;
  218. }
  219. $type = explode(':', $vars['type']);
  220. $l_explain = '';
  221. if ($vars['explain'] && isset($vars['lang_explain']))
  222. {
  223. $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
  224. }
  225. else if ($vars['explain'])
  226. {
  227. $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
  228. }
  229. $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
  230. if (empty($content))
  231. {
  232. continue;
  233. }
  234. $template->assign_block_vars('options', array(
  235. 'KEY' => $config_key,
  236. 'TITLE' => $user->lang[$vars['lang']],
  237. 'S_EXPLAIN' => $vars['explain'],
  238. 'TITLE_EXPLAIN' => $l_explain,
  239. 'CONTENT' => $content,
  240. )
  241. );
  242. unset($display_vars['vars'][$config_key]);
  243. }
  244. break;
  245. case 'extensions':
  246. if ($submit || isset($_POST['add_extension_check']))
  247. {
  248. if ($submit)
  249. {
  250. // Change Extensions ?
  251. $extension_change_list = request_var('extension_change_list', array(0));
  252. $group_select_list = request_var('group_select', array(0));
  253. // Generate correct Change List
  254. $extensions = array();
  255. for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++)
  256. {
  257. $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
  258. }
  259. $sql = 'SELECT *
  260. FROM ' . EXTENSIONS_TABLE . '
  261. ORDER BY extension_id';
  262. $result = $db->sql_query($sql);
  263. while ($row = $db->sql_fetchrow($result))
  264. {
  265. if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
  266. {
  267. $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
  268. SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
  269. WHERE extension_id = ' . $row['extension_id'];
  270. $db->sql_query($sql);
  271. add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
  272. }
  273. }
  274. $db->sql_freeresult($result);
  275. // Delete Extension?
  276. $extension_id_list = request_var('extension_id_list', array(0));
  277. if (sizeof($extension_id_list))
  278. {
  279. $sql = 'SELECT extension
  280. FROM ' . EXTENSIONS_TABLE . '
  281. WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
  282. $result = $db->sql_query($sql);
  283. $extension_list = '';
  284. while ($row = $db->sql_fetchrow($result))
  285. {
  286. $extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
  287. }
  288. $db->sql_freeresult($result);
  289. $sql = 'DELETE
  290. FROM ' . EXTENSIONS_TABLE . '
  291. WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
  292. $db->sql_query($sql);
  293. add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
  294. }
  295. }
  296. // Add Extension?
  297. $add_extension = strtolower(request_var('add_extension', ''));
  298. $add_extension_group = request_var('add_group_select', 0);
  299. $add = (isset($_POST['add_extension_check'])) ? true : false;
  300. if ($add_extension && $add)
  301. {
  302. if (!sizeof($error))
  303. {
  304. $sql = 'SELECT extension_id
  305. FROM ' . EXTENSIONS_TABLE . "
  306. WHERE extension = '" . $db->sql_escape($add_extension) . "'";
  307. $result = $db->sql_query($sql);
  308. if ($row = $db->sql_fetchrow($result))
  309. {
  310. $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
  311. }
  312. $db->sql_freeresult($result);
  313. if (!sizeof($error))
  314. {
  315. $sql_ary = array(
  316. 'group_id' => $add_extension_group,
  317. 'extension' => $add_extension
  318. );
  319. $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
  320. add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
  321. }
  322. }
  323. }
  324. if (!sizeof($error))
  325. {
  326. $notify[] = $user->lang['EXTENSIONS_UPDATED'];
  327. }
  328. $cache->destroy('_extensions');
  329. }
  330. $template->assign_vars(array(
  331. 'S_EXTENSIONS' => true,
  332. 'ADD_EXTENSION' => (isset($add_extension)) ? $add_extension : '',
  333. 'GROUP_SELECT_OPTIONS' => (isset($_POST['add_extension_check'])) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group'))
  334. );
  335. $sql = 'SELECT *
  336. FROM ' . EXTENSIONS_TABLE . '
  337. ORDER BY group_id, extension';
  338. $result = $db->sql_query($sql);
  339. if ($row = $db->sql_fetchrow($result))
  340. {
  341. $old_group_id = $row['group_id'];
  342. do
  343. {
  344. $s_spacer = false;
  345. $current_group_id = $row['group_id'];
  346. if ($old_group_id != $current_group_id)
  347. {
  348. $s_spacer = true;
  349. $old_group_id = $current_group_id;
  350. }
  351. $template->assign_block_vars('extensions', array(
  352. 'S_SPACER' => $s_spacer,
  353. 'EXTENSION_ID' => $row['extension_id'],
  354. 'EXTENSION' => $row['extension'],
  355. 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id']))
  356. );
  357. }
  358. while ($row = $db->sql_fetchrow($result));
  359. }
  360. $db->sql_freeresult($result);
  361. break;
  362. case 'ext_groups':
  363. $template->assign_var('S_EXTENSION_GROUPS', true);
  364. if ($submit)
  365. {
  366. $action = request_var('action', '');
  367. $group_id = request_var('g', 0);
  368. if ($action != 'add' && $action != 'edit')
  369. {
  370. trigger_error('NO_MODE', E_USER_ERROR);
  371. }
  372. if (!$group_id && $action == 'edit')
  373. {
  374. trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
  375. }
  376. if ($group_id)
  377. {
  378. $sql = 'SELECT *
  379. FROM ' . EXTENSION_GROUPS_TABLE . "
  380. WHERE group_id = $group_id";
  381. $result = $db->sql_query($sql);
  382. $ext_row = $db->sql_fetchrow($result);
  383. $db->sql_freeresult($result);
  384. if (!$ext_row)
  385. {
  386. trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
  387. }
  388. }
  389. else
  390. {
  391. $ext_row = array();
  392. }
  393. $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
  394. $new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
  395. if (!$group_name)
  396. {
  397. $error[] = $user->lang['NO_EXT_GROUP_NAME'];
  398. }
  399. // Check New Group Name
  400. if ($new_group_name)
  401. {
  402. $sql = 'SELECT group_id
  403. FROM ' . EXTENSION_GROUPS_TABLE . "
  404. WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
  405. if ($group_id)
  406. {
  407. $sql .= ' AND group_id <> ' . $group_id;
  408. }
  409. $result = $db->sql_query($sql);
  410. if ($db->sql_fetchrow($result))
  411. {
  412. $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
  413. }
  414. $db->sql_freeresult($result);
  415. }
  416. if (!sizeof($error))
  417. {
  418. // Ok, build the update/insert array
  419. $upload_icon = request_var('upload_icon', 'no_image');
  420. $size_select = request_var('size_select', 'b');
  421. $forum_select = request_var('forum_select', false);
  422. $allowed_forums = request_var('allowed_forums', array(0));
  423. $allow_in_pm = (isset($_POST['allow_in_pm'])) ? true : false;
  424. $max_filesize = request_var('max_filesize', 0);
  425. $max_filesize = ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
  426. $allow_group = (isset($_POST['allow_group'])) ? true : false;
  427. if ($max_filesize == $config['max_filesize'])
  428. {
  429. $max_filesize = 0;
  430. }
  431. if (!sizeof($allowed_forums))
  432. {
  433. $forum_select = false;
  434. }
  435. $group_ary = array(
  436. 'group_name' => $group_name,
  437. 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE),
  438. 'allow_group' => ($allow_group) ? 1 : 0,
  439. 'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
  440. 'max_filesize' => $max_filesize,
  441. 'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
  442. 'allow_in_pm' => ($allow_in_pm) ? 1 : 0,
  443. );
  444. if ($action == 'add')
  445. {
  446. $group_ary['download_mode'] = INLINE_LINK;
  447. }
  448. $sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
  449. $sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
  450. $sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
  451. $db->sql_query($sql);
  452. if ($action == 'add')
  453. {
  454. $group_id = $db->sql_nextid();
  455. }
  456. $group_name = (isset($user->lang['EXT_GROUP_' . $group_name])) ? $user->lang['EXT_GROUP_' . $group_name] : $group_name;
  457. add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
  458. }
  459. $extension_list = request_var('extensions', array(0));
  460. if ($action == 'edit' && sizeof($extension_list))
  461. {
  462. $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
  463. SET group_id = 0
  464. WHERE group_id = $group_id";
  465. $db->sql_query($sql);
  466. }
  467. if (sizeof($extension_list))
  468. {
  469. $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
  470. SET group_id = $group_id
  471. WHERE " . $db->sql_in_set('extension_id', $extension_list);
  472. $db->sql_query($sql);
  473. }
  474. $cache->destroy('_extensions');
  475. if (!sizeof($error))
  476. {
  477. $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
  478. }
  479. }
  480. $cat_lang = array(
  481. ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
  482. ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
  483. ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
  484. ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
  485. ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
  486. ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
  487. );
  488. $group_id = request_var('g', 0);
  489. $action = (isset($_POST['add'])) ? 'add' : $action;
  490. switch ($action)
  491. {
  492. case 'delete':
  493. if (confirm_box(true))
  494. {
  495. $sql = 'SELECT group_name
  496. FROM ' . EXTENSION_GROUPS_TABLE . "
  497. WHERE group_id = $group_id";
  498. $result = $db->sql_query($sql);
  499. $group_name = (string) $db->sql_fetchfield('group_name');
  500. $db->sql_freeresult($result);
  501. $sql = 'DELETE
  502. FROM ' . EXTENSION_GROUPS_TABLE . "
  503. WHERE group_id = $group_id";
  504. $db->sql_query($sql);
  505. // Set corresponding Extensions to a pending Group
  506. $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
  507. SET group_id = 0
  508. WHERE group_id = $group_id";
  509. $db->sql_query($sql);
  510. add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
  511. $cache->destroy('_extensions');
  512. trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
  513. }
  514. else
  515. {
  516. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  517. 'i' => $id,
  518. 'mode' => $mode,
  519. 'group_id' => $group_id,
  520. 'action' => 'delete',
  521. )));
  522. }
  523. break;
  524. case 'edit':
  525. if (!$group_id)
  526. {
  527. trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
  528. }
  529. $sql = 'SELECT *
  530. FROM ' . EXTENSION_GROUPS_TABLE . "
  531. WHERE group_id = $group_id";
  532. $result = $db->sql_query($sql);
  533. $ext_group_row = $db->sql_fetchrow($result);
  534. $db->sql_freeresult($result);
  535. $forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
  536. // no break;
  537. case 'add':
  538. if ($action == 'add')
  539. {
  540. $ext_group_row = array(
  541. 'group_name' => utf8_normalize_nfc(request_var('group_name', '', true)),
  542. 'cat_id' => 0,
  543. 'allow_group' => 1,
  544. 'allow_in_pm' => 1,
  545. 'upload_icon' => '',
  546. 'max_filesize' => 0,
  547. );
  548. $forum_ids = array();
  549. }
  550. $extensions = array();
  551. $sql = 'SELECT *
  552. FROM ' . EXTENSIONS_TABLE . "
  553. WHERE group_id = $group_id
  554. OR group_id = 0
  555. ORDER BY extension";
  556. $result = $db->sql_query($sql);
  557. $extensions = $db->sql_fetchrowset($result);
  558. $db->sql_freeresult($result);
  559. if ($ext_group_row['max_filesize'] == 0)
  560. {
  561. $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
  562. }
  563. $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
  564. $size_format = $max_filesize['si_identifier'];
  565. $ext_group_row['max_filesize'] = $max_filesize['value'];
  566. $img_path = $config['upload_icons_path'];
  567. $filename_list = '';
  568. $no_image_select = false;
  569. $imglist = filelist($phpbb_root_path . $img_path);
  570. if (!empty($imglist['']))
  571. {
  572. $imglist = array_values($imglist);
  573. $imglist = $imglist[0];
  574. foreach ($imglist as $key => $img)
  575. {
  576. if (!$ext_group_row['upload_icon'])
  577. {
  578. $no_image_select = true;
  579. $selected = '';
  580. }
  581. else
  582. {
  583. $selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
  584. }
  585. if (strlen($img) > 255)
  586. {
  587. continue;
  588. }
  589. $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
  590. }
  591. }
  592. $i = 0;
  593. $assigned_extensions = '';
  594. foreach ($extensions as $num => $row)
  595. {
  596. if ($row['group_id'] == $group_id && $group_id)
  597. {
  598. $assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
  599. $i++;
  600. }
  601. }
  602. $s_extension_options = '';
  603. foreach ($extensions as $row)
  604. {
  605. $s_extension_options .= '<option' . ((!$row['group_id']) ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . (($row['group_id'] == $group_id && $group_id) ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
  606. }
  607. $template->assign_vars(array(
  608. 'PHPBB_ROOT_PATH' => $phpbb_root_path,
  609. 'IMG_PATH' => $img_path,
  610. 'ACTION' => $action,
  611. 'GROUP_ID' => $group_id,
  612. 'GROUP_NAME' => $ext_group_row['group_name'],
  613. 'ALLOW_GROUP' => $ext_group_row['allow_group'],
  614. 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'],
  615. 'UPLOAD_ICON_SRC' => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
  616. 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'],
  617. 'ASSIGNED_EXTENSIONS' => $assigned_extensions,
  618. 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'),
  619. 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format),
  620. 'S_EXTENSION_OPTIONS' => $s_extension_options,
  621. 'S_FILENAME_LIST' => $filename_list,
  622. 'S_EDIT_GROUP' => true,
  623. 'S_NO_IMAGE' => $no_image_select,
  624. 'S_FORUM_IDS' => (sizeof($forum_ids)) ? true : false,
  625. 'U_EXTENSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
  626. 'U_BACK' => $this->u_action,
  627. 'L_LEGEND' => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
  628. );
  629. $s_forum_id_options = '';
  630. /** @todo use in-built function **/
  631. $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
  632. FROM ' . FORUMS_TABLE . '
  633. ORDER BY left_id ASC';
  634. $result = $db->sql_query($sql, 600);
  635. $right = $cat_right = $padding_inc = 0;
  636. $padding = $forum_list = $holding = '';
  637. $padding_store = array('0' => '');
  638. while ($row = $db->sql_fetchrow($result))
  639. {
  640. if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  641. {
  642. // Non-postable forum with no subforums, don't display
  643. continue;
  644. }
  645. if (!$auth->acl_get('f_list', $row['forum_id']))
  646. {
  647. // if the user does not have permissions to list this forum skip
  648. continue;
  649. }
  650. if ($row['left_id'] < $right)
  651. {
  652. $padding .= '&nbsp; &nbsp;';
  653. $padding_store[$row['parent_id']] = $padding;
  654. }
  655. else if ($row['left_id'] > $right + 1)
  656. {
  657. $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
  658. }
  659. $right = $row['right_id'];
  660. $selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
  661. if ($row['left_id'] > $cat_right)
  662. {
  663. // make sure we don't forget anything
  664. $s_forum_id_options .= $holding;
  665. $holding = '';
  666. }
  667. if ($row['right_id'] - $row['left_id'] > 1)
  668. {
  669. $cat_right = max($cat_right, $row['right_id']);
  670. $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
  671. }
  672. else
  673. {
  674. $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
  675. $holding = '';
  676. }
  677. }
  678. if ($holding)
  679. {
  680. $s_forum_id_options .= $holding;
  681. }
  682. $db->sql_freeresult($result);
  683. unset($padding_store);
  684. $template->assign_vars(array(
  685. 'S_FORUM_ID_OPTIONS' => $s_forum_id_options)
  686. );
  687. break;
  688. }
  689. $sql = 'SELECT *
  690. FROM ' . EXTENSION_GROUPS_TABLE . '
  691. ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
  692. $result = $db->sql_query($sql);
  693. $old_allow_group = $old_allow_pm = 1;
  694. while ($row = $db->sql_fetchrow($result))
  695. {
  696. $s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
  697. $template->assign_block_vars('groups', array(
  698. 'S_ADD_SPACER' => $s_add_spacer,
  699. 'S_ALLOWED_IN_PM' => ($row['allow_in_pm']) ? true : false,
  700. 'S_GROUP_ALLOWED' => ($row['allow_group']) ? true : false,
  701. 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
  702. 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
  703. 'GROUP_NAME' => (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'],
  704. 'CATEGORY' => $cat_lang[$row['cat_id']],
  705. )
  706. );
  707. $old_allow_group = $row['allow_group'];
  708. $old_allow_pm = $row['allow_in_pm'];
  709. }
  710. $db->sql_freeresult($result);
  711. break;
  712. case 'orphan':
  713. if ($submit)
  714. {
  715. $delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
  716. $add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
  717. $post_ids = request_var('post_id', array('' => 0));
  718. if (sizeof($delete_files))
  719. {
  720. $sql = 'SELECT *
  721. FROM ' . ATTACHMENTS_TABLE . '
  722. WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
  723. AND is_orphan = 1';
  724. $result = $db->sql_query($sql);
  725. $delete_files = array();
  726. while ($row = $db->sql_fetchrow($result))
  727. {
  728. phpbb_unlink($row['physical_filename'], 'file');
  729. if ($row['thumbnail'])
  730. {
  731. phpbb_unlink($row['physical_filename'], 'thumbnail');
  732. }
  733. $delete_files[$row['attach_id']] = $row['real_filename'];
  734. }
  735. $db->sql_freeresult($result);
  736. }
  737. if (sizeof($delete_files))
  738. {
  739. $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
  740. WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
  741. $db->sql_query($sql);
  742. add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
  743. $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
  744. }
  745. $upload_list = array();
  746. foreach ($add_files as $attach_id)
  747. {
  748. if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
  749. {
  750. $upload_list[$attach_id] = $post_ids[$attach_id];
  751. }
  752. }
  753. unset($add_files);
  754. if (sizeof($upload_list))
  755. {
  756. $template->assign_var('S_UPLOADING_FILES', true);
  757. $sql = 'SELECT forum_id, forum_name
  758. FROM ' . FORUMS_TABLE;
  759. $result = $db->sql_query($sql);
  760. $forum_names = array();
  761. while ($row = $db->sql_fetchrow($result))
  762. {
  763. $forum_names[$row['forum_id']] = $row['forum_name'];
  764. }
  765. $db->sql_freeresult($result);
  766. $sql = 'SELECT forum_id, topic_id, post_id, poster_id
  767. FROM ' . POSTS_TABLE . '
  768. WHERE ' . $db->sql_in_set('post_id', $upload_list);
  769. $result = $db->sql_query($sql);
  770. $post_info = array();
  771. while ($row = $db->sql_fetchrow($result))
  772. {
  773. $post_info[$row['post_id']] = $row;
  774. }
  775. $db->sql_freeresult($result);
  776. // Select those attachments we want to change...
  777. $sql = 'SELECT *
  778. FROM ' . ATTACHMENTS_TABLE . '
  779. WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
  780. AND is_orphan = 1';
  781. $result = $db->sql_query($sql);
  782. $files_added = $space_taken = 0;
  783. while ($row = $db->sql_fetchrow($result))
  784. {
  785. $post_row = $post_info[$upload_list[$row['attach_id']]];
  786. $template->assign_block_vars('upload', array(
  787. 'FILE_INFO' => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
  788. 'S_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
  789. 'L_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
  790. );
  791. if (!$auth->acl_get('f_attach', $post_row['forum_id']))
  792. {
  793. continue;
  794. }
  795. // Adjust attachment entry
  796. $sql_ary = array(
  797. 'in_message' => 0,
  798. 'is_orphan' => 0,
  799. 'poster_id' => $post_row['poster_id'],
  800. 'post_msg_id' => $post_row['post_id'],
  801. 'topic_id' => $post_row['topic_id'],
  802. );
  803. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
  804. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  805. WHERE attach_id = ' . $row['attach_id'];
  806. $db->sql_query($sql);
  807. $sql = 'UPDATE ' . POSTS_TABLE . '
  808. SET post_attachment = 1
  809. WHERE post_id = ' . $post_row['post_id'];
  810. $db->sql_query($sql);
  811. $sql = 'UPDATE ' . TOPICS_TABLE . '
  812. SET topic_attachment = 1
  813. WHERE topic_id = ' . $post_row['topic_id'];
  814. $db->sql_query($sql);
  815. $space_taken += $row['filesize'];
  816. $files_added++;
  817. add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
  818. }
  819. $db->sql_freeresult($result);
  820. if ($files_added)
  821. {
  822. set_config_count('upload_dir_size', $space_taken, true);
  823. set_config_count('num_files', $files_added, true);
  824. }
  825. }
  826. }
  827. $template->assign_vars(array(
  828. 'S_ORPHAN' => true)
  829. );
  830. // Just get the files with is_orphan set and older than 3 hours
  831. $sql = 'SELECT *
  832. FROM ' . ATTACHMENTS_TABLE . '
  833. WHERE is_orphan = 1
  834. AND filetime < ' . (time() - 3*60*60) . '
  835. ORDER BY filetime DESC';
  836. $result = $db->sql_query($sql);
  837. while ($row = $db->sql_fetchrow($result))
  838. {
  839. $template->assign_block_vars('orphan', array(
  840. 'FILESIZE' => get_formatted_filesize($row['filesize']),
  841. 'FILETIME' => $user->format_date($row['filetime']),
  842. 'REAL_FILENAME' => utf8_basename($row['real_filename']),
  843. 'PHYSICAL_FILENAME' => utf8_basename($row['physical_filename']),
  844. 'ATTACH_ID' => $row['attach_id'],
  845. 'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
  846. 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
  847. );
  848. }
  849. $db->sql_freeresult($result);
  850. break;
  851. }
  852. if (sizeof($error))
  853. {
  854. $template->assign_vars(array(
  855. 'S_WARNING' => true,
  856. 'WARNING_MSG' => implode('<br />', $error))
  857. );
  858. }
  859. if (sizeof($notify))
  860. {
  861. $template->assign_vars(array(
  862. 'S_NOTIFY' => true,
  863. 'NOTIFY_MSG' => implode('<br />', $notify))
  864. );
  865. }
  866. }
  867. /**
  868. * Build Select for category items
  869. */
  870. function category_select($select_name, $group_id = false, $key = '')
  871. {
  872. global $db, $user;
  873. $types = array(
  874. ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
  875. ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
  876. ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
  877. ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
  878. ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
  879. ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
  880. );
  881. if ($group_id)
  882. {
  883. $sql = 'SELECT cat_id
  884. FROM ' . EXTENSION_GROUPS_TABLE . '
  885. WHERE group_id = ' . (int) $group_id;
  886. $result = $db->sql_query($sql);
  887. $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
  888. $db->sql_freeresult($result);
  889. }
  890. else
  891. {
  892. $cat_type = ATTACHMENT_CATEGORY_NONE;
  893. }
  894. $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
  895. foreach ($types as $type => $mode)
  896. {
  897. $selected = ($type == $cat_type) ? ' selected="selected"' : '';
  898. $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
  899. }
  900. $group_select .= '</select>';
  901. return $group_select;
  902. }
  903. /**
  904. * Extension group select
  905. */
  906. function group_select($select_name, $default_group = false, $key = '')
  907. {
  908. global $db, $user;
  909. $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
  910. $sql = 'SELECT group_id, group_name
  911. FROM ' . EXTENSION_GROUPS_TABLE . '
  912. ORDER BY group_name';
  913. $result = $db->sql_query($sql);
  914. $group_name = array();
  915. while ($row = $db->sql_fetchrow($result))
  916. {
  917. $row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];
  918. $group_name[] = $row;
  919. }
  920. $db->sql_freeresult($result);
  921. $row['group_id'] = 0;
  922. $row['group_name'] = $user->lang['NOT_ASSIGNED'];
  923. $group_name[] = $row;
  924. for ($i = 0; $i < sizeof($group_name); $i++)
  925. {
  926. if ($default_group === false)
  927. {
  928. $selected = ($i == 0) ? ' selected="selected"' : '';
  929. }
  930. else
  931. {
  932. $selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
  933. }
  934. $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
  935. }
  936. $group_select .= '</select>';
  937. return $group_select;
  938. }
  939. /**
  940. * Search Imagick
  941. */
  942. function search_imagemagick()
  943. {
  944. $imagick = '';
  945. $exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS))) ? '.exe' : '';
  946. $magic_home = getenv('MAGICK_HOME');
  947. if (empty($magic_home))
  948. {
  949. $locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
  950. $path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
  951. $locations = array_merge($path_locations, $locations);
  952. foreach ($locations as $location)
  953. {
  954. // The path might not end properly, fudge it
  955. if (substr($location, -1) !== '/')
  956. {
  957. $location .= '/';
  958. }
  959. if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
  960. {
  961. $imagick = str_replace('\\', '/', $location);
  962. continue;
  963. }
  964. }
  965. }
  966. else
  967. {
  968. $imagick = str_replace('\\', '/', $magic_home);
  969. }
  970. return $imagick;
  971. }
  972. /**
  973. * Test Settings
  974. */
  975. function test_upload(&$error, $upload_dir, $create_directory = false)
  976. {
  977. global $user, $phpbb_root_path;
  978. // Does the target directory exist, is it a directory and writable.
  979. if ($create_directory)
  980. {
  981. if (!file_exists($phpbb_root_path . $upload_dir))
  982. {
  983. @mkdir($phpbb_root_path . $upload_dir, 0777);
  984. phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
  985. }
  986. }
  987. if (!file_exists($phpbb_root_path . $upload_dir))
  988. {
  989. $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
  990. return;
  991. }
  992. if (!is_dir($phpbb_root_path . $upload_dir))
  993. {
  994. $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
  995. return;
  996. }
  997. if (!phpbb_is_writable($phpbb_root_path . $upload_dir))
  998. {
  999. $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
  1000. return;
  1001. }
  1002. }
  1003. /**
  1004. * Perform operations on sites for external linking
  1005. */
  1006. function perform_site_list()
  1007. {
  1008. global $db, $user;
  1009. if (isset($_REQUEST['securesubmit']))
  1010. {
  1011. // Grab the list of entries
  1012. $ips = request_var('ips', '');
  1013. $ip_list = array_unique(explode("\n", $ips));
  1014. $ip_list_log = implode(', ', $ip_list);
  1015. $ip_exclude = (!empty($_POST['ipexclude'])) ? 1 : 0;
  1016. $iplist = array();
  1017. $hostlist = array();
  1018. foreach ($ip_list as $item)
  1019. {
  1020. if (preg_match('#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#', trim($item), $ip_range_explode))
  1021. {
  1022. // Don't ask about all this, just don't ask ... !
  1023. $ip_1_counter = $ip_range_explode[1];
  1024. $ip_1_end = $ip_range_explode[5];
  1025. while ($ip_1_counter <= $ip_1_end)
  1026. {
  1027. $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
  1028. $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
  1029. if ($ip_2_counter == 0 && $ip_2_end == 254)
  1030. {
  1031. $ip_2_counter = 256;
  1032. $ip_2_fragment = 256;
  1033. $iplist[] = "'$ip_1_counter.*'";
  1034. }
  1035. while ($ip_2_counter <= $ip_2_end)
  1036. {
  1037. $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
  1038. $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
  1039. if ($ip_3_counter == 0 && $ip_3_end == 254)
  1040. {
  1041. $ip_3_counter = 256;
  1042. $ip_3_fragment = 256;
  1043. $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
  1044. }
  1045. while ($ip_3_counter <= $ip_3_end)
  1046. {
  1047. $ip_4_counter = ($ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[4] : 0;
  1048. $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
  1049. if ($ip_4_counter == 0 && $ip_4_end == 254)
  1050. {
  1051. $ip_4_counter = 256;
  1052. $ip_4_fragment = 256;
  1053. $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
  1054. }
  1055. while ($ip_4_counter <= $ip_4_end)
  1056. {
  1057. $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
  1058. $ip_4_counter++;
  1059. }
  1060. $ip_3_counter++;
  1061. }
  1062. $ip_2_counter++;
  1063. }
  1064. $ip_1_counter++;
  1065. }
  1066. }
  1067. else if (preg_match('#^([0-9]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})$#', trim($item)) || preg_match('#^[a-f0-9:]+\*?$#i', trim($item)))
  1068. {
  1069. $iplist[] = "'" . trim($item) . "'";
  1070. }
  1071. else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
  1072. {
  1073. $hostlist[] = "'" . trim($item) . "'";
  1074. }
  1075. else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
  1076. {
  1077. $hostlist[] = "'" . trim($item) . "'";
  1078. }
  1079. }
  1080. $sql = 'SELECT site_ip, site_hostname
  1081. FROM ' . SITELIST_TABLE . "
  1082. WHERE ip_exclude = $ip_exclude";
  1083. $result = $db->sql_query($sql);
  1084. if ($row = $db->sql_fetchrow($result))
  1085. {
  1086. $iplist_tmp = array();
  1087. $hostlist_tmp = array();
  1088. do
  1089. {
  1090. if ($row['site_ip'])
  1091. {
  1092. if (strlen($row['site_ip']) > 40)
  1093. {
  1094. continue;
  1095. }
  1096. $iplist_tmp[] = "'" . $row['site_ip'] . "'";
  1097. }
  1098. else if ($row['site_hostname'])
  1099. {
  1100. if (strlen($row['site_hostname']) > 255)
  1101. {
  1102. continue;
  1103. }
  1104. $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
  1105. }
  1106. // break;
  1107. }
  1108. while ($row = $db->sql_fetchrow($result));
  1109. $iplist = array_unique(array_diff($iplist, $iplist_tmp));
  1110. $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
  1111. unset($iplist_tmp);
  1112. unset($hostlist_tmp);
  1113. }
  1114. $db->sql_freeresult($result);
  1115. if (sizeof($iplist))
  1116. {
  1117. foreach ($iplist as $ip_entry)
  1118. {
  1119. $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
  1120. VALUES ($ip_entry, $ip_exclude)";
  1121. $db->sql_query($sql);
  1122. }
  1123. }
  1124. if (sizeof($hostlist))
  1125. {
  1126. foreach ($hostlist as $host_entry)
  1127. {
  1128. $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
  1129. VALUES ($host_entry, $ip_exclude)";
  1130. $db->sql_query($sql);
  1131. }
  1132. }
  1133. if (!empty($ip_list_log))
  1134. {
  1135. // Update log
  1136. $log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
  1137. add_log('admin', $log_entry, $ip_list_log);
  1138. }
  1139. trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
  1140. }
  1141. else if (isset($_POST['unsecuresubmit']))
  1142. {
  1143. $unip_sql = request_var('unip', array(0));
  1144. if (sizeof($unip_sql))
  1145. {
  1146. $l_unip_list = '';
  1147. // Grab details of ips for logging information later
  1148. $sql = 'SELECT site_ip, site_hostname
  1149. FROM ' . SITELIST_TABLE . '
  1150. WHERE ' . $db->sql_in_set('site_id', $unip_sql);
  1151. $result = $db->sql_query($sql);
  1152. while ($row = $db->sql_fetchrow($result))
  1153. {
  1154. $l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
  1155. }
  1156. $db->sql_freeresult($result);
  1157. $sql = 'DELETE FROM ' . SITELIST_TABLE . '
  1158. WHERE ' . $db->sql_in_set('site_id', $unip_sql);
  1159. $db->sql_query($sql);
  1160. add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
  1161. }
  1162. trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
  1163. }
  1164. }
  1165. /**
  1166. * Write display_order config field
  1167. */
  1168. function display_order($value, $key = '')
  1169. {
  1170. $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
  1171. return h_radio('config[display_order]', $radio_ary, $value, $key);
  1172. }
  1173. /**
  1174. * Adjust all three max_filesize config vars for display
  1175. */
  1176. function max_filesize($value, $key = '')
  1177. {
  1178. // Determine size var and adjust the value accordingly
  1179. $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
  1180. $size_var = $filesize['si_identifier'];
  1181. $value = $filesize['value'];
  1182. return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
  1183. }
  1184. /**
  1185. * Write secure_allow_deny config field
  1186. */
  1187. function select_allow_deny($value, $key = '')
  1188. {
  1189. $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
  1190. return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
  1191. }
  1192. }
  1193. ?>