How to provide a confirm to the logout

I would like to give a chance to the user to confirm the logout operation with a javascript-like "confirm" in a new window, and keep the current window content not changed.

I have no idea at moment, If changed it to template, the current displayed window will also redirect to the new view.

your suggestion are welcomed. thanks

the openwrt original code attached as below:

function action_logout()  
        local dsp = require "luci.dispatcher"
        local utl = require "luci.util"      
        local sid = dsp.context.authsession      
--      I would like to give a confirm here                                                                   
        if sid then  
                utl.ubus("session", "destroy", { ubus_rpc_session = sid })
                                                                          
                dsp.context.urltoken.stok = nil
                                               
                luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
                        sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()       
                })                                                           
        end                                                                                       
        luci.http.redirect(luci.dispatcher.build_url())                                                                                                                                                                          
end

I don't think that messing with the Lua scripts is a good idea and it will not help you much.
Lua runs on the backend of the HTTP server, similar to PHP; in order to display a confirmation pop-up you will most likely need to edit the frontend code which is written in JavaScript.

Well change it to something like this:

if luci.http.formvalue('confirm') == 'yes' then
   -- original logout code
else
   luci.template.render('logout_confirmation')
end

Have your logout_confirmation template render a form like this:

<h3>Do you really want to log out?</h3>
<form action="/admin/logout" method="post">
  <input type="hidden" name="confirm" value="yes" />
  <input type="button" onclick="window.history.back();" value="Cancel" />
  <input type="submit" value="Confirm logout" />
</form>

Thanks Jow, that's a good solution. Is it possible to template window as a popup window (just like javascript's confirm)? it is better to keep the current window not changed instead of replacing it with the template. appreciated for your help.

===================================================================================

I posted the related code as below:
(1) the controller code: (index.lua)

function index()
        local root = node()
        if not root.target then
                root.target = call("action_home")
                root.index = true
        end

        local page   = node("admin")
        page.target  = firstchild()
        page.title   = _("Administration")
        page.order   = 10
        page.sysauth = "root"
        page.sysauth_authenticator = "htmlauth"
        page.ucidata = true
        page.index = true

        entry({"admin", "logout"}, call("action_logout"), _("Logout"), 90)
end

function action_logout()
    if luci.http.formvalue('confirm') == 'yes' then
        local dsp = require "luci.dispatcher"
        local utl = require "luci.util"
        local sid = dsp.context.authsession
        if sid then
                utl.ubus("session", "destroy", { ubus_rpc_session = sid })

                dsp.context.urltoken.stok = nil

                luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
                        sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
                })
        end
        luci.http.redirect(luci.dispatcher.build_url())
    else
        luci.template.render('logout_cfm')
    end
end

(2) the view (template) code, the file name is "logout_cfm.htm"

<%+header%>
 <h3>Do you really want to log out?</h3>
  <form action="<%=REQUEST_URI%>" method="post">
    <input type="hidden" name="confirm" value="yes" />
    <input type="button" onclick="window.history.back();" value="Cancel" />
    <input type="submit" value="Confirm logout" />
 </form> 
<%+footer%>