From fb195633021967499447451ecf7a435644846ce3 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 22 Apr 2003 19:44:00 +0000 Subject: first version of attachment admin panel + some fixes (i hope i do not screw someones code with this, my appologies) git-svn-id: file:///svn/phpbb/trunk@3926 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_attachments.php | 551 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 551 insertions(+) create mode 100644 phpBB/adm/admin_attachments.php (limited to 'phpBB/adm/admin_attachments.php') diff --git a/phpBB/adm/admin_attachments.php b/phpBB/adm/admin_attachments.php new file mode 100644 index 0000000000..22de35990b --- /dev/null +++ b/phpBB/adm/admin_attachments.php @@ -0,0 +1,551 @@ +acl_get('a_attach')) ? $filename . $SID . '&mode=manage' : ''; + + return; +} + +define('IN_PHPBB', 1); +// Include files +$phpbb_root_path = '../'; +require($phpbb_root_path . 'extension.inc'); +require('pagestart.' . $phpEx); + +if (!$auth->acl_get('a_attach')) +{ + trigger_error($user->lang['NO_ADMIN']); +} + +function size_select($select_name, $size_compare) +{ + global $user; + + $size_types_text = array($user->lang['BYTES'], $user->lang['KB'], $user->lang['MB']); + $size_types = array('b', 'kb', 'mb'); + + $select_field = ''; + + return ($select_field); +} + +function test_upload(&$error, &$error_msg, $upload_dir, $ftp_path, $ftp_upload_allowed, $create_directory = false) +{ + global $user; + + $error = FALSE; + + // Does the target directory exist, is it a directory and writeable. (only test if ftp upload is disabled) + if (!$ftp_upload_allowed) + { + if ($create_directory) + { + if (!@file_exists($upload_dir)) + { + @mkdir($upload_dir, 0755); + @chmod($upload_dir, 0777); + } + } + + if (!@file_exists($upload_dir)) + { + $error = TRUE; + $error_msg = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $new['upload_dir']) . '
'; + } + + if (!$error && !is_dir($upload_dir)) + { + $error = TRUE; + $error_msg = sprintf($user->lang['DIRECTORY_IS_NOT_A_DIR'], $new['upload_dir']) . '
'; + } + + if (!$error) + { + if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) ) + { + $error = TRUE; + $error_msg = sprintf($user->lang['DIRECTORY_NOT_WRITEABLE'], $new['upload_dir']) . '
'; + } + else + { + @fclose($fp); + @unlink($upload_dir . '/0_000000.000'); + } + } + } + else + { + // Check FTP Settings + $server = ( empty($new['ftp_server']) ) ? 'localhost' : $new['ftp_server']; + $conn_id = @ftp_connect($server); + + if (!$conn_id) + { + $error = TRUE; + $error_msg = sprintf($user->lang['FTP_ERROR_CONNECT'], $server) . '
'; + } + + $login_result = @ftp_login($conn_id, $new['ftp_user'], $new['ftp_pass']); + + if (!$login_result && !$error) + { + $error = TRUE; + $error_msg = sprintf($user->lang['FTP_ERROR_LOGIN'], $new['ftp_user']) . '
'; + } + + if (!@ftp_pasv($conn_id, intval($new['ftp_pasv_mode']))) + { + $error = TRUE; + $error_msg = $user->lang['FTP_ERROR_PASV_MODE']; + } + + if (!$error) + { + // Check Upload + $tmpfname = @tempnam('/tmp', 't0000'); + @unlink($tmpfname); // unlink for safety on php4.0.3+ + $fp = @fopen($tmpfname, 'w'); + @fwrite($fp, 'test'); + @fclose($fp); + + if ($create_directory) + { + $result = @ftp_chdir($conn_id, $ftp_path); + + if (!$result) + { + @ftp_mkdir($conn_id, $ftp_path); + } + } + + $result = @ftp_chdir($conn_id, $ftp_path); + + if (!$result) + { + $error = TRUE; + $error_msg = sprintf($user->lang['FTP_ERROR_PATH'], $ftp_path) . '
'; + } + else + { + $res = @ftp_put($conn_id, 't0000', $tmpfname, FTP_ASCII); + + if (!$res) + { + $error = TRUE; + $error_msg = sprintf($user->lang['FTP_ERROR_UPLOAD'], $ftp_path) . '
'; + } + else + { + $res = @ftp_delete($conn_id, 't0000'); + + if (!$res) + { + $error = TRUE; + $error_msg = sprintf($user->lang['FTP_ERROR_DELETE'], $ftp_path) . '
'; + } + } + } + + @ftp_quit($conn_id); + @unlink($tmpfname); + } + } +} + +$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : ''; + +$config_sizes = array('max_filesize' => 'size', 'attachment_quota' => 'quota_size', 'max_filesize_pm' => 'pm_size'); + +foreach ($config_sizes as $cfg_key => $var) +{ + $$var = (isset($_REQUEST[$var])) ? htmlspecialchars($_REQUEST[$var]) : ''; +} + +$submit = (isset($_POST['submit'])) ? TRUE : FALSE; +$search_imagick = (isset($_POST['search_imagick'])) ? TRUE : FALSE; + +$error = $notify = false; +$error_msg = $notify_msg = ''; + +// Pull all config data +$sql = "SELECT * + FROM " . CONFIG_TABLE; +$result = $db->sql_query($sql); + +while ($row = $db->sql_fetchrow($result)) +{ + $config_name = $row['config_name']; + $config_value = $row['config_value']; + + $default_config[$config_name] = $config_value; + $new[$config_name] = (isset($_POST[$config_name])) ? $_POST[$config_name] : $default_config[$config_name]; + + foreach ($config_sizes as $cfg_key => $var) + { + if (empty($$var) && !$submit && $config_name == $cfg_key) + { + $$var = (intval($default_config[$config_name]) >= 1048576) ? 'mb' : ((intval($default_config[$config_name]) >= 1024) ? 'kb' : 'b'); + } + + if (!$submit && $config_name == $cfg_key) + { + if ($new[$config_name] >= 1048576) + { + $new[$config_name] = round($new[$config_name] / 1048576 * 100) / 100; + } + else if($new[$config_name] >= 1024) + { + $new[$config_name] = round($new[$config_name] / 1024 * 100) / 100; + } + } + + if ($submit && $mode == 'manage' && $config_name == $cfg_key) + { + $old = $new[$config_name]; + $new[$config_name] = ($$var == 'kb') ? round($new[$config_name] * 1024) : (($$var == 'mb') ? round($new[$config_name] * 1048576) : $new[$config_name]); + } + } + + if ($submit && $mode == 'manage') + { + // Update Extension Group Filesizes + if ($config_name == 'max_filesize') + { + $old_size = intval($default_config[$config_name]); + $new_size = intval($new[$config_name]); + + if ($old_size != $new_size) + { + // See, if we have a similar value of old_size in Extension Groups. If so, update these values. + $sql = "UPDATE " . EXTENSION_GROUPS_TABLE . " + SET max_filesize = " . $new_size . " + WHERE max_filesize = " . $old_size; + $db->sql_query($sql); + } + } + + set_config($config_name, stripslashes($new[$config_name])); + + if (in_array($config_name, array('max_filesize', 'attachment_quota', 'max_filesize_pm'))) + { + $new[$config_name] = $old; + } + } +} + +if ($submit && $mode == 'manage') +{ + add_log('admin', 'LOG_SETTING_CONFIG'); + $notify = TRUE; + $notify_msg = $user->lang['Config_updated']; +} + +// Adjust the Upload Directory +if (!$new['allow_ftp_upload']) +{ + if ( ($new['upload_dir'][0] == '/') || ( ($new['upload_dir'][0] != '/') && ($new['upload_dir'][1] == ':') ) ) + { + $upload_dir = $new['upload_dir']; + } + else + { + $upload_dir = $phpbb_root_path . $new['upload_dir']; + } +} +else +{ + $upload_dir = $new['download_path']; +} + +switch ($mode) +{ + case 'manage': + $l_title = 'ATTACHMENT_CONFIG'; + break; +} + +// Temporary Language Variables + +page_header($user->lang[$l_title]); + +// Search Imagick +if ($search_imagick) +{ + $imagick = ''; + + if (eregi('convert', $imagick)) + { + continue; + } + else if ($imagick != 'none') + { + if (!eregi('WIN', PHP_OS)) + { + $retval = @exec('whereis convert'); + $paths = explode(' ', $retval); + + if (is_array($paths)) + { + foreach($paths as $path) + { + if (basename($path) == 'convert') + { + $imagick = $path; + } + } + } + } + else if (eregi('WIN', PHP_OS)) + { + $path = 'c:/imagemagick/convert.exe'; + + if (@file_exists($path)) + { + $imagick = $path; + } + } + } + + $new['img_imagick'] = (@file_exists(trim($imagick))) ? trim($imagick) : ''; +} + +// Check Settings +if ($submit && $mode == 'manage') +{ + $upload_dir = ( ($new['upload_dir'][0] == '/') || ($new['upload_dir'][0] != '/' && $new['upload_dir'][1] == ':') ) ? $new['upload_dir'] : $phpbb_root_path . $new['upload_dir']; + + test_upload($error, $error_msg, $upload_dir, $new['ftp_path'], $new['allow_ftp_upload'], false); +} + + +if ($submit && $mode == 'cats') +{ + $upload_dir = ( ($new['upload_dir'][0] == '/') || ($new['upload_dir'][0] != '/' && $new['upload_dir'][1] == ':') ) ? $new['upload_dir'] . '/thumbs' : $phpbb_root_path . $new['upload_dir'] . '/thumbs'; + test_upload($error, $error_msg, $upload_dir, $new['ftp_path'] . '/thumbs', $new['allow_ftp_upload'], true); +} + +?> + +

lang[$l_title]; ?>

+ +

lang[$l_title . '_EXPLAIN']; ?>

+ + + +

lang['WARNING']; ?>

+ +

+ + + +

lang['NOTIFY']; ?>

+ +

+ + +
" method="post"> + + + + +
   + | lang['ATTACH_' . strtoupper($modes[$i]) . '_URL']; + + if ($mode != $modes[$i]) + { + ?>
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lang['ATTACHMENT_SETTINGS']; ?>
lang['UPLOAD_DIR']; ?>:
lang['UPLOAD_DIR_EXPLAIN']; ?>
lang['DISPLAY_ORDER']; ?>:
lang['DISPLAY_ORDER_EXPLAIN']; ?>
+ + + + + + + +
/> lang['DESCENDING']; ?>
/> lang['ASCENDING']; ?>
lang['ATTACH_MAX_FILESIZE']; ?>:
lang['ATTACH_MAX_FILESIZE_EXPLAIN']; ?>
lang['ATTACH_QUOTA']; ?>:
lang['ATTACH_QUOTA_EXPLAIN']; ?>
lang['ATTACH_MAX_PM_FILESIZE']; ?>:
lang['ATTACH_MAX_PM_FILESIZE_EXPLAIN']; ?>
lang['MAX_ATTACHMENTS'] ?>:
lang['MAX_ATTACHMENTS_EXPLAIN']; ?>
lang['MAX_ATTACHMENTS_PM'] ?>:
lang['MAX_ATTACHMENTS_PM_EXPLAIN']; ?>
lang['PM_ATTACH']; ?>:
lang['PM_ATTACH_EXPLAIN']; ?>
/> lang['YES']; ?>   /> lang['NO']; ?>
lang['NO_FTP_EXTENSIONS_INSTALLED']; ?>
lang['FTP_UPLOAD']; ?>:
lang['FTP_UPLOAD_EXPLAIN']; ?>
/> lang['YES']; ?>   /> lang['NO']; ?>
lang['FTP_SERVER']; ?>:
lang['FTP_SERVER_EXPLAIN']; ?>
lang['ATTACH_FTP_PATH']; ?>:
lang['ATTACH_FTP_PATH_EXPLAIN']; ?>
lang['FTP_DOWNLOAD_PATH']; ?>:
lang['FTP_DOWNLOAD_PATH_EXPLAIN']; ?>
lang['FTP_PASSIVE_MODE']; ?>:
lang['FTP_PASSIVE_MODE_EXPLAIN']; ?>
/> lang['YES']; ?>   /> lang['NO']; ?>
lang['FTP_USER']; ?>:
lang['FTP_PASS']; ?>:
  
+ +
+ + \ No newline at end of file -- cgit v1.2.1