« Back to History
activity_scan_report.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php // Activity Logging Usage Scanner for ERP root files $erpDir = realpath(__DIR__ . '/..'); $files = scandir($erpDir); $keywords = [ 'log_activity', 'activity_log', 'activity_create', 'activity_update', 'activity_delete', 'user_activity_logs', 'activity_logger.php', ]; $results = []; foreach ($files as $file) { $full = $erpDir . DIRECTORY_SEPARATOR . $file; if ( is_file($full) && preg_match('/\.php$/i', $file) && $file !== basename(__FILE__) ) { $lines = @file($full, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $found = []; if ($lines) { foreach ($lines as $lnum => $line) { foreach ($keywords as $kw) { if (stripos($line, $kw) !== false) { $found[] = htmlspecialchars(trim($line)); } } } } if ($found) { $results[] = [ 'file' => $file, 'matches' => $found, ]; } } } ?><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ERP Activity Logging Scan Report</title> <style> body { font-family: Arial, sans-serif; background: #f8fafc; color: #222; } table { border-collapse: collapse; width: 100%; background: #fff; } th, td { border: 1px solid #ccc; padding: 8px; } th { background: #222; color: #fff; } tr:nth-child(even) { background: #f3f4f6; } .file { font-weight: bold; color: #1d4ed8; } .code { font-family: monospace; font-size: 0.97em; color: #0a0; } </style> </head> <body> <h2>ERP Activity Logging Scan Report (Root Files Only)</h2> <p>Scans only direct PHP files in <b>erp/</b> (no subfolders). Shows lines using activity logging or related keywords.</p> <table> <tr> <th>File</th> <th>Matched Lines</th> </tr> <?php if ($results): ?> <?php foreach ($results as $row): ?> <tr> <td class="file"><?= htmlspecialchars($row['file']) ?></td> <td> <?php foreach ($row['matches'] as $m): ?> <div class="code"><?= $m ?></div> <?php endforeach; ?> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr><td colspan="2">No activity logging usage found in root files.</td></tr> <?php endif; ?> </table> </body> </html> error_reporting(E_ALL); ini_set('display_errors', 1); $baseDir = realpath(__DIR__ . '/../'); if (!$baseDir || !is_dir($baseDir)) { die('ERP base directory not found'); } /* ============================================================ SETTINGS ============================================================ */ $excludeDirs = [ 'vendor', 'node_modules', '.git', 'storage', 'cache', 'logs', 'tmp', ]; $excludeFiles = [ 'activity_helper.php', ]; /* ============================================================ HELPERS ============================================================ */ function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } function matchesAnyPattern($content, array $patterns) { foreach ($patterns as $pattern) { if (preg_match($pattern, $content) === 1) { return true; } } return false; } function shouldSkipPath($path, array $excludeDirs) { foreach ($excludeDirs as $dir) { if ( stripos( $path, DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR ) !== false ) { return true; } } return false; } /* ============================================================ SCAN ============================================================ */ $detectionPatterns = [ 'create' => [ '/\bINSERT\s+INTO\b/i', ], 'edit' => [ '/\bUPDATE\b/i', '/(?<![a-z])edit(?![a-z])/i', '/(?<![a-z])modify(?![a-z])/i', '/(?<![a-z])update(?![a-z])/i', ], 'delete' => [ '/\bDELETE\s+FROM\b/i', '/(?<![a-z])delete(?![a-z])/i', ], 'export' => [ '/(?<![a-z])export(?![a-z])/i', '/(?<![a-z])csv(?![a-z])/i', '/(?<![a-z])excel(?![a-z])/i', '/(?<![a-z])xlsx(?![a-z])/i', '/(?<![a-z])download(?![a-z])/i', '/\bfputcsv\b/i', ], 'print' => [ '/\bwindow\s*\.\s*print\b/i', '/(?<![a-z])print(?![a-z])/i', '/(?<![a-z])pdf(?![a-z])/i', '/\bdompdf\b/i', '/\btcpdf\b/i', '/\bmpdf\b/i', ], 'approve' => [ '/(?<![a-z])approve(?![a-z])/i', '/(?<![a-z])approval(?![a-z])/i', '/(?<![a-z])approved(?![a-z])/i', ], 'status' => [ '/(?<![a-z])status(?![a-z])/i', '/(?<![a-z])active(?![a-z])/i', '/(?<![a-z])inactive(?![a-z])/i', '/(?<![a-z])enable(?![a-z])/i', '/(?<![a-z])disable(?![a-z])/i', ], ]; $results = []; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($baseDir) ); foreach ($iterator as $file) { if (!$file->isFile()) { continue; } $path = $file->getPathname(); if (shouldSkipPath($path, $excludeDirs)) { continue; } if ( strtolower(pathinfo($path, PATHINFO_EXTENSION)) !== 'php' ) { continue; } $filename = basename($path); if (in_array($filename, $excludeFiles, true)) { continue; } $content = @file_get_contents($path); if ($content === false) { continue; } $hasCreate = matchesAnyPattern( $content, $detectionPatterns['create'] ); $hasEdit = matchesAnyPattern( $content, $detectionPatterns['edit'] ); $hasDelete = matchesAnyPattern( $content, $detectionPatterns['delete'] ); $hasExport = matchesAnyPattern( $content, $detectionPatterns['export'] ); $hasPrint = matchesAnyPattern( $content, $detectionPatterns['print'] ); $hasApprove = matchesAnyPattern( $content, $detectionPatterns['approve'] ); $hasStatus = matchesAnyPattern( $content, $detectionPatterns['status'] ); if ( !$hasCreate && !$hasEdit && !$hasDelete && !$hasExport && !$hasPrint && !$hasApprove && !$hasStatus ) { continue; } $hasHelper = ( stripos($content, 'activity_helper.php') !== false || stripos($content, 'log_activity(') !== false ); $relative = str_replace($baseDir, '', $path); $results[] = [ 'file' => $relative, 'create' => $hasCreate ? 'YES' : '-', 'edit' => $hasEdit ? 'YES' : '-', 'delete' => $hasDelete ? 'YES' : '-', 'export' => $hasExport ? 'YES' : '-', 'print' => $hasPrint ? 'YES' : '-', 'approve' => $hasApprove ? 'YES' : '-', 'status' => $hasStatus ? 'YES' : '-', 'has_helper' => $hasHelper ? 'YES' : 'NO', ]; } /* ============================================================ SORT ============================================================ */ usort($results, function ($a, $b) { return strcmp($a['file'], $b['file']); }); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ERP Activity Scan Report </title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" > <style> body{ background:#f4f6f9; } .scan-wrap{ max-width:1400px; margin:30px auto; } .table td, .table th{ vertical-align:middle; font-size:13px; } .badge-yes{ background:#198754; } .badge-no{ background:#dc3545; } </style> </head> <body> <div class="container-fluid scan-wrap"> <div class="card shadow-sm border-0"> <div class="card-header bg-dark text-white"> <h4 class="mb-0"> ERP Activity Logging Scan Report </h4> </div> <div class="card-body"> <div class="mb-3"> <strong> Total Files Found: </strong> <?= count($results) ?> </div> <div class="table-responsive"> <table class="table table-bordered table-hover bg-white align-middle"> <thead class="table-light"> <tr> <th width="60">#</th> <th>File</th> <th width="90">CREATE</th> <th width="90">EDIT</th> <th width="90">DELETE</th> <th width="90">EXPORT</th> <th width="90">PRINT</th> <th width="90">APPROVE</th> <th width="90">STATUS</th> <th width="140"> Logging Exists </th> </tr> </thead> <tbody> <?php if ($results): ?> <?php foreach ($results as $k => $r): ?> <tr> <td> <?= $k + 1 ?> </td> <td> <code> <?= h($r['file']) ?> </code> </td> <td class="text-center"> <?= $r['create'] ?> </td> <td class="text-center"> <?= $r['edit'] ?> </td> <td class="text-center"> <?= $r['delete'] ?> </td> <td class="text-center"> <?= $r['export'] ?> </td> <td class="text-center"> <?= $r['print'] ?> </td> <td class="text-center"> <?= $r['approve'] ?> </td> <td class="text-center"> <?= $r['status'] ?> </td> <td class="text-center"> <?php if ($r['has_helper'] === 'YES'): ?> <span class="badge badge-yes"> YES </span> <?php else: ?> <span class="badge badge-no"> NO </span> <?php endif; ?> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="10" class="text-center py-4" > No matching files found. </td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> </body> </html>