From ad6caa909c85fc79c0912b6ce0a5b58d1e262545 Mon Sep 17 00:00:00 2001 From: Nano Date: Sun, 3 May 2026 09:42:27 -0400 Subject: [PATCH] Read Abacus API key from server env var --- app/controllers/AdminController.asp | 4 +-- core/helpers.asp | 39 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/controllers/AdminController.asp b/app/controllers/AdminController.asp index 8e4f1b0..443f7f9 100644 --- a/app/controllers/AdminController.asp +++ b/app/controllers/AdminController.asp @@ -151,8 +151,8 @@ Class AdminController_Class End Sub Private Sub GeneratePostContentFromAI(ByRef post, ByRef generatedSummary, ByRef generatedBody) - Dim apiKey : apiKey = Trim(CStr(GetAppSetting("AbacusApiKey"))) - If Len(apiKey) = 0 Or LCase(apiKey) = "nothing" Then + Dim apiKey : apiKey = Trim(CStr(GetSecureSetting("AbacusApiKey", "ABACUS_API_KEY"))) + If Len(apiKey) = 0 Then Err.Raise 1, "AdminController.GeneratePostContentFromAI", "Abacus API key is not configured." End If diff --git a/core/helpers.asp b/core/helpers.asp index f8b3683..fcd29a8 100644 --- a/core/helpers.asp +++ b/core/helpers.asp @@ -56,6 +56,45 @@ Public Function GetAppSetting(key) GetAppSetting = "nothing" End Function +Public Function GetEnvironmentValue(name) + Dim shell, env, value + value = "" + + On Error Resume Next + Set shell = Server.CreateObject("WScript.Shell") + Set env = shell.Environment("PROCESS") + If Err.Number = 0 Then + value = env(name) + If Err.Number <> 0 Then + Err.Clear + value = "" + End If + Else + Err.Clear + End If + On Error GoTo 0 + + GetEnvironmentValue = Trim(CStr(value)) +End Function + +Public Function GetSecureSetting(key, envName) + Dim value + + value = Trim(CStr(GetAppSetting(key))) + If Len(value) > 0 And LCase(value) <> "nothing" Then + GetSecureSetting = value + Exit Function + End If + + value = Trim(CStr(GetEnvironmentValue(envName))) + If Len(value) > 0 Then + GetSecureSetting = value + Exit Function + End If + + GetSecureSetting = "" +End Function + Public Sub ShowServerVariables Dim varName, htmlTable htmlTable = ""