Add cancel shutdown feature and enhance system control access methods in dashboard

This commit is contained in:
Din
2025-08-08 12:00:42 +08:00
parent 1129f9a2b1
commit eceec1b72d
5 changed files with 265 additions and 22 deletions
+42
View File
@@ -227,6 +227,48 @@ namespace ResourceMonitorService.Controllers
return StatusCode(500, "Internal server error");
}
}
[HttpPost("cancel-shutdown")]
public ActionResult CancelShutdown()
{
try
{
// Execute the shutdown abort command
var processInfo = new ProcessStartInfo
{
FileName = "shutdown",
Arguments = "/a",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = Process.Start(processInfo);
process?.WaitForExit();
var exitCode = process?.ExitCode ?? -1;
string message;
if (exitCode == 0)
{
message = "Shutdown/restart canceled successfully";
_logger.LogInformation("Shutdown/restart canceled by user");
}
else
{
message = "No shutdown/restart was scheduled to cancel, or cancellation failed";
_logger.LogInformation("Attempted to cancel shutdown but none was scheduled");
}
return Ok(new { message });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error canceling shutdown command");
return StatusCode(500, "Internal server error");
}
}
}
public class SystemControlRequest