@@ -2288,6 +2288,9 @@ function ddosProtection() {
2288
2288
//progressive timeout-> more requests, longer timeout
2289
2289
$ active_connections = count ($ _SESSION ['bruteForceBlock ' ]);
2290
2290
$ timeoutReal = ($ active_connections / $ maxCon ) < 1 ? 0 : ($ active_connections / $ maxCon ) * $ secondTimeout ;
2291
+ if ($ timeoutReal ){
2292
+ _error_log ("ddosProtection:: progressive timeout timeoutReal = ( $ timeoutReal) active_connections = ( $ active_connections) maxCon = ( $ maxCon) " , AVideoLog::$ SECURITY );
2293
+ }
2291
2294
sleep ($ timeoutReal );
2292
2295
2293
2296
//with strict mode, penalize "attacker" with sleep() above, log and then die
@@ -2906,6 +2909,7 @@ function getUsageFromFilename($filename, $dir = "") {
2906
2909
_error_log ("getUsageFromFilename: start {$ dir }{$ filename }" );
2907
2910
$ files = glob ("{$ dir }{$ filename }* " );
2908
2911
session_write_close ();
2912
+ $ filesProcessed = array ();
2909
2913
foreach ($ files as $ f ) {
2910
2914
if (is_dir ($ f )) {
2911
2915
_error_log ("getUsageFromFilename: {$ f } is Dir " );
@@ -2940,11 +2944,19 @@ function getUsageFromFilename($filename, $dir = "") {
2940
2944
}
2941
2945
if (!empty ($ urls ['mp4 ' ])) {
2942
2946
foreach ($ urls ['mp4 ' ] as $ mp4 ) {
2947
+ if (in_array ($ mp4 , $ filesProcessed )){
2948
+ continue ;
2949
+ }
2950
+ $ filesProcessed [] = $ mp4 ;
2943
2951
$ filesize += getUsageFromURL ($ mp4 );
2944
2952
}
2945
2953
}
2946
2954
if (!empty ($ urls ['webm ' ])) {
2947
2955
foreach ($ urls ['webm ' ] as $ mp4 ) {
2956
+ if (in_array ($ mp4 , $ filesProcessed )){
2957
+ continue ;
2958
+ }
2959
+ $ filesProcessed [] = $ mp4 ;
2948
2960
$ filesize += getUsageFromURL ($ mp4 );
2949
2961
}
2950
2962
}
@@ -3314,6 +3326,15 @@ function wget($url, $filename) {
3314
3326
return false ;
3315
3327
}
3316
3328
wgetLock ($ url );
3329
+ if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
3330
+ $ content = file_get_contents ($ url );
3331
+ if (file_put_contents ($ filename , $ content ) > 100 ){
3332
+ wgetRemoveLock ($ url );
3333
+ return true ;
3334
+ }
3335
+ wgetRemoveLock ($ url );
3336
+ return false ;
3337
+ }
3317
3338
$ cmd = "wget {$ url } -O {$ filename } --no-check-certificate " ;
3318
3339
//_error_log("wget Start ({$cmd}) ");
3319
3340
//echo $cmd;
@@ -3375,17 +3396,36 @@ function isWritable($dir) {
3375
3396
return $ result ;
3376
3397
}
3377
3398
3399
+ function _isWritable ($ dir ){
3400
+ if (!isWritable ($ dir )) {
3401
+ return false ;
3402
+ }
3403
+ $ tmpFile = "{$ dir }" . uniqid ();
3404
+ $ bytes = file_put_contents ($ tmpFile , time ());
3405
+ @unlink ($ tmpFile );
3406
+ return !empty ($ bytes );
3407
+ }
3408
+
3378
3409
function getTmpDir ($ subdir = "" ) {
3379
3410
global $ global ;
3380
- $ tmpDir = sys_get_temp_dir ();
3381
- if (!isWritable ($ tmpDir )) {
3382
- $ tmpDir = "{$ global ['systemRootPath ' ]}videos/cache/ " ;
3383
- }
3384
- $ tmpDir = rtrim ($ tmpDir , '/ ' ) . '/ ' ;
3385
- $ tmpDir = "{$ tmpDir }{$ subdir }" ;
3386
- $ tmpDir = rtrim ($ tmpDir , '/ ' ) . '/ ' ;
3387
- if (!is_dir ($ tmpDir )) {
3388
- mkdir ($ tmpDir , 0755 , true );
3411
+ if (empty ($ _SESSION ['getTmpDir ' ])){
3412
+ $ _SESSION ['getTmpDir ' ] = array ();
3413
+ }
3414
+ if (empty ($ _SESSION ['getTmpDir ' ][$ subdir ."_ " ])){
3415
+ $ tmpDir = sys_get_temp_dir ();
3416
+ if (!_isWritable ($ tmpDir )) {
3417
+ $ tmpDir = "{$ global ['systemRootPath ' ]}videos/cache/ " ;
3418
+ }
3419
+ $ tmpDir = rtrim ($ tmpDir , '/ ' ) . '/ ' ;
3420
+ $ tmpDir = "{$ tmpDir }{$ subdir }" ;
3421
+ $ tmpDir = rtrim ($ tmpDir , '/ ' ) . '/ ' ;
3422
+ if (!is_dir ($ tmpDir )) {
3423
+ mkdir ($ tmpDir , 0755 , true );
3424
+ }
3425
+ _session_start ();
3426
+ $ _SESSION ['getTmpDir ' ][$ subdir ."_ " ] = $ tmpDir ;
3427
+ }else {
3428
+ $ tmpDir = $ _SESSION ['getTmpDir ' ][$ subdir ."_ " ];
3389
3429
}
3390
3430
return $ tmpDir ;
3391
3431
}
0 commit comments