Skip to content

Commit 945890e

Browse files
https://github.com/WWBN/AVideo-Storage/issues/12
1 parent 4aa70f3 commit 945890e

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

objects/functions.php

+49-9
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,9 @@ function ddosProtection() {
22882288
//progressive timeout-> more requests, longer timeout
22892289
$active_connections = count($_SESSION['bruteForceBlock']);
22902290
$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+
}
22912294
sleep($timeoutReal);
22922295

22932296
//with strict mode, penalize "attacker" with sleep() above, log and then die
@@ -2906,6 +2909,7 @@ function getUsageFromFilename($filename, $dir = "") {
29062909
_error_log("getUsageFromFilename: start {$dir}{$filename}");
29072910
$files = glob("{$dir}{$filename}*");
29082911
session_write_close();
2912+
$filesProcessed = array();
29092913
foreach ($files as $f) {
29102914
if (is_dir($f)) {
29112915
_error_log("getUsageFromFilename: {$f} is Dir");
@@ -2940,11 +2944,19 @@ function getUsageFromFilename($filename, $dir = "") {
29402944
}
29412945
if (!empty($urls['mp4'])) {
29422946
foreach ($urls['mp4'] as $mp4) {
2947+
if(in_array($mp4, $filesProcessed)){
2948+
continue;
2949+
}
2950+
$filesProcessed[] = $mp4;
29432951
$filesize += getUsageFromURL($mp4);
29442952
}
29452953
}
29462954
if (!empty($urls['webm'])) {
29472955
foreach ($urls['webm'] as $mp4) {
2956+
if(in_array($mp4, $filesProcessed)){
2957+
continue;
2958+
}
2959+
$filesProcessed[] = $mp4;
29482960
$filesize += getUsageFromURL($mp4);
29492961
}
29502962
}
@@ -3314,6 +3326,15 @@ function wget($url, $filename) {
33143326
return false;
33153327
}
33163328
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+
}
33173338
$cmd = "wget {$url} -O {$filename} --no-check-certificate";
33183339
//_error_log("wget Start ({$cmd}) ");
33193340
//echo $cmd;
@@ -3375,17 +3396,36 @@ function isWritable($dir) {
33753396
return $result;
33763397
}
33773398

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+
33783409
function getTmpDir($subdir = "") {
33793410
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."_"];
33893429
}
33903430
return $tmpDir;
33913431
}

0 commit comments

Comments
 (0)