PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/package/webif-iw-lua-pepperspot/files/www/cgi-bin/login/login2

http://lua-wrt.googlecode.com/
Lua | 173 lines | 122 code | 14 blank | 37 comment | 14 complexity | 5dffc2818532f72e86d4ec504f0a89ea MD5 | raw file
  1. #!/usr/bin/lua
  2. require("set_path")
  3. require("init")
  4. require("uci_iwaddon")
  5. require("htmlClass")
  6. require("md5")
  7. user_label = uci.get("chillipages","login","user_label")
  8. pass_enable = tonumber(uci.get("chillipages","login","pass_enable") or 0)
  9. pass_label = uci.get("chillipages","login","pass_label")
  10. pass_value = uci.get("chillipages","login","pass_value")
  11. msg_label = uci.get("chillipages","login","msg_label")
  12. msg_enable = tonumber(uci.get("chillipages","login","msg_enable") or 0)
  13. function notyet()
  14. local strpage = [[
  15. <form METHOD="get" name="logon" >
  16. <INPUT TYPE="HIDDEN" NAME="nasid" VALUE="]]..__FORM['nasid']..[[" />
  17. <INPUT TYPE="HIDDEN" NAME="challenge" VALUE="]]..__FORM['challenge']..[[" />
  18. <INPUT TYPE="HIDDEN" NAME="uamip" VALUE="]]..__FORM['uamip']..[[" />
  19. <INPUT TYPE="HIDDEN" NAME="uamport" VALUE="]]..__FORM['uamport']..[[" />
  20. <INPUT TYPE="HIDDEN" NAME="userurl" VALUE="]]..__FORM['userurl']..[[" />
  21. <table id="logonTable" border="0" >
  22. <tr>
  23. <td colspan="2" style="font-size:120%;">
  24. <div id="logonMessage" style="font-size:70%;padding-top:4px; ]]
  25. if msg_enable == 0 then
  26. strpage=strpage..[[ display:none; ]]
  27. end
  28. strpage=strpage..[[">]]..msg_label..[[</div>
  29. </td>
  30. </tr>
  31. <tr id="usernameRow">
  32. <td id="usernameLabel"><b>]]..user_label..[[ </b></td>
  33. <td><input name="username" type="text" id="username" size="20"/></td>
  34. </tr>
  35. ]]
  36. if pass_enable == 0 then
  37. strpage=strpage..[[ <tr id="passwordRow" style="display:none">]]
  38. else
  39. strpage=strpage..[[ <tr id="passwordRow" > ]]
  40. end
  41. strpage=strpage..[[
  42. <td id="passwordLabel" ><b> ]]..pass_label..[[ </b></td>
  43. <td><input name="password" type="password" id="password"]]
  44. if pass_enable == 0 then
  45. strpage=strpage..[[ value="]]..pass_value..[["]]
  46. end
  47. strpage=strpage..[[ size="20"/></td>
  48. </tr>
  49. <tr>
  50. <!--td colspan="2"><input type="submit" value="Connect" onClick="connect();"/></td-->
  51. <td colspan="2"><input type="submit" name="login" value="Identificarse" /></td>
  52. </tr>
  53. </table>
  54. </form>
  55. ]]
  56. return strpage;
  57. end
  58. function sumhexa (k)
  59. -- k = core.sum(k)
  60. return (string.gsub(k, ".", function (c)
  61. return string.format("%02x", string.byte(c))
  62. end))
  63. end
  64. function encriptpass()
  65. -- $hexchal = pack ("H32", $_GET['chal']);
  66. -- if (isset ($this->uamsecret)) {
  67. -- $newchal = pack ("H*", md5($hexchal . $this->uamsecret));
  68. -- } else {
  69. -- $newchal = $hexchal;
  70. -- }
  71. -- $response = md5("\0" . $_GET['Password'] . $newchal);
  72. -- $newpwd = pack("a32", $_GET['Password']);
  73. -- $pappassword = implode ("", unpack("H32", ($newpwd ^ $newchal)));
  74. -- $this->title = 'Logging in to HotSpot';
  75. -- $this->headline = 'Logging in to HotSpot';
  76. -- $this->bodytext = '';
  77. -- $this->strForm .="<html><head><META NAME=\"author\" CONTENT=\"Fabian Omar Franzotti\">";
  78. -- $this->strForm .="<meta http-equiv=\"Cache-control\" content=\"no-cache\">";
  79. -- $this->strForm .="<meta http-equiv=\"Pragma\" content=\"no-cache\">";
  80. page.head.metas:add({
  81. { ["http-equiv"] = "Cache-control", content="no-cache" },
  82. { ["http-equiv"] = "Pragma", content="no-cache" }
  83. })
  84. response=sumhexa(md5.sum(__FORM["password"]..__FORM["challenge"]))
  85. -- if ((isset ($uamsecret)) && isset($userpassword)) {
  86. -- $this->strForm .= '<meta http-equiv="refresh" content="30;url=http://' . $_GET['uamip'] . ':' . $_GET['uamport'] . '/logon?username=' . $_GET['UserName'] . '&password=' . $pappassword . '">';
  87. -- page.head.metas:add(
  88. -- { ["http-equiv"] = "refresh", content=[[10;url=http://]]..__FORM["uamip"]..":"..__FORM["uamport"].."/logon?username="..__FORM["username"].."&password="..__FORM["password"].."&userurl="..__FORM["userurl"] }
  89. -- )
  90. -- } else {
  91. -- $this->strForm .= '<meta http-equiv="refresh" content="30;url=http://' . $_GET['uamip'] . ':' . $_GET['uamport'] . '/logon?username=' . $_GET['UserName'] . '&response=' . $response . '&userurl=' . $_GET['userurl'] . '">';
  92. page.head.metas:add(
  93. { ["http-equiv"] = "refresh", content=[[10;url=http://]]..__FORM["uamip"]..":"..__FORM["uamport"].."/logon?username="..__FORM["username"].."&response="..response.."&userurl="..__FORM["userurl"] }
  94. )
  95. -- }
  96. -- $this->strForm .="<link rel=\"icon\" href=\"/favicon.ico\" type=\"image/x-icon\"><link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\"><link rel=\"stylesheet\" type=\"text/css\" href=\"css/NiftyLayout.css\" media=\"screen\">";
  97. -- $this->strForm .="<script src=\"niftycube.js\" type=\"text/javascript\" language=\"javascript\"></script><script src=\"libraries/niftyLayout.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  98. -- $this->strForm .= "</head>";
  99. -- $this->strForm .= "<body>";
  100. -- $this->big_body();
  101. end
  102. page = htmlpageClass.new(tr("Login Page").." - "..__SYSTEM.general.firmware_name.." "..tr("Administrative Console"))
  103. page.head.links:add(
  104. {rel = "stylesheet", type = "text/css", href = "/themes/active/webif.css"}
  105. )
  106. page.head.metas:add({
  107. { ["http_equiv"] = "Content-Type", content = [[text/html; charset=UTF-8]]},
  108. { ["http-equiv"] = "expires", content = "-1" }
  109. })
  110. -- Can add code with this way, then the script open and close the div an set the id
  111. page.container:add(htmlsectionClass.new("div","header"))
  112. page.container.header:add([[
  113. <h1>X-Wrt</h1>
  114. <em>OpenWrt for end users</em>
  115. ]])
  116. -- or can add code directly to page.container like you write on standart html file
  117. page.container:add([[<div id="mainmenu"></div>]])
  118. page.container:add()
  119. page.container:add(htmlsectionClass.new("div","content"))
  120. local strpage=""
  121. if __FORM.login ~= nil then encriptpass()
  122. else
  123. if __FORM['res'] ~= nil and __FORM['res'] ~= "" then
  124. if __FORM['res'] == "notyet" then strpage=notyet() end
  125. -- else
  126. end
  127. end
  128. local str ="<br /><br />"
  129. for i,v in pairs(__FORM) do
  130. str=str..i.."="..v.."<br>"
  131. end
  132. str=str.."<br /><br />"
  133. pepe=md5.sum("pepe")
  134. str=str..pepe
  135. str=str.."<br />"
  136. str=str..sumhexa(__FORM["challenge"])
  137. str=str.."<br />"
  138. str=str..md5.crypt("pepe","pepe")
  139. --[[
  140. for i,v in pairs(__SERVER) do
  141. str=str..i.."="..v.."<br>"
  142. end
  143. ]]
  144. strpage=strpage..str
  145. page.container.content:add(strpage)
  146. page.container:add([[
  147. <fieldset id="save">
  148. <legend><strong>Proceed Changes</strong></legend>
  149. <div class="page-save"></div>
  150. <ul class="apply">
  151. </ul>
  152. </fieldset>
  153. <hr />
  154. <div id="footer">
  155. <h3>X-Wrt</h3>
  156. <em>End user extensions for OpenWrt</em>
  157. </div>
  158. ]])
  159. page:print()