Skip to content

Commit ed78927

Browse files
author
Casey Boettcher
committed
Improvements to CSS and form layout
1 parent bf72ef2 commit ed78927

File tree

5 files changed

+138
-32
lines changed

5 files changed

+138
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ gen
66
test/xforce.cfg
77
notes.txt
88
keys.txt
9-
__pycache__/*
9+
__pycache__

web/webui.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def process_form(self, api_key, api_password, ip_addresses):
2222
xfipchk.r
2323
xfipchk.call_xforce_api(ip_addresses, api_key, api_password)
2424

25+
@cherrypy.expose()
26+
def stop_demo(self, stop_demo):
27+
cherrypy.engine.stop()
28+
2529

2630
if __name__ == '__main__':
2731
cherrypy.quickstart(XforceForm())

web/xfipchk.css

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,71 @@
11
body
22
{
3-
background-color: #777777;
3+
color: #02AAFF;
4+
font-family: sans-serif;
5+
position: absolute;
6+
width: 800px;
7+
height: 600px;
8+
top: 20%;
9+
left: 30%;
10+
margin: -100px 0 0 -150px;
11+
margin: auto;
12+
background-color: #313233;
413
}
514

6-
div#column
15+
.instructions
716
{
8-
color: #FF6100;
17+
font-size: 16pt;
918
}
1019

11-
.api-cred
20+
li
1221
{
13-
width: 250px;
14-
}
22+
margin-bottom: 10px;
23+
margin-top: 10px;
24+
}
25+
26+
.api_cred
27+
{
28+
margin-top: 10px;
29+
margin-bottom: 10px;
30+
font-size: 14pt;
31+
font-family: sans-serif;
32+
text-color: #EEEEEE;
33+
size: 36;
34+
width: 350px;
35+
}
36+
37+
div#textarea
38+
{
39+
width: 100%;
40+
maargin: 0 auto;
41+
margin-top: 10px;
42+
}
43+
44+
textarea
45+
{
46+
width: 100%;
47+
height: 10em;
48+
}
49+
50+
div#std_buttons
51+
{
52+
margin: 0 auto;
53+
width: 23%;
54+
}
55+
56+
div#stop_demo_button
57+
{
58+
margin: 0 auto;
59+
margin-top: 20px;
60+
width: 14%;
61+
}
62+
63+
button
64+
{
65+
color: #02AAFF;
66+
font-size: 14pt;
67+
font-family: sans-serif;
68+
background-color: #313233;
69+
margin: 0 auto;
70+
}
71+

web/xfipchk.html

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,71 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>X-Force IP Check</title>
6-
<script src="jquery.js"></script>
7-
<script src="jquery.validate.js"></script>
6+
<script src="https://code.jquery.com/jquery-3.2.1.slim.js"
7+
integrity="sha256-tA8y0XqiwnpwmOIl3SGAcFl2RvxHjA8qp0+1uCGmRmg=" crossorigin="anonymous"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>
9+
<script>
10+
function warn_stop()
11+
{
12+
var conf = confirm("This will stop the web server and close your browser tab/window. You will loose any"+
13+
"data returned from X-Force. Proceed?" );
14+
15+
if (conf)
16+
{
17+
$.post("/stop_demo", function(data){ alert("Data Loaded: " + data); });
18+
}
19+
/*$.post( "/stop_demo", function() {
20+
21+
})
22+
.success(data, status, ajaxRequestObj) function() {
23+
24+
.done(function() {
25+
alert( "second success" );
26+
})
27+
.fail(function() {
28+
alert( "error" );
29+
})
30+
.always(function() {
31+
alert( "finished" );
32+
});
33+
}*/
34+
}
35+
</script>
836
<link rel="stylesheet" type="text/css" href="xfipchk.css"/>
9-
:w
1037
</head>
1138
<body>
1239
<div id="column">
13-
<form id="the-form" action="process_form">
40+
<form id="the_form" action="process_form" method="post">
1441
<div>
15-
<p><span>Instructions:</span>
42+
<p><span class="instructions">Instructions:</span></p>
1643
<ol>
1744
<li>Paste your IBM X-Force API key and password into the corresponding fields.</li>
18-
<li>Enter IP addresses in the box labeled accordingly. They may be delimited by commas or newlines.</li>
45+
<li>Enter IP addresses in the box labeled accordingly. They must be delimited by commas or newlines.</li>
1946
<li>Press the Submit button to call the API.</li>
47+
<li>Review the results.</li>
48+
<li>Press the Stop Demo button to stop the demo.</li>
2049
</ol>
2150
</p>
22-
<label for="api-key">X-Force API Key</label>
23-
<input type="text" autofocus required class="api-cred" name="api_key" id="api-key" title="api-key"
24-
placeholder="01234567-9abc-def0-1234-56789abcdef0"/>
25-
<label for="api-password">X-Force API Password</label>
26-
<input type="text" class="api-cred" required name="api_password" id="api-password" title="api-password"
27-
placeholder="01234567-9abc-def0-1234-56789abcdef0"/>
51+
<label for="api_key">X-Force API Key</label>
52+
<input type="text" autofocus required class="api_cred" name="api_key" id="api_key" title="api_key"
53+
placeholder="01234567-9abc-def0-1234-56789abcdef0" pattern="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" max="36"/>
54+
<br/>
55+
<label for="api_password">X-Force API Password</label>
56+
<input type="text" class="api_cred" required name="api_password" id="api_password" title="api_password"
57+
placeholder="01234567-9abc-def0-1234-56789abcdef0" pattern="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" maxlength="36"/>
2858
</div>
29-
<div>
30-
<label for="ip-addresses">IP Addresses</label>
31-
<input type="textarea" class="ip-addresses" name="ip_addresses" id="ip-addresses"/>
59+
<div id="textarea">
60+
<label for="ip_addresses">IP Addresses</label>
61+
<textarea class="ip_addresses" name="ip_addresses" id="ip_addresses"></textarea>
62+
</div>
63+
<div id="std_buttons">
64+
<button id="submit" type="submit" form="the_form" value="submit">Submit</button> <button id="reset" type="reset" form="the_form" value="reset">Reset</button>
65+
</div>
66+
</form>
67+
<form id="stop_form">
68+
<div id="stop_demo_button">
69+
<button name="stop_demo" form="stop_form" onclick="warn_stop()">Stop Demo</button>
3270
</div>
33-
<script>
34-
$("the-form").validate();
35-
36-
37-
</script>
3871
</form>
3972
</div>
4073
</body>

xfipchk.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
XFORCE_API_IP_REP = 'ipr'
2525
XFORCE_CRED_PATTERN = '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
2626

27+
global pidfile
28+
2729

2830
def parse_args():
2931
"""
@@ -205,21 +207,31 @@ def start_server(address='127.0.0.1', port=8000):
205207
cherrypy.config.update(config)
206208
cherrypy.tree.mount(webapp, config=config)
207209
cherrypy.engine.start()
208-
pidfile = tempfile.TemporaryFile(suffix='.pid')
210+
pidfile = tempfile.TemporaryFile(prefix='xfipchk', suffix='.pid')
209211
PIDFile(cherrypy.engine, pidfile).subscribe()
212+
213+
cherrypy.engine.subscribe('stop', cleanup(pidfile))
210214
cherrypy.engine.block()
211215

216+
return pidfile.name
217+
218+
219+
def cleanup(pid_file):
220+
print(pid_file.name)
221+
if os.path.exists(pid_file):
222+
cherrypy.engine.stop()
223+
212224

213225
def main():
226+
global pidfile
214227
args = parse_args()
215228
# if port is in Namespace object, assume web interface
216229
if hasattr(args, 'port'):
217230
# TODO: should use a context manager here
218231
try:
219-
start_server(args.address, args.port, pidfile)
220-
except:
221-
print(ose.strerror)
222-
finally:
232+
pidfile = start_server(args.address, args.port)
233+
except (ConnectionError, KeyboardInterrupt) as err:
234+
print("Server failed to start: {}".format(err.strerror))
223235

224236
# assume cli if user passed in api key file
225237
elif hasattr(args, 'authN'):

0 commit comments

Comments
 (0)