forked from bradfitz/websomtep
/
ui.html
92 lines (92 loc) · 2.37 KB
/
ui.html
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
<html>
<head>
<script type="text/javascript">
var ws;
function init() {
console.log("init.");
var mail = document.getElementById("mail");
var status = document.getElementById("status");
var numClients = 0;
var numSenders = 0;
function onOpen() {
status.innerText = "connected";
};
function onClose() {
status.innerHTML = "connection closed";
};
function updateStatus() {
status.innerHTML = "connected<br>(" + numClients + " browsers, " + numSenders + " SMTP clients)";
return;
}
function onMessage(e) {
var m = JSON.parse(e.data);
if (m.NumClients != null) {
numClients = m.NumClients;
updateStatus();
return;
}
if (m.NumSenders != null) {
numSenders = m.NumSenders;
updateStatus();
return;
}
console.log(m);
var md = document.createElement("div");
md.innerHTML = "<table>" +
"<tr class='from'><th>From:</th><td>" + m.From + "</td></tr>" +
"<tr class='to'><th>To:</th><td>"+m.To+"</td></tr>" +
"<tr class='subject'><th>Subject:</th><td>" + m.Subject + "</td></tr>" +
"<tr class='body'><th>Body:</th><td>" + m.Body + "</td></tr>" +
"</table>";
mail.insertBefore(md, mail.firstChild)
};
function connect() {
if (ws != null) {
ws.close();
ws = null;
}
status.innerText = "connecting...";
var url = "ws://{{.WSAddr}}/stream";
ws = new WebSocket(url);
ws.onopen = onOpen;
ws.onclose = onClose;
ws.onmessage = onMessage;
}
connect();
}
</script>
<style>
body {
font-family: Futura;
}
#about {
float: right;
width: 350px;
padding: 10px;
border: 1px solid black;
}
#status {
padding: 10px;
margin-bottom: 1em;
}
#mail table {
margin-bottom: 1em;
}
#mail table th,
#mail table td {
vertical-align: top;
text-align: left;
}
</style>
</head>
<body onLoad="init();">
<div id="about">
<p>This is an SMTP server written in <a href="http://golang.org/">Go</a> which streams incoming mail to your (and everybody else's) active WebSocket connection.</p>
<p>Test it! Email <a href="mailto:whatever@websomtep.danga.com"><i>whatever</i>@websomtep.danga.com</a> (protip: images work too)</p>
<p>Source code is here: <a href="https://github.com/bradfitz/websomtep">https://github.com/bradfitz/websomtep</a>.</p>
</div>
<h1>websomtep == websockets + SMTP</h1>
<div id="status"></div>
<div id="mail"></div>
</body>
</html>