Traverse Directory Tree



' . "\n"; if (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false) { echo 'Domain:

' . "http://" . $_SERVER['SERVER_NAME'] . str_replace(":80/","/",":" . $_SERVER['SERVER_PORT'] . "/") . '


' . "\n"; echo '
' . "\n"; echo 'Subdirectory (end with ' . DIRECTORY_SEPARATOR . '):

'; } else { echo 'Domain:
' . "\n"; echo '
' . "\n"; echo 'Subdirectory (end with ' . DIRECTORY_SEPARATOR . '):

'; } echo ' Find 1 of 2 (optional):
Find 2 of 2 (optional):

'; } else if (isset($_GET['fix'])) { $hdr = "Traverse Directory Tree - RJM Programming - November, 2019"; $onhdr = ""; if (1 == 3 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { $hdr = "Traverse Directory Tree - RJM Programming - November, 2019"; $onhdr = ' onload=" onloadf(); " '; } echo ' ' . $hdr . ' '; exit; } else { if (strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") === false) { exit; } $prehuhb=""; $huhb=explode("/listing.php", $_SERVER['REQUEST_URI'])[0]; $posthuhb=trim(explode(":",explode("/listing.php", $_SERVER['REQUEST_URI'])[0])[1]); if (strpos($_SERVER['HTTP_REFERER'], "index.html") === false && strpos($_SERVER['HTTP_REFERER'], $huhb) === false) { echo $prehuhb . "*" . $huhb . "*" . $_SERVER['HTTP_REFERER'] . " why"; exit; } //echo $_SERVER['SERVER_NAME'] . ' ' . $prehuhb . "*" . $huhb . "*" . $_SERVER['HTTP_REFERER']; //exit; set_time_limit(0); $vshtml = ""; $suffix = ""; $dirs = array(); $dir = dirname(__FILE__) . "/"; $fdir = ""; $inspec1 = ''; $inspec2 = ''; $icnt = 0; if ($argv) { foreach ($argv as $arg) { // PHP command line if ($icnt == 0) { if (strpos(urldecode($arg), ".php") === false) $dir = urldecode($arg); if (strpos(urldecode($arg), ".php") === false) $fdir = $dir; } else if ($icnt == 1) { $inspec1 = urldecode($arg); } else if ($icnt == 2) { $inspec2 = urldecode($arg); } if (strpos(urldecode($arg), ".php") === false) $icnt = $icnt + 1; } } if (isset($_GET['subdirectory']) || isset($_POST['subdirectory'])) { // web browsing $hdr = "Traverse Directory " . $huhb . " Tree - RJM Programming - November, 2019"; $onhdr = ""; if (1 == 2 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { $hdr = ""; $onhdr = ' onload=" onloadf(); " '; } echo ' ' . $hdr . '

Traverse Directory ' . $huhb . ' Tree Results



'; } // business logic if (isset($_GET['dir'])) { // curl (parameterising idea) or web browsing later $swstuff = explode("@", urldecode($_GET['dir'])); if (sizeof($swstuff) == 1) { $dir = urldecode($_GET['dir']); } else { $dir = urldecode($swstuff[0]); if (sizeof($swstuff) >= 2) $inspec1 = urldecode($swstuff[1]); if (sizeof($swstuff) >= 3) $inspec2 = urldecode($swstuff[3]); } $fdir = $dir; } if (isset($_GET['inspec1'])) { $inspec1 = urldecode($_GET['inspec1']); } if (isset($_GET['inspec2'])) { $inspec2 = urldecode($_GET['inspec2']); } if (isset($_POST['dir'])) { // curl parameterising idea $swstuff = explode("@", urldecode($_POST['dir'])); if (sizeof($swstuff) == 1) { $dir = urldecode($_POST['dir']); } else { $dir = urldecode($swstuff[0]); if (sizeof($swstuff) >= 2) $inspec1 = urldecode($swstuff[1]); if (sizeof($swstuff) >= 3) $inspec2 = urldecode($swstuff[3]); } $fdir = $dir; } if (isset($_POST['inspec1'])) { $inspec1 = urldecode($_POST['inspec1']); } if (isset($_POST['inspec2'])) { $inspec2 = urldecode($_POST['inspec2']); } if (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false) { $dir = str_replace(":80/","/",str_replace("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/", str_replace("PHP/", "/", dirname(__FILE__) . "/"), $dir)); } $result = array(); function moredirs($inidea) { global $dirs; $idirs = 0; $dirs[sizeof($dirs)] = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $inidea); $cdir = scandir($inidea); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($inidea . DIRECTORY_SEPARATOR . $value)) { moredirs($inidea . DIRECTORY_SEPARATOR . $value); return 1; } } } return $idirs; } $dirs[sizeof($dirs)] = $dir; if (trim($fdir) == "") { $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { moredirs($dir . DIRECTORY_SEPARATOR . $value); } } } } if (sizeof($dirs) >= 1) { for ($j=0; $j" . "http:" . $pbs[1] . "
"; echo "" . explode("/", "http:" . $pbs[1])[-1 + sizeof(explode("/", "http:" . $pbs[1]))] . "
"; //$result[-1 + sizeof($result)] = str_replace("http:" . $pbs[1], "" . "http:" . $pbs[1] . "", $result[-1 + sizeof($result)]); } } else { $result[sizeof($result)] = $filename; } } } } if (1 == 1 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { $dirs[$j] = str_replace(str_replace("PHP/", "/", dirname(__FILE__) . "/"), "http://" . str_replace(":80/","/",$_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/"), $dirs[$j]); } } } $fis = "Files"; if (isset($_GET['inspec1']) && isset($_GET['inspec2'])) { $fis = str_replace(" and ", "", "Files containing " . $inspec1 . " and " . $inspec2 . " "); } else if (isset($_GET['inspec1'])) { $fis = "Files containing " . $inspec1; } else if (isset($_POST['inspec1']) && isset($_POST['inspec2'])) { $fis = str_replace(" and ", "", "Files containing " . $inspec1 . " and " . $inspec2 . " "); } else if (isset($_POST['inspec1'])) { $fis = "Files containing " . $inspec1; } if (isset($_GET['subdirectory']) || isset($_POST['subdirectory'])) { // web browsing if (1 == 1 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { if (sizeof($dirs) >= 1) { for ($j=0; $j

Directories ...


" . $fis . " ...

'; } echo '
'; } else { echo "\n\nDirectories ...\n"; print_r($dirs); echo "\n\n" . $fis . " ...\n"; print_r($result); } // business logic } ?>