module("luci.controller.web", package.seeall)
function index()
local fs = require "nixio.fs"
entry({"admin", "system","web"}, call("action"), "修改密码", 6)
entry({"admin", "system","web","commit"}, call("commit"))
end
--设置修改密码向导页面
function action()
luci.template.render("admin_system/web")
end
--修改密码基本设置
function commit()
local uci = require "luci.model.uci".cursor()
local v1 = luci.http.formvalue("pw1")
local v2 = luci.http.formvalue("pw2")
if v1=="" and v2=="" then
--os.execute("/etc/init.d/dropbear restart")
luci.sys.exec("/etc/init.d/dropbear restart")
end
if v1 and v2 and #v1 > 0 and #v2 > 0 then
if v1 == v2 then
--[[if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
m.message = translate("Password successfully changed!")
else
m.message = translate("Unknown Error, password not changed!")
end--]]
--md5加密
md5pass = luci.sys.exec("echo -n \""..v1.."\"|md5sum|cut -d ' ' -f1")
md5pass=string.gsub(md5pass,"\n","")
--修改配置文件里面的密码
--luci.sys.exec("uci set web.@web[0].passwd="..md5pass)
--luci.sys.exec("uci commit web 2>/dev/null")
local uci = require "luci.model.uci".cursor()
--[[uci:foreach("web","web",function(s)
local lcName = s[".name"]
uci:set("web",lcName,"passwd",md5pass)
end
)--]]
uci:set("web","login","passwd",md5pass)
uci:commit("web")
-- m.message = translate("Password successfully changed!")
-- else
-- m.message = translate("Given password confirmation did not match, password not changed!")
end
end
end
function index()
local fs = require "nixio.fs"
entry({"admin", "system","web"}, call("action"), "修改密码", 6)
entry({"admin", "system","web","commit"}, call("commit"))
end
--设置修改密码向导页面
function action()
luci.template.render("admin_system/web")
end
--修改密码基本设置
function commit()
local uci = require "luci.model.uci".cursor()
local v1 = luci.http.formvalue("pw1")
local v2 = luci.http.formvalue("pw2")
if v1=="" and v2=="" then
--os.execute("/etc/init.d/dropbear restart")
luci.sys.exec("/etc/init.d/dropbear restart")
end
if v1 and v2 and #v1 > 0 and #v2 > 0 then
if v1 == v2 then
--[[if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
m.message = translate("Password successfully changed!")
else
m.message = translate("Unknown Error, password not changed!")
end--]]
--md5加密
md5pass = luci.sys.exec("echo -n \""..v1.."\"|md5sum|cut -d ' ' -f1")
md5pass=string.gsub(md5pass,"\n","")
--修改配置文件里面的密码
--luci.sys.exec("uci set web.@web[0].passwd="..md5pass)
--luci.sys.exec("uci commit web 2>/dev/null")
local uci = require "luci.model.uci".cursor()
--[[uci:foreach("web","web",function(s)
local lcName = s[".name"]
uci:set("web",lcName,"passwd",md5pass)
end
)--]]
uci:set("web","login","passwd",md5pass)
uci:commit("web")
-- m.message = translate("Password successfully changed!")
-- else
-- m.message = translate("Given password confirmation did not match, password not changed!")
end
end
end