-
Notifications
You must be signed in to change notification settings - Fork 65
/
convertCore.php
2241 lines (2157 loc) · 147 KB
/
convertCore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<?php
// / -----------------------------------------------------------------------------------
// / COPYRIGHT INFORMATION ...
// / HRConvert2, Copyright on 6/9/2024 by Justin Grimes, www.github.com/zelon88
// /
// / LICENSE INFORMATION ...
// / This project is protected by the GNU GPLv3 Open-Source license.
// / https://www.gnu.org/licenses/gpl-3.0.html
// /
// / APPLICATION INFORMATION ...
// / This application is designed to provide a web-interface for converting file formats
// / on a server for users of any web browser without authentication.
// /
// / FILE INFORMATION ...
// / v3.3.7.
// / This file contains the core logic of the application.
// /
// / HARDWARE REQUIREMENTS ...
// / This application requires at least a Raspberry Pi Model B+ or greater.
// / This application will run on just about any x86 or x64 computer.
// /
// / DEPENDENCY REQUIREMENTS ...
// / This application requires Debian Linux (w/3rd Party audio license),
// / Apache 2.4, PHP 8+, LibreOffice, Unoconv, ClamAV, Tesseract, Rar, Unrar, Unzip,
// / 7zipper, FFMPEG, PDFTOTEXT, Dia, PopplerUtils, MeshLab, Mkisofs & ImageMagick.
// /
// / <3 Open-Source
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to reset PHP's time limit for execution.
function setTimeLimit() {
$TimeReset = set_time_limit(0);
return $TimeReset; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set the date & time for the session.
function verifyTime() {
// / Set variables.
global $TimeIsSet, $Date, $Time;
$TimeIsSet = FALSE;
$tzAbbreviations = DateTimeZone::listAbbreviations();
$tzList = array();
// / Build a list of timezones supported by this PHP installation.
foreach ($tzAbbreviations as $zone) foreach ($zone as $item) if (is_string($item['timezone_id']) && $item['timezone_id'] !== '') $tzList[] = $item['timezone_id'];
$tzList = array_unique($tzList);
$zoneList = array_values($tzList);
// / Check that the currently set timezone is valid.
if (in_array(@date_default_timezone_get(), $zoneList)) $TimeIsSet = TRUE;
// / Try to set the time regardless of whether or not the timezone is correct.
$Date = date("m_d_y");
$Time = date("F j, Y, g:i a");
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$tzAbbreviations = $tzList = $zoneList = $zone = $item = NULL;
unset($tzAbbreviations, $tzList, $zoneList, $zone, $item);
return array($TimeIsSet, $Date, $Time); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to sanitize input strings with varying degrees of tolerance.
// / Filters a given string of | \ ~ # [ ] ( ) { } ; : $ ! # ^ & % @ > * < " / '
// / This function will replace any of the above specified charcters with NOTHING. No character at all. An empty string.
// / This function will replace whitespace with the underscore character.
// / Set $strict to TRUE to also filter out backslash characters as well. Example: /
function sanitizeString($Variable, $strict) {
if ($strict) $Variable = htmlentities(trim(str_replace(' ', '_', str_replace('..', '', str_replace('//', '', str_replace(str_split('|\\~#[](){};:$!#^&%@>*<"\'/'), '', $Variable))))), ENT_QUOTES, 'UTF-8');
if (!$strict) $Variable = htmlentities(trim(str_replace(' ', '_', str_replace('..', '', str_replace('//', '', str_replace(str_split('|\\[](){};"\''), '', $Variable))))), ENT_QUOTES, 'UTF-8');
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$strict = NULL;
unset($strict);
return $Variable; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to sanitize input strings or arrays with varying degrees of tolerance.
// / Filters a given string of | \ ~ # [ ] ( ) { } ; : $ ! # ^ & % @ > * < " / '
// / This function will replace any of the above specified charcters with NOTHING. No character at all. An empty string.
// / This function will replace whitespace with the underscore character.
// / Set $strict to TRUE to also filter out backslash characters as well. Example: /
function sanitize($Variable, $strict) {
// / Set variables.
$VariableIsSanitized = TRUE;
$var = '';
$key = 0;
if (!is_bool($strict)) $strict = TRUE;
// / Only continue if the input variable is a type that we can properly sanitize.
if (!is_string($Variable) && !is_numeric($Variable) && !is_array($Variable)) $VariableIsSanitized = FALSE;
else {
// / Sanitize array inputs.
// / Note that when $strict is TRUE this also filters out backslashes.
if (is_array($Variable)) foreach ($Variable as $key => $var) $Variable[$key] = sanitizeString($Variable[$key], $strict);
// / Sanitize string & numeric inputs.
// / Note that when $strict is TRUE this also filters out backslashes.
if (is_string($Variable) or is_numeric($Variable)) $Variable = sanitizeString($Variable, $strict); }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$strict = $key = $var = NULL;
unset($strict, $key, $var);
return array($Variable, $VariableIsSanitized); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to load required HRConvert2 files.
function verifyInstallation() {
// / Set variables.
global $Salts1, $Salts2, $Salts3, $Salts4, $Salts5, $Salts6, $URL, $VirusScan, $AllowUserVirusScan, $InstLoc, $ServerRootDir, $ConvertLoc, $LogDir, $ApplicationName, $ApplicationTitle, $SupportedLanguages, $DefaultLanguage, $AllowUserSelectableLanguage, $SupportedGuis, $DefaultGui, $AllowUserSelectableGui, $DeleteThreshold, $Verbose, $MaxLogSize, $Font, $ButtonStyle, $DefaultColor, $SupportedColors, $AllowUserSelectableColor, $ColorToUse, $ShowGUI, $ShowFinePrint, $TOSURL, $PPURL, $ScanCoreMemoryLimit, $ScanCoreChunkSize, $ScanCoreDebug, $ScanCoreVerbose, $SpinnerStyle, $SpinnerColor, $URL, $AllowUserShare, $SupportedConversionTypes, $VersionInfoFile, $Version, $DeleteBuildEnvironment, $DeleteDevelopmentDocumentation, $UserArchiveArray, $UserDearchiveArray, $UserDocumentArray, $UserSpreadsheetArray, $UserPresentationArray, $UserImageArray, $UserMediaInputArray, $UserMediaOutputArray, $UserVideoInputArray, $UserVideoOutputArray, $UserStreamArray, $UserDrawingArray, $UserModelArray, $UserSubtitleInputArray, $UserSubtitleOutputArray, $UserPDFWorkArr, $RARArchiveMethod, $RetryCount;
// / Define absolute paths for files that we only have relative paths for.
$InstallationIsVerified = $buildDirDeleted = $dockerFileDeleted = $readmeDeleted = $changelogFileDeleted = $buildEnvDeleted = $devDocsDeleted = $checkOne = $checkTwo = FALSE;
$ConfigFile = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config.php');
$VersionInfoFile = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'versionInfo.php');
$dockerFile = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'Documentation'.DIRECTORY_SEPARATOR.'Build'.DIRECTORY_SEPARATOR.'Dockerfile');
$changelogFile = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'Documentation'.DIRECTORY_SEPARATOR.'CHANGELOG.txt');
$readmeFile = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'README.md');
$buildDir = realpath(dirname(__DIR__).DIRECTORY_SEPARATOR.'Build');
// / Check for required files & stop execution if they are missing.
if (!file_exists($ConfigFile)) die ('ERROR!!! HRConvert2-0: Could not process the HRConvert2 Configuration file (config.php)!'.PHP_EOL.'<br />');
else require_once ($ConfigFile);
if (!file_exists($VersionInfoFile)) die ('ERROR!!! HRConvert2-24000: Could not process the HRConvert2 Version Information file (versionInfo.php)!'.PHP_EOL.'<br />');
else require_once ($VersionInfoFile);
// / Delete the build environment if specified by config.php.
if ($DeleteBuildEnvironment) {
if (is_dir($buildDir)) $buildDirDeleted = cleanFiles($buildDir);
if (file_exists($dockerFile)) $dockerFileDeleted = unlink($dockerFile);
if ($buildDirDeleted && $dockerFileDeleted) $buildEnvDeleted = TRUE; }
// / Delete the development environment if specified by config.php.
if ($DeleteDevelopmentDocumentation) {
if (file_exists($changelogFile)) $changelogFileDeleted = unlink($changelogFile);
if (file_exists($readmeFile)) $readmeDeleted = unlink($readmeFile);
if ($changelogFileDeleted && $readmeDeleted) $devDocsDeleted = TRUE; }
// / Perform a check to see if any required operations failed.
if ($DeleteBuildEnvironment) if (!$buildEnvDeleted) $checkOne = TRUE;
if ($DeleteDevelopmentDocumentation) if (!$devDocsDeleted) $checkTwo = TRUE;
// / Installation is considered verified when check one & check two are both false.
if (!$checkOne && !$checkTwo) $InstallationIsVerified = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$buildDir = $buildDirDeleted = $dockerFile = $dockerFileDeleted = $readmeFile = $readmeDeleted = $changelogFile = $changelogFileDeleted = $buildEnvDeleted = $devDocsDeleted = $checkOne = $checkTwo = NULL;
unset($buildDir, $buildDirDeleted, $dockerFile, $dockerFileDeleted, $readmeFile, $readmeDeleted, $changelogFile, $changelogFileDeleted, $buildEnvDeleted, $devDocsDeleted, $checkOne, $checkTwo);
return array($InstallationIsVerified, $ConfigFile, $Version); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to attempt to detect the users IP so it can be used as an identifier for the session.
function verifySession() {
// / Set variables.
$IP = '';
$HashedUserAgent = hash('sha256', $_SERVER['HTTP_USER_AGENT']);
$SessionIsVerified = TRUE;
// / Detect an IP that we can use as an identifier for the session.
if (!empty($_SERVER['HTTP_CLIENT_IP'])) $IP = htmlentities(str_replace(str_split('~#[](){};:$!#^&%@>*<"\''), '', $_SERVER['HTTP_CLIENT_IP']), ENT_QUOTES, 'UTF-8');
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $IP = htmlentities(str_replace(str_split('~#[](){};:$!#^&%@>*<"\''), '', $_SERVER['HTTP_X_FORWARDED_FOR']), ENT_QUOTES, 'UTF-8');
else $IP = htmlentities(str_replace('..', '', str_replace(str_split('~#[](){};:$!#^&%@>*<"\''), '', $_SERVER['REMOTE_ADDR'])), ENT_QUOTES, 'UTF-8');
return array($SessionIsVerified, $IP, $HashedUserAgent); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to define the $SesHash related variables for the session.
function verifySesHash($IP, $HashedUserAgent) {
// / Set variables.
global $Date, $Salts1, $Salts2, $Salts3, $Salts4, $Salts5, $Salts6, $Token1;
if (is_string($Salts1) && is_string($Salts2) && is_string($Salts3) && is_string($Salts4) && is_string($Salts4) && is_string($Salts5) && is_string($Salts6)) {
$SesHashIsVerified = TRUE;
$SesHash = substr(hash('ripemd160', $Date.$Salts1.$Salts2.$Salts3.$Salts4.$Salts5.$Salts6), -12);
$SesHash2 = substr(hash('ripemd160', $SesHash.$Token1.$Date.$IP.$HashedUserAgent.$Salts1.$Salts2.$Salts3.$Salts4.$Salts5.$Salts6), -12);
$SesHash3 = $SesHash.'/'.$SesHash2;
$SesHash4 = hash('ripemd160', $Salts6.$Salts5.$Salts4.$Salts3.$Salts2.$Salts1); }
else $SesHashIsVerified = $SesHash = $SesHash2 = $SesHash3 = $SesHash4 = FALSE;
return array($SesHashIsVerified, $SesHash, $SesHash2, $SesHash3, $SesHash4); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to create a logfile if one does not exist.
function verifyLogs() {
// / Set variables.
global $LogDir, $LogFile, $MaxLogSize, $InstLoc, $SesHash, $SesHash4, $DefaultLogDir, $DefaultLogSize, $Time, $Date, $LogInc, $LogInc2, $MaxLogSize, $LogDir, $LogFile, $VirusScan, $ApplicationName, $PermissionLevels;
$LogExists = $logWritten = FALSE;
$LogInc = $LogInc2 = 0;
$LogFile = str_replace('..', '', $LogDir.'/'.$ApplicationName.'_'.$LogInc.'_'.$Date.'_'.$SesHash4.'_'.$SesHash.'.txt');
$DefaultLogDir = $InstLoc.'/Logs';
$DefaultLogSize = 1048576;
$ClamLogFile = str_replace('..', '', $LogDir.'/ClamLog_'.$LogInc2.'_'.$Date.'_'.$SesHash4.'_'.$SesHash.'.txt');
if (!is_numeric($MaxLogSize)) $MaxLogSize = $DefaultLogSize;
if (!is_dir($LogDir)) @mkdir($LogDir, $PermissionLevels);
if (!is_dir($LogDir)) $LogDir = $DefaultLogDir;
if (!is_dir($LogDir)) die('ERROR!!! '.$Time.': '.$ApplicationName.'-3, The log directory does not exist at '.$LogDir.'.');
if (!file_exists($LogDir.'/index.html')) @copy('index.html', $LogDir.'/index.html');
// / Create a log file depending on whether or not the max filesize has been reached.
while (file_exists($LogFile) && round((filesize($LogFile) / $MaxLogSize), 2) > $MaxLogSize) {
$LogInc++;
$LogFile = str_replace('..', '', $LogDir.'/'.$ApplicationName.'_'.$LogInc.'_'.$Date.'_'.$SesHash4.'_'.$SesHash.'.txt');
$logWritten = file_put_contents($LogFile, 'OP-Act, '.$Time.': Logfile created using method 0.'.PHP_EOL, FILE_APPEND); }
if (!file_exists($LogFile)) $logWritten = file_put_contents($LogFile, 'OP-Act, '.$Time.': Logfile created using method 1.'.PHP_EOL, FILE_APPEND);
if (file_exists($LogFile)) $LogExists = TRUE;
// / Set a clamlog file depending on whether or not the max filesize has been reached, but do not create one yet.
if ($VirusScan) {
while (file_exists($ClamLogFile) && round((filesize($ClamLogFile) / $MaxLogSize), 2) > $MaxLogSize) {
$LogInc2++;
$LogFile = str_replace('..', '', $LogDir.'/ClamLog_'.$LogInc2.'_'.$Date.'_'.$SesHash4.'_'.$SesHash.'.txt'); } }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$logWritten = NULL;
unset($logWritten);
return array($LogExists, $LogFile, $ClamLogFile); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to format a log entry & write it to the logfile.
function logEntry($entry) {
// / Set variables.
global $Time, $LogFile, $SesHash3;
$LogWritten = FALSE;
// / Format the input string into a log entry & write it to the $LogFile.
$LogWritten = file_put_contents($LogFile, 'Op-Act, '.$Time.', '.$SesHash3.': '.$entry.PHP_EOL, FILE_APPEND);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$entry = NULL;
unset($entry);
return $LogWritten; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to format an error entry & write it to the logfile.
function errorEntry($entry, $errorNumber, $die) {
// / Set variables.
global $Time, $LogFile, $SesHash3, $ApplicationName;
$LogWritten = FALSE;
// / Format the error number into a unique error identifier.
if (!is_numeric($errorNumber)) $errorNumber = $ApplicationName.'-###';
else $errorNumber = $ApplicationName.'-'.$errorNumber;
// / Format the input string into a log entry with the error number & write it to the $LogFile.
$LogWritten = file_put_contents($LogFile, 'ERROR!!! '.$Time.', '.$errorNumber.', '.$SesHash3.': '.$entry.PHP_EOL, FILE_APPEND);
if ($die) die('ERROR!!! '.$Time.' '.$errorNumber.': '.$entry.PHP_EOL);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$entry = $errorNumber = $die = NULL;
unset($entry, $errorNumber, $die);
return $LogWritten; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set an echo variable that adjusts printed URL's to https when SSL is enabled.
function verifyEncryption() {
$EncryptionVerified = TRUE;
// / Determine if the connection is encrypted and adjust the $URLEcho accordingly.
if (!empty($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == 443) $URLEcho = 's';
else $URLEcho = '';
return array($EncryptionVerified, $URLEcho); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set or validate a Token so it can be used as a unique identifier for the session.
function verifyTokens($Token1, $Token2) {
// / Verify variables.
global $Salts1, $Salts2, $Salts3, $Salts4, $Salts5, $Salts6;
$TokensAreValid = TRUE;
// / Check that tokens are valid & set them if they are not.
if (!isset($Token1) or $Token1 === '' or strlen($Token1) < 19) $Token1 = hash('ripemd160', rand(0, 1000000000).rand(0, 1000000000));
if (isset($Token2)) if ($Token2 !== hash('ripemd160', $Token1.$Salts1.$Salts2.$Salts3.$Salts4.$Salts5.$Salts6)) $TokensAreValid = FALSE;
if (!isset($Token2) or $Token2 === '' or strlen($Token2) < 19) $Token2 = hash('ripemd160', $Token1.$Salts1.$Salts2.$Salts3.$Salts4.$Salts5.$Salts6);
return array($TokensAreValid, $Token1, $Token2); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to verify that all required POST & GET inputs are properly sanitized.
function verifyInputs() {
// / Set variables.
$var = FALSE;
$InputsAreVerified = TRUE;
$GUI = $Color = $Language = $Token1 = $Token2 = $Height = $Width = $Rotate = $Bitrate = $Method = $Download = $UserFilename = $UserExtension = $Archive = $UserScanType = $ScanAll = $UserClamScan = $UserScanCoreScan = $var = '';
$variableIsSanitized = $ConvertSelected = $PDFWorkSelected = $FilesToArchive = $FilesToScan = $FilesToDelete = array();
$key = 0;
$ScanType = 'all';
// / Sanitize each variable as needed & build a list of error check results.
if (isset($_POST['noGui'])) $_GET['noGui'] = TRUE;
if (isset($_POST['filesToDelete'])) list ($FilesToDelete, $variableIsSanitized[$key++]) = sanitize($_POST['filesToDelete'], TRUE);
if (isset($_POST['language'])) list ($Language, $variableIsSanitized[$key++]) = sanitize($_POST['language'], TRUE);
if (isset($_GET['language'])) list ($Language, $variableIsSanitized[$key++]) = sanitize($_GET['language'], TRUE);
if (isset($_POST['color'])) list ($Color, $variableIsSanitized[$key++]) = sanitize($_POST['color'], TRUE);
if (isset($_GET['color'])) list ($Color, $variableIsSanitized[$key++]) = sanitize($_GET['color'], TRUE);
if (isset($_POST['gui'])) list ($GUI, $variableIsSanitized[$key++]) = sanitize($_POST['gui'], TRUE);
if (isset($_GET['gui'])) list ($GUI, $variableIsSanitized[$key++]) = sanitize($_GET['gui'], TRUE);
if (isset($_POST['Token1'])) list ($Token1, $variableIsSanitized[$key++]) = sanitize($_POST['Token1'], TRUE);
if (isset($_POST['Token2'])) list ($Token2, $variableIsSanitized[$key++]) = sanitize($_POST['Token2'], TRUE);
if (isset($_POST['height'])) list ($Height, $variableIsSanitized[$key++]) = sanitize($_POST['height'], TRUE);
if (isset($_POST['width'])) list ($Width, $variableIsSanitized[$key++]) = sanitize($_POST['width'], TRUE);
if (isset($_POST['rotate'])) list ($Rotate, $variableIsSanitized[$key++]) = sanitize($_POST['rotate'], TRUE);
if (isset($_POST['bitrate'])) list ($Bitrate, $variableIsSanitized[$key++]) = sanitize($_POST['bitrate'], TRUE);
if (isset($_POST['method'])) list ($Method, $variableIsSanitized[$key++]) = sanitize($_POST['method'], TRUE);
if (isset($_POST['download'])) list ($Download, $variableIsSanitized[$key++]) = sanitize($_POST['download'], TRUE);
if (isset($_POST['archive'])) list ($Archive, $variableIsSanitized[$key++]) = sanitize($_POST['archive'], TRUE);
if (isset($_POST['extension'])) list ($UserExtension, $variableIsSanitized[$key++]) = sanitize($_POST['extension'], TRUE);
if (isset($_POST['filesToArchive'])) list ($FilesToArchive, $variableIsSanitized[$key++]) = sanitize($_POST['filesToArchive'], TRUE);
if (isset($_POST['archextension'])) list ($UserExtension, $variableIsSanitized[$key++]) = sanitize($_POST['archextension'], TRUE);
if (isset($_POST['userfilename'])) list ($UserFilename, $variableIsSanitized[$key++]) = sanitize($_POST['userfilename'], TRUE);
if (isset($_POST['userconvertfilename'])) list ($UserFilename, $variableIsSanitized[$key++]) = sanitize($_POST['userconvertfilename'], TRUE);
if (isset($_POST['pdfworkSelected'])) list ($PDFWorkSelected, $variableIsSanitized[$key++]) = sanitize($_POST['pdfworkSelected'], TRUE);
if (isset($_POST['convertSelected'])) list ($ConvertSelected, $variableIsSanitized[$key++]) = sanitize($_POST['convertSelected'], TRUE);
if (isset($_POST['pdfextension'])) list ($UserExtension, $variableIsSanitized[$key++]) = sanitize($_POST['pdfextension'], TRUE);
if (isset($_POST['userpdfconvertfilename'])) list ($UserFilename, $variableIsSanitized[$key++]) = sanitize($_POST['userpdfconvertfilename'], TRUE);
if (isset($_POST['scanallbutton'])) list ($ScanAll, $variableIsSanitized[$key++]) = sanitize($_POST['scanallbutton'], TRUE);
if (isset($_POST['scantype'])) list ($UserScanType, $variableIsSanitized[$key++]) = sanitize($_POST['scantype'], TRUE);
if (isset($_POST['clamscanbutton'])) list ($UserClamScan, $variableIsSanitized[$key++]) = sanitize($_POST['clamscanbutton'], TRUE);
if (isset($_POST['scancorebutton'])) list ($UserScanCoreScan, $variableIsSanitized[$key++]) = sanitize($_POST['scancorebutton'], TRUE);
if (isset($_POST['filesToScan'])) list ($FilesToScan, $variableIsSanitized[$key++]) = sanitize($_POST['filesToScan'], TRUE);
// / Handle when a user submits User Virus Scan options.
if (isset($_POST['clamScanButton']) && isset($_POST['filesToScan'])) $ScanType = 'clamav';
if (isset($_POST['scancorebutton']) && isset($_POST['filesToScan'])) $ScanType = 'scancore';
if (isset($_POST['scanallbutton']) && isset($_POST['filesToScan'])) $ScanType = 'all';
// / Check the list of error check results and see if any errors occured.
foreach ($variableIsSanitized as $var) if (!$var) ($InputsAreVerified = FALSE);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$variableIsSanitized = $key = $var = NULL;
unset($variableIsSanitized, $key, $var);
return array($InputsAreVerified, $GUI, $Color, $Language, $Token1, $Token2, $Height, $Width, $Rotate, $Bitrate, $Method, $Download, $UserFilename, $UserExtension, $FilesToArchive, $PDFWorkSelected, $ConvertSelected, $FilesToScan, $FilesToDelete, $UserScanType); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set the styles to use for the session.
function verifyColors($ButtonStyle) {
// / Set variables.
global $ButtonStyle, $Color, $SupportedColors, $AllowUserSelectableColor, $ColorToUse, $GreenButtonCode, $BlueButtonCode, $RedButtonCode, $DefaultButtonCode;
$ColorsAreSet = FALSE;
$ColorToUse = 'blue';
$ButtonStyle = strtolower($ButtonStyle);
$ButtonCode = $DefaultButtonCode;
$validColors = array('green', 'blue', 'red', 'grey');
// / Make sure $SupportedColors is valid.
if (!isset($SupportedColors) or !is_array($SupportedColors)) $SupportedColors = $validColors;
// / Make sure the Default Color is valid.
if (isset($ButtonStyle)) if (in_array($ButtonStyle, $SupportedColors)) $ColorToUse = $ButtonStyle;
// / If allowed and if specified, detect the users specified color and set that as the color to use.
if (isset($AllowUserSelectableColor)) {
if ($AllowUserSelectableColor) if (isset($Color)) if (in_array($Color, $SupportedColors)) {
$ColorToUse = $Color; }
if (!$AllowUserSelectableColor) $ButtonStyle = $DefaultColor; }
// / Set the $Color variable to whatever the current color is so the next page will use the same one.
$_GET['color'] = $ColorToUse;
// / Validate the desired color and set it as the color to use if possible.
if (in_array($ColorToUse, $validColors)) {
$ColorsAreSet = TRUE;
if ($ColorToUse === 'green') $ButtonCode = $GreenButtonCode;
if ($ColorToUse === 'blue') $ButtonCode = $BlueButtonCode;
if ($ColorToUse === 'red') $ButtonCode = $RedButtonCode;
if ($ColorToUse === 'grey') $ButtonCode = $DefaultButtonCode; }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$validColors = NULL;
unset($validColors);
return array($ColorsAreSet, $ButtonCode); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set the GUI to use for the session.
function verifyGui() {
// / Set variables.
global $GUI, $DefaultGui, $SupportedGuis, $AllowUserSelectableGui, $GuiFiles, $GuiDir, $GuiResourcesDir, $GuiImageDir, $GuiCSSDir, $GuiJSDir, $GuiHeaderFile, $GuiFooterFile, $GuiUI1File, $GuiUI2File, $GreenButtonCode, $BlueButtonCode, $RedButtonCode, $DefaultButtonCode, $Font;
$defaultGui = $reqFile = $variableIsSanitized = FALSE;
$GuiIsSet = TRUE;
$GuiToUse = 'Default';
$GuiFiles = $guiFiles = array();
$defaultGuis = array('Default');
// / Make sure $SupportedGuis is valid.
if (!isset($SupportedGuis) or !is_array($SupportedGuis)) $SupportedGuis = $defaultGuis;
// / Make sure the Default GUI is valid.
if (isset($DefaultGui)) if (in_array($DefaultGui, $SupportedGuis)) $GuiToUse = $DefaultGui;
// / If allowed and if specified, detect the users specified GUI and set that as the GUI to use.
if (isset($AllowUserSelectableGui)) {
if ($AllowUserSelectableGui) if (isset($GUI)) if (in_array($GUI, $SupportedGuis)) {
$GuiToUse = $GUI; }
if (!$AllowUserSelectableGui) $GuiToUse = $DefaultGui; }
// / Set the $GUI variable to whatever the current GUI is so the next page will use the same one.
$_GET['gui'] = $GuiToUse;
// / Set the variables to a URL safe relative path to required UI files.
$GuiDir = 'UI/'.$GuiToUse.'/';
$StyleCoreFile = $GuiDir.'styleCore.php';
$GuiHeaderFile = $GuiDir.'header.php';
$GuiFooterFile = $GuiDir.'footer.php';
$GuiUI1File = $GuiDir.'convertGui1.php';
$GuiUI2File = $GuiDir.'convertGui2.php';
$GuiResourcesDir = $GuiDir.'Resources/';
$GuiImageDir = $GuiResourcesDir.'Image/';
$GuiCSSDir = $GuiResourcesDir.'CSS/';
$GuiJSDir = $GuiResourcesDir.'JS/';
$guiFiles = array($GuiHeaderFile, $GuiFooterFile, $GuiUI1File, $GuiUI2File, $StyleCoreFile);
// / Verify that the required GUI folder exists.
if (is_dir($GuiDir)) $GuiIsSet = TRUE;
// / Verify that required GUI files exist.
foreach ($guiFiles as $reqFile) if (file_exists($reqFile)) array_push($GuiFiles, $reqFile);
// / Determine if the styleCore.php file is part of the desired GUI, and load it if required.
if (in_array($StyleCoreFile, $GuiFiles)) {
// / Load the styleCore.php file.
require_once($StyleCoreFile);
// / Set the variables for required color data.
$GreenButtonCode = $greenButtonCode;
$BlueButtonCode = $blueButtonCode;
$RedButtonCode = $redButtonCode;
$DefaultButtonCode = $defaultButtonCode; }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$defaultGuis = $reqFile = $guiFiles = $greenButtonCode = $blueButtonCode = $redButtonCode = $defaultButtonCode = NULL;
unset($defaultGuis, $reqFile, $guiFiles, $greenButtonCode, $blueButtonCode, $redButtonCode, $defaultButtonCode);
return array($GuiIsSet, $GuiToUse, $GuiDir, $GuiFiles); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set the language to use for the session.
function verifyLanguage() {
// / Set variables.
global $Language, $DefaultLanguage, $SupportedLanguages, $AllowUserSelectableLanguage, $LanguageFiles, $GuiDir, $LanguageDir, $LanguageStringsFile, $Language;
$defaultLanguages = $reqFile = $variableIsSanitized = FALSE;
$LanguageIsSet = TRUE;
$LanguageToUse = 'en';
$LanguageFiles = $languageFiles = array();
$defaultLanguages = array('en', 'fr', 'es', 'zh', 'hi', 'ar', 'ru', 'uk', 'bn', 'de', 'ko', 'it', 'pt');
// / Make sure $SupportedLanguages is valid.
if (!isset($SupportedLanguages) or !is_array($SupportedLanguages)) $SupportedLanguages = $defaultLanguages;
// / Make sure the Default Language is valid.
if (isset($DefaultLanguage)) if (in_array($DefaultLanguage, $SupportedLanguages)) $LanguageToUse = $DefaultLanguage;
// / If allowed and if specified, detect the users specified language and set that as the language to use.
if (isset($AllowUserSelectableLanguage)) {
if ($AllowUserSelectableLanguage) if (isset($Language)) if (in_array($Language, $SupportedLanguages)) {
$LanguageToUse = $Language; }
if (!$AllowUserSelectableLanguage) $LanguageToUse = $DefaultLanguage; }
// / Set the $Language variable to whatever the current language is so the next page will use the same one.
$_GET['language'] = $LanguageToUse;
// / Set the variables to required UI files.
$LanguageDir = $GuiDir.'Languages/'.$LanguageToUse.'/';
$LanguageStringsFile = $LanguageDir.'languageStrings.php';
$languageFiles = array($LanguageStringsFile);
// / Verify that the required langauge folder exists.
if (!is_dir($LanguageDir)) $LanguageIsSet = FALSE;
// / Verify that required language files exist.
if (file_exists($LanguageStringsFile)) $LanguageIsSet = TRUE;
foreach ($languageFiles as $reqFile) if (file_exists($reqFile)) array_push($LanguageFiles, $reqFile);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$defaultLanguages = $reqFile = $variableIsSanitized = $languageFiles = NULL;
unset($defaultLanguages, $reqFile, $variableIsSanitized, $languageFiles);
return array($LanguageIsSet, $LanguageToUse, $LanguageDir, $LanguageFiles); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to reliably sanitize a path or URL of dangerous strings.
function securePath($PathToSecure, $DangerArr, $isURL) {
// / Set variables.
global $DirSep;
// / Loop through each dangerous file & remove it from the supplied path.
foreach ($DangerArr as $dArr) $PathToSecure = str_replace($dArr, '', $PathToSecure);
// / Remove double directory separatorsthat may have been created during the last step.
$PathToSecure = str_replace($DirSep.$DirSep, $DirSep, str_replace($DirSep.$DirSep, $DirSep, str_replace('..', '', $PathToSecure)));
// / Detect if the path is a URL & remove double directory separators that may exist.
if ($isURL) $PathToSecure = str_replace($DirSep, '/', $PathToSecure);
// / Rempve double dots that may have been created during the last step.
$PathToSecure = str_replace('..', '', $PathToSecure);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$dArr = $isURL = NULL;
unset($dArr, $isURL);
return $PathToSecure; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to set the global variables for the session.
function verifyGlobals() {
// / Set global variables to be used through the entire application.
global $URL, $URLEcho, $HRConvertVersion, $Date, $Time, $SesHash, $SesHash2, $SesHash3, $SesHash4, $CoreLoaded, $ConvertDir, $InstLoc, $ConvertTemp, $ConvertTempDir, $ConvertGuiCounter1, $DefaultApps, $RequiredDirs, $RequiredIndexes, $DangerousFiles, $Allowed, $ArchiveArray, $DearchiveArray, $DocumentArray, $SpreadsheetArray, $PresentationArray, $ImageArray, $MediaInputArray, $MediaOutputArray, $VideoInputArray, $VideoOutputArray, $StreamArray, $DrawingArray, $ModelArray, $SubtitleInputArray, $SubtitleOutputArray, $PDFWorkArr, $ConvertLoc, $DirSep, $SupportedConversionTypes, $Lol, $Lolol, $Append, $PathExt, $ConsolidatedLogFileName, $ConsolidatedLogFile, $Alert, $Alert1, $Alert2, $Alert3, $FCPlural, $FCPlural1, $FCPlural2, $FCPlural3, $UserClamLogFile, $UserClamLogFileName, $UserScanCoreLogFile, $UserScanCoreFileName, $SpinnerStyle, $SpinnerColor, $FullURL, $ServerRootDir, $StopCounter, $SleepTimer, $PermissionLevels, $ApacheUser, $File, $HeaderDisplayed, $UIDisplayed, $FooterDisplayed, $LanguageStringsLoaded, $GUIDisplayed, $Version, $GUIDirection, $SupportedFormatCount, $GUIAlignment, $GreenButtonCode, $BlueButtonCode, $RedButtonCode, $DefaultButtonCode, $UserArchiveArray, $UserDearchiveArray, $UserDocumentArray, $UserSpreadsheetArray, $UserPresentationArray, $UserImageArray, $UserMediaInputArray, $UserMediaOutputArray, $UserVideoInputArray, $UserVideoOutputArray, $UserStreamArray, $UserDrawingArray, $UserModelArray, $UserSubtitleInputArray, $UserSubtitleOutputArray, $UserPDFWorkArr, $RetryCount;
// / Application related variables.
$HRConvertVersion = 'v3.3.7';
$GlobalsAreVerified = FALSE;
$CoreLoaded = TRUE;
$SleepTimer = 0;
$StopCounter = $RetryCount;
$PermissionLevels = 0755;
$ApacheUser = 'www-data';
// / Convinience variables.
$DirSep = DIRECTORY_SEPARATOR;
$Lol = PHP_EOL;
$Lolol = $Lolol;
$Append = FILE_APPEND;
$PathExt = PATHINFO_EXTENSION;
// / UI Related variables.
$ConvertGuiCounter1 = 0;
$File = $FCPlural = $FCPlural1 = $FCPlural2 = $FCPlural3 = $GreenButtonCode = $BlueButtonCode = $RedButtonCode = $DefaultButtonCode = '';
$HeaderDisplayed = $UIDisplayed = $FooterDisplayed =$LanguageStringsLoaded = $GUIDisplayed = FALSE;
$GUIDirection = 'ltr';
$GUIAlignment = 'left';
$Alert = 'Cannot convert this file! Try changing the name.';
$Alert1 = 'Cannot perform a virus scan on this file!';
$Alert2 = 'File Link Copied to Clipboard!';
$Alert3 = 'Operation Failed!';
// / Security related variables.
$DefaultApps = array('.', '..');
$DangerousFiles = array('js', 'php', '.html', 'css', 'phar', '.', '..', 'index.php', 'index.html');
// / URL related variables.
$subDir = securePath(str_replace($ServerRootDir.$DirSep, '', $InstLoc), $DangerousFiles, TRUE);
$partURL = securePath($URL.'/'.$subDir, $DangerousFiles, TRUE);
$FullURL = 'http'.$URLEcho.'://'.$partURL;
// / Directory related variables.
$convertDir0 = securePath($ConvertLoc.$DirSep.$SesHash, $DangerousFiles, $DangerousFiles, FALSE);
$ConvertDir = securePath($convertDir0.$DirSep.$SesHash2.$DirSep, $DangerousFiles, FALSE);
$ConvertTemp = securePath($InstLoc.'/DATA', $DangerousFiles, FALSE);
$convertTempDir0 = securePath($ConvertTemp.$DirSep.$SesHash, $DangerousFiles, FALSE);
$ConvertTempDir = securePath($convertTempDir0.$DirSep.$SesHash2.$DirSep, $DangerousFiles, FALSE);
$RequiredDirs = array($convertDir0, $ConvertDir, $ConvertTemp, $convertTempDir0, $ConvertTempDir);
$RequiredIndexes = array($ConvertTemp, $convertTempDir0, $ConvertTempDir);
// / A/V related variables.
$UserClamLogFileName = 'User_ClamScan_Virus_Scan_Report.txt';
$UserClamLogFile = $ConvertDir.$UserClamLogFileName;
$UserScanCoreFileName = 'User_ScanCore_Virus_Scan_Report.txt';
$UserScanCoreLogFile = $ConvertDir.$UserScanCoreFileName;
$ConsolidatedLogFileName = 'User_Consolidated_Virus_Scan_Report.txt';
$ConsolidatedLogFile = $ConvertTempDir.$ConsolidatedLogFileName;
// / Format related variables.
$ArchiveArray = $DearchiveArray = $DocumentArray = $SpreadsheetArray = $PresentationArray = $ImageArray = $MediaArray = $VideoArray = $StreamArray = $DrawingArray = $ModelArray = $SubtitleArray = $PDFWorkArr = array();
if (in_array('Archive', $SupportedConversionTypes)) $ArchiveArray = $UserArchiveArray;
if (in_array('Archive', $SupportedConversionTypes)) $DearchiveArray = $UserDearchiveArray;
if (in_array('Document', $SupportedConversionTypes)) $DocumentArray = $UserDocumentArray;
if (in_array('Document', $SupportedConversionTypes)) $SpreadsheetArray = $UserSpreadsheetArray;
if (in_array('Document', $SupportedConversionTypes)) $PresentationArray = $UserPresentationArray;
if (in_array('Image', $SupportedConversionTypes)) $ImageArray = $UserImageArray;
if (in_array('Audio', $SupportedConversionTypes)) $MediaInputArray = $UserMediaInputArray;
if (in_array('Audio', $SupportedConversionTypes)) $MediaOutputArray = $UserMediaOutputArray;
if (in_array('Video', $SupportedConversionTypes)) $VideoInputArray = $UserVideoInputArray;
if (in_array('Video', $SupportedConversionTypes)) $VideoOutputArray = $UserVideoOutputArray;
if (in_array('Stream', $SupportedConversionTypes) && in_array('Audio', $SupportedConversionTypes)) $StreamArray = $UserStreamArray;
if (in_array('Drawing', $SupportedConversionTypes)) $DrawingArray = $UserDrawingArray;
if (in_array('Model', $SupportedConversionTypes)) $ModelArray = $UserModelArray;
if (in_array('Subtitle', $SupportedConversionTypes)) $SubtitleInputArray = $UserSubtitleInputArray;
if (in_array('Subtitle', $SupportedConversionTypes)) $SubtitleOutputArray = $UserSubtitleOutputArray;
if (in_array('OCR', $SupportedConversionTypes) && in_array('Document', $SupportedConversionTypes)) $PDFWorkArr = $UserPDFWorkArr;
$Allowed = array_unique(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge(array_merge($ArchiveArray, $DearchiveArray), $DocumentArray), $SpreadsheetArray), $PresentationArray), $ImageArray), $MediaInputArray), $VideoInputArray), $StreamArray), $DrawingArray), $ModelArray), $SubtitleInputArray), $PDFWorkArr));
$SupportedFormatCount = count($Allowed);
// / Perform a version integrity check.
if ($HRConvertVersion === $Version) $GlobalsAreVerified = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$convertDir0 = $convertTempDir0 = $subDir = $partURL = NULL;
unset($convertDir0, $convertTempDir0, $subDir, $partURL);
return array($GlobalsAreVerified, $CoreLoaded); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to sanitize & verifie an array of files.
function getFiles($pathToFiles) {
// / Set variables.
global $DangerousFiles, $DirSep, $PathExt;
$Files = $dirtyFileArr = array();
if (is_dir($pathToFiles)) $dirtyFileArr = @scandir($pathToFiles);
// / Iterate through each detected file & make sure it's not dangerous before adding it to the output array.
foreach ($dirtyFileArr as $dirtyFile) {
$dirtyExt = pathinfo($pathToFiles.$DirSep.$dirtyFile, $PathExt);
// / Make sure the file is safe to handle.
if (in_array(strtolower($dirtyExt), $DangerousFiles) or is_dir($pathToFiles.$DirSep.$dirtyFile)) continue;
array_push($Files, $dirtyFile); }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$dirtyFile = $pathToFiles = $dirtyFileArr = NULL;
unset($dirtyFile, $pathToFiles, $dirtyFileArr);
return $Files; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to return the extension to a specified file.
function getExtension($pathToFile) {
// / Set variables.
global $PathExt;
$Pathinfo = pathinfo($pathToFile, $PathExt);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$pathToFile = NULL;
unset($pathToFile);
return $Pathinfo; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to return the filesize of a specified file.
function getFilesize($File) {
// / Set variables.
$Size = @filesize($File);
// / Determine the most efficient unit of measure to represent the specified value in.
if ($Size < 1024) $Size = $Size." Bytes";
elseif (($Size < 1048576) && ($Size > 1023)) $Size = round($Size / 1024, 1)." KB";
elseif (($Size < 1073741824) && ($Size > 1048575)) $Size = round($Size / 1048576, 1)." MB";
else $Size = round($Size/1073741824, 1)." GB";
return $Size; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to return the file time of a specified symlink.
function symlinkmtime($symlinkPath) {
// / Set variables.
$Stat = @lstat($symlinkPath);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$symlinkPath = NULL;
unset($symlinkPath);
return isset($Stat['mtime']) ? $Stat['mtime'] : NULL; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to return the file time of a specified file.
// / Only returns a value if the specified file exists.
function fileTime($filePath) {
if (file_exists($filePath)) $Stat = @filemtime($filePath);
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$filePath = NULL;
unset($filePath);
return $Stat; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to test if a folder is empty.
// / Returns TRUE when a folder is empty.
// / Returns FALSE when a folder is not empty.
function is_dir_empty($dir) {
// / Set variables.
$Check = TRUE;
// / Make sure the selected directory is actually a directory.
if (is_dir($dir)) {
// / Gather the contents of the directory.
$contents = scandir($dir);
// / Iterate through the contents of the directory & break once any valid file is found.
foreach ($contents as $content) if ($content == '.' or $content == '..') $Check = FALSE; }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$dir = $contents = $content = NULL;
unset($dir, $contents, $content);
return $Check; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to scan an input file or folder for viruses with ClamAV.
function virusScan($path) {
// / Set variables.
global $Verbose, $ClamLogFile, $AllowUserVirusScan, $Lol, $Lolol, $ApplicationName;
$ScanComplete = TRUE;
$VirusFound = FALSE;
$returnData = '';
$returnData = shell_exec(str_replace(' ', ' ', str_replace(' ', ' ', 'clamscan -r '.$path.' | grep FOUND >> '.$ClamLogFile)));
$clamLogFileDATA = @file_get_contents($ClamLogFile);
// / Check if ClamAV found an infection in the specified file.
if (strpos($clamLogFileDATA, 'Virus Detected') !== FALSE or strpos($clamLogFileDATA, 'FOUND') !== FALSE) {
$ScanComplete = $virusFound = TRUE;
// / If the specified file exists, is infected, is not a directory, & $AllowUserVirusScan is set to FALSE then delete the infected file.
if (file_exists($path)) if (is_file($path) && !is_dir($path) && !$AllowUserVirusScan) @unlink($path);
errorEntry('There were potentially infected files detected at '.$path.'!', 500, FALSE);
errorEntry('ClamAV output the following: '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))), 501, TRUE); }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $clamLogFileDATA = $path = NULL;
unset($returnData, $clamLogFileDATA, $path);
return array($ScanComplete, $VirusFound); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to create required directories if they do not exist.
function verifyRequiredDirs() {
// / Set variables.
global $ConvertLoc, $RequiredDirs, $RequiredIndexes, $Time, $LogFile, $Verbose, $PermissionLevels;
$RequiredDirsExist = FALSE;
// / If the $ConvertLoc does not exist we stop execution rather than create one.
if (!is_dir($ConvertLoc)) errorEntry('The specified Data Storage Directory does not exist at '.$ConvertLoc.'!', 1000, TRUE);
// / Iterate through the array of required directories.
foreach ($RequiredDirs as $requiredDir) {
// / Check that the currently selected directory exists.
if (!is_dir($requiredDir)) {
if ($Verbose) logEntry('Created a directory at '.$requiredDir.'.');
// / Try to create the currently selected directory.
@mkdir($requiredDir, $PermissionLevels); }
// / Re-check to see if our attempt to create the directory was successful & log the result.
if (is_dir($requiredDir)) $RequiredDirsExist = TRUE;
else errorEntry('Could not create a directory at '.$requiredDir.'!', 1001, TRUE); }
// / Make sure that each required directory has an index.html file for document root protection.
foreach ($RequiredIndexes as $requiredIndex) @copy('index.html', $requiredIndex.'/index.html');
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$requiredDir = $requiredIndex = $MAKELogFile = NULL;
unset($requiredDir, $requiredIndex, $MAKELogFile);
return array($RequiredDirsExist, $RequiredDirs); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to clean a selection of files.
// / Recursively deletes files.
// / This function is extremely dangerous! Please handle with care.
function cleanFiles($path) {
// / Set variables.
global $ConvertLoc, $ConvertTemp, $DefaultApps, $DirSep;
$variableIsSanitized = $i = $f = $CleanSuccess = $pathCheck = $loopCheck = FALSE;
list ($path, $variableIsSanitized) = sanitize($path, FALSE);
// / Make sure the selected directory is actually a directory.
if ($variableIsSanitized && is_dir($path)) {
$i = array_diff(scandir($path), array('..', '.'));
// / Iterate through each file object in the directory.
foreach ($i as $f) {
// / If the selected file object is a file, delete it.
if (is_file($path.$DirSep.$f) && !in_array(basename($path.$DirSep.$f), $DefaultApps)) @unlink($path.$DirSep.$f);
// / If the selected file object is a directory, try to delete it.
if (is_dir($path.$DirSep.$f) && !in_array(basename($path.$DirSep.$f), $DefaultApps) && is_dir_empty($path)) @rmdir($path.$DirSep.$f);
// / If the selected file object is a directory that still exists, run this function on it to remove any file objects it contains.
if (is_dir($path.$DirSep.$f) && !in_array(basename($path.$DirSep.$f), $DefaultApps) && !is_dir_empty($path)) $loopCheck = cleanFiles($path.$DirSep.$f); }
// / Once all file objects in the selected directory have been deleted, attempt to delete the selected directory.
if ($path !== $ConvertLoc && $path !== $ConvertTemp) @rmdir($path); }
// / Check if the function was successful. Note that $ConvertLoc and $ConvertTemp locations are not deleted..
$pathCheck = is_dir($path);
if ($pathCheck) if (is_dir_empty($path)) $CleanSuccess = TRUE;
if (!$pathCheck) $CleanSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$path = $i = $f = $variableIsSanitized = $pathCheck = $loopCheck = NULL;
unset($path, $i, $f, $variableIsSanitized, $pathCheck, $loopCheck);
return $CleanSuccess; }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to clean up old files in the $TempLoc.
function cleanTempLoc() {
// / Set variables.
global $ConvertTemp, $DeleteThreshold, $DefaultApps, $DirSep, $PermissionLevels;
$TempLocDeepCleaned = FALSE;
$CleanedTempLoc = $loopCheck = TRUE;
// / Make sure the directory to be scanned exists.
if (file_exists($ConvertTemp)) {
$dFiles = array_diff(scandir($ConvertTemp), array('..', '.'));
$now = time();
// / Iterate through each subfolder in the directory.
foreach ($dFiles as $dFile) {
// / Validate the folder.
if (in_array($dFile, $DefaultApps)) continue;
$dFilePath = $ConvertTemp.$DirSep.$dFile;
if ($dFilePath == $ConvertTemp.'/index.html') continue;
// / See if the folder is due for deletion.
if ($now - fileTime($dFilePath) > ($DeleteThreshold * 60)) {
// / If the folder is due to be deleted, recursively delete it.
if (is_dir($dFilePath)) {
$TempLocDeepCleaned = TRUE;
@chmod ($dFilePath, $PermissionLevels);
$loopCheck = cleanFiles($dFilePath);
if (is_dir_empty($dFilePath)) @rmdir($dFilePath); } }
// / Check if the most recent iteration of the loop was successful.
if (!$loopCheck) $CleanedTempLoc = FALSE; $loopCheck = TRUE; } }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$dFiles = $dFile = $dFilePath = $now = $loopCheck = NULL;
unset($dFiles, $dFile, $dFilePath, $now, $loopCheck);
return array($CleanedTempLoc, $TempLocDeepCleaned); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to clean up old files in the $ConvertLoc.
function cleanConvertLoc() {
// / Set variables.
global $ConvertLoc, $DeleteThreshold, $DefaultApps, $DirSep, $PermissionLevels;
$ConvertLocDeepCleaned = FALSE;
$CleanedConvertLoc = $loopCheck = TRUE;
// / Make sure the directory to be scanned exists.
if (file_exists($ConvertLoc)) {
$dFiles = array_diff(scandir($ConvertLoc), array('..', '.'));
$now = time();
// / Iterate through each subfolder in the directory.
foreach ($dFiles as $dFile) {
// / Validate the folder.
if (in_array($dFile, $DefaultApps)) continue;
$dFilePath = $ConvertLoc.$DirSep.$dFile;
// / See if the folder is due for deletion.
if ($now - fileTime($dFilePath) > ($DeleteThreshold * 60)) {
// / If the folder is due to be deleted, recursively delete it.
if (is_dir($dFilePath)) {
$ConvertLocDeepCleaned = TRUE;
@chmod ($dFilePath, $PermissionLevels);
$loopCheck = cleanFiles($dFilePath);
if (is_dir_empty($dFilePath)) @rmdir($dFilePath); } }
// / Check if the most recent iteration of the loop was successful.
if (!$loopCheck) $CleanedConvertLoc = FALSE; $loopCheck = TRUE; } }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$dFiles = $dFile = $dFilePath = $now = $loopCheck = NULL;
unset($dFiles, $dFile, $dFilePath, $now, $loopCheck);
return array($CleanedConvertLoc, $ConvertLocDeepCleaned); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to verify that the document conversion engine is installed & running.
function verifyDocumentConversionEngine() {
// / Set variables.
global $Verbose, $Lol, $Lolol;
$DocEnginePID = 0;
$DocumentEngineStarted = FALSE;
$returnData = '';
// / Determine if the document conversion engine (Unoconv) is installed.
if (!file_exists('/usr/bin/unoconv')) errorEntry('Could not verify the document conversion engine installation at /usr/bin/unoconv!', 2000, TRUE);
if (file_exists('/usr/bin/unoconv')) {
if ($Verbose) logEntry('Verified the document conversion engine installation.');
$DocEnginePID = shell_exec('pgrep soffice.bin');
if ($Verbose) logEntry('The document conversion engine PID is: '.str_replace($Lol, '', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($DocEnginePID)))));
// / Determine if the document conversion engine is already running.
if ($DocEnginePID === 0 or $DocEnginePID === '' or $DocEnginePID === NULL or !$DocEnginePID) {
// / Try to start the document conversion engine.
if ($Verbose)logEntry('Starting the document conversion engine.');
$returnData = shell_exec('/usr/bin/unoconv -l &');
if ($Verbose && trim($returnData) !== '') logEntry('The document conversion engine PID is: '.str_replace($Lol, '', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($DocEnginePID))))); } }
$DocumentEnginePID = trim($DocEnginePID);
// / Write the document engine PID to the log file.
if ($DocEnginePID !== 0 && $DocEnginePID !== '' && $DocEnginePID !== NULL) {
$DocumentEngineStarted = TRUE;
if ($Verbose) logEntry('The document conversion engine is running.'); }
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = NULL;
unset($returnData);
return array($DocumentEngineStarted, $DocEnginePID); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert document formats.
function convertDocuments($pathname, $newPathname, $extension) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
// / The following code verifies that the document conversion engine is installed & running.
list ($documentEngineStarted, $documentEnginePID) = verifyDocumentConversionEngine();
if (!$documentEngineStarted) {
$ConversionErrors = TRUE;
errorEntry('Could not verify the document conversion engine!', 7000, FALSE); }
else if ($Verbose) logEntry('Verified the document conversion engine.');
// / The following code performs the actual document conversion.
if ($documentEngineStarted) {
if ($Verbose) logEntry('Converting document.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('unoconv -o '.$newPathname.' -f '.$extension.' '.$pathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The document converter timed out!', 7001, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('Unoconv returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData))))); }
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$stopper = $pathname = $newPathname = $extension = $returnData = $documentEngineStarted = $documentEnginePID = $sleepTime = NULL;
unset($stopper, $pathname, $newPathname, $extension, $returnData, $documentEngineStarted, $documentEnginePID, $sleepTime);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert image formats.
function convertImages($pathname, $newPathname, $height, $width, $rotate) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = $imgMethod = FALSE;
$returnData = $wh = '';
$stopper = $whx = 0;
$sleepTime = $SleepTimer;
// / Validate the height, width, & rotate arguments.
if (!is_numeric($height) or $height === FALSE) $height = 0;
if (!is_numeric($width) or $width === FALSE) $width = 0;
if (!is_numeric($rotate) or $rotate === FALSE) '-rotate '.$rotate;
$wxh = $width.'x'.$height;
if ($wxh == '0x0' or $wxh =='x0' or $wxh == '0x' or $wxh == '0' or $wxh == '00' or $wxh == '' or $wxh == ' ') $wh = '';
else $wh = '-resize '.$wxh.' ';
if ($Verbose) logEntry('Converting image.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('convert -background none '.$wh.$rotate.' '.$pathname.' '.$newPathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The image converter timed out!', 8000, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('ImageMagick returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))));
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $stopper = $pathname = $newPathname = $height = $width = $extension = $wxh = $rotate = $imgMethod = $wh = $sleepTime = NULL;
unset($returnData, $stopper, $pathname, $newPathname, $height, $width, $extension, $wxh, $rotate, $imgMethod, $wh, $sleepTime);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert 3D model formats.
function convertModels($pathname, $newPathname) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
if ($Verbose) logEntry('Converting model.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('meshlabserver -i '.$pathname.' -o '.$newPathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The model converter timed out!', 9000, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('Meshlab returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))));
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $stopper = $pathname = $newPathname = NULL;
unset($returnData, $stopper, $pathname, $newPathname);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert 2D vector drawing formats.
function convertDrawings($pathname, $newPathname) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
if ($Verbose) logEntry('Converting drawing.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('dia '.$pathname.' -e '.$newPathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The drawing converter timed out!', 10000, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('Dia returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))));
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $stopper = $pathname = $newPathname = $sleepTime = NULL;
unset($returnData, $stopper, $pathname, $newPathname, $sleepTime);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert video formats.
function convertVideos($pathname, $newPathname) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
if ($Verbose) logEntry('Converting video.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('ffmpeg -i '.$pathname.' -c:v libx264 '.$newPathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The video converter timed out!', 11000, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('Ffmpeg returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))));
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $stopper = $pathname = $newPathname = $sleepTime = NULL;
unset($returnData, $stopper, $pathname, $newPathname, $sleepTime);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert subtitle formats.
function convertSubtitles($pathname, $newPathname) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
if ($Verbose) logEntry('Converting subtitle.');
// / This code will attempt the conversion up to $StopCounter number of times.
while (!file_exists($newPathname) && $stopper <= $StopCounter) {
// / If the last conversion attempt failed, wait a moment before trying again.
if ($stopper !== 0) sleep($sleepTime++);
// / Attempt the conversion.
$returnData = shell_exec('ffmpeg -i '.$pathname.' '.$newPathname);
// / Count the number of conversions to avoid infinite loops.
$stopper++;
// / Stop attempting the conversion after $StopCounter number of attempts.
if ($stopper === $StopCounter) {
$ConversionErrors = TRUE;
errorEntry('The subtitle converter timed out!', 22000, FALSE); } }
if ($Verbose && trim($returnData) !== '') logEntry('Ffmpeg returned the following: '.$Lol.' '.str_replace($Lol, $Lol.' ', str_replace($Lolol, $Lol, str_replace($Lolol, $Lol, trim($returnData)))));
if (file_exists($newPathname)) $ConversionSuccess = TRUE;
// / Manually clean up sensitive memory. Helps to keep track of variable assignments.
$returnData = $stopper = $pathname = $newPathname = $sleepTime = NULL;
unset($returnData, $stopper, $pathname, $newPathname, $sleepTime);
return array($ConversionSuccess, $ConversionErrors); }
// / -----------------------------------------------------------------------------------
// / -----------------------------------------------------------------------------------
// / A function to convert stream formats.
function convertStreams($pathname, $newPathname) {
// / Set variables.
global $Verbose, $Lol, $Lolol, $StopCounter, $SleepTimer;
$ConversionSuccess = $ConversionErrors = FALSE;
$returnData = '';
$stopper = 0;
$sleepTime = $SleepTimer;
if ($Verbose) logEntry('Converting stream.');