first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>File Format Check Module for OpenConf</title>
|
||||
<style type="text/css">
|
||||
body { font-family: arial, helvetica, sans-serif; font-size: 80%; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>File Format Check Module for OpenConf</h1>
|
||||
<p>This module verifies whether an uploaded file matches the selected format. Instead of relying on the file extension or browser-provided MIME type, at least for the formats below, the file itself is inspected to determine its format through signature matching. If a signature is not available, the file extension is checked instead.</p>
|
||||
<p>Signature checking is currently available for the following:<br />
|
||||
<ul>
|
||||
<li>Adobe PDF</li>
|
||||
<li>HTML</li>
|
||||
<li>Microsoft Word</li>
|
||||
<li>PostScript</li>
|
||||
<li>RTF</li>
|
||||
<li>WordPerfect</li>
|
||||
<li>XML</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h3>Requirements</h3>
|
||||
|
||||
<p>none</p>
|
||||
|
||||
<h3>Configuration</h3>
|
||||
|
||||
<p>Options are provided in this module's settings that allow excluding Office (2007) Open XML documents (.docx) and RTF documents from being accepted as Word documents.</p>
|
||||
|
||||
<h3>Usage</h3>
|
||||
|
||||
<p>When a file is uploaded, the detected file format is automatically verified against the selected format. If the format does not match, the upload will not be completed and a notice is displayed.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p>Version 3.0.1<br />
|
||||
- Fixed missing setting export/import hooks</p>
|
||||
|
||||
<p>Version 3.0.0<br />
|
||||
- Added file format identification using PHP Fileinfo</p>
|
||||
|
||||
<p>Version 2.0.1<br />
|
||||
- Added file extension verification of MS Office 2007+ formats</p>
|
||||
|
||||
<p>Version 2.0.0<br />
|
||||
- Added settings import/export<br />
|
||||
- Added module installation and activation as part of standard OpenConf installation<br />
|
||||
- Added support for custom Author/Chair name<br />
|
||||
- Added alternative file extensions for jpg and mpg<br />
|
||||
- Renamed module to File Format Check
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.5<br />
|
||||
- Fixed HTML file type verification
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.4<br />
|
||||
- Dropped setting MOD_FILETYPE_allow_officeopenxml as .docx/.xlsx/.pptx added as MIME types<br />
|
||||
- Changed paperid to mediumint(6)<br />
|
||||
- Changed author-file-validate to handle both submission and upload (dropped author-upload-validate)
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.3<br />
|
||||
- Added token check for settings.inc
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.2<br />
|
||||
- Added support for file type validation of files uploaded during initial submission
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.1<br />
|
||||
- Fixed extraneous print in author-upload-validate.inc
|
||||
</p>
|
||||
|
||||
<p>Version 1.0.0<br />
|
||||
- Initial Release</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
// Skip if chair?
|
||||
if ( ! isset($chair) || ! $chair || ! $OC_configAR['MOD_FILETYPE_chairoverride']) {
|
||||
$MOD_FILETYPE_file = $_FILES['file']['tmp_name']; // uploaded file loc
|
||||
$MOD_FILETYPE_name = $_FILES['file']['name']; // uploaded file original name
|
||||
// uploaded file original name extension
|
||||
if (($MOD_FILETYPE_extbegin = strrpos($MOD_FILETYPE_name, '.')) !== FALSE) {
|
||||
$MOD_FILETYPE_ext = substr($MOD_FILETYPE_name, ($MOD_FILETYPE_extbegin + 1));
|
||||
} else {
|
||||
$MOD_FILETYPE_ext = '';
|
||||
}
|
||||
$MOD_FILETYPE_format = $_POST['format']; // user selected format
|
||||
|
||||
// Valid extensions for each format w/o automated detection
|
||||
$MOD_FILETYPE_validExtAR = array(
|
||||
'txt' => array('txt', 'text'),
|
||||
'jpg' => array('jpg', 'jpeg'),
|
||||
'mpg' => array('mpg', 'mpeg', 'mp4')
|
||||
);
|
||||
|
||||
// Checks $data for $sig from $offset
|
||||
function mod_filetype_checksig($data, $sig, $offset=0, $case=1) {
|
||||
if (($case && (strpos($data, $sig) === $offset))
|
||||
|| (! $case && stripos($data, $sig) === $offset)
|
||||
) {
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
// Check using Fileinfo
|
||||
if (function_exists('finfo_open')
|
||||
&& isset($GLOBALS['OC_mimeTypeAR'][$MOD_FILETYPE_format])
|
||||
&& ($mod_filetype_finfo = finfo_open(FILEINFO_MIME_TYPE))
|
||||
&& (finfo_file($mod_filetype_finfo, $MOD_FILETYPE_file) == $GLOBALS['OC_mimeTypeAR'][$MOD_FILETYPE_format])
|
||||
) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
} else { // Check using signature
|
||||
$MOD_FILETYPE_valid = false;
|
||||
|
||||
if ($MOD_FILETYPE_fp = fopen($MOD_FILETYPE_file, 'r')) {
|
||||
$MOD_FILETYPE_bytes = fread($MOD_FILETYPE_fp, 512);
|
||||
switch ($MOD_FILETYPE_format) {
|
||||
case 'doc':
|
||||
case 'ppt':
|
||||
case 'xls':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, "\320\317\021\340\241\261\032\341")) {
|
||||
$MOD_FILETYPE_bytes = fread($MOD_FILETYPE_fp, 512);
|
||||
if (($MOD_FILETYPE_format == 'doc') && mod_filetype_checksig($MOD_FILETYPE_bytes, "\354\245\301\0")) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
elseif (($MOD_FILETYPE_format == 'doc') && $OC_configAR['MOD_FILETYPE_allow_rtfforword'] && mod_filetype_checksig($MOD_FILETYPE_bytes, "{\\rtf")) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
elseif (($MOD_FILETYPE_format == 'ppt') && preg_match("/^ppt/", $MOD_FILETYPE_ext)) { # mod_filetype_checksig($MOD_FILETYPE_bytes, "")) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
} elseif (($MOD_FILETYPE_format == 'xls') && preg_match("/^xls/", $MOD_FILETYPE_ext)) { # && mod_filetype_checksig($MOD_FILETYPE_bytes, "")) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'docx':
|
||||
case 'pptx':
|
||||
case 'xlsx':
|
||||
if (
|
||||
mod_filetype_checksig($MOD_FILETYPE_bytes, "PK\003\004\024\0\006\0")
|
||||
&&
|
||||
preg_match("/^" . substr($MOD_FILETYPE_format, 0, 3) . "/", $MOD_FILETYPE_ext)
|
||||
) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'pdf':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '%PDF')) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'ps':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '%!PS-Adobe')) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'rtf':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '{\\rtf')) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'wp':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '\377WPC')) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'xml':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '<?xml')) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
case 'html':
|
||||
if (mod_filetype_checksig($MOD_FILETYPE_bytes, '<html', 0, 0)
|
||||
|| mod_filetype_checksig($MOD_FILETYPE_bytes, '<!DOCTYPE HTML', 0, 0)
|
||||
|| mod_filetype_checksig($MOD_FILETYPE_bytes, '<?xml version="1.0" encoding="', 0, 0)
|
||||
) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
default: // check file extension - yes, we've wasted the fopen call :(
|
||||
if (($MOD_FILETYPE_ext == $MOD_FILETYPE_format)
|
||||
|| (isset($MOD_FILETYPE_validExtAR[oc_strtolower($MOD_FILETYPE_format)]) && in_array(oc_strtolower($MOD_FILETYPE_ext), $MOD_FILETYPE_validExtAR[oc_strtolower($MOD_FILETYPE_format)]))
|
||||
) {
|
||||
$MOD_FILETYPE_valid = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
fclose($MOD_FILETYPE_fp);
|
||||
} else {
|
||||
err(oc_('Unable to open file to check format'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($mod_filetype_finfo) {
|
||||
finfo_close($mod_filetype_finfo);
|
||||
}
|
||||
|
||||
// Warn on invalid type
|
||||
if (! $MOD_FILETYPE_valid) {
|
||||
if (preg_match("/submit/", $_SERVER['PHP_SELF'])) {
|
||||
$fileUploaded = false;
|
||||
$err .= '<li>' . oc_('File uploaded does not match format selected') . '</li>';
|
||||
} else { // upload
|
||||
warn(oc_('File uploaded does not match format selected. Please re-check and try again. If you are unable to upload the file, contact the Chair.'));
|
||||
}
|
||||
}
|
||||
} // skip if chair
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
//// Add hooks
|
||||
|
||||
oc_addHook('author-file-validate', '../modules/filetype/author-file-validate.inc');
|
||||
oc_addHook('author-upload-validate', '../modules/filetype/author-file-validate.inc');
|
||||
|
||||
// Register chair settings hook
|
||||
oc_addHook('chair-menu-settings-modules', array($OC_modulesAR[$moduleId]['name'], '<a href="../modules/request.php?module=filetype&action=settings.inc">File Format Check</a>'));
|
||||
|
||||
// Settings Export/Import
|
||||
oc_addHook('settings-export-options', '../modules/filetype/settings-export-options.inc');
|
||||
oc_addHook('settings-export-prep', '../modules/filetype/settings-export-prep.inc');
|
||||
@@ -0,0 +1,22 @@
|
||||
## +----------------------------------------------------------------------+
|
||||
## | OpenConf |
|
||||
## +----------------------------------------------------------------------+
|
||||
## | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
## +----------------------------------------------------------------------+
|
||||
## | This source file is subject to the OpenConf License, available on |
|
||||
## | the OpenConf web site: www.OpenConf.com |
|
||||
## +----------------------------------------------------------------------+
|
||||
|
||||
|
||||
## NOTE: UPDATES TO THIS FILE NEED TO BE REFLECTED IN lib/DB.sql
|
||||
|
||||
|
||||
|
||||
## NOTE: This file cannot contain a semi-colon (;) except at the end of a
|
||||
## SQL statement.
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('filetype', 'MOD_FILETYPE_chairoverride', '1', 'Skip Check if Chair', 'Skips file format check if Chair uploading', 0);
|
||||
|
||||
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('filetype', 'MOD_FILETYPE_allow_rtfforword', '1', 'Accept RTF for Word Doc', 'Permit RTF MS Word docs', 0);
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
// Module ID - needs to match directory name
|
||||
$moduleId = 'filetype';
|
||||
|
||||
// Module info
|
||||
$OC_modulesAR[$moduleId] = array(
|
||||
'name' => 'File Format Check',
|
||||
'description' => 'Verifies file uploaded matches selected format',
|
||||
'version' => '3.0.1',
|
||||
'dependencies' => array(),
|
||||
'developer' => 'OpenConf'
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
|
||||
print '
|
||||
<br />
|
||||
<label><input type="checkbox" name="settings[]" value="filetype" /> FileType - Configuration</label><br />
|
||||
';
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
if (in_array('filetype', $_POST['settings'])) {
|
||||
$settings['modules']['filetype'] = $OC_modulesAR['filetype']['name'];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------+
|
||||
// | OpenConf |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to the OpenConf License, available on |
|
||||
// | the OpenConf web site: www.OpenConf.com |
|
||||
// +----------------------------------------------------------------------+
|
||||
|
||||
$MOD_FILETYPE_configVars = array('MOD_FILETYPE_chairoverride', 'MOD_FILETYPE_allow_rtfforword');
|
||||
|
||||
if (isset($_POST['submit']) && ($_POST['submit'] == 'Save Settings')) {
|
||||
// Check for valid submission
|
||||
if (!validToken('chair')) {
|
||||
warn('Invalid submission');
|
||||
}
|
||||
|
||||
// Update config & status settings
|
||||
updateAllConfigSettings($MOD_FILETYPE_configVars, $_POST, OCC_MODULE_ID);
|
||||
|
||||
// notify user
|
||||
print '<p style="text-align: center" class="note">Settings Saved</p>';
|
||||
}
|
||||
|
||||
print '
|
||||
<form method="post" action="' . OCC_SELF . '">
|
||||
<input type="hidden" name="token" value="' . $_SESSION[OCC_SESSION_VAR_NAME]['chairtoken'] . '" />
|
||||
|
||||
<p><strong>Skip Check if ' . OCC_WORD_CHAIR . ':</strong> ' .
|
||||
generateRadioOptions('MOD_FILETYPE_chairoverride', $yesNoAR, $OC_configAR['MOD_FILETYPE_chairoverride'])
|
||||
. '<br /><span class="note">Skips file format check if ' . OCC_WORD_CHAIR . ' uploading.</p>
|
||||
|
||||
<p><strong>Allow RTF for Word Doc:</strong> ' .
|
||||
generateRadioOptions('MOD_FILETYPE_allow_rtfforword', $yesNoAR, $OC_configAR['MOD_FILETYPE_allow_rtfforword'])
|
||||
. '<br /><span class="note">Checking Yes will allow Word documents (.doc) in RTF format.</p>
|
||||
|
||||
<br />
|
||||
<p><input type="submit" name="submit" class="submit" value="Save Settings" /></p>
|
||||
</form>
|
||||
';
|
||||
@@ -0,0 +1,15 @@
|
||||
## +----------------------------------------------------------------------+
|
||||
## | OpenConf |
|
||||
## +----------------------------------------------------------------------+
|
||||
## | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
|
||||
## +----------------------------------------------------------------------+
|
||||
## | This source file is subject to the OpenConf License, available on |
|
||||
## | the OpenConf web site: www.OpenConf.com |
|
||||
## +----------------------------------------------------------------------+
|
||||
|
||||
## NOTE: This file cannot contain a semi-colon (;) except at the end of a
|
||||
## SQL statement.
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
DELETE FROM `config` WHERE `module`='filetype';
|
||||
Reference in New Issue
Block a user