7272if (!is_array ($ allowed_folders ))
7373 $ allowed_folders = array ();
7474
75+ /*
76+ * Get a list of windows drives
77+ */
78+ function get_windows_drives () {
79+ $ checklist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ' ;
80+ $ drives = array ();
81+ for ($ i = 0 ; $ i < strlen ($ d ); $ i ++) {
82+ if (is_dir ($ checklist [$ i ].': \\' )) {
83+ $ drives [] = $ checklist [$ i ].': \\' ;
84+ }
85+ }
86+ return $ drives ;
87+ }
88+
7589/*
7690 * Allowed folders in windows if none are set
7791 */
7892if (stripos ($ vbox ->vbox ->host ->operatingSystem ,'win ' ) === 0 && !count ($ allowed_folders )) {
79-
93+
8094 /*
81- * Get from WMIC. Assumes web server and vbox host are the same physical machine
95+ * Assumes web server and vbox host are the same physical machine
8296 */
8397 if ($ request ['fullpath ' ] && !$ settings ->forceWindowsAllDriveList && !$ settings ->noWindowsDriveList && stripos (PHP_OS ,'win ' ) === 0 ) {
84-
85- exec ("wmic logicaldisk get caption " , $ out );
86- if (is_array ($ out ) && count ($ out ) > 2 ) {
87-
88- $ allowed_folders = array ();
89-
90- // Shift off header
91- array_shift ($ out );
92-
93- // Shift off footer
94- array_pop ($ out );
95-
96- // These are now restricted folders
97- foreach ($ out as $ val ) {
98- $ allowed_folders [] = $ val . '\\' ;
99- }
100- }
101-
98+
99+
100+ $ allowed_folders = get_windows_drives ();
101+
102102 /*
103103 * Just show all C-Z drive letters if vboxhost is windows and our web server is not...
104104 */
109109 }
110110 }
111111 $ allowed_folders = array_combine ($ allowed_folders ,$ allowed_folders );
112-
112+
113113}
114114
115115
124124$ request ['dir ' ] = str_replace (DSEP .DSEP ,DSEP ,$ request ['dir ' ]);
125125
126126
127- /*
127+ /*
128128 * Check that folder restriction validates if it exists
129129 */
130130if ($ request ['dir ' ] != DSEP && count ($ allowed_folders )) {
147147
148148/* Folder Restriction with root '/' requested */
149149if ($ request ['dir ' ] == DSEP && count ($ allowed_folders )) {
150-
150+
151151 /* Just return restricted folders */
152152 foreach ($ allowed_folders as $ f ) {
153153 array_push ($ returnData , folder_entry ($ f , true ));
154-
154+
155155 }
156-
156+
157157} else {
158158
159159
160160 /* Full, expanded path to $dir */
161161 if ($ request ['fullpath ' ]) {
162-
163-
162+
163+
164164 /* Go through allowed folders if it is set */
165165 if (count ($ allowed_folders )) {
166-
167-
166+
167+
168168 foreach ($ allowed_folders as $ f ) {
169-
169+
170170 /* If this was not exactly the requested folder, but a parent,
171171 * list everything below it.
172172 */
173173 if ((strtoupper ($ request ['dir ' ]) != strtoupper ($ f )) && strpos (strtoupper ($ request ['dir ' ]),strtoupper ($ f )) === 0 ) {
174-
175-
174+
175+
176176 // List entries in this folder
177177 $ path = explode (DSEP ,substr ($ request ['dir ' ],strlen ($ f )));
178178
179179 // Folder entry
180180 array_push ($ returnData , getdir ($ f , $ request ['dirsOnly ' ], $ path ));
181181
182182 } else {
183-
183+
184184 array_push ($ returnData , folder_entry ($ f ,true ));
185185 }
186186 }
191191 // List entries in this folder
192192 $ path = explode (DSEP ,$ request ['dir ' ]);
193193 $ root = array_shift ($ path ).DSEP ;
194-
194+
195195 // Folder entry
196196 $ returnData = getdir ($ root , $ request ['dirsOnly ' ], $ path );
197197
198198 }
199-
199+
200200
201201 } else {
202-
202+
203203 /* Default action. Return dir requested */
204204 $ returnData = getdir ($ request ['dir ' ], $ request ['dirsOnly ' ]);
205205
206206 }
207-
207+
208208}
209209
210210header ('Content-type ' , 'application/json ' );
211- #echo("<pre>");
212- #print_r($returnData);
213211echo (json_encode ($ returnData ));
214212
215213
@@ -221,41 +219,41 @@ function getdir($dir, $dirsOnly=false, $recurse=array()) {
221219 if (!$ dir ) $ dir = DSEP ;
222220
223221 $ entries = getDirEntries ($ dir , $ dirsOnly );
224-
222+
225223 if (!count ($ entries ))
226224 return array ();
227-
225+
228226 $ dirents = array ();
229227 foreach ($ entries as $ path => $ type ) {
230-
228+
231229 if ($ type == 'folder ' && count ($ recurse ) && (strcasecmp ($ recurse [0 ],vbox_basename ($ path )) == 0 )) {
232230
233231 $ entry = folder_entry ($ path , false , true );
234-
232+
235233 $ entry ['children ' ] = getdir ($ dir .DSEP .array_shift ($ recurse ), $ dirsOnly , $ recurse );
236-
234+
237235 array_push ($ dirents , $ entry );
238-
236+
239237 } else {
240-
238+
241239 // Push folder on to stack
242240 if ($ type == 'folder ' ) {
243-
241+
244242 array_push ($ dirents , folder_entry ($ path ));
245-
243+
246244 // Push file on to stack
247245 } else {
248-
246+
249247 $ ext = strtolower (preg_replace ('/^.*\./ ' , '' , $ file ));
250248
251249 if (count ($ allowed ) && !$ allowed ['. ' .$ ext ]) continue ;
252-
250+
253251 array_push ($ dirents , file_entry ($ path ));
254252 }
255253 }
256-
254+
257255 }
258-
256+
259257 return $ dirents ;
260258
261259}
@@ -288,55 +286,55 @@ function folder_entry($f,$full=false,$expanded=false) {
288286
289287/**
290288 * Rreturn a list of directory entries
291- *
289+ *
292290 * @param String $dir
293291 * @return Array of entries
294292 */
295293
296294function getDirEntries ($ dir , $ foldersOnly =false ) {
297-
295+
298296 global $ localbrowser , $ allowed_exts , $ vbox ;
299-
297+
300298 // Append trailing slash if it isn't here
301299 if (substr ($ dir ,-1 ) != DSEP )
302300 $ dir .= DSEP ;
303-
304-
305- /*
301+
302+
303+ /*
306304 * Use local file / folder browser (PHP)
307305 */
308306 if ($ localbrowser ) {
309-
307+
310308 // If the dir doesn't exist or we can't scan it, just return
311309 if (!(file_exists ($ dir ) && ($ ents = @scandir ($ dir ))))
312310 return array ();
313-
311+
314312 $ newtypes = array ();
315313 $ newents = array ();
316314 for ($ i = 0 ; $ i < count ($ ents ); $ i ++) {
317-
315+
318316 // Skip . and ..
319317 if ($ ents [$ i ] == '. ' || $ ents [$ i ] == '.. ' )
320318 continue ;
321-
319+
322320 $ fullpath = $ dir .$ ents [$ i ];
323321 $ isdir = @is_dir ($ fullpath );
324-
322+
325323 if (!$ isdir && $ foldersOnly )
326324 continue ;
327-
325+
328326 array_push ($ newtypes , $ isdir ? 'folder ' : 'file ' );
329327 array_push ($ newents , $ fullpath );
330328 }
331329 return array_combine ($ newents , $ newtypes );
332-
330+
333331 /*
334332 * Use remote file / folder browser (vbox)
335333 */
336334 } else {
337-
335+
338336 try {
339-
337+
340338
341339 $ appl = $ vbox ->vbox ->createAppliance ();
342340 $ vfs = $ appl ->createVFSExplorer ('file:// ' .str_replace (DSEP .DSEP ,DSEP ,$ dir ));
@@ -346,35 +344,35 @@ function getDirEntries($dir, $foldersOnly=false) {
346344 list ($ ents ,$ types ) = $ vfs ->entryList ();
347345 $ vfs ->releaseRemote ();
348346 $ appl ->releaseRemote ();
349-
347+
350348 } catch (Exception $ e ) {
351-
349+
352350 echo ($ e ->getMessage ());
353-
351+
354352 return array ();
355-
353+
356354 }
357-
355+
358356 // Convert types to file / folder
359357 $ newtypes = array ();
360358 $ newents = array ();
361359 for ($ i = 0 ; $ i < count ($ types ); $ i ++) {
362-
360+
363361 // Skip . and ..
364362 if ($ ents [$ i ] == '. ' || $ ents [$ i ] == '.. ' )
365363 continue ;
366-
364+
367365 $ isdir = $ types [$ i ] == 4 ;
368-
366+
369367 if (!$ isdir && $ foldersOnly )
370368 continue ;
371-
369+
372370 array_push ($ newtypes , $ isdir ? 'folder ' : 'file ' );
373371 array_push ($ newents , $ dir .$ ents [$ i ]);
374372 }
375373 return array_combine ($ newents ,$ newtypes );
376-
374+
377375 }
378-
379-
376+
377+
380378}
0 commit comments