<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/php
&lt;?php
error_reporting(0);

/***
 * Small script to create graph from multiple users JSON's taken from MS Graph Explorer
 * (Search for a SharePoint site by keyword) keyword = %00
 ***/

$folder = "/mnt/hgfs/PentestOS/pentests/2020/Devon/MS_Graph/";

$mainArray = array();

$rootDir = getDirContents($folder, '/\.json$/');
foreach($rootDir as $h =&gt; $i){ // remove begining of vdb path (keeps clean)
    $rootDir[$h] = str_replace("sites_null_", "", str_replace(".json", "", str_replace($folder, "", $i)));
    //echo "Reading: ".$rootDir[$h]."\n";

    $jsonFile = file_get_contents($i);
	$jsonContents = json_decode($jsonFile, true);

	foreach($jsonContents as $j){
		foreach($j as $k){
			//echo "	".$k['name']." -&gt; ".$k['webUrl']."\n";
			$shortname[$k['name']] = $k['webUrl'];
			$rarw[$k['name']][] = $rootDir[$h];
		}
		//print_r($j);
	}
}
echo "Files: ".sizeof($rootDir)."\n";

foreach($shortname as $short =&gt; $long){
	$lenToShow = 120;
	if(strlen($long)&lt;$lenToShow)
		$long = str_pad($long, $lenToShow, "-");
	echo substr($long, 0, $lenToShow)." -&gt;	";
	
	//print_r($rarw[$short]);
	foreach($rarw[$short] as $shortname =&gt; $username){
		echo $username."	";

	}
	echo "\n";
}







function getDirContents($dir, $filter = '', &amp;$results = array()) {
    $files = scandir($dir);

    foreach($files as $key =&gt; $value){
        $path = realpath($dir.DIRECTORY_SEPARATOR.$value); 

        if(!is_dir($path)) {
            if(empty($filter) || preg_match($filter, $path)) $results[] = $path;
        } elseif($value != "." &amp;&amp; $value != "..") {
            getDirContents($path, $filter, $results);
        }
    }

    return $results;
} 

?&gt;</pre></body></html>