Last active
December 16, 2017 22:10
-
-
Save gulducat/ff408eff755916fcbec1fbdaa2c86c19 to your computer and use it in GitHub Desktop.
terrible wordpress plugin that is super mean to the filesystem on purpose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: BadFS | |
Plugin URI: http://wpengine.com/ | |
Description: Be intentionally terrible to the filesystem to test storage performance. | |
Version: 1.0.0 | |
Author: Daniel Bennett | |
Author URI: http://wpengine.com/ | |
*/ | |
// $fs_traversals = 0; | |
function get_files_and_directories(){ | |
// global $fs_traversals; | |
$items = array(); | |
$stupid_files_dir = plugin_dir_path(__FILE__) . 'stupidfiles'; | |
$directory = new RecursiveDirectoryIterator($stupid_files_dir); | |
$iterator = new RecursiveIteratorIterator($directory); | |
foreach ($iterator as $item){ | |
// $fs_traversals++; | |
// skip */.. | |
if ( stripos(strrev($item), '..') === 0 ){ continue; } | |
$items[] = $item->getPathname(); | |
} | |
return $items; | |
} | |
function get_php_files(){ | |
$files = array(); | |
foreach (get_files_and_directories() as $f) { | |
if ( stripos($f, '.php') > 0 ){ | |
$files[] = $f; | |
} | |
} | |
return $files; | |
} | |
function find_php_file($filename){ | |
foreach (get_files_and_directories() as $f) { | |
if ( strpos($f, $filename) ){ | |
return $f; | |
} | |
} | |
} | |
try { | |
foreach (get_php_files() as $f){ | |
$f = array_slice(explode('/', $f), -1)[0]; | |
include(find_php_file($f)); | |
} | |
// global $fs_traversals; | |
// error_log("Looked at $fs_traversals files and directories."); | |
} | |
catch(Exception $e) { | |
error_log("installing badfs plugin?"); | |
} | |
function badfs_activate(){ | |
$stupid_files_dir = plugin_dir_path(__FILE__) . 'stupidfiles'; | |
if ( file_exists($stupid_files_dir) ) { | |
return; | |
} | |
for ($x=0; $x<=25; $x++) { | |
mkdir("$stupid_files_dir/$x/$x/$x/$x/$x/$x", 0775, true); | |
} | |
$x = 0; | |
// this will only get directories, since that's all that exists at the moment. | |
foreach (get_files_and_directories() as $dir) { | |
touch("$dir/$x.php"); | |
$x++; | |
} | |
} | |
register_activation_hook(__FILE__, 'badfs_activate'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment