SIMON Master Console Rebuild
True command center for SIMON + WEB360
This rebuild gives you a cleaner production spine: interactive tree, live viewer, guarded editor, dynamic graphics, architecture map, and note storage. It is designed to sit beside your existing
console.php
and become the stronger replacement path.
Dashboard
Tree
Viewer
System Map
File Registry
Notes
Files
15,338
Folders
408
Scanned Size
3.84 GB
PHP Files
890
Editable Text Files
12,599
File viewer
guarded to /htdocs
/simon/old/20.php
<?php declare(strict_types=1); date_default_timezone_set('America/Chicago'); error_reporting(E_ALL); ini_set('display_errors', '1'); header('Content-Type: text/html; charset=utf-8'); if (!function_exists('str_contains')) { function str_contains($haystack, $needle) { return $needle !== '' && strpos((string)$haystack, (string)$needle) !== false; } } function s_sub($text, $start, $len = null) { if (function_exists('mb_substr')) { return $len === null ? mb_substr((string)$text, $start) : mb_substr((string)$text, $start, $len); } return $len === null ? substr((string)$text, $start) : substr((string)$text, $start, $len); } function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } function json_write($path, $data) { $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); if ($json === false) { $json = json_encode(['error'=>'json_encode_failed','message'=>json_last_error_msg()]); } file_put_contents($path, $json); } define('MAX_FILE_BYTES', 1048576); define('MAX_LINES_PREVIEW', 14); $defaultRoot = isset($_SERVER['DOCUMENT_ROOT']) && $_SERVER['DOCUMENT_ROOT'] ? realpath($_SERVER['DOCUMENT_ROOT']) : realpath(dirname(__DIR__, 2)); if (!$defaultRoot) $defaultRoot = dirname(__DIR__, 2); $scanRoot = $defaultRoot; $dataDir = $scanRoot . '/simon/data/scans'; if (!is_dir($dataDir)) { @mkdir($dataDir, 0775, true); } function rel_path($path, $root) { $root = rtrim(str_replace('\\', '/', (string)$root), '/'); $path = str_replace('\\', '/', (string)$path); if (strpos($path, $root) === 0) { $out = substr($path, strlen($root)); return $out !== '' ? $out : '/'; } return $path; } function file_ext($path) { return strtolower(pathinfo((string)$path, PATHINFO_EXTENSION)); } function infer_kind($path) { $ext = file_ext($path); $map = [ 'php'=>'php','js'=>'javascript','mjs'=>'javascript','cjs'=>'javascript','css'=>'stylesheet', 'json'=>'json','xml'=>'xml','txt'=>'text','md'=>'text','log'=>'text', 'jpg'=>'image','jpeg'=>'image','png'=>'image','gif'=>'image','webp'=>'image','svg'=>'image','ico'=>'image', 'mp4'=>'media','mov'=>'media','webm'=>'media','mp3'=>'media','wav'=>'media', 'zip'=>'archive','gz'=>'archive','tar'=>'archive' ]; return isset($map[$ext]) ? $map[$ext] : ($ext !== '' ? $ext : 'unknown'); } function infer_module($relative) { $r = strtolower((string)$relative); $map = [ '/simon/' => 'SIMON', '/web360/' => 'WEB360', '/social/' => 'SOCIAL', '/api/' => 'API', '/_inc/' => 'INCLUDES', '/data/' => 'DATA', '/storage/' => 'STORAGE', '/assets/' => 'ASSETS', '/tools/' => 'TOOLS', ]; foreach ($map as $needle => $module) if (strpos($r, $needle) !== false) return $module; return 'ROOT'; } function classify_purpose($relative, $content, $kind) { $r = strtolower((string)$relative); $c = strtolower((string)$content); if ($kind === 'image') return 'branding_or_media_asset'; if (strpos($r, 'dashboard') !== false || strpos($c, 'dashboard') !== false) return 'dashboard_ui'; if (strpos($r, 'console') !== false || strpos($c, 'command center') !== false) return 'operator_console'; if (strpos($r, 'api/') !== false || preg_match('/header\s*\(\s*["\']content-type:\s*application\//i', $content)) return 'api_endpoint'; if (strpos($r, '/_inc/') !== false || preg_match('/\bfunction\s+h\s*\(/', $content)) return 'shared_include_or_library'; if (strpos($r, 'config') !== false || strpos($r, 'settings') !== false) return 'configuration'; if (strpos($r, 'log') !== false || strpos($r, 'scan') !== false) return 'logging_or_diagnostics'; if (strpos($r, 'security') !== false || strpos($c, 'x-robots-tag') !== false) return 'security_or_policy'; if (strpos($r, 'template') !== false || strpos($r, 'generator') !== false) return 'generation_or_template'; if (strpos($r, 'viewer') !== false || strpos($r, 'preview') !== false) return 'viewer_or_preview'; if (preg_match('/<html|<!doctype html/i', $content)) return 'rendered_page'; return 'general_support'; } function safe_read($path) { if (!is_file($path) || !is_readable($path)) return ''; $size = @filesize($path); if ($size === false || $size > MAX_FILE_BYTES) return ''; $data = @file_get_contents($path); return is_string($data) ? $data : ''; } function line_count_custom($content) { return $content === '' ? 0 : substr_count($content, "\n") + 1; } function first_nonempty_lines($content, $max) { $lines = preg_split('/\R/', (string)$content); if (!is_array($lines)) $lines = []; $out = []; foreach ($lines as $line) { $trim = trim($line); if ($trim === '') continue; $out[] = s_sub($trim, 0, 180); if (count($out) >= $max) break; } return $out; } function extract_paths($content) { preg_match_all('/(?:include|require)(?:_once)?\s*\(?\s*["\']([^"\']+)["\']/i', $content, $a); preg_match_all('/(?:href|src|action|fetch\s*\(|url:\s*)\s*=*\s*\(?\s*["\']([^"\']+)["\']/i', $content, $b); $all = array_merge(isset($a[1]) ? $a[1] : [], isset($b[1]) ? $b[1] : []); $matches = []; foreach ($all as $m) { $m = trim($m); if ($m === '' || strpos($m, 'http://') === 0 || strpos($m, 'https://') === 0 || strpos($m, 'data:') === 0 || strpos($m, '#') === 0) continue; $matches[] = $m; } return array_values(array_unique($matches)); } function extract_forms($content) { preg_match_all('/<form[^>]*action=["\']([^"\']*)["\'][^>]*method=["\']?([^"\' >]+)?/i', $content, $m, PREG_SET_ORDER); $out = []; foreach ($m as $row) $out[] = ['action' => isset($row[1]) ? $row[1] : '', 'method' => strtoupper(isset($row[2]) ? $row[2] : 'GET')]; return $out; } function extract_functions($content) { preg_match_all('/function\s+([a-zA-Z0-9_]+)\s*\(/', $content, $m); $list = isset($m[1]) ? array_values(array_unique($m[1])) : []; return array_slice($list, 0, 40); } function secret_hits($content) { $rules = [ 'possible_password' => '/password\s*[:=]/i', 'possible_secret' => '/secret\s*[:=]/i', 'possible_api_key' => '/(?:api[_-]?key|token|bearer)\s*[:=]/i', 'private_key_block' => '/-----BEGIN [A-Z ]*PRIVATE KEY-----/', 'db_credentials' => '/(?:db_pass|db_user|smtp_password|access_token_ref|client_secret)/i', ]; $hits = []; foreach ($rules as $label => $pattern) if (preg_match($pattern, $content)) $hits[] = $label; return $hits; } function risk_level_custom($relative, $secretHits, $content) { $r = strtolower((string)$relative); if (!empty($secretHits)) return 'critical'; if (strpos($r, '.env') !== false || strpos($r, 'config') !== false || strpos($r, 'backup') !== false || strpos($r, '/logs/') !== false) return 'warn'; if (preg_match('/chmod\(|shell_exec|exec\(|system\(|passthru\(/i', $content)) return 'warn'; return 'ok'; } function what_from_content($relative, $purpose, $content) { $head = first_nonempty_lines($content, 4); $summary = $head ? implode(' | ', $head) : basename((string)$relative); return $purpose . ': ' . s_sub($summary, 0, 220); } function why_from_content($purpose, $deps, $forms, $funcs) { $parts = [$purpose]; if ($deps) $parts[] = 'connects to ' . count($deps) . ' internal references'; if ($forms) $parts[] = 'handles ' . count($forms) . ' forms/actions'; if ($funcs) $parts[] = 'defines ' . count($funcs) . ' functions'; return implode('; ', $parts); } function how_from_content($deps, $forms, $funcs, $secretHits) { $parts = []; if ($deps) $parts[] = 'includes/routes/assets=' . count($deps); if ($forms) $parts[] = 'forms=' . count($forms); if ($funcs) $parts[] = 'functions=' . count($funcs); if ($secretHits) $parts[] = 'security_flags=' . implode(',', $secretHits); return $parts ? implode(' | ', $parts) : 'static_or_low-signal'; } function who_from_relative($relative) { $r = strtolower((string)$relative); if (strpos($r, '/simon/') !== false) return 'SIMON operator'; if (strpos($r, '/web360/') !== false) return 'WEB360 builder'; if (strpos($r, '/social/') !== false) return 'SOCIAL operator'; if (strpos($r, '/api/') !== false) return 'system integrations'; if (strpos($r, '/_inc/') !== false) return 'shared platform'; return 'root/site'; } function scan_tree($root) { $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); $files = []; $dirs = []; foreach ($rii as $item) { $path = $item->getPathname(); $relative = rel_path($path, $root); if ($item->isDir()) { $dirs[] = $relative; continue; } $content = safe_read($path); $kind = infer_kind($path); $module = infer_module($relative); $purpose = classify_purpose($relative, $content, $kind); $deps = extract_paths($content); $forms = extract_forms($content); $funcs = extract_functions($content); $secrets = secret_hits($content); $risk = risk_level_custom($relative, $secrets, $content); $mtime = @filemtime($path); if (!$mtime) $mtime = time(); $files[] = [ 'path' => $relative, 'name' => basename($path), 'module' => $module, 'kind' => $kind, 'purpose' => $purpose, 'size_bytes' => @filesize($path) ?: 0, 'modified_at' => date('c', $mtime), 'line_count' => line_count_custom($content), 'depends_on' => $deps, 'forms' => $forms, 'functions' => $funcs, 'secret_flags' => $secrets, 'risk' => $risk, 'preview' => first_nonempty_lines($content, MAX_LINES_PREVIEW), 'quick_ref' => [ 'one_line' => s_sub(what_from_content($relative, $purpose, $content), 0, 240), 'status' => $risk === 'critical' ? 'needs_security_review' : ($risk === 'warn' ? 'review_recommended' : 'normal'), ], 'five_w_one_h' => [ 'what' => s_sub(what_from_content($relative, $purpose, $content), 0, 300), 'why' => s_sub(why_from_content($purpose, $deps, $forms, $funcs), 0, 260), 'where' => $relative, 'when' => date('Y-m-d H:i:s', $mtime), 'who' => who_from_relative($relative), 'how' => s_sub(how_from_content($deps, $forms, $funcs, $secrets), 0, 260), 'event' => $risk === 'critical' ? 'security_flag' : (!empty($forms) ? 'user_interaction' : (!empty($deps) ? 'dependency_or_route' : 'static_component')), ], ]; } return [$files, $dirs]; } function summarize($files, $dirs, $scanRoot) { $byModule = []; $byKind = []; $risk = ['ok'=>0,'warn'=>0,'critical'=>0]; foreach ($files as $f) { $byModule[$f['module']] = isset($byModule[$f['module']]) ? $byModule[$f['module']] + 1 : 1; $byKind[$f['kind']] = isset($byKind[$f['kind']]) ? $byKind[$f['kind']] + 1 : 1; $risk[$f['risk']] = isset($risk[$f['risk']]) ? $risk[$f['risk']] + 1 : 1; } ksort($byModule); ksort($byKind); return ['scanned_at'=>date('c'),'root'=>$scanRoot,'total_files'=>count($files),'total_dirs'=>count($dirs),'modules'=>$byModule,'kinds'=>$byKind,'risk'=>$risk]; } $run = isset($_GET['run']) && $_GET['run'] === '1'; $result = null; $exports = []; $fatal = null; if ($run) { try { list($files, $dirs) = scan_tree($scanRoot); $summary = summarize($files, $dirs, $scanRoot); $registry = ['meta'=>$summary,'files'=>$files,'directories'=>$dirs]; $reviews = []; $quick = []; $five = []; $deps = []; $security = []; foreach ($files as $f) { $reviews[] = [ 'path'=>$f['path'],'module'=>$f['module'],'purpose'=>$f['purpose'],'risk'=>$f['risk'], 'review'=>$f['five_w_one_h']['why'], 'recommended_action'=>$f['risk']==='critical' ? 'inspect secrets/config exposure and move secrets to protected refs' : ($f['risk']==='warn' ? 'review access control, permissions, and execution paths' : 'keep and map dependencies'), ]; $quick[] = ['path'=>$f['path'],'summary'=>$f['quick_ref']['one_line'],'status'=>$f['quick_ref']['status']]; $five[] = ['path'=>$f['path'],'5w1h'=>$f['five_w_one_h']]; $deps[] = ['path'=>$f['path'],'depends_on'=>$f['depends_on'],'forms'=>$f['forms']]; if ($f['risk'] !== 'ok' || !empty($f['secret_flags'])) $security[] = ['path'=>$f['path'],'risk'=>$f['risk'],'secret_flags'=>$f['secret_flags'],'notes'=>$f['five_w_one_h']['how']]; } $masterTemplate = [ 'template_name'=>'SIMON Master File Template','generated_at'=>date('c'),'root'=>$scanRoot,'schema_version'=>'1.0', 'required_json_outputs'=>['scan_summary.json','master_registry.json','file_reviews.json','quick_ref.json','five_w_one_h_master.json','dependency_map.json','security_events.json'], '5w1h_standard'=>['what','why','where','when','who','how','event'], 'recommended_next_jobs'=>['chunked_php_review','ui_consistency_review','include_dependency_validation','security_hardening_review','orphan_file_detection'], 'module_targets'=>array_keys($summary['modules']) ]; $exports = [ 'scan_summary.json' => $dataDir . '/scan_summary.json', 'master_registry.json' => $dataDir . '/master_registry.json', 'file_reviews.json' => $dataDir . '/file_reviews.json', 'quick_ref.json' => $dataDir . '/quick_ref.json', 'five_w_one_h_master.json' => $dataDir . '/five_w_one_h_master.json', 'dependency_map.json' => $dataDir . '/dependency_map.json', 'security_events.json' => $dataDir . '/security_events.json', 'master_template.json' => $dataDir . '/master_template.json', ]; json_write($exports['scan_summary.json'], $summary); json_write($exports['master_registry.json'], $registry); json_write($exports['file_reviews.json'], $reviews); json_write($exports['quick_ref.json'], $quick); json_write($exports['five_w_one_h_master.json'], $five); json_write($exports['dependency_map.json'], $deps); json_write($exports['security_events.json'], $security); json_write($exports['master_template.json'], $masterTemplate); $result = compact('summary', 'files', 'security', 'exports'); } catch (Throwable $e) { $fatal = $e->getMessage(); } catch (Exception $e) { $fatal = $e->getMessage(); } } ?><!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SIMON Master Scanner</title><style>:root{--bg:#06111d;--panel:rgba(10,20,38,.88);--line:rgba(120,190,255,.15);--text:#edf6ff;--muted:#97afca}*{box-sizing:border-box}body{margin:0;font:14px/1.5 Inter,system-ui,sans-serif;color:var(--text);background:linear-gradient(180deg,#06111d,#030811)}.wrap{max-width:1500px;margin:auto;padding:22px}.panel{background:var(--panel);border:1px solid var(--line);border-radius:20px;padding:18px;margin-bottom:18px}.grid{display:grid;gap:16px}.g4{grid-template-columns:repeat(4,1fr)}.g2{grid-template-columns:1.1fr .9fr}.badge{display:inline-block;padding:4px 9px;border-radius:999px;font-size:12px;font-weight:700}.ok{background:rgba(97,240,174,.12);color:#dfffee}.warn{background:rgba(255,211,111,.12);color:#fff0cd}.critical{background:rgba(255,122,147,.12);color:#ffd9e1}.btn{display:inline-block;padding:12px 14px;border-radius:12px;background:linear-gradient(135deg,rgba(111,231,255,.15),rgba(162,135,255,.15));color:#fff;text-decoration:none;font-weight:800;border:1px solid rgba(255,255,255,.08)}.code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}.muted{color:var(--muted)} table{width:100%;border-collapse:collapse;min-width:920px} th,td{padding:10px 12px;border-bottom:1px solid rgba(255,255,255,.08);vertical-align:top;text-align:left} th{font-size:12px;color:var(--muted);text-transform:uppercase} .table{overflow:auto;border:1px solid var(--line);border-radius:16px}@media(max-width:1100px){.g4,.g2{grid-template-columns:1fr}}</style></head><body><div class="wrap"><div class="panel"><div style="display:flex;justify-content:space-between;gap:18px;align-items:center;flex-wrap:wrap"><div><div class="muted" style="text-transform:uppercase;letter-spacing:.12em;font-size:12px">SIMON Intelligence • htdocs scanner • 5W1H registry</div><h1 style="margin:8px 0 10px;font-size:36px">Master Scanner + JSON Template Builder</h1><div class="muted">Scans the live htdocs tree, classifies files, inspects contents, builds dependency clues, and writes master JSON outputs into <span class="code">/simon/data/scans/</span>.</div></div><div><a class="btn" href="?run=1">Run Full Scan Now</a></div></div></div><?php if ($fatal): ?><div class="panel"><h2 style="margin-top:0;color:#ffb3c1">Scanner Error</h2><div class="code"><?php echo h($fatal); ?></div><div class="muted" style="margin-top:8px">Common causes: older PHP version, unreadable directories, or write permission issues on /simon/data/scans/.</div></div><?php endif; ?><?php if (!$run): ?><div class="panel"><h2 style="margin-top:0">What this writes</h2><div class="grid g4"><div><strong>master_registry.json</strong><br><span class="muted">Full file inventory with module, purpose, risk, preview, dependencies, functions, forms.</span></div><div><strong>five_w_one_h_master.json</strong><br><span class="muted">Per-file What / Why / Where / When / Who / How / Event structure.</span></div><div><strong>quick_ref.json</strong><br><span class="muted">Compressed one-line memory for fast operator recall.</span></div><div><strong>security_events.json</strong><br><span class="muted">Files needing harder review due to config, secret, or execution risk.</span></div></div></div><?php endif; ?><?php if ($result): ?><div class="grid g4"><div class="panel"><div class="muted">Files</div><div style="font-size:32px;font-weight:900"><?php echo (int)$result['summary']['total_files']; ?></div></div><div class="panel"><div class="muted">Directories</div><div style="font-size:32px;font-weight:900"><?php echo (int)$result['summary']['total_dirs']; ?></div></div><div class="panel"><div class="muted">Warnings</div><div style="font-size:32px;font-weight:900"><?php echo (int)(isset($result['summary']['risk']['warn']) ? $result['summary']['risk']['warn'] : 0); ?></div></div><div class="panel"><div class="muted">Critical</div><div style="font-size:32px;font-weight:900"><?php echo (int)(isset($result['summary']['risk']['critical']) ? $result['summary']['risk']['critical'] : 0); ?></div></div></div><div class="grid g2"><div class="panel"><h2 style="margin-top:0">Module Breakdown</h2><div class="table"><table><thead><tr><th>Module</th><th>Files</th></tr></thead><tbody><?php foreach ($result['summary']['modules'] as $module => $count): ?><tr><td><?php echo h($module); ?></td><td><?php echo (int)$count; ?></td></tr><?php endforeach; ?></tbody></table></div></div><div class="panel"><h2 style="margin-top:0">JSON Exports</h2><div class="table"><table><thead><tr><th>File</th><th>Path</th></tr></thead><tbody><?php foreach ($exports as $name => $path): ?><tr><td><?php echo h($name); ?></td><td class="code"><?php echo h(rel_path($path, $scanRoot)); ?></td></tr><?php endforeach; ?></tbody></table></div></div></div><div class="panel"><h2 style="margin-top:0">Top Security Review Items</h2><div class="table"><table><thead><tr><th>Risk</th><th>Path</th><th>Flags</th><th>Notes</th></tr></thead><tbody><?php foreach (array_slice($result['security'], 0, 60) as $row): ?><tr><td><span class="badge <?php echo h($row['risk']); ?>"><?php echo h(strtoupper($row['risk'])); ?></span></td><td class="code"><?php echo h($row['path']); ?></td><td><?php echo h(implode(', ', $row['secret_flags'])); ?></td><td><?php echo h($row['notes']); ?></td></tr><?php endforeach; ?></tbody></table></div></div><div class="panel"><h2 style="margin-top:0">First 80 Files in Registry</h2><div class="table"><table><thead><tr><th>Path</th><th>Module</th><th>Purpose</th><th>Risk</th><th>5W1H Event</th></tr></thead><tbody><?php foreach (array_slice($result['files'], 0, 80) as $f): ?><tr><td class="code"><?php echo h($f['path']); ?></td><td><?php echo h($f['module']); ?></td><td><?php echo h($f['purpose']); ?></td><td><span class="badge <?php echo h($f['risk']); ?>"><?php echo h(strtoupper($f['risk'])); ?></span></td><td><?php echo h($f['five_w_one_h']['event']); ?></td></tr><?php endforeach; ?></tbody></table></div></div><?php endif; ?></div></body></html>
Save file
Quick jump
open a path
Open