comparison src/luan/modules/http/Shell_mod.luan @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents http/src/luan/modules/http/Shell_mod.luan@b620b8e1010f
children
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local ipairs = Luan.ipairs or error()
4 local load = Luan.load or error()
5 local try = Luan.try or error()
6 local Io = require "luan:Io.luan"
7 local print = Io.print or error()
8 local Http = require "luan:http/Http.luan"
9
10
11 local M = {}
12
13 local history = {}
14 M.env = {}
15
16 function M.respond()
17 if Http.request.parameter.clear ~= nil then
18 Http.clear_session()
19 Http.response.send_redirect(Http.request.path) -- reload page
20 return
21 else
22 local cmd = Http.request.parameter.cmd
23 if cmd ~= nil then
24 Io.stdout = {}
25 function Io.stdout.write(...)
26 for v in Luan.values(...) do
27 history[#history+1] = v
28 end
29 end
30 print( "% "..cmd )
31 try {
32 function()
33 local line
34 try {
35 function()
36 line = load("return "..cmd,"<web_shell>",M.env)
37 end
38 catch = function(e)
39 line = load(cmd,"<web_shell>",M.env)
40 end
41 }
42 print( line() )
43 end
44 catch = function(e)
45 Io.print_to(Io.stderr,e)
46 print(e)
47 end
48 }
49 end
50 end
51
52 Io.stdout = Http.response.text_writer()
53 %>
54 <html>
55 <head>
56 <title>Luan Shell</title>
57 <style>
58 body {
59 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
60 margin: 2em 5% 0 5%;
61 }
62 pre {
63 font: inherit;
64 }
65 input[type="text"] {
66 font: inherit;
67 padding: .5em .8em;
68 border-radius: 8px;
69 border-style: groove;
70 }
71 input[type="text"]:focus {
72 border-color: #66afe9;
73 outline: none;
74 }
75 input[type="submit"] {
76 color: white;
77 background: #337ab7;
78 border-color: #337ab7;
79 font: inherit;
80 padding: .5em;
81 border-radius: 4px;
82 }
83 input[type="submit"]:hover {
84 background: #236aa7 !important;
85 }
86 </style>
87 </head>
88 <body>
89 <h2>Luan Shell</h2>
90 <p>This is a command shell. Enter commands below.</p>
91 <pre><%
92 for _,v in ipairs(history) do
93 Io.stdout.write(v)
94 end
95 %></pre>
96 <form name='form0' method='post'>
97 % <input type="text" name='cmd' size="80" autofocus>
98 <input type="submit" value="run">
99 <input type="submit" name="clear" value="clear">
100 </form>
101 </body>
102 </html>
103 <%
104 end
105
106 Http.per_session(M.respond)
107
108 return M