This. ^ WITH an isolation transformer, of course!
You'll need a few hundred VA capacity to avoid sag. If you don't have one already, it's an investment, useful for far more than this one project (unless, like, you're normally writing software and this is truly a one-off case or something..).
Don't worry about heavy filtering, or regulation. Line voltage changes, you can handle by turning the knob. No biggie. Ripple, it's surely made to handle in the first place. The only exception would be a DC transformer, giving output proportional to input, but I don't think those are very common in the 300VDC input module space?
Tim