Пример #1
0
 public static function deletePost($post_id)
 {
     //delete img
     //first get the post
     $post = self::getPost($post_id);
     //post->getImg
     $img = $post->getImagesPost();
     //foreach img delete img in the DB
     if ($img != NULL) {
         foreach ($img as $image) {
             DAL::deleteImg($image->getImg_id());
         }
         //then in the files (somthing like rmdir /images/posts/$postid -R) !!!this section might rise errors...
         $dir = 'images/posts/' . $post->getPost_id();
         $files = array_diff(scandir($dir), array('.', '..'));
         foreach ($files as $file) {
             is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
         }
         rmdir($dir);
     }
     //then get votes
     $votes = $post->getVote_post();
     //foreach vote, unset it
     if ($votes != NULL) {
         foreach ($votes as $vote) {
             DAL::unsetVote_post($vote->getPost_id(), $vote->getUser()->getUsername());
         }
     }
     DAL::deletePost($post_id);
 }
Пример #2
0
	private function delTree($dir) {
		$files = array_diff(scandir($dir), array('.','..'));
		foreach ($files as $file) {
			(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
		}
		return rmdir($dir);
	}
Пример #3
0
/**
* Check the given log file for all tests that match
* 
* @param mixed $logFile
* @param mixed $match
*/
function CheckLog($logFile, $match)
{
    global $count;
    echo "\r({$count}): Checking {$logFile}";
    $file = file_get_contents($logFile);
    if (stripos($file, $match) !== false) {
        $lines = explode("\n", $file);
        $file = '';
        foreach ($lines as $line) {
            if (stripos($line, $match) !== false) {
                $parseLine = str_replace("\t", "\t ", $line);
                $parts = explode("\t", $parseLine);
                $testId = trim($parts[4]);
                $testPath = './' . GetTestPath($testId);
                if (strlen($testPath)) {
                    delTree($testPath);
                    usleep(100000);
                    // give the system a chance to breathe
                    $count++;
                    echo "\r({$count}): Checking {$logFile}";
                }
            } else {
                $file .= $line . "\n";
            }
        }
        // rewrite the trimmed file
        file_put_contents($logFile, $file);
    } else {
        unset($file);
    }
}
Пример #4
0
function delTree($dir)
{
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
    }
    return rmdir($dir);
}
Пример #5
0
function data_remove($file)
{
    if (file_exists("data/{$file}.php")) {
        unlink("data/{$file}.php");
    } elseif (is_dir("data/{$file}")) {
        delTree("data/{$file}");
    }
}
/**
* Convert an AVI video capture into the video frames the WPT is expecting
* 
* @param mixed $testPath
* @param mixed $run
* @param mixed $cached
*/
function ProcessAVIVideo(&$test, $testPath, $run, $cached)
{
    $cachedText = '';
    if ($cached) {
        $cachedText = '_Cached';
    }
    $videoFile = "{$testPath}/{$run}{$cachedText}_video.avi";
    $crop = '';
    if (!is_file($videoFile)) {
        $videoFile = "{$testPath}/{$run}{$cachedText}_video.mp4";
    }
    if (!is_file($videoFile)) {
        $crop = ',crop=in_w:in_h-80:0:80';
        $videoFile = "{$testPath}/{$run}{$cachedText}_appurify.mp4";
    }
    // trim the video to align with the capture if we have timestamps for both
    $renderStart = null;
    if (array_key_exists('appurify_tests', $test) && is_array($test['appurify_tests']) && array_key_exists($run, $test['appurify_tests']) && is_array($test['appurify_tests'][$run])) {
        require_once 'page_data.inc';
        $page_data = loadPageRunData($testPath, $run, $cached);
        if (isset($page_data) && is_array($page_data) && array_key_exists('render', $page_data)) {
            $renderStart = $page_data['render'];
        }
    }
    if (is_file($videoFile)) {
        $videoDir = "{$testPath}/video_{$run}" . strtolower($cachedText);
        if (!is_file("{$videoDir}/video.json")) {
            if (is_dir($videoDir)) {
                delTree($videoDir, false);
            }
            if (!is_dir($videoDir)) {
                mkdir($videoDir, 0777, true);
            }
            $videoFile = realpath($videoFile);
            $videoDir = realpath($videoDir);
            if (strlen($videoFile) && strlen($videoDir)) {
                if (Video2PNG($videoFile, $videoDir, $crop)) {
                    $startOffset = DevToolsGetVideoOffset($testPath, $run, $cached, $endTime);
                    FindAVIViewport($videoDir, $startOffset, $viewport);
                    EliminateDuplicateAVIFiles($videoDir, $viewport);
                    $lastImage = ProcessVideoFrames($videoDir, $renderStart, $viewport);
                    $screenShot = "{$testPath}/{$run}{$cachedText}_screen.jpg";
                    if (isset($lastImage) && is_file($lastImage)) {
                        //unlink($videoFile);
                        if (!is_file($screenShot)) {
                            copy($lastImage, $screenShot);
                        }
                    }
                }
            }
            $videoInfo = array();
            if (isset($viewport)) {
                $videoInfo['viewport'] = $viewport;
            }
            file_put_contents("{$videoDir}/video.json", json_encode($videoInfo));
        }
    }
}
Пример #7
0
function delTree($dir)
{
    global $ds;
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir($dir . $ds . $file) ? delTree($dir . $ds . $file) : unlink($dir . $ds . $file);
    }
    return rmdir($dir);
}
Пример #8
0
function delTree($dir)
{
    foreach (glob($dir) as $file) {
        if (is_dir($file)) {
            delTree("{$file}/*");
            rmdir($file);
        } else {
            unlink($file);
        }
    }
}
Пример #9
0
/**
* Convert an AVI video capture into the video frames the WPT is expecting
* 
* @param mixed $testPath
* @param mixed $run
* @param mixed $cached
*/
function ProcessAVIVideo(&$test, $testPath, $run, $cached)
{
    global $max_load;
    $cachedText = '';
    if ($cached) {
        $cachedText = '_Cached';
    }
    $videoFile = "{$testPath}/{$run}{$cachedText}_video.mp4";
    $crop = '';
    if (!is_file($videoFile)) {
        $videoFile = "{$testPath}/{$run}{$cachedText}_video.avi";
    }
    if (is_file($videoFile)) {
        $videoDir = "{$testPath}/video_{$run}" . strtolower($cachedText);
        if (!is_file("{$videoDir}/video.json")) {
            if (isset($max_load) && $max_load > 0) {
                WaitForSystemLoad($max_load, 3600);
            }
            if (is_dir($videoDir)) {
                delTree($videoDir, false);
            }
            if (!is_dir($videoDir)) {
                mkdir($videoDir, 0777, true);
            }
            $videoFile = realpath($videoFile);
            $videoDir = realpath($videoDir);
            if (strlen($videoFile) && strlen($videoDir)) {
                if (PythonVisualMetrics($videoFile, $videoDir, $testPath, $run, $cached)) {
                    unlink($videoFile);
                } else {
                    $crop = FindVideoCrop($videoFile, $videoDir);
                    if (Video2PNG($videoFile, $videoDir, $crop)) {
                        $startOffset = DevToolsGetVideoOffset($testPath, $run, $cached, $endTime);
                        FindAVIViewport($videoDir, $startOffset, $viewport);
                        EliminateDuplicateAVIFiles($videoDir, $viewport);
                        $lastImage = ProcessVideoFrames($videoDir, $viewport);
                        $screenShot = "{$testPath}/{$run}{$cachedText}_screen.jpg";
                        if (isset($lastImage) && is_file($lastImage)) {
                            unlink($videoFile);
                            if (!is_file($screenShot)) {
                                copy($lastImage, $screenShot);
                            }
                        }
                    }
                }
            }
            $videoInfo = array();
            if (isset($viewport)) {
                $videoInfo['viewport'] = $viewport;
            }
            file_put_contents("{$videoDir}/video.json", json_encode($videoInfo));
        }
    }
}
Пример #10
0
function delTree($dir = '')
{
    if (strlen($dir) < 2) {
        return false;
    }
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
    }
    return rmdir($dir);
}
Пример #11
0
 function delTree($dir)
 {
     foreach (glob($dir . '*') as $file) {
         $fileext = explode('/', $file);
         if (!strstr(end($fileext), '.')) {
             delTree($file . '/');
         } else {
             unlink($file);
         }
     }
     rmdir($dir);
 }
Пример #12
0
function delTree($dir, $withdirectory = "true")
{
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
    }
    if ($withdirectory) {
        return rmdir($dir);
    } else {
        return true;
    }
}
Пример #13
0
 private static function delTree($dir)
 {
     if (is_dir($dir)) {
         $files = array_diff(scandir($dir), array('.', '..'));
         foreach ($files as $file) {
             is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
         }
         return rmdir($dir);
     } else {
         return true;
     }
 }
Пример #14
0
function delTree($dir)
{
    $files = glob($dir . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (substr($file, -1) == '/') {
            delTree($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dir);
}
Пример #15
0
function delTree($dir)
{
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
    }
    if (!preg_match('/ADODB_cache$/', $dir, $matches)) {
        echo 'Removing dir: ' . $dir;
        echo '<br>';
        rmdir($dir);
    }
}
Пример #16
0
 public static function deleteUser($username)
 {
     //delete picture
     $usr = self::getUserWithoutPassword($username);
     if ($usr->getProfile_pic() != "images/users/default.jpg") {
         $dir = 'images/users/' . $username;
         $files = array_diff(scandir($dir), array('.', '..'));
         foreach ($files as $file) {
             is_dir("{$dir}/{$file}") ? delTree("{$dir}/{$file}") : unlink("{$dir}/{$file}");
         }
         rmdir($dir);
     }
     DAL::deleteUser($username);
 }
Пример #17
0
function delTree($path)
{
    if (is_dir($path) === true) {
        $files = array_diff(scandir($path), array('.', '..'));
        foreach ($files as $file) {
            delTree(realpath($path) . '/' . $file);
        }
        return rmdir($path);
    } else {
        if (is_file($path) === true) {
            return unlink($path);
        }
    }
    return false;
}
Пример #18
0
function delfile($filename)
{
    global $db;
    if (!$db->Query("SELECT album FROM album where id=" . $filename)) {
        $db->Kill('Error1');
    }
    $array = $db->RowArray();
    //$filename=trim($array['album']);
    if (file_exists('upload/album/' . $filename) && $filename != '') {
        if (delTree('upload/album/' . $filename)) {
        } else {
            return false;
        }
    }
}
/**
 * A simple recursive delTree method
 *
 * @param string $dir
 * @return bool
 */
function delTree($dir)
{
    $files = array_diff(scandir($dir), array(".", ".."));
    foreach ($files as $file) {
        if (is_dir("{$dir}/{$file}")) {
            $result = delTree("{$dir}/{$file}");
        } else {
            exec("rm -f '{$dir}/{$file}'", $_, $status);
            $result = $status === 0;
        }
        if ($result === false) {
            echo "Error while removing '{$dir}/{$file}'\n";
            return false;
        }
    }
    return @rmdir($dir);
}
function delTree($dir)
{
    $files = array_diff(scandir($dir), array('.', '..'));
    if ($files) {
        foreach ($files as $file) {
            $fp = cms_join_path($dir, $file);
            if (is_dir($fp)) {
                if (!delTree($fp)) {
                    return false;
                }
            } else {
                unlink($fp);
            }
        }
        unset($files);
    }
    return rmdir($dir);
}
/**
 *
 * This is a very simple plugin that should be deleted as soon as the update is finished.
 * Upon acceptance from the WordPress repo we need to rename the plugin folder from rapidology to rapidology-by-leadpages
 * to recieve updates from the repo
 *
 */
function rapidology_updater()
{
    add_option('update_refresh', 0);
    $old_file = WP_PLUGIN_DIR . '/rapidology';
    $new_file = WP_PLUGIN_DIR . '/rapidology-by-leadpages';
    $update_folder = WP_PLUGIN_DIR . '/rapidology-by-leadpages.zip';
    //deactivate old rapidology
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if (!file_exists($new_file)) {
        mkdir($new_file, 0777);
        $result = copy_dir($old_file, $new_file, array('.DS_Store', '.git', '.gitignore', '.idea'));
        deactivate_plugins('rapidology/rapidology.php');
        delTree($old_file);
        update_option('update_refresh', true);
    }
}
Пример #22
0
function ResubmitTest($id)
{
    echo "{$id} - Resubmitting...";
    $testPath = './' . GetTestPath($id);
    if (gz_is_file("{$testPath}/testinfo.json")) {
        $test = json_decode(gz_file_get_contents("{$testPath}/testinfo.json"), true);
        if (array_key_exists('job_file', $test) && array_key_exists('location', $test) && is_file("{$testPath}/test.job")) {
            if ($lock = LockLocation($test['location'])) {
                if (copy("{$testPath}/test.job", $test['job_file'])) {
                    $files = scandir($testPath);
                    foreach ($files as $file) {
                        if ($file != '.' && $file != '..' && strncasecmp($file, 'test', 4)) {
                            if (is_file("{$testPath}/{$file}")) {
                                unlink("{$testPath}/{$file}");
                            } elseif (is_dir("{$testPath}/{$file}")) {
                                delTree("{$testPath}/{$file}");
                            }
                        }
                    }
                    AddJobFile($test['workdir'], $test['job'], $test['priority'], false);
                    $test['started'] = time();
                    unset($test['completeTime']);
                    gz_file_put_contents("{$testPath}/testinfo.json", json_encode($test));
                    echo "OK";
                } else {
                    echo "Failed to copy job file";
                }
                UnlockLocation($lock);
            } else {
                echo "Failed to lock location";
            }
        } else {
            echo "Invalid test";
        }
    } else {
        echo "Test not found";
    }
    echo "\n";
}
Пример #23
0
function CronProcess($path, $maxAllowedAge)
{
    $file = $path . 'testinfo.ini';
    if (is_file($file)) {
        $testInfo = GetTestInfo($path);
        if ($testInfo) {
            if (array_key_exists('archived', $testInfo) && $testInfo['archived']) {
                $currentTime = time();
                $timestamp = filemtime($file);
                if ($maxAllowedAge < $currentTime - $timestamp) {
                    // Remove the expired test results from the
                    echo "{$path}: expired and deleted.\r\n";
                    delTree($path);
                }
            } else {
                $info = parse_ini_file($file, true);
                if (isset($info['test']['completeTime'])) {
                    // Deal with the pre-existing test results. Upload them into
                    // remote storage.
                    require_once 'storage/storage.inc';
                    $id = $info['test']['id'];
                    StoreResults($id);
                    // StoreResults always generates zipped testinfo.json. We
                    // delete the unzipped version if there is here.
                    if (is_file($path . 'testinfo.json')) {
                        unlink($path . 'testinfo.json');
                    }
                    echo "test {$id} is uploaded.\r\n";
                }
            }
        }
    } else {
        $paths = glob($path . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
        foreach ($paths as $path) {
            CronProcess($path, $maxAllowedAge);
        }
    }
}
Пример #24
0
function delTree($dir)
{
    $dir = preg_replace('~([/])\\1+~', '$1', $dir);
    //echo "Durchsuche ".encode_to_html($dir)."<br>";
    $directory = opendir($dir);
    while ($file = readdir($directory)) {
        if ($file != "." && $file != ".." && $file != "small") {
            if (is_dir($dir . "/" . $file)) {
                delTree($dir . "/" . $file);
            } else {
                //echo "L&ouml;sche Datei ".encode_to_html($dir."/".$file)." <br>";
                if (file_exists($dir . "/" . $file)) {
                    unlink($dir . "/" . $file);
                } else {
                    echo "Fehler: Kann Date " . encode_to_html($dir . "/" . $file) . " nicht l&ouml;schen <br>";
                }
            }
        }
    }
    closedir($directory);
    //echo "L&ouml;sche Verzeichnis ".encode_to_html($dir."/".$file)." <br>";
    rmdir($dir);
}
Пример #25
0
/**
* Create a single test and return the test ID
*
* @param mixed $test
* @param mixed $url
*/
function CreateTest(&$test, $url, $batch = 0, $batch_locations = 0)
{
    global $settings;
    $testId = null;
    if (is_file('./settings/block.txt')) {
        $forceBlock = trim(file_get_contents('./settings/block.txt'));
    }
    if (CheckUrl($url) && WptHookValidateTest($test)) {
        // generate the test ID
        $test_num;
        $id = uniqueId($test_num);
        if ($test['private']) {
            $id = ShardKey($test_num) . md5(uniqid(rand(), true));
        } else {
            $id = ShardKey($test_num) . $id;
        }
        $today = new DateTime("now", new DateTimeZone('UTC'));
        $testId = $today->format('ymd_') . $id;
        $test['path'] = './' . GetTestPath($testId);
        // make absolutely CERTAIN that this test ID doesn't already exist
        while (is_dir($test['path'])) {
            // fall back to random ID's
            $id = ShardKey($test_num) . md5(uniqid(rand(), true));
            $testId = $today->format('ymd_') . $id;
            $test['path'] = './' . GetTestPath($testId);
        }
        // create the folder for the test results
        if (!is_dir($test['path'])) {
            mkdir($test['path'], 0777, true);
        }
        // write out the ini file
        $testInfo = "[test]\r\n";
        $testInfo .= "fvonly={$test['fvonly']}\r\n";
        $testInfo .= "timeout={$test['timeout']}\r\n";
        $resultRuns = $test['runs'] - $test['discard'];
        $testInfo .= "runs={$resultRuns}\r\n";
        $testInfo .= "location=\"{$test['locationText']}\"\r\n";
        $testInfo .= "loc={$test['location']}\r\n";
        $testInfo .= "id={$testId}\r\n";
        $testInfo .= "batch={$batch}\r\n";
        $testInfo .= "batch_locations={$batch_locations}\r\n";
        $testInfo .= "sensitive={$test['sensitive']}\r\n";
        if (strlen($test['login'])) {
            $testInfo .= "authenticated=1\r\n";
        }
        $testInfo .= "connections={$test['connections']}\r\n";
        if (strlen($test['script'])) {
            $testInfo .= "script=1\r\n";
        }
        if (strlen($test['notify'])) {
            $testInfo .= "notify={$test['notify']}\r\n";
        }
        if (strlen($test['video'])) {
            $testInfo .= "video=1\r\n";
        }
        if (strlen($test['uid'])) {
            $testInfo .= "uid={$test['uid']}\r\n";
        }
        if (strlen($test['owner'])) {
            $testInfo .= "owner={$test['owner']}\r\n";
        }
        if (strlen($test['type'])) {
            $testInfo .= "type={$test['type']}\r\n";
        }
        if (strlen($test['industry']) && strlen($test['industry_page'])) {
            $testInfo .= "industry=\"{$test['industry']}\"\r\n";
            $testInfo .= "industry_page=\"{$test['industry_page']}\"\r\n";
        }
        if (isset($test['connectivity'])) {
            $testInfo .= "connectivity={$test['connectivity']}\r\n";
            $testInfo .= "bwIn={$test['bwIn']}\r\n";
            $testInfo .= "bwOut={$test['bwOut']}\r\n";
            $testInfo .= "latency={$test['latency']}\r\n";
            $testInfo .= "plr={$test['plr']}\r\n";
        }
        $testInfo .= "\r\n[runs]\r\n";
        if ($test['median_video']) {
            $testInfo .= "median_video=1\r\n";
        }
        file_put_contents("{$test['path']}/testinfo.ini", $testInfo);
        // for "batch" tests (the master) we don't need to submit an actual test request
        if (!$batch && !$batch_locations) {
            // build up the actual test commands
            $testFile = '';
            if (strlen($test['domElement'])) {
                $testFile .= "\r\nDOMElement={$test['domElement']}";
            }
            if ($test['fvonly']) {
                $testFile .= "\r\nfvonly=1";
            }
            if ($test['timeout']) {
                $testFile .= "\r\ntimeout={$test['timeout']}";
            }
            if ($test['web10']) {
                $testFile .= "\r\nweb10=1";
            }
            if ($test['ignoreSSL']) {
                $testFile .= "\r\nignoreSSL=1";
            }
            if ($test['tcpdump']) {
                $testFile .= "\r\ntcpdump=1";
            }
            if ($test['standards']) {
                $testFile .= "\r\nstandards=1";
            }
            if ($test['timeline']) {
                $testFile .= "\r\ntimeline=1";
                $testFile .= "\r\ntimelineStackDepth={$test['timelineStackDepth']}";
            }
            if ($test['trace']) {
                $testFile .= "\r\ntrace=1";
            }
            if ($test['swrender']) {
                $testFile .= "\r\nswRender=1";
            }
            if ($test['netlog']) {
                $testFile .= "\r\nnetlog=1";
            }
            if ($test['spdy3']) {
                $testFile .= "\r\nspdy3=1";
            }
            if ($test['noscript']) {
                $testFile .= "\r\nnoscript=1";
            }
            if ($test['fullsizevideo']) {
                $testFile .= "\r\nfullSizeVideo=1";
            }
            if ($test['blockads']) {
                $testFile .= "\r\nblockads=1";
            }
            if ($test['video']) {
                $testFile .= "\r\nCapture Video=1";
            }
            if (GetSetting('save_mp4') || $test['keepvideo']) {
                $testFile .= "\r\nkeepvideo=1";
            }
            if (strlen($test['type'])) {
                $testFile .= "\r\ntype={$test['type']}";
            }
            if ($test['block']) {
                $testFile .= "\r\nblock={$test['block']}";
                if (isset($forceBlock)) {
                    $testFile .= " {$forceBlock}";
                }
            } elseif (isset($forceBlock)) {
                $testFile .= "\r\nblock={$forceBlock}";
            }
            if ($test['noopt']) {
                $testFile .= "\r\nnoopt=1";
            }
            if ($test['noimages']) {
                $testFile .= "\r\nnoimages=1";
            }
            if ($test['noheaders']) {
                $testFile .= "\r\nnoheaders=1";
            }
            if ($test['discard']) {
                $testFile .= "\r\ndiscard={$test['discard']}";
            }
            $testFile .= "\r\nruns={$test['runs']}\r\n";
            if (isset($test['connectivity'])) {
                $testFile .= "bwIn={$test['bwIn']}\r\n";
                $testFile .= "bwOut={$test['bwOut']}\r\n";
                $testFile .= "latency={$test['testLatency']}\r\n";
                $testFile .= "plr={$test['plr']}\r\n";
            }
            if (isset($test['browserExe']) && strlen($test['browserExe'])) {
                $testFile .= "browserExe={$test['browserExe']}\r\n";
            }
            if (isset($test['browser']) && strlen($test['browser'])) {
                $testFile .= "browser={$test['browser']}\r\n";
            }
            if ($test['pngss'] || $settings['pngss']) {
                $testFile .= "pngScreenShot=1\r\n";
            }
            if ($test['iq']) {
                $testFile .= "imageQuality={$test['iq']}\r\n";
            } elseif ($settings['iq']) {
                $testFile .= "imageQuality={$settings['iq']}\r\n";
            }
            if ($test['bodies']) {
                $testFile .= "bodies=1\r\n";
            }
            if ($test['htmlbody']) {
                $testFile .= "htmlbody=1\r\n";
            }
            if ($test['time']) {
                $testFile .= "time={$test['time']}\r\n";
            }
            if ($test['clear_rv']) {
                $testFile .= "clearRV={$test['clear_rv']}\r\n";
            }
            if ($test['keepua']) {
                $testFile .= "keepua=1\r\n";
            }
            if ($test['mobile']) {
                $testFile .= "mobile=1\r\n";
            }
            if (isset($test['dpr']) && $test['dpr'] > 0) {
                $testFile .= "dpr={$test['dpr']}\r\n";
            }
            if (isset($test['width']) && $test['width'] > 0) {
                $testFile .= "width={$test['width']}\r\n";
            }
            if (isset($test['height']) && $test['height'] > 0) {
                $testFile .= "height={$test['height']}\r\n";
            }
            if ($test['clearcerts']) {
                $testFile .= "clearcerts=1\r\n";
            }
            if ($test['orientation']) {
                $testFile .= "orientation={$test['orientation']}\r\n";
            }
            if (array_key_exists('continuousVideo', $test) && $test['continuousVideo']) {
                $testFile .= "continuousVideo=1\r\n";
            }
            if (array_key_exists('responsive', $test) && $test['responsive']) {
                $testFile .= "responsive=1\r\n";
            }
            if (array_key_exists('cmdLine', $test) && strlen($test['cmdLine'])) {
                $testFile .= "cmdLine={$test['cmdLine']}\r\n";
            }
            if (array_key_exists('addCmdLine', $test) && strlen($test['addCmdLine'])) {
                $testFile .= "addCmdLine={$test['addCmdLine']}\r\n";
            }
            if (array_key_exists('customBrowserUrl', $test) && strlen($test['customBrowserUrl'])) {
                $testFile .= "customBrowserUrl={$test['customBrowserUrl']}\r\n";
            }
            if (array_key_exists('customBrowserMD5', $test) && strlen($test['customBrowserMD5'])) {
                $testFile .= "customBrowserMD5={$test['customBrowserMD5']}\r\n";
            }
            if (array_key_exists('customBrowserSettings', $test) && is_array($test['customBrowserSettings']) && count($test['customBrowserSettings'])) {
                foreach ($test['customBrowserSettings'] as $setting => $value) {
                    $testFile .= "customBrowser_{$setting}={$value}\r\n";
                }
            }
            if (isset($test['uastring'])) {
                $testFile .= "uastring={$test['uastring']}\r\n";
            }
            $UAModifier = GetSetting('UAModifier');
            if ($UAModifier && strlen($UAModifier)) {
                $testFile .= "UAModifier={$UAModifier}\r\n";
            }
            if (isset($test['appendua'])) {
                $testFile .= "AppendUA={$test['appendua']}\r\n";
            }
            // see if we need to add custom scan rules
            if (array_key_exists('custom_rules', $test)) {
                foreach ($test['custom_rules'] as &$rule) {
                    $rule = trim($rule);
                    if (strlen($rule)) {
                        $testFile .= "customRule={$rule}\r\n";
                    }
                }
            }
            // Add custom metrics
            if (array_key_exists('customMetrics', $test)) {
                foreach ($test['customMetrics'] as $name => $code) {
                    $testFile .= "customMetric={$name}:{$code}\r\n";
                }
            }
            if (!SubmitUrl($testId, $testFile, $test, $url)) {
                $testId = null;
            }
        }
        // log the test
        if (isset($testId)) {
            logTestMsg($testId, "Test Created");
            // store the entire test data structure JSON encoded (instead of a bunch of individual files)
            $oldUrl = @$test['url'];
            $test['url'] = $url;
            SaveTestInfo($testId, $test);
            $test['url'] = $oldUrl;
            if ($batch_locations) {
                LogTest($test, $testId, 'Multiple Locations test');
            } else {
                if ($batch) {
                    LogTest($test, $testId, 'Bulk Test');
                } else {
                    LogTest($test, $testId, $url);
                }
            }
        } else {
            // delete the test if we didn't really submit it
            delTree("{$test['path']}/");
        }
    } else {
        global $error;
        $error = 'Your test request was intercepted by our spam filters (or because we need to talk to you about how you are submitting tests)';
    }
    return $testId;
}
Пример #26
0
         $hashstr = $_REQUEST['tests'] . $_REQUEST['template'] . $version . trim($_REQUEST['end']) . $videoIdExtra . $bgColor . $textColor;
         if ($_REQUEST['slow']) {
             $hashstr .= '.slow';
         }
         if (strpos($hashstr, '_') == 6) {
             $date = substr($hashstr, 0, 7);
         }
         $id = $date . sha1($hashstr);
     } else {
         $id = gmdate('ymd_') . md5(uniqid(rand(), true));
     }
 }
 $path = GetVideoPath($id);
 if (is_file("./{$path}/video.mp4")) {
     if ($_REQUEST['force']) {
         delTree("./{$path}/");
     } else {
         $exists = true;
     }
 }
 if (!$exists) {
     // set up the result directory
     $dest = './' . GetVideoPath($id);
     if (!is_dir($dest)) {
         mkdir($dest, 0777, true);
     }
     if (count($labels)) {
         file_put_contents("{$dest}/labels.txt", json_encode($labels));
     }
     gz_file_put_contents("{$dest}/testinfo.json", json_encode($tests));
     // kick off the actual rendering
Пример #27
0
/**
* Reset the state of the given test directory (delete all the results)
* 
* @param mixed $testDir
*/
function ResetTestDir($testPath)
{
    $files = scandir($testPath);
    foreach ($files as $file) {
        if ($file != '.' && $file != '..' && strncasecmp($file, 'test', 4)) {
            if (is_file("{$testPath}/{$file}")) {
                unlink("{$testPath}/{$file}");
            } elseif (is_dir("{$testPath}/{$file}")) {
                delTree("{$testPath}/{$file}");
            }
        }
    }
}
Пример #28
0
/**
* Prune the extra data we don't need for benchmarks from the test result
* video, screen shots, headers, etc
* 
* @param mixed $id
*/
function PruneTestData($id)
{
    $testPath = './' . GetTestPath($id);
    $files = scandir($testPath);
    foreach ($files as $file) {
        // just do the videos for now
        if (strpos($file, 'video_') !== false && is_dir("{$testPath}/{$file}")) {
            delTree("{$testPath}/{$file}");
        } elseif (strpos($file, 'bodies') !== false) {
            unlink("{$testPath}/{$file}");
        } elseif (strpos($file, 'pagespeed') !== false) {
            unlink("{$testPath}/{$file}");
        } elseif (strpos($file, '_doc.jpg') !== false) {
            unlink("{$testPath}/{$file}");
        } elseif (strpos($file, '_render.jpg') !== false) {
            unlink("{$testPath}/{$file}");
        } elseif (strpos($file, 'status.txt') !== false) {
            unlink("{$testPath}/{$file}");
        }
    }
}
Пример #29
0
function delTree($dir)
{
    $files = glob($dir . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            delTree($file);
        } else {
            unlink($file);
        }
    }
    if (is_dir($dir)) {
        rmdir($dir);
    }
}
Пример #30
0
session_start();
require "include/functions.php";
$config_file = 'config.php';
if (file_exists($config_file)) {
    require "config.php";
} else {
    header("Location: error.php?e=config");
    die;
}
require "include/apply_config.php";
$Token = filter_var($_GET["Token"], FILTER_SANITIZE_STRING);
$username = $_COOKIE["username"];
$UserID = query_one("SELECT UserID FROM Users WHERE UserName='******'", $connection);
$valid_token = query_one("SELECT COUNT(*) FROM Tokens WHERE TokenID='{$Token}' AND UserID='{$UserID}'", $connection);
if ($valid_token == 1) {
    $SoundID = query_one("SELECT soundfile_id FROM Tokens WHERE TokenID='{$Token}' LIMIT 1", $connection);
    $random_cookie = query_one("SELECT random_cookie FROM Tokens WHERE TokenID='{$Token}' LIMIT 1", $connection);
    $from_db = query_one("SELECT from_db FROM Tokens WHERE TokenID='{$Token}' LIMIT 1", $connection);
}
$del_token = query_one("DELETE FROM Tokens WHERE TokenID='{$Token}'", $connection);
#rm temp dir
delTree('tmp/' . $random_cookie . '/');
// Relocate back to the first page of the application
if ($from_db == "TRUE") {
    #echo $from_db;
    header("Location: ./db_filedetails.php?SoundID={$SoundID}");
    die;
} else {
    header("Location: ./");
    die;
}