-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
232 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(function () { | ||
window.avalanchemq = window.avalanchemq || {}; | ||
let avalanchemq = window.avalanchemq; | ||
|
||
function fetch(cb) { | ||
let url = "/api/users"; | ||
let raw = localStorage.getItem(url); | ||
if (raw) { | ||
var users = JSON.parse(raw); | ||
cb(users); | ||
} | ||
avalanchemq.http.request("GET", url).then(function (users) { | ||
try { | ||
localStorage.setItem("/api/users", JSON.stringify(users)); | ||
} catch (e) { | ||
console.error("Saving localStorage", e); | ||
} | ||
cb(users); | ||
}).catch(function (e) { | ||
console.error(e.message); | ||
}); | ||
} | ||
|
||
Object.assign(window.avalanchemq, { | ||
users: { | ||
fetch | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Virtual host | AvalancheMQ</title> | ||
<link href="/main.css" rel="stylesheet"> | ||
<meta name="google" content="notranslate"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<header> | ||
<h1> | ||
AvalancheMQ | ||
<small id="version"></small> | ||
</h1> | ||
<div id="user-info"> | ||
<span>👤: </span> | ||
<span id="username"></span> | ||
<span id="vhost"></span> | ||
</div> | ||
</header> | ||
<ul id="menu"> | ||
<li><a href="/">Overview</a></li> | ||
<li><a href="/connections">Connections</a></li> | ||
<li><a href="/channels">Channels</a></li> | ||
<li><a href="/queues">Queues</a></li> | ||
<li><a href="/exchanges">Exchanges</a></li> | ||
<li><a href="/users">Users</a></li> | ||
<li><a href="/vhosts">Virtual Hosts</a></li> | ||
</ul> | ||
<h2> | ||
Virtual host: | ||
<small id="vhost2"></small> | ||
</h2> | ||
<h2> | ||
Message stats | ||
</h2> | ||
<table id="msg-table" class="table"> | ||
<thead> | ||
<tr> | ||
<th>Ready</th> | ||
<th>Unacked</th> | ||
<th>Total</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<td id="ready"></td> | ||
<td id="unacked"></td> | ||
<td id="total"></td> | ||
</tbody> | ||
</table> | ||
<div id="table-error"></div> | ||
<h2> | ||
Permissions | ||
<small id="table-count"></small> | ||
</h2> | ||
<table id="table" class="table"> | ||
<thead> | ||
<tr> | ||
<th>User</th> | ||
<th>Configure regexp</th> | ||
<th>Write regexp</th> | ||
<th>Read regexp</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody></tbody> | ||
</table> | ||
<form method="put" id="setPermission"> | ||
<fieldset> | ||
<legend>Set permission</legend> | ||
<label> | ||
User | ||
<select name="user" required></select> | ||
</label> | ||
<label> | ||
Configure regexp | ||
<input type="text" name="configure" required value=".*"> | ||
</label> | ||
<label> | ||
Write regexp | ||
<input type="text" name="write" required value=".*"> | ||
</label> | ||
<label> | ||
Read regexp | ||
<input type="text" name="read" required value=".*"> | ||
</label> | ||
<button type="submit">Set permission</button> | ||
</fieldset> | ||
</form> | ||
<form method="delete" id="deleteVhost"> | ||
<fieldset> | ||
<legend>Delete vhost</legend> | ||
<button type="submit">Delete</button> | ||
</fieldset> | ||
</form> | ||
</div> | ||
<script src="/js/auth.js"></script> | ||
<script src="/js/http.js"></script> | ||
<script src="/js/overview.js"></script> | ||
<script src="/js/users.js"></script> | ||
<script src="/js/table.js"></script> | ||
<script> | ||
const vhost = new URLSearchParams(window.location.search).get("name") | ||
document.title = vhost + " | AvalancheMQ" | ||
document.querySelector("#vhost2").textContent = vhost | ||
const urlEncodedVhost = encodeURIComponent(vhost) | ||
|
||
const vhostUrl = "/api/vhosts/" + urlEncodedVhost | ||
avalanchemq.http.request("GET", vhostUrl).then(item => { | ||
document.getElementById("ready").textContent = item.messages_ready | ||
document.getElementById("unacked").textContent = item.messages_unacknowledged | ||
document.getElementById("total").textContent = item.messages | ||
}) | ||
|
||
const permissionsUrl = "/api/vhosts/" + urlEncodedVhost + "/permissions" | ||
avalanchemq.table.renderTable("table", permissionsUrl, [], 0, (tr, item) => { | ||
let btn = document.createElement("button") | ||
btn.innerHTML = "Clear" | ||
btn.onclick = function (evt) { | ||
let url = "/api/permissions/" + urlEncodedVhost + "/" + encodeURIComponent(item.user) | ||
avalanchemq.http.request("DELETE", url) | ||
.then(() => window.location.reload()) | ||
.catch(e => console.error.apply(console, e)) | ||
} | ||
let userLink = document.createElement("a") | ||
userLink.href = "/user?name=" + encodeURIComponent(item.user) | ||
userLink.textContent = item.user | ||
avalanchemq.table.renderCell(tr, 0, userLink) | ||
avalanchemq.table.renderCell(tr, 1, item.configure) | ||
avalanchemq.table.renderCell(tr, 2, item.write) | ||
avalanchemq.table.renderCell(tr, 3, item.read) | ||
avalanchemq.table.renderCell(tr, 4, btn) | ||
}) | ||
|
||
function addUserOptions(users) { | ||
let select = document.forms["setPermission"].elements["user"] | ||
while (select.options.length) select.remove(0) | ||
for (let i = 0; i < users.length; i++) { | ||
let opt = document.createElement("option") | ||
opt.text = users[i].name | ||
select.add(opt) | ||
} | ||
} | ||
|
||
avalanchemq.users.fetch(addUserOptions); | ||
|
||
document.querySelector("#setPermission").addEventListener("submit", function (evt) { | ||
evt.preventDefault(); | ||
let data = new FormData(this) | ||
let url = "/api/permissions/" + urlEncodedVhost + "/" + encodeURIComponent(data.get("user")) | ||
body = { | ||
configure: data.get("configure"), | ||
write: data.get("write"), | ||
read: data.get("read") | ||
} | ||
avalanchemq.http.request("PUT", url, body) | ||
.then(() => window.location.reload()) | ||
.catch(e => console.error.apply(console, e)) | ||
}) | ||
|
||
document.querySelector("#deleteVhost").addEventListener("submit", function (evt) { | ||
evt.preventDefault(); | ||
let url = "/api/vhosts/" + urlEncodedVhost | ||
avalanchemq.http.request("DELETE", url) | ||
.then(() => window.location = "/vhosts") | ||
.catch(e => console.error.apply(console, e)) | ||
}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters