function processFolder($dir, &$array) { global $host; if (is_dir($host . $dir . "/") && ($handle = opendir($host . $dir . "/"))) { while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } else { if (is_file($host . $dir . "/" . $file)) { $name = $dir . "/" . $file; $array[] = $name; //echo $name, BR; } else { if (is_dir($host . $dir . "/" . $file . "/")) { processFolder($dir . "/" . $file, $array); } } } } } }
function processFolder($dir, &$array) { global $host; if (is_dir($host . $dir . "/") && ($handle = opendir($host . $dir . "/"))) { while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } else { if (is_file($host . $dir . "/" . $file)) { $name = $dir . "/" . $file; if (u\StringUtility::endsWith($name, ".php")) { $array[] = $name; } } else { if (is_dir($host . $dir . "/" . $file . "/")) { processFolder($dir . "/" . $file, $array); } } } } } }
} if ($processFolder) { $config = getConfig(); $snortFile = $config['snortFile']; $substringLength = $config['substringLength']; if (isset($_POST['local'])) { processFolder($path, $path, $includeSubfolders, $scoringMethod, $substringLength, $snortFile); } else { if (isset($_POST['network'])) { $ip = $_POST['ip']; $user = $_POST['user']; $pass = $_POST['pass']; $folder = $_POST['location']; $netPath = "//" . $ip . ($folder[0] == "/" ? $folder : "/" . $folder . "/"); $path = openShare($ip, $user, $pass, $folder); processFolder($path, $netPath, $includeSubfolders, $scoringMethod, $substringLength, $snortFile); closeShare(); } } } ?> <div id="page"> <div id="content"> <div class="post"> <div class="entry"> <h2 class="title">Process Network Folder</a></h2> <form action="folderPath.php" method="post"> <table> <tr><td><b>IP Address: </b></td<td><input type="text" id="ip" name="ip"/></td> <td><b>Network Folder: </b></td<td><input type="text" id="location" name="location"/></td> <tr><td><b>Username: </b></td<td><input type="text" id="user" name="user"/></td>
/** * Crawl a directory a process each file found. * * Used by folderPath.php * * @param $startingDirectory - the directory to begin crawling for files (will be the local mounted directory ("/mnt/share")) * @param $netPath - used to store the actual location in the database, instead of using the local mounted directory ("/mnt/share") * @param $includeSubfolders - binary variable that if true will include sub folders * @param $scoringMethod - the scoring method chosen (i.e. histogram, random, etc.) * @param $substringLength - length of the substring from the config table * @param $snortFile - location of the snort file from the config table */ function processFolder($startingDirectory, $netPath, $includeSubfolders, $scoringMethod, $substringLength, $snortFile) { if ($dObj = dir($startingDirectory)) { while ($thisEntry = $dObj->read()) { if ($thisEntry != "." && $thisEntry != "..") { $path = "{$startingDirectory}{$thisEntry}"; //process the file we found if (!is_dir($path)) { processFile(2, $path, $netPath, $scoringMethod, $substringLength, $snortFile); //if the found file is not a directory, process it } // If we are processing subdirectories and the entry is a directory, recursively call our function on it if ($includeSubfolders && is_dir($path)) { $netPathTemp = ($netPath[strlen($netPath) - 1] == "/" ? $netPath : $netPath . "/") . $thisEntry . "/"; //gets the new path to add to the db processFolder($path . "/", $netPathTemp, $includeSubfolders, $scoringMethod, $substringLength, $snortFile); } } else { //ignore "." and ".." to prevent an infinite loop } } } }