mail4one/jsdev/index.html

182 lines
6.3 KiB
HTML

<!doctype html>
<html>
<head>
<title>Mail4one Web config</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<script type="application/json" id="m41config">
{
"matches": [
{
"name": "mydomain",
"addr_rexs": [
".*@mydomain.com",
".*@m.mydomain.com"
]
},
{
"name": "personal",
"addrs": [
"first.last@mydomain.com",
"secret.name@mydomain.com"
]
}
],
"boxes": [
{
"name": "spam",
"rules": [
{
"match_name": "mydomain",
"negate": true,
"stop_check": true
}
]
},
{
"name": "important",
"rules": [
{
"match_name": "personal"
}
]
},
{
"name": "all",
"rules": [
{
"match_name": "default_match_all"
}
]
}
],
"users": [
{
"username": "mymobile",
"password_hash": "AFTY5EVN7AX47ZL7UMH3BETYWFBTAV3XHR73CEFAJBPN2NIHPWDZHV2UQSMSPHSQQ2A2BFQBNC77VL7F2UKATQNJZGYLCSU6C43UQDAQXWXSWNGAEPGIMG2F3QDKBXL3MRHY6K2BPID64ZR6LABLPVSF",
"mbox": "important"
},
{
"username": "mydesk",
"password_hash": "AFTY5EVN7AX47ZL7UMH3BETYWFBTAV3XHR73CEFAJBPN2NIHPWDZHV2UQSMSPHSQQ2A2BFQBNC77VL7F2UKATQNJZGYLCSU6C43UQDAQXWXSWNGAEPGIMG2F3QDKBXL3MRHY6K2BPID64ZR6LABLPVSF",
"mbox": "all"
}
]
}
</script>
<script type="application/javascript">
"use strict"
// Globals
let matches_table
let match_row_template
let config
function populate_match_table(matches_config) {
for (let match_config of matches_config) {
const {
"name": match_name,
"addrs" : addrs,
"addr_rexs" : addr_rexs,
} = match_config
const [match_type, match_values] = (() => {
if (addrs != undefined) {
return ["addrs", addrs]
} else {
return ["addr_rexs", addr_rexs]
}
})();
addMatchRow()
const rows = matches_table.tBodies[0].rows
const last_row = rows.item(rows.length -1 )
const [ name_cell, type_cell, value_cell ] = last_row.cells
name_cell.innerText = match_name
type_cell.firstElementChild.value = match_type
value_cell.firstElementChild.value = match_values.join("\n")
}
}
function extract_match_table() {
let matches = []
for (let row of matches_table.tBodies[0].rows) {
const [ name_cell, type_cell, value_cell ] = row.cells
let m = {"name" : name_cell.innerText}
switch (type_cell.firstElementChild.value) {
case "addrs": {
m["addrs"] = value_cell.firstElementChild.value.split("\n")
break;
}
case "addr_rexs": {
m["addr_rexs"] = value_cell.firstElementChild.value.split("\n")
break;
}
}
matches.push(m)
}
return matches
}
function main() {
matches_table = document.getElementById("web-cfg-matches")
match_row_template = document.getElementById("web-cfg-matches-row")
config = JSON.parse(document.getElementById('m41config').text);
populate_match_table(config["matches"])
save()
document.getElementById("before").value = JSON.stringify(config["matches"])
}
function save() {
const matches = extract_match_table()
document.getElementById("after").value = JSON.stringify(matches)
}
function addMatchRow() {
let row_clone = match_row_template.content.cloneNode(true)
matches_table.tBodies[0].appendChild(row_clone)
}
</script>
</head>
<body onload="main()">
<template id="web-cfg-matches-row">
<tr>
<td contentEditable="true" >Name</td>
<td>
<select>
<option value="addrs">List of addresses</option>
<option value="addr_rexs">List of regexes for addresses</option>
</select>
</td>
<td>
<textarea></textarea>
</td>
</tr>
</template>
<h1>Mail4one Web config</h1>
<table id="web-cfg-matches">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Values</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button onClick="addMatchRow()">Add Match</button>
<button onClick="save()">Save</button>
<div>
<label for="cfg_before">Before</label>
<textarea id="before" name="cfg_before" style="width=100%"></textarea>
</div>
<div>
<label for="cfg_after">After</label>
<textarea id="after" name="cfg_after"></textarea>
</div>
</body>
</html>