@@ -372,8 +372,6 @@ function sanitizeLogInput($input) {
372372 '/services/status ' => 15 , // 15 seconds - service status should be fresh
373373 '/sites ' => 120 , // 2 minutes - site list rarely changes
374374 '/sites/count ' => 120 , // 2 minutes
375- '/activity/recent ' => 30 , // 30 seconds
376- '/alerts ' => 30 , // 30 seconds
377375 '/tools/filemanager/status ' => 300 , // 5 minutes - rarely changes
378376 '/monitoring/uptime ' => 60 , // 1 minute
379377 '/monitoring/uptime/monitors ' => 60 , // 1 minute
@@ -573,8 +571,6 @@ function outputCachedResponse($data, $ttl) {
573571 '/services/status ' ,
574572 '/sites ' ,
575573 '/sites/count ' ,
576- '/activity/recent ' ,
577- '/alerts ' ,
578574 '/tools/filemanager/status ' ,
579575 '/monitoring/uptime ' ,
580576 '/monitoring/uptime/monitors ' ,
@@ -657,12 +653,6 @@ function handleBatchRequest() {
657653 case '/sites/count ' :
658654 handleSitesCount ();
659655 break ;
660- case '/activity/recent ' :
661- handleRecentActivity ();
662- break ;
663- case '/alerts ' :
664- handleAlerts ();
665- break ;
666656 case '/tools/filemanager/status ' :
667657 handleFileManagerStatus ();
668658 break ;
@@ -784,14 +774,6 @@ function handleCacheClear() {
784774 handleSitesCount ();
785775 break ;
786776
787- case '/activity/recent ' :
788- handleRecentActivity ();
789- break ;
790-
791- case '/alerts ' :
792- case '/alerts/ ' :
793- handleAlerts ();
794- break ;
795777
796778 case '/tools/filemanager/status ' :
797779 handleFileManagerStatus ();
@@ -948,25 +930,6 @@ function handleSitesCount() {
948930 }
949931}
950932
951- function handleRecentActivity () {
952- try {
953- echo json_encode (sanitizeOutput (getRecentActivity ())); // codacy:ignore - echo required for JSON API response
954- } catch (Exception $ e ) {
955- http_response_code (500 );
956- logSecurityEvent ('Recent activity error ' , $ e ->getMessage ());
957- echo json_encode (['error ' => 'Unable to retrieve recent activity ' ]); // codacy:ignore - echo required for JSON API response
958- }
959- }
960-
961- function handleAlerts () {
962- try {
963- echo json_encode (sanitizeOutput (getSystemAlerts ())); // codacy:ignore - echo required for JSON API response
964- } catch (Exception $ e ) {
965- http_response_code (500 );
966- logSecurityEvent ('Alerts error ' , $ e ->getMessage ());
967- echo json_encode (['error ' => 'Unable to retrieve alerts ' ]); // codacy:ignore - echo required for JSON API response
968- }
969- }
970933
971934function handleFileManagerStatus () {
972935 try {
@@ -1413,116 +1376,6 @@ function getWordPressVersion($document_root) {
14131376 }
14141377}
14151378
1416- // Recent activity helpers
1417- function checkRecentSSHActivity () {
1418- $ auth_log = '/var/log/auth.log ' ;
1419- $ real_auth_log = realpath ($ auth_log ); // codacy:ignore - realpath() required for log file path validation in standalone API
1420-
1421- if (!isValidLogFile ($ real_auth_log , $ auth_log )) {
1422- return null ;
1423- }
1424-
1425- $ handle = fopen ($ real_auth_log , 'r ' ); // codacy:ignore - fopen() required for log file reading in standalone API
1426- if (!$ handle ) {
1427- return null ;
1428- }
1429-
1430- $ ssh_activity = parseAuthLogForActivity ($ handle );
1431- fclose ($ handle ); // codacy:ignore - fclose() required for proper file handle cleanup in standalone API
1432-
1433- return $ ssh_activity ;
1434- }
1435-
1436- function getRecentActivity () {
1437- $ activities = [];
1438-
1439- try {
1440- // Check for SSH login activity
1441- $ ssh_activity = checkRecentSSHActivity ();
1442- if ($ ssh_activity ) {
1443- $ activities [] = $ ssh_activity ;
1444- }
1445-
1446- // Add system status update
1447- $ activities [] = [
1448- 'message ' => 'System status updated ' ,
1449- 'time ' => 'Just now ' ,
1450- 'icon ' => 'fa-sync-alt '
1451- ];
1452- } catch (Exception $ e ) {
1453- logSecurityEvent ('Recent activity error ' , $ e ->getMessage ());
1454- // Add fallback activity
1455- $ activities [] = [
1456- 'message ' => 'System monitoring active ' ,
1457- 'time ' => 'Just now ' ,
1458- 'icon ' => 'fa-shield-alt '
1459- ];
1460- }
1461-
1462- return $ activities ;
1463- }
1464-
1465- function isValidLogFile ($ real_path , $ expected_path ) {
1466- return $ real_path &&
1467- $ real_path === $ expected_path &&
1468- file_exists ($ real_path ) && // codacy:ignore - file_exists() required for log file validation in standalone API
1469- is_readable ($ real_path ); // codacy:ignore - is_readable() required for log file validation in standalone API
1470- }
1471-
1472- function parseAuthLogForActivity ($ handle ) {
1473- $ file_size = filesize ('/var/log/auth.log ' ); // codacy:ignore - filesize() required for log file size checking in standalone API
1474- if (!$ file_size || $ file_size <= 0 ) {
1475- return null ;
1476- }
1477-
1478- fseek ($ handle , max (0 , $ file_size - 1024 ), SEEK_SET ); // codacy:ignore - fseek() required for log file positioning in standalone API
1479- $ content = fread ($ handle , 1024 ); // codacy:ignore - fread() required for log file reading in standalone API
1480-
1481- if ($ content && strpos ($ content , 'Accepted ' ) !== false ) {
1482- return [
1483- 'message ' => 'Recent SSH login detected ' ,
1484- 'time ' => '5 minutes ago ' ,
1485- 'icon ' => 'fa-sign-in-alt '
1486- ];
1487- }
1488-
1489- return null ;
1490- }
1491-
1492- function getSystemAlerts () {
1493- $ alerts = [];
1494-
1495- // Check disk usage
1496- $ disk_usage = (float )str_replace ('% ' , '' , getDiskUsage ());
1497- if ($ disk_usage > 90 ) {
1498- $ alerts [] = [
1499- 'message ' => 'High disk usage detected ' ,
1500- 'time ' => 'Now ' ,
1501- 'type ' => 'warning '
1502- ];
1503- }
1504-
1505- // Check memory usage
1506- $ memory_usage = (float )str_replace ('% ' , '' , getMemoryUsage ());
1507- if ($ memory_usage > 85 ) {
1508- $ alerts [] = [
1509- 'message ' => 'High memory usage detected ' ,
1510- 'time ' => 'Now ' ,
1511- 'type ' => 'warning '
1512- ];
1513- }
1514-
1515- // If no alerts, return success message
1516- if (empty ($ alerts )) {
1517- $ alerts [] = [
1518- 'message ' => 'All systems operational ' ,
1519- 'time ' => 'Just now ' ,
1520- 'type ' => 'info '
1521- ];
1522- }
1523-
1524- return $ alerts ;
1525- }
15261379
15271380// External services functions moved to external-services/external-services-api.php
15281381
0 commit comments