Yes - this is the missing datum: “Certify traps the standard output”.
Maybe it’s in the doc somewhere, but I didn’t see it.
Default exec modes across the board (rule of thumb: change nothing until you have to).
And yes – conflicts with buffering, async tasks, and who knows what else was a big worry.
The scripts are going to do a bunch of things using the cPanel API via Invoke-WebRequest:
- Install the new cert into/via cPanel
- Figure out if there’s wildcard subdomains that need to be updated
- Cleanout old garbage
Details subject to change of course.
I already know I can “hit” the cPanel API and get results, while running from Certify,
so all the rest is just grunt work now.
Just tested and maybe spotted a bug.
First, just:
Write-Output “$logpath1” # logpath1 is just a leftover handy text string
Write-Output “xxx”
This yields:
2023-08-06 20:45:06.193 -06:00 [INF] ---- Performing Task [On-Demand or Manual Execution] :: Run cPanel Powershell ----
2023-08-06 20:45:06.195 -06:00 [INF] Task [Run cPanel Powershell] :: Task is being has been forced to run. Normal status would be [Task is enabled but will not run because primary request unsuccessful.]
2023-08-06 20:45:06.195 -06:00 [INF] Executing command via PowerShell
2023-08-06 20:45:06.372 -06:00 [INF] C:\ProgramData\certify\logs\log_487e154f-1868-47e2-b19b-a4d1377339fd.txt
xxx
Powershell Task Completed.
So – How do I get the second Write-Output to have it’s prefix?
But here’s a bigger issue (which may be related to the missing prefix on line 2):
Write-Output “$logpath1”
Write-Output “xxx”
Write-Error “Something broke!!!”
It properly yields a popup in the UI showing the error.
BUT - the “INF” lines are changed to “ERR” and the actual Write-Error is just some text at the end of “Completed”.
2023-08-06 20:57:22.376 -06:00 [INF] ---- Performing Task [On-Demand or Manual Execution] :: Run cPanel Powershell ----
2023-08-06 20:57:22.381 -06:00 [INF] Task [Run cPanel Powershell] :: Task is being has been forced to run. Normal status would be [Task is enabled but will not run because primary request unsuccessful.]
2023-08-06 20:57:22.381 -06:00 [INF] Executing command via PowerShell
2023-08-06 20:57:22.554 -06:00 [ERR] C:\ProgramData\certify\logs\log_487e154f-1868-47e2-b19b-a4d1377339fd.txt
xxx
Powershell Task Completed.Error: cPanel.ps1: Something broke!!!
Maybe this is “per design” – or a “dang didn’t know it did that, but it’s ‘per design’ now.” LOL
Note the text “Error:” on that last line probably should have a leading space.
I could dig into the C# but would have to dust off old brain cells that haven’t been used in a decade or two, and my brain is kinda busy learning PowerShell (never did more than “Hello World” until yesterday).
P.S. I’m guessing that if I “catch” an error and a retry works, I better not “Write-Error” to log that -
thinking that you kill the task on any error – or maybe there’s a parm to say “it’s OK-fixed now”.