From 35fba1ef9f562a10a6b796e47024305218043bfc Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 8 Jul 2015 13:18:58 +0200 Subject: [PATCH 1/3] Move mimetypes.list.php to config/mimetypemapping.json This allows users to add new mimetypemappings (extention -> mimetype) themself. And not have to wait until a new release for updated mimetypes. Fixes: #15384 --- config/mimetypemapping.json | 168 ++++++++++++++++++++++ lib/private/files/type/detection.php | 2 +- lib/private/helper.php | 5 +- lib/private/mimetypes.list.php | 200 --------------------------- 4 files changed, 173 insertions(+), 202 deletions(-) create mode 100644 config/mimetypemapping.json delete mode 100644 lib/private/mimetypes.list.php diff --git a/config/mimetypemapping.json b/config/mimetypemapping.json new file mode 100644 index 0000000000..49f3d8c9a1 --- /dev/null +++ b/config/mimetypemapping.json @@ -0,0 +1,168 @@ +{ + "_comment" : "Array mapping file extensions to mimetypes (in alphabetical order]", + "_comment2": "The first index in the mime type array is the assumed correct mimetype", + "_comment3": "and the second (if present] is a secure alternative", + + + "3gp": ["video/3gpp"], + "7z": ["application/x-7z-compressed"], + "accdb": ["application/msaccess"], + "ai": ["application/illustrator"], + "apk": ["application/vnd.android.package-archive"], + "arw": ["image/x-dcraw"], + "avi": ["video/x-msvideo"], + "bash": ["text/x-shellscript"], + "blend": ["application/x-blender"], + "bin": ["application/x-bin"], + "bmp": ["image/bmp"], + "bpg": ["image/bpg"], + "cb7": ["application/x-cbr"], + "cba": ["application/x-cbr"], + "cbr": ["application/x-cbr"], + "cbt": ["application/x-cbr"], + "cbtc": ["application/x-cbr"], + "cbz": ["application/x-cbr"], + "cc": ["text/x-c"], + "cdr": ["application/coreldraw"], + "cnf": ["text/plain"], + "conf": ["text/plain"], + "cpp": ["text/x-c++src"], + "cr2": ["image/x-dcraw"], + "css": ["text/css"], + "csv": ["text/csv"], + "cvbdl": ["application/x-cbr"], + "c": ["text/x-c"], + "c++": ["text/x-c++src"], + "dcr": ["image/x-dcraw"], + "deb": ["application/x-deb"], + "dng": ["image/x-dcraw"], + "doc": ["application/msword"], + "docm": ["application/vnd.ms-word.document.macroEnabled.12"], + "docx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], + "dot": ["application/msword"], + "dotx": ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"], + "dv": ["video/dv"], + "eot": ["application/vnd.ms-fontobject"], + "epub": ["application/epub+zip"], + "eps": ["application/postscript"], + "erf": ["image/x-dcraw"], + "exe": ["application/x-ms-dos-executable"], + "flac": ["audio/flac"], + "flv": ["video/x-flv"], + "gif": ["image/gif"], + "gz": ["application/x-gzip"], + "gzip": ["application/x-gzip"], + "h": ["text/x-h"], + "hh": ["text/x-h"], + "html": ["text/html", "text/plain"], + "htm": ["text/html", "text/plain"], + "ical": ["text/calendar"], + "ics": ["text/calendar"], + "iiq": ["image/x-dcraw"], + "impress": ["text/impress"], + "jpeg": ["image/jpeg"], + "jpg": ["image/jpeg"], + "jps": ["image/jpeg"], + "js": ["application/javascript", "text/plain"], + "json": ["application/json", "text/plain"], + "k25": ["image/x-dcraw"], + "kdc": ["image/x-dcraw"], + "key": ["application/x-iwork-keynote-sffkey"], + "keynote": ["application/x-iwork-keynote-sffkey"], + "kra": ["application/x-krita"], + "m2t": ["video/mp2t"], + "m4v": ["video/mp4"], + "markdown": ["text/markdown"], + "mdown": ["text/markdown"], + "md": ["text/markdown"], + "mdb": ["application/msaccess"], + "mdwn": ["text/markdown"], + "mkd": ["text/markdown"], + "mef": ["image/x-dcraw"], + "mkv": ["video/x-matroska"], + "mobi": ["application/x-mobipocket-ebook"], + "mov": ["video/quicktime"], + "mp3": ["audio/mpeg"], + "mp4": ["video/mp4"], + "mpeg": ["video/mpeg"], + "mpg": ["video/mpeg"], + "mpo": ["image/jpeg"], + "msi": ["application/x-msi"], + "mts": ["video/MP2T"], + "mt2s": ["video/MP2T"], + "nef": ["image/x-dcraw"], + "numbers": ["application/x-iwork-numbers-sffnumbers"], + "odf": ["application/vnd.oasis.opendocument.formula"], + "odg": ["application/vnd.oasis.opendocument.graphics"], + "odp": ["application/vnd.oasis.opendocument.presentation"], + "ods": ["application/vnd.oasis.opendocument.spreadsheet"], + "odt": ["application/vnd.oasis.opendocument.text"], + "oga": ["audio/ogg"], + "ogg": ["audio/ogg"], + "ogv": ["video/ogg"], + "opus": ["audio/ogg"], + "orf": ["image/x-dcraw"], + "otf": ["application/font-sfnt"], + "pages": ["application/x-iwork-pages-sffpages"], + "pdf": ["application/pdf"], + "pfb": ["application/x-font"], + "pef": ["image/x-dcraw"], + "php": ["application/x-php"], + "pl": ["application/x-perl"], + "png": ["image/png"], + "pot": ["application/vnd.ms-powerpoint"], + "potm": ["application/vnd.ms-powerpoint.template.macroEnabled.12"], + "potx": ["application/vnd.openxmlformats-officedocument.presentationml.template"], + "ppa": ["application/vnd.ms-powerpoint"], + "ppam": ["application/vnd.ms-powerpoint.addin.macroEnabled.12"], + "pps": ["application/vnd.ms-powerpoint"], + "ppsm": ["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"], + "ppsx": ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"], + "ppt": ["application/vnd.ms-powerpoint"], + "pptm": ["application/vnd.ms-powerpoint.presentation.macroEnabled.12"], + "pptx": ["application/vnd.openxmlformats-officedocument.presentationml.presentation"], + "ps": ["application/postscript"], + "psd": ["application/x-photoshop"], + "py": ["text/x-python"], + "raf": ["image/x-dcraw"], + "rar": ["application/x-rar-compressed"], + "reveal": ["text/reveal"], + "rw2": ["image/x-dcraw"], + "sgf": ["application/sgf"], + "sh-lib": ["text/x-shellscript"], + "sh": ["text/x-shellscript"], + "srf": ["image/x-dcraw"], + "sr2": ["image/x-dcraw"], + "svg": ["image/svg+xml", "text/plain"], + "swf": ["application/x-shockwave-flash", "application/octet-stream"], + "tar": ["application/x-tar"], + "tar.gz": ["application/x-compressed"], + "tex": ["application/x-tex"], + "tgz": ["application/x-compressed"], + "tiff": ["image/tiff"], + "tif": ["image/tiff"], + "ttf": ["application/font-sfnt"], + "txt": ["text/plain"], + "vcard": ["text/vcard"], + "vcf": ["text/vcard"], + "vob": ["video/dvd"], + "wav": ["audio/wav"], + "webm": ["video/webm"], + "woff": ["application/font-woff"], + "wmv": ["video/x-ms-wmv"], + "xcf": ["application/x-gimp"], + "xla": ["application/vnd.ms-excel"], + "xlam": ["application/vnd.ms-excel.addin.macroEnabled.12"], + "xls": ["application/vnd.ms-excel"], + "xlsb": ["application/vnd.ms-excel.sheet.binary.macroEnabled.12"], + "xlsm": ["application/vnd.ms-excel.sheet.macroEnabled.12"], + "xlsx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], + "xlt": ["application/vnd.ms-excel"], + "xltm": ["application/vnd.ms-excel.template.macroEnabled.12"], + "xltx": ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"], + "xml": ["application/xml", "text/plain"], + "xrf": ["image/x-dcraw"], + "yaml": ["application/yaml", "text/plain"], + "yml": ["application/yaml", "text/plain"], + "zip": ["application/zip"] +} diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 61ca32a5ed..3287375bc7 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -66,7 +66,7 @@ class Detection { // Update the alternative mimetypes to avoid having to look them up each time. foreach ($this->mimetypes as $mimeType) { - $this->secureMimeTypes[$mimeType[0]] = $mimeType[1] ?: $mimeType[0]; + $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; } } diff --git a/lib/private/helper.php b/lib/private/helper.php index b7938416fb..abe1e42ecb 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -424,8 +424,11 @@ class OC_Helper { */ static public function getMimetypeDetector() { if (!self::$mimetypeDetector) { + $file = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); + $mimetypemapping = get_object_vars(json_decode($file)); + self::$mimetypeDetector = new \OC\Files\Type\Detection(); - self::$mimetypeDetector->registerTypeArray(include 'mimetypes.list.php'); + self::$mimetypeDetector->registerTypeArray($mimetypemapping); } return self::$mimetypeDetector; } diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php deleted file mode 100644 index efb8089420..0000000000 --- a/lib/private/mimetypes.list.php +++ /dev/null @@ -1,200 +0,0 @@ - - * @author Jörn Friedrich Dreyer - * @author Morris Jobke - * @author Normal Ra - * @author Olivier Paroz - * @author Robin Appelman - * @author Thomas Müller - * @author Thomas Tanghus - * @author tiezdne - * @author Victor Dubiniuk - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -/** - * Array mapping file extensions to mimetypes (in alphabetical order). - * - * The first index in the mime type array is the assumed correct mimetype - * and the second is either a secure alternative or null if the correct - * is considered secure. - */ -return array( - '3gp' => array('video/3gpp', null), - '7z' => array('application/x-7z-compressed', null), - 'accdb' => array('application/msaccess', null), - 'ai' => array('application/illustrator', null), - 'apk' => array('application/vnd.android.package-archive', null), - 'arw' => array('image/x-dcraw', null), - 'avi' => array('video/x-msvideo', null), - 'bash' => array('text/x-shellscript', null), - 'blend' => array('application/x-blender', null), - 'bin' => array('application/x-bin', null), - 'bmp' => array('image/bmp', null), - 'bpg' => array('image/bpg', null), - 'cb7' => array('application/x-cbr', null), - 'cba' => array('application/x-cbr', null), - 'cbr' => array('application/x-cbr', null), - 'cbt' => array('application/x-cbr', null), - 'cbtc' => array('application/x-cbr', null), - 'cbz' => array('application/x-cbr', null), - 'cc' => array('text/x-c', null), - 'cdr' => array('application/coreldraw', null), - 'cnf' => array('text/plain', null), - 'conf' => array('text/plain', null), - 'cpp' => array('text/x-c++src', null), - 'cr2' => array('image/x-dcraw', null), - 'css' => array('text/css', null), - 'csv' => array('text/csv', null), - 'cvbdl' => array('application/x-cbr', null), - 'c' => array('text/x-c', null), - 'c++' => array('text/x-c++src', null), - 'dcr' => array('image/x-dcraw', null), - 'deb' => array('application/x-deb', null), - 'dng' => array('image/x-dcraw', null), - 'doc' => array('application/msword', null), - 'docm' => array('application/vnd.ms-word.document.macroEnabled.12', null), - 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', null), - 'dot' => array('application/msword', null), - 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.template', null), - 'dv' => array('video/dv', null), - 'eot' => array('application/vnd.ms-fontobject', null), - 'epub' => array('application/epub+zip', null), - 'eps' => array('application/postscript', null), - 'erf' => array('image/x-dcraw', null), - 'exe' => array('application/x-ms-dos-executable', null), - 'flac' => array('audio/flac', null), - 'flv' => array('video/x-flv', null), - 'gif' => array('image/gif', null), - 'gz' => array('application/x-gzip', null), - 'gzip' => array('application/x-gzip', null), - 'h' => array('text/x-h', null), - 'hh' => array('text/x-h', null), - 'html' => array('text/html', 'text/plain'), - 'htm' => array('text/html', 'text/plain'), - 'ical' => array('text/calendar', null), - 'ics' => array('text/calendar', null), - 'iiq' => array('image/x-dcraw', null), - 'impress' => array('text/impress', null), - 'jpeg' => array('image/jpeg', null), - 'jpg' => array('image/jpeg', null), - 'jps' => array('image/jpeg', null), - 'js' => array('application/javascript', 'text/plain'), - 'json' => array('application/json', 'text/plain'), - 'k25' => array('image/x-dcraw', null), - 'kdc' => array('image/x-dcraw', null), - 'key' => array('application/x-iwork-keynote-sffkey', null), - 'keynote' => array('application/x-iwork-keynote-sffkey', null), - 'kra' => array('application/x-krita', null), - 'm2t' => array('video/mp2t', null), - 'm4v' => array('video/mp4', null), - 'markdown' => array('text/markdown', null), - 'mdown' => array('text/markdown', null), - 'md' => array('text/markdown', null), - 'mdb' => array('application/msaccess', null), - 'mdwn' => array('text/markdown', null), - 'mkd' => array('text/markdown', null), - 'mef' => array('image/x-dcraw', null), - 'mkv' => array('video/x-matroska', null), - 'mobi' => array('application/x-mobipocket-ebook', null), - 'mov' => array('video/quicktime', null), - 'mp3' => array('audio/mpeg', null), - 'mp4' => array('video/mp4', null), - 'mpeg' => array('video/mpeg', null), - 'mpg' => array('video/mpeg', null), - 'mpo' => array('image/jpeg', null), - 'msi' => array('application/x-msi', null), - 'mts' => ['video/MP2T', null], - 'mt2s' => ['video/MP2T', null], - 'nef' => array('image/x-dcraw', null), - 'numbers' => array('application/x-iwork-numbers-sffnumbers', null), - 'odf' => array('application/vnd.oasis.opendocument.formula', null), - 'odg' => array('application/vnd.oasis.opendocument.graphics', null), - 'odp' => array('application/vnd.oasis.opendocument.presentation', null), - 'ods' => array('application/vnd.oasis.opendocument.spreadsheet', null), - 'odt' => array('application/vnd.oasis.opendocument.text', null), - 'oga' => array('audio/ogg', null), - 'ogg' => array('audio/ogg', null), - 'ogv' => array('video/ogg', null), - 'opus' => array('audio/ogg', null), - 'orf' => array('image/x-dcraw', null), - 'otf' => array('application/font-sfnt', null), - 'pages' => array('application/x-iwork-pages-sffpages', null), - 'pdf' => array('application/pdf', null), - 'pfb' => array('application/x-font', null), - 'pef' => array('image/x-dcraw', null), - 'php' => array('application/x-php', null), - 'pl' => array('application/x-perl', null), - 'png' => array('image/png', null), - 'pot' => array('application/vnd.ms-powerpoint', null), - 'potm' => array('application/vnd.ms-powerpoint.template.macroEnabled.12', null), - 'potx' => array('application/vnd.openxmlformats-officedocument.presentationml.template', null), - 'ppa' => array('application/vnd.ms-powerpoint', null), - 'ppam' => array('application/vnd.ms-powerpoint.addin.macroEnabled.12', null), - 'pps' => array('application/vnd.ms-powerpoint', null), - 'ppsm' => array('application/vnd.ms-powerpoint.slideshow.macroEnabled.12', null), - 'ppsx' => array('application/vnd.openxmlformats-officedocument.presentationml.slideshow', null), - 'ppt' => array('application/vnd.ms-powerpoint', null), - 'pptm' => array('application/vnd.ms-powerpoint.presentation.macroEnabled.12', null), - 'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', null), - 'ps' => array('application/postscript', null), - 'psd' => array('application/x-photoshop', null), - 'py' => array('text/x-python', null), - 'raf' => array('image/x-dcraw', null), - 'rar' => array('application/x-rar-compressed', null), - 'reveal' => array('text/reveal', null), - 'rw2' => array('image/x-dcraw', null), - 'sgf' => array('application/sgf', null), - 'sh-lib' => array('text/x-shellscript', null), - 'sh' => array('text/x-shellscript', null), - 'srf' => array('image/x-dcraw', null), - 'sr2' => array('image/x-dcraw', null), - 'svg' => array('image/svg+xml', 'text/plain'), - 'swf' => array('application/x-shockwave-flash', 'application/octet-stream'), - 'tar' => array('application/x-tar', null), - 'tar.gz' => array('application/x-compressed', null), - 'tex' => array('application/x-tex', null), - 'tgz' => array('application/x-compressed', null), - 'tiff' => array('image/tiff', null), - 'tif' => array('image/tiff', null), - 'ttf' => array('application/font-sfnt', null), - 'txt' => array('text/plain', null), - 'vcard' => array('text/vcard', null), - 'vcf' => array('text/vcard', null), - 'vob' => array('video/dvd', null), - 'wav' => array('audio/wav', null), - 'webm' => array('video/webm', null), - 'woff' => array('application/font-woff', null), - 'wmv' => array('video/x-ms-wmv', null), - 'xcf' => array('application/x-gimp', null), - 'xla' => array('application/vnd.ms-excel', null), - 'xlam' => array('application/vnd.ms-excel.addin.macroEnabled.12', null), - 'xls' => array('application/vnd.ms-excel', null), - 'xlsb' => array('application/vnd.ms-excel.sheet.binary.macroEnabled.12', null), - 'xlsm' => array('application/vnd.ms-excel.sheet.macroEnabled.12', null), - 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', null), - 'xlt' => array('application/vnd.ms-excel', null), - 'xltm' => array('application/vnd.ms-excel.template.macroEnabled.12', null), - 'xltx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.template', null), - 'xml' => array('application/xml', 'text/plain'), - 'xrf' => array('image/x-dcraw', null), - 'yaml' => array('application/yaml', 'text/plain'), - 'yml' => array('application/yaml', 'text/plain'), - 'zip' => array('application/zip', null), -); From 895d29adf18fcf6a334839aead46bdb4bd9dbbec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 8 Jul 2015 15:49:53 +0200 Subject: [PATCH 2/3] Move mimetypemapping.json to mimetypemapping.dist.json This allows users to create their own mapping file to extend our current mappings. This makes sure that custom mappings are not lost on OC upgrades. --- ...mimetypemapping.json => mimetypemapping.dist.json} | 3 +++ lib/private/helper.php | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) rename config/{mimetypemapping.json => mimetypemapping.dist.json} (97%) diff --git a/config/mimetypemapping.json b/config/mimetypemapping.dist.json similarity index 97% rename from config/mimetypemapping.json rename to config/mimetypemapping.dist.json index 49f3d8c9a1..48ec4a56da 100644 --- a/config/mimetypemapping.json +++ b/config/mimetypemapping.dist.json @@ -3,6 +3,9 @@ "_comment2": "The first index in the mime type array is the assumed correct mimetype", "_comment3": "and the second (if present] is a secure alternative", + "_comment4": "Any changes you make here will be overwritten on an update of ownCloud", + "_comment5": "Put any custom mappings in a new file mimetypemapping.json in this directory", + "3gp": ["video/3gpp"], "7z": ["application/x-7z-compressed"], diff --git a/lib/private/helper.php b/lib/private/helper.php index abe1e42ecb..09b319e90c 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -424,8 +424,15 @@ class OC_Helper { */ static public function getMimetypeDetector() { if (!self::$mimetypeDetector) { - $file = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); - $mimetypemapping = get_object_vars(json_decode($file)); + $dist = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.dist.json'); + $mimetypemapping = get_object_vars(json_decode($dist)); + + //Check if need to load custom mappings + if (file_exists(OC::$SERVERROOT . '/config/mimetypemapping.json')) { + $custom = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); + $custom_mapping = get_object_vars(json_decode($custom)); + $mimetypemapping = array_merge($mimetypemapping, $custom_mapping); + } self::$mimetypeDetector = new \OC\Files\Type\Detection(); self::$mimetypeDetector->registerTypeArray($mimetypemapping); From 8cac236135c4b07983e824c1ff0b9235aa0a0762 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 10 Jul 2015 13:37:26 +0200 Subject: [PATCH 3/3] Move to OC::$configDif --- lib/private/helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index 09b319e90c..8efa0284a1 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -424,12 +424,12 @@ class OC_Helper { */ static public function getMimetypeDetector() { if (!self::$mimetypeDetector) { - $dist = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.dist.json'); + $dist = file_get_contents(OC::$configDir . '/mimetypemapping.dist.json'); $mimetypemapping = get_object_vars(json_decode($dist)); //Check if need to load custom mappings - if (file_exists(OC::$SERVERROOT . '/config/mimetypemapping.json')) { - $custom = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); + if (file_exists(OC::$configDir . '/mimetypemapping.json')) { + $custom = file_get_contents(OC::$configDir . '/mimetypemapping.json'); $custom_mapping = get_object_vars(json_decode($custom)); $mimetypemapping = array_merge($mimetypemapping, $custom_mapping); }