-
Notifications
You must be signed in to change notification settings - Fork 56
/
web_index.html.go
232 lines (217 loc) · 8.42 KB
/
web_index.html.go
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package main
var (
indexPageContentTemplate = `<!DOCTYPE html>
<html>
<head lang="en">
<title>Request Baskets</title>{{.ThemeCSS}}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
html { position: relative; min-height: 100%; }
body { padding-top: 70px; margin-bottom: 60px; }
.footer { position: absolute; bottom: 0; left: 0; min-width: 100%; height: 60px; background-color: #f5f5f5; }
.container .text-muted { margin: 20px 0; }
h1 { margin-top: 2px; }
#baskets { margin-left: -30px; }
#baskets li { list-style: none; }
#baskets li:before { content: "\f291"; font-family: "FontAwesome"; padding-right: 5px; }
</style>
<script>
(function($) {
function randomName() {
var name = Math.random().toString(36).substring(2, 9);
$("#basket_name").val(name);
}
function onAjaxError(jqXHR) {
if (jqXHR.status == 401) {
$("#master_token_dialog").modal({ keyboard : false });
} else {
$("#error_message_label").html("HTTP " + jqXHR.status + " - " + jqXHR.statusText);
$("#error_message_text").html(jqXHR.responseText);
$("#error_message").modal();
}
}
function addBasketName(name) {
$("#empty_list").addClass("hide");
$("#baskets").append("<li id='basket_" + name + "'><a href='{{.Prefix}}/web/" + name + "'>" + name + "</a></li>");
}
function showMyBaskets() {
$("#empty_list").removeClass("hide");
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
if (key && key.indexOf("basket_") == 0) {
addBasketName(key.substring("basket_".length));
}
}
}
function createBasket() {
var basket = $.trim($("#basket_name").val());
if (basket) {
$.ajax({
method: "POST",
url: "{{.Prefix}}/api/baskets/" + basket,
headers: {
"Authorization" : sessionStorage.getItem("master_token")
}
}).done(function(data) {
localStorage.setItem("basket_" + basket, data.token);
$("#created_message_text").html("<p>Basket '" + basket +
"' is successfully created!</p><p>Your token is: <mark>" + data.token + "</mark></p>");
$("#basket_link").attr("href", "{{.Prefix}}/web/" + basket);
$("#created_message").modal();
// refresh
addBasketName(basket);
}).always(function() {
randomName();
}).fail(onAjaxError);
} else {
$("#error_message_label").html("Missing basket name");
$("#error_message_text").html("Please, provide a name of basket you would like to create");
$("#error_message").modal();
}
}
function saveMasterToken() {
var token = $("#master_token").val();
$("#master_token").val("");
$("#master_token_dialog").modal("hide");
if (token) {
sessionStorage.setItem("master_token", token);
} else {
sessionStorage.removeItem("master_token");
}
}
// Initialization
$(document).ready(function() {
$("#base_uri").html(window.location.protocol + "//" + window.location.host + "{{.Prefix}}/");
$("#create_basket").on("submit", function(event) {
createBasket();
event.preventDefault();
});
$("#refresh").on("click", function(event) {
randomName();
});
$("#master_token_dialog").on("hidden.bs.modal", function (event) {
saveMasterToken();
});
randomName();
showMyBaskets();
});
})(jQuery);
</script>
</head>
<body>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a id="refresh" class="navbar-brand" href="#">Request Baskets</a>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-right">
<a href="{{.Prefix}}/web/baskets" alt="Administration" title="Administration" class="btn btn-default">
<span class="glyphicon glyphicon-cog"></span>
</a>
</form>
</div>
</div>
</nav>
<!-- Error message -->
<div class="modal fade" id="error_message" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content panel-danger">
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="error_message_label">HTTP error</h4>
</div>
<div class="modal-body">
<p id="error_message_text"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Created message -->
<div class="modal fade" id="created_message" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content panel-success">
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="created_message_label">Created</h4>
</div>
<div class="modal-body" id="created_message_text">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a id="basket_link" class="btn btn-primary">Open Basket</a>
</div>
</div>
</div>
</div>
<!-- Master token dialog -->
<div class="modal fade" id="master_token_dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content panel-warning">
<div class="modal-header panel-heading">
<h4 class="modal-title">Master Token</h4>
</div>
<form id="master_token_form">
<div class="modal-body">
<p>This service is operating in <abbr title="In this mode some public functionality is not available without proper authorization">restricted</abbr>
mode. The master token is required in order to be able to create a new basket.</p>
<div class="form-group">
<label for="master_token" class="control-label">Token:</label>
<input type="password" class="form-control" id="master_token">
</div>
</div>
<div class="modal-footer">
<a href="." class="btn btn-default">Back to list of your baskets</a>
<button type="submit" class="btn btn-success" data-dismiss="modal">Authorize</button>
</div>
</form>
</div>
</div>
</div>
<!-- Content -->
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="jumbotron text-center col-md-12" id="create_basket">
<h1>New Basket</h1>
<p>Create a basket to collect and inspect HTTP requests</p>
<form id="create_basket" class="navbar-form">
<div class="form-group">
<label for="basket_name"><span id="base_uri"></span></label>
<input id="basket_name" type="text" placeholder="type a name" class="form-control">
</div>
<button type="submit" class="btn btn-success">Create</button>
</form>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">My Baskets:</div>
<div class="panel-body">
<div id="empty_list" class="hide"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> You have no baskets yet</div>
<ul id="baskets">
</ul>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">
<small>
Powered by <a href="{{.Version.SourceCode}}">{{.Version.Name}}</a> |
Version: <abbr title="From commit: {{.Version.CommitShort}} ({{.Version.Commit}})">{{.Version.Version}}</abbr>
</small>
</p>
</div>
</footer>
</body>
</html>`
)