Skip to content

Commit ed956ee

Browse files
committed
* [ADD] Added mime type file checking instead of extension. Thanks to @vmario89 for the feedback. Related #825
* [MOD] Improved exception handling in controllers Signed-off-by: nuxsmin <[email protected]>
1 parent a159569 commit ed956ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+920
-175
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ app/temp/*
5252
app/plugins/*
5353
app/modules/**/plugins/*
5454
!app/config/actions.xml
55+
!app/config/mime.xml
5556
!app/config/*.inc
5657
res/*
5758
tools/

app/config/mime.xml

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<?xml version="1.0" standalone="yes"?>
2+
<!DOCTYPE mimetypes>
3+
<mimetypes>
4+
<mime multiple="1">
5+
<type>application/x-abiword</type>
6+
<description>AbiWord document</description>
7+
<extension>abw</extension>
8+
</mime>
9+
<mime multiple="1">
10+
<type>application/octet-stream</type>
11+
<description>Archive document (multiple files embedded)</description>
12+
<extension>arc</extension>
13+
</mime>
14+
<mime multiple="1">
15+
<type>application/vnd.amazon.ebook</type>
16+
<description>Amazon Kindle eBook format</description>
17+
<extension>azw</extension>
18+
</mime>
19+
<mime multiple="1">
20+
<type>application/octet-stream</type>
21+
<description>Any kind of binary data</description>
22+
<extension>bin</extension>
23+
</mime>
24+
<mime multiple="1">
25+
<type>image/bmp</type>
26+
<description>Windows OS/2 Bitmap Graphics</description>
27+
<extension>bmp</extension>
28+
</mime>
29+
<mime multiple="1">
30+
<type>application/x-bzip</type>
31+
<description>BZip archive</description>
32+
<extension>bz</extension>
33+
</mime>
34+
<mime multiple="1">
35+
<type>application/x-bzip2</type>
36+
<description>BZip2 archive</description>
37+
<extension>bz2</extension>
38+
</mime>
39+
<mime multiple="1">
40+
<type>application/x-csh</type>
41+
<description>C-Shell script</description>
42+
<extension>csh</extension>
43+
</mime>
44+
<mime multiple="1">
45+
<type>text/csv</type>
46+
<description>Comma-separated values (CSV)</description>
47+
<extension>csv</extension>
48+
</mime>
49+
<mime multiple="1">
50+
<type>application/msword</type>
51+
<description>Microsoft Word</description>
52+
<extension>doc</extension>
53+
</mime>
54+
<mime multiple="1">
55+
<type>application/vnd.openxmlformats-officedocument.wordprocessingml.document</type>
56+
<description>Microsoft Word (OpenXML)</description>
57+
<extension>docx</extension>
58+
</mime>
59+
<mime multiple="1">
60+
<type>application/vnd.ms-fontobject</type>
61+
<description>MS Embedded OpenType fonts</description>
62+
<extension>eot</extension>
63+
</mime>
64+
<mime multiple="1">
65+
<type>application/epub+zip</type>
66+
<description>Electronic publication (EPUB)</description>
67+
<extension>epub</extension>
68+
</mime>
69+
<mime multiple="1">
70+
<type>image/gif</type>
71+
<description>Graphics Interchange Format (GIF)</description>
72+
<extension>gif</extension>
73+
</mime>
74+
<mime multiple="1">
75+
<type>text/html</type>
76+
<description>HyperText Markup Language (HTML)</description>
77+
<extension>html</extension>
78+
</mime>
79+
<mime multiple="1">
80+
<type>text/calendar</type>
81+
<description>iCalendar format</description>
82+
<extension>ics</extension>
83+
</mime>
84+
<mime multiple="1">
85+
<type>application/java-archive</type>
86+
<description>Java Archive (JAR)</description>
87+
<extension>jar</extension>
88+
</mime>
89+
<mime multiple="1">
90+
<type>image/jpeg</type>
91+
<description>JPEG images</description>
92+
<extension>jpg</extension>
93+
</mime>
94+
<mime multiple="1">
95+
<type>application/json</type>
96+
<description>JSON format</description>
97+
<extension>json</extension>
98+
</mime>
99+
<mime multiple="1">
100+
<type>application/vnd.apple.installer+xml</type>
101+
<description>Apple Installer Package</description>
102+
<extension>mpkg</extension>
103+
</mime>
104+
<mime multiple="1">
105+
<type>application/vnd.oasis.opendocument.presentation</type>
106+
<description>OpenDocument presentation document</description>
107+
<extension>odp</extension>
108+
</mime>
109+
<mime multiple="1">
110+
<type>application/vnd.oasis.opendocument.spreadsheet</type>
111+
<description>OpenDocument spreadsheet document</description>
112+
<extension>ods</extension>
113+
</mime>
114+
<mime multiple="1">
115+
<type>application/vnd.oasis.opendocument.text</type>
116+
<description>OpenDocument text document</description>
117+
<extension>odt</extension>
118+
</mime>
119+
<mime multiple="1">
120+
<type>image/png</type>
121+
<description>Portable Network Graphics</description>
122+
<extension>png</extension>
123+
</mime>
124+
<mime multiple="1">
125+
<type>application/pdf</type>
126+
<description>Adobe Portable Document Format (PDF)</description>
127+
<extension>pdf</extension>
128+
</mime>
129+
<mime multiple="1">
130+
<type>application/vnd.ms-powerpoint</type>
131+
<description>Microsoft PowerPoint</description>
132+
<extension>ppt</extension>
133+
</mime>
134+
<mime multiple="1">
135+
<type>application/vnd.openxmlformats-officedocument.presentationml.presentation</type>
136+
<description>Microsoft PowerPoint (OpenXML)</description>
137+
<extension>pptx</extension>
138+
</mime>
139+
<mime multiple="1">
140+
<type>application/x-rar-compressed</type>
141+
<description>RAR archive</description>
142+
<extension>rar</extension>
143+
</mime>
144+
<mime multiple="1">
145+
<type>application/rtf</type>
146+
<description>Rich Text Format (RTF)</description>
147+
<extension>rtf</extension>
148+
</mime>
149+
<mime multiple="1">
150+
<type>application/x-sh</type>
151+
<description>Bourne shell script</description>
152+
<extension>sh</extension>
153+
</mime>
154+
<mime multiple="1">
155+
<type>image/svg+xml</type>
156+
<description>Scalable Vector Graphics (SVG)</description>
157+
<extension>svg</extension>
158+
</mime>
159+
<mime multiple="1">
160+
<type>application/x-tar</type>
161+
<description>Tape Archive (TAR)</description>
162+
<extension>tar</extension>
163+
</mime>
164+
<mime multiple="1">
165+
<type>text/plain</type>
166+
<description>Text, (generally ASCII or ISO 8859-n)</description>
167+
<extension>txt</extension>
168+
</mime>
169+
<mime multiple="1">
170+
<type>application/vnd.visio</type>
171+
<description>Microsoft Visio</description>
172+
<extension>vsd</extension>
173+
</mime>
174+
<mime multiple="1">
175+
<type>application/xhtml+xml</type>
176+
<description>XHTML</description>
177+
<extension>xhtml</extension>
178+
</mime>
179+
<mime multiple="1">
180+
<type>application/vnd.ms-excel</type>
181+
<description>Microsoft Excel</description>
182+
<extension>xls</extension>
183+
</mime>
184+
<mime multiple="1">
185+
<type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</type>
186+
<description>Microsoft Excel (OpenXML)</description>
187+
<extension>xlsx</extension>
188+
</mime>
189+
<mime multiple="1">
190+
<type>application/xml</type>
191+
<description>XML</description>
192+
<extension>xml</extension>
193+
</mime>
194+
<mime multiple="1">
195+
<type>application/vnd.mozilla.xul+xml</type>
196+
<description>XUL</description>
197+
<extension>xul</extension>
198+
</mime>
199+
<mime multiple="1">
200+
<type>application/zip</type>
201+
<description>ZIP archive</description>
202+
<extension>zip</extension>
203+
</mime>
204+
<mime multiple="1">
205+
<type>application/x-7z-compressed</type>
206+
<description>7-zip archive</description>
207+
<extension>7z</extension>
208+
</mime>
209+
</mimetypes>

app/config/strings.js.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ return [
4242
16 => __('Your browser does not support HTML5 file uploads'),
4343
17 => __('Too many files'),
4444
18 => __('File size not allowed'),
45-
19 => __('Extension not allowed'),
45+
19 => __('MIME type not allowed'),
4646
20 => __('Clear the event log out?'),
4747
21 => __('Select Group'),
4848
22 => __('Select User'),

app/modules/web/Controllers/AccountController.php

+36
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public function indexAction()
9292
} catch (\Exception $e) {
9393
processException($e);
9494

95+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
96+
9597
ErrorUtil::showExceptionInView($this->view, $e);
9698
}
9799
}
@@ -115,6 +117,8 @@ public function searchAction()
115117
} catch (\Exception $e) {
116118
processException($e);
117119

120+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
121+
118122
return $this->returnJsonResponseException($e);
119123
}
120124
}
@@ -163,6 +167,8 @@ public function viewAction($id)
163167
} catch (\Exception $e) {
164168
processException($e);
165169

170+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
171+
166172
ErrorUtil::showExceptionInView($this->view, $e, 'account');
167173
}
168174
}
@@ -239,6 +245,8 @@ public function viewLinkAction($hash)
239245
} catch (\Exception $e) {
240246
processException($e);
241247

248+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
249+
242250
ErrorUtil::showExceptionInView($this->view, $e, 'account-link');
243251
}
244252
}
@@ -320,6 +328,8 @@ public function copyAction($id)
320328
} catch (\Exception $e) {
321329
processException($e);
322330

331+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
332+
323333
ErrorUtil::showExceptionInView($this->view, $e, 'account');
324334
}
325335
}
@@ -368,6 +378,8 @@ public function editAction($id)
368378
} catch (\Exception $e) {
369379
processException($e);
370380

381+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
382+
371383
ErrorUtil::showExceptionInView($this->view, $e, 'account');
372384
}
373385
}
@@ -413,6 +425,8 @@ public function deleteAction($id = null)
413425
} catch (\Exception $e) {
414426
processException($e);
415427

428+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
429+
416430
ErrorUtil::showExceptionInView($this->view, $e, 'account');
417431
}
418432
}
@@ -458,6 +472,8 @@ public function editPassAction($id)
458472
} catch (\Exception $e) {
459473
processException($e);
460474

475+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
476+
461477
ErrorUtil::showExceptionInView($this->view, $e, 'account-editpass');
462478
}
463479
}
@@ -503,6 +519,8 @@ public function viewHistoryAction($id)
503519
} catch (\Exception $e) {
504520
processException($e);
505521

522+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
523+
506524
ErrorUtil::showExceptionInView($this->view, $e, 'account-history');
507525
}
508526
}
@@ -537,6 +555,8 @@ public function requestAccessAction($id)
537555
} catch (\Exception $e) {
538556
processException($e);
539557

558+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
559+
540560
ErrorUtil::showExceptionInView($this->view, $e, 'account-request');
541561
}
542562
}
@@ -578,6 +598,8 @@ public function viewPassAction($id, $parentId = 0)
578598
} catch (\Exception $e) {
579599
processException($e);
580600

601+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
602+
581603
return $this->returnJsonResponseException($e);
582604
}
583605
}
@@ -636,6 +658,8 @@ public function viewPassHistoryAction($id)
636658
} catch (\Exception $e) {
637659
processException($e);
638660

661+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
662+
639663
return $this->returnJsonResponseException($e);
640664
}
641665
}
@@ -762,6 +786,8 @@ public function saveCreateAction()
762786
} catch (\Exception $e) {
763787
processException($e);
764788

789+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
790+
765791
return $this->returnJsonResponseException($e);
766792
}
767793
}
@@ -809,6 +835,8 @@ public function saveEditAction($id)
809835
} catch (\Exception $e) {
810836
processException($e);
811837

838+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
839+
812840
return $this->returnJsonResponseException($e);
813841
}
814842
}
@@ -852,6 +880,8 @@ public function saveEditPassAction($id)
852880
} catch (\Exception $e) {
853881
processException($e);
854882

883+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
884+
855885
return $this->returnJsonResponseException($e);
856886
}
857887
}
@@ -891,6 +921,8 @@ public function saveEditRestoreAction($historyId, $id)
891921
} catch (\Exception $e) {
892922
processException($e);
893923

924+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
925+
894926
return $this->returnJsonResponseException($e);
895927
}
896928
}
@@ -936,6 +968,8 @@ public function saveDeleteAction($id)
936968
} catch (\Exception $e) {
937969
processException($e);
938970

971+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
972+
939973
return $this->returnJsonResponseException($e);
940974
}
941975
}
@@ -986,6 +1020,8 @@ public function saveRequestAction($id)
9861020
} catch (\Exception $e) {
9871021
processException($e);
9881022

1023+
$this->eventDispatcher->notifyEvent('exception', new Event($e));
1024+
9891025
return $this->returnJsonResponseException($e);
9901026
}
9911027
}

0 commit comments

Comments
 (0)