require("luamods/command")
require("config/system_conf")
require("luamods/layout")

header = layout.getHeader()
footer = layout.getFooter()

content = ""

userLevel = db.getPriv(layout.username) or 1

if (userLevel == 1) then
    buttonControl = " disabled"
    inputControl = " readonly"
else
    buttonControl = ""
    inputControl = ""
end

if (cgi.post.Reboot == "Reboot System") and (userLevel ~= 1) then
    print([[

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <link rel="stylesheet" href="styles/mainstyle.css" type="text/css" />
    <link rel="shortcut icon" href="styles/img/favicon.ico">
    <meta http-equiv="content-type" content="text/html; charset=windows-1251" />
    <title>Guinnux Config Site</title>
</head>

<body onload="setTimeout('location.reload(true);', 1000 * 60);">
    <div id="main">
        <div id="logo"><a href="http://www.kses.net/" target="window"><img src="images/kses-header-logo.png"/></a></div><!--****** Image is set in .css file with logo id ******-->
        <div id="content" style="text-align: center;">
            <div style="display:inline-block; background: url(styles/img/box_2.png) repeat-x; border: solid 1px #aaaaaa; margin:25px;padding: 25px; width: 400px; height: 240px; border-radius:10px;">
                <center><h2>Rebooting, please wait...</h2><br><img src="images/spinner.gif"/></center><br>
            </div>
        </div>
        <div id="footer">
            Copyright 2013 Keystone Electronic Solutions Version 2.5 | <a href="http://www.kses.net/" target="window">www.kses.net</a>
        </div>
    </div>
</body>
</html>

]])
    command.ex("logger 'System reboot requested from webconfig'")
    command.ex(system_conf.reboot)
    return
else
    content = content .. [[
                    <div id="info">
                        <div style="background:url(images/system.png); background-size:32px; background-repeat:no-repeat; background-position: 20px center;">
                            <center><h1>System Information</h1></center>
                        </div>
                    </div>

                    <h3>UNIX Name : </h3>
                    <pre class="formLayoutfull">
                    <!-- System uname start -->
]]..command.ex( system_conf.uname )..[[
                    <!-- System uname end -->
                    </pre>

                    <h3>Disk Space: </h3>
                    <pre class="formLayoutfull">
                    <!-- Disk space start -->
]]..command.ex( system_conf.disk_space )..[[
                    <!-- Disk space end -->
                    </pre>

                    <h3>Top Processes: </h3>
                    <pre class="formLayoutfull">
                    <!-- Top processes start -->
]]..command.ex( system_conf.top_proc )..[[
                    <!-- Top processes end -->
                    </pre>

                    <h3>Services: </h3>
                    <pre class="formLayoutfull">
                    <!-- Services start -->
]]..command.ex( system_conf.services )..[[
                    <!-- Services end -->
                    </pre>
                    
                    <h3>Sytem log: </h3>
                    <pre class="formLayoutfull" style="overflow: auto;">
                    <!-- Services start -->
]]..command.ex( system_conf.syslog )..[[
                    <!-- Services end -->
                    </pre>
                    <br><hr><br>
                    <form action="system.lua" method="post" onsubmit="return confirm('Are you sure you want to reboot the system?');">
                        <img src="images/power.png" style="vertical-align: middle;"/><input type="submit" name="Reboot" value="Reboot System"]]..buttonControl..[[/>
                    </form>

]]

end

print(header..content..footer)
