인증서 생성기 화면 및 관련 작업
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Npgsql;
|
||||
using OpcPks.Core.Data;
|
||||
using OpcPks.Core.Services;
|
||||
using OpcPks.Core.Models; // CertRequestModel 참조 추가
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,13 +11,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OpcPks.Web.Controllers;
|
||||
|
||||
[Route("Engineering")] // 🚨 경로를 명시적으로 고정
|
||||
[Route("Engineering")]
|
||||
public class EngineeringController : Controller
|
||||
{
|
||||
[HttpGet("TagExplorer")] // Engineering/TagExplorer
|
||||
// 하니웰 데이터 및 PKI 경로 고정
|
||||
private readonly string _basePath = "/home/pacer/projects/OpcPksPlatform/OpcPks.Core/Data";
|
||||
|
||||
#region [기존 기능: 태그 탐사 및 관리]
|
||||
|
||||
[HttpGet("TagExplorer")]
|
||||
public IActionResult TagExplorer() => View();
|
||||
|
||||
[HttpGet("Admin")] // Engineering/Admin
|
||||
[HttpGet("Admin")]
|
||||
public IActionResult Admin() => View();
|
||||
|
||||
[HttpPost("SearchByFilter")]
|
||||
@@ -100,34 +106,20 @@ public class EngineeringController : Controller
|
||||
[HttpPost("RunCrawler")]
|
||||
public async Task<IActionResult> RunCrawler()
|
||||
{
|
||||
Console.WriteLine("\n[API] === RunCrawler 요청 수신됨 ===");
|
||||
try
|
||||
{
|
||||
try {
|
||||
var sessionManager = new OpcSessionManager();
|
||||
var session = await sessionManager.GetSessionAsync();
|
||||
|
||||
if (session == null || !session.Connected)
|
||||
{
|
||||
Console.WriteLine("❌ [API] 세션 연결 실패!");
|
||||
return BadRequest(new { message = "하니웰 서버 연결 실패." });
|
||||
}
|
||||
|
||||
var crawler = new HoneywellCrawler(session);
|
||||
string csvPath = @"/home/pacer/projects/OpcPksPlatform/OpcPks.Core/Data/Honeywell_FullMap.csv";
|
||||
string csvPath = Path.Combine(_basePath, "Honeywell_FullMap.csv");
|
||||
|
||||
string dir = Path.GetDirectoryName(csvPath);
|
||||
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
||||
|
||||
await crawler.RunAsync("ns=1;s=$assetmodel", csvPath);
|
||||
|
||||
Console.WriteLine("✅ [API] 모든 탐사 공정 완료!");
|
||||
return Ok(new { message = "탐사 및 CSV 생성 완료!" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"❌ [API] 치명적 오류: {ex.Message}");
|
||||
return BadRequest(new { message = ex.Message });
|
||||
}
|
||||
catch (Exception ex) { return BadRequest(new { message = ex.Message }); }
|
||||
}
|
||||
|
||||
[HttpPost("ImportCsv")]
|
||||
@@ -136,10 +128,11 @@ public class EngineeringController : Controller
|
||||
try {
|
||||
using var conn = new NpgsqlConnection(DbConfig.ConnectionString);
|
||||
await conn.OpenAsync();
|
||||
var sql = @"TRUNCATE raw_node_map;
|
||||
COPY raw_node_map(level, node_class, name, node_id)
|
||||
FROM '/home/pacer/projects/OpcPksPlatform/OpcPks.Core/Data/Honeywell_FullMap.csv'
|
||||
DELIMITER ',' CSV HEADER;";
|
||||
string csvPath = Path.Combine(_basePath, "Honeywell_FullMap.csv");
|
||||
var sql = $@"TRUNCATE raw_node_map;
|
||||
COPY raw_node_map(level, node_class, name, node_id)
|
||||
FROM '{csvPath}'
|
||||
DELIMITER ',' CSV HEADER;";
|
||||
using var cmd = new NpgsqlCommand(sql, conn);
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
return Ok(new { message = "DB 동기화 완료" });
|
||||
@@ -147,6 +140,48 @@ public class EngineeringController : Controller
|
||||
catch (Exception ex) { return BadRequest(ex.Message); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region [신규 기능: 하니웰 전용 인증서 관리]
|
||||
|
||||
[HttpGet("CertManager")]
|
||||
public IActionResult CertManager()
|
||||
{
|
||||
string pfxPath = Path.Combine(_basePath, "pki/own/private/OpcTestClient.pfx");
|
||||
|
||||
// 파일 존재 여부를 ViewData에 담아 보냅니다.
|
||||
ViewBag.IsCertExists = System.IO.File.Exists(pfxPath);
|
||||
|
||||
ViewBag.SuccessMsg = TempData["Success"];
|
||||
ViewBag.ErrorMsg = TempData["Error"];
|
||||
return View(new CertRequestModel());
|
||||
}
|
||||
|
||||
[HttpPost("GenerateCertificate")]
|
||||
public async Task<IActionResult> GenerateCertificate(CertRequestModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var generator = new CertificateGenerator(_basePath);
|
||||
var success = await generator.CreateHoneywellCertificateAsync(model);
|
||||
|
||||
if (success) {
|
||||
TempData["Success"] = "하니웰 FTE 대응 인증서가 생성 및 백업되었습니다.";
|
||||
return RedirectToAction("CertManager");
|
||||
}
|
||||
|
||||
TempData["Error"] = "인증서 생성 중 오류가 발생했습니다.";
|
||||
return RedirectToAction("CertManager");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TempData["Error"] = ex.Message;
|
||||
return RedirectToAction("CertManager");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class SearchRequest { public string TagTerm { get; set; } public List<string> Suffixes { get; set; } }
|
||||
public class TagRegistrationRequest { public string TagName { get; set; } public string NodeId { get; set; } public string DataType { get; set; } }
|
||||
}
|
||||
Reference in New Issue
Block a user